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