svn-gvsig-desktop / 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 / searchpanel / SearchFieldController.java @ 44376
History | View | Annotate | Download (21.1 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.searchpanel; |
---|---|
2 |
|
3 |
import java.awt.Cursor; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.awt.event.ItemEvent; |
8 |
import java.awt.event.ItemListener; |
9 |
import java.awt.event.MouseAdapter; |
10 |
import java.awt.event.MouseEvent; |
11 |
import java.util.ArrayList; |
12 |
import java.util.HashMap; |
13 |
import java.util.List; |
14 |
import java.util.Map; |
15 |
import java.util.Objects; |
16 |
import javax.swing.ComboBoxModel; |
17 |
import javax.swing.DefaultComboBoxModel; |
18 |
import javax.swing.ImageIcon; |
19 |
import javax.swing.JComboBox; |
20 |
import javax.swing.JLabel; |
21 |
import javax.swing.JScrollPane; |
22 |
import javax.swing.JTree; |
23 |
import javax.swing.SwingUtilities; |
24 |
import javax.swing.tree.TreePath; |
25 |
import org.apache.commons.lang3.ObjectUtils; |
26 |
import org.apache.commons.lang3.StringUtils; |
27 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
28 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
29 |
import org.gvsig.fmap.dal.DataManager; |
30 |
import org.gvsig.fmap.dal.complements.Search; |
31 |
import org.gvsig.fmap.dal.exception.DataException; |
32 |
import org.gvsig.fmap.dal.feature.Feature; |
33 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
34 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
35 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
37 |
import org.gvsig.fmap.dal.feature.FeatureType; |
38 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.AdvancedAttributeSelectionTreeModel.Node; |
39 |
import static org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel.getAttributeDescriptorLabel; |
40 |
import org.gvsig.tools.ToolsLocator; |
41 |
import org.gvsig.tools.dataTypes.CoercionException; |
42 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
43 |
import org.gvsig.tools.exception.BaseException; |
44 |
import org.gvsig.tools.swing.api.DropDown; |
45 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
46 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
47 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
48 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
49 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
50 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
51 |
import org.gvsig.tools.util.LabeledValue; |
52 |
import org.gvsig.tools.util.LabeledValueImpl; |
53 |
import org.gvsig.tools.visitor.VisitCanceledException; |
54 |
import org.gvsig.tools.visitor.Visitor; |
55 |
import org.slf4j.Logger; |
56 |
import org.slf4j.LoggerFactory; |
57 |
|
58 |
/**
|
59 |
*
|
60 |
* @author jjdelcerro
|
61 |
*/
|
62 |
@SuppressWarnings("UseSpecificCatch") |
63 |
public class SearchFieldController { |
64 |
|
65 |
private static final Logger LOGGER = LoggerFactory.getLogger(SearchFieldController.class); |
66 |
|
67 |
private static class FeatureAttribute extends LabeledValueImpl<String> { |
68 |
|
69 |
FeatureAttributeDescriptor attrdesc; |
70 |
private final FeatureStore store; |
71 |
private final int type; |
72 |
private final boolean showStoreName; |
73 |
|
74 |
public FeatureAttribute(FeatureStore store, FeatureAttributeDescriptor attrdesc, int type) { |
75 |
this(store, attrdesc, null, type, false); |
76 |
} |
77 |
|
78 |
public FeatureAttribute(
|
79 |
FeatureStore store, |
80 |
FeatureAttributeDescriptor attrdesc, |
81 |
String value,
|
82 |
int type,
|
83 |
boolean showStoreName
|
84 |
) { |
85 |
super(
|
86 |
getAttributeDescriptorLabel(attrdesc, store.getName()), |
87 |
ObjectUtils.defaultIfNull(value, attrdesc.getName()) |
88 |
); |
89 |
this.store = store;
|
90 |
this.attrdesc = attrdesc;
|
91 |
this.type = type;
|
92 |
this.showStoreName = showStoreName;
|
93 |
} |
94 |
|
95 |
@Override
|
96 |
public String getLabel() { |
97 |
String theLabel = getAttributeDescriptorLabel(attrdesc, showStoreName? store.getName():null); |
98 |
switch(this.type) { |
99 |
case Search.OrderedAttribute.TYPE_REGURAL:
|
100 |
break;
|
101 |
case Search.OrderedAttribute.TYPE_FAVORITE:
|
102 |
theLabel = "<html><b>"+theLabel+"</b></html>"; |
103 |
break;
|
104 |
case Search.OrderedAttribute.TYPE_RECENT:
|
105 |
theLabel = "<html><i><b>"+theLabel+"</b></i></html>"; |
106 |
break;
|
107 |
} |
108 |
return theLabel;
|
109 |
} |
110 |
|
111 |
public FeatureAttributeDescriptor getDescriptor() {
|
112 |
return this.attrdesc; |
113 |
} |
114 |
|
115 |
public FeatureStore getFeatureStore() {
|
116 |
return this.store; |
117 |
} |
118 |
|
119 |
public boolean isExpression() { |
120 |
FeatureType type = this.attrdesc.getFeatureType();
|
121 |
if (type == null) { |
122 |
return false; |
123 |
} |
124 |
Object x = type.get(this.getValue()); |
125 |
return x == null; |
126 |
} |
127 |
|
128 |
} |
129 |
|
130 |
private FeatureStore store;
|
131 |
private final JLabel lblFields; |
132 |
private final JLabel lblExtraFields; |
133 |
private final JLabel lblLogicalOperators; |
134 |
private final JLabel lblRelationalOperators; |
135 |
private final JComboBox cboValue; |
136 |
private Object valueAssigned = null; |
137 |
|
138 |
private DropDown ddnFields;
|
139 |
private DropDown ddnLogicalOperators;
|
140 |
private DropDown ddnRelationalOperators;
|
141 |
|
142 |
private final LabeledValue[] relationalOperators = { |
143 |
new LabeledValueImpl("Equals to", ExpressionBuilder.OPERATOR_EQ), |
144 |
new LabeledValueImpl("Like to", ExpressionBuilder.OPERATOR_ILIKE), |
145 |
new LabeledValueImpl("Not equals to", ExpressionBuilder.OPERATOR_NE), |
146 |
new LabeledValueImpl("Greater than", ExpressionBuilder.OPERATOR_GT), |
147 |
new LabeledValueImpl("Greater or equal to", ExpressionBuilder.OPERATOR_GE), |
148 |
new LabeledValueImpl("Less than", ExpressionBuilder.OPERATOR_LT), |
149 |
new LabeledValueImpl("Less or equal to", ExpressionBuilder.OPERATOR_LE) |
150 |
}; |
151 |
private final LabeledValue[] logicalOperators = { |
152 |
new LabeledValueImpl("Or", ExpressionBuilder.OPERATOR_OR), |
153 |
new LabeledValueImpl("And", ExpressionBuilder.OPERATOR_AND) |
154 |
}; |
155 |
|
156 |
public SearchFieldController(
|
157 |
FeatureStore store, |
158 |
JLabel lblFields,
|
159 |
JLabel lblExtraFields,
|
160 |
JLabel lblRelationalOperators,
|
161 |
JComboBox cboValue,
|
162 |
JLabel lblLogicalOperators
|
163 |
) { |
164 |
this.store = store;
|
165 |
this.lblFields = lblFields;
|
166 |
this.lblExtraFields = lblExtraFields;
|
167 |
this.lblRelationalOperators = lblRelationalOperators;
|
168 |
this.cboValue = cboValue;
|
169 |
this.lblLogicalOperators = lblLogicalOperators;
|
170 |
this.initComponents();
|
171 |
} |
172 |
|
173 |
public boolean isAValidRelationOperator(String name) { |
174 |
for (LabeledValue relationalOperator : relationalOperators) {
|
175 |
if( StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
176 |
return true; |
177 |
} |
178 |
} |
179 |
return false; |
180 |
} |
181 |
|
182 |
private void initComponents() { |
183 |
try {
|
184 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
185 |
this.lblExtraFields.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
186 |
|
187 |
this.ddnFields = toolsSwingManager.createDropDown(lblFields);
|
188 |
this.ddnFields.setVisibleDropdownArrow(false); |
189 |
this.ddnRelationalOperators = toolsSwingManager.createDropDown(lblRelationalOperators);
|
190 |
this.ddnRelationalOperators.setVisibleDropdownArrow(false); |
191 |
if (lblLogicalOperators != null) { |
192 |
this.ddnLogicalOperators = toolsSwingManager.createDropDown(lblLogicalOperators);
|
193 |
this.ddnLogicalOperators.setVisibleDropdownArrow(false); |
194 |
} |
195 |
|
196 |
DefaultComboBoxModel modelRelationalOperators = new DefaultComboBoxModel(); |
197 |
for (LabeledValue op : relationalOperators) {
|
198 |
modelRelationalOperators.addElement(op); |
199 |
} |
200 |
this.ddnRelationalOperators.setModel(modelRelationalOperators);
|
201 |
|
202 |
if (this.ddnLogicalOperators != null) { |
203 |
DefaultComboBoxModel modelLogicalOperators = new DefaultComboBoxModel(); |
204 |
for (LabeledValue op : logicalOperators) {
|
205 |
modelLogicalOperators.addElement(op); |
206 |
} |
207 |
this.ddnLogicalOperators.setModel(modelLogicalOperators);
|
208 |
} |
209 |
FeatureType featureType = store.getDefaultFeatureType(); |
210 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
211 |
Search.COMPLEMENT_MANE, featureType |
212 |
); |
213 |
List<Search.OrderedAttribute> orderedAttributes = search.getOrderedAttributes(
|
214 |
Search.BASIC_TYPES_FILTER, |
215 |
Search.STR_INT_LONG_LABEL_ORDER, |
216 |
20
|
217 |
); |
218 |
List<ImageIcon>icons = new ArrayList<>(); |
219 |
// DataTypesManager dataTypeManager = ToolsLocator.getDataTypesManager();
|
220 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
221 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
222 |
for (Search.OrderedAttribute attr : orderedAttributes) {
|
223 |
FeatureAttributeDescriptor attrdesc = attr.getDescriptor(); |
224 |
model.addElement(new FeatureAttribute(this.store, attrdesc, attr.getType())); |
225 |
String iconName = attrdesc.getDataType().getIconName();
|
226 |
if( iconTheme.exists(iconName) ) {
|
227 |
icons.add(iconTheme.get(iconName)); |
228 |
} else {
|
229 |
icons.add(null);
|
230 |
} |
231 |
} |
232 |
this.ddnFields.setIcons(icons);
|
233 |
this.ddnFields.setModel(model);
|
234 |
this.ddnFields.addItemListener(new ItemListener() { |
235 |
@Override
|
236 |
public void itemStateChanged(ItemEvent e) { |
237 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
238 |
doUpdateValuesList(); |
239 |
} |
240 |
|
241 |
} |
242 |
}); |
243 |
|
244 |
this.lblExtraFields.addMouseListener(new MouseAdapter() { |
245 |
@Override
|
246 |
public void mouseClicked(MouseEvent e) { |
247 |
doSelectExtraField(); |
248 |
} |
249 |
}); |
250 |
clear(); |
251 |
} catch (Exception ex) { |
252 |
throw new RuntimeException(ex); |
253 |
} |
254 |
} |
255 |
|
256 |
private FeatureType getFeatureType() {
|
257 |
try {
|
258 |
return this.store.getDefaultFeatureType(); |
259 |
} catch (DataException ex) {
|
260 |
return null; |
261 |
} |
262 |
} |
263 |
|
264 |
private void doSelectExtraField() { |
265 |
FeatureType featureType = this.getFeatureType();
|
266 |
AdvancedAttributeSelectionTreeModel treeModel = new AdvancedAttributeSelectionTreeModel(
|
267 |
this.store,
|
268 |
Search.BASIC_TYPES_FILTER |
269 |
); |
270 |
final JTree tree = new JTree(); |
271 |
tree.setCellRenderer(new AdvancedAttributeSelectionTreeCellRenderer());
|
272 |
tree.setModel(treeModel); |
273 |
try {
|
274 |
tree.setSelectionRow(1);
|
275 |
} catch(Throwable th) { |
276 |
} |
277 |
JScrollPane scrollpane = new JScrollPane(tree); |
278 |
scrollpane.setPreferredSize(new Dimension(400, 300)); |
279 |
scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
280 |
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
281 |
|
282 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
283 |
final Dialog dialog = winManager.createDialog( |
284 |
scrollpane, |
285 |
"Select attribute",
|
286 |
null,
|
287 |
WindowManager_v2.BUTTONS_OK_CANCEL |
288 |
); |
289 |
dialog.addActionListener(new ActionListener() { |
290 |
@Override
|
291 |
public void actionPerformed(ActionEvent e) { |
292 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) {
|
293 |
TreePath path = tree.getSelectionPath();
|
294 |
doAddAndSelect(path.getPath()); |
295 |
} |
296 |
} |
297 |
}); |
298 |
dialog.show(WindowManager.MODE.DIALOG); |
299 |
|
300 |
} |
301 |
|
302 |
private void doAddAndSelect(Object[] nodes) { |
303 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
304 |
List<String> list = new ArrayList<>(); |
305 |
for (int i = 1; i < nodes.length; i++) { |
306 |
Node node = (Node) nodes[i]; |
307 |
FeatureAttributeDescriptor attrdesc = node.getValue(); |
308 |
list.add(attrdesc.getName()); |
309 |
} |
310 |
Node node = (Node) nodes[nodes.length - 1];
|
311 |
FeatureStore theStore = node.getFeatureStore(); |
312 |
FeatureAttributeDescriptor attrdesc = node.getValue(); |
313 |
String storeFullName = theStore.getFullName();
|
314 |
DefaultComboBoxModel<FeatureAttribute> model = (DefaultComboBoxModel) this.ddnFields.getModel(); |
315 |
for (int i = 0; i < model.getSize(); i++) { |
316 |
FeatureAttribute attr = model.getElementAt(i); |
317 |
FeatureAttributeDescriptor attrdescN = attr.getDescriptor(); |
318 |
if (StringUtils.equalsIgnoreCase(storeFullName, attrdescN.getStore().getFullName())
|
319 |
&& StringUtils.equalsIgnoreCase(attrdesc.getName(), attrdescN.getName())) { |
320 |
this.setAttribute(i);
|
321 |
return;
|
322 |
} |
323 |
} |
324 |
String formula;
|
325 |
boolean showStoreName;
|
326 |
if (StringUtils.equalsIgnoreCase(storeFullName, this.store.getFullName())) { |
327 |
formula = attrdesc.getName(); |
328 |
showStoreName = false;
|
329 |
} else {
|
330 |
formula = builder.function( |
331 |
DataManager.FUNCTION_FOREING_VALUE, |
332 |
builder.constant(StringUtils.join(list,"."))
|
333 |
).toString(); |
334 |
showStoreName = true;
|
335 |
} |
336 |
FeatureAttribute attribute = new FeatureAttribute(theStore, attrdesc, formula, Search.OrderedAttribute.TYPE_REGURAL, showStoreName);
|
337 |
model.addElement(attribute); |
338 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
339 |
this.ddnFields.getIcons().add(iconTheme.get(attrdesc.getDataType().getIconName()));
|
340 |
this.setAttribute(model.getSize() - 1); |
341 |
} |
342 |
|
343 |
public void clear() { |
344 |
this.ddnRelationalOperators.setSelectedIndex(0); |
345 |
if (this.ddnLogicalOperators != null) { |
346 |
this.ddnLogicalOperators.setSelectedIndex(0); |
347 |
} |
348 |
this.cboValue.setSelectedIndex(-1); |
349 |
} |
350 |
|
351 |
private void doUpdateValuesList() { |
352 |
final FeatureAttribute attribute = (FeatureAttribute) this.ddnFields.getSelectedItem(); |
353 |
if (attribute == null) { |
354 |
return;
|
355 |
} |
356 |
|
357 |
final List<Object> values = new ArrayList<>(); |
358 |
final int limit = 60; |
359 |
final long timeLimit = System.currentTimeMillis() + limit * 1000; |
360 |
final DefaultComboBoxModel model = new DefaultComboBoxModel(); |
361 |
this.setEnabled(false); |
362 |
final FeatureStore theStore = attribute.getFeatureStore();
|
363 |
final FeatureQuery query = theStore.createFeatureQuery();
|
364 |
query.addAttributeName(attribute.getDescriptor().getName()); |
365 |
query.setGroup(true);
|
366 |
query.setLimit(1000);
|
367 |
Thread th = new Thread(new Runnable() { |
368 |
@Override
|
369 |
public void run() { |
370 |
try {
|
371 |
FeatureSet set = theStore.getFeatureSet(query); |
372 |
set.accept(new Visitor() {
|
373 |
@Override
|
374 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
375 |
Object value = ((Feature) o).get(attribute.getDescriptor().getName());
|
376 |
if (!values.contains(value)) {
|
377 |
values.add(value); |
378 |
} |
379 |
if (System.currentTimeMillis() > timeLimit) { |
380 |
throw new VisitCanceledException(); |
381 |
} |
382 |
if (values.size() > 1000) { |
383 |
throw new VisitCanceledException(); |
384 |
} |
385 |
} |
386 |
}); |
387 |
} catch (VisitCanceledException ex) {
|
388 |
|
389 |
} catch (Exception ex) { |
390 |
LOGGER.warn("Can't update list of values of '"+attribute.getLabel()+"'.", ex); |
391 |
} |
392 |
List<LabeledValue> elements = new ArrayList<>(); |
393 |
if (!values.isEmpty()) {
|
394 |
LabeledValue[] availableValues = attribute.getDescriptor().getAvailableValues();
|
395 |
Map<String, String> availableValuesMap = new HashMap<>(); |
396 |
if (availableValues != null) { |
397 |
for (LabeledValue availableValue : availableValues) {
|
398 |
availableValuesMap.put( |
399 |
Objects.toString(availableValue.getValue()), |
400 |
availableValue.getLabel() |
401 |
); |
402 |
} |
403 |
} |
404 |
elements.add(new LabeledValueImpl("", null)); |
405 |
for (Object value : values) { |
406 |
String key = Objects.toString(value);
|
407 |
String label = availableValuesMap.getOrDefault(key, key);
|
408 |
elements.add(new LabeledValueImpl(label, value));
|
409 |
} |
410 |
elements.sort(null);
|
411 |
|
412 |
} |
413 |
for (LabeledValue element : elements) {
|
414 |
model.addElement(element); |
415 |
} |
416 |
SwingUtilities.invokeLater(new Runnable() { |
417 |
@Override
|
418 |
public void run() { |
419 |
cboValue.setModel(model); |
420 |
if( valueAssigned!=null ) { |
421 |
cboValue.setSelectedItem(valueAssigned); |
422 |
valueAssigned = null;
|
423 |
} |
424 |
setEnabled(true);
|
425 |
} |
426 |
}); |
427 |
} |
428 |
}); |
429 |
th.start(); |
430 |
} |
431 |
|
432 |
public void setEnabled(boolean enabled) { |
433 |
this.ddnFields.setEnabled(enabled);
|
434 |
if( this.ddnLogicalOperators!=null ) { |
435 |
this.ddnLogicalOperators.setEnabled(enabled);
|
436 |
} |
437 |
this.ddnRelationalOperators.setEnabled(enabled);
|
438 |
this.lblExtraFields.setEnabled(enabled);
|
439 |
} |
440 |
|
441 |
public String getRelationalOperator() { |
442 |
LabeledValue<String> op = (LabeledValue) this.ddnRelationalOperators.getSelectedItem(); |
443 |
if (op == null) { |
444 |
return null; |
445 |
} |
446 |
return op.getValue();
|
447 |
} |
448 |
|
449 |
public int setRelationalOperator(String name) { |
450 |
int n = 0; |
451 |
for (LabeledValue relationalOperator : relationalOperators) {
|
452 |
if( StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
453 |
break;
|
454 |
} |
455 |
n++; |
456 |
} |
457 |
if( this.relationalOperators.length<=n ) { |
458 |
return -1; |
459 |
} |
460 |
this.ddnRelationalOperators.setSelectedIndex(n);
|
461 |
return n;
|
462 |
} |
463 |
|
464 |
public String getLogicalOperator() { |
465 |
if (this.ddnLogicalOperators == null) { |
466 |
return null; |
467 |
} |
468 |
LabeledValue<String> rel = (LabeledValue) this.ddnLogicalOperators.getSelectedItem(); |
469 |
if (rel == null) { |
470 |
return null; |
471 |
} |
472 |
return rel.getValue();
|
473 |
} |
474 |
|
475 |
public Object getValue() { |
476 |
final FeatureAttribute attribute = (FeatureAttribute) this.ddnFields.getSelectedItem(); |
477 |
if (attribute == null) { |
478 |
return null; |
479 |
} |
480 |
Object v = this.cboValue.getSelectedItem(); |
481 |
if (v == null) { |
482 |
return null; |
483 |
} |
484 |
if (v instanceof LabeledValue) { |
485 |
v = ((LabeledValue) v).getValue(); |
486 |
if (v == null) { |
487 |
return null; |
488 |
} |
489 |
} |
490 |
if (v instanceof CharSequence) { |
491 |
if (StringUtils.isBlank((CharSequence) v)) { |
492 |
return null; |
493 |
} |
494 |
} |
495 |
DataTypesManager.Coercion coercion = attribute.getDescriptor().getDataType().getCoercion(); |
496 |
try {
|
497 |
return coercion.coerce(v);
|
498 |
} catch (CoercionException ex) {
|
499 |
return null; |
500 |
} |
501 |
} |
502 |
|
503 |
public void setValue(Object value) { |
504 |
this.cboValue.setSelectedItem(value);
|
505 |
this.valueAssigned = value;
|
506 |
} |
507 |
|
508 |
public boolean isAttributeAnExpression() { |
509 |
final FeatureAttribute attribute = (FeatureAttribute) this.ddnFields.getSelectedItem(); |
510 |
if (attribute == null) { |
511 |
return false; |
512 |
} |
513 |
return attribute.isExpression();
|
514 |
} |
515 |
|
516 |
public String getAttribute() { |
517 |
final FeatureAttribute attribute = (FeatureAttribute) this.ddnFields.getSelectedItem(); |
518 |
if (attribute == null) { |
519 |
return null; |
520 |
} |
521 |
if( this.getValue()!=null ) { |
522 |
attribute.getDescriptor().recentUsed(); |
523 |
} |
524 |
return attribute.getValue();
|
525 |
} |
526 |
|
527 |
public int setAttribute(String name) { |
528 |
ComboBoxModel<FeatureAttribute> model = this.ddnFields.getModel(); |
529 |
for (int i = 0; i < model.getSize(); i++) { |
530 |
FeatureAttribute x = model.getElementAt(i); |
531 |
if (StringUtils.equalsIgnoreCase(name, x.getValue())) {
|
532 |
this.setAttribute(i);
|
533 |
return i;
|
534 |
} |
535 |
} |
536 |
this.setAttribute(-1); |
537 |
return -1; |
538 |
} |
539 |
|
540 |
public void setAttribute(int index) { |
541 |
try {
|
542 |
this.ddnFields.setSelectedIndex(index);
|
543 |
} catch (Exception ex) { |
544 |
this.ddnFields.setSelectedIndex(-1); |
545 |
} |
546 |
doUpdateValuesList(); |
547 |
} |
548 |
|
549 |
} |