Revision 41127 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/exportto/swing/prov/jdbc/panel/SelectPkPanel.java
SelectPkPanel.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.exportto.swing.prov.jdbc.panel; |
25 | 25 |
|
26 |
import java.awt.BorderLayout; |
|
27 |
|
|
28 |
import javax.swing.JLabel; |
|
29 |
import javax.swing.JPanel; |
|
30 |
import javax.swing.JTextField; |
|
31 |
|
|
26 | 32 |
import org.gvsig.exportto.swing.ExporttoSwingLocator; |
27 | 33 |
import org.gvsig.exportto.swing.ExporttoSwingManager; |
28 | 34 |
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException; |
35 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
29 | 37 |
|
30 | 38 |
/** |
31 | 39 |
* @author gvSIG Team |
... | ... | |
38 | 46 |
|
39 | 47 |
private static final ExporttoSwingManager EXPORTTO_SWING_MANAGER = |
40 | 48 |
ExporttoSwingLocator.getSwingManager(); |
49 |
|
|
50 |
private FeatureType featType = null; |
|
51 |
|
|
52 |
public SelectPkPanel() { |
|
53 |
super(); |
|
54 |
} |
|
55 |
|
|
56 |
public SelectPkPanel(FeatureType ft) { |
|
57 |
super(); |
|
58 |
featType = ft; |
|
59 |
} |
|
60 |
|
|
61 |
protected void initializeComponents() { |
|
62 |
this.setLayout(new BorderLayout()); |
|
63 |
|
|
64 |
JPanel topPanel = new JPanel(new BorderLayout()); |
|
65 |
textField = new JTextField(); |
|
66 |
|
|
67 |
String msg = EXPORTTO_SWING_MANAGER.getTranslation( |
|
68 |
"_Enter_new_field_name_for_primary_key_or_blank_to_not_add_primary_key"); |
|
69 |
topPanel.add(new JLabel(msg + ":"), BorderLayout.NORTH); |
|
70 |
topPanel.add(textField, BorderLayout.CENTER); |
|
71 |
// ============================================== |
|
72 |
add(topPanel, BorderLayout.NORTH); |
|
73 |
} |
|
41 | 74 |
|
75 |
public String getText() { |
|
76 |
String field = textField.getText(); |
|
77 |
if ((field == null) || (field.trim().equals(""))) { |
|
78 |
return null; |
|
79 |
} |
|
80 |
return field; |
|
81 |
} |
|
82 |
|
|
83 |
|
|
42 | 84 |
@Override |
43 | 85 |
public String getPanelTitle() { |
44 |
return EXPORTTO_SWING_MANAGER.getTranslation("input_pk_field_name");
|
|
86 |
return EXPORTTO_SWING_MANAGER.getTranslation("_Primary_key");
|
|
45 | 87 |
} |
46 | 88 |
|
47 | 89 |
@Override |
48 | 90 |
public boolean isValidPanel() throws ExporttoPanelValidationException { |
91 |
String txt = this.getText(); |
|
92 |
if (isFieldName(txt, featType)) { |
|
93 |
throw new ExporttoPanelValidationException( |
|
94 |
EXPORTTO_SWING_MANAGER.getTranslation( |
|
95 |
"_Field_name_already_exists")); |
|
96 |
} |
|
49 | 97 |
return true; |
50 | 98 |
} |
99 |
|
|
100 |
private boolean isFieldName(String txt, FeatureType ft) { |
|
101 |
|
|
102 |
if (ft == null || txt == null) { |
|
103 |
return false; |
|
104 |
} |
|
105 |
|
|
106 |
FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors(); |
|
107 |
for (int i=0; i<atts.length; i++) { |
|
108 |
if (atts[i].getName().equals(txt)) { |
|
109 |
return true; |
|
110 |
} |
|
111 |
} |
|
112 |
return false; |
|
113 |
} |
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
51 | 118 |
} |
Also available in: Unified diff