Revision 7493 trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/panels/JPanelFieldDefinition.java
JPanelFieldDefinition.java | ||
---|---|---|
3 | 3 |
import java.awt.BorderLayout; |
4 | 4 |
import java.awt.Component; |
5 | 5 |
import java.sql.Types; |
6 |
import java.util.ArrayList; |
|
6 | 7 |
|
7 | 8 |
import javax.swing.DefaultCellEditor; |
8 | 9 |
import javax.swing.JButton; |
... | ... | |
18 | 19 |
import javax.swing.table.DefaultTableModel; |
19 | 20 |
import javax.swing.table.TableColumn; |
20 | 21 |
|
22 |
import jwizardcomponent.JWizardComponents; |
|
23 |
import jwizardcomponent.JWizardPanel; |
|
24 |
|
|
21 | 25 |
import com.iver.andami.PluginServices; |
22 | 26 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
23 | 27 |
|
24 |
import jwizardcomponent.JWizardComponents; |
|
25 |
import jwizardcomponent.JWizardPanel; |
|
26 |
|
|
27 | 28 |
/** |
28 | 29 |
* @author fjp |
29 | 30 |
* |
... | ... | |
59 | 60 |
for (int i = 0;i<tm.getRowCount();i++) { |
60 | 61 |
String s=(String)tm.getValueAt(i,0); |
61 | 62 |
valid=validate(s); |
63 |
String type = (String) tm.getValueAt(i,1); |
|
64 |
int length = Integer.parseInt((String) tm.getValueAt(i,2)); |
|
65 |
if (type.equals("String") && length > MAX_FIELD_LENGTH) { |
|
66 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "max_length_is") + ": " + MAX_FIELD_LENGTH+ |
|
67 |
"\n"+PluginServices.getText(this, "length of field")+ " '"+ s + "' " + PluginServices.getText(this, "will_be_truncated")); |
|
68 |
tm.setValueAt(String.valueOf(MAX_FIELD_LENGTH),i,2); |
|
69 |
} |
|
70 |
|
|
62 | 71 |
} |
72 |
|
|
73 |
// ensure no field name is used more than once |
|
74 |
ArrayList fieldNames = new ArrayList(); |
|
75 |
for (int i = 0; i < jTable.getRowCount(); i++) { |
|
76 |
if (fieldNames.contains(tm.getValueAt(i,0))) { |
|
77 |
valid = false; |
|
78 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "two_or_more_fields_with_the_same_name")); |
|
79 |
break; |
|
80 |
} |
|
81 |
fieldNames.add(tm.getValueAt(i, 0)); |
|
82 |
} |
|
83 |
|
|
63 | 84 |
if (valid) |
64 | 85 |
super.next(); |
65 | 86 |
if (!((FileBasedPanel)getWizardComponents().getWizardPanel(2)).getPath().equals("")) |
... | ... | |
191 | 212 |
jButtonAddField.setBounds(new java.awt.Rectangle(7,5,85,23)); |
192 | 213 |
jButtonAddField.addActionListener(new java.awt.event.ActionListener() { |
193 | 214 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
215 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
|
216 |
|
|
217 |
// Figure out a suitable field name |
|
218 |
ArrayList fieldNames = new ArrayList(); |
|
219 |
for (int i = 0; i < jTable.getRowCount(); i++) { |
|
220 |
fieldNames.add(tm.getValueAt(i, 0)); |
|
221 |
} |
|
222 |
String[] currentFieldNames = (String[]) fieldNames.toArray(new String[0]); |
|
223 |
String newField = PluginServices.getText(this, "new_field").replaceAll(" +", "_"); |
|
224 |
int index=0; |
|
225 |
for (int i = 0; i < currentFieldNames.length; i++) { |
|
226 |
if (currentFieldNames[i].startsWith(newField)) { |
|
227 |
try { |
|
228 |
index = Integer.parseInt(currentFieldNames[i].replaceAll(newField,"")); |
|
229 |
} catch (Exception ex) { /* we don't care */} |
|
230 |
} |
|
231 |
} |
|
232 |
String newFieldName = newField+(++index); |
|
233 |
|
|
234 |
|
|
194 | 235 |
// Add a new row |
195 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
|
196 | 236 |
Object[] newRow = new Object[tm.getColumnCount()]; |
197 |
newRow[0] = PluginServices.getText(this,"field");
|
|
237 |
newRow[0] = newFieldName;
|
|
198 | 238 |
newRow[1] = "String"; |
199 | 239 |
newRow[2] = "20"; |
200 | 240 |
tm.addRow(newRow); |
... | ... | |
273 | 313 |
int fieldLength = Integer.parseInt((String) tm.getValueAt(i,2)); |
274 | 314 |
fieldsDesc[i].setFieldLength(fieldLength); |
275 | 315 |
|
276 |
if (fieldsDesc[i].getFieldType() == Types.VARCHAR && fieldLength > MAX_FIELD_LENGTH ) { |
|
277 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "max_length_is") + ": " + MAX_FIELD_LENGTH+ |
|
278 |
"\n"+PluginServices.getText(this, "length of field")+ " "+ fieldsDesc[i].getFieldName() + " " + PluginServices.getText(this, "will_be_truncated")); |
|
279 |
fieldLength = MAX_FIELD_LENGTH; |
|
280 |
} |
|
281 |
|
|
282 | 316 |
// TODO: HACERLO BIEN |
283 | 317 |
if (strType.equals("Double")) |
284 | 318 |
fieldsDesc[i].setFieldDecimalCount(5); |
Also available in: Unified diff