Revision 44207 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/java/org/gvsig/expressionevaluator/swing/impl/AbstractAutomaticExpressionChecker.java
AbstractAutomaticExpressionChecker.java | ||
---|---|---|
17 | 17 |
import javax.swing.event.DocumentListener; |
18 | 18 |
import javax.swing.text.JTextComponent; |
19 | 19 |
import org.apache.commons.lang3.StringUtils; |
20 |
import org.apache.commons.lang3.mutable.Mutable; |
|
21 |
import org.apache.commons.lang3.mutable.MutableObject; |
|
22 |
import org.gvsig.expressionevaluator.Code; |
|
23 |
import org.gvsig.expressionevaluator.Code.Caller; |
|
24 |
import org.gvsig.expressionevaluator.Code.Identifier; |
|
20 | 25 |
import org.gvsig.expressionevaluator.Expression; |
21 | 26 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
22 | 27 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
23 | 28 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
24 | 29 |
import org.gvsig.expressionevaluator.ExpressionSyntaxException; |
30 |
import org.gvsig.expressionevaluator.Function; |
|
25 | 31 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
26 | 32 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
27 | 33 |
import org.gvsig.tools.ToolsLocator; |
34 |
import org.gvsig.tools.exception.BaseException; |
|
28 | 35 |
import org.gvsig.tools.i18n.I18nManager; |
29 | 36 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
30 | 37 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
31 | 38 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
32 | 39 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
33 | 40 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
41 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
42 |
import org.gvsig.tools.visitor.Visitor; |
|
34 | 43 |
|
35 | 44 |
/** |
36 | 45 |
* |
... | ... | |
173 | 182 |
this.setMessage(JOptionPane.ERROR_MESSAGE, "Syntax error in expression"); |
174 | 183 |
return; |
175 | 184 |
} |
176 |
expression.setSQLCompatible(this.config.isSQLCompatible()); |
|
185 |
final Mutable<String> theTip = new MutableObject<>(null); |
|
186 |
expression.setSQLCompatible(false); |
|
177 | 187 |
if (this.config.getPreviewSymbolTable() == null) { |
178 | 188 |
try { |
179 | 189 |
ExpressionEvaluatorManager theManager = ExpressionEvaluatorLocator.getManager(); |
... | ... | |
188 | 198 |
Object theValue = expression.execute(this.config.getPreviewSymbolTable()); |
189 | 199 |
this.setPreview(theValue); |
190 | 200 |
} catch (ExpressionRuntimeException ex) { |
191 |
this.setTip(ex.getTip());
|
|
201 |
theTip.setValue(ex.getTip());
|
|
192 | 202 |
this.setMessage(JOptionPane.ERROR_MESSAGE, "Runtime error. " + ex.getMessage()); |
193 | 203 |
} catch (Exception ex) { |
194 | 204 |
this.setMessage(JOptionPane.ERROR_MESSAGE, "Runtime error. " + ex.getMessage()); |
195 | 205 |
} |
196 | 206 |
} |
207 |
if( this.config.isSQLCompatible() ) { |
|
208 |
Code code = expression.getCode(); |
|
209 |
try { |
|
210 |
code.accept(new Visitor() { |
|
211 |
@Override |
|
212 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
213 |
Code code = (Code) obj; |
|
214 |
switch(code.code()) { |
|
215 |
case Code.CALLER: |
|
216 |
Function function = ((Caller)code).function(); |
|
217 |
if( function!=null && !function.isSQLCompatible() ) { |
|
218 |
theTip.setValue(I18N.Avoid_the_use_of_functions_not_compatible_with_SQL_in_this_data_source(function.name())); |
|
219 |
} |
|
220 |
break; |
|
221 |
case Code.IDENTIFIER: |
|
222 |
if( config.getPreviewSymbolTable()!=null && |
|
223 |
!config.getPreviewSymbolTable().isSQLCompatible(((Identifier)code).name()) ) { |
|
224 |
theTip.setValue(I18N.Avoid_the_use_of_functions_not_compatible_with_SQL_in_this_data_source(((Identifier)code).name())); |
|
225 |
} |
|
226 |
break; |
|
227 |
case Code.METHOD: |
|
228 |
theTip.setValue(I18N.Avoid_the_use_of_functions_not_compatible_with_SQL_in_this_data_source(((Caller)code).name())); |
|
229 |
break; |
|
230 |
} |
|
231 |
} |
|
232 |
}); |
|
233 |
} catch (BaseException ex) { |
|
234 |
} |
|
235 |
} |
|
236 |
if( !StringUtils.isBlank(theTip.getValue()) ) { |
|
237 |
this.setTip(theTip.getValue()); |
|
238 |
} |
|
197 | 239 |
} |
198 | 240 |
|
199 | 241 |
protected boolean isTipEnabled() { |
Also available in: Unified diff