svn-gvsig-desktop / 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 / function / programming / SwingBlockFunction.java @ 46068
History | View | Annotate | Download (1.99 KB)
1 | 44138 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.programming; |
---|---|---|---|
2 | 43512 | jjdelcerro | |
3 | 46068 | omartinez | import java.util.logging.Level; |
4 | import java.util.logging.Logger; |
||
5 | import javax.swing.SwingUtilities; |
||
6 | 43512 | jjdelcerro | import org.apache.commons.lang3.Range; |
7 | 46068 | omartinez | import org.apache.commons.lang3.mutable.MutableObject; |
8 | 43939 | jjdelcerro | import org.gvsig.expressionevaluator.Code; |
9 | 44138 | jjdelcerro | import org.gvsig.expressionevaluator.Codes; |
10 | 43939 | jjdelcerro | import org.gvsig.expressionevaluator.Function; |
11 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Interpreter; |
12 | 44138 | jjdelcerro | import org.gvsig.expressionevaluator.impl.DefaultInterpreter; |
13 | 43512 | jjdelcerro | import org.gvsig.expressionevaluator.spi.AbstractFunction; |
14 | |||
15 | 46068 | omartinez | public class SwingBlockFunction extends AbstractFunction { |
16 | 43512 | jjdelcerro | |
17 | 46068 | omartinez | public static final String NAME = "SWING"; |
18 | 43512 | jjdelcerro | |
19 | 46068 | omartinez | public SwingBlockFunction() {
|
20 | super(Function.GROUP_PROGRAMMING,
|
||
21 | NAME, |
||
22 | Range.between(1, Integer.MAX_VALUE), |
||
23 | "Evaluate each of the arguments sequentially.",
|
||
24 | "SWING({{sentence}}, sentence2, ...)",
|
||
25 | null,
|
||
26 | "Object",
|
||
27 | false
|
||
28 | ); |
||
29 | } |
||
30 | 43939 | jjdelcerro | |
31 | 46068 | omartinez | @Override
|
32 | public boolean isHidden() { |
||
33 | return true; |
||
34 | } |
||
35 | |||
36 | @Override
|
||
37 | public boolean useArgumentsInsteadObjects() { |
||
38 | return true; |
||
39 | } |
||
40 | |||
41 | @Override
|
||
42 | public boolean allowConstantFolding() { |
||
43 | return false; |
||
44 | } |
||
45 | |||
46 | @Override
|
||
47 | public Object call(Interpreter interpreter, Object[] args) throws Exception { |
||
48 | throw new UnsupportedOperationException("Not supported yet."); |
||
49 | } |
||
50 | |||
51 | @Override
|
||
52 | public Object call(Interpreter interpreter, final Codes args) throws Exception { |
||
53 | if (SwingUtilities.isEventDispatchThread()) { |
||
54 | Object value = null; |
||
55 | for (Code arg : args) {
|
||
56 | // LLamamos a runCode para que no atrape los returns.
|
||
57 | value = ((DefaultInterpreter) interpreter).runCode(arg); |
||
58 | } |
||
59 | return value;
|
||
60 | } else {
|
||
61 | MutableObject value = new MutableObject();
|
||
62 | SwingUtilities.invokeAndWait(new Runnable() { |
||
63 | @Override
|
||
64 | public void run() { |
||
65 | try {
|
||
66 | for (Code arg : args) {
|
||
67 | // LLamamos a runCode para que no atrape los returns.
|
||
68 | value.setValue(((DefaultInterpreter) interpreter).runCode(arg)); |
||
69 | } |
||
70 | } catch (Exception ex) { |
||
71 | } |
||
72 | } |
||
73 | }); |
||
74 | return value.getValue();
|
||
75 | } |
||
76 | } |
||
77 | |||
78 | 43512 | jjdelcerro | } |