/[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 56 by alfonx, Fri Apr 17 15:19:00 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     * 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    
49            public StyledFeatureCollectionTableModel(
50                            StyledFeatureCollectionInterface map) {
51                    super();
52                    setFeatureCollection(map);
53            }
54    
55            public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
56                    super();
57                    setFeatureCollection(map);
58            }
59    
60            protected void setFeatureSource(FeatureSource fs,
61                            Map<Integer, AttributeMetaData> amd) throws Exception {
62                    FeatureCollection fc = null;
63                    this.visibleAMD = null;
64                    if (fs != null) {
65                            Query query = new DefaultQuery();
66                            if (amd != null) {
67                                    // determine the names of the visible Attributes
68                                    this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(
69                                                    amd, true);
70                                    Vector<String> visibleAttrNames = new Vector<String>();
71    
72                                    // Add the column with the geometry (usually "the_geom")
73                                    visibleAttrNames.add(fs.getSchema().getDefaultGeometry()
74                                                    .getLocalName());
75    
76                                    for (int attrIdx : visibleAMD.keySet())
77                                            visibleAttrNames.add(fs.getSchema().getAttributeType(
78                                                            attrIdx).getLocalName());
79    
80                                    // create a query for the visible attributes
81                                    String[] properties = visibleAttrNames.toArray(new String[0]);
82    
83                                    query = new DefaultQuery(fs.getSchema().getTypeName(),
84                                                    Filter.INCLUDE, properties);
85                            }
86                            fc = fs.getFeatures(query);
87                    }
88                    setFeatureCollection(fc);
89            }
90    
91            public void setFeatureCollection(StyledFeatureCollectionInterface map) {
92                    try {
93                            if (map == null)
94                                    setFeatureSource(null, null);
95                            else {
96                                    FeatureCollection fc = map.getGeoObject();
97                                    String fcName = fc.getFeatureType().getTypeName();
98                                    FeatureSource fs = new MemoryDataStore(fc)
99                                                    .getFeatureSource(fcName);
100                                    setFeatureSource(fs, map.getAttributeMetaDataMap());
101                            }
102                    } catch (Exception err) {
103                            throw new RuntimeException(err);
104                    }
105            }
106    
107            public void setFeatureCollection(StyledFeatureSourceInterface map) {
108                    try {
109                            if (map == null)
110                                    setFeatureSource(null, null);
111                            else
112                                    setFeatureSource(map.getGeoObject(), map
113                                                    .getAttributeMetaDataMap());
114                    } catch (Exception err) {
115                            throw new RuntimeException(err);
116                    }
117            }
118    
119  public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel {          @Override
120              public void reorganize() {
121    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {                  super.reorganize();
122      super(null);                  // translate the column names
123    }                  if (visibleAMD != null) {
124                              Iterator<Integer> keys = visibleAMD.keySet().iterator();
125    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {                          for (int i = 0; i < colNames.length && keys.hasNext(); i++) {
126      super(null);                                  Translation title = visibleAMD.get(keys.next()).getTitle();
127    }                                  if (!I8NUtil.isEmpty(title)) {
128                                            System.out.println("set colname " + i + " to "
129    public String[] createColumnNames() {                                                          + title.toString());
130      return new String[0];                                          colNames[i] = title.toString();
131    }                                  }
132                              }
133    public int getRowCount() {                  }
134      return 0;                  fireTableStructureChanged();
135    }          }
     
   public Object getValueAt(int row, int col) {  
     return "";  
   }  
136  }  }

Legend:
Removed from v.47  
changed lines
  Added in v.56

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26