[Schmitzm-commits] r464 - in branches/1.0-gt2-2.6/src/skrueger: . geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 13 15:22:34 CEST 2009


Author: alfonx
Date: 2009-10-13 15:22:31 +0200 (Tue, 13 Oct 2009)
New Revision: 464

Removed:
   branches/1.0-gt2-2.6/src/skrueger/AttributeMetaData.java
Modified:
   branches/1.0-gt2-2.6/src/skrueger/AttributeMetaDataAttributeTypeFilter.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/MapContextManagerInterface.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerInterface.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
Log:
* Changed AttributeMetadata and AttributeMetadataMap. It's not based on the attributes colIdx any more, but on the geotools.feature.type.Name. All the XML read/write methods have been adapted. 
This change was needed, as some users tend to change the DBF structure after the shapefile has been imported. Now columns can be moved, inserted and deleted. Just click "reload atlas" in Geopublisher after you changed the table schema. Geopublisher doesn't have to be closed.

Deleted: branches/1.0-gt2-2.6/src/skrueger/AttributeMetaData.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetaData.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/AttributeMetaData.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- * 
- * This file is part of the SCHMITZM library - a collection of utility 
- * classes based on Java 1.6, focusing (not only) on Java Swing 
- * and the Geotools library.
- * 
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- * 
- * Contributors:
- *     Martin O. J. Schmitz - initial API and implementation
- *     Stefan A. Krüger - additional utility classes
- ******************************************************************************/
-package skrueger;
-
-import org.apache.log4j.Logger;
-
-import skrueger.geotools.Copyable;
-import skrueger.geotools.StyledLayerInterface;
-import skrueger.i8n.Translation;
-
-/**
- * This class holds meta information about an attribute/column. This
- * information is used by {@link StyledLayerInterface}.
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
- */
-public class AttributeMetaData implements Copyable<AttributeMetaData>{
-	static private final Logger LOGGER = Logger
-			.getLogger(AttributeMetaData.class);
-	protected Translation title = new Translation();
-	protected Translation desc = new Translation();
-	protected boolean visible = false;
-	protected String unit = "";
-	protected int colIdx;
-	
-	/**
-	 * Creates an {@link AttributeMetaData} object with the following information
-	 * @param colIdx The column index of this attribute in the underlying table/dbf/etc...
-	 * @param visible Shall this attribute be displayed or hidden from the user?
-	 * @param title {@link Translation} for Name
-	 * @param desc {@link Translation} for an attribute description
-	 * @param unit {@link String} of the unit that the information is in
-	 */
-	public AttributeMetaData(final int colIdx, final Boolean visible,
-			final Translation title, final Translation desc, final String unit) {
-	
-		this.colIdx = colIdx;
-		this.title = title;
-		this.desc = desc;
-		if (colIdx == 0){
-			// The first attribute is THE_GEOM and shall never be visible!
-			this.visible = false;
-		}else
-			this.visible = visible;
-		this.unit = unit;
-	}
-
-	/**
-	 * Creates a new visible {@link AttributeMetaData} with default (no) values.  
-	 */
-	public AttributeMetaData(final Integer col, final String defaultName) {
-		this(col, true, new Translation(defaultName), new Translation(), "");
-	}
-
-	/** Only used for {@link Copyable<AttributeMetaData>#copy()}**/
-	private AttributeMetaData() {
-	}
-
-	public boolean isVisible() {
-		return visible;
-	}
-
-	public void setVisible(final Boolean visible) {
-		this.visible = visible;
-	}
-
-	/** @return the index of this attribute in the underlying table/dbf **/
-	public int getColIdx() {
-		return colIdx;
-	}
-
-	public Translation getTitle() {
-		return title;
-	}
-
-	public void setTitle(final Translation title) {
-		this.title = title;
-	}
-
-	public Translation getDesc() {
-		return desc;
-	}
-
-	public void setDesc(final Translation desc) {
-		this.desc = desc;
-	}
-
-	public String getUnit() {
-		return unit;
-	}
-
-	public void setUnit(final String unit) {
-		this.unit = unit;
-	}
-
-	@Override
-	public AttributeMetaData copyTo(AttributeMetaData amd) {
-		getTitle().copyTo(amd.getTitle());
-		getDesc().copyTo(amd.getDesc());
-		amd.setUnit(getUnit());
-		amd.setVisible(isVisible());
-		amd.setColIdx(getColIdx());
-		
-		return amd;
-	}
-
-	@Override
-	public AttributeMetaData copy() {
-		AttributeMetaData amd = new AttributeMetaData();
-		getTitle().copyTo(amd.getTitle());
-		getDesc().copyTo(amd.getDesc());
-		amd.setUnit(getUnit());
-		amd.setVisible(isVisible());
-		amd.setColIdx(getColIdx());
-		
-		return amd;
-	}
-
-	private void setColIdx(int colIdx_) {
-		colIdx = colIdx_;
-	}
-}

