/[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 47 by mojays, Fri Apr 17 12:28:50 2009 UTC revision 55 by mojays, Fri Apr 17 14:26:14 2009 UTC
# Line 10  Line 10 
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.47  
changed lines
  Added in v.55

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26