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