svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / TableNumericFieldOperations.java @ 25777
History | View | Annotate | Download (8.54 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.math.BigDecimal; |
4 |
import java.util.BitSet; |
5 |
import java.util.Iterator; |
6 |
|
7 |
import org.gvsig.fmap.dal.DataTypes; |
8 |
import org.gvsig.fmap.dal.exception.ReadException; |
9 |
import org.gvsig.fmap.dal.feature.Feature; |
10 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
12 |
import org.gvsig.fmap.mapcontext.rendering.legend.NullValue; |
13 |
import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel; |
14 |
import org.opengis.feature.FeatureCollection; |
15 |
|
16 |
import com.iver.andami.PluginServices; |
17 |
import com.iver.andami.plugins.Extension; |
18 |
import com.iver.andami.ui.mdiManager.IWindow; |
19 |
import com.iver.cit.gvsig.project.documents.table.gui.Statistics; |
20 |
|
21 |
/**
|
22 |
* @author Fernando Gonz?lez Cort?s
|
23 |
*/
|
24 |
public class TableNumericFieldOperations extends Extension{ |
25 |
|
26 |
/**
|
27 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
28 |
*/
|
29 |
public void initialize() { |
30 |
registerIcons(); |
31 |
} |
32 |
|
33 |
private void registerIcons(){ |
34 |
PluginServices.getIconTheme().registerDefault( |
35 |
"table-statistics",
|
36 |
this.getClass().getClassLoader().getResource("images/statistics.png") |
37 |
); |
38 |
} |
39 |
|
40 |
/**
|
41 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
42 |
*/
|
43 |
public void execute(String actionCommand) { |
44 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
45 |
|
46 |
if (v != null) { |
47 |
if (v.getClass() == FeatureTableDocumentPanel.class) {
|
48 |
|
49 |
FeatureTableDocumentPanel table = (FeatureTableDocumentPanel) v; |
50 |
|
51 |
doExecute(table); |
52 |
} |
53 |
} |
54 |
} |
55 |
/**
|
56 |
* "execute" method acction
|
57 |
* @param actionCommand
|
58 |
* The acction command that executes this method
|
59 |
* @param table
|
60 |
* Table to operate
|
61 |
*/
|
62 |
|
63 |
protected void doExecute(FeatureTableDocumentPanel table){ |
64 |
// FIXME
|
65 |
// int fieldIndex = table.getSelectedFieldIndices().nextSetBit(0);
|
66 |
// int numRows=0;
|
67 |
// FeatureStore fs=null;
|
68 |
//// try {
|
69 |
// fs = table.getModel().getStore();
|
70 |
//// } catch (ReadException e) {
|
71 |
//// e.printStackTrace();
|
72 |
//// }
|
73 |
//
|
74 |
// FeatureCollection fCollection = (FeatureCollection)fs.getSelection();
|
75 |
// FeatureCollection fCollec=null;
|
76 |
// BigDecimal suma = new BigDecimal(0);
|
77 |
// BigDecimal min = new BigDecimal(Double.MAX_VALUE);
|
78 |
// BigDecimal max = new BigDecimal(-Double.MAX_VALUE);
|
79 |
// Iterator iterator=null;
|
80 |
// if (!fCollection.isEmpty()){
|
81 |
// iterator=fCollection.iterator();
|
82 |
// while (iterator.hasNext()) {
|
83 |
// Feature feature = (Feature) iterator.next();
|
84 |
// if (feature.get(fieldIndex) == null) {
|
85 |
// continue;
|
86 |
// }
|
87 |
// Number number=(Number)feature.get(fieldIndex);
|
88 |
// double d=number.doubleValue();
|
89 |
// numRows++;
|
90 |
// suma = suma.add(new BigDecimal(d));
|
91 |
// if (d < min.doubleValue()) {
|
92 |
// min = new BigDecimal(d);
|
93 |
// }
|
94 |
// if (d > max.doubleValue()) {
|
95 |
// max = new BigDecimal(d);
|
96 |
// }
|
97 |
// }
|
98 |
// }else{
|
99 |
//
|
100 |
// try {
|
101 |
// fCollec = (FeatureCollection)fs.getDataSet(new String[]{((FeatureAttributeDescriptor)fs.getDefaultFeatureType().get(fieldIndex)).getName()});
|
102 |
// } catch (ReadException e) {
|
103 |
// // TODO Auto-generated catch block
|
104 |
// e.printStackTrace();
|
105 |
// }
|
106 |
//
|
107 |
// iterator=fCollec.iterator();
|
108 |
// while (iterator.hasNext()) {
|
109 |
// Feature feature = (Feature) iterator.next();
|
110 |
// if (feature.get(fieldIndex) instanceof NullValue){
|
111 |
// continue;
|
112 |
// }
|
113 |
// Number number=(Number)feature.get(fieldIndex);
|
114 |
// double d=number.doubleValue();
|
115 |
// numRows++;
|
116 |
// suma = suma.add(new BigDecimal(d));
|
117 |
// if (d < min.doubleValue()) {
|
118 |
// min = new BigDecimal(d);
|
119 |
// }
|
120 |
// if (d > max.doubleValue()) {
|
121 |
// max = new BigDecimal(d);
|
122 |
// }
|
123 |
// }
|
124 |
// }
|
125 |
// Statistics st = new Statistics();
|
126 |
// BigDecimal media = new BigDecimal(0);
|
127 |
// BigDecimal varianza = new BigDecimal(0);
|
128 |
// double desviacion = 0;
|
129 |
// if (numRows==0) {
|
130 |
// suma = new BigDecimal(0);
|
131 |
// min = new BigDecimal(0);
|
132 |
// max = new BigDecimal(0);
|
133 |
// }else {
|
134 |
// media = suma.divide(new BigDecimal(numRows), BigDecimal.ROUND_HALF_DOWN);
|
135 |
// varianza = new BigDecimal(0);
|
136 |
// if (!fCollection.isEmpty()){
|
137 |
// iterator=fCollection.iterator();
|
138 |
// }else{
|
139 |
// iterator=fCollec.iterator();
|
140 |
// }
|
141 |
// while (iterator.hasNext()) {
|
142 |
// Feature feature = (Feature) iterator.next();
|
143 |
// if (feature.get(fieldIndex) instanceof NullValue){
|
144 |
// continue;
|
145 |
// }
|
146 |
// Number number=(Number)feature.get(fieldIndex);
|
147 |
// double d=number.doubleValue();
|
148 |
//
|
149 |
// BigDecimal dif = new BigDecimal(d).subtract(media);
|
150 |
// varianza = dif.multiply(dif).add(varianza);
|
151 |
// }
|
152 |
// varianza = varianza.divide(new BigDecimal(numRows), BigDecimal.ROUND_HALF_DOWN);
|
153 |
// desviacion = Math.sqrt(varianza.doubleValue());
|
154 |
// }
|
155 |
// st.setStatistics(media.doubleValue(), max.doubleValue(), min.doubleValue(), varianza.doubleValue(), desviacion, numRows, new BigDecimal(max.doubleValue()).subtract(min).doubleValue(), suma.doubleValue());
|
156 |
// PluginServices.getMDIManager().addWindow(st);
|
157 |
//// }else{
|
158 |
////
|
159 |
//// }
|
160 |
//
|
161 |
//// BitSet selectedRows = (BitSet)ds.getSelection().clone();
|
162 |
//// try {
|
163 |
//// int rc = (int) ds.getRowCount();
|
164 |
//// //Si no hay selecci?n se usan todos los registros
|
165 |
//// if (selectedRows.cardinality() == 0){
|
166 |
//// selectedRows.set(0, rc);
|
167 |
//// }else{
|
168 |
//// rc = selectedRows.cardinality();
|
169 |
//// }
|
170 |
//// BigDecimal suma = new BigDecimal(0);
|
171 |
//// BigDecimal min = new BigDecimal(Double.MAX_VALUE);
|
172 |
//// BigDecimal max = new BigDecimal(-Double.MAX_VALUE);
|
173 |
//// for(int i=selectedRows.nextSetBit(0); i>=0; i=selectedRows.nextSetBit(i+1)) {
|
174 |
//// if (fs.getFieldValue(i, fieldIndex) instanceof NullValue)
|
175 |
//// continue;
|
176 |
//// numRows++;
|
177 |
//// double d = ((NumericValue) ds.getFieldValue(i, fieldIndex)).doubleValue();
|
178 |
//// suma = suma.add(new BigDecimal(d));
|
179 |
//// if (d < min.doubleValue()) min = new BigDecimal(d);
|
180 |
//// if (d > max.doubleValue()) max = new BigDecimal(d);
|
181 |
//// }
|
182 |
//// Statistics st = new Statistics();
|
183 |
//// BigDecimal media = new BigDecimal(0);
|
184 |
//// BigDecimal varianza = new BigDecimal(0);
|
185 |
//// double desviacion = 0;
|
186 |
//// if (numRows==0) {
|
187 |
//// suma = new BigDecimal(0);
|
188 |
//// min = new BigDecimal(0);
|
189 |
//// max = new BigDecimal(0);
|
190 |
//// }else {
|
191 |
//// media = suma.divide(new BigDecimal(numRows), BigDecimal.ROUND_HALF_DOWN);
|
192 |
//// varianza = new BigDecimal(0);
|
193 |
//// for(int i=selectedRows.nextSetBit(0); i>=0; i=selectedRows.nextSetBit(i+1)) {
|
194 |
//// if (ds.getFieldValue(i, fieldIndex) instanceof NullValue)
|
195 |
//// continue;
|
196 |
//// double d = ((NumericValue) ds.getFieldValue(i, fieldIndex)).doubleValue();
|
197 |
//// BigDecimal dif = new BigDecimal(d).subtract(media);
|
198 |
//// varianza = dif.multiply(dif).add(varianza);
|
199 |
//// }
|
200 |
//// varianza = varianza.divide(new BigDecimal(numRows), BigDecimal.ROUND_HALF_DOWN);
|
201 |
//// desviacion = Math.sqrt(varianza.doubleValue());
|
202 |
//// }
|
203 |
////
|
204 |
//// st.setStatistics(media.doubleValue(), max.doubleValue(), min.doubleValue(), varianza.doubleValue(), desviacion, numRows, new BigDecimal(max.doubleValue()).subtract(min).doubleValue(), suma.doubleValue());
|
205 |
//// PluginServices.getMDIManager().addWindow(st);
|
206 |
////
|
207 |
//// } catch (ReadDriverException e) {
|
208 |
//// NotificationManager.addError("No se pudo acceder a los datos", e);
|
209 |
//// }
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
214 |
*/
|
215 |
public boolean isEnabled() { |
216 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
217 |
|
218 |
if (v == null) { |
219 |
return false; |
220 |
} |
221 |
|
222 |
if (v instanceof FeatureTableDocumentPanel) { |
223 |
FeatureTableDocumentPanel table = (FeatureTableDocumentPanel) v; |
224 |
return doIsEnabled(table);
|
225 |
} |
226 |
return false; |
227 |
} |
228 |
|
229 |
protected boolean doIsEnabled(FeatureTableDocumentPanel table){ |
230 |
// FIXME
|
231 |
// BitSet indices = table.getSelectedFieldIndices();
|
232 |
// // System.out.println("TableNumericFieldOperations.isEnabled: Tabla: " + table.getModel().getModelo().getRecordset().getName() );
|
233 |
// if (indices.cardinality() == 1){
|
234 |
//// try {
|
235 |
// int index=indices.nextSetBit(0);
|
236 |
// if (table.getModel().getStore().getDefaultFeatureType().size()<index+1) {
|
237 |
// return false;
|
238 |
// }
|
239 |
// int type = ((FeatureAttributeDescriptor)table.getModel().getStore().getDefaultFeatureType().get(index)).getDataType();
|
240 |
// if ((type==DataTypes.LONG) ||
|
241 |
// (type== DataTypes.DOUBLE) ||
|
242 |
// (type==DataTypes.FLOAT) ||
|
243 |
// (type==DataTypes.INT)){
|
244 |
// return true;
|
245 |
// }
|
246 |
//// } catch (ReadException e) {
|
247 |
//// return false;
|
248 |
//// }
|
249 |
// }
|
250 |
return false; |
251 |
} |
252 |
|
253 |
|
254 |
/**
|
255 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
256 |
*/
|
257 |
public boolean isVisible() { |
258 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
259 |
|
260 |
if (v == null) { |
261 |
return false; |
262 |
} |
263 |
|
264 |
if (v instanceof FeatureTableDocumentPanel) { |
265 |
return true; |
266 |
} |
267 |
return false; |
268 |
} |
269 |
|
270 |
} |