Revision 43987
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/expressionevaluator/DefaultExpressionEvaluator.java | ||
---|---|---|
95 | 95 |
); |
96 | 96 |
} |
97 | 97 |
|
98 |
private void compile() { |
|
99 |
this.code = this.compiler.compileExpression(expression.getPhrase()); |
|
100 |
} |
|
101 |
|
|
102 | 98 |
@Override |
103 | 99 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
104 | 100 |
if (this.code == null) { |
... | ... | |
121 | 117 |
public EvaluatorFieldsInfo getFieldsInfo() { |
122 | 118 |
final Set<String> names = new HashSet<>(); |
123 | 119 |
try { |
124 |
this.code.accept(new Visitor() {
|
|
120 |
this.compile().accept(new Visitor() {
|
|
125 | 121 |
@Override |
126 | 122 |
public void visit(Object code) throws VisitCanceledException, BaseException { |
127 | 123 |
if (code instanceof Code.Identifier) { |
... | ... | |
181 | 177 |
return interpreter; |
182 | 178 |
} |
183 | 179 |
|
180 |
private Compiler getCompiler() { |
|
181 |
if (this.compiler == null) { |
|
182 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
183 |
this.compiler = manager.createCompiler(); |
|
184 |
} |
|
185 |
return compiler; |
|
186 |
} |
|
187 |
|
|
188 |
private Code compile() { |
|
189 |
if (this.code == null) { |
|
190 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
191 |
this.code = this.getCompiler().compileExpression(expression.getPhrase()); |
|
192 |
} |
|
193 |
return code; |
|
194 |
} |
|
195 |
|
|
184 | 196 |
@Override |
185 | 197 |
public Evaluator clone() throws CloneNotSupportedException { |
186 | 198 |
DefaultExpressionEvaluator other = (DefaultExpressionEvaluator) super.clone(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/expressionevaluator/DefaultFeatureSymbolTable.java | ||
---|---|---|
5 | 5 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
6 | 6 |
import org.gvsig.expressionevaluator.Function; |
7 | 7 |
import org.gvsig.expressionevaluator.Interpreter; |
8 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
9 | 8 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 | 9 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
10 |
import org.gvsig.fmap.dal.DataManager; |
|
11 | 11 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
12 | 12 |
import org.gvsig.fmap.dal.feature.Feature; |
13 | 13 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
... | ... | |
61 | 61 |
|
62 | 62 |
@Override |
63 | 63 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
64 |
if( feature==null ) { |
|
65 |
return null; |
|
66 |
} |
|
64 | 67 |
return feature.getStore(); |
65 | 68 |
} |
66 | 69 |
|
... | ... | |
83 | 86 |
|
84 | 87 |
@Override |
85 | 88 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
89 |
if( feature==null ) { |
|
90 |
return false; |
|
91 |
} |
|
86 | 92 |
FeatureStore store = feature.getStore(); |
87 | 93 |
FeatureSelection selection = store.getFeatureSelection(); |
88 | 94 |
return selection.isSelected(feature); |
... | ... | |
93 | 99 |
private Feature feature; |
94 | 100 |
private FeatureType type; |
95 | 101 |
|
102 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
96 | 103 |
public DefaultFeatureSymbolTable() { |
97 |
super("DAL.FeatureSymbolTable");
|
|
104 |
super(DataManager.FEATURE_SYMBOL_TABLE);
|
|
98 | 105 |
|
99 | 106 |
this.addFunction(new FeatureFunction()); |
100 | 107 |
this.addFunction(new FeatureStoreFunction()); |
... | ... | |
114 | 121 |
} |
115 | 122 |
} |
116 | 123 |
|
117 |
public final void addFunction(Function function) { |
|
118 |
if (function == null) { |
|
119 |
throw new IllegalArgumentException("function can't be null"); |
|
120 |
} |
|
121 |
this.getFunctions().put(function.name().toUpperCase(), function); |
|
122 |
} |
|
123 |
|
|
124 | 124 |
@Override |
125 | 125 |
public FeatureSymbolTable clone() throws CloneNotSupportedException { |
126 | 126 |
DefaultFeatureSymbolTable other = (DefaultFeatureSymbolTable) super.clone(); |
... | ... | |
129 | 129 |
|
130 | 130 |
@Override |
131 | 131 |
public boolean exists(String name) { |
132 |
if (type.get(name) != null) { |
|
132 |
if (type!=null && type.get(name) != null) {
|
|
133 | 133 |
return true; |
134 | 134 |
} |
135 | 135 |
return false; |
... | ... | |
137 | 137 |
|
138 | 138 |
@Override |
139 | 139 |
public Object value(String name) { |
140 |
if( feature==null ) { |
|
141 |
return null; |
|
142 |
} |
|
140 | 143 |
return this.feature.get(name); |
141 | 144 |
} |
142 | 145 |
|
... | ... | |
148 | 151 |
|
149 | 152 |
public static void selfRegister() { |
150 | 153 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
151 |
manager.registerSymbolTable(new DefaultFeatureSymbolTable()); |
|
154 |
manager.registerSymbolTable(new DefaultFeatureSymbolTable(), false);
|
|
152 | 155 |
} |
153 | 156 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/expressionevaluator/FeatureAttributeElement.java | ||
---|---|---|
3 | 3 |
import java.util.ArrayList; |
4 | 4 |
import java.util.Iterator; |
5 | 5 |
import java.util.List; |
6 |
import org.apache.commons.lang.mutable.MutableInt; |
|
7 | 6 |
import org.gvsig.expressionevaluator.Function; |
8 | 7 |
import org.gvsig.expressionevaluator.swing.Element; |
9 | 8 |
import org.gvsig.expressionevaluator.swing.Element.GroupElement; |
... | ... | |
79 | 78 |
} |
80 | 79 |
|
81 | 80 |
@Override |
81 |
public void reload() { |
|
82 |
this.elements=null; |
|
83 |
hasMoreElements = false; |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
82 | 87 |
public List<Element> getElements() { |
83 | 88 |
if( this.elements==null ) { |
84 | 89 |
hasMoreElements = false; |
85 |
final int limit = this.configPanel==null? 1000 : this.configPanel.getSimpleElementsLimit(); |
|
86 | 90 |
ExpressionEvaluatorSwingManager manager = ExpressionEvaluatorSwingLocator.getManager(); |
87 | 91 |
final List<Object> values = new ArrayList<>(); |
92 |
final int limit = this.configPanel==null? 60 : this.configPanel.getSimpleElementsLimit(); |
|
93 |
final long timeLimit = System.currentTimeMillis() + limit*1000; |
|
88 | 94 |
try { |
89 | 95 |
FeatureSet set = this.store.getFeatureSet(); |
90 |
final MutableInt count = new MutableInt(0); |
|
91 | 96 |
set.accept(new Visitor() { |
92 | 97 |
@Override |
93 | 98 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
... | ... | |
95 | 100 |
if( !values.contains(value ) ) { |
96 | 101 |
values.add(value); |
97 | 102 |
} |
98 |
count.increment(); |
|
99 |
if( count.intValue()>= limit ) { |
|
103 |
if( System.currentTimeMillis() > timeLimit ) { |
|
100 | 104 |
hasMoreElements = true; |
101 | 105 |
throw new VisitCanceledException(); |
102 | 106 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/expressionevaluator/FeatureStoreElementFactory.java | ||
---|---|---|
9 | 9 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
10 | 10 |
import org.gvsig.expressionevaluator.swing.spi.AbstractElementFactory; |
11 | 11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
12 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
|
12 | 13 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
13 | 14 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
14 | 15 |
|
... | ... | |
19 | 20 |
public class FeatureStoreElementFactory extends AbstractElementFactory { |
20 | 21 |
|
21 | 22 |
public FeatureStoreElementFactory() { |
22 |
super("DAL.FeatureStoreElement", null);
|
|
23 |
super(DataSwingManager.FEATURE_STORE_EXPRESSION_ELEMENT, null);
|
|
23 | 24 |
} |
24 | 25 |
|
25 | 26 |
@Override |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/DataSwingManager.java | ||
---|---|---|
39 | 39 |
* |
40 | 40 |
*/ |
41 | 41 |
public interface DataSwingManager { |
42 |
public static final String FEATURE_STORE_EXPRESSION_ELEMENT = "DAL.FeatureStoreExpressionElement"; |
|
42 | 43 |
|
43 | 44 |
public JFeaturesForm createJFeaturesForm(FeatureStore store) throws CreateJFeatureFormException; |
44 | 45 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureSet.java | ||
---|---|---|
59 | 59 |
* metodos o en la doc general del featureset. |
60 | 60 |
* |
61 | 61 |
*/ |
62 |
public interface FeatureSet extends DataSet, IndexedVisitable { |
|
62 |
public interface FeatureSet extends DataSet, IndexedVisitable, Iterable<Feature> {
|
|
63 | 63 |
|
64 | 64 |
/** |
65 | 65 |
* Returns the default {@link FeatureType} of this FeatureSet. |
... | ... | |
214 | 214 |
* |
215 | 215 |
* @throws DataException |
216 | 216 |
*/ |
217 |
public DisposableIterator fastIterator(long index) throws DataException;
|
|
217 |
public DisposableIterator fastIterator(long index) throws DataException;
|
|
218 | 218 |
|
219 | 219 |
public DisposableIterator fastIterator(long index, long elemets) throws DataException; |
220 | 220 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureQueryOrder.java | ||
---|---|---|
27 | 27 |
import java.util.Iterator; |
28 | 28 |
import java.util.List; |
29 | 29 |
import java.util.NoSuchElementException; |
30 |
import org.apache.commons.lang3.StringUtils; |
|
30 | 31 |
|
31 | 32 |
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
32 | 33 |
import org.gvsig.tools.evaluator.Evaluator; |
... | ... | |
103 | 104 |
public FeatureQueryOrder() { |
104 | 105 |
} |
105 | 106 |
|
107 |
public Object add(String order) { |
|
108 |
if( StringUtils.isEmpty(order) ) { |
|
109 |
return null; |
|
110 |
} |
|
111 |
Object r = null; |
|
112 |
String[] attributes = StringUtils.split(order, ','); |
|
113 |
for (String attribute : attributes) { |
|
114 |
boolean ascending = true; |
|
115 |
if( attribute.startsWith("+") ) { |
|
116 |
ascending = true; |
|
117 |
attribute = attribute.substring(1); |
|
118 |
} else if( attribute.startsWith("-") ) { |
|
119 |
ascending = false; |
|
120 |
attribute = attribute.substring(1); |
|
121 |
} |
|
122 |
attribute = attribute.trim(); |
|
123 |
r = this.add(attribute,ascending); |
|
124 |
} |
|
125 |
return r; |
|
126 |
} |
|
127 |
|
|
106 | 128 |
public Object add(String attributeName, boolean ascending) { |
107 | 129 |
FeatureQueryOrderMember member = new FeatureQueryOrderMember( |
108 | 130 |
attributeName, ascending); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DALLibrary.java | ||
---|---|---|
27 | 27 |
import java.util.List; |
28 | 28 |
|
29 | 29 |
import org.cresques.ProjectionLibrary; |
30 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary; |
|
30 | 31 |
|
31 | 32 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
32 | 33 |
import org.gvsig.fmap.geom.GeometryLibrary; |
... | ... | |
47 | 48 |
*/ |
48 | 49 |
public class DALLibrary extends AbstractLibrary { |
49 | 50 |
|
51 |
@Override |
|
50 | 52 |
public void doRegistration() { |
51 | 53 |
registerAsAPI(DALLibrary.class); |
52 | 54 |
require(ToolsLibrary.class); |
... | ... | |
54 | 56 |
require(ProjectionLibrary.class); |
55 | 57 |
require(GeometryLibrary.class); |
56 | 58 |
require(TimeSupportLibrary.class); |
59 |
require(ExpressionEvaluatorLibrary.class); |
|
57 | 60 |
} |
58 | 61 |
|
62 |
@Override |
|
59 | 63 |
protected void doInitialize() throws LibraryException { |
60 | 64 |
// Do nothing |
61 | 65 |
} |
62 | 66 |
|
67 |
@Override |
|
63 | 68 |
protected void doPostInitialize() throws LibraryException { |
64 | 69 |
List exs = new ArrayList(); |
65 | 70 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataManager.java | ||
---|---|---|
64 | 64 |
public static final String READ_STORE_AUTHORIZATION = "dal-read-store"; |
65 | 65 |
public static final String WRITE_STORE_AUTHORIZATION = "dal-write-store"; |
66 | 66 |
|
67 |
public static final String FEATURE_SYMBOL_TABLE = "DAL.FeatureSymbolTable"; |
|
67 | 68 |
/** |
68 | 69 |
* Returns the default DAL's temporary directory |
69 | 70 |
* |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/resources-plugin/config.xml | ||
---|---|---|
693 | 693 |
icon="selection-by-attributes" |
694 | 694 |
accelerator="" |
695 | 695 |
/> |
696 |
<action |
|
697 |
name="selection2-by-attributes-table" |
|
698 |
label="_Select_by_attributes" |
|
699 |
tooltip="_Select_by_attributes" |
|
700 |
position="300400001" |
|
701 |
action-command="selection2-by-attributes-table" |
|
702 |
icon="selection-by-attributes" |
|
703 |
accelerator="" |
|
704 |
/> |
|
696 | 705 |
<menu |
697 | 706 |
name="selection-by-attributes-table" |
698 | 707 |
text="Selection/_Select_by_attributes" |
699 | 708 |
/> |
709 |
<menu |
|
710 |
name="selection2-by-attributes-table" |
|
711 |
text="Selection/_Select_by_attributes_new" |
|
712 |
/> |
|
700 | 713 |
|
701 | 714 |
<tool-bar name="table"> |
702 | 715 |
<action-tool |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/SelectByAttributesInTableExtension.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.app.extension; |
25 | 25 |
|
26 |
import java.awt.event.ActionEvent; |
|
27 |
import java.awt.event.ActionListener; |
|
26 | 28 |
import java.util.Iterator; |
27 | 29 |
|
28 | 30 |
import javax.swing.JOptionPane; |
... | ... | |
36 | 38 |
import org.gvsig.app.gui.filter.ExpressionListener; |
37 | 39 |
import org.gvsig.app.gui.filter.FilterDialog; |
38 | 40 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
41 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
42 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
43 |
import org.gvsig.expressionevaluator.swing.Element; |
|
44 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
|
45 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
|
46 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
|
39 | 47 |
import org.gvsig.fmap.dal.DALLocator; |
40 | 48 |
import org.gvsig.fmap.dal.DataManager; |
41 | 49 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
46 | 54 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
47 | 55 |
import org.gvsig.i18n.Messages; |
48 | 56 |
import org.gvsig.tools.dispose.DisposeUtils; |
57 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
58 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
59 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
60 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
49 | 61 |
import org.gvsig.utils.exceptionHandling.ExceptionListener; |
50 | 62 |
|
51 | 63 |
/** |
52 | 64 |
* Extensi?n que abre un di?logo para poder hacer un filtro de una capa o tabla. |
53 |
*
|
|
65 |
* |
|
54 | 66 |
* @author Vicente Caballero Navarro |
55 | 67 |
*/ |
56 | 68 |
public class SelectByAttributesInTableExtension extends Extension implements ExpressionListener { |
... | ... | |
64 | 76 |
} |
65 | 77 |
|
66 | 78 |
private void registerIcons() { |
67 |
IconThemeHelper.registerIcon("action", "selection-by-attributes", this);
|
|
79 |
IconThemeHelper.registerIcon("action", "selection-by-attributes", this);
|
|
68 | 80 |
} |
69 | 81 |
|
70 | 82 |
public void execute(String actionCommand) { |
71 |
if ("selection-by-attributes-table".equals(actionCommand)) { |
|
72 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
83 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
73 | 84 |
|
74 |
if (v instanceof FeatureTableDocumentPanel) { |
|
75 |
table = (FeatureTableDocumentPanel) v; |
|
85 |
if (!(v instanceof FeatureTableDocumentPanel)) { |
|
86 |
return; |
|
87 |
} |
|
88 |
if ("selection-by-attributes-table2".equals(actionCommand)) { |
|
89 |
table = (FeatureTableDocumentPanel) v; |
|
76 | 90 |
|
77 |
featureStore = table.getModel().getStore(); |
|
78 |
filterTitle = table.getModel().getName(); |
|
79 |
table.getModel().setModified(true); |
|
80 |
} |
|
91 |
featureStore = table.getModel().getStore(); |
|
92 |
filterTitle = table.getModel().getName(); |
|
93 |
table.getModel().setModified(true); |
|
81 | 94 |
|
95 |
doSelectByAttributes2(filterTitle, featureStore); |
|
96 |
|
|
97 |
} else if ("selection-by-attributes-table".equals(actionCommand)) { |
|
98 |
table = (FeatureTableDocumentPanel) v; |
|
99 |
|
|
100 |
featureStore = table.getModel().getStore(); |
|
101 |
filterTitle = table.getModel().getName(); |
|
102 |
table.getModel().setModified(true); |
|
103 |
|
|
82 | 104 |
doExecute(); |
83 | 105 |
} |
84 | 106 |
} |
... | ... | |
115 | 137 |
return; |
116 | 138 |
} |
117 | 139 |
featureStore.setSelection(set); |
118 |
|
|
140 |
|
|
119 | 141 |
} catch (Exception e) { |
120 |
logger.warn("Problems executing query '"+expression+"' on store '"+featureStore+"'.",e);
|
|
142 |
logger.warn("Problems executing query '" + expression + "' on store '" + featureStore + "'.", e);
|
|
121 | 143 |
JOptionPane.showMessageDialog( |
122 |
ApplicationLocator.getManager().getRootComponent(), |
|
123 |
Messages.getText("_Invalid_expression") + ":\n" |
|
144 |
ApplicationLocator.getManager().getRootComponent(),
|
|
145 |
Messages.getText("_Invalid_expression") + ":\n"
|
|
124 | 146 |
+ getLastMessage(e), |
125 |
Messages.getText("_Invalid_expression"), |
|
126 |
JOptionPane.ERROR_MESSAGE); |
|
147 |
Messages.getText("_Invalid_expression"),
|
|
148 |
JOptionPane.ERROR_MESSAGE);
|
|
127 | 149 |
} finally { |
128 | 150 |
DisposeUtils.disposeQuietly(set); |
129 | 151 |
} |
... | ... | |
153 | 175 |
featureStore.getFeatureSelection().select(set); |
154 | 176 |
|
155 | 177 |
} catch (Exception e) { |
156 |
logger.warn("Problems executing query '"+expression+"' on store '"+featureStore+"'.",e);
|
|
178 |
logger.warn("Problems executing query '" + expression + "' on store '" + featureStore + "'.", e);
|
|
157 | 179 |
JOptionPane.showMessageDialog( |
158 |
ApplicationLocator.getManager().getRootComponent(), |
|
159 |
Messages.getText("_Invalid_expression") + ":\n" |
|
180 |
ApplicationLocator.getManager().getRootComponent(),
|
|
181 |
Messages.getText("_Invalid_expression") + ":\n"
|
|
160 | 182 |
+ getLastMessage(e), |
161 |
Messages.getText("_Invalid_expression"), |
|
162 |
JOptionPane.ERROR_MESSAGE); |
|
183 |
Messages.getText("_Invalid_expression"),
|
|
184 |
JOptionPane.ERROR_MESSAGE);
|
|
163 | 185 |
} finally { |
164 | 186 |
DisposeUtils.disposeQuietly(set); |
165 | 187 |
} |
... | ... | |
168 | 190 |
|
169 | 191 |
@Override |
170 | 192 |
public void fromSet(String expression) throws DataException { |
171 |
if ( !this.filterExpressionFromWhereIsEmpty(expression) ) {
|
|
193 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) {
|
|
172 | 194 |
FeatureSet set = null; |
173 | 195 |
try { |
174 | 196 |
set = doSet(expression); |
175 |
if ( set == null ) {
|
|
197 |
if (set == null) {
|
|
176 | 198 |
return; |
177 | 199 |
} |
178 | 200 |
FeatureSelection oldSelection = featureStore.getFeatureSelection(); |
179 | 201 |
FeatureSelection newSelection = featureStore.createFeatureSelection(); |
180 | 202 |
Iterator iterator = set.iterator(); |
181 |
while ( iterator.hasNext() ) {
|
|
203 |
while (iterator.hasNext()) {
|
|
182 | 204 |
Feature feature = (Feature) iterator.next(); |
183 |
if ( oldSelection.isSelected(feature) ) {
|
|
205 |
if (oldSelection.isSelected(feature)) {
|
|
184 | 206 |
newSelection.select(feature); |
185 | 207 |
} |
186 | 208 |
} |
187 | 209 |
featureStore.setSelection(newSelection); |
188 | 210 |
} catch (Exception e) { |
189 |
logger.warn("Problems executing query '"+expression+"' on store '"+featureStore+"'.",e);
|
|
211 |
logger.warn("Problems executing query '" + expression + "' on store '" + featureStore + "'.", e);
|
|
190 | 212 |
JOptionPane.showMessageDialog( |
191 |
ApplicationLocator.getManager().getRootComponent(), |
|
192 |
Messages.getText("_Invalid_expression") + ":\n" |
|
213 |
ApplicationLocator.getManager().getRootComponent(),
|
|
214 |
Messages.getText("_Invalid_expression") + ":\n"
|
|
193 | 215 |
+ getLastMessage(e), |
194 |
Messages.getText("_Invalid_expression"), |
|
195 |
JOptionPane.ERROR_MESSAGE); |
|
216 |
Messages.getText("_Invalid_expression"),
|
|
217 |
JOptionPane.ERROR_MESSAGE);
|
|
196 | 218 |
} finally { |
197 | 219 |
DisposeUtils.disposeQuietly(set); |
198 | 220 |
} |
... | ... | |
200 | 222 |
featureStore.getFeatureSelection().deselectAll(); |
201 | 223 |
} |
202 | 224 |
} |
203 |
|
|
225 |
|
|
204 | 226 |
/** |
205 | 227 |
* Returns true if the WHERE subconsultation of the filterExpression is |
206 | 228 |
* empty ("") |
207 |
*
|
|
229 |
* |
|
208 | 230 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com) |
209 |
* @param expression |
|
210 |
* An string |
|
231 |
* @param expression An string |
|
211 | 232 |
* @return A boolean value |
212 | 233 |
*/ |
213 | 234 |
private boolean filterExpressionFromWhereIsEmpty(String expression) { |
214 |
|
|
235 |
|
|
215 | 236 |
if (expression == null) { |
216 | 237 |
return true; |
217 | 238 |
} |
218 |
|
|
239 |
|
|
219 | 240 |
String subExpression = expression.trim(); |
220 |
|
|
241 |
|
|
221 | 242 |
if (subExpression.length() == 0) { |
222 | 243 |
return true; |
223 | 244 |
} |
224 |
|
|
245 |
|
|
225 | 246 |
int pos; |
226 | 247 |
|
227 | 248 |
// Remove last ';' if exists |
228 | 249 |
if (subExpression.charAt(subExpression.length() - 1) == ';') { |
229 |
subExpression =
|
|
230 |
subExpression.substring(0, subExpression.length() - 1).trim(); |
|
250 |
subExpression |
|
251 |
= subExpression.substring(0, subExpression.length() - 1).trim();
|
|
231 | 252 |
} |
232 | 253 |
|
233 | 254 |
// If there is no 'where' clause |
... | ... | |
237 | 258 |
|
238 | 259 |
// If there is no subexpression in the WHERE clause -> true |
239 | 260 |
// ( + 5 is the length of the 'where') |
240 |
subExpression =subExpression.substring(pos + 5, subExpression.length()).trim();
|
|
241 |
|
|
261 |
subExpression = subExpression.substring(pos + 5, subExpression.length()).trim();
|
|
262 |
|
|
242 | 263 |
if (subExpression.length() == 0) { |
243 | 264 |
return true; |
244 | 265 |
} else { |
245 | 266 |
return false; |
246 | 267 |
} |
247 | 268 |
} |
248 |
|
|
249 |
|
|
269 |
|
|
250 | 270 |
/** |
251 | 271 |
* @param ex |
252 | 272 |
* @return |
253 | 273 |
*/ |
254 | 274 |
public static String getLastMessage(Throwable ex) { |
255 |
|
|
275 |
|
|
256 | 276 |
Throwable p = ex; |
257 | 277 |
while (p.getCause() != null && p.getCause() != p) { |
258 | 278 |
p = p.getCause(); |
259 | 279 |
} |
260 | 280 |
return p.getMessage(); |
261 |
} |
|
281 |
} |
|
282 |
|
|
283 |
private void doSelectByAttributes2(String title, final FeatureStore store) { |
|
284 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
285 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
286 |
ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
|
287 |
|
|
288 |
final JExpressionBuilder panel = swingManager.createJExpressionBuilder(); |
|
289 |
Element element = swingManager.createElement("DAL.FeatureStoreElement", panel, store); |
|
290 |
if (element != null) { |
|
291 |
panel.getElements().add(element); |
|
292 |
} |
|
293 |
final Dialog dialog = windowManager.createDialog( |
|
294 |
panel.asJComponent(), |
|
295 |
title, |
|
296 |
null, |
|
297 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
298 |
); |
|
299 |
dialog.addActionListener(new ActionListener() { |
|
300 |
@Override |
|
301 |
public void actionPerformed(ActionEvent e) { |
|
302 |
if (dialog.getAction() == WindowManager_v2.BUTTON_OK) { |
|
303 |
try { |
|
304 |
DataManager manager = DALLocator.getDataManager(); |
|
305 |
|
|
306 |
FeatureQuery query = store.createFeatureQuery(); |
|
307 |
query.setFilter(manager.createExpresion(panel.getExpression())); |
|
308 |
FeatureSet selection = store.getFeatureSet(query); |
|
309 |
store.getFeatureSelection().select(selection); |
|
310 |
} catch (Exception ex) { |
|
311 |
logger.warn("Can't build selecction from filter expression.", ex); |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
}); |
|
316 |
dialog.show(WindowManager.MODE.WINDOW); |
|
317 |
|
|
318 |
} |
|
262 | 319 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/pom.xml | ||
---|---|---|
90 | 90 |
<groupId>org.gvsig</groupId> |
91 | 91 |
<artifactId>org.gvsig.i18n</artifactId> |
92 | 92 |
<scope>compile</scope> |
93 |
</dependency> |
|
94 |
|
|
93 |
</dependency> |
|
94 |
<dependency> |
|
95 |
<groupId>org.gvsig</groupId> |
|
96 |
<artifactId>org.gvsig.expressionevaluator.swing.api</artifactId> |
|
97 |
<scope>compile</scope> |
|
98 |
</dependency> |
|
95 | 99 |
</dependencies> |
96 | 100 |
|
97 | 101 |
<build> |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/BaseViewDocument.java | ||
---|---|---|
327 | 327 |
return this.propertiesHelper.getExtendedProperties(); |
328 | 328 |
} |
329 | 329 |
|
330 |
@Override |
|
331 |
public FLayer getLayer(String name) { |
|
332 |
FLayer layer = this.getMapContext().getLayers().getLayer(name); |
|
333 |
return layer; |
|
334 |
} |
|
335 |
|
|
330 | 336 |
public Iterator<FLayer> iterator() { |
331 | 337 |
return this.mapContext.iterator(); |
332 | 338 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/ViewDocument.java | ||
---|---|---|
82 | 82 |
public void setProjection (IProjection proj); |
83 | 83 |
|
84 | 84 |
public void setBackColor(Color c) ; |
85 |
|
|
86 |
public FLayer getLayer(String name); |
|
85 | 87 |
|
86 | 88 |
/** |
87 | 89 |
* Get the first level of layer in the view TOC. |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/ProjectSymbolTable.java | ||
---|---|---|
1 |
package org.gvsig.app.project; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Map; |
|
7 |
import java.util.Properties; |
|
8 |
import org.apache.commons.io.IOUtils; |
|
9 |
import org.apache.commons.lang3.Range; |
|
10 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
11 |
import org.gvsig.app.project.documents.view.ViewManager; |
|
12 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
13 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
14 |
import org.gvsig.expressionevaluator.Interpreter; |
|
15 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
16 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
|
17 |
import org.gvsig.fmap.dal.feature.Feature; |
|
18 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
19 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
20 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
21 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
22 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
23 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
24 |
|
|
25 |
/** |
|
26 |
* |
|
27 |
* @author jjdelcerro |
|
28 |
*/ |
|
29 |
@SuppressWarnings("UseSpecificCatch") |
|
30 |
public class ProjectSymbolTable extends AbstractSymbolTable { |
|
31 |
|
|
32 |
private abstract class CachedValue<T> { |
|
33 |
|
|
34 |
T value = null; |
|
35 |
long lastAccess = 0; |
|
36 |
|
|
37 |
protected abstract void reload(); |
|
38 |
|
|
39 |
public boolean isExpired() { |
|
40 |
long now = System.currentTimeMillis(); |
|
41 |
return now - lastAccess > 3000; |
|
42 |
} |
|
43 |
|
|
44 |
public T get() { |
|
45 |
if (isExpired()) { |
|
46 |
reload(); |
|
47 |
} |
|
48 |
lastAccess = System.currentTimeMillis(); |
|
49 |
return value; |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
private class ProjectValue extends CachedValue<Project> { |
|
54 |
|
|
55 |
@Override |
|
56 |
protected void reload() { |
|
57 |
value = ProjectManager.getInstance().getCurrentProject(); |
|
58 |
} |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
private class PropertiesValue extends CachedValue<Map<File, Properties>> { |
|
63 |
|
|
64 |
@Override |
|
65 |
protected void reload() { |
|
66 |
value = new HashMap<>(); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
private class CurrentProjectFunction extends AbstractFunction { |
|
71 |
|
|
72 |
public CurrentProjectFunction() { |
|
73 |
super( |
|
74 |
"Project", |
|
75 |
"project", |
|
76 |
Range.is(0), |
|
77 |
"Access to the current project loaded in gvSIG desktop.\n", |
|
78 |
"project()", |
|
79 |
null, |
|
80 |
"Project" |
|
81 |
); |
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
85 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
86 |
return currentProject.get(); |
|
87 |
} |
|
88 |
|
|
89 |
} |
|
90 |
|
|
91 |
private class FirstSelectedFeatureFunction extends AbstractFunction { |
|
92 |
|
|
93 |
public FirstSelectedFeatureFunction() { |
|
94 |
super( |
|
95 |
"Project", |
|
96 |
"firstSelectedFeature", |
|
97 |
Range.between(3, 4), |
|
98 |
"Access to the first selected feature of the layer, and " |
|
99 |
+ "return the value of the attribute.", |
|
100 |
"firstSelectedFeature({{view}}, layer, attribute, defaulValue)", |
|
101 |
new String[]{ |
|
102 |
"view - String value with the name of a view", |
|
103 |
"layer - String value with the name of a layer in the indicated view", |
|
104 |
"attribute - String value with the name of the attribute in the indicated layer", |
|
105 |
"defaultValue - Optional. Value to use if the indicated " |
|
106 |
+ "attribute can not be accessed. For example, if the " |
|
107 |
+ "view or layer does not exist, or it does not have " |
|
108 |
+ "selected elements." |
|
109 |
}, |
|
110 |
"Object" |
|
111 |
); |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
116 |
Object defaultValue = null; |
|
117 |
String viewName = getStr(args, 0); |
|
118 |
String layerName = getStr(args, 1); |
|
119 |
String attrName = getStr(args, 2); |
|
120 |
if (args.length == 4) { |
|
121 |
defaultValue = getObject(args, 3); |
|
122 |
} |
|
123 |
try { |
|
124 |
Project project = currentProject.get(); |
|
125 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
126 |
if (view == null) { |
|
127 |
return defaultValue; |
|
128 |
} |
|
129 |
FLayer layer = view.getLayer(layerName); |
|
130 |
if (!(layer instanceof FLyrVect)) { |
|
131 |
return defaultValue; |
|
132 |
} |
|
133 |
FeatureSelection selection = ((FLyrVect) layer).getFeatureStore().getFeatureSelection(); |
|
134 |
if (selection == null || selection.isEmpty()) { |
|
135 |
return defaultValue; |
|
136 |
} |
|
137 |
Feature feature = selection.first(); |
|
138 |
if (feature == null) { |
|
139 |
return defaultValue; |
|
140 |
} |
|
141 |
return feature.get(attrName); |
|
142 |
} catch (Exception ex) { |
|
143 |
return defaultValue; |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
} |
|
148 |
|
|
149 |
private class FirstFeatureFunction extends AbstractFunction { |
|
150 |
|
|
151 |
public FirstFeatureFunction() { |
|
152 |
super( |
|
153 |
"Project", |
|
154 |
"firstFeature", |
|
155 |
Range.between(3, 6), |
|
156 |
"Access to the first feature of the layer, and " |
|
157 |
+ "return the value of the attribute.", |
|
158 |
"firstFeature({{view}}, layer, attribute, filter, order, defaulValue)", |
|
159 |
new String[]{ |
|
160 |
"view - String value with the name of a view", |
|
161 |
"layer - String value with the name of a layer in the indicated view", |
|
162 |
"attribute - String value with the name of the attribute in the indicated layer", |
|
163 |
"filter - Optional. String value with a filter expression", |
|
164 |
"order - Optional. String value with the order. must be a string with the names of separate fields with commas", |
|
165 |
"defaultValue - Optional. Value to use if the indicated " |
|
166 |
+ "attribute can not be accessed. For example, if the " |
|
167 |
+ "view or layer does not exist." |
|
168 |
}, |
|
169 |
"Object" |
|
170 |
); |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
175 |
Object defaultValue = null; |
|
176 |
String filter = null; |
|
177 |
String order = null; |
|
178 |
String viewName = getStr(args, 0); |
|
179 |
String layerName = getStr(args, 1); |
|
180 |
String attrName = getStr(args, 2); |
|
181 |
switch(args.length ) { |
|
182 |
case 4: |
|
183 |
filter = getStr(args, 3); |
|
184 |
break; |
|
185 |
case 5: |
|
186 |
filter = getStr(args, 3); |
|
187 |
order = getStr(args, 4); |
|
188 |
break; |
|
189 |
case 6: |
|
190 |
filter = getStr(args, 3); |
|
191 |
order = getStr(args, 4); |
|
192 |
defaultValue = getObject(args, 6); |
|
193 |
break; |
|
194 |
} |
|
195 |
try { |
|
196 |
Project project = currentProject.get(); |
|
197 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
198 |
if (view == null) { |
|
199 |
return defaultValue; |
|
200 |
} |
|
201 |
FLayer layer = view.getLayer(layerName); |
|
202 |
if (!(layer instanceof FLyrVect)) { |
|
203 |
return defaultValue; |
|
204 |
} |
|
205 |
FeatureStore store = ((FLyrVect) layer).getFeatureStore(); |
|
206 |
FeatureSet set; |
|
207 |
if( filter==null && order==null ) { |
|
208 |
set = store.getFeatureSet(); |
|
209 |
} else { |
|
210 |
FeatureQuery query = store.createFeatureQuery(); |
|
211 |
if( filter != null ) { |
|
212 |
query.addFilter(filter); |
|
213 |
} |
|
214 |
if( order!=null ) { |
|
215 |
query.getOrder().add(order); |
|
216 |
} |
|
217 |
set = store.getFeatureSet(query); |
|
218 |
} |
|
219 |
Feature feature = set.first(); |
|
220 |
if (feature == null) { |
|
221 |
return defaultValue; |
|
222 |
} |
|
223 |
return feature.get(attrName); |
|
224 |
} catch (Exception ex) { |
|
225 |
return defaultValue; |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
229 |
} |
|
230 |
|
|
231 |
private class ViewFunction extends AbstractFunction { |
|
232 |
|
|
233 |
public ViewFunction() { |
|
234 |
super( |
|
235 |
"Project", |
|
236 |
"view", |
|
237 |
Range.is(1), |
|
238 |
"Access to the indicated view", |
|
239 |
"view({{viewName}})", |
|
240 |
new String[]{ |
|
241 |
"view - String value with the name of a view" |
|
242 |
}, |
|
243 |
"DocumentView" |
|
244 |
); |
|
245 |
} |
|
246 |
|
|
247 |
@Override |
|
248 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
249 |
String viewName = getStr(args, 0); |
|
250 |
Project project = currentProject.get(); |
|
251 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
252 |
return view; |
|
253 |
} |
|
254 |
|
|
255 |
} |
|
256 |
|
|
257 |
private class PropertyFunction extends AbstractFunction { |
|
258 |
|
|
259 |
public PropertyFunction() { |
|
260 |
super( |
|
261 |
"Project", |
|
262 |
"property", |
|
263 |
Range.between(2, 3), |
|
264 |
"Access to a property value in a properties file. If the" |
|
265 |
+ "indicated filename is not absolute, access it relative" |
|
266 |
+ "to the project.", |
|
267 |
"property({{filename}}, name, defaultValue)", |
|
268 |
new String[]{ |
|
269 |
"filename - String value with the name of the properties file", |
|
270 |
"name - String value with the name of the property to retrieve from the file", |
|
271 |
"defaultValue - Optional. Default value if can't access the file or the property",}, |
|
272 |
"String" |
|
273 |
); |
|
274 |
} |
|
275 |
|
|
276 |
@Override |
|
277 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
278 |
String filename = getStr(args, 0); |
|
279 |
String name = getStr(args, 1); |
|
280 |
String defaultValue = null; |
|
281 |
if (args.length == 3) { |
|
282 |
defaultValue = getStr(args, 2); |
|
283 |
} |
|
284 |
|
|
285 |
File file = new File(filename); |
|
286 |
if (!file.isAbsolute()) { |
|
287 |
Project project = currentProject.get(); |
|
288 |
if (project.getFile() == null) { |
|
289 |
return defaultValue; |
|
290 |
} |
|
291 |
file = new File(project.getFile().getParent(), filename); |
|
292 |
} |
|
293 |
Map<File, Properties> x = propertiesFiles.get(); |
|
294 |
Properties properties = x.get(file); |
|
295 |
if (properties == null) { |
|
296 |
properties = new Properties(); |
|
297 |
FileInputStream in = null; |
|
298 |
try { |
|
299 |
in = new FileInputStream(file); |
|
300 |
properties.load(in); |
|
301 |
} catch (Exception ex) { |
|
302 |
return defaultValue; |
|
303 |
} finally { |
|
304 |
IOUtils.closeQuietly(in); |
|
305 |
} |
|
306 |
x.put(file, properties); |
|
307 |
} |
|
308 |
String value = properties.getProperty(name, defaultValue); |
|
309 |
return value; |
|
310 |
} |
|
311 |
|
|
312 |
} |
|
313 |
|
|
314 |
ProjectValue currentProject = new ProjectValue(); |
|
315 |
PropertiesValue propertiesFiles = new PropertiesValue(); |
|
316 |
|
|
317 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
318 |
public ProjectSymbolTable() { |
|
319 |
super("Project"); |
|
320 |
this.addFunction(new CurrentProjectFunction()); |
|
321 |
this.addFunction(new FirstSelectedFeatureFunction()); |
|
322 |
this.addFunction(new FirstFeatureFunction()); |
|
323 |
this.addFunction(new ViewFunction()); |
|
324 |
this.addFunction(new PropertyFunction()); |
|
325 |
} |
|
326 |
|
|
327 |
public static void selfRegister() { |
|
328 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
329 |
manager.registerSymbolTable(new ProjectSymbolTable(), true); |
|
330 |
} |
|
331 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/ApplicationLibrary.java | ||
---|---|---|
34 | 34 |
import org.gvsig.app.extension.InitializeApplicationExtension; |
35 | 35 |
import org.gvsig.app.gui.preferencespage.AppSymbolPreferences; |
36 | 36 |
import org.gvsig.app.project.DefaultProject; |
37 |
import org.gvsig.app.project.ProjectSymbolTable; |
|
38 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary; |
|
37 | 39 |
import org.gvsig.fmap.mapcontext.MapContextLibrary; |
38 | 40 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
39 | 41 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
... | ... | |
62 | 64 |
require(MapContextLibrary.class); |
63 | 65 |
require(MapControlLibrary.class); |
64 | 66 |
require(InstallerLibrary.class); |
67 |
require(ExpressionEvaluatorLibrary.class); |
|
65 | 68 |
} |
66 | 69 |
|
67 | 70 |
@Override |
... | ... | |
87 | 90 |
MapContextLocator.getSymbolManager().setSymbolPreferences(new AppSymbolPreferences()); |
88 | 91 |
|
89 | 92 |
installBaseSymbols(); |
90 |
} |
|
93 |
ProjectSymbolTable.selfRegister(); |
|
94 |
} |
|
91 | 95 |
|
92 | 96 |
/** |
93 | 97 |
* Copy symbol folders from this plugin's 'Symbols' folder |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/SelectByAttributesExtension.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package org.gvsig.app.extension; |
24 | 24 |
|
25 |
import java.awt.BorderLayout; |
|
26 |
import java.awt.FlowLayout; |
|
27 |
import java.awt.event.ActionEvent; |
|
25 | 28 |
import java.util.Iterator; |
29 |
import javax.swing.AbstractAction; |
|
30 |
import javax.swing.JButton; |
|
26 | 31 |
|
27 | 32 |
import javax.swing.JOptionPane; |
33 |
import javax.swing.JPanel; |
|
28 | 34 |
|
29 | 35 |
import org.gvsig.andami.IconThemeHelper; |
30 | 36 |
import org.gvsig.andami.PluginServices; |
... | ... | |
36 | 42 |
import org.gvsig.app.gui.filter.FilterDialog; |
37 | 43 |
import org.gvsig.app.project.documents.view.ViewDocument; |
38 | 44 |
import org.gvsig.app.project.documents.view.gui.IView; |
45 |
import org.gvsig.expressionevaluator.Expression; |
|
46 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
|
47 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
|
48 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
|
49 |
import org.gvsig.expressionevaluator.swing.Element; |
|
39 | 50 |
import org.gvsig.fmap.dal.DALLocator; |
40 | 51 |
import org.gvsig.fmap.dal.DataManager; |
41 | 52 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
44 | 55 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
45 | 56 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
46 | 57 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
58 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
|
47 | 59 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
48 | 60 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
49 | 61 |
import org.gvsig.i18n.Messages; |
62 |
import org.gvsig.tools.ToolsLocator; |
|
63 |
import org.gvsig.tools.i18n.I18nManager; |
|
64 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
65 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
50 | 66 |
import org.gvsig.utils.exceptionHandling.ExceptionListener; |
51 | 67 |
|
52 | 68 |
/** |
... | ... | |
54 | 70 |
* |
55 | 71 |
* @author Vicente Caballero Navarro |
56 | 72 |
*/ |
73 |
@SuppressWarnings("UseSpecificCatch") |
|
57 | 74 |
public class SelectByAttributesExtension extends Extension implements ExpressionListener { |
58 | 75 |
|
59 | 76 |
protected FeatureStore featureStore = null; |
60 | 77 |
private String filterTitle; |
61 | 78 |
|
79 |
@Override |
|
62 | 80 |
public void initialize() { |
63 | 81 |
IconThemeHelper.registerIcon("action", "selection-by-attributes", this); |
64 | 82 |
} |
65 | 83 |
|
84 |
@Override |
|
66 | 85 |
public void execute(String actionCommand) { |
67 | 86 |
ApplicationManager application = ApplicationLocator.getManager(); |
68 | 87 |
|
... | ... | |
70 | 89 |
if (view == null) { |
71 | 90 |
return; |
72 | 91 |
} |
73 |
ViewDocument document = view.getViewDocument();
|
|
74 |
|
|
75 |
if ("selection-by-attributes-layer".equalsIgnoreCase(actionCommand)) { |
|
92 |
if ("selection-by-attributes-layer2".equals(actionCommand)) {
|
|
93 |
ViewDocument document = view.getViewDocument(); |
|
94 |
|
|
76 | 95 |
FLayer layer = document.getMapContext().getLayers().getActives()[0]; |
77 | 96 |
filterTitle = layer.getName(); |
78 | 97 |
featureStore = ((FLyrVect) layer).getFeatureStore(); |
79 | 98 |
document.setModified(true); |
99 |
doSelectByAttributes2(filterTitle, featureStore); |
|
100 |
|
|
101 |
} else if ("selection-by-attributes-layer".equals(actionCommand)) { |
|
102 |
ViewDocument document = view.getViewDocument(); |
|
103 |
|
|
104 |
FLayer layer = document.getMapContext().getLayers().getActives()[0]; |
|
105 |
filterTitle = layer.getName(); |
|
106 |
featureStore = ((FLyrVect) layer).getFeatureStore(); |
|
107 |
document.setModified(true); |
|
80 | 108 |
doExecute(); |
81 | 109 |
} |
82 | 110 |
} |
... | ... | |
90 | 118 |
dlg.addExpressionListener(this); |
91 | 119 |
dlg.addExceptionListener(new ExceptionListener() { |
92 | 120 |
|
121 |
@Override |
|
93 | 122 |
public void exceptionThrown(Throwable t) { |
94 | 123 |
NotificationManager.addError(t.getMessage(), t); |
95 | 124 |
} |
... | ... | |
98 | 127 |
PluginServices.getMDIManager().addWindow(dlg); |
99 | 128 |
} |
100 | 129 |
|
130 |
@Override |
|
101 | 131 |
public boolean isEnabled() { |
102 | 132 |
return true; |
103 | 133 |
} |
104 | 134 |
|
135 |
@Override |
|
105 | 136 |
public boolean isVisible() { |
106 | 137 |
ApplicationManager application = ApplicationLocator.getManager(); |
107 | 138 |
|
... | ... | |
114 | 145 |
} |
115 | 146 |
|
116 | 147 |
// By Pablo: if no filter expression -> no element selected |
148 |
@Override |
|
117 | 149 |
public void newSet(String expression) throws DataException { |
118 | 150 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) { |
119 | 151 |
FeatureSet set = null; |
... | ... | |
152 | 184 |
return featureStore.getFeatureSet(query); |
153 | 185 |
} |
154 | 186 |
|
187 |
@Override |
|
155 | 188 |
public void addToSet(String expression) throws DataException { |
156 | 189 |
// By Pablo: if no filter expression -> don't add more elements to set |
157 | 190 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) { |
... | ... | |
172 | 205 |
} |
173 | 206 |
} |
174 | 207 |
|
208 |
@Override |
|
175 | 209 |
public void fromSet(String expression) throws DataException { |
176 | 210 |
// By Pablo: if no filter expression -> no element selected |
177 | 211 |
try { |
... | ... | |
179 | 213 |
// NotificationManager.showMessageInfo("Falta por implementar", |
180 | 214 |
// null); |
181 | 215 |
|
182 |
FeatureSet set = null;
|
|
216 |
FeatureSet set; |
|
183 | 217 |
set = doSet(expression); |
184 | 218 |
|
185 | 219 |
if (set == null) { |
... | ... | |
204 | 238 |
} else { |
205 | 239 |
// By Pablo: if no expression -> no element selected |
206 | 240 |
featureStore.getFeatureSelection().deselectAll(); |
207 |
; |
|
208 | 241 |
} |
209 | 242 |
} catch (DataException e) { |
210 | 243 |
NotificationManager.addError(e); |
... | ... | |
263 | 296 |
} |
264 | 297 |
return p.getMessage(); |
265 | 298 |
} |
299 |
|
|
300 |
private void doSelectByAttributes2(String title, final FeatureStore store) { |
|
301 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
302 |
WindowManager windowManager = ToolsSwingLocator.getWindowManager(); |
|
303 |
ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
|
304 |
|
|
305 |
final JPanel panel = new JPanel(); |
|
306 |
panel.setLayout(new BorderLayout()); |
|
307 |
|
|
308 |
final JExpressionBuilder builder = swingManager.createJExpressionBuilder(); |
|
309 |
builder.addSymbolTable(DataManager.FEATURE_SYMBOL_TABLE); |
|
310 |
Element element = swingManager.createElement( |
|
311 |
DataSwingManager.FEATURE_STORE_EXPRESSION_ELEMENT, |
|
312 |
builder, |
|
313 |
store |
|
314 |
); |
|
315 |
if (element != null) { |
|
316 |
builder.getElements().add(element); |
|
317 |
} |
|
318 |
panel.add(builder.asJComponent(), BorderLayout.CENTER); |
|
319 |
JPanel buttons = new JPanel(); |
|
320 |
buttons.setLayout(new FlowLayout(FlowLayout.RIGHT, 4, 4)); |
|
321 |
buttons.add(new JButton(new AbstractAction(i18n.getTranslation("_Set_selection")) { |
|
322 |
@Override |
|
323 |
public void actionPerformed(ActionEvent e) { |
|
324 |
doSetSelection(store, builder.getExpression()); |
|
325 |
} |
|
326 |
})); |
|
327 |
buttons.add(new JButton(new AbstractAction(i18n.getTranslation("_Add_to_selection")) { |
|
328 |
@Override |
|
329 |
public void actionPerformed(ActionEvent e) { |
|
330 |
doAddToSelection(store, builder.getExpression()); |
|
331 |
} |
|
332 |
})); |
|
333 |
buttons.add(new JButton(new AbstractAction(i18n.getTranslation("_Filter_selection")) { |
|
334 |
@Override |
|
335 |
public void actionPerformed(ActionEvent e) { |
|
336 |
doFilterSelection(store, builder.getExpression()); |
|
337 |
} |
|
338 |
})); |
|
339 |
buttons.add(new JButton(new AbstractAction(i18n.getTranslation("_Close")) { |
|
340 |
@Override |
|
341 |
public void actionPerformed(ActionEvent e) { |
|
342 |
panel.setVisible(false); |
|
343 |
} |
|
344 |
})); |
|
345 |
panel.add(buttons, BorderLayout.SOUTH); |
|
346 |
|
|
347 |
windowManager.showWindow( |
|
348 |
panel, |
|
349 |
title, |
|
350 |
WindowManager.MODE.WINDOW |
|
351 |
); |
|
352 |
|
|
353 |
} |
|
354 |
|
|
355 |
private void doSetSelection(FeatureStore store, Expression expression) { |
|
356 |
try { |
|
357 |
DataManager manager = DALLocator.getDataManager(); |
|
358 |
|
|
359 |
FeatureSelection currentSelection = store.getFeatureSelection(); |
|
360 |
FeatureQuery query = store.createFeatureQuery(); |
|
361 |
query.setFilter(manager.createExpresion(expression)); |
|
362 |
FeatureSet selection = store.getFeatureSet(query); |
|
363 |
currentSelection.deselectAll(); |
|
364 |
currentSelection.select(selection); |
|
365 |
} catch (Exception ex) { |
|
366 |
logger.warn("Can't build selecction from filter expression.", ex); |
|
367 |
} |
|
368 |
} |
|
369 |
|
|
370 |
private void doAddToSelection(FeatureStore store, Expression expression) { |
|
371 |
try { |
|
372 |
DataManager manager = DALLocator.getDataManager(); |
|
373 |
|
|
374 |
FeatureSelection currentSelection = store.getFeatureSelection(); |
|
375 |
FeatureQuery query = store.createFeatureQuery(); |
|
376 |
query.setFilter(manager.createExpresion(expression)); |
|
377 |
FeatureSet selection = store.getFeatureSet(query); |
|
378 |
currentSelection.select(selection); |
|
379 |
} catch (Exception ex) { |
|
380 |
logger.warn("Can't build selecction from filter expression.", ex); |
|
381 |
} |
|
382 |
} |
|
383 |
|
|
384 |
private void doFilterSelection(FeatureStore store, Expression expression) { |
|
385 |
try { |
|
386 |
DataManager manager = DALLocator.getDataManager(); |
|
387 |
|
|
388 |
FeatureSelection currentSelection = store.getFeatureSelection(); |
|
389 |
FeatureQuery query = store.createFeatureQuery(); |
|
390 |
query.setFilter(manager.createExpresion(expression)); |
|
391 |
FeatureSet set = store.getFeatureSet(query); |
|
392 |
FeatureSelection newSelection = store.createFeatureSelection(); |
|
393 |
for (Feature feature : set) { |
|
394 |
if( currentSelection.isSelected(feature) ) { |
|
395 |
newSelection.select(feature); |
|
396 |
} |
|
397 |
} |
|
398 |
store.setSelection(newSelection); |
|
399 |
} catch (Exception ex) { |
|
400 |
logger.warn("Can't build selecction from filter expression.", ex); |
|
401 |
} |
|
402 |
} |
|
403 |
|
|
266 | 404 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/config.xml | ||
---|---|---|
824 | 824 |
accelerator="" |
825 | 825 |
/> |
826 | 826 |
|
827 |
<action |
|
828 |
name="selection-by-attributes-layer2" |
|
829 |
label="_Select_by_attributes" |
|
830 |
position="300080001" |
|
831 |
icon="selection-by-attributes" |
|
832 |
tooltip="_Select_by_attributes" |
|
833 |
action-command="selection-by-attributes-layer2" |
|
834 |
accelerator="" |
|
835 |
/> |
|
836 |
|
|
827 | 837 |
<menu |
828 | 838 |
name="selection-by-attributes-layer" |
839 |
text="Selection/_Select_by_attributes_old" |
|
840 |
/> |
|
841 |
|
|
842 |
<menu |
|
843 |
name="selection-by-attributes-layer2" |
|
829 | 844 |
text="Selection/_Select_by_attributes" |
830 | 845 |
/> |
831 | 846 |
|
832 | 847 |
<tool-bar name="selection"> |
833 |
<action-tool name="selection-by-attributes-layer" /> |
|
848 |
<action-tool name="selection-by-attributes-layer2" />
|
|
834 | 849 |
</tool-bar> |
835 | 850 |
|
836 | 851 |
</extension> |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/pom.xml | ||
---|---|---|
309 | 309 |
<dependency> |
310 | 310 |
<groupId>org.gvsig</groupId> |
311 | 311 |
<artifactId>org.gvsig.expressionevaluator.swing.api</artifactId> |
312 |
<scope>runtime</scope> |
|
312 |
<version>2.0.233-SNAPSHOT</version> |
|
313 |
<type>jar</type> |
|
313 | 314 |
</dependency> |
314 | 315 |
<dependency> |
315 | 316 |
<groupId>org.gvsig</groupId> |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractSymbolTable.java | ||
---|---|---|
11 | 11 |
import java.util.Set; |
12 | 12 |
import org.apache.commons.lang3.Range; |
13 | 13 |
import org.apache.commons.lang3.StringUtils; |
14 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
15 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
16 | 14 |
import org.gvsig.expressionevaluator.Function; |
17 | 15 |
import org.gvsig.expressionevaluator.Interpreter; |
18 | 16 |
import org.gvsig.expressionevaluator.SymbolTable; |
... | ... | |
68 | 66 |
public String getName() { |
69 | 67 |
return name; |
70 | 68 |
} |
69 |
|
|
70 |
protected void addFunction(Function function) { |
|
71 |
if (function == null) { |
|
72 |
throw new IllegalArgumentException("function can't be null"); |
|
73 |
} |
|
74 |
this.getFunctions().put(function.name().toUpperCase(), function); |
|
75 |
} |
|
71 | 76 |
|
72 | 77 |
@Override |
73 | 78 |
public void addSymbolTable(SymbolTable symbolTable) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionEvaluatorManager.java | ||
---|---|---|
22 | 22 |
|
23 | 23 |
public Collection<SymbolTable> getSymbolTables(); |
24 | 24 |
|
25 |
public void registerSymbolTable(SymbolTable symbolTable); |
|
25 |
public void registerSymbolTable(SymbolTable symbolTable, boolean autoload); |
|
26 |
|
|
27 |
public boolean isAutoload(SymbolTable symbolTable); |
|
26 | 28 |
|
27 | 29 |
public LexicalAnalyzer createLexicalAnalyzer(); |
28 | 30 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/symboltable/OGCSymbolTable.java | ||
---|---|---|
87 | 87 |
this.addFunction(new STYFunction()); |
88 | 88 |
this.addFunction(new STZFunction()); |
89 | 89 |
|
90 |
} |
|
91 |
|
|
92 |
private void addFunction(Function function) { |
|
93 |
if( function==null ) { |
|
94 |
throw new IllegalArgumentException("function can't be null"); |
|
95 |
} |
|
96 |
this.getFunctions().put(function.name().toUpperCase(), function); |
|
97 |
} |
|
98 |
|
|
99 |
|
|
90 |
} |
|
100 | 91 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/symboltable/SQLSymbolTable.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl.symboltable; |
2 | 2 |
|
3 | 3 |
import org.gvsig.expressionevaluator.Function; |
4 |
import org.gvsig.expressionevaluator.impl.function.date.DateFunction; |
|
5 |
import org.gvsig.expressionevaluator.impl.function.date.NowFunction; |
|
6 |
import org.gvsig.expressionevaluator.impl.function.date.TimeFunction; |
|
7 |
import org.gvsig.expressionevaluator.impl.function.date.TimestampFunction; |
|
4 | 8 |
import org.gvsig.expressionevaluator.impl.function.numeric.ACosFunction; |
5 | 9 |
import org.gvsig.expressionevaluator.impl.function.numeric.ASinFunction; |
6 | 10 |
import org.gvsig.expressionevaluator.impl.function.numeric.ATanFunction; |
... | ... | |
73 | 77 |
*/ |
74 | 78 |
public class SQLSymbolTable extends AbstractSymbolTable { |
75 | 79 |
|
80 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
76 | 81 |
public SQLSymbolTable() { |
77 | 82 |
super("SQL"); |
78 | 83 |
|
... | ... | |
147 | 152 |
this.addFunction(new TrimFunction()); |
148 | 153 |
this.addFunction(new UpperFunction()); |
149 | 154 |
|
155 |
this.addFunction(new NowFunction()); |
|
156 |
this.addFunction(new DateFunction()); |
|
157 |
this.addFunction(new TimeFunction()); |
|
158 |
this.addFunction(new TimestampFunction()); |
|
150 | 159 |
} |
151 | 160 |
|
152 |
private void addFunction(Function function) { |
|
153 |
if( function==null ) { |
|
154 |
throw new IllegalArgumentException("function can't be null"); |
|
155 |
} |
|
156 |
this.getFunctions().put(function.name().toUpperCase(), function); |
|
157 |
} |
|
158 |
|
|
159 | 161 |
private void addOperator(Function operator) { |
160 | 162 |
this.addFunction(operator); |
161 | 163 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpressionEvaluatorManager.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.Collection; |
4 | 4 |
import java.util.HashMap; |
5 |
import java.util.HashSet; |
|
5 | 6 |
import java.util.Map; |
7 |
import java.util.Set; |
|
6 | 8 |
import org.gvsig.expressionevaluator.Code; |
7 | 9 |
import org.gvsig.expressionevaluator.CodeBuilder; |
8 | 10 |
import org.gvsig.expressionevaluator.Compiler; |
... | ... | |
20 | 22 |
|
21 | 23 |
private Double accuracy; |
22 | 24 |
private final Map<String,SymbolTable>symbolTables; |
25 |
private final Set<String>autoloadSymbolTables; |
|
23 | 26 |
|
24 | 27 |
public DefaultExpressionEvaluatorManager() { |
25 | 28 |
this.symbolTables = new HashMap<>(); |
26 |
this.registerSymbolTable(new SQLSymbolTable()); |
|
27 |
this.registerSymbolTable(new OGCSymbolTable()); |
|
29 |
this.autoloadSymbolTables = new HashSet<>(); |
|
30 |
this.registerSymbolTable(new SQLSymbolTable(), true); |
|
31 |
this.registerSymbolTable(new OGCSymbolTable(), true); |
|
28 | 32 |
} |
29 | 33 |
|
30 | 34 |
@Override |
... | ... | |
38 | 42 |
} |
39 | 43 |
|
40 | 44 |
@Override |
41 |
public final void registerSymbolTable(SymbolTable symbolTable) { |
|
45 |
public final void registerSymbolTable(SymbolTable symbolTable, boolean autoload) {
|
|
42 | 46 |
this.symbolTables.put(symbolTable.getName().toUpperCase(),symbolTable); |
47 |
if( autoload ) { |
Also available in: Unified diff