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 @ 43563
History | View | Annotate | Download (41.6 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 |
|
270 |
tm.addColumn(Messages.getText("_Name"));
|
271 |
tm.addColumn(Messages.getText("type"));
|
272 |
tm.addColumn(Messages.getText("length"));
|
273 |
tm.addColumn(Messages.getText("_Geometry_type"));
|
274 |
tm.addColumn(Messages.getText("_Dimensions"));
|
275 |
tm.addColumn(Messages.getText("CRS"));
|
276 |
tm.addColumn("PK");
|
277 |
tm.addColumn(Messages.getText("_Mandatory_(short_text)"));
|
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.getColumnModel().getColumn(0).setPreferredWidth(100); |
304 |
// PK column
|
305 |
jTable.getColumnModel().getColumn(6).setPreferredWidth(30); |
306 |
// Oblig column
|
307 |
jTable.getColumnModel().getColumn(7).setPreferredWidth(50); |
308 |
|
309 |
jTable.getModel().addTableModelListener(new TableModelListener() { |
310 |
public void tableChanged(TableModelEvent e) { |
311 |
if (e.getColumn() == COLUMN_TYPE){
|
312 |
jTable.repaint(); |
313 |
} |
314 |
} |
315 |
}); |
316 |
|
317 |
|
318 |
if (!fieldsInited) {
|
319 |
initFields(); |
320 |
} |
321 |
|
322 |
// Rellenado de la tabla
|
323 |
if (defaultFeatType != null) { |
324 |
|
325 |
Iterator it = defaultFeatType.iterator();
|
326 |
boolean some_error = false; |
327 |
while (it.hasNext()) {
|
328 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) it |
329 |
.next(); |
330 |
|
331 |
if (!addRowToFieldTable(
|
332 |
jTable, |
333 |
null,
|
334 |
inProjection, |
335 |
descriptor)) { |
336 |
|
337 |
some_error = true;
|
338 |
} |
339 |
/*
|
340 |
tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD);
|
341 |
tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE);
|
342 |
tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH);
|
343 |
tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE);
|
344 |
tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE);
|
345 |
tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS);
|
346 |
tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY);
|
347 |
tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY);
|
348 |
*/
|
349 |
} |
350 |
|
351 |
if (some_error) {
|
352 |
String tit = Messages.getText("_Default_fields"); |
353 |
String msg = Messages.getText("_Unable_to_add_fields"); |
354 |
JOptionPane.showMessageDialog(
|
355 |
jTable, msg, tit, |
356 |
JOptionPane.ERROR_MESSAGE);
|
357 |
} |
358 |
} |
359 |
|
360 |
} |
361 |
jTable.setEnabled(allowEditableFeatureType()); |
362 |
return jTable;
|
363 |
} |
364 |
|
365 |
/**
|
366 |
* This method initializes jPanelWest
|
367 |
*
|
368 |
* @return javax.swing.JPanel
|
369 |
*/
|
370 |
private JPanel getJPanelSouth() { |
371 |
if (jPanelEast == null) { |
372 |
jPanelEast = new JPanel(); |
373 |
jPanelEast.setLayout(new BorderLayout()); |
374 |
|
375 |
JPanel south_east = new JPanel(new GridBagLayout()); |
376 |
// south_east.setPreferredSize(new java.awt.Dimension(170, 50));
|
377 |
GridBagConstraints c = new GridBagConstraints(); |
378 |
c.fill = GridBagConstraints.HORIZONTAL;
|
379 |
c.insets = new Insets(8,10,8,0); //top padding |
380 |
c.gridx = 0;
|
381 |
c.gridwidth = 1;
|
382 |
c.gridy = 0;
|
383 |
south_east.add(getJButtonAddField(), c); |
384 |
c.gridx = 1;
|
385 |
south_east.add(getJButtonDeleteField(), c); |
386 |
|
387 |
jPanelEast.add(south_east, BorderLayout.EAST);
|
388 |
} |
389 |
return jPanelEast;
|
390 |
} |
391 |
|
392 |
/**
|
393 |
* This method initializes jButtonAddField
|
394 |
*
|
395 |
* @return javax.swing.JButton
|
396 |
*/
|
397 |
private JButton getJButtonAddField() { |
398 |
if (addFieldButton == null) { |
399 |
addFieldButton = new JButton(); |
400 |
addFieldButton.setText(Messages.getText("add_field"));
|
401 |
addFieldButton.setLocation(new java.awt.Point(7, 5)); |
402 |
addFieldButton.setSize(new java.awt.Dimension(180, 23)); |
403 |
addFieldButton.setPreferredSize(new java.awt.Dimension(180, 23)); |
404 |
addFieldButton |
405 |
.addActionListener(new java.awt.event.ActionListener() {
|
406 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
407 |
DefaultTableModel tm = (DefaultTableModel) jTable |
408 |
.getModel(); |
409 |
|
410 |
// Figure out a suitable field name
|
411 |
ArrayList fieldNames = new ArrayList(); |
412 |
for (int i = 0; i < jTable.getRowCount(); i++) { |
413 |
fieldNames.add(tm.getValueAt(i, COLUMN_FIELD)); |
414 |
} |
415 |
String[] currentFieldNames = (String[]) fieldNames |
416 |
.toArray(new String[0]); |
417 |
String newField = Messages.getText("field") |
418 |
.replaceAll(" +", "_"); |
419 |
int index = 0; |
420 |
for (int i = 0; i < currentFieldNames.length; i++) { |
421 |
if (currentFieldNames[i].startsWith(newField)) {
|
422 |
try {
|
423 |
index = Integer
|
424 |
.parseInt(currentFieldNames[i] |
425 |
.replaceAll(newField, |
426 |
""));
|
427 |
} catch (Exception ex) { /* we don't care */ |
428 |
} |
429 |
} |
430 |
} |
431 |
String newFieldName = newField + (++index);
|
432 |
|
433 |
// Esto lo a?ado aqu? porque si no tiene registros,
|
434 |
// no hace caso. (Por eso no
|
435 |
// lo pongo en getJTable()
|
436 |
if (!addRowToFieldTable(
|
437 |
jTable, |
438 |
newFieldName, |
439 |
inProjection, |
440 |
null)) {
|
441 |
|
442 |
String tit = Messages.getText("_Default_fields"); |
443 |
String msg = Messages.getText("_Unable_to_add_fields"); |
444 |
JOptionPane.showMessageDialog(
|
445 |
jTable, msg, tit, |
446 |
JOptionPane.ERROR_MESSAGE);
|
447 |
} |
448 |
} |
449 |
}); |
450 |
|
451 |
} |
452 |
addFieldButton.setEnabled(allowEditableFeatureType()); |
453 |
return addFieldButton;
|
454 |
} |
455 |
|
456 |
private boolean allowEditableFeatureType(){ |
457 |
|
458 |
if (!fieldsInited) {
|
459 |
initFields(); |
460 |
} |
461 |
|
462 |
DataManager dataManager = DALLocator.getDataManager(); |
463 |
FeatureStoreProviderFactory factory = |
464 |
(FeatureStoreProviderFactory) dataManager. |
465 |
getStoreProviderFactory(inStoreName); |
466 |
if (factory.allowEditableFeatureType()==FeatureStoreProviderFactory.NO) {
|
467 |
return false; |
468 |
} |
469 |
return true; |
470 |
} |
471 |
|
472 |
private class ComboItemDataType { |
473 |
private DataType dataType;
|
474 |
|
475 |
public ComboItemDataType(DataType dataType) {
|
476 |
this.dataType = dataType;
|
477 |
} |
478 |
|
479 |
@Override
|
480 |
public String toString() { |
481 |
return this.dataType.getName(); |
482 |
} |
483 |
} |
484 |
|
485 |
private class ComboModelDataType implements ComboBoxModel { |
486 |
|
487 |
private List<ComboItemDataType> dataTypes; |
488 |
private ComboItemDataType selected;
|
489 |
|
490 |
public ComboModelDataType(List<DataType> dataTypes, int sel_type) { |
491 |
|
492 |
this.dataTypes = new ArrayList<ComboItemDataType>(); |
493 |
ComboItemDataType item = null;
|
494 |
for (Iterator iterator = dataTypes.iterator(); iterator.hasNext();) { |
495 |
DataType dataType = (DataType) iterator.next(); |
496 |
item = new ComboItemDataType(dataType);
|
497 |
this.dataTypes.add(item);
|
498 |
if (sel_type == dataType.getType()) {
|
499 |
this.setSelectedItem(item);
|
500 |
} |
501 |
} |
502 |
} |
503 |
|
504 |
public void addListDataListener(ListDataListener arg0) { |
505 |
// DO NOTHING
|
506 |
} |
507 |
|
508 |
public Object getElementAt(int arg0) { |
509 |
return this.dataTypes.get(arg0); |
510 |
} |
511 |
|
512 |
public int getSize() { |
513 |
return this.dataTypes.size(); |
514 |
} |
515 |
|
516 |
public void removeListDataListener(ListDataListener arg0) { |
517 |
// DO NOTHING
|
518 |
} |
519 |
|
520 |
public Object getSelectedItem() { |
521 |
return this.selected; |
522 |
} |
523 |
|
524 |
public void setSelectedItem(Object anItem) { |
525 |
this.selected = (ComboItemDataType) anItem;
|
526 |
} |
527 |
|
528 |
} |
529 |
|
530 |
class CrsRenderer extends JButton implements TableCellRenderer { |
531 |
private static final long serialVersionUID = -573793294070515376L; |
532 |
private JLabel label = null; |
533 |
|
534 |
public CrsRenderer() {
|
535 |
setOpaque(true);
|
536 |
label = new JLabel(Messages.getText("not_applicable")); |
537 |
this.setMargin(new Insets(2, 0, 2, 0)); |
538 |
this.setFont(this.getFont().deriveFont(9f)); |
539 |
} |
540 |
|
541 |
public Component getTableCellRendererComponent(JTable table, |
542 |
Object value, boolean isSelected, boolean hasFocus, int row, |
543 |
int column) {
|
544 |
|
545 |
ComboItemDataType item = |
546 |
(ComboItemDataType) table.getValueAt(row, COLUMN_TYPE); |
547 |
|
548 |
if (item == null) { |
549 |
// happens sometimes. perhaps an early rendering?
|
550 |
return new JLabel(); |
551 |
} |
552 |
|
553 |
DataType dataType = item.dataType; |
554 |
|
555 |
if (dataType.getType() != DataTypes.GEOMETRY) {
|
556 |
return label;
|
557 |
} |
558 |
|
559 |
if (isSelected) {
|
560 |
setForeground(table.getSelectionForeground()); |
561 |
setBackground(table.getSelectionBackground()); |
562 |
} else {
|
563 |
setForeground(table.getForeground()); |
564 |
setBackground(UIManager.getColor("Button.background")); |
565 |
} |
566 |
setText((value == null) ? "" : ((IProjection) value).getFullCode()); |
567 |
return this; |
568 |
} |
569 |
} |
570 |
|
571 |
private class GeometryComboCellRenderer extends JLabel implements TableCellRenderer{ |
572 |
|
573 |
public Component getTableCellRendererComponent(JTable table, |
574 |
Object value, boolean isSelected, boolean hasFocus, int row, |
575 |
int column) {
|
576 |
|
577 |
ComboItemDataType item = (ComboItemDataType) table.getValueAt(row, COLUMN_TYPE); |
578 |
DataType dataType = item.dataType; |
579 |
|
580 |
if (dataType.getType() == DataTypes.GEOMETRY) {
|
581 |
ComboItemGeomType geomType = (ComboItemGeomType)value; |
582 |
if (geomType != null) { |
583 |
this.setText(geomType.toString());
|
584 |
} |
585 |
} else {
|
586 |
this.setText(Messages.getText("not_applicable")); |
587 |
} |
588 |
|
589 |
return this; |
590 |
} |
591 |
|
592 |
} |
593 |
|
594 |
class ButtonEditor extends DefaultCellEditor { |
595 |
/**
|
596 |
*
|
597 |
*/
|
598 |
private static final long serialVersionUID = -2820892672026188802L; |
599 |
|
600 |
protected JButton button; |
601 |
|
602 |
private String label; |
603 |
|
604 |
private boolean isPushed; |
605 |
|
606 |
private Object value; |
607 |
|
608 |
public ButtonEditor(JCheckBox checkBox) { |
609 |
super(checkBox);
|
610 |
button = new JButton(); |
611 |
button.setOpaque(true);
|
612 |
button.addActionListener(new ActionListener() { |
613 |
public void actionPerformed(ActionEvent e) { |
614 |
fireEditingStopped(); |
615 |
} |
616 |
}); |
617 |
} |
618 |
|
619 |
public Component getTableCellEditorComponent(JTable table, |
620 |
Object value, boolean isSelected, int row, int column) { |
621 |
if (isSelected) {
|
622 |
button.setForeground(table.getSelectionForeground()); |
623 |
button.setBackground(table.getSelectionBackground()); |
624 |
} else {
|
625 |
button.setForeground(table.getForeground()); |
626 |
button.setBackground(table.getBackground()); |
627 |
} |
628 |
label = (value == null) ? "" : ((IProjection) value).getFullCode();// .toString(); |
629 |
button.setText(label); |
630 |
isPushed = true;
|
631 |
this.value = value;
|
632 |
return button;
|
633 |
} |
634 |
|
635 |
public Object getCellEditorValue() { |
636 |
IProjection curProj = (IProjection) this.value;
|
637 |
if (isPushed) {
|
638 |
ISelectCrsPanel csSelect = CRSSelectPanel.getUIFactory() |
639 |
.getSelectCrsPanel(curProj, true);
|
640 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
641 |
wm.showWindow((JPanel) csSelect, "Projection", |
642 |
WindowManager.MODE.DIALOG); |
643 |
curProj = csSelect.getProjection(); |
644 |
} |
645 |
isPushed = false;
|
646 |
return curProj;
|
647 |
} |
648 |
|
649 |
public boolean stopCellEditing() { |
650 |
isPushed = false;
|
651 |
return super.stopCellEditing(); |
652 |
} |
653 |
|
654 |
protected void fireEditingStopped() { |
655 |
super.fireEditingStopped();
|
656 |
} |
657 |
} |
658 |
|
659 |
private class ComboItemGeomType { |
660 |
private int type; |
661 |
private String name; |
662 |
|
663 |
public ComboItemGeomType(String name, int type) { |
664 |
this.type = type;
|
665 |
this.name = name;
|
666 |
} |
667 |
|
668 |
@Override
|
669 |
public String toString() { |
670 |
return this.name; |
671 |
} |
672 |
|
673 |
public int getGeomType() { |
674 |
return type;
|
675 |
} |
676 |
} |
677 |
|
678 |
private class ComboModelGeomType implements ComboBoxModel { |
679 |
|
680 |
private List<ComboItemGeomType> geomTypes; |
681 |
private ComboItemGeomType selected;
|
682 |
|
683 |
public ComboModelGeomType(
|
684 |
List<ComboItemGeomType> geomTypes, int sel_geom_type) { |
685 |
|
686 |
this.geomTypes = geomTypes;
|
687 |
int len = geomTypes.size();
|
688 |
ComboItemGeomType item = null;
|
689 |
for (int i=0; i<len; i++) { |
690 |
item = geomTypes.get(i); |
691 |
if (item.getGeomType() == sel_geom_type) {
|
692 |
setSelectedItem(item); |
693 |
} |
694 |
} |
695 |
} |
696 |
|
697 |
public void addListDataListener(ListDataListener arg0) { |
698 |
// DO NOTHING
|
699 |
} |
700 |
|
701 |
public Object getElementAt(int arg0) { |
702 |
return this.geomTypes.get(arg0); |
703 |
} |
704 |
|
705 |
public int getSize() { |
706 |
return this.geomTypes.size(); |
707 |
} |
708 |
|
709 |
public void removeListDataListener(ListDataListener arg0) { |
710 |
// DO NOTHING
|
711 |
} |
712 |
|
713 |
public Object getSelectedItem() { |
714 |
return this.selected; |
715 |
} |
716 |
|
717 |
public void setSelectedItem(Object anItem) { |
718 |
this.selected = (ComboItemGeomType) anItem;
|
719 |
} |
720 |
|
721 |
} |
722 |
|
723 |
private List<ComboItemGeomType> getGeomTypes() { |
724 |
List<ComboItemGeomType> geomTypes = new ArrayList<ComboItemGeomType>(); |
725 |
geomTypes.add(new ComboItemGeomType("GEOMETRY", Geometry.TYPES.GEOMETRY)); |
726 |
geomTypes.add(new ComboItemGeomType("POINT", Geometry.TYPES.POINT)); |
727 |
geomTypes.add(new ComboItemGeomType("LINE", Geometry.TYPES.LINE)); |
728 |
geomTypes.add(new ComboItemGeomType("POLYGON", Geometry.TYPES.POLYGON)); |
729 |
geomTypes.add(new ComboItemGeomType("SOLID", Geometry.TYPES.SOLID)); |
730 |
geomTypes.add(new ComboItemGeomType("AGGREGATE", Geometry.TYPES.AGGREGATE)); |
731 |
geomTypes.add(new ComboItemGeomType("MULTIPOINT", Geometry.TYPES.MULTIPOINT)); |
732 |
geomTypes.add(new ComboItemGeomType("MULTILINE", Geometry.TYPES.MULTILINE)); |
733 |
geomTypes.add(new ComboItemGeomType("MULTIPOLYGON", Geometry.TYPES.MULTIPOLYGON)); |
734 |
geomTypes.add(new ComboItemGeomType("MULTISOLID", 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(180, 23)); |
791 |
deleteFieldButton.setPreferredSize(new java.awt.Dimension(180, 23)); |
792 |
deleteFieldButton.setEnabled(false);
|
793 |
deleteFieldButton |
794 |
.addActionListener(new java.awt.event.ActionListener() {
|
795 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
796 |
int[] selecteds = jTable.getSelectedRows(); |
797 |
DefaultTableModel tm = (DefaultTableModel) jTable |
798 |
.getModel(); |
799 |
|
800 |
for (int i = selecteds.length - 1; i >= 0; i--) { |
801 |
/*
|
802 |
*
|
803 |
removedFields.add((String) tm.getValueAt(i, 0));
|
804 |
*/
|
805 |
tm.removeRow(selecteds[i]); |
806 |
} |
807 |
} |
808 |
}); |
809 |
} |
810 |
deleteFieldButton.setEnabled(false);
|
811 |
return deleteFieldButton;
|
812 |
} |
813 |
|
814 |
public String getPanelTitle() { |
815 |
return Messages.getText("_Field_definitions"); |
816 |
} |
817 |
|
818 |
public void nextPanel() throws NotContinueWizardException { |
819 |
if (allowEditableFeatureType()){
|
820 |
fillFeatureType(); |
821 |
} |
822 |
} |
823 |
|
824 |
private void fillFeatureType() throws NotContinueWizardException { |
825 |
|
826 |
if (!fieldsInited) {
|
827 |
initFields(); |
828 |
} |
829 |
|
830 |
/*
|
831 |
* Coge los datos del formulario y los guarda en
|
832 |
* this.service.getFeatureType()
|
833 |
*/
|
834 |
|
835 |
EditableFeatureType edft = newLayer_Service.getFeatureType(); |
836 |
|
837 |
// Clean and rebuild featureType everytime we click next
|
838 |
removeAllFields(edft); |
839 |
edft.setDefaultGeometryAttributeName(null);
|
840 |
|
841 |
GeometryManager gm = GeometryLocator.getGeometryManager(); |
842 |
DefaultTableModel tm = (DefaultTableModel) jTable.getModel(); |
843 |
|
844 |
for (int i = 0; i < tm.getRowCount(); i++) { |
845 |
DataType dataType = ((ComboItemDataType) tm.getValueAt(i, COLUMN_TYPE)).dataType; |
846 |
|
847 |
int fieldLength = 20; |
848 |
if (dataTypeNeedsSize(dataType.getType())) {
|
849 |
fieldLength = |
850 |
Integer.parseInt((String) tm.getValueAt(i, COLUMN_LENGTH)); |
851 |
} |
852 |
|
853 |
EditableFeatureAttributeDescriptor efad1 = |
854 |
edft.add( |
855 |
(String) tm.getValueAt(i, COLUMN_FIELD), dataType.getType(),
|
856 |
fieldLength); |
857 |
|
858 |
if (dataType.getType() == DataTypes.DOUBLE ||
|
859 |
dataType.getType() == DataTypes.FLOAT) { |
860 |
// TODO Improve this?
|
861 |
// Half of the size dedicated
|
862 |
// to precision (at least 1)
|
863 |
efad1.setPrecision(Math.max(1, fieldLength/2)); |
864 |
} |
865 |
|
866 |
if (dataType.getType() == DataTypes.GEOMETRY) {
|
867 |
|
868 |
int g_type = ((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYTYPE)).type;
|
869 |
int g_subtype = ((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYSUBTYPE)).type;
|
870 |
|
871 |
GeometryType gty = null;
|
872 |
|
873 |
try {
|
874 |
gty = gm.getGeometryType(g_type, g_subtype); |
875 |
efad1.setGeometryType(gty); |
876 |
// efad1.setGeometryType(g_type);
|
877 |
} catch (Exception ex) { |
878 |
String _msg = Messages.getText("_Invalid_geometry_type") |
879 |
+ " (" + g_type + ", " + g_subtype + ")"; |
880 |
throw new NotContinueWizardException(_msg, ex, this); |
881 |
} |
882 |
|
883 |
efad1.setSRS((IProjection) tm.getValueAt(i, COLUMN_CRS)); |
884 |
|
885 |
//If there is not a previous default geometry field, add it
|
886 |
// this will set the first geometry field
|
887 |
// as the default geometry field
|
888 |
if (edft.getDefaultGeometryAttribute() == null){ |
889 |
edft.setDefaultGeometryAttributeName(efad1.getName()); |
890 |
} |
891 |
} |
892 |
|
893 |
// pk and mandatory
|
894 |
efad1.setIsPrimaryKey(((Boolean) tm.getValueAt(i, COLUMN_PRIMARYKEY))
|
895 |
.booleanValue()); |
896 |
efad1.setAllowNull(!((Boolean) tm.getValueAt(i, COLUMN_MANDATORY))
|
897 |
.booleanValue()); |
898 |
|
899 |
} |
900 |
} |
901 |
|
902 |
/**
|
903 |
* @param featureType
|
904 |
*/
|
905 |
private void removeAllFields(EditableFeatureType ft) { |
906 |
|
907 |
FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
|
908 |
int len = atts.length;
|
909 |
FeatureAttributeDescriptor item = null;
|
910 |
for (int i=0; i<len; i++) { |
911 |
item = atts[i]; |
912 |
ft.remove(item.getName()); |
913 |
} |
914 |
} |
915 |
|
916 |
public void lastPanel() { |
917 |
// TODO Auto-generated method stub
|
918 |
logger.info("FeatureTypePanel: lastPanel");
|
919 |
} |
920 |
|
921 |
public void updatePanel() { |
922 |
initializeComponents(); |
923 |
|
924 |
} |
925 |
|
926 |
public JPanel getJPanel() { |
927 |
return this; |
928 |
} |
929 |
|
930 |
/**
|
931 |
* If fad is null, it's an addition after user has clicked on 'Add field'.
|
932 |
* If fad is not null, it's the description of a default field and the
|
933 |
* field name will also be taken from there.
|
934 |
*
|
935 |
* @param the_table
|
936 |
* @param new_fld_name
|
937 |
* @param the_projection
|
938 |
* @param fad
|
939 |
*
|
940 |
* @return true if field was actually added, false otherwise
|
941 |
*/
|
942 |
private boolean addRowToFieldTable( |
943 |
JTable the_table,
|
944 |
String new_fld_name,
|
945 |
IProjection the_projection, |
946 |
FeatureAttributeDescriptor fad) { |
947 |
|
948 |
if (fad == null && new_fld_name == null) { |
949 |
logger.info("Error: unable to add field to table (no description and no name)");
|
950 |
return false; |
951 |
} |
952 |
|
953 |
DefaultTableModel the_tm = (DefaultTableModel) the_table.getModel(); |
954 |
Object[] newRow = new Object[the_tm.getColumnCount()]; |
955 |
|
956 |
/*
|
957 |
tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD);
|
958 |
tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE);
|
959 |
tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH);
|
960 |
tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE);
|
961 |
tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE);
|
962 |
tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS);
|
963 |
tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY);
|
964 |
tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY);
|
965 |
*/
|
966 |
|
967 |
// =============================== name
|
968 |
if (fad == null) { |
969 |
newRow[COLUMN_FIELD] = new_fld_name; |
970 |
} else {
|
971 |
newRow[COLUMN_FIELD] = fad.getName(); |
972 |
} |
973 |
// ===================================== field type
|
974 |
TableColumn typeColumn = the_table.getColumnModel().getColumn(COLUMN_TYPE);
|
975 |
List supp_types = spFactory.getSupportedDataTypes();
|
976 |
|
977 |
DataManager daman = DALLocator.getDataManager(); |
978 |
List all_types = daman.getDataTypes();
|
979 |
|
980 |
|
981 |
ComboModelDataType model = null;
|
982 |
if (fad == null) { |
983 |
|
984 |
// this is a user defined column, remove geometry if in default feattype
|
985 |
if (defaultHasGeometry) {
|
986 |
supp_types = removeGeometryType(supp_types); |
987 |
all_types = removeGeometryType(all_types); |
988 |
} |
989 |
|
990 |
if (supp_types != null && supp_types.size() > 0) { |
991 |
model = new ComboModelDataType(
|
992 |
supp_types, |
993 |
((DataType) supp_types.get(0)).getType());
|
994 |
} else {
|
995 |
model = new ComboModelDataType(
|
996 |
all_types, |
997 |
((DataType) all_types.get(0)).getType());
|
998 |
} |
999 |
} else {
|
1000 |
model = new ComboModelDataType(supp_types, fad.getType());
|
1001 |
} |
1002 |
|
1003 |
JComboBox comboBox = new JComboBox(model); |
1004 |
typeColumn.setCellEditor(new DefaultCellEditor(comboBox)); |
1005 |
newRow[COLUMN_TYPE] = model.getSelectedItem(); |
1006 |
|
1007 |
// ============================= width
|
1008 |
TableColumn widthColumn =
|
1009 |
the_table.getColumnModel().getColumn(COLUMN_LENGTH); |
1010 |
if (fad == null) { |
1011 |
newRow[COLUMN_LENGTH] = "20";
|
1012 |
} else {
|
1013 |
newRow[COLUMN_LENGTH] = "" + fad.getSize();
|
1014 |
} |
1015 |
|
1016 |
SimpleTextCellRenderer stcr = new SimpleTextCellRenderer();
|
1017 |
widthColumn.setCellEditor(new DefaultCellEditor(new JTextField())); |
1018 |
widthColumn.setCellRenderer(stcr); |
1019 |
|
1020 |
|
1021 |
// ============================= geom type
|
1022 |
TableColumn geomTypeColumn =
|
1023 |
the_table.getColumnModel().getColumn(COLUMN_GEOMETRYTYPE); |
1024 |
ComboModelGeomType geomTypeModel = null;
|
1025 |
|
1026 |
List<ComboItemGeomType> supptd =
|
1027 |
leaveSupportedGeomTypes(getGeomTypes(), |
1028 |
spFactory.getSupportedGeometryTypesSubtypes(), 0);
|
1029 |
|
1030 |
if (fad == null) { |
1031 |
geomTypeModel = new ComboModelGeomType(
|
1032 |
supptd, supptd.size() > 0 ? supptd.get(0).getGeomType() : -1); |
1033 |
} else {
|
1034 |
geomTypeModel = new ComboModelGeomType(
|
1035 |
supptd, fad.getGeomType().getType()); |
1036 |
} |
1037 |
|
1038 |
JComboBox geomTypeComboBox = new JComboBox(geomTypeModel); |
1039 |
geomTypeColumn.setCellEditor(new DefaultCellEditor(geomTypeComboBox)); |
1040 |
|
1041 |
GeometryComboCellRenderer gccr = new GeometryComboCellRenderer();
|
1042 |
geomTypeColumn.setCellRenderer(gccr); |
1043 |
newRow[COLUMN_GEOMETRYTYPE] = geomTypeModel.getSelectedItem(); |
1044 |
|
1045 |
// ============================= geom sub type
|
1046 |
|
1047 |
TableColumn geomSubTypeColumn =
|
1048 |
the_table.getColumnModel().getColumn(COLUMN_GEOMETRYSUBTYPE); |
1049 |
ComboModelGeomType geomSubTypeModel = null;
|
1050 |
|
1051 |
supptd = |
1052 |
leaveSupportedGeomTypes(getGeomSubtypes(), |
1053 |
spFactory.getSupportedGeometryTypesSubtypes(), 1);
|
1054 |
|
1055 |
if (fad == null) { |
1056 |
geomSubTypeModel = new ComboModelGeomType(
|
1057 |
supptd, supptd.size() > 0 ? supptd.get(0).getGeomType() : -1); |
1058 |
} else {
|
1059 |
geomSubTypeModel = new ComboModelGeomType(
|
1060 |
supptd, fad.getGeomType().getSubType()); |
1061 |
} |
1062 |
|
1063 |
JComboBox geomSubTypeComboBox = new JComboBox(geomSubTypeModel); |
1064 |
geomSubTypeColumn.setCellEditor(new DefaultCellEditor( |
1065 |
geomSubTypeComboBox)); |
1066 |
geomSubTypeColumn.setCellRenderer(new GeometryComboCellRenderer());
|
1067 |
newRow[COLUMN_GEOMETRYSUBTYPE] = geomSubTypeModel.getSelectedItem(); |
1068 |
|
1069 |
// ============================= CRS
|
1070 |
|
1071 |
TableColumn crsColumn = the_table.getColumnModel().getColumn(COLUMN_CRS);
|
1072 |
crsColumn.setCellEditor(new ButtonEditor(new JCheckBox())); |
1073 |
CrsRenderer crsButtonRenderer = new CrsRenderer();
|
1074 |
crsColumn.setCellRenderer(crsButtonRenderer); |
1075 |
newRow[COLUMN_CRS] = the_projection; |
1076 |
|
1077 |
// ============================= PK
|
1078 |
|
1079 |
TableColumn primaryKeyColumn =
|
1080 |
the_table.getColumnModel().getColumn(COLUMN_PRIMARYKEY); |
1081 |
JCheckBox primaryKeyCheckBox = new JCheckBox(); |
1082 |
|
1083 |
if (fad == null) { |
1084 |
primaryKeyCheckBox.setSelected(false);
|
1085 |
} else {
|
1086 |
primaryKeyCheckBox.setSelected(fad.isPrimaryKey()); |
1087 |
} |
1088 |
|
1089 |
primaryKeyColumn.setCellEditor( |
1090 |
new DefaultCellEditor(primaryKeyCheckBox)); |
1091 |
CheckBoxRenderer primaryKeyCheckBoxRenderer = new CheckBoxRenderer();
|
1092 |
primaryKeyColumn.setCellRenderer(primaryKeyCheckBoxRenderer); |
1093 |
newRow[COLUMN_PRIMARYKEY] = primaryKeyCheckBox.isSelected(); |
1094 |
|
1095 |
// ================================== mandatory
|
1096 |
|
1097 |
TableColumn mandatoryColumn =
|
1098 |
the_table.getColumnModel().getColumn(COLUMN_MANDATORY); |
1099 |
JCheckBox mandatoryCheckBox = new JCheckBox(); |
1100 |
|
1101 |
if (fad == null) { |
1102 |
mandatoryCheckBox.setSelected(false);
|
1103 |
} else {
|
1104 |
mandatoryCheckBox.setSelected(fad.isMandatory()); |
1105 |
} |
1106 |
|
1107 |
mandatoryColumn.setCellEditor(new DefaultCellEditor(mandatoryCheckBox)); |
1108 |
CheckBoxRenderer mandatoryCheckBoxRenderer = new CheckBoxRenderer();
|
1109 |
mandatoryColumn.setCellRenderer(mandatoryCheckBoxRenderer); |
1110 |
newRow[COLUMN_MANDATORY] = mandatoryCheckBox.isSelected(); |
1111 |
|
1112 |
// ==================================
|
1113 |
|
1114 |
// Add a new row
|
1115 |
the_tm.addRow(newRow); |
1116 |
return true; |
1117 |
} |
1118 |
|
1119 |
/**
|
1120 |
* @param supp_types
|
1121 |
* @return
|
1122 |
*/
|
1123 |
private List removeGeometryType(List dta_types) { |
1124 |
List resp = new ArrayList(); |
1125 |
|
1126 |
int len = dta_types.size();
|
1127 |
Object item_o = null; |
1128 |
DataType item_dt = null;
|
1129 |
|
1130 |
for (int i=0; i<len; i++) { |
1131 |
item_o = dta_types.get(i); |
1132 |
if (item_o instanceof DataType) { |
1133 |
item_dt = (DataType) item_o; |
1134 |
if (item_dt.getType() != DataTypes.GEOMETRY) {
|
1135 |
resp.add(item_dt); |
1136 |
} |
1137 |
} |
1138 |
} |
1139 |
return resp;
|
1140 |
} |
1141 |
|
1142 |
private List<ComboItemGeomType> leaveSupportedGeomTypes( |
1143 |
List<ComboItemGeomType> all_types,
|
1144 |
List<int[]> supported, |
1145 |
int index /* 0 for geom types, 1 for geom subtypes */) { |
1146 |
|
1147 |
if (supported == null) { |
1148 |
// all supported
|
1149 |
return all_types;
|
1150 |
} |
1151 |
|
1152 |
List<ComboItemGeomType> resp = new ArrayList<ComboItemGeomType>(); |
1153 |
int len = all_types.size();
|
1154 |
ComboItemGeomType item = null;
|
1155 |
for (int i=0; i<len; i++) { |
1156 |
item = all_types.get(i); |
1157 |
if (isInNthElement(item.getGeomType(), supported, index)) {
|
1158 |
resp.add(item); |
1159 |
} |
1160 |
} |
1161 |
return resp;
|
1162 |
} |
1163 |
|
1164 |
|
1165 |
private boolean isInNthElement(int val, List<int[]> arr_list, int index) { |
1166 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
1167 |
int len = arr_list.size();
|
1168 |
int[] item = null; |
1169 |
for (int i=0; i<len; i++) { |
1170 |
item = arr_list.get(i); |
1171 |
if (item != null && item.length > index ) { |
1172 |
if( geomManager.isSubtype(item[index], val) ) {
|
1173 |
return true; |
1174 |
} |
1175 |
} |
1176 |
} |
1177 |
return false; |
1178 |
} |
1179 |
|
1180 |
private boolean dataTypeNeedsSize(int data_type) { |
1181 |
|
1182 |
if (data_type == DataTypes.FLOAT
|
1183 |
|| data_type == DataTypes.INT |
1184 |
|| data_type == DataTypes.STRING) { |
1185 |
return true; |
1186 |
} else {
|
1187 |
return false; |
1188 |
} |
1189 |
} |
1190 |
|
1191 |
private class SimpleTextCellRenderer extends DefaultTableCellRenderer { |
1192 |
|
1193 |
public SimpleTextCellRenderer() {
|
1194 |
super();
|
1195 |
} |
1196 |
/* (non-Javadoc)
|
1197 |
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
|
1198 |
*/
|
1199 |
public Component getTableCellRendererComponent( |
1200 |
JTable table,
|
1201 |
Object value, boolean isSelected, boolean hasFocus, int row, |
1202 |
int column) {
|
1203 |
|
1204 |
TableModel tm = table.getModel();
|
1205 |
Object new_val = ""; |
1206 |
Object type_obj = tm.getValueAt(row, COLUMN_TYPE);
|
1207 |
if (type_obj instanceof ComboItemDataType) { |
1208 |
ComboItemDataType type_item = (ComboItemDataType) type_obj; |
1209 |
if (dataTypeNeedsSize(type_item.dataType.getType())) {
|
1210 |
new_val = getCurrentOr(value, "");
|
1211 |
} else {
|
1212 |
new_val = Messages.getText("not_applicable");
|
1213 |
} |
1214 |
return super.getTableCellRendererComponent( |
1215 |
table, new_val, isSelected, hasFocus, row, column); |
1216 |
} else {
|
1217 |
return super.getTableCellRendererComponent( |
1218 |
table, value, isSelected, hasFocus, row, column); |
1219 |
} |
1220 |
} |
1221 |
|
1222 |
private Object getCurrentOr(Object v, String d) { |
1223 |
|
1224 |
if (v instanceof String) { |
1225 |
String parse_str = (String) v; |
1226 |
try {
|
1227 |
Integer.parseInt(parse_str);
|
1228 |
return v;
|
1229 |
} catch (Exception ex) { |
1230 |
// not a valid integer
|
1231 |
return d;
|
1232 |
} |
1233 |
} else {
|
1234 |
return v;
|
1235 |
} |
1236 |
} |
1237 |
|
1238 |
} |
1239 |
|
1240 |
private class EnableLengthItemListener implements ItemListener { |
1241 |
|
1242 |
private TableModel theTableModel = null; |
1243 |
private JTable theTable = null; |
1244 |
|
1245 |
public EnableLengthItemListener(JTable t, boolean b) { |
1246 |
theTable = t; |
1247 |
theTableModel = t.getModel(); |
1248 |
} |
1249 |
|
1250 |
public void itemStateChanged(final ItemEvent e) { |
1251 |
doUpdate(e); |
1252 |
} |
1253 |
|
1254 |
public void doUpdate(ItemEvent e) { |
1255 |
|
1256 |
Object src_obj = e.getSource();
|
1257 |
if (src_obj instanceof JComboBox) { |
1258 |
|
1259 |
// one of the field type combos has changed
|
1260 |
int len = theTableModel.getRowCount();
|
1261 |
Object type_obj = null; |
1262 |
ComboItemDataType type_item = null;
|
1263 |
for (int i=0; i<len; i++) { |
1264 |
type_obj = theTableModel.getValueAt(i, COLUMN_TYPE); |
1265 |
if (type_obj instanceof ComboItemDataType) { |
1266 |
type_item = (ComboItemDataType) type_obj; |
1267 |
if (dataTypeNeedsSize(type_item.dataType.getType())) {
|
1268 |
theTableModel.setValueAt( |
1269 |
"20",
|
1270 |
i, COLUMN_LENGTH); |
1271 |
} else {
|
1272 |
theTableModel.setValueAt( |
1273 |
Messages.getText("not_applicable"),
|
1274 |
i, COLUMN_LENGTH); |
1275 |
} |
1276 |
} |
1277 |
} |
1278 |
theTable.validate(); // .revalidate(); // .repaint();
|
1279 |
} |
1280 |
} |
1281 |
|
1282 |
} |
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 |
} |