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 / featuretable / SimpleFeaturesTableModelImpl.java @ 47818
History | View | Annotate | Download (21.7 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.featuretable; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Component; |
5 |
import java.awt.Font; |
6 |
import java.awt.FontMetrics; |
7 |
import java.awt.Insets; |
8 |
import java.awt.image.BufferedImage; |
9 |
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel; |
10 |
import java.util.ArrayList; |
11 |
import java.util.Collections; |
12 |
import java.util.Iterator; |
13 |
import java.util.List; |
14 |
import java.util.Map; |
15 |
import java.util.Objects; |
16 |
import javax.swing.ImageIcon; |
17 |
import javax.swing.JCheckBox; |
18 |
import javax.swing.JComponent; |
19 |
import javax.swing.JLabel; |
20 |
import javax.swing.JTable; |
21 |
import javax.swing.SwingConstants; |
22 |
import javax.swing.UIManager; |
23 |
import javax.swing.table.AbstractTableModel; |
24 |
import javax.swing.table.DefaultTableCellRenderer; |
25 |
import javax.swing.table.DefaultTableColumnModel; |
26 |
import javax.swing.table.TableCellRenderer; |
27 |
import javax.swing.table.TableColumn; |
28 |
import org.apache.commons.lang3.ArrayUtils; |
29 |
import org.apache.commons.lang3.StringUtils; |
30 |
import org.gvsig.expressionevaluator.Expression; |
31 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
32 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
33 |
import org.gvsig.fmap.dal.complements.Search; |
34 |
import org.gvsig.fmap.dal.exception.DataException; |
35 |
import org.gvsig.fmap.dal.feature.DataProfile; |
36 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
37 |
import org.gvsig.fmap.dal.feature.Feature; |
38 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
40 |
import org.gvsig.fmap.dal.feature.FeatureType; |
41 |
import org.gvsig.fmap.dal.feature.paging.FacadeOfAFeaturePagingHelper; |
42 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
43 |
import org.gvsig.tools.ToolsLocator; |
44 |
import org.gvsig.tools.dataTypes.DataTypeUtils; |
45 |
import org.gvsig.tools.dataTypes.DataTypes; |
46 |
import org.gvsig.tools.dispose.DisposeUtils; |
47 |
import org.gvsig.tools.dynobject.DynObjectManager; |
48 |
import org.gvsig.tools.dynobject.Tags; |
49 |
import org.gvsig.tools.i18n.I18nManager; |
50 |
import org.gvsig.tools.logger.FilteredLogger; |
51 |
import org.gvsig.tools.swing.api.SimpleImage; |
52 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
53 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
54 |
import org.slf4j.Logger; |
55 |
import org.slf4j.LoggerFactory; |
56 |
|
57 |
/**
|
58 |
*
|
59 |
* @author jjdelcerro
|
60 |
*/
|
61 |
public class SimpleFeaturesTableModelImpl |
62 |
extends AbstractTableModel |
63 |
implements SimpleFeaturesTableModel {
|
64 |
|
65 |
private static final String TAG_FEATURETABLEMODEL_IMAGE_WIDTH = "featuretablemodel.image.width"; |
66 |
private static final String TAG_FEATURETABLEMODEL_IMAGE_HEIGHT = "featuretablemodel.image.height"; |
67 |
|
68 |
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleFeaturesTableModelImpl.class); |
69 |
|
70 |
|
71 |
// public static class LegendOne implements TableCellRenderer {
|
72 |
// public LegendOne() {
|
73 |
//
|
74 |
// }
|
75 |
//
|
76 |
// @Override
|
77 |
// public Component getTableCellRendererComponent(JTable jtable, Object o, boolean bln, boolean bln1, int i, int i1) {
|
78 |
// TableCellRenderer renderer = this.getRenderByValue(o);
|
79 |
// Component xxx = renderer.getTableCellRendererComponent(jtable, o, bln, bln1, i, i1);
|
80 |
// return xxx;
|
81 |
// }
|
82 |
//
|
83 |
// public Object getSymbolByValue(Object value) {
|
84 |
//
|
85 |
// return null;
|
86 |
// }
|
87 |
//
|
88 |
// public TableCellRenderer getRenderByValue(Object value) {
|
89 |
// Object symbol = getSymbolByValue(value);
|
90 |
// return null;symbol.createRenderer();
|
91 |
// }
|
92 |
// }
|
93 |
|
94 |
|
95 |
public static class ColorRangeRenderer extends FeatureAttributeCellRenderer { |
96 |
|
97 |
private final double max; |
98 |
private final double min; |
99 |
|
100 |
public ColorRangeRenderer(FeatureAttributeDescriptor descriptor,double min, double max) { |
101 |
super(descriptor);
|
102 |
this.min = min;
|
103 |
this.max = max;
|
104 |
} |
105 |
|
106 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
107 |
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
108 |
|
109 |
if (this.getDescriptor().getDataType().isNumeric()) { |
110 |
double myvalue = 0; |
111 |
if (value==null) { |
112 |
myvalue = 0;
|
113 |
} else {
|
114 |
myvalue = DataTypeUtils.toDouble(value); |
115 |
} |
116 |
Color color = this.getColor(myvalue); |
117 |
label.setBackground(color); |
118 |
} |
119 |
return label;
|
120 |
} |
121 |
|
122 |
public Color getColor(double n) { |
123 |
if (n<=min) {
|
124 |
n = 0;
|
125 |
} else if(n>=max) { |
126 |
n = max-min; |
127 |
} |
128 |
int per = DataTypeUtils.toInteger((100*(n-min))/(max-min)); |
129 |
int R = (255 * per) / 100; |
130 |
int G = (255 * (100 - per)) / 100; |
131 |
int B = 0; |
132 |
Color color;
|
133 |
try {
|
134 |
color = new Color(R, G, B, 100); |
135 |
} catch(Exception ex) { |
136 |
color = Color.GRAY;
|
137 |
} |
138 |
return color;
|
139 |
} |
140 |
} |
141 |
|
142 |
private static class FeatureAttributeCellRenderer extends DefaultTableCellRenderer { |
143 |
|
144 |
private final FeatureAttributeDescriptor descriptor; |
145 |
private final JCheckBox check; |
146 |
|
147 |
public FeatureAttributeCellRenderer(FeatureAttributeDescriptor descriptor) {
|
148 |
this.descriptor = descriptor;
|
149 |
this.check = new JCheckBox(); |
150 |
this.check.setHorizontalAlignment(SwingConstants.CENTER); |
151 |
this.check.setBackground(UIManager.getColor(ToolsSwingManager.COLOR_TABLE_BACKGROUND)); |
152 |
} |
153 |
// @Override
|
154 |
// protected void setValue(Object value) {
|
155 |
// if (value == null) {
|
156 |
// setText("");
|
157 |
// } else {
|
158 |
// setText((String) descriptor.format(value));
|
159 |
// }
|
160 |
// }
|
161 |
|
162 |
@Override
|
163 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
164 |
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
165 |
label.setText("");
|
166 |
label.setIcon(null);
|
167 |
int type = descriptor.getType();
|
168 |
if (value instanceof Boolean && type==DataTypes.BOOLEAN) { |
169 |
check.setSelected((boolean) value);
|
170 |
check.setBackground(label.getBackground()); |
171 |
return check;
|
172 |
} |
173 |
if( type == DataTypes.BYTEARRAY ) {
|
174 |
label.setText("(binary)");
|
175 |
label.setHorizontalAlignment(SwingConstants.CENTER);
|
176 |
if( value == null ) { |
177 |
label.setText("null");
|
178 |
} else if( value instanceof SimpleImage ) { |
179 |
SimpleImage image = (SimpleImage) value; |
180 |
Tags tags = descriptor.getTags(); |
181 |
ImageIcon icon = createImageIcon(tags, image);
|
182 |
if( icon != null ) { |
183 |
label.setIcon(icon); |
184 |
label.setText("");
|
185 |
} |
186 |
} else if( StringUtils.equalsIgnoreCase("image", descriptor.getDataProfileName()) ) { |
187 |
DataProfile profile = descriptor.getDataProfile(); |
188 |
Tags tags = descriptor.getTags(); |
189 |
SimpleImage image = (SimpleImage) profile.createData(value, tags); |
190 |
if( image != null ) { |
191 |
ImageIcon icon = createImageIcon(tags, image);
|
192 |
if( icon != null ) { |
193 |
label.setIcon(icon); |
194 |
label.setText("");
|
195 |
} |
196 |
} |
197 |
} |
198 |
} else {
|
199 |
label.setText((String) descriptor.format(value));
|
200 |
if (descriptor.getAvailableValues()==null && (descriptor.getDataType().isNumeric() || |
201 |
type == DataTypes.TIMESTAMP || |
202 |
type == DataTypes.TIME || |
203 |
type == DataTypes.DATE)) { |
204 |
label.setHorizontalAlignment(SwingConstants.RIGHT);
|
205 |
} else if (type==DataTypes.BOOLEAN) { |
206 |
label.setHorizontalAlignment(SwingConstants.CENTER);
|
207 |
label.setText("null");
|
208 |
} else {
|
209 |
label.setHorizontalAlignment(SwingConstants.LEFT);
|
210 |
} |
211 |
} |
212 |
return label;
|
213 |
} |
214 |
|
215 |
public FeatureAttributeDescriptor getDescriptor() {
|
216 |
return this.descriptor; |
217 |
} |
218 |
|
219 |
private ImageIcon createImageIcon(Tags tags, SimpleImage image) { |
220 |
if( image == null ) { |
221 |
return null; |
222 |
} |
223 |
try {
|
224 |
int h = tags.getInt(TAG_FEATURETABLEMODEL_IMAGE_HEIGHT, 16); |
225 |
int w = tags.getInt(TAG_FEATURETABLEMODEL_IMAGE_WIDTH,
|
226 |
(image.getWidth()*h) / image.getHeight() |
227 |
); |
228 |
image = image.resize(w,h); |
229 |
if( image == null ) { |
230 |
return null; |
231 |
} |
232 |
BufferedImage bufferedImage = image.getBufferedImage();
|
233 |
if( bufferedImage == null ) { |
234 |
return null; |
235 |
} |
236 |
return new ImageIcon(bufferedImage); |
237 |
} catch(Throwable t) { |
238 |
LOGGER.debug("Can't create image",t);
|
239 |
return null; |
240 |
} |
241 |
} |
242 |
|
243 |
} |
244 |
|
245 |
private List<Feature> features; |
246 |
private final List<String> columnNames; |
247 |
private final FeatureType featureType; |
248 |
private FilteredLogger logger;
|
249 |
private boolean errors; |
250 |
|
251 |
public SimpleFeaturesTableModelImpl(FeatureStore store) throws DataException { |
252 |
this(store.getDefaultFeatureType(), null, store.getFeatures()); |
253 |
} |
254 |
|
255 |
public SimpleFeaturesTableModelImpl(FeatureStore store, Expression filter) throws DataException { |
256 |
this(store.getDefaultFeatureType(), null, store.getFeatures(filter)); |
257 |
} |
258 |
|
259 |
public SimpleFeaturesTableModelImpl(FeatureType featureType) {
|
260 |
this(featureType, null, null); |
261 |
this.logger = new FilteredLogger(LOGGER, "SimpleFeaturesTableModel", 10); |
262 |
} |
263 |
|
264 |
public SimpleFeaturesTableModelImpl(FeatureType featureType, List<String> columnNames, List<Feature> features) { |
265 |
this.logger = new FilteredLogger(LOGGER, "SimpleFeaturesTableModel", 10); |
266 |
this.features = features;
|
267 |
this.featureType = featureType;
|
268 |
this.errors = false; |
269 |
if (columnNames == null || columnNames.isEmpty()) { |
270 |
this.columnNames = new ArrayList<>(); |
271 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
272 |
Search.COMPLEMENT_MANE, featureType |
273 |
); |
274 |
List<Search.OrderedAttribute> attributos = search.getOrderedAttributes(
|
275 |
Search.BASIC_TYPES_FILTER, |
276 |
Search.STR_INT_LONG_LABEL_ORDER, |
277 |
12
|
278 |
); |
279 |
for (Search.OrderedAttribute attrdesc : attributos) {
|
280 |
this.columnNames.add(attrdesc.getDescriptor().getName());
|
281 |
} |
282 |
} else {
|
283 |
this.columnNames = columnNames;
|
284 |
} |
285 |
} |
286 |
|
287 |
@Override
|
288 |
public List<String> getColumnNames() { |
289 |
return Collections.unmodifiableList(this.columnNames); |
290 |
} |
291 |
|
292 |
private int getColumnHeaderWidth(JTable table, TableColumn tableColumn) { |
293 |
|
294 |
String value = Objects.toString(tableColumn.getHeaderValue());
|
295 |
TableCellRenderer renderer = tableColumn.getHeaderRenderer();
|
296 |
if (renderer == null) { |
297 |
renderer = table.getTableHeader().getDefaultRenderer(); |
298 |
} |
299 |
JComponent c = (JComponent) renderer.getTableCellRendererComponent(table, value, false, false, -1, tableColumn.getModelIndex()); |
300 |
Font font = c.getFont();
|
301 |
FontMetrics fm = c.getFontMetrics(font);
|
302 |
int w = fm.stringWidth(value);
|
303 |
Insets insets = c.getInsets(null); |
304 |
int dx = insets.left + insets.right;
|
305 |
return w+dx;
|
306 |
} |
307 |
|
308 |
@Override
|
309 |
public void setCellRenderers(JTable table) { |
310 |
setCellRenderers(table, Collections.EMPTY_MAP);
|
311 |
} |
312 |
|
313 |
public void setCellRenderers(JTable table, Map<String, TableCellRenderer> renderers) { |
314 |
if ( table.getModel() != this ) { |
315 |
return;
|
316 |
} |
317 |
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
318 |
|
319 |
// JScrollPane js=new JScrollPane(table);
|
320 |
// js.setVisible(true);
|
321 |
// table.add(js);
|
322 |
|
323 |
DefaultTableColumnModel columnsModel = new DefaultTableColumnModel(); |
324 |
int n = 0; |
325 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
326 |
FeatureAttributeDescriptor descriptor = null;
|
327 |
for (String columnName : this.columnNames) { |
328 |
try {
|
329 |
descriptor = this.featureType.getAttributeDescriptor(columnName);
|
330 |
if (descriptor == null) { |
331 |
descriptor = this.featureType.getExtraColumns().get(columnName);
|
332 |
} |
333 |
TableColumn columnModel = new TableColumn(); |
334 |
columnModel.setModelIndex(n); |
335 |
columnModel.setHeaderValue(DALSwingLocator.getDataSwingManager().getAttributeDescriptorLabel(descriptor)); |
336 |
TableCellRenderer renderer = renderers.get(columnName);
|
337 |
if (renderer == null) { |
338 |
renderer = new FeatureAttributeCellRenderer(descriptor);
|
339 |
} |
340 |
columnModel.setCellRenderer(renderer); |
341 |
if (descriptor.getDisplaySize()>0) { |
342 |
int displaySize = ToolsSwingUtils.cols2px(descriptor.getDisplaySize());
|
343 |
columnModel.setPreferredWidth(displaySize); |
344 |
} |
345 |
columnsModel.addColumn(columnModel); |
346 |
n++; |
347 |
} catch (Exception ex) { |
348 |
throw new RuntimeException("Not able to get type of descriptor for column", ex); |
349 |
} |
350 |
} |
351 |
if (descriptor!=null && descriptor.getType()==DataTypes.STRING) { |
352 |
table.getTableHeader().setResizingColumn(columnsModel.getColumn(n-1));
|
353 |
} |
354 |
table.setColumnModel(columnsModel); |
355 |
n = 0;
|
356 |
for (String columnName : this.columnNames) { |
357 |
try {
|
358 |
descriptor = this.featureType.getAttributeDescriptor(columnName);
|
359 |
if (descriptor == null) { |
360 |
descriptor = this.featureType.getExtraColumns().get(columnName);
|
361 |
} |
362 |
TableColumn columnModel = columnsModel.getColumn(n);
|
363 |
if (descriptor.getDisplaySize()<=0) { |
364 |
columnModel.setPreferredWidth(getColumnHeaderWidth(table, columnModel)); |
365 |
} |
366 |
n++; |
367 |
} catch (Exception ex) { |
368 |
throw new RuntimeException("Not able to get type of descriptor for column", ex); |
369 |
} |
370 |
} |
371 |
table.setColumnModel(columnsModel); |
372 |
} |
373 |
|
374 |
@Override
|
375 |
public List<Feature> getFeatures() { |
376 |
return this.features; |
377 |
} |
378 |
|
379 |
@Override
|
380 |
public void dispose() { |
381 |
if (this.features != null) { |
382 |
if( this.features instanceof FacadeOfAFeaturePagingHelper) { |
383 |
DisposeUtils.disposeQuietly(((FacadeOfAFeaturePagingHelper) features).getFeaturePagingHelper()); |
384 |
} else {
|
385 |
DisposeUtils.disposeQuietly(features); |
386 |
} |
387 |
this.features = null; |
388 |
} |
389 |
this.features = null; |
390 |
} |
391 |
|
392 |
@Override
|
393 |
public int getRowCount() { |
394 |
if (this.getFeatures() == null) { |
395 |
return 0; |
396 |
} |
397 |
try {
|
398 |
return this.getFeatures().size(); |
399 |
} catch (Throwable ex) { |
400 |
this.errors = true; |
401 |
LOGGER.warn("Can't calculate row count.", ex);
|
402 |
return 0; |
403 |
} |
404 |
} |
405 |
|
406 |
@Override
|
407 |
public boolean hasErrors() { |
408 |
return this.errors; |
409 |
} |
410 |
|
411 |
@Override
|
412 |
public int getColumnCount() { |
413 |
return this.columnNames.size(); |
414 |
} |
415 |
|
416 |
@Override
|
417 |
public String getColumnName(int columnIndex) { |
418 |
String attrName = this.columnNames.get(columnIndex); |
419 |
if (this.featureType == null) { |
420 |
return attrName;
|
421 |
} |
422 |
FeatureAttributeDescriptor attrdesc = this.featureType.getAttributeDescriptor(attrName);
|
423 |
if (attrdesc == null) { |
424 |
EditableFeatureAttributeDescriptor extraCol = this.featureType.getExtraColumns().get(attrName);
|
425 |
if (extraCol != null) { |
426 |
return extraCol.getLocalizedShortLabel();
|
427 |
} |
428 |
if (attrName == null) { |
429 |
return "Column" + columnIndex; |
430 |
} |
431 |
return attrName;
|
432 |
} |
433 |
return attrdesc.getLocalizedShortLabel();
|
434 |
} |
435 |
|
436 |
@Override
|
437 |
public Class<?> getColumnClass(int columnIndex) { |
438 |
if (this.featureType == null) { |
439 |
return String.class; |
440 |
} |
441 |
try {
|
442 |
String attrName = this.columnNames.get(columnIndex); |
443 |
FeatureAttributeDescriptor attrdesc = this.featureType.getAttributeDescriptor(attrName);
|
444 |
if (attrdesc == null) { |
445 |
int extraIndex = featureType.getExtraColumns().getIndexOf(attrName);
|
446 |
if (extraIndex != -1) { |
447 |
attrdesc = featureType.getExtraColumns().get(extraIndex); |
448 |
} |
449 |
} |
450 |
if (attrdesc == null) { |
451 |
return String.class; |
452 |
} |
453 |
if (attrdesc.isForeingKey() && attrdesc.getForeingKey().isClosedList()) {
|
454 |
return String.class; |
455 |
} |
456 |
Class theClass = attrdesc.getDataType().getDefaultClass();
|
457 |
if (theClass == null) { |
458 |
return String.class; |
459 |
} |
460 |
return theClass;
|
461 |
} catch (Exception ex) { |
462 |
return String.class; |
463 |
} |
464 |
} |
465 |
|
466 |
@Override
|
467 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
468 |
return false; |
469 |
} |
470 |
|
471 |
public FeatureAttributeDescriptor getFeatureDescriptor(int columnIndex) { |
472 |
String attrName = this.columnNames.get(columnIndex); |
473 |
if (this.featureType == null) { |
474 |
return null; |
475 |
} |
476 |
for (FeatureAttributeDescriptor attr : this.featureType.getAllAttributeDescriptors()) { |
477 |
if (StringUtils.equals(attrName,attr.getName())) {
|
478 |
return attr;
|
479 |
} |
480 |
} |
481 |
return null; |
482 |
} |
483 |
|
484 |
@Override
|
485 |
public Feature get(int position) { |
486 |
if (this.getFeatures() == null) { |
487 |
return null; |
488 |
} |
489 |
Feature feature = this.getFeatures().get(position);
|
490 |
return feature;
|
491 |
} |
492 |
|
493 |
@Override
|
494 |
public Feature getFeatureAt(int rowIndex) { |
495 |
if (this.getFeatures() == null || rowIndex<0 ) { |
496 |
return null; |
497 |
} |
498 |
try {
|
499 |
Feature feature = this.getFeatures().get(rowIndex);
|
500 |
return feature;
|
501 |
} catch (Throwable th) { |
502 |
this.errors = true; |
503 |
logger.warn("Can't get feature at row " + rowIndex + ".", th); |
504 |
return null; |
505 |
} |
506 |
} |
507 |
|
508 |
@Override
|
509 |
public Object getValueAt(int rowIndex, int columnIndex) { |
510 |
if (this.getFeatures() == null) { |
511 |
return null; |
512 |
} |
513 |
try {
|
514 |
Feature feature = this.getFeatures().get(rowIndex);
|
515 |
return this.getValueAt(feature, columnIndex); |
516 |
} catch (Throwable th) { |
517 |
this.errors = true; |
518 |
logger.warn("Can't get cell value at " + rowIndex + ", " + columnIndex + ".", th); |
519 |
return null; |
520 |
} |
521 |
} |
522 |
|
523 |
public Object getValueAt(Feature feature, int columnIndex) { |
524 |
String attrName = this.columnNames.get(columnIndex); |
525 |
Object value = null; |
526 |
value = feature.get(attrName); |
527 |
FeatureAttributeDescriptor attrdesc = this.featureType.getAttributeDescriptor(attrName);
|
528 |
if(attrdesc == null && this.featureType.getExtraColumns().get(attrName)!=null) { |
529 |
attrdesc = this.featureType.getExtraColumns().get(attrName);
|
530 |
} |
531 |
if (attrdesc != null) { |
532 |
if (value == null) { |
533 |
return null; |
534 |
} |
535 |
if (attrdesc.isForeingKey() && attrdesc.getForeingKey().isClosedList()) {
|
536 |
value = attrdesc.getForeingKey().getLabelForValue(value); |
537 |
} |
538 |
} |
539 |
return value;
|
540 |
} |
541 |
|
542 |
@Override
|
543 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
544 |
|
545 |
} |
546 |
|
547 |
@Override
|
548 |
public List<Feature> toList() { |
549 |
return this.getFeatures(); |
550 |
} |
551 |
|
552 |
@Override
|
553 |
public boolean isEmpty() { |
554 |
return this.getFeatures().isEmpty(); |
555 |
} |
556 |
|
557 |
@Override
|
558 |
public int size() { |
559 |
return this.getFeatures().size(); |
560 |
} |
561 |
|
562 |
@Override
|
563 |
public Iterator<Feature> iterator() { |
564 |
return this.getFeatures().iterator(); |
565 |
} |
566 |
|
567 |
public static void selfRegister() { |
568 |
DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager(); |
569 |
dynObjectManager.registerTag(TAG_FEATURETABLEMODEL_IMAGE_HEIGHT, "Height to use when images have to be represented in a table, by default 48.");
|
570 |
dynObjectManager.registerTag(TAG_FEATURETABLEMODEL_IMAGE_WIDTH, "Width to use when images have to be represented in a table, by default 48.");
|
571 |
} |
572 |
|
573 |
@Override
|
574 |
public Expression getFeaturesFilter(int[] rows) { |
575 |
if( ArrayUtils.isEmpty(rows) ) {
|
576 |
return null; |
577 |
} |
578 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
579 |
for (int row : rows) { |
580 |
Feature feature = this.getFeatureAt(row);
|
581 |
if( feature == null ) { |
582 |
continue;
|
583 |
} |
584 |
ExpressionBuilder filter = feature.createBuilderFilter(); |
585 |
if( filter == null ) { |
586 |
continue;
|
587 |
} |
588 |
builder.or(filter.value()); |
589 |
} |
590 |
if( builder.value() == null ) { |
591 |
return null; |
592 |
} |
593 |
Expression filter = ExpressionUtils.createExpression(builder.toString());
|
594 |
return filter;
|
595 |
} |
596 |
} |