|
1 |
/*
|
|
2 |
* gvSIG. Desktop Geographic Information System.
|
|
3 |
*
|
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or
|
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
9 |
* of the License, or (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
18 |
*
|
|
19 |
* For any additional information, do not hesitate to contact us
|
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
21 |
*/
|
|
22 |
package org.gvsig.vcsgis.swing.impl.changes;
|
|
23 |
|
|
24 |
import java.awt.Component;
|
|
25 |
import java.awt.Cursor;
|
|
26 |
import java.awt.Dimension;
|
|
27 |
import java.awt.event.ActionEvent;
|
|
28 |
import java.awt.event.KeyAdapter;
|
|
29 |
import java.awt.event.KeyEvent;
|
|
30 |
import java.sql.Timestamp;
|
|
31 |
import java.util.ArrayList;
|
|
32 |
import java.util.Date;
|
|
33 |
import java.util.HashSet;
|
|
34 |
import java.util.Iterator;
|
|
35 |
import java.util.List;
|
|
36 |
import java.util.Set;
|
|
37 |
import javax.json.JsonObject;
|
|
38 |
import javax.swing.JButton;
|
|
39 |
import javax.swing.JLabel;
|
|
40 |
import javax.swing.JOptionPane;
|
|
41 |
import javax.swing.JTable;
|
|
42 |
import javax.swing.JTextField;
|
|
43 |
import javax.swing.JTree;
|
|
44 |
import javax.swing.ListSelectionModel;
|
|
45 |
import javax.swing.event.ChangeEvent;
|
|
46 |
import javax.swing.event.ListSelectionEvent;
|
|
47 |
import javax.swing.event.TableModelEvent;
|
|
48 |
import javax.swing.event.TableModelListener;
|
|
49 |
import javax.swing.table.DefaultTableCellRenderer;
|
|
50 |
import javax.swing.table.TableModel;
|
|
51 |
import org.apache.commons.collections.CollectionUtils;
|
|
52 |
import org.apache.commons.lang3.StringUtils;
|
|
53 |
import org.apache.commons.lang3.mutable.MutableObject;
|
|
54 |
import org.gvsig.featureform.swing.CreateJFeatureFormException;
|
|
55 |
import org.gvsig.featureform.swing.JFeatureForm;
|
|
56 |
import org.gvsig.fmap.dal.feature.Feature;
|
|
57 |
import org.gvsig.fmap.dal.feature.FeatureStore;
|
|
58 |
import org.gvsig.fmap.dal.swing.DALSwingLocator;
|
|
59 |
import org.gvsig.fmap.dal.swing.DataSwingManager;
|
|
60 |
import org.gvsig.fmap.geom.Geometry;
|
|
61 |
import org.gvsig.tools.ToolsLocator;
|
|
62 |
import org.gvsig.tools.dispose.DisposeUtils;
|
|
63 |
import org.gvsig.tools.dispose.impl.AbstractDisposable;
|
|
64 |
import org.gvsig.tools.exception.BaseException;
|
|
65 |
import org.gvsig.tools.i18n.I18nManager;
|
|
66 |
import org.gvsig.tools.swing.api.ToolsSwingLocator;
|
|
67 |
import org.gvsig.tools.swing.api.ToolsSwingManager;
|
|
68 |
import org.gvsig.tools.swing.api.pickercontroller.DatePickerController;
|
|
69 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
|
|
70 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
|
|
71 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
|
|
72 |
import org.gvsig.vcsgis.lib.VCSGisChange;
|
|
73 |
import org.gvsig.vcsgis.lib.VCSGisEntity;
|
|
74 |
import org.gvsig.vcsgis.lib.VCSGisLocator;
|
|
75 |
import org.gvsig.vcsgis.lib.VCSGisManager;
|
|
76 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK;
|
|
77 |
import static org.gvsig.vcsgis.lib.VCSGisManager.OP_ADD_ENTITY;
|
|
78 |
import static org.gvsig.vcsgis.lib.VCSGisManager.OP_DELETE;
|
|
79 |
import org.gvsig.vcsgis.lib.VCSGisRuntimeException;
|
|
80 |
import org.gvsig.vcsgis.lib.VCSGisTopologyPlan;
|
|
81 |
import org.gvsig.vcsgis.lib.VCSGisTopologyPlanStatus;
|
|
82 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace;
|
|
83 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceChange;
|
|
84 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceChanges;
|
|
85 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity;
|
|
86 |
import org.gvsig.vcsgis.swing.VCSGisEntitySelectorController;
|
|
87 |
import org.gvsig.vcsgis.swing.VCSGisSwingLocator;
|
|
88 |
import org.gvsig.vcsgis.swing.VCSGisSwingManager;
|
|
89 |
import org.gvsig.vcsgis.swing.VCSGisSwingServices;
|
|
90 |
import static org.gvsig.vcsgis.swing.VCSGisSwingServices.HIGHLIGHT_WORKSPACE;
|
|
91 |
import static org.gvsig.vcsgis.swing.VCSGisSwingServices.HIGHLIGHT_WORKSPACE_PREVIOUS;
|
|
92 |
import org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons;
|
|
93 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.cleanHighligthed;
|
|
94 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.notInSwingThreadInvokeLater;
|
|
95 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.refreshDocument;
|
|
96 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationErrors;
|
|
97 |
import org.slf4j.Logger;
|
|
98 |
import org.slf4j.LoggerFactory;
|
|
99 |
|
|
100 |
/**
|
|
101 |
*
|
|
102 |
* @author gvSIG Team
|
|
103 |
*/
|
|
104 |
public class LocalChangesController extends AbstractDisposable {
|
|
105 |
private static final Logger LOGGER = LoggerFactory.getLogger(LocalChangesController.class);
|
|
106 |
|
|
107 |
private final JButton btnLocalCheckAllEntities;
|
|
108 |
private final JButton btnLocalUnCheckAllEntities;
|
|
109 |
private final JTable tblLocalChanges;
|
|
110 |
private final JButton btnLocalCheckAll;
|
|
111 |
private final JButton btnLocalUnCheckAll;
|
|
112 |
private final JButton btnLocalShowForm;
|
|
113 |
private final JButton btnLocalRefresh;
|
|
114 |
private final JButton btnLocalCommit;
|
|
115 |
private final JButton btnLocalRevert;
|
|
116 |
private final JLabel lblLocalEffectiveDate;
|
|
117 |
private final JTextField txtLocalEffectiveDate;
|
|
118 |
private final JTextField txtLocalComment;
|
|
119 |
private final JButton btnLocalEffectiveDate;
|
|
120 |
private final JLabel lblLocalComment;
|
|
121 |
private final PickerController<VCSGisWorkspace> workspacePicker;
|
|
122 |
private final VCSGisJChangesImpl context;
|
|
123 |
private final JButton btnLocalZoom;
|
|
124 |
private final JButton btnLocalCenter;
|
|
125 |
private final JButton btnLocalHighlight;
|
|
126 |
private final JLabel lblLocalChangesCount;
|
|
127 |
private final JButton btnExecuteTopologyPlan;
|
|
128 |
|
|
129 |
private VCSGisWorkspaceChanges<VCSGisWorkspaceChange> changes;
|
|
130 |
private ChangesTableModel localChangesTableModel;
|
|
131 |
private List<VCSGisWorkspaceEntity> entitiesWithSelectedChanges = null;
|
|
132 |
|
|
133 |
private DatePickerController effectiveDatePicker;
|
|
134 |
|
|
135 |
private final Set<String> entitiesToUnCheckAll;
|
|
136 |
private TableModelListener tableModelListener;
|
|
137 |
private boolean dissabledUncheckAllByEntities;
|
|
138 |
private final JButton btnLocalCleanHighlighted;
|
|
139 |
private final JTextField txtLocalTablesFilter;
|
|
140 |
private final JButton btnLocalTable;
|
|
141 |
private final JTree treeLocalTables;
|
|
142 |
private VCSGisEntitySelectorController entitySelector;
|
|
143 |
private boolean isSelectionFromEntitiesEmpty;
|
|
144 |
|
|
145 |
public LocalChangesController(
|
|
146 |
VCSGisJChangesImpl context,
|
|
147 |
PickerController<VCSGisWorkspace> workspacePicker,
|
|
148 |
JButton btnLocalCheckAllEntities,
|
|
149 |
JButton btnLocalUnCheckAllEntities,
|
|
150 |
JTable tblLocalChanges,
|
|
151 |
JButton btnLocalCheckAll,
|
|
152 |
JButton btnLocalUnCheckAll,
|
|
153 |
JButton btnLocalShowForm,
|
|
154 |
JButton btnLocalRefresh,
|
|
155 |
JButton btnLocalCommit,
|
|
156 |
JButton btnLocalRevert,
|
|
157 |
JLabel lblLocalEffectiveDate,
|
|
158 |
JTextField txtLocalEffectiveDate,
|
|
159 |
JTextField txtLocalComment,
|
|
160 |
JButton btnLocalEffectiveDate,
|
|
161 |
JLabel lblLocalComment,
|
|
162 |
JButton btnLocalZoom,
|
|
163 |
JButton btnLocalCenter,
|
|
164 |
JButton btnLocalHighlight,
|
|
165 |
JButton btnLocalCleanHighlighted,
|
|
166 |
JLabel lblLocalChangesCount,
|
|
167 |
JTextField txtLocalTablesFilter,
|
|
168 |
JButton btnLocalTable,
|
|
169 |
JTree treeLocalTables,
|
|
170 |
JButton btnExecuteTopologyPlan
|
|
171 |
) {
|
|
172 |
this.dissabledUncheckAllByEntities = false;
|
|
173 |
|
|
174 |
this.context = context;
|
|
175 |
this.workspacePicker = workspacePicker;
|
|
176 |
this.tblLocalChanges = tblLocalChanges;
|
|
177 |
this.btnLocalCheckAll = btnLocalCheckAll;
|
|
178 |
this.btnLocalCheckAllEntities = btnLocalCheckAllEntities;
|
|
179 |
this.btnLocalCommit = btnLocalCommit;
|
|
180 |
this.btnLocalEffectiveDate = btnLocalEffectiveDate;
|
|
181 |
this.btnLocalRefresh = btnLocalRefresh;
|
|
182 |
this.btnLocalRevert = btnLocalRevert;
|
|
183 |
this.btnLocalShowForm = btnLocalShowForm;
|
|
184 |
this.btnLocalUnCheckAll = btnLocalUnCheckAll;
|
|
185 |
this.btnLocalUnCheckAllEntities = btnLocalUnCheckAllEntities;
|
|
186 |
this.lblLocalComment = lblLocalComment;
|
|
187 |
this.lblLocalEffectiveDate = lblLocalEffectiveDate;
|
|
188 |
this.txtLocalComment = txtLocalComment;
|
|
189 |
this.txtLocalEffectiveDate = txtLocalEffectiveDate;
|
|
190 |
this.btnLocalZoom = btnLocalZoom;
|
|
191 |
this.btnLocalCenter = btnLocalCenter;
|
|
192 |
this.btnLocalHighlight = btnLocalHighlight;
|
|
193 |
this.btnLocalCleanHighlighted = btnLocalCleanHighlighted;
|
|
194 |
this.lblLocalChangesCount= lblLocalChangesCount;
|
|
195 |
|
|
196 |
this.txtLocalTablesFilter = txtLocalTablesFilter;
|
|
197 |
this.btnLocalTable = btnLocalTable;
|
|
198 |
this.treeLocalTables = treeLocalTables;
|
|
199 |
|
|
200 |
this.btnExecuteTopologyPlan = btnExecuteTopologyPlan;
|
|
201 |
|
|
202 |
this.entitiesToUnCheckAll = new HashSet<>();
|
|
203 |
|
|
204 |
initComponents();
|
|
205 |
}
|
|
206 |
|
|
207 |
private void initComponents() {
|
|
208 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
|
|
209 |
|
|
210 |
translate();
|
|
211 |
|
|
212 |
this.btnLocalCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
213 |
this.btnLocalUnCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
214 |
this.btnLocalCheckAll.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
215 |
this.btnLocalCommit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
216 |
this.btnLocalEffectiveDate.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
217 |
this.btnLocalRefresh.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
218 |
this.btnLocalRevert.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
219 |
this.btnLocalShowForm.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
220 |
this.btnLocalUnCheckAll.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
221 |
this.btnLocalZoom.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
222 |
this.btnLocalCenter.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
223 |
this.btnLocalHighlight.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
224 |
this.btnLocalCleanHighlighted.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
225 |
this.btnExecuteTopologyPlan.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
226 |
|
|
227 |
this.btnLocalCheckAllEntities.addActionListener((ActionEvent e) -> {
|
|
228 |
this.entitySelector.checkAll();
|
|
229 |
});
|
|
230 |
|
|
231 |
this.btnLocalUnCheckAllEntities.addActionListener((ActionEvent e) -> {
|
|
232 |
this.entitySelector.clearChecks();
|
|
233 |
});
|
|
234 |
|
|
235 |
this.entitySelector = VCSGisSwingLocator.getVCSGisSwingManager().createEntitySelectorController(
|
|
236 |
this.treeLocalTables,
|
|
237 |
txtLocalTablesFilter,
|
|
238 |
btnLocalTable
|
|
239 |
);
|
|
240 |
this.entitySelector.setViewFilter(VCSGisEntitySelectorController.LOCAL_ENTITIES);
|
|
241 |
this.entitySelector.setFilter(VCSGisEntitySelectorController.LOCAL_ENTITIES);
|
|
242 |
this.entitySelector.setChecksEnabled(true);
|
|
243 |
this.entitySelector.addChangeListener((ChangeEvent e) -> {
|
|
244 |
doUpdateTableLocalChanges();
|
|
245 |
});
|
|
246 |
this.entitySelector.addActionListener((ActionEvent e) -> {
|
|
247 |
switch(e.getID()) {
|
|
248 |
case VCSGisEntitySelectorController.ACTION_SELECT_ID:
|
|
249 |
doUpdateComponents();
|
|
250 |
break;
|
|
251 |
case VCSGisEntitySelectorController.ACTION_CHECK_ID:
|
|
252 |
doUpdateTableLocalChanges();
|
|
253 |
doUpdateComponents();
|
|
254 |
break;
|
|
255 |
case VCSGisEntitySelectorController.ACTION_RELOAD_ID:
|
|
256 |
doUpdateTableLocalChanges();
|
|
257 |
doUpdateComponents();
|
|
258 |
break;
|
|
259 |
}
|
|
260 |
});
|
|
261 |
|
|
262 |
this.tblLocalChanges.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
|
263 |
|
|
264 |
this.tblLocalChanges.addKeyListener(new KeyAdapter() {
|
|
265 |
@Override
|
|
266 |
public void keyPressed(KeyEvent e) {
|
|
267 |
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
|
268 |
doToggleSelection();
|
|
269 |
}
|
|
270 |
}
|
|
271 |
});
|
|
272 |
|
|
273 |
this.tblLocalChanges.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
|
|
274 |
doUpdateEntitiesWithSelectedChanges();
|
|
275 |
doUpdateIsSelectionFromEntitiesEmpty();
|
|
276 |
context.doUpdateComponents();
|
|
277 |
});
|
|
278 |
|
|
279 |
this.btnLocalCheckAll.addActionListener((ActionEvent e) -> {
|
|
280 |
if (changes != null) {
|
|
281 |
doCheckAll();
|
|
282 |
doUpdateTableLocalChanges();
|
|
283 |
}
|
|
284 |
});
|
|
285 |
|
|
286 |
this.btnLocalUnCheckAll.addActionListener((ActionEvent e) -> {
|
|
287 |
if (changes != null) {
|
|
288 |
doUnCheckAll();
|
|
289 |
doUpdateTableLocalChanges();
|
|
290 |
}
|
|
291 |
});
|
|
292 |
|
|
293 |
this.btnLocalShowForm.addActionListener((ActionEvent e) -> {
|
|
294 |
doShowForm();
|
|
295 |
});
|
|
296 |
|
|
297 |
this.btnLocalCommit.addActionListener((ActionEvent e) -> {
|
|
298 |
doCommit();
|
|
299 |
});
|
|
300 |
|
|
301 |
this.btnLocalRevert.addActionListener((ActionEvent e) -> {
|
|
302 |
doRevert();
|
|
303 |
});
|
|
304 |
|
|
305 |
this.effectiveDatePicker = toolsSwingManager.createDatePickerController(
|
|
306 |
this.txtLocalEffectiveDate,
|
|
307 |
this.btnLocalEffectiveDate
|
|
308 |
);
|
|
309 |
|
|
310 |
this.effectiveDatePicker.set(new Date());
|
|
311 |
|
|
312 |
this.btnLocalRefresh.addActionListener((ActionEvent e) -> {
|
|
313 |
doUpdateTableLocalChanges();
|
|
314 |
});
|
|
315 |
|
|
316 |
this.btnLocalZoom.addActionListener((ActionEvent e) -> {
|
|
317 |
doZoomToSelectedChange();
|
|
318 |
});
|
|
319 |
|
|
320 |
this.btnLocalCenter.addActionListener((ActionEvent e) -> {
|
|
321 |
doCenterToSelectedChange();
|
|
322 |
});
|
|
323 |
|
|
324 |
this.btnLocalHighlight.addActionListener((ActionEvent e) -> {
|
|
325 |
doHighLightSelectedChange();
|
|
326 |
});
|
|
327 |
|
|
328 |
this.btnLocalCleanHighlighted.addActionListener((ActionEvent e) -> {
|
|
329 |
cleanHighligthed();
|
|
330 |
});
|
|
331 |
|
|
332 |
this.btnExecuteTopologyPlan.addActionListener((ActionEvent e) -> {
|
|
333 |
doExecuteTopologyPlan();
|
|
334 |
});
|
|
335 |
|
|
336 |
toolsSwingManager.addClearButton(this.txtLocalComment);
|
|
337 |
toolsSwingManager.setDefaultPopupMenu(txtLocalComment);
|
|
338 |
|
|
339 |
context.doUpdateComponents();
|
|
340 |
}
|
|
341 |
|
|
342 |
public void doChangeWorkspace() {
|
|
343 |
VCSGisWorkspace ws = getUndisposableWorkspace();
|
|
344 |
this.entitySelector.setWorkspace(ws);
|
|
345 |
// doUpdateTableLocalChanges();
|
|
346 |
}
|
|
347 |
|
|
348 |
private void translate() {
|
|
349 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager();
|
|
350 |
|
|
351 |
swingManager.translate(this.btnLocalCheckAll);
|
|
352 |
swingManager.translate(this.btnLocalCommit);
|
|
353 |
swingManager.translate(this.btnLocalRefresh);
|
|
354 |
swingManager.translate(this.btnLocalRevert);
|
|
355 |
swingManager.translate(this.btnLocalShowForm);
|
|
356 |
swingManager.translate(this.btnLocalUnCheckAll);
|
|
357 |
|
|
358 |
swingManager.translate(this.lblLocalEffectiveDate);
|
|
359 |
swingManager.translate(this.lblLocalComment);
|
|
360 |
|
|
361 |
swingManager.translate(this.btnLocalCenter);
|
|
362 |
swingManager.translate(this.btnLocalHighlight);
|
|
363 |
swingManager.translate(this.btnLocalZoom);
|
|
364 |
swingManager.translate(this.btnLocalCleanHighlighted);
|
|
365 |
}
|
|
366 |
|
|
367 |
private Iterator<Long> getSelectionIterator() {
|
|
368 |
ListSelectionModel selection = this.tblLocalChanges.getSelectionModel();
|
|
369 |
return new Iterator<Long>() {
|
|
370 |
long n = selection.getMinSelectionIndex();
|
|
371 |
@Override
|
|
372 |
public boolean hasNext() {
|
|
373 |
while (n <= selection.getMaxSelectionIndex()){
|
|
374 |
if(selection.isSelectedIndex((int) n)){
|
|
375 |
return true;
|
|
376 |
}
|
|
377 |
n++;
|
|
378 |
}
|
|
379 |
return false;
|
|
380 |
}
|
|
381 |
|
|
382 |
@Override
|
|
383 |
public Long next() {
|
|
384 |
if(n > selection.getMaxSelectionIndex()){
|
|
385 |
throw new IllegalStateException();
|
|
386 |
}
|
|
387 |
return n++;
|
|
388 |
}
|
|
389 |
};
|
|
390 |
}
|
|
391 |
|
|
392 |
private void doToggleSelection() {
|
|
393 |
Thread task = new Thread(() -> {
|
|
394 |
try {
|
|
395 |
context.processing = true;
|
|
396 |
context.doUpdateComponents();
|
|
397 |
Iterator<Long> rows = getSelectionIterator();
|
|
398 |
|
|
399 |
this.changes.process(rows, (VCSGisWorkspaceChange change) -> {
|
|
400 |
if(change.getOperation() == OP_ADD_ENTITY) {
|
|
401 |
if(change.isSelected()){
|
|
402 |
entitiesToUnCheckAll.add(change.getEntityCode());
|
|
403 |
}
|
|
404 |
}
|
|
405 |
change.setSelected(!change.isSelected());
|
|
406 |
return true;
|
|
407 |
});
|
|
408 |
if(!entitiesToUnCheckAll.isEmpty()){
|
|
409 |
doUnCheckAllByEntities();
|
|
410 |
}
|
|
411 |
} finally {
|
|
412 |
doUpdateEntitiesWithSelectedChanges();
|
|
413 |
doUpdateIsSelectionFromEntitiesEmpty();
|
|
414 |
context.processing = false;
|
|
415 |
context.doUpdateComponents();
|
|
416 |
}
|
|
417 |
}, "VCSGisToggleSelectionLocalChanges");
|
|
418 |
task.start();
|
|
419 |
}
|
|
420 |
|
|
421 |
private Iterator<Long> getRowsByEntitiesToUnCheckIterator() {
|
|
422 |
|
|
423 |
long size = changes.size64();
|
|
424 |
TableModel model = this.tblLocalChanges.getModel();
|
|
425 |
return new Iterator<Long>() {
|
|
426 |
long n = 0;
|
|
427 |
@Override
|
|
428 |
public boolean hasNext() {
|
|
429 |
while (n < size){
|
|
430 |
VCSGisWorkspaceChange row = changes.get64(n);
|
|
431 |
if(entitiesToUnCheckAll.contains(row.getEntityCode())){
|
|
432 |
return true;
|
|
433 |
}
|
|
434 |
n++;
|
|
435 |
}
|
|
436 |
return false;
|
|
437 |
}
|
|
438 |
|
|
439 |
@Override
|
|
440 |
public Long next() {
|
|
441 |
return n++;
|
|
442 |
}
|
|
443 |
};
|
|
444 |
}
|
|
445 |
|
|
446 |
|
|
447 |
private void doUnCheckAllByEntities(){
|
|
448 |
if(dissabledUncheckAllByEntities){
|
|
449 |
return;
|
|
450 |
}
|
|
451 |
Thread task = new Thread(() -> {
|
|
452 |
try {
|
|
453 |
context.processing = true;
|
|
454 |
context.doUpdateComponents();
|
|
455 |
if(!entitiesToUnCheckAll.isEmpty()) {
|
|
456 |
Iterator<Long> rows = getRowsByEntitiesToUnCheckIterator();
|
|
457 |
this.changes.process(rows, (VCSGisWorkspaceChange change) -> {
|
|
458 |
if(change.getOperation() != OP_ADD_ENTITY) {
|
|
459 |
change.setSelected(false);
|
|
460 |
}
|
|
461 |
return true;
|
|
462 |
});
|
|
463 |
entitiesToUnCheckAll.clear();
|
|
464 |
}
|
|
465 |
} finally {
|
|
466 |
doUpdateEntitiesWithSelectedChanges();
|
|
467 |
context.processing = false;
|
|
468 |
context.doUpdateComponents();
|
|
469 |
}
|
|
470 |
}, "VCSGisUnCheckAllByEntitiesLocalChanges");
|
|
471 |
task.start();
|
|
472 |
}
|
|
473 |
|
|
474 |
private Iterator<Long> getRowsIterator() {
|
|
475 |
long size = changes.size64();
|
|
476 |
return new Iterator<Long>() {
|
|
477 |
long n = 0;
|
|
478 |
@Override
|
|
479 |
public boolean hasNext() {
|
|
480 |
return (n < size);
|
|
481 |
}
|
|
482 |
|
|
483 |
@Override
|
|
484 |
public Long next() {
|
|
485 |
return n++;
|
|
486 |
}
|
|
487 |
};
|
|
488 |
}
|
|
489 |
|
|
490 |
|
|
491 |
private void doCheckAll() {
|
|
492 |
Thread task = new Thread(() -> {
|
|
493 |
try {
|
|
494 |
context.processing = true;
|
|
495 |
dissabledUncheckAllByEntities = true;
|
|
496 |
context.doUpdateComponents();
|
|
497 |
this.changes.setSelectionAll();
|
|
498 |
} finally {
|
|
499 |
context.processing = false;
|
|
500 |
dissabledUncheckAllByEntities = false;
|
|
501 |
context.doUpdateComponents();
|
|
502 |
}
|
|
503 |
}, "VCSGisCheckAllLocalChanges");
|
|
504 |
task.start();
|
|
505 |
}
|
|
506 |
|
|
507 |
private void doUnCheckAll() {
|
|
508 |
Thread task = new Thread(() -> {
|
|
509 |
try {
|
|
510 |
context.processing = true;
|
|
511 |
dissabledUncheckAllByEntities = true;
|
|
512 |
context.doUpdateComponents();
|
|
513 |
this.changes.clearSelection();
|
|
514 |
} finally {
|
|
515 |
context.processing = false;
|
|
516 |
dissabledUncheckAllByEntities = false;
|
|
517 |
context.doUpdateComponents();
|
|
518 |
}
|
|
519 |
}, "VCSGisUncheckAllLocalChanges");
|
|
520 |
task.start();
|
|
521 |
}
|
|
522 |
|
|
523 |
private VCSGisWorkspace getUndisposableWorkspace() {
|
|
524 |
VCSGisWorkspace ws = getWorkspace();
|
|
525 |
DisposeUtils.disposeQuietly(ws);
|
|
526 |
// LOGGER.info("ws.references = " + DisposeUtils.getReferences(ws));
|
|
527 |
return ws;
|
|
528 |
}
|
|
529 |
|
|
530 |
private VCSGisWorkspace getWorkspace() {
|
|
531 |
VCSGisWorkspace ws = this.context.getWorkspace();
|
|
532 |
return ws;
|
|
533 |
}
|
|
534 |
|
|
535 |
/* friend */ void doUpdateComponents() {
|
|
536 |
if (notInSwingThreadInvokeLater(() -> {
|
|
537 |
doUpdateComponents();
|
|
538 |
})) {
|
|
539 |
return;
|
|
540 |
}
|
|
541 |
try {
|
|
542 |
this.context.setVisibleStatus(context.processing);
|
|
543 |
VCSGisWorkspace ws = getUndisposableWorkspace();
|
|
544 |
this.context.updateEntitiesFromRepository(false);
|
|
545 |
this.entitySelector.setEnabled(!context.processing);
|
|
546 |
this.effectiveDatePicker.setEnabled(!context.processing);
|
|
547 |
this.workspacePicker.setEnabled(!context.processing);
|
|
548 |
this.btnLocalCheckAll.setEnabled(!context.processing && changes != null && changes.size64() > 0);
|
|
549 |
this.btnLocalUnCheckAll.setEnabled(!context.processing && changes != null && changes.size64() > 0);
|
|
550 |
List<VCSGisEntity> checkedEntities = entitySelector.getCheckedEntities();
|
|
551 |
this.btnLocalRefresh.setEnabled(!context.processing && changes != null && CollectionUtils.isNotEmpty(checkedEntities));
|
|
552 |
this.btnLocalRevert.setEnabled(ws != null
|
|
553 |
&& !context.processing
|
|
554 |
&& changes != null
|
|
555 |
&& changes.size64() > 0
|
|
556 |
&& CollectionUtils.isNotEmpty(checkedEntities)
|
|
557 |
&& entitiesWithSelectedChanges != null
|
|
558 |
&& !entitiesWithSelectedChanges.isEmpty()
|
|
559 |
&& !isSelectionFromEntitiesEmpty
|
|
560 |
);
|
|
561 |
this.btnLocalRevert.setVisible(true);
|
|
562 |
this.btnLocalCommit.setEnabled(ws != null
|
|
563 |
&& !context.processing
|
|
564 |
&& changes != null
|
|
565 |
&& !this.changes.isSelectionEmpty()
|
|
566 |
&& CollectionUtils.isNotEmpty(checkedEntities)
|
|
567 |
&& entitiesWithSelectedChanges != null
|
|
568 |
&& !entitiesWithSelectedChanges.isEmpty()
|
|
569 |
&& !isSelectionFromEntitiesEmpty
|
|
570 |
&& ws.canCommit(null, getEntityCodes(checkedEntities))
|
|
571 |
);
|
|
572 |
//Show form
|
|
573 |
boolean enableShowForm = false;
|
|
574 |
|
|
575 |
int row = this.tblLocalChanges.getSelectedRow();
|
|
576 |
if (!context.processing && row >= 0) {
|
|
577 |
VCSGisWorkspaceChange change = this.changes.get64(row);
|
|
578 |
if (change.getOperation() != OP_ADD_ENTITY) {
|
|
579 |
enableShowForm = true;
|
|
580 |
}
|
|
581 |
}
|
|
582 |
this.btnLocalShowForm.setEnabled(!context.processing && enableShowForm);
|
|
583 |
|
|
584 |
this.tblLocalChanges.setEnabled(!context.processing);
|
|
585 |
this.txtLocalComment.setEnabled(!context.processing);
|
|
586 |
this.effectiveDatePicker.setEnabled(!context.processing);
|
|
587 |
this.workspacePicker.setEnabled(!context.processing);
|
|
588 |
|
|
589 |
Geometry geom = getGeometryOfSelectedChange();
|
|
590 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange();
|
|
591 |
this.btnLocalCenter.setEnabled(!context.processing && (geom != null || originalGeom != null));
|
|
592 |
this.btnLocalHighlight.setEnabled(!context.processing && (geom != null || originalGeom != null));
|
|
593 |
this.btnLocalZoom.setEnabled(!context.processing && (geom != null || originalGeom != null));
|
|
594 |
this.btnLocalCleanHighlighted.setEnabled(!context.processing);
|
|
595 |
VCSGisEntity selectedEntity = entitySelector.getSelectedEntity();
|
|
596 |
this.btnExecuteTopologyPlan.setEnabled(
|
|
597 |
!context.processing
|
|
598 |
&& selectedEntity != null
|
|
599 |
&& StringUtils.isNotBlank(selectedEntity.getTopologyPlanCode()));
|
|
600 |
} catch (VCSGisRuntimeException e1) {
|
|
601 |
LOGGER.warn("Can't updating components.", e1);
|
|
602 |
if (showAuthenticationErrors("_VCS_Changes", e1)) {
|
|
603 |
this.workspacePicker.set(null);
|
|
604 |
doChangeWorkspace();
|
|
605 |
}
|
|
606 |
} catch (Exception e2) {
|
|
607 |
LOGGER.warn("Can't updating components.", e2);
|
|
608 |
}
|
|
609 |
|
|
610 |
}
|
|
611 |
|
|
612 |
public void doReloadTables() {
|
|
613 |
this.entitySelector.reloadEntities();
|
|
614 |
}
|
|
615 |
|
|
616 |
public void doUpdateEntitiesWithSelectedChanges() {
|
|
617 |
VCSGisWorkspace ws = this.getUndisposableWorkspace();
|
|
618 |
if (ws != null) {
|
|
619 |
entitiesWithSelectedChanges = ws.getEntitiesWithSelectedChanges();
|
|
620 |
}
|
|
621 |
}
|
|
622 |
|
|
623 |
private void doUpdateIsSelectionFromEntitiesEmpty() {
|
|
624 |
VCSGisWorkspace ws = this.getUndisposableWorkspace();
|
|
625 |
if (ws != null) {
|
|
626 |
List<VCSGisEntity> checkedEntities = entitySelector.getCheckedEntities();
|
|
627 |
this.isSelectionFromEntitiesEmpty = changes.isSelectionFromEntitiesEmpty(checkedEntities);
|
|
628 |
}
|
|
629 |
}
|
|
630 |
|
|
631 |
|
|
632 |
public void doUpdateTableLocalChanges() {
|
|
633 |
if( context.processing ) {
|
|
634 |
return;
|
|
635 |
}
|
|
636 |
I18nManager i18n = ToolsLocator.getI18nManager();
|
|
637 |
VCSGisWorkspace ws = this.getUndisposableWorkspace();
|
|
638 |
|
|
639 |
if(ws != null){
|
|
640 |
|
|
641 |
doUpdateEntitiesWithSelectedChanges();
|
|
642 |
|
|
643 |
List<VCSGisEntity> checkedEntities = entitySelector.getCheckedEntities();
|
|
644 |
if(CollectionUtils.isEmpty(checkedEntities)) {
|
|
645 |
localChangesTableModel = new ChangesTableModel(ws);
|
|
646 |
this.tblLocalChanges.setModel(localChangesTableModel);
|
|
647 |
return;
|
|
648 |
}
|
|
649 |
|
|
650 |
changes = ws.getLocalChanges(checkedEntities);
|
|
651 |
|
|
652 |
localChangesTableModel = new ChangesTableModel(changes, ws);
|
|
653 |
this.tblLocalChanges.setModel(localChangesTableModel);
|
|
654 |
|
|
655 |
int columns = this.tblLocalChanges.getColumnModel().getColumnCount();
|
|
656 |
for (int i = 1; i < columns; i++) {
|
|
657 |
this.tblLocalChanges.getColumnModel().getColumn(i).setCellRenderer(new DefaultTableCellRenderer() {
|
|
658 |
@Override
|
|
659 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
660 |
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
|
661 |
VCSGisChange changeRow = changes.get64(row);
|
|
662 |
VCSGisSwingCommons.setColorCompoment(c, changeRow.getStatus());
|
|
663 |
return c;
|
|
664 |
}
|
|
665 |
});
|
|
666 |
}
|
|
667 |
this.tableModelListener = null;
|
|
668 |
localChangesTableModel.addTableModelListener(getTableModelListener());
|
|
669 |
context.message(i18n.getTranslation(
|
|
670 |
"_Workingcopy_changes_list_updated",
|
|
671 |
new String[]{String.valueOf(changes.size64())}
|
|
672 |
)
|
|
673 |
);
|
|
674 |
this.lblLocalChangesCount.setText(String.valueOf(changes.size64()));
|
|
675 |
}
|
|
676 |
doUpdateIsSelectionFromEntitiesEmpty();
|
|
677 |
context.doUpdateComponents();
|
|
678 |
}
|
|
679 |
|
|
680 |
private TableModelListener getTableModelListener() {
|
|
681 |
if(tableModelListener == null){
|
|
682 |
tableModelListener = (TableModelEvent e) -> {
|
|
683 |
if (e.getType() == TableModelEvent.UPDATE) {
|
|
684 |
TableModel model = ((TableModel) (e.getSource()));
|
|
685 |
VCSGisWorkspaceChange change = changes.get64(e.getFirstRow());
|
|
686 |
if(change.getOperation() == OP_ADD_ENTITY) {
|
|
687 |
if(!change.isSelected()) {
|
|
688 |
if (entitiesToUnCheckAll.add(change.getEntityCode())) {
|
|
689 |
doUnCheckAllByEntities();
|
|
690 |
}
|
|
691 |
}
|
|
692 |
}
|
|
693 |
}
|
|
694 |
};
|
|
695 |
}
|
|
696 |
return tableModelListener;
|
|
697 |
}
|
|
698 |
|
|
699 |
private void doShowForm() {
|
|
700 |
|
|
701 |
int row = this.tblLocalChanges.getSelectedRow();
|
|
702 |
VCSGisWorkspaceChange change = this.changes.get64(row);
|
|
703 |
if(change.getOperation() == OP_DELETE || change.getOperation() == OP_ADD_ENTITY){
|
|
704 |
return;
|
|
705 |
}
|
|
706 |
Feature feature = change.getRelatedFeature();
|
|
707 |
if(feature == null){
|
|
708 |
return;
|
|
709 |
}
|
|
710 |
try {
|
|
711 |
DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
|
|
712 |
JFeatureForm form;
|
|
713 |
form = dataSwingManager.createJFeatureForm(feature);
|
|
714 |
WindowManager winManager = ToolsSwingLocator.getWindowManager();
|
|
715 |
form.asJComponent().setPreferredSize(new Dimension(400,200));
|
|
716 |
winManager.showWindow(form.asJComponent(), "Local change: "+change.getLabel(), WindowManager.MODE.WINDOW);
|
|
717 |
} catch (CreateJFeatureFormException ex) {
|
|
718 |
LOGGER.warn("Can't show form", ex);
|
|
719 |
}
|
|
720 |
|
|
721 |
}
|
|
722 |
|
|
723 |
private void doCommit() {
|
|
724 |
I18nManager i18n = ToolsLocator.getI18nManager();
|
|
725 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
|
|
726 |
|
|
727 |
VCSGisWorkspace ws = getUndisposableWorkspace();
|
|
728 |
if( ws==null ) {
|
|
729 |
// TODO: Mensaje al usuario ??
|
|
730 |
return;
|
|
731 |
}
|
|
732 |
List<VCSGisEntity> entities = entitySelector.getCheckedEntities();
|
|
733 |
List<String> entityCodes = getEntityCodes(entities);
|
|
734 |
if( CollectionUtils.isEmpty(entities)){
|
|
735 |
// TODO: Mensaje al usuario ??
|
|
736 |
return;
|
|
737 |
}
|
|
738 |
this.context.updateEntitiesFromRepository(false);
|
|
739 |
MutableObject<String> message = new MutableObject<>();
|
|
740 |
if( !ws.canCommit(message, entityCodes) ) {
|
|
741 |
dialogs.messageDialog(
|
|
742 |
i18n.getTranslation("_Cant_commit") + "\n" + message.getValue(),
|
|
743 |
i18n.getTranslation("_Commit"),
|
|
744 |
JOptionPane.WARNING_MESSAGE
|
|
745 |
);
|
|
746 |
return;
|
|
747 |
}
|
|
748 |
Timestamp effectiveDate = new Timestamp(effectiveDatePicker.get().getTime());
|
|
749 |
this.tblLocalChanges.setModel(new ChangesTableModel(ws));
|
|
750 |
|
|
751 |
List<VCSGisTopologyPlanStatus> topologicPlanStatusList = new ArrayList<>();
|
|
752 |
|
|
753 |
Thread task = new Thread(() -> {
|
|
754 |
try {
|
|
755 |
context.processing = true;
|
|
756 |
context.doUpdateComponents();
|
|
757 |
if(!existsAllTopologyPlansLocally(ws, entities)) {
|
|
758 |
ws.updateTopologyPlansFromRepository(null);
|
|
759 |
}
|
|
760 |
if( !executeTopologyPlans(ws, entities, topologicPlanStatusList) ) {
|
|
761 |
dialogs.messageDialog(
|
|
762 |
i18n.getTranslation("_Cant_pass_topology_plans"),
|
|
763 |
i18n.getTranslation("_Commit"),
|
|
764 |
JOptionPane.WARNING_MESSAGE
|
|
765 |
);
|
|
766 |
return;
|
|
767 |
}
|
|
768 |
int r = ws.commit(
|
|
769 |
entityCodes,
|
|
770 |
null,
|
|
771 |
effectiveDate,
|
|
772 |
this.txtLocalComment.getText(),
|
|
773 |
this.context.getTaskStatusController().getSimpleTaskStatus(),
|
|
774 |
topologicPlanStatusList
|
|
775 |
);
|
|
776 |
if(r==VCSGisManager.ERR_TOPOLOGYPLAN_OUTDATED){
|
|
777 |
ws.updateTopologyPlansFromRepository(null);
|
|
778 |
}
|
|
779 |
doPostCommit(r);
|
|
780 |
} finally {
|
|
781 |
context.processing = false;
|
|
782 |
context.doUpdateComponents();
|
|
783 |
}
|
|
784 |
}, "VCSGisCommit");
|
|
785 |
|
|
786 |
context.processing = true;
|
|
787 |
context.doUpdateComponents();
|
|
788 |
task.start();
|
|
789 |
}
|
|
790 |
|
|
791 |
private boolean executeTopologyPlans(VCSGisWorkspace ws, List<VCSGisEntity> entities,
|
|
792 |
List<VCSGisTopologyPlanStatus> topologicPlanStatus) {
|
|
793 |
boolean hasTopologyPlans = false;
|
|
794 |
for (VCSGisEntity entity : entities) {
|
|
795 |
VCSGisTopologyPlan topologyPlan = ws.getTopologyPlan(entity.getTopologyPlanCode());
|
|
796 |
if( topologyPlan != null && StringUtils.isNotBlank(topologyPlan.getData()) ) {
|
|
797 |
hasTopologyPlans= true;
|
|
798 |
break;
|
|
799 |
}
|
|
800 |
}
|
|
801 |
if (!hasTopologyPlans){
|
|
802 |
return true;
|
|
803 |
}
|
|
804 |
try {
|
|
805 |
TopologyPlansExecutor executor = new TopologyPlansExecutor();
|
|
806 |
return executor.execute(ws, entities, topologicPlanStatus, true);
|
|
807 |
}catch(Exception ex){
|
|
808 |
return false;
|
|
809 |
}
|
|
810 |
}
|
|
811 |
|
|
812 |
private void doPostCommit(int commitStatus) {
|
|
813 |
if (notInSwingThreadInvokeLater(() -> {doPostCommit(commitStatus);})) {
|
|
814 |
return;
|
|
815 |
}
|
|
816 |
switch (commitStatus) {
|
|
817 |
case ERR_OK:
|
|
818 |
this.context.setVisibleStatus(false);
|
|
819 |
break;
|
|
820 |
case VCSGisManager.ERR_TOPOLOGYPLAN_OUTDATED:
|
|
821 |
I18nManager i18n = ToolsLocator.getI18nManager();
|
|
822 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
|
|
823 |
dialogs.messageDialog(
|
|
824 |
i18n.getTranslation("_TopologyPlan_has_been_updated_please_retry_commit"),
|
|
825 |
i18n.getTranslation("_VCS_Commit"),
|
|
826 |
JOptionPane.WARNING_MESSAGE
|
|
827 |
);
|
|
828 |
break;
|
|
829 |
default:
|
|
830 |
showAuthenticationErrors("_VCS_Commit", commitStatus);
|
|
831 |
break;
|
|
832 |
}
|
|
833 |
this.entitySelector.reloadEntities();
|
|
834 |
context.updateLocalChangesTable();
|
|
835 |
cleanHighligthed();
|
|
836 |
}
|
|
837 |
|
|
838 |
private void doRevert() {
|
|
839 |
VCSGisWorkspace ws = getUndisposableWorkspace();
|
|
840 |
if( ws==null ) {
|
|
841 |
// TODO: Mensaje al usuario
|
|
842 |
return;
|
|
843 |
}
|
|
844 |
this.context.updateEntitiesFromRepository(false);
|
|
845 |
|
|
846 |
Thread task = new Thread(() -> {
|
|
847 |
try {
|
|
848 |
context.processing = true;
|
|
849 |
context.doUpdateComponents();
|
|
850 |
List<VCSGisWorkspaceEntity> entities = ws.getEntitiesWithSelectedChanges();
|
|
851 |
List<String> selectedEntityCodes = getEntityCodes(entitySelector.getCheckedEntities());
|
|
852 |
int r = ERR_OK;
|
|
853 |
if(!entities.isEmpty() && CollectionUtils.isNotEmpty(selectedEntityCodes)){
|
|
854 |
for (VCSGisWorkspaceEntity entity : entities) {
|
|
855 |
if(selectedEntityCodes.contains(entity.getEntityCode())){
|
|
856 |
r = ws.revert(entity.getEntityCode(),
|
|
857 |
this.context.getTaskStatusController().getSimpleTaskStatus()
|
|
858 |
);
|
|
859 |
}
|
|
860 |
if(r != ERR_OK){
|
|
861 |
break;
|
|
862 |
}
|
|
863 |
}
|
|
864 |
}
|
|
865 |
doPostRevert(r, entities);
|
|
866 |
} finally {
|
|
867 |
context.processing = false;
|
|
868 |
context.doUpdateComponents();
|
|
869 |
}
|
|
870 |
}, "VCSGisRevert");
|
|
871 |
|
|
872 |
context.processing = true;
|
|
873 |
context.doUpdateComponents();
|
|
874 |
task.start();
|
|
875 |
}
|
|
876 |
|
|
877 |
private void doPostRevert(int revertStatus, List<VCSGisWorkspaceEntity> entities) {
|
|
878 |
if (notInSwingThreadInvokeLater(() -> {doPostRevert(revertStatus, entities);})) {
|
|
879 |
return;
|
|
880 |
}
|
|
881 |
if( revertStatus == ERR_OK) {
|
|
882 |
this.context.setVisibleStatus(false);
|
|
883 |
}
|
|
884 |
for (VCSGisWorkspaceEntity entity : entities) {
|
|
885 |
FeatureStore store = getUndisposableWorkspace().getFeatureStore(entity.getEntityName());
|
|
886 |
refreshDocument(store);
|
|
887 |
}
|
|
888 |
context.updateLocalChangesTable();
|
|
889 |
cleanHighligthed();
|
|
890 |
|
|
891 |
}
|
|
892 |
|
|
893 |
private Geometry getGeometryOfSelectedChange() {
|
|
894 |
Geometry geom = null;
|
|
895 |
int selected = this.tblLocalChanges.getSelectedRow();
|
|
896 |
if(selected >= 0){
|
|
897 |
VCSGisWorkspaceChange change = changes.get64(selected);
|
|
898 |
try {
|
|
899 |
Feature feature = change.getRelatedFeature();
|
|
900 |
geom = feature.getDefaultGeometry();
|
|
901 |
} catch (Exception ex){
|
|
902 |
|
|
903 |
}
|
|
904 |
}
|
|
905 |
return geom;
|
|
906 |
}
|
|
907 |
|
|
908 |
private Geometry getOriginalGeometryOfSelectedChange() {
|
|
909 |
Geometry geom = null;
|
|
910 |
int selected = this.tblLocalChanges.getSelectedRow();
|
|
911 |
if(selected >= 0){
|
|
912 |
VCSGisWorkspaceChange change = changes.get64(selected);
|
|
913 |
try {
|
|
914 |
VCSGisWorkspace ws = getUndisposableWorkspace();
|
|
915 |
if(ws!=null) {
|
|
916 |
JsonObject json = change.getDataAsJson();
|
|
917 |
String entityCode = change.getEntityCode();
|
|
918 |
VCSGisEntity entity = ws.getEntity(entityCode);
|
|
919 |
FeatureStore store = ws.getFeatureStore(entity.getEntityName());
|
|
920 |
Feature feature = store.createNewFeature(json);
|
|
921 |
geom = feature.getDefaultGeometry();
|
|
922 |
}
|
|
923 |
} catch (Exception ex){
|
|
924 |
|
|
925 |
}
|
|
926 |
}
|
|
927 |
return geom;
|
|
928 |
}
|
|
929 |
|
|
930 |
private FeatureStore getStoreOfSelectedChange() {
|
|
931 |
FeatureStore store = null;
|
|
932 |
int selected = this.tblLocalChanges.getSelectedRow();
|
|
933 |
if(selected >= 0){
|
|
934 |
VCSGisWorkspaceChange change = changes.get64(selected);
|
|
935 |
try {
|
|
936 |
VCSGisWorkspace ws = getUndisposableWorkspace();
|
|
937 |
if(ws!=null) {
|
|
938 |
String entityCode = change.getEntityCode();
|
|
939 |
VCSGisEntity entity = ws.getEntity(entityCode);
|
|
940 |
store = ws.getFeatureStore(entity.getEntityName());
|
|
941 |
}
|
|
942 |
} catch (Exception ex){
|
|
943 |
|
|
944 |
}
|
|
945 |
}
|
|
946 |
return store;
|
|
947 |
}
|
|
948 |
|
|
949 |
private void doZoomToSelectedChange() {
|
|
950 |
cleanHighligthed();
|
|
951 |
VCSGisManager manager = VCSGisLocator.getVCSGisManager();
|
|
952 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager();
|
|
953 |
VCSGisSwingServices services =swingManager.getDefaultServices();
|
|
954 |
FeatureStore store = getStoreOfSelectedChange();
|
|
955 |
Geometry geom = getGeometryOfSelectedChange();
|
|
956 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange();
|
|
957 |
services.zoomViewsHavingAStoreToGeometry(store, VCSGisSwingCommons.createBBox(geom, originalGeom));
|
|
958 |
if(geom != null){
|
|
959 |
services.highlight(HIGHLIGHT_WORKSPACE, geom, store);
|
|
960 |
}
|
|
961 |
if(originalGeom != null){
|
|
962 |
services.highlight(HIGHLIGHT_WORKSPACE_PREVIOUS, originalGeom, store);
|
|
963 |
}
|
|
964 |
}
|
|
965 |
|
|
966 |
private void doCenterToSelectedChange() {
|
|
967 |
cleanHighligthed();
|
|
968 |
VCSGisManager manager = VCSGisLocator.getVCSGisManager();
|
|
969 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager();
|
|
970 |
VCSGisSwingServices services =swingManager.getDefaultServices();
|
|
971 |
FeatureStore store = getStoreOfSelectedChange();
|
|
972 |
Geometry geom = getGeometryOfSelectedChange();
|
|
973 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange();
|
|
974 |
services.centerViewsHavingAStoreToGeometry(store, VCSGisSwingCommons.createBBox(geom, originalGeom));
|
|
975 |
if(geom != null){
|
|
976 |
services.highlight(HIGHLIGHT_WORKSPACE, geom, store);
|
|
977 |
}
|
|
978 |
if(originalGeom != null){
|
|
979 |
services.highlight(HIGHLIGHT_WORKSPACE_PREVIOUS, originalGeom, store);
|
|
980 |
}
|
|
981 |
|
|
982 |
}
|
|
983 |
|
|
984 |
private void doHighLightSelectedChange() {
|
|
985 |
cleanHighligthed();
|
|
986 |
VCSGisManager manager = VCSGisLocator.getVCSGisManager();
|
|
987 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager();
|
|
988 |
VCSGisSwingServices services =swingManager.getDefaultServices();
|
|
989 |
FeatureStore store = getStoreOfSelectedChange();
|
|
990 |
Geometry geom = getGeometryOfSelectedChange();
|
|
991 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange();
|
|
992 |
if(geom != null){
|
|
993 |
services.highlight(HIGHLIGHT_WORKSPACE, geom, store);
|
|
994 |
}
|
|
995 |
if(originalGeom != null){
|
|
996 |
services.highlight(HIGHLIGHT_WORKSPACE_PREVIOUS, originalGeom, store);
|
|
997 |
}
|
|
998 |
|
|
999 |
}
|
|
1000 |
|
|
1001 |
private void doExecuteTopologyPlan() {
|
|
1002 |
VCSGisWorkspace ws = getUndisposableWorkspace();
|
|
1003 |
if(ws == null){
|
|
1004 |
return;
|
|
1005 |
}
|
|
1006 |
List<VCSGisTopologyPlanStatus> topologicPlanStatusList = new ArrayList<>();
|
|
1007 |
VCSGisEntity entity = entitySelector.getSelectedEntity();
|
|
1008 |
List<VCSGisEntity> entities = new ArrayList();
|
|
1009 |
entities.add(entity);
|
|
1010 |
|
|
1011 |
Thread task = new Thread(() -> {
|
|
1012 |
try {
|
|
1013 |
context.processing = true;
|
|
1014 |
context.doUpdateComponents();
|
|
1015 |
|
|
1016 |
if (entity != null) {
|
|
1017 |
entities.add(entity);
|
|
1018 |
try {
|
|
1019 |
TopologyPlansExecutor executor = new TopologyPlansExecutor();
|
|
1020 |
executor.execute(ws, entities, topologicPlanStatusList, false);
|
|
1021 |
} catch (Exception ex) {
|
|
1022 |
// return false;
|
|
1023 |
}
|
|
1024 |
}
|
|
1025 |
} finally {
|
|
1026 |
context.processing = false;
|
|
1027 |
context.doUpdateComponents();
|
|
1028 |
}
|
|
1029 |
}, "VCSGisTopologyplan");
|
|
1030 |
|
|
1031 |
context.processing = true;
|
|
1032 |
context.doUpdateComponents();
|
|
1033 |
task.start();
|
|
1034 |
|
|
1035 |
}
|
|
1036 |
|
|
1037 |
private List<String> getEntityCodes(List<VCSGisEntity> entities) {
|
|
1038 |
List<String> res = new ArrayList();
|
|
1039 |
for (VCSGisEntity entity : entities) {
|
|
1040 |
res.add(entity.getEntityCode());
|
|
1041 |
}
|
|
1042 |
return res;
|
|
1043 |
}
|
|
1044 |
|
|
1045 |
public void selectOnlyAEntity(VCSGisEntity entity){
|
|
1046 |
entitySelector.clearChecks();
|
|
1047 |
entitySelector.check(entity);
|
|
1048 |
}
|
|
1049 |
|
|
1050 |
private boolean existsAllTopologyPlansLocally(VCSGisWorkspace ws, List<VCSGisEntity> entities) {
|
|
1051 |
for (VCSGisEntity entity : entities) {
|
|
1052 |
String topologyPlanCode = entity.getTopologyPlanCode();
|
|
1053 |
if (StringUtils.isBlank(topologyPlanCode)) {
|
|
1054 |
continue;
|
|
1055 |
}
|
|
1056 |
|
|
1057 |
VCSGisTopologyPlan topologyPlan = ws.getTopologyPlan(topologyPlanCode);
|
|
1058 |
|
|
1059 |
if( topologyPlan == null || StringUtils.isBlank(topologyPlan.getData()) ) {
|
|
1060 |
return false;
|
|
1061 |
}
|
|
1062 |
}
|
|
1063 |
return true;
|
|
1064 |
}
|
|
1065 |
|
|
1066 |
@Override
|
|
1067 |
protected void doDispose() throws BaseException {
|
|
1068 |
DisposeUtils.disposeQuietly(entitySelector);
|
|
1069 |
}
|
|
1070 |
}
|