Merge "Issue #2998 Fixed null pointer in AttributeViewer. Improved sizing of displayAttributes." into development

Former-commit-id: efdd37b012 [formerly 750c054ab0] [formerly 5f82bb7cc8 [formerly 3038cbecf8efc76c76cdc86702986069788b6a02]]
Former-commit-id: 5f82bb7cc8
Former-commit-id: 1df03eb2dc
This commit is contained in:
Ron Anderson 2014-04-21 13:25:11 -05:00 committed by Gerrit Code Review
commit 020045fee3
3 changed files with 42 additions and 25 deletions

View file

@ -26,6 +26,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.preference.IPreferenceStore; 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 11, 2014 #2718 randerso Changes for GeoTools 10.5
* Mar 25, 2014 #2664 randerso Added support for non-WGS84 shape files * 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 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
* *
* </pre> * </pre>
* *
@ -452,11 +454,11 @@ public class DataStoreResource extends
*/ */
private TimeRange timeRange; private TimeRange timeRange;
private String[] attributeNames; private Map<String, Class<?>> attrTypeMap;
private Object[][] attributes; private Object[][] attributes;
private Map<String, DisplayAttributes> displayAttributes; protected Map<String, DisplayAttributes> displayAttributes;
protected IWireframeShape outlineShape; protected IWireframeShape outlineShape;
@ -578,11 +580,11 @@ public class DataStoreResource extends
loadDataStore(); loadDataStore();
getCapability(LabelableCapability.class).setAvailableLabelFields( String[] names = this.getAttributeNames();
this.attributeNames); getCapability(LabelableCapability.class).setAvailableLabelFields(names);
getCapability(ShadeableCapability.class).setAvailableShadingFields( getCapability(ShadeableCapability.class).setAvailableShadingFields(
this.attributeNames); names);
IPreferenceStore prefs = Activator.getDefault().getPreferenceStore(); IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();
if (this.timeRange != null) { if (this.timeRange != null) {
@ -625,26 +627,22 @@ public class DataStoreResource extends
List<AttributeDescriptor> attrDesc = schema List<AttributeDescriptor> attrDesc = schema
.getAttributeDescriptors(); .getAttributeDescriptors();
// TODO: Should ID be in attributes and if so do we need a more
// unique attribute name
if (attrDesc == null) { if (attrDesc == null) {
attributeNames = new String[] { ID_ATTRIBUTE_NAME }; attrTypeMap = new HashMap<String, Class<?>>(1);
attrTypeMap.put(ID_ATTRIBUTE_NAME, Integer.class);
} else { } else {
List<String> names = new ArrayList<String>(attrDesc.size()); attrTypeMap = new HashMap<String, Class<?>>(attrDesc.size(),
names.add(ID_ATTRIBUTE_NAME); 1.0f);
attrTypeMap.put(ID_ATTRIBUTE_NAME, Integer.class);
for (AttributeDescriptor at : attrDesc) { for (AttributeDescriptor at : attrDesc) {
Class<?> atType = at.getType().getBinding(); Class<?> atType = at.getType().getBinding();
if (!Geometry.class.isAssignableFrom(atType)) { if (!Geometry.class.isAssignableFrom(atType)) {
names.add(at.getLocalName()); attrTypeMap.put(at.getLocalName(), atType);
} }
} }
attributeNames = names.toArray(new String[names.size()]);
} }
displayAttributes = new HashMap<String, DataStoreResource.DisplayAttributes>(
(int) Math.ceil(attributeNames.length / 0.75f), 0.75f);
timer.stop(); timer.stop();
perfLog.logDuration("loadDataStore", timer.getElapsedTime()); perfLog.logDuration("loadDataStore", timer.getElapsedTime());
} catch (Exception e) { } catch (Exception e) {
@ -694,7 +692,9 @@ public class DataStoreResource extends
featureCollection = featureSource.getFeatures(query); featureCollection = featureSource.getFeatures(query);
int size = featureCollection.size(); int size = featureCollection.size();
attributes = new Object[size][attributeNames.length]; Set<String> attributeNames = attrTypeMap.keySet();
attributes = new Object[size][attributeNames.size()];
featureIterator = featureCollection.features(); featureIterator = featureCollection.features();
int i = 0; int i = 0;
while (featureIterator.hasNext()) { while (featureIterator.hasNext()) {
@ -708,9 +708,10 @@ public class DataStoreResource extends
incomingToLatLon)); incomingToLatLon));
attributes[index][0] = id; attributes[index][0] = id;
for (int j = 1; j < attributeNames.length; j++) { int j = 1;
Object attr = f.getAttribute(attributeNames[j]); for (String attrName : attributeNames) {
attributes[index][j] = attr; Object attr = f.getAttribute(attrName);
attributes[index][j++] = attr;
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -1266,7 +1267,18 @@ public class DataStoreResource extends
* @return the attribute names * @return the attribute names
*/ */
public String[] getAttributeNames() { 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);
} }
/** /**

View file

@ -59,6 +59,7 @@ import com.vividsolutions.jts.geom.Point;
* Feb 18, 2014 #2819 randerso Removed unnecessary clones of geometries * Feb 18, 2014 #2819 randerso Removed unnecessary clones of geometries
* Mar 11, 2014 #2718 randerso Changes for GeoTools 10.5 * Mar 11, 2014 #2718 randerso Changes for GeoTools 10.5
* Mar 25, 2014 #2664 randerso Added support for non-WGS84 shape files * 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
* *
* </pre> * </pre>
* *
@ -289,6 +290,12 @@ class ReloadJob extends Job {
featureCollection = featureSource.getFeatures(query); featureCollection = featureSource.getFeatures(query);
featureIterator = featureCollection.features(); featureIterator = featureCollection.features();
if (req.rsc.displayAttributes == null) {
req.rsc.displayAttributes = new HashMap<String, DataStoreResource.DisplayAttributes>(
(int) Math.ceil(featureCollection.size() / 0.75f),
0.75f);
}
// TODO: do we need to implement the GeometryCache/gidMap // TODO: do we need to implement the GeometryCache/gidMap
// stuff like in DbMapResource? // stuff like in DbMapResource?

View file

@ -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 * 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. * Jul 24, 2013 #1908 randerso Added support for updating attributes when resource cropped.
* Code cleanup * 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.
* *
* </pre> * </pre>
* *
@ -326,7 +328,6 @@ public class AttributeViewer extends CaveJFACEDialog implements RemoveListener,
Table table = viewer.getTable(); Table table = viewer.getTable();
table.setHeaderVisible(true); table.setHeaderVisible(true);
// table.setLinesVisible(true);
table.setSortDirection(SWT.UP); table.setSortDirection(SWT.UP);
comparator = new ColumnComparator(); comparator = new ColumnComparator();
ArrayList<Pair<String, Integer>> sortOrder = new ArrayList<Pair<String, Integer>>( ArrayList<Pair<String, Integer>> sortOrder = new ArrayList<Pair<String, Integer>>(
@ -341,16 +342,13 @@ public class AttributeViewer extends CaveJFACEDialog implements RemoveListener,
for (String attrName : names) { for (String attrName : names) {
int index = i++; int index = i++;
int alignment = SWT.LEFT; int alignment = SWT.LEFT;
if (this.attributes[0][index] instanceof Integer) { if (Number.class.isAssignableFrom(rsc.getAttributeType(attrName))) {
alignment = SWT.RIGHT; alignment = SWT.RIGHT;
} }
TableViewerColumn tvc = new TableViewerColumn(viewer, alignment, TableViewerColumn tvc = new TableViewerColumn(viewer, alignment,
index); index);
final TableColumn column = tvc.getColumn(); final TableColumn column = tvc.getColumn();
column.setText(attrName); column.setText(attrName);
// column.addSelectionListener(new
// ColumnSelectionAdapter(tableViewer,
// index));
column.pack(); column.pack();
int extent = column.getWidth(); int extent = column.getWidth();
for (Object[] atts : this.attributes) { for (Object[] atts : this.attributes) {