root / 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 @ 38367
History | View | Annotate | Download (24 KB)
1 | 36022 | fdiaz | package org.gvsig.newlayer.impl; |
---|---|---|---|
2 | |||
3 | import java.awt.BorderLayout; |
||
4 | 36721 | fdiaz | import java.awt.Component; |
5 | import java.awt.event.ActionEvent; |
||
6 | import java.awt.event.ActionListener; |
||
7 | 36022 | fdiaz | import java.util.ArrayList; |
8 | import java.util.Iterator; |
||
9 | 36220 | fdiaz | import java.util.List; |
10 | 36022 | fdiaz | |
11 | 36721 | fdiaz | import javax.swing.ComboBoxModel; |
12 | 36022 | fdiaz | import javax.swing.DefaultCellEditor; |
13 | import javax.swing.JButton; |
||
14 | 36721 | fdiaz | import javax.swing.JCheckBox; |
15 | 36022 | fdiaz | import javax.swing.JComboBox; |
16 | import javax.swing.JLabel; |
||
17 | import javax.swing.JPanel; |
||
18 | import javax.swing.JScrollPane; |
||
19 | import javax.swing.JTable; |
||
20 | import javax.swing.ListSelectionModel; |
||
21 | 36721 | fdiaz | import javax.swing.UIManager; |
22 | import javax.swing.event.ListDataListener; |
||
23 | 36022 | fdiaz | import javax.swing.event.ListSelectionEvent; |
24 | import javax.swing.event.ListSelectionListener; |
||
25 | 37807 | jpiera | import javax.swing.event.TableModelEvent; |
26 | import javax.swing.event.TableModelListener; |
||
27 | 36022 | fdiaz | import javax.swing.table.DefaultTableModel; |
28 | 36721 | fdiaz | import javax.swing.table.TableCellRenderer; |
29 | 36022 | fdiaz | import javax.swing.table.TableColumn; |
30 | |||
31 | 36721 | fdiaz | import org.cresques.cts.IProjection; |
32 | 37807 | jpiera | import org.slf4j.Logger; |
33 | import org.slf4j.LoggerFactory; |
||
34 | |||
35 | 36721 | fdiaz | import org.gvsig.app.gui.panels.CRSSelectPanel; |
36 | import org.gvsig.app.gui.panels.crs.ISelectCrsPanel; |
||
37 | import org.gvsig.fmap.dal.DALLocator; |
||
38 | import org.gvsig.fmap.dal.DataManager; |
||
39 | 36022 | fdiaz | import org.gvsig.fmap.dal.DataServerExplorer; |
40 | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
||
41 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
42 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
43 | 37333 | fdiaz | import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
44 | 36721 | fdiaz | import org.gvsig.fmap.geom.DataTypes; |
45 | import org.gvsig.fmap.geom.Geometry; |
||
46 | 36022 | fdiaz | import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
47 | import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
||
48 | import org.gvsig.i18n.Messages; |
||
49 | 36721 | fdiaz | import org.gvsig.newlayer.NewLayerService; |
50 | 36022 | fdiaz | import org.gvsig.newlayer.NewLayerWizard; |
51 | 36721 | fdiaz | import org.gvsig.tools.dataTypes.DataType; |
52 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
53 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
54 | 36022 | fdiaz | |
55 | 36721 | fdiaz | public class FeatureTypePanel extends JPanel implements OptionPanel { |
56 | 37807 | jpiera | 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 | |||
65 | 36022 | fdiaz | private static final long serialVersionUID = 263541873998597624L; |
66 | private NewLayerWizard wizard;
|
||
67 | 36721 | fdiaz | private static final Logger logger = LoggerFactory |
68 | .getLogger(FeatureTypePanel.class); |
||
69 | 36022 | fdiaz | |
70 | private JLabel jLabel = null; |
||
71 | private JScrollPane jScrollPane = null; |
||
72 | protected JTable jTable = null; |
||
73 | private JPanel jPanelEast = null; |
||
74 | private JButton jButtonAddField = null; |
||
75 | private JButton jButtonDeleteField = null; |
||
76 | protected int MAX_FIELD_LENGTH = 254; |
||
77 | 38367 | jldominguez | |
78 | // we dont need this list
|
||
79 | // we'll clear and rebuild featureType each time
|
||
80 | // the user clicks next
|
||
81 | // private List removedFields;
|
||
82 | 36022 | fdiaz | |
83 | private DataServerExplorer explorer = null; |
||
84 | |||
85 | 36721 | fdiaz | public FeatureTypePanel(NewLayerWizard wizard) {
|
86 | 36022 | fdiaz | this.wizard = wizard;
|
87 | } |
||
88 | |||
89 | 36721 | fdiaz | private void initializeComponents() { |
90 | jLabel = new JLabel(); |
||
91 | jLabel.setText(Messages.getText("define_fields"));
|
||
92 | this.setLayout(new BorderLayout(5, 5)); |
||
93 | this.setSize(new java.awt.Dimension(499, 232)); |
||
94 | this.add(jLabel, java.awt.BorderLayout.NORTH);
|
||
95 | this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
|
||
96 | this.add(getJPanelEast(), java.awt.BorderLayout.EAST);
|
||
97 | 36022 | fdiaz | |
98 | 36721 | fdiaz | } |
99 | |||
100 | 36022 | fdiaz | /**
|
101 | * This method initializes jScrollPane
|
||
102 | 36721 | fdiaz | *
|
103 | 36022 | fdiaz | * @return javax.swing.JScrollPane
|
104 | */
|
||
105 | private JScrollPane getJScrollPane() { |
||
106 | if (jScrollPane == null) { |
||
107 | jScrollPane = new JScrollPane(); |
||
108 | jScrollPane.setViewportView(getJTable()); |
||
109 | } |
||
110 | return jScrollPane;
|
||
111 | } |
||
112 | |||
113 | /**
|
||
114 | * This method initializes jTable
|
||
115 | 36721 | fdiaz | *
|
116 | 36022 | fdiaz | * @return javax.swing.JTable
|
117 | */
|
||
118 | private JTable getJTable() { |
||
119 | if (jTable == null) { |
||
120 | 37807 | jpiera | jTable = new JTable(){ |
121 | public boolean isCellEditable(int row,int column){ |
||
122 | Object o = getValueAt(row,column);
|
||
123 | |||
124 | if ((column == COLUMN_GEOMETRYTYPE) ||
|
||
125 | (column == COLUMN_GEOMETRYSUBTYPE) || |
||
126 | (column == COLUMN_CRS)) { |
||
127 | DataType dataType = |
||
128 | ((ComboItemDataType) getValueAt(row, COLUMN_TYPE)).dataType; |
||
129 | return dataType.getType() == DataTypes.GEOMETRY;
|
||
130 | } |
||
131 | return true; |
||
132 | } |
||
133 | }; |
||
134 | 36022 | fdiaz | |
135 | DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
||
136 | tm.addColumn(Messages.getText("field"));
|
||
137 | |||
138 | tm.addColumn(Messages.getText("type"));
|
||
139 | tm.addColumn(Messages.getText("length"));
|
||
140 | 36721 | fdiaz | tm.addColumn(Messages.getText("geomType"));
|
141 | tm.addColumn(Messages.getText("geomSubtype"));
|
||
142 | tm.addColumn(Messages.getText("CRS"));
|
||
143 | tm.addColumn(Messages.getText("primaryKey"));
|
||
144 | tm.addColumn(Messages.getText("mandatory"));
|
||
145 | 36022 | fdiaz | |
146 | 36721 | fdiaz | // Ask to be notified of selection changes.
|
147 | 36022 | fdiaz | ListSelectionModel rowSM = jTable.getSelectionModel();
|
148 | rowSM.addListSelectionListener(new ListSelectionListener() { |
||
149 | 36721 | fdiaz | public void valueChanged(ListSelectionEvent e) { |
150 | // Ignore extra messages.
|
||
151 | if (e.getValueIsAdjusting())
|
||
152 | return;
|
||
153 | 36022 | fdiaz | |
154 | 36721 | fdiaz | ListSelectionModel lsm = (ListSelectionModel) e.getSource(); |
155 | if (lsm.isSelectionEmpty()) {
|
||
156 | // no rows are selected
|
||
157 | jButtonDeleteField.setEnabled(false);
|
||
158 | } else {
|
||
159 | jButtonDeleteField.setEnabled(true);
|
||
160 | 37807 | jpiera | } |
161 | 36721 | fdiaz | } |
162 | 36022 | fdiaz | }); |
163 | jTable.getColumn(Messages.getText("field")).setWidth(180); |
||
164 | |||
165 | 37807 | jpiera | jTable.getModel().addTableModelListener(new TableModelListener() { |
166 | public void tableChanged(TableModelEvent e) { |
||
167 | if (e.getColumn() == COLUMN_TYPE){
|
||
168 | jTable.repaint(); |
||
169 | } |
||
170 | } |
||
171 | }); |
||
172 | |||
173 | 36721 | fdiaz | // Rellenado de la tabla
|
174 | EditableFeatureType featureType = this.wizard.getService()
|
||
175 | .getFeatureType(); |
||
176 | if (featureType != null) { |
||
177 | 36022 | fdiaz | int row = 0; |
178 | 37333 | fdiaz | tm.setRowCount(featureType.size()); |
179 | 36022 | fdiaz | Iterator it = featureType.iterator();
|
180 | while (it.hasNext()) {
|
||
181 | 36721 | fdiaz | FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) it |
182 | .next(); |
||
183 | 37807 | jpiera | tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD); |
184 | tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE); |
||
185 | tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH); |
||
186 | tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE); |
||
187 | tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE); |
||
188 | tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS); |
||
189 | tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY); |
||
190 | tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY); |
||
191 | row++; |
||
192 | 36022 | fdiaz | } |
193 | } |
||
194 | 36721 | fdiaz | |
195 | 36022 | fdiaz | } |
196 | 37333 | fdiaz | jTable.setEnabled(allowEditableFeatureType()); |
197 | 36022 | fdiaz | return jTable;
|
198 | } |
||
199 | |||
200 | /**
|
||
201 | * This method initializes jPanelWest
|
||
202 | 36721 | fdiaz | *
|
203 | 36022 | fdiaz | * @return javax.swing.JPanel
|
204 | */
|
||
205 | private JPanel getJPanelEast() { |
||
206 | if (jPanelEast == null) { |
||
207 | jPanelEast = new JPanel(); |
||
208 | jPanelEast.setLayout(null);
|
||
209 | 36721 | fdiaz | jPanelEast.setPreferredSize(new java.awt.Dimension(170, 100)); |
210 | 36022 | fdiaz | jPanelEast.add(getJButtonAddField(), null);
|
211 | jPanelEast.add(getJButtonDeleteField(), null);
|
||
212 | } |
||
213 | return jPanelEast;
|
||
214 | } |
||
215 | |||
216 | /**
|
||
217 | * This method initializes jButtonAddField
|
||
218 | 36721 | fdiaz | *
|
219 | 36022 | fdiaz | * @return javax.swing.JButton
|
220 | */
|
||
221 | private JButton getJButtonAddField() { |
||
222 | if (jButtonAddField == null) { |
||
223 | jButtonAddField = new JButton(); |
||
224 | jButtonAddField.setText(Messages.getText("add_field"));
|
||
225 | 36721 | fdiaz | 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 |
||
229 | .addActionListener(new java.awt.event.ActionListener() {
|
||
230 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
231 | DefaultTableModel tm = (DefaultTableModel) jTable |
||
232 | .getModel(); |
||
233 | 36022 | fdiaz | |
234 | 36721 | fdiaz | // Figure out a suitable field name
|
235 | ArrayList fieldNames = new ArrayList(); |
||
236 | for (int i = 0; i < jTable.getRowCount(); i++) { |
||
237 | 37807 | jpiera | fieldNames.add(tm.getValueAt(i, COLUMN_FIELD)); |
238 | 36721 | fdiaz | } |
239 | String[] currentFieldNames = (String[]) fieldNames |
||
240 | .toArray(new String[0]); |
||
241 | String newField = Messages.getText("field") |
||
242 | .replaceAll(" +", "_"); |
||
243 | int index = 0; |
||
244 | for (int i = 0; i < currentFieldNames.length; i++) { |
||
245 | if (currentFieldNames[i].startsWith(newField)) {
|
||
246 | try {
|
||
247 | index = Integer
|
||
248 | .parseInt(currentFieldNames[i] |
||
249 | .replaceAll(newField, |
||
250 | ""));
|
||
251 | } catch (Exception ex) { /* we don't care */ |
||
252 | } |
||
253 | } |
||
254 | } |
||
255 | String newFieldName = newField + (++index);
|
||
256 | |||
257 | // Esto lo a?ado aqu? porque si no tiene registros,
|
||
258 | // no hace caso. (Por eso no
|
||
259 | // lo pongo en getJTable()
|
||
260 | TableColumn typeColumn = jTable.getColumnModel()
|
||
261 | 37807 | jpiera | .getColumn(COLUMN_TYPE); |
262 | 36721 | fdiaz | 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 | 37807 | jpiera | .getColumn(COLUMN_LENGTH); |
272 | 36721 | fdiaz | |
273 | TableColumn geomTypeColumn = jTable
|
||
274 | 37807 | jpiera | .getColumnModel().getColumn(COLUMN_GEOMETRYTYPE); |
275 | 36721 | fdiaz | ComboModelGeomType geomTypeModel = new ComboModelGeomType(
|
276 | getGeomTypes()); |
||
277 | JComboBox geomTypeComboBox = new JComboBox( |
||
278 | geomTypeModel); |
||
279 | geomTypeColumn.setCellEditor(new DefaultCellEditor( |
||
280 | geomTypeComboBox)); |
||
281 | 37807 | jpiera | geomTypeColumn.setCellRenderer(new GeometryComboCellRenderer());
|
282 | |||
283 | 36721 | fdiaz | |
284 | TableColumn geomSubTypeColumn = jTable
|
||
285 | 37807 | jpiera | .getColumnModel().getColumn(COLUMN_GEOMETRYSUBTYPE); |
286 | 36721 | fdiaz | ComboModelGeomType geomSubTypeModel = new ComboModelGeomType(
|
287 | getGeomSubtypes()); |
||
288 | JComboBox geomSubTypeComboBox = new JComboBox( |
||
289 | geomSubTypeModel); |
||
290 | geomSubTypeColumn |
||
291 | .setCellEditor(new DefaultCellEditor( |
||
292 | geomSubTypeComboBox)); |
||
293 | 37807 | jpiera | geomSubTypeColumn.setCellRenderer(new GeometryComboCellRenderer());
|
294 | 36721 | fdiaz | |
295 | TableColumn crsColumn = jTable.getColumnModel()
|
||
296 | 37807 | jpiera | .getColumn(COLUMN_CRS); |
297 | 36721 | fdiaz | crsColumn.setCellEditor(new ButtonEditor(
|
298 | new JCheckBox())); |
||
299 | 37807 | jpiera | CrsRenderer crsButtonRenderer = new CrsRenderer();
|
300 | 36721 | fdiaz | crsColumn.setCellRenderer(crsButtonRenderer); |
301 | |||
302 | TableColumn primaryKeyColumn = jTable
|
||
303 | 37807 | jpiera | .getColumnModel().getColumn(COLUMN_PRIMARYKEY); |
304 | 36721 | fdiaz | 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 | 37807 | jpiera | .getColumnModel().getColumn(COLUMN_MANDATORY); |
314 | 36721 | fdiaz | 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 | 37807 | jpiera | 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 | 36721 | fdiaz | // Por defecto, la proyeccion de la vista
|
330 | 37807 | jpiera | newRow[COLUMN_CRS] = wizard.getService().getMapContext() |
331 | 36721 | fdiaz | .getProjection(); |
332 | 37807 | jpiera | newRow[COLUMN_PRIMARYKEY] = primaryKeyCheckBox.isSelected(); |
333 | newRow[COLUMN_MANDATORY] = mandatoryCheckBox.isSelected(); |
||
334 | tm.addRow(newRow); |
||
335 | 36022 | fdiaz | } |
336 | 36721 | fdiaz | }); |
337 | 36022 | fdiaz | |
338 | 36721 | fdiaz | } |
339 | 37333 | fdiaz | jButtonAddField.setEnabled(allowEditableFeatureType()); |
340 | 36721 | fdiaz | return jButtonAddField;
|
341 | } |
||
342 | 37333 | fdiaz | |
343 | private boolean allowEditableFeatureType(){ |
||
344 | NewLayerService service = this.wizard.getService();
|
||
345 | DataManager dataManager = DALLocator.getDataManager(); |
||
346 | FeatureStoreProviderFactory factory = (FeatureStoreProviderFactory) dataManager.getStoreProviderFactory(service.getStoreName()); |
||
347 | if (factory.allowEditableFeatureType()==FeatureStoreProviderFactory.NO) {
|
||
348 | return false; |
||
349 | } |
||
350 | return true; |
||
351 | } |
||
352 | 36022 | fdiaz | |
353 | 36721 | fdiaz | private class ComboItemDataType { |
354 | private DataType dataType;
|
||
355 | 36022 | fdiaz | |
356 | 36721 | fdiaz | public ComboItemDataType(DataType dataType) {
|
357 | this.dataType = dataType;
|
||
358 | } |
||
359 | 36022 | fdiaz | |
360 | 36721 | fdiaz | @Override
|
361 | public String toString() { |
||
362 | return this.dataType.getName(); |
||
363 | } |
||
364 | } |
||
365 | 36022 | fdiaz | |
366 | 36721 | fdiaz | private class ComboModelDataType implements ComboBoxModel { |
367 | |||
368 | private List<ComboItemDataType> dataTypes; |
||
369 | private ComboItemDataType selected;
|
||
370 | |||
371 | public ComboModelDataType(List<DataType> dataTypes) { |
||
372 | this.dataTypes = new ArrayList<ComboItemDataType>(); |
||
373 | for (Iterator iterator = dataTypes.iterator(); iterator.hasNext();) { |
||
374 | DataType dataType = (DataType) iterator.next(); |
||
375 | this.dataTypes.add(new ComboItemDataType(dataType)); |
||
376 | } |
||
377 | } |
||
378 | |||
379 | public void addListDataListener(ListDataListener arg0) { |
||
380 | // DO NOTHING
|
||
381 | } |
||
382 | |||
383 | public Object getElementAt(int arg0) { |
||
384 | return this.dataTypes.get(arg0); |
||
385 | } |
||
386 | |||
387 | public int getSize() { |
||
388 | return this.dataTypes.size(); |
||
389 | } |
||
390 | |||
391 | public void removeListDataListener(ListDataListener arg0) { |
||
392 | // DO NOTHING
|
||
393 | } |
||
394 | |||
395 | public Object getSelectedItem() { |
||
396 | return this.selected; |
||
397 | } |
||
398 | |||
399 | public void setSelectedItem(Object anItem) { |
||
400 | this.selected = (ComboItemDataType) anItem;
|
||
401 | } |
||
402 | |||
403 | } |
||
404 | |||
405 | 37807 | jpiera | class CrsRenderer extends JButton implements TableCellRenderer { |
406 | 36721 | fdiaz | private static final long serialVersionUID = -573793294070515376L; |
407 | 37807 | jpiera | private JLabel label = null; |
408 | |||
409 | public CrsRenderer() {
|
||
410 | 36721 | fdiaz | setOpaque(true);
|
411 | 37807 | jpiera | label = new JLabel(Messages.getText("not_applicable")); |
412 | 36721 | fdiaz | } |
413 | |||
414 | public Component getTableCellRendererComponent(JTable table, |
||
415 | Object value, boolean isSelected, boolean hasFocus, int row, |
||
416 | int column) {
|
||
417 | 37807 | jpiera | |
418 | DataType dataType = |
||
419 | ((ComboItemDataType) table.getValueAt(row, COLUMN_TYPE)).dataType; |
||
420 | |||
421 | if (dataType.getType() != DataTypes.GEOMETRY) {
|
||
422 | return label;
|
||
423 | } |
||
424 | |||
425 | if (isSelected) {
|
||
426 | 36721 | fdiaz | setForeground(table.getSelectionForeground()); |
427 | setBackground(table.getSelectionBackground()); |
||
428 | } else {
|
||
429 | setForeground(table.getForeground()); |
||
430 | setBackground(UIManager.getColor("Button.background")); |
||
431 | } |
||
432 | setText((value == null) ? "" : ((IProjection) value).getFullCode()); |
||
433 | return this; |
||
434 | } |
||
435 | 37807 | jpiera | } |
436 | |||
437 | private class GeometryComboCellRenderer extends JLabel implements TableCellRenderer{ |
||
438 | 36721 | fdiaz | |
439 | 37807 | jpiera | public Component getTableCellRendererComponent(JTable table, |
440 | Object value, boolean isSelected, boolean hasFocus, int row, |
||
441 | int column) {
|
||
442 | |||
443 | DataType dataType = |
||
444 | ((ComboItemDataType) table.getValueAt(row, COLUMN_TYPE)).dataType; |
||
445 | |||
446 | if (dataType.getType() == DataTypes.GEOMETRY) {
|
||
447 | ComboItemGeomType geomType = (ComboItemGeomType)value; |
||
448 | if (geomType != null) { |
||
449 | this.setText(geomType.toString());
|
||
450 | } |
||
451 | } else {
|
||
452 | this.setText(Messages.getText("not_applicable")); |
||
453 | } |
||
454 | |||
455 | return this; |
||
456 | } |
||
457 | |||
458 | } |
||
459 | |||
460 | 36721 | fdiaz | class ButtonEditor extends DefaultCellEditor { |
461 | /**
|
||
462 | *
|
||
463 | */
|
||
464 | private static final long serialVersionUID = -2820892672026188802L; |
||
465 | |||
466 | protected JButton button; |
||
467 | |||
468 | private String label; |
||
469 | |||
470 | private boolean isPushed; |
||
471 | |||
472 | private Object value; |
||
473 | |||
474 | public ButtonEditor(JCheckBox checkBox) { |
||
475 | super(checkBox);
|
||
476 | button = new JButton(); |
||
477 | button.setOpaque(true);
|
||
478 | button.addActionListener(new ActionListener() { |
||
479 | public void actionPerformed(ActionEvent e) { |
||
480 | fireEditingStopped(); |
||
481 | 36022 | fdiaz | } |
482 | }); |
||
483 | 36721 | fdiaz | } |
484 | 36022 | fdiaz | |
485 | 36721 | fdiaz | public Component getTableCellEditorComponent(JTable table, |
486 | Object value, boolean isSelected, int row, int column) { |
||
487 | if (isSelected) {
|
||
488 | button.setForeground(table.getSelectionForeground()); |
||
489 | button.setBackground(table.getSelectionBackground()); |
||
490 | } else {
|
||
491 | button.setForeground(table.getForeground()); |
||
492 | button.setBackground(table.getBackground()); |
||
493 | } |
||
494 | label = (value == null) ? "" : ((IProjection) value).getFullCode();// .toString(); |
||
495 | button.setText(label); |
||
496 | isPushed = true;
|
||
497 | this.value = value;
|
||
498 | return button;
|
||
499 | 36022 | fdiaz | } |
500 | 36721 | fdiaz | |
501 | public Object getCellEditorValue() { |
||
502 | IProjection curProj = (IProjection) this.value;
|
||
503 | if (isPushed) {
|
||
504 | ISelectCrsPanel csSelect = CRSSelectPanel.getUIFactory() |
||
505 | .getSelectCrsPanel(curProj, true);
|
||
506 | WindowManager wm = ToolsSwingLocator.getWindowManager(); |
||
507 | wm.showWindow((JPanel) csSelect, "Projection", |
||
508 | WindowManager.MODE.DIALOG); |
||
509 | curProj = csSelect.getProjection(); |
||
510 | } |
||
511 | isPushed = false;
|
||
512 | return curProj;
|
||
513 | } |
||
514 | |||
515 | public boolean stopCellEditing() { |
||
516 | isPushed = false;
|
||
517 | return super.stopCellEditing(); |
||
518 | } |
||
519 | |||
520 | protected void fireEditingStopped() { |
||
521 | super.fireEditingStopped();
|
||
522 | } |
||
523 | 36022 | fdiaz | } |
524 | |||
525 | 36721 | fdiaz | private class ComboItemGeomType { |
526 | private int type; |
||
527 | private String name; |
||
528 | 36022 | fdiaz | |
529 | 36721 | fdiaz | public ComboItemGeomType(String name, int type) { |
530 | this.type = type;
|
||
531 | this.name = name;
|
||
532 | } |
||
533 | |||
534 | @Override
|
||
535 | public String toString() { |
||
536 | return this.name; |
||
537 | } |
||
538 | } |
||
539 | |||
540 | private class ComboModelGeomType implements ComboBoxModel { |
||
541 | |||
542 | private List<ComboItemGeomType> geomTypes; |
||
543 | private ComboItemGeomType selected;
|
||
544 | |||
545 | public ComboModelGeomType(List<ComboItemGeomType> geomTypes) { |
||
546 | this.geomTypes = geomTypes;
|
||
547 | } |
||
548 | |||
549 | public void addListDataListener(ListDataListener arg0) { |
||
550 | // DO NOTHING
|
||
551 | } |
||
552 | |||
553 | public Object getElementAt(int arg0) { |
||
554 | return this.geomTypes.get(arg0); |
||
555 | } |
||
556 | |||
557 | public int getSize() { |
||
558 | return this.geomTypes.size(); |
||
559 | } |
||
560 | |||
561 | public void removeListDataListener(ListDataListener arg0) { |
||
562 | // DO NOTHING
|
||
563 | } |
||
564 | |||
565 | public Object getSelectedItem() { |
||
566 | return this.selected; |
||
567 | } |
||
568 | |||
569 | public void setSelectedItem(Object anItem) { |
||
570 | this.selected = (ComboItemGeomType) anItem;
|
||
571 | } |
||
572 | |||
573 | } |
||
574 | |||
575 | private List<ComboItemGeomType> getGeomTypes() { |
||
576 | List<ComboItemGeomType> geomTypes = new ArrayList<ComboItemGeomType>(); |
||
577 | geomTypes |
||
578 | .add(new ComboItemGeomType("GEOMETRY", Geometry.TYPES.GEOMETRY)); |
||
579 | geomTypes.add(new ComboItemGeomType("POINT", Geometry.TYPES.POINT)); |
||
580 | geomTypes.add(new ComboItemGeomType("CURVE", Geometry.TYPES.CURVE)); |
||
581 | geomTypes.add(new ComboItemGeomType("SURFACE", Geometry.TYPES.SURFACE)); |
||
582 | geomTypes.add(new ComboItemGeomType("SOLID", Geometry.TYPES.SOLID)); |
||
583 | geomTypes.add(new ComboItemGeomType("AGGREGATE", |
||
584 | Geometry.TYPES.AGGREGATE)); |
||
585 | geomTypes.add(new ComboItemGeomType("MULTIPOINT", |
||
586 | Geometry.TYPES.MULTIPOINT)); |
||
587 | geomTypes.add(new ComboItemGeomType("MULTICURVE", |
||
588 | Geometry.TYPES.MULTICURVE)); |
||
589 | geomTypes.add(new ComboItemGeomType("MULTISURFACE", |
||
590 | Geometry.TYPES.MULTISURFACE)); |
||
591 | geomTypes.add(new ComboItemGeomType("MULTISOLID", |
||
592 | Geometry.TYPES.MULTISOLID)); |
||
593 | |||
594 | return geomTypes;
|
||
595 | } |
||
596 | |||
597 | private List<ComboItemGeomType> getGeomSubtypes() { |
||
598 | List<ComboItemGeomType> geomSubtypes = new ArrayList<ComboItemGeomType>(); |
||
599 | geomSubtypes.add(new ComboItemGeomType("GEOM2D", |
||
600 | Geometry.SUBTYPES.GEOM2D)); |
||
601 | geomSubtypes.add(new ComboItemGeomType("GEOM2DM", |
||
602 | Geometry.SUBTYPES.GEOM2DM)); |
||
603 | geomSubtypes.add(new ComboItemGeomType("GEOM3D", |
||
604 | Geometry.SUBTYPES.GEOM3D)); |
||
605 | geomSubtypes.add(new ComboItemGeomType("GEOM3DM", |
||
606 | Geometry.SUBTYPES.GEOM3DM)); |
||
607 | geomSubtypes.add(new ComboItemGeomType("UNKNOWN", |
||
608 | Geometry.SUBTYPES.UNKNOWN)); |
||
609 | return geomSubtypes;
|
||
610 | } |
||
611 | |||
612 | class CheckBoxRenderer extends JCheckBox implements TableCellRenderer { |
||
613 | |||
614 | /**
|
||
615 | *
|
||
616 | */
|
||
617 | private static final long serialVersionUID = 5093448776058027505L; |
||
618 | |||
619 | CheckBoxRenderer() { |
||
620 | setHorizontalAlignment(JLabel.CENTER);
|
||
621 | } |
||
622 | |||
623 | public Component getTableCellRendererComponent(JTable table, |
||
624 | Object value, boolean isSelected, boolean hasFocus, int row, |
||
625 | int column) {
|
||
626 | if (isSelected) {
|
||
627 | setForeground(table.getSelectionForeground()); |
||
628 | setBackground(table.getSelectionBackground()); |
||
629 | } else {
|
||
630 | setForeground(table.getForeground()); |
||
631 | setBackground(table.getBackground()); |
||
632 | } |
||
633 | setSelected((value != null && ((Boolean) value).booleanValue())); |
||
634 | return this; |
||
635 | } |
||
636 | } |
||
637 | |||
638 | 36022 | fdiaz | /**
|
639 | * This method initializes jButton
|
||
640 | 36721 | fdiaz | *
|
641 | 36022 | fdiaz | * @return javax.swing.JButton
|
642 | */
|
||
643 | private JButton getJButtonDeleteField() { |
||
644 | if (jButtonDeleteField == null) { |
||
645 | jButtonDeleteField = new JButton(); |
||
646 | jButtonDeleteField.setText(Messages.getText("delete_field"));
|
||
647 | 36721 | fdiaz | jButtonDeleteField.setLocation(new java.awt.Point(7, 33)); |
648 | jButtonDeleteField.setSize(new java.awt.Dimension(145, 23)); |
||
649 | 36022 | fdiaz | jButtonDeleteField.setEnabled(false);
|
650 | 36721 | fdiaz | jButtonDeleteField |
651 | .addActionListener(new java.awt.event.ActionListener() {
|
||
652 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
653 | int[] selecteds = jTable.getSelectedRows(); |
||
654 | DefaultTableModel tm = (DefaultTableModel) jTable |
||
655 | .getModel(); |
||
656 | 36022 | fdiaz | |
657 | 36721 | fdiaz | for (int i = selecteds.length - 1; i >= 0; i--) { |
658 | 38367 | jldominguez | /*
|
659 | *
|
||
660 | 36721 | fdiaz | removedFields.add((String) tm.getValueAt(i, 0));
|
661 | 38367 | jldominguez | */
|
662 | 36721 | fdiaz | tm.removeRow(selecteds[i]); |
663 | } |
||
664 | } |
||
665 | }); |
||
666 | 36022 | fdiaz | } |
667 | 37333 | fdiaz | jButtonDeleteField.setEnabled(allowEditableFeatureType()); |
668 | 36022 | fdiaz | return jButtonDeleteField;
|
669 | } |
||
670 | |||
671 | public String getPanelTitle() { |
||
672 | return Messages.getText("fields_definitions"); |
||
673 | } |
||
674 | |||
675 | public void nextPanel() throws NotContinueWizardException { |
||
676 | 37333 | fdiaz | if (allowEditableFeatureType()){
|
677 | fillFeatureType(); |
||
678 | } |
||
679 | 36220 | fdiaz | } |
680 | 36721 | fdiaz | |
681 | 36220 | fdiaz | private void fillFeatureType() { |
682 | 36721 | fdiaz | /*
|
683 | 36220 | fdiaz | * Coge los datos del formulario y los guarda en
|
684 | 36022 | fdiaz | * this.service.getFeatureType()
|
685 | */
|
||
686 | 36721 | fdiaz | NewLayerService service = this.wizard.getService();
|
687 | EditableFeatureType featureType = service.getFeatureType(); |
||
688 | 38367 | jldominguez | |
689 | // Clean and rebuild featureType everytime we click next
|
||
690 | removeAllFields(featureType); |
||
691 | 36721 | fdiaz | |
692 | 38367 | jldominguez | /*
|
693 | 36220 | fdiaz | for (Iterator iterator = removedFields.iterator(); iterator.hasNext();) {
|
694 | String name = (String) iterator.next();
|
||
695 | featureType.remove(name);
|
||
696 | }
|
||
697 | removedFields.clear();
|
||
698 | 38367 | jldominguez | */
|
699 | 36721 | fdiaz | |
700 | 36022 | fdiaz | DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
701 | 36721 | fdiaz | for (int i = 0; i < tm.getRowCount(); i++) { |
702 | 37807 | jpiera | DataType dataType = ((ComboItemDataType) tm.getValueAt(i, COLUMN_TYPE)).dataType; |
703 | 36022 | fdiaz | |
704 | 37807 | jpiera | int fieldLength = Integer.parseInt((String) tm.getValueAt(i, COLUMN_LENGTH)); |
705 | 36022 | fdiaz | // TODO: HACERLO BIEN
|
706 | 36721 | fdiaz | if (dataType.getType() == DataTypes.DOUBLE) {
|
707 | fieldLength = 5;
|
||
708 | } |
||
709 | 38367 | jldominguez | |
710 | 36721 | fdiaz | // FIXME: Arreglar lo que pasa si en el siguiente panel volvemos
|
711 | // hacia atras, y en este volvemos a ir hacia adelante
|
||
712 | 38367 | jldominguez | /*
|
713 | 37807 | jpiera | String fieldName = (String) tm.getValueAt(i, COLUMN_FIELD);
|
714 | 36721 | fdiaz | EditableFeatureAttributeDescriptor attrDescriptor = (EditableFeatureAttributeDescriptor) featureType
|
715 | .getAttributeDescriptor(fieldName);
|
||
716 | 38367 | jldominguez | |
717 | 36220 | fdiaz | if (attrDescriptor != null) {
|
718 | featureType.remove(attrDescriptor);
|
||
719 | }
|
||
720 | 38367 | jldominguez | */
|
721 | |||
722 | 36721 | fdiaz | EditableFeatureAttributeDescriptor efad1 = featureType.add( |
723 | 37807 | jpiera | (String) tm.getValueAt(i, COLUMN_FIELD), dataType.getType(),
|
724 | 36721 | fdiaz | fieldLength); |
725 | if (dataType.getType() == DataTypes.GEOMETRY) {
|
||
726 | 37807 | jpiera | efad1.setGeometryType(((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYTYPE)).type); |
727 | 36721 | fdiaz | efad1.setGeometrySubType(((ComboItemGeomType) tm.getValueAt(i, |
728 | 37807 | jpiera | COLUMN_GEOMETRYSUBTYPE)).type); |
729 | efad1.setIsPrimaryKey(((Boolean) tm.getValueAt(i, COLUMN_PRIMARYKEY))
|
||
730 | 36721 | fdiaz | .booleanValue()); |
731 | 37807 | jpiera | efad1.setAllowNull(!((Boolean) tm.getValueAt(i, COLUMN_MANDATORY))
|
732 | 36721 | fdiaz | .booleanValue()); |
733 | 37807 | jpiera | efad1.setSRS((IProjection) tm.getValueAt(i, COLUMN_CRS)); |
734 | 37804 | jpiera | //If there is not a previous default geometry field, add it
|
735 | if (featureType.getDefaultGeometryAttribute() == null){ |
||
736 | featureType.setDefaultGeometryAttributeName(efad1.getName()); |
||
737 | 37807 | jpiera | } |
738 | 36721 | fdiaz | } |
739 | 36022 | fdiaz | } |
740 | 36220 | fdiaz | } |
741 | 36022 | fdiaz | |
742 | 38367 | jldominguez | /**
|
743 | * @param featureType
|
||
744 | */
|
||
745 | private void removeAllFields(EditableFeatureType ft) { |
||
746 | |||
747 | FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
|
||
748 | int len = atts.length;
|
||
749 | FeatureAttributeDescriptor item = null;
|
||
750 | for (int i=0; i<len; i++) { |
||
751 | item = atts[i]; |
||
752 | ft.remove(item.getName()); |
||
753 | } |
||
754 | } |
||
755 | |||
756 | public void lastPanel() { |
||
757 | 36220 | fdiaz | // TODO Auto-generated method stub
|
758 | logger.info("FeatureTypePanel: lastPanel");
|
||
759 | 36022 | fdiaz | } |
760 | |||
761 | 36220 | fdiaz | public void updatePanel() { |
762 | initializeComponents(); |
||
763 | 36721 | fdiaz | |
764 | 36220 | fdiaz | } |
765 | |||
766 | public JPanel getJPanel() { |
||
767 | return this; |
||
768 | } |
||
769 | 36022 | fdiaz | } |