Revision 38533 branches/v2_0_0_prep/libraries/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/FeatureTypePanel.java
FeatureTypePanel.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.BorderLayout; |
4 | 4 |
import java.awt.Component; |
5 |
import java.awt.GridBagConstraints; |
|
6 |
import java.awt.GridBagLayout; |
|
7 |
import java.awt.Insets; |
|
5 | 8 |
import java.awt.event.ActionEvent; |
6 | 9 |
import java.awt.event.ActionListener; |
10 |
import java.awt.event.ItemEvent; |
|
11 |
import java.awt.event.ItemListener; |
|
12 |
import java.lang.reflect.InvocationTargetException; |
|
7 | 13 |
import java.util.ArrayList; |
8 | 14 |
import java.util.Iterator; |
9 | 15 |
import java.util.List; |
... | ... | |
14 | 20 |
import javax.swing.JCheckBox; |
15 | 21 |
import javax.swing.JComboBox; |
16 | 22 |
import javax.swing.JLabel; |
23 |
import javax.swing.JOptionPane; |
|
17 | 24 |
import javax.swing.JPanel; |
18 | 25 |
import javax.swing.JScrollPane; |
19 | 26 |
import javax.swing.JTable; |
27 |
import javax.swing.JTextField; |
|
20 | 28 |
import javax.swing.ListSelectionModel; |
29 |
import javax.swing.SwingUtilities; |
|
21 | 30 |
import javax.swing.UIManager; |
22 | 31 |
import javax.swing.event.ListDataListener; |
23 | 32 |
import javax.swing.event.ListSelectionEvent; |
24 | 33 |
import javax.swing.event.ListSelectionListener; |
25 | 34 |
import javax.swing.event.TableModelEvent; |
26 | 35 |
import javax.swing.event.TableModelListener; |
36 |
import javax.swing.table.DefaultTableCellRenderer; |
|
27 | 37 |
import javax.swing.table.DefaultTableModel; |
28 | 38 |
import javax.swing.table.TableCellRenderer; |
29 | 39 |
import javax.swing.table.TableColumn; |
40 |
import javax.swing.table.TableModel; |
|
30 | 41 |
|
31 | 42 |
import org.cresques.cts.IProjection; |
32 | 43 |
import org.slf4j.Logger; |
... | ... | |
37 | 48 |
import org.gvsig.fmap.dal.DALLocator; |
38 | 49 |
import org.gvsig.fmap.dal.DataManager; |
39 | 50 |
import org.gvsig.fmap.dal.DataServerExplorer; |
51 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
|
52 |
import org.gvsig.fmap.dal.DataTypes; |
|
40 | 53 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
41 | 54 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
42 | 55 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
43 | 56 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
44 |
import org.gvsig.fmap.geom.DataTypes;
|
|
57 |
import org.gvsig.fmap.dal.feature.FeatureType;
|
|
45 | 58 |
import org.gvsig.fmap.geom.Geometry; |
59 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
60 |
import org.gvsig.fmap.geom.GeometryManager; |
|
61 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
46 | 62 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
47 | 63 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
48 | 64 |
import org.gvsig.i18n.Messages; |
49 | 65 |
import org.gvsig.newlayer.NewLayerService; |
50 |
import org.gvsig.newlayer.NewLayerWizard; |
|
51 | 66 |
import org.gvsig.tools.dataTypes.DataType; |
52 | 67 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
53 | 68 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
... | ... | |
63 | 78 |
private static final int COLUMN_MANDATORY = 7; |
64 | 79 |
|
65 | 80 |
private static final long serialVersionUID = 263541873998597624L; |
66 |
private NewLayerWizard wizard; |
|
81 |
|
|
82 |
private FeatureType defaultFeatType = null; |
|
83 |
|
|
84 |
private NewLayerService newLayerService = null; |
|
85 |
private int inDefaultFeatTypeFieldCount = 0; |
|
86 |
private String inStoreName = null; |
|
87 |
private IProjection inProjection = null; |
|
88 |
private FeatureStoreProviderFactory spFactory = null; |
|
89 |
private boolean defaultHasGeometry = false; |
|
90 |
|
|
67 | 91 |
private static final Logger logger = LoggerFactory |
68 | 92 |
.getLogger(FeatureTypePanel.class); |
69 | 93 |
|
... | ... | |
71 | 95 |
private JScrollPane jScrollPane = null; |
72 | 96 |
protected JTable jTable = null; |
73 | 97 |
private JPanel jPanelEast = null; |
74 |
private JButton jButtonAddField = null;
|
|
75 |
private JButton jButtonDeleteField = null;
|
|
98 |
private JButton addFieldButton = null;
|
|
99 |
private JButton deleteFieldButton = null;
|
|
76 | 100 |
protected int MAX_FIELD_LENGTH = 254; |
77 | 101 |
|
78 | 102 |
// we dont need this list |
... | ... | |
80 | 104 |
// the user clicks next |
81 | 105 |
// private List removedFields; |
82 | 106 |
|
83 |
private DataServerExplorer explorer = null; |
|
107 |
// private DataServerExplorer explorer = null;
|
|
84 | 108 |
|
85 |
public FeatureTypePanel(NewLayerWizard wizard) { |
|
86 |
this.wizard = wizard; |
|
109 |
public FeatureTypePanel(NewLayerService new_layer_service) { |
|
110 |
|
|
111 |
/* |
|
112 |
service.getFeatureType(), |
|
113 |
service.getStoreName(), |
|
114 |
service.getMapContext().getProjection(); |
|
115 |
*/ |
|
116 |
newLayerService = new_layer_service; |
|
117 |
inStoreName = newLayerService.getStoreName(); |
|
118 |
inProjection = newLayerService.getMapContext().getProjection(); |
|
119 |
|
|
120 |
DataStoreProviderFactory dspf = |
|
121 |
DALLocator.getDataManager().getStoreProviderFactory(inStoreName); |
|
122 |
spFactory = (FeatureStoreProviderFactory) dspf; |
|
123 |
defaultFeatType = spFactory.createDefaultFeatureType(); |
|
124 |
if (defaultFeatType != null) { |
|
125 |
inDefaultFeatTypeFieldCount = |
|
126 |
defaultFeatType.getAttributeDescriptors().length; |
|
127 |
int def_geom_fld_index = defaultFeatType.getDefaultGeometryAttributeIndex(); |
|
128 |
if (def_geom_fld_index >= 0 && |
|
129 |
def_geom_fld_index < inDefaultFeatTypeFieldCount && |
|
130 |
defaultFeatType. |
|
131 |
getAttributeDescriptor(def_geom_fld_index). |
|
132 |
getDataType().getType() == DataTypes.GEOMETRY) { |
|
133 |
|
|
134 |
defaultHasGeometry = true; |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
87 | 138 |
} |
88 | 139 |
|
89 | 140 |
private void initializeComponents() { |
... | ... | |
93 | 144 |
this.setSize(new java.awt.Dimension(499, 232)); |
94 | 145 |
this.add(jLabel, java.awt.BorderLayout.NORTH); |
95 | 146 |
this.add(getJScrollPane(), java.awt.BorderLayout.CENTER); |
96 |
this.add(getJPanelEast(), java.awt.BorderLayout.EAST);
|
|
147 |
this.add(getJPanelSouth(), java.awt.BorderLayout.SOUTH);
|
|
97 | 148 |
|
98 | 149 |
} |
99 | 150 |
|
... | ... | |
118 | 169 |
private JTable getJTable() { |
119 | 170 |
if (jTable == null) { |
120 | 171 |
jTable = new JTable(){ |
121 |
public boolean isCellEditable(int row,int column){ |
|
122 |
Object o = getValueAt(row,column); |
|
172 |
public boolean isCellEditable(int row,int column){ |
|
123 | 173 |
|
174 |
|
|
175 |
if (row < inDefaultFeatTypeFieldCount) { |
|
176 |
// default fields |
|
177 |
Object o = getValueAt(row,COLUMN_TYPE); |
|
178 |
if (o instanceof ComboItemDataType) { |
|
179 |
|
|
180 |
ComboItemDataType ot = (ComboItemDataType) o; |
|
181 |
return (ot.dataType.getType() == DataTypes.GEOMETRY) |
|
182 |
&& |
|
183 |
(column == COLUMN_GEOMETRYTYPE || |
|
184 |
column == COLUMN_GEOMETRYSUBTYPE); |
|
185 |
|
|
186 |
} else { |
|
187 |
return false; |
|
188 |
} |
|
189 |
|
|
190 |
} else { |
|
191 |
// fields added by user |
|
192 |
if (column == COLUMN_PRIMARYKEY) { |
|
193 |
return spFactory.allowsPrimaryKeyAttributes(); |
|
194 |
} |
|
195 |
|
|
196 |
if (column == COLUMN_MANDATORY) { |
|
197 |
return spFactory.allowsMandatoryAttributes(); |
|
198 |
} |
|
199 |
|
|
200 |
if (column == COLUMN_LENGTH) { |
|
201 |
|
|
202 |
Object o = getValueAt(row,COLUMN_TYPE); |
|
203 |
if (o instanceof ComboItemDataType) { |
|
204 |
|
|
205 |
ComboItemDataType ot = (ComboItemDataType) o; |
|
206 |
return dataTypeNeedsSize(ot.dataType.getType()); |
|
207 |
|
|
208 |
} else { |
|
209 |
return false; |
|
210 |
} |
|
211 |
|
|
212 |
} |
|
213 |
|
|
214 |
if (defaultHasGeometry && |
|
215 |
(column == COLUMN_GEOMETRYTYPE |
|
216 |
|| column == COLUMN_GEOMETRYSUBTYPE |
|
217 |
|| column == COLUMN_CRS)) { |
|
218 |
// geom-related columns not editable |
|
219 |
return false; |
|
220 |
} else { |
|
221 |
return true; |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
/* |
|
124 | 226 |
if ((column == COLUMN_GEOMETRYTYPE) || |
125 | 227 |
(column == COLUMN_GEOMETRYSUBTYPE) || |
126 | 228 |
(column == COLUMN_CRS)) { |
... | ... | |
128 | 230 |
((ComboItemDataType) getValueAt(row, COLUMN_TYPE)).dataType; |
129 | 231 |
return dataType.getType() == DataTypes.GEOMETRY; |
130 | 232 |
} |
131 |
return true;
|
|
233 |
*/
|
|
132 | 234 |
} |
133 | 235 |
}; |
134 | 236 |
|
... | ... | |
154 | 256 |
ListSelectionModel lsm = (ListSelectionModel) e.getSource(); |
155 | 257 |
if (lsm.isSelectionEmpty()) { |
156 | 258 |
// no rows are selected |
157 |
jButtonDeleteField.setEnabled(false);
|
|
259 |
deleteFieldButton.setEnabled(false);
|
|
158 | 260 |
} else { |
159 |
jButtonDeleteField.setEnabled(true); |
|
160 |
} |
|
261 |
int min_sele = lsm.getMinSelectionIndex(); |
|
262 |
if (min_sele > -1 && |
|
263 |
min_sele < inDefaultFeatTypeFieldCount) { |
|
264 |
deleteFieldButton.setEnabled(false); |
|
265 |
} else { |
|
266 |
deleteFieldButton.setEnabled(allowEditableFeatureType()); |
|
267 |
} |
|
268 |
} |
|
269 |
|
|
161 | 270 |
} |
162 | 271 |
}); |
163 | 272 |
jTable.getColumn(Messages.getText("field")).setWidth(180); |
... | ... | |
171 | 280 |
}); |
172 | 281 |
|
173 | 282 |
// Rellenado de la tabla |
174 |
EditableFeatureType featureType = this.wizard.getService() |
|
175 |
.getFeatureType(); |
|
176 |
if (featureType != null) { |
|
177 |
int row = 0; |
|
178 |
tm.setRowCount(featureType.size()); |
|
179 |
Iterator it = featureType.iterator(); |
|
283 |
if (defaultFeatType != null) { |
|
284 |
|
|
285 |
Iterator it = defaultFeatType.iterator(); |
|
286 |
boolean some_error = false; |
|
180 | 287 |
while (it.hasNext()) { |
181 | 288 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) it |
182 | 289 |
.next(); |
290 |
|
|
291 |
if (!addRowToFieldTable( |
|
292 |
jTable, |
|
293 |
null, |
|
294 |
inProjection, |
|
295 |
descriptor)) { |
|
296 |
|
|
297 |
some_error = true; |
|
298 |
} |
|
299 |
/* |
|
183 | 300 |
tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD); |
184 | 301 |
tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE); |
185 | 302 |
tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH); |
... | ... | |
188 | 305 |
tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS); |
189 | 306 |
tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY); |
190 | 307 |
tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY); |
191 |
row++;
|
|
308 |
*/
|
|
192 | 309 |
} |
310 |
|
|
311 |
if (some_error) { |
|
312 |
String tit = Messages.getText("_Default_fields"); |
|
313 |
String msg = Messages.getText("_Unable_to_add_fields"); |
|
314 |
JOptionPane.showMessageDialog( |
|
315 |
jTable, msg, tit, |
|
316 |
JOptionPane.ERROR_MESSAGE); |
|
317 |
} |
|
193 | 318 |
} |
194 | 319 |
|
195 | 320 |
} |
... | ... | |
202 | 327 |
* |
203 | 328 |
* @return javax.swing.JPanel |
204 | 329 |
*/ |
205 |
private JPanel getJPanelEast() {
|
|
330 |
private JPanel getJPanelSouth() {
|
|
206 | 331 |
if (jPanelEast == null) { |
207 | 332 |
jPanelEast = new JPanel(); |
208 |
jPanelEast.setLayout(null); |
|
209 |
jPanelEast.setPreferredSize(new java.awt.Dimension(170, 100)); |
|
210 |
jPanelEast.add(getJButtonAddField(), null); |
|
211 |
jPanelEast.add(getJButtonDeleteField(), null); |
|
333 |
jPanelEast.setLayout(new BorderLayout()); |
|
334 |
|
|
335 |
JPanel south_east = new JPanel(new GridBagLayout()); |
|
336 |
// south_east.setPreferredSize(new java.awt.Dimension(170, 50)); |
|
337 |
GridBagConstraints c = new GridBagConstraints(); |
|
338 |
c.fill = GridBagConstraints.HORIZONTAL; |
|
339 |
c.insets = new Insets(8,10,8,0); //top padding |
|
340 |
c.gridx = 0; |
|
341 |
c.gridwidth = 1; |
|
342 |
c.gridy = 0; |
|
343 |
south_east.add(getJButtonAddField(), c); |
|
344 |
c.gridx = 1; |
|
345 |
south_east.add(getJButtonDeleteField(), c); |
|
346 |
|
|
347 |
jPanelEast.add(south_east, BorderLayout.EAST); |
|
212 | 348 |
} |
213 | 349 |
return jPanelEast; |
214 | 350 |
} |
... | ... | |
219 | 355 |
* @return javax.swing.JButton |
220 | 356 |
*/ |
221 | 357 |
private JButton getJButtonAddField() { |
222 |
if (jButtonAddField == null) {
|
|
223 |
jButtonAddField = new JButton();
|
|
224 |
jButtonAddField.setText(Messages.getText("add_field"));
|
|
225 |
jButtonAddField.setLocation(new java.awt.Point(7, 5));
|
|
226 |
jButtonAddField.setSize(new java.awt.Dimension(145, 23));
|
|
227 |
jButtonAddField.setPreferredSize(new java.awt.Dimension(100, 26));
|
|
228 |
jButtonAddField
|
|
358 |
if (addFieldButton == null) {
|
|
359 |
addFieldButton = new JButton();
|
|
360 |
addFieldButton.setText(Messages.getText("add_field"));
|
|
361 |
addFieldButton.setLocation(new java.awt.Point(7, 5));
|
|
362 |
addFieldButton.setSize(new java.awt.Dimension(145, 23));
|
|
363 |
addFieldButton.setPreferredSize(new java.awt.Dimension(100, 23));
|
|
364 |
addFieldButton
|
|
229 | 365 |
.addActionListener(new java.awt.event.ActionListener() { |
230 | 366 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
231 | 367 |
DefaultTableModel tm = (DefaultTableModel) jTable |
... | ... | |
257 | 393 |
// Esto lo a?ado aqu? porque si no tiene registros, |
258 | 394 |
// no hace caso. (Por eso no |
259 | 395 |
// lo pongo en getJTable() |
260 |
TableColumn typeColumn = jTable.getColumnModel() |
|
261 |
.getColumn(COLUMN_TYPE); |
|
262 |
DataManager dataManager = DALLocator |
|
263 |
.getDataManager(); |
|
264 |
ComboModelDataType model = new ComboModelDataType( |
|
265 |
dataManager.getDataTypes()); |
|
266 |
JComboBox comboBox = new JComboBox(model); |
|
267 |
typeColumn.setCellEditor(new DefaultCellEditor( |
|
268 |
comboBox)); |
|
269 |
|
|
270 |
TableColumn widthColumn = jTable.getColumnModel() |
|
271 |
.getColumn(COLUMN_LENGTH); |
|
272 |
|
|
273 |
TableColumn geomTypeColumn = jTable |
|
274 |
.getColumnModel().getColumn(COLUMN_GEOMETRYTYPE); |
|
275 |
ComboModelGeomType geomTypeModel = new ComboModelGeomType( |
|
276 |
getGeomTypes()); |
|
277 |
JComboBox geomTypeComboBox = new JComboBox( |
|
278 |
geomTypeModel); |
|
279 |
geomTypeColumn.setCellEditor(new DefaultCellEditor( |
|
280 |
geomTypeComboBox)); |
|
281 |
geomTypeColumn.setCellRenderer(new GeometryComboCellRenderer()); |
|
396 |
if (!addRowToFieldTable( |
|
397 |
jTable, |
|
398 |
newFieldName, |
|
399 |
inProjection, |
|
400 |
null)) { |
|
282 | 401 |
|
283 |
|
|
284 |
TableColumn geomSubTypeColumn = jTable |
|
285 |
.getColumnModel().getColumn(COLUMN_GEOMETRYSUBTYPE); |
|
286 |
ComboModelGeomType geomSubTypeModel = new ComboModelGeomType( |
|
287 |
getGeomSubtypes()); |
|
288 |
JComboBox geomSubTypeComboBox = new JComboBox( |
|
289 |
geomSubTypeModel); |
|
290 |
geomSubTypeColumn |
|
291 |
.setCellEditor(new DefaultCellEditor( |
|
292 |
geomSubTypeComboBox)); |
|
293 |
geomSubTypeColumn.setCellRenderer(new GeometryComboCellRenderer()); |
|
294 |
|
|
295 |
TableColumn crsColumn = jTable.getColumnModel() |
|
296 |
.getColumn(COLUMN_CRS); |
|
297 |
crsColumn.setCellEditor(new ButtonEditor( |
|
298 |
new JCheckBox())); |
|
299 |
CrsRenderer crsButtonRenderer = new CrsRenderer(); |
|
300 |
crsColumn.setCellRenderer(crsButtonRenderer); |
|
301 |
|
|
302 |
TableColumn primaryKeyColumn = jTable |
|
303 |
.getColumnModel().getColumn(COLUMN_PRIMARYKEY); |
|
304 |
JCheckBox primaryKeyCheckBox = new JCheckBox(); |
|
305 |
primaryKeyColumn |
|
306 |
.setCellEditor(new DefaultCellEditor( |
|
307 |
primaryKeyCheckBox)); |
|
308 |
CheckBoxRenderer primaryKeyCheckBoxRenderer = new CheckBoxRenderer(); |
|
309 |
primaryKeyColumn |
|
310 |
.setCellRenderer(primaryKeyCheckBoxRenderer); |
|
311 |
|
|
312 |
TableColumn mandatoryColumn = jTable |
|
313 |
.getColumnModel().getColumn(COLUMN_MANDATORY); |
|
314 |
JCheckBox mandatoryCheckBox = new JCheckBox(); |
|
315 |
mandatoryColumn |
|
316 |
.setCellEditor(new DefaultCellEditor( |
|
317 |
mandatoryCheckBox)); |
|
318 |
CheckBoxRenderer mandatoryCheckBoxRenderer = new CheckBoxRenderer(); |
|
319 |
mandatoryColumn |
|
320 |
.setCellRenderer(mandatoryCheckBoxRenderer); |
|
321 |
|
|
322 |
// Add a new row |
|
323 |
Object[] newRow = new Object[tm.getColumnCount()]; |
|
324 |
newRow[COLUMN_FIELD] = newFieldName; |
|
325 |
newRow[COLUMN_TYPE] = model.getElementAt(0); |
|
326 |
newRow[COLUMN_LENGTH] = "20"; |
|
327 |
newRow[COLUMN_GEOMETRYTYPE] = geomTypeModel.getElementAt(0); |
|
328 |
newRow[COLUMN_GEOMETRYSUBTYPE] = geomSubTypeModel.getElementAt(0); |
|
329 |
// Por defecto, la proyeccion de la vista |
|
330 |
newRow[COLUMN_CRS] = wizard.getService().getMapContext() |
|
331 |
.getProjection(); |
|
332 |
newRow[COLUMN_PRIMARYKEY] = primaryKeyCheckBox.isSelected(); |
|
333 |
newRow[COLUMN_MANDATORY] = mandatoryCheckBox.isSelected(); |
|
334 |
tm.addRow(newRow); |
|
402 |
String tit = Messages.getText("_Default_fields"); |
|
403 |
String msg = Messages.getText("_Unable_to_add_fields"); |
|
404 |
JOptionPane.showMessageDialog( |
|
405 |
jTable, msg, tit, |
|
406 |
JOptionPane.ERROR_MESSAGE); |
|
407 |
} |
|
335 | 408 |
} |
336 | 409 |
}); |
337 | 410 |
|
338 | 411 |
} |
339 |
jButtonAddField.setEnabled(allowEditableFeatureType());
|
|
340 |
return jButtonAddField;
|
|
412 |
addFieldButton.setEnabled(allowEditableFeatureType());
|
|
413 |
return addFieldButton;
|
|
341 | 414 |
} |
342 | 415 |
|
343 | 416 |
private boolean allowEditableFeatureType(){ |
344 |
NewLayerService service = this.wizard.getService(); |
|
417 |
|
|
345 | 418 |
DataManager dataManager = DALLocator.getDataManager(); |
346 |
FeatureStoreProviderFactory factory = (FeatureStoreProviderFactory) dataManager.getStoreProviderFactory(service.getStoreName()); |
|
419 |
FeatureStoreProviderFactory factory = |
|
420 |
(FeatureStoreProviderFactory) dataManager. |
|
421 |
getStoreProviderFactory(inStoreName); |
|
347 | 422 |
if (factory.allowEditableFeatureType()==FeatureStoreProviderFactory.NO) { |
348 | 423 |
return false; |
349 | 424 |
} |
... | ... | |
368 | 443 |
private List<ComboItemDataType> dataTypes; |
369 | 444 |
private ComboItemDataType selected; |
370 | 445 |
|
371 |
public ComboModelDataType(List<DataType> dataTypes) { |
|
446 |
public ComboModelDataType(List<DataType> dataTypes, int sel_type) { |
|
447 |
|
|
372 | 448 |
this.dataTypes = new ArrayList<ComboItemDataType>(); |
449 |
ComboItemDataType item = null; |
|
373 | 450 |
for (Iterator iterator = dataTypes.iterator(); iterator.hasNext();) { |
374 | 451 |
DataType dataType = (DataType) iterator.next(); |
375 |
this.dataTypes.add(new ComboItemDataType(dataType)); |
|
452 |
item = new ComboItemDataType(dataType); |
|
453 |
this.dataTypes.add(item); |
|
454 |
if (sel_type == dataType.getType()) { |
|
455 |
this.setSelectedItem(item); |
|
456 |
} |
|
376 | 457 |
} |
377 | 458 |
} |
378 | 459 |
|
... | ... | |
415 | 496 |
Object value, boolean isSelected, boolean hasFocus, int row, |
416 | 497 |
int column) { |
417 | 498 |
|
418 |
DataType dataType = |
|
419 |
((ComboItemDataType) table.getValueAt(row, COLUMN_TYPE)).dataType; |
|
499 |
ComboItemDataType item = |
|
500 |
(ComboItemDataType) table.getValueAt(row, COLUMN_TYPE); |
|
501 |
|
|
502 |
if (item == null) { |
|
503 |
// happens sometimes. perhaps an early rendering? |
|
504 |
return new JLabel(); |
|
505 |
} |
|
506 |
|
|
507 |
DataType dataType = item.dataType; |
|
420 | 508 |
|
421 | 509 |
if (dataType.getType() != DataTypes.GEOMETRY) { |
422 | 510 |
return label; |
... | ... | |
440 | 528 |
Object value, boolean isSelected, boolean hasFocus, int row, |
441 | 529 |
int column) { |
442 | 530 |
|
443 |
DataType dataType =
|
|
444 |
((ComboItemDataType) table.getValueAt(row, COLUMN_TYPE)).dataType;
|
|
531 |
ComboItemDataType item = (ComboItemDataType) table.getValueAt(row, COLUMN_TYPE);
|
|
532 |
DataType dataType = item.dataType;
|
|
445 | 533 |
|
446 | 534 |
if (dataType.getType() == DataTypes.GEOMETRY) { |
447 | 535 |
ComboItemGeomType geomType = (ComboItemGeomType)value; |
... | ... | |
535 | 623 |
public String toString() { |
536 | 624 |
return this.name; |
537 | 625 |
} |
626 |
|
|
627 |
public int getGeomType() { |
|
628 |
return type; |
|
629 |
} |
|
538 | 630 |
} |
539 | 631 |
|
540 | 632 |
private class ComboModelGeomType implements ComboBoxModel { |
... | ... | |
542 | 634 |
private List<ComboItemGeomType> geomTypes; |
543 | 635 |
private ComboItemGeomType selected; |
544 | 636 |
|
545 |
public ComboModelGeomType(List<ComboItemGeomType> geomTypes) { |
|
637 |
public ComboModelGeomType( |
|
638 |
List<ComboItemGeomType> geomTypes, int sel_geom_type) { |
|
639 |
|
|
546 | 640 |
this.geomTypes = geomTypes; |
641 |
int len = geomTypes.size(); |
|
642 |
ComboItemGeomType item = null; |
|
643 |
for (int i=0; i<len; i++) { |
|
644 |
item = geomTypes.get(i); |
|
645 |
if (item.getGeomType() == sel_geom_type) { |
|
646 |
setSelectedItem(item); |
|
647 |
} |
|
648 |
} |
|
547 | 649 |
} |
548 | 650 |
|
549 | 651 |
public void addListDataListener(ListDataListener arg0) { |
... | ... | |
616 | 718 |
*/ |
617 | 719 |
private static final long serialVersionUID = 5093448776058027505L; |
618 | 720 |
|
619 |
CheckBoxRenderer() { |
|
721 |
public CheckBoxRenderer() {
|
|
620 | 722 |
setHorizontalAlignment(JLabel.CENTER); |
621 | 723 |
} |
622 | 724 |
|
... | ... | |
641 | 743 |
* @return javax.swing.JButton |
642 | 744 |
*/ |
643 | 745 |
private JButton getJButtonDeleteField() { |
644 |
if (jButtonDeleteField == null) {
|
|
645 |
jButtonDeleteField = new JButton();
|
|
646 |
jButtonDeleteField.setText(Messages.getText("delete_field"));
|
|
647 |
jButtonDeleteField.setLocation(new java.awt.Point(7, 33));
|
|
648 |
jButtonDeleteField.setSize(new java.awt.Dimension(145, 23));
|
|
649 |
jButtonDeleteField.setEnabled(false);
|
|
650 |
jButtonDeleteField
|
|
746 |
if (deleteFieldButton == null) {
|
|
747 |
deleteFieldButton = new JButton();
|
|
748 |
deleteFieldButton.setText(Messages.getText("delete_field"));
|
|
749 |
deleteFieldButton.setLocation(new java.awt.Point(7, 33));
|
|
750 |
deleteFieldButton.setSize(new java.awt.Dimension(145, 23));
|
|
751 |
deleteFieldButton.setEnabled(false);
|
|
752 |
deleteFieldButton
|
|
651 | 753 |
.addActionListener(new java.awt.event.ActionListener() { |
652 | 754 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
653 | 755 |
int[] selecteds = jTable.getSelectedRows(); |
... | ... | |
664 | 766 |
} |
665 | 767 |
}); |
666 | 768 |
} |
667 |
jButtonDeleteField.setEnabled(allowEditableFeatureType());
|
|
668 |
return jButtonDeleteField;
|
|
769 |
deleteFieldButton.setEnabled(false);
|
|
770 |
return deleteFieldButton;
|
|
669 | 771 |
} |
670 | 772 |
|
671 | 773 |
public String getPanelTitle() { |
... | ... | |
678 | 780 |
} |
679 | 781 |
} |
680 | 782 |
|
681 |
private void fillFeatureType() { |
|
783 |
private void fillFeatureType() throws NotContinueWizardException {
|
|
682 | 784 |
/* |
683 | 785 |
* Coge los datos del formulario y los guarda en |
684 | 786 |
* this.service.getFeatureType() |
685 | 787 |
*/ |
686 |
NewLayerService service = this.wizard.getService(); |
|
687 |
EditableFeatureType featureType = service.getFeatureType();
|
|
688 |
|
|
788 |
|
|
789 |
EditableFeatureType edft = newLayerService.getFeatureType();
|
|
790 |
|
|
689 | 791 |
// Clean and rebuild featureType everytime we click next |
690 |
removeAllFields(featureType); |
|
792 |
removeAllFields(edft); |
|
793 |
edft.setDefaultGeometryAttributeName(null); |
|
691 | 794 |
|
692 |
/* |
|
693 |
for (Iterator iterator = removedFields.iterator(); iterator.hasNext();) { |
|
694 |
String name = (String) iterator.next(); |
|
695 |
featureType.remove(name); |
|
696 |
} |
|
697 |
removedFields.clear(); |
|
698 |
*/ |
|
699 |
|
|
795 |
GeometryManager gm = GeometryLocator.getGeometryManager(); |
|
700 | 796 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
797 |
|
|
701 | 798 |
for (int i = 0; i < tm.getRowCount(); i++) { |
702 | 799 |
DataType dataType = ((ComboItemDataType) tm.getValueAt(i, COLUMN_TYPE)).dataType; |
703 | 800 |
|
704 |
int fieldLength = Integer.parseInt((String) tm.getValueAt(i, COLUMN_LENGTH));
|
|
705 |
// TODO: HACERLO BIEN
|
|
706 |
if (dataType.getType() == DataTypes.DOUBLE) {
|
|
707 |
fieldLength = 5;
|
|
801 |
int fieldLength = 20;
|
|
802 |
if (dataTypeNeedsSize(dataType.getType())) {
|
|
803 |
fieldLength =
|
|
804 |
Integer.parseInt((String) tm.getValueAt(i, COLUMN_LENGTH));
|
|
708 | 805 |
} |
709 |
|
|
710 |
// FIXME: Arreglar lo que pasa si en el siguiente panel volvemos |
|
711 |
// hacia atras, y en este volvemos a ir hacia adelante |
|
712 |
/* |
|
713 |
String fieldName = (String) tm.getValueAt(i, COLUMN_FIELD); |
|
714 |
EditableFeatureAttributeDescriptor attrDescriptor = (EditableFeatureAttributeDescriptor) featureType |
|
715 |
.getAttributeDescriptor(fieldName); |
|
716 | 806 |
|
717 |
if (attrDescriptor != null) { |
|
718 |
featureType.remove(attrDescriptor); |
|
719 |
} |
|
720 |
*/ |
|
721 |
|
|
722 |
EditableFeatureAttributeDescriptor efad1 = featureType.add( |
|
807 |
EditableFeatureAttributeDescriptor efad1 = |
|
808 |
edft.add( |
|
723 | 809 |
(String) tm.getValueAt(i, COLUMN_FIELD), dataType.getType(), |
724 | 810 |
fieldLength); |
811 |
|
|
812 |
if (dataType.getType() == DataTypes.DOUBLE || |
|
813 |
dataType.getType() == DataTypes.FLOAT) { |
|
814 |
// TODO Improve this? |
|
815 |
// Half of the size dedicated |
|
816 |
// to precision (at least 1) |
|
817 |
efad1.setPrecision(Math.max(1, fieldLength/2)); |
|
818 |
} |
|
819 |
|
|
725 | 820 |
if (dataType.getType() == DataTypes.GEOMETRY) { |
726 |
efad1.setGeometryType(((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYTYPE)).type); |
|
727 |
efad1.setGeometrySubType(((ComboItemGeomType) tm.getValueAt(i, |
|
728 |
COLUMN_GEOMETRYSUBTYPE)).type); |
|
821 |
|
|
822 |
int g_type = ((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYTYPE)).type; |
|
823 |
int g_subtype = ((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYSUBTYPE)).type; |
|
824 |
|
|
825 |
GeometryType gty = null; |
|
826 |
|
|
827 |
try { |
|
828 |
gty = gm.getGeometryType(g_type, g_subtype); |
|
829 |
efad1.setGeometryType(gty); |
|
830 |
// efad1.setGeometryType(g_type); |
|
831 |
} catch (Exception ex) { |
|
832 |
String _msg = Messages.getText("_Invalid_geometry_type") |
|
833 |
+ " (" + g_type + ", " + g_subtype + ")"; |
|
834 |
throw new NotContinueWizardException(_msg, ex, this); |
|
835 |
} |
|
836 |
|
|
729 | 837 |
efad1.setIsPrimaryKey(((Boolean) tm.getValueAt(i, COLUMN_PRIMARYKEY)) |
730 | 838 |
.booleanValue()); |
731 | 839 |
efad1.setAllowNull(!((Boolean) tm.getValueAt(i, COLUMN_MANDATORY)) |
732 | 840 |
.booleanValue()); |
733 | 841 |
efad1.setSRS((IProjection) tm.getValueAt(i, COLUMN_CRS)); |
842 |
|
|
734 | 843 |
//If there is not a previous default geometry field, add it |
735 |
if (featureType.getDefaultGeometryAttribute() == null){ |
|
736 |
featureType.setDefaultGeometryAttributeName(efad1.getName()); |
|
844 |
// this will set the first geometry field |
|
845 |
// as the default geometry field |
|
846 |
if (edft.getDefaultGeometryAttribute() == null){ |
|
847 |
edft.setDefaultGeometryAttributeName(efad1.getName()); |
|
737 | 848 |
} |
738 | 849 |
} |
739 | 850 |
} |
... | ... | |
766 | 877 |
public JPanel getJPanel() { |
767 | 878 |
return this; |
768 | 879 |
} |
880 |
|
|
881 |
/** |
|
882 |
* If fad is null, it's an addition after user has clicked on 'Add field'. |
|
883 |
* If fad is not null, it's the description of a default field and the |
|
884 |
* field name will also be taken from there. |
|
885 |
* |
|
886 |
* @param the_table |
|
887 |
* @param new_fld_name |
|
888 |
* @param the_projection |
|
889 |
* @param fad |
|
890 |
* |
|
891 |
* @return true if field was actually added, false otherwise |
|
892 |
*/ |
|
893 |
private boolean addRowToFieldTable( |
|
894 |
JTable the_table, |
|
895 |
String new_fld_name, |
|
896 |
IProjection the_projection, |
|
897 |
FeatureAttributeDescriptor fad) { |
|
898 |
|
|
899 |
if (fad == null && new_fld_name == null) { |
|
900 |
logger.info("Error: unable to add field to table (no description and no name)"); |
|
901 |
return false; |
|
902 |
} |
|
903 |
|
|
904 |
DefaultTableModel the_tm = (DefaultTableModel) the_table.getModel(); |
|
905 |
Object[] newRow = new Object[the_tm.getColumnCount()]; |
|
906 |
|
|
907 |
/* |
|
908 |
tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD); |
|
909 |
tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE); |
|
910 |
tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH); |
|
911 |
tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE); |
|
912 |
tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE); |
|
913 |
tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS); |
|
914 |
tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY); |
|
915 |
tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY); |
|
916 |
*/ |
|
917 |
|
|
918 |
// =============================== name |
|
919 |
if (fad == null) { |
|
920 |
newRow[COLUMN_FIELD] = new_fld_name; |
|
921 |
} else { |
|
922 |
newRow[COLUMN_FIELD] = fad.getName(); |
|
923 |
} |
|
924 |
// ===================================== field type |
|
925 |
TableColumn typeColumn = the_table.getColumnModel().getColumn(COLUMN_TYPE); |
|
926 |
List supp_types = spFactory.getSupportedDataTypes(); |
|
927 |
|
|
928 |
DataManager daman = DALLocator.getDataManager(); |
|
929 |
List all_types = daman.getDataTypes(); |
|
930 |
|
|
931 |
|
|
932 |
ComboModelDataType model = null; |
|
933 |
if (fad == null) { |
|
934 |
|
|
935 |
// this is a user defined column, remove geometry if in default feattype |
|
936 |
if (defaultHasGeometry) { |
|
937 |
supp_types = removeGeometryType(supp_types); |
|
938 |
all_types = removeGeometryType(all_types); |
|
939 |
} |
|
940 |
|
|
941 |
if (supp_types != null && supp_types.size() > 0) { |
|
942 |
model = new ComboModelDataType( |
|
943 |
supp_types, |
|
944 |
((DataType) supp_types.get(0)).getType()); |
|
945 |
} else { |
|
946 |
model = new ComboModelDataType( |
|
947 |
all_types, |
|
948 |
((DataType) all_types.get(0)).getType()); |
|
949 |
} |
|
950 |
} else { |
|
951 |
model = new ComboModelDataType(supp_types, fad.getType()); |
|
952 |
} |
|
953 |
|
|
954 |
JComboBox comboBox = new JComboBox(model); |
|
955 |
typeColumn.setCellEditor(new DefaultCellEditor(comboBox)); |
|
956 |
newRow[COLUMN_TYPE] = model.getSelectedItem(); |
|
957 |
|
|
958 |
// ============================= width |
|
959 |
TableColumn widthColumn = |
|
960 |
the_table.getColumnModel().getColumn(COLUMN_LENGTH); |
|
961 |
if (fad == null) { |
|
962 |
newRow[COLUMN_LENGTH] = "20"; |
|
963 |
} else { |
|
964 |
newRow[COLUMN_LENGTH] = "" + fad.getSize(); |
|
965 |
} |
|
966 |
|
|
967 |
SimpleTextCellRenderer stcr = new SimpleTextCellRenderer(); |
|
968 |
widthColumn.setCellEditor(new DefaultCellEditor(new JTextField())); |
|
969 |
widthColumn.setCellRenderer(stcr); |
|
970 |
|
|
971 |
|
|
972 |
// ============================= geom type |
|
973 |
TableColumn geomTypeColumn = |
|
974 |
the_table.getColumnModel().getColumn(COLUMN_GEOMETRYTYPE); |
|
975 |
ComboModelGeomType geomTypeModel = null; |
|
976 |
|
|
977 |
List<ComboItemGeomType> supptd = |
|
978 |
leaveSupportedGeomTypes(getGeomTypes(), |
|
979 |
spFactory.getSupportedGeometryTypesSubtypes(), 0); |
|
980 |
|
|
981 |
if (fad == null) { |
|
982 |
geomTypeModel = new ComboModelGeomType( |
|
983 |
supptd, supptd.size() > 0 ? supptd.get(0).getGeomType() : -1); |
|
984 |
} else { |
|
985 |
geomTypeModel = new ComboModelGeomType( |
|
986 |
supptd, fad.getGeomType().getType()); |
|
987 |
} |
|
988 |
|
|
989 |
JComboBox geomTypeComboBox = new JComboBox(geomTypeModel); |
|
990 |
geomTypeColumn.setCellEditor(new DefaultCellEditor(geomTypeComboBox)); |
|
991 |
|
|
992 |
GeometryComboCellRenderer gccr = new GeometryComboCellRenderer(); |
|
993 |
geomTypeColumn.setCellRenderer(gccr); |
|
994 |
newRow[COLUMN_GEOMETRYTYPE] = geomTypeModel.getSelectedItem(); |
|
995 |
|
|
996 |
// ============================= geom sub type |
|
997 |
|
|
998 |
TableColumn geomSubTypeColumn = |
|
999 |
the_table.getColumnModel().getColumn(COLUMN_GEOMETRYSUBTYPE); |
|
1000 |
ComboModelGeomType geomSubTypeModel = null; |
|
1001 |
|
|
1002 |
supptd = |
|
1003 |
leaveSupportedGeomTypes(getGeomSubtypes(), |
|
1004 |
spFactory.getSupportedGeometryTypesSubtypes(), 1); |
|
1005 |
|
|
1006 |
if (fad == null) { |
|
1007 |
geomSubTypeModel = new ComboModelGeomType( |
|
1008 |
supptd, supptd.size() > 0 ? supptd.get(0).getGeomType() : -1); |
|
1009 |
} else { |
|
1010 |
geomSubTypeModel = new ComboModelGeomType( |
|
1011 |
supptd, fad.getGeomType().getSubType()); |
|
1012 |
} |
|
1013 |
|
|
1014 |
JComboBox geomSubTypeComboBox = new JComboBox(geomSubTypeModel); |
|
1015 |
geomSubTypeColumn.setCellEditor(new DefaultCellEditor( |
|
1016 |
geomSubTypeComboBox)); |
|
1017 |
geomSubTypeColumn.setCellRenderer(new GeometryComboCellRenderer()); |
|
1018 |
newRow[COLUMN_GEOMETRYSUBTYPE] = geomSubTypeModel.getSelectedItem(); |
|
1019 |
|
|
1020 |
// ============================= CRS |
|
1021 |
|
|
1022 |
TableColumn crsColumn = the_table.getColumnModel().getColumn(COLUMN_CRS); |
|
1023 |
crsColumn.setCellEditor(new ButtonEditor(new JCheckBox())); |
|
1024 |
CrsRenderer crsButtonRenderer = new CrsRenderer(); |
|
1025 |
crsColumn.setCellRenderer(crsButtonRenderer); |
|
1026 |
newRow[COLUMN_CRS] = the_projection; |
|
1027 |
|
|
1028 |
// ============================= PK |
|
1029 |
|
|
1030 |
TableColumn primaryKeyColumn = |
|
1031 |
the_table.getColumnModel().getColumn(COLUMN_PRIMARYKEY); |
|
1032 |
JCheckBox primaryKeyCheckBox = new JCheckBox(); |
|
1033 |
|
|
1034 |
if (fad == null) { |
|
1035 |
primaryKeyCheckBox.setSelected(false); |
|
1036 |
} else { |
|
1037 |
primaryKeyCheckBox.setSelected(fad.isPrimaryKey()); |
|
1038 |
} |
|
1039 |
|
|
1040 |
primaryKeyColumn.setCellEditor( |
|
1041 |
new DefaultCellEditor(primaryKeyCheckBox)); |
|
1042 |
CheckBoxRenderer primaryKeyCheckBoxRenderer = new CheckBoxRenderer(); |
|
1043 |
primaryKeyColumn.setCellRenderer(primaryKeyCheckBoxRenderer); |
|
1044 |
newRow[COLUMN_PRIMARYKEY] = primaryKeyCheckBox.isSelected(); |
|
1045 |
|
|
1046 |
// ================================== mandatory |
|
1047 |
|
|
1048 |
TableColumn mandatoryColumn = |
|
1049 |
the_table.getColumnModel().getColumn(COLUMN_MANDATORY); |
|
1050 |
JCheckBox mandatoryCheckBox = new JCheckBox(); |
|
1051 |
|
|
1052 |
if (fad == null) { |
|
1053 |
mandatoryCheckBox.setSelected(false); |
|
1054 |
} else { |
|
1055 |
mandatoryCheckBox.setSelected(fad.isMandatory()); |
|
1056 |
} |
|
1057 |
|
|
1058 |
mandatoryColumn.setCellEditor(new DefaultCellEditor(mandatoryCheckBox)); |
|
1059 |
CheckBoxRenderer mandatoryCheckBoxRenderer = new CheckBoxRenderer(); |
|
1060 |
mandatoryColumn.setCellRenderer(mandatoryCheckBoxRenderer); |
|
1061 |
newRow[COLUMN_MANDATORY] = mandatoryCheckBox.isSelected(); |
|
1062 |
|
|
1063 |
// ================================== |
|
1064 |
|
|
1065 |
// Add a new row |
|
1066 |
the_tm.addRow(newRow); |
|
1067 |
return true; |
|
1068 |
} |
|
1069 |
|
|
1070 |
/** |
|
1071 |
* @param supp_types |
|
1072 |
* @return |
|
1073 |
*/ |
|
1074 |
private List removeGeometryType(List dta_types) { |
|
1075 |
List resp = new ArrayList(); |
|
1076 |
|
|
1077 |
int len = dta_types.size(); |
|
1078 |
Object item_o = null; |
|
1079 |
DataType item_dt = null; |
|
1080 |
|
|
1081 |
for (int i=0; i<len; i++) { |
|
1082 |
item_o = dta_types.get(i); |
|
1083 |
if (item_o instanceof DataType) { |
|
1084 |
item_dt = (DataType) item_o; |
|
1085 |
if (item_dt.getType() != DataTypes.GEOMETRY) { |
|
1086 |
resp.add(item_dt); |
|
1087 |
} |
|
1088 |
} |
|
1089 |
} |
|
1090 |
return resp; |
|
1091 |
} |
|
1092 |
|
|
1093 |
private List<ComboItemGeomType> leaveSupportedGeomTypes( |
|
1094 |
List<ComboItemGeomType> all_types, |
|
1095 |
List<int[]> supported, |
|
1096 |
int index /* 0 for geom types, 1 for geom subtypes */) { |
|
1097 |
|
|
1098 |
List<ComboItemGeomType> resp = new ArrayList<ComboItemGeomType>(); |
|
1099 |
int len = all_types.size(); |
|
1100 |
ComboItemGeomType item = null; |
|
1101 |
for (int i=0; i<len; i++) { |
|
1102 |
item = all_types.get(i); |
|
1103 |
if (isInNthElement(item.getGeomType(), supported, index)) { |
|
1104 |
resp.add(item); |
|
1105 |
} |
|
1106 |
} |
|
1107 |
return resp; |
|
1108 |
} |
|
1109 |
|
|
1110 |
|
|
1111 |
private boolean isInNthElement(int val, List<int[]> arr_list, int index) { |
|
1112 |
|
|
1113 |
int len = arr_list.size(); |
|
1114 |
int[] item = null; |
|
1115 |
for (int i=0; i<len; i++) { |
|
1116 |
item = arr_list.get(i); |
|
1117 |
if (item != null && item.length > index && item[index] == val) { |
|
1118 |
return true; |
|
1119 |
} |
|
1120 |
} |
|
1121 |
return false; |
|
1122 |
} |
|
1123 |
|
|
1124 |
private boolean dataTypeNeedsSize(int data_type) { |
|
1125 |
|
|
1126 |
if (data_type == DataTypes.FLOAT |
|
1127 |
|| data_type == DataTypes.INT |
|
1128 |
|| data_type == DataTypes.STRING) { |
|
1129 |
return true; |
|
1130 |
} else { |
|
1131 |
return false; |
|
1132 |
} |
|
1133 |
} |
|
1134 |
|
|
1135 |
private class SimpleTextCellRenderer extends DefaultTableCellRenderer { |
|
1136 |
|
|
1137 |
public SimpleTextCellRenderer() { |
|
1138 |
super(); |
|
1139 |
} |
|
1140 |
/* (non-Javadoc) |
|
1141 |
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) |
|
1142 |
*/ |
|
1143 |
public Component getTableCellRendererComponent( |
|
1144 |
JTable table, |
|
1145 |
Object value, boolean isSelected, boolean hasFocus, int row, |
|
1146 |
int column) { |
|
1147 |
|
|
1148 |
TableModel tm = table.getModel(); |
|
1149 |
Object new_val = ""; |
|
1150 |
Object type_obj = tm.getValueAt(row, COLUMN_TYPE); |
|
1151 |
if (type_obj instanceof ComboItemDataType) { |
|
1152 |
ComboItemDataType type_item = (ComboItemDataType) type_obj; |
|
1153 |
if (dataTypeNeedsSize(type_item.dataType.getType())) { |
|
1154 |
new_val = getCurrentOr(value, ""); |
|
1155 |
} else { |
|
1156 |
new_val = Messages.getText("not_applicable"); |
|
1157 |
} |
|
1158 |
return super.getTableCellRendererComponent( |
|
1159 |
table, new_val, isSelected, hasFocus, row, column); |
|
1160 |
} else { |
|
1161 |
return super.getTableCellRendererComponent( |
|
1162 |
table, value, isSelected, hasFocus, row, column); |
|
1163 |
} |
|
1164 |
} |
|
1165 |
|
|
1166 |
private Object getCurrentOr(Object v, String d) { |
|
1167 |
|
|
1168 |
if (v instanceof String) { |
|
1169 |
String parse_str = (String) v; |
|
1170 |
try { |
|
1171 |
Integer.parseInt(parse_str); |
|
1172 |
return v; |
|
1173 |
} catch (Exception ex) { |
|
1174 |
// not a valid integer |
|
1175 |
return d; |
|
1176 |
} |
|
1177 |
} else { |
|
1178 |
return v; |
|
1179 |
} |
|
1180 |
} |
|
1181 |
|
|
1182 |
} |
|
1183 |
|
|
1184 |
private class EnableLengthItemListener implements ItemListener { |
|
1185 |
|
|
1186 |
private TableModel theTableModel = null; |
|
1187 |
private JTable theTable = null; |
|
1188 |
|
|
1189 |
public EnableLengthItemListener(JTable t, boolean b) { |
|
1190 |
theTable = t; |
|
1191 |
theTableModel = t.getModel(); |
|
1192 |
} |
|
1193 |
|
|
1194 |
public void itemStateChanged(final ItemEvent e) { |
|
1195 |
doUpdate(e); |
|
1196 |
} |
|
1197 |
|
|
1198 |
public void doUpdate(ItemEvent e) { |
|
1199 |
|
|
1200 |
Object src_obj = e.getSource(); |
|
1201 |
if (src_obj instanceof JComboBox) { |
|
1202 |
|
|
1203 |
// one of the field type combos has changed |
|
1204 |
int len = theTableModel.getRowCount(); |
|
1205 |
Object type_obj = null; |
|
1206 |
ComboItemDataType type_item = null; |
|
1207 |
for (int i=0; i<len; i++) { |
|
1208 |
type_obj = theTableModel.getValueAt(i, COLUMN_TYPE); |
|
1209 |
if (type_obj instanceof ComboItemDataType) { |
|
1210 |
type_item = (ComboItemDataType) type_obj; |
|
1211 |
if (dataTypeNeedsSize(type_item.dataType.getType())) { |
|
1212 |
theTableModel.setValueAt( |
|
1213 |
"20", |
|
1214 |
i, COLUMN_LENGTH); |
|
1215 |
} else { |
|
1216 |
theTableModel.setValueAt( |
|
1217 |
Messages.getText("not_applicable"), |
|
1218 |
i, COLUMN_LENGTH); |
|
1219 |
} |
|
1220 |
} |
|
1221 |
} |
|
1222 |
theTable.validate(); // .revalidate(); // .repaint(); |
|
1223 |
} |
|
1224 |
} |
|
1225 |
|
|
1226 |
} |
|
1227 |
|
|
1228 |
|
|
1229 |
|
|
1230 |
|
|
1231 |
|
|
769 | 1232 |
} |
Also available in: Unified diff