Modified: branches/1.0-gt2-2.6/src/skrueger/AttributeMetaDataAttributeTypeFilter.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetaDataAttributeTypeFilter.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/AttributeMetaDataAttributeTypeFilter.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -29,17 +29,15 @@
  ******************************************************************************/
 package skrueger;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.opengis.feature.type.AttributeDescriptor;
 
 import schmitzm.geotools.feature.AttributeTypeFilter;
+import skrueger.geotools.AttributeMetadataMap;
 
 /**
  * Implements an {@link AttributeTypeFilter} using the
- * {@linkplain AttributeMetaData#isVisible() visible}-property of an
- * {@link AttributeMetaData} map (or array).<br>
+ * {@linkplain AttributeMetadata#isVisible() visible}-property of an
+ * {@link AttributeMetadata} map (or array).<br>
  * If this filter is created from a {@code null} map or {@code null} array,
  * the filter accepts ALL attributes except geometries.
  * @see AttributeTypeFilter#NO_GEOMETRY
@@ -49,23 +47,23 @@
 public class AttributeMetaDataAttributeTypeFilter implements AttributeTypeFilter {
 
   /** The meta data of a set of attributes */
-  protected Map<Integer,AttributeMetaData> attrMetaDataMap = null;
+  protected AttributeMetadataMap attrMetaDataMap = null;
 
   /**
    * Creates a new filter.
    * @param attrMetaData the meta data of some attributes
    */
