Issue #2998 Fixed null pointer in AttributeViewer.

Improved sizing of displayAttributes.

Change-Id: I40b3dc486a713f6ba6ce6f5075ffce1eb6555f93

Former-commit-id: 541a908a41 [formerly 811f05f164 [formerly 0fac12a4f17de189a88e6dd4415f6364afc4f459]]
Former-commit-id: 811f05f164
Former-commit-id: a3a8a1ebb4
This commit is contained in:
Ron Anderson 2014-04-21 13:03:50 -05:00
parent 8a6655cb35
commit a506479e56
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.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
*
* </pre>
*
@ -452,11 +454,11 @@ public class DataStoreResource extends
*/
private TimeRange timeRange;
private String[] attributeNames;
private Map<String, Class<?>> attrTypeMap;
private Object[][] attributes;
private Map<String, DisplayAttributes> displayAttributes;
protected Map<String, DisplayAttributes> 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<AttributeDescriptor> 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<String, Class<?>>(1);
attrTypeMap.put(ID_ATTRIBUTE_NAME, Integer.class);
} else {
List<String> names = new ArrayList<String>(attrDesc.size());
names.add(ID_ATTRIBUTE_NAME);
attrTypeMap = new HashMap<String, Class<?>>(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<String, DataStoreResource.DisplayAttributes>(
(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<String> 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);
}
/**

View file

@ -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
*
* </pre>
*
@ -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<String, DataStoreResource.DisplayAttributes>(
(int) Math.ceil(featureCollection.size() / 0.75f),
0.75f);
}
// TODO: do we need to implement the GeometryCache/gidMap
// 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
* 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.
*
* </pre>
*
@ -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<Pair<String, Integer>> sortOrder = new ArrayList<Pair<String, Integer>>(
@ -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) {