diff --git a/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/rsc/DataStoreResource.java b/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/rsc/DataStoreResource.java index c34365a018..87ee8cc4f7 100644 --- a/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/rsc/DataStoreResource.java +++ b/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/rsc/DataStoreResource.java @@ -26,6 +26,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.core.runtime.ListenerList; import org.eclipse.jface.preference.IPreferenceStore; @@ -120,6 +121,7 @@ import com.vividsolutions.jts.geom.Point; * Mar 11, 2014 #2718 randerso Changes for GeoTools 10.5 * Mar 25, 2014 #2664 randerso Added support for non-WGS84 shape files * Apr 14, 2014 #2664 randerso Fix NullPointerException when no .prj file present + * Apr 21, 2014 #2998 randerso Stored types of attributes to be used in the AttributeViewer * * * @@ -452,11 +454,11 @@ public class DataStoreResource extends */ private TimeRange timeRange; - private String[] attributeNames; + private Map> attrTypeMap; private Object[][] attributes; - private Map displayAttributes; + protected Map displayAttributes; protected IWireframeShape outlineShape; @@ -578,11 +580,11 @@ public class DataStoreResource extends loadDataStore(); - getCapability(LabelableCapability.class).setAvailableLabelFields( - this.attributeNames); + String[] names = this.getAttributeNames(); + getCapability(LabelableCapability.class).setAvailableLabelFields(names); getCapability(ShadeableCapability.class).setAvailableShadingFields( - this.attributeNames); + names); IPreferenceStore prefs = Activator.getDefault().getPreferenceStore(); if (this.timeRange != null) { @@ -625,26 +627,22 @@ public class DataStoreResource extends List attrDesc = schema .getAttributeDescriptors(); - // TODO: Should ID be in attributes and if so do we need a more - // unique attribute name if (attrDesc == null) { - attributeNames = new String[] { ID_ATTRIBUTE_NAME }; + attrTypeMap = new HashMap>(1); + attrTypeMap.put(ID_ATTRIBUTE_NAME, Integer.class); } else { - List names = new ArrayList(attrDesc.size()); - names.add(ID_ATTRIBUTE_NAME); + attrTypeMap = new HashMap>(attrDesc.size(), + 1.0f); + attrTypeMap.put(ID_ATTRIBUTE_NAME, Integer.class); for (AttributeDescriptor at : attrDesc) { Class atType = at.getType().getBinding(); if (!Geometry.class.isAssignableFrom(atType)) { - names.add(at.getLocalName()); + attrTypeMap.put(at.getLocalName(), atType); } } - attributeNames = names.toArray(new String[names.size()]); } - displayAttributes = new HashMap( - (int) Math.ceil(attributeNames.length / 0.75f), 0.75f); - timer.stop(); perfLog.logDuration("loadDataStore", timer.getElapsedTime()); } catch (Exception e) { @@ -694,7 +692,9 @@ public class DataStoreResource extends featureCollection = featureSource.getFeatures(query); int size = featureCollection.size(); - attributes = new Object[size][attributeNames.length]; + Set attributeNames = attrTypeMap.keySet(); + attributes = new Object[size][attributeNames.size()]; + featureIterator = featureCollection.features(); int i = 0; while (featureIterator.hasNext()) { @@ -708,9 +708,10 @@ public class DataStoreResource extends incomingToLatLon)); attributes[index][0] = id; - for (int j = 1; j < attributeNames.length; j++) { - Object attr = f.getAttribute(attributeNames[j]); - attributes[index][j] = attr; + int j = 1; + for (String attrName : attributeNames) { + Object attr = f.getAttribute(attrName); + attributes[index][j++] = attr; } } } catch (Exception e) { @@ -1266,7 +1267,18 @@ public class DataStoreResource extends * @return the attribute names */ public String[] getAttributeNames() { - return attributeNames; + return attrTypeMap.keySet().toArray(new String[attrTypeMap.size()]); + } + + /** + * Get Java type of an attribute + * + * @param attributeName + * name of the desired attribute + * @return the type + */ + public Class getAttributeType(String attributeName) { + return attrTypeMap.get(attributeName); } /** diff --git a/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/rsc/ReloadJob.java b/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/rsc/ReloadJob.java index 697f839864..6948a7b57e 100644 --- a/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/rsc/ReloadJob.java +++ b/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/rsc/ReloadJob.java @@ -59,6 +59,7 @@ import com.vividsolutions.jts.geom.Point; * Feb 18, 2014 #2819 randerso Removed unnecessary clones of geometries * Mar 11, 2014 #2718 randerso Changes for GeoTools 10.5 * Mar 25, 2014 #2664 randerso Added support for non-WGS84 shape files + * Apr 21, 2014 #2998 randerso Make a better stab at sizing displayAttributes correctly * * * @@ -289,6 +290,12 @@ class ReloadJob extends Job { featureCollection = featureSource.getFeatures(query); featureIterator = featureCollection.features(); + if (req.rsc.displayAttributes == null) { + req.rsc.displayAttributes = new HashMap( + (int) Math.ceil(featureCollection.size() / 0.75f), + 0.75f); + } + // TODO: do we need to implement the GeometryCache/gidMap // stuff like in DbMapResource? diff --git a/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/ui/AttributeViewer.java b/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/ui/AttributeViewer.java index d177871fd8..cd96e03f91 100644 --- a/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/ui/AttributeViewer.java +++ b/cave/com.raytheon.uf.viz.gisdatastore/src/com/raytheon/uf/viz/gisdatastore/ui/AttributeViewer.java @@ -83,6 +83,8 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * Mar 21, 2013 1638 mschenke Created Pair class internal so no dependencies on GFE * Jul 24, 2013 #1908 randerso Added support for updating attributes when resource cropped. * Code cleanup + * Apr 21, 2014 #2998 randerso Changed to use attribute type (not type of attribute value + * which may be null) to determine alignment of column. * * * @@ -326,7 +328,6 @@ public class AttributeViewer extends CaveJFACEDialog implements RemoveListener, Table table = viewer.getTable(); table.setHeaderVisible(true); - // table.setLinesVisible(true); table.setSortDirection(SWT.UP); comparator = new ColumnComparator(); ArrayList> sortOrder = new ArrayList>( @@ -341,16 +342,13 @@ public class AttributeViewer extends CaveJFACEDialog implements RemoveListener, for (String attrName : names) { int index = i++; int alignment = SWT.LEFT; - if (this.attributes[0][index] instanceof Integer) { + if (Number.class.isAssignableFrom(rsc.getAttributeType(attrName))) { alignment = SWT.RIGHT; } TableViewerColumn tvc = new TableViewerColumn(viewer, alignment, index); final TableColumn column = tvc.getColumn(); column.setText(attrName); - // column.addSelectionListener(new - // ColumnSelectionAdapter(tableViewer, - // index)); column.pack(); int extent = column.getWidth(); for (Object[] atts : this.attributes) {