root / trunk / extensions / extSDE / src / com / iver / cit / gvsig / sde / gui / sdewizard2 / UserSelectedFieldsPanel.java @ 11193
History | View | Annotate | Download (7.22 KB)
1 |
/* 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.iver.cit.gvsig.sde.gui.sdewizard2; |
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 |
import org.gvsig.gui.beans.swing.JButton; |
54 |
|
55 |
import com.iver.andami.PluginServices; |
56 |
|
57 |
|
58 |
/**
|
59 |
* Utility class that holds a single table field selection controls.
|
60 |
*
|
61 |
* @author jldominguez
|
62 |
*
|
63 |
*/
|
64 |
public class UserSelectedFieldsPanel extends JPanel implements ActionListener { |
65 |
private String[] fieldNames = null; |
66 |
private String[] fieldTypes = null; |
67 |
private JScrollPane fieldsScrollPane = null; |
68 |
private AvailableFieldsCheckBoxList fieldsList = null; |
69 |
private JButton selAllFieldsButton = null; |
70 |
private JButton deselAllFieldsButton = null; |
71 |
private WizardSDE parent = null; |
72 |
|
73 |
public UserSelectedFieldsPanel(String[] fNames, String[] fTypes, |
74 |
boolean empty, WizardSDE _p) {
|
75 |
parent = _p; |
76 |
fieldNames = fNames; |
77 |
fieldTypes = fTypes; |
78 |
initialize(); |
79 |
|
80 |
if (empty) {
|
81 |
enableControls(false);
|
82 |
} |
83 |
else {
|
84 |
setAllFieldsInTable(fNames, fieldTypes); |
85 |
} |
86 |
} |
87 |
|
88 |
public void loadValues() { |
89 |
setAllFieldsInTable(fieldNames, fieldTypes); |
90 |
} |
91 |
|
92 |
public String[] getUserSelectedFields(String idf, String gef) { |
93 |
String[] resp = getUserSelectedFields(); |
94 |
resp = addBeginningIfNotContained(resp, idf); |
95 |
resp = removeIfContained(resp, gef); |
96 |
|
97 |
return resp;
|
98 |
} |
99 |
|
100 |
private String[] addBeginningIfNotContained(String[] arr, String item) { |
101 |
if (contains(arr, item)) {
|
102 |
return arr;
|
103 |
} |
104 |
else {
|
105 |
int size = arr.length;
|
106 |
String[] resp = new String[size + 1]; |
107 |
resp[0] = item;
|
108 |
|
109 |
for (int i = 0; i < size; i++) { |
110 |
resp[i + 1] = arr[i];
|
111 |
} |
112 |
|
113 |
return resp;
|
114 |
} |
115 |
} |
116 |
|
117 |
private String[] removeIfContained(String[] arr, String item) { |
118 |
if (!contains(arr, item)) {
|
119 |
return arr;
|
120 |
} |
121 |
else {
|
122 |
int size = arr.length;
|
123 |
ArrayList aux = new ArrayList(); |
124 |
|
125 |
for (int i = 0; i < size; i++) |
126 |
aux.add(arr[i]); |
127 |
|
128 |
aux.remove(item); |
129 |
|
130 |
return (String[]) aux.toArray(new String[0]); |
131 |
} |
132 |
} |
133 |
|
134 |
private boolean contains(String[] arr, String item) { |
135 |
for (int i = 0; i < arr.length; i++) { |
136 |
if (arr[i].compareTo(item) == 0) { |
137 |
return true; |
138 |
} |
139 |
} |
140 |
|
141 |
return false; |
142 |
} |
143 |
|
144 |
public void enableControls(boolean enable) { |
145 |
getFieldsList().setEnabled(enable); |
146 |
getSelAllFieldsButton().setEnabled(enable); |
147 |
getDeselAllFieldsButton().setEnabled(enable); |
148 |
} |
149 |
|
150 |
private void initialize() { |
151 |
setLayout(null);
|
152 |
setBounds(new java.awt.Rectangle(255, 55, 251, 191)); |
153 |
setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
154 |
PluginServices.getText(this, "table_fields"), |
155 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
156 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
157 |
add(getFieldsScrollPane(), null);
|
158 |
|
159 |
add(getSelAllFieldsButton(), null);
|
160 |
add(getDeselAllFieldsButton(), null);
|
161 |
} |
162 |
|
163 |
private JScrollPane getFieldsScrollPane() { |
164 |
if (fieldsScrollPane == null) { |
165 |
fieldsScrollPane = new JScrollPane(); |
166 |
fieldsScrollPane.setBounds(new java.awt.Rectangle(5, 20, |
167 |
101 + (28 * 5), 101 + (7 * 5))); |
168 |
fieldsScrollPane.setViewportView(getFieldsList()); |
169 |
} |
170 |
|
171 |
return fieldsScrollPane;
|
172 |
} |
173 |
|
174 |
private AvailableFieldsCheckBoxList getFieldsList() {
|
175 |
if (fieldsList == null) { |
176 |
fieldsList = new AvailableFieldsCheckBoxList();
|
177 |
} |
178 |
|
179 |
return fieldsList;
|
180 |
} |
181 |
|
182 |
private void setAllFieldsInTable(String[] all_f, String[] all_t) { |
183 |
DefaultListModel lmodel = new DefaultListModel(); |
184 |
|
185 |
for (int i = 0; i < all_f.length; i++) { |
186 |
lmodel.addElement(new FieldsListItem(all_f[i], all_t[i]));
|
187 |
} |
188 |
|
189 |
getFieldsList().setModel(lmodel); |
190 |
getFieldsScrollPane().setViewportView(fieldsList); |
191 |
getFieldsScrollPane().updateUI(); |
192 |
} |
193 |
|
194 |
private JButton getSelAllFieldsButton() { |
195 |
if (selAllFieldsButton == null) { |
196 |
selAllFieldsButton = new JButton(); |
197 |
selAllFieldsButton.addActionListener(this);
|
198 |
selAllFieldsButton.setBounds(new java.awt.Rectangle(28 + 5, 160, |
199 |
90, 26)); |
200 |
selAllFieldsButton.setText(PluginServices.getText(this, "all")); |
201 |
} |
202 |
|
203 |
return selAllFieldsButton;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* This method initializes deselAllFieldsButton
|
208 |
*
|
209 |
* @return javax.swing.JButton
|
210 |
*/
|
211 |
private JButton getDeselAllFieldsButton() { |
212 |
if (deselAllFieldsButton == null) { |
213 |
deselAllFieldsButton = new JButton(); |
214 |
deselAllFieldsButton.addActionListener(this);
|
215 |
deselAllFieldsButton.setBounds(new java.awt.Rectangle(28 + 100, |
216 |
160, 90, 26)); |
217 |
deselAllFieldsButton.setText(PluginServices.getText(this, "none2")); |
218 |
} |
219 |
|
220 |
return deselAllFieldsButton;
|
221 |
} |
222 |
|
223 |
public void actionPerformed(ActionEvent e) { |
224 |
Object src = e.getSource();
|
225 |
|
226 |
if (src == getDeselAllFieldsButton()) {
|
227 |
getFieldsList().checkAll(false);
|
228 |
} |
229 |
|
230 |
if (src == getSelAllFieldsButton()) {
|
231 |
getFieldsList().checkAll(true);
|
232 |
} |
233 |
} |
234 |
|
235 |
private String[] getUserSelectedFields() { |
236 |
Object[] sel = fieldsList.getCheckedItems(); |
237 |
int size = sel.length;
|
238 |
|
239 |
String[] resp = new String[size]; |
240 |
|
241 |
for (int i = 0; i < size; i++) { |
242 |
resp[i] = ((FieldsListItem) sel[i]).getName(); |
243 |
} |
244 |
|
245 |
return resp;
|
246 |
} |
247 |
|
248 |
public void repaint() { |
249 |
super.repaint();
|
250 |
getFieldsList().updateUI(); |
251 |
getFieldsScrollPane().updateUI(); |
252 |
} |
253 |
} |