[hg] main-silver: Rewrite refresh mechanism, prepare for notific...

  • From: Jan Peska < >
  • To:
  • Subject: [hg] main-silver: Rewrite refresh mechanism, prepare for notific...
  • Date: Fri, 03 May 2013 03:48:03 -0700

changeset ca389b0c3688 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/ca389b0c3688
description:
        Rewrite refresh mechanism, prepare for notifications about incoming 
changes

diffstat:

 bugtracking/src/org/netbeans/modules/bugtracking/tasks/Category.java         
         |   3 +-
 
bugtracking/src/org/netbeans/modules/bugtracking/tasks/DashboardTopComponent.java
     |   1 +
 bugtracking/src/org/netbeans/modules/bugtracking/tasks/Utils.java            
         |  52 ++++++-
 
bugtracking/src/org/netbeans/modules/bugtracking/tasks/DashboardRefresher.java
        |  78 +++++++++-
 
bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/DashboardViewer.java
 |  43 +-----
 5 files changed, 126 insertions(+), 51 deletions(-)

diffs (293 lines):

diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/Category.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/Category.java
--- a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/Category.java
+++ b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/Category.java
@@ -48,7 +48,6 @@
 import java.util.Set;
 import org.netbeans.modules.bugtracking.api.Issue;
 import org.netbeans.modules.bugtracking.api.Repository;
-import org.netbeans.modules.bugtracking.tasks.dashboard.DashboardViewer;
 
 /**
  *
@@ -126,7 +125,7 @@
         if (loaded) {
             refreshTasks();
         } else {
-            DashboardViewer.getInstance().loadCategory(this);
+            Utils.loadCategory(this);
         }
     }
 
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/DashboardTopComponent.java
 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/DashboardTopComponent.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/DashboardTopComponent.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/DashboardTopComponent.java
@@ -41,6 +41,7 @@
  */
 package org.netbeans.modules.bugtracking.tasks;
 
+import org.netbeans.modules.bugtracking.tasks.dashboard.DashboardRefresher;
 import org.netbeans.modules.bugtracking.tasks.dashboard.DashboardViewer;
 import java.awt.*;
 import java.awt.event.ActionEvent;
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/Utils.java 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/Utils.java
--- a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/Utils.java
+++ b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/Utils.java
@@ -43,9 +43,14 @@
 
 import java.awt.Font;
 import java.awt.FontMetrics;
-import java.beans.PropertyChangeEvent;
 import java.io.CharConversionException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 import javax.swing.JButton;
 import javax.swing.JComponent;
 import javax.swing.event.ChangeEvent;
@@ -53,10 +58,10 @@
 import org.netbeans.modules.bugtracking.api.Issue;
 import org.netbeans.modules.bugtracking.api.Issue.Status;
 import org.netbeans.modules.bugtracking.api.Repository;
+import org.netbeans.modules.bugtracking.api.RepositoryManager;
 import org.netbeans.modules.bugtracking.api.Util;
-import org.netbeans.modules.bugtracking.tasks.DashboardTopComponent;
-import org.netbeans.modules.bugtracking.tasks.QuickSearchPanel;
 import org.netbeans.modules.bugtracking.tasks.cache.DashboardStorage;
+import org.netbeans.modules.bugtracking.tasks.cache.TaskEntry;
 import org.netbeans.modules.bugtracking.tasks.dashboard.CategoryNode;
 import org.netbeans.modules.bugtracking.tasks.dashboard.DashboardViewer;
 import org.netbeans.modules.bugtracking.tasks.dashboard.RepositoryNode;
@@ -247,4 +252,45 @@
         List<String> closedIds = 
DashboardStorage.getInstance().readClosedRepositories();
         return !closedIds.contains(repositoryId);
     }
+
+    public static void loadCategory(Category category) {
+        DashboardStorage storage = DashboardStorage.getInstance();
+        List<TaskEntry> taskEntries = 
storage.readCategory(category.getName());
+        category.setTasks(loadTasks(taskEntries));
 }
