/[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 57 by mojays, Fri Apr 17 15:26:14 2009 UTC revision 59 by mojays, Fri Apr 17 17:26:58 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      /** Contains the complete {@link AttributeMetaData}-Map of the styled layer. */
48      protected Map<Integer, AttributeMetaData> origAMD = null;
49      /** Holds the current filter on the table */
50      protected Filter filter = null;
51    
52      /**
53       * Creates a new table model for a styled map.
54       * @param map the styled map
55       */
56    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
57      this(map,Filter.INCLUDE);      this(map,Filter.INCLUDE);
58    }    }
59    
60      /**
61       * Creates a new table model for a styled map.
62       * @param map the styled map
63       * @param filter filter applied to the table
64       */
65    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map, Filter filter) {    public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map, Filter filter) {
66      super();      super();
67      setFeatureCollection(map, filter);      setFeatureCollection(map, filter);
68    }    }
69    
70      /**
71       * Creates a new table model for a styled map.
72       * @param map the styled map
73       */
74    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
75      this(map,Filter.INCLUDE);      this(map,Filter.INCLUDE);
76    }    }
77    
78      /**
79       * Creates a new table model for a styled map.
80       * @param map the styled map
81       * @param filter filter applied to the table
82       */
83    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map, Filter filter) {    public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map, Filter filter) {
84      super();      super();
85      setFeatureCollection(map, filter);      setFeatureCollection(map, filter);
86    }    }
87    
88      /**
89       * Sets a new data source for the table.
90       * @param fs     the feature source
91       * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
92       *               and translation
93       */
94    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;  
95      if ( filter == null )      if ( filter == null )
96        filter = Filter.INCLUDE;        filter = Filter.INCLUDE;
97    
98        this.featureSource = fs;
99        this.filter        = filter;
100        this.origAMD       = amd;
101        this.visibleAMD    = null;
102            
103      FeatureCollection fc = null;      FeatureCollection fc = null;
104      if (fs != null) {      if (fs != null) {
# Line 90  public class StyledFeatureCollectionTabl Line 121  public class StyledFeatureCollectionTabl
121      setFeatureCollection(fc);      setFeatureCollection(fc);
122    }    }
123    
124      /**
125       * Converts the {@code StyledFeatureCollection} to a {@code FeatureSource}
126       * and sets this as the new data source for the table.
127       * @param fs     the feature source
128       * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
129       *               and translation
130       */
131    public void setFeatureCollection(StyledFeatureCollectionInterface map, Filter filter) {    public void setFeatureCollection(StyledFeatureCollectionInterface map, Filter filter) {
132        this.map = map;
133      try {      try {
134        if (map == null)        if (map == null)
135          setFeatureSource(null, null, null);          setFeatureSource(null, null, null);
# Line 105  public class StyledFeatureCollectionTabl Line 144  public class StyledFeatureCollectionTabl
144      }      }
145    }    }
146    
147      /**
148       * Sets the {@code StyledFeatureCollection} as new data source for the table.
149       * @param fs     the feature source
150       * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
151       *               and translation
152       */
153    public void setFeatureCollection(StyledFeatureSourceInterface map, Filter filter) {    public void setFeatureCollection(StyledFeatureSourceInterface map, Filter filter) {
154        this.map = map;
155      try {      try {
156        if (map == null)        if (map == null)
157          setFeatureSource(null, null, null);          setFeatureSource(null, null, null);
# Line 115  public class StyledFeatureCollectionTabl Line 161  public class StyledFeatureCollectionTabl
161        throw new RuntimeException(err);        throw new RuntimeException(err);
162      }      }
163    }    }
164      
165      /**
166       * Resets the filter for the table.
167       * @param filter a filter
168       */
169      public void setFilter(Filter filter) {
170        try{
171          setFeatureSource(this.featureSource, this.origAMD, filter);
172        } catch (Exception err) {
173          throw new RuntimeException(err);
174        }
175      }
176    
177      /**
178       * After calling {@code super.reorganize(.)} this method replaced the
179       * column descriptions with the titles of the {@code AttributeMetaData}.
180       * @param fireTableStructureChanged indicates whether a table event is
181       *        initiated after reorganize
182       */
183    @Override    @Override
184    public void reorganize() {    protected void reorganize(boolean fireTableStructureChanged) {
185      super.reorganize();      super.reorganize(false);
186      // translate the column names      // translate the column names
187      if (visibleAMD != null) {      if (visibleAMD != null) {
188        Iterator<Integer> keys = visibleAMD.keySet().iterator();        Iterator<Integer> keys = visibleAMD.keySet().iterator();
# Line 130  public class StyledFeatureCollectionTabl Line 194  public class StyledFeatureCollectionTabl
194          }          }
195        }        }
196      }      }
197      fireTableStructureChanged();      if ( fireTableStructureChanged )
198          fireTableStructureChanged();
199    }    }
200  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26