Revision 44189 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/symboltables/ProjectSymbolTable.java
ProjectSymbolTable.java | ||
---|---|---|
1 | 1 |
package org.gvsig.app.project.symboltables; |
2 | 2 |
|
3 |
import com.sun.corba.se.impl.protocol.FullServantCacheLocalCRDImpl; |
|
4 | 3 |
import java.io.File; |
5 | 4 |
import java.io.FileInputStream; |
6 | 5 |
import java.util.HashMap; |
... | ... | |
20 | 19 |
import org.gvsig.expressionevaluator.Expression; |
21 | 20 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
22 | 21 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
22 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
|
23 | 23 |
import org.gvsig.expressionevaluator.Interpreter; |
24 | 24 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
25 | 25 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
26 | 26 |
import org.gvsig.fmap.crs.CRSFactory; |
27 | 27 |
import org.gvsig.fmap.dal.DALLocator; |
28 | 28 |
import org.gvsig.fmap.dal.DataManager; |
29 |
import org.gvsig.fmap.dal.HasDataStore; |
|
29 | 30 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
30 | 31 |
import org.gvsig.fmap.dal.feature.Feature; |
31 | 32 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
32 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
33 | 33 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
34 | 34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
35 | 35 |
import org.gvsig.fmap.geom.Geometry; |
36 | 36 |
import org.gvsig.fmap.geom.primitive.Point; |
37 | 37 |
import org.gvsig.fmap.mapcontext.MapContext; |
38 | 38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
39 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
|
40 | 39 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
41 | 40 |
import org.gvsig.fmap.mapcontrol.AreaAndPerimeterCalculator; |
42 | 41 |
import org.gvsig.temporarystorage.TemporaryStorageGroup; |
... | ... | |
58 | 57 |
|
59 | 58 |
static final String NAME = "Project"; |
60 | 59 |
|
60 |
private static final String TABLE_DOCUMENT_TYPENAME = "project.document.table"; |
|
61 |
|
|
61 | 62 |
private abstract class CachedValue<T> { |
62 | 63 |
|
63 | 64 |
T value = null; |
... | ... | |
143 | 144 |
|
144 | 145 |
} |
145 | 146 |
|
146 |
private class FirstSelectedFeatureFunction extends AbstractFunction { |
|
147 |
|
|
148 |
public FirstSelectedFeatureFunction() { |
|
149 |
super( |
|
150 |
"Project", |
|
151 |
"firstSelectedFeature", |
|
152 |
Range.between(3, 4), |
|
153 |
"Access to the first selected feature of the layer, and " |
|
154 |
+ "return the value of the attribute.", |
|
155 |
"firstSelectedFeature({{view}}, layer, attribute, defaulValue)", |
|
156 |
new String[]{ |
|
157 |
"view - String value with the name of a view", |
|
158 |
"layer - String value with the name of a layer in the indicated view", |
|
159 |
"attribute - String value with the name of the attribute in the indicated layer", |
|
160 |
"defaultValue - Optional. Value to use if the indicated " |
|
161 |
+ "attribute can not be accessed. For example, if the " |
|
162 |
+ "view or layer does not exist, or it does not have " |
|
163 |
+ "selected elements." |
|
164 |
}, |
|
165 |
"Object" |
|
166 |
); |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
171 |
Object defaultValue = null; |
|
172 |
String viewName = getStr(args, 0); |
|
173 |
String layerName = getStr(args, 1); |
|
174 |
String attrName = getStr(args, 2); |
|
175 |
if (args.length == 4) { |
|
176 |
defaultValue = getObject(args, 3); |
|
177 |
} |
|
178 |
try { |
|
179 |
Project project = currentProject.get(); |
|
180 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
181 |
if (view == null) { |
|
182 |
return defaultValue; |
|
183 |
} |
|
184 |
FLayer layer = view.getLayer(layerName); |
|
185 |
if (!(layer instanceof FLyrVect)) { |
|
186 |
return defaultValue; |
|
187 |
} |
|
188 |
FeatureSelection selection = ((FLyrVect) layer).getFeatureStore().getFeatureSelection(); |
|
189 |
if (selection == null || selection.isEmpty()) { |
|
190 |
return defaultValue; |
|
191 |
} |
|
192 |
Feature feature = selection.first(); |
|
193 |
if (feature == null) { |
|
194 |
return defaultValue; |
|
195 |
} |
|
196 |
return feature.get(attrName); |
|
197 |
} catch (Exception ex) { |
|
198 |
return defaultValue; |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
202 |
} |
|
203 |
|
|
204 | 147 |
private class StoreFunction extends AbstractFunction { |
205 |
|
|
148 |
|
|
206 | 149 |
public StoreFunction() { |
207 | 150 |
super( |
208 | 151 |
"Project", |
... | ... | |
228 | 171 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
229 | 172 |
Project project = currentProject.get(); |
230 | 173 |
switch (args.length) { |
231 |
// case 1: |
|
232 |
// String tableName = getStr(args, 0); |
|
233 |
// TableDocument table = (TableDocument) project.getDocument(tableName, TableManager.TYPENAME); |
|
234 |
// if (table == null) { |
|
235 |
// return null; |
|
236 |
// } |
|
237 |
// return table.getFeatureStore(); |
|
238 |
// break; |
|
174 |
case 1: |
|
175 |
String tableName = getStr(args, 0); |
|
176 |
Document document = project.getDocument(tableName, TABLE_DOCUMENT_TYPENAME); |
|
177 |
if (document == null) { |
|
178 |
return null; |
|
179 |
} |
|
180 |
if( document instanceof HasDataStore ) { |
|
181 |
return ((HasDataStore) document).getDataStore(); |
|
182 |
} |
|
183 |
return null; |
|
184 |
|
|
239 | 185 |
case 2: |
240 | 186 |
String viewName = getStr(args, 0); |
241 | 187 |
String layerName = getStr(args, 1); |
... | ... | |
244 | 190 |
return null; |
245 | 191 |
} |
246 | 192 |
FLayer layer = view.getLayer(layerName); |
247 |
if( !(layer instanceof SingleLayer ) ) {
|
|
248 |
return null;
|
|
193 |
if( layer instanceof HasDataStore ) {
|
|
194 |
return ((HasDataStore)layer).getDataStore();
|
|
249 | 195 |
} |
250 |
return ((SingleLayer)layer).getDataStore();
|
|
196 |
return null;
|
|
251 | 197 |
} |
252 | 198 |
return null; |
253 | 199 |
} |
... | ... | |
276 | 222 |
|
277 | 223 |
@Override |
278 | 224 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
279 |
Object value = null;
|
|
225 |
Object value; |
|
280 | 226 |
String where = null; |
281 | 227 |
String order = null; |
282 | 228 |
String expression_s = getStr(args, 0); |
283 | 229 |
FeatureStore store = (FeatureStore) getObject(args, 1); |
284 | 230 |
switch (args.length) { |
285 |
case 2:
|
|
231 |
case 3:
|
|
286 | 232 |
where = getStr(args, 2); |
287 | 233 |
break; |
288 | 234 |
case 4: |
... | ... | |
320 | 266 |
|
321 | 267 |
return value; |
322 | 268 |
} catch (Exception ex) { |
323 |
return null;
|
|
269 |
throw new ExpressionRuntimeException("Problems calling '"+FETCH_FIRST_NAME+"' function", ex);
|
|
324 | 270 |
} |
325 | 271 |
} |
326 | 272 |
} |
... | ... | |
362 | 308 |
|
363 | 309 |
return value; |
364 | 310 |
} catch (Exception ex) { |
365 |
return null;
|
|
311 |
throw new ExpressionRuntimeException("Problems calling '"+FETCH_FIRST_SELECTED_NAME+"' function", ex);
|
|
366 | 312 |
} |
367 | 313 |
} |
368 | 314 |
} |
... | ... | |
590 | 536 |
public ProjectSymbolTable() { |
591 | 537 |
super(NAME); |
592 | 538 |
this.addFunction(new CurrentProjectFunction()); |
593 |
this.addFunction(new FirstSelectedFeatureFunction()); |
|
594 | 539 |
this.addFunction(new StoreFunction()); |
595 | 540 |
this.addFunction(new FetchFirstFunction()); |
596 | 541 |
this.addFunction(new FetchFirstSelectedFunction()); |
Also available in: Unified diff