+
+    private static List<Issue> loadTasks(List<TaskEntry> taskEntries) {
+        List<Issue> tasks = new ArrayList<Issue>(taskEntries.size());
+        Map<String, List<String>> repository2Ids = new HashMap<String, 
List<String>>();
+
+        for (TaskEntry taskEntry : taskEntries) {
+            List<String> idList = 
repository2Ids.get(taskEntry.getRepositoryId());
+            if (idList == null) {
+                idList = new LinkedList<String>();
+                repository2Ids.put(taskEntry.getRepositoryId(), idList);
+            }
+            idList.add(taskEntry.getIssueId());
+        }
+        for (Entry<String, List<String>> e : repository2Ids.entrySet()) {
+            Repository repository = getRepository(e.getKey());
+            if (repository != null) {
+                List<String> l = e.getValue();
+                Issue[] issues = repository.getIssues(l.toArray(new 
String[l.size()]));
+                if (issues != null) {
+                    tasks.addAll(Arrays.asList(issues));
+                }
+            }
+        }
+        return tasks;
+    }
+
+    private static Repository getRepository(String repositoryId) {
+        List<Repository> repositories = new 
ArrayList<Repository>(RepositoryManager.getInstance().getRepositories());
+        for (Repository repository : repositories) {
+            if (repository.getId().equals(repositoryId)) {
+                return repository;
+            }
+        }
+        return null;
+    }
+}
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/DashboardRefresher.java
 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/DashboardRefresher.java
rename from 
bugtracking/src/org/netbeans/modules/bugtracking/tasks/DashboardRefresher.java
rename to 
bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/DashboardRefresher.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/DashboardRefresher.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/DashboardRefresher.java
@@ -39,9 +39,17 @@
  *
  * Portions Copyrighted 2012 Sun Microsystems, Inc.
  */
-package org.netbeans.modules.bugtracking.tasks;
+package org.netbeans.modules.bugtracking.tasks.dashboard;
 
-import org.netbeans.modules.bugtracking.tasks.dashboard.DashboardViewer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.netbeans.modules.bugtracking.api.Issue;
+import org.netbeans.modules.bugtracking.api.Query;
+import org.netbeans.modules.bugtracking.api.Repository;
+import org.netbeans.modules.bugtracking.tasks.Category;
 import org.netbeans.modules.bugtracking.tasks.settings.DashboardSettings;
 import org.openide.util.RequestProcessor;
 import org.openide.util.RequestProcessor.Task;
@@ -53,7 +61,7 @@
 public class DashboardRefresher {
 
     private static final RequestProcessor RP = new 
RequestProcessor(DashboardRefresher.class.getName());
-    private Task refreshDashboard;
+    private final Task refreshDashboard;
     private static DashboardRefresher instance;
     private boolean refreshEnabled;
     private boolean dashboardBusy = false;
@@ -71,7 +79,7 @@
                     return;
                 }
                 try {
-                    DashboardViewer.getInstance().loadData();
+                    refresh();
                 } finally {
                     setupDashboardRefresh();
                 }
@@ -112,4 +120,66 @@
             refreshDashboard.run();
         }
     }
+
+    private void refresh() {
+        List<Repository> repositories = 
DashboardViewer.getInstance().getRepositories(false);
+        List<Category> categories = 
DashboardViewer.getInstance().getCategories(false);
+        List<Issue> changedTasks = new ArrayList<Issue>();
+        for (Repository repository : repositories) {
+            for (Query query : repository.getQueries()) {
+                Collection<TaskContainer> oldTasks = 
getTaskContainers(query.getIssues());
+                query.refresh();
+                Collection<Issue> newTasks = query.getIssues();
+                changedTasks.addAll(getChangedTasks(oldTasks, newTasks));
 }
+        }
+
+        for (Category category : categories) {
+            Collection<TaskContainer> oldTasks = 
getTaskContainers(category.getTasks());
+            category.refresh();
+            List<Issue> newTasks = category.getTasks();
+            changedTasks.addAll(getChangedTasks(oldTasks, newTasks));
+        }
+
+    }
+
+    private List<Issue> getChangedTasks(Collection<TaskContainer> oldTasks, 
Collection<Issue> newTasks) {
+        List<Issue> changedTask = new ArrayList<Issue>();
+        for (Issue newTask : newTasks) {
+            boolean isChanged = true;
+            for (TaskContainer oldTask : oldTasks) {
+                if (newTask.getID().equals(oldTask.id) && 
newTask.getRepository().getId().equals(oldTask.idRepository)) {
+                    if (newTask.getStatus().equals(oldTask.status)) {
+                        isChanged = false;
+                    }
+                    break;
+                }
+            }
+            if (isChanged) {
+                changedTask.add(newTask);
+            }
+        }
+
+        return changedTask;
+    }
+    
+    private List<TaskContainer> getTaskContainers(Collection<Issue> tasks) {
+        List<TaskContainer> containers = new 
ArrayList<TaskContainer>(tasks.size());
+        for (Issue task : tasks) {
+            containers.add(new TaskContainer(task));
+        }
+        return containers;
+    }
+
+    private static class TaskContainer {
+        private final String id;
+        private final String idRepository;
+        private final Issue.Status status;
+
+        public TaskContainer(Issue issue) {
+            this.id = issue.getID();
+            this.idRepository = issue.getRepository().getId();
+            this.status = issue.getStatus();
+        }
+    }
+}
diff --git 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/DashboardViewer.java
 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/DashboardViewer.java
