root / branches / v2_0_0_prep / extensions / extGeoDB / src / org / gvsig / geodb / vectorialdb / wizard / UserTableSettingsPanel.java @ 35341
History | View | Annotate | Download (11.4 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 org.gvsig.geodb.vectorialdb.wizard; |
44 |
|
45 |
import java.awt.Point; |
46 |
import java.awt.event.ActionEvent; |
47 |
import java.awt.event.ActionListener; |
48 |
import java.awt.event.KeyEvent; |
49 |
import java.awt.event.KeyListener; |
50 |
import java.text.DecimalFormat; |
51 |
import java.text.DecimalFormatSymbols; |
52 |
import java.util.ArrayList; |
53 |
import java.util.List; |
54 |
|
55 |
import javax.swing.JCheckBox; |
56 |
import javax.swing.JComboBox; |
57 |
import javax.swing.JLabel; |
58 |
import javax.swing.JPanel; |
59 |
import javax.swing.JScrollPane; |
60 |
import javax.swing.JTextArea; |
61 |
import javax.swing.JTextField; |
62 |
|
63 |
import org.slf4j.Logger; |
64 |
import org.slf4j.LoggerFactory; |
65 |
|
66 |
import org.gvsig.andami.PluginServices; |
67 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
68 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor; |
69 |
import org.gvsig.gui.beans.swing.JButton; |
70 |
import org.gvsig.tools.service.ServiceException; |
71 |
|
72 |
|
73 |
|
74 |
/**
|
75 |
* Utility class that holds a single table settings controls.
|
76 |
*
|
77 |
* @author jldominguez
|
78 |
*
|
79 |
*/
|
80 |
public class UserTableSettingsPanel extends JPanel implements ActionListener, |
81 |
KeyListener {
|
82 |
|
83 |
private static final long serialVersionUID = -9205704982299200912L; |
84 |
|
85 |
private static Logger LOG = LoggerFactory |
86 |
.getLogger(UserTableSettingsPanel.class); |
87 |
|
88 |
private FieldComboItem[] ids; |
89 |
private String initLayerName = ""; |
90 |
private JComboBox idComboBox = null; |
91 |
private JTextArea sqlTextArea = null; |
92 |
private JLabel idLabel = null; |
93 |
private JLabel sqlLabel = null; |
94 |
private JCheckBox activateSQLCheckBox = null; |
95 |
protected JLabel tableNamejLabel = null; |
96 |
private JTextField layerNameTextField = null; |
97 |
private JScrollPane sqlTextAreaScroll = null; |
98 |
protected WizardDB parent = null; |
99 |
private JButton advanzedButton; |
100 |
protected DBStoreParameters parameters;
|
101 |
|
102 |
protected UserTableSettingsPanel() {
|
103 |
super();
|
104 |
} |
105 |
|
106 |
protected void setInitValues(FieldComboItem[] idComboItems, |
107 |
String initialLayerName, boolean empty, WizardDB _p,DBStoreParameters parameters) { |
108 |
parent = _p; |
109 |
|
110 |
initLayerName = initialLayerName; |
111 |
ids = idComboItems; |
112 |
this.parameters = parameters;
|
113 |
|
114 |
} |
115 |
|
116 |
public UserTableSettingsPanel(FieldComboItem[] idComboItems, |
117 |
String initialLayerName, boolean empty, WizardDB _p, |
118 |
DBStoreParameters parameters) { |
119 |
setInitValues(idComboItems, initialLayerName, empty, _p, parameters); |
120 |
initialize(empty); |
121 |
} |
122 |
|
123 |
public boolean hasValidValues() { |
124 |
if (!combosHaveItems()) {
|
125 |
return false; |
126 |
} |
127 |
|
128 |
if ((activateSQLCheckBox.isSelected()) &&
|
129 |
(getSqlTextArea().getText().trim().length() == 0)) {
|
130 |
return false; |
131 |
} |
132 |
|
133 |
if (getLayerNameTextField().getText().trim().length() == 0) { |
134 |
return false; |
135 |
} |
136 |
|
137 |
return true; |
138 |
} |
139 |
|
140 |
protected void initialize(boolean _empty) { |
141 |
tableNamejLabel = new JLabel(); |
142 |
tableNamejLabel.setText(PluginServices.getText(this, "name")); |
143 |
tableNamejLabel.setSize(new java.awt.Dimension(86, 21)); |
144 |
tableNamejLabel.setLocation(new java.awt.Point(5, 25)); |
145 |
sqlLabel = new JLabel(); |
146 |
// sqlLabel.setBounds(new java.awt.Rectangle(30, 90, 116, 21));
|
147 |
sqlLabel.setBounds(new java.awt.Rectangle(30, 55, 116, 21)); |
148 |
sqlLabel.setText(PluginServices.getText(this, "sql_restriction")); |
149 |
idLabel = new JLabel(); |
150 |
// idLabel.setBounds(new java.awt.Rectangle(5, 55, 86, 21));
|
151 |
idLabel.setBounds(new java.awt.Rectangle(260, 25, 86, 21)); |
152 |
idLabel.setText(PluginServices.getText(this, "id_field")); |
153 |
|
154 |
setLayout(null);
|
155 |
setBounds(new java.awt.Rectangle(3, 225, 501, 246)); |
156 |
setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
157 |
PluginServices.getText(this, "specify_table_settings"), |
158 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
159 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
160 |
add(getIdComboBox(), null);
|
161 |
add(getSqlTextAreaScroll(), null);
|
162 |
add(idLabel, null);
|
163 |
add(sqlLabel, null);
|
164 |
add(getActivateSQLCheckBox(), null);
|
165 |
add(getLayerNameTextField(), null);
|
166 |
add(tableNamejLabel, null);
|
167 |
add(getAdvancedButton(), null);
|
168 |
|
169 |
loadValues(_empty); |
170 |
} |
171 |
|
172 |
public void enableAlphaControls(boolean enable) { |
173 |
getIdComboBox().setEnabled(enable); |
174 |
getLayerNameTextField().setEnabled(enable); |
175 |
getSqlTextArea().setEnabled(enable); |
176 |
getActivateSQLCheckBox().setEnabled(enable); |
177 |
getAdvancedButton().setEnabled(enable); |
178 |
} |
179 |
|
180 |
public void enableSpatialControls(boolean enable) { |
181 |
|
182 |
} |
183 |
|
184 |
public void loadValues() { |
185 |
loadValues(false);
|
186 |
} |
187 |
|
188 |
protected void loadValues(boolean is_empty) { |
189 |
if (is_empty) {
|
190 |
enableAlphaControls(false);
|
191 |
enableSpatialControls(false);
|
192 |
getLayerNameTextField().setText("");
|
193 |
getActivateSQLCheckBox().setSelected(false);
|
194 |
} |
195 |
else {
|
196 |
enableAlphaControls(true);
|
197 |
enableSpatialControls(true);
|
198 |
getActivateSQLCheckBox().setEnabled(true);
|
199 |
getIdComboBox().removeAllItems(); |
200 |
|
201 |
for (int i = 0; i < ids.length; i++) { |
202 |
getIdComboBox().addItem(ids[i]); |
203 |
} |
204 |
|
205 |
|
206 |
getLayerNameTextField().setText(initLayerName); |
207 |
|
208 |
} |
209 |
} |
210 |
|
211 |
private JComboBox getIdComboBox() { |
212 |
if (idComboBox == null) { |
213 |
idComboBox = new JComboBox(); |
214 |
|
215 |
// idComboBox.setBounds(new java.awt.Rectangle(105, 55, 126, 21));
|
216 |
idComboBox.setBounds(new java.awt.Rectangle(351, 25, 134, 21)); |
217 |
} |
218 |
|
219 |
return idComboBox;
|
220 |
} |
221 |
|
222 |
private JButton getAdvancedButton() { |
223 |
if (advanzedButton == null) { |
224 |
advanzedButton = new JButton(); |
225 |
advanzedButton.setLocation(new Point(350, 110)); |
226 |
advanzedButton.setText(PluginServices.getText(this,
|
227 |
"advanced_properties"));
|
228 |
advanzedButton.addActionListener(this);
|
229 |
} |
230 |
return advanzedButton;
|
231 |
} |
232 |
|
233 |
private JCheckBox getActivateSQLCheckBox() { |
234 |
if (activateSQLCheckBox == null) { |
235 |
activateSQLCheckBox = new JCheckBox(); |
236 |
activateSQLCheckBox.addActionListener(this);
|
237 |
//activateSQLCheckBox
|
238 |
//.setBounds(new java.awt.Rectangle(5, 90, 21, 21));
|
239 |
activateSQLCheckBox |
240 |
.setBounds(new java.awt.Rectangle(5, 55, 21, 21)); |
241 |
} |
242 |
|
243 |
return activateSQLCheckBox;
|
244 |
} |
245 |
|
246 |
private JTextField getLayerNameTextField() { |
247 |
if (layerNameTextField == null) { |
248 |
layerNameTextField = new JTextField(); |
249 |
layerNameTextField.setSize(new java.awt.Dimension(118, 21)); |
250 |
// layerNameTextField.setLocation(new java.awt.Point(105, 25));
|
251 |
layerNameTextField.setLocation(new java.awt.Point(120, 25)); |
252 |
layerNameTextField.addKeyListener(this);
|
253 |
} |
254 |
|
255 |
return layerNameTextField;
|
256 |
} |
257 |
|
258 |
private JTextArea getSqlTextArea() { |
259 |
if (sqlTextArea == null) { |
260 |
sqlTextArea = new JTextArea(); |
261 |
sqlTextArea.setLineWrap(true);
|
262 |
sqlTextArea.setWrapStyleWord(true);
|
263 |
sqlTextArea.addKeyListener(this);
|
264 |
|
265 |
// sqlTextArea.setBounds(new java.awt.Rectangle(160,90,326,41));
|
266 |
} |
267 |
|
268 |
return sqlTextArea;
|
269 |
} |
270 |
|
271 |
private JScrollPane getSqlTextAreaScroll() { |
272 |
if (sqlTextAreaScroll == null) { |
273 |
sqlTextAreaScroll = new JScrollPane(); |
274 |
// sqlTextAreaScroll.setBounds(new java.awt.Rectangle(160, 90, 326,
|
275 |
// 41));
|
276 |
sqlTextAreaScroll |
277 |
.setBounds(new java.awt.Rectangle(160, 55, 326, 41)); |
278 |
sqlTextAreaScroll.setViewportView(getSqlTextArea()); |
279 |
sqlTextAreaScroll.updateUI(); |
280 |
} |
281 |
|
282 |
return sqlTextAreaScroll;
|
283 |
} |
284 |
|
285 |
public void actionPerformed(ActionEvent e) { |
286 |
Object src = e.getSource();
|
287 |
|
288 |
if (src == activateSQLCheckBox) {
|
289 |
enableSQLSettings(activateSQLCheckBox.isSelected()); |
290 |
parent.checkFinishable(); |
291 |
} else if (src == advanzedButton) { |
292 |
List<String> toHide = new ArrayList<String>(); |
293 |
toHide.add(DBStoreParameters.PASSWORD_PARAMTER_NAME); |
294 |
toHide.add(DBStoreParameters.HOST_PARAMTER_NAME); |
295 |
toHide.add(DBStoreParameters.PORT_PARAMTER_NAME); |
296 |
toHide.add(DBStoreParameters.USER_PARAMTER_NAME); |
297 |
toHide.add(DBStoreParameters.DBNAME_PARAMTER_NAME); |
298 |
toHide.add(DBStoreParameters.DEFAULTGEOMETRY_PARAMTER_NAME); |
299 |
toHide.add(DBStoreParameters.PKFIELDS_PARAMTER_NAME); |
300 |
toHide.add(DBStoreParameters.FIELDS_PARAMTER_NAME); |
301 |
toHide.add(DBStoreParameters.BASEFILTER_PARAMTER_NAME); |
302 |
toHide.add(DBStoreParameters.WORKINGAREA_PARAMTER_NAME); |
303 |
toHide.add(DBStoreParameters.TABLE_PARAMTER_NAME); |
304 |
toHide.add(DBStoreParameters.CRS_PARAMTER_NAME); |
305 |
try {
|
306 |
parameters.validate(); |
307 |
} catch (Exception ex) { |
308 |
// ignore... only for fill default values
|
309 |
} |
310 |
try {
|
311 |
DynObjectEditor editor = new DynObjectEditor(parameters);
|
312 |
editor.editObject(true);
|
313 |
} catch (ServiceException ex) {
|
314 |
LOG.error( |
315 |
"Error creating a Swing component for the DynObject: "
|
316 |
+ parameters, ex); |
317 |
} |
318 |
|
319 |
|
320 |
return;
|
321 |
|
322 |
} |
323 |
|
324 |
} |
325 |
|
326 |
|
327 |
private void enableSQLSettings(boolean b) { |
328 |
sqlTextArea.setEnabled(b); |
329 |
} |
330 |
|
331 |
protected String getFormattedDouble(double d) { |
332 |
DecimalFormat df = new DecimalFormat("#.###"); |
333 |
DecimalFormatSymbols dfs = new DecimalFormatSymbols(); |
334 |
dfs.setDecimalSeparator('.');
|
335 |
df.setDecimalFormatSymbols(dfs); |
336 |
return df.format(d);
|
337 |
} |
338 |
|
339 |
public void keyPressed(KeyEvent e) { |
340 |
} |
341 |
|
342 |
public void keyReleased(KeyEvent e) { |
343 |
parent.checkFinishable(); |
344 |
} |
345 |
|
346 |
public void keyTyped(KeyEvent e) { |
347 |
} |
348 |
|
349 |
|
350 |
public String getUserLayerName() { |
351 |
return getLayerNameTextField().getText();
|
352 |
} |
353 |
|
354 |
public boolean combosHaveItems() { |
355 |
if (getIdComboBox().getItemCount() == 0) { |
356 |
return false; |
357 |
} |
358 |
|
359 |
return true; |
360 |
} |
361 |
|
362 |
public void repaint() { |
363 |
super.repaint();
|
364 |
getIdComboBox().updateUI(); |
365 |
} |
366 |
|
367 |
public String getIdFieldName() { |
368 |
return getIdComboBox().getSelectedItem().toString();
|
369 |
} |
370 |
|
371 |
public String getWhereClause() { |
372 |
return getSqlTextArea().getText();
|
373 |
} |
374 |
|
375 |
public boolean isSqlActive() { |
376 |
return getActivateSQLCheckBox().isSelected();
|
377 |
} |
378 |
} |