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