--- 
a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/DashboardViewer.java
+++ 
b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/dashboard/DashboardViewer.java
@@ -70,7 +70,6 @@
 import org.netbeans.modules.bugtracking.tasks.filter.DashboardFilter;
 import org.netbeans.modules.bugtracking.tasks.Category;
 import org.netbeans.modules.bugtracking.tasks.settings.DashboardSettings;
-import org.netbeans.modules.bugtracking.tasks.DashboardRefresher;
 import org.netbeans.modules.bugtracking.tasks.Utils;
 import org.netbeans.modules.team.ui.util.treelist.ColorManager;
 import org.netbeans.modules.team.ui.util.treelist.TreeList;
@@ -336,7 +335,7 @@
                 if 
(DashboardViewer.getInstance().isTaskNodeActive(taskNode)) {
                     DashboardViewer.getInstance().setActiveTaskNode(toAdd);
                 }
-                toSelect.add(taskNode);
+                toSelect.add(toAdd);
             }
             if (isTaskInFilter && !isCatInFilter) {
                 addCategoryToModel(destCategoryNode);
@@ -828,12 +827,6 @@
         }
     }
 
-    public void loadCategory(Category category) {
-        DashboardStorage storage = DashboardStorage.getInstance();
-        List<TaskEntry> taskEntries = 
storage.readCategory(category.getName());
-        category.setTasks(loadTasks(taskEntries));
-    }
-
     private void loadCategories() {
         try {
             DashboardStorage storage = DashboardStorage.getInstance();
@@ -867,40 +860,6 @@
         }
     }
 
-    private List<Issue> loadTasks(List<TaskEntry> taskEntries) {
-        List<Issue> tasks = new ArrayList<Issue>(taskEntries.size());
-        Map<String, List<String>> m = new HashMap<String, List<String>>();
-        for (TaskEntry taskEntry : taskEntries) {
-            List<String> l = m.get(taskEntry.getRepositoryId());
-            if (l == null) {
-                l = new LinkedList<String>();
-                m.put(taskEntry.getRepositoryId(), l);
-            }
-            l.add(taskEntry.getIssueId());
-        }
-        for (Entry<String, List<String>> e : m.entrySet()) {
-            Repository repository = getRepository(e.getKey());
-            if (repository != null) {
-                List<String> l = e.getValue();
-                Issue[] issues = repository.getIssues(l.toArray(new 
String[l.size()]));
-                if (issues != null) {
-                    tasks.addAll(Arrays.asList(issues));
-                }
-            }
-        }
-        return tasks;
-    }
-
-    private Repository getRepository(String repositoryId) {
-        List<Repository> repositories = new 
ArrayList<Repository>(RepositoryManager.getInstance().getRepositories());
-        for (Repository repository : repositories) {
-            if (repository.getId().equals(repositoryId)) {
-                return repository;
-            }
-        }
-        return null;
-    }
-
     private void updateRepositories(Collection<Repository> 
addedRepositories, Collection<Repository> removedRepositories) {
         synchronized (LOCK_REPOSITORIES) {
             List<RepositoryNode> toAdd = new ArrayList<RepositoryNode>();

[hg] main-silver: Rewrite refresh mechanism, prepare for notific...

Jan Peska 05/03/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 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close