Revision 37807 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 | ||
---|---|---|
22 | 22 |
import javax.swing.event.ListDataListener; |
23 | 23 |
import javax.swing.event.ListSelectionEvent; |
24 | 24 |
import javax.swing.event.ListSelectionListener; |
25 |
import javax.swing.event.TableModelEvent; |
|
26 |
import javax.swing.event.TableModelListener; |
|
25 | 27 |
import javax.swing.table.DefaultTableModel; |
26 | 28 |
import javax.swing.table.TableCellRenderer; |
27 | 29 |
import javax.swing.table.TableColumn; |
28 | 30 |
|
29 | 31 |
import org.cresques.cts.IProjection; |
32 |
import org.slf4j.Logger; |
|
33 |
import org.slf4j.LoggerFactory; |
|
34 |
|
|
30 | 35 |
import org.gvsig.app.gui.panels.CRSSelectPanel; |
31 | 36 |
import org.gvsig.app.gui.panels.crs.ISelectCrsPanel; |
32 | 37 |
import org.gvsig.fmap.dal.DALLocator; |
... | ... | |
46 | 51 |
import org.gvsig.tools.dataTypes.DataType; |
47 | 52 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
48 | 53 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
49 |
import org.slf4j.Logger; |
|
50 |
import org.slf4j.LoggerFactory; |
|
51 | 54 |
|
52 | 55 |
public class FeatureTypePanel extends JPanel implements OptionPanel { |
53 |
|
|
54 |
/** |
|
55 |
* |
|
56 |
*/ |
|
56 |
private static final int COLUMN_FIELD = 0; |
|
57 |
private static final int COLUMN_TYPE = 1; |
|
58 |
private static final int COLUMN_LENGTH = 2; |
|
59 |
private static final int COLUMN_GEOMETRYTYPE = 3; |
|
60 |
private static final int COLUMN_GEOMETRYSUBTYPE = 4; |
|
61 |
private static final int COLUMN_CRS = 5; |
|
62 |
private static final int COLUMN_PRIMARYKEY = 6; |
|
63 |
private static final int COLUMN_MANDATORY = 7; |
|
64 |
|
|
57 | 65 |
private static final long serialVersionUID = 263541873998597624L; |
58 | 66 |
private NewLayerWizard wizard; |
59 | 67 |
private static final Logger logger = LoggerFactory |
... | ... | |
106 | 114 |
*/ |
107 | 115 |
private JTable getJTable() { |
108 | 116 |
if (jTable == null) { |
109 |
jTable = new JTable(); |
|
117 |
jTable = new JTable(){ |
|
118 |
public boolean isCellEditable(int row,int column){ |
|
119 |
Object o = getValueAt(row,column); |
|
120 |
|
|
121 |
if ((column == COLUMN_GEOMETRYTYPE) || |
|
122 |
(column == COLUMN_GEOMETRYSUBTYPE) || |
|
123 |
(column == COLUMN_CRS)) { |
|
124 |
DataType dataType = |
|
125 |
((ComboItemDataType) getValueAt(row, COLUMN_TYPE)).dataType; |
|
126 |
return dataType.getType() == DataTypes.GEOMETRY; |
|
127 |
} |
|
128 |
return true; |
|
129 |
} |
|
130 |
}; |
|
110 | 131 |
|
111 | 132 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
112 | 133 |
tm.addColumn(Messages.getText("field")); |
... | ... | |
133 | 154 |
jButtonDeleteField.setEnabled(false); |
134 | 155 |
} else { |
135 | 156 |
jButtonDeleteField.setEnabled(true); |
136 |
} |
|
157 |
}
|
|
137 | 158 |
} |
138 | 159 |
}); |
139 | 160 |
jTable.getColumn(Messages.getText("field")).setWidth(180); |
140 | 161 |
|
162 |
jTable.getModel().addTableModelListener(new TableModelListener() { |
|
163 |
public void tableChanged(TableModelEvent e) { |
|
164 |
if (e.getColumn() == COLUMN_TYPE){ |
|
165 |
jTable.repaint(); |
|
166 |
} |
|
167 |
} |
|
168 |
}); |
|
169 |
|
|
141 | 170 |
// Rellenado de la tabla |
142 | 171 |
EditableFeatureType featureType = this.wizard.getService() |
143 | 172 |
.getFeatureType(); |
... | ... | |
148 | 177 |
while (it.hasNext()) { |
149 | 178 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) it |
150 | 179 |
.next(); |
151 |
tm.setValueAt(descriptor.getName(), row, 0);
|
|
152 |
tm.setValueAt(descriptor.getType(), row, 1);
|
|
153 |
tm.setValueAt(descriptor.getSize(), row, 2);
|
|
154 |
tm.setValueAt(descriptor.getGeometryType(), row, 3);
|
|
155 |
tm.setValueAt(descriptor.getGeometrySubType(), row, 4);
|
|
156 |
tm.setValueAt(descriptor.getSRS(), row, 5);
|
|
157 |
tm.setValueAt(descriptor.isPrimaryKey(), row, 6);
|
|
158 |
tm.setValueAt(descriptor.isMandatory(), row, 7);
|
|
159 |
row++; |
|
180 |
tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD);
|
|
181 |
tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE);
|
|
182 |
tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH);
|
|
183 |
tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE);
|
|
184 |
tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE);
|
|
185 |
tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS);
|
|
186 |
tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY);
|
|
187 |
tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY);
|
|
188 |
row++;
|
|
160 | 189 |
} |
161 | 190 |
} |
162 | 191 |
|
... | ... | |
202 | 231 |
// Figure out a suitable field name |
203 | 232 |
ArrayList fieldNames = new ArrayList(); |
204 | 233 |
for (int i = 0; i < jTable.getRowCount(); i++) { |
205 |
fieldNames.add(tm.getValueAt(i, 0));
|
|
234 |
fieldNames.add(tm.getValueAt(i, COLUMN_FIELD));
|
|
206 | 235 |
} |
207 | 236 |
String[] currentFieldNames = (String[]) fieldNames |
208 | 237 |
.toArray(new String[0]); |
... | ... | |
226 | 255 |
// no hace caso. (Por eso no |
227 | 256 |
// lo pongo en getJTable() |
228 | 257 |
TableColumn typeColumn = jTable.getColumnModel() |
229 |
.getColumn(1);
|
|
258 |
.getColumn(COLUMN_TYPE);
|
|
230 | 259 |
DataManager dataManager = DALLocator |
231 | 260 |
.getDataManager(); |
232 | 261 |
ComboModelDataType model = new ComboModelDataType( |
... | ... | |
236 | 265 |
comboBox)); |
237 | 266 |
|
238 | 267 |
TableColumn widthColumn = jTable.getColumnModel() |
239 |
.getColumn(2);
|
|
268 |
.getColumn(COLUMN_LENGTH);
|
|
240 | 269 |
|
241 | 270 |
TableColumn geomTypeColumn = jTable |
242 |
.getColumnModel().getColumn(3);
|
|
271 |
.getColumnModel().getColumn(COLUMN_GEOMETRYTYPE);
|
|
243 | 272 |
ComboModelGeomType geomTypeModel = new ComboModelGeomType( |
244 | 273 |
getGeomTypes()); |
245 | 274 |
JComboBox geomTypeComboBox = new JComboBox( |
246 | 275 |
geomTypeModel); |
247 | 276 |
geomTypeColumn.setCellEditor(new DefaultCellEditor( |
248 | 277 |
geomTypeComboBox)); |
278 |
geomTypeColumn.setCellRenderer(new GeometryComboCellRenderer()); |
|
279 |
|
|
249 | 280 |
|
250 | 281 |
TableColumn geomSubTypeColumn = jTable |
251 |
.getColumnModel().getColumn(4);
|
|
282 |
.getColumnModel().getColumn(COLUMN_GEOMETRYSUBTYPE);
|
|
252 | 283 |
ComboModelGeomType geomSubTypeModel = new ComboModelGeomType( |
253 | 284 |
getGeomSubtypes()); |
254 | 285 |
JComboBox geomSubTypeComboBox = new JComboBox( |
... | ... | |
256 | 287 |
geomSubTypeColumn |
257 | 288 |
.setCellEditor(new DefaultCellEditor( |
258 | 289 |
geomSubTypeComboBox)); |
290 |
geomSubTypeColumn.setCellRenderer(new GeometryComboCellRenderer()); |
|
259 | 291 |
|
260 | 292 |
TableColumn crsColumn = jTable.getColumnModel() |
261 |
.getColumn(5);
|
|
293 |
.getColumn(COLUMN_CRS);
|
|
262 | 294 |
crsColumn.setCellEditor(new ButtonEditor( |
263 | 295 |
new JCheckBox())); |
264 |
ButtonRenderer crsButtonRenderer = new ButtonRenderer();
|
|
296 |
CrsRenderer crsButtonRenderer = new CrsRenderer();
|
|
265 | 297 |
crsColumn.setCellRenderer(crsButtonRenderer); |
266 | 298 |
|
267 | 299 |
TableColumn primaryKeyColumn = jTable |
268 |
.getColumnModel().getColumn(6);
|
|
300 |
.getColumnModel().getColumn(COLUMN_PRIMARYKEY);
|
|
269 | 301 |
JCheckBox primaryKeyCheckBox = new JCheckBox(); |
270 | 302 |
primaryKeyColumn |
271 | 303 |
.setCellEditor(new DefaultCellEditor( |
... | ... | |
275 | 307 |
.setCellRenderer(primaryKeyCheckBoxRenderer); |
276 | 308 |
|
277 | 309 |
TableColumn mandatoryColumn = jTable |
278 |
.getColumnModel().getColumn(7);
|
|
310 |
.getColumnModel().getColumn(COLUMN_MANDATORY);
|
|
279 | 311 |
JCheckBox mandatoryCheckBox = new JCheckBox(); |
280 | 312 |
mandatoryColumn |
281 | 313 |
.setCellEditor(new DefaultCellEditor( |
... | ... | |
286 | 318 |
|
287 | 319 |
// Add a new row |
288 | 320 |
Object[] newRow = new Object[tm.getColumnCount()]; |
289 |
newRow[0] = newFieldName;
|
|
290 |
newRow[1] = model.getElementAt(0);
|
|
291 |
newRow[2] = "20";
|
|
292 |
newRow[3] = geomTypeModel.getElementAt(0);
|
|
293 |
newRow[4] = geomSubTypeModel.getElementAt(0);
|
|
321 |
newRow[COLUMN_FIELD] = newFieldName;
|
|
322 |
newRow[COLUMN_TYPE] = model.getElementAt(0);
|
|
323 |
newRow[COLUMN_LENGTH] = "20";
|
|
324 |
newRow[COLUMN_GEOMETRYTYPE] = geomTypeModel.getElementAt(0);
|
|
325 |
newRow[COLUMN_GEOMETRYSUBTYPE] = geomSubTypeModel.getElementAt(0);
|
|
294 | 326 |
// Por defecto, la proyeccion de la vista |
295 |
newRow[5] = wizard.getService().getMapContext()
|
|
327 |
newRow[COLUMN_CRS] = wizard.getService().getMapContext()
|
|
296 | 328 |
.getProjection(); |
297 |
newRow[6] = primaryKeyCheckBox.isSelected();
|
|
298 |
newRow[7] = mandatoryCheckBox.isSelected();
|
|
299 |
tm.addRow(newRow); |
|
329 |
newRow[COLUMN_PRIMARYKEY] = primaryKeyCheckBox.isSelected();
|
|
330 |
newRow[COLUMN_MANDATORY] = mandatoryCheckBox.isSelected();
|
|
331 |
tm.addRow(newRow);
|
|
300 | 332 |
} |
301 | 333 |
}); |
302 | 334 |
|
... | ... | |
367 | 399 |
|
368 | 400 |
} |
369 | 401 |
|
370 |
class ButtonRenderer extends JButton implements TableCellRenderer { |
|
371 |
|
|
372 |
/** |
|
373 |
* |
|
374 |
*/ |
|
402 |
class CrsRenderer extends JButton implements TableCellRenderer { |
|
375 | 403 |
private static final long serialVersionUID = -573793294070515376L; |
376 |
|
|
377 |
public ButtonRenderer() { |
|
404 |
private JLabel label = null; |
|
405 |
|
|
406 |
public CrsRenderer() { |
|
378 | 407 |
setOpaque(true); |
408 |
label = new JLabel(Messages.getText("not_applicable")); |
|
379 | 409 |
} |
380 | 410 |
|
381 | 411 |
public Component getTableCellRendererComponent(JTable table, |
382 | 412 |
Object value, boolean isSelected, boolean hasFocus, int row, |
383 | 413 |
int column) { |
384 |
if (isSelected) { |
|
414 |
|
|
415 |
DataType dataType = |
|
416 |
((ComboItemDataType) table.getValueAt(row, COLUMN_TYPE)).dataType; |
|
417 |
|
|
418 |
if (dataType.getType() != DataTypes.GEOMETRY) { |
|
419 |
return label; |
|
420 |
} |
|
421 |
|
|
422 |
if (isSelected) { |
|
385 | 423 |
setForeground(table.getSelectionForeground()); |
386 | 424 |
setBackground(table.getSelectionBackground()); |
387 | 425 |
} else { |
... | ... | |
391 | 429 |
setText((value == null) ? "" : ((IProjection) value).getFullCode()); |
392 | 430 |
return this; |
393 | 431 |
} |
394 |
} |
|
432 |
} |
|
433 |
|
|
434 |
private class GeometryComboCellRenderer extends JLabel implements TableCellRenderer{ |
|
395 | 435 |
|
436 |
public Component getTableCellRendererComponent(JTable table, |
|
437 |
Object value, boolean isSelected, boolean hasFocus, int row, |
|
438 |
int column) { |
|
439 |
|
|
440 |
DataType dataType = |
|
441 |
((ComboItemDataType) table.getValueAt(row, COLUMN_TYPE)).dataType; |
|
442 |
|
|
443 |
if (dataType.getType() == DataTypes.GEOMETRY) { |
|
444 |
ComboItemGeomType geomType = (ComboItemGeomType)value; |
|
445 |
if (geomType != null) { |
|
446 |
this.setText(geomType.toString()); |
|
447 |
} |
|
448 |
} else { |
|
449 |
this.setText(Messages.getText("not_applicable")); |
|
450 |
} |
|
451 |
|
|
452 |
return this; |
|
453 |
} |
|
454 |
|
|
455 |
} |
|
456 |
|
|
396 | 457 |
class ButtonEditor extends DefaultCellEditor { |
397 | 458 |
/** |
398 | 459 |
* |
... | ... | |
627 | 688 |
|
628 | 689 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
629 | 690 |
for (int i = 0; i < tm.getRowCount(); i++) { |
630 |
DataType dataType = ((ComboItemDataType) tm.getValueAt(i, 1)).dataType;
|
|
691 |
DataType dataType = ((ComboItemDataType) tm.getValueAt(i, COLUMN_TYPE)).dataType;
|
|
631 | 692 |
|
632 |
int fieldLength = Integer.parseInt((String) tm.getValueAt(i, 2));
|
|
693 |
int fieldLength = Integer.parseInt((String) tm.getValueAt(i, COLUMN_LENGTH));
|
|
633 | 694 |
// TODO: HACERLO BIEN |
634 | 695 |
if (dataType.getType() == DataTypes.DOUBLE) { |
635 | 696 |
fieldLength = 5; |
636 | 697 |
} |
637 | 698 |
// FIXME: Arreglar lo que pasa si en el siguiente panel volvemos |
638 | 699 |
// hacia atras, y en este volvemos a ir hacia adelante |
639 |
String fieldName = (String) tm.getValueAt(i, 0);
|
|
700 |
String fieldName = (String) tm.getValueAt(i, COLUMN_FIELD);
|
|
640 | 701 |
EditableFeatureAttributeDescriptor attrDescriptor = (EditableFeatureAttributeDescriptor) featureType |
641 | 702 |
.getAttributeDescriptor(fieldName); |
642 | 703 |
if (attrDescriptor != null) { |
643 | 704 |
featureType.remove(attrDescriptor); |
644 | 705 |
} |
645 | 706 |
EditableFeatureAttributeDescriptor efad1 = featureType.add( |
646 |
(String) tm.getValueAt(i, 0), dataType.getType(),
|
|
707 |
(String) tm.getValueAt(i, COLUMN_FIELD), dataType.getType(),
|
|
647 | 708 |
fieldLength); |
648 | 709 |
if (dataType.getType() == DataTypes.GEOMETRY) { |
649 |
efad1.setGeometryType(((ComboItemGeomType) tm.getValueAt(i, 3)).type);
|
|
710 |
efad1.setGeometryType(((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYTYPE)).type);
|
|
650 | 711 |
efad1.setGeometrySubType(((ComboItemGeomType) tm.getValueAt(i, |
651 |
4)).type);
|
|
652 |
efad1.setIsPrimaryKey(((Boolean) tm.getValueAt(i, 6))
|
|
712 |
COLUMN_GEOMETRYSUBTYPE)).type);
|
|
713 |
efad1.setIsPrimaryKey(((Boolean) tm.getValueAt(i, COLUMN_PRIMARYKEY))
|
|
653 | 714 |
.booleanValue()); |
654 |
efad1.setAllowNull(!((Boolean) tm.getValueAt(i, 7))
|
|
715 |
efad1.setAllowNull(!((Boolean) tm.getValueAt(i, COLUMN_MANDATORY))
|
|
655 | 716 |
.booleanValue()); |
656 |
efad1.setSRS((IProjection) tm.getValueAt(i, 5));
|
|
717 |
efad1.setSRS((IProjection) tm.getValueAt(i, COLUMN_CRS));
|
|
657 | 718 |
//If there is not a previous default geometry field, add it |
658 | 719 |
if (featureType.getDefaultGeometryAttribute() == null){ |
659 | 720 |
featureType.setDefaultGeometryAttributeName(efad1.getName()); |
660 |
} |
|
721 |
}
|
|
661 | 722 |
} |
662 | 723 |
} |
663 | 724 |
} |
... | ... | |
675 | 736 |
public JPanel getJPanel() { |
676 | 737 |
return this; |
677 | 738 |
} |
678 |
|
|
679 | 739 |
} |
Also available in: Unified diff