Revision 23697
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/fmap/data/feature/swing/FeatureCollectionTable.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 {DiSiD Technologies} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.data.feature.swing; |
|
28 |
|
|
29 |
import java.util.Vector; |
|
30 |
|
|
31 |
import javax.swing.JTable; |
|
32 |
import javax.swing.ListSelectionModel; |
|
33 |
import javax.swing.table.TableColumnModel; |
|
34 |
import javax.swing.table.TableModel; |
|
35 |
|
|
36 |
import org.gvsig.fmap.data.feature.Feature; |
|
37 |
import org.gvsig.fmap.data.feature.swing.table.FeatureCellRenderer; |
|
38 |
import org.gvsig.fmap.data.feature.swing.table.GeometryCellRenderer; |
|
39 |
import org.gvsig.fmap.geom.Geometry; |
|
40 |
|
|
41 |
/** |
|
42 |
* Table to show FeatureCollection data. |
|
43 |
* |
|
44 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
45 |
*/ |
|
46 |
public class FeatureCollectionTable extends JTable { |
|
47 |
|
|
48 |
/** |
|
49 |
* Generated Serial UID |
|
50 |
*/ |
|
51 |
private static final long serialVersionUID = -6139395189283163964L; |
|
52 |
|
|
53 |
/** |
|
54 |
* @see JTable#JTable() |
|
55 |
*/ |
|
56 |
public FeatureCollectionTable() { |
|
57 |
super(); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* @see JTable#JTable(int, int) |
|
62 |
*/ |
|
63 |
public FeatureCollectionTable(int numRows, int numColumns) { |
|
64 |
super(numRows, numColumns); |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* @see JTable#JTable(Object[][], Object[]) |
|
69 |
*/ |
|
70 |
public FeatureCollectionTable(Object[][] rowData, Object[] columnNames) { |
|
71 |
super(rowData, columnNames); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* @see JTable#JTable(TableModel, TableColumnModel, ListSelectionModel) |
|
76 |
*/ |
|
77 |
public FeatureCollectionTable(TableModel dm, TableColumnModel cm, |
|
78 |
ListSelectionModel sm) { |
|
79 |
super(dm, cm, sm); |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* @see JTable#JTable(TableModel, TableColumnModel) |
|
84 |
*/ |
|
85 |
public FeatureCollectionTable(TableModel dm, TableColumnModel cm) { |
|
86 |
super(dm, cm); |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* @see JTable#JTable(TableModel) |
|
91 |
*/ |
|
92 |
public FeatureCollectionTable(TableModel dm) { |
|
93 |
super(dm); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* @see JTable#JTable(Vector, Vector) |
|
98 |
*/ |
|
99 |
@SuppressWarnings("unchecked") |
|
100 |
public FeatureCollectionTable(Vector rowData, Vector columnNames) { |
|
101 |
super(rowData, columnNames); |
|
102 |
} |
|
103 |
|
|
104 |
protected void initializeLocalVars() { |
|
105 |
super.initializeLocalVars(); |
|
106 |
setDefaultRenderer(Geometry.class, new GeometryCellRenderer()); |
|
107 |
setDefaultRenderer(Feature.class, new FeatureCellRenderer()); |
|
108 |
// setDefaultRenderer(Date.class, new DateCellRenderer()); |
|
109 |
} |
|
110 |
} |
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/fmap/data/feature/swing/table/FeatureCollectionTableModel.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 {DiSiD Technologies} {Create a JTable TableModel for a FeatureCollection} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.data.feature.swing.table; |
|
28 |
|
|
29 |
import javax.swing.table.AbstractTableModel; |
|
30 |
|
|
31 |
import org.gvsig.fmap.data.ReadException; |
|
32 |
import org.gvsig.fmap.data.feature.*; |
|
33 |
import org.gvsig.fmap.data.feature.paging.FeatureCollectionPagingHelper; |
|
34 |
import org.gvsig.fmap.data.feature.paging.FeatureCollectionPagingHelperImpl; |
|
35 |
|
|
36 |
/** |
|
37 |
* TableModel to access data of a FeatureCollection. |
|
38 |
* |
|
39 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
40 |
*/ |
|
41 |
public class FeatureCollectionTableModel extends AbstractTableModel { |
|
42 |
|
|
43 |
private static final long serialVersionUID = -2488157521902851301L; |
|
44 |
|
|
45 |
private FeatureCollectionPagingHelper helper; |
|
46 |
|
|
47 |
/** |
|
48 |
* Constructs a TableModel from a FeatureCollection, with the default page |
|
49 |
* size. |
|
50 |
* |
|
51 |
* @param featureCollection |
|
52 |
* to extract data from |
|
53 |
* @throws ReadException |
|
54 |
* if there is an error reading data from the FeatureStore |
|
55 |
*/ |
|
56 |
public FeatureCollectionTableModel(FeatureStore featureStore, |
|
57 |
FeatureQuery featureQuery) throws ReadException { |
|
58 |
this(featureStore, featureQuery, |
|
59 |
FeatureCollectionPagingHelper.DEFAULT_PAGE_SIZE); |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Constructs a TableModel from a FeatureCollection, and a given page size. |
|
64 |
* |
|
65 |
* @param featureCollection |
|
66 |
* to extract data from |
|
67 |
* @param pageSize |
|
68 |
* the number of elements per page data |
|
69 |
* @throws ReadException |
|
70 |
* if there is an error reading data from the FeatureStore |
|
71 |
*/ |
|
72 |
public FeatureCollectionTableModel(FeatureStore featureStore, |
|
73 |
FeatureQuery featureQuery, |
|
74 |
int pageSize) throws ReadException { |
|
75 |
this(new FeatureCollectionPagingHelperImpl(featureStore, |
|
76 |
featureQuery, |
|
77 |
pageSize)); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Constructs a TableModel from a FeatureCollection and a Paging helper. |
|
82 |
* |
|
83 |
* @param featureCollection |
|
84 |
* to extract data from |
|
85 |
* @param helper |
|
86 |
* the paging helper |
|
87 |
* @throws ReadException |
|
88 |
* if there is an error reading data from the FeatureStore |
|
89 |
*/ |
|
90 |
public FeatureCollectionTableModel(FeatureCollectionPagingHelper helper) { |
|
91 |
this.helper = helper; |
|
92 |
} |
|
93 |
|
|
94 |
public int getColumnCount() { |
|
95 |
// Return the number of fields of the Features |
|
96 |
FeatureType featureType = getFeatureType(); |
|
97 |
return featureType.getFields().length; |
|
98 |
} |
|
99 |
|
|
100 |
public int getRowCount() { |
|
101 |
// Return the total size of the collection |
|
102 |
return getHelper().getTotalSize(); |
|
103 |
} |
|
104 |
|
|
105 |
public Object getValueAt(int rowIndex, int columnIndex) { |
|
106 |
// Get the Feature at row "rowIndex", and return the value of the |
|
107 |
// attribute at "columnIndex" |
|
108 |
return getHelper().getFeatureAt(rowIndex).get(columnIndex); |
|
109 |
} |
|
110 |
|
|
111 |
@SuppressWarnings("unchecked") |
|
112 |
public Class getColumnClass(int columnIndex) { |
|
113 |
// Return the class of the FeatureAttributeDescriptor for the value |
|
114 |
FeatureAttributeDescriptor attributeDesc = getAttributeDescriptor(columnIndex); |
|
115 |
Class clazz = attributeDesc.getObjectClass(); |
|
116 |
return (clazz == null ? super.getColumnClass(columnIndex) : clazz); |
|
117 |
} |
|
118 |
|
|
119 |
public String getColumnName(int column) { |
|
120 |
// Return the Feature attribute name |
|
121 |
FeatureAttributeDescriptor attributeDesc = getAttributeDescriptor(column); |
|
122 |
return attributeDesc.getName(); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Returns a reference to the Paging Helper used to load the data from the |
|
127 |
* DataStore. |
|
128 |
* |
|
129 |
* @return the paging helper |
|
130 |
*/ |
|
131 |
public FeatureCollectionPagingHelper getHelper() { |
|
132 |
return helper; |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Returns the FeatureCollection used to get the data. |
|
137 |
* |
|
138 |
* @return the FeatureCollection |
|
139 |
*/ |
|
140 |
protected FeatureCollection getFeatureCollection() { |
|
141 |
return getHelper().getFeatureCollection(); |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Returns the FeatureStore of the Collection. |
|
146 |
* |
|
147 |
* @return the FeatureStore |
|
148 |
*/ |
|
149 |
protected FeatureStore getFeatureStore() { |
|
150 |
return getHelper().getFeatureStore(); |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* Returns the type of the features. |
|
155 |
*/ |
|
156 |
private FeatureType getFeatureType() { |
|
157 |
return getFeatureCollection().getFeatureType(); |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Returns the descriptor of a Feature attribute. |
|
162 |
*/ |
|
163 |
private FeatureAttributeDescriptor getAttributeDescriptor(int columnIndex) { |
|
164 |
return getFeatureType().getByOrder(columnIndex); |
|
165 |
} |
|
166 |
} |
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/fmap/data/feature/swing/table/FeatureCellRenderer.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 {DiSiD Technologies} {Create a JTable TableModel for a FeatureCollection} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.data.feature.swing.table; |
|
28 |
|
|
29 |
import javax.swing.table.DefaultTableCellRenderer; |
|
30 |
|
|
31 |
import org.gvsig.fmap.data.feature.Feature; |
|
32 |
|
|
33 |
/** |
|
34 |
* Renderer for cells of type {@link Feature} . |
|
35 |
* |
|
36 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
37 |
*/ |
|
38 |
public class FeatureCellRenderer extends DefaultTableCellRenderer { |
|
39 |
|
|
40 |
/** |
|
41 |
* Generated Serial UID. |
|
42 |
*/ |
|
43 |
private static final long serialVersionUID = 3547431185199502021L; |
|
44 |
|
|
45 |
protected void setValue(Object value) { |
|
46 |
// TODO: change the current dumb implementation with something |
|
47 |
// more useful, as a link or button to show the Feature details |
|
48 |
// or, maybe, a subRow |
|
49 |
if (value == null) { |
|
50 |
setText(""); |
|
51 |
} else { |
|
52 |
Feature feature = (Feature) value; |
|
53 |
setText(feature.toString()); |
|
54 |
} |
|
55 |
} |
|
56 |
} |
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/fmap/data/feature/swing/table/GeometryCellRenderer.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 {DiSiD Technologies} {Create a JTable TableModel for a FeatureCollection} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.data.feature.swing.table; |
|
28 |
|
|
29 |
import javax.swing.table.DefaultTableCellRenderer; |
|
30 |
|
|
31 |
import org.gvsig.fmap.geom.Geometry; |
|
32 |
|
|
33 |
/** |
|
34 |
* Renderer for cells of type {@link Geometry} . |
|
35 |
* |
|
36 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
37 |
*/ |
|
38 |
public class GeometryCellRenderer extends DefaultTableCellRenderer { |
|
39 |
|
|
40 |
/** |
|
41 |
* Generated Serial UID. |
|
42 |
*/ |
|
43 |
private static final long serialVersionUID = -2470239399517077869L; |
|
44 |
|
|
45 |
protected void setValue(Object value) { |
|
46 |
if (value == null) { |
|
47 |
setText(""); |
|
48 |
} else { |
|
49 |
Geometry geometry = (Geometry) value; |
|
50 |
setText(geometry.toString()); |
|
51 |
setToolTipText(geometry.getGeometryType().getName()); |
|
52 |
} |
|
53 |
} |
|
54 |
} |
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/fmap/data/feature/swing/table/SetFeatureValueException.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 {DiSiD Technologies} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.data.feature.swing.table; |
|
28 |
|
|
29 |
import java.util.HashMap; |
|
30 |
import java.util.Map; |
|
31 |
|
|
32 |
import org.gvsig.tools.exception.BaseRuntimeException; |
|
33 |
|
|
34 |
/** |
|
35 |
* |
|
36 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
37 |
*/ |
|
38 |
public class SetFeatureValueException extends BaseRuntimeException { |
|
39 |
|
|
40 |
private static final String KEY = "set_feature_value_exception"; |
|
41 |
|
|
42 |
private static final String MESSAGE = "Error setting the value of the cell " |
|
43 |
+ "at row = %(rowIndex) and column = %(columnIndex) " |
|
44 |
+ "with the value = %(value)"; |
|
45 |
|
|
46 |
private static final long serialVersionUID = -414675652211552543L; |
|
47 |
|
|
48 |
private int rowIndex; |
|
49 |
|
|
50 |
private int columnIndex; |
|
51 |
|
|
52 |
private Object value; |
|
53 |
|
|
54 |
/** |
|
55 |
* Creates a new Exception when setting a Feature value. |
|
56 |
* |
|
57 |
* @param rowIndex |
|
58 |
* the position of the Feature |
|
59 |
* @param columnIndex |
|
60 |
* the position of the value into the Feature |
|
61 |
* @param value |
|
62 |
* the value to set |
|
63 |
*/ |
|
64 |
public SetFeatureValueException(int rowIndex, int columnIndex, Object value) { |
|
65 |
super(MESSAGE, KEY, serialVersionUID); |
|
66 |
this.rowIndex = rowIndex; |
|
67 |
this.columnIndex = columnIndex; |
|
68 |
this.value = value; |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Creates a new Exception when setting a Feature value. |
|
73 |
* |
|
74 |
* @param rowIndex |
|
75 |
* the position of the Feature |
|
76 |
* @param columnIndex |
|
77 |
* the position of the value into the Feature |
|
78 |
* @param value |
|
79 |
* the value to set |
|
80 |
* @param cause |
|
81 |
* the original Throwable |
|
82 |
*/ |
|
83 |
public SetFeatureValueException(int rowIndex, int columnIndex, |
|
84 |
Object value, Throwable cause) { |
|
85 |
super(MESSAGE, cause, KEY, serialVersionUID); |
|
86 |
this.rowIndex = rowIndex; |
|
87 |
this.columnIndex = columnIndex; |
|
88 |
this.value = value; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* @return the rowIndex |
|
93 |
*/ |
|
94 |
public int getRowIndex() { |
|
95 |
return rowIndex; |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* @return the columnIndex |
|
100 |
*/ |
|
101 |
public int getColumnIndex() { |
|
102 |
return columnIndex; |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* @return the value |
|
107 |
*/ |
|
108 |
public Object getValue() { |
|
109 |
return value; |
|
110 |
} |
|
111 |
|
|
112 |
@SuppressWarnings("unchecked") |
|
113 |
@Override |
|
114 |
protected Map values() { |
|
115 |
Map values = new HashMap(3); |
|
116 |
values.put("rowIndex", getRowIndex()); |
|
117 |
values.put("columnIndex", getColumnIndex()); |
|
118 |
values.put("value", getValue()); |
|
119 |
return values; |
|
120 |
} |
|
121 |
|
|
122 |
} |
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/fmap/data/feature/swing/table/EditableFeatureCollectionTableModel.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 {DiSiD Technologies} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.data.feature.swing.table; |
|
28 |
|
|
29 |
import org.gvsig.fmap.data.DataException; |
|
30 |
import org.gvsig.fmap.data.ReadException; |
|
31 |
import org.gvsig.fmap.data.feature.*; |
|
32 |
import org.gvsig.fmap.data.feature.paging.FeatureCollectionPagingHelper; |
|
33 |
|
|
34 |
/** |
|
35 |
* Extends the FeatureCollectionTableModel to add edition capabilities. |
|
36 |
* |
|
37 |
* TODO: the current implementation does not work, update to the last API |
|
38 |
* changes for Feature edition. |
|
39 |
* |
|
40 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
41 |
*/ |
|
42 |
public class EditableFeatureCollectionTableModel extends |
|
43 |
FeatureCollectionTableModel { |
|
44 |
|
|
45 |
/** |
|
46 |
* Serial Version UID |
|
47 |
*/ |
|
48 |
private static final long serialVersionUID = -8486424379657039107L; |
|
49 |
|
|
50 |
private FeatureQuery featureQuery; |
|
51 |
|
|
52 |
/** |
|
53 |
* @see FeatureCollectionTableModel#FeatureCollectionTableModel(FeatureStore, |
|
54 |
* FeatureQuery, int) |
|
55 |
*/ |
|
56 |
public EditableFeatureCollectionTableModel(FeatureStore featureStore, |
|
57 |
FeatureQuery featureQuery, int pageSize) throws ReadException { |
|
58 |
super(featureStore, featureQuery, pageSize); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* @see FeatureCollectionTableModel#FeatureCollectionTableModel(FeatureStore, |
|
63 |
* FeatureQuery) |
|
64 |
*/ |
|
65 |
public EditableFeatureCollectionTableModel(FeatureStore featureStore, |
|
66 |
FeatureQuery featureQuery) throws ReadException { |
|
67 |
super(featureStore, featureQuery); |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* @see FeatureCollectionTableModel#FeatureCollectionTableModel(FeatureCollectionPagingHelper) |
|
72 |
*/ |
|
73 |
public EditableFeatureCollectionTableModel( |
|
74 |
FeatureCollectionPagingHelper helper) { |
|
75 |
super(helper); |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
|
80 |
return getFeatureStore().isEditing(); |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public void setValueAt(Object value, int rowIndex, int columnIndex) { |
|
85 |
// Get the feature at rowIndex |
|
86 |
Feature feature = getHelper().getFeatureAt(rowIndex); |
|
87 |
// Only set the value if the feature exists |
|
88 |
if (feature != null) { |
|
89 |
// We only need to update if the value to set is not equal to the |
|
90 |
// current value |
|
91 |
Object currentValue = feature.get(columnIndex); |
|
92 |
if (value != currentValue |
|
93 |
|| (value != null && !value.equals(currentValue))) { |
|
94 |
try { |
|
95 |
// getFeatureStore().startEditing(); |
|
96 |
// |
|
97 |
// EditableFeature editable = feature.getEditableFeature(); |
|
98 |
// editable.set(columnIndex, value); |
|
99 |
// |
|
100 |
// getFeatureStore().update(editable); |
|
101 |
// getFeatureStore().finishEditing(); |
|
102 |
|
|
103 |
getFeatureStore().startEditing(); |
|
104 |
feature.editing(); |
|
105 |
feature.set(columnIndex, value); |
|
106 |
getFeatureStore().update(feature); |
|
107 |
// getHelper().reload(); |
|
108 |
// TODO: REVISAR |
|
109 |
getHelper().setFeatureCollection( |
|
110 |
(FeatureCollection) getFeatureStore() |
|
111 |
.getDataCollection(featureQuery)); |
|
112 |
} catch (DataException ex) { |
|
113 |
throw new SetFeatureValueException(rowIndex, columnIndex, |
|
114 |
value, ex); |
|
115 |
} |
|
116 |
} |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
} |
Also available in: Unified diff