Revision 45155 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/featuretype/DefaultFeatureAttributesSelectionPanel.java
DefaultFeatureAttributesSelectionPanel.java | ||
---|---|---|
10 | 10 |
import javax.swing.DefaultListCellRenderer; |
11 | 11 |
import javax.swing.ImageIcon; |
12 | 12 |
import javax.swing.JComponent; |
13 |
import javax.swing.event.DocumentEvent; |
|
14 |
import javax.swing.event.DocumentListener; |
|
13 | 15 |
import javax.swing.event.ListSelectionEvent; |
14 | 16 |
import org.apache.commons.io.FilenameUtils; |
17 |
import org.gvsig.expressionevaluator.Expression; |
|
18 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
19 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
|
15 | 20 |
import org.gvsig.fmap.dal.exception.DataException; |
16 | 21 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
17 | 22 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
18 | 23 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
19 | 24 |
import org.gvsig.fmap.dal.feature.FeatureType; |
25 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
|
20 | 26 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
21 | 27 |
import org.gvsig.tools.swing.api.FilteredListController; |
22 | 28 |
import org.gvsig.tools.swing.api.FilteredListModel; |
... | ... | |
39 | 45 |
private final ActionListenerSupport actionListenerSupport; |
40 | 46 |
private FilteredListController availableFieldsController; |
41 | 47 |
private final List<String> selecteds; |
48 |
private ExpressionPickerController expressionPicker = null; |
|
49 |
private boolean allowCalculatedAttributes; |
|
42 | 50 |
|
43 | 51 |
public DefaultFeatureAttributesSelectionPanel() { |
44 | 52 |
this.actionListenerSupport = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport(); |
... | ... | |
65 | 73 |
} |
66 | 74 |
doSelectColumn(); |
67 | 75 |
}); |
76 |
this.txtExpression.getDocument().addDocumentListener(new DocumentListener() { |
|
77 |
public void changedUpdate(DocumentEvent e) { |
|
78 |
doSelectAvailableColumn(); |
|
79 |
} |
|
80 |
@Override |
|
81 |
public void insertUpdate(DocumentEvent de) { |
|
82 |
doSelectAvailableColumn(); |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
86 |
public void removeUpdate(DocumentEvent de) { |
|
87 |
doSelectAvailableColumn(); |
|
88 |
} |
|
89 |
}); |
|
68 | 90 |
this.btnColumnAdd.addActionListener((ActionEvent e) -> { |
69 | 91 |
doColumnAdd(); |
70 | 92 |
}); |
... | ... | |
81 | 103 |
lstAvailableColumns, |
82 | 104 |
txtColumnsFilter, |
83 | 105 |
btnColumnsFilter |
84 |
); |
|
106 |
);
|
|
85 | 107 |
Dimension sz = this.getPreferredSize(); |
86 | 108 |
if( sz.width<450 ) { |
87 | 109 |
sz.width = 450; |
... | ... | |
109 | 131 |
} |
110 | 132 |
|
111 | 133 |
private void doSelectAvailableColumn() { |
112 |
if( this.lstAvailableColumns.getSelectedIndex()>=0 ) { |
|
134 |
if( this.lstAvailableColumns.getSelectedIndex()>=0 || !this.expressionPicker.isEmpty()) {
|
|
113 | 135 |
this.btnColumnAdd.setEnabled(true); |
114 | 136 |
return; |
115 | 137 |
} |
... | ... | |
159 | 181 |
this.lstSelectedColumns.setSelectedIndex(n+1); |
160 | 182 |
this.updateControls(); |
161 | 183 |
} |
184 |
|
|
185 |
private boolean checkIfAttributeInFeatureType(String myAttr) { |
|
186 |
for (FeatureAttributeDescriptor attr : featureType) { |
|
187 |
if(attr.getName().equalsIgnoreCase(myAttr) ) { |
|
188 |
return true; |
|
189 |
} |
|
190 |
} |
|
191 |
List<EditableFeatureAttributeDescriptor> columns = featureType.getExtraColumns().getColumns(); |
|
192 |
if (columns!=null && !columns.isEmpty()) { |
|
193 |
for (EditableFeatureAttributeDescriptor extraCol : columns) { |
|
194 |
if(extraCol.getName().equalsIgnoreCase(myAttr)) { |
|
195 |
return true; |
|
196 |
} |
|
197 |
} |
|
198 |
} |
|
199 |
return false; |
|
200 |
} |
|
162 | 201 |
|
163 | 202 |
private void doColumnRemove() { |
164 | 203 |
LabeledValue attr = (LabeledValue) this.lstSelectedColumns.getSelectedValue(); |
165 | 204 |
if( attr == null ) { |
166 | 205 |
return; |
167 | 206 |
} |
168 |
int n = this.selecteds.indexOf(attr.getLabel()); |
|
207 |
String label = attr.getLabel(); |
|
208 |
int n = this.selecteds.indexOf(label); |
|
169 | 209 |
if( n<0 ) { |
170 | 210 |
return; |
171 | 211 |
} |
212 |
|
|
213 |
if (!checkIfAttributeInFeatureType(label)) { |
|
214 |
Expression toExp = ExpressionEvaluatorLocator.getManager().createExpression(); |
|
215 |
toExp.setPhrase(label); |
|
216 |
this.expressionPicker.set(toExp); |
|
217 |
} |
|
218 |
|
|
172 | 219 |
this.selecteds.remove(n); |
173 | 220 |
this.updateControls(); |
174 | 221 |
} |
175 | 222 |
|
176 | 223 |
private void doColumnAdd() { |
177 |
LabeledValue attr = (LabeledValue) this.lstAvailableColumns.getSelectedValue(); |
|
178 |
if( attr == null ) { |
|
179 |
return; |
|
224 |
|
|
225 |
if (this.expressionPicker.isEmpty()) { |
|
226 |
LabeledValue attr = (LabeledValue) this.lstAvailableColumns.getSelectedValue(); |
|
227 |
if( attr == null ) { |
|
228 |
return; |
|
229 |
} |
|
230 |
int n = this.selecteds.indexOf(attr); |
|
231 |
if( n>=0 ) { |
|
232 |
return; |
|
233 |
} |
|
234 |
this.selecteds.add(attr.getLabel()); |
|
235 |
} else { |
|
236 |
if (this.expressionPicker.isValid()) { |
|
237 |
Expression exp = this.expressionPicker.get(); |
|
238 |
String expressionField = exp.getPhrase(); |
|
239 |
int n = this.selecteds.indexOf(expressionField); |
|
240 |
if (n >= 0) { |
|
241 |
return; |
|
242 |
} |
|
243 |
this.selecteds.add(expressionField); |
|
244 |
this.expressionPicker.set(null); |
|
245 |
} |
|
180 | 246 |
} |
181 |
int n = this.selecteds.indexOf(attr); |
|
182 |
if( n>=0 ) { |
|
183 |
return; |
|
184 |
} |
|
185 |
this.selecteds.add(attr.getLabel()); |
|
186 | 247 |
this.updateControls(); |
187 | 248 |
} |
188 | 249 |
|
... | ... | |
245 | 306 |
} |
246 | 307 |
|
247 | 308 |
private void updateControls() { |
309 |
|
|
310 |
if (this.expressionPicker == null) { |
|
311 |
this.expressionPicker = |
|
312 |
DALSwingLocator.getDataSwingManager().createExpressionPickerController( |
|
313 |
this.featureType.getStore(), |
|
314 |
txtExpression, |
|
315 |
btnExpression, |
|
316 |
btnBookmarks, |
|
317 |
btnHistory); |
|
318 |
} |
|
248 | 319 |
int indexAvailables = this.lstAvailableColumns.getSelectedIndex(); |
249 | 320 |
int indexSelecteds = this.lstSelectedColumns.getSelectedIndex(); |
250 | 321 |
FilteredListModel modelAvailables = ToolsSwingLocator.getToolsSwingManager().createFilteredListModel(); |
251 | 322 |
FilteredListModel modelSelecteds = ToolsSwingLocator.getToolsSwingManager().createFilteredListModel(); |
252 | 323 |
for (FeatureAttributeDescriptor attr : featureType) { |
253 | 324 |
if( !this.selecteds.contains(attr.getName()) ) { |
254 |
modelAvailables.addElement(attr.getName()); |
|
325 |
modelAvailables.addElement(attr.getName()); //label?
|
|
255 | 326 |
} |
256 | 327 |
} |
257 | 328 |
List<EditableFeatureAttributeDescriptor> columns = featureType.getExtraColumns().getColumns(); |
... | ... | |
277 | 348 |
this.lstAvailableColumns.setSelectedIndex(indexAvailables); |
278 | 349 |
this.btnColumnAdd.setEnabled(true); |
279 | 350 |
} else { |
280 |
this.btnColumnAdd.setEnabled(false); |
|
351 |
if(!this.expressionPicker.isEmpty()) { |
|
352 |
this.btnColumnAdd.setEnabled(true); |
|
353 |
} else { |
|
354 |
this.btnColumnAdd.setEnabled(false); |
|
355 |
} |
|
281 | 356 |
} |
282 | 357 |
|
283 | 358 |
if( indexSelecteds >= 0 && modelSelecteds.getSize()>0 ) { |
... | ... | |
319 | 394 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
320 | 395 |
} |
321 | 396 |
} |
397 |
|
|
398 |
public void allowCalculatedAttributes(boolean b) { |
|
399 |
this.allowCalculatedAttributes = b; |
|
400 |
} |
|
322 | 401 |
} |
Also available in: Unified diff