/[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 57 by mojays, Fri Apr 17 15:26:14 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      /** Contains only the visible elements of the {@link AttributeMetaData}-Map */
44    protected Map<Integer, AttributeMetaData> visibleAMD = null;    protected Map<Integer, AttributeMetaData> visibleAMD = null;
45      /** Holds the data source for the table as {@code FeatureSource}. */
46      protected FeatureSource featureSource = null;
47      /** Holds the current filter on the table */
48      protected Filter filter = null;
49    
50      /**
51       * Creates a new table model for a styled map.
52       * @param map the styled map
53       */
54    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
55      this(map,Filter.INCLUDE);      this(map,Filter.INCLUDE);
56    }    }
57    
58      /**
59       * Creates a new table model for a styled map.
60       * @param map the styled map
61       * @param filter filter applied to the table
62       */
63    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map, Filter filter) {    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map, Filter filter) {
64      super();      super();
65      setFeatureCollection(map, filter);      setFeatureCollection(map, filter);
66    }    }
67    
68      /**
69       * Creates a new table model for a styled map.
70       * @param map the styled map
71       */
72    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
73      this(map,Filter.INCLUDE);      this(map,Filter.INCLUDE);
74    }    }
75    
76      /**
77       * Creates a new table model for a styled map.
78       * @param map the styled map
79       * @param filter filter applied to the table
80       */
81    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map, Filter filter) {    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map, Filter filter) {
82      super();      super();
83      setFeatureCollection(map, filter);      setFeatureCollection(map, filter);
84    }    }
85    
86      /**
87       * Sets a new data source for the table.
88       * @param fs     the feature source
89       * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
90       *               and translation
91       */
92    protected void setFeatureSource(FeatureSource fs, Map<Integer, AttributeMetaData> amd, Filter filter) throws Exception {    protected void setFeatureSource(FeatureSource fs, Map<Integer, AttributeMetaData> amd, Filter filter) throws Exception {
     this.visibleAMD = null;  
93      if ( filter == null )      if ( filter == null )
94        filter = Filter.INCLUDE;        filter = Filter.INCLUDE;
95    
96        this.featureSource = fs;
97        this.filter        = filter;
98        this.visibleAMD    = null;
99            
100      FeatureCollection fc = null;      FeatureCollection fc = null;
101      if (fs != null) {      if (fs != null) {
# Line 90  public class StyledFeatureCollectionTabl Line 118  public class StyledFeatureCollectionTabl
118      setFeatureCollection(fc);      setFeatureCollection(fc);
119    }    }
120    
121      /**
122       * Converts the {@code StyledFeatureCollection} to a {@code FeatureSource}
123       * and sets this as the new data source for the table.
124       * @param fs     the feature source
125       * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
126       *               and translation
127       */
128    public void setFeatureCollection(StyledFeatureCollectionInterface map, Filter filter) {    public void setFeatureCollection(StyledFeatureCollectionInterface map, Filter filter) {
129        this.map = map;
130      try {      try {
131        if (map == null)        if (map == null)
132          setFeatureSource(null, null, null);          setFeatureSource(null, null, null);
# Line 105  public class StyledFeatureCollectionTabl Line 141  public class StyledFeatureCollectionTabl
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) {    public void setFeatureCollection(StyledFeatureSourceInterface map, Filter filter) {
151        this.map = map;
152      try {      try {
153        if (map == null)        if (map == null)
154          setFeatureSource(null, null, null);          setFeatureSource(null, null, null);
# Line 115  public class StyledFeatureCollectionTabl Line 158  public class StyledFeatureCollectionTabl
158        throw new RuntimeException(err);        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    @Override
181    public void reorganize() {    protected void reorganize(boolean fireTableStructureChanged) {
182      super.reorganize();      super.reorganize(false);
183      // translate the column names      // translate the column names
184      if (visibleAMD != null) {      if (visibleAMD != null) {
185        Iterator<Integer> keys = visibleAMD.keySet().iterator();        Iterator<Integer> keys = visibleAMD.keySet().iterator();
# Line 130  public class StyledFeatureCollectionTabl Line 191  public class StyledFeatureCollectionTabl
191          }          }
192        }        }
193      }      }
194      fireTableStructureChanged();      if ( fireTableStructureChanged )
195          fireTableStructureChanged();
196    }    }
197  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26