Revision 10033 trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/panels/JPanelFieldDefinition.java
JPanelFieldDefinition.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import com.iver.andami.PluginServices; |
26 | 26 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
27 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
|
27 | 28 |
|
28 | 29 |
/** |
29 | 30 |
* @author fjp |
... | ... | |
42 | 43 |
private JButton jButtonAddField = null; |
43 | 44 |
private JButton jButtonDeleteField = null; |
44 | 45 |
private int MAX_FIELD_LENGTH = 254; |
46 |
|
|
47 |
private IWriter writer = null; |
|
45 | 48 |
|
46 | 49 |
|
47 | 50 |
public JPanelFieldDefinition(JWizardComponents wizardComponents) { |
... | ... | |
61 | 64 |
String s=(String)tm.getValueAt(i,0); |
62 | 65 |
valid=validate(s); |
63 | 66 |
String size=(String) tm.getValueAt(i,2); |
64 |
valid=validateInteger(size); |
|
67 |
valid=valid && validateInteger(size);
|
|
65 | 68 |
if (!valid){ |
66 | 69 |
return; |
67 | 70 |
} |
... | ... | |
85 | 88 |
} |
86 | 89 |
fieldNames.add(tm.getValueAt(i, 0)); |
87 | 90 |
} |
88 |
|
|
91 |
|
|
89 | 92 |
if (valid) |
90 | 93 |
super.next(); |
91 | 94 |
if (!((FileBasedPanel)getWizardComponents().getWizardPanel(2)).getPath().equals("")) |
... | ... | |
94 | 97 |
setFinishButtonEnabled(false); |
95 | 98 |
} |
96 | 99 |
|
100 |
public void setWriter(IWriter writer) { |
|
101 |
this.writer = writer; |
|
102 |
} |
|
103 |
|
|
104 |
public IWriter getWriter() { |
|
105 |
return this.writer; |
|
106 |
} |
|
97 | 107 |
|
98 | 108 |
private boolean validateInteger(String size) { |
99 | 109 |
boolean valid=true; |
... | ... | |
112 | 122 |
|
113 | 123 |
private boolean validate(String s) { |
114 | 124 |
boolean valid=true; |
125 |
if (s.equals("")) { |
|
126 |
valid=false; |
|
127 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
|
128 |
PluginServices.getText(this,"no_puede_continuar")+"\n"+ |
|
129 |
PluginServices.getText(this,"the_field_name_is_required")); |
|
130 |
} |
|
115 | 131 |
if (s.indexOf(" ")!=-1) { |
116 | 132 |
valid=false; |
117 | 133 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
... | ... | |
119 | 135 |
PluginServices.getText(this,"field")+" : "+s+"\n"+ |
120 | 136 |
PluginServices.getText(this,"contiene_espacios_en_blanco")); |
121 | 137 |
} |
138 |
if (this.writer != null && this.writer.getCapability("FieldNameMaxLength") != null) { |
|
139 |
String value = writer.getCapability("FieldNameMaxLength"); |
|
140 |
int intValue; |
|
141 |
try { |
|
142 |
intValue = Integer.parseInt(value); |
|
143 |
} catch (NumberFormatException e) { |
|
144 |
intValue = 0; |
|
145 |
} |
|
146 |
if (intValue > 0 && s.length() > intValue) { |
|
147 |
valid=false; |
|
148 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
|
149 |
PluginServices.getText(this,"no_puede_continuar")+"\n"+ |
|
150 |
PluginServices.getText(this,"field")+" : "+s+"\n"+ |
|
151 |
PluginServices.getText(this,"too_long_name")+"\n"+ |
|
152 |
PluginServices.getText(this,"maximun_name_size")+" : "+intValue+"\n" |
|
153 |
); |
|
154 |
} |
|
155 |
} |
|
122 | 156 |
return valid; |
123 | 157 |
} |
124 | 158 |
|
... | ... | |
245 | 279 |
fieldNames.add(tm.getValueAt(i, 0)); |
246 | 280 |
} |
247 | 281 |
String[] currentFieldNames = (String[]) fieldNames.toArray(new String[0]); |
248 |
String newField = PluginServices.getText(this, "new_field").replaceAll(" +", "_");
|
|
282 |
String newField = PluginServices.getText(this, "field").replaceAll(" +", "_"); |
|
249 | 283 |
int index=0; |
250 | 284 |
for (int i = 0; i < currentFieldNames.length; i++) { |
251 | 285 |
if (currentFieldNames[i].startsWith(newField)) { |
... | ... | |
255 | 289 |
} |
256 | 290 |
} |
257 | 291 |
String newFieldName = newField+(++index); |
292 |
|
|
258 | 293 |
|
259 |
|
|
260 | 294 |
// Add a new row |
261 | 295 |
Object[] newRow = new Object[tm.getColumnCount()]; |
262 | 296 |
newRow[0] = newFieldName; |
Also available in: Unified diff