svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / project / documents / table / gui / CreateNewAttributePanel.java @ 44103
History | View | Annotate | Download (24.8 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.table.gui; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.GridLayout; |
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
import java.awt.event.KeyEvent; |
33 |
import java.awt.event.KeyListener; |
34 |
import java.text.ParseException; |
35 |
import javax.swing.ButtonGroup; |
36 |
import javax.swing.JButton; |
37 |
|
38 |
import javax.swing.JComboBox; |
39 |
import javax.swing.JLabel; |
40 |
import javax.swing.JOptionPane; |
41 |
import javax.swing.JPanel; |
42 |
import javax.swing.JRadioButton; |
43 |
import javax.swing.JTextField; |
44 |
|
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.andami.messages.NotificationManager; |
47 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
48 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
49 |
import org.gvsig.app.ApplicationLocator; |
50 |
import org.gvsig.app.ApplicationManager; |
51 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
52 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
53 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
54 |
import org.gvsig.expressionevaluator.swing.Element; |
55 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
56 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
57 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
58 |
import org.gvsig.fmap.dal.DALLocator; |
59 |
import org.gvsig.fmap.dal.DataManager; |
60 |
import org.gvsig.fmap.dal.DataTypes; |
61 |
import org.gvsig.fmap.dal.exception.DataException; |
62 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
63 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
64 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
65 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
66 |
import org.gvsig.fmap.dal.feature.Feature; |
67 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
68 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
69 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
70 |
import org.gvsig.i18n.Messages; |
71 |
import org.gvsig.tools.ToolsLocator; |
72 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
73 |
import org.gvsig.tools.i18n.I18nManager; |
74 |
|
75 |
/**
|
76 |
* To create new FeatureAttributeDescriptor from the interface.
|
77 |
*
|
78 |
* @author Vicente Caballero Navarro
|
79 |
*
|
80 |
*/
|
81 |
public class CreateNewAttributePanel extends JPanel implements IWindow, ActionListener { |
82 |
|
83 |
/**
|
84 |
*
|
85 |
*/
|
86 |
private static final long serialVersionUID = 6447641307779709964L; |
87 |
private static final String DEFAULT_FIELD_LENGTH = "50"; |
88 |
private JLabel jLblFieldName = null; |
89 |
private JTextField jTxtFieldName = null; |
90 |
private JLabel jLblFieldType = null; |
91 |
private JComboBox jCboFieldType = null; |
92 |
private JLabel jLblFieldLength = null; |
93 |
private JTextField jTxtFieldLength = null; |
94 |
private JLabel jLblFieldPrecision = null; |
95 |
private JTextField jTxtFieldPrecision = null; |
96 |
private JLabel jLblDefaultValue = null; |
97 |
private JTextField jTxtDefaultValue = null; |
98 |
private JLabel jLblExpression = null; |
99 |
private JTextField jTxtExpression = null; |
100 |
private JRadioButton jRdbFieldReal = null; |
101 |
private JRadioButton jRdbFieldVirtual = null; |
102 |
private JButton jBtnExpression = null; |
103 |
private WindowInfo viewInfo;
|
104 |
private JPanel jPanel = null; |
105 |
private AcceptCancelPanel jPanelOkCancel = null; |
106 |
private JPanel jPnlFields = null; |
107 |
private int maxAttributeNameSize=-1; |
108 |
private KeyListener checkInt = new KeyListener() { |
109 |
|
110 |
public void keyPressed(KeyEvent e) { |
111 |
// do nothing
|
112 |
} |
113 |
|
114 |
public void keyReleased(KeyEvent e) { |
115 |
JTextField component = (JTextField) e.getComponent(); |
116 |
|
117 |
try {
|
118 |
component.setText(String.valueOf(Integer.parseInt(component |
119 |
.getText()))); |
120 |
|
121 |
} catch (Exception ex) { |
122 |
String text = component.getText();
|
123 |
text = |
124 |
(text.length() <= 1) ? "0" : text.substring(0, |
125 |
text.length() - 1);
|
126 |
component.setText(text); |
127 |
} |
128 |
} |
129 |
|
130 |
public void keyTyped(KeyEvent e) { |
131 |
// do nothing
|
132 |
} |
133 |
}; |
134 |
private String[] currentFieldNames; |
135 |
private ExpressionPickerController expressionPicker;
|
136 |
private FeatureStore store;
|
137 |
|
138 |
// public CreateNewAttributePanel() {
|
139 |
// super();
|
140 |
// initialize();
|
141 |
// }
|
142 |
|
143 |
public CreateNewAttributePanel(FeatureStore store) {
|
144 |
super();
|
145 |
this.store = store;
|
146 |
initialize(); |
147 |
} |
148 |
|
149 |
// public CreateNewAttributePanel(boolean isDoubleBuffered) {
|
150 |
// super(isDoubleBuffered);
|
151 |
// initialize();
|
152 |
// }
|
153 |
//
|
154 |
// public CreateNewAttributePanel(LayoutManager layout) {
|
155 |
// super(layout);
|
156 |
// initialize();
|
157 |
// }
|
158 |
//
|
159 |
// public CreateNewAttributePanel(LayoutManager layout,
|
160 |
// boolean isDoubleBuffered) {
|
161 |
// super(layout, isDoubleBuffered);
|
162 |
// initialize();
|
163 |
// }
|
164 |
|
165 |
public WindowInfo getWindowInfo() {
|
166 |
if (viewInfo == null) { |
167 |
viewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
168 |
viewInfo.setWidth(this.getWidth() + 8); |
169 |
viewInfo.setHeight(this.getHeight());
|
170 |
viewInfo.setTitle(PluginServices.getText(this,
|
171 |
"new_field_properties"));
|
172 |
} |
173 |
return viewInfo;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* This method initializes this
|
178 |
*
|
179 |
* @return void
|
180 |
*/
|
181 |
private void initialize() { |
182 |
this.setLayout(new BorderLayout()); |
183 |
this.setSize(300, 310); |
184 |
this.setPreferredSize(new java.awt.Dimension(300, 310)); |
185 |
this.add(getJPanel(), java.awt.BorderLayout.CENTER);
|
186 |
this.add(getJPanelOkCancel(), java.awt.BorderLayout.SOUTH);
|
187 |
|
188 |
jBtnExpression.setText("");
|
189 |
ExpressionEvaluatorSwingManager manager = ExpressionEvaluatorSwingLocator.getManager(); |
190 |
this.expressionPicker = manager.createExpressionPickerController(jTxtExpression, jBtnExpression);
|
191 |
if( this.store != null ) { |
192 |
Element element = manager.createElement(
|
193 |
DataSwingManager.FEATURE_STORE_EXPRESSION_ELEMENT, |
194 |
this.expressionPicker,
|
195 |
this.store
|
196 |
); |
197 |
if( element != null ) { |
198 |
this.expressionPicker.addElement(element);
|
199 |
} |
200 |
Feature sampleFeature = null;
|
201 |
try {
|
202 |
sampleFeature = store.getFeatureSelection().first(); |
203 |
if( sampleFeature == null ) { |
204 |
sampleFeature = store.first(); |
205 |
} |
206 |
} catch (DataException ex) {
|
207 |
} |
208 |
if( sampleFeature!=null ) { |
209 |
FeatureSymbolTable featureSymbolTable = DALLocator.getDataManager() |
210 |
.createFeatureSymbolTable(); |
211 |
featureSymbolTable.setFeature(sampleFeature); |
212 |
this.expressionPicker.setPreviewSymbolTable(
|
213 |
featureSymbolTable.createParent() |
214 |
); |
215 |
} |
216 |
|
217 |
} |
218 |
} |
219 |
|
220 |
/**
|
221 |
* This method initializes jTxtFieldName
|
222 |
*
|
223 |
* @return javax.swing.JTextField
|
224 |
*/
|
225 |
private JTextField getJTxtFieldName() { |
226 |
if (jTxtFieldName == null) { |
227 |
jTxtFieldName = new JTextField(); |
228 |
jTxtFieldName.setBounds(new java.awt.Rectangle(147, 15, 138, 22)); |
229 |
} |
230 |
return jTxtFieldName;
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* This method initializes jCboFieldType
|
235 |
*
|
236 |
* @return javax.swing.JComboBox
|
237 |
*/
|
238 |
private JComboBox getJCboFieldType() { |
239 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
240 |
if (jCboFieldType == null) { |
241 |
jCboFieldType = new JComboBox(); |
242 |
jCboFieldType.setBounds(new java.awt.Rectangle(147, 52, 138, 22)); |
243 |
jCboFieldType.addItem(manager.getTypeName(DataTypes.BOOLEAN)); |
244 |
jCboFieldType.addItem(manager.getTypeName(DataTypes.DATE)); |
245 |
jCboFieldType.addItem(manager.getTypeName(DataTypes.INT)); |
246 |
jCboFieldType.addItem(manager.getTypeName(DataTypes.DOUBLE)); |
247 |
jCboFieldType.addItem(manager.getTypeName(DataTypes.STRING)); |
248 |
|
249 |
jCboFieldType.setSelectedIndex(4);
|
250 |
jCboFieldType |
251 |
.addActionListener(new java.awt.event.ActionListener() {
|
252 |
|
253 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
254 |
DataTypesManager manager = |
255 |
ToolsLocator.getDataTypesManager(); |
256 |
String strType =
|
257 |
(String) getJCboFieldType().getModel()
|
258 |
.getSelectedItem(); |
259 |
if (strType == manager.getTypeName(DataTypes.DOUBLE)) {
|
260 |
getJTxtFieldPrecision().setEnabled(true);
|
261 |
if (getJTxtFieldPrecision().getText().equals("")) { |
262 |
getJTxtFieldPrecision().setText("3");
|
263 |
} else {
|
264 |
try {
|
265 |
Integer.parseInt(getJTxtFieldPrecision()
|
266 |
.getText()); |
267 |
} catch (NumberFormatException e1) { |
268 |
getJTxtFieldPrecision().setText("3");
|
269 |
} |
270 |
} |
271 |
} else {
|
272 |
getJTxtFieldPrecision().setEnabled(false);
|
273 |
} |
274 |
if (strType == manager.getTypeName(DataTypes.BOOLEAN)) {
|
275 |
getJTxtFieldLength().setText("0");
|
276 |
getJTxtFieldLength().setEnabled(false);
|
277 |
} else {
|
278 |
getJTxtFieldLength().setEnabled(true);
|
279 |
} |
280 |
|
281 |
} |
282 |
}); |
283 |
|
284 |
} |
285 |
return jCboFieldType;
|
286 |
} |
287 |
|
288 |
/**
|
289 |
* This method initializes jTxtFieldLength
|
290 |
*
|
291 |
* @return javax.swing.JTextField
|
292 |
*/
|
293 |
private JTextField getJTxtFieldLength() { |
294 |
if (jTxtFieldLength == null) { |
295 |
jTxtFieldLength = new JTextField(); |
296 |
jTxtFieldLength.setBounds(new java.awt.Rectangle(147, 89, 138, 22)); |
297 |
jTxtFieldLength.setText(DEFAULT_FIELD_LENGTH); |
298 |
jTxtFieldLength.addKeyListener(checkInt); |
299 |
} |
300 |
return jTxtFieldLength;
|
301 |
} |
302 |
|
303 |
/**
|
304 |
* This method initializes jTxtFieldPrecision
|
305 |
*
|
306 |
* @return javax.swing.JTextField
|
307 |
*/
|
308 |
private JTextField getJTxtFieldPrecision() { |
309 |
if (jTxtFieldPrecision == null) { |
310 |
jTxtFieldPrecision = new JTextField(); |
311 |
jTxtFieldPrecision.setBounds(new java.awt.Rectangle(147, 126, 138, |
312 |
22));
|
313 |
jTxtFieldPrecision.setEnabled(false);
|
314 |
jTxtFieldPrecision.addKeyListener(checkInt); |
315 |
} |
316 |
return jTxtFieldPrecision;
|
317 |
} |
318 |
|
319 |
/**
|
320 |
* This method initializes jTxtDefaultValue
|
321 |
*
|
322 |
* @return javax.swing.JTextField
|
323 |
*/
|
324 |
private JTextField getJTxtDefaultValue() { |
325 |
if (jTxtDefaultValue == null) { |
326 |
jTxtDefaultValue = new JTextField(); |
327 |
jTxtDefaultValue |
328 |
.setBounds(new java.awt.Rectangle(147, 200, 138, 22)); |
329 |
} |
330 |
return jTxtDefaultValue;
|
331 |
} |
332 |
|
333 |
public EditableFeatureAttributeDescriptor loadFieldDescription(
|
334 |
EditableFeatureType featureType) throws ParseException { |
335 |
String nameAttr = ""; |
336 |
int typeAttr = DataTypes.STRING;
|
337 |
int sizeAttr = 0; |
338 |
int precisionAttr = 0; |
339 |
Object defaultValueAttr = ""; |
340 |
|
341 |
nameAttr = getJTxtFieldName().getText(); |
342 |
|
343 |
if (nameAttr == null || nameAttr.length() == 0) { |
344 |
|
345 |
JOptionPane.showMessageDialog(
|
346 |
this,
|
347 |
Messages.getText("_No_input_name"),
|
348 |
Messages.getText("_Rename_column"),
|
349 |
JOptionPane.ERROR_MESSAGE);
|
350 |
return null; |
351 |
} |
352 |
|
353 |
if (maxAttributeNameSize>0){ |
354 |
if (nameAttr.length()>maxAttributeNameSize){
|
355 |
JOptionPane.showMessageDialog(
|
356 |
this,
|
357 |
Messages.getText("_Name_too_long"),
|
358 |
Messages.getText("_Rename_column"),
|
359 |
JOptionPane.ERROR_MESSAGE);
|
360 |
return null; |
361 |
} |
362 |
} |
363 |
|
364 |
String strType =
|
365 |
(String) getJCboFieldType().getModel().getSelectedItem();
|
366 |
typeAttr = ToolsLocator.getDataTypesManager().getType(strType); |
367 |
try {
|
368 |
int fieldLength = Integer.parseInt(getJTxtFieldLength().getText()); |
369 |
sizeAttr = fieldLength; |
370 |
} catch (Exception e) { |
371 |
throw new ParseException(e.getMessage(), 0); |
372 |
} |
373 |
|
374 |
if (typeAttr == DataTypes.DOUBLE) {
|
375 |
try {
|
376 |
precisionAttr = |
377 |
Integer.parseInt(getJTxtFieldPrecision().getText());
|
378 |
} catch (NumberFormatException e) { |
379 |
precisionAttr = 3;
|
380 |
} |
381 |
} |
382 |
|
383 |
if (featureType.getIndex(nameAttr) != -1) { |
384 |
NotificationManager.showMessageInfo( |
385 |
PluginServices.getText(this, "field_already_exists"), null); |
386 |
return null; |
387 |
} |
388 |
EditableFeatureAttributeDescriptor ead = null;
|
389 |
if (getJRdbFieldVirtual().isSelected()) {
|
390 |
FeatureAttributeEmulatorExpression myEmulated = DALLocator.getDataManager().createFeatureAttributeEmulatorExpression( |
391 |
featureType, |
392 |
this.expressionPicker.get()
|
393 |
); |
394 |
if (!myEmulated.isValid()) {
|
395 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
396 |
ApplicationManager application = ApplicationLocator.getManager(); |
397 |
int x = application.confirmDialog(
|
398 |
"The expression used in this field is not valid."+
|
399 |
"\n\n"+
|
400 |
myEmulated.getErrorMessage()+ |
401 |
"\n\n"+
|
402 |
"Do you want add this field anyway?",
|
403 |
"Add invalid field",
|
404 |
JOptionPane.YES_NO_OPTION,
|
405 |
JOptionPane.QUESTION_MESSAGE,
|
406 |
"_AddingInvalidField.DoYouWantAddAnyway");
|
407 |
if (x==JOptionPane.YES_OPTION) { |
408 |
ead = featureType.add(nameAttr, typeAttr, myEmulated) |
409 |
.setSize(sizeAttr); |
410 |
} |
411 |
} else {
|
412 |
ead = featureType.add(nameAttr, typeAttr, myEmulated) |
413 |
.setSize(sizeAttr); |
414 |
} |
415 |
} else {
|
416 |
defaultValueAttr = getJTxtDefaultValue().getText(); |
417 |
if (defaultValueAttr.equals("")) { |
418 |
defaultValueAttr = null;
|
419 |
} |
420 |
ead = featureType.add(nameAttr, typeAttr, sizeAttr); |
421 |
ead.setPrecision(precisionAttr); |
422 |
ead.setDefaultValue(defaultValueAttr); |
423 |
} |
424 |
|
425 |
return ead;
|
426 |
} |
427 |
|
428 |
public void setOkAction(ActionListener okAction) { |
429 |
getJPanelOkCancel().setOkButtonActionListener(okAction); |
430 |
|
431 |
} |
432 |
|
433 |
/**
|
434 |
* This method initializes jPanel
|
435 |
*
|
436 |
* @return javax.swing.JPanel
|
437 |
*/
|
438 |
private JPanel getJPanel() { |
439 |
if (jPanel == null) { |
440 |
jPanel = new JPanel(); |
441 |
jPanel.setLayout(null);
|
442 |
|
443 |
jPanel.add(getJPnlFields(), null);
|
444 |
} |
445 |
return jPanel;
|
446 |
} |
447 |
|
448 |
/**
|
449 |
* This method initializes jPanelOkCancel
|
450 |
*
|
451 |
* @return javax.swing.JPanel
|
452 |
*/
|
453 |
private AcceptCancelPanel getJPanelOkCancel() {
|
454 |
if (jPanelOkCancel == null) { |
455 |
jPanelOkCancel = new AcceptCancelPanel();
|
456 |
jPanelOkCancel.setCancelButtonActionListener(new ActionListener() { |
457 |
|
458 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
459 |
PluginServices.getMDIManager().closeWindow( |
460 |
CreateNewAttributePanel.this); |
461 |
} |
462 |
}); |
463 |
jPanelOkCancel.setPreferredSize(new java.awt.Dimension(10, 50)); |
464 |
} |
465 |
return jPanelOkCancel;
|
466 |
} |
467 |
|
468 |
/**
|
469 |
* This method initializes jPnlFields
|
470 |
*
|
471 |
* @return javax.swing.JPanel
|
472 |
*/
|
473 |
private JPanel getJPnlFields() { |
474 |
if (jPnlFields == null) { |
475 |
GridLayout gridLayout = new GridLayout(); |
476 |
gridLayout.setRows(8);
|
477 |
gridLayout.setVgap(3);
|
478 |
gridLayout.setHgap(5);
|
479 |
gridLayout.setColumns(2);
|
480 |
jPnlFields = new JPanel(); |
481 |
jPnlFields.setLayout(gridLayout); |
482 |
jPnlFields.setBounds(new java.awt.Rectangle(5, 12, 290, 200)); |
483 |
// jLblFieldReal = new JLabel();
|
484 |
// jLblFieldReal.setBounds(14, 237, 125, 22);
|
485 |
// jLblFieldReal.setText(PluginServices.getText(this,
|
486 |
// "default_value"));
|
487 |
// jLblEmulated = new JLabel();
|
488 |
// jLblEmulated
|
489 |
// .setBounds(new java.awt.Rectangle(14, 200, 125, 22));
|
490 |
// jLblEmulated.setText(PluginServices.getText(this,
|
491 |
// "emulated"));
|
492 |
jLblExpression = new JLabel(); |
493 |
jLblExpression |
494 |
.setBounds(new java.awt.Rectangle(14, 272, 125, 22)); |
495 |
jLblExpression.setText(PluginServices.getText(this,
|
496 |
"expression"));
|
497 |
jLblDefaultValue = new JLabel(); |
498 |
jLblDefaultValue |
499 |
.setBounds(new java.awt.Rectangle(14, 200, 125, 22)); |
500 |
jLblDefaultValue.setText(PluginServices.getText(this,
|
501 |
"default_value"));
|
502 |
jLblFieldPrecision = new JLabel(); |
503 |
jLblFieldPrecision.setBounds(new java.awt.Rectangle(14, 126, 112, |
504 |
22));
|
505 |
jLblFieldPrecision.setText(PluginServices |
506 |
.getText(this, "precision")); |
507 |
jLblFieldLength = new JLabel(); |
508 |
jLblFieldLength.setBounds(new java.awt.Rectangle(14, 89, 99, 22)); |
509 |
jLblFieldLength.setText(PluginServices |
510 |
.getText(this, "field_length")); |
511 |
jLblFieldType = new JLabel(); |
512 |
jLblFieldType.setBounds(new java.awt.Rectangle(14, 52, 94, 22)); |
513 |
jLblFieldType.setText(PluginServices.getText(this, "field_type")); |
514 |
jLblFieldName = new JLabel(); |
515 |
jLblFieldName.setText(PluginServices.getText(this, "field_name")); |
516 |
jLblFieldName.setBounds(new java.awt.Rectangle(14, 15, 99, 22)); |
517 |
jPnlFields.add(jLblFieldName, null);
|
518 |
jPnlFields.add(getJTxtFieldName(), null);
|
519 |
jPnlFields.add(jLblFieldType, null);
|
520 |
jPnlFields.add(getJCboFieldType(), null);
|
521 |
jPnlFields.add(jLblFieldLength, null);
|
522 |
jPnlFields.add(getJTxtFieldLength(), null);
|
523 |
jPnlFields.add(jLblFieldPrecision, null);
|
524 |
jPnlFields.add(getJTxtFieldPrecision(), null);
|
525 |
|
526 |
|
527 |
|
528 |
jPnlFields.add(getJRdbFieldReal(), null);
|
529 |
jRdbFieldReal.addActionListener(this);
|
530 |
jPnlFields.add(new JLabel(), null); |
531 |
//JPanel panelReal = new JPanel();
|
532 |
jPnlFields.add(jLblDefaultValue, null);
|
533 |
jPnlFields.add(getJTxtDefaultValue(), null);
|
534 |
//jPnlFields.add(panelReal);
|
535 |
|
536 |
jPnlFields.add(getJRdbFieldVirtual(), null);
|
537 |
jRdbFieldVirtual.addActionListener(this);
|
538 |
|
539 |
jPnlFields.add(new JLabel(), null); |
540 |
jPnlFields.add(jLblExpression, null);
|
541 |
JPanel panelVirtual = new JPanel(); |
542 |
// panelVirtual.setLayout(new GridLayout(1, 2));
|
543 |
GridBagLayout grid = new GridBagLayout(); |
544 |
GridBagConstraints gbc = new GridBagConstraints(); |
545 |
gbc.gridx = 0;
|
546 |
gbc.gridy = 0;
|
547 |
gbc.gridwidth = 3;
|
548 |
gbc.gridheight = 1;
|
549 |
gbc.weightx = 1.0;
|
550 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
551 |
panelVirtual.setLayout(grid); |
552 |
|
553 |
panelVirtual.add(getJTxtExpression(), gbc); |
554 |
gbc.gridx = 4;
|
555 |
gbc.gridy = 0;
|
556 |
gbc.gridwidth = 1;
|
557 |
gbc.gridheight = 1;
|
558 |
gbc.weightx = 0.0;
|
559 |
gbc.weighty = 0.0;
|
560 |
gbc.fill = GridBagConstraints.NONE;
|
561 |
panelVirtual.add(getJBtnExpression(), gbc); |
562 |
jPnlFields.add(panelVirtual); |
563 |
|
564 |
//jPnlFields.add(jLblFieldVirtual, null);
|
565 |
ButtonGroup defaultGroup = new ButtonGroup(); |
566 |
defaultGroup.add(jRdbFieldReal); |
567 |
defaultGroup.add(jRdbFieldVirtual); |
568 |
|
569 |
// init visible
|
570 |
jLblDefaultValue.setEnabled(true);
|
571 |
jTxtDefaultValue.setEnabled(true);
|
572 |
jLblExpression.setEnabled(false);
|
573 |
jTxtExpression.setEnabled(false);
|
574 |
jBtnExpression.setEnabled(false);
|
575 |
|
576 |
} |
577 |
return jPnlFields;
|
578 |
} |
579 |
|
580 |
public void setCurrentFieldNames(String[] fieldNames) { |
581 |
currentFieldNames = fieldNames; |
582 |
String newField =
|
583 |
PluginServices.getText(this, "field").replaceAll(" +", "_"); |
584 |
int index = 0; |
585 |
for (int i = 0; i < currentFieldNames.length; i++) { |
586 |
if (currentFieldNames[i].startsWith(newField)) {
|
587 |
try {
|
588 |
index = |
589 |
Integer.parseInt(currentFieldNames[i].replaceAll(
|
590 |
newField, ""));
|
591 |
} catch (Exception e) { /* we don't care */ |
592 |
} |
593 |
} |
594 |
} |
595 |
jTxtFieldName.setText(newField + (++index)); |
596 |
} |
597 |
|
598 |
public Object getWindowProfile() { |
599 |
return WindowInfo.DIALOG_PROFILE;
|
600 |
} |
601 |
|
602 |
public void setMaxAttributeNameSize(int maxAttributeNameSize) { |
603 |
this.maxAttributeNameSize = maxAttributeNameSize;
|
604 |
} |
605 |
|
606 |
private JTextField getJTxtExpression() { |
607 |
if (jTxtExpression == null) { |
608 |
jTxtExpression = new JTextField(); |
609 |
jTxtExpression.setBounds(new java.awt.Rectangle(147, 200, 125, 22)); |
610 |
jTxtExpression.setColumns(4);
|
611 |
} |
612 |
return jTxtExpression;
|
613 |
} |
614 |
|
615 |
private JRadioButton getJRdbFieldReal() { |
616 |
if (jRdbFieldReal == null) { |
617 |
jRdbFieldReal = new JRadioButton(PluginServices.getText(this, "_Real_field")); //"real_value")); |
618 |
jRdbFieldReal.setBounds(new java.awt.Rectangle(14, 163, 125, 22)); |
619 |
jRdbFieldReal.setSelected(true);
|
620 |
} |
621 |
return jRdbFieldReal;
|
622 |
} |
623 |
private JRadioButton getJRdbFieldVirtual() { |
624 |
if (jRdbFieldVirtual == null) { |
625 |
jRdbFieldVirtual = new JRadioButton(PluginServices.getText(this, "_Virtual_field"));//"virtual_value")); |
626 |
jRdbFieldVirtual.setBounds(new java.awt.Rectangle(14, 237, 125, 22)); |
627 |
} |
628 |
return jRdbFieldVirtual;
|
629 |
} |
630 |
|
631 |
private JButton getJBtnExpression() { |
632 |
if (jBtnExpression == null) { |
633 |
jBtnExpression = new JButton(); |
634 |
jBtnExpression.setText("...");
|
635 |
//jBtnExpression.setBounds(new java.awt.Rectangle(147, 200, 125, 22));
|
636 |
//jBtnExpression.setColumns(4);
|
637 |
} |
638 |
return jBtnExpression;
|
639 |
} |
640 |
@Override
|
641 |
public void actionPerformed(ActionEvent e) { |
642 |
if (e.getSource()==jRdbFieldReal) {
|
643 |
jLblDefaultValue.setEnabled(true);
|
644 |
jTxtDefaultValue.setEnabled(true);
|
645 |
jLblExpression.setEnabled(false);
|
646 |
jTxtExpression.setEnabled(false);
|
647 |
jBtnExpression.setEnabled(false);
|
648 |
|
649 |
} else if (e.getSource()==jRdbFieldVirtual) { |
650 |
jLblDefaultValue.setEnabled(false);
|
651 |
jTxtDefaultValue.setEnabled(false);
|
652 |
jLblExpression.setEnabled(true);
|
653 |
jTxtExpression.setEnabled(true);
|
654 |
jBtnExpression.setEnabled(true);
|
655 |
|
656 |
} |
657 |
} |
658 |
|
659 |
} |