Index: 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/DefaultExpression.java
===================================================================
--- 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/DefaultExpression.java	(revision 44162)
+++ 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/DefaultExpression.java	(revision 44163)
@@ -54,6 +54,20 @@
     }
 
     @Override
+    public boolean isEmpty() {
+        if( !StringUtils.isBlank(this.phrase) ) {
+            return false;
+        }
+        if( this.scripts!=null && !this.scripts.isEmpty() ) {
+            return false;
+        }
+        if( !StringUtils.isBlank(this.userScript.getCode()) ) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
     public Script getUserScript() {
         return this.userScript;
     }
@@ -70,14 +84,15 @@
     }
 
     @Override
-    public void setPhrase(String phrase) {
+    public Expression setPhrase(String phrase) {
         this.phrase = phrase;
         this.code = null;
         this.hasNotBeenOptimized = true;
+        return this;
     }
 
     @Override
-    public void setUserScript(String code, String languaje) {
+    public Expression setUserScript(String code, String languaje) {
         if (this.userScript == null) {
             ScriptManager scriptMananger = ToolsLocator.getScriptManager();
             this.userScript = scriptMananger.createScript("user", code, languaje);
@@ -87,16 +102,19 @@
             ScriptManager scriptMananger = ToolsLocator.getScriptManager();
             this.userScript = scriptMananger.createScript("user", code, languaje);
         }
+        return this;
     }
 
     @Override
-    public void setUserScript(Script script) {
+    public Expression setUserScript(Script script) {
         this.userScript = script;
+        return this;
     }
 
     @Override
-    public void setUserScript(String code) {
+    public Expression setUserScript(String code) {
         this.setUserScript(code, "python");
+        return this;
     }
 
     @Override
@@ -106,11 +124,12 @@
     }
 
     @Override
-    public void addScript(Script script) {
+    public Expression addScript(Script script) {
         if (this.scripts == null) {
             this.scripts = new ArrayList<>();
         }
         this.scripts.add(script);
+        return this;
     }
 
     @Override
Index: 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/Expression.java
===================================================================
--- 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/Expression.java	(revision 44162)
+++ 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/Expression.java	(revision 44163)
@@ -22,17 +22,17 @@
     
     public UnmodifiableBasicList<Script> getScripts();
 
-    public void setPhrase(String phrase);
+    public Expression setPhrase(String phrase);
     
-    public void setUserScript(String code, String languaje);
+    public Expression setUserScript(String code, String languaje);
     
-    public void setUserScript(String code);
+    public Expression setUserScript(String code);
     
-    public void setUserScript(Script script);
+    public Expression setUserScript(Script script);
     
     public void removeAllScripts();
     
-    public void addScript(Script script);
+    public Expression addScript(Script script);
     
     public Object execute(SymbolTable symbolTable);
     
@@ -46,4 +46,5 @@
     
     public boolean isPhraseEmpty();
     
+    public boolean isEmpty();
 }
Index: 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/ExpressionUtils.java
===================================================================
--- 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/ExpressionUtils.java	(revision 0)
+++ 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/ExpressionUtils.java	(revision 44163)
@@ -0,0 +1,77 @@
+package org.gvsig.expressionevaluator;
+
+import org.gvsig.tools.script.Script;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class ExpressionUtils {
+
+    public static boolean isEmpty(Expression expression) {
+        return expression == null || expression.isEmpty();
+    }
+
+    public static boolean isPhraseEmpty(Expression expression) {
+        return expression == null || expression.isPhraseEmpty();
+    }
+    
+    public static Expression defaultIfEmpty(Expression expression, Expression defaultValue) {
+        if( expression==null || expression.isEmpty() ) {
+            return defaultValue;
+        }
+        return expression;
+    }
+    
+    public static Expression defaultNullIfEmpty(Expression expression) {
+        if( expression==null || expression.isEmpty() ) {
+            return null;
+        }
+        return expression;
+    }
+    
+    public static Expression defaultIfPhraseEmpty(Expression expression, Expression defaultValue) {
+        if( expression==null || expression.isPhraseEmpty() ) {
+            return defaultValue;
+        }
+        return expression;
+    }
+
+    public static Expression defaultNullIfPhraseEmpty(Expression expression) {
+        if( expression==null || expression.isPhraseEmpty() ) {
+            return null;
+        }
+        return expression;
+    }
+   
+    public static Expression createExpression() {
+        Expression expression = ExpressionEvaluatorLocator.getManager().createExpression();
+        return expression;
+    }
+
+    public static Expression createExpression(String phrase) {
+        Expression expression = ExpressionEvaluatorLocator.getManager().createExpression();
+        expression.setPhrase(phrase);
+        return expression;
+    }
+
+    public static Expression createExpression(String phrase, String code, Script... scripts) {
+        Expression expression = ExpressionEvaluatorLocator.getManager().createExpression();
+        expression.setPhrase(phrase);
+        expression.setUserScript(code);
+        for (Script script : scripts) {
+            expression.addScript(script);
+        }
+        return expression;
+    }
+
+    public static Expression createExpression(String phrase, String code, String languaje, Script... scripts) {
+        Expression expression = ExpressionEvaluatorLocator.getManager().createExpression();
+        expression.setPhrase(phrase);
+        expression.setUserScript(code, languaje);
+        for (Script script : scripts) {
+            expression.addScript(script);
+        }
+        return expression;
+    }
+}
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.api/src/main/java/org/gvsig/expressionevaluator/swing/ExpressionPickerController.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.api/src/main/java/org/gvsig/expressionevaluator/swing/ExpressionPickerController.java	(revision 44162)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.api/src/main/java/org/gvsig/expressionevaluator/swing/ExpressionPickerController.java	(revision 44163)
@@ -10,4 +10,18 @@
 public interface ExpressionPickerController 
         extends PickerController<Expression>, ExpressionBuilderConfig {
 
+    /**
+     * Return the expression in the picker.
+     * If a non-null value is assigned as the expression, it will return 
+     * this value updated with what the user entered.
+     * If a null value is assigned as the expression, when the user did not 
+     * enter any value return null. When the user enter values, and the 
+     * expression is not empty, it will return a new expression.
+     * 
+     * @return 
+     */
+    @Override
+    public Expression get();
+
+    
 }
Index: 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
===================================================================
--- 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	(revision 44162)
+++ 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	(revision 44163)
@@ -14,6 +14,7 @@
 import org.gvsig.expressionevaluator.DataTypes;
 import org.gvsig.expressionevaluator.Expression;
 import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
+import org.gvsig.expressionevaluator.ExpressionUtils;
 import org.gvsig.expressionevaluator.SymbolTable;
 import org.gvsig.expressionevaluator.swing.Element;
 import org.gvsig.tools.ToolsLocator;
@@ -59,6 +60,7 @@
     private final ActionListener buttonAction;
     private final JMenuItem menuItem;
     private final AbstractAutomaticExpressionChecker automaticExpressionChecker;
+    private boolean returnNullWhenEmptyExpression;
     
     public DefaultExpressionPickerController(ExpressionEvaluatorSwingManager manager, JTextComponent text, JButton button) {
         ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager();
@@ -69,6 +71,7 @@
         this.text = text;
         this.button = button;
         this.value = null;
+        this.returnNullWhenEmptyExpression = true;
         this.button.setIcon(this.getIcon("picker-expression"));
         this.buttonAction = new ActionListener() {
             @Override
@@ -115,13 +118,15 @@
     @Override
     public Expression get() {
         String s = this.text.getText();
-        if( StringUtils.isBlank(s) ) {
-            return null;
+        if( this.returnNullWhenEmptyExpression ) {
+            if( ExpressionUtils.isEmpty(this.value) &&  StringUtils.isBlank(s) ) {
+                return null;
+            }
         }
-        if( value == null ) {
-            value = ExpressionEvaluatorLocator.getManager().createExpression();
+        if( this.value == null ) {
+            this.value = ExpressionEvaluatorLocator.getManager().createExpression();
         }
-        this.value.setPhrase(this.text.getText());
+        this.value.setPhrase(StringUtils.defaultIfBlank(this.text.getText(),null));
         return this.value;
     }
 
@@ -130,9 +135,11 @@
         if( value==null ) {
             this.text.setText("");
             this.value = null;
+            this.returnNullWhenEmptyExpression = true;
         } else {
             this.value = value;
             this.text.setText(this.value.getPhrase());
+            this.returnNullWhenEmptyExpression = false;
         }
     }
 
