Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / dal / feature / swing / FeatureTablePanel.java @ 33378

History | View | Annotate | Download (5.79 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {Create a Table component for Features}
26
 */
27
package org.gvsig.fmap.mapcontrol.dal.feature.swing;
28

    
29
import java.awt.BorderLayout;
30

    
31
import javax.swing.JPanel;
32
import javax.swing.JScrollPane;
33

    
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.feature.Feature;
36
import org.gvsig.fmap.dal.feature.FeatureQuery;
37
import org.gvsig.fmap.dal.feature.FeatureStore;
38
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.ConfigurableFeatureTableModel;
39
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableConfigurationPanel;
40

    
41
/**
42
 * Panel to show a table of Feature data.
43
 *
44
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
45
 */
46
public class FeatureTablePanel extends JPanel {
47

    
48
    private static final long serialVersionUID = -9199073063283531216L;
49

    
50
        private ConfigurableFeatureTableModel tableModel;
51

    
52
    private JScrollPane jScrollPane = null;
53

    
54
    private FeatureTable table = null;
55

    
56
    /**
57
     * Constructs a Panel to show a table with the features of a FeatureStore.
58
     *
59
     * @param featureStore
60
     *            to extract the features from
61
     * @throws DataException
62
     *             if there is an error reading data from the FeatureStore
63
     */
64
    public FeatureTablePanel(FeatureStore featureStore) throws DataException {
65
        this(featureStore, true);
66
    }
67

    
68
    /**
69
     * Constructs a Panel to show a table with the features of a FeatureStore.
70
     *
71
     * @param featureStore
72
     *            to extract the features from
73
     * @param isDoubleBuffered
74
     *            a boolean, true for double-buffering, which uses additional
75
     *            memory space to achieve fast, flicker-free updates
76
     * @throws DataException
77
     *             if there is an error reading data from the FeatureStore
78
     */
79
    public FeatureTablePanel(FeatureStore featureStore, boolean isDoubleBuffered)
80
            throws DataException {
81
        this(featureStore, null, isDoubleBuffered);
82
    }
83

    
84
    /**
85
     * @throws DataException
86
     *
87
     */
88
    public FeatureTablePanel(FeatureStore featureStore,
89
            FeatureQuery featureQuery) throws DataException {
90
        this(featureStore, featureQuery, true);
91
    }
92

    
93
    /**
94
     * @param isDoubleBuffered
95
     * @throws DataException
96
     */
97
    public FeatureTablePanel(FeatureStore featureStore,
98
            FeatureQuery featureQuery, boolean isDoubleBuffered)
99
            throws DataException {
100
                this(createModel(featureStore, featureQuery));
101
    }
102

    
103
        public FeatureTablePanel(ConfigurableFeatureTableModel tableModel)
104
                        throws DataException {
105
                this(tableModel, true);
106
        }
107

    
108
        public FeatureTablePanel(ConfigurableFeatureTableModel tableModel,
109
                        boolean isDoubleBuffered) throws DataException {
110
                super(isDoubleBuffered);
111
                this.tableModel = tableModel;
112
        this.setLayout(new BorderLayout());
113
        this.add(getJScrollPane(), BorderLayout.CENTER);
114
    }
115

    
116
    public JPanel createConfigurationPanel() {
117
        return new FeatureTableConfigurationPanel(tableModel);
118
    }
119

    
120
    /**
121
     * Returns the internal Table Model for the Features of the FeatureStore.
122
     *
123
     * @return the internal Table Model
124
     */
125
    public ConfigurableFeatureTableModel getTableModel() {
126
        return tableModel;
127
    }
128

    
129
        /**
130
         * Returns the {@link FeatureStore} of the {@link Feature}s being shown in
131
         * the table.
132
         * 
133
         * @return the store of the features
134
         */
135
        public FeatureStore getFeatureStore() {
136
                return getTableModel().getFeatureStore();
137
        }
138

    
139
        /**
140
         * Sets that the selected Features to be viewed first.
141
         */
142
        public void setSelectionUp(boolean selectionUp) {
143
                try {
144
                        getTable().setSelectionUp(selectionUp);
145
                } catch (DataException e) {
146
                        // TODO: create and throw a SetSelectionUpException
147
                        e.printStackTrace();
148
                }
149
        }
150

    
151
        private static ConfigurableFeatureTableModel createModel(
152
                        FeatureStore featureStore, FeatureQuery featureQuery)
153
                        throws DataException {
154
                FeatureQuery query =
155
                                featureQuery == null ? featureStore.createFeatureQuery()
156
                                                : featureQuery;
157

    
158
                return new ConfigurableFeatureTableModel(featureStore, query);
159
    }
160

    
161
    public FeatureTable getTable() throws DataException {
162
        if (table == null) {
163
            table = new FeatureTable(tableModel);
164
            // Change the selection model to link with the FeatureStore
165
            // selection
166
            // through the FeatureTableModel
167
            table.setRowSelectionAllowed(true);
168
            table.setColumnSelectionAllowed(false);
169
            // table.setSelectionModel(new FeatureSelectionModel(tableModel));
170
        }
171
        return table;
172
    }
173

    
174
    /**
175
     * This method initializes jScrollPane
176
     *
177
     * @return javax.swing.JScrollPane
178
     * @throws DataException
179
     */
180
    private JScrollPane getJScrollPane() throws DataException {
181
        if (jScrollPane == null) {
182
            jScrollPane = new JScrollPane();
183
            jScrollPane.setViewportView(getTable());
184
        }
185
        return jScrollPane;
186
    }
187
}