/[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 56 by alfonx, Fri Apr 17 15:19:00 2009 UTC revision 58 by mojays, Fri Apr 17 15:55:33 2009 UTC
# Line 32  import skrueger.i8n.Translation; Line 32  import skrueger.i8n.Translation;
32   * functionalities of the {@link AttributeMetaData} of   * functionalities of the {@link AttributeMetaData} of
33   * {@linkplain StyledMapInterface styled objects}.   * {@linkplain StyledMapInterface styled objects}.
34   * <ul>   * <ul>
35   * <li>column names are translated according to   *   <li>column names are translated according to {@link AttributeMetaData#getTitle()}</li>
36   * {@link AttributeMetaData#getTitle()}</li>   *   <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
  * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>  
37   * </ul>   * </ul>
38   *   * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
  * @author <a href="mailto:[email protected]">Martin Schmitz</a>  
  *         (University of Bonn/Germany)  
  *  
39   */   */
40  public class StyledFeatureCollectionTableModel extends  public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel {
41                  FeatureCollectionTableModel {    /** Holds the data source as styled map. */
42      protected StyledMapInterface map = null;
43          protected Map<Integer, AttributeMetaData> visibleAMD = null;    /** Contains only the visible elements of the {@link AttributeMetaData}-Map */
44      protected Map<Integer, AttributeMetaData> visibleAMD = null;
45          public StyledFeatureCollectionTableModel(    /** Holds the data source for the table as {@code FeatureSource}. */
46                          StyledFeatureCollectionInterface map) {    protected FeatureSource featureSource = null;
47                  super();    /** Holds the current filter on the table */
48                  setFeatureCollection(map);    protected Filter filter = null;
49          }  
50      /**
51          public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {     * Creates a new table model for a styled map.
52                  super();     * @param map the styled map
53                  setFeatureCollection(map);     */
54          }    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
55        this(map,Filter.INCLUDE);
56          protected void setFeatureSource(FeatureSource fs,    }
57                          Map<Integer, AttributeMetaData> amd) throws Exception {  
58                  FeatureCollection fc = null;    /**
59                  this.visibleAMD = null;     * Creates a new table model for a styled map.
60                  if (fs != null) {     * @param map the styled map
61                          Query query = new DefaultQuery();     * @param filter filter applied to the table
62                          if (amd != null) {     */
63                                  // determine the names of the visible Attributes    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map, Filter filter) {
64                                  this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(      super();
65                                                  amd, true);      setFeatureCollection(map, filter);
66                                  Vector<String> visibleAttrNames = new Vector<String>();    }
67    
68                                  // Add the column with the geometry (usually "the_geom")    /**
69                                  visibleAttrNames.add(fs.getSchema().getDefaultGeometry()     * Creates a new table model for a styled map.
70                                                  .getLocalName());     * @param map the styled map
71       */
72                                  for (int attrIdx : visibleAMD.keySet())    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
73                                          visibleAttrNames.add(fs.getSchema().getAttributeType(      this(map,Filter.INCLUDE);
74                                                          attrIdx).getLocalName());    }
75    
76                                  // create a query for the visible attributes    /**
77                                  String[] properties = visibleAttrNames.toArray(new String[0]);     * Creates a new table model for a styled map.
78       * @param map the styled map
79                                  query = new DefaultQuery(fs.getSchema().getTypeName(),     * @param filter filter applied to the table
80                                                  Filter.INCLUDE, properties);     */
81                          }    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map, Filter filter) {
82                          fc = fs.getFeatures(query);      super();
83                  }      setFeatureCollection(map, filter);
84                  setFeatureCollection(fc);    }
85          }  
86      /**
87          public void setFeatureCollection(StyledFeatureCollectionInterface map) {     * Sets a new data source for the table.
88                  try {     * @param fs     the feature source
89                          if (map == null)     * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
90                                  setFeatureSource(null, null);     *               and translation
91                          else {     */
92                                  FeatureCollection fc = map.getGeoObject();    protected void setFeatureSource(FeatureSource fs, Map<Integer, AttributeMetaData> amd, Filter filter) throws Exception {
93                                  String fcName = fc.getFeatureType().getTypeName();      if ( filter == null )
94                                  FeatureSource fs = new MemoryDataStore(fc)        filter = Filter.INCLUDE;
95                                                  .getFeatureSource(fcName);  
96                                  setFeatureSource(fs, map.getAttributeMetaDataMap());      this.featureSource = fs;
97                          }      this.filter        = filter;
98                  } catch (Exception err) {      this.visibleAMD    = null;
99                          throw new RuntimeException(err);      
100                  }      FeatureCollection fc = null;
101          }      if (fs != null) {
102          Query query = new DefaultQuery();
103          public void setFeatureCollection(StyledFeatureSourceInterface map) {        if (amd != null) {
104                  try {          // determine the names of the visible Attributes
105                          if (map == null)          this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true);
106                                  setFeatureSource(null, null);          Vector<String> visibleAttrNames = new Vector<String>();
107                          else          // Add the column with the geometry (usually "the_geom")
108                                  setFeatureSource(map.getGeoObject(), map          visibleAttrNames.add(fs.getSchema().getDefaultGeometry().getLocalName());
109                                                  .getAttributeMetaDataMap());          for (int attrIdx : visibleAMD.keySet())
110                  } catch (Exception err) {            visibleAttrNames.add(fs.getSchema().getAttributeType(attrIdx).getLocalName());
111                          throw new RuntimeException(err);  
112                  }          // create a query for the visible attributes
113          }          String[] properties = visibleAttrNames.toArray(new String[0]);
114            query = new DefaultQuery(fs.getSchema().getTypeName(), filter, properties);
115          @Override        }
116          public void reorganize() {        fc = fs.getFeatures(query);
117                  super.reorganize();      }
118                  // translate the column names      setFeatureCollection(fc);
119                  if (visibleAMD != null) {    }
120                          Iterator<Integer> keys = visibleAMD.keySet().iterator();  
121                          for (int i = 0; i < colNames.length && keys.hasNext(); i++) {    /**
122                                  Translation title = visibleAMD.get(keys.next()).getTitle();     * Converts the {@code StyledFeatureCollection} to a {@code FeatureSource}
123                                  if (!I8NUtil.isEmpty(title)) {     * and sets this as the new data source for the table.
124                                          System.out.println("set colname " + i + " to "     * @param fs     the feature source
125                                                          + title.toString());     * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
126                                          colNames[i] = title.toString();     *               and translation
127                                  }     */
128                          }    public void setFeatureCollection(StyledFeatureCollectionInterface map, Filter filter) {
129                  }      this.map = map;
130                  fireTableStructureChanged();      try {
131          }        if (map == null)
132            setFeatureSource(null, null, null);
133          else {
134            FeatureCollection fc = map.getGeoObject();
135            String fcName = fc.getFeatureType().getTypeName();
136            FeatureSource fs = new MemoryDataStore(fc).getFeatureSource(fcName);
137            setFeatureSource(fs, map.getAttributeMetaDataMap(), filter);
138          }
139        } catch (Exception err) {
140          throw new RuntimeException(err);
141        }
142      }
143    
144      /**
145       * Sets the {@code StyledFeatureCollection} as new data source for the table.
146       * @param fs     the feature source
147       * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
148       *               and translation
149       */
150      public void setFeatureCollection(StyledFeatureSourceInterface map, Filter filter) {
151        this.map = map;
152        try {
153          if (map == null)
154            setFeatureSource(null, null, null);
155          else
156            setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap(), filter);
157        } catch (Exception err) {
158          throw new RuntimeException(err);
159        }
160      }
161      
162      /**
163       * Resets the filter for the table.
164       * @param filter a filter
165       */
166      public void setFilter(Filter filter) {
167        try{
168          setFeatureSource(this.featureSource, this.visibleAMD, filter);
169        } catch (Exception err) {
170          throw new RuntimeException(err);
171        }
172      }
173    
174      /**
175       * After calling {@code super.reorganize(.)} this method replaced the
176       * column descriptions with the titles of the {@code AttributeMetaData}.
177       * @param fireTableStructureChanged indicates whether a table event is
178       *        initiated after reorganize
179       */
180      @Override
181      protected void reorganize(boolean fireTableStructureChanged) {
182        super.reorganize(false);
183        // translate the column names
184        if (visibleAMD != null) {
185          Iterator<Integer> keys = visibleAMD.keySet().iterator();
186          for (int i = 0; i < colNames.length && keys.hasNext(); i++) {
187            Translation title = visibleAMD.get(keys.next()).getTitle();
188            if (!I8NUtil.isEmpty(title)) {
189              System.out.println("set colname " + i + " to " + title.toString());
190              colNames[i] = title.toString();
191            }
192          }
193        }
194        if ( fireTableStructureChanged )
195          fireTableStructureChanged();
196      }
197  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26