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/LocalChangesController.java
LocalChangesController.java | ||
---|---|---|
29 | 29 |
import java.awt.event.KeyEvent; |
30 | 30 |
import java.util.ArrayList; |
31 | 31 |
import java.util.Collection; |
32 |
import java.util.HashMap; |
|
32 | 33 |
import java.util.HashSet; |
33 | 34 |
import java.util.Iterator; |
34 | 35 |
import java.util.List; |
36 |
import java.util.Map; |
|
35 | 37 |
import java.util.Set; |
36 | 38 |
import javax.json.JsonObject; |
37 | 39 |
import javax.swing.JButton; |
... | ... | |
63 | 65 |
import static org.gvsig.online.lib.api.OnlineManager.OP_DELETE; |
64 | 66 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_CONFLICT; |
65 | 67 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_CORRUPT; |
68 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_DISCONNECTED; |
|
66 | 69 |
import org.gvsig.online.lib.api.OnlineRuntimeException; |
67 | 70 |
import org.gvsig.online.lib.api.workingcopy.OnlineChange; |
68 | 71 |
import org.gvsig.online.lib.api.workingcopy.OnlineEntity; |
69 | 72 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
70 | 73 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChange; |
71 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChanges; |
|
72 | 74 |
import org.gvsig.online.swing.api.OnlineSwingLocator; |
73 | 75 |
import org.gvsig.online.swing.api.OnlineSwingManager; |
74 | 76 |
import org.gvsig.online.swing.api.OnlineSwingServices; |
... | ... | |
92 | 94 |
import org.gvsig.tools.task.UserCancelTaskException; |
93 | 95 |
import org.slf4j.Logger; |
94 | 96 |
import org.slf4j.LoggerFactory; |
97 |
import org.gvsig.online.lib.api.workingcopy.OnlineChanges; |
|
95 | 98 |
|
96 | 99 |
/** |
97 | 100 |
* |
... | ... | |
99 | 102 |
*/ |
100 | 103 |
public class LocalChangesController extends AbstractDisposable { |
101 | 104 |
private static final Logger LOGGER = LoggerFactory.getLogger(LocalChangesController.class); |
105 |
private static final int MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES = 200; |
|
102 | 106 |
|
103 | 107 |
// private final JButton btnLocalCheckRecomendedEntities; |
104 | 108 |
// private final JButton btnLocalCheckAllEntities; |
... | ... | |
119 | 123 |
private final JButton btnLocalHighlight; |
120 | 124 |
private final JLabel lblLocalChangesCount; |
121 | 125 |
|
122 |
private OnlineWorkingcopyChanges<OnlineWorkingcopyChange> changes;
|
|
126 |
private OnlineChanges<OnlineWorkingcopyChange> changes; |
|
123 | 127 |
private LocalChangesTableModel localChangesTableModel; |
124 | 128 |
private List<OnlineEntity> entitiesWithSelectedChanges = null; |
125 | 129 |
|
... | ... | |
545 | 549 |
&& !isSelectionFromEntitiesEmpty |
546 | 550 |
) { |
547 | 551 |
MutableObject<String> msg = new MutableObject<>(); |
548 |
if( areCorruptOrDisconnectedEntities(checkedEntities) ) { |
|
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) ) { |
|
549 | 557 |
context.alert("_There_are_selected_corrupted_or_disconnected_entities"); |
550 | 558 |
this.btnLocalCommit.setEnabled(false); |
551 |
LOGGER.info("Can't enable commit (1.2). There are selected corrupted or disconnected entities.");
|
|
559 |
LOGGER.info("Can't enable commit (1.2). There are selected corrputed or diconnected entities.");
|
|
552 | 560 |
} else if (!ws.canUpload(msg, getEntityCodes(checkedEntities))) { |
553 | 561 |
context.alert(msg.getValue()); |
554 | 562 |
this.btnLocalCommit.setEnabled(false); |
... | ... | |
584 | 592 |
|
585 | 593 |
int row = this.tblLocalChanges.getSelectedRow(); |
586 | 594 |
if (!context.processing && row >= 0) { |
587 |
OnlineWorkingcopyChange change = this.changes.get64(row); |
|
588 |
// if (change.getOperation() != OP_ADD_ENTITY) { |
|
589 |
// enableShowForm = true; |
|
590 |
// } |
|
595 |
enableShowForm = true; |
|
591 | 596 |
} |
592 | 597 |
this.btnLocalShowForm.setEnabled(!context.processing && enableShowForm); |
593 | 598 |
|
... | ... | |
596 | 601 |
|
597 | 602 |
Geometry geom = getGeometryOfSelectedChange(); |
598 | 603 |
Geometry originalGeom = getOriginalGeometryOfSelectedChange(); |
599 |
this.btnLocalCenter.setEnabled(!context.processing && (geom != null || originalGeom != null)); |
|
604 |
this.btnLocalCenter.setEnabled(!context.processing); // && (geom != null || originalGeom != null));
|
|
600 | 605 |
this.btnLocalHighlight.setEnabled(!context.processing && (geom != null || originalGeom != null)); |
601 |
this.btnLocalZoom.setEnabled(!context.processing && (geom != null || originalGeom != null)); |
|
606 |
this.btnLocalZoom.setEnabled(!context.processing); // && (geom != null || originalGeom != null));
|
|
602 | 607 |
this.btnLocalCleanHighlighted.setEnabled(!context.processing); |
603 | 608 |
} catch (OnlineRuntimeException e1) { |
604 | 609 |
LOGGER.warn("Can't updating components.", e1); |
... | ... | |
892 | 897 |
|
893 | 898 |
private Geometry getOriginalBBoxOfSelectedChanges() { |
894 | 899 |
int[] selecteds = this.tblLocalChanges.getSelectedRows(); |
895 |
if(selecteds!=null && selecteds.length >= 0){
|
|
900 |
if(selecteds != null && selecteds.length >= 0) {
|
|
896 | 901 |
Envelope env = GeometryUtils.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
897 |
for (int i = 0; i < selecteds.length; i++) { |
|
898 |
int selected = selecteds[i]; |
|
899 |
OnlineWorkingcopyChange change = changes.get64(selected); |
|
900 |
try { |
|
901 |
OnlineWorkingcopy ws = getUndisposableWorkspace(); |
|
902 |
if(ws!=null) { |
|
903 |
JsonObject json = change.getDataAsJson(); |
|
904 |
String entityCode = change.getEntityCode(); |
|
905 |
OnlineEntity entity = ws.getEntity(entityCode); |
|
906 |
FeatureStore store = ws.openFeatureStore(entity.getEntityName(),false); |
|
907 |
Feature feature = store.createNewFeature(json); |
|
908 |
Geometry geom = feature.getDefaultGeometry(); |
|
909 |
env.add(geom); |
|
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 |
|
|
910 | 925 |
} |
911 |
} catch (Exception ex){ |
|
912 |
|
|
913 | 926 |
} |
927 |
} finally { |
|
928 |
for (FeatureStore value : stores.values()) { |
|
929 |
DisposeUtils.disposeQuietly(value); |
|
930 |
} |
|
931 |
stores = null; |
|
914 | 932 |
} |
915 |
if( !env.isEmpty() ) {
|
|
933 |
if (!env.isEmpty()) {
|
|
916 | 934 |
return env.getBox2D(); |
917 | 935 |
} |
918 | 936 |
} |
... | ... | |
922 | 940 |
private Geometry getGeometryOfSelectedChange() { |
923 | 941 |
Geometry geom = null; |
924 | 942 |
try { |
925 |
if( this.tblLocalChanges.getSelectedRowCount()>1 && this.tblLocalChanges.getSelectedRowCount()<200 ) {
|
|
943 |
if( this.tblLocalChanges.getSelectedRowCount()>1 && this.tblLocalChanges.getSelectedRowCount()<MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) {
|
|
926 | 944 |
for (int selectedRow : this.tblLocalChanges.getSelectedRows()) { |
927 | 945 |
OnlineWorkingcopyChange change = changes.get64(selectedRow); |
928 | 946 |
Feature feature = change.getRelatedFeature(); |
... | ... | |
964 | 982 |
private Geometry getOriginalGeometryOfSelectedChange() { |
965 | 983 |
Geometry geom = null; |
966 | 984 |
try { |
967 |
if( this.tblLocalChanges.getSelectedRowCount()>1 && this.tblLocalChanges.getSelectedRowCount()<200 ) {
|
|
985 |
if( this.tblLocalChanges.getSelectedRowCount()>1 && this.tblLocalChanges.getSelectedRowCount()<MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) {
|
|
968 | 986 |
for (int selectedRow : this.tblLocalChanges.getSelectedRows()) { |
969 | 987 |
OnlineWorkingcopyChange change = changes.get64(selectedRow); |
970 | 988 |
try { |
... | ... | |
1021 | 1039 |
} |
1022 | 1040 |
} |
1023 | 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 |
|
|
1024 | 1071 |
private FeatureStore getStoreOfSelectedChange() { |
1025 | 1072 |
FeatureStore store = null; |
1026 | 1073 |
int selected = this.tblLocalChanges.getSelectedRow(); |
... | ... | |
1046 | 1093 |
OnlineSwingManager swingManager = OnlineSwingLocator.getOnlineSwingManager(); |
1047 | 1094 |
OnlineSwingServices services =swingManager.getDefaultServices(); |
1048 | 1095 |
|
1049 |
FeatureStore store = getStoreOfSelectedChange(); |
|
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 |
} |
|
1050 | 1105 |
|
1051 |
if( this.tblLocalChanges.getSelectedRowCount() > 200 ) { |
|
1106 |
FeatureStore store = getStoreOfSelectedChange(); |
|
1107 |
if( this.tblLocalChanges.getSelectedRowCount() > MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) { |
|
1052 | 1108 |
Geometry geom = getBBoxOfSelectedChanges(); |
1053 | 1109 |
Geometry originalGeom = getOriginalBBoxOfSelectedChanges(); |
1054 | 1110 |
services.zoomViewsHavingAStoreToGeometry(store, OnlineSwingCommons.createBBox(geom, originalGeom)); |
... | ... | |
1068 | 1124 |
|
1069 | 1125 |
private void doCenterToSelectedChange() { |
1070 | 1126 |
cleanHighligthed(); |
1071 |
// OnlineManager manager = OnlineLocator.getOnlineManager(); |
|
1072 | 1127 |
OnlineSwingManager swingManager = OnlineSwingLocator.getOnlineSwingManager(); |
1073 | 1128 |
OnlineSwingServices services =swingManager.getDefaultServices(); |
1074 | 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 |
|
|
1075 | 1140 |
FeatureStore store = getStoreOfSelectedChange(); |
1076 | 1141 |
|
1077 |
if( this.tblLocalChanges.getSelectedRowCount() > 200 ) {
|
|
1142 |
if( this.tblLocalChanges.getSelectedRowCount() > MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) {
|
|
1078 | 1143 |
Geometry geom = getBBoxOfSelectedChanges(); |
1079 | 1144 |
Geometry originalGeom = getOriginalBBoxOfSelectedChanges(); |
1080 | 1145 |
services.centerViewsHavingAStoreToGeometry(store, OnlineSwingCommons.createBBox(geom, originalGeom)); |
... | ... | |
1100 | 1165 |
|
1101 | 1166 |
FeatureStore store = getStoreOfSelectedChange(); |
1102 | 1167 |
|
1103 |
if( this.tblLocalChanges.getSelectedRowCount() > 200 ) {
|
|
1168 |
if( this.tblLocalChanges.getSelectedRowCount() > MAX_SELECTED_ROWS_TO_SHOW_GEOMETRIES ) {
|
|
1104 | 1169 |
this.context.message("_Too_many_items_selected"); |
1105 | 1170 |
} else { |
1106 | 1171 |
Geometry geom = getGeometryOfSelectedChange(); |
... | ... | |
1175 | 1240 |
if( entity instanceof OnlineEntity ) { |
1176 | 1241 |
OnlineEntity lentity = (OnlineEntity) entity; |
1177 | 1242 |
int maskState = lentity.getState(); |
1178 |
if( (maskState & STATE_CONFLICT) == STATE_CONFLICT ||
|
|
1243 |
if( (maskState & STATE_DISCONNECTED) == STATE_DISCONNECTED ||
|
|
1179 | 1244 |
(maskState & STATE_CORRUPT) == STATE_CORRUPT) { |
1180 | 1245 |
return true; |
1181 | 1246 |
} |
... | ... | |
1183 | 1248 |
} |
1184 | 1249 |
return false; |
1185 | 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 |
} |
|
1186 | 1264 |
} |
Also available in: Unified diff