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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26