Revision 9512 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/OnlineJChangesImpl.java
OnlineJChangesImpl.java | ||
---|---|---|
25 | 25 |
import java.awt.Color; |
26 | 26 |
import java.awt.Cursor; |
27 | 27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
|
28 | 29 |
import java.awt.event.ComponentAdapter; |
29 | 30 |
import java.awt.event.ComponentEvent; |
30 | 31 |
import java.sql.Timestamp; |
32 |
import java.util.ArrayList; |
|
31 | 33 |
import java.util.Collection; |
32 | 34 |
import java.util.Collections; |
33 | 35 |
import java.util.HashSet; |
34 | 36 |
import java.util.List; |
35 | 37 |
import java.util.Map; |
36 | 38 |
import java.util.Set; |
39 |
import javax.swing.DefaultComboBoxModel; |
|
37 | 40 |
import javax.swing.ImageIcon; |
38 |
import javax.swing.JButton; |
|
39 | 41 |
import javax.swing.JComponent; |
40 | 42 |
import javax.swing.JSplitPane; |
41 | 43 |
import javax.swing.SwingUtilities; |
42 | 44 |
import javax.swing.Timer; |
43 | 45 |
import javax.swing.event.ChangeEvent; |
44 | 46 |
import org.apache.commons.lang3.StringUtils; |
47 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
48 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
49 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
50 |
import org.gvsig.online.lib.api.OnlineLayer; |
|
45 | 51 |
import org.gvsig.online.lib.api.OnlineManager; |
52 |
import org.gvsig.online.lib.api.OnlineProject; |
|
46 | 53 |
import org.gvsig.online.lib.api.OnlineRuntimeException; |
47 | 54 |
import org.gvsig.online.lib.api.workingcopy.OnlineEntity; |
48 | 55 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
49 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChange; |
|
50 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChanges; |
|
56 |
import org.gvsig.online.lib.api.workingcopy.WorkingArea; |
|
51 | 57 |
import org.gvsig.online.swing.api.OnlineEntitySelectorController; |
52 | 58 |
import org.gvsig.online.swing.api.OnlineJChanges; |
53 | 59 |
import org.gvsig.online.swing.api.OnlineSwingLocator; |
54 | 60 |
import org.gvsig.online.swing.api.OnlineSwingManager; |
61 |
import org.gvsig.online.swing.api.OnlineSwingServices; |
|
55 | 62 |
import org.gvsig.online.swing.impl.OnlineSwingCommons; |
56 | 63 |
import static org.gvsig.online.swing.impl.OnlineSwingCommons.notInSwingThreadInvokeLater; |
57 | 64 |
import static org.gvsig.online.swing.impl.OnlineSwingCommons.showAuthenticationErrors; |
... | ... | |
59 | 66 |
import org.gvsig.online.swing.impl.OnlineSwingManagerImpl; |
60 | 67 |
import static org.gvsig.online.swing.impl.OnlineSwingManagerImpl.ICON_GROUP_NAME; |
61 | 68 |
import static org.gvsig.online.swing.impl.OnlineSwingManagerImpl.ICON_PROVIDER_NAME; |
69 |
import org.gvsig.online.swing.impl.workingarea.WorkingAreaPickerControllerImpl; |
|
62 | 70 |
import org.gvsig.tools.ToolsLocator; |
63 | 71 |
import org.gvsig.tools.dispose.DisposeUtils; |
64 | 72 |
import org.gvsig.tools.i18n.I18nManager; |
... | ... | |
70 | 78 |
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager; |
71 | 79 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
72 | 80 |
import org.gvsig.tools.task.SimpleTaskStatus; |
81 |
import org.gvsig.tools.util.LabeledValue; |
|
82 |
import org.gvsig.tools.util.LabeledValueImpl; |
|
73 | 83 |
import org.gvsig.tools.util.PropertiesSupport; |
74 | 84 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
75 | 85 |
import org.slf4j.Logger; |
... | ... | |
87 | 97 |
|
88 | 98 |
private static final Logger LOGGER = LoggerFactory.getLogger(OnlineJChangesImpl.class); |
89 | 99 |
|
100 |
private static final int ZONE_ONLY_CHANGES = 0; |
|
101 |
private static final int ZONE_CHANGES_AND_WORKING_AREA = 1; |
|
102 |
|
|
90 | 103 |
public static final int NOTCLOSABLE = 64; |
91 | 104 |
public static final int RESIZABLE = 1; |
92 | 105 |
public static final int MAXIMIZABLE = 2; |
... | ... | |
110 | 123 |
private PropertiesSupportHelper propertiesSupport; |
111 | 124 |
private List<String> defaultTablesSelection; |
112 | 125 |
private OnlineEntitySelectorController entitySelector; |
126 |
private WorkingAreaPickerControllerImpl workingAreaPicker; |
|
113 | 127 |
|
114 | 128 |
public OnlineJChangesImpl() { |
115 | 129 |
this(null,null,null, null); |
... | ... | |
158 | 172 |
swingManager.translate(this.btnLocalUnCheckAllEntities); |
159 | 173 |
swingManager.translate(this.btnLocalCollapseAllEntities); |
160 | 174 |
swingManager.translate(this.btnLocalExpandAllEntities); |
161 |
swingManager.translate(this.btnRemoteTablesReload);
|
|
175 |
swingManager.translate(this.btnEntitiesReload);
|
|
162 | 176 |
|
177 |
swingManager.translate(this.lblSynchorizationZone); |
|
178 |
swingManager.translate(this.cboSynchorizationZone); |
|
179 |
|
|
163 | 180 |
} |
164 | 181 |
|
165 | 182 |
private void initComponents() { |
166 | 183 |
OnlineSwingManager onlineSwingManager = OnlineSwingLocator.getOnlineSwingManager(); |
167 | 184 |
TaskStatusSwingManager taskStatusManager = ToolsSwingLocator.getTaskStatusSwingManager(); |
185 |
OnlineSwingServices onlineservices = OnlineSwingLocator.getOnlineSwingManager().getDefaultServices(); |
|
168 | 186 |
|
169 | 187 |
this.addComponentListener(new ComponentAdapter() { |
170 | 188 |
@Override |
... | ... | |
245 | 263 |
break; |
246 | 264 |
case OnlineEntitySelectorController.ACTION_CHECK_ID: |
247 | 265 |
localChangesController.doUpdateTableLocalChanges(); |
266 |
remoteChangesController.doReloadChanges(); |
|
248 | 267 |
doUpdateComponents(); |
249 | 268 |
break; |
250 | 269 |
case OnlineEntitySelectorController.ACTION_RELOAD_ID: |
251 | 270 |
localChangesController.doUpdateTableLocalChanges(); |
271 |
remoteChangesController.doReloadChanges(); |
|
252 | 272 |
doUpdateComponents(); |
253 | 273 |
break; |
254 | 274 |
} |
255 | 275 |
}); |
256 | 276 |
|
277 |
this.workingAreaPicker = new WorkingAreaPickerControllerImpl( |
|
278 |
() -> {return getWorkspace().getSite();}, |
|
279 |
txtWorkingAreaLabel, |
|
280 |
txtWorkingArea, |
|
281 |
btnWorkingAreaFromView, |
|
282 |
btnWorkingAreaDialog, |
|
283 |
btnWorkingAreaHistory, |
|
284 |
btnWorkingAreaBookmarks, |
|
285 |
() -> { |
|
286 |
LabeledValue<MapControl> n = onlineservices.getActiveMapControl(); |
|
287 |
return (n == null) ? null : n.getValue(); |
|
288 |
}, |
|
289 |
() -> { |
|
290 |
List<OnlineLayer> selectedLayers = getSelectedLayers(); |
|
291 |
if (selectedLayers.isEmpty()) { |
|
292 |
return null; |
|
293 |
} |
|
294 |
return selectedLayers; |
|
295 |
} |
|
296 |
); |
|
297 |
this.workingAreaPicker.addChangeListener((ChangeEvent e) -> { |
|
298 |
doUpdateComponents(); |
|
299 |
}); |
|
257 | 300 |
|
301 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
302 |
DefaultComboBoxModel<LabeledValue<Integer>> zoneModel = new DefaultComboBoxModel<>(); |
|
303 |
zoneModel.addElement(new LabeledValueImpl<>(i18n.getTranslation("_Only_changes_zone"), ZONE_ONLY_CHANGES)); |
|
304 |
zoneModel.addElement(new LabeledValueImpl<>(i18n.getTranslation("_Changes_zone_and_working_area"), ZONE_CHANGES_AND_WORKING_AREA)); |
|
305 |
this.cboSynchorizationZone.setModel(zoneModel); |
|
306 |
this.cboSynchorizationZone.addActionListener(new ActionListener() { |
|
307 |
@Override |
|
308 |
public void actionPerformed(ActionEvent e) { |
|
309 |
doUpdateComponents(); |
|
310 |
} |
|
311 |
}); |
|
312 |
this.cboSynchorizationZone.setSelectedIndex(0); |
|
258 | 313 |
|
259 | 314 |
this.localChangesController = new LocalChangesController( |
260 | 315 |
this, |
... | ... | |
303 | 358 |
doCheckRecomendedEntities(); |
304 | 359 |
}); |
305 | 360 |
|
306 |
this.btnRemoteTablesReload.addActionListener((ActionEvent e) -> {
|
|
361 |
this.btnEntitiesReload.addActionListener((ActionEvent e) -> {
|
|
307 | 362 |
doReloadTables(); |
308 |
remoteChangesController.doReloadChanges(); |
|
363 |
// remoteChangesController.doReloadChanges();
|
|
309 | 364 |
}); |
310 | 365 |
|
311 | 366 |
this.btnSynchronize.addActionListener((ActionEvent e) -> { |
312 | 367 |
doSynchronize(); |
313 |
remoteChangesController.doReloadChanges(); |
|
314 | 368 |
}); |
315 | 369 |
|
316 |
|
|
317 | 370 |
ToolsSwingUtils.ensureRowsCols(this, 14, 100); |
318 | 371 |
} |
319 | 372 |
|
373 |
private List<OnlineLayer> getSelectedLayers(){ |
|
374 |
List<OnlineEntity> entities = this.getEntitySelector().getCheckedEntities(); |
|
375 |
OnlineProject project = this.getWorkspace().getProject(); |
|
376 |
List<OnlineLayer> result = new ArrayList<>(); |
|
377 |
for (OnlineEntity entity : entities) { |
|
378 |
OnlineLayer layer = project.getLayer( |
|
379 |
(OnlineLayer t) -> StringUtils.equalsIgnoreCase(t.getName(), entity.getEntityName()), |
|
380 |
null |
|
381 |
); |
|
382 |
result.add(layer); |
|
383 |
} |
|
384 |
return result; |
|
385 |
} |
|
386 |
|
|
320 | 387 |
/* friend */ void doUpdateComponents() { |
321 | 388 |
if( notInSwingThreadInvokeLater(() -> {doUpdateComponents();}) ) { |
322 | 389 |
return; |
323 | 390 |
} |
324 |
|
|
325 | 391 |
if(this.localChangesController != null){ |
326 | 392 |
this.localChangesController.doUpdateComponents(); |
327 | 393 |
} |
328 | 394 |
if(this.remoteChangesController != null){ |
329 | 395 |
this.remoteChangesController.doUpdateComponents(); |
330 | 396 |
} |
397 |
OnlineWorkingcopy ws = this.getWorkspace(); |
|
398 |
if(ws == null) { |
|
399 |
this.cboSynchorizationZone.setEnabled(false); |
|
400 |
this.workingAreaPicker.setEnabled(false); |
|
401 |
this.btnSynchronize.setEnabled(false); |
|
402 |
this.btnEntitiesReload.setEnabled(false); |
|
403 |
return; |
|
404 |
} |
|
405 |
LabeledValue<Integer> zoneMode = (LabeledValue<Integer>) this.cboSynchorizationZone.getSelectedItem(); |
|
406 |
if(zoneMode == null) { |
|
407 |
this.cboSynchorizationZone.setEnabled(false); |
|
408 |
this.workingAreaPicker.setEnabled(false); |
|
409 |
this.btnSynchronize.setEnabled(false); |
|
410 |
this.btnEntitiesReload.setEnabled(false); |
|
411 |
return; |
|
412 |
} |
|
413 |
this.cboSynchorizationZone.setEnabled(true); |
|
414 |
this.btnSynchronize.setEnabled(true); |
|
415 |
this.btnEntitiesReload.setEnabled(true); |
|
416 |
switch (zoneMode.getValue()) { |
|
417 |
case ZONE_CHANGES_AND_WORKING_AREA: |
|
418 |
this.workingAreaPicker.setEnabled(true); |
|
419 |
break; |
|
420 |
case ZONE_ONLY_CHANGES: |
|
421 |
default: |
|
422 |
this.workingAreaPicker.setEnabled(false); |
|
423 |
break; |
|
424 |
} |
|
331 | 425 |
} |
332 | 426 |
|
333 | 427 |
public void updateLocalChangesTable() { |
... | ... | |
375 | 469 |
// showAuthenticationRequiredMessage("_Online_Changes"); |
376 | 470 |
// this.workspacePicker.set(null); |
377 | 471 |
// doChangeWorkspace(); |
472 |
this.workingAreaPicker.set(ws.getCurrentWorkingArea()); |
|
378 | 473 |
} catch (OnlineRuntimeException e1) { |
379 | 474 |
LOGGER.warn("Can't set workspace.", e1); |
380 | 475 |
if (showAuthenticationErrors("_Online_Changes", e1)) { |
... | ... | |
388 | 483 |
} |
389 | 484 |
} |
390 | 485 |
|
391 |
private void doReloadTables() {
|
|
486 |
public void doReloadTables() {
|
|
392 | 487 |
OnlineWorkingcopy ws = this.getUndisposableWorkspace(); |
393 | 488 |
if (ws == null) { |
394 | 489 |
this.entitySelector.setWorkspace(null); |
... | ... | |
404 | 499 |
this.entitySelector.setWorkspace(null); |
405 | 500 |
return; |
406 | 501 |
} |
502 |
LabeledValue<Integer> zoneMode = (LabeledValue<Integer>) this.cboSynchorizationZone.getSelectedItem(); |
|
503 |
int zone = ZONE_ONLY_CHANGES; |
|
504 |
if(zoneMode != null){ |
|
505 |
zone = zoneMode.getValue(); |
|
506 |
} |
|
507 |
WorkingArea workingArea = this.workingAreaPicker.get(); |
|
508 |
Envelope env = null; |
|
509 |
switch(zone){ |
|
510 |
case ZONE_CHANGES_AND_WORKING_AREA: |
|
511 |
if(workingArea != null) { |
|
512 |
env = workingArea.getValue(); |
|
513 |
} |
|
514 |
break; |
|
515 |
case ZONE_ONLY_CHANGES: |
|
516 |
default: |
|
517 |
break; |
|
518 |
} |
|
519 |
|
|
407 | 520 |
List<OnlineEntity> checkedEntities = this.entitySelector.getCheckedEntities(); |
408 | 521 |
for (OnlineEntity checkedEntity : checkedEntities) { |
409 |
ws.synchronize(checkedEntity, this.taskStatus); |
|
522 |
ws.synchronize(checkedEntity, env, this.taskStatus);
|
|
410 | 523 |
} |
524 |
|
|
525 |
doReloadTables(); |
|
526 |
localChangesController.doUpdateTableLocalChanges(); |
|
527 |
remoteChangesController.doReloadChanges(); |
|
528 |
remoteChangesController.doUpdateComponents(); |
|
411 | 529 |
|
412 | 530 |
} |
413 | 531 |
|
... | ... | |
562 | 680 |
public OnlineEntitySelectorController getEntitySelector() { |
563 | 681 |
return entitySelector; |
564 | 682 |
} |
565 |
private void doCheckRecomendedEntities() { |
|
683 |
|
|
684 |
private void doCheckRecomendedEntities() { |
|
566 | 685 |
final OnlineWorkingcopy workspace = this.getUndisposableWorkspace(); |
567 | 686 |
if( workspace==null ) { |
568 | 687 |
return; |
... | ... | |
590 | 709 |
this.entitySelector.setCheck(updateEntities, true); |
591 | 710 |
} |
592 | 711 |
|
712 |
protected FeatureStore getWorkspaceStoreOfSelectedEntity() { |
|
713 |
OnlineEntity entity = this.getEntitySelector().getSelectedEntity(); |
|
714 |
FeatureStore store = null; |
|
715 |
|
|
716 |
if(entity != null){ |
|
717 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
|
718 |
store = ws.openFeatureStore(entity.getEntityName(),false); |
|
719 |
} |
|
720 |
return store; |
|
721 |
} |
|
722 |
|
|
593 | 723 |
} |
Also available in: Unified diff