[Schmitzm-commits] r534 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/gui skrueger skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Nov 20 11:28:06 CET 2009
Author: alfonx
Date: 2009-11-20 11:28:01 +0100 (Fri, 20 Nov 2009)
New Revision: 534
Modified:
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java
branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java
branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java
branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
Log:
* Added more documentation to AttributeMetadataMap
* Changed StyledFeatureCollectionTableModel to show the columns in the order that is defined in the AttributeMetaData.
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java 2009-11-19 17:27:01 UTC (rev 533)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java 2009-11-20 10:28:01 UTC (rev 534)
@@ -144,7 +144,7 @@
featuresTable.getParent().setPreferredSize(new Dimension(400, 300));
featuresTable.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
- // In the NORTH, the ToolBar and a JLabel presenting the total and selected number of features is displayed
+ // In the NORTH, the ToolBar and a JLabel presenting the total and selected number of features is displayed
JPanel north = new JPanel(new BorderLayout());
north.add(getToolBar(), BorderLayout.WEST);
north.add(getStatusLabel(), BorderLayout.EAST);
@@ -156,7 +156,6 @@
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()){
- if (!SwingUtilities.isEventDispatchThread()) throw new RuntimeException("Not on EDT!");
getStatusLabel();
}
}
@@ -186,10 +185,12 @@
if (statusLabel == null){
statusLabel = new JLabel();
}
- // TODO Cache totalAnz and localizedGeometryTypeName. Do not recalc all the time!
int selectedAnz = getSelectedFeatures().size();
+
+ // TODO Cache totalAnz and localizedGeometryTypeName. Do not recalc all the time!
int totalAnz = getFeatureCollection().size();
+
String localizedGeometryTypeName = "rows";
switch ( FeatureUtil.getGeometryForm(getFeatureCollection()) ){
Modified: branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009-11-19 17:27:01 UTC (rev 533)
+++ branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009-11-20 10:28:01 UTC (rev 534)
@@ -50,99 +50,68 @@
*/
public class AttributeMetadata implements Copyable<AttributeMetadata>,
Comparable<AttributeMetadata> {
+
static private final Logger LOGGER = Logger
.getLogger(AttributeMetadata.class);
- // public class WeightComparator implements Comparator<AttributeDescriptor>
- // {
- //
- // @Override
- // public int compare(AttributeDescriptor o1, AttributeDescriptor o2) {
- // // TODO Auto-generated method stub
- // return 0;
- // }
- //
- // };
-
- /** Translation of the attribute's title **/
- protected Translation title = new Translation();
-
/** Translation of the attribute's description **/
protected Translation desc = new Translation();
- /** Is the attribute visible to the user or ignored where possible **/
- protected boolean visible = true;
+ /**
+ * For numerical attributes the value can be transformed by VALUE*X+A when
+ * presented on screen. TODO not implemented yet
+ **/
+ protected Double functionA = 0.;
/**
- * The unit append to all visualizations of values of this attribute (is not
- * null)
+ * For numerical attributes the value can be transformed by VALUE*X+A when
+ * presented on screen. TODO not implemented yet
**/
- protected String unit = "";
+ protected Double functionX = 1.;
/** The Name of the attribute **/
private Name name;
- public int getWeight() {
- return weight;
- }
-
- public void setWeight(int weight) {
- this.weight = weight;
- }
-
- public List<Object> getNodataValues() {
- return nodataValues;
- }
-
- public void setNodataValues(List<Object> nodataValues) {
- this.nodataValues = nodataValues;
- }
-
- public Double getFunctionX() {
- return functionX;
- }
-
- public void setFunctionX(Double functionX) {
- this.functionX = functionX;
- }
-
- public Double getFunctionA() {
- return functionA;
- }
-
- public void setFunctionA(Double functionA) {
- this.functionA = functionA;
- }
-
- public void setVisible(boolean visible) {
- this.visible = visible;
- }
-
/**
- * When listed, the attributes are listed according to their weight (heavier
- * => further down)
- **/
- protected int weight = 0;
-
- /**
* Allows to define general NODATA values for an attribute. e.g. -9999 can
* be set and will always be interpreted as NULL internally and will usually
- * be ignored.
+ * be ignored. TODO not implemented yet
**/
protected List<Object> nodataValues = new ArrayList<Object>();
+ /** Translation of the attribute's title **/
+ protected Translation title = new Translation();
+
/**
- * For numerical attributes the value can be transformed by VALUE*X+A when
- * presented on screen
+ * The unit append to all visualizations of values of this attribute (is not
+ * null)
**/
- protected Double functionX = 1.;
+ protected String unit = "";
+ /** Is the attribute visible to the user or ignored where possible **/
+ protected boolean visible = true;
+
/**
- * For numerical attributes the value can be transformed by VALUE*X+A when
- * presented on screen
+ * When listed, the attributes are listed according to their {@link #weight} (heavier
+ * => further down)
+ * @see #compareTo(AttributeMetadata)
**/
- protected Double functionA = 0.;
+ protected int weight = 0;
+ /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
+ private AttributeMetadata() {
+ }
+
+ public AttributeMetadata(final AttributeDescriptor attDesc, final int weight,
+ final List<String> langs) {
+ this(attDesc.getName(), langs);
+ setWeight(weight);
+ }
+
+ public AttributeMetadata(final AttributeDescriptor attDesc, final List<String> langs) {
+ this(attDesc.getName(), langs);
+ }
+
/**
* Creates an {@link AttributeMetadata} object with the following
* information
@@ -165,17 +134,34 @@
this.setName(name);
this.title = title;
this.desc = desc;
+//
+// // The THE_GEOM and shall never be visible!
+// if (name.getLocalPart().equalsIgnoreCase("the_geom"))
+// this.visible = false;
+// else
+// this.visible = visible;
- // The THE_GEOM and shall never be visible!
- if (name.getLocalPart().equalsIgnoreCase("the_geom"))
- this.visible = false;
- else
- this.visible = visible;
-
this.unit = unit;
}
/**
+ * Creates a new visible {@link AttributeMetadata}
+ */
+ public AttributeMetadata(final Name name, final List<String> langs) {
+ this(name, true, new Translation(langs, name.getLocalPart()),
+ new Translation(), "");
+ }
+
+ /**
+ * Creates a new visible {@link AttributeMetadata}
+ */
+ public AttributeMetadata(final Name name, final String defaultTitle,
+ final List<String> langs) {
+ this(name, true, new Translation(langs, defaultTitle),
+ new Translation(), "");
+ }
+
+ /**
* Creates an {@link AttributeMetadata} object with the following
* information
*
@@ -196,153 +182,192 @@
/**
* Creates a new visible {@link AttributeMetadata} with default (no) values.
*/
- public AttributeMetadata(final String localName, final String defaultTitle, List<String> langs) {
- this(localName, true, new Translation(langs, defaultTitle), new Translation(),
- "");
+ public AttributeMetadata(final String localName, final List<String> langs) {
+ this(localName, true, new Translation(langs, localName),
+ new Translation(), "");
}
/**
- * Creates a new visible {@link AttributeMetadata} with default (no) values.
+ * Creates a new visible {@link AttributeMetadata}
*/
- public AttributeMetadata(final Name name, final String defaultTitle, List<String> langs) {
- this(name, true, new Translation(langs, defaultTitle), new Translation(), "");
+ public AttributeMetadata(final String localName, final String defaultTitle,
+ final List<String> langs) {
+ this(localName, true, new Translation(langs, defaultTitle),
+ new Translation(), "");
}
/**
- * Creates a new visible {@link AttributeMetadata} with default (no) values.
+ * Orders the attributes according to their {@link #weight}. Heavier =>
+ * further down.
*/
- public AttributeMetadata(final Name name, List<String> langs) {
- this(name, true, new Translation(langs, name.getLocalPart()),
- new Translation(), "");
+ @Override
+ public int compareTo(final AttributeMetadata atm2) {
+ return new Integer(weight).compareTo(atm2.getWeight());
}
/**
- * Creates a new visible {@link AttributeMetadata} with default (no) values.
+ * @see Copyable inferface
*/
- public AttributeMetadata(final String localName, List<String> langs) {
- this(localName, true, new Translation(langs, localName), new Translation(), "");
+ @Override
+ public AttributeMetadata copy() {
+ return copyTo(new AttributeMetadata());
}
- /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
- private AttributeMetadata() {
+ /**
+ * @see Copyable inferface
+ */
+ @Override
+ public AttributeMetadata copyTo(final AttributeMetadata amd) {
+ getTitle().copyTo(amd.getTitle());
+ getDesc().copyTo(amd.getDesc());
+ amd.setUnit(getUnit());
+ amd.setVisible(isVisible());
+ amd.setName(new NameImpl(getName().getNamespaceURI(), getName()
+ .getLocalPart()));
+
+ amd.setWeight(getWeight());
+ amd.setFunctionX(getFunctionX());
+ amd.setFunctionA(getFunctionA());
+
+ for (final Object nodataValue : getNodataValues()) {
+ amd.getNodataValues().add(nodataValue);
+ }
+
+ return amd;
}
- public AttributeMetadata(AttributeDescriptor attDesc, List<String> langs) {
- this(attDesc.getName(), langs);
+ public Translation getDesc() {
+ return desc;
}
- public AttributeMetadata(AttributeDescriptor attDesc, int weight, List<String> langs) {
- this(attDesc.getName(), langs);
- setWeight(weight);
+ public Double getFunctionA() {
+ return functionA;
}
- public boolean isVisible() {
- return visible;
+ public Double getFunctionX() {
+ return functionX;
}
- public void setVisible(final Boolean visible) {
-
- // The THE_GEOM and shall never be visible! // TODO MAKE BETTER
- if (name.getLocalPart().equalsIgnoreCase("the_geom"))
- this.visible = false;
- else
- this.visible = visible;
-
- this.visible = visible;
+ /**
+ * The local name. E.g. the name of the DBF column as a {@link String}
+ */
+ public String getLocalName() {
+ return getName().getLocalPart();
}
- public Translation getTitle() {
- return title;
+ /**
+ * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>
+ */
+ public Name getName() {
+ return name;
}
- public void setTitle(final Translation title) {
- this.title = title;
+ public List<Object> getNodataValues() {
+ return nodataValues;
}
- public Translation getDesc() {
- return desc;
+ /**
+ * @return a number between 0 (bad) and 1 (good) that is calculated from the
+ * amount of translation available. If this attribute is not
+ * {@link #visible}, it will return 1.
+ */
+ public double getQuality(final List<String> languages) {
+
+ if (!isVisible())
+ return 1.;
+
+ return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
+ .qmTranslation(languages, getDesc()) * 1.) / 3.;
}
- public void setDesc(final Translation desc) {
- this.desc = desc;
+ public Translation getTitle() {
+ return title;
}
public String getUnit() {
return unit;
}
- public void setUnit(final String unit) {
- this.unit = unit;
+ public int getWeight() {
+ return weight;
}
- @Override
- public AttributeMetadata copyTo(AttributeMetadata amd) {
- getTitle().copyTo(amd.getTitle());
- getDesc().copyTo(amd.getDesc());
- amd.setUnit(getUnit());
- amd.setVisible(isVisible());
- amd.setName(new NameImpl(getName().getNamespaceURI(), getName()
- .getLocalPart()));
+ /**
+ * Will the end-user see this attribute?
+ */
+ public boolean isVisible() {
+ return visible;
+ }
- amd.setWeight(getWeight());
- amd.setFunctionX(getFunctionX());
- amd.setFunctionA(getFunctionA());
-
- for (Object nodataValue : getNodataValues()) {
- amd.getNodataValues().add(nodataValue);
- }
-
- return amd;
+ public void setDesc(final Translation desc) {
+ this.desc = desc;
}
- @Override
- public AttributeMetadata copy() {
- return copyTo(new AttributeMetadata());
+ public void setFunctionA(final Double functionA) {
+ this.functionA = functionA;
}
- /**
- * The local Name. E.g. the name of the DBF column as a String
- */
- public String getLocalName() {
- return getName().getLocalPart();
+ public void setFunctionX(final Double functionX) {
+ this.functionX = functionX;
}
/**
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub
*/
- public Name getName() {
- return name;
+ public void setLocalName(final String localName) {
+ this.name = new NameImpl(localName);
}
/**
- * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
+ * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>
*/
- public void setName(org.opengis.feature.type.Name name) {
+ public void setName(final Name name) {
this.name = name;
}
- /**
- * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
- */
- public void setLocalName(String localName) {
- this.name = new NameImpl(localName);
+ public void setNodataValues(final List<Object> nodataValues) {
+ this.nodataValues = nodataValues;
}
+ public void setTitle(final Translation title) {
+ this.title = title;
+ }
+
+ public void setUnit(final String unit) {
+ this.unit = unit;
+ }
+
+ public void setVisible(final boolean visible) {
+ this.visible = visible;
+ }
+
/**
- * Orders the Attributes according to their weight. Heavier => further down.
+ * Shall the end-user see this attribute?
+ * @param visible
*/
- @Override
- public int compareTo(AttributeMetadata atm2) {
- // Double double1 = new Double(1./weight);
- // double double2 = 1./atm2.getWeight();
- return new Integer(weight).compareTo(atm2.getWeight());
+ public void setVisible(final Boolean visible) {
+// // The THE_GEOM and shall never be visible!
+// if (name.getLocalPart().equalsIgnoreCase("the_geom"))
+// this.visible = false;
+// else
+// this.visible = visible;
+
+ this.visible = visible;
}
+ public void setWeight(final int weight) {
+ this.weight = weight;
+ }
+
/**
- * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes
+ * For nicer debugging
*/
- public double getQuality(List<String> languages) {
- return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
- .qmTranslation(languages, getDesc()) * 1.) / 3.;
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ if (name != null) sb.append(name.toString()+" ");
+ sb.append("weight="+weight+" ");
+ sb.append("title="+getTitle().toString());
+ return sb.toString();
}
}
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java 2009-11-19 17:27:01 UTC (rev 533)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java 2009-11-20 10:28:01 UTC (rev 534)
@@ -3,97 +3,133 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.TreeMap;
import org.apache.log4j.Logger;
import org.geotools.feature.NameImpl;
import org.opengis.feature.type.Name;
-import cern.colt.Arrays;
-
import skrueger.AttributeMetadata;
-import skrueger.i8n.I8NUtil;
import skrueger.i8n.Translation;
/**
- * An extension of TreeMap, that is copyable in the sense of the {@link Copyable} interface
+ * The {@link AttributeMetadataMap} is a {@link Map} holding
+ * {@link AttributeMetadata} object for {@link Name} keys. It's an extension of
+ * a {@link TreeMap}. It's copyable in the sense of the {@link Copyable}
+ * interface.<br>
+ * The {@link #get(Name)} and {@link #get(String)} methods will never return
+ * <code>null</code>, but rather create a default {@link AttributeMetadata}
+ * on-the-fly.
*/
public class AttributeMetadataMap extends TreeMap<Name, AttributeMetadata>
implements Copyable<AttributeMetadataMap> {
- static private final Logger LOGGER = Logger.getLogger(AttributeMetadataMap.class);
- private List<String> langs;
-
- public AttributeMetadataMap(List<String> defLanguages) {
- langs = defLanguages;
- }
-
- @Deprecated
+ static private final Logger LOGGER = Logger
+ .getLogger(AttributeMetadataMap.class);
+
+ /**
+ * A list of default languages used when creating default
+ * {@link AttributeMetadata} on-the-fly. If not initialized by a
+ * constructor, it will be {@link Translation#getActiveLang()} only.
+ **/
+ private final List<String> langs;
+
+ @Deprecated
public AttributeMetadataMap() {
langs = new ArrayList<String>();
langs.add(Translation.getActiveLang());
}
-
-
- public AttributeMetadataMap(String[] strings) {
+
+ /**
+ * Creates an {@link AttributeMetadataMap} and sets the list of default
+ * languages.
+ */
+ public AttributeMetadataMap(final List<String> defLanguages) {
+ langs = defLanguages;
+ }
+
+ /**
+ * Creates an {@link AttributeMetadataMap} and sets the list of default
+ * languages.
+ */
+ public AttributeMetadataMap(final String[] strings) {
langs = new ArrayList<String>(java.util.Arrays.asList(strings));
}
/**
- * @Deprecated use get(Name name) or get(String localName)
+ * Returns a deep-copy. @see {@link Copyable} interface
*/
- @Deprecated
- public AttributeMetadata get(Object key) {
- LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
- LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
- LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
- return super.get(key);
+ @Override
+ public AttributeMetadataMap copy() {
+ final AttributeMetadataMap copy = new AttributeMetadataMap(langs);
+ return copyTo(copy);
}
-
- public AttributeMetadata get(Name name) {
- final AttributeMetadata attributeMetadata = super.get(name);
- if (attributeMetadata == null && name != null && !name.getLocalPart().trim().isEmpty()) {
- put(name,new AttributeMetadata(name, langs));
- return super.get(name);
- }
- return attributeMetadata;
- }
- public AttributeMetadata get(String localName) {
- return this.get(new NameImpl(localName));
- }
-
+ /**
+ * Copies all its values to another {@link AttributeMetadataMap}. @see
+ * {@link Copyable} interface.
+ */
@Override
- public AttributeMetadataMap copyTo(AttributeMetadataMap amdMap) {
-
+ public AttributeMetadataMap copyTo(final AttributeMetadataMap amdMap) {
+
amdMap.clear();
-
- for (Name key : keySet()) {
- AttributeMetadata attributeMetaData = get(key);
+
+ for (final Name key : keySet()) {
+ final AttributeMetadata attributeMetaData = get(key);
amdMap.put(key, attributeMetaData.copy());
}
return amdMap;
}
+ /**
+ * Returns the {@link AttributeMetadata} for a given {@link Name}. Never
+ * returns <code>null</code>, but rather creates a default
+ * {@link AttributeMetadata} on the fly.
+ */
+ public AttributeMetadata get(final Name name) {
+ final AttributeMetadata attributeMetadata = super.get(name);
+ if (attributeMetadata == null && name != null
+ && !name.getLocalPart().trim().isEmpty()) {
+ put(name, new AttributeMetadata(name, langs));
+ return super.get(name);
+ }
+ return attributeMetadata;
+ }
+
+ /**
+ * @Deprecated use get(Name name) or get(String localName)
+ */
@Override
- public AttributeMetadataMap copy() {
- AttributeMetadataMap copy = new AttributeMetadataMap(langs);
- return copyTo(copy);
+ @Deprecated
+ public AttributeMetadata get(final Object key) {
+ LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
+ LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
+ LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
+ return super.get(key);
}
- public List<AttributeMetadata> sortedValues() {
- ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>();
- list.addAll(values());
- return list;
+ /**
+ * Returns the {@link AttributeMetadata} for a given {@link Name}. Never
+ * returns <code>null</code>, but rather creates a default
+ * {@link AttributeMetadata} on the fly.
+ */
+ public AttributeMetadata get(final String localName) {
+ return this.get(new NameImpl(localName));
}
+ public List<String> getLanguages() {
+ return langs;
+ }
+
/**
- * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes
+ * @return a number between 0. (bad) and 1. (good) that is calculated from
+ * the amount of translation available in the visible attributes
*/
- public double getQuality(List<String> languages) {
+ public double getQuality(final List<String> languages) {
int allVisible = 0;
double colQmSum = 0.;
for (final AttributeMetadata oneCol : values()) {
-
+
if (oneCol.isVisible()) {
allVisible++;
colQmSum += oneCol.getQuality(languages);
@@ -107,7 +143,28 @@
}
- public List<String> getLanguages() {
- return langs;
+
+ /**
+ * @return List of {@link AttributeMetadata} objects ordered by their
+ * weight. (heavier => further down)
+ */
+ public List<AttributeMetadata> sortedValues() {
+ final ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>();
+ list.addAll(values());
+ Collections.sort(list);
+ return list;
}
+
+ /**
+ * @return List of only the visible {@link AttributeMetadata} objects
+ * ordered by their weight. (heavier => further down)
+ */
+ public List<AttributeMetadata> sortedValuesVisibleOnly() {
+ final ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>();
+ for (final AttributeMetadata atm : sortedValues()) {
+ if (atm.isVisible())
+ list.add(atm);
+ }
+ return list;
+ }
}
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollectionTableModel.java 2009-11-19 17:27:01 UTC (rev 533)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollectionTableModel.java 2009-11-20 10:28:01 UTC (rev 534)
@@ -29,6 +29,7 @@
******************************************************************************/
package skrueger.geotools;
+import java.util.HashMap;
import java.util.Vector;
import org.apache.log4j.Logger;
@@ -41,6 +42,7 @@
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
+import schmitzm.geotools.feature.FeatureUtil;
import schmitzm.geotools.gui.FeatureCollectionTableModel;
import skrueger.AttributeMetadata;
@@ -53,7 +55,8 @@
* <li>column names are translated according to
* {@link AttributeMetadata#getTitle()}</li>
* <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
- * <li>Any filter defined in the {@link StyledFeaturesInterface} will be applied.</li>
+ * <li>Any filter defined in the {@link StyledFeaturesInterface} will be
+ * applied.</li>
* </ul>
*
* @author Stefan A. Krüger
@@ -63,13 +66,17 @@
final static private Logger LOGGER = Logger
.getLogger(StyledFeatureCollectionTableModel.class);
/** Contains the complete {@link AttributeMetadata}-Map of the styled layer. */
- protected AttributeMetadataMap origAMD = null;
+ protected AttributeMetadataMap amdMap = null;
/** Holds the current filter on the table */
protected Filter filter = null;
/** Holds the Bounds for all features. Only set once during the constructor **/
protected Envelope bounds;
+ /**
+ * Tooltips für die Spaltennamen. Wird nur beim Aufruf von
+ * {@link #reorganize} befuellt.
+ */
+ protected String[] colTooltips = null;
-
/**
* Creates a new table model for a styled layer.
*
@@ -78,7 +85,8 @@
* @param filter
* filter applied to the table
*/
- public StyledFeatureCollectionTableModel(StyledFeaturesInterface<?> styledFeatures) {
+ public StyledFeatureCollectionTableModel(
+ StyledFeaturesInterface<?> styledFeatures) {
setStyledFeatures(styledFeatures);
}
@@ -87,20 +95,20 @@
*
* @param fs
* the feature source
- * @param amd
+ * @param amdm
* {@link AttributeMetadata}-Map to define the visible attributes
* and translation
*/
- protected void setFeatureSource(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
- AttributeMetadataMap amd, Filter filter)
- throws Exception {
-
+ protected void setFeatureSource(
+ FeatureSource<SimpleFeatureType, SimpleFeature> fs,
+ AttributeMetadataMap amdm, Filter filter) throws Exception {
+
if (filter == null)
filter = Filter.INCLUDE;
-// this.featureSource = fs;
+ // this.featureSource = fs;
this.filter = filter;
- this.origAMD = amd;
+ this.amdMap = amdm;
FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
if (fs != null) {
@@ -109,33 +117,42 @@
final SimpleFeatureType schema = fs.getSchema();
Query query = new DefaultQuery(schema.getTypeName(), filter);
- if (amd != null) {
+ if (amdm != null) {
Vector<String> visibleAttrNames = new Vector<String>();
+
// Add the column with the geometry (usually "the_geom")
-
- for (AttributeDescriptor aDesc : schema.getAttributeDescriptors()) {
-
- // Always add the geometry
- if (schema.getGeometryDescriptor()
- .getName().equals(aDesc.getName())) {
- visibleAttrNames.add(schema.getGeometryDescriptor()
- .getLocalName());
- continue;
- }
-
- if (amd.get(aDesc.getName()).isVisible())
- visibleAttrNames.add(aDesc.getName().getLocalPart());
+ visibleAttrNames.add(schema.getGeometryDescriptor()
+ .getLocalName());
+
+ // Add other visible attributes as ordered by weights
+ for (AttributeMetadata a : amdm.sortedValuesVisibleOnly()) {
+ visibleAttrNames.add(a.getLocalName());
}
- // create a query for the visible attributes
+ // for (AttributeDescriptor aDesc :
+ // schema.getAttributeDescriptors()) {
+ //
+ // // Always add the geometry
+ // if (schema.getGeometryDescriptor()
+ // .getName().equals(aDesc.getName())) {
+ // visibleAttrNames.add(schema.getGeometryDescriptor()
+ // .getLocalName());
+ // continue;
+ // }
+ //
+ // if (amd.get(aDesc.getName()).isVisible())
+ // visibleAttrNames.add(aDesc.getName().getLocalPart());
+ // }
+ //
+ // // create a query for the visible attributes
String[] properties = visibleAttrNames.toArray(new String[] {});
+ //
+ // LOGGER.debug("Query contains the following attributes: "
+ // + visibleAttrNames);
- LOGGER.debug("Query contains the following attributes: "
- + visibleAttrNames);
-
-
/**
* I got NPEs when properties contained only [the_geom] ?!??!!??
+ * TODO Try again one day... Not today... 20.11.2009, SK
*/
if (properties.length > 1) {
query = new DefaultQuery(schema.getTypeName(), filter,
@@ -164,7 +181,9 @@
if (styledFeatures == null)
setFeatureSource(null, null, null);
else {
- setFeatureSource(styledFeatures.getFeatureSource(), styledFeatures.getAttributeMetaDataMap(), styledFeatures.getFilter());
+ setFeatureSource(styledFeatures.getFeatureSource(),
+ styledFeatures.getAttributeMetaDataMap(),
+ styledFeatures.getFilter());
}
} catch (Exception err) {
throw new RuntimeException(err);
@@ -180,18 +199,64 @@
*/
@Override
protected void reorganize(boolean fireTableStructureChanged) {
-
- super.reorganize(false);
-
- // translate the column names
- if (origAMD != null) {
+
+ featureArray = FeatureUtil.featuresToArray(featureTable);
+ if (featureArray == null || featureArray.length == 0) {
+ colNames = new String[0];
+ colTooltips = new String[0]; // Only set and used in
+ // StyledFeatureCollectionTableModel
+ colClass = new Class[0];
+ } else {
+ // Struktur der Tabelle vom AttributeMetaDtaaMap übernehmen
+ SimpleFeatureType schema = featureArray[0].getFeatureType();
+ // Pruefen, welche Attribute angezeigt werden
+ attrTypes.clear();
+ for (AttributeMetadata amd : amdMap.sortedValuesVisibleOnly()) {
+ AttributeDescriptor type = schema.getDescriptor(amd.getName());
+ if (attrFilter == null || attrFilter.accept(type))
+ attrTypes.add(type);
+ }
+ // Namen und Attribut-Indizes der angezeigten Spalten ermitteln
+ colNames = new String[attrTypes.size()];
+ colTooltips = new String[attrTypes.size()]; // Only set and used in
+ // StyledFeatureCollectionTableModel
+ colClass = new Class[attrTypes.size()];
+ attrIdxForCol = new int[attrTypes.size()];
for (int i = 0; i < colNames.length; i++) {
- colNames[i] = origAMD.get(colNames[i]).getTitle().toString();
+ AttributeDescriptor descriptor = schema.getDescriptor(amdMap.sortedValuesVisibleOnly().get(i).getName());
+
+ // Not so nice in 26: find the index of an attribute...
+ int idx = schema.getAttributeDescriptors().indexOf(descriptor);
+ attrIdxForCol[i] = idx;
+
+ String attName = schema.getAttributeDescriptors().get(idx)
+ .getLocalName();
+ colNames[i] = amdMap.get(attName).getTitle().toString();
+ AttributeMetadata amd = amdMap.get(attName);
+ colTooltips[i] = "<html>"+amd.getDesc().toString()+"<br>"+amd.getName()+"</html>";
+ colClass[i] = schema.getAttributeDescriptors().get(idx).getType()
+ .getBinding();
}
-
}
+
+ // store feature indexes in HashMap to optimize findFeature(.)
+ featureIdx = new HashMap<String, Integer>();
+ for (int i = 0; i < featureArray.length; i++)
+ if (featureArray[i] != null)
+ featureIdx.put(featureArray[i].getID(), i);
+//
+// // translate the column names
+// if (amdMap != null) {
+// for (int i = 0; i < colNames.length; i++) {
+// colTooltips[i] = amdMap.get(colNames[i]).getDesc().toString()
+// + "<br>" + colNames[i];
+// colNames[i] = amdMap.get(colNames[i]).getTitle().toString();
+//
+// }
+// }
if (fireTableStructureChanged)
fireTableStructureChanged();
+
}
/**
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java 2009-11-19 17:27:01 UTC (rev 533)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java 2009-11-20 10:28:01 UTC (rev 534)
@@ -245,6 +245,8 @@
* @param visible
* indicated whether the visible or invisible entries are
* returned
+ *
+ * TODO replace with {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
*/
public static AttributeMetadataMap getVisibleAttributeMetaData(
final AttributeMetadataMap amdMap, final boolean visible) {
@@ -262,6 +264,11 @@
* This method works like {@link
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM.
*
+ * TODO 20.11.2009, SK: There are some new attribute weight, functiona,
+ * functionX and nodata in AttributeMetaData that should be parsed/exported
+ * too. but this method is only used by ISDSS, which is not supporting that
+ * stuff anyways.
+ *
* @param element
* {@link Element} to parse
*/
More information about the Schmitzm-commits
mailing list