Statistics
| Revision:

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
package org.gvsig.expressionevaluator.impl.function.programming;
2

    
3
import java.util.logging.Level;
4
import java.util.logging.Logger;
5
import javax.swing.SwingUtilities;
6
import org.apache.commons.lang3.Range;
7
import org.apache.commons.lang3.mutable.MutableObject;
8
import org.gvsig.expressionevaluator.Code;
9
import org.gvsig.expressionevaluator.Codes;
10
import org.gvsig.expressionevaluator.Function;
11
import org.gvsig.expressionevaluator.Interpreter;
12
import org.gvsig.expressionevaluator.impl.DefaultInterpreter;
13
import org.gvsig.expressionevaluator.spi.AbstractFunction;
14

    
15
public class SwingBlockFunction extends AbstractFunction {
16

    
17
        public static final String NAME = "SWING";
18

    
19
        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

    
31
        @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
}