Revision 43978 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
CreateNewAttributePanel.java | ||
---|---|---|
24 | 24 |
package org.gvsig.app.project.documents.table.gui; |
25 | 25 |
|
26 | 26 |
import java.awt.BorderLayout; |
27 |
import java.awt.GridBagConstraints; |
|
28 |
import java.awt.GridBagLayout; |
|
27 | 29 |
import java.awt.GridLayout; |
28 | 30 |
import java.awt.LayoutManager; |
31 |
import java.awt.event.ActionEvent; |
|
29 | 32 |
import java.awt.event.ActionListener; |
30 | 33 |
import java.awt.event.KeyEvent; |
31 | 34 |
import java.awt.event.KeyListener; |
32 | 35 |
import java.text.ParseException; |
33 |
import javax.swing.JCheckBox; |
|
36 |
import javax.swing.ButtonGroup; |
|
37 |
import javax.swing.JButton; |
|
34 | 38 |
|
35 | 39 |
import javax.swing.JComboBox; |
36 | 40 |
import javax.swing.JLabel; |
37 | 41 |
import javax.swing.JOptionPane; |
38 | 42 |
import javax.swing.JPanel; |
43 |
import javax.swing.JRadioButton; |
|
39 | 44 |
import javax.swing.JTextField; |
40 | 45 |
|
41 | 46 |
import org.gvsig.andami.PluginServices; |
... | ... | |
45 | 50 |
import org.gvsig.fmap.dal.DataTypes; |
46 | 51 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
47 | 52 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
53 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
54 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
|
48 | 55 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
49 | 56 |
import org.gvsig.i18n.Messages; |
50 | 57 |
import org.gvsig.tools.ToolsLocator; |
... | ... | |
56 | 63 |
* @author Vicente Caballero Navarro |
57 | 64 |
* |
58 | 65 |
*/ |
59 |
public class CreateNewAttributePanel extends JPanel implements IWindow { |
|
66 |
public class CreateNewAttributePanel extends JPanel implements IWindow, ActionListener {
|
|
60 | 67 |
|
61 | 68 |
/** |
62 | 69 |
* |
... | ... | |
73 | 80 |
private JTextField jTxtFieldPrecision = null; |
74 | 81 |
private JLabel jLblDefaultValue = null; |
75 | 82 |
private JTextField jTxtDefaultValue = null; |
76 |
private JLabel jLblEmulated = null; |
|
77 |
private JCheckBox jChbEmulated = null; |
|
83 |
private JLabel jLblExpression = null; |
|
84 |
private JTextField jTxtExpression = null; |
|
85 |
private JRadioButton jRdbFieldReal = null; |
|
86 |
private JRadioButton jRdbFieldVirtual = null; |
|
87 |
private JButton jBtnExpression = null; |
|
78 | 88 |
private WindowInfo viewInfo; |
79 | 89 |
private JPanel jPanel = null; |
80 | 90 |
private AcceptCancelPanel jPanelOkCancel = null; |
... | ... | |
147 | 157 |
*/ |
148 | 158 |
private void initialize() { |
149 | 159 |
this.setLayout(new BorderLayout()); |
150 |
this.setSize(300, 210);
|
|
151 |
this.setPreferredSize(new java.awt.Dimension(300, 210));
|
|
160 |
this.setSize(300, 310);
|
|
161 |
this.setPreferredSize(new java.awt.Dimension(300, 310));
|
|
152 | 162 |
this.add(getJPanel(), java.awt.BorderLayout.CENTER); |
153 | 163 |
this.add(getJPanelOkCancel(), java.awt.BorderLayout.SOUTH); |
154 | 164 |
} |
... | ... | |
261 | 271 |
if (jTxtDefaultValue == null) { |
262 | 272 |
jTxtDefaultValue = new JTextField(); |
263 | 273 |
jTxtDefaultValue |
264 |
.setBounds(new java.awt.Rectangle(147, 163, 138, 22));
|
|
274 |
.setBounds(new java.awt.Rectangle(147, 200, 138, 22));
|
|
265 | 275 |
} |
266 | 276 |
return jTxtDefaultValue; |
267 | 277 |
} |
... | ... | |
315 | 325 |
precisionAttr = 3; |
316 | 326 |
} |
317 | 327 |
} |
318 |
defaultValueAttr = getJTxtDefaultValue().getText(); |
|
319 |
if (defaultValueAttr.equals("")) { |
|
320 |
defaultValueAttr = null; |
|
321 |
} |
|
328 |
|
|
322 | 329 |
if (featureType.getIndex(nameAttr) != -1) { |
323 | 330 |
NotificationManager.showMessageInfo( |
324 | 331 |
PluginServices.getText(this, "field_already_exists"), null); |
325 | 332 |
return null; |
326 | 333 |
} |
327 |
EditableFeatureAttributeDescriptor ead = |
|
328 |
featureType.add(nameAttr, typeAttr, sizeAttr); |
|
329 |
ead.setPrecision(precisionAttr); |
|
330 |
ead.setDefaultValue(defaultValueAttr); |
|
334 |
EditableFeatureAttributeDescriptor ead; |
|
335 |
if (getJRdbFieldVirtual().isSelected()) { |
|
336 |
String code = getJTxtExpression().getText(); |
|
337 |
FeatureAttributeDescriptor[] descriptors = |
|
338 |
featureType.getAttributeDescriptors(); |
|
339 |
String[] fields = new String[descriptors.length]; |
|
340 |
for (int i = 0; i < descriptors.length; i++) { |
|
341 |
FeatureAttributeDescriptor descriptor = descriptors[i]; |
|
342 |
fields[i] = descriptor.getName(); |
|
343 |
} |
|
344 |
FeatureAttributeEmulator myEmulated = |
|
345 |
new EmulatedFieldExpression( |
|
346 |
fields, |
|
347 |
code); |
|
348 |
ead = featureType.add(nameAttr, typeAttr, myEmulated) |
|
349 |
.setSize(sizeAttr); |
|
350 |
} else { |
|
351 |
defaultValueAttr = getJTxtDefaultValue().getText(); |
|
352 |
if (defaultValueAttr.equals("")) { |
|
353 |
defaultValueAttr = null; |
|
354 |
} |
|
355 |
ead = featureType.add(nameAttr, typeAttr, sizeAttr); |
|
356 |
ead.setPrecision(precisionAttr); |
|
357 |
ead.setDefaultValue(defaultValueAttr); |
|
358 |
} |
|
359 |
|
|
331 | 360 |
return ead; |
332 | 361 |
} |
333 | 362 |
|
... | ... | |
379 | 408 |
private JPanel getJPnlFields() { |
380 | 409 |
if (jPnlFields == null) { |
381 | 410 |
GridLayout gridLayout = new GridLayout(); |
382 |
gridLayout.setRows(6);
|
|
411 |
gridLayout.setRows(8);
|
|
383 | 412 |
gridLayout.setVgap(3); |
384 | 413 |
gridLayout.setHgap(5); |
385 | 414 |
gridLayout.setColumns(2); |
386 | 415 |
jPnlFields = new JPanel(); |
387 | 416 |
jPnlFields.setLayout(gridLayout); |
388 |
jPnlFields.setBounds(new java.awt.Rectangle(5, 12, 290, 142)); |
|
389 |
jLblEmulated = new JLabel(); |
|
390 |
jLblEmulated |
|
391 |
.setBounds(new java.awt.Rectangle(14, 200, 125, 22)); |
|
392 |
jLblEmulated.setText(PluginServices.getText(this, |
|
393 |
"emulated")); |
|
417 |
jPnlFields.setBounds(new java.awt.Rectangle(5, 12, 290, 200)); |
|
418 |
// jLblFieldReal = new JLabel(); |
|
419 |
// jLblFieldReal.setBounds(14, 237, 125, 22); |
|
420 |
// jLblFieldReal.setText(PluginServices.getText(this, |
|
421 |
// "default_value")); |
|
422 |
// jLblEmulated = new JLabel(); |
|
423 |
// jLblEmulated |
|
424 |
// .setBounds(new java.awt.Rectangle(14, 200, 125, 22)); |
|
425 |
// jLblEmulated.setText(PluginServices.getText(this, |
|
426 |
// "emulated")); |
|
427 |
jLblExpression = new JLabel(); |
|
428 |
jLblExpression |
|
429 |
.setBounds(new java.awt.Rectangle(14, 272, 125, 22)); |
|
430 |
jLblExpression.setText(PluginServices.getText(this, |
|
431 |
"expression")); |
|
394 | 432 |
jLblDefaultValue = new JLabel(); |
395 | 433 |
jLblDefaultValue |
396 |
.setBounds(new java.awt.Rectangle(14, 163, 125, 22));
|
|
434 |
.setBounds(new java.awt.Rectangle(14, 200, 125, 22));
|
|
397 | 435 |
jLblDefaultValue.setText(PluginServices.getText(this, |
398 | 436 |
"default_value")); |
399 | 437 |
jLblFieldPrecision = new JLabel(); |
... | ... | |
419 | 457 |
jPnlFields.add(getJTxtFieldLength(), null); |
420 | 458 |
jPnlFields.add(jLblFieldPrecision, null); |
421 | 459 |
jPnlFields.add(getJTxtFieldPrecision(), null); |
460 |
|
|
461 |
|
|
462 |
|
|
463 |
jPnlFields.add(getJRdbFieldReal(), null); |
|
464 |
jRdbFieldReal.addActionListener(this); |
|
465 |
jPnlFields.add(new JLabel(), null); |
|
466 |
//JPanel panelReal = new JPanel(); |
|
422 | 467 |
jPnlFields.add(jLblDefaultValue, null); |
423 | 468 |
jPnlFields.add(getJTxtDefaultValue(), null); |
424 |
jPnlFields.add(jLblEmulated, null); |
|
425 |
jPnlFields.add(getJTxtEmulated(), null); |
|
469 |
//jPnlFields.add(panelReal); |
|
470 |
|
|
471 |
jPnlFields.add(getJRdbFieldVirtual(), null); |
|
472 |
jRdbFieldVirtual.addActionListener(this); |
|
473 |
|
|
474 |
jPnlFields.add(new JLabel(), null); |
|
475 |
jPnlFields.add(jLblExpression, null); |
|
476 |
JPanel panelVirtual = new JPanel(); |
|
477 |
// panelVirtual.setLayout(new GridLayout(1, 2)); |
|
478 |
GridBagLayout grid = new GridBagLayout(); |
|
479 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
480 |
gbc.gridx = 0; |
|
481 |
gbc.gridy = 0; |
|
482 |
gbc.gridwidth = 3; |
|
483 |
gbc.gridheight = 1; |
|
484 |
gbc.weightx = 1.0; |
|
485 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
486 |
panelVirtual.setLayout(grid); |
|
487 |
|
|
488 |
panelVirtual.add(getJTxtExpression(), gbc); |
|
489 |
gbc.gridx = 4; |
|
490 |
gbc.gridy = 0; |
|
491 |
gbc.gridwidth = 1; |
|
492 |
gbc.gridheight = 1; |
|
493 |
gbc.weightx = 0.0; |
|
494 |
gbc.weighty = 0.0; |
|
495 |
gbc.fill = GridBagConstraints.NONE; |
|
496 |
panelVirtual.add(getJBtnExpression(), gbc); |
|
497 |
jPnlFields.add(panelVirtual); |
|
498 |
|
|
499 |
//jPnlFields.add(jLblFieldVirtual, null); |
|
500 |
ButtonGroup defaultGroup = new ButtonGroup(); |
|
501 |
defaultGroup.add(jRdbFieldReal); |
|
502 |
defaultGroup.add(jRdbFieldVirtual); |
|
503 |
|
|
504 |
// init visible |
|
505 |
jLblDefaultValue.setEnabled(true); |
|
506 |
jTxtDefaultValue.setEnabled(true); |
|
507 |
jLblExpression.setEnabled(false); |
|
508 |
jTxtExpression.setEnabled(false); |
|
509 |
jBtnExpression.setEnabled(false); |
|
510 |
|
|
426 | 511 |
} |
427 | 512 |
return jPnlFields; |
428 | 513 |
} |
... | ... | |
453 | 538 |
this.maxAttributeNameSize = maxAttributeNameSize; |
454 | 539 |
} |
455 | 540 |
|
456 |
private JCheckBox getJTxtEmulated() { |
|
457 |
if (jChbEmulated == null) { |
|
458 |
jChbEmulated = new JCheckBox(); |
|
459 |
jChbEmulated.setBounds(new java.awt.Rectangle(147, 200, 125, 22)); |
|
541 |
private JTextField getJTxtExpression() { |
|
542 |
if (jTxtExpression == null) { |
|
543 |
jTxtExpression = new JTextField(); |
|
544 |
jTxtExpression.setBounds(new java.awt.Rectangle(147, 200, 125, 22)); |
|
545 |
jTxtExpression.setColumns(4); |
|
460 | 546 |
} |
461 |
return jChbEmulated;
|
|
547 |
return jTxtExpression;
|
|
462 | 548 |
} |
463 |
|
|
549 |
|
|
550 |
private JRadioButton getJRdbFieldReal() { |
|
551 |
if (jRdbFieldReal == null) { |
|
552 |
jRdbFieldReal = new JRadioButton(PluginServices.getText(this, "_Real_field")); //"real_value")); |
|
553 |
jRdbFieldReal.setBounds(new java.awt.Rectangle(14, 163, 125, 22)); |
|
554 |
jRdbFieldReal.setSelected(true); |
|
555 |
} |
|
556 |
return jRdbFieldReal; |
|
557 |
} |
|
558 |
private JRadioButton getJRdbFieldVirtual() { |
|
559 |
if (jRdbFieldVirtual == null) { |
|
560 |
jRdbFieldVirtual = new JRadioButton(PluginServices.getText(this, "_Virtual_field"));//"virtual_value")); |
|
561 |
jRdbFieldVirtual.setBounds(new java.awt.Rectangle(14, 237, 125, 22)); |
|
562 |
} |
|
563 |
return jRdbFieldVirtual; |
|
564 |
} |
|
565 |
|
|
566 |
private JButton getJBtnExpression() { |
|
567 |
if (jBtnExpression == null) { |
|
568 |
jBtnExpression = new JButton(); |
|
569 |
jBtnExpression.setText("..."); |
|
570 |
//jBtnExpression.setBounds(new java.awt.Rectangle(147, 200, 125, 22)); |
|
571 |
//jBtnExpression.setColumns(4); |
|
572 |
} |
|
573 |
return jBtnExpression; |
|
574 |
} |
|
575 |
@Override |
|
576 |
public void actionPerformed(ActionEvent e) { |
|
577 |
if (e.getSource()==jRdbFieldReal) { |
|
578 |
jLblDefaultValue.setEnabled(true); |
|
579 |
jTxtDefaultValue.setEnabled(true); |
|
580 |
jLblExpression.setEnabled(false); |
|
581 |
jTxtExpression.setEnabled(false); |
|
582 |
jBtnExpression.setEnabled(false); |
|
583 |
|
|
584 |
} else if (e.getSource()==jRdbFieldVirtual) { |
|
585 |
jLblDefaultValue.setEnabled(false); |
|
586 |
jTxtDefaultValue.setEnabled(false); |
|
587 |
jLblExpression.setEnabled(true); |
|
588 |
jTxtExpression.setEnabled(true); |
|
589 |
jBtnExpression.setEnabled(true); |
|
590 |
|
|
591 |
} |
|
592 |
} |
|
593 |
|
|
464 | 594 |
} |
Also available in: Unified diff