/[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 53 - (show annotations)
Fri Apr 17 14:04:22 2009 UTC (15 years, 10 months ago) by mojays
File size: 5134 byte(s)
Hacking session in progress. No atomic commits.
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
28
29 /**
30 * This class extends the the {@link FeatureCollectionTableModel} with the
31 * functionalities of the {@link AttributeMetaData} (AMD) of {@linkplain StyledMapInterface styled objects}.
32 * <ul>
33 * <li>column names are translated according to (AMD)</li>
34 * <li>columns are hidden according to
35 * </ul>
36 * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
37 *
38 */
39 public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel {
40
41 protected Map<Integer,AttributeMetaData> visibleAMD = null;
42
43 public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
44 super();
45 setFeatureCollection(map);
46 }
47
48 public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
49 super();
50 setFeatureCollection(map);
51 }
52
53 protected void setFeatureSource(FeatureSource fs, Map<Integer,AttributeMetaData> amd) throws Exception {
54 FeatureCollection fc = null;
55 this.visibleAMD = null;
56 if ( fs != null ) {
57 Query query = new DefaultQuery();
58 if ( amd != null ) {
59 // determine the names of the visible Attributes
60 this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true);
61 Vector<String> visibleAttrNames = new Vector<String>();
62 for ( int attrIdx : visibleAMD.keySet() )
63 visibleAttrNames.add( fs.getSchema().getAttributeType(attrIdx).getLocalName() );
64 // create a query for the visible attributes
65 query = new DefaultQuery(
66 fs.getSchema().getTypeName(),
67 Filter.INCLUDE,
68 visibleAttrNames.toArray(new String[0])
69 );
70 }
71 fc = fs.getFeatures(query);
72 }
73 setFeatureCollection( fc );
74 }
75
76 public void setFeatureCollection(StyledFeatureCollectionInterface map) {
77 try {
78 if ( map == null )
79 setFeatureSource(null,null);
80 else {
81 FeatureCollection fc = map.getGeoObject();
82 String fcName = fc.getFeatureType().getTypeName();
83 FeatureSource fs = new MemoryDataStore(fc).getFeatureSource(fcName);
84 setFeatureSource(fs, map.getAttributeMetaDataMap());
85 }
86 } catch (Exception err) {
87 throw new RuntimeException(err);
88 }
89 }
90
91 public void setFeatureCollection(StyledFeatureSourceInterface map) {
92 try {
93 if ( map == null )
94 setFeatureSource(null,null);
95 else
96 setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap());
97 } catch (Exception err) {
98 throw new RuntimeException(err);
99 }
100 }
101
102 @Override
103 public void reorganize() {
104 super.reorganize();
105 // translate the column names
106 if ( visibleAMD != null ) {
107 Iterator<Integer> keys = visibleAMD.keySet().iterator();
108 for (int i=0; keys.hasNext(); i++)
109 colNames[i] = visibleAMD.get( keys.next() ).getTitle().toString();
110 }
111 }
112 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26