root / branches / v2_0_0_prep / extensions / extGeoDB / src / com / prodevelop / cit / gvsig / vectorialdb / wizard / UserSelectedFieldsPanel.java @ 29199
History | View | Annotate | Download (7.37 KB)
1 | 11971 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * Prodevelop Integraci?n de Tecnolog?as SL
|
||
34 | * Conde Salvatierra de ?lava , 34-10
|
||
35 | * 46004 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963 510 612
|
||
39 | * +34 963 510 968
|
||
40 | * gis@prodevelop.es
|
||
41 | * http://www.prodevelop.es
|
||
42 | */
|
||
43 | package com.prodevelop.cit.gvsig.vectorialdb.wizard; |
||
44 | |||
45 | import java.awt.event.ActionEvent; |
||
46 | import java.awt.event.ActionListener; |
||
47 | import java.util.ArrayList; |
||
48 | |||
49 | import javax.swing.DefaultListModel; |
||
50 | import javax.swing.JPanel; |
||
51 | import javax.swing.JScrollPane; |
||
52 | |||
53 | 24759 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
54 | 12826 | jaume | import org.gvsig.gui.beans.swing.JButton; |
55 | 11971 | caballero | |
56 | 12826 | jaume | import com.iver.andami.PluginServices; |
57 | |||
58 | |||
59 | 11971 | caballero | /**
|
60 | * Utility class that holds a single table field selection controls.
|
||
61 | *
|
||
62 | * @author jldominguez
|
||
63 | *
|
||
64 | */
|
||
65 | public class UserSelectedFieldsPanel extends JPanel implements ActionListener { |
||
66 | 21910 | vcaballero | private FeatureAttributeDescriptor[] descriptors = null; |
67 | // private String[] fieldTypes = null;
|
||
68 | 11971 | caballero | private JScrollPane fieldsScrollPane = null; |
69 | private AvailableFieldsCheckBoxList fieldsList = null; |
||
70 | private JButton selAllFieldsButton = null; |
||
71 | private JButton deselAllFieldsButton = null; |
||
72 | 29199 | jmvivo | private WizardDB parent = null; |
73 | 11971 | caballero | |
74 | 21910 | vcaballero | public UserSelectedFieldsPanel(FeatureAttributeDescriptor[] descriptors, |
75 | 29199 | jmvivo | boolean empty, WizardDB _p) {
|
76 | 11971 | caballero | parent = _p; |
77 | 21910 | vcaballero | this.descriptors = descriptors;
|
78 | // fieldTypes = fTypes;
|
||
79 | 11971 | caballero | initialize(); |
80 | |||
81 | if (empty) {
|
||
82 | enableControls(false);
|
||
83 | } |
||
84 | else {
|
||
85 | 21910 | vcaballero | setAllFieldsInTable(descriptors); |
86 | 11971 | caballero | } |
87 | } |
||
88 | |||
89 | public void loadValues() { |
||
90 | 21910 | vcaballero | setAllFieldsInTable(descriptors); |
91 | 11971 | caballero | } |
92 | |||
93 | 29199 | jmvivo | public String[] getUserSelectedFields(String idf, String geo) { |
94 | 11971 | caballero | String[] resp = getUserSelectedFields(); |
95 | 29199 | jmvivo | if (idf != null) { |
96 | resp = addBeginningIfNotContained(resp, idf); |
||
97 | } |
||
98 | if (geo != null) { |
||
99 | resp = addBeginningIfNotContained(resp, geo); |
||
100 | } |
||
101 | 11971 | caballero | |
102 | return resp;
|
||
103 | } |
||
104 | |||
105 | private String[] addBeginningIfNotContained(String[] arr, String item) { |
||
106 | if (contains(arr, item)) {
|
||
107 | return arr;
|
||
108 | } |
||
109 | else {
|
||
110 | int size = arr.length;
|
||
111 | String[] resp = new String[size + 1]; |
||
112 | resp[0] = item;
|
||
113 | |||
114 | for (int i = 0; i < size; i++) { |
||
115 | resp[i + 1] = arr[i];
|
||
116 | } |
||
117 | |||
118 | return resp;
|
||
119 | } |
||
120 | } |
||
121 | |||
122 | private String[] removeIfContained(String[] arr, String item) { |
||
123 | if (!contains(arr, item)) {
|
||
124 | return arr;
|
||
125 | } |
||
126 | else {
|
||
127 | int size = arr.length;
|
||
128 | ArrayList aux = new ArrayList(); |
||
129 | |||
130 | 24759 | jmvivo | for (int i = 0; i < size; i++) { |
131 | aux.add(arr[i]); |
||
132 | } |
||
133 | 11971 | caballero | |
134 | aux.remove(item); |
||
135 | |||
136 | return (String[]) aux.toArray(new String[0]); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | private boolean contains(String[] arr, String item) { |
||
141 | for (int i = 0; i < arr.length; i++) { |
||
142 | if (arr[i].compareTo(item) == 0) { |
||
143 | return true; |
||
144 | } |
||
145 | } |
||
146 | |||
147 | return false; |
||
148 | } |
||
149 | |||
150 | public void enableControls(boolean enable) { |
||
151 | getFieldsList().setEnabled(enable); |
||
152 | getSelAllFieldsButton().setEnabled(enable); |
||
153 | getDeselAllFieldsButton().setEnabled(enable); |
||
154 | } |
||
155 | |||
156 | private void initialize() { |
||
157 | setLayout(null);
|
||
158 | 29199 | jmvivo | setBounds(new java.awt.Rectangle(255, 55, 251, 166)); |
159 | 11971 | caballero | setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
160 | PluginServices.getText(this, "table_fields"), |
||
161 | javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
||
162 | javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
||
163 | add(getFieldsScrollPane(), null);
|
||
164 | |||
165 | add(getSelAllFieldsButton(), null);
|
||
166 | add(getDeselAllFieldsButton(), null);
|
||
167 | } |
||
168 | |||
169 | private JScrollPane getFieldsScrollPane() { |
||
170 | if (fieldsScrollPane == null) { |
||
171 | fieldsScrollPane = new JScrollPane(); |
||
172 | fieldsScrollPane.setBounds(new java.awt.Rectangle(5, 20, |
||
173 | 29199 | jmvivo | 101 + (28 * 5), 76 + (7 * 5))); |
174 | 11971 | caballero | fieldsScrollPane.setViewportView(getFieldsList()); |
175 | } |
||
176 | |||
177 | return fieldsScrollPane;
|
||
178 | } |
||
179 | |||
180 | private AvailableFieldsCheckBoxList getFieldsList() {
|
||
181 | if (fieldsList == null) { |
||
182 | fieldsList = new AvailableFieldsCheckBoxList();
|
||
183 | } |
||
184 | |||
185 | return fieldsList;
|
||
186 | } |
||
187 | |||
188 | 21910 | vcaballero | private void setAllFieldsInTable(FeatureAttributeDescriptor[] descriptors) { |
189 | 11971 | caballero | DefaultListModel lmodel = new DefaultListModel(); |
190 | |||
191 | 21910 | vcaballero | for (int i = 0; i < descriptors.length; i++) { |
192 | lmodel.addElement(new FieldsListItem(descriptors[i]));
|
||
193 | 11971 | caballero | } |
194 | |||
195 | getFieldsList().setModel(lmodel); |
||
196 | getFieldsScrollPane().setViewportView(fieldsList); |
||
197 | getFieldsScrollPane().updateUI(); |
||
198 | } |
||
199 | |||
200 | private JButton getSelAllFieldsButton() { |
||
201 | if (selAllFieldsButton == null) { |
||
202 | selAllFieldsButton = new JButton(); |
||
203 | selAllFieldsButton.addActionListener(this);
|
||
204 | 29199 | jmvivo | selAllFieldsButton.setBounds(new java.awt.Rectangle(28 + 5, 135, |
205 | 11971 | caballero | 90, 26)); |
206 | selAllFieldsButton.setText(PluginServices.getText(this, "all")); |
||
207 | } |
||
208 | |||
209 | return selAllFieldsButton;
|
||
210 | } |
||
211 | |||
212 | /**
|
||
213 | * This method initializes deselAllFieldsButton
|
||
214 | *
|
||
215 | * @return javax.swing.JButton
|
||
216 | */
|
||
217 | private JButton getDeselAllFieldsButton() { |
||
218 | if (deselAllFieldsButton == null) { |
||
219 | deselAllFieldsButton = new JButton(); |
||
220 | deselAllFieldsButton.addActionListener(this);
|
||
221 | deselAllFieldsButton.setBounds(new java.awt.Rectangle(28 + 100, |
||
222 | 29199 | jmvivo | 135, 90, 26)); |
223 | 11971 | caballero | deselAllFieldsButton.setText(PluginServices.getText(this, "none2")); |
224 | } |
||
225 | |||
226 | return deselAllFieldsButton;
|
||
227 | } |
||
228 | |||
229 | public void actionPerformed(ActionEvent e) { |
||
230 | Object src = e.getSource();
|
||
231 | |||
232 | if (src == getDeselAllFieldsButton()) {
|
||
233 | getFieldsList().checkAll(false);
|
||
234 | } |
||
235 | |||
236 | if (src == getSelAllFieldsButton()) {
|
||
237 | getFieldsList().checkAll(true);
|
||
238 | } |
||
239 | } |
||
240 | |||
241 | private String[] getUserSelectedFields() { |
||
242 | Object[] sel = fieldsList.getCheckedItems(); |
||
243 | int size = sel.length;
|
||
244 | |||
245 | String[] resp = new String[size]; |
||
246 | |||
247 | for (int i = 0; i < size; i++) { |
||
248 | resp[i] = ((FieldsListItem) sel[i]).getName(); |
||
249 | } |
||
250 | |||
251 | return resp;
|
||
252 | } |
||
253 | |||
254 | public void repaint() { |
||
255 | super.repaint();
|
||
256 | getFieldsList().updateUI(); |
||
257 | getFieldsScrollPane().updateUI(); |
||
258 | } |
||
259 | } |