Revision 44340 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/DefaultSearchPanel.java
DefaultSearchPanel.java | ||
---|---|---|
19 | 19 |
import javax.swing.SwingUtilities; |
20 | 20 |
import javax.swing.event.ListSelectionEvent; |
21 | 21 |
import javax.swing.event.ListSelectionListener; |
22 |
import javax.swing.table.AbstractTableModel; |
|
23 | 22 |
import javax.swing.table.TableModel; |
24 | 23 |
import org.apache.commons.io.FilenameUtils; |
25 | 24 |
import org.apache.commons.lang.mutable.MutableObject; |
... | ... | |
42 | 41 |
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory.AbstractDALActionContext; |
43 | 42 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
44 | 43 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
44 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel; |
|
45 | 45 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
46 | 46 |
import org.gvsig.tools.ToolsLocator; |
47 | 47 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
... | ... | |
61 | 61 |
|
62 | 62 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class); |
63 | 63 |
private Expression currentSearch; |
64 |
|
|
65 |
private class FeaturesTableModel extends AbstractTableModel { |
|
66 |
|
|
67 |
private final List<Feature> features; |
|
68 |
private final List<String> columnNames; |
|
69 |
private final FeatureType featureType; |
|
70 |
|
|
71 |
public FeaturesTableModel(FeatureType featureType) { |
|
72 |
this(featureType, null, null); |
|
73 |
} |
|
74 |
|
|
75 |
public FeaturesTableModel(FeatureType featureType, List<String> columnNames, List<Feature> features) { |
|
76 |
this.features = features; |
|
77 |
this.featureType = featureType; |
|
78 |
if (columnNames == null || columnNames.isEmpty()) { |
|
79 |
this.columnNames = new ArrayList<>(); |
|
80 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
|
81 |
Search.COMPLEMENT_MANE, featureType |
|
82 |
); |
|
83 |
List<Search.OrderedAttribute> attributos = search.getOrderedAttributes( |
|
84 |
Search.BASIC_TYPES_FILTER, |
|
85 |
Search.STR_INT_LONG_LABEL_ORDER, |
|
86 |
12 |
|
87 |
); |
|
88 |
for (Search.OrderedAttribute attrdesc : attributos) { |
|
89 |
this.columnNames.add(attrdesc.getDescriptor().getName()); |
|
90 |
} |
|
91 |
} else { |
|
92 |
this.columnNames = columnNames; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
public List<Feature> getFeatures() { |
|
97 |
return this.features; |
|
98 |
} |
|
99 |
|
|
100 |
@Override |
|
101 |
public int getRowCount() { |
|
102 |
if (this.features == null) { |
|
103 |
return 0; |
|
104 |
} |
|
105 |
return this.features.size(); |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public int getColumnCount() { |
|
110 |
return this.columnNames.size(); |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public String getColumnName(int columnIndex) { |
|
115 |
String attrName = this.columnNames.get(columnIndex); |
|
116 |
if (this.featureType == null) { |
|
117 |
return attrName; |
|
118 |
} |
|
119 |
FeatureAttributeDescriptor attrdesc = this.featureType.getAttributeDescriptor(attrName); |
|
120 |
if (attrdesc == null) { |
|
121 |
return "C" + columnIndex; |
|
122 |
} |
|
123 |
return attrdesc.getLocalizedShortLabel(); |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public Class<?> getColumnClass(int columnIndex) { |
|
128 |
if (this.featureType == null) { |
|
129 |
return String.class; |
|
130 |
} |
|
131 |
String attrName = this.columnNames.get(columnIndex); |
|
132 |
FeatureAttributeDescriptor attrdesc = this.featureType.getAttributeDescriptor(attrName); |
|
133 |
if (attrdesc == null) { |
|
134 |
return String.class; |
|
135 |
} |
|
136 |
if( attrdesc.isForeingKey() && attrdesc.getForeingKey().isClosedList() ) { |
|
137 |
return String.class; |
|
138 |
} |
|
139 |
Class theClass = attrdesc.getDataType().getDefaultClass(); |
|
140 |
if( theClass==null ) { |
|
141 |
return String.class; |
|
142 |
} |
|
143 |
return theClass; |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
|
148 |
return false; |
|
149 |
} |
|
150 |
|
|
151 |
@Override |
|
152 |
public Object getValueAt(int rowIndex, int columnIndex) { |
|
153 |
if (this.features == null) { |
|
154 |
return null; |
|
155 |
} |
|
156 |
try { |
|
157 |
Feature feature = this.features.get(rowIndex); |
|
158 |
String attrName = this.columnNames.get(columnIndex); |
|
159 |
Object value = feature.get(attrName); |
|
160 |
FeatureAttributeDescriptor attrdesc = this.featureType.getAttributeDescriptor(attrName); |
|
161 |
if (attrdesc != null) { |
|
162 |
if( attrdesc.isForeingKey() && attrdesc.getForeingKey().isClosedList() ) { |
|
163 |
value = attrdesc.getForeingKey().getLabelForValue(value); |
|
164 |
} |
|
165 |
} |
|
166 |
return value; |
|
167 |
} catch (Throwable th) { |
|
168 |
return null; |
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
@Override |
|
173 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
|
174 |
|
|
175 |
} |
|
176 |
} |
|
177 | 64 |
|
178 | 65 |
private class ActionButtons { |
179 | 66 |
|
... | ... | |
490 | 377 |
features = store.getFeatures(exp); |
491 | 378 |
} |
492 | 379 |
currentSearch = exp; |
493 |
model.setValue( new FeaturesTableModel( |
|
380 |
model.setValue( new SimpleFeaturesTableModel(
|
|
494 | 381 |
store.getDefaultFeatureType(), |
495 | 382 |
null, |
496 | 383 |
features |
... | ... | |
548 | 435 |
} |
549 | 436 |
} |
550 | 437 |
} |
551 |
FeaturesTableModel model = new FeaturesTableModel(this.getStore().getDefaultFeatureType());
|
|
438 |
SimpleFeaturesTableModel model = new SimpleFeaturesTableModel(this.getStore());
|
|
552 | 439 |
tblResults.setModel(model); |
553 | 440 |
lblMsg.setText(""); |
554 | 441 |
return true; |
... | ... | |
575 | 462 |
return null; |
576 | 463 |
} |
577 | 464 |
try { |
578 |
List<Feature> features = ((FeaturesTableModel) this.tblResults.getModel()).getFeatures(); |
|
465 |
List<Feature> features = ((SimpleFeaturesTableModel) this.tblResults.getModel()).getFeatures();
|
|
579 | 466 |
Feature feature = features.get(selectedRow); |
580 | 467 |
|
581 | 468 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
Also available in: Unified diff