/[schmitzm]/branches/2.2.x/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
ViewVC logotype

Diff of /branches/2.2.x/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 55 by mojays, Fri Apr 17 14: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    /**
32     * This class extends the the {@link FeatureCollectionTableModel} with the
33     * functionalities of the {@link AttributeMetaData} of {@linkplain StyledMapInterface styled objects}.
34     * <ul>
35     *   <li>column names are translated according to {@link AttributeMetaData#getTitle()}</li>
36     *   <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
37     * </ul>
38     * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
39     *
40     */
41  public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel {  public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel {
42        
43      protected Map<Integer,AttributeMetaData> visibleAMD = null;
44      
45    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
46      super(null);      super();
47        setFeatureCollection(map);
48    }    }
49        
50    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
51      super(null);      super();
52        setFeatureCollection(map);
53    }    }
54      
55    public String[] createColumnNames() {    protected void setFeatureSource(FeatureSource fs, Map<Integer,AttributeMetaData> amd) throws Exception {
56      return new String[0];      FeatureCollection fc = null;
57        this.visibleAMD      = null;
58        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      }
77      
78      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    }    }
92        
93    public int getRowCount() {    public void setFeatureCollection(StyledFeatureSourceInterface map) {
94      return 0;      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    }    }
103        
104    public Object getValueAt(int row, int col) {    @Override
105      return "";    public void reorganize() {
106        super.reorganize();
107        // translate the column names
108        if ( visibleAMD != null ) {
109          Iterator<Integer> keys = visibleAMD.keySet().iterator();
110          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        }
116    }    }
117  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26