Revision 7493 branches/v10/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 |
import com.iver.cit.gvsig.gui.dialogs.DlgFieldManager; |
|
24 | 27 |
|
25 |
import jwizardcomponent.JWizardComponents; |
|
26 |
import jwizardcomponent.JWizardPanel; |
|
27 |
|
|
28 | 28 |
/** |
29 | 29 |
* @author fjp |
30 | 30 |
* |
... | ... | |
60 | 60 |
for (int i = 0;i<tm.getRowCount();i++) { |
61 | 61 |
String s=(String)tm.getValueAt(i,0); |
62 | 62 |
valid=validateFieldName(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 |
|
|
63 | 71 |
} |
64 | 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 |
|
|
65 | 84 |
if (valid) |
66 | 85 |
super.next(); |
67 | 86 |
if (!((FileBasedPanel)getWizardComponents().getWizardPanel(2)).getPath().equals("")) |
... | ... | |
193 | 212 |
jButtonAddField.setBounds(new java.awt.Rectangle(7,5,85,23)); |
194 | 213 |
jButtonAddField.addActionListener(new java.awt.event.ActionListener() { |
195 | 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 |
|
|
196 | 234 |
// Add a new row |
197 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
|
198 | 235 |
Object[] newRow = new Object[tm.getColumnCount()]; |
199 |
newRow[0] = PluginServices.getText(this,"field");
|
|
236 |
newRow[0] = newFieldName;
|
|
200 | 237 |
newRow[1] = "String"; |
201 | 238 |
newRow[2] = "20"; |
202 | 239 |
tm.addRow(newRow); |
... | ... | |
274 | 311 |
fieldsDesc[i].setFieldType(Types.DATE); |
275 | 312 |
int fieldLength = Integer.parseInt((String) tm.getValueAt(i,2)); |
276 | 313 |
|
277 |
if (fieldsDesc[i].getFieldType() == Types.VARCHAR && fieldLength > MAX_FIELD_LENGTH) { |
|
278 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "max_length_is") + ": " + MAX_FIELD_LENGTH+ |
|
279 |
"\n"+PluginServices.getText(this, "length of field")+ " "+ fieldsDesc[i].getFieldName() + " " + PluginServices.getText(this, "will_be_truncated")); |
|
280 |
fieldLength = MAX_FIELD_LENGTH; |
|
281 |
} |
|
282 | 314 |
|
283 | 315 |
fieldsDesc[i].setFieldLength(fieldLength); |
284 | 316 |
|
Also available in: Unified diff