Revision 27382 branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/data/feature/swing/FeatureSelectionModel.java
FeatureSelectionModel.java | ||
---|---|---|
32 | 32 |
import org.gvsig.fmap.dal.feature.Feature; |
33 | 33 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
34 | 34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
35 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
|
35 | 36 |
import org.gvsig.fmap.data.feature.swing.table.FeatureTableModel; |
37 |
import org.gvsig.tools.observer.Observable; |
|
38 |
import org.gvsig.tools.observer.Observer; |
|
36 | 39 |
|
37 | 40 |
/** |
38 | 41 |
* ListSelectionModel implementation based on the FeatureSelection of a |
... | ... | |
40 | 43 |
* |
41 | 44 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
42 | 45 |
*/ |
43 |
public class FeatureSelectionModel extends DefaultListSelectionModel { |
|
46 |
public class FeatureSelectionModel extends DefaultListSelectionModel implements |
|
47 |
Observer { |
|
44 | 48 |
|
45 | 49 |
private static final long serialVersionUID = 7643472991526133823L; |
46 | 50 |
|
47 |
private final FeatureSelection selection; |
|
48 | 51 |
private final FeatureTableModel featureTableModel; |
49 | 52 |
|
50 | 53 |
/** |
... | ... | |
59 | 62 |
public FeatureSelectionModel(FeatureTableModel featureTableModel) |
60 | 63 |
throws DataException { |
61 | 64 |
this.featureTableModel = featureTableModel; |
62 |
FeatureStore store = getFeatureStore(); |
|
63 |
this.selection = store.getFeatureSelection(); |
|
65 |
this.featureTableModel.getFeatureStore().addObserver(this); |
|
64 | 66 |
} |
65 | 67 |
|
66 | 68 |
@Override |
... | ... | |
72 | 74 |
return false; |
73 | 75 |
} |
74 | 76 |
Feature feature = featureTableModel.getFeatureAt(index); |
75 |
return selection.isSelected(feature);
|
|
77 |
return getSelection().isSelected(feature);
|
|
76 | 78 |
// } |
77 | 79 |
} |
78 | 80 |
|
... | ... | |
80 | 82 |
public void setSelectionInterval(int index0, int index1) { |
81 | 83 |
// if (!getValueIsAdjusting()) { |
82 | 84 |
try { |
83 |
selection.deselectAll();
|
|
85 |
getSelection().deselectAll();
|
|
84 | 86 |
} catch (DataException ex) { |
85 | 87 |
throw new SelectionChangeException(ex); |
86 | 88 |
} |
... | ... | |
125 | 127 |
private void selectFeatureInterval(int index0, int index1, boolean select) { |
126 | 128 |
// If only single selection is allowed, the valid value is index1 |
127 | 129 |
if (getSelectionMode() == SINGLE_SELECTION) { |
128 |
selectFeatureAt(index1, select); |
|
130 |
selectFeatureAt(index1, select, getSelection());
|
|
129 | 131 |
} else { |
130 | 132 |
// index0 < index1 is not guaranteed |
131 | 133 |
int first = index0 <= index1 ? index0 : index1; |
... | ... | |
135 | 137 |
if (first == 0 && last == featureTableModel.getRowCount() - 1) { |
136 | 138 |
try { |
137 | 139 |
if (select) { |
138 |
selection.selectAll();
|
|
140 |
getSelection().selectAll();
|
|
139 | 141 |
} else { |
140 |
selection.deselectAll();
|
|
142 |
getSelection().deselectAll();
|
|
141 | 143 |
} |
142 | 144 |
} catch (DataException ex) { |
143 | 145 |
throw new SelectionChangeException(ex); |
144 | 146 |
} |
145 | 147 |
} else { |
146 |
for (int i = first; i <= last; i++) { |
|
147 |
selectFeatureAt(i, select); |
|
148 |
FeatureSelection selection; |
|
149 |
try { |
|
150 |
selection = this.getFeatureStore().createFeatureSelection(); |
|
151 |
} catch (DataException e) { |
|
152 |
throw new SelectionChangeException(e); |
|
153 |
} |
|
154 |
for (int i = first; i <= last; i++) { |
|
155 |
selectFeatureAt(i, select, selection); |
|
148 | 156 |
} |
157 |
try { |
|
158 |
this.getFeatureStore().setSelection(selection); |
|
159 |
} catch (DataException e) { |
|
160 |
throw new SelectionChangeException(e); |
|
161 |
} |
|
149 | 162 |
} |
150 | 163 |
} |
151 | 164 |
} |
152 | 165 |
|
153 |
/** |
|
154 |
* Selects a feature at a row position. |
|
155 |
* |
|
156 |
* @param index |
|
157 |
* the Feature row index |
|
158 |
* @param select |
|
159 |
* if to select or deselect |
|
160 |
*/ |
|
161 |
private void selectFeatureAt(int index, boolean select) { |
|
166 |
/** |
|
167 |
* Selects a feature at a row position. |
|
168 |
* |
|
169 |
* @param index |
|
170 |
* the Feature row index |
|
171 |
* @param select |
|
172 |
* if to select or deselect |
|
173 |
* @param selection |
|
174 |
* selection instance to use |
|
175 |
*/ |
|
176 |
private void selectFeatureAt(int index, boolean select, |
|
177 |
FeatureSelection selection) { |
|
162 | 178 |
Feature feature = getFeature(index); |
163 | 179 |
if (select) { |
164 | 180 |
selection.select(feature); |
165 | 181 |
} else { |
166 |
selection.deselect(feature);
|
|
182 |
selection.deselect(feature);
|
|
167 | 183 |
} |
168 | 184 |
} |
169 | 185 |
|
... | ... | |
180 | 196 |
private FeatureStore getFeatureStore() { |
181 | 197 |
return featureTableModel.getFeatureStore(); |
182 | 198 |
} |
199 |
|
|
200 |
/** |
|
201 |
* Returns the FeatureStore. |
|
202 |
*/ |
|
203 |
private FeatureSelection getSelection() { |
|
204 |
try { |
|
205 |
return (FeatureSelection) getFeatureStore().getSelection(); |
|
206 |
} catch (DataException ex) { |
|
207 |
throw new SelectionChangeException(ex); |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
public void update(Observable observable, Object notification) { |
|
212 |
if (notification instanceof FeatureStoreNotification) { |
|
213 |
FeatureStoreNotification fnotification = (FeatureStoreNotification) notification; |
|
214 |
if (!fnotification.getSource().equals(getFeatureStore())) { |
|
215 |
return; |
|
216 |
} |
|
217 |
if (FeatureStoreNotification.SELECTION_CHANGE.equals(fnotification |
|
218 |
.getType())) { |
|
219 |
this.fireValueChanged(-1, -1, false); |
|
220 |
|
|
221 |
} |
|
222 |
} |
|
223 |
|
|
224 |
} |
|
225 |
|
|
183 | 226 |
} |
Also available in: Unified diff