Revision 44855
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestInterpreter.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expresionevaluator.impl; |
2 | 2 |
|
3 | 3 |
import junit.framework.TestCase; |
4 |
import org.apache.commons.lang3.StringUtils; |
|
5 |
import org.gvsig.expressionevaluator.AttributeHandler; |
|
4 | 6 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
5 | 7 |
import org.gvsig.expressionevaluator.Compiler; |
6 | 8 |
import org.gvsig.expressionevaluator.SymbolTable; |
... | ... | |
46 | 48 |
} |
47 | 49 |
|
48 | 50 |
|
49 |
protected SymbolTable createSymbolTable() { |
|
51 |
protected MutableSymbolTable createSymbolTable() {
|
|
50 | 52 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
51 | 53 |
MutableSymbolTable symbolTable = manager.createSymbolTable(); |
52 | 54 |
symbolTable.setVar("precio", 200); |
... | ... | |
512 | 514 |
assertEquals("dos", (String)v); |
513 | 515 |
} |
514 | 516 |
|
517 |
public void testGetattr1() { |
|
518 |
MutableSymbolTable symbolTable = createSymbolTable(); |
|
519 |
Compiler compiler = createCompiler(); |
|
520 |
Interpreter interpreter = createInterpreter(symbolTable); |
|
521 |
compiler.getLexicalAnalyzer().setUseBracketsForIdentifiers(false); |
|
522 |
|
|
523 |
symbolTable.setVar( |
|
524 |
"PARCELA", |
|
525 |
(AttributeHandler) (String key) -> StringUtils.equalsIgnoreCase(key, "MASA")? "100":null |
|
526 |
); |
|
527 |
String source = "PARCELA.MASA" ; |
|
528 |
|
|
529 |
Code code = compiler.compileExpression(source); |
|
530 |
assertEquals("GETATTR(\"PARCELA\", 'MASA')", code.toString()); |
|
531 |
|
|
532 |
Object v = interpreter.run(code); |
|
533 |
assertEquals("100", (String)v); |
|
534 |
} |
|
515 | 535 |
} |
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/operator/SubstOperator.java | ||
---|---|---|
25 | 25 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
26 | 26 |
int type = this.getType(op1, op2); |
27 | 27 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
28 |
double value = ((Number) op1).doubleValue() - ((Number) op2).doubleValue();
|
|
28 |
double value = getDouble(op1,1) - getDouble(op2,2);
|
|
29 | 29 |
return value; |
30 | 30 |
} |
31 | 31 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
32 |
double value = ((Number) op1).floatValue() - ((Number) op2).floatValue();
|
|
32 |
double value = getFloat(op1,1) - getFloat(op2,2);
|
|
33 | 33 |
return value; |
34 | 34 |
} |
35 | 35 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
36 |
long value = ((Number) op1).longValue() - ((Number) op2).longValue();
|
|
36 |
long value = getLong(op1,1) - getLong(op2,2);
|
|
37 | 37 |
return value; |
38 | 38 |
} |
39 | 39 |
if( (type & TYPE_INT) == TYPE_INT ) { |
40 |
int value = ((Number) op1).intValue() - ((Number) op2).intValue();
|
|
40 |
int value = getInt(op1,1) - getInt(op2,2);
|
|
41 | 41 |
return value; |
42 | 42 |
} |
43 | 43 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/NotOperator.java | ||
---|---|---|
22 | 22 |
if( ! (arg instanceof Boolean) ) { |
23 | 23 |
throw new IllegalArgumentException("NOT operator require a boolean"); |
24 | 24 |
} |
25 |
return !((Boolean)arg);
|
|
25 |
return !getBoolean(arg,1);
|
|
26 | 26 |
} |
27 | 27 |
|
28 | 28 |
} |
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/operator/LeOperator.java | ||
---|---|---|
21 | 21 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
22 | 22 |
int type = this.getType(op1, op2); |
23 | 23 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
24 |
boolean value = MathUtils.compareTo(
|
|
25 |
((Number) op1).doubleValue(),
|
|
26 |
((Number) op2).doubleValue(),
|
|
27 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
28 |
) <= 0; |
|
24 |
double accuracy = MathUtils.EPSILON;
|
|
25 |
if( interpreter.getAccuracy()!=null ) {
|
|
26 |
accuracy = interpreter.getAccuracy();
|
|
27 |
}
|
|
28 |
boolean value = MathUtils.compareTo(getDouble(op1, 1),getDouble(op2, 2),accuracy) <= 0;
|
|
29 | 29 |
return value; |
30 | 30 |
} |
31 | 31 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
32 |
boolean value = MathUtils.compareTo(
|
|
33 |
((Number) op1).floatValue(),
|
|
34 |
((Number) op2).floatValue(),
|
|
35 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
36 |
) <= 0; |
|
32 |
double accuracy = MathUtils.EPSILON;
|
|
33 |
if( interpreter.getAccuracy()!=null ) {
|
|
34 |
accuracy = interpreter.getAccuracy();
|
|
35 |
}
|
|
36 |
boolean value = MathUtils.compareTo(getFloat(op1, 1),getFloat(op2, 2),accuracy) <= 0;
|
|
37 | 37 |
return value; |
38 | 38 |
} |
39 | 39 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
40 |
boolean value = ((Number) op1).longValue() <= ((Number) op2).longValue();
|
|
40 |
boolean value = Long.compare(getLong(op1, 1),getLong(op2, 2)) <= 0;
|
|
41 | 41 |
return value; |
42 | 42 |
} |
43 | 43 |
if( (type & TYPE_INT) == TYPE_INT ) { |
44 |
boolean value = ((Number) op1).intValue() <= ((Number) op2).intValue();
|
|
44 |
boolean value = Integer.compare(getInt(op1, 1),getInt(op2, 2)) <= 0;
|
|
45 | 45 |
return value; |
46 |
}
|
|
46 |
} |
|
47 | 47 |
if( op2 instanceof Comparable && op2 instanceof Comparable ) { |
48 |
boolean value = ObjectUtils.compare((Comparable)op1,(Comparable)op2) <= 0;
|
|
48 |
boolean value = getComparable(op1,1).compareTo(getComparable(op2,2)) <= 0;
|
|
49 | 49 |
return value; |
50 | 50 |
} |
51 | 51 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/AndOperator.java | ||
---|---|---|
18 | 18 |
@Override |
19 | 19 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
20 | 20 |
if( op1 instanceof Boolean && op2 instanceof Boolean ) { |
21 |
boolean value = ((Boolean) op1) && ((Boolean) op2);
|
|
21 |
boolean value = getBoolean(op1,1) && getBoolean(op2,2);
|
|
22 | 22 |
return value; |
23 | 23 |
} |
24 | 24 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/NeOperator.java | ||
---|---|---|
27 | 27 |
} |
28 | 28 |
int type = this.getType(op1, op2); |
29 | 29 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
30 |
boolean value = MathUtils.compareTo(
|
|
31 |
((Number) op1).doubleValue(),
|
|
32 |
((Number) op2).doubleValue(),
|
|
33 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
34 |
) != 0; |
|
30 |
double accuracy = MathUtils.EPSILON;
|
|
31 |
if( interpreter.getAccuracy()!=null ) {
|
|
32 |
accuracy = interpreter.getAccuracy();
|
|
33 |
}
|
|
34 |
boolean value = MathUtils.compareTo(getDouble(op1, 1),getDouble(op2, 2),accuracy) != 0;
|
|
35 | 35 |
return value; |
36 | 36 |
} |
37 | 37 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
38 |
boolean value = MathUtils.compareTo(
|
|
39 |
((Number) op1).floatValue(),
|
|
40 |
((Number) op2).floatValue(),
|
|
41 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
42 |
) != 0; |
|
38 |
double accuracy = MathUtils.EPSILON;
|
|
39 |
if( interpreter.getAccuracy()!=null ) {
|
|
40 |
accuracy = interpreter.getAccuracy();
|
|
41 |
}
|
|
42 |
boolean value = MathUtils.compareTo(getFloat(op1, 1),getFloat(op2, 2),accuracy) != 0;
|
|
43 | 43 |
return value; |
44 | 44 |
} |
45 | 45 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
46 |
boolean value = Long.compare( |
|
47 |
((Number) op1).longValue(), |
|
48 |
((Number) op2).longValue() |
|
49 |
) != 0; |
|
46 |
boolean value = Long.compare(getLong(op1, 1),getLong(op2, 2)) != 0; |
|
50 | 47 |
return value; |
51 | 48 |
} |
52 | 49 |
if( (type & TYPE_INT) == TYPE_INT ) { |
53 |
boolean value = Integer.compare( |
|
54 |
((Number) op1).intValue(), |
|
55 |
((Number) op2).intValue() |
|
56 |
) != 0; |
|
50 |
boolean value = Integer.compare(getInt(op1, 1),getInt(op2, 2)) != 0; |
|
57 | 51 |
return value; |
58 | 52 |
} |
59 | 53 |
if( op2 instanceof Comparable && op2 instanceof Comparable ) { |
60 |
// boolean value = ObjectUtils.compare((Comparable)op1,(Comparable)op2) != 0; |
|
61 |
boolean value = ((Comparable)op1).compareTo((Comparable)op2) != 0; |
|
54 |
boolean value = getComparable(op1,1).compareTo(getComparable(op2,2)) != 0; |
|
62 | 55 |
return value; |
63 | 56 |
} |
64 | 57 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/EqOperator.java | ||
---|---|---|
26 | 26 |
} |
27 | 27 |
int type = this.getType(op1, op2); |
28 | 28 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
29 |
boolean value = MathUtils.compareTo(
|
|
30 |
((Number) op1).doubleValue(),
|
|
31 |
((Number) op2).doubleValue(),
|
|
32 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
33 |
) == 0; |
|
29 |
double accuracy = MathUtils.EPSILON;
|
|
30 |
if( interpreter.getAccuracy()!=null ) {
|
|
31 |
accuracy = interpreter.getAccuracy();
|
|
32 |
}
|
|
33 |
boolean value = MathUtils.compareTo(getDouble(op1, 1),getDouble(op2, 2),accuracy) == 0;
|
|
34 | 34 |
return value; |
35 | 35 |
} |
36 | 36 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
37 |
boolean value = MathUtils.compareTo(
|
|
38 |
((Number) op1).floatValue(),
|
|
39 |
((Number) op2).floatValue(),
|
|
40 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
41 |
) == 0; |
|
37 |
double accuracy = MathUtils.EPSILON;
|
|
38 |
if( interpreter.getAccuracy()!=null ) {
|
|
39 |
accuracy = interpreter.getAccuracy();
|
|
40 |
}
|
|
41 |
boolean value = MathUtils.compareTo(getFloat(op1, 1),getFloat(op2, 2),accuracy) == 0;
|
|
42 | 42 |
return value; |
43 | 43 |
} |
44 | 44 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
45 |
boolean value = Long.compare( |
|
46 |
((Number) op1).longValue(), |
|
47 |
((Number) op2).longValue() |
|
48 |
) == 0; |
|
45 |
boolean value = Long.compare(getLong(op1, 1),getLong(op2, 2)) == 0; |
|
49 | 46 |
return value; |
50 | 47 |
} |
51 | 48 |
if( (type & TYPE_INT) == TYPE_INT ) { |
52 |
boolean value = Integer.compare( |
|
53 |
((Number) op1).intValue(), |
|
54 |
((Number) op2).intValue() |
|
55 |
) == 0; |
|
49 |
boolean value = Integer.compare(getInt(op1, 1),getInt(op2, 2)) == 0; |
|
56 | 50 |
return value; |
57 | 51 |
} |
58 | 52 |
if( op2 instanceof Comparable && op2 instanceof Comparable ) { |
59 |
boolean value = ((Comparable)op1).compareTo((Comparable)op2) == 0;
|
|
53 |
boolean value = getComparable(op1,1).compareTo(getComparable(op2,2)) == 0;
|
|
60 | 54 |
return value; |
61 | 55 |
} |
62 | 56 |
throw new IllegalArgumentException("Types not allowed in '" + name() + "' operand."); |
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/operator/GtOperator.java | ||
---|---|---|
21 | 21 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
22 | 22 |
int type = this.getType(op1, op2); |
23 | 23 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
24 |
boolean value = MathUtils.compareTo(
|
|
25 |
((Number) op1).doubleValue(),
|
|
26 |
((Number) op2).doubleValue(),
|
|
27 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
28 |
) > 0; |
|
24 |
double accuracy = MathUtils.EPSILON;
|
|
25 |
if( interpreter.getAccuracy()!=null ) {
|
|
26 |
accuracy = interpreter.getAccuracy();
|
|
27 |
}
|
|
28 |
boolean value = MathUtils.compareTo(getDouble(op1, 1),getDouble(op2, 2),accuracy) > 0;
|
|
29 | 29 |
return value; |
30 | 30 |
} |
31 | 31 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
32 |
boolean value = MathUtils.compareTo(
|
|
33 |
((Number) op1).floatValue(),
|
|
34 |
((Number) op2).floatValue(),
|
|
35 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
36 |
) > 0; |
|
32 |
double accuracy = MathUtils.EPSILON;
|
|
33 |
if( interpreter.getAccuracy()!=null ) {
|
|
34 |
accuracy = interpreter.getAccuracy();
|
|
35 |
}
|
|
36 |
boolean value = MathUtils.compareTo(getFloat(op1, 1),getFloat(op2, 2),accuracy) > 0;
|
|
37 | 37 |
return value; |
38 | 38 |
} |
39 | 39 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
40 |
boolean value = ((Number) op1).longValue() > ((Number) op2).longValue();
|
|
40 |
boolean value = Long.compare(getLong(op1, 1),getLong(op2, 2)) > 0;
|
|
41 | 41 |
return value; |
42 | 42 |
} |
43 | 43 |
if( (type & TYPE_INT) == TYPE_INT ) { |
44 |
boolean value = ((Number) op1).intValue() > ((Number) op2).intValue();
|
|
44 |
boolean value = Integer.compare(getInt(op1, 1),getInt(op2, 2)) > 0;
|
|
45 | 45 |
return value; |
46 |
}
|
|
46 |
} |
|
47 | 47 |
if( op2 instanceof Comparable && op2 instanceof Comparable ) { |
48 |
boolean value = ObjectUtils.compare((Comparable)op1,(Comparable)op2) > 0;
|
|
48 |
boolean value = getComparable(op1,1).compareTo(getComparable(op2,2)) > 0;
|
|
49 | 49 |
return value; |
50 | 50 |
} |
51 | 51 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/ModOperator.java | ||
---|---|---|
19 | 19 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
20 | 20 |
int type = this.getType(op1, op2); |
21 | 21 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
22 |
double value = ((Number) op1).doubleValue() % ((Number) op2).doubleValue();
|
|
22 |
double value = getDouble(op1,1) % getDouble(op2,2);
|
|
23 | 23 |
return value; |
24 | 24 |
} |
25 | 25 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
26 |
double value = ((Number) op1).floatValue() % ((Number) op2).floatValue();
|
|
26 |
double value = getFloat(op1,1) % getFloat(op2,2);
|
|
27 | 27 |
return value; |
28 | 28 |
} |
29 | 29 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
30 |
long value = ((Number) op1).longValue() % ((Number) op2).longValue();
|
|
30 |
long value = getLong(op1,1) % getLong(op2,2);
|
|
31 | 31 |
return value; |
32 | 32 |
} |
33 | 33 |
if( (type & TYPE_INT) == TYPE_INT ) { |
34 |
int value = ((Number) op1).intValue() % ((Number) op2).intValue();
|
|
34 |
int value = getInt(op1,1) % getInt(op2,2);
|
|
35 | 35 |
return value; |
36 | 36 |
} |
37 | 37 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/LtOperator.java | ||
---|---|---|
21 | 21 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
22 | 22 |
int type = this.getType(op1, op2); |
23 | 23 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
24 |
boolean value = MathUtils.compareTo(
|
|
25 |
((Number) op1).doubleValue(),
|
|
26 |
((Number) op2).doubleValue(),
|
|
27 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
28 |
) < 0; |
|
24 |
double accuracy = MathUtils.EPSILON;
|
|
25 |
if( interpreter.getAccuracy()!=null ) {
|
|
26 |
accuracy = interpreter.getAccuracy();
|
|
27 |
}
|
|
28 |
boolean value = MathUtils.compareTo(getDouble(op1, 1),getDouble(op2, 2),accuracy) < 0;
|
|
29 | 29 |
return value; |
30 | 30 |
} |
31 | 31 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
32 |
boolean value = MathUtils.compareTo(
|
|
33 |
((Number) op1).floatValue(),
|
|
34 |
((Number) op2).floatValue(),
|
|
35 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
36 |
) < 0; |
|
32 |
double accuracy = MathUtils.EPSILON;
|
|
33 |
if( interpreter.getAccuracy()!=null ) {
|
|
34 |
accuracy = interpreter.getAccuracy();
|
|
35 |
}
|
|
36 |
boolean value = MathUtils.compareTo(getFloat(op1, 1),getFloat(op2, 2),accuracy) < 0;
|
|
37 | 37 |
return value; |
38 | 38 |
} |
39 | 39 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
40 |
boolean value = ((Number) op1).longValue() < ((Number) op2).longValue();
|
|
40 |
boolean value = Long.compare(getLong(op1, 1),getLong(op2, 2)) < 0;
|
|
41 | 41 |
return value; |
42 | 42 |
} |
43 | 43 |
if( (type & TYPE_INT) == TYPE_INT ) { |
44 |
boolean value = ((Number) op1).intValue() < ((Number) op2).intValue();
|
|
44 |
boolean value = Integer.compare(getInt(op1, 1),getInt(op2, 2)) < 0;
|
|
45 | 45 |
return value; |
46 |
}
|
|
46 |
} |
|
47 | 47 |
if( op2 instanceof Comparable && op2 instanceof Comparable ) { |
48 |
boolean value = ObjectUtils.compare((Comparable)op1,(Comparable)op2) < 0;
|
|
48 |
boolean value = getComparable(op1,1).compareTo(getComparable(op2,2)) < 0;
|
|
49 | 49 |
return value; |
50 | 50 |
} |
51 | 51 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/OrOperator.java | ||
---|---|---|
18 | 18 |
@Override |
19 | 19 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
20 | 20 |
if( op1 instanceof Boolean && op2 instanceof Boolean ) { |
21 |
boolean value = ((Boolean) op1) || ((Boolean) op2);
|
|
21 |
boolean value = getBoolean(op1,1) || getBoolean(op2,2);
|
|
22 | 22 |
return value; |
23 | 23 |
} |
24 | 24 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/DivOperator.java | ||
---|---|---|
24 | 24 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
25 | 25 |
int type = this.getType(op1, op2); |
26 | 26 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
27 |
double value = ((Number) op1).doubleValue() / ((Number) op2).doubleValue();
|
|
27 |
double value = getDouble(op1,1) / getDouble(op2,2);
|
|
28 | 28 |
return value; |
29 | 29 |
} |
30 | 30 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
31 |
double value = ((Number) op1).floatValue() / ((Number) op2).floatValue();
|
|
31 |
double value = getFloat(op1,1) / getFloat(op2,2);
|
|
32 | 32 |
return value; |
33 | 33 |
} |
34 | 34 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
35 |
long value = ((Number) op1).longValue() / ((Number) op2).longValue();
|
|
35 |
long value = getLong(op1,1) / getLong(op2,2);
|
|
36 | 36 |
return value; |
37 | 37 |
} |
38 | 38 |
if( (type & TYPE_INT) == TYPE_INT ) { |
39 |
int value = ((Number) op1).intValue() / ((Number) op2).intValue();
|
|
39 |
int value = getInt(op1,1) / getInt(op2,2);
|
|
40 | 40 |
return value; |
41 | 41 |
} |
42 | 42 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/AddOperator.java | ||
---|---|---|
3 | 3 |
import java.util.Objects; |
4 | 4 |
import org.gvsig.expressionevaluator.Code; |
5 | 5 |
import org.gvsig.expressionevaluator.Code.Constant; |
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
7 | 6 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_ADD; |
8 | 7 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
9 | 8 |
import org.gvsig.expressionevaluator.Function; |
... | ... | |
32 | 31 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
33 | 32 |
int type = this.getType(op1, op2); |
34 | 33 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
35 |
double value = ((Number) op1).doubleValue() + ((Number) op2).doubleValue();
|
|
34 |
double value = getDouble(op1,1) + getDouble(op2,2);
|
|
36 | 35 |
return value; |
37 | 36 |
} |
38 | 37 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
39 |
double value = ((Number) op1).floatValue() + ((Number) op2).floatValue();
|
|
38 |
double value = getFloat(op1,1) + getFloat(op2,2);
|
|
40 | 39 |
return value; |
41 | 40 |
} |
42 | 41 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
43 |
long value = ((Number) op1).longValue() + ((Number) op2).longValue();
|
|
42 |
long value = getLong(op1,1) + getLong(op2,2);
|
|
44 | 43 |
return value; |
45 | 44 |
} |
46 | 45 |
if( (type & TYPE_INT) == TYPE_INT ) { |
47 |
int value = ((Number) op1).intValue()+ ((Number) op2).intValue();
|
|
46 |
int value = getInt(op1,1) + getInt(op2,2);
|
|
48 | 47 |
return value; |
49 | 48 |
} |
50 | 49 |
if( (type & TYPE_STRING) == TYPE_STRING ) { |
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/operator/GeOperator.java | ||
---|---|---|
21 | 21 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
22 | 22 |
int type = this.getType(op1, op2); |
23 | 23 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
24 |
boolean value = MathUtils.compareTo(
|
|
25 |
((Number) op1).doubleValue(),
|
|
26 |
((Number) op2).doubleValue(),
|
|
27 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
28 |
) >= 0; |
|
24 |
double accuracy = MathUtils.EPSILON;
|
|
25 |
if( interpreter.getAccuracy()!=null ) {
|
|
26 |
accuracy = interpreter.getAccuracy();
|
|
27 |
}
|
|
28 |
boolean value = MathUtils.compareTo(getDouble(op2, 1),getDouble(op2, 2),accuracy) >= 0;
|
|
29 | 29 |
return value; |
30 | 30 |
} |
31 | 31 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
32 |
boolean value = MathUtils.compareTo(
|
|
33 |
((Number) op1).floatValue(),
|
|
34 |
((Number) op2).floatValue(),
|
|
35 |
interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
|
36 |
) >= 0; |
|
32 |
double accuracy = MathUtils.EPSILON;
|
|
33 |
if( interpreter.getAccuracy()!=null ) {
|
|
34 |
accuracy = interpreter.getAccuracy();
|
|
35 |
}
|
|
36 |
boolean value = MathUtils.compareTo(getFloat(op1, 1),getFloat(op2, 2),accuracy) >= 0;
|
|
37 | 37 |
return value; |
38 | 38 |
} |
39 | 39 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
40 |
boolean value = ((Number) op1).longValue() >= ((Number) op2).longValue();
|
|
40 |
boolean value = Long.compare(getLong(op1, 1),getLong(op2, 2)) >= 0;
|
|
41 | 41 |
return value; |
42 | 42 |
} |
43 | 43 |
if( (type & TYPE_INT) == TYPE_INT ) { |
44 |
boolean value = ((Number) op1).intValue() >= ((Number) op2).intValue();
|
|
44 |
boolean value = Integer.compare(getInt(op1, 1),getInt(op2, 2)) >= 0;
|
|
45 | 45 |
return value; |
46 |
}
|
|
46 |
} |
|
47 | 47 |
if( op2 instanceof Comparable && op2 instanceof Comparable ) { |
48 |
boolean value = ObjectUtils.compare((Comparable)op1,(Comparable)op2) >= 0;
|
|
48 |
boolean value = getComparable(op1,1).compareTo(getComparable(op2,2)) >= 0;
|
|
49 | 49 |
return value; |
50 | 50 |
} |
51 | 51 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/operator/MulOperator.java | ||
---|---|---|
24 | 24 |
public Object call(Interpreter interpreter, Object op1, Object op2) { |
25 | 25 |
int type = this.getType(op1, op2); |
26 | 26 |
if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) { |
27 |
double value = ((Number) op1).doubleValue() * ((Number) op2).doubleValue();
|
|
27 |
double value = getDouble(op1,1) * getDouble(op2,2);
|
|
28 | 28 |
return value; |
29 | 29 |
} |
30 | 30 |
if( (type & TYPE_FLOAT) == TYPE_FLOAT ) { |
31 |
double value = ((Number) op1).floatValue() * ((Number) op2).floatValue();
|
|
31 |
double value = getFloat(op1,1) * getFloat(op2,2);
|
|
32 | 32 |
return value; |
33 | 33 |
} |
34 | 34 |
if( (type & TYPE_LONG) == TYPE_LONG ) { |
35 |
long value = ((Number) op1).longValue() * ((Number) op2).longValue();
|
|
35 |
long value = getLong(op1,1) * getLong(op2,2);
|
|
36 | 36 |
return value; |
37 | 37 |
} |
38 | 38 |
if( (type & TYPE_INT) == TYPE_INT ) { |
39 |
int value = ((Number) op1).intValue() * ((Number) op2).intValue();
|
|
39 |
int value = getInt(op1,1) * getInt(op2,2);
|
|
40 | 40 |
return value; |
41 | 41 |
} |
42 | 42 |
throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
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/GetattrFunction.java | ||
---|---|---|
8 | 8 |
import org.gvsig.expressionevaluator.Interpreter; |
9 | 9 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 | 10 |
import org.gvsig.tools.dynobject.DynObject; |
11 |
import org.gvsig.tools.util.GetItemByKey; |
|
11 | 12 |
|
12 | 13 |
public class GetattrFunction extends AbstractFunction { |
13 | 14 |
|
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/DefaultExpressionBuilder.java | ||
---|---|---|
769 | 769 |
public Variable column(String name) { |
770 | 770 |
return new VariableBase(this, name); |
771 | 771 |
} |
772 |
|
|
772 |
|
|
773 | 773 |
@Override |
774 |
public Value column(String tableName, String columnName) { |
|
775 |
return getattr(tableName,columnName); |
|
776 |
} |
|
777 |
|
|
778 |
@Override |
|
774 | 779 |
public Parameter parameter(String name) { |
775 | 780 |
List<Parameter> parameters = this.parameters(); |
776 | 781 |
for (Parameter parameter : parameters) { |
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/DefaultCodeBuilder.java | ||
---|---|---|
818 | 818 |
public Code getattr(Code obj, String attrname) { |
819 | 819 |
BaseCodes args = args(); |
820 | 820 |
args.add(obj); |
821 |
args.add(identifier(attrname));
|
|
821 |
args.add(constant(attrname));
|
|
822 | 822 |
return function(ExpressionBuilder.FUNCTION_GETATTR, args); |
823 | 823 |
} |
824 | 824 |
|
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/AbstractFunction.java | ||
---|---|---|
159 | 159 |
if( args.length < n ) { |
160 | 160 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
161 | 161 |
} |
162 |
Object value = args[n]; |
|
162 |
return getInt(args[n],n); |
|
163 |
} |
|
164 |
|
|
165 |
protected int getInt(Object value, int n) { |
|
163 | 166 |
if( value == null ) { |
164 | 167 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
165 | 168 |
} |
... | ... | |
177 | 180 |
if( args.length < n ) { |
178 | 181 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
179 | 182 |
} |
180 |
Object value = args[n]; |
|
183 |
return getLong(args[n],n); |
|
184 |
} |
|
185 |
|
|
186 |
protected long getLong(Object value, int n) { |
|
181 | 187 |
if( value == null ) { |
182 | 188 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
183 | 189 |
} |
... | ... | |
195 | 201 |
if( args.length < n ) { |
196 | 202 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
197 | 203 |
} |
198 |
Object value = args[n]; |
|
204 |
return getDouble(args[n],n); |
|
205 |
} |
|
206 |
|
|
207 |
protected double getDouble(Object value, int arg) { |
|
199 | 208 |
if( value == null ) { |
200 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n));
|
|
209 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), arg));
|
|
201 | 210 |
} |
202 | 211 |
if( !(value instanceof Number) ) { |
203 | 212 |
String type = value.getClass().getCanonicalName(); |
204 | 213 |
throw new IllegalArgumentException( |
205 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " +
|
|
214 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), arg) + " " +
|
|
206 | 215 |
I18N.Expected_XexpectedX_and_found_XfoundX("Number",type) |
207 | 216 |
); |
208 | 217 |
} |
209 | 218 |
return ((Number)value).doubleValue(); |
210 | 219 |
} |
211 | 220 |
|
221 |
protected float getFloat(Object args[], int n) { |
|
222 |
if( args.length < n ) { |
|
223 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
|
224 |
} |
|
225 |
return getFloat(args[n],n); |
|
226 |
} |
|
227 |
|
|
228 |
protected float getFloat(Object value, int arg) { |
|
229 |
if( value == null ) { |
|
230 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), arg)); |
|
231 |
} |
|
232 |
if( !(value instanceof Number) ) { |
|
233 |
String type = value.getClass().getCanonicalName(); |
|
234 |
throw new IllegalArgumentException( |
|
235 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), arg) + " " + |
|
236 |
I18N.Expected_XexpectedX_and_found_XfoundX("Number",type) |
|
237 |
); |
|
238 |
} |
|
239 |
return ((Number)value).floatValue(); |
|
240 |
} |
|
241 |
|
|
212 | 242 |
protected String getStr(Object args[], int n) { |
213 | 243 |
if( args.length < n ) { |
214 | 244 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
215 | 245 |
} |
216 |
return Objects.toString(args[n], "");
|
|
246 |
return getStr(args[n],n);
|
|
217 | 247 |
} |
218 | 248 |
|
249 |
protected String getStr(Object value, int n) { |
|
250 |
return Objects.toString(value, ""); |
|
251 |
} |
|
252 |
|
|
219 | 253 |
protected File getFile(Object args[], int n) { |
220 | 254 |
if( args.length < n ) { |
221 | 255 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
222 | 256 |
} |
223 |
Object arg = args[n]; |
|
224 |
if( arg == null ) { |
|
257 |
return getFile(args[n],n); |
|
258 |
} |
|
259 |
|
|
260 |
protected File getFile(Object value, int n) { |
|
261 |
if( value == null ) { |
|
225 | 262 |
return null; |
226 | 263 |
} |
227 |
if( arg instanceof File ) {
|
|
228 |
return (File)arg;
|
|
264 |
if( value instanceof File ) {
|
|
265 |
return (File)value;
|
|
229 | 266 |
} |
230 |
if( arg instanceof URL ) {
|
|
267 |
if( value instanceof URL ) {
|
|
231 | 268 |
try { |
232 |
return new File(((URL)arg).toURI());
|
|
269 |
return new File(((URL)value).toURI());
|
|
233 | 270 |
} catch (URISyntaxException ex) { |
234 | 271 |
return null; |
235 | 272 |
} |
236 | 273 |
} |
237 |
if( arg instanceof URI ) {
|
|
238 |
return new File(((URI)arg));
|
|
274 |
if( value instanceof URI ) {
|
|
275 |
return new File(((URI)value));
|
|
239 | 276 |
} |
240 |
String s = Objects.toString(arg, null);
|
|
277 |
String s = Objects.toString(value, null);
|
|
241 | 278 |
if( s == null ) { |
242 | 279 |
return null; |
243 | 280 |
} |
... | ... | |
264 | 301 |
return value; |
265 | 302 |
} |
266 | 303 |
|
267 |
protected Date getDate(Object[] args, int n) {
|
|
304 |
protected Comparable getComparable(Object[] args, int n) {
|
|
268 | 305 |
if( args.length < n ) { |
269 | 306 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
270 | 307 |
} |
271 |
Object value = args[n]; |
|
308 |
return getComparable(args[n],n); |
|
309 |
} |
|
310 |
|
|
311 |
protected Comparable getComparable(Object value, int n) { |
|
272 | 312 |
if( value == null ) { |
273 | 313 |
return null; |
274 | 314 |
} |
315 |
if( !(value instanceof Comparable) ) { |
|
316 |
String type = value.getClass().getCanonicalName(); |
|
317 |
throw new IllegalArgumentException( |
|
318 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
319 |
I18N.Expected_XexpectedX_and_found_XfoundX("Comparable",type) |
|
320 |
); |
|
321 |
} |
|
322 |
return (Comparable)value; |
|
323 |
} |
|
324 |
|
|
325 |
protected Comparable getDate(Object[] args, int n) { |
|
326 |
if( args.length < n ) { |
|
327 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
|
328 |
} |
|
329 |
return getDate(args[n],n); |
|
330 |
} |
|
331 |
|
|
332 |
protected Date getDate(Object value, int n) { |
|
333 |
if( value == null ) { |
|
334 |
return null; |
|
335 |
} |
|
275 | 336 |
if( !(value instanceof Date) ) { |
276 | 337 |
String type = value.getClass().getCanonicalName(); |
277 | 338 |
throw new IllegalArgumentException( |
... | ... | |
286 | 347 |
if( args.length < n ) { |
287 | 348 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
288 | 349 |
} |
289 |
Object value = args[n]; |
|
350 |
return getLocalDateTime(args[n],n); |
|
351 |
} |
|
352 |
|
|
353 |
protected LocalDateTime getLocalDateTime(Object value, int n) { |
|
290 | 354 |
if( value == null ) { |
291 | 355 |
return null; |
292 | 356 |
} |
... | ... | |
311 | 375 |
if( args.length < n ) { |
312 | 376 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
313 | 377 |
} |
314 |
Object value = args[n]; |
|
378 |
return getBoolean(args[n], n, accuracy); |
|
379 |
} |
|
380 |
|
|
381 |
protected boolean getBoolean(Object value, int n) { |
|
382 |
return getBoolean(value, n, MathUtils.EPSILON); |
|
383 |
} |
|
384 |
|
|
385 |
protected boolean getBoolean(Object value, int n, Double accuracy) { |
|
315 | 386 |
return toBoolean(value, accuracy); |
316 | 387 |
} |
317 | 388 |
|
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/ExpressionBuilder.java | ||
---|---|---|
288 | 288 |
|
289 | 289 |
public Variable column(String name); // Alias for variable(name) |
290 | 290 |
|
291 |
public Value column(String tableName, String columnName); |
|
292 |
|
|
291 | 293 |
public Parameter parameter(String name); |
292 | 294 |
|
293 | 295 |
public Parameter parameter(); |
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 | ||
---|---|---|
6 | 6 |
import java.awt.event.ActionListener; |
7 | 7 |
import java.awt.event.KeyAdapter; |
8 | 8 |
import java.awt.event.KeyEvent; |
9 |
import java.util.Collection; |
|
9 | 10 |
import java.util.Objects; |
11 |
import javax.swing.Action; |
|
12 |
import javax.swing.JComponent; |
|
10 | 13 |
import javax.swing.JEditorPane; |
11 | 14 |
import javax.swing.JMenuItem; |
12 | 15 |
import javax.swing.JOptionPane; |
... | ... | |
19 | 22 |
import org.apache.commons.lang3.StringUtils; |
20 | 23 |
import org.apache.commons.lang3.mutable.Mutable; |
21 | 24 |
import org.apache.commons.lang3.mutable.MutableObject; |
25 |
import org.gvsig.configurableactions.ConfigurableActionsMamager; |
|
22 | 26 |
import org.gvsig.expressionevaluator.Code; |
23 | 27 |
import org.gvsig.expressionevaluator.Code.Identifier; |
24 | 28 |
import org.gvsig.expressionevaluator.Expression; |
... | ... | |
40 | 44 |
import org.gvsig.tools.visitor.VisitCanceledException; |
41 | 45 |
import org.gvsig.tools.visitor.Visitor; |
42 | 46 |
import org.gvsig.expressionevaluator.Code.Callable; |
47 |
import static org.gvsig.expressionevaluator.swing.JExpressionBuilder.CONFIGURABLE_PANEL_ID; |
|
48 |
import org.gvsig.tools.util.ToolsUtilLocator; |
|
43 | 49 |
|
44 | 50 |
/** |
45 | 51 |
* |
... | ... | |
49 | 55 |
public abstract class AbstractAutomaticExpressionChecker { |
50 | 56 |
|
51 | 57 |
private static final Color COLOR_ERROR = new Color(255,225,232); |
58 |
private static final Color COLOR_SUGGESTION = new Color(255,255,159); |
|
52 | 59 |
|
53 | 60 |
private final JTextComponent text; |
54 | 61 |
private final ExpressionBuilderConfig builderConfig; |
... | ... | |
85 | 92 |
JPopupMenu popupMenu = this.text.getComponentPopupMenu(); |
86 | 93 |
|
87 | 94 |
this.menuItemShowTip = new JMenuItem(i18n.getTranslation("_Show_tip")); |
88 |
this.menuItemShowTip.addActionListener(new ActionListener() { |
|
89 |
@Override |
|
90 |
public void actionPerformed(ActionEvent e) { |
|
91 |
if( StringUtils.isBlank(tip) ) { |
|
92 |
return; |
|
93 |
} |
|
94 |
JOptionPane.showMessageDialog( |
|
95 |
text.getParent(), |
|
96 |
tip, |
|
97 |
i18n.getTranslation("Tip"), |
|
98 |
JOptionPane.INFORMATION_MESSAGE |
|
99 |
); |
|
100 |
} |
|
95 |
this.menuItemShowTip.addActionListener((ActionEvent e) -> { |
|
96 |
if( StringUtils.isBlank(tip) ) { |
|
97 |
return; |
|
98 |
} |
|
99 |
JOptionPane.showMessageDialog( |
|
100 |
text.getParent(), |
|
101 |
toHTML(tip), |
|
102 |
i18n.getTranslation("Tip"), |
|
103 |
JOptionPane.INFORMATION_MESSAGE |
|
104 |
); |
|
101 | 105 |
}); |
102 | 106 |
popupMenu.add(this.menuItemShowTip); |
103 | 107 |
|
104 | 108 |
this.menuItemShowPreview = new JMenuItem(i18n.getTranslation("_Show_preview")); |
105 |
this.menuItemShowPreview.addActionListener(new ActionListener() { |
|
106 |
@Override |
|
107 |
public void actionPerformed(ActionEvent e) { |
|
108 |
showMessageDialog( |
|
109 |
i18n.getTranslation("_Preview_value"), |
|
110 |
preview |
|
111 |
); |
|
112 |
} |
|
109 |
this.menuItemShowPreview.addActionListener((ActionEvent e) -> { |
|
110 |
showMessageDialog(i18n.getTranslation("_Preview_value"),preview); |
|
113 | 111 |
}); |
114 | 112 |
popupMenu.add(this.menuItemShowPreview); |
115 | 113 |
|
116 | 114 |
this.menuItemShowMessage = new JMenuItem(i18n.getTranslation("_Show_message")); |
117 |
this.menuItemShowMessage.addActionListener(new ActionListener() { |
|
118 |
@Override |
|
119 |
public void actionPerformed(ActionEvent e) { |
|
120 |
showMessageDialog( |
|
121 |
i18n.getTranslation("_Message"), |
|
122 |
message |
|
123 |
); |
|
124 |
} |
|
115 |
this.menuItemShowMessage.addActionListener((ActionEvent e) -> { |
|
116 |
showMessageDialog(i18n.getTranslation("_Message"),message+"\n\n"+tip); |
|
125 | 117 |
}); |
126 | 118 |
popupMenu.add(this.menuItemShowMessage); |
119 |
|
|
120 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
|
121 |
Collection<Action> actions = cfgActionsManager.getConfigurableActions(CONFIGURABLE_PANEL_ID); |
|
122 |
if( !actions.isEmpty() ) { |
|
123 |
popupMenu.addSeparator(); |
|
124 |
for( Action action : actions) { |
|
125 |
JMenuItem item = new JMenuItem(action); |
|
126 |
item.addActionListener((ActionEvent e) -> { |
|
127 |
e.setSource(this); |
|
128 |
action.actionPerformed(e); |
|
129 |
}); |
|
130 |
popupMenu.add(item); |
|
131 |
} |
|
132 |
} |
|
127 | 133 |
|
128 |
this.timelistener = new ActionListener() { |
|
129 |
@Override |
|
130 |
public void actionPerformed(ActionEvent e) { |
|
131 |
doCheckExpression(); |
|
132 |
} |
|
134 |
this.timelistener = (ActionEvent e) -> { |
|
135 |
doCheckExpression(); |
|
133 | 136 |
}; |
134 | 137 |
this.doclistener = new DocumentListener() { |
135 | 138 |
@Override |
... | ... | |
233 | 236 |
} catch (BaseException ex) { |
234 | 237 |
} |
235 | 238 |
} |
239 |
String suggestion = this.getSuggestion(); |
|
240 |
if( suggestion!=null ) { |
|
241 |
if( StringUtils.isBlank(theTip.getValue()) ) { |
|
242 |
theTip.setValue(suggestion); |
|
243 |
} else { |
|
244 |
theTip.setValue(suggestion+"\n\n"+theTip.getValue()); |
|
245 |
} |
|
246 |
} |
|
236 | 247 |
if( !StringUtils.isBlank(theTip.getValue()) ) { |
237 | 248 |
this.setTip(theTip.getValue()); |
249 |
if( this.text.getBackground()==this.color_ok ) { |
|
250 |
this.text.setBackground(COLOR_SUGGESTION); |
|
251 |
} |
|
252 |
// this.setMessage(JOptionPane.INFORMATION_MESSAGE, theTip.getValue()); |
|
238 | 253 |
} |
239 | 254 |
} |
240 | 255 |
|
... | ... | |
286 | 301 |
scroll.setPreferredSize(new Dimension(500, 300)); |
287 | 302 |
toolsSwingManager.setDefaultPopupMenu(textMessage); |
288 | 303 |
textMessage.setContentType("text/html"); |
289 |
textMessage.setText("<html>"+msg+"</html>");
|
|
304 |
textMessage.setText(toHTML(msg));
|
|
290 | 305 |
textMessage.setCaretPosition(0); |
291 | 306 |
WindowManager_v2 winmgr = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
292 | 307 |
Dialog dialog = winmgr.createDialog( |
... | ... | |
301 | 316 |
protected void setPreview(Object value) { |
302 | 317 |
this.preview = Objects.toString(value, null); |
303 | 318 |
this.text.setToolTipText( |
304 |
"<html>" + |
|
305 |
StringUtils.abbreviate(Objects.toString(this.preview,""),100) + |
|
306 |
"</html>" |
|
319 |
toHTML(StringUtils.abbreviate(Objects.toString(this.preview,""),100)) |
|
307 | 320 |
); |
308 | 321 |
this.menuItemShowPreview.setEnabled(this.isPreviewEnabled()); |
309 | 322 |
this.text.setBackground(color_ok); |
310 | 323 |
} |
311 | 324 |
|
312 | 325 |
protected void setMessage(int mode, String text) { |
313 |
this.message = text; |
|
314 | 326 |
if( StringUtils.isBlank(text) ) { |
327 |
this.message = ""; |
|
315 | 328 |
this.text.setToolTipText(""); |
316 | 329 |
this.menuItemShowMessage.setEnabled(false); |
317 |
} else {
|
|
318 |
this.text.setToolTipText(
|
|
319 |
"<html>" +
|
|
320 |
StringUtils.abbreviate(Objects.toString(text,""),100) +
|
|
321 |
"</html>"
|
|
322 |
);
|
|
323 |
this.menuItemShowMessage.setEnabled(true);
|
|
324 |
}
|
|
330 |
this.text.setBackground(color_ok);
|
|
331 |
return;
|
|
332 |
}
|
|
333 |
this.message = text;
|
|
334 |
this.text.setToolTipText(
|
|
335 |
toHTML(StringUtils.abbreviate(Objects.toString(text,""),100))
|
|
336 |
); |
|
337 |
this.menuItemShowMessage.setEnabled(true);
|
|
325 | 338 |
switch (mode) { |
326 | 339 |
case JOptionPane.INFORMATION_MESSAGE: |
327 |
this.text.setBackground(color_ok);
|
|
340 |
this.text.setBackground(COLOR_SUGGESTION);
|
|
328 | 341 |
break; |
329 | 342 |
case JOptionPane.WARNING_MESSAGE: |
330 | 343 |
case JOptionPane.ERROR_MESSAGE: |
... | ... | |
340 | 353 |
} |
341 | 354 |
|
342 | 355 |
protected abstract Expression getExpression(); |
356 |
|
|
357 |
protected abstract String getSuggestion(); |
|
358 |
|
|
359 |
protected String toHTML(String s) { |
|
360 |
s = StringUtils.replace(s, "<html>", ""); |
|
361 |
s = StringUtils.replace(s, "</html>", ""); |
|
362 |
s = StringUtils.replace(s, "\n", "<br>"); |
|
363 |
s = "<html>"+s+"</html>"; |
|
364 |
return s; |
|
365 |
} |
|
343 | 366 |
} |
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/DefaultExpressionBuilderConfig.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.swing.impl; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
3 | 4 |
import java.util.Collection; |
4 | 5 |
import java.util.Collections; |
5 | 6 |
import java.util.HashMap; |
6 | 7 |
import java.util.List; |
7 | 8 |
import java.util.Map; |
9 |
import org.apache.commons.lang3.StringUtils; |
|
10 |
import org.gvsig.expressionevaluator.Expression; |
|
8 | 11 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
9 | 12 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
10 | 13 |
import org.gvsig.expressionevaluator.Function; |
... | ... | |
14 | 17 |
import org.gvsig.expressionevaluator.swing.ElementFactory; |
15 | 18 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
16 | 19 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
20 |
import org.gvsig.expressionevaluator.swing.SuggestionProvider; |
|
17 | 21 |
import org.gvsig.tools.dataTypes.DataType; |
22 |
import org.gvsig.tools.util.Factory; |
|
18 | 23 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
19 | 24 |
|
20 | 25 |
/** |
... | ... | |
26 | 31 |
|
27 | 32 |
private List<Element> elements; |
28 | 33 |
private int limit; |
29 |
private HashMap<String, SymbolTable> symbolTables;
|
|
34 |
private Map<String, SymbolTable> symbolTables; |
|
30 | 35 |
private final ExpressionEvaluatorSwingManager manager; |
31 |
private boolean scriptsEnabled = true; |
|
32 | 36 |
private SymbolTable previewSymbolTable; |
33 | 37 |
private boolean SQLCompatible; |
34 | 38 |
private final PropertiesSupportHelper propertiesSupportHelper; |
35 | 39 |
private boolean showLabelsOfAttributes; |
36 | 40 |
private boolean allowAggregates; |
37 | 41 |
private java.util.function.Function<String, Integer>allowedFunctions; |
42 |
private Map<String,Factory> suggestionFactories; |
|
43 |
|
|
38 | 44 |
|
39 | 45 |
public DefaultExpressionBuilderConfig(ExpressionEvaluatorSwingManager manager) { |
40 | 46 |
this.manager = manager; |
... | ... | |
43 | 49 |
this.propertiesSupportHelper = new PropertiesSupportHelper(); |
44 | 50 |
this.showLabelsOfAttributes = true; |
45 | 51 |
this.allowAggregates = false; |
52 |
this.suggestionFactories = new HashMap<>(); |
|
46 | 53 |
initSymbolTables(); |
47 | 54 |
} |
48 | 55 |
|
49 | 56 |
@Override |
57 |
public void copyConfigFrom(ExpressionBuilderConfig other) { |
|
58 |
// Hay que tener cuidado al copiar ya que puede darse el caso |
|
59 |
// que "other = this", por eso lo de las variables other_* |
|
60 |
this.getPreferences().copyPreferencesFrom(other.getPreferences()); |
|
61 |
|
|
62 |
this.allowAggregates = other.allowAggregates(); |
|
63 |
this.allowedFunctions = other.getAllowedFunctions(); |
|
64 |
this.previewSymbolTable = other.getPreviewSymbolTable(); |
|
65 |
|
|
66 |
Collection<SymbolTable> other_symbolTables = other.getSymbolTables(); |
|
67 |
List<Element> other_elements = other.getElements(); |
|
68 |
Collection<Factory> other_suggestionFactories = other.getSuggestionFactories(); |
|
69 |
|
|
70 |
this.symbolTables = new HashMap<>(); |
|
71 |
this.elements = new ArrayList<>(); |
|
72 |
this.suggestionFactories = new HashMap<>(); |
|
73 |
|
|
74 |
for (SymbolTable symbolTable : other_symbolTables) { |
|
75 |
this.addSymbolTable(symbolTable); |
|
76 |
} |
|
77 |
|
|
78 |
for (Element element : other_elements) { |
|
79 |
this.elements.add(element); |
|
80 |
} |
|
81 |
|
|
82 |
for (Factory suggestionFactory : other_suggestionFactories) { |
|
83 |
this.addSuggestionFactory(suggestionFactory); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public void copyPreferencesFrom(Preferences other) { |
|
89 |
other.setSQLCompatible(this.SQLCompatible); |
|
90 |
other.setShowLabelsOfElements(this.showLabelsOfAttributes); |
|
91 |
other.setSimpleElementsLimit(limit); |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
50 | 95 |
public Preferences getPreferences() { |
51 | 96 |
return this; |
52 | 97 |
} |
53 | 98 |
|
99 |
@Override |
|
100 |
public Collection<Factory> getSuggestionFactories() { |
|
101 |
return this.suggestionFactories.values(); |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public java.util.function.Function<String, Integer> getAllowedFunctions() { |
|
106 |
return this.allowedFunctions; |
|
107 |
} |
|
108 |
|
|
54 | 109 |
private void initSymbolTables() { |
55 | 110 |
ExpressionEvaluatorManager theManager = ExpressionEvaluatorLocator.getManager(); |
56 | 111 |
for (SymbolTableFactory factory : theManager.getSymbolTableFactories()) { |
... | ... | |
62 | 117 |
|
63 | 118 |
@Override |
64 | 119 |
public List<Element> getElements() { |
65 |
if (this.elements == null) { |
|
120 |
if (this.elements == null || this.elements.isEmpty() ) {
|
|
66 | 121 |
this.elements = manager.createElements(this.getSymbolTables(), (Function f) -> { |
67 | 122 |
if( f.group().equalsIgnoreCase(Function.GROUP_AGGREGATE) && |
68 | 123 |
!this.allowAggregates() ) { |
... | ... | |
120 | 175 |
if (symbolTable == null) { |
121 | 176 |
return; |
122 | 177 |
} |
123 |
if (this.elements != null) { |
|
178 |
if (this.elements != null && !this.elements.isEmpty() ) {
|
|
124 | 179 |
throw new IllegalStateException("Can not add symbol tables once the elements are built."); |
125 | 180 |
} |
126 | 181 |
if (this.symbolTables == null) { |
... | ... | |
135 | 190 |
} |
136 | 191 |
|
137 | 192 |
@Override |
193 |
public void removeAllElements() { |
|
194 |
this.elements.clear(); |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
138 | 198 |
public int getSimpleElementsLimit() { |
139 | 199 |
return this.limit; |
140 | 200 |
} |
... | ... | |
226 | 286 |
this.allowedFunctions = allow; |
227 | 287 |
} |
228 | 288 |
|
289 |
@Override |
|
290 |
public String getSuggestion(Expression expression) { |
|
291 |
if( expression == null ) { |
|
292 |
return null; |
|
293 |
} |
|
294 |
String text = expression.getPhrase(); |
|
295 |
if( StringUtils.isBlank(text) ) { |
|
296 |
return null; |
|
297 |
} |
|
298 |
boolean needseparator = false; |
|
299 |
StringBuilder builder = null; |
|
300 |
for (Factory factory : suggestionFactories.values()) { |
|
301 |
SuggestionProvider provider = (SuggestionProvider) factory.create(); |
|
302 |
String suggestion = provider.getSuggestion(text); |
|
303 |
if( suggestion != null ) { |
|
304 |
if( builder == null ) { |
|
305 |
builder = new StringBuilder(); |
|
306 |
builder.append(suggestion); |
|
307 |
} else { |
|
308 |
builder.append("\n\n"); |
|
309 |
builder.append(suggestion); |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
if( builder!=null ) { |
|
314 |
return builder.toString(); |
|
315 |
} |
|
316 |
return null; |
|
317 |
} |
|
318 |
|
|
319 |
@Override |
|
320 |
public void addSuggestionFactory(Factory factory) { |
|
321 |
if( factory == null ) { |
|
322 |
return; |
|
323 |
} |
|
324 |
this.suggestionFactories.put(factory.getName(), factory); |
|
325 |
} |
|
326 |
|
|
229 | 327 |
} |
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/DefaultJExpressionBuilder.java | ||
---|---|---|
20 | 20 |
import java.util.Locale; |
21 | 21 |
import java.util.Map; |
22 | 22 |
import java.util.Objects; |
23 |
import java.util.function.Function; |
|
24 |
import java.util.function.Predicate; |
|
23 | 25 |
import javax.swing.DefaultListCellRenderer; |
24 | 26 |
import javax.swing.ImageIcon; |
25 | 27 |
import javax.swing.JComponent; |
... | ... | |
74 | 76 |
import org.gvsig.tools.swing.api.script.ScriptSwingManager; |
75 | 77 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
76 | 78 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
79 |
import org.gvsig.tools.util.Factory; |
|
77 | 80 |
import org.gvsig.tools.util.ToolsUtilLocator; |
78 | 81 |
|
79 | 82 |
/** |
... | ... | |
322 | 325 |
@Override |
323 | 326 |
protected void setMessage(int mode, String text) { |
324 | 327 |
super.setMessage(mode, text); |
325 |
lblMsg.setText("<html>"+StringUtils.abbreviate(text,100)+"</html>");
|
|
328 |
message(text);
|
|
326 | 329 |
} |
327 | 330 |
|
328 | 331 |
@Override |
329 | 332 |
protected void setPreview(Object value) { |
330 | 333 |
super.setPreview(value); |
331 |
lblMsg.setText("<html>"+StringUtils.abbreviate(this.getPreview(),100)+"</html>");
|
|
334 |
message(this.getPreview());
|
|
332 | 335 |
} |
333 | 336 |
|
334 | 337 |
@Override |
335 | 338 |
protected void setTip(String theTip) { |
336 | 339 |
super.setTip(theTip); |
337 |
btnTip.setToolTipText(this.getTip());
|
|
340 |
btnTip.setToolTipText(toHTML(this.getTip()));
|
|
338 | 341 |
btnTip.setVisible(this.isTipEnabled()); |
339 | 342 |
} |
343 |
|
|
344 |
@Override |
|
345 |
protected String getSuggestion() { |
|
346 |
return builderConfig.getSuggestion(this.getExpression()); |
|
347 |
} |
|
340 | 348 |
|
341 | 349 |
}; |
342 | 350 |
this.infoPanel = new InfoPanel(this.pnlDescription, load_description_from_resource()); |
... | ... | |
659 | 667 |
this.spnlItem.setDividerLocation(dim.width/3); |
660 | 668 |
} |
661 | 669 |
|
670 |
private void message(String text) { |
|
671 |
if( StringUtils.isBlank(text) ) { |
|
672 |
lblMsg.setText(""); |
|
673 |
return; |
|
674 |
} |
|
675 |
String msg = text; |
|
676 |
String tail = ""; |
|
677 |
if( StringUtils.contains(msg, "\n") ) { |
|
678 |
String[] ss = StringUtils.split(msg, "\n"); |
|
679 |
if( ss.length>1 ) { |
|
680 |
tail = String.format("(%d lines more)", ss.length); |
|
681 |
msg = ss[0]; |
|
682 |
} |
|
683 |
} |
|
684 |
lblMsg.setText(toHTML(StringUtils.abbreviate(msg,70)+tail)); |
|
685 |
} |
|
686 |
|
|
687 |
private String toHTML(String s) { |
|
688 |
s = StringUtils.replace(s, "\n", "\n<br>"); |
|
689 |
s = StringUtils.replace(s, "<html>", ""); |
|
690 |
s = StringUtils.replace(s, "</html>", ""); |
|
691 |
s = "<html>"+s+"</html>"; |
|
692 |
return s; |
|
693 |
} |
|
694 |
|
|
662 | 695 |
private String removeCursorMark(String s) { |
663 | 696 |
if( s == null ) { |
664 | 697 |
return null; |
... | ... | |
961 | 994 |
} |
962 | 995 |
|
963 | 996 |
@Override |
997 |
public void expandElement(Predicate<Element> condition) { |
|
998 |
if( condition == null ) { |
|
999 |
return; |
|
1000 |
} |
|
1001 |
this.initializeTree(); |
|
1002 |
for (int i = 0; i < this.treeElements.getRowCount(); i++) { |
|
1003 |
TreePath path = this.treeElements.getPathForRow(i); |
|
1004 |
if( condition.test((Element) path.getLastPathComponent()) ) { |
|
1005 |
// FIXME: habria que expandir los padres hasta llegar a este. |
|
1006 |
this.treeElements.expandPath(path); |
|
1007 |
return; |
|
1008 |
} |
|
1009 |
} |
|
1010 |
} |
|
1011 |
|
|
1012 |
@Override |
|
964 | 1013 |
public Object getProperty(String name) { |
965 | 1014 |
return this.builderConfig.getProperty(name); |
966 | 1015 |
} |
... | ... | |
994 | 1043 |
public void setAllowedFunctions(java.util.function.Function<String, Integer> allow) { |
995 | 1044 |
this.builderConfig.setAllowedFunctions(allow); |
996 | 1045 |
} |
1046 |
|
|
1047 |
@Override |
|
1048 |
public void addSuggestionFactory(Factory factory) { |
|
1049 |
this.builderConfig.addSuggestionFactory(factory); |
|
1050 |
} |
|
1051 |
|
|
1052 |
@Override |
|
1053 |
public String getSuggestion(Expression expression) { |
|
1054 |
return this.builderConfig.getSuggestion(expression); |
|
1055 |
} |
|
1056 |
|
|
1057 |
@Override |
|
1058 |
public void copyConfigFrom(ExpressionBuilderConfig other) { |
|
1059 |
this.builderConfig.copyConfigFrom(other); |
|
1060 |
} |
|
1061 |
|
|
1062 |
@Override |
|
1063 |
public Function<String, Integer> getAllowedFunctions() { |
|
1064 |
return this.builderConfig.getAllowedFunctions(); |
|
1065 |
} |
|
1066 |
|
|
1067 |
@Override |
|
1068 |
public Collection<Factory> getSuggestionFactories() { |
|
1069 |
return this.builderConfig.getSuggestionFactories(); |
|
1070 |
} |
|
1071 |
|
|
1072 |
@Override |
|
1073 |
public void removeAllElements() { |
|
1074 |
this.builderConfig.removeAllElements(); |
|
1075 |
} |
|
1076 |
|
|
997 | 1077 |
} |
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/DefaultExpressionPickerController.java | ||
---|---|---|
6 | 6 |
import java.util.Collection; |
7 | 7 |
import java.util.List; |
8 | 8 |
import java.util.Map; |
9 |
import java.util.function.Function; |
|
9 | 10 |
import javax.swing.ImageIcon; |
10 | 11 |
import javax.swing.JButton; |
11 | 12 |
import javax.swing.JMenuItem; |
... | ... | |
28 | 29 |
import org.gvsig.tools.swing.icontheme.IconThemeManager; |
29 | 30 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
30 | 31 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
32 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
|
31 | 33 |
import org.gvsig.tools.dataTypes.Coercion; |
32 | 34 |
import org.gvsig.tools.i18n.I18nManager; |
33 | 35 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
... | ... | |
39 | 41 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
40 | 42 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
41 | 43 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
44 |
import org.gvsig.tools.util.Factory; |
|
42 | 45 |
|
43 | 46 |
/** |
44 | 47 |
* |
... | ... | |
132 | 135 |
protected Expression getExpression() { |
133 | 136 |
return getWithOutHistory(); |
134 | 137 |
} |
138 |
|
|
139 |
@Override |
|
140 |
protected String getSuggestion() { |
|
141 |
return config.getSuggestion(this.getExpression()); |
|
142 |
} |
|
143 |
|
|
135 | 144 |
}; |
136 | 145 |
} |
137 | 146 |
|
... | ... | |
140 | 149 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
141 | 150 |
|
142 | 151 |
Expression theValue = this.get(); |
143 |
DefaultJExpressionBuilder panel = new DefaultJExpressionBuilder(this.manager, this.config);
|
|
144 |
panel.setPreviewSymbolTable(this.getPreviewSymbolTable());
|
|
152 |
JExpressionBuilder panel = new DefaultJExpressionBuilder(this.manager, this.config); |
|
153 |
panel.copyConfigFrom(this);
|
|
145 | 154 |
panel.setExpression(theValue); |
146 | 155 |
|
147 | 156 |
Dialog dialog = windowManager.createDialog( |
... | ... | |
294 | 303 |
return this.config.getProperties(); |
295 | 304 |
} |
296 | 305 |
|
297 |
@Override |
|
298 |
public boolean allowAggregates() { |
|
299 |
return this.config.allowAggregates(); |
|
300 |
} |
|
306 |
@Override
|
|
307 |
public boolean allowAggregates() {
|
|
308 |
return this.config.allowAggregates();
|
|
309 |
}
|
|
301 | 310 |
|
302 |
@Override |
|
303 |
public boolean allowAggregates(boolean allow) { |
|
304 |
return this.config.allowAggregates(allow); |
|
305 |
} |
|
311 |
@Override
|
|
312 |
public boolean allowAggregates(boolean allow) {
|
|
313 |
return this.config.allowAggregates(allow);
|
|
314 |
}
|
|
306 | 315 |
|
307 |
@Override |
|
308 |
public java.util.function.Function<String, Integer> isFunctionAllowed() { |
|
309 |
return this.config.isFunctionAllowed(); |
|
310 |
} |
|
316 |
@Override
|
|
317 |
public java.util.function.Function<String, Integer> isFunctionAllowed() {
|
|
318 |
return this.config.isFunctionAllowed();
|
|
319 |
}
|
|
311 | 320 |
|
312 |
@Override |
|
313 |
public void setAllowedFunctions(java.util.function.Function<String, Integer> allow) { |
|
314 |
this.config.setAllowedFunctions(allow); |
|
315 |
} |
|
321 |
@Override
|
|
322 |
public void setAllowedFunctions(java.util.function.Function<String, Integer> allow) {
|
|
323 |
this.config.setAllowedFunctions(allow);
|
|
324 |
}
|
|
316 | 325 |
|
326 |
@Override |
|
327 |
public void addSuggestionFactory(Factory factory) { |
|
328 |
this.config.addSuggestionFactory(factory); |
|
329 |
} |
|
330 |
|
|
331 |
@Override |
|
332 |
public String getSuggestion(Expression expression) { |
|
333 |
return this.config.getSuggestion(expression); |
|
334 |
} |
|
335 |
|
|
336 |
@Override |
|
337 |
public void copyConfigFrom(ExpressionBuilderConfig other) { |
|
338 |
this.config.copyConfigFrom(other); |
|
339 |
} |
|
340 |
|
|
341 |
@Override |
|
342 |
public Function<String, Integer> getAllowedFunctions() { |
|
343 |
return this.config.getAllowedFunctions(); |
|
344 |
} |
|
345 |
|
|
346 |
@Override |
|
347 |
public Collection<Factory> getSuggestionFactories() { |
|
348 |
return this.config.getSuggestionFactories(); |
|
349 |
} |
|
350 |
|
|
351 |
@Override |
|
352 |
public void removeAllElements() { |
|
353 |
this.config.removeAllElements(); |
|
354 |
} |
|
355 |
|
|
317 | 356 |
} |
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/DefaultJExpressionPicker.java | ||
---|---|---|
4 | 4 |
import java.util.Collection; |
5 | 5 |
import java.util.List; |
6 | 6 |
import java.util.Map; |
7 |
import java.util.function.Function; |
|
7 | 8 |
import javax.swing.JButton; |
8 | 9 |
import javax.swing.JComponent; |
9 | 10 |
import javax.swing.JPanel; |
... | ... | |
11 | 12 |
import org.gvsig.expressionevaluator.Expression; |
12 | 13 |
import org.gvsig.expressionevaluator.SymbolTable; |
13 | 14 |
import org.gvsig.expressionevaluator.swing.Element; |
15 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
|
14 | 16 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
15 | 17 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
16 | 18 |
import org.gvsig.expressionevaluator.swing.JExpressionPicker; |
19 |
import org.gvsig.tools.util.Factory; |
|
17 | 20 |
|
18 | 21 |
/** |
19 | 22 |
* |
... | ... | |
151 | 154 |
public void setAllowedFunctions(java.util.function.Function<String, Integer> allow) { |
152 | 155 |
this.controller.setAllowedFunctions(allow); |
153 | 156 |
} |
157 |
|
|
158 |
@Override |
|
159 |
public void addSuggestionFactory(Factory factory) { |
|
160 |
this.controller.addSuggestionFactory(factory); |
|
161 |
} |
|
162 |
|
|
163 |
@Override |
|
164 |
public String getSuggestion(Expression expression) { |
|
165 |
return this.controller.getSuggestion(expression); |
|
166 |
} |
|
167 |
|
|
168 |
@Override |
|
169 |
public void copyConfigFrom(ExpressionBuilderConfig other) { |
|
170 |
this.controller.copyConfigFrom(other); |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public Function<String, Integer> getAllowedFunctions() { |
|
175 |
return this.controller.getAllowedFunctions(); |
|
176 |
} |
|
177 |
|
|
178 |
@Override |
|
179 |
public Collection<Factory> getSuggestionFactories() { |
|
180 |
return this.controller.getSuggestionFactories(); |
Also available in: Unified diff