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 |
|
if (name.getLocalPart().equalsIgnoreCase("the_geom")) |
83 |
this.visible = false; |
this.visible = false; |
84 |
}else |
else |
85 |
this.visible = visible; |
this.visible = visible; |
86 |
|
|
87 |
this.unit = unit; |
this.unit = unit; |
88 |
} |
} |
89 |
|
|
90 |
/** |
/** |
91 |
* Creates a new visible {@link AttributeMetaData} with default (no) values. |
* Creates an {@link AttributeMetadata} object with the following |
92 |
|
* information |
93 |
|
* |
94 |
|
* @param visible |
95 |
|
* Shall this attribute be displayed or hidden from the user? |
96 |
|
* @param title |
97 |
|
* {@link Translation} for Name |
98 |
|
* @param desc |
99 |
|
* {@link Translation} for an attribute description |
100 |
|
* @param unit |
101 |
|
* {@link String} of the unit that the information is in |
102 |
|
*/ |
103 |
|
public AttributeMetadata(final String localName, final Boolean visible, |
104 |
|
final Translation title, final Translation desc, final String unit) { |
105 |
|
this(new NameImpl(localName), true, title, desc, ""); |
106 |
|
} |
107 |
|
|
108 |
|
/** |
109 |
|
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
110 |
*/ |
*/ |
111 |
public AttributeMetaData(final Integer col, final String defaultName) { |
public AttributeMetadata(final String localName, final String defaultTitle) { |
112 |
this(col, true, new Translation(defaultName), new Translation(), ""); |
this(localName, true, new Translation(defaultTitle), new Translation(), |
113 |
|
""); |
114 |
} |
} |
115 |
|
|
116 |
/** Only used for {@link Copyable<AttributeMetaData>#copy()}**/ |
/** |
117 |
private AttributeMetaData() { |
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
118 |
|
*/ |
119 |
|
public AttributeMetadata(final Name name, final String defaultTitle) { |
120 |
|
this(name, true, new Translation(defaultTitle), new Translation(), ""); |
121 |
|
} |
122 |
|
|
123 |
|
/** |
124 |
|
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
125 |
|
*/ |
126 |
|
public AttributeMetadata(final Name name) { |
127 |
|
this(name, true, new Translation(name.getLocalPart()), |
128 |
|
new Translation(), ""); |
129 |
|
} |
130 |
|
|
131 |
|
/** |
132 |
|
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
133 |
|
*/ |
134 |
|
public AttributeMetadata(final String localName) { |
135 |
|
this(localName, true, new Translation(localName), new Translation(), ""); |
136 |
|
} |
137 |
|
|
138 |
|
/** Only used for {@link Copyable<AttributeMetaData>#copy()} **/ |
139 |
|
private AttributeMetadata() { |
140 |
|
} |
141 |
|
|
142 |
|
public AttributeMetadata(AttributeDescriptor attDesc) { |
143 |
|
this(attDesc.getName()); |
144 |
} |
} |
145 |
|
|
146 |
public boolean isVisible() { |
public boolean isVisible() { |
151 |
this.visible = visible; |
this.visible = visible; |
152 |
} |
} |
153 |
|
|
154 |
/** @return the index of this attribute in the underlying table/dbf **/ |
// |
155 |
public int getColIdx() { |
// /** @return the index of this attribute in the underlying table/dbf **/ |
156 |
return colIdx; |
// public int getColIdx() { |
157 |
} |
// return colIdx; |
158 |
|
// } |
159 |
|
|
160 |
public Translation getTitle() { |
public Translation getTitle() { |
161 |
return title; |
return title; |
182 |
} |
} |
183 |
|
|
184 |
@Override |
@Override |
185 |
public AttributeMetaData copyTo(AttributeMetaData amd) { |
public AttributeMetadata copyTo(AttributeMetadata amd) { |
186 |
getTitle().copyTo(amd.getTitle()); |
getTitle().copyTo(amd.getTitle()); |
187 |
getDesc().copyTo(amd.getDesc()); |
getDesc().copyTo(amd.getDesc()); |
188 |
amd.setUnit(getUnit()); |
amd.setUnit(getUnit()); |
189 |
amd.setVisible(isVisible()); |
amd.setVisible(isVisible()); |
190 |
amd.setColIdx(getColIdx()); |
amd.setName(new NameImpl(getName().getNamespaceURI(), getName() |
191 |
|
.getLocalPart())); |
192 |
|
|
193 |
return amd; |
return amd; |
194 |
} |
} |
195 |
|
|
196 |
@Override |
@Override |
197 |
public AttributeMetaData copy() { |
public AttributeMetadata copy() { |
198 |
AttributeMetaData amd = new AttributeMetaData(); |
return copyTo(new AttributeMetadata()); |
199 |
getTitle().copyTo(amd.getTitle()); |
} |
200 |
getDesc().copyTo(amd.getDesc()); |
|
201 |
amd.setUnit(getUnit()); |
/** |
202 |
amd.setVisible(isVisible()); |
* The local Name. E.g. the name of the DBF column as a String |
203 |
amd.setColIdx(getColIdx()); |
*/ |
204 |
|
public String getLocalName() { |
205 |
return amd; |
return getName().getLocalPart(); |
206 |
|
} |
207 |
|
|
208 |
|
/** |
209 |
|
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub |
210 |
|
*/ |
211 |
|
public Name getName() { |
212 |
|
return name; |
213 |
} |
} |
214 |
|
|
215 |
private void setColIdx(int colIdx_) { |
/** |
216 |
colIdx = colIdx_; |
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub |
217 |
|
*/ |
218 |
|
public void setName(org.opengis.feature.type.Name name) { |
219 |
|
this.name = name; |
220 |
|
} |
221 |
|
|
222 |
|
/** |
223 |
|
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub |
224 |
|
*/ |
225 |
|
public void setLocalName(String localName) { |
226 |
|
this.name = new NameImpl(localName); |
227 |
} |
} |
228 |
} |
} |