gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.swing / org.gvsig.online.swing.impl / src / main / java / org / gvsig / online / swing / impl / changes / LocalChangesController.java @ 9512
History | View | Annotate | Download (53.1 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.online.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.util.ArrayList; |
31 |
import java.util.Collection; |
32 |
import java.util.HashMap; |
33 |
import java.util.HashSet; |
34 |
import java.util.Iterator; |
35 |
import java.util.List; |
36 |
import java.util.Map; |
37 |
import java.util.Set; |
38 |
import javax.json.JsonObject; |
39 |
import javax.swing.JButton; |
40 |
import javax.swing.JLabel; |
41 |
import javax.swing.JOptionPane; |
42 |
import javax.swing.JTable; |
43 |
import javax.swing.JTextField; |
44 |
import javax.swing.ListSelectionModel; |
45 |
import javax.swing.event.ListSelectionEvent; |
46 |
import javax.swing.event.TableModelEvent; |
47 |
import javax.swing.event.TableModelListener; |
48 |
import javax.swing.table.DefaultTableCellRenderer; |
49 |
import javax.swing.table.TableModel; |
50 |
import org.apache.commons.collections.CollectionUtils; |
51 |
import org.apache.commons.lang3.mutable.MutableObject; |
52 |
import org.gvsig.featureform.swing.CreateJFeatureFormException; |
53 |
import org.gvsig.featureform.swing.JFeatureForm; |
54 |
import org.gvsig.fmap.dal.feature.Feature; |
55 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
56 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
57 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
58 |
import org.gvsig.fmap.geom.Geometry; |
59 |
import org.gvsig.fmap.geom.GeometryLocator; |
60 |
import org.gvsig.fmap.geom.GeometryUtils; |
61 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
62 |
import org.gvsig.fmap.geom.primitive.Envelope; |
63 |
import org.gvsig.online.lib.api.OnlineManager; |
64 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_OK; |
65 |
import static org.gvsig.online.lib.api.OnlineManager.OP_DELETE; |
66 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_CONFLICT; |
67 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_CORRUPT; |
68 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_DISCONNECTED; |
69 |
import org.gvsig.online.lib.api.OnlineRuntimeException; |
70 |
import org.gvsig.online.lib.api.workingcopy.OnlineChange; |
71 |
import org.gvsig.online.lib.api.workingcopy.OnlineEntity; |
72 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
73 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChange; |
74 |
import org.gvsig.online.swing.api.OnlineSwingLocator; |
75 |
import org.gvsig.online.swing.api.OnlineSwingManager; |
76 |
import org.gvsig.online.swing.api.OnlineSwingServices; |
77 |
import static org.gvsig.online.swing.api.OnlineSwingServices.HIGHLIGHT_WORKSPACE; |
78 |
import static org.gvsig.online.swing.api.OnlineSwingServices.HIGHLIGHT_WORKSPACE_PREVIOUS; |
79 |
import org.gvsig.online.swing.impl.OnlineSwingCommons; |
80 |
import static org.gvsig.online.swing.impl.OnlineSwingCommons.cleanHighligthed; |
81 |
import static org.gvsig.online.swing.impl.OnlineSwingCommons.notInSwingThreadInvokeLater; |
82 |
import static org.gvsig.online.swing.impl.OnlineSwingCommons.refreshDocument; |
83 |
import static org.gvsig.online.swing.impl.OnlineSwingCommons.showAuthenticationErrors; |
84 |
import org.gvsig.tools.ToolsLocator; |
85 |
import org.gvsig.tools.dispose.DisposeUtils; |
86 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
87 |
import org.gvsig.tools.exception.BaseException; |
88 |
import org.gvsig.tools.i18n.I18nManager; |
89 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
90 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
91 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
92 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
93 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
94 |
import org.gvsig.tools.task.UserCancelTaskException; |
95 |
import org.slf4j.Logger; |
96 |
import org.slf4j.LoggerFactory; |
97 |
import org.gvsig.online.lib.api.workingcopy.OnlineChanges; |
98 |
|
99 |
/**
|
100 |
*
|
101 |
* @author gvSIG Team
|
102 |
*/
|
103 |
public class LocalChangesController extends AbstractDisposable { |
104 |
private static final Logger LOGGER = LoggerFactory.getLogger(LocalChangesController.class); |
105 |
private static final int MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES = 200; |
106 |
|
107 |
// private final JButton btnLocalCheckRecomendedEntities;
|
108 |
// private final JButton btnLocalCheckAllEntities;
|
109 |
// private final JButton btnLocalUnCheckAllEntities;
|
110 |
// private final JButton btnLocalExpandAllEntities;
|
111 |
// private final JButton btnLocalCollapseAllEntities;
|
112 |
private final JTable tblLocalChanges; |
113 |
private final JButton btnLocalCheckAll; |
114 |
private final JButton btnLocalUnCheckAll; |
115 |
private final JButton btnLocalShowForm; |
116 |
private final JButton btnLocalRefresh; |
117 |
private final JButton btnLocalCommit; |
118 |
private final JButton btnLocalRevert; |
119 |
private final PickerController<OnlineWorkingcopy> workspacePicker; |
120 |
private final OnlineJChangesImpl context; |
121 |
private final JButton btnLocalZoom; |
122 |
private final JButton btnLocalCenter; |
123 |
private final JButton btnLocalHighlight; |
124 |
private final JLabel lblLocalChangesCount; |
125 |
|
126 |
private OnlineChanges<OnlineWorkingcopyChange> changes;
|
127 |
private LocalChangesTableModel localChangesTableModel;
|
128 |
private List<OnlineEntity> entitiesWithSelectedChanges = null; |
129 |
|
130 |
private final Set<String> entitiesToUnCheckAll; |
131 |
private TableModelListener tableModelListener; |
132 |
private boolean dissabledUncheckAllByEntities; |
133 |
private final JButton btnLocalCleanHighlighted; |
134 |
private boolean isSelectionFromEntitiesEmpty; |
135 |
|
136 |
public LocalChangesController(
|
137 |
OnlineJChangesImpl context, |
138 |
PickerController<OnlineWorkingcopy> workspacePicker, |
139 |
JTable tblLocalChanges,
|
140 |
JButton btnLocalCheckAll,
|
141 |
JButton btnLocalUnCheckAll,
|
142 |
JButton btnLocalShowForm,
|
143 |
JButton btnLocalRefresh,
|
144 |
JButton btnLocalCommit,
|
145 |
JButton btnLocalRevert,
|
146 |
JButton btnLocalZoom,
|
147 |
JButton btnLocalCenter,
|
148 |
JButton btnLocalHighlight,
|
149 |
JButton btnLocalCleanHighlighted,
|
150 |
JLabel lblLocalChangesCount,
|
151 |
JTextField txtLocalTablesFilter,
|
152 |
JButton btnLocalTable
|
153 |
) { |
154 |
this.dissabledUncheckAllByEntities = false; |
155 |
|
156 |
this.context = context;
|
157 |
this.workspacePicker = workspacePicker;
|
158 |
this.tblLocalChanges = tblLocalChanges;
|
159 |
this.btnLocalCheckAll = btnLocalCheckAll;
|
160 |
|
161 |
this.btnLocalCommit = btnLocalCommit;
|
162 |
this.btnLocalRefresh = btnLocalRefresh;
|
163 |
this.btnLocalRevert = btnLocalRevert;
|
164 |
this.btnLocalShowForm = btnLocalShowForm;
|
165 |
this.btnLocalUnCheckAll = btnLocalUnCheckAll;
|
166 |
this.btnLocalZoom = btnLocalZoom;
|
167 |
this.btnLocalCenter = btnLocalCenter;
|
168 |
this.btnLocalHighlight = btnLocalHighlight;
|
169 |
this.btnLocalCleanHighlighted = btnLocalCleanHighlighted;
|
170 |
this.lblLocalChangesCount= lblLocalChangesCount;
|
171 |
|
172 |
this.entitiesToUnCheckAll = new HashSet<>(); |
173 |
|
174 |
initComponents(); |
175 |
} |
176 |
|
177 |
private void initComponents() { |
178 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
179 |
OnlineSwingManager onlineSwingManager = OnlineSwingLocator.getOnlineSwingManager(); |
180 |
|
181 |
translate(); |
182 |
|
183 |
// this.btnLocalCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
184 |
// this.btnLocalUnCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
185 |
this.btnLocalCheckAll.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
186 |
this.btnLocalCommit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
187 |
this.btnLocalRefresh.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
188 |
this.btnLocalRevert.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
189 |
this.btnLocalShowForm.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
190 |
this.btnLocalUnCheckAll.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
191 |
this.btnLocalZoom.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
192 |
this.btnLocalCenter.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
193 |
this.btnLocalHighlight.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
194 |
this.btnLocalCleanHighlighted.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
195 |
|
196 |
// this.btnLocalCheckAllEntities.addActionListener((ActionEvent e) -> {
|
197 |
// this.entitySelector.checkAll();
|
198 |
// });
|
199 |
//
|
200 |
// this.btnLocalUnCheckAllEntities.addActionListener((ActionEvent e) -> {
|
201 |
// this.entitySelector.clearChecks();
|
202 |
// });
|
203 |
// this.btnLocalCollapseAllEntities.addActionListener((ActionEvent e) -> {
|
204 |
// this.entitySelector.collapseAll();
|
205 |
// });
|
206 |
// this.btnLocalExpandAllEntities.addActionListener((ActionEvent e) -> {
|
207 |
// this.entitySelector.expandAll();
|
208 |
// });
|
209 |
//
|
210 |
// this.entitySelector = onlineSwingManager.createEntitySelectorController(
|
211 |
// this.treeLocalTables,
|
212 |
// txtLocalTablesFilter,
|
213 |
// btnLocalTable
|
214 |
// );
|
215 |
// this.entitySelector.setViewFilter(OnlineEntitySelectorController.LOCAL_ENTITIES);
|
216 |
// this.entitySelector.setFilter(OnlineEntitySelectorController.LOCAL_ENTITIES);
|
217 |
// this.entitySelector.setChecksEnabled(true);
|
218 |
// this.entitySelector.addChangeListener((ChangeEvent e) -> {
|
219 |
// doUpdateTableLocalChanges();
|
220 |
// });
|
221 |
// this.entitySelector.addActionListener((ActionEvent e) -> {
|
222 |
// switch(e.getID()) {
|
223 |
// case OnlineEntitySelectorController.ACTION_SELECT_ID:
|
224 |
// doUpdateComponents();
|
225 |
// break;
|
226 |
// case OnlineEntitySelectorController.ACTION_CHECK_ID:
|
227 |
// doUpdateTableLocalChanges();
|
228 |
// doUpdateComponents();
|
229 |
// break;
|
230 |
// case OnlineEntitySelectorController.ACTION_RELOAD_ID:
|
231 |
// doUpdateTableLocalChanges();
|
232 |
// doUpdateComponents();
|
233 |
// break;
|
234 |
// }
|
235 |
// });
|
236 |
|
237 |
this.tblLocalChanges.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
238 |
|
239 |
this.tblLocalChanges.addKeyListener(new KeyAdapter() { |
240 |
@Override
|
241 |
public void keyPressed(KeyEvent e) { |
242 |
if (e.getKeyCode() == KeyEvent.VK_SPACE) { |
243 |
doToggleSelection(); |
244 |
} |
245 |
} |
246 |
}); |
247 |
|
248 |
this.tblLocalChanges.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { |
249 |
doUpdateEntitiesWithSelectedChanges(); |
250 |
doUpdateIsSelectionFromEntitiesEmpty(); |
251 |
context.doUpdateComponents(); |
252 |
}); |
253 |
|
254 |
this.btnLocalCheckAll.addActionListener((ActionEvent e) -> { |
255 |
if (changes != null) { |
256 |
doCheckAll(); |
257 |
doUpdateTableLocalChanges(); |
258 |
} |
259 |
}); |
260 |
|
261 |
this.btnLocalUnCheckAll.addActionListener((ActionEvent e) -> { |
262 |
if (changes != null) { |
263 |
doUnCheckAll(); |
264 |
doUpdateTableLocalChanges(); |
265 |
} |
266 |
}); |
267 |
|
268 |
this.btnLocalShowForm.addActionListener((ActionEvent e) -> { |
269 |
doShowForm(); |
270 |
}); |
271 |
|
272 |
this.btnLocalCommit.addActionListener((ActionEvent e) -> { |
273 |
doCommit(); |
274 |
}); |
275 |
|
276 |
this.btnLocalRevert.addActionListener((ActionEvent e) -> { |
277 |
doRevert(); |
278 |
}); |
279 |
|
280 |
this.btnLocalRefresh.addActionListener((ActionEvent e) -> { |
281 |
doUpdateTableLocalChanges(); |
282 |
}); |
283 |
|
284 |
this.btnLocalZoom.addActionListener((ActionEvent e) -> { |
285 |
doZoomToSelectedChange(); |
286 |
}); |
287 |
|
288 |
this.btnLocalCenter.addActionListener((ActionEvent e) -> { |
289 |
doCenterToSelectedChange(); |
290 |
}); |
291 |
|
292 |
this.btnLocalHighlight.addActionListener((ActionEvent e) -> { |
293 |
doHighLightSelectedChange(); |
294 |
}); |
295 |
|
296 |
this.btnLocalCleanHighlighted.addActionListener((ActionEvent e) -> { |
297 |
cleanHighligthed(); |
298 |
}); |
299 |
|
300 |
// this.btnLocalCheckRecomendedEntities.addActionListener((ActionEvent e) -> {
|
301 |
// doCheckRecomendedEntities();
|
302 |
// });
|
303 |
|
304 |
context.doUpdateComponents(); |
305 |
} |
306 |
|
307 |
// public void doChangeWorkspace() {
|
308 |
// OnlineWorkingcopy ws = getUndisposableWorkspace();
|
309 |
// this.entitySelector.setWorkspace(ws);
|
310 |
// if( ws!=null ) {
|
311 |
// for (String tableName : this.context.getDefaultTablesSelection()) {
|
312 |
// OnlineEntity entity = ws.getWorkspaceEntity(tableName);
|
313 |
// if( entity!=null ) {
|
314 |
// this.entitySelector.check(entity);
|
315 |
// }
|
316 |
// }
|
317 |
// }
|
318 |
//// doUpdateTableLocalChanges();
|
319 |
// }
|
320 |
|
321 |
private void translate() { |
322 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
323 |
|
324 |
// swingManager.translate(this.btnLocalCheckRecomendedEntities);
|
325 |
// swingManager.translate(this.btnLocalCheckAllEntities);
|
326 |
// swingManager.translate(this.btnLocalUnCheckAllEntities);
|
327 |
swingManager.translate(this.btnLocalCheckAll);
|
328 |
swingManager.translate(this.btnLocalCommit);
|
329 |
swingManager.translate(this.btnLocalRefresh);
|
330 |
swingManager.translate(this.btnLocalRevert);
|
331 |
swingManager.translate(this.btnLocalShowForm);
|
332 |
swingManager.translate(this.btnLocalUnCheckAll);
|
333 |
|
334 |
swingManager.translate(this.btnLocalCenter);
|
335 |
swingManager.translate(this.btnLocalHighlight);
|
336 |
swingManager.translate(this.btnLocalZoom);
|
337 |
swingManager.translate(this.btnLocalCleanHighlighted);
|
338 |
|
339 |
// swingManager.translate(this.btnLocalCollapseAllEntities);
|
340 |
// swingManager.translate(this.btnLocalExpandAllEntities);
|
341 |
|
342 |
} |
343 |
|
344 |
private Iterator<Long> getSelectionIterator() { |
345 |
ListSelectionModel selection = this.tblLocalChanges.getSelectionModel(); |
346 |
return new Iterator<Long>() { |
347 |
long n = selection.getMinSelectionIndex();
|
348 |
@Override
|
349 |
public boolean hasNext() { |
350 |
while (n <= selection.getMaxSelectionIndex()){
|
351 |
if(selection.isSelectedIndex((int) n)){ |
352 |
return true; |
353 |
} |
354 |
n++; |
355 |
} |
356 |
return false; |
357 |
} |
358 |
|
359 |
@Override
|
360 |
public Long next() { |
361 |
if(n > selection.getMaxSelectionIndex()){
|
362 |
throw new IllegalStateException(); |
363 |
} |
364 |
return n++;
|
365 |
} |
366 |
}; |
367 |
} |
368 |
|
369 |
private void doToggleSelection() { |
370 |
Thread task = new Thread(() -> { |
371 |
try {
|
372 |
context.processing = true;
|
373 |
context.doUpdateComponents(); |
374 |
Iterator<Long> rows = getSelectionIterator(); |
375 |
|
376 |
this.changes.process(rows, (OnlineWorkingcopyChange change) -> {
|
377 |
// if(change.getOperation() == OP_ADD_ENTITY) {
|
378 |
// if(change.isSelected()){
|
379 |
// entitiesToUnCheckAll.add(change.getEntityCode());
|
380 |
// }
|
381 |
// }
|
382 |
change.setSelected(!change.isSelected()); |
383 |
return true; |
384 |
}); |
385 |
if(!entitiesToUnCheckAll.isEmpty()){
|
386 |
doUnCheckAllByEntities(); |
387 |
} |
388 |
} finally {
|
389 |
doUpdateEntitiesWithSelectedChanges(); |
390 |
doUpdateIsSelectionFromEntitiesEmpty(); |
391 |
context.processing = false;
|
392 |
context.doUpdateComponents(); |
393 |
} |
394 |
}, "VCSGisToggleSelectionLocalChanges");
|
395 |
task.start(); |
396 |
} |
397 |
|
398 |
private Iterator<Long> getRowsByEntitiesToUnCheckIterator() { |
399 |
|
400 |
long size = changes.size64();
|
401 |
TableModel model = this.tblLocalChanges.getModel(); |
402 |
return new Iterator<Long>() { |
403 |
long n = 0; |
404 |
@Override
|
405 |
public boolean hasNext() { |
406 |
while (n < size){
|
407 |
OnlineWorkingcopyChange row = changes.get64(n); |
408 |
if(entitiesToUnCheckAll.contains(row.getEntityCode())){
|
409 |
return true; |
410 |
} |
411 |
n++; |
412 |
} |
413 |
return false; |
414 |
} |
415 |
|
416 |
@Override
|
417 |
public Long next() { |
418 |
return n++;
|
419 |
} |
420 |
}; |
421 |
} |
422 |
|
423 |
|
424 |
private void doUnCheckAllByEntities(){ |
425 |
if(dissabledUncheckAllByEntities){
|
426 |
return;
|
427 |
} |
428 |
Thread task = new Thread(() -> { |
429 |
try {
|
430 |
context.processing = true;
|
431 |
context.doUpdateComponents(); |
432 |
if(!entitiesToUnCheckAll.isEmpty()) {
|
433 |
Iterator<Long> rows = getRowsByEntitiesToUnCheckIterator(); |
434 |
this.changes.process(rows, (OnlineWorkingcopyChange change) -> {
|
435 |
// if(change.getOperation() != OP_ADD_ENTITY) {
|
436 |
// change.setSelected(false);
|
437 |
// }
|
438 |
return true; |
439 |
}); |
440 |
entitiesToUnCheckAll.clear(); |
441 |
} |
442 |
} finally {
|
443 |
doUpdateEntitiesWithSelectedChanges(); |
444 |
context.processing = false;
|
445 |
context.doUpdateComponents(); |
446 |
} |
447 |
}, "VCSGisUnCheckAllByEntitiesLocalChanges");
|
448 |
task.start(); |
449 |
} |
450 |
|
451 |
private Iterator<Long> getRowsIterator() { |
452 |
long size = changes.size64();
|
453 |
return new Iterator<Long>() { |
454 |
long n = 0; |
455 |
@Override
|
456 |
public boolean hasNext() { |
457 |
return (n < size);
|
458 |
} |
459 |
|
460 |
@Override
|
461 |
public Long next() { |
462 |
return n++;
|
463 |
} |
464 |
}; |
465 |
} |
466 |
|
467 |
|
468 |
private void doCheckAll() { |
469 |
Thread task = new Thread(() -> { |
470 |
try {
|
471 |
context.processing = true;
|
472 |
dissabledUncheckAllByEntities = true;
|
473 |
context.doUpdateComponents(); |
474 |
this.changes.setSelectionAll();
|
475 |
} finally {
|
476 |
context.processing = false;
|
477 |
dissabledUncheckAllByEntities = false;
|
478 |
context.doUpdateComponents(); |
479 |
} |
480 |
}, "VCSGisCheckAllLocalChanges");
|
481 |
task.start(); |
482 |
} |
483 |
|
484 |
private void doUnCheckAll() { |
485 |
Thread task = new Thread(() -> { |
486 |
try {
|
487 |
context.processing = true;
|
488 |
dissabledUncheckAllByEntities = true;
|
489 |
context.doUpdateComponents(); |
490 |
this.changes.clearSelection();
|
491 |
} finally {
|
492 |
context.processing = false;
|
493 |
dissabledUncheckAllByEntities = false;
|
494 |
context.doUpdateComponents(); |
495 |
} |
496 |
}, "VCSGisUncheckAllLocalChanges");
|
497 |
task.start(); |
498 |
} |
499 |
|
500 |
private OnlineWorkingcopy getUndisposableWorkspace() {
|
501 |
OnlineWorkingcopy ws = getWorkspace(); |
502 |
DisposeUtils.disposeQuietly(ws); |
503 |
// LOGGER.info("ws.references = " + DisposeUtils.getReferences(ws));
|
504 |
return ws;
|
505 |
} |
506 |
|
507 |
private OnlineWorkingcopy getWorkspace() {
|
508 |
OnlineWorkingcopy ws = this.context.getWorkspace();
|
509 |
return ws;
|
510 |
} |
511 |
|
512 |
/* friend */ void doUpdateComponents() { |
513 |
if (notInSwingThreadInvokeLater(() -> {
|
514 |
doUpdateComponents(); |
515 |
})) { |
516 |
return;
|
517 |
} |
518 |
OnlineSwingManager vcsgisSwingManager = OnlineSwingLocator.getOnlineSwingManager(); |
519 |
|
520 |
try {
|
521 |
this.context.message(""); |
522 |
boolean changesIsEmpty = changes == null || changes.isEmpty(); |
523 |
this.context.setVisibleStatus(context.processing);
|
524 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
525 |
// this.context.updateEntitiesFromRepository(false);
|
526 |
this.context.btnClose.setEnabled(!context.processing);
|
527 |
// this.entitySelector.setEnabled(!context.processing);
|
528 |
this.workspacePicker.setEnabled(!context.processing);
|
529 |
this.btnLocalCheckAll.setEnabled(!context.processing && !changesIsEmpty);
|
530 |
this.btnLocalUnCheckAll.setEnabled(!context.processing && !changesIsEmpty);
|
531 |
List<OnlineEntity> checkedEntities = context.getEntitySelector().getCheckedEntities();
|
532 |
this.btnLocalRefresh.setEnabled(!context.processing && changes != null && CollectionUtils.isNotEmpty(checkedEntities)); |
533 |
this.btnLocalRevert.setEnabled(ws != null |
534 |
&& !context.processing |
535 |
&& !changesIsEmpty |
536 |
&& CollectionUtils.isNotEmpty(checkedEntities) |
537 |
&& entitiesWithSelectedChanges != null
|
538 |
&& !entitiesWithSelectedChanges.isEmpty() |
539 |
&& !isSelectionFromEntitiesEmpty |
540 |
); |
541 |
this.btnLocalRevert.setVisible(true); |
542 |
if (ws != null |
543 |
&& !context.processing |
544 |
&& changes != null
|
545 |
&& !this.changes.isSelectionEmpty()
|
546 |
&& CollectionUtils.isNotEmpty(checkedEntities) |
547 |
&& entitiesWithSelectedChanges != null
|
548 |
&& !entitiesWithSelectedChanges.isEmpty() |
549 |
&& !isSelectionFromEntitiesEmpty |
550 |
) { |
551 |
MutableObject<String> msg = new MutableObject<>(); |
552 |
if( areConflictEntities(checkedEntities) ) {
|
553 |
context.alert("_There_are_selected_entities_that_have_conflicts");
|
554 |
this.btnLocalCommit.setEnabled(false); |
555 |
LOGGER.info("Can't enable commit (1.2). There are selected entities that have conflicts.");
|
556 |
} else if( areCorruptOrDisconnectedEntities(checkedEntities) ) { |
557 |
context.alert("_There_are_selected_corrupted_or_disconnected_entities");
|
558 |
this.btnLocalCommit.setEnabled(false); |
559 |
LOGGER.info("Can't enable commit (1.2). There are selected corrputed or diconnected entities.");
|
560 |
} else if (!ws.canUpload(msg, getEntityCodes(checkedEntities))) { |
561 |
context.alert(msg.getValue()); |
562 |
this.btnLocalCommit.setEnabled(false); |
563 |
LOGGER.info("Can't enable commit (1). "+ msg.getValue());
|
564 |
} else {
|
565 |
this.btnLocalCommit.setEnabled(true); |
566 |
} |
567 |
|
568 |
} else {
|
569 |
try {
|
570 |
if( CollectionUtils.isEmpty(checkedEntities) ) {
|
571 |
this.context.message("_Select_tables_to_view_changes"); |
572 |
LOGGER.info("Can't enable commit (2).");
|
573 |
} else if( changes == null || this.changes.isSelectionEmpty() ) { |
574 |
this.context.message("_Select_the_changes_to_commit"); |
575 |
LOGGER.info("Can't enable commit (3).");
|
576 |
} else if( entitiesWithSelectedChanges == null || entitiesWithSelectedChanges.isEmpty() ) { |
577 |
this.context.message("_Cant_locate_the_tables_related_to_changes"); |
578 |
LOGGER.info("Can't enable commit (4).");
|
579 |
} else if( isSelectionFromEntitiesEmpty ) { |
580 |
this.context.message("_Cant_locate_changes_in_selected_tables"); |
581 |
LOGGER.info("Can't enable commit (5).");
|
582 |
} else {
|
583 |
LOGGER.info("Can't enable commit (6).");
|
584 |
} |
585 |
} catch(Exception ex) { |
586 |
LOGGER.info("Can't enable commit (7).");
|
587 |
} |
588 |
this.btnLocalCommit.setEnabled(false); |
589 |
} |
590 |
//Show form
|
591 |
boolean enableShowForm = false; |
592 |
|
593 |
int row = this.tblLocalChanges.getSelectedRow(); |
594 |
if (!context.processing && row >= 0) { |
595 |
enableShowForm = true;
|
596 |
} |
597 |
this.btnLocalShowForm.setEnabled(!context.processing && enableShowForm);
|
598 |
|
599 |
this.tblLocalChanges.setEnabled(!context.processing);
|
600 |
this.workspacePicker.setEnabled(!context.processing);
|
601 |
|
602 |
Geometry geom = getGeometryOfSelectedChange(); |
603 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange(); |
604 |
this.btnLocalCenter.setEnabled(!context.processing); // && (geom != null || originalGeom != null)); |
605 |
this.btnLocalHighlight.setEnabled(!context.processing && (geom != null || originalGeom != null)); |
606 |
this.btnLocalZoom.setEnabled(!context.processing); // && (geom != null || originalGeom != null)); |
607 |
this.btnLocalCleanHighlighted.setEnabled(!context.processing);
|
608 |
} catch (OnlineRuntimeException e1) {
|
609 |
LOGGER.warn("Can't updating components.", e1);
|
610 |
if (showAuthenticationErrors("_Online_Changes", e1)) { |
611 |
this.workspacePicker.set(null); |
612 |
// doChangeWorkspace();
|
613 |
} |
614 |
} catch (Exception e2) { |
615 |
LOGGER.warn("Can't updating components.", e2);
|
616 |
} |
617 |
|
618 |
} |
619 |
|
620 |
// public void doReloadTables() {
|
621 |
// this.entitySelector.reloadEntities();
|
622 |
// }
|
623 |
|
624 |
public void doUpdateEntitiesWithSelectedChanges() { |
625 |
OnlineWorkingcopy ws = this.getUndisposableWorkspace();
|
626 |
if (ws != null) { |
627 |
entitiesWithSelectedChanges = ws.getEntitiesWithSelectedChanges(); |
628 |
} |
629 |
} |
630 |
|
631 |
private void doUpdateIsSelectionFromEntitiesEmpty() { |
632 |
OnlineWorkingcopy ws = this.getUndisposableWorkspace();
|
633 |
if (ws != null) { |
634 |
List<OnlineEntity> checkedEntities = context.getEntitySelector().getCheckedEntities();
|
635 |
this.isSelectionFromEntitiesEmpty = changes.isSelectionFromEntitiesEmpty(checkedEntities);
|
636 |
} |
637 |
} |
638 |
|
639 |
|
640 |
public void doUpdateTableLocalChanges() { |
641 |
if( context.processing ) {
|
642 |
return;
|
643 |
} |
644 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
645 |
OnlineWorkingcopy ws = this.getUndisposableWorkspace();
|
646 |
|
647 |
if(ws != null){ |
648 |
|
649 |
doUpdateEntitiesWithSelectedChanges(); |
650 |
|
651 |
List<OnlineEntity> checkedEntities = context.getEntitySelector().getCheckedEntities();
|
652 |
if(CollectionUtils.isEmpty(checkedEntities)) {
|
653 |
localChangesTableModel = new LocalChangesTableModel(ws);
|
654 |
this.tblLocalChanges.setModel(localChangesTableModel);
|
655 |
return;
|
656 |
} |
657 |
|
658 |
changes = ws.getLocalChanges(checkedEntities); |
659 |
|
660 |
localChangesTableModel = new LocalChangesTableModel(changes, ws);
|
661 |
this.tblLocalChanges.setModel(localChangesTableModel);
|
662 |
|
663 |
int columns = this.tblLocalChanges.getColumnModel().getColumnCount(); |
664 |
for (int i = 1; i < columns; i++) { |
665 |
this.tblLocalChanges.getColumnModel().getColumn(i).setCellRenderer(new DefaultTableCellRenderer() { |
666 |
@Override
|
667 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
668 |
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
669 |
OnlineChange changeRow = changes.get64(row); |
670 |
OnlineSwingCommons.setColorCompoment(c, changeRow.getStatus()); |
671 |
return c;
|
672 |
} |
673 |
}); |
674 |
} |
675 |
this.tableModelListener = null; |
676 |
localChangesTableModel.addTableModelListener(getTableModelListener()); |
677 |
context.message(i18n.getTranslation( |
678 |
"_Workingcopy_changes_list_updated",
|
679 |
new String[]{String.valueOf(changes.size64())} |
680 |
) |
681 |
); |
682 |
this.lblLocalChangesCount.setText(String.valueOf(changes.size64())); |
683 |
} |
684 |
doUpdateIsSelectionFromEntitiesEmpty(); |
685 |
context.doUpdateComponents(); |
686 |
} |
687 |
|
688 |
private TableModelListener getTableModelListener() { |
689 |
if(tableModelListener == null){ |
690 |
tableModelListener = (TableModelEvent e) -> {
|
691 |
if (e.getType() == TableModelEvent.UPDATE) { |
692 |
TableModel model = ((TableModel) (e.getSource())); |
693 |
OnlineWorkingcopyChange change = changes.get64(e.getFirstRow()); |
694 |
// if(change.getOperation() == OP_ADD_ENTITY) {
|
695 |
// if(!change.isSelected()) {
|
696 |
// if (entitiesToUnCheckAll.add(change.getEntityCode())) {
|
697 |
// doUnCheckAllByEntities();
|
698 |
// }
|
699 |
// }
|
700 |
// }
|
701 |
} |
702 |
}; |
703 |
} |
704 |
return tableModelListener;
|
705 |
} |
706 |
|
707 |
private void doShowForm() { |
708 |
|
709 |
int row = this.tblLocalChanges.getSelectedRow(); |
710 |
OnlineWorkingcopyChange change = this.changes.get64(row);
|
711 |
if(change.getOperation() == OP_DELETE
|
712 |
// || change.getOperation() == OP_ADD_ENTITY
|
713 |
){ |
714 |
return;
|
715 |
} |
716 |
Feature feature = change.getRelatedFeature(); |
717 |
if(feature == null){ |
718 |
return;
|
719 |
} |
720 |
try {
|
721 |
DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager(); |
722 |
JFeatureForm form; |
723 |
form = dataSwingManager.createJFeatureForm(feature); |
724 |
WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
725 |
form.asJComponent().setPreferredSize(new Dimension(400,200)); |
726 |
winManager.showWindow(form.asJComponent(), "Local change: "+change.getLabel(), WindowManager.MODE.WINDOW);
|
727 |
} catch (CreateJFeatureFormException ex) {
|
728 |
LOGGER.warn("Can't show form", ex);
|
729 |
} |
730 |
|
731 |
} |
732 |
|
733 |
private void doCommit() { |
734 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
735 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
736 |
|
737 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
738 |
if( ws==null ) { |
739 |
// TODO: Mensaje al usuario ??
|
740 |
return;
|
741 |
} |
742 |
List<OnlineEntity> entities = context.getEntitySelector().getCheckedEntities();
|
743 |
List<String> entityCodes = getEntityCodes(entities); |
744 |
if( CollectionUtils.isEmpty(entities)){
|
745 |
// TODO: Mensaje al usuario ??
|
746 |
return;
|
747 |
} |
748 |
// this.context.updateEntitiesFromRepository(false);
|
749 |
MutableObject<String> message = new MutableObject<>(); |
750 |
if( !ws.canUpload(message, entityCodes) ) {
|
751 |
dialogs.messageDialog( |
752 |
i18n.getTranslation("_Cant_commit") + "\n" + message.getValue(), |
753 |
i18n.getTranslation("_Commit"),
|
754 |
JOptionPane.WARNING_MESSAGE
|
755 |
); |
756 |
return;
|
757 |
} |
758 |
this.tblLocalChanges.setModel(new LocalChangesTableModel(ws)); |
759 |
|
760 |
// List<VCSGisTopologyPlanStatus> topologicPlanStatusList = new ArrayList<>();
|
761 |
//
|
762 |
// Thread task = new Thread(() -> {
|
763 |
// try {
|
764 |
// context.processing = true;
|
765 |
// context.doUpdateComponents();
|
766 |
// if(!existsAllTopologyPlansLocally(ws, entities)) {
|
767 |
// ws.updateTopologyPlansFromRepository(null);
|
768 |
// }
|
769 |
// if( !executeTopologyPlans(ws, entities, topologicPlanStatusList) ) {
|
770 |
// dialogs.messageDialog(
|
771 |
// i18n.getTranslation("_Cant_pass_topology_plans"),
|
772 |
// i18n.getTranslation("_Commit"),
|
773 |
// JOptionPane.WARNING_MESSAGE
|
774 |
// );
|
775 |
// return;
|
776 |
// }
|
777 |
// int r = ws.commit(
|
778 |
// entityCodes,
|
779 |
// null,
|
780 |
// effectiveDate,
|
781 |
// this.txtLocalComment.getText(),
|
782 |
// this.context.getTaskStatusController().getSimpleTaskStatus(),
|
783 |
// topologicPlanStatusList
|
784 |
// );
|
785 |
// if(r==OnlineManager.ERR_TOPOLOGYPLAN_OUTDATED){
|
786 |
// ws.updateTopologyPlansFromRepository(null);
|
787 |
// }
|
788 |
// doPostCommit(r);
|
789 |
// } catch(UserCancelledException ex) {
|
790 |
// LOGGER.warn("User cancelled");
|
791 |
// } finally {
|
792 |
// context.processing = false;
|
793 |
// context.doUpdateComponents();
|
794 |
// }
|
795 |
// }, "VCSGisCommit");
|
796 |
//
|
797 |
// context.processing = true;
|
798 |
// context.doUpdateComponents();
|
799 |
// task.start();
|
800 |
} |
801 |
|
802 |
private void doPostCommit(int commitStatus) { |
803 |
if (notInSwingThreadInvokeLater(() -> {doPostCommit(commitStatus);})) {
|
804 |
return;
|
805 |
} |
806 |
switch (commitStatus) {
|
807 |
case ERR_OK:
|
808 |
this.context.setVisibleStatus(false); |
809 |
break;
|
810 |
default:
|
811 |
showAuthenticationErrors("_VCS_Commit", commitStatus);
|
812 |
break;
|
813 |
} |
814 |
context.getEntitySelector().reloadEntities(); |
815 |
context.updateLocalChangesTable(); |
816 |
cleanHighligthed(); |
817 |
} |
818 |
|
819 |
private void doRevert() { |
820 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
821 |
if( ws==null ) { |
822 |
// TODO: Mensaje al usuario
|
823 |
return;
|
824 |
} |
825 |
// this.context.updateEntitiesFromRepository(false);
|
826 |
|
827 |
Thread task = new Thread(() -> { |
828 |
try {
|
829 |
context.processing = true;
|
830 |
context.doUpdateComponents(); |
831 |
List<OnlineEntity> entities = ws.getEntitiesWithSelectedChanges();
|
832 |
List<String> selectedEntityCodes = getEntityCodes(context.getEntitySelector().getCheckedEntities()); |
833 |
int r = ERR_OK;
|
834 |
if(!entities.isEmpty() && CollectionUtils.isNotEmpty(selectedEntityCodes)){
|
835 |
for (OnlineEntity entity : entities) {
|
836 |
if(selectedEntityCodes.contains(entity.getEntityCode())){
|
837 |
r = ws.revert(entity.getEntityCode(), |
838 |
this.context.getTaskStatusController().getSimpleTaskStatus()
|
839 |
); |
840 |
} |
841 |
if(r != ERR_OK){
|
842 |
break;
|
843 |
} |
844 |
} |
845 |
} |
846 |
doPostRevert(r, entities); |
847 |
} catch(UserCancelTaskException ex) {
|
848 |
LOGGER.warn("User cancelled");
|
849 |
} finally {
|
850 |
context.processing = false;
|
851 |
context.doUpdateComponents(); |
852 |
} |
853 |
}, "VCSGisRevert");
|
854 |
|
855 |
context.processing = true;
|
856 |
context.doUpdateComponents(); |
857 |
task.start(); |
858 |
} |
859 |
|
860 |
private void doPostRevert(int revertStatus, List<OnlineEntity> entities) { |
861 |
if (notInSwingThreadInvokeLater(() -> {doPostRevert(revertStatus, entities);})) {
|
862 |
return;
|
863 |
} |
864 |
if( revertStatus == ERR_OK) {
|
865 |
this.context.setVisibleStatus(false); |
866 |
} |
867 |
for (OnlineEntity entity : entities) {
|
868 |
FeatureStore store = getUndisposableWorkspace().getFeatureStore(entity.getEntityName()); |
869 |
refreshDocument(store); |
870 |
} |
871 |
context.updateLocalChangesTable(); |
872 |
cleanHighligthed(); |
873 |
|
874 |
} |
875 |
|
876 |
private Geometry getBBoxOfSelectedChanges() {
|
877 |
int[] selecteds = this.tblLocalChanges.getSelectedRows(); |
878 |
if(selecteds!=null && selecteds.length >= 0){ |
879 |
Envelope env = GeometryUtils.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
880 |
for (int i = 0; i < selecteds.length; i++) { |
881 |
int selected = selecteds[i];
|
882 |
OnlineWorkingcopyChange change = changes.get64(selected); |
883 |
try {
|
884 |
Feature feature = change.getRelatedFeature(); |
885 |
Geometry geom = feature.getDefaultGeometry(); |
886 |
env.add(geom); |
887 |
} catch (Exception ex){ |
888 |
|
889 |
} |
890 |
} |
891 |
if( !env.isEmpty() ) {
|
892 |
return env.getBox2D();
|
893 |
} |
894 |
} |
895 |
return null; |
896 |
} |
897 |
|
898 |
private Geometry getOriginalBBoxOfSelectedChanges() {
|
899 |
int[] selecteds = this.tblLocalChanges.getSelectedRows(); |
900 |
if(selecteds != null && selecteds.length >= 0) { |
901 |
Envelope env = GeometryUtils.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
902 |
Map<String, FeatureStore> stores = new HashMap<>(); |
903 |
try {
|
904 |
for (int i = 0; i < selecteds.length; i++) { |
905 |
int selected = selecteds[i];
|
906 |
OnlineWorkingcopyChange change = changes.get64(selected); |
907 |
FeatureStore store = null;
|
908 |
try {
|
909 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
910 |
if (ws != null) { |
911 |
JsonObject json = change.getDataAsJson(); |
912 |
String entityCode = change.getEntityCode();
|
913 |
OnlineEntity entity = ws.getEntity(entityCode); |
914 |
store = stores.get(entity.getEntityName()); |
915 |
if (store == null) { |
916 |
store = ws.openFeatureStore(entity.getEntityName(), false);
|
917 |
stores.put(entity.getEntityName(), store); |
918 |
} |
919 |
Feature feature = store.createNewFeature(json); |
920 |
Geometry geom = feature.getDefaultGeometry(); |
921 |
env.add(geom); |
922 |
} |
923 |
} catch (Exception ex) { |
924 |
|
925 |
} |
926 |
} |
927 |
} finally {
|
928 |
for (FeatureStore value : stores.values()) {
|
929 |
DisposeUtils.disposeQuietly(value); |
930 |
} |
931 |
stores = null;
|
932 |
} |
933 |
if (!env.isEmpty()) {
|
934 |
return env.getBox2D();
|
935 |
} |
936 |
} |
937 |
return null; |
938 |
} |
939 |
|
940 |
private Geometry getGeometryOfSelectedChange() {
|
941 |
Geometry geom = null;
|
942 |
try {
|
943 |
if( this.tblLocalChanges.getSelectedRowCount()>1 && this.tblLocalChanges.getSelectedRowCount()<MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) { |
944 |
for (int selectedRow : this.tblLocalChanges.getSelectedRows()) { |
945 |
OnlineWorkingcopyChange change = changes.get64(selectedRow); |
946 |
Feature feature = change.getRelatedFeature(); |
947 |
Geometry currentGeom = feature.getDefaultGeometry(); |
948 |
if( currentGeom!=null ) { |
949 |
if( geom == null ) { |
950 |
int type = currentGeom.getType();
|
951 |
if( GeometryUtils.isSubtype(Geometry.TYPES.POINT, type) || GeometryUtils.isSubtype(Geometry.TYPES.MULTIPOINT, type)) {
|
952 |
geom = GeometryLocator.getGeometryManager().createMultiPoint(currentGeom.getGeometryType().getSubType()); |
953 |
} else if( GeometryUtils.isSubtype(Geometry.TYPES.LINE, type) || GeometryUtils.isSubtype(Geometry.TYPES.MULTILINE, type)) { |
954 |
geom = GeometryLocator.getGeometryManager().createMultiCurve(currentGeom.getGeometryType().getSubType()); |
955 |
} else if( GeometryUtils.isSubtype(Geometry.TYPES.SURFACE, type) || GeometryUtils.isSubtype(Geometry.TYPES.MULTISURFACE, type)) { |
956 |
geom = GeometryLocator.getGeometryManager().createMultiSurface(currentGeom.getGeometryType().getSubType()); |
957 |
} else {
|
958 |
return geom;
|
959 |
} |
960 |
} |
961 |
((MultiPrimitive)geom).addPrimitives(currentGeom); |
962 |
} |
963 |
} |
964 |
} else {
|
965 |
int selected = this.tblLocalChanges.getSelectedRow(); |
966 |
if(selected >= 0){ |
967 |
OnlineWorkingcopyChange change = changes.get64(selected); |
968 |
try {
|
969 |
Feature feature = change.getRelatedFeature(); |
970 |
geom = feature.getDefaultGeometry(); |
971 |
} catch (Exception ex){ |
972 |
|
973 |
} |
974 |
} |
975 |
} |
976 |
return geom;
|
977 |
} catch (Exception ex) { |
978 |
return geom;
|
979 |
} |
980 |
} |
981 |
|
982 |
private Geometry getOriginalGeometryOfSelectedChange() {
|
983 |
Geometry geom = null;
|
984 |
try {
|
985 |
if( this.tblLocalChanges.getSelectedRowCount()>1 && this.tblLocalChanges.getSelectedRowCount()<MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) { |
986 |
for (int selectedRow : this.tblLocalChanges.getSelectedRows()) { |
987 |
OnlineWorkingcopyChange change = changes.get64(selectedRow); |
988 |
try {
|
989 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
990 |
if(ws!=null) { |
991 |
JsonObject json = change.getDataAsJson(); |
992 |
String entityCode = change.getEntityCode();
|
993 |
OnlineEntity entity = ws.getEntity(entityCode); |
994 |
FeatureStore store = ws.openFeatureStore(entity.getEntityName(),false);
|
995 |
Feature feature = store.createNewFeature(json); |
996 |
Geometry currentGeom = feature.getDefaultGeometry(); |
997 |
if( currentGeom!=null ) { |
998 |
if( geom == null ) { |
999 |
int type = currentGeom.getType();
|
1000 |
if( GeometryUtils.isSubtype(Geometry.TYPES.POINT, type) || GeometryUtils.isSubtype(Geometry.TYPES.MULTIPOINT, type)) {
|
1001 |
geom = GeometryLocator.getGeometryManager().createMultiPoint(currentGeom.getGeometryType().getSubType()); |
1002 |
} else if( GeometryUtils.isSubtype(Geometry.TYPES.LINE, type) || GeometryUtils.isSubtype(Geometry.TYPES.MULTILINE, type)) { |
1003 |
geom = GeometryLocator.getGeometryManager().createMultiCurve(currentGeom.getGeometryType().getSubType()); |
1004 |
} else if( GeometryUtils.isSubtype(Geometry.TYPES.SURFACE, type) || GeometryUtils.isSubtype(Geometry.TYPES.MULTISURFACE, type)) { |
1005 |
geom = GeometryLocator.getGeometryManager().createMultiSurface(currentGeom.getGeometryType().getSubType()); |
1006 |
} else {
|
1007 |
return geom;
|
1008 |
} |
1009 |
} |
1010 |
((MultiPrimitive)geom).addPrimitives(currentGeom); |
1011 |
} |
1012 |
} |
1013 |
} catch (Exception ex){ |
1014 |
|
1015 |
} |
1016 |
} |
1017 |
} else {
|
1018 |
int selected = this.tblLocalChanges.getSelectedRow(); |
1019 |
if(selected >= 0){ |
1020 |
OnlineWorkingcopyChange change = changes.get64(selected); |
1021 |
try {
|
1022 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
1023 |
if(ws!=null) { |
1024 |
JsonObject json = change.getDataAsJson(); |
1025 |
String entityCode = change.getEntityCode();
|
1026 |
OnlineEntity entity = ws.getEntity(entityCode); |
1027 |
FeatureStore store = ws.openFeatureStore(entity.getEntityName(),false);
|
1028 |
Feature feature = store.createNewFeature(json); |
1029 |
geom = feature.getDefaultGeometry(); |
1030 |
} |
1031 |
} catch (Exception ex){ |
1032 |
|
1033 |
} |
1034 |
} |
1035 |
} |
1036 |
return geom;
|
1037 |
} catch (Exception ex) { |
1038 |
return geom;
|
1039 |
} |
1040 |
} |
1041 |
|
1042 |
private Envelope getEnvelopeOfAllLocalChanges() {
|
1043 |
Envelope env = GeometryUtils.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
1044 |
try {
|
1045 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
1046 |
for (int i = 0; i < changes.size64(); i++) { |
1047 |
OnlineWorkingcopyChange change = changes.get64(i); |
1048 |
Geometry currentGeom = change.getRelatedFeature().getDefaultGeometry(); |
1049 |
env.add(currentGeom); |
1050 |
if (ws != null) { |
1051 |
try {
|
1052 |
JsonObject json = change.getDataAsJson(); |
1053 |
String entityCode = change.getEntityCode();
|
1054 |
OnlineEntity entity = ws.getEntity(entityCode); |
1055 |
FeatureStore store = ws.openFeatureStore(entity.getEntityName(), false);
|
1056 |
Feature feature = store.createNewFeature(json); |
1057 |
Geometry originalGeom = feature.getDefaultGeometry(); |
1058 |
env.add(originalGeom); |
1059 |
} catch (Exception ex) { |
1060 |
continue;
|
1061 |
} |
1062 |
} |
1063 |
} |
1064 |
return env;
|
1065 |
} catch (Exception ex) { |
1066 |
return env;
|
1067 |
} |
1068 |
} |
1069 |
|
1070 |
|
1071 |
private FeatureStore getStoreOfSelectedChange() {
|
1072 |
FeatureStore store = null;
|
1073 |
int selected = this.tblLocalChanges.getSelectedRow(); |
1074 |
if(selected >= 0){ |
1075 |
OnlineWorkingcopyChange change = changes.get64(selected); |
1076 |
try {
|
1077 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
1078 |
if(ws!=null) { |
1079 |
String entityCode = change.getEntityCode();
|
1080 |
OnlineEntity entity = ws.getEntity(entityCode); |
1081 |
store = ws.openFeatureStore(entity.getEntityName(),false);
|
1082 |
} |
1083 |
} catch (Exception ex){ |
1084 |
|
1085 |
} |
1086 |
} |
1087 |
return store;
|
1088 |
} |
1089 |
|
1090 |
private void doZoomToSelectedChange() { |
1091 |
cleanHighligthed(); |
1092 |
// OnlineManager manager = OnlineLocator.getOnlineManager();
|
1093 |
OnlineSwingManager swingManager = OnlineSwingLocator.getOnlineSwingManager(); |
1094 |
OnlineSwingServices services =swingManager.getDefaultServices(); |
1095 |
|
1096 |
if(tblLocalChanges.getSelectionModel().isSelectionEmpty()){
|
1097 |
FeatureStore store = this.context.getWorkspaceStoreOfSelectedEntity();
|
1098 |
if(store == null){ |
1099 |
return;
|
1100 |
} |
1101 |
Envelope env = getEnvelopeOfAllLocalChanges(); |
1102 |
services.zoomViewsHavingAStoreToGeometry(store, env.getBox2D()); |
1103 |
return;
|
1104 |
} |
1105 |
|
1106 |
FeatureStore store = getStoreOfSelectedChange(); |
1107 |
if( this.tblLocalChanges.getSelectedRowCount() > MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) { |
1108 |
Geometry geom = getBBoxOfSelectedChanges(); |
1109 |
Geometry originalGeom = getOriginalBBoxOfSelectedChanges(); |
1110 |
services.zoomViewsHavingAStoreToGeometry(store, OnlineSwingCommons.createBBox(geom, originalGeom)); |
1111 |
this.context.message("_Too_many_items_selected"); |
1112 |
} else {
|
1113 |
Geometry geom = getGeometryOfSelectedChange(); |
1114 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange(); |
1115 |
services.zoomViewsHavingAStoreToGeometry(store, OnlineSwingCommons.createBBox(geom, originalGeom)); |
1116 |
if(geom != null){ |
1117 |
services.highlight(HIGHLIGHT_WORKSPACE, geom, store); |
1118 |
} |
1119 |
if(originalGeom != null){ |
1120 |
services.highlight(HIGHLIGHT_WORKSPACE_PREVIOUS, originalGeom, store); |
1121 |
} |
1122 |
} |
1123 |
} |
1124 |
|
1125 |
private void doCenterToSelectedChange() { |
1126 |
cleanHighligthed(); |
1127 |
OnlineSwingManager swingManager = OnlineSwingLocator.getOnlineSwingManager(); |
1128 |
OnlineSwingServices services =swingManager.getDefaultServices(); |
1129 |
|
1130 |
if(tblLocalChanges.getSelectionModel().isSelectionEmpty()){
|
1131 |
FeatureStore store = this.context.getWorkspaceStoreOfSelectedEntity();
|
1132 |
if(store == null){ |
1133 |
return;
|
1134 |
} |
1135 |
Envelope env = getEnvelopeOfAllLocalChanges(); |
1136 |
services.centerViewsHavingAStoreToGeometry(store, env.getBox2D()); |
1137 |
return;
|
1138 |
} |
1139 |
|
1140 |
FeatureStore store = getStoreOfSelectedChange(); |
1141 |
|
1142 |
if( this.tblLocalChanges.getSelectedRowCount() > MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) { |
1143 |
Geometry geom = getBBoxOfSelectedChanges(); |
1144 |
Geometry originalGeom = getOriginalBBoxOfSelectedChanges(); |
1145 |
services.centerViewsHavingAStoreToGeometry(store, OnlineSwingCommons.createBBox(geom, originalGeom)); |
1146 |
this.context.message("_Too_many_items_selected"); |
1147 |
} else {
|
1148 |
Geometry geom = getGeometryOfSelectedChange(); |
1149 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange(); |
1150 |
services.centerViewsHavingAStoreToGeometry(store, OnlineSwingCommons.createBBox(geom, originalGeom)); |
1151 |
if(geom != null){ |
1152 |
services.highlight(HIGHLIGHT_WORKSPACE, geom, store); |
1153 |
} |
1154 |
if(originalGeom != null){ |
1155 |
services.highlight(HIGHLIGHT_WORKSPACE_PREVIOUS, originalGeom, store); |
1156 |
} |
1157 |
} |
1158 |
} |
1159 |
|
1160 |
private void doHighLightSelectedChange() { |
1161 |
cleanHighligthed(); |
1162 |
// OnlineManager manager = OnlineLocator.getOnlineManager();
|
1163 |
OnlineSwingManager swingManager = OnlineSwingLocator.getOnlineSwingManager(); |
1164 |
OnlineSwingServices services =swingManager.getDefaultServices(); |
1165 |
|
1166 |
FeatureStore store = getStoreOfSelectedChange(); |
1167 |
|
1168 |
if( this.tblLocalChanges.getSelectedRowCount() > MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) { |
1169 |
this.context.message("_Too_many_items_selected"); |
1170 |
} else {
|
1171 |
Geometry geom = getGeometryOfSelectedChange(); |
1172 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange(); |
1173 |
if(geom != null){ |
1174 |
services.highlight(HIGHLIGHT_WORKSPACE, geom, store); |
1175 |
} |
1176 |
if(originalGeom != null){ |
1177 |
services.highlight(HIGHLIGHT_WORKSPACE_PREVIOUS, originalGeom, store); |
1178 |
} |
1179 |
} |
1180 |
} |
1181 |
|
1182 |
private List<String> getEntityCodes(List<OnlineEntity> entities) { |
1183 |
List<String> res = new ArrayList(); |
1184 |
for (OnlineEntity entity : entities) {
|
1185 |
res.add(entity.getEntityCode()); |
1186 |
} |
1187 |
return res;
|
1188 |
} |
1189 |
|
1190 |
public void selectOnlyAEntity(OnlineEntity entity){ |
1191 |
context.getEntitySelector().clearChecks(); |
1192 |
context.getEntitySelector().check(entity); |
1193 |
} |
1194 |
|
1195 |
public void selectOnlyAEntity(List<OnlineEntity> entities){ |
1196 |
context.getEntitySelector().clearChecks(); |
1197 |
for (OnlineEntity entity : entities) {
|
1198 |
context.getEntitySelector().check(entity); |
1199 |
} |
1200 |
} |
1201 |
|
1202 |
@Override
|
1203 |
protected void doDispose() throws BaseException { |
1204 |
// DisposeUtils.disposeQuietly(entitySelector);
|
1205 |
} |
1206 |
|
1207 |
private void doCheckRecomendedEntities() { |
1208 |
final OnlineWorkingcopy workspace = this.getUndisposableWorkspace(); |
1209 |
if( workspace==null ) { |
1210 |
return;
|
1211 |
} |
1212 |
Set<String> commitEntities = new HashSet<>(); |
1213 |
Collection<OnlineEntity> entities = context.getEntitySelector().getEntities();
|
1214 |
for (OnlineEntity entity : entities) {
|
1215 |
if (workspace.existsInWorkspace(entity)) {
|
1216 |
OnlineEntity lentity = workspace.getWorkspaceEntityByCode(entity.getEntityCode()); |
1217 |
switch (lentity.getState()) {
|
1218 |
case OnlineManager.STATE_LOCAL_MODIFIED:
|
1219 |
case OnlineManager.STATE_LOCAL_NEW:
|
1220 |
default:
|
1221 |
commitEntities.add(entity.getEntityCode()); |
1222 |
break;
|
1223 |
case OnlineManager.STATE_LOCAL_UNMODIFIED:
|
1224 |
case OnlineManager.STATE_REMOTE_NEW:
|
1225 |
case OnlineManager.STATE_CONFLICT:
|
1226 |
case OnlineManager.STATE_CORRUPT:
|
1227 |
case OnlineManager.STATE_CORRUPT+OnlineManager.STATE_DISCONNECTED:
|
1228 |
case OnlineManager.STATE_DISCONNECTED:
|
1229 |
case OnlineManager.STATE_LOCAL_OUTDATED:
|
1230 |
case OnlineManager.STATE_LOCAL_OUTDATED_AND_MODIFIED:
|
1231 |
break;
|
1232 |
} |
1233 |
} |
1234 |
} |
1235 |
context.getEntitySelector().setCheck(commitEntities, true);
|
1236 |
} |
1237 |
|
1238 |
private boolean areCorruptOrDisconnectedEntities(List<OnlineEntity> entities) { |
1239 |
for (OnlineEntity entity : entities) {
|
1240 |
if( entity instanceof OnlineEntity ) { |
1241 |
OnlineEntity lentity = (OnlineEntity) entity; |
1242 |
int maskState = lentity.getState();
|
1243 |
if( (maskState & STATE_DISCONNECTED) == STATE_DISCONNECTED ||
|
1244 |
(maskState & STATE_CORRUPT) == STATE_CORRUPT) { |
1245 |
return true; |
1246 |
} |
1247 |
} |
1248 |
} |
1249 |
return false; |
1250 |
} |
1251 |
|
1252 |
private boolean areConflictEntities(List<OnlineEntity> entities) { |
1253 |
for (OnlineEntity entity : entities) {
|
1254 |
if( entity instanceof OnlineEntity ) { |
1255 |
OnlineEntity lentity = (OnlineEntity) entity; |
1256 |
int maskState = lentity.getState();
|
1257 |
if( (maskState & STATE_CONFLICT) == STATE_CONFLICT) {
|
1258 |
return true; |
1259 |
} |
1260 |
} |
1261 |
} |
1262 |
return false; |
1263 |
} |
1264 |
} |