-  public AttributeMetaDataAttributeTypeFilter(AttributeMetaData[] attrMetaData) {
-    this.attrMetaDataMap = new HashMap<Integer,AttributeMetaData>();
+  public AttributeMetaDataAttributeTypeFilter(AttributeMetadata[] attrMetaData) {
+    this.attrMetaDataMap = new AttributeMetadataMap();
     for (int i=0; attrMetaData!=null && i<attrMetaData.length; i++)
-      this.attrMetaDataMap.put(i, attrMetaData[i]);
+      this.attrMetaDataMap.put(attrMetaData[i].getName(), attrMetaData[i]);
   }
 
   /**
    * Creates a new filter.
    * @param attrMetaData the meta data of some attributes
    */
-  public AttributeMetaDataAttributeTypeFilter(Map<Integer,AttributeMetaData> attrMetaData) {
+  public AttributeMetaDataAttributeTypeFilter(AttributeMetadataMap attrMetaData) {
     this.attrMetaDataMap = attrMetaData;
   }
 
@@ -79,7 +77,7 @@
     if ( attrMetaDataMap == null )
       return NO_GEOMETRY.accept(type, idx);
 
-    AttributeMetaData metaData = attrMetaDataMap.get(idx);
+    AttributeMetadata metaData = attrMetaDataMap.get(idx);
     return NO_GEOMETRY.accept(type, idx)  // no geometry attributes at all
         && metaData != null               // meta data must be present for column
         && metaData.isVisible();          // attribute must be visible

Modified: branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -30,59 +30,116 @@
 package skrueger;
 
 import org.apache.log4j.Logger;
+import org.geotools.feature.NameImpl;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.feature.type.Name;
 
 import skrueger.geotools.Copyable;
 import skrueger.geotools.StyledLayerInterface;
 import skrueger.i8n.Translation;
 
 /**
- * This class holds meta information about an attribute/column. This
- * information is used by {@link StyledLayerInterface}.
- *
+ * This class holds meta information about an attribute/column. This information
+ * is used by {@link StyledLayerInterface}.
+ * 
  * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
  */
-public class AttributeMetadata implements Copyable<AttributeMetadata>{
+public class AttributeMetadata implements Copyable<AttributeMetadata> {
 	static private final Logger LOGGER = Logger
 			.getLogger(AttributeMetadata.class);
+
 	protected Translation title = new Translation();
 	protected Translation desc = new Translation();
-	protected boolean visible = false;
+	protected boolean visible = true;
 	protected String unit = "";
 	protected int colIdx;
-	
+	private org.opengis.feature.type.Name name;
+
 	/**
-	 * Creates an {@link AttributeMetadata} object with the following information
-	 * @param colIdx The column index of this attribute in the underlying table/dbf/etc...
-	 * @param visible Shall this attribute be displayed or hidden from the user?
-	 * @param title {@link Translation} for Name
-	 * @param desc {@link Translation} for an attribute description
-	 * @param unit {@link String} of the unit that the information is in
+	 * Creates an {@link AttributeMetadata} object with the following
+	 * information
+	 * 
+	 * @param colIdx
+	 *            The column index of this attribute in the underlying
+	 *            table/dbf/etc...
+	 * @param visible
+	 *            Shall this attribute be displayed or hidden from the user?
+	 * @param title
+	 *            {@link Translation} for Name
+	 * @param desc
+	 *            {@link Translation} for an attribute description
+	 * @param unit
+	 *            {@link String} of the unit that the information is in
 	 */
-	public AttributeMetadata(final int colIdx, final Boolean visible,
+	public AttributeMetadata(final Name name, final Boolean visible,
 			final Translation title, final Translation desc, final String unit) {
-	
-		this.colIdx = colIdx;
+
+		this.setName(name);
 		this.title = title;
 		this.desc = desc;
-		if (colIdx == 0){
-			// The first attribute is THE_GEOM and shall never be visible!
-			this.visible = false;
-		}else
-			this.visible = visible;
+		
+		// The THE_GEOM and shall never be visible!
+		if (name.getLocalPart().equalsIgnoreCase("the_geom")) this.visible = false;
+		
 		this.unit = unit;
 	}
 
 	/**
-	 * Creates a new visible {@link AttributeMetadata} with default (no) values.  
+	 * Creates an {@link AttributeMetadata} object with the following
+	 * information
+	 * 
+	 * @param visible
+	 *            Shall this attribute be displayed or hidden from the user?
+	 * @param title
+	 *            {@link Translation} for Name
+	 * @param desc
+	 *            {@link Translation} for an attribute description
+	 * @param unit
+	 *            {@link String} of the unit that the information is in
 	 */
-	public AttributeMetadata(final Integer col, final String defaultName) {
-		this(col, true, new Translation(defaultName), new Translation(), "");
+	public AttributeMetadata(final String localName, final Boolean visible,
+			final Translation title, final Translation desc, final String unit) {
+		this(new NameImpl(localName), true, title, desc, "");
 	}
 
-	/** Only used for {@link Copyable<AttributeMetaData>#copy()}**/
+	/**
+	 * Creates a new visible {@link AttributeMetadata} with default (no) values.
+	 */
+	public AttributeMetadata(final String localName, final String defaultTitle) {
+		this(localName, true, new Translation(defaultTitle), new Translation(),
+				"");
+	}
+
+	/**
+	 * Creates a new visible {@link AttributeMetadata} with default (no) values.
+	 */
+	public AttributeMetadata(final Name name, final String defaultTitle) {
+		this(name, true, new Translation(defaultTitle), new Translation(), "");
+	}
+
+	/**
+	 * Creates a new visible {@link AttributeMetadata} with default (no) values.
+	 */
+	public AttributeMetadata(final Name name) {
+		this(name, true, new Translation(name.getLocalPart()),
+				new Translation(), "");
+	}
+
+	/**
+	 * Creates a new visible {@link AttributeMetadata} with default (no) values.
+	 */
+	public AttributeMetadata(final String localName) {
+		this(localName, true, new Translation(localName), new Translation(), "");
+	}
+
+	/** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
 	private AttributeMetadata() {
 	}
 
+	public AttributeMetadata(AttributeDescriptor attDesc) {
+		this(attDesc.getName());
+	}
+
 	public boolean isVisible() {
 		return visible;
 	}
@@ -90,12 +147,12 @@
 	public void setVisible(final Boolean visible) {
 		this.visible = visible;
 	}
+//
+//	/** @return the index of this attribute in the underlying table/dbf **/
+//	public int getColIdx() {
+//		return colIdx;
+//	}
 
-	/** @return the index of this attribute in the underlying table/dbf **/
-	public int getColIdx() {
-		return colIdx;
-	}
-
 	public Translation getTitle() {
 		return title;
 	}
@@ -126,24 +183,41 @@
 		getDesc().copyTo(amd.getDesc());
 		amd.setUnit(getUnit());
 		amd.setVisible(isVisible());
-		amd.setColIdx(getColIdx());
-		
+		amd.setName(new NameImpl(getName().getNamespaceURI(), getName().getLocalPart()));
+
 		return amd;
 	}
 
 	@Override
 	public AttributeMetadata copy() {
-		AttributeMetadata amd = new AttributeMetadata();
-		getTitle().copyTo(amd.getTitle());
-		getDesc().copyTo(amd.getDesc());
-		amd.setUnit(getUnit());
-		amd.setVisible(isVisible());
-		amd.setColIdx(getColIdx());
-		
-		return amd;
+		return copyTo( new AttributeMetadata());
 	}
 
-	private void setColIdx(int colIdx_) {
-		colIdx = colIdx_;
+	/**
+	 * The local Name. E.g. the name of the DBF column as a String
+	 */
+	public String getLocalName() {
+		return getName().getLocalPart();
 	}
+
+	/**
+	 * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
+	 */
+	public Name getName() {
+		return name;
+	}
+
+	/**
+	 * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
+	 */
+	public void setName(org.opengis.feature.type.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);
+	}
 }

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -1,28 +1,49 @@
 package skrueger.geotools;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
 import java.util.TreeMap;
 
-import skrueger.AttributeMetaData;
+import org.geotools.feature.NameImpl;
+import org.opengis.feature.type.Name;
 
+import skrueger.AttributeMetadata;
+
 /**
- * An extension of TreeMap, that is clonable in the sense of
- * 
- * @author stefan
- * 
+ * An extension of TreeMap, that is copyable in the sense of the {@link Copyable} interface
  */
-public class AttributeMetadataMap extends TreeMap<Integer, AttributeMetaData>
+public class AttributeMetadataMap extends TreeMap<Name, AttributeMetadata>
 		implements Copyable<AttributeMetadataMap> {
 
-	public AttributeMetadataMap() {
+	/**
+	 * @Deprecated use get(Name name) or get(String localName)
+	 */
+	@Deprecated
+	public AttributeMetadata get(Object key) {
+		return super.get(key);
 	}
 
+	public AttributeMetadata get(Name name) {
+		final AttributeMetadata attributeMetadata = super.get(name);
+		if (attributeMetadata == null) {
+			put(name,new AttributeMetadata(name));
+			return super.get(name);
+		}
+		return attributeMetadata;
+	}
+
+	public AttributeMetadata get(String localName) {
+		return this.get(new NameImpl(localName));
+	}
+	
 	@Override
 	public AttributeMetadataMap copyTo(AttributeMetadataMap amdMap) {
 		
 		amdMap.clear();
 		
-		for (Integer key : keySet()) {
-			AttributeMetaData attributeMetaData = get(key);
+		for (Name key : keySet()) {
+			AttributeMetadata attributeMetaData = get(key);
 			amdMap.put(key, attributeMetaData.copy());
 		}
 		return amdMap;
@@ -33,4 +54,10 @@
 		AttributeMetadataMap copy = new AttributeMetadataMap();
 		return copyTo(copy);
 	}
+
+	public List<AttributeMetadata> sortedValues() {
+		ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>();
+		list.addAll(values());
+		return list;
+	}
 }

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/MapContextManagerInterface.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/MapContextManagerInterface.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/MapContextManagerInterface.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -35,7 +35,7 @@
 import org.geotools.map.event.MapLayerListListener;
 import org.geotools.map.event.MapLayerListener;
 
-import skrueger.AttributeMetaData;
+import skrueger.AttributeMetadata;
 import skrueger.RasterLegendData;
 
 /**
@@ -84,10 +84,10 @@
 	List<StyledLayerInterface<?>> getStyledObjects();
 
 	/**
-	 * Returns a list of {@link AttributeMetaData} that shall be shown (e.g. when the Mouse clicked into the map)
+	 * Returns a list of {@link AttributeMetadata} that shall be shown (e.g. when the Mouse clicked into the map)
 	 * Returns an empty list if the layer doesn't exist or is not backed by a {@link StyledFeatureCollectionInterface}
 	 */
-	List<AttributeMetaData> getVisibleAttribsFor(MapLayer mapLayer);
+	List<AttributeMetadata> getVisibleAttribsFor(MapLayer mapLayer);
 
 	/**
 	 * Returns the title of the layer

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -52,7 +52,7 @@
 
 import schmitzm.geotools.io.GeoImportUtil;
 import schmitzm.geotools.styling.StylingUtil;
-import skrueger.AttributeMetaData;
+import skrueger.AttributeMetadata;
 import skrueger.i8n.Translation;
 
 import com.vividsolutions.jts.geom.Envelope;
@@ -249,11 +249,10 @@
 
 			// Leaving out the first one, it will be the_geom
 			for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
-				AttributeDescriptor att = fs.getSchema().getDescriptor(i);
+				AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
 
-				AttributeMetaData attMetaData = new AttributeMetaData(i, att
-						.getLocalName());
-				map.put(i, attMetaData);
+				AttributeMetadata attMetaData = new AttributeMetadata(attDesc.getName());
+				map.put(attDesc.getName(), attMetaData);
 			}
 		}
 		return map;

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -46,7 +46,7 @@
 import org.opengis.filter.Filter;
 
 import schmitzm.geotools.feature.FeatureUtil;
-import skrueger.AttributeMetaData;
+import skrueger.AttributeMetadata;
 import skrueger.i8n.Translation;
 
 /**
@@ -317,12 +317,12 @@
 		AttributeMetadataMap metaDataMap = new AttributeMetadataMap();
 		SimpleFeatureType ftype = fc.getSchema();
 		for (int i = 0; i < ftype.getAttributeCount(); i++) {
-			AttributeDescriptor aType = ftype.getAttributeDescriptors().get(i);
-			if (aType != ftype.getGeometryDescriptor())
-				metaDataMap.put(i, new AttributeMetaData(i, // Column no.
+			AttributeDescriptor aDesc = ftype.getAttributeDescriptors().get(i);
+			if (aDesc != ftype.getGeometryDescriptor())
+				metaDataMap.put(aDesc.getName(), new AttributeMetadata(aDesc.getName(), 
 						true, // visible
-						new Translation(aType.getLocalName()), // Column name
-						new Translation(), // description
+						new Translation(aDesc.getLocalName()), // Column name
+						new Translation(aDesc.getLocalName()), // description
 						"" // Unit
 				));
 		}

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollectionTableModel.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollectionTableModel.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -29,8 +29,6 @@
  ******************************************************************************/
 package skrueger.geotools;
 
-import java.util.Iterator;
-import java.util.Map;
 import java.util.Vector;
 
 import org.apache.log4j.Logger;
@@ -44,18 +42,16 @@
 import org.opengis.filter.Filter;
 
 import schmitzm.geotools.gui.FeatureCollectionTableModel;
-import skrueger.AttributeMetaData;
-import skrueger.i8n.I8NUtil;
-import skrueger.i8n.Translation;
+import skrueger.AttributeMetadata;
 
 import com.vividsolutions.jts.geom.Envelope;
 
 /**
  * This class extends the the {@link FeatureCollectionTableModel} with the
- * functionalities of the {@link AttributeMetaData}.
+ * functionalities of the {@link AttributeMetadata}.
  * <ul>
  * <li>column names are translated according to
- * {@link AttributeMetaData#getTitle()}</li>
+ * {@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>
  * </ul>
@@ -66,12 +62,8 @@
 		FeatureCollectionTableModel {
 	final static private Logger LOGGER = Logger
 			.getLogger(StyledFeatureCollectionTableModel.class);
-	/** Contains only the visible elements of the {@link AttributeMetaData}-Map */
-	protected Map<Integer, AttributeMetaData> visibleAMD = null;
-//	/** Holds the data source for the table as {@code FeatureSource}. */
-//	protected FeatureSource featureSource = null;
-	/** Contains the complete {@link AttributeMetaData}-Map of the styled layer. */
-	protected Map<Integer, AttributeMetaData> origAMD = null;
+	/** Contains the complete {@link AttributeMetadata}-Map of the styled layer. */
+	protected AttributeMetadataMap origAMD = null;
 	/** Holds the current filter on the table */
 	protected Filter filter = null;
 	/** Holds the Bounds for all features. Only set once during the constructor **/
@@ -96,11 +88,11 @@
 	 * @param fs
 	 *            the feature source
 	 * @param amd
-	 *            {@link AttributeMetaData}-Map to define the visible attributes
+	 *            {@link AttributeMetadata}-Map to define the visible attributes
 	 *            and translation
 	 */
 	protected void setFeatureSource(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
-			Map<Integer, AttributeMetaData> amd, Filter filter)
+			AttributeMetadataMap amd, Filter filter)
 			throws Exception {
 		
 		if (filter == null)
@@ -109,46 +101,39 @@
 //		this.featureSource = fs;
 		this.filter = filter;
 		this.origAMD = amd;
-		this.visibleAMD = null;
 
 		FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
 		if (fs != null) {
 
 			bounds = fs.getBounds();
 
-			Query query = new DefaultQuery(fs.getSchema().getName().getLocalPart(), filter);
+			final SimpleFeatureType schema = fs.getSchema();
+			Query query = new DefaultQuery(schema.getTypeName(), filter);
 			if (amd != null) {
-				// determine the names of the visible Attributes
-				this.visibleAMD = StyledLayerUtil.getVisibleAttributeMetaData(
-						amd, true);
 				Vector<String> visibleAttrNames = new Vector<String>();
 				// Add the column with the geometry (usually "the_geom")
-				visibleAttrNames.add(fs.getSchema().getGeometryDescriptor()
-						.getLocalName());
-				for (int attrIdx : visibleAMD.keySet()) {
-
-					/**
-					 * If the user removed columns from the schema of the DBF
-					 * file, there might exist AttributeMetaData for columns
-					 * that don't exists. We check here to avoid an
-					 * ArrayOutOfIndex.
-					 */
-					if (attrIdx < fs.getSchema().getAttributeCount()) {
-						final AttributeDescriptor attributeTypeAtIdx = fs.getSchema()
-								.getAttributeDescriptors().get(attrIdx);
-						visibleAttrNames.add(attributeTypeAtIdx.getLocalName());
-					} else {
-						LOGGER.warn("AttributeMetaData has been found for columnIdx="+attrIdx+", but fs.getSchema().getAttributeCount() = "+fs.getSchema().getAttributeCount()+". Ignored.");
+				
+				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[0]);
+				String[] properties = visibleAttrNames.toArray(new String[] {});
 
 				LOGGER.debug("Query contains the following attributes: "
 						+ visibleAttrNames);
 
-				query = new DefaultQuery(fs.getSchema().getTypeName(), filter,
+				query = new DefaultQuery(schema.getTypeName(), filter,
 						properties);
 			}
 			fc = fs.getFeatures(query);
@@ -163,7 +148,7 @@
 	 * @param fs
 	 *            the feature source
 	 * @param amd
-	 *            {@link AttributeMetaData}-Map to define the visible attributes
+	 *            {@link AttributeMetadata}-Map to define the visible attributes
 	 *            and translation
 	 */
 	public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {
@@ -187,18 +172,15 @@
 	 */
 	@Override
 	protected void reorganize(boolean fireTableStructureChanged) {
+		
 		super.reorganize(false);
+		
 		// translate the column names
-		if (visibleAMD != null) {
-			Iterator<Integer> keys = visibleAMD.keySet().iterator();
-			for (int i = 0; i < colNames.length && keys.hasNext(); i++) {
-				Translation title = visibleAMD.get(keys.next()).getTitle();
-				if (!I8NUtil.isEmpty(title)) {
-					// System.out.println("set colname " + i + " to " +
-					// title.toString());
-					colNames[i] = title.toString();
-				}
+		if (origAMD != null) {
+			for (int i = 0; i < colNames.length; i++) {
+				colNames[i] = origAMD.get(colNames[i]).getTitle().toString();
 			}
+			
 		}
 		if (fireTableStructureChanged)
 			fireTableStructureChanged();

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerInterface.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerInterface.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerInterface.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -37,7 +37,7 @@
 import org.geotools.styling.Style;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 
-import skrueger.AttributeMetaData;
+import skrueger.AttributeMetadata;
 import skrueger.RasterLegendData;
 import skrueger.i8n.Translation;
 
@@ -85,11 +85,11 @@
  * <ul>
  * <li>layer list only depends on {@link StyledLayerInterface}</li>
  * <li>methods returning {@link Translation} must not return {@code null}</li>
- * <li>methods returning {@link AttributeMetaData}-Map must not return {@code
+ * <li>methods returning {@link AttributeMetadata}-Map must not return {@code
  * null}</li>
- * <li>static helper method to get a new {@link AttributeMetaData}-map withe the
+ * <li>static helper method to get a new {@link AttributeMetadata}-map withe the
  * visible attributes only</li>
- * <li>static helper method to create a "default" {@link AttributeMetaData}-map
+ * <li>static helper method to create a "default" {@link AttributeMetadata}-map
  * for a {@link FeatureCollection} with all attributes visible and without real
  * translations, but the attribute name as description.</li>
  * </ul>

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-10-13 11:29:54 UTC (rev 463)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-10-13 13:22:31 UTC (rev 464)
@@ -60,6 +60,7 @@
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
 import org.geotools.coverage.grid.io.AbstractGridFormat;
 import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.NameImpl;
 import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.map.DefaultMapLayer;
 import org.geotools.map.MapLayer;
@@ -77,6 +78,7 @@
 import org.jdom.output.XMLOutputter;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.feature.type.Name;
 import org.opengis.parameter.GeneralParameterValue;
 
 import schmitzm.geotools.JTSUtil;
@@ -85,7 +87,7 @@
 import schmitzm.io.IOUtil;
 import schmitzm.lang.LangUtil;
 import schmitzm.swing.SwingUtil;
-import skrueger.AttributeMetaData;
+import skrueger.AttributeMetadata;
 import skrueger.RasterLegendData;
 import skrueger.i8n.Translation;
 
@@ -243,25 +245,28 @@
 	 *            returned
 	 */
 	public static AttributeMetadataMap getVisibleAttributeMetaData(
-			Map<Integer, AttributeMetaData> amdMap, boolean visible) {
+			AttributeMetadataMap amdMap, boolean visible) {
+		
 		AttributeMetadataMap filteredMap = new AttributeMetadataMap();
-		for (AttributeMetaData amd : amdMap.values())
-			if (amd.isVisible())
-				filteredMap.put(amd.getColIdx(), amd);
+		for (AttributeMetadata amd : amdMap.values())
+			if (amd.isVisible() == visible)
+				filteredMap.put(amd.getName(), amd);
 
 		return filteredMap;
 	}
 
 	/**
-	 * Parses a {@link AttributeMetaData} object from an JDOM-{@link Element}.
+	 * Parses a {@link AttributeMetadata} object from an JDOM-{@link Element}.
 	 * This method works like {@link
 	 * AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM.
 	 * 
 	 * @param element
 	 *            {@link Element} to parse
 	 */
-	public static AttributeMetaData parseAttributeMetaData(final Element element) {
-		final Integer col = Integer.valueOf(element.getAttributeValue("col"));
+	public static AttributeMetadata parseAttributeMetaData(final Element element) {
+		final String namespace = String.valueOf(element.getAttributeValue("namespace"));
+		final String localname = String.valueOf(element.getAttributeValue("localname"));
+		final Name aName= new NameImpl(namespace,localname);
 		final Boolean visible = Boolean.valueOf(element
 				.getAttributeValue("visible"));
 		final String unit = element.getAttributeValue("unit");
@@ -277,11 +282,11 @@
 			else if (childElement.getName().equals("desc"))
 				desc = parseTranslation(childElement);
 		}
-		return new AttributeMetaData(col, visible, name, desc, unit);
+		return new AttributeMetadata(aName, visible, name, desc, unit);
 	}
 
 	/**
-	 * Parses a {@link AttributeMetaData} map from an JDOM-{@link Element} with
+	 * Parses a {@link AttributeMetadata} map from an JDOM-{@link Element} with
 	 * {@code <attribute>}-childs.
 	 * 
 	 * @param element
@@ -293,14 +298,14 @@
 		List<Element> attributesElements = element
 				.getChildren(ELEM_NAME_ATTRIBUTE);
 		for (Element attibuteElement : attributesElements) {
-			AttributeMetaData attrMetaData = parseAttributeMetaData(attibuteElement);
-			metaData.put(attrMetaData.getColIdx(), attrMetaData);
+			AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement);
+			metaData.put(attrMetaData.getName(), attrMetaData);
 		}
 		return metaData;
 	}
 
 	/**
-	 * Loads a {@link AttributeMetaData} object from an URL.
+	 * Loads a {@link AttributeMetadata} object from an URL.
 	 * 
 	 * @param documentUrl
 	 *            {@link URL} to parse
@@ -313,16 +318,17 @@
 	}
 
 	/**
-	 * Creates an JDOM {@link Element} for the given {@link AttributeMetaData}
+	 * Creates an JDOM {@link Element} for the given {@link AttributeMetadata}
 	 * object.
 	 * 
 	 * @param amd
 	 *            meta data for one attribute
 	 */
 	public static Element createAttributeMetaDataElement(
-			final AttributeMetaData amd) {
+			final AttributeMetadata amd) {
 		final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);
-		element.setAttribute("col", String.valueOf(amd.getColIdx()));
+		element.setAttribute("namespace", String.valueOf(amd.getName().getNamespaceURI()));
+		element.setAttribute("localname", String.valueOf(amd.getLocalName()));
 		element.setAttribute("visible", String.valueOf(amd.isVisible()));
 		element.setAttribute("unit", amd.getUnit());
 		// Creating a aml:name tag...
@@ -333,7 +339,7 @@
 	}
 
 	/**
-	 * Creates an JDOM {@link Element} for the given {@link AttributeMetaData}
+	 * Creates an JDOM {@link Element} for the given {@link AttributeMetadata}
 	 * map.
 	 * 
 	 * @param amdMap
@@ -342,16 +348,16 @@
 	public static Element createAttributeMetaDataMapElement(
 			final AttributeMetadataMap amdMap) {
 		final Element element = new Element(ELEM_NAME_AMD, AMLURI);
-		for (AttributeMetaData amd : amdMap.values())
+		for (AttributeMetadata amd : amdMap.values())
 			element.addContent(createAttributeMetaDataElement(amd));
 		return element;
 	}
 
 	/**
-	 * Saves a {@link AttributeMetaData AttributeMetaData-Map} to an URL.
+	 * Saves a {@link AttributeMetadata AttributeMetaData-Map} to an URL.
 	 * 
 	 * @param amdMap
-	 *            map of {@link AttributeMetaData}
+	 *            map of {@link AttributeMetadata}
 	 * @param documentUrl
 	 *            {@link URL} to store the XML
 	 */
@@ -686,9 +692,9 @@
 	 * @param styledFC
 	 *            a styled feature collection
 	 */
-	public static StyledLayerStyle<Map<Integer, AttributeMetaData>> getStyledLayerStyle(
+	public static StyledLayerStyle<AttributeMetadataMap> getStyledLayerStyle(
 			StyledFeatureCollectionInterface styledFC) {
-		return new StyledLayerStyle<Map<Integer, AttributeMetaData>>(styledFC
+		return new StyledLayerStyle<AttributeMetadataMap>(styledFC
 				.getStyle(), styledFC.getAttributeMetaDataMap());
 	}
 
@@ -755,7 +761,7 @@
 	}
 
 	/**
-	 * Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetaData
+	 * Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetadata
 	 * AttributeMetaData-Map} for a given geo-object (feature) source. The SLD
 	 * file must be present. A missing attribute meta-data file is tolerated.
 	 * 
@@ -767,9 +773,9 @@
 	 *            file extention for the raster legend-data file
 	 * @return {@code null} in case of any error
 	 */
-	public static StyledLayerStyle<Map<Integer, AttributeMetaData>> loadStyledFeatureStyle(
+	public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(
 			URL geoObjectURL, String sldExt, String rldExt) {
-		Map<Integer, AttributeMetaData> metaData = null;
+		AttributeMetadataMap metaData = null;
 		Style sldStyle = null;
 		try {
 			Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
@@ -795,13 +801,13 @@
 			return null;
 		}
 
-		return new StyledLayerStyle<Map<Integer, AttributeMetaData>>(sldStyle,
+		return new StyledLayerStyle<AttributeMetadataMap>(sldStyle,
 				metaData);
 	}
 
 	/**
 	 * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
-	 * {@linkplain AttributeMetaData AttributeMetaData-Map} from a {@code .amd}
+	 * {@linkplain AttributeMetadata AttributeMetaData-Map} from a {@code .amd}
 	 * file for a given geo-object (feature) source. The SLD file must be
 	 * present. A missing attribute meta-data file is tolerated.
 	 * 
@@ -813,7 +819,7 @@
 	 *            file extention for the raster legend-data file
 	 * @return {@code null} in case of any error
 	 */
-	public static StyledLayerStyle<Map<Integer, AttributeMetaData>> loadStyledFeatureStyle(
+	public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(
 			URL geoObjectURL) {
 		return loadStyledFeatureStyle(geoObjectURL, "sld", "amd");
 	}
@@ -862,7 +868,7 @@
 
 	/**
 	 * Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the
-	 * meta data ({@link RasterLegendData} or {@link AttributeMetaData}) to a
+	 * meta data ({@link RasterLegendData} or {@link AttributeMetadata}) to a
 	 * {@code .rld} or {@code .amd} file. for a given geo-object source.
 	 * 
 	 * @param style



More information about the Schmitzm-commits mailing list