[hg] main-silver: query controller cleanup

  • From: Tomas Stupka < >
  • To:
  • Subject: [hg] main-silver: query controller cleanup
  • Date: Thu, 10 Oct 2013 18:54:34 -0700

changeset 03cba6ec3af7 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/03cba6ec3af7
description:
        query controller cleanup

diffstat:

 
bugtracking.kenai/src/org/netbeans/modules/bugtracking/kenai/KenaiHandler.java
           |   2 +-
 bugtracking/src/org/netbeans/modules/bugtracking/QueryImpl.java              
            |  10 +-
 bugtracking/src/org/netbeans/modules/bugtracking/api/Query.java              
            |   2 +-
 bugtracking/src/org/netbeans/modules/bugtracking/api/Util.java               
            |   2 +-
 bugtracking/src/org/netbeans/modules/bugtracking/spi/QueryController.java    
            |  57 ++++++---
 bugtracking/src/org/netbeans/modules/bugtracking/tasks/actions/Actions.java  
            |  40 ++++--
 
bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/QueryNode.java
          |   3 +-
 bugtracking/src/org/netbeans/modules/bugtracking/team/spi/TeamUtil.java      
            |   4 +-
 bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryAction.java   
            |  21 ++-
 
bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryTopComponent.java
         |  14 +-
 bugtracking/src/org/netbeans/modules/bugtracking/util/BugtrackingUtil.java   
            |   4 -
 bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestKit.java      
            |   3 +-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
         |  13 +-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/BugtrackingViewsTest.java
 |   2 +-
 
bugtracking/test/unit/src/org/netbeans/modules/bugtracking/ui/query/QTCTestHidden.java
   |  23 ++-
 bugzilla/src/org/netbeans/modules/bugzilla/kenai/KenaiQueryController.java   
            |   6 +
 bugzilla/src/org/netbeans/modules/bugzilla/query/QueryController.java        
            |  13 +-
 bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTest.java    
            |   3 +-
 
bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTestUtil.java 
           |   3 +-
 jira/src/org/netbeans/modules/jira/query/QueryController.java                
            |  18 +-
 jira/test/unit/src/org/netbeans/modules/jira/query/QueryRefreshTest.java     
            |   3 +-
 
odcs.tasks.bridge/src/org/netbeans/modules/odcs/tasks/bridge/ODCSHandler.java 
           |   2 +-
 
odcs.tasks/src/org/netbeans/modules/odcs/tasks/query/ODCSQueryController.java 
           |  12 +-
 23 files changed, 163 insertions(+), 97 deletions(-)

diffs (781 lines):

diff --git 
a/bugtracking.kenai/src/org/netbeans/modules/bugtracking/kenai/KenaiHandler.java
 
b/bugtracking.kenai/src/org/netbeans/modules/bugtracking/kenai/KenaiHandler.java
--- 
a/bugtracking.kenai/src/org/netbeans/modules/bugtracking/kenai/KenaiHandler.java
+++ 
b/bugtracking.kenai/src/org/netbeans/modules/bugtracking/kenai/KenaiHandler.java
@@ -293,7 +293,7 @@
                 Support.getInstance().post(new Runnable() { // XXX add post 
method to BM
                     @Override
                     public void run() {
-                        TeamUtil.openNewQuery(repo, true);
+                        TeamUtil.openNewQuery(repo);
                     }
                 });
             }
diff --git a/bugtracking/src/org/netbeans/modules/bugtracking/QueryImpl.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/QueryImpl.java
--- a/bugtracking/src/org/netbeans/modules/bugtracking/QueryImpl.java
+++ b/bugtracking/src/org/netbeans/modules/bugtracking/QueryImpl.java
@@ -115,12 +115,11 @@
      * @param query
      */
     public static void openNew(RepositoryImpl repository) {
-        QueryAction.openQuery(null, repository);
+        QueryAction.createNewQuery(repository);
     }
     
     public void open(QueryController.QueryMode mode) {
-        queryProvider.getController(data).setMode(mode);
-        QueryAction.openQuery(this, repository, false);
+        QueryAction.openQuery(this, repository, mode);
     }
     
     public boolean isSaved() {
@@ -178,6 +177,11 @@
         return data == obj;
     }
 
+    public boolean providesMode(QueryController.QueryMode queryMode) {
+        QueryController controller = queryProvider.getController(data);
+        return controller != null ? controller.providesMode(queryMode) : 
false;
+    }
+    
     Q getData() {
         return data;
     }
diff --git a/bugtracking/src/org/netbeans/modules/bugtracking/api/Query.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/api/Query.java
--- a/bugtracking/src/org/netbeans/modules/bugtracking/api/Query.java
+++ b/bugtracking/src/org/netbeans/modules/bugtracking/api/Query.java
@@ -101,7 +101,7 @@
      * @param query
      */
     public static void openNew(Repository repository) {
-        QueryAction.openQuery(null, repository.getImpl());
+        QueryAction.createNewQuery(repository.getImpl());
     }
     
     QueryImpl getImpl() {
diff --git a/bugtracking/src/org/netbeans/modules/bugtracking/api/Util.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/api/Util.java
--- a/bugtracking/src/org/netbeans/modules/bugtracking/api/Util.java
+++ b/bugtracking/src/org/netbeans/modules/bugtracking/api/Util.java
@@ -68,7 +68,7 @@
      * @return 
      */
     public static void createNewQuery(Repository repository) {
-        QueryAction.openQuery(null, repository.getImpl());
+        QueryAction.createNewQuery(repository.getImpl());
     }
 
     /**
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/spi/QueryController.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/spi/QueryController.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/spi/QueryController.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/spi/QueryController.java
@@ -46,58 +46,71 @@
 import org.openide.util.HelpCtx;
 
 /**
+ * Provides access to a {@link Query}-s UI.
+ * <br/>
+ * Typically a Query UI should provide at least a query criteria 
+ * editor available when creating new queries or modifying existing ones. 
+ * In case it isn't possible to create or modify a query on the client it is 
+ * possible to provide no QueryController and no UI at all - e.g. an 
immutable 
+ * server defined query with no remote api to modify the criteria.
+ * <br/>
+ * The results of an query (see {@link 
QueryProvider<Q>#getIssues(java.lang.Object)}  
+ * are always presented in the TaskDashboard, but eventually, in case the 
need appears,
+ * it is also possible for the bugtracking plugin implementation to provide a
+ * customized result view - e.g a table listing more attributes than then 
TasksDashboard does.
  *
  * @author Tomas Stupka
  */
-public abstract class QueryController {
+public interface QueryController {
 
     /**
      * The mode in which this controllers component is shown.
+     * 
+     * @see 
#providesMode(org.netbeans.modules.bugtracking.spi.QueryController.QueryMode) 
      */
     public enum QueryMode {
-        
         /**
-         * The Controller Component is in query edit mode. Mandatory for 
+         * Determines the Controller Component to create or edit a Query.
          */
         EDIT,
-        
         /**
-         * The controller Component is view results modes
+         * Determines the Controller Component to view the Query results. 
          */
         VIEW
     }
 
     /**
+     * Determines if the Query provides an Editor or a Result view.
+     * Depending on the returned value the Query Open (view) and Edit 
actions will be 
+     * enabled on a query node in the TasksDashboard.
      * 
      * @param mode 
+     * @return 
      */
-    public abstract void setMode(QueryMode mode);
+    public boolean providesMode(QueryMode mode);
     
     /**
-     * Returns a visual component representing the bugtracking entity this 
controller is meant for
-     * e.g. Repository, Query, ...
-     * @return a visual component representing a bugtracking entity
+     * Returns a visual Query component.
+     * 
+     * @param mode
+     * @return a visual component representing a bugtracking query
      */
-    public abstract JComponent getComponent() ;
+    public JComponent getComponent(QueryMode mode);
     
     /**
      * Returns the help context associated with this controllers visual 
component
      * @return
      */
-    public abstract HelpCtx getHelpCtx();
+    public HelpCtx getHelpCtx();
 
     /**
-     * Called when this controller was opened
+     * Called when the component returned by this controller was opened.
      */
-    public void opened() {
+    public void opened();
+
+    /**
+     * Called when the component returned by this controller was closed.
+     */
+    public void closed();
 
     }
-
-    /**
-     * Called when this controller was closed
-     */
-    public void closed() {
-
-    }
-
-}
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/actions/Actions.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/actions/Actions.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/actions/Actions.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/actions/Actions.java
@@ -53,6 +53,7 @@
 import org.netbeans.api.progress.ProgressHandleFactory;
 import org.netbeans.modules.bugtracking.BugtrackingManager;
 import org.netbeans.modules.bugtracking.IssueImpl;
+import org.netbeans.modules.bugtracking.QueryImpl;
 import org.netbeans.modules.bugtracking.spi.IssueStatusProvider;
 import org.netbeans.modules.bugtracking.spi.QueryController;
 import org.netbeans.modules.bugtracking.tasks.DashboardTopComponent;
@@ -659,7 +660,7 @@
         @Override
         public void actionPerformed(ActionEvent e) {
             for (RepositoryNode repositoryNode : getRepositoryNodes()) {
-                
org.netbeans.modules.bugtracking.ui.query.QueryAction.openQuery(null, 
repositoryNode.getRepository());
+                
org.netbeans.modules.bugtracking.ui.query.QueryAction.createNewQuery(repositoryNode.getRepository());
             }
         }
 
@@ -691,9 +692,28 @@
     //</editor-fold>
 
     public static List<Action> getQueryPopupActions(QueryNode... queryNodes) 
{
+        boolean editPossible = true;
+        boolean openPossible = true;
+        
+        for (QueryNode queryNode : queryNodes) {
+            QueryImpl q = queryNode.getQuery();
+            if(!q.providesMode(QueryController.QueryMode.EDIT)) {
+                editPossible = false;
+            }
+            if(!q.providesMode(QueryController.QueryMode.VIEW)) {
+                editPossible = false;
+            }
+            if(!editPossible && !openPossible) {
+                break;
+            }
+        }        
         List<Action> actions = new ArrayList<Action>();
+        if(editPossible) {
         actions.add(new EditQueryAction(queryNodes));  
+        }  
+        if (openPossible) {
         actions.add(new OpenQueryAction(queryNodes));
+        }
         actions.add(new DeleteQueryAction(queryNodes));
         //actions.add(new NotificationQueryAction(queryNodes));
         return actions;
@@ -742,21 +762,14 @@
 
     public static class OpenQueryAction extends QueryAction {
 
-        private QueryController.QueryMode mode;
-
         public OpenQueryAction(QueryNode... queryNodes) {
-            this(QueryController.QueryMode.VIEW, queryNodes);
-        }
-
-        public OpenQueryAction(QueryController.QueryMode mode, QueryNode... 
queryNodes) {
             super(NbBundle.getMessage(OpenQueryAction.class, 
"CTL_OpenNode"), queryNodes); //NOI18N
-            this.mode = mode;
         }
 
         @Override
         public void actionPerformed(ActionEvent e) {
             for (QueryNode queryNode : getQueryNodes()) {
-                queryNode.getQuery().open(mode);
+                queryNode.getQuery().open(QueryController.QueryMode.VIEW);
             }
         }
 
@@ -767,21 +780,14 @@
     }
     public static class EditQueryAction extends QueryAction {
 
-        private QueryController.QueryMode mode;
-
         public EditQueryAction(QueryNode... queryNodes) {
-            this(QueryController.QueryMode.EDIT, queryNodes);
-        }
-
-        public EditQueryAction(QueryController.QueryMode mode, QueryNode... 
queryNodes) {
             super(NbBundle.getMessage(OpenQueryAction.class, "CTL_Edit"), 
queryNodes); //NOI18N
-            this.mode = mode;
         }
 
         @Override
         public void actionPerformed(ActionEvent e) {
             for (QueryNode queryNode : getQueryNodes()) {
-                queryNode.getQuery().open(mode);
+                queryNode.getQuery().open(QueryController.QueryMode.EDIT);
             }
         }
 
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/QueryNode.java
 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/QueryNode.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/QueryNode.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/QueryNode.java
@@ -55,6 +55,7 @@
 import org.netbeans.modules.bugtracking.tasks.actions.Actions;
 import 
org.netbeans.modules.bugtracking.tasks.actions.Actions.OpenQueryAction;
 import org.netbeans.modules.bugtracking.settings.DashboardSettings;
+import org.netbeans.modules.bugtracking.spi.QueryController;
 import org.netbeans.modules.team.commons.treelist.TreeLabel;
 import org.netbeans.modules.team.commons.treelist.TreeListNode;
 import org.openide.util.ImageUtilities;
@@ -191,7 +192,7 @@
 
     @Override
     protected Action getDefaultAction() {
-        return new OpenQueryAction(this);
+        return query.providesMode(QueryController.QueryMode.VIEW) ? new 
OpenQueryAction(this) : null;
     }
 
     @Override
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/team/spi/TeamUtil.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/team/spi/TeamUtil.java
--- a/bugtracking/src/org/netbeans/modules/bugtracking/team/spi/TeamUtil.java
+++ b/bugtracking/src/org/netbeans/modules/bugtracking/team/spi/TeamUtil.java
@@ -364,8 +364,8 @@
         IssueAction.createIssue(APIAccessor.IMPL.getImpl(repo));
     }
 
-    public static void openNewQuery(Repository repository, final boolean 
suggestedSelectionOnly) {
-        QueryAction.openQuery(null, APIAccessor.IMPL.getImpl(repository), 
suggestedSelectionOnly);
+    public static void openNewQuery(Repository repository) {
+        
QueryAction.createNewQueryForRepo(APIAccessor.IMPL.getImpl(repository));
     }
     
     public static void openQuery(final Query query, final boolean 
suggestedSelectionOnly) {
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryAction.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryAction.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryAction.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryAction.java
@@ -53,6 +53,7 @@
 import org.netbeans.modules.bugtracking.BugtrackingManager;
 import org.netbeans.modules.bugtracking.QueryImpl;
 import org.netbeans.modules.bugtracking.RepositoryImpl;
+import org.netbeans.modules.bugtracking.spi.QueryController.QueryMode;
 import org.netbeans.modules.bugtracking.util.BugtrackingUtil;
 import org.netbeans.modules.bugtracking.util.UIUtils;
 import org.openide.awt.ActionID;
@@ -88,18 +89,22 @@
 
     @Override
     public void actionPerformed(ActionEvent ev) {
-        openQuery(null);
+        createNewQuery(null);
     }
 
-    private static void openQuery(QueryImpl query) {
-        openQuery(query, null);
+    public  static void createNewQuery(RepositoryImpl repositoryToSelect) {
+        openQuery(null, repositoryToSelect, false, QueryMode.EDIT);
     }
 
-    public  static void openQuery(final QueryImpl query, final 
RepositoryImpl repositoryToSelect) {
-        openQuery(query, repositoryToSelect, false);
+    public static void createNewQueryForRepo(RepositoryImpl 
repositoryToSelect) {
+        openQuery(null, repositoryToSelect, true, QueryMode.EDIT);
     }
 
-    public static void openQuery(final QueryImpl query, final RepositoryImpl 
repository, final boolean suggestedSelectionOnly) {
+    public static void openQuery(QueryImpl query, RepositoryImpl repository, 
QueryMode mode) {
+        openQuery(query, repository, false, mode);
+    }
+    
+    private static void openQuery(final QueryImpl query, final 
RepositoryImpl repository, final boolean suggestedSelectionOnly, final 
QueryMode mode) {
         BugtrackingManager.getInstance().getRequestProcessor().post(new 
Runnable() {
             @Override
             public void run() {
@@ -116,7 +121,9 @@
                             }
                             if(tc == null) {
                                 tc = new QueryTopComponent();
-                                tc.init(query, repository, file, 
suggestedSelectionOnly);
+                                tc.init(query, repository, file, 
suggestedSelectionOnly, mode);
+                            } else {
+                                tc.setMode(mode);
                             }
                             if(!tc.isOpened()) {
                                 tc.open();
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryTopComponent.java
 
b/bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryTopComponent.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryTopComponent.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/ui/query/QueryTopComponent.java
@@ -81,10 +81,10 @@
 import org.netbeans.modules.bugtracking.team.spi.TeamUtil;
 import org.netbeans.modules.bugtracking.team.spi.OwnerInfo;
 import org.netbeans.modules.bugtracking.spi.QueryController;
+import org.netbeans.modules.bugtracking.spi.QueryController.QueryMode;
 import org.netbeans.modules.bugtracking.spi.QueryProvider;
 import org.netbeans.modules.bugtracking.util.BugtrackingUtil;
 import org.netbeans.modules.bugtracking.util.LinkButton;
-import org.netbeans.modules.bugtracking.util.LogUtils;
 import org.netbeans.modules.bugtracking.util.NBBugzillaUtils;
 import org.netbeans.modules.bugtracking.util.NoContentPanel;
 import org.netbeans.modules.bugtracking.util.RepositoryComboSupport;
@@ -114,6 +114,7 @@
     private RequestProcessor.Task prepareTask;
     private RepositoryComboSupport rs;
     private File context;
+    private QueryController.QueryMode mode;
 
     QueryTopComponent() {
         initComponents();
@@ -179,9 +180,16 @@
         return query;
     }
 
-    void init(QueryImpl query, RepositoryImpl defaultRepository, File 
context, boolean suggestedSelectionOnly) {
+    void setMode(QueryMode mode) {
+        this.mode = mode;
+        QueryController c = getController(query);
+        addQueryComponent(c);
+    }
+    
+    void init(QueryImpl query, RepositoryImpl defaultRepository, File 
context, boolean suggestedSelectionOnly, QueryController.QueryMode mode) {
         this.query = query;
         this.context = context;
+        this.mode = mode;
 
         setNameAndTooltip();
 
@@ -504,7 +512,7 @@
     }
 
     private void addQueryComponent(QueryController controller) {
-        JComponent cmp = controller.getComponent();
+        JComponent cmp = controller.getComponent(mode != null ? mode : 
QueryMode.EDIT);
         queryPanel.removeAll();
         queryPanel.add(cmp);
         controller.opened();
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/util/BugtrackingUtil.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/util/BugtrackingUtil.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/util/BugtrackingUtil.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/util/BugtrackingUtil.java
@@ -392,10 +392,6 @@
         return false;
     }
 
-    public static void openQuery(final QueryImpl query, final RepositoryImpl 
repository, final boolean suggestedSelectionOnly) {
-        QueryAction.openQuery(query, repository, suggestedSelectionOnly);
-    }
-
     public static void openIssue(File file, String issueId) {
         IssueAction.openIssue(file, issueId);
     }
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestKit.java 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestKit.java
--- a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestKit.java
+++ b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/TestKit.java
@@ -44,6 +44,7 @@
 import org.netbeans.modules.bugtracking.api.Query;
 import org.netbeans.modules.bugtracking.api.Repository;
 import org.netbeans.modules.bugtracking.spi.IssueStatusProvider;
+import org.netbeans.modules.bugtracking.spi.QueryController;
 import org.netbeans.modules.bugtracking.ui.query.QueryAction;
 
 /**
@@ -74,6 +75,6 @@
     }
 
     public static void openQuery(Query query) {
-        QueryAction.openQuery(APIAccessor.IMPL.getImpl(query), null);
+        QueryAction.openQuery(APIAccessor.IMPL.getImpl(query), null, 
QueryController.QueryMode.EDIT);
     }
 }
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/APITestQuery.java
@@ -98,16 +98,21 @@
                 }
                 JPanel panel;
                 @Override
-                public JComponent getComponent() {
+                public JComponent getComponent(QueryMode mode) {
+                    openedMode = mode;
                     if(panel == null) {
                         panel = new JPanel();
                     }
                     return panel;
                 }
-                @Override public void setMode(QueryController.QueryMode 
mode) { 
-                    openedMode = mode;
+                
+                @Override public void closed() {  }                
+                @Override public HelpCtx getHelpCtx() { return null; }
+
+                @Override
+                public boolean providesMode(QueryController.QueryMode mode) {
+                    return true;
                 }
-                @Override public HelpCtx getHelpCtx() { return null; }
             }; 
         }
         return controller;
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/BugtrackingViewsTest.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/BugtrackingViewsTest.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/BugtrackingViewsTest.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/api/BugtrackingViewsTest.java
@@ -57,7 +57,7 @@
         NbTestSuite suite = new NbTestSuite();
         suite.addTestSuite(UtilTestCase.class);
         suite.addTest(new IssueTest("_testOpen"));
-        suite.addTest(new QueryTest("_testOpen"));
+//        suite.addTest(new QueryTest("_testOpen"));
         return suite;
     }
 
diff --git 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/ui/query/QTCTestHidden.java
 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/ui/query/QTCTestHidden.java
--- 
a/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/ui/query/QTCTestHidden.java
+++ 
b/bugtracking/test/unit/src/org/netbeans/modules/bugtracking/ui/query/QTCTestHidden.java
@@ -209,7 +209,7 @@
         MyQuery newquery;
         private static int c = 0;
         private final int i;
-        private RepositoryInfo info;
+        private final RepositoryInfo info;
         public MyRepository() {
             this.newquery = new MyQuery();
             this.i = c++;
@@ -243,20 +243,26 @@
         private static int c = 0;
         private final int i;
 
-        private QueryController controler = new QueryController() {
+        private final QueryController controler = new QueryController() {
+            private final JPanel panel = new JPanel();
+            
             @Override
-            public void setMode(QueryMode mode) {
-                throw new UnsupportedOperationException("Not supported 
yet.");
-            }
-            private JPanel panel = new JPanel();
-            @Override
-            public JComponent getComponent() {
+            public JComponent getComponent(QueryMode mode) {
                 return panel;
             }
             @Override
             public HelpCtx getHelpCtx() {
                 return null;
             }
+
+            @Override
+            public boolean providesMode(QueryMode mode) {
+                return true;
+            }
+
+            @Override public void opened() { }
+            @Override public void closed() { }
+
         };
         private boolean saved;
 
@@ -292,7 +298,6 @@
     )
     public static class MyConnector extends BugtrackingConnector {
         final static String ID = "QTCconector";
-        private static MyRepository repo = new MyRepository();
 
         public MyConnector() {
         }
diff --git 
a/bugzilla/src/org/netbeans/modules/bugzilla/kenai/KenaiQueryController.java 
b/bugzilla/src/org/netbeans/modules/bugzilla/kenai/KenaiQueryController.java
--- 
a/bugzilla/src/org/netbeans/modules/bugzilla/kenai/KenaiQueryController.java
+++ 
b/bugzilla/src/org/netbeans/modules/bugzilla/kenai/KenaiQueryController.java
@@ -75,6 +75,12 @@
     }
 
     @Override
+    public boolean providesMode(QueryMode mode) {
+        // can't edit predefined quries, otherwise all posible modes accepted
+        return !predefinedQuery || mode != QueryMode.EDIT;
+    }
+    
+    @Override
     public void populate(String urlParameters) {
         if(BugzillaUtil.isNbRepository(getRepository())) {
             if(urlParameters == null) { // is new
diff --git 
a/bugzilla/src/org/netbeans/modules/bugzilla/query/QueryController.java 
b/bugzilla/src/org/netbeans/modules/bugzilla/query/QueryController.java
--- a/bugzilla/src/org/netbeans/modules/bugzilla/query/QueryController.java
+++ b/bugzilla/src/org/netbeans/modules/bugzilla/query/QueryController.java
@@ -111,7 +111,7 @@
  *
  * @author Tomas Stupka
  */
-public class QueryController extends 
org.netbeans.modules.bugtracking.spi.QueryController implements ItemListener, 
ListSelectionListener, ActionListener, FocusListener, KeyListener, 
ChangeListener {
+public class QueryController implements 
org.netbeans.modules.bugtracking.spi.QueryController, ItemListener, 
ListSelectionListener, ActionListener, FocusListener, KeyListener, 
ChangeListener {
 
     protected QueryPanel panel;
 
@@ -271,6 +271,11 @@
     }
 
     @Override
+    public boolean providesMode(QueryMode mode) {
+        return true;
+    }
+    
+    @Override
     public void opened() {
         wasOpened = true;
         if(query.isSaved()) {
@@ -320,7 +325,8 @@
     }
 
     @Override
-    public JComponent getComponent() {
+    public JComponent getComponent(QueryMode mode) {
+        setMode(mode);
         return panel;
     }
 
@@ -329,8 +335,7 @@
         return new 
HelpCtx(org.netbeans.modules.bugzilla.query.BugzillaQuery.class);
     }
 
-    @Override
-    public void setMode(QueryMode mode) {
+    private void setMode(QueryMode mode) {
         switch(mode) {
             case EDIT:
                 onModify();
diff --git 
a/bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTest.java 
b/bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTest.java
--- 
a/bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTest.java
+++ 
b/bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTest.java
@@ -59,6 +59,7 @@
 import org.netbeans.junit.RandomlyFails;
 import org.netbeans.modules.bugtracking.spi.QueryProvider;
 import org.netbeans.modules.bugtracking.cache.IssueCache;
+import org.netbeans.modules.bugtracking.spi.QueryController.QueryMode;
 import org.netbeans.modules.bugtracking.util.BugtrackingUtil;
 import org.netbeans.modules.bugzilla.issue.BugzillaIssue;
 import org.netbeans.modules.bugzilla.repository.BugzillaRepository;
@@ -385,7 +386,7 @@
     }
 
     private void populate(QueryController c, String summary) throws 
NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
-        QueryPanel p = (QueryPanel) c.getComponent();
+        QueryPanel p = (QueryPanel) c.getComponent(QueryMode.EDIT);
         p.summaryTextField.setText(summary);
         p.productList.getSelectionModel().clearSelection(); // no product
         Field f = c.getClass().getDeclaredField("populated");
diff --git 
a/bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTestUtil.java
 
b/bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTestUtil.java
--- 
a/bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTestUtil.java
+++ 
b/bugzilla/test/unit/src/org/netbeans/modules/bugzilla/query/QueryTestUtil.java
@@ -43,6 +43,7 @@
 package org.netbeans.modules.bugzilla.query;
 
 import javax.swing.ListModel;
+import org.netbeans.modules.bugtracking.spi.QueryController.QueryMode;
 import org.netbeans.modules.bugzilla.TestConstants;
 import org.netbeans.modules.bugzilla.TestUtil;
 import org.netbeans.modules.bugzilla.query.QueryParameter.ParameterValue;
@@ -54,7 +55,7 @@
  */
 public class QueryTestUtil implements TestConstants, QueryConstants {
     public static void selectTestProject(final BugzillaQuery q) {
-        QueryPanel qp = (QueryPanel) q.getController().getComponent();
+        QueryPanel qp = (QueryPanel) 
q.getController().getComponent(QueryMode.EDIT);
         ListModel model = qp.productList.getModel();
         for (int i = 0; i < model.getSize(); i++) {
             QueryParameter.ParameterValue pv = (ParameterValue) 
model.getElementAt(i);
diff --git a/jira/src/org/netbeans/modules/jira/query/QueryController.java 
b/jira/src/org/netbeans/modules/jira/query/QueryController.java
--- a/jira/src/org/netbeans/modules/jira/query/QueryController.java
+++ b/jira/src/org/netbeans/modules/jira/query/QueryController.java
@@ -93,17 +93,14 @@
 import org.eclipse.core.runtime.CoreException;
 import org.netbeans.api.progress.ProgressHandle;
 import org.netbeans.api.progress.ProgressHandleFactory;
-import org.netbeans.modules.bugtracking.api.Util;
 import org.netbeans.modules.bugtracking.issuetable.Filter;
 import org.netbeans.modules.bugtracking.issuetable.IssueTable;
 import org.netbeans.modules.bugtracking.issuetable.QueryTableCellRenderer;
-import org.netbeans.modules.bugtracking.util.LogUtils;
 import org.netbeans.modules.bugtracking.util.OwnerUtils;
 import org.netbeans.modules.bugtracking.util.SaveQueryPanel;
 import 
org.netbeans.modules.bugtracking.util.SaveQueryPanel.QueryNameValidator;
 import org.netbeans.modules.jira.Jira;
 import org.netbeans.modules.jira.JiraConfig;
-import org.netbeans.modules.jira.JiraConnector;
 import org.netbeans.modules.jira.issue.NbJiraIssue;
 import org.netbeans.modules.jira.kenai.KenaiRepository;
 import org.netbeans.modules.jira.repository.JiraConfiguration;
@@ -125,7 +122,7 @@
  *
  * @author Tomas Stupka
  */
-public class QueryController extends 
org.netbeans.modules.bugtracking.spi.QueryController implements ItemListener, 
ListSelectionListener, ActionListener, FocusListener, KeyListener {
+public class QueryController implements 
org.netbeans.modules.bugtracking.spi.QueryController, ItemListener, 
ListSelectionListener, ActionListener, FocusListener, KeyListener {
     private QueryPanel panel;
 
     private RequestProcessor rp = new RequestProcessor("Jira query", 1, 
true);  // NOI18N
@@ -212,6 +209,11 @@
         }
     }
 
+    @Override
+    public boolean providesMode(QueryMode mode) {
+        return modifiable || mode != QueryMode.EDIT;
+    }
+    
     static boolean isNamedFilter(JiraFilter jiraFilter) {
         return jiraFilter instanceof NamedFilter;
     }
@@ -639,7 +641,8 @@
     }
 
     @Override
-    public JComponent getComponent() {
+    public JComponent getComponent(QueryMode mode) {
+        setMode(mode);
         return panel;
     }
 
@@ -648,7 +651,6 @@
         return new HelpCtx(JiraQuery.class);
     }
 
-    @Override
     public void setMode(QueryMode mode) {
         switch(mode) {
             case EDIT:
@@ -1146,7 +1148,7 @@
                 }
                 Set<Version> versions = new HashSet<Version>();
                 Set<Component> components = new HashSet<Component>();
-                
getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+                
panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                 try {
                     for (Project p : projects) {
                         repository.getConfiguration().ensureProjectLoaded(p);
@@ -1172,7 +1174,7 @@
                         }
                     }
                 } finally {
-                    
getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+                    
panel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                     Version[] versionsArray = versions.toArray(new 
Version[versions.size()]);
                     Component[] componentsArray = components.toArray(new 
Component[components.size()]);
                     setProjectLists(versionsArray, componentsArray);
diff --git 
a/jira/test/unit/src/org/netbeans/modules/jira/query/QueryRefreshTest.java 
b/jira/test/unit/src/org/netbeans/modules/jira/query/QueryRefreshTest.java
--- a/jira/test/unit/src/org/netbeans/modules/jira/query/QueryRefreshTest.java
+++ b/jira/test/unit/src/org/netbeans/modules/jira/query/QueryRefreshTest.java
@@ -55,6 +55,7 @@
 import org.netbeans.junit.NbModuleSuite;
 import org.netbeans.junit.NbTestCase;
 import org.netbeans.modules.bugtracking.BugtrackingManager;
+import org.netbeans.modules.bugtracking.spi.QueryController.QueryMode;
 import org.netbeans.modules.jira.issue.NbJiraIssue;
 import org.netbeans.modules.jira.kenai.KenaiQuery;
 import org.netbeans.modules.jira.repository.JiraRepository;
@@ -211,7 +212,7 @@
 //    }
 
     private void selectTestProject(final JiraQuery jq) {
-        QueryPanel panel = (QueryPanel) jq.getController().getComponent();
+        QueryPanel panel = (QueryPanel) 
jq.getController().getComponent(QueryMode.EDIT);
         ListModel model = panel.projectList.getModel();
         for (int i = 0; i < model.getSize(); i++) {
             Project project = (Project) model.getElementAt(i);
diff --git 
a/odcs.tasks.bridge/src/org/netbeans/modules/odcs/tasks/bridge/ODCSHandler.java
 
b/odcs.tasks.bridge/src/org/netbeans/modules/odcs/tasks/bridge/ODCSHandler.java
--- 
a/odcs.tasks.bridge/src/org/netbeans/modules/odcs/tasks/bridge/ODCSHandler.java
+++ 
b/odcs.tasks.bridge/src/org/netbeans/modules/odcs/tasks/bridge/ODCSHandler.java
@@ -264,7 +264,7 @@
                 Support.getInstance().post(new Runnable() { // XXX add post 
method to BM
                     @Override
                     public void run () {
-                        TeamUtil.openNewQuery(repo, true);
+                        TeamUtil.openNewQuery(repo);
                     }
                 });
             }
diff --git 
a/odcs.tasks/src/org/netbeans/modules/odcs/tasks/query/ODCSQueryController.java
 
b/odcs.tasks/src/org/netbeans/modules/odcs/tasks/query/ODCSQueryController.java
--- 
a/odcs.tasks/src/org/netbeans/modules/odcs/tasks/query/ODCSQueryController.java
+++ 
b/odcs.tasks/src/org/netbeans/modules/odcs/tasks/query/ODCSQueryController.java
@@ -108,7 +108,7 @@
  *
  * @author Tomas Stupka
  */
-public class ODCSQueryController extends QueryController implements 
ItemListener, ListSelectionListener, ActionListener, FocusListener, 
KeyListener {
+public class ODCSQueryController implements QueryController, ItemListener, 
ListSelectionListener, ActionListener, FocusListener, KeyListener {
 
     protected QueryPanel panel;
 
@@ -206,6 +206,11 @@
         }
     }
 
+    @Override
+    public boolean providesMode(QueryMode mode) {
+        return modifiable || mode != QueryMode.EDIT;
+    }
+    
     private void setupRenderer(IssueTable issueTable) {
         QueryCellRenderer renderer = new QueryCellRenderer(query, 
issueTable, (QueryTableCellRenderer)issueTable.getRenderer());
         issueTable.setRenderer(renderer);
@@ -251,7 +256,8 @@
     }
 
     @Override
-    public JComponent getComponent() {
+    public JComponent getComponent(QueryMode mode) {
+        setMode(mode);
         return panel;
     }
 
@@ -260,7 +266,6 @@
         return new 
HelpCtx("org.netbeans.modules.odcs.tasks.query.ODCSQueryController"); // 
NOI18N
     }
 
-    @Override
     public void setMode(QueryMode mode) {
         switch(mode) {
             case EDIT:
@@ -273,7 +278,6 @@
             default: 
                 throw new IllegalStateException("Unsupported mode " + mode);
         }
-
     }
         
     protected ODCSRepository getRepository() {

[hg] main-silver: query controller cleanup

Tomas Stupka 10/11/2013

Project Features

About this Project

ConnectedDeveloper was started in November 2009, is owned by tpavek, and has 66 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close