/[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 46 by mojays, Fri Apr 17 11:44:05 2009 UTC revision 56 by alfonx, Fri Apr 17 15:19:00 2009 UTC
# Line 1  Line 1 
1    /** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
2    
3        This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
4        This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
5        You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
6    
7        Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
8        Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
9        Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
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.46  
changed lines
  Added in v.56

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26