Revision 3950
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/workspace/FeatureStoreObserver.java | ||
---|---|---|
11 | 11 |
import static org.gvsig.fmap.dal.feature.FeatureStore.MODE_PASS_THROUGH; |
12 | 12 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
13 | 13 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
14 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
14 | 15 |
import org.gvsig.tools.observer.Observable; |
15 | 16 |
import org.gvsig.tools.observer.Observer; |
16 | 17 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
... | ... | |
46 | 47 |
|
47 | 48 |
@Override |
48 | 49 |
public void update(Observable observable, Object notification) { |
49 |
VCSGisWorkspace workspace; |
|
50 |
if (notification instanceof EditingNotification) { |
|
51 |
EditingNotification n = (EditingNotification) notification; |
|
52 |
if (n.getType().equals(EditingNotification.BEFORE_INSERT_FEATURE)) { |
|
53 |
FeatureStore store = n.getFeatureStore(); |
|
54 |
workspace = getWorkspace(store); |
|
55 |
if (workspace != null) { |
|
56 |
Feature feature = n.getFeature(); |
|
57 |
if (StringUtils.isBlank(feature.getString(FEATURECODE_FIELD_NAME)) && feature instanceof EditableFeature) { |
|
58 |
((EditableFeature)feature).set(FEATURECODE_FIELD_NAME, workspace.createUniqueCode()); |
|
50 |
VCSGisWorkspace workspace = null; |
|
51 |
try { |
|
52 |
if (notification instanceof EditingNotification) { |
|
53 |
EditingNotification n = (EditingNotification) notification; |
|
54 |
if (n.getType().equals(EditingNotification.BEFORE_INSERT_FEATURE)) { |
|
55 |
FeatureStore store = n.getFeatureStore(); |
|
56 |
workspace = getWorkspace(store); |
|
57 |
if (workspace != null) { |
|
58 |
Feature feature = n.getFeature(); |
|
59 |
if (StringUtils.isBlank(feature.getString(FEATURECODE_FIELD_NAME)) && feature instanceof EditableFeature) { |
|
60 |
((EditableFeature)feature).set(FEATURECODE_FIELD_NAME, workspace.createUniqueCode()); |
|
61 |
} |
|
59 | 62 |
} |
60 | 63 |
} |
64 |
return; |
|
61 | 65 |
} |
62 |
return; |
|
63 |
} |
|
64 |
FeatureStoreNotification n = (FeatureStoreNotification) notification; |
|
65 |
FeatureStore store = (FeatureStore) n.getSource(); |
|
66 |
switch (n.getType()) { |
|
67 |
case FeatureStoreNotification.BEFORE_INSERT: |
|
68 |
workspace = getWorkspace(store); |
|
69 |
if (workspace != null) { |
|
70 |
EditableFeature feature = (EditableFeature) n.getFeature(); |
|
71 |
if (StringUtils.isBlank(feature.getString(FEATURECODE_FIELD_NAME))) { |
|
72 |
feature.set(FEATURECODE_FIELD_NAME, workspace.createUniqueCode()); |
|
66 |
FeatureStoreNotification n = (FeatureStoreNotification) notification; |
|
67 |
FeatureStore store = (FeatureStore) n.getSource(); |
|
68 |
switch (n.getType()) { |
|
69 |
case FeatureStoreNotification.BEFORE_INSERT: |
|
70 |
workspace = getWorkspace(store); |
|
71 |
if (workspace != null) { |
|
72 |
EditableFeature feature = (EditableFeature) n.getFeature(); |
|
73 |
if (StringUtils.isBlank(feature.getString(FEATURECODE_FIELD_NAME))) { |
|
74 |
feature.set(FEATURECODE_FIELD_NAME, workspace.createUniqueCode()); |
|
75 |
} |
|
76 |
if (store.isAppending() || store.getMode() == MODE_PASS_THROUGH) { |
|
77 |
workspace.addChange(OP_INSERT, store, feature); |
|
78 |
} |
|
73 | 79 |
} |
80 |
break; |
|
81 |
case FeatureStoreNotification.BEFORE_UPDATE: |
|
74 | 82 |
if (store.isAppending() || store.getMode() == MODE_PASS_THROUGH) { |
75 |
workspace.addChange(OP_INSERT, store, feature); |
|
83 |
workspace = getWorkspace(store); |
|
84 |
if (workspace != null) { |
|
85 |
workspace.addChange(OP_UPDATE, store, n.getFeature()); |
|
86 |
} |
|
76 | 87 |
} |
77 |
}
|
|
78 |
break;
|
|
79 |
case FeatureStoreNotification.BEFORE_UPDATE:
|
|
80 |
if (store.isAppending() || store.getMode() == MODE_PASS_THROUGH) {
|
|
81 |
workspace = getWorkspace(store);
|
|
82 |
if (workspace != null) {
|
|
83 |
workspace.addChange(OP_UPDATE, store, n.getFeature());
|
|
88 |
break;
|
|
89 |
case FeatureStoreNotification.BEFORE_DELETE:
|
|
90 |
if (store.isAppending() || store.getMode() == MODE_PASS_THROUGH) {
|
|
91 |
workspace = getWorkspace(store);
|
|
92 |
if (workspace != null) {
|
|
93 |
workspace.addChange(OP_DELETE, store, n.getFeature());
|
|
94 |
}
|
|
84 | 95 |
} |
85 |
} |
|
86 |
break; |
|
87 |
case FeatureStoreNotification.BEFORE_DELETE: |
|
88 |
if (store.isAppending() || store.getMode() == MODE_PASS_THROUGH) { |
|
89 |
workspace = getWorkspace(store); |
|
90 |
if (workspace != null) { |
|
91 |
workspace.addChange(OP_DELETE, store, n.getFeature()); |
|
96 |
break; |
|
97 |
case FeatureStoreNotification.AFTER_UPDATE_TYPE: |
|
98 |
if (store.isAppending()) { |
|
99 |
|
|
92 | 100 |
} |
93 |
} |
|
94 |
break; |
|
95 |
case FeatureStoreNotification.AFTER_UPDATE_TYPE: |
|
96 |
if (store.isAppending()) { |
|
97 |
|
|
98 |
} |
|
99 |
break; |
|
100 |
case FeatureStoreNotification.BEFORE_FINISHEDITING: |
|
101 |
if (store.isEditing()) { |
|
102 |
workspace = getWorkspace(store); |
|
103 |
if (workspace != null) { |
|
104 |
int stat = workspace.addChanges( |
|
105 |
store, |
|
106 |
n.getInsertedsFeatures(), |
|
107 |
n.getUpdatedsFeatures(), |
|
108 |
n.getDeletedsFeatures() |
|
109 |
); |
|
110 |
if (stat != ERR_NO_ERROR) { |
|
111 |
n.cancel(); |
|
101 |
break; |
|
102 |
case FeatureStoreNotification.BEFORE_FINISHEDITING: |
|
103 |
if (store.isEditing()) { |
|
104 |
workspace = getWorkspace(store); |
|
105 |
if (workspace != null) { |
|
106 |
int stat = workspace.addChanges( |
|
107 |
store, |
|
108 |
n.getInsertedsFeatures(), |
|
109 |
n.getUpdatedsFeatures(), |
|
110 |
n.getDeletedsFeatures() |
|
111 |
); |
|
112 |
if (stat != ERR_NO_ERROR) { |
|
113 |
n.cancel(); |
|
114 |
} |
|
112 | 115 |
} |
113 | 116 |
} |
114 |
} |
|
115 |
break; |
|
117 |
break; |
|
118 |
} |
|
119 |
} finally { |
|
120 |
DisposeUtils.disposeQuietly(workspace); |
|
116 | 121 |
} |
117 | 122 |
} |
118 | 123 |
|
Also available in: Unified diff