Index: SelectByAttributesInTableExtension.java
===================================================================
--- SelectByAttributesInTableExtension.java	(revision 43986)
+++ SelectByAttributesInTableExtension.java	(revision 43987)
@@ -23,6 +23,8 @@
  */
 package org.gvsig.app.extension;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.util.Iterator;
 
 import javax.swing.JOptionPane;
@@ -36,6 +38,12 @@
 import org.gvsig.app.gui.filter.ExpressionListener;
 import org.gvsig.app.gui.filter.FilterDialog;
 import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
+import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
+import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
+import org.gvsig.expressionevaluator.swing.Element;
+import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator;
+import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager;
+import org.gvsig.expressionevaluator.swing.JExpressionBuilder;
 import org.gvsig.fmap.dal.DALLocator;
 import org.gvsig.fmap.dal.DataManager;
 import org.gvsig.fmap.dal.exception.DataException;
@@ -46,11 +54,15 @@
 import org.gvsig.fmap.dal.feature.FeatureStore;
 import org.gvsig.i18n.Messages;
 import org.gvsig.tools.dispose.DisposeUtils;
+import org.gvsig.tools.swing.api.ToolsSwingLocator;
+import org.gvsig.tools.swing.api.windowmanager.Dialog;
+import org.gvsig.tools.swing.api.windowmanager.WindowManager;
+import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
 import org.gvsig.utils.exceptionHandling.ExceptionListener;
 
 /**
  * Extensión que abre un diálogo para poder hacer un filtro de una capa o tabla.
- * 
+ *
  * @author Vicente Caballero Navarro
  */
 public class SelectByAttributesInTableExtension extends Extension implements ExpressionListener {
@@ -64,21 +76,31 @@
     }
 
     private void registerIcons() {
-    	IconThemeHelper.registerIcon("action", "selection-by-attributes", this);
+        IconThemeHelper.registerIcon("action", "selection-by-attributes", this);
     }
 
     public void execute(String actionCommand) {
-        if ("selection-by-attributes-table".equals(actionCommand)) {
-            IWindow v = PluginServices.getMDIManager().getActiveWindow();
+        IWindow v = PluginServices.getMDIManager().getActiveWindow();
 
-            if (v instanceof FeatureTableDocumentPanel) {
-                table = (FeatureTableDocumentPanel) v;
+        if (!(v instanceof FeatureTableDocumentPanel)) {
+            return;
+        }
+        if ("selection-by-attributes-table2".equals(actionCommand)) {
+            table = (FeatureTableDocumentPanel) v;
 
-                featureStore = table.getModel().getStore();
-                filterTitle = table.getModel().getName();
-                table.getModel().setModified(true);
-            }
+            featureStore = table.getModel().getStore();
+            filterTitle = table.getModel().getName();
+            table.getModel().setModified(true);
 
+            doSelectByAttributes2(filterTitle, featureStore);
+            
+        } else if ("selection-by-attributes-table".equals(actionCommand)) {
+            table = (FeatureTableDocumentPanel) v;
+
+            featureStore = table.getModel().getStore();
+            filterTitle = table.getModel().getName();
+            table.getModel().setModified(true);
+
             doExecute();
         }
     }
@@ -115,15 +137,15 @@
                     return;
                 }
                 featureStore.setSelection(set);
-                
+
             } catch (Exception e) {
-                logger.warn("Problems executing query '"+expression+"' on store '"+featureStore+"'.",e);
+                logger.warn("Problems executing query '" + expression + "' on store '" + featureStore + "'.", e);
                 JOptionPane.showMessageDialog(
-                    ApplicationLocator.getManager().getRootComponent(),
-                    Messages.getText("_Invalid_expression") + ":\n"
+                        ApplicationLocator.getManager().getRootComponent(),
+                        Messages.getText("_Invalid_expression") + ":\n"
                         + getLastMessage(e),
-                    Messages.getText("_Invalid_expression"),
-                    JOptionPane.ERROR_MESSAGE);
+                        Messages.getText("_Invalid_expression"),
+                        JOptionPane.ERROR_MESSAGE);
             } finally {
                 DisposeUtils.disposeQuietly(set);
             }
@@ -153,13 +175,13 @@
                 featureStore.getFeatureSelection().select(set);
 
             } catch (Exception e) {
-                logger.warn("Problems executing query '"+expression+"' on store '"+featureStore+"'.",e);
+                logger.warn("Problems executing query '" + expression + "' on store '" + featureStore + "'.", e);
                 JOptionPane.showMessageDialog(
-                    ApplicationLocator.getManager().getRootComponent(),
-                    Messages.getText("_Invalid_expression") + ":\n"
+                        ApplicationLocator.getManager().getRootComponent(),
+                        Messages.getText("_Invalid_expression") + ":\n"
                         + getLastMessage(e),
-                    Messages.getText("_Invalid_expression"),
-                    JOptionPane.ERROR_MESSAGE);
+                        Messages.getText("_Invalid_expression"),
+                        JOptionPane.ERROR_MESSAGE);
             } finally {
                 DisposeUtils.disposeQuietly(set);
             }
