--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009/10/13 11:29:54 463 +++ branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009/10/13 13:22:31 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 Stefan Alfons Krüger */ -public class AttributeMetadata implements Copyable{ +public class AttributeMetadata implements Copyable { 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 String localName, final Boolean visible, + final Translation title, final Translation desc, final String unit) { + this(new NameImpl(localName), true, title, desc, ""); + } + + /** + * 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 Integer col, final String defaultName) { - this(col, true, new Translation(defaultName), new Translation(), ""); + public AttributeMetadata(final Name name) { + this(name, true, new Translation(name.getLocalPart()), + new Translation(), ""); } - /** Only used for {@link Copyable#copy()}**/ + /** + * 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#copy()} **/ private AttributeMetadata() { } + public AttributeMetadata(AttributeDescriptor attDesc) { + this(attDesc.getName()); + } + public boolean isVisible() { return visible; } @@ -90,11 +147,11 @@ 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()); + } + + /** + * 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; } - private void setColIdx(int colIdx_) { - colIdx = colIdx_; + /** + * 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); } }