Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / data / feature / swing / FeatureTablePanel.java @ 31544

History | View | Annotate | Download (5.22 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.data.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.FeatureQuery;
36
import org.gvsig.fmap.dal.feature.FeatureStore;
37
import org.gvsig.fmap.data.feature.swing.table.ConfigurableFeatureTableModel;
38
import org.gvsig.fmap.data.feature.swing.table.FeatureTableConfigurationPanel;
39

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

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

    
49
    private FeatureStore featureStore;
50
    private FeatureQuery featureQuery;
51
    private ConfigurableFeatureTableModel tableModel;
52

    
53
    private JScrollPane jScrollPane = null;
54

    
55
    private FeatureTable table = null;
56

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

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

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

    
94
    /**
95
     * @param isDoubleBuffered
96
     * @throws DataException
97
     */
98
    public FeatureTablePanel(FeatureStore featureStore,
99
            FeatureQuery featureQuery, boolean isDoubleBuffered)
100
            throws DataException {
101
        super(isDoubleBuffered);
102
        this.featureStore = featureStore;
103
        if (featureQuery != null) {
104
                        this.featureQuery = featureQuery;
105
                } else {
106
                        this.featureQuery = featureStore.createFeatureQuery();
107
                }
108
        createModel();
109
        initialize();
110
        // createGUI();
111
    }
112

    
113
    /**
114
     * This method initializes this
115
     *
116
     * @throws DataException
117
     *
118
     */
119
    private void initialize() throws DataException {
120
        this.setLayout(new BorderLayout());
121
        this.add(getJScrollPane(), BorderLayout.CENTER);
122
    }
123

    
124
    public JPanel createConfigurationPanel() {
125
        return new FeatureTableConfigurationPanel(tableModel);
126
    }
127

    
128
    /**
129
     * Returns the internal Table Model for the Features of the FeatureStore.
130
     *
131
     * @return the internal Table Model
132
     */
133
    public ConfigurableFeatureTableModel getTableModel() {
134
        return tableModel;
135
    }
136

    
137
    private void createModel() throws DataException {
138
        tableModel = new ConfigurableFeatureTableModel(featureStore,
139
                featureQuery);
140
    }
141

    
142
    public FeatureTable getTable() throws DataException {
143
        if (table == null) {
144
            table = new FeatureTable(tableModel);
145
            // Change the selection model to link with the FeatureStore
146
            // selection
147
            // through the FeatureTableModel
148
            table.setRowSelectionAllowed(true);
149
            table.setColumnSelectionAllowed(false);
150
            // table.setSelectionModel(new FeatureSelectionModel(tableModel));
151
        }
152
        return table;
153
    }
154

    
155
    /**
156
     * This method initializes jScrollPane
157
     *
158
     * @return javax.swing.JScrollPane
159
     * @throws DataException
160
     */
161
    private JScrollPane getJScrollPane() throws DataException {
162
        if (jScrollPane == null) {
163
            jScrollPane = new JScrollPane();
164
            jScrollPane.setViewportView(getTable());
165
        }
166
        return jScrollPane;
167
    }
168
}