gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.swing / org.gvsig.vcsgis.swing.impl / src / main / java / org / gvsig / vcsgis / swing / impl / changes / LocalChangesController.java @ 3459
History | View | Annotate | Download (35.2 KB)
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.i18n.I18nManager; |
63 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
64 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
65 |
import org.gvsig.tools.swing.api.pickercontroller.DatePickerController; |
66 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
67 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
68 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
69 |
import org.gvsig.vcsgis.lib.VCSGisChange; |
70 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
71 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
72 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
73 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK; |
74 |
import static org.gvsig.vcsgis.lib.VCSGisManager.OP_ADD_ENTITY; |
75 |
import static org.gvsig.vcsgis.lib.VCSGisManager.OP_DELETE; |
76 |
import org.gvsig.vcsgis.lib.VCSGisRuntimeException; |
77 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
78 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceChange; |
79 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceChanges; |
80 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
81 |
import org.gvsig.vcsgis.swing.VCSGisSwingLocator; |
82 |
import org.gvsig.vcsgis.swing.VCSGisSwingManager; |
83 |
import org.gvsig.vcsgis.swing.VCSGisSwingServices; |
84 |
import static org.gvsig.vcsgis.swing.VCSGisSwingServices.HIGHLIGHT_WORKSPACE; |
85 |
import static org.gvsig.vcsgis.swing.VCSGisSwingServices.HIGHLIGHT_WORKSPACE_PREVIOUS; |
86 |
import org.gvsig.vcsgis.swing.impl.VCSGisEntitySelectorController; |
87 |
import org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons; |
88 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.cleanHighligthed; |
89 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.notInSwingThreadInvokeLater; |
90 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.refreshDocument; |
91 |
import org.slf4j.Logger; |
92 |
import org.slf4j.LoggerFactory; |
93 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationErrors; |
94 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationErrors; |
95 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationErrors; |
96 |
|
97 |
/**
|
98 |
*
|
99 |
* @author gvSIG Team
|
100 |
*/
|
101 |
public class LocalChangesController { |
102 |
private static final Logger LOGGER = LoggerFactory.getLogger(LocalChangesController.class); |
103 |
|
104 |
private final JButton btnLocalCheckAllEntities; |
105 |
private final JButton btnLocalUnCheckAllEntities; |
106 |
private final JTable tblLocalChanges; |
107 |
private final JButton btnLocalCheckAll; |
108 |
private final JButton btnLocalUnCheckAll; |
109 |
private final JButton btnLocalShowForm; |
110 |
private final JButton btnLocalRefresh; |
111 |
private final JButton btnLocalCommit; |
112 |
private final JButton btnLocalRevert; |
113 |
private final JLabel lblLocalEffectiveDate; |
114 |
private final JTextField txtLocalEffectiveDate; |
115 |
private final JTextField txtLocalComment; |
116 |
private final JButton btnLocalEffectiveDate; |
117 |
private final JLabel lblLocalComment; |
118 |
private final PickerController<VCSGisWorkspace> workspacePicker; |
119 |
private final VCSGisJChangesImpl context; |
120 |
private final JButton btnLocalZoom; |
121 |
private final JButton btnLocalCenter; |
122 |
private final JLabel lblLocalChangesCount; |
123 |
|
124 |
private VCSGisWorkspaceChanges<VCSGisWorkspaceChange> changes;
|
125 |
private ChangesTableModel localChangesTableModel;
|
126 |
private List<VCSGisWorkspaceEntity> entitiesWithChanges = null; |
127 |
|
128 |
private DatePickerController effectiveDatePicker;
|
129 |
|
130 |
private final Set<String> entitiesToUnCheckAll; |
131 |
private TableModelListener tableModelListener; |
132 |
private boolean dissabledUncheckAllByEntities; |
133 |
private final JButton btnLocalCleanHighlighted; |
134 |
private final JTextField txtLocalTablesFilter; |
135 |
private final JButton btnLocalTable; |
136 |
private final JTree treeLocalTables; |
137 |
private VCSGisEntitySelectorController entitySelector;
|
138 |
|
139 |
public LocalChangesController(
|
140 |
VCSGisJChangesImpl context, |
141 |
PickerController<VCSGisWorkspace> workspacePicker, |
142 |
JButton btnLocalCheckAllEntities,
|
143 |
JButton btnLocalUnCheckAllEntities,
|
144 |
JTable tblLocalChanges,
|
145 |
JButton btnLocalCheckAll,
|
146 |
JButton btnLocalUnCheckAll,
|
147 |
JButton btnLocalShowForm,
|
148 |
JButton btnLocalRefresh,
|
149 |
JButton btnLocalCommit,
|
150 |
JButton btnLocalRevert,
|
151 |
JLabel lblLocalEffectiveDate,
|
152 |
JTextField txtLocalEffectiveDate,
|
153 |
JTextField txtLocalComment,
|
154 |
JButton btnLocalEffectiveDate,
|
155 |
JLabel lblLocalComment,
|
156 |
JButton btnLocalZoom,
|
157 |
JButton btnLocalCenter,
|
158 |
JButton btnLocalCleanHighlighted,
|
159 |
JLabel lblLocalChangesCount,
|
160 |
JTextField txtLocalTablesFilter,
|
161 |
JButton btnLocalTable,
|
162 |
JTree treeLocalTables
|
163 |
) { |
164 |
this.dissabledUncheckAllByEntities = false; |
165 |
|
166 |
this.context = context;
|
167 |
this.workspacePicker = workspacePicker;
|
168 |
this.tblLocalChanges = tblLocalChanges;
|
169 |
this.btnLocalCheckAll = btnLocalCheckAll;
|
170 |
this.btnLocalCheckAllEntities = btnLocalCheckAllEntities;
|
171 |
this.btnLocalCommit = btnLocalCommit;
|
172 |
this.btnLocalEffectiveDate = btnLocalEffectiveDate;
|
173 |
this.btnLocalRefresh = btnLocalRefresh;
|
174 |
this.btnLocalRevert = btnLocalRevert;
|
175 |
this.btnLocalShowForm = btnLocalShowForm;
|
176 |
this.btnLocalUnCheckAll = btnLocalUnCheckAll;
|
177 |
this.btnLocalUnCheckAllEntities = btnLocalUnCheckAllEntities;
|
178 |
this.lblLocalComment = lblLocalComment;
|
179 |
this.lblLocalEffectiveDate = lblLocalEffectiveDate;
|
180 |
this.txtLocalComment = txtLocalComment;
|
181 |
this.txtLocalEffectiveDate = txtLocalEffectiveDate;
|
182 |
this.btnLocalZoom = btnLocalZoom;
|
183 |
this.btnLocalCenter = btnLocalCenter;
|
184 |
this.btnLocalCleanHighlighted = btnLocalCleanHighlighted;
|
185 |
this.lblLocalChangesCount= lblLocalChangesCount;
|
186 |
|
187 |
this.txtLocalTablesFilter = txtLocalTablesFilter;
|
188 |
this.btnLocalTable = btnLocalTable;
|
189 |
this.treeLocalTables = treeLocalTables;
|
190 |
|
191 |
this.entitiesToUnCheckAll = new HashSet<>(); |
192 |
|
193 |
initComponents(); |
194 |
} |
195 |
|
196 |
private void initComponents() { |
197 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
198 |
|
199 |
translate(); |
200 |
|
201 |
this.btnLocalCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
202 |
this.btnLocalUnCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
203 |
this.btnLocalCheckAll.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
204 |
this.btnLocalCommit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
205 |
this.btnLocalEffectiveDate.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
206 |
this.btnLocalRefresh.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
207 |
this.btnLocalRevert.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
208 |
this.btnLocalShowForm.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
209 |
this.btnLocalUnCheckAll.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
210 |
this.btnLocalZoom.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
211 |
this.btnLocalCenter.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
212 |
this.btnLocalCleanHighlighted.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
213 |
|
214 |
this.btnLocalCheckAllEntities.addActionListener((ActionEvent e) -> { |
215 |
this.entitySelector.checkAll();
|
216 |
}); |
217 |
|
218 |
this.btnLocalUnCheckAllEntities.addActionListener((ActionEvent e) -> { |
219 |
this.entitySelector.clearChecks();
|
220 |
}); |
221 |
|
222 |
this.entitySelector = VCSGisEntitySelectorController.create(
|
223 |
this.treeLocalTables,
|
224 |
txtLocalTablesFilter, |
225 |
btnLocalTable |
226 |
); |
227 |
this.entitySelector.setViewFilter(VCSGisEntitySelectorController.LOCAL_ENTITIES);
|
228 |
this.entitySelector.setFilter(VCSGisEntitySelectorController.LOCAL_ENTITIES);
|
229 |
this.entitySelector.setChecksEnabled(true); |
230 |
this.entitySelector.addChangeListener((ChangeEvent e) -> { |
231 |
doUpdateTableLocalChanges(); |
232 |
// doUpdateComponents();
|
233 |
}); |
234 |
this.entitySelector.addActionListener((ActionEvent e) -> { |
235 |
switch(e.getID()) {
|
236 |
case VCSGisEntitySelectorController.ACTION_SELECT_ID:
|
237 |
break;
|
238 |
case VCSGisEntitySelectorController.ACTION_CHECK_ID:
|
239 |
doUpdateTableLocalChanges(); |
240 |
doUpdateComponents(); |
241 |
break;
|
242 |
} |
243 |
}); |
244 |
|
245 |
this.tblLocalChanges.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
246 |
|
247 |
this.tblLocalChanges.addKeyListener(new KeyAdapter() { |
248 |
@Override
|
249 |
public void keyPressed(KeyEvent e) { |
250 |
if (e.getKeyCode() == KeyEvent.VK_SPACE) { |
251 |
doToggleSelection(); |
252 |
} |
253 |
} |
254 |
}); |
255 |
|
256 |
this.tblLocalChanges.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { |
257 |
context.doUpdateComponents(); |
258 |
}); |
259 |
|
260 |
this.btnLocalCheckAll.addActionListener((ActionEvent e) -> { |
261 |
if (changes != null) { |
262 |
doCheckAll(); |
263 |
doUpdateTableLocalChanges(); |
264 |
} |
265 |
}); |
266 |
|
267 |
this.btnLocalUnCheckAll.addActionListener((ActionEvent e) -> { |
268 |
if (changes != null) { |
269 |
doUnCheckAll(); |
270 |
doUpdateTableLocalChanges(); |
271 |
} |
272 |
}); |
273 |
|
274 |
this.btnLocalShowForm.addActionListener((ActionEvent e) -> { |
275 |
doShowForm(); |
276 |
}); |
277 |
|
278 |
this.btnLocalCommit.addActionListener((ActionEvent e) -> { |
279 |
doCommit(); |
280 |
}); |
281 |
|
282 |
this.btnLocalRevert.addActionListener((ActionEvent e) -> { |
283 |
doRevert(); |
284 |
}); |
285 |
|
286 |
this.effectiveDatePicker = toolsSwingManager.createDatePickerController(
|
287 |
this.txtLocalEffectiveDate,
|
288 |
this.btnLocalEffectiveDate
|
289 |
); |
290 |
|
291 |
this.effectiveDatePicker.set(new Date()); |
292 |
|
293 |
this.btnLocalRefresh.addActionListener((ActionEvent e) -> { |
294 |
doUpdateTableLocalChanges(); |
295 |
}); |
296 |
|
297 |
this.btnLocalZoom.addActionListener((ActionEvent e) -> { |
298 |
doZoomToSelectedChange(); |
299 |
}); |
300 |
|
301 |
this.btnLocalCenter.addActionListener((ActionEvent e) -> { |
302 |
doCenterToSelectedChange(); |
303 |
}); |
304 |
|
305 |
this.btnLocalCleanHighlighted.addActionListener((ActionEvent e) -> { |
306 |
cleanHighligthed(); |
307 |
}); |
308 |
|
309 |
toolsSwingManager.addClearButton(this.txtLocalComment);
|
310 |
toolsSwingManager.setDefaultPopupMenu(txtLocalComment); |
311 |
|
312 |
context.doUpdateComponents(); |
313 |
} |
314 |
|
315 |
public void doChangeWorkspace() { |
316 |
doReloadTables(); |
317 |
doUpdateTableLocalChanges(); |
318 |
} |
319 |
|
320 |
private void translate() { |
321 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
322 |
|
323 |
swingManager.translate(this.btnLocalCheckAll);
|
324 |
swingManager.translate(this.btnLocalCommit);
|
325 |
swingManager.translate(this.btnLocalRefresh);
|
326 |
swingManager.translate(this.btnLocalRevert);
|
327 |
swingManager.translate(this.btnLocalShowForm);
|
328 |
swingManager.translate(this.btnLocalUnCheckAll);
|
329 |
|
330 |
swingManager.translate(this.lblLocalEffectiveDate);
|
331 |
swingManager.translate(this.lblLocalComment);
|
332 |
|
333 |
swingManager.translate(this.btnLocalCenter);
|
334 |
swingManager.translate(this.btnLocalZoom);
|
335 |
swingManager.translate(this.btnLocalCleanHighlighted);
|
336 |
} |
337 |
|
338 |
private Iterator<Long> getSelectionIterator() { |
339 |
ListSelectionModel selection = this.tblLocalChanges.getSelectionModel(); |
340 |
return new Iterator<Long>() { |
341 |
long n = selection.getMinSelectionIndex();
|
342 |
@Override
|
343 |
public boolean hasNext() { |
344 |
while (n <= selection.getMaxSelectionIndex()){
|
345 |
if(selection.isSelectedIndex((int) n)){ |
346 |
return true; |
347 |
} |
348 |
n++; |
349 |
} |
350 |
return false; |
351 |
} |
352 |
|
353 |
@Override
|
354 |
public Long next() { |
355 |
if(n > selection.getMaxSelectionIndex()){
|
356 |
throw new IllegalStateException(); |
357 |
} |
358 |
return n++;
|
359 |
} |
360 |
}; |
361 |
} |
362 |
|
363 |
private void doToggleSelection() { |
364 |
Thread task = new Thread(() -> { |
365 |
try {
|
366 |
context.processing = true;
|
367 |
context.doUpdateComponents(); |
368 |
Iterator<Long> rows = getSelectionIterator(); |
369 |
|
370 |
this.changes.process(rows, (VCSGisWorkspaceChange change) -> {
|
371 |
if(change.getOperation() == OP_ADD_ENTITY) {
|
372 |
if(change.isSelected()){
|
373 |
entitiesToUnCheckAll.add(change.getEntityCode()); |
374 |
} |
375 |
} |
376 |
change.setSelected(!change.isSelected()); |
377 |
return true; |
378 |
}); |
379 |
if(!entitiesToUnCheckAll.isEmpty()){
|
380 |
doUnCheckAllByEntities(); |
381 |
} |
382 |
} finally {
|
383 |
context.processing = false;
|
384 |
context.doUpdateComponents(); |
385 |
} |
386 |
}, "VCSGisToggleSelectionLocalChanges");
|
387 |
task.start(); |
388 |
} |
389 |
|
390 |
private Iterator<Long> getRowsByEntitiesToUnCheckIterator() { |
391 |
|
392 |
long size = changes.size64();
|
393 |
TableModel model = this.tblLocalChanges.getModel(); |
394 |
return new Iterator<Long>() { |
395 |
long n = 0; |
396 |
@Override
|
397 |
public boolean hasNext() { |
398 |
while (n < size){
|
399 |
VCSGisWorkspaceChange row = changes.get64(n); |
400 |
if(entitiesToUnCheckAll.contains(row.getEntityCode())){
|
401 |
return true; |
402 |
} |
403 |
n++; |
404 |
} |
405 |
return false; |
406 |
} |
407 |
|
408 |
@Override
|
409 |
public Long next() { |
410 |
return n++;
|
411 |
} |
412 |
}; |
413 |
} |
414 |
|
415 |
|
416 |
private void doUnCheckAllByEntities(){ |
417 |
if(dissabledUncheckAllByEntities){
|
418 |
return;
|
419 |
} |
420 |
Thread task = new Thread(() -> { |
421 |
try {
|
422 |
context.processing = true;
|
423 |
context.doUpdateComponents(); |
424 |
if(!entitiesToUnCheckAll.isEmpty()) {
|
425 |
Iterator<Long> rows = getRowsByEntitiesToUnCheckIterator(); |
426 |
this.changes.process(rows, (VCSGisWorkspaceChange change) -> {
|
427 |
if(change.getOperation() != OP_ADD_ENTITY) {
|
428 |
change.setSelected(false);
|
429 |
} |
430 |
return true; |
431 |
}); |
432 |
entitiesToUnCheckAll.clear(); |
433 |
} |
434 |
} finally {
|
435 |
context.processing = false;
|
436 |
context.doUpdateComponents(); |
437 |
} |
438 |
}, "VCSGisUnCheckAllByEntitiesLocalChanges");
|
439 |
task.start(); |
440 |
} |
441 |
|
442 |
private Iterator<Long> getRowsIterator() { |
443 |
long size = changes.size64();
|
444 |
return new Iterator<Long>() { |
445 |
long n = 0; |
446 |
@Override
|
447 |
public boolean hasNext() { |
448 |
return (n < size);
|
449 |
} |
450 |
|
451 |
@Override
|
452 |
public Long next() { |
453 |
return n++;
|
454 |
} |
455 |
}; |
456 |
} |
457 |
|
458 |
|
459 |
private void doCheckAll() { |
460 |
Thread task = new Thread(() -> { |
461 |
try {
|
462 |
context.processing = true;
|
463 |
dissabledUncheckAllByEntities = true;
|
464 |
context.doUpdateComponents(); |
465 |
this.changes.setSelectionAll();
|
466 |
} finally {
|
467 |
context.processing = false;
|
468 |
dissabledUncheckAllByEntities = false;
|
469 |
context.doUpdateComponents(); |
470 |
} |
471 |
}, "VCSGisCheckAllLocalChanges");
|
472 |
task.start(); |
473 |
} |
474 |
|
475 |
private void doUnCheckAll() { |
476 |
Thread task = new Thread(() -> { |
477 |
try {
|
478 |
context.processing = true;
|
479 |
dissabledUncheckAllByEntities = true;
|
480 |
context.doUpdateComponents(); |
481 |
this.changes.clearSelection();
|
482 |
} finally {
|
483 |
context.processing = false;
|
484 |
dissabledUncheckAllByEntities = false;
|
485 |
context.doUpdateComponents(); |
486 |
} |
487 |
}, "VCSGisUncheckAllLocalChanges");
|
488 |
task.start(); |
489 |
} |
490 |
|
491 |
public VCSGisWorkspace getWorkspace() {
|
492 |
return this.context.getWorkspace(); |
493 |
} |
494 |
|
495 |
/* friend */ void doUpdateComponents() { |
496 |
if (notInSwingThreadInvokeLater(() -> {
|
497 |
doUpdateComponents(); |
498 |
})) { |
499 |
return;
|
500 |
} |
501 |
try {
|
502 |
this.context.setVisibleStatus(context.processing);
|
503 |
VCSGisWorkspace ws = getWorkspace(); |
504 |
this.context.updateEntitiesFromRepository(false); |
505 |
this.entitySelector.setEnabled(!context.processing);
|
506 |
this.effectiveDatePicker.setEnabled(!context.processing);
|
507 |
this.workspacePicker.setEnabled(!context.processing);
|
508 |
this.btnLocalCheckAll.setEnabled(!context.processing && changes != null && changes.size64() > 0); |
509 |
this.btnLocalUnCheckAll.setEnabled(!context.processing && changes != null && changes.size64() > 0); |
510 |
List<VCSGisEntity> checkedEntities = entitySelector.getCheckedEntities();
|
511 |
this.btnLocalRefresh.setEnabled(!context.processing && changes != null && CollectionUtils.isNotEmpty(checkedEntities)); |
512 |
this.btnLocalRevert.setEnabled(ws != null |
513 |
&& !context.processing |
514 |
&& changes != null
|
515 |
&& changes.size64() > 0
|
516 |
&& entitiesWithChanges != null
|
517 |
&& CollectionUtils.isNotEmpty(checkedEntities) |
518 |
&& !entitiesWithChanges.isEmpty() |
519 |
); |
520 |
this.btnLocalRevert.setVisible(true); |
521 |
this.btnLocalCommit.setEnabled(ws != null |
522 |
&& !context.processing |
523 |
&& changes != null
|
524 |
&& !this.changes.isSelectionEmpty()
|
525 |
&& CollectionUtils.isNotEmpty(checkedEntities) |
526 |
&& ws.canCommit(null, getEntityCodes(checkedEntities))
|
527 |
); |
528 |
//Show form
|
529 |
boolean enableShowForm = false; |
530 |
|
531 |
int row = this.tblLocalChanges.getSelectedRow(); |
532 |
if (!context.processing && row >= 0) { |
533 |
VCSGisWorkspaceChange change = this.changes.get64(row);
|
534 |
if (change.getOperation() != OP_ADD_ENTITY) {
|
535 |
enableShowForm = true;
|
536 |
} |
537 |
} |
538 |
this.btnLocalShowForm.setEnabled(!context.processing && enableShowForm);
|
539 |
|
540 |
this.tblLocalChanges.setEnabled(!context.processing);
|
541 |
this.txtLocalComment.setEnabled(!context.processing);
|
542 |
this.effectiveDatePicker.setEnabled(!context.processing);
|
543 |
this.workspacePicker.setEnabled(!context.processing);
|
544 |
|
545 |
Geometry geom = getGeometryOfSelectedChange(); |
546 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange(); |
547 |
this.btnLocalCenter.setEnabled(!context.processing && (geom != null || originalGeom != null)); |
548 |
this.btnLocalZoom.setEnabled(!context.processing && (geom != null || originalGeom != null)); |
549 |
this.btnLocalCleanHighlighted.setEnabled(!context.processing);
|
550 |
} catch (VCSGisRuntimeException e1) {
|
551 |
LOGGER.warn("Can't updating components.", e1);
|
552 |
if (showAuthenticationErrors("_VCS_Changes", e1)) { |
553 |
this.workspacePicker.set(null); |
554 |
doChangeWorkspace(); |
555 |
} |
556 |
} catch (Exception e2) { |
557 |
LOGGER.warn("Can't updating components.", e2);
|
558 |
} |
559 |
|
560 |
} |
561 |
|
562 |
public void doReloadTables() { |
563 |
this.entitySelector.setWorkspace(this.getWorkspace()); |
564 |
} |
565 |
|
566 |
|
567 |
public void doUpdateTableLocalChanges() { |
568 |
if( context.processing ) {
|
569 |
return;
|
570 |
} |
571 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
572 |
VCSGisWorkspace ws = this.getWorkspace();
|
573 |
|
574 |
if(ws != null){ |
575 |
|
576 |
entitiesWithChanges = ws.getEntitiesWithChanges(); |
577 |
|
578 |
List<VCSGisEntity> checkedEntities = entitySelector.getCheckedEntities();
|
579 |
if(CollectionUtils.isEmpty(checkedEntities)) {
|
580 |
localChangesTableModel = new ChangesTableModel(ws);
|
581 |
this.tblLocalChanges.setModel(localChangesTableModel);
|
582 |
return;
|
583 |
} |
584 |
|
585 |
changes = ws.getLocalChanges(checkedEntities); |
586 |
|
587 |
localChangesTableModel = new ChangesTableModel(changes, ws);
|
588 |
this.tblLocalChanges.setModel(localChangesTableModel);
|
589 |
|
590 |
int columns = this.tblLocalChanges.getColumnModel().getColumnCount(); |
591 |
for (int i = 1; i < columns; i++) { |
592 |
this.tblLocalChanges.getColumnModel().getColumn(i).setCellRenderer(new DefaultTableCellRenderer() { |
593 |
@Override
|
594 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
595 |
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
596 |
VCSGisChange changeRow = changes.get64(row); |
597 |
VCSGisSwingCommons.setColorCompoment(c, changeRow.getStatus()); |
598 |
return c;
|
599 |
} |
600 |
}); |
601 |
} |
602 |
this.tableModelListener = null; |
603 |
localChangesTableModel.addTableModelListener(getTableModelListener()); |
604 |
context.message(i18n.getTranslation( |
605 |
"_Workspace_changes_list_updated",
|
606 |
new String[]{String.valueOf(changes.size64())} |
607 |
) |
608 |
); |
609 |
this.lblLocalChangesCount.setText(String.valueOf(changes.size64())); |
610 |
} |
611 |
context.doUpdateComponents(); |
612 |
} |
613 |
|
614 |
private TableModelListener getTableModelListener() { |
615 |
if(tableModelListener == null){ |
616 |
tableModelListener = (TableModelEvent e) -> {
|
617 |
if (e.getType() == TableModelEvent.UPDATE) { |
618 |
TableModel model = ((TableModel) (e.getSource())); |
619 |
VCSGisWorkspaceChange change = changes.get64(e.getFirstRow()); |
620 |
if(change.getOperation() == OP_ADD_ENTITY) {
|
621 |
if(!change.isSelected()) {
|
622 |
if (entitiesToUnCheckAll.add(change.getEntityCode())) {
|
623 |
doUnCheckAllByEntities(); |
624 |
} |
625 |
} |
626 |
} |
627 |
} |
628 |
}; |
629 |
} |
630 |
return tableModelListener;
|
631 |
} |
632 |
|
633 |
private void doShowForm() { |
634 |
|
635 |
int row = this.tblLocalChanges.getSelectedRow(); |
636 |
VCSGisWorkspaceChange change = this.changes.get64(row);
|
637 |
if(change.getOperation() == OP_DELETE || change.getOperation() == OP_ADD_ENTITY){
|
638 |
return;
|
639 |
} |
640 |
Feature feature = change.getRelatedFeature(); |
641 |
if(feature == null){ |
642 |
return;
|
643 |
} |
644 |
try {
|
645 |
DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager(); |
646 |
JFeatureForm form; |
647 |
form = dataSwingManager.createJFeatureForm(feature); |
648 |
WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
649 |
form.asJComponent().setPreferredSize(new Dimension(400,200)); |
650 |
winManager.showWindow(form.asJComponent(), "Local change: "+change.getLabel(), WindowManager.MODE.WINDOW);
|
651 |
} catch (CreateJFeatureFormException ex) {
|
652 |
LOGGER.warn("Can't show form", ex);
|
653 |
} |
654 |
|
655 |
} |
656 |
|
657 |
private void doCommit() { |
658 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
659 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
660 |
|
661 |
VCSGisWorkspace ws = getWorkspace(); |
662 |
if( ws==null ) { |
663 |
// TODO: Mensaje al usuario ??
|
664 |
return;
|
665 |
} |
666 |
List<VCSGisEntity> entities = entitySelector.getCheckedEntities();
|
667 |
List<String> entityCodes = getEntityCodes(entities); |
668 |
if( CollectionUtils.isEmpty(entities)){
|
669 |
// TODO: Mensaje al usuario ??
|
670 |
return;
|
671 |
} |
672 |
this.context.updateEntitiesFromRepository(false); |
673 |
MutableObject<String> message = new MutableObject<>(); |
674 |
if( !ws.canCommit(message, entityCodes) ) {
|
675 |
dialogs.messageDialog( |
676 |
i18n.getTranslation("_Cant_commit") + "\n" + message.getValue(), |
677 |
i18n.getTranslation("_Commit"),
|
678 |
JOptionPane.WARNING_MESSAGE
|
679 |
); |
680 |
return;
|
681 |
} |
682 |
Timestamp effectiveDate = new Timestamp(effectiveDatePicker.get().getTime()); |
683 |
this.tblLocalChanges.setModel(new ChangesTableModel(ws)); |
684 |
|
685 |
Thread task = new Thread(() -> { |
686 |
try {
|
687 |
context.processing = true;
|
688 |
context.doUpdateComponents(); |
689 |
if( !executeTopologyPlans(ws, entities) ) {
|
690 |
dialogs.messageDialog( |
691 |
i18n.getTranslation("_Cant_pass_topology_plans"),
|
692 |
i18n.getTranslation("_Commit"),
|
693 |
JOptionPane.WARNING_MESSAGE
|
694 |
); |
695 |
return;
|
696 |
} |
697 |
int r = ws.commit(
|
698 |
entityCodes, |
699 |
null,
|
700 |
effectiveDate, |
701 |
this.txtLocalComment.getText(),
|
702 |
this.context.getTaskStatusController().getSimpleTaskStatus()
|
703 |
); |
704 |
doPostCommit(r); |
705 |
} finally {
|
706 |
context.processing = false;
|
707 |
context.doUpdateComponents(); |
708 |
} |
709 |
}, "VCSGisCommit");
|
710 |
|
711 |
context.processing = true;
|
712 |
context.doUpdateComponents(); |
713 |
task.start(); |
714 |
} |
715 |
|
716 |
private boolean executeTopologyPlans(VCSGisWorkspace ws, List<VCSGisEntity> entities) { |
717 |
boolean topologyRequired = false; |
718 |
for (VCSGisEntity entity : entities) {
|
719 |
String x = ws.getTopologyPlan(entity.getTopologyPlanCode());
|
720 |
if( StringUtils.isNotBlank(x) ) {
|
721 |
topologyRequired= true;
|
722 |
break;
|
723 |
} |
724 |
} |
725 |
if (!topologyRequired){
|
726 |
return true; |
727 |
} |
728 |
try {
|
729 |
TopologyPlansExecutor executor = new TopologyPlansExecutor();
|
730 |
return executor.execute(ws, entities);
|
731 |
}catch(Exception ex){ |
732 |
return false; |
733 |
} |
734 |
} |
735 |
|
736 |
private void doPostCommit(int commitStatus) { |
737 |
if (notInSwingThreadInvokeLater(() -> {doPostCommit(commitStatus);})) {
|
738 |
return;
|
739 |
} |
740 |
if( commitStatus == ERR_OK) {
|
741 |
this.context.setVisibleStatus(false); |
742 |
} else {
|
743 |
showAuthenticationErrors("_VCS_Commit", commitStatus);
|
744 |
} |
745 |
context.updateLocalChangesTable(); |
746 |
} |
747 |
|
748 |
private void doRevert() { |
749 |
VCSGisWorkspace ws = getWorkspace(); |
750 |
if( ws==null ) { |
751 |
// TODO: Mensaje al usuario
|
752 |
return;
|
753 |
} |
754 |
this.context.updateEntitiesFromRepository(false); |
755 |
|
756 |
Thread task = new Thread(() -> { |
757 |
try {
|
758 |
context.processing = true;
|
759 |
context.doUpdateComponents(); |
760 |
List<VCSGisWorkspaceEntity> entities = ws.getEntitiesWithChanges();
|
761 |
List<String> selectedEntityCodes = getEntityCodes(entitySelector.getCheckedEntities()); |
762 |
int r = ERR_OK;
|
763 |
if(!entities.isEmpty() && CollectionUtils.isNotEmpty(selectedEntityCodes)){
|
764 |
for (VCSGisWorkspaceEntity entity : entities) {
|
765 |
if(selectedEntityCodes.contains(entity.getEntityCode())){
|
766 |
r = ws.revert(entity.getEntityCode(), |
767 |
this.context.getTaskStatusController().getSimpleTaskStatus()
|
768 |
); |
769 |
} |
770 |
if(r != ERR_OK){
|
771 |
break;
|
772 |
} |
773 |
} |
774 |
} |
775 |
doPostRevert(r, entities); |
776 |
} finally {
|
777 |
context.processing = false;
|
778 |
context.doUpdateComponents(); |
779 |
} |
780 |
}, "VCSGisRevert");
|
781 |
|
782 |
context.processing = true;
|
783 |
context.doUpdateComponents(); |
784 |
task.start(); |
785 |
} |
786 |
|
787 |
private void doPostRevert(int revertStatus, List<VCSGisWorkspaceEntity> entities) { |
788 |
if (notInSwingThreadInvokeLater(() -> {doPostRevert(revertStatus, entities);})) {
|
789 |
return;
|
790 |
} |
791 |
if( revertStatus == ERR_OK) {
|
792 |
this.context.setVisibleStatus(false); |
793 |
} |
794 |
for (VCSGisWorkspaceEntity entity : entities) {
|
795 |
FeatureStore store = getWorkspace().getFeatureStore(entity.getEntityName()); |
796 |
refreshDocument(store); |
797 |
} |
798 |
// doReloadTables();
|
799 |
context.updateLocalChangesTable(); |
800 |
} |
801 |
|
802 |
private Geometry getGeometryOfSelectedChange() {
|
803 |
Geometry geom = null;
|
804 |
int selected = this.tblLocalChanges.getSelectedRow(); |
805 |
if(selected >= 0){ |
806 |
VCSGisWorkspaceChange change = changes.get64(selected); |
807 |
try {
|
808 |
Feature feature = change.getRelatedFeature(); |
809 |
geom = feature.getDefaultGeometry(); |
810 |
} catch (Exception ex){ |
811 |
|
812 |
} |
813 |
} |
814 |
return geom;
|
815 |
} |
816 |
|
817 |
private Geometry getOriginalGeometryOfSelectedChange() {
|
818 |
Geometry geom = null;
|
819 |
int selected = this.tblLocalChanges.getSelectedRow(); |
820 |
if(selected >= 0){ |
821 |
VCSGisWorkspaceChange change = changes.get64(selected); |
822 |
try {
|
823 |
VCSGisWorkspace ws = getWorkspace(); |
824 |
if(ws!=null) { |
825 |
JsonObject json = change.getDataAsJson(); |
826 |
String entityCode = change.getEntityCode();
|
827 |
VCSGisEntity entity = ws.getEntity(entityCode); |
828 |
FeatureStore store = ws.getFeatureStore(entity.getEntityName()); |
829 |
Feature feature = store.createNewFeature(json); |
830 |
geom = feature.getDefaultGeometry(); |
831 |
} |
832 |
} catch (Exception ex){ |
833 |
|
834 |
} |
835 |
} |
836 |
return geom;
|
837 |
} |
838 |
|
839 |
private FeatureStore getStoreOfSelectedChange() {
|
840 |
FeatureStore store = null;
|
841 |
int selected = this.tblLocalChanges.getSelectedRow(); |
842 |
if(selected >= 0){ |
843 |
VCSGisWorkspaceChange change = changes.get64(selected); |
844 |
try {
|
845 |
VCSGisWorkspace ws = getWorkspace(); |
846 |
if(ws!=null) { |
847 |
String entityCode = change.getEntityCode();
|
848 |
VCSGisEntity entity = ws.getEntity(entityCode); |
849 |
store = ws.getFeatureStore(entity.getEntityName()); |
850 |
} |
851 |
} catch (Exception ex){ |
852 |
|
853 |
} |
854 |
} |
855 |
return store;
|
856 |
} |
857 |
|
858 |
private void doZoomToSelectedChange() { |
859 |
cleanHighligthed(); |
860 |
VCSGisManager manager = VCSGisLocator.getVCSGisManager(); |
861 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager(); |
862 |
VCSGisSwingServices services =swingManager.getDefaultServices(); |
863 |
FeatureStore store = getStoreOfSelectedChange(); |
864 |
Geometry geom = getGeometryOfSelectedChange(); |
865 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange(); |
866 |
// services.zoomActiveViewToGeometry(VCSGisSwingCommons.createBBox(geom, originalGeom));
|
867 |
services.zoomViewsHavingAStoreToGeometry(store, VCSGisSwingCommons.createBBox(geom, originalGeom)); |
868 |
if(geom != null){ |
869 |
services.highlight(HIGHLIGHT_WORKSPACE, geom, store); |
870 |
} |
871 |
if(originalGeom != null){ |
872 |
services.highlight(HIGHLIGHT_WORKSPACE_PREVIOUS, originalGeom, store); |
873 |
} |
874 |
} |
875 |
|
876 |
private void doCenterToSelectedChange() { |
877 |
cleanHighligthed(); |
878 |
VCSGisManager manager = VCSGisLocator.getVCSGisManager(); |
879 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager(); |
880 |
VCSGisSwingServices services =swingManager.getDefaultServices(); |
881 |
FeatureStore store = getStoreOfSelectedChange(); |
882 |
Geometry geom = getGeometryOfSelectedChange(); |
883 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange(); |
884 |
// services.centerActiveViewToGeometry(VCSGisSwingCommons.createBBox(geom, originalGeom));
|
885 |
services.centerViewsHavingAStoreToGeometry(store, VCSGisSwingCommons.createBBox(geom, originalGeom)); |
886 |
if(geom != null){ |
887 |
services.highlight(HIGHLIGHT_WORKSPACE, geom, store); |
888 |
} |
889 |
if(originalGeom != null){ |
890 |
services.highlight(HIGHLIGHT_WORKSPACE_PREVIOUS, originalGeom, store); |
891 |
} |
892 |
|
893 |
} |
894 |
|
895 |
private List<String> getEntityCodes(List<VCSGisEntity> entities) { |
896 |
List<String> res = new ArrayList(); |
897 |
for (VCSGisEntity entity : entities) {
|
898 |
res.add(entity.getEntityCode()); |
899 |
} |
900 |
return res;
|
901 |
} |
902 |
|
903 |
public void selectOnlyAEntity(VCSGisEntity entity){ |
904 |
entitySelector.clearChecks(); |
905 |
entitySelector.check(entity); |
906 |
} |
907 |
|
908 |
} |