cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [4/4] cayenne git commit: Remove code duplication in SelectQuery and SQLTemplate tabs
Date Mon, 05 Mar 2018 07:47:35 GMT
Remove code duplication in SelectQuery and SQLTemplate tabs


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/7758dbf4
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/7758dbf4
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/7758dbf4

Branch: refs/heads/master
Commit: 7758dbf420b1cb611d0710a26304d7d2c34227c7
Parents: f86af37
Author: stariy <stariy95@gmail.com>
Authored: Mon Mar 5 10:47:08 2018 +0300
Committer: stariy <stariy95@gmail.com>
Committed: Mon Mar 5 10:47:08 2018 +0300

----------------------------------------------------------------------
 .../modeler/editor/BaseQueryMainTab.java        |  90 ++++++++++
 .../modeler/editor/RootSelectionHandler.java    |  86 ++++++++++
 .../modeler/editor/SQLTemplateMainTab.java      | 169 ++-----------------
 .../modeler/editor/SelectQueryMainTab.java      | 140 +--------------
 4 files changed, 199 insertions(+), 286 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/7758dbf4/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/BaseQueryMainTab.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/BaseQueryMainTab.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/BaseQueryMainTab.java
new file mode 100644
index 0000000..a1d9033
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/BaseQueryMainTab.java
@@ -0,0 +1,90 @@
+package org.apache.cayenne.modeler.editor;
+
+import org.apache.cayenne.configuration.event.QueryEvent;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.QueryDescriptor;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.util.CellRenderers;
+import org.apache.cayenne.modeler.util.ProjectUtil;
+import org.apache.cayenne.modeler.util.TextAdapter;
+import org.apache.cayenne.modeler.util.combo.AutoCompletion;
+import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationException;
+
+import javax.swing.*;
+
+abstract class BaseQueryMainTab extends JPanel {
+    protected ProjectController mediator;
+    protected TextAdapter name;
+    protected JComboBox<ObjEntity> queryRoot;
+
+    BaseQueryMainTab(ProjectController mediator) {
+        this.mediator = mediator;
+    }
+
+    protected void initQueryRoot() {
+        queryRoot = Application.getWidgetFactory().createComboBox();
+        AutoCompletion.enable(queryRoot);
+        queryRoot.setRenderer(CellRenderers.listRendererWithIcons());
+
+        RootSelectionHandler rootHandler = new RootSelectionHandler(this);
+
+        queryRoot.addActionListener(rootHandler);
+        queryRoot.addFocusListener(rootHandler);
+        queryRoot.getEditor().getEditorComponent().addFocusListener(rootHandler);
+    }
+
+    public TextAdapter getNameField() {
+        return name;
+    }
+
+    public JComboBox<ObjEntity> getQueryRoot() {
+        return queryRoot;
+    }
+
+    public ProjectController getMediator() {
+        return mediator;
+    }
+
+    /**
+     * Initializes Query name from string.
+     */
+    void setQueryName(String newName) {
+        if (newName != null && newName.trim().length() == 0) {
+            newName = null;
+        }
+
+        QueryDescriptor query = getQuery();
+
+        if (query == null) {
+            return;
+        }
+
+        if (Util.nullSafeEquals(newName, query.getName())) {
+            return;
+        }
+
+        if (newName == null) {
+            throw new ValidationException("SelectQuery name is required.");
+        }
+
+        DataMap map = mediator.getCurrentDataMap();
+        QueryDescriptor matchingQuery = map.getQueryDescriptor(newName);
+
+        if (matchingQuery == null) {
+            // completely new name, set new name for entity
+            QueryEvent e = new QueryEvent(this, query, query.getName());
+            ProjectUtil.setQueryName(map, query, newName);
+            mediator.fireQueryEvent(e);
+        } else if (matchingQuery != query) {
+            // there is a query with the same name
+            throw new ValidationException("There is another query named '"
+                    + newName
+                    + "'. Use a different name.");
+        }
+    }
+
+    abstract QueryDescriptor getQuery();
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7758dbf4/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/RootSelectionHandler.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/RootSelectionHandler.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/RootSelectionHandler.java
new file mode 100644
index 0000000..8bafed2
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/RootSelectionHandler.java
@@ -0,0 +1,86 @@
+package org.apache.cayenne.modeler.editor;
+
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.QueryDescriptor;
+import org.apache.cayenne.modeler.util.CellRenderers;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+
+/**
+ * Handler to user's actions with root selection combobox
+ */
+class RootSelectionHandler implements FocusListener, ActionListener {
+    private String newName = null;
+    private boolean needChangeName;
+    private final BaseQueryMainTab queryTab;
+
+    RootSelectionHandler(BaseQueryMainTab queryTab) {
+        this.queryTab = queryTab;
+    }
+
+    public void actionPerformed(ActionEvent ae) {
+        QueryDescriptor query = queryTab.getQuery();
+        if (query != null) {
+            Entity root = (Entity) queryTab.getQueryRoot().getModel().getSelectedItem();
+
+            if (root != null) {
+                query.setRoot(root);
+
+                if (needChangeName) { //not changed by user
+                    /*
+                     * Doing auto name change, following CAY-888 #2
+                     */
+                    String newPrefix = root.getName() + "Query";
+                    newName = newPrefix;
+
+                    DataMap map = queryTab.getMediator().getCurrentDataMap();
+                    long postfix = 1;
+
+                    while (map.getQueryDescriptor(newName) != null) {
+                        newName = newPrefix + (postfix++);
+                    }
+
+                    queryTab.getNameField().setText(newName);
+                }
+            }
+        }
+    }
+
+    public void focusGained(FocusEvent e) {
+        //reset new name tracking
+        newName = null;
+
+        QueryDescriptor query = queryTab.getQuery();
+        if (query != null) {
+            needChangeName = hasDefaultName(query);
+        } else {
+            needChangeName = false;
+        }
+    }
+
+    public void focusLost(FocusEvent e) {
+        if (newName != null) {
+            queryTab.setQueryName(newName);
+        }
+
+        newName = null;
+        needChangeName = false;
+    }
+
+    /**
+     * @return whether specified's query name is 'default' i.e. Cayenne generated
+     * A query's name is 'default' if it starts with 'UntitledQuery' or with root name.
+     *
+     * We cannot follow user input because tab might be opened many times
+     */
+    boolean hasDefaultName(QueryDescriptor query) {
+        String prefix = query.getRoot() == null ? "UntitledQuery" :
+            CellRenderers.asString(query.getRoot()) + "Query";
+
+        return queryTab.getNameField().getComponent().getText().startsWith(prefix);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7758dbf4/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateMainTab.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateMainTab.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateMainTab.java
index 78ef8d0..cbfb99e 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateMainTab.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateMainTab.java
@@ -25,34 +25,23 @@ import com.jgoodies.forms.layout.FormLayout;
 import com.jgoodies.forms.layout.RowSpec;
 import org.apache.cayenne.configuration.event.QueryEvent;
 import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
-import org.apache.cayenne.modeler.util.CellRenderers;
 import org.apache.cayenne.modeler.util.Comparators;
-import org.apache.cayenne.modeler.util.ProjectUtil;
 import org.apache.cayenne.modeler.util.TextAdapter;
-import org.apache.cayenne.modeler.util.combo.AutoCompletion;
 import org.apache.cayenne.project.extension.info.ObjectInfo;
 import org.apache.cayenne.query.CapsStrategy;
 import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.util.Util;
-import org.apache.cayenne.validation.ValidationException;
 
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.DefaultListCellRenderer;
 import javax.swing.JComboBox;
 import javax.swing.JList;
-import javax.swing.JPanel;
 import javax.swing.JTextField;
 import java.awt.BorderLayout;
 import java.awt.Component;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
@@ -61,7 +50,7 @@ import java.util.Map;
  * A main panel for editing a SQLTemplate.
  * 
  */
-public class SQLTemplateMainTab extends JPanel {
+public class SQLTemplateMainTab extends BaseQueryMainTab {
 
     private static final String DEFAULT_CAPS_LABEL = "Database Default";
     private static final String LOWER_CAPS_LABEL = "Force Lower Case";
@@ -79,17 +68,14 @@ public class SQLTemplateMainTab extends JPanel {
         labelCapsLabels.put(CapsStrategy.UPPER, UPPER_CAPS_LABEL);
     }
 
-    protected ProjectController mediator;
-    protected TextAdapter name;
     protected TextAdapter comment;
-    protected JComboBox<ObjEntity> queryRoot;
     protected SelectPropertiesPanel properties;
 
     public SQLTemplateMainTab(ProjectController mediator) {
-        this.mediator = mediator;
+        super(mediator);
 
+        initQueryRoot();
         initView();
-        initController();
     }
 
     private void initView() {
@@ -108,10 +94,6 @@ public class SQLTemplateMainTab extends JPanel {
             }
         };
 
-        queryRoot = Application.getWidgetFactory().createComboBox();
-        AutoCompletion.enable(queryRoot);
-        queryRoot.setRenderer(CellRenderers.listRendererWithIcons());
-
         properties = new SQLTemplateQueryPropertiesPanel(mediator);
 
         // assemble
@@ -135,14 +117,6 @@ public class SQLTemplateMainTab extends JPanel {
         this.add(properties, BorderLayout.CENTER);
     }
 
-    private void initController() {
-        RootSelectionHandler rootHandler = new RootSelectionHandler();
-
-        queryRoot.addActionListener(rootHandler);
-        queryRoot.addFocusListener(rootHandler);
-        queryRoot.getEditor().getEditorComponent().addFocusListener(rootHandler);
-    }
-
     /**
      * Updates the view from the current model state. Invoked when a currently displayed
      * query is changed.
@@ -173,120 +147,13 @@ public class SQLTemplateMainTab extends JPanel {
         setVisible(true);
     }
 
+    @Override
     protected QueryDescriptor getQuery() {
         QueryDescriptor query = mediator.getCurrentQuery();
         return (query != null && QueryDescriptor.SQL_TEMPLATE.equals(query.getType()))
? query : null;
     }
 
     /**
-     * Initializes Query name from string.
-     */
-    void setQueryName(String newName) {
-        if (newName != null && newName.trim().length() == 0) {
-            newName = null;
-        }
-
-        QueryDescriptor query = getQuery();
-
-        if (query == null) {
-            return;
-        }
-
-        if (Util.nullSafeEquals(newName, query.getName())) {
-            return;
-        }
-
-        if (newName == null) {
-            throw new ValidationException("Query name is required.");
-        }
-
-        DataMap map = mediator.getCurrentDataMap();
-
-        if (map.getQueryDescriptor(newName) == null) {
-            // completely new name, set new name for entity
-            QueryEvent e = new QueryEvent(this, query, query.getName());
-            ProjectUtil.setQueryName(map, query, newName);
-            mediator.fireQueryEvent(e);
-        }
-        else {
-            // there is a query with the same name
-            throw new ValidationException("There is another query named '"
-                    + newName
-                    + "'. Use a different name.");
-        }
-    }
-
-    /**
-     * Handler to user's actions with root selection combobox
-     */
-    class RootSelectionHandler implements FocusListener, ActionListener {
-        String newName = null;
-        boolean needChangeName;
-
-        public void actionPerformed(ActionEvent ae) {
-            QueryDescriptor query = getQuery();
-            if (query != null) {
-                Entity root = (Entity) queryRoot.getModel().getSelectedItem();
-
-                if (root != null) {
-                    query.setRoot(root);
-
-                    if (needChangeName) { //not changed by user
-                        /*
-                         * Doing auto name change, following CAY-888 #2
-                         */
-                        String newPrefix = root.getName() + "Query";
-                        newName = newPrefix;
-
-                        DataMap map = mediator.getCurrentDataMap();
-                        long postfix = 1;
-
-                        while (map.getQueryDescriptor(newName) != null) {
-                            newName = newPrefix + (postfix++);
-                        }
-
-                        name.setText(newName);
-                    }
-                }
-            }
-        }
-
-        public void focusGained(FocusEvent e) {
-            //reset new name tracking
-            newName = null;
-
-            QueryDescriptor query = getQuery();
-            if (query != null) {
-                needChangeName = hasDefaultName(query);
-            } else {
-                needChangeName = false;
-            }
-        }
-
-        public void focusLost(FocusEvent e) {
-            if (newName != null) {
-                setQueryName(newName);
-            }
-
-            newName = null;
-            needChangeName = false;
-        }
-
-        /**
-         * @return whether specified's query name is 'default' i.e. Cayenne generated
-         * A query's name is 'default' if it starts with 'UntitledQuery' or with root name.
-         *
-         * We cannot follow user input because tab might be opened many times
-         */
-        boolean hasDefaultName(QueryDescriptor query) {
-            String prefix = query.getRoot() == null ? "UntitledQuery" :
-                    CellRenderers.asString(query.getRoot()) + "Query";
-
-            return name.getComponent().getText().startsWith(prefix);
-        }
-    }
-
-    /**
      * Returns an entity that maps to a procedure query result class.
      */
     ObjEntity getEntity(QueryDescriptor query) {
@@ -319,7 +186,7 @@ public class SQLTemplateMainTab extends JPanel {
     }
 
     final class LabelCapsRenderer extends DefaultListCellRenderer {
-
+        @Override
         public Component getListCellRendererComponent(
                 JList list,
                 Object object,
@@ -333,22 +200,20 @@ public class SQLTemplateMainTab extends JPanel {
 
     final class SQLTemplateQueryPropertiesPanel extends RawQueryPropertiesPanel {
 
-        private JComboBox labelCase;
+        private JComboBox<CapsStrategy> labelCase;
 
         SQLTemplateQueryPropertiesPanel(ProjectController mediator) {
             super(mediator);
         }
 
+        @Override
         protected PanelBuilder createPanelBuilder() {
             labelCase = Application.getWidgetFactory().createUndoableComboBox();
             labelCase.setRenderer(new LabelCapsRenderer());
 
-            labelCase.addActionListener(new ActionListener() {
-
-                public void actionPerformed(ActionEvent event) {
-                    CapsStrategy value = (CapsStrategy) labelCase.getModel().getSelectedItem();
-                    setQueryProperty(SQLTemplate.COLUMN_NAME_CAPITALIZATION_PROPERTY, value.name());
-                }
+            labelCase.addActionListener(event -> {
+                CapsStrategy value = (CapsStrategy) labelCase.getModel().getSelectedItem();
+                setQueryProperty(SQLTemplate.COLUMN_NAME_CAPITALIZATION_PROPERTY, value.name());
             });
 
             PanelBuilder builder = super.createPanelBuilder();
@@ -365,25 +230,27 @@ public class SQLTemplateMainTab extends JPanel {
             return builder;
         }
 
+        @Override
         public void initFromModel(QueryDescriptor query) {
             super.initFromModel(query);
 
             if (query != null && QueryDescriptor.SQL_TEMPLATE.equals(query.getType()))
{
-                DefaultComboBoxModel labelCaseModel = new DefaultComboBoxModel(
-                        LABEL_CAPITALIZATION);
-
+                DefaultComboBoxModel<CapsStrategy> labelCaseModel = new DefaultComboBoxModel<>(LABEL_CAPITALIZATION);
                 String columnNameCapitalization = query.getProperty(SQLTemplate.COLUMN_NAME_CAPITALIZATION_PROPERTY);
 
-                labelCaseModel.setSelectedItem(columnNameCapitalization != null ?
-                        CapsStrategy.valueOf(columnNameCapitalization) : CapsStrategy.DEFAULT);
+                labelCaseModel.setSelectedItem(columnNameCapitalization != null
+                        ? CapsStrategy.valueOf(columnNameCapitalization)
+                        : CapsStrategy.DEFAULT);
                 labelCase.setModel(labelCaseModel);
             }
         }
 
+        @Override
         protected void setEntity(ObjEntity entity) {
             SQLTemplateMainTab.this.setEntity(entity);
         }
 
+        @Override
         public ObjEntity getEntity(QueryDescriptor query) {
             if (query != null && QueryDescriptor.SQL_TEMPLATE.equals(query.getType()))
{
                 return SQLTemplateMainTab.this.getEntity(query);
@@ -399,5 +266,5 @@ public class SQLTemplateMainTab extends JPanel {
                 setEntity(null);
             }
         }
-    };
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/7758dbf4/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryMainTab.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryMainTab.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryMainTab.java
index e68d17a..c0bc6d1 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryMainTab.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryMainTab.java
@@ -20,10 +20,6 @@
 package org.apache.cayenne.modeler.editor;
 
 import java.awt.BorderLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.util.Arrays;
@@ -31,8 +27,6 @@ import java.util.Iterator;
 
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JPanel;
 import javax.swing.JTextField;
 
 import org.apache.cayenne.configuration.event.QueryEvent;
@@ -44,18 +38,14 @@ import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.map.SelectQueryDescriptor;
-import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.swing.components.JCayenneCheckBox;
 import org.apache.cayenne.modeler.ProjectController;
-import org.apache.cayenne.modeler.util.CellRenderers;
 import org.apache.cayenne.modeler.util.Comparators;
 import org.apache.cayenne.modeler.util.ExpressionConvertor;
-import org.apache.cayenne.modeler.util.ProjectUtil;
 import org.apache.cayenne.modeler.util.TextAdapter;
 import org.apache.cayenne.modeler.util.ValidatorTextAdapter;
-import org.apache.cayenne.modeler.util.combo.AutoCompletion;
 import org.apache.cayenne.project.extension.info.ObjectInfo;
-import org.apache.cayenne.query.*;
 import org.apache.cayenne.util.CayenneMapEntry;
 import org.apache.cayenne.util.Util;
 import org.apache.cayenne.validation.ValidationException;
@@ -68,20 +58,17 @@ import com.jgoodies.forms.layout.FormLayout;
  * A tabbed pane that contains editors for various SelectQuery parts.
  * 
  */
-public class SelectQueryMainTab extends JPanel {
+public class SelectQueryMainTab extends BaseQueryMainTab {
 
-    protected ProjectController mediator;
-
-    protected TextAdapter name;
     protected TextAdapter comment;
-    protected JComboBox<ObjEntity> queryRoot;
     protected TextAdapter qualifier;
     protected JCheckBox distinct;
     protected ObjectQueryPropertiesPanel properties;
 
     public SelectQueryMainTab(ProjectController mediator) {
-        this.mediator = mediator;
+        super(mediator);
 
+        initQueryRoot();
         initView();
         initController();
     }
@@ -96,10 +83,6 @@ public class SelectQueryMainTab extends JPanel {
             }
         };
 
-        queryRoot = Application.getWidgetFactory().createComboBox();
-        AutoCompletion.enable(queryRoot);
-        queryRoot.setRenderer(CellRenderers.listRendererWithIcons());
-
         qualifier = new ValidatorTextAdapter(new JTextField()) {
 
             @Override
@@ -150,11 +133,6 @@ public class SelectQueryMainTab extends JPanel {
     }
 
     private void initController() {
-        RootSelectionHandler rootHandler = new RootSelectionHandler();
-
-        queryRoot.addActionListener(rootHandler);
-        queryRoot.addFocusListener(rootHandler);
-        queryRoot.getEditor().getEditorComponent().addFocusListener(rootHandler);
 
         distinct.addItemListener(new ItemListener() {
 
@@ -215,6 +193,7 @@ public class SelectQueryMainTab extends JPanel {
         setVisible(true);
     }
 
+    @Override
     protected SelectQueryDescriptor getQuery() {
         if(mediator.getCurrentQuery() == null) {
             return null;
@@ -277,45 +256,6 @@ public class SelectQueryMainTab extends JPanel {
     }
 
     /**
-     * Initializes Query name from string.
-     */
-    void setQueryName(String newName) {
-        if (newName != null && newName.trim().length() == 0) {
-            newName = null;
-        }
-
-        QueryDescriptor query = getQuery();
-
-        if (query == null) {
-            return;
-        }
-
-        if (Util.nullSafeEquals(newName, query.getName())) {
-            return;
-        }
-
-        if (newName == null) {
-            throw new ValidationException("SelectQuery name is required.");
-        }
-
-        DataMap map = mediator.getCurrentDataMap();
-        QueryDescriptor matchingQuery = map.getQueryDescriptor(newName);
-
-        if (matchingQuery == null) {
-            // completely new name, set new name for entity
-            QueryEvent e = new QueryEvent(this, query, query.getName());
-            ProjectUtil.setQueryName(map, query, newName);
-            mediator.fireQueryEvent(e);
-        }
-        else if (matchingQuery != query) {
-            // there is a query with the same name
-            throw new ValidationException("There is another query named '"
-                    + newName
-                    + "'. Use a different name.");
-        }
-    }
-
-    /**
      * Advanced checking of an expression, needed because Expression.fromString()
      * might terminate normally, but returned Expression will not be appliable
      * for real Entities.
@@ -351,76 +291,6 @@ public class SelectQueryMainTab extends JPanel {
             throw new ValidationException(eex.getUnlabeledMessage());
         }
     }
-    
-    /**
-     * Handler to user's actions with root selection combobox
-     */
-    class RootSelectionHandler implements FocusListener, ActionListener {
-        String newName = null;
-        boolean needChangeName;
-
-        public void actionPerformed(ActionEvent ae) {
-            QueryDescriptor query = getQuery();
-            if (query != null) {
-                Entity root = (Entity) queryRoot.getModel().getSelectedItem();
-
-                if (root != null) {
-                    query.setRoot(root);
-                    
-                    if (needChangeName) { //not changed by user
-                        /*
-                         * Doing auto name change, following CAY-888 #2
-                         */
-                        String newPrefix = root.getName() + "Query";
-                        newName = newPrefix;
-                        
-                        DataMap map = mediator.getCurrentDataMap();
-                        long postfix = 1;
-                        
-                        while (map.getQueryDescriptor(newName) != null) {
-                            newName = newPrefix + (postfix++);
-                        }
-                        
-                        name.setText(newName);
-                    }
-                }
-            }
-        }
-
-        public void focusGained(FocusEvent e) {
-            //reset new name tracking
-            newName = null;
-            
-            QueryDescriptor query = getQuery();
-            if (query != null) {
-                needChangeName = hasDefaultName(query);
-            } else {
-                needChangeName = false;
-            }
-        }
-
-        public void focusLost(FocusEvent e) {
-            if (newName != null) {
-                setQueryName(newName);
-            }
-            
-            newName = null;
-            needChangeName = false;
-        }
-
-        /**
-         * @return whether specified's query name is 'default' i.e. Cayenne generated
-         * A query's name is 'default' if it starts with 'UntitledQuery' or with root name.
-         * 
-         * We cannot follow user input because tab might be opened many times
-         */
-        boolean hasDefaultName(QueryDescriptor query) {
-            String prefix = query.getRoot() == null ? "UntitledQuery" :
-                CellRenderers.asString(query.getRoot()) + "Query";
-            
-            return name.getComponent().getText().startsWith(prefix);
-        }
-    }
 
     private void setQueryComment(String text) {
         QueryDescriptor query = getQuery();


Mime
View raw message