@@ -168,31 +190,31 @@
 
     @Override
     public void fromSet(String expression) throws DataException {
-        if ( !this.filterExpressionFromWhereIsEmpty(expression) ) {
+        if (!this.filterExpressionFromWhereIsEmpty(expression)) {
             FeatureSet set = null;
             try {
                 set = doSet(expression);
-                if ( set == null ) {
+                if (set == null) {
                     return;
                 }
                 FeatureSelection oldSelection = featureStore.getFeatureSelection();
                 FeatureSelection newSelection = featureStore.createFeatureSelection();
                 Iterator iterator = set.iterator();
-                while ( iterator.hasNext() ) {
+                while (iterator.hasNext()) {
                     Feature feature = (Feature) iterator.next();
-                    if ( oldSelection.isSelected(feature) ) {
+                    if (oldSelection.isSelected(feature)) {
                         newSelection.select(feature);
                     }
                 }
                 featureStore.setSelection(newSelection);
             } catch (Exception e) {
-                logger.warn("Problems executing query '"+expression+"' on store '"+featureStore+"'.",e);
+                logger.warn("Problems executing query '" + expression + "' on store '" + featureStore + "'.", e);
                 JOptionPane.showMessageDialog(
-                    ApplicationLocator.getManager().getRootComponent(),
-                    Messages.getText("_Invalid_expression") + ":\n"
+                        ApplicationLocator.getManager().getRootComponent(),
+                        Messages.getText("_Invalid_expression") + ":\n"
                         + getLastMessage(e),
-                    Messages.getText("_Invalid_expression"),
-                    JOptionPane.ERROR_MESSAGE);
+                        Messages.getText("_Invalid_expression"),
+                        JOptionPane.ERROR_MESSAGE);
             } finally {
                 DisposeUtils.disposeQuietly(set);
             }
@@ -200,34 +222,33 @@
             featureStore.getFeatureSelection().deselectAll();
         }
     }
-    
+
     /**
      * Returns true if the WHERE subconsultation of the filterExpression is
      * empty ("")
-     * 
+     *
      * @author Pablo Piqueras Bartolomé (p_queras@hotmail.com)
-     * @param expression
-     *            An string
+     * @param expression An string
      * @return A boolean value
      */
     private boolean filterExpressionFromWhereIsEmpty(String expression) {
-        
+
         if (expression == null) {
             return true;
         }
-        
+
         String subExpression = expression.trim();
-        
+
         if (subExpression.length() == 0) {
             return true;
         }
-        
+
         int pos;
 
         // Remove last ';' if exists
         if (subExpression.charAt(subExpression.length() - 1) == ';') {
-            subExpression =
-                subExpression.substring(0, subExpression.length() - 1).trim();
+            subExpression
+                    = subExpression.substring(0, subExpression.length() - 1).trim();
         }
 
         // If there is no 'where' clause
@@ -237,26 +258,62 @@
 
         // If there is no subexpression in the WHERE clause -> true
         // ( + 5 is the length of the 'where')
-        subExpression =subExpression.substring(pos + 5, subExpression.length()).trim(); 
-                                                                             
+        subExpression = subExpression.substring(pos + 5, subExpression.length()).trim();
+
         if (subExpression.length() == 0) {
             return true;
         } else {
             return false;
         }
     }
-    
-    
+
     /**
      * @param ex
      * @return
      */
     public static String getLastMessage(Throwable ex) {
-        
+
         Throwable p = ex;
         while (p.getCause() != null && p.getCause() != p) {
             p = p.getCause();
         }
         return p.getMessage();
-    }    
+    }
+
+    private void doSelectByAttributes2(String title, final FeatureStore store) {
+        WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
+        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
+        ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager();
+
+        final JExpressionBuilder panel = swingManager.createJExpressionBuilder();
+        Element element = swingManager.createElement("DAL.FeatureStoreElement", panel, store);
+        if (element != null) {
+            panel.getElements().add(element);
+        }
+        final Dialog dialog = windowManager.createDialog(
+                panel.asJComponent(),
+                title,
+                null,
+                WindowManager_v2.BUTTONS_OK_CANCEL
+        );
+        dialog.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                if (dialog.getAction() == WindowManager_v2.BUTTON_OK) {
+                    try {
+                        DataManager manager = DALLocator.getDataManager();
+
+                        FeatureQuery query = store.createFeatureQuery();
+                        query.setFilter(manager.createExpresion(panel.getExpression()));
+                        FeatureSet selection = store.getFeatureSet(query);
+                        store.getFeatureSelection().select(selection);
+                    } catch (Exception ex) {
+                        logger.warn("Can't build selecction from filter expression.", ex);
+                    }
+                }
+            }
+        });
+        dialog.show(WindowManager.MODE.WINDOW);
+
+    }
 }
