/[schmitzm]/trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
ViewVC logotype

Contents of /trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56 - (show annotations)
Fri Apr 17 15:19:00 2009 UTC (15 years, 10 months ago) by alfonx
File size: 5465 byte(s)


1 /** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
2
3 This library 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 2.1 of the License, or (at your option) any later version.
4 This library 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 Lesser General Public License for more details.
5 You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
6
7 Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
8 Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
9 Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
10 **/
11 package skrueger.geotools;
12
13 import java.util.Iterator;
14 import java.util.Map;
15 import java.util.TreeMap;
16 import java.util.Vector;
17
18 import org.geotools.data.DefaultQuery;
19 import org.geotools.data.FeatureSource;
20 import org.geotools.data.Query;
21 import org.geotools.data.memory.MemoryDataStore;
22 import org.geotools.feature.FeatureCollection;
23 import org.opengis.filter.Filter;
24
25 import schmitzm.geotools.gui.FeatureCollectionTableModel;
26 import skrueger.AttributeMetaData;
27 import skrueger.i8n.I8NUtil;
28 import skrueger.i8n.Translation;
29
30 /**
31 * This class extends the the {@link FeatureCollectionTableModel} with the
32 * functionalities of the {@link AttributeMetaData} of
33 * {@linkplain StyledMapInterface styled objects}.
34 * <ul>
35 * <li>column names are translated according to
36 * {@link AttributeMetaData#getTitle()}</li>
37 * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
38 * </ul>
39 *
40 * @author <a href="mailto:[email protected]">Martin Schmitz</a>
41 * (University of Bonn/Germany)
42 *
43 */
44 public class StyledFeatureCollectionTableModel extends
45 FeatureCollectionTableModel {
46
47 protected Map<Integer, AttributeMetaData> visibleAMD = null;
48
49 public StyledFeatureCollectionTableModel(
50 StyledFeatureCollectionInterface map) {
51 super();
52 setFeatureCollection(map);
53 }
54
55 public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
56 super();
57 setFeatureCollection(map);
58 }
59
60 protected void setFeatureSource(FeatureSource fs,
61 Map<Integer, AttributeMetaData> amd) throws Exception {
62 FeatureCollection fc = null;
63 this.visibleAMD = null;
64 if (fs != null) {
65 Query query = new DefaultQuery();
66 if (amd != null) {
67 // determine the names of the visible Attributes
68 this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(
69 amd, true);
70 Vector<String> visibleAttrNames = new Vector<String>();
71
72 // Add the column with the geometry (usually "the_geom")
73 visibleAttrNames.add(fs.getSchema().getDefaultGeometry()
74 .getLocalName());
75
76 for (int attrIdx : visibleAMD.keySet())
77 visibleAttrNames.add(fs.getSchema().getAttributeType(
78 attrIdx).getLocalName());
79
80 // create a query for the visible attributes
81 String[] properties = visibleAttrNames.toArray(new String[0]);
82
83 query = new DefaultQuery(fs.getSchema().getTypeName(),
84 Filter.INCLUDE, properties);
85 }
86 fc = fs.getFeatures(query);
87 }
88 setFeatureCollection(fc);
89 }
90
91 public void setFeatureCollection(StyledFeatureCollectionInterface map) {
92 try {
93 if (map == null)
94 setFeatureSource(null, null);
95 else {
96 FeatureCollection fc = map.getGeoObject();
97 String fcName = fc.getFeatureType().getTypeName();
98 FeatureSource fs = new MemoryDataStore(fc)
99 .getFeatureSource(fcName);
100 setFeatureSource(fs, map.getAttributeMetaDataMap());
101 }
102 } catch (Exception err) {
103 throw new RuntimeException(err);
104 }
105 }
106
107 public void setFeatureCollection(StyledFeatureSourceInterface map) {
108 try {
109 if (map == null)
110 setFeatureSource(null, null);
111 else
112 setFeatureSource(map.getGeoObject(), map
113 .getAttributeMetaDataMap());
114 } catch (Exception err) {
115 throw new RuntimeException(err);
116 }
117 }
118
119 @Override
120 public void reorganize() {
121 super.reorganize();
122 // translate the column names
123 if (visibleAMD != null) {
124 Iterator<Integer> keys = visibleAMD.keySet().iterator();
125 for (int i = 0; i < colNames.length && keys.hasNext(); i++) {
126 Translation title = visibleAMD.get(keys.next()).getTitle();
127 if (!I8NUtil.isEmpty(title)) {
128 System.out.println("set colname " + i + " to "
129 + title.toString());
130 colNames[i] = title.toString();
131 }
132 }
133 }
134 fireTableStructureChanged();
135 }
136 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26