30 |
package skrueger; |
package skrueger; |
31 |
|
|
32 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
33 |
|
import org.geotools.feature.NameImpl; |
34 |
|
import org.opengis.feature.type.AttributeDescriptor; |
35 |
|
import org.opengis.feature.type.Name; |
36 |
|
|
37 |
import skrueger.geotools.Copyable; |
import skrueger.geotools.Copyable; |
38 |
import skrueger.geotools.StyledLayerInterface; |
import skrueger.geotools.StyledLayerInterface; |
39 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
40 |
|
|
41 |
/** |
/** |
42 |
* This class holds meta information about an attribute/column. This |
* This class holds meta information about an attribute/column. This information |
43 |
* information is used by {@link StyledLayerInterface}. |
* is used by {@link StyledLayerInterface}. |
44 |
* |
* |
45 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
46 |
*/ |
*/ |
47 |
public class AttributeMetadata implements Copyable<AttributeMetadata>{ |
public class AttributeMetadata implements Copyable<AttributeMetadata> { |
48 |
static private final Logger LOGGER = Logger |
static private final Logger LOGGER = Logger |
49 |
.getLogger(AttributeMetadata.class); |
.getLogger(AttributeMetadata.class); |
50 |
|
|
51 |
protected Translation title = new Translation(); |
protected Translation title = new Translation(); |
52 |
protected Translation desc = new Translation(); |
protected Translation desc = new Translation(); |
53 |
protected boolean visible = false; |
protected boolean visible = true; |
54 |
protected String unit = ""; |
protected String unit = ""; |
55 |
protected int colIdx; |
protected int colIdx; |
56 |
|
private Name name; |
57 |
|
|
58 |
/** |
/** |
59 |
* Creates an {@link AttributeMetadata} object with the following information |
* Creates an {@link AttributeMetadata} object with the following |
60 |
* @param colIdx The column index of this attribute in the underlying table/dbf/etc... |
* information |
61 |
* @param visible Shall this attribute be displayed or hidden from the user? |
* |
62 |
* @param title {@link Translation} for Name |
* @param colIdx |
63 |
* @param desc {@link Translation} for an attribute description |
* The column index of this attribute in the underlying |
64 |
* @param unit {@link String} of the unit that the information is in |
* table/dbf/etc... |
65 |
|
* @param visible |
66 |
|
* Shall this attribute be displayed or hidden from the user? |
67 |
|
* @param title |
68 |
|
* {@link Translation} for Name |
69 |
|
* @param desc |
70 |
|
* {@link Translation} for an attribute description |
71 |
|
* @param unit |
72 |
|
* {@link String} of the unit that the information is in |
73 |
*/ |
*/ |
74 |
public AttributeMetadata(final int colIdx, final Boolean visible, |
public AttributeMetadata(final Name name, final Boolean visible, |
75 |
final Translation title, final Translation desc, final String unit) { |
final Translation title, final Translation desc, final String unit) { |
76 |
|
|
77 |
this.colIdx = colIdx; |
this.setName(name); |
78 |
this.title = title; |
this.title = title; |
79 |
this.desc = desc; |
this.desc = desc; |
80 |
if (colIdx == 0){ |
|
81 |
// The first attribute is THE_GEOM and shall never be visible! |
// The THE_GEOM and shall never be visible! |
82 |
this.visible = false; |
if (name.getLocalPart().equalsIgnoreCase("the_geom")) this.visible = false; |
83 |
}else |
|
|
this.visible = visible; |
|
84 |
this.unit = unit; |
this.unit = unit; |
85 |
} |
} |
86 |
|
|
87 |
/** |
/** |
88 |
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
* Creates an {@link AttributeMetadata} object with the following |
89 |
|
* information |
90 |
|
* |
91 |
|
* @param visible |
92 |
|
* Shall this attribute be displayed or hidden from the user? |
93 |
|
* @param title |
94 |
|
* {@link Translation} for Name |
95 |
|
* @param desc |
96 |
|
* {@link Translation} for an attribute description |
97 |
|
* @param unit |
98 |
|
* {@link String} of the unit that the information is in |
99 |
|
*/ |
100 |
|
public AttributeMetadata(final String localName, final Boolean visible, |
101 |
|
final Translation title, final Translation desc, final String unit) { |
102 |
|
this(new NameImpl(localName), true, title, desc, ""); |
103 |
|
} |
104 |
|
|
105 |
|
/** |
106 |
|
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
107 |
|
*/ |
108 |
|
public AttributeMetadata(final String localName, final String defaultTitle) { |
109 |
|
this(localName, true, new Translation(defaultTitle), new Translation(), |
110 |
|
""); |
111 |
|
} |
112 |
|
|
113 |
|
/** |
114 |
|
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
115 |
|
*/ |
116 |
|
public AttributeMetadata(final Name name, final String defaultTitle) { |
117 |
|
this(name, true, new Translation(defaultTitle), new Translation(), ""); |
118 |
|
} |
119 |
|
|
120 |
|
/** |
121 |
|
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
122 |
*/ |
*/ |
123 |
public AttributeMetadata(final Integer col, final String defaultName) { |
public AttributeMetadata(final Name name) { |
124 |
this(col, true, new Translation(defaultName), new Translation(), ""); |
this(name, true, new Translation(name.getLocalPart()), |
125 |
|
new Translation(), ""); |
126 |
} |
} |
127 |
|
|
128 |
/** Only used for {@link Copyable<AttributeMetaData>#copy()}**/ |
/** |
129 |
|
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
130 |
|
*/ |
131 |
|
public AttributeMetadata(final String localName) { |
132 |
|
this(localName, true, new Translation(localName), new Translation(), ""); |
133 |
|
} |
134 |
|
|
135 |
|
/** Only used for {@link Copyable<AttributeMetaData>#copy()} **/ |
136 |
private AttributeMetadata() { |
private AttributeMetadata() { |
137 |
} |
} |
138 |
|
|
139 |
|
public AttributeMetadata(AttributeDescriptor attDesc) { |
140 |
|
this(attDesc.getName()); |
141 |
|
} |
142 |
|
|
143 |
public boolean isVisible() { |
public boolean isVisible() { |
144 |
return visible; |
return visible; |
145 |
} |
} |
147 |
public void setVisible(final Boolean visible) { |
public void setVisible(final Boolean visible) { |
148 |
this.visible = visible; |
this.visible = visible; |
149 |
} |
} |
150 |
|
// |
151 |
/** @return the index of this attribute in the underlying table/dbf **/ |
// /** @return the index of this attribute in the underlying table/dbf **/ |
152 |
public int getColIdx() { |
// public int getColIdx() { |
153 |
return colIdx; |
// return colIdx; |
154 |
} |
// } |
155 |
|
|
156 |
public Translation getTitle() { |
public Translation getTitle() { |
157 |
return title; |
return title; |
183 |
getDesc().copyTo(amd.getDesc()); |
getDesc().copyTo(amd.getDesc()); |
184 |
amd.setUnit(getUnit()); |
amd.setUnit(getUnit()); |
185 |
amd.setVisible(isVisible()); |
amd.setVisible(isVisible()); |
186 |
amd.setColIdx(getColIdx()); |
amd.setName(new NameImpl(getName().getNamespaceURI(), getName().getLocalPart())); |
187 |
|
|
188 |
return amd; |
return amd; |
189 |
} |
} |
190 |
|
|
191 |
@Override |
@Override |
192 |
public AttributeMetadata copy() { |
public AttributeMetadata copy() { |
193 |
AttributeMetadata amd = new AttributeMetadata(); |
return copyTo( new AttributeMetadata()); |
194 |
getTitle().copyTo(amd.getTitle()); |
} |
195 |
getDesc().copyTo(amd.getDesc()); |
|
196 |
amd.setUnit(getUnit()); |
/** |
197 |
amd.setVisible(isVisible()); |
* The local Name. E.g. the name of the DBF column as a String |
198 |
amd.setColIdx(getColIdx()); |
*/ |
199 |
|
public String getLocalName() { |
200 |
return amd; |
return getName().getLocalPart(); |
201 |
|
} |
202 |
|
|
203 |
|
/** |
204 |
|
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub |
205 |
|
*/ |
206 |
|
public Name getName() { |
207 |
|
return name; |
208 |
} |
} |
209 |
|
|
210 |
private void setColIdx(int colIdx_) { |
/** |
211 |
colIdx = colIdx_; |
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub |
212 |
|
*/ |
213 |
|
public void setName(org.opengis.feature.type.Name name) { |
214 |
|
this.name = name; |
215 |
|
} |
216 |
|
|
217 |
|
/** |
218 |
|
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub |
219 |
|
*/ |
220 |
|
public void setLocalName(String localName) { |
221 |
|
this.name = new NameImpl(localName); |
222 |
} |
} |
223 |
} |
} |