Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Parker2014-12-30 19:25:01 -0500
committerGerrit Code Review @ Eclipse.org2015-01-13 17:04:04 -0500
commit2f739bb47953bd501c791e736f4214165feeb16a (patch)
treef2e9e82bf7fad036eec439d411de24ecf766d9c7 /org.eclipse.mylyn.reviews.ui/src
parent330f8abb043e2489291bd76f24d978dbdb03806c (diff)
downloadorg.eclipse.mylyn.reviews-2f739bb47953bd501c791e736f4214165feeb16a.tar.gz
org.eclipse.mylyn.reviews-2f739bb47953bd501c791e736f4214165feeb16a.tar.xz
org.eclipse.mylyn.reviews-2f739bb47953bd501c791e736f4214165feeb16a.zip
371428: Generalize support for active review
Change-Id: I1fe9a4e8761bb5068b0de41264d81899bfac9314 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=371428
Diffstat (limited to 'org.eclipse.mylyn.reviews.ui/src')
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ActiveReviewManager.java147
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/IActiveReviewListener.java21
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsUiPlugin.java8
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/views/ReviewExplorer.java156
4 files changed, 219 insertions, 113 deletions
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ActiveReviewManager.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ActiveReviewManager.java
new file mode 100644
index 00000000..e5d06860
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ActiveReviewManager.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.reviews.ui;
+
+import java.util.List;
+
+import org.eclipse.mylyn.reviews.core.model.IReview;
+import org.eclipse.mylyn.reviews.ui.spi.editor.AbstractReviewTaskEditorPage;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
+import org.eclipse.ui.IPageListener;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IWindowListener;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.editor.IFormPage;
+
+import com.google.common.collect.Lists;
+
+public class ActiveReviewManager {
+
+ private IReview review = null;
+
+ private TaskEditor currentPart;
+
+ private final List<IActiveReviewListener> reviewListeners = Lists.newArrayList();
+
+ private final IPartListener editorPartListener = new IPartListener() {
+ public void partOpened(IWorkbenchPart part) {
+ }
+
+ public void partDeactivated(IWorkbenchPart part) {
+ }
+
+ public void partClosed(IWorkbenchPart part) {
+ if (part == currentPart) {
+ currentPart = null;
+ setReview(null);
+ }
+ }
+
+ public void partBroughtToTop(IWorkbenchPart part) {
+ }
+
+ public void partActivated(IWorkbenchPart part) {
+ if (part instanceof TaskEditor && currentPart != part) {
+ TaskEditor editor = (TaskEditor) part;
+ IFormPage page = editor.getActivePageInstance();
+ if (page instanceof AbstractReviewTaskEditorPage) {
+ currentPart = editor;
+ AbstractReviewTaskEditorPage reviewPage = (AbstractReviewTaskEditorPage) page;
+ setReview(reviewPage.getReview());
+ }
+ }
+ }
+ };
+
+ private final IPageListener pageListener = new IPageListener() {
+
+ private IWorkbenchPage activePage;
+
+ public void pageOpened(IWorkbenchPage page) {
+ }
+
+ public void pageClosed(IWorkbenchPage page) {
+ pageActivated(null);
+ }
+
+ public void pageActivated(IWorkbenchPage page) {
+ if (page != activePage) {
+ if (activePage != null) {
+ activePage.removePartListener(editorPartListener);
+ }
+ if (page != null) {
+ page.addPartListener(editorPartListener);
+ editorPartListener.partActivated(page.getActiveEditor());
+ }
+ activePage = page;
+ }
+ }
+ };
+
+ private final IWindowListener windowListener = new IWindowListener() {
+
+ public void windowOpened(IWorkbenchWindow window) {
+ }
+
+ public void windowDeactivated(IWorkbenchWindow window) {
+ window.removePageListener(pageListener);
+ }
+
+ public void windowClosed(IWorkbenchWindow window) {
+ }
+
+ public void windowActivated(IWorkbenchWindow window) {
+ window.addPageListener(pageListener);
+ pageListener.pageActivated(window.getActivePage());
+ }
+ };
+
+ public ActiveReviewManager() {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPageListener(pageListener);
+ PlatformUI.getWorkbench().addWindowListener(windowListener);
+ windowListener.windowActivated(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+ }
+
+ public void setReview(IReview review) {
+ if (this.review != review) {
+ this.review = review;
+ if (review != null) {
+ for (IActiveReviewListener reviewListener : reviewListeners) {
+ reviewListener.reviewActivated(review);
+ }
+ } else {
+ for (IActiveReviewListener reviewListener : reviewListeners) {
+ reviewListener.reviewDeactivated();
+ }
+ }
+ }
+ }
+
+ public void addReviewListener(IActiveReviewListener listener) {
+ reviewListeners.add(listener);
+ }
+
+ public void removeReviewListener(IActiveReviewListener listener) {
+ reviewListeners.remove(listener);
+ }
+
+ public IReview getReview() {
+ return review;
+ }
+
+ public TaskEditor getCurrentPart() {
+ return currentPart;
+ }
+}
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/IActiveReviewListener.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/IActiveReviewListener.java
new file mode 100644
index 00000000..d7333cb2
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/IActiveReviewListener.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.reviews.ui;
+
+import org.eclipse.mylyn.reviews.core.model.IReview;
+
+public interface IActiveReviewListener {
+
+ void reviewActivated(IReview review);
+
+ void reviewDeactivated();
+}
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsUiPlugin.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsUiPlugin.java
index b8c89289..e8d16acf 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsUiPlugin.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsUiPlugin.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Tasktop Technologies - initial API and implementation
*********************************************************************/
@@ -22,6 +22,8 @@ public class ReviewsUiPlugin extends AbstractUIPlugin {
private static ReviewsUiPlugin plugin;
+ private ActiveReviewManager reviewManager;
+
public ReviewsUiPlugin() {
}
@@ -29,6 +31,7 @@ public class ReviewsUiPlugin extends AbstractUIPlugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ reviewManager = new ActiveReviewManager();
}
@Override
@@ -41,4 +44,7 @@ public class ReviewsUiPlugin extends AbstractUIPlugin {
return plugin;
}
+ public ActiveReviewManager getReviewManager() {
+ return reviewManager;
+ }
}
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/views/ReviewExplorer.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/views/ReviewExplorer.java
index 85329194..86f881ed 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/views/ReviewExplorer.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/views/ReviewExplorer.java
@@ -36,8 +36,10 @@ import org.eclipse.jface.viewers.TreeExpansionEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.mylyn.internal.reviews.ui.IActiveReviewListener;
import org.eclipse.mylyn.internal.reviews.ui.ReviewsImages;
import org.eclipse.mylyn.internal.reviews.ui.ReviewsUiConstants;
+import org.eclipse.mylyn.internal.reviews.ui.ReviewsUiPlugin;
import org.eclipse.mylyn.internal.reviews.ui.providers.ReviewsLabelProvider;
import org.eclipse.mylyn.internal.reviews.ui.providers.TableStyledLabelProvider;
import org.eclipse.mylyn.internal.reviews.ui.providers.TableStyledLabelProvider.TableColumnProvider;
@@ -51,9 +53,6 @@ import org.eclipse.mylyn.reviews.core.spi.ReviewsConnector;
import org.eclipse.mylyn.reviews.core.spi.remote.emf.RemoteEmfConsumer;
import org.eclipse.mylyn.reviews.core.spi.remote.emf.RemoteEmfObserver;
import org.eclipse.mylyn.reviews.core.spi.remote.review.IReviewRemoteFactoryProvider;
-import org.eclipse.mylyn.reviews.ui.spi.editor.AbstractReviewTaskEditorPage;
-import org.eclipse.mylyn.tasks.core.ITask;
-import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
@@ -63,12 +62,6 @@ import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IPageListener;
-import org.eclipse.ui.IPartListener;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.forms.editor.IFormPage;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.navigator.ICommonFilterDescriptor;
@@ -96,10 +89,6 @@ public class ReviewExplorer extends CommonNavigator {
private boolean filterForComments;
- private IReview review = null;
-
- private TaskEditor currentPart;
-
private ReviewsLabelProvider treeLabelProvider;
private ReviewsLabelProvider flatLabelProvider;
@@ -146,62 +135,6 @@ public class ReviewExplorer extends CommonNavigator {
private final Map<IReviewItemSet, RemoteItemSetContentObserver> patchSetObservers = new HashMap<IReviewItemSet, RemoteItemSetContentObserver>();
- private final IPartListener editorPartListener = new IPartListener() {
- public void partOpened(IWorkbenchPart part) {
- }
-
- public void partDeactivated(IWorkbenchPart part) {
- }
-
- public void partClosed(IWorkbenchPart part) {
- if (part == currentPart) {
- currentPart = null;
- setReview(null);
- }
- }
-
- public void partBroughtToTop(IWorkbenchPart part) {
- }
-
- public void partActivated(IWorkbenchPart part) {
- if (part instanceof TaskEditor && currentPart != part) {
- TaskEditor editor = (TaskEditor) part;
- IFormPage page = editor.getActivePageInstance();
- if (page instanceof AbstractReviewTaskEditorPage) {
- currentPart = (TaskEditor) part;
- AbstractReviewTaskEditorPage reviewPage = (AbstractReviewTaskEditorPage) page;
- setReview(reviewPage.getReview());
- updateContentDescription();
- }
- }
- }
- };
-
- private final IPageListener pageListener = new IPageListener() {
-
- private IWorkbenchPage activePage;
-
- public void pageOpened(IWorkbenchPage page) {
- }
-
- public void pageClosed(IWorkbenchPage page) {
- pageActivated(null);
- }
-
- public void pageActivated(IWorkbenchPage page) {
- if (page != activePage) {
- if (activePage != null) {
- activePage.removePartListener(editorPartListener);
- }
- if (page != null) {
- page.addPartListener(editorPartListener);
- editorPartListener.partActivated(page.getActiveEditor());
- }
- activePage = page;
- }
- }
- };
-
private IReviewRemoteFactoryProvider factoryProvider;
class ShowListAction extends Action {
@@ -460,28 +393,39 @@ public class ReviewExplorer extends CommonNavigator {
updateActivations();
- pageListener.pageActivated(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage());
- update();
+ ReviewsUiPlugin.getDefault().getReviewManager().addReviewListener(new IActiveReviewListener() {
+
+ @Override
+ public void reviewDeactivated() {
+ setReview(null);
+ }
+
+ @Override
+ public void reviewActivated(IReview review) {
+ setReview(review);
+ }
+ });
+ setReview(getActiveReview());
}
- protected void updateContentDescription() {
+ protected void update() {
String title = Messages.ReviewExplorer_No_Selection;
- if (currentPart != null && currentPart.getTaskEditorInput() != null) {
- ITask task = currentPart.getTaskEditorInput().getTask();
- title = NLS.bind(Messages.ReviewExplorer_Change_X_colon_Y, task.getTaskId(), task.getSummary());
+ if (getActiveReview() != null) {
+ title = NLS.bind(Messages.ReviewExplorer_Change_X_colon_Y, getActiveReview().getId(),
+ getActiveReview().getSubject());
}
setContentDescription(title);
- }
-
- protected void update() {
- updateContentDescription();
if (!getCommonViewer().getControl().isDisposed()) {
- refreshAction.setEnabled(review != null);
- getCommonViewer().setInput(review);
+ refreshAction.setEnabled(getActiveReview() != null);
+ getCommonViewer().setInput(getActiveReview());
getCommonViewer().refresh();
}
}
+ private IReview getActiveReview() {
+ return ReviewsUiPlugin.getDefault().getReviewManager().getReview();
+ }
+
protected void refresh() {
if (reviewConsumer != null) {
reviewConsumer.retrieve(true);
@@ -502,10 +446,10 @@ public class ReviewExplorer extends CommonNavigator {
getCommonViewer().getControl().setRedraw(false);
update();
Collection<Object> newExpanded = matchingElements(
- (ITreeContentProvider) getCommonViewer().getContentProvider(), review,
+ (ITreeContentProvider) getCommonViewer().getContentProvider(), getActiveReview(),
new HashSet<Object>(Arrays.asList(priorExpanded)), true);
Collection<Object> newSelection = matchingElements(
- (ITreeContentProvider) getCommonViewer().getContentProvider(), review,
+ (ITreeContentProvider) getCommonViewer().getContentProvider(), getActiveReview(),
new HashSet<Object>(Arrays.asList(priorSelection)), false);
getCommonViewer().setExpandedElements(newExpanded.toArray());
getCommonViewer().setSelection(new StructuredSelection(newSelection.toArray()), true);
@@ -515,29 +459,23 @@ public class ReviewExplorer extends CommonNavigator {
}
public void setReview(IReview review) {
- if (this.review != review) {
- this.review = review;
-
- for (RemoteEmfObserver<IReviewItemSet, List<IFileItem>, String, Long> observer : patchSetObservers.values()) {
- observer.dispose();
- }
- patchSetObservers.clear();
- if (reviewConsumer != null) {
- reviewConsumer.removeObserver(reviewObserver);
- }
- if (review != null) {
- ReviewsConnector connector = (ReviewsConnector) TasksUiPlugin.getConnector(review.getRepository()
- .getTaskConnectorKind());
- ReviewsClient reviewsClient = connector.getReviewClient(review.getRepository().getTaskRepository());
- factoryProvider = (IReviewRemoteFactoryProvider) reviewsClient.getFactoryProvider();
- reviewConsumer = factoryProvider.getReviewFactory().getConsumerForModel(factoryProvider.getRoot(),
- review);
- reviewConsumer.addObserver(reviewObserver);
- updatePatchSetObservers();
- }
-
- update();
+ for (RemoteEmfObserver<IReviewItemSet, List<IFileItem>, String, Long> observer : patchSetObservers.values()) {
+ observer.dispose();
+ }
+ patchSetObservers.clear();
+ if (reviewConsumer != null) {
+ reviewConsumer.removeObserver(reviewObserver);
+ }
+ if (review != null) {
+ ReviewsConnector connector = (ReviewsConnector) TasksUiPlugin.getConnector(review.getRepository()
+ .getTaskConnectorKind());
+ ReviewsClient reviewsClient = connector.getReviewClient(review.getRepository().getTaskRepository());
+ factoryProvider = (IReviewRemoteFactoryProvider) reviewsClient.getFactoryProvider();
+ reviewConsumer = factoryProvider.getReviewFactory().getConsumerForModel(factoryProvider.getRoot(), review);
+ reviewConsumer.addObserver(reviewObserver);
+ updatePatchSetObservers();
}
+ update();
}
/**
@@ -553,7 +491,7 @@ public class ReviewExplorer extends CommonNavigator {
}
public void updatePatchSetObservers() {
- for (IReviewItemSet set : review.getSets()) {
+ for (IReviewItemSet set : getActiveReview().getSets()) {
RemoteItemSetContentObserver client = patchSetObservers.get(set);
if (client == null) {
RemoteItemSetContentObserver patchSetObserver = new RemoteItemSetContentObserver();
@@ -574,9 +512,7 @@ public class ReviewExplorer extends CommonNavigator {
//Don't hang on to references
flatLabelProvider.doDispose();
treeLabelProvider.doDispose();
- currentPart = null;
setReview(null);
- pageListener.pageActivated(null);
}
public boolean isFlat() {
@@ -648,8 +584,4 @@ public class ReviewExplorer extends CommonNavigator {
updateTreeViewer(getCommonViewer());
getCommonViewer().refresh();
}
-
- public IWorkbenchPart getCurrentPart() {
- return currentPart;
- }
}

Back to the top