svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.newlayer / org.gvsig.newlayer.lib / org.gvsig.newlayer.lib.impl / src / main / java / org / gvsig / newlayer / impl / FeatureTypePanel.java @ 40560
History | View | Annotate | Download (41.1 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.newlayer.impl; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Component; |
28 |
import java.awt.GridBagConstraints; |
29 |
import java.awt.GridBagLayout; |
30 |
import java.awt.Insets; |
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
import java.awt.event.ItemEvent; |
34 |
import java.awt.event.ItemListener; |
35 |
import java.util.ArrayList; |
36 |
import java.util.Iterator; |
37 |
import java.util.List; |
38 |
|
39 |
import javax.swing.ComboBoxModel; |
40 |
import javax.swing.DefaultCellEditor; |
41 |
import javax.swing.JButton; |
42 |
import javax.swing.JCheckBox; |
43 |
import javax.swing.JComboBox; |
44 |
import javax.swing.JLabel; |
45 |
import javax.swing.JOptionPane; |
46 |
import javax.swing.JPanel; |
47 |
import javax.swing.JScrollPane; |
48 |
import javax.swing.JTable; |
49 |
import javax.swing.JTextField; |
50 |
import javax.swing.ListSelectionModel; |
51 |
import javax.swing.UIManager; |
52 |
import javax.swing.event.ListDataListener; |
53 |
import javax.swing.event.ListSelectionEvent; |
54 |
import javax.swing.event.ListSelectionListener; |
55 |
import javax.swing.event.TableModelEvent; |
56 |
import javax.swing.event.TableModelListener; |
57 |
import javax.swing.table.DefaultTableCellRenderer; |
58 |
import javax.swing.table.DefaultTableModel; |
59 |
import javax.swing.table.TableCellRenderer; |
60 |
import javax.swing.table.TableColumn; |
61 |
import javax.swing.table.TableModel; |
62 |
|
63 |
import org.cresques.cts.IProjection; |
64 |
import org.slf4j.Logger; |
65 |
import org.slf4j.LoggerFactory; |
66 |
|
67 |
import org.gvsig.app.gui.panels.CRSSelectPanel; |
68 |
import org.gvsig.app.gui.panels.crs.ISelectCrsPanel; |
69 |
import org.gvsig.fmap.dal.DALLocator; |
70 |
import org.gvsig.fmap.dal.DataManager; |
71 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
72 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
73 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
74 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
75 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
76 |
import org.gvsig.fmap.dal.feature.FeatureType; |
77 |
import org.gvsig.fmap.geom.DataTypes; |
78 |
import org.gvsig.fmap.geom.Geometry; |
79 |
import org.gvsig.fmap.geom.GeometryLocator; |
80 |
import org.gvsig.fmap.geom.GeometryManager; |
81 |
import org.gvsig.fmap.geom.type.GeometryType; |
82 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
83 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
84 |
import org.gvsig.i18n.Messages; |
85 |
import org.gvsig.newlayer.NewLayerService; |
86 |
import org.gvsig.tools.dataTypes.DataType; |
87 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
88 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
89 |
|
90 |
public class FeatureTypePanel extends JPanel implements OptionPanel { |
91 |
private static final int COLUMN_FIELD = 0; |
92 |
private static final int COLUMN_TYPE = 1; |
93 |
private static final int COLUMN_LENGTH = 2; |
94 |
private static final int COLUMN_GEOMETRYTYPE = 3; |
95 |
private static final int COLUMN_GEOMETRYSUBTYPE = 4; |
96 |
private static final int COLUMN_CRS = 5; |
97 |
private static final int COLUMN_PRIMARYKEY = 6; |
98 |
private static final int COLUMN_MANDATORY = 7; |
99 |
|
100 |
private static final long serialVersionUID = 263541873998597624L; |
101 |
|
102 |
private FeatureType defaultFeatType = null; |
103 |
|
104 |
private NewLayerService newLayer_Service = null; |
105 |
private int inDefaultFeatTypeFieldCount = 0; |
106 |
private String inStoreName = null; |
107 |
private IProjection inProjection = null; |
108 |
private FeatureStoreProviderFactory spFactory = null; |
109 |
private boolean defaultHasGeometry = false; |
110 |
|
111 |
private static final Logger logger = LoggerFactory |
112 |
.getLogger(FeatureTypePanel.class); |
113 |
|
114 |
private JLabel jLabel = null; |
115 |
private JScrollPane jScrollPane = null; |
116 |
protected JTable jTable = null; |
117 |
private JPanel jPanelEast = null; |
118 |
private JButton addFieldButton = null; |
119 |
private JButton deleteFieldButton = null; |
120 |
protected int MAX_FIELD_LENGTH = 254; |
121 |
|
122 |
// we dont need this list
|
123 |
// we'll clear and rebuild featureType each time
|
124 |
// the user clicks next
|
125 |
// private List removedFields;
|
126 |
|
127 |
// private DataServerExplorer explorer = null;
|
128 |
|
129 |
public FeatureTypePanel(NewLayerService new_layer_service) {
|
130 |
|
131 |
/*
|
132 |
service.getFeatureType(),
|
133 |
service.getStoreName(),
|
134 |
service.getMapContext().getProjection();
|
135 |
*/
|
136 |
newLayer_Service = new_layer_service; |
137 |
} |
138 |
|
139 |
private boolean fieldsInited = false; |
140 |
|
141 |
private void initFields() { |
142 |
|
143 |
if (newLayer_Service == null) { |
144 |
return;
|
145 |
} |
146 |
|
147 |
fieldsInited = true;
|
148 |
|
149 |
inStoreName = newLayer_Service.getStoreName(); |
150 |
inProjection = newLayer_Service.getMapContext().getProjection(); |
151 |
|
152 |
DataStoreProviderFactory dspf = |
153 |
DALLocator.getDataManager().getStoreProviderFactory(inStoreName); |
154 |
spFactory = (FeatureStoreProviderFactory) dspf; |
155 |
defaultFeatType = spFactory.createDefaultFeatureType(); |
156 |
if (defaultFeatType != null) { |
157 |
inDefaultFeatTypeFieldCount = |
158 |
defaultFeatType.getAttributeDescriptors().length; |
159 |
int def_geom_fld_index = defaultFeatType.getDefaultGeometryAttributeIndex();
|
160 |
if (def_geom_fld_index >= 0 && |
161 |
def_geom_fld_index < inDefaultFeatTypeFieldCount && |
162 |
defaultFeatType. |
163 |
getAttributeDescriptor(def_geom_fld_index). |
164 |
getDataType().getType() == DataTypes.GEOMETRY) { |
165 |
|
166 |
defaultHasGeometry = true;
|
167 |
} |
168 |
} |
169 |
} |
170 |
|
171 |
private void initializeComponents() { |
172 |
jLabel = new JLabel(); |
173 |
jLabel.setText(Messages.getText("define_fields"));
|
174 |
this.setLayout(new BorderLayout(5, 5)); |
175 |
this.setSize(new java.awt.Dimension(499, 232)); |
176 |
this.add(jLabel, java.awt.BorderLayout.NORTH);
|
177 |
this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
|
178 |
this.add(getJPanelSouth(), java.awt.BorderLayout.SOUTH);
|
179 |
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* This method initializes jScrollPane
|
184 |
*
|
185 |
* @return javax.swing.JScrollPane
|
186 |
*/
|
187 |
private JScrollPane getJScrollPane() { |
188 |
if (jScrollPane == null) { |
189 |
jScrollPane = new JScrollPane(); |
190 |
jScrollPane.setViewportView(getJTable()); |
191 |
} |
192 |
return jScrollPane;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* This method initializes jTable
|
197 |
*
|
198 |
* @return javax.swing.JTable
|
199 |
*/
|
200 |
private JTable getJTable() { |
201 |
if (jTable == null) { |
202 |
jTable = new JTable(){ |
203 |
public boolean isCellEditable(int row,int column){ |
204 |
|
205 |
|
206 |
if (row < inDefaultFeatTypeFieldCount) {
|
207 |
// default fields
|
208 |
Object o = getValueAt(row,COLUMN_TYPE);
|
209 |
if (o instanceof ComboItemDataType) { |
210 |
|
211 |
ComboItemDataType ot = (ComboItemDataType) o; |
212 |
return (ot.dataType.getType() == DataTypes.GEOMETRY)
|
213 |
&& |
214 |
(column == COLUMN_GEOMETRYTYPE || |
215 |
column == COLUMN_GEOMETRYSUBTYPE); |
216 |
|
217 |
} else {
|
218 |
return false; |
219 |
} |
220 |
|
221 |
} else {
|
222 |
// fields added by user
|
223 |
if (column == COLUMN_PRIMARYKEY) {
|
224 |
return spFactory.allowsPrimaryKeyAttributes();
|
225 |
} |
226 |
|
227 |
if (column == COLUMN_MANDATORY) {
|
228 |
return spFactory.allowsMandatoryAttributes();
|
229 |
} |
230 |
|
231 |
if (column == COLUMN_LENGTH) {
|
232 |
|
233 |
Object o = getValueAt(row,COLUMN_TYPE);
|
234 |
if (o instanceof ComboItemDataType) { |
235 |
|
236 |
ComboItemDataType ot = (ComboItemDataType) o; |
237 |
return dataTypeNeedsSize(ot.dataType.getType());
|
238 |
|
239 |
} else {
|
240 |
return false; |
241 |
} |
242 |
|
243 |
} |
244 |
|
245 |
if (defaultHasGeometry &&
|
246 |
(column == COLUMN_GEOMETRYTYPE |
247 |
|| column == COLUMN_GEOMETRYSUBTYPE |
248 |
|| column == COLUMN_CRS)) { |
249 |
// geom-related columns not editable
|
250 |
return false; |
251 |
} else {
|
252 |
return true; |
253 |
} |
254 |
} |
255 |
|
256 |
/*
|
257 |
if ((column == COLUMN_GEOMETRYTYPE) ||
|
258 |
(column == COLUMN_GEOMETRYSUBTYPE) ||
|
259 |
(column == COLUMN_CRS)) {
|
260 |
DataType dataType =
|
261 |
((ComboItemDataType) getValueAt(row, COLUMN_TYPE)).dataType;
|
262 |
return dataType.getType() == DataTypes.GEOMETRY;
|
263 |
}
|
264 |
*/
|
265 |
} |
266 |
}; |
267 |
|
268 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
269 |
tm.addColumn(Messages.getText("field"));
|
270 |
|
271 |
tm.addColumn(Messages.getText("type"));
|
272 |
tm.addColumn(Messages.getText("length"));
|
273 |
tm.addColumn(Messages.getText("geomType"));
|
274 |
tm.addColumn(Messages.getText("geomSubtype"));
|
275 |
tm.addColumn(Messages.getText("CRS"));
|
276 |
tm.addColumn(Messages.getText("primaryKey"));
|
277 |
tm.addColumn(Messages.getText("mandatory"));
|
278 |
|
279 |
// Ask to be notified of selection changes.
|
280 |
ListSelectionModel rowSM = jTable.getSelectionModel();
|
281 |
rowSM.addListSelectionListener(new ListSelectionListener() { |
282 |
public void valueChanged(ListSelectionEvent e) { |
283 |
// Ignore extra messages.
|
284 |
if (e.getValueIsAdjusting())
|
285 |
return;
|
286 |
|
287 |
ListSelectionModel lsm = (ListSelectionModel) e.getSource(); |
288 |
if (lsm.isSelectionEmpty()) {
|
289 |
// no rows are selected
|
290 |
deleteFieldButton.setEnabled(false);
|
291 |
} else {
|
292 |
int min_sele = lsm.getMinSelectionIndex();
|
293 |
if (min_sele > -1 && |
294 |
min_sele < inDefaultFeatTypeFieldCount) { |
295 |
deleteFieldButton.setEnabled(false);
|
296 |
} else {
|
297 |
deleteFieldButton.setEnabled(allowEditableFeatureType()); |
298 |
} |
299 |
} |
300 |
|
301 |
} |
302 |
}); |
303 |
jTable.getColumn(Messages.getText("field")).setWidth(180); |
304 |
|
305 |
jTable.getModel().addTableModelListener(new TableModelListener() { |
306 |
public void tableChanged(TableModelEvent e) { |
307 |
if (e.getColumn() == COLUMN_TYPE){
|
308 |
jTable.repaint(); |
309 |
} |
310 |
} |
311 |
}); |
312 |
|
313 |
|
314 |
if (!fieldsInited) {
|
315 |
initFields(); |
316 |
} |
317 |
|
318 |
// Rellenado de la tabla
|
319 |
if (defaultFeatType != null) { |
320 |
|
321 |
Iterator it = defaultFeatType.iterator();
|
322 |
boolean some_error = false; |
323 |
while (it.hasNext()) {
|
324 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) it |
325 |
.next(); |
326 |
|
327 |
if (!addRowToFieldTable(
|
328 |
jTable, |
329 |
null,
|
330 |
inProjection, |
331 |
descriptor)) { |
332 |
|
333 |
some_error = true;
|
334 |
} |
335 |
/*
|
336 |
tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD);
|
337 |
tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE);
|
338 |
tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH);
|
339 |
tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE);
|
340 |
tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE);
|
341 |
tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS);
|
342 |
tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY);
|
343 |
tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY);
|
344 |
*/
|
345 |
} |
346 |
|
347 |
if (some_error) {
|
348 |
String tit = Messages.getText("_Default_fields"); |
349 |
String msg = Messages.getText("_Unable_to_add_fields"); |
350 |
JOptionPane.showMessageDialog(
|
351 |
jTable, msg, tit, |
352 |
JOptionPane.ERROR_MESSAGE);
|
353 |
} |
354 |
} |
355 |
|
356 |
} |
357 |
jTable.setEnabled(allowEditableFeatureType()); |
358 |
return jTable;
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* This method initializes jPanelWest
|
363 |
*
|
364 |
* @return javax.swing.JPanel
|
365 |
*/
|
366 |
private JPanel getJPanelSouth() { |
367 |
if (jPanelEast == null) { |
368 |
jPanelEast = new JPanel(); |
369 |
jPanelEast.setLayout(new BorderLayout()); |
370 |
|
371 |
JPanel south_east = new JPanel(new GridBagLayout()); |
372 |
// south_east.setPreferredSize(new java.awt.Dimension(170, 50));
|
373 |
GridBagConstraints c = new GridBagConstraints(); |
374 |
c.fill = GridBagConstraints.HORIZONTAL;
|
375 |
c.insets = new Insets(8,10,8,0); //top padding |
376 |
c.gridx = 0;
|
377 |
c.gridwidth = 1;
|
378 |
c.gridy = 0;
|
379 |
south_east.add(getJButtonAddField(), c); |
380 |
c.gridx = 1;
|
381 |
south_east.add(getJButtonDeleteField(), c); |
382 |
|
383 |
jPanelEast.add(south_east, BorderLayout.EAST);
|
384 |
} |
385 |
return jPanelEast;
|
386 |
} |
387 |
|
388 |
/**
|
389 |
* This method initializes jButtonAddField
|
390 |
*
|
391 |
* @return javax.swing.JButton
|
392 |
*/
|
393 |
private JButton getJButtonAddField() { |
394 |
if (addFieldButton == null) { |
395 |
addFieldButton = new JButton(); |
396 |
addFieldButton.setText(Messages.getText("add_field"));
|
397 |
addFieldButton.setLocation(new java.awt.Point(7, 5)); |
398 |
addFieldButton.setSize(new java.awt.Dimension(145, 23)); |
399 |
addFieldButton.setPreferredSize(new java.awt.Dimension(100, 23)); |
400 |
addFieldButton |
401 |
.addActionListener(new java.awt.event.ActionListener() {
|
402 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
403 |
DefaultTableModel tm = (DefaultTableModel) jTable |
404 |
.getModel(); |
405 |
|
406 |
// Figure out a suitable field name
|
407 |
ArrayList fieldNames = new ArrayList(); |
408 |
for (int i = 0; i < jTable.getRowCount(); i++) { |
409 |
fieldNames.add(tm.getValueAt(i, COLUMN_FIELD)); |
410 |
} |
411 |
String[] currentFieldNames = (String[]) fieldNames |
412 |
.toArray(new String[0]); |
413 |
String newField = Messages.getText("field") |
414 |
.replaceAll(" +", "_"); |
415 |
int index = 0; |
416 |
for (int i = 0; i < currentFieldNames.length; i++) { |
417 |
if (currentFieldNames[i].startsWith(newField)) {
|
418 |
try {
|
419 |
index = Integer
|
420 |
.parseInt(currentFieldNames[i] |
421 |
.replaceAll(newField, |
422 |
""));
|
423 |
} catch (Exception ex) { /* we don't care */ |
424 |
} |
425 |
} |
426 |
} |
427 |
String newFieldName = newField + (++index);
|
428 |
|
429 |
// Esto lo a?ado aqu? porque si no tiene registros,
|
430 |
// no hace caso. (Por eso no
|
431 |
// lo pongo en getJTable()
|
432 |
if (!addRowToFieldTable(
|
433 |
jTable, |
434 |
newFieldName, |
435 |
inProjection, |
436 |
null)) {
|
437 |
|
438 |
String tit = Messages.getText("_Default_fields"); |
439 |
String msg = Messages.getText("_Unable_to_add_fields"); |
440 |
JOptionPane.showMessageDialog(
|
441 |
jTable, msg, tit, |
442 |
JOptionPane.ERROR_MESSAGE);
|
443 |
} |
444 |
} |
445 |
}); |
446 |
|
447 |
} |
448 |
addFieldButton.setEnabled(allowEditableFeatureType()); |
449 |
return addFieldButton;
|
450 |
} |
451 |
|
452 |
private boolean allowEditableFeatureType(){ |
453 |
|
454 |
if (!fieldsInited) {
|
455 |
initFields(); |
456 |
} |
457 |
|
458 |
DataManager dataManager = DALLocator.getDataManager(); |
459 |
FeatureStoreProviderFactory factory = |
460 |
(FeatureStoreProviderFactory) dataManager. |
461 |
getStoreProviderFactory(inStoreName); |
462 |
if (factory.allowEditableFeatureType()==FeatureStoreProviderFactory.NO) {
|
463 |
return false; |
464 |
} |
465 |
return true; |
466 |
} |
467 |
|
468 |
private class ComboItemDataType { |
469 |
private DataType dataType;
|
470 |
|
471 |
public ComboItemDataType(DataType dataType) {
|
472 |
this.dataType = dataType;
|
473 |
} |
474 |
|
475 |
@Override
|
476 |
public String toString() { |
477 |
return this.dataType.getName(); |
478 |
} |
479 |
} |
480 |
|
481 |
private class ComboModelDataType implements ComboBoxModel { |
482 |
|
483 |
private List<ComboItemDataType> dataTypes; |
484 |
private ComboItemDataType selected;
|
485 |
|
486 |
public ComboModelDataType(List<DataType> dataTypes, int sel_type) { |
487 |
|
488 |
this.dataTypes = new ArrayList<ComboItemDataType>(); |
489 |
ComboItemDataType item = null;
|
490 |
for (Iterator iterator = dataTypes.iterator(); iterator.hasNext();) { |
491 |
DataType dataType = (DataType) iterator.next(); |
492 |
item = new ComboItemDataType(dataType);
|
493 |
this.dataTypes.add(item);
|
494 |
if (sel_type == dataType.getType()) {
|
495 |
this.setSelectedItem(item);
|
496 |
} |
497 |
} |
498 |
} |
499 |
|
500 |
public void addListDataListener(ListDataListener arg0) { |
501 |
// DO NOTHING
|
502 |
} |
503 |
|
504 |
public Object getElementAt(int arg0) { |
505 |
return this.dataTypes.get(arg0); |
506 |
} |
507 |
|
508 |
public int getSize() { |
509 |
return this.dataTypes.size(); |
510 |
} |
511 |
|
512 |
public void removeListDataListener(ListDataListener arg0) { |
513 |
// DO NOTHING
|
514 |
} |
515 |
|
516 |
public Object getSelectedItem() { |
517 |
return this.selected; |
518 |
} |
519 |
|
520 |
public void setSelectedItem(Object anItem) { |
521 |
this.selected = (ComboItemDataType) anItem;
|
522 |
} |
523 |
|
524 |
} |
525 |
|
526 |
class CrsRenderer extends JButton implements TableCellRenderer { |
527 |
private static final long serialVersionUID = -573793294070515376L; |
528 |
private JLabel label = null; |
529 |
|
530 |
public CrsRenderer() {
|
531 |
setOpaque(true);
|
532 |
label = new JLabel(Messages.getText("not_applicable")); |
533 |
} |
534 |
|
535 |
public Component getTableCellRendererComponent(JTable table, |
536 |
Object value, boolean isSelected, boolean hasFocus, int row, |
537 |
int column) {
|
538 |
|
539 |
ComboItemDataType item = |
540 |
(ComboItemDataType) table.getValueAt(row, COLUMN_TYPE); |
541 |
|
542 |
if (item == null) { |
543 |
// happens sometimes. perhaps an early rendering?
|
544 |
return new JLabel(); |
545 |
} |
546 |
|
547 |
DataType dataType = item.dataType; |
548 |
|
549 |
if (dataType.getType() != DataTypes.GEOMETRY) {
|
550 |
return label;
|
551 |
} |
552 |
|
553 |
if (isSelected) {
|
554 |
setForeground(table.getSelectionForeground()); |
555 |
setBackground(table.getSelectionBackground()); |
556 |
} else {
|
557 |
setForeground(table.getForeground()); |
558 |
setBackground(UIManager.getColor("Button.background")); |
559 |
} |
560 |
setText((value == null) ? "" : ((IProjection) value).getFullCode()); |
561 |
return this; |
562 |
} |
563 |
} |
564 |
|
565 |
private class GeometryComboCellRenderer extends JLabel implements TableCellRenderer{ |
566 |
|
567 |
public Component getTableCellRendererComponent(JTable table, |
568 |
Object value, boolean isSelected, boolean hasFocus, int row, |
569 |
int column) {
|
570 |
|
571 |
ComboItemDataType item = (ComboItemDataType) table.getValueAt(row, COLUMN_TYPE); |
572 |
DataType dataType = item.dataType; |
573 |
|
574 |
if (dataType.getType() == DataTypes.GEOMETRY) {
|
575 |
ComboItemGeomType geomType = (ComboItemGeomType)value; |
576 |
if (geomType != null) { |
577 |
this.setText(geomType.toString());
|
578 |
} |
579 |
} else {
|
580 |
this.setText(Messages.getText("not_applicable")); |
581 |
} |
582 |
|
583 |
return this; |
584 |
} |
585 |
|
586 |
} |
587 |
|
588 |
class ButtonEditor extends DefaultCellEditor { |
589 |
/**
|
590 |
*
|
591 |
*/
|
592 |
private static final long serialVersionUID = -2820892672026188802L; |
593 |
|
594 |
protected JButton button; |
595 |
|
596 |
private String label; |
597 |
|
598 |
private boolean isPushed; |
599 |
|
600 |
private Object value; |
601 |
|
602 |
public ButtonEditor(JCheckBox checkBox) { |
603 |
super(checkBox);
|
604 |
button = new JButton(); |
605 |
button.setOpaque(true);
|
606 |
button.addActionListener(new ActionListener() { |
607 |
public void actionPerformed(ActionEvent e) { |
608 |
fireEditingStopped(); |
609 |
} |
610 |
}); |
611 |
} |
612 |
|
613 |
public Component getTableCellEditorComponent(JTable table, |
614 |
Object value, boolean isSelected, int row, int column) { |
615 |
if (isSelected) {
|
616 |
button.setForeground(table.getSelectionForeground()); |
617 |
button.setBackground(table.getSelectionBackground()); |
618 |
} else {
|
619 |
button.setForeground(table.getForeground()); |
620 |
button.setBackground(table.getBackground()); |
621 |
} |
622 |
label = (value == null) ? "" : ((IProjection) value).getFullCode();// .toString(); |
623 |
button.setText(label); |
624 |
isPushed = true;
|
625 |
this.value = value;
|
626 |
return button;
|
627 |
} |
628 |
|
629 |
public Object getCellEditorValue() { |
630 |
IProjection curProj = (IProjection) this.value;
|
631 |
if (isPushed) {
|
632 |
ISelectCrsPanel csSelect = CRSSelectPanel.getUIFactory() |
633 |
.getSelectCrsPanel(curProj, true);
|
634 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
635 |
wm.showWindow((JPanel) csSelect, "Projection", |
636 |
WindowManager.MODE.DIALOG); |
637 |
curProj = csSelect.getProjection(); |
638 |
} |
639 |
isPushed = false;
|
640 |
return curProj;
|
641 |
} |
642 |
|
643 |
public boolean stopCellEditing() { |
644 |
isPushed = false;
|
645 |
return super.stopCellEditing(); |
646 |
} |
647 |
|
648 |
protected void fireEditingStopped() { |
649 |
super.fireEditingStopped();
|
650 |
} |
651 |
} |
652 |
|
653 |
private class ComboItemGeomType { |
654 |
private int type; |
655 |
private String name; |
656 |
|
657 |
public ComboItemGeomType(String name, int type) { |
658 |
this.type = type;
|
659 |
this.name = name;
|
660 |
} |
661 |
|
662 |
@Override
|
663 |
public String toString() { |
664 |
return this.name; |
665 |
} |
666 |
|
667 |
public int getGeomType() { |
668 |
return type;
|
669 |
} |
670 |
} |
671 |
|
672 |
private class ComboModelGeomType implements ComboBoxModel { |
673 |
|
674 |
private List<ComboItemGeomType> geomTypes; |
675 |
private ComboItemGeomType selected;
|
676 |
|
677 |
public ComboModelGeomType(
|
678 |
List<ComboItemGeomType> geomTypes, int sel_geom_type) { |
679 |
|
680 |
this.geomTypes = geomTypes;
|
681 |
int len = geomTypes.size();
|
682 |
ComboItemGeomType item = null;
|
683 |
for (int i=0; i<len; i++) { |
684 |
item = geomTypes.get(i); |
685 |
if (item.getGeomType() == sel_geom_type) {
|
686 |
setSelectedItem(item); |
687 |
} |
688 |
} |
689 |
} |
690 |
|
691 |
public void addListDataListener(ListDataListener arg0) { |
692 |
// DO NOTHING
|
693 |
} |
694 |
|
695 |
public Object getElementAt(int arg0) { |
696 |
return this.geomTypes.get(arg0); |
697 |
} |
698 |
|
699 |
public int getSize() { |
700 |
return this.geomTypes.size(); |
701 |
} |
702 |
|
703 |
public void removeListDataListener(ListDataListener arg0) { |
704 |
// DO NOTHING
|
705 |
} |
706 |
|
707 |
public Object getSelectedItem() { |
708 |
return this.selected; |
709 |
} |
710 |
|
711 |
public void setSelectedItem(Object anItem) { |
712 |
this.selected = (ComboItemGeomType) anItem;
|
713 |
} |
714 |
|
715 |
} |
716 |
|
717 |
private List<ComboItemGeomType> getGeomTypes() { |
718 |
List<ComboItemGeomType> geomTypes = new ArrayList<ComboItemGeomType>(); |
719 |
geomTypes |
720 |
.add(new ComboItemGeomType("GEOMETRY", Geometry.TYPES.GEOMETRY)); |
721 |
geomTypes.add(new ComboItemGeomType("POINT", Geometry.TYPES.POINT)); |
722 |
geomTypes.add(new ComboItemGeomType("CURVE", Geometry.TYPES.CURVE)); |
723 |
geomTypes.add(new ComboItemGeomType("SURFACE", Geometry.TYPES.SURFACE)); |
724 |
geomTypes.add(new ComboItemGeomType("SOLID", Geometry.TYPES.SOLID)); |
725 |
geomTypes.add(new ComboItemGeomType("AGGREGATE", |
726 |
Geometry.TYPES.AGGREGATE)); |
727 |
geomTypes.add(new ComboItemGeomType("MULTIPOINT", |
728 |
Geometry.TYPES.MULTIPOINT)); |
729 |
geomTypes.add(new ComboItemGeomType("MULTICURVE", |
730 |
Geometry.TYPES.MULTICURVE)); |
731 |
geomTypes.add(new ComboItemGeomType("MULTISURFACE", |
732 |
Geometry.TYPES.MULTISURFACE)); |
733 |
geomTypes.add(new ComboItemGeomType("MULTISOLID", |
734 |
Geometry.TYPES.MULTISOLID)); |
735 |
|
736 |
return geomTypes;
|
737 |
} |
738 |
|
739 |
private List<ComboItemGeomType> getGeomSubtypes() { |
740 |
List<ComboItemGeomType> geomSubtypes = new ArrayList<ComboItemGeomType>(); |
741 |
geomSubtypes.add(new ComboItemGeomType("GEOM2D", |
742 |
Geometry.SUBTYPES.GEOM2D)); |
743 |
geomSubtypes.add(new ComboItemGeomType("GEOM2DM", |
744 |
Geometry.SUBTYPES.GEOM2DM)); |
745 |
geomSubtypes.add(new ComboItemGeomType("GEOM3D", |
746 |
Geometry.SUBTYPES.GEOM3D)); |
747 |
geomSubtypes.add(new ComboItemGeomType("GEOM3DM", |
748 |
Geometry.SUBTYPES.GEOM3DM)); |
749 |
geomSubtypes.add(new ComboItemGeomType("UNKNOWN", |
750 |
Geometry.SUBTYPES.UNKNOWN)); |
751 |
return geomSubtypes;
|
752 |
} |
753 |
|
754 |
class CheckBoxRenderer extends JCheckBox implements TableCellRenderer { |
755 |
|
756 |
/**
|
757 |
*
|
758 |
*/
|
759 |
private static final long serialVersionUID = 5093448776058027505L; |
760 |
|
761 |
public CheckBoxRenderer() {
|
762 |
setHorizontalAlignment(JLabel.CENTER);
|
763 |
} |
764 |
|
765 |
public Component getTableCellRendererComponent(JTable table, |
766 |
Object value, boolean isSelected, boolean hasFocus, int row, |
767 |
int column) {
|
768 |
if (isSelected) {
|
769 |
setForeground(table.getSelectionForeground()); |
770 |
setBackground(table.getSelectionBackground()); |
771 |
} else {
|
772 |
setForeground(table.getForeground()); |
773 |
setBackground(table.getBackground()); |
774 |
} |
775 |
setSelected((value != null && ((Boolean) value).booleanValue())); |
776 |
return this; |
777 |
} |
778 |
} |
779 |
|
780 |
/**
|
781 |
* This method initializes jButton
|
782 |
*
|
783 |
* @return javax.swing.JButton
|
784 |
*/
|
785 |
private JButton getJButtonDeleteField() { |
786 |
if (deleteFieldButton == null) { |
787 |
deleteFieldButton = new JButton(); |
788 |
deleteFieldButton.setText(Messages.getText("delete_field"));
|
789 |
deleteFieldButton.setLocation(new java.awt.Point(7, 33)); |
790 |
deleteFieldButton.setSize(new java.awt.Dimension(145, 23)); |
791 |
deleteFieldButton.setEnabled(false);
|
792 |
deleteFieldButton |
793 |
.addActionListener(new java.awt.event.ActionListener() {
|
794 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
795 |
int[] selecteds = jTable.getSelectedRows(); |
796 |
DefaultTableModel tm = (DefaultTableModel) jTable |
797 |
.getModel(); |
798 |
|
799 |
for (int i = selecteds.length - 1; i >= 0; i--) { |
800 |
/*
|
801 |
*
|
802 |
removedFields.add((String) tm.getValueAt(i, 0));
|
803 |
*/
|
804 |
tm.removeRow(selecteds[i]); |
805 |
} |
806 |
} |
807 |
}); |
808 |
} |
809 |
deleteFieldButton.setEnabled(false);
|
810 |
return deleteFieldButton;
|
811 |
} |
812 |
|
813 |
public String getPanelTitle() { |
814 |
return Messages.getText("fields_definitions"); |
815 |
} |
816 |
|
817 |
public void nextPanel() throws NotContinueWizardException { |
818 |
if (allowEditableFeatureType()){
|
819 |
fillFeatureType(); |
820 |
} |
821 |
} |
822 |
|
823 |
private void fillFeatureType() throws NotContinueWizardException { |
824 |
|
825 |
if (!fieldsInited) {
|
826 |
initFields(); |
827 |
} |
828 |
|
829 |
/*
|
830 |
* Coge los datos del formulario y los guarda en
|
831 |
* this.service.getFeatureType()
|
832 |
*/
|
833 |
|
834 |
EditableFeatureType edft = newLayer_Service.getFeatureType(); |
835 |
|
836 |
// Clean and rebuild featureType everytime we click next
|
837 |
removeAllFields(edft); |
838 |
edft.setDefaultGeometryAttributeName(null);
|
839 |
|
840 |
GeometryManager gm = GeometryLocator.getGeometryManager(); |
841 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
842 |
|
843 |
for (int i = 0; i < tm.getRowCount(); i++) { |
844 |
DataType dataType = ((ComboItemDataType) tm.getValueAt(i, COLUMN_TYPE)).dataType; |
845 |
|
846 |
int fieldLength = 20; |
847 |
if (dataTypeNeedsSize(dataType.getType())) {
|
848 |
fieldLength = |
849 |
Integer.parseInt((String) tm.getValueAt(i, COLUMN_LENGTH)); |
850 |
} |
851 |
|
852 |
EditableFeatureAttributeDescriptor efad1 = |
853 |
edft.add( |
854 |
(String) tm.getValueAt(i, COLUMN_FIELD), dataType.getType(),
|
855 |
fieldLength); |
856 |
|
857 |
if (dataType.getType() == DataTypes.DOUBLE ||
|
858 |
dataType.getType() == DataTypes.FLOAT) { |
859 |
// TODO Improve this?
|
860 |
// Half of the size dedicated
|
861 |
// to precision (at least 1)
|
862 |
efad1.setPrecision(Math.max(1, fieldLength/2)); |
863 |
} |
864 |
|
865 |
if (dataType.getType() == DataTypes.GEOMETRY) {
|
866 |
|
867 |
int g_type = ((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYTYPE)).type;
|
868 |
int g_subtype = ((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYSUBTYPE)).type;
|
869 |
|
870 |
GeometryType gty = null;
|
871 |
|
872 |
try {
|
873 |
gty = gm.getGeometryType(g_type, g_subtype); |
874 |
efad1.setGeometryType(gty); |
875 |
// efad1.setGeometryType(g_type);
|
876 |
} catch (Exception ex) { |
877 |
String _msg = Messages.getText("_Invalid_geometry_type") |
878 |
+ " (" + g_type + ", " + g_subtype + ")"; |
879 |
throw new NotContinueWizardException(_msg, ex, this); |
880 |
} |
881 |
|
882 |
efad1.setSRS((IProjection) tm.getValueAt(i, COLUMN_CRS)); |
883 |
|
884 |
//If there is not a previous default geometry field, add it
|
885 |
// this will set the first geometry field
|
886 |
// as the default geometry field
|
887 |
if (edft.getDefaultGeometryAttribute() == null){ |
888 |
edft.setDefaultGeometryAttributeName(efad1.getName()); |
889 |
} |
890 |
} |
891 |
|
892 |
// pk and mandatory
|
893 |
efad1.setIsPrimaryKey(((Boolean) tm.getValueAt(i, COLUMN_PRIMARYKEY))
|
894 |
.booleanValue()); |
895 |
efad1.setAllowNull(!((Boolean) tm.getValueAt(i, COLUMN_MANDATORY))
|
896 |
.booleanValue()); |
897 |
|
898 |
} |
899 |
} |
900 |
|
901 |
/**
|
902 |
* @param featureType
|
903 |
*/
|
904 |
private void removeAllFields(EditableFeatureType ft) { |
905 |
|
906 |
FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
|
907 |
int len = atts.length;
|
908 |
FeatureAttributeDescriptor item = null;
|
909 |
for (int i=0; i<len; i++) { |
910 |
item = atts[i]; |
911 |
ft.remove(item.getName()); |
912 |
} |
913 |
} |
914 |
|
915 |
public void lastPanel() { |
916 |
// TODO Auto-generated method stub
|
917 |
logger.info("FeatureTypePanel: lastPanel");
|
918 |
} |
919 |
|
920 |
public void updatePanel() { |
921 |
initializeComponents(); |
922 |
|
923 |
} |
924 |
|
925 |
public JPanel getJPanel() { |
926 |
return this; |
927 |
} |
928 |
|
929 |
/**
|
930 |
* If fad is null, it's an addition after user has clicked on 'Add field'.
|
931 |
* If fad is not null, it's the description of a default field and the
|
932 |
* field name will also be taken from there.
|
933 |
*
|
934 |
* @param the_table
|
935 |
* @param new_fld_name
|
936 |
* @param the_projection
|
937 |
* @param fad
|
938 |
*
|
939 |
* @return true if field was actually added, false otherwise
|
940 |
*/
|
941 |
private boolean addRowToFieldTable( |
942 |
JTable the_table,
|
943 |
String new_fld_name,
|
944 |
IProjection the_projection, |
945 |
FeatureAttributeDescriptor fad) { |
946 |
|
947 |
if (fad == null && new_fld_name == null) { |
948 |
logger.info("Error: unable to add field to table (no description and no name)");
|
949 |
return false; |
950 |
} |
951 |
|
952 |
DefaultTableModel the_tm = (DefaultTableModel) the_table.getModel(); |
953 |
Object[] newRow = new Object[the_tm.getColumnCount()]; |
954 |
|
955 |
/*
|
956 |
tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD);
|
957 |
tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE);
|
958 |
tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH);
|
959 |
tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE);
|
960 |
tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE);
|
961 |
tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS);
|
962 |
tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY);
|
963 |
tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY);
|
964 |
*/
|
965 |
|
966 |
// =============================== name
|
967 |
if (fad == null) { |
968 |
newRow[COLUMN_FIELD] = new_fld_name; |
969 |
} else {
|
970 |
newRow[COLUMN_FIELD] = fad.getName(); |
971 |
} |
972 |
// ===================================== field type
|
973 |
TableColumn typeColumn = the_table.getColumnModel().getColumn(COLUMN_TYPE);
|
974 |
List supp_types = spFactory.getSupportedDataTypes();
|
975 |
|
976 |
DataManager daman = DALLocator.getDataManager(); |
977 |
List all_types = daman.getDataTypes();
|
978 |
|
979 |
|
980 |
ComboModelDataType model = null;
|
981 |
if (fad == null) { |
982 |
|
983 |
// this is a user defined column, remove geometry if in default feattype
|
984 |
if (defaultHasGeometry) {
|
985 |
supp_types = removeGeometryType(supp_types); |
986 |
all_types = removeGeometryType(all_types); |
987 |
} |
988 |
|
989 |
if (supp_types != null && supp_types.size() > 0) { |
990 |
model = new ComboModelDataType(
|
991 |
supp_types, |
992 |
((DataType) supp_types.get(0)).getType());
|
993 |
} else {
|
994 |
model = new ComboModelDataType(
|
995 |
all_types, |
996 |
((DataType) all_types.get(0)).getType());
|
997 |
} |
998 |
} else {
|
999 |
model = new ComboModelDataType(supp_types, fad.getType());
|
1000 |
} |
1001 |
|
1002 |
JComboBox comboBox = new JComboBox(model); |
1003 |
typeColumn.setCellEditor(new DefaultCellEditor(comboBox)); |
1004 |
newRow[COLUMN_TYPE] = model.getSelectedItem(); |
1005 |
|
1006 |
// ============================= width
|
1007 |
TableColumn widthColumn =
|
1008 |
the_table.getColumnModel().getColumn(COLUMN_LENGTH); |
1009 |
if (fad == null) { |
1010 |
newRow[COLUMN_LENGTH] = "20";
|
1011 |
} else {
|
1012 |
newRow[COLUMN_LENGTH] = "" + fad.getSize();
|
1013 |
} |
1014 |
|
1015 |
SimpleTextCellRenderer stcr = new SimpleTextCellRenderer();
|
1016 |
widthColumn.setCellEditor(new DefaultCellEditor(new JTextField())); |
1017 |
widthColumn.setCellRenderer(stcr); |
1018 |
|
1019 |
|
1020 |
// ============================= geom type
|
1021 |
TableColumn geomTypeColumn =
|
1022 |
the_table.getColumnModel().getColumn(COLUMN_GEOMETRYTYPE); |
1023 |
ComboModelGeomType geomTypeModel = null;
|
1024 |
|
1025 |
List<ComboItemGeomType> supptd =
|
1026 |
leaveSupportedGeomTypes(getGeomTypes(), |
1027 |
spFactory.getSupportedGeometryTypesSubtypes(), 0);
|
1028 |
|
1029 |
if (fad == null) { |
1030 |
geomTypeModel = new ComboModelGeomType(
|
1031 |
supptd, supptd.size() > 0 ? supptd.get(0).getGeomType() : -1); |
1032 |
} else {
|
1033 |
geomTypeModel = new ComboModelGeomType(
|
1034 |
supptd, fad.getGeomType().getType()); |
1035 |
} |
1036 |
|
1037 |
JComboBox geomTypeComboBox = new JComboBox(geomTypeModel); |
1038 |
geomTypeColumn.setCellEditor(new DefaultCellEditor(geomTypeComboBox)); |
1039 |
|
1040 |
GeometryComboCellRenderer gccr = new GeometryComboCellRenderer();
|
1041 |
geomTypeColumn.setCellRenderer(gccr); |
1042 |
newRow[COLUMN_GEOMETRYTYPE] = geomTypeModel.getSelectedItem(); |
1043 |
|
1044 |
// ============================= geom sub type
|
1045 |
|
1046 |
TableColumn geomSubTypeColumn =
|
1047 |
the_table.getColumnModel().getColumn(COLUMN_GEOMETRYSUBTYPE); |
1048 |
ComboModelGeomType geomSubTypeModel = null;
|
1049 |
|
1050 |
supptd = |
1051 |
leaveSupportedGeomTypes(getGeomSubtypes(), |
1052 |
spFactory.getSupportedGeometryTypesSubtypes(), 1);
|
1053 |
|
1054 |
if (fad == null) { |
1055 |
geomSubTypeModel = new ComboModelGeomType(
|
1056 |
supptd, supptd.size() > 0 ? supptd.get(0).getGeomType() : -1); |
1057 |
} else {
|
1058 |
geomSubTypeModel = new ComboModelGeomType(
|
1059 |
supptd, fad.getGeomType().getSubType()); |
1060 |
} |
1061 |
|
1062 |
JComboBox geomSubTypeComboBox = new JComboBox(geomSubTypeModel); |
1063 |
geomSubTypeColumn.setCellEditor(new DefaultCellEditor( |
1064 |
geomSubTypeComboBox)); |
1065 |
geomSubTypeColumn.setCellRenderer(new GeometryComboCellRenderer());
|
1066 |
newRow[COLUMN_GEOMETRYSUBTYPE] = geomSubTypeModel.getSelectedItem(); |
1067 |
|
1068 |
// ============================= CRS
|
1069 |
|
1070 |
TableColumn crsColumn = the_table.getColumnModel().getColumn(COLUMN_CRS);
|
1071 |
crsColumn.setCellEditor(new ButtonEditor(new JCheckBox())); |
1072 |
CrsRenderer crsButtonRenderer = new CrsRenderer();
|
1073 |
crsColumn.setCellRenderer(crsButtonRenderer); |
1074 |
newRow[COLUMN_CRS] = the_projection; |
1075 |
|
1076 |
// ============================= PK
|
1077 |
|
1078 |
TableColumn primaryKeyColumn =
|
1079 |
the_table.getColumnModel().getColumn(COLUMN_PRIMARYKEY); |
1080 |
JCheckBox primaryKeyCheckBox = new JCheckBox(); |
1081 |
|
1082 |
if (fad == null) { |
1083 |
primaryKeyCheckBox.setSelected(false);
|
1084 |
} else {
|
1085 |
primaryKeyCheckBox.setSelected(fad.isPrimaryKey()); |
1086 |
} |
1087 |
|
1088 |
primaryKeyColumn.setCellEditor( |
1089 |
new DefaultCellEditor(primaryKeyCheckBox)); |
1090 |
CheckBoxRenderer primaryKeyCheckBoxRenderer = new CheckBoxRenderer();
|
1091 |
primaryKeyColumn.setCellRenderer(primaryKeyCheckBoxRenderer); |
1092 |
newRow[COLUMN_PRIMARYKEY] = primaryKeyCheckBox.isSelected(); |
1093 |
|
1094 |
// ================================== mandatory
|
1095 |
|
1096 |
TableColumn mandatoryColumn =
|
1097 |
the_table.getColumnModel().getColumn(COLUMN_MANDATORY); |
1098 |
JCheckBox mandatoryCheckBox = new JCheckBox(); |
1099 |
|
1100 |
if (fad == null) { |
1101 |
mandatoryCheckBox.setSelected(false);
|
1102 |
} else {
|
1103 |
mandatoryCheckBox.setSelected(fad.isMandatory()); |
1104 |
} |
1105 |
|
1106 |
mandatoryColumn.setCellEditor(new DefaultCellEditor(mandatoryCheckBox)); |
1107 |
CheckBoxRenderer mandatoryCheckBoxRenderer = new CheckBoxRenderer();
|
1108 |
mandatoryColumn.setCellRenderer(mandatoryCheckBoxRenderer); |
1109 |
newRow[COLUMN_MANDATORY] = mandatoryCheckBox.isSelected(); |
1110 |
|
1111 |
// ==================================
|
1112 |
|
1113 |
// Add a new row
|
1114 |
the_tm.addRow(newRow); |
1115 |
return true; |
1116 |
} |
1117 |
|
1118 |
/**
|
1119 |
* @param supp_types
|
1120 |
* @return
|
1121 |
*/
|
1122 |
private List removeGeometryType(List dta_types) { |
1123 |
List resp = new ArrayList(); |
1124 |
|
1125 |
int len = dta_types.size();
|
1126 |
Object item_o = null; |
1127 |
DataType item_dt = null;
|
1128 |
|
1129 |
for (int i=0; i<len; i++) { |
1130 |
item_o = dta_types.get(i); |
1131 |
if (item_o instanceof DataType) { |
1132 |
item_dt = (DataType) item_o; |
1133 |
if (item_dt.getType() != DataTypes.GEOMETRY) {
|
1134 |
resp.add(item_dt); |
1135 |
} |
1136 |
} |
1137 |
} |
1138 |
return resp;
|
1139 |
} |
1140 |
|
1141 |
private List<ComboItemGeomType> leaveSupportedGeomTypes( |
1142 |
List<ComboItemGeomType> all_types,
|
1143 |
List<int[]> supported, |
1144 |
int index /* 0 for geom types, 1 for geom subtypes */) { |
1145 |
|
1146 |
if (supported == null) { |
1147 |
// all supported
|
1148 |
return all_types;
|
1149 |
} |
1150 |
|
1151 |
List<ComboItemGeomType> resp = new ArrayList<ComboItemGeomType>(); |
1152 |
int len = all_types.size();
|
1153 |
ComboItemGeomType item = null;
|
1154 |
for (int i=0; i<len; i++) { |
1155 |
item = all_types.get(i); |
1156 |
if (isInNthElement(item.getGeomType(), supported, index)) {
|
1157 |
resp.add(item); |
1158 |
} |
1159 |
} |
1160 |
return resp;
|
1161 |
} |
1162 |
|
1163 |
|
1164 |
private boolean isInNthElement(int val, List<int[]> arr_list, int index) { |
1165 |
|
1166 |
int len = arr_list.size();
|
1167 |
int[] item = null; |
1168 |
for (int i=0; i<len; i++) { |
1169 |
item = arr_list.get(i); |
1170 |
if (item != null && item.length > index && item[index] == val) { |
1171 |
return true; |
1172 |
} |
1173 |
} |
1174 |
return false; |
1175 |
} |
1176 |
|
1177 |
private boolean dataTypeNeedsSize(int data_type) { |
1178 |
|
1179 |
if (data_type == DataTypes.FLOAT
|
1180 |
|| data_type == DataTypes.INT |
1181 |
|| data_type == DataTypes.STRING) { |
1182 |
return true; |
1183 |
} else {
|
1184 |
return false; |
1185 |
} |
1186 |
} |
1187 |
|
1188 |
private class SimpleTextCellRenderer extends DefaultTableCellRenderer { |
1189 |
|
1190 |
public SimpleTextCellRenderer() {
|
1191 |
super();
|
1192 |
} |
1193 |
/* (non-Javadoc)
|
1194 |
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
|
1195 |
*/
|
1196 |
public Component getTableCellRendererComponent( |
1197 |
JTable table,
|
1198 |
Object value, boolean isSelected, boolean hasFocus, int row, |
1199 |
int column) {
|
1200 |
|
1201 |
TableModel tm = table.getModel();
|
1202 |
Object new_val = ""; |
1203 |
Object type_obj = tm.getValueAt(row, COLUMN_TYPE);
|
1204 |
if (type_obj instanceof ComboItemDataType) { |
1205 |
ComboItemDataType type_item = (ComboItemDataType) type_obj; |
1206 |
if (dataTypeNeedsSize(type_item.dataType.getType())) {
|
1207 |
new_val = getCurrentOr(value, "");
|
1208 |
} else {
|
1209 |
new_val = Messages.getText("not_applicable");
|
1210 |
} |
1211 |
return super.getTableCellRendererComponent( |
1212 |
table, new_val, isSelected, hasFocus, row, column); |
1213 |
} else {
|
1214 |
return super.getTableCellRendererComponent( |
1215 |
table, value, isSelected, hasFocus, row, column); |
1216 |
} |
1217 |
} |
1218 |
|
1219 |
private Object getCurrentOr(Object v, String d) { |
1220 |
|
1221 |
if (v instanceof String) { |
1222 |
String parse_str = (String) v; |
1223 |
try {
|
1224 |
Integer.parseInt(parse_str);
|
1225 |
return v;
|
1226 |
} catch (Exception ex) { |
1227 |
// not a valid integer
|
1228 |
return d;
|
1229 |
} |
1230 |
} else {
|
1231 |
return v;
|
1232 |
} |
1233 |
} |
1234 |
|
1235 |
} |
1236 |
|
1237 |
private class EnableLengthItemListener implements ItemListener { |
1238 |
|
1239 |
private TableModel theTableModel = null; |
1240 |
private JTable theTable = null; |
1241 |
|
1242 |
public EnableLengthItemListener(JTable t, boolean b) { |
1243 |
theTable = t; |
1244 |
theTableModel = t.getModel(); |
1245 |
} |
1246 |
|
1247 |
public void itemStateChanged(final ItemEvent e) { |
1248 |
doUpdate(e); |
1249 |
} |
1250 |
|
1251 |
public void doUpdate(ItemEvent e) { |
1252 |
|
1253 |
Object src_obj = e.getSource();
|
1254 |
if (src_obj instanceof JComboBox) { |
1255 |
|
1256 |
// one of the field type combos has changed
|
1257 |
int len = theTableModel.getRowCount();
|
1258 |
Object type_obj = null; |
1259 |
ComboItemDataType type_item = null;
|
1260 |
for (int i=0; i<len; i++) { |
1261 |
type_obj = theTableModel.getValueAt(i, COLUMN_TYPE); |
1262 |
if (type_obj instanceof ComboItemDataType) { |
1263 |
type_item = (ComboItemDataType) type_obj; |
1264 |
if (dataTypeNeedsSize(type_item.dataType.getType())) {
|
1265 |
theTableModel.setValueAt( |
1266 |
"20",
|
1267 |
i, COLUMN_LENGTH); |
1268 |
} else {
|
1269 |
theTableModel.setValueAt( |
1270 |
Messages.getText("not_applicable"),
|
1271 |
i, COLUMN_LENGTH); |
1272 |
} |
1273 |
} |
1274 |
} |
1275 |
theTable.validate(); // .revalidate(); // .repaint();
|
1276 |
} |
1277 |
} |
1278 |
|
1279 |
} |
1280 |
|
1281 |
|
1282 |
|
1283 |
|
1284 |
|
1285 |
} |