/[schmitzm]/branches/2.0-RC2/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
ViewVC logotype

Annotation of /branches/2.0-RC2/src/skrueger/geotools/StyledFeatureCollectionTableModel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 57 - (hide annotations)
Fri Apr 17 15:26:14 2009 UTC (15 years, 10 months ago) by mojays
Original Path: trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
File size: 5999 byte(s)


1 mojays 47 /** 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 mojays 46 package skrueger.geotools;
12    
13 mojays 52 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 mojays 46 import schmitzm.geotools.gui.FeatureCollectionTableModel;
26 mojays 52 import skrueger.AttributeMetaData;
27 mojays 55 import skrueger.i8n.I8NUtil;
28     import skrueger.i8n.Translation;
29 mojays 46
30 mojays 52 /**
31 mojays 53 * This class extends the the {@link FeatureCollectionTableModel} with the
32 alfonx 56 * functionalities of the {@link AttributeMetaData} of
33     * {@linkplain StyledMapInterface styled objects}.
34 mojays 53 * <ul>
35 alfonx 56 * <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 mojays 52 */
44 alfonx 56 public class StyledFeatureCollectionTableModel extends
45 mojays 57 FeatureCollectionTableModel {
46 alfonx 56
47 mojays 57 protected Map<Integer, AttributeMetaData> visibleAMD = null;
48 alfonx 56
49 mojays 57 public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
50     this(map,Filter.INCLUDE);
51     }
52 alfonx 56
53 mojays 57 public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map, Filter filter) {
54     super();
55     setFeatureCollection(map, filter);
56     }
57 alfonx 56
58 mojays 57 public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
59     this(map,Filter.INCLUDE);
60     }
61 alfonx 56
62 mojays 57 public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map, Filter filter) {
63     super();
64     setFeatureCollection(map, filter);
65     }
66 alfonx 56
67 mojays 57 protected void setFeatureSource(FeatureSource fs, Map<Integer, AttributeMetaData> amd, Filter filter) throws Exception {
68     this.visibleAMD = null;
69     if ( filter == null )
70     filter = Filter.INCLUDE;
71    
72     FeatureCollection fc = null;
73     if (fs != null) {
74     Query query = new DefaultQuery();
75     if (amd != null) {
76     // determine the names of the visible Attributes
77     this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true);
78     Vector<String> visibleAttrNames = new Vector<String>();
79     // Add the column with the geometry (usually "the_geom")
80     visibleAttrNames.add(fs.getSchema().getDefaultGeometry().getLocalName());
81     for (int attrIdx : visibleAMD.keySet())
82     visibleAttrNames.add(fs.getSchema().getAttributeType(attrIdx).getLocalName());
83 alfonx 56
84 mojays 57 // create a query for the visible attributes
85     String[] properties = visibleAttrNames.toArray(new String[0]);
86     query = new DefaultQuery(fs.getSchema().getTypeName(), filter, properties);
87     }
88     fc = fs.getFeatures(query);
89     }
90     setFeatureCollection(fc);
91     }
92 alfonx 56
93 mojays 57 public void setFeatureCollection(StyledFeatureCollectionInterface map, Filter filter) {
94     try {
95     if (map == null)
96     setFeatureSource(null, null, null);
97     else {
98     FeatureCollection fc = map.getGeoObject();
99     String fcName = fc.getFeatureType().getTypeName();
100     FeatureSource fs = new MemoryDataStore(fc).getFeatureSource(fcName);
101     setFeatureSource(fs, map.getAttributeMetaDataMap(), filter);
102     }
103     } catch (Exception err) {
104     throw new RuntimeException(err);
105     }
106     }
107 alfonx 56
108 mojays 57 public void setFeatureCollection(StyledFeatureSourceInterface map, Filter filter) {
109     try {
110     if (map == null)
111     setFeatureSource(null, null, null);
112     else
113     setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap(), filter);
114     } catch (Exception err) {
115     throw new RuntimeException(err);
116     }
117     }
118 alfonx 56
119 mojays 57 @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 " + title.toString());
129     colNames[i] = title.toString();
130     }
131     }
132     }
133     fireTableStructureChanged();
134     }
135 mojays 46 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26