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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 46 by mojays, Fri Apr 17 11:44:05 2009 UTC revision 57 by mojays, Fri Apr 17 15:26:14 2009 UTC
# Line 1  Line 1 
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;  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;  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    
 public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel {  
     
49    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
50      super(null);      this(map,Filter.INCLUDE);
51      }
52    
53      public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map, Filter filter) {
54        super();
55        setFeatureCollection(map, filter);
56    }    }
57      
58    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
59      super(null);      this(map,Filter.INCLUDE);
60      }
61    
62      public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map, Filter filter) {
63        super();
64        setFeatureCollection(map, filter);
65      }
66    
67      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    
84            // 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    
93    public String[] createColumnNames() {    public void setFeatureCollection(StyledFeatureCollectionInterface map, Filter filter) {
94      return new String[0];      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      
108    public int getRowCount() {    public void setFeatureCollection(StyledFeatureSourceInterface map, Filter filter) {
109      return 0;      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      
119    public Object getValueAt(int row, int col) {    @Override
120      return "";    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  }  }

Legend:
Removed from v.46  
changed lines
  Added in v.57

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26