Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2007-06-26 05:07:37 +0000
committermkersten2007-06-26 05:07:37 +0000
commitf56be02d230b50a3ca1eb67394b2d7038da7213f (patch)
tree8babae7655a14c830b687837715d7c882c975746
parent019cdc6bae07f735fbb1e9d0089c94378f518c48 (diff)
downloadorg.eclipse.mylyn.tasks-f56be02d230b50a3ca1eb67394b2d7038da7213f.tar.gz
org.eclipse.mylyn.tasks-f56be02d230b50a3ca1eb67394b2d7038da7213f.tar.xz
org.eclipse.mylyn.tasks-f56be02d230b50a3ca1eb67394b2d7038da7213f.zip
RESOLVED - bug 193059: switch task working set to match active task
https://bugs.eclipse.org/bugs/show_bug.cgi?id=193059
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskWorkingSetAction.java181
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/ToggleAllWorkingSetsAction.java59
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/ToggleWorkingSetAction.java90
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java4
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/workingsets/TaskWorkingSetUpdater.java96
5 files changed, 260 insertions, 170 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskWorkingSetAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskWorkingSetAction.java
index 9ba305f8d..f4ab72aef 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskWorkingSetAction.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/TaskWorkingSetAction.java
@@ -20,8 +20,6 @@ import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.bindings.keys.IKeyLookup;
-import org.eclipse.jface.bindings.keys.KeyLookupFactory;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -32,6 +30,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
+import org.eclipse.mylyn.internal.tasks.ui.workingsets.TaskWorkingSetUpdater;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -62,8 +61,6 @@ public class TaskWorkingSetAction extends Action implements IMenuCreator {
public static final String LABEL_SETS_NONE = "All";
- public static String ID_TASK_WORKING_SET = "org.eclipse.mylyn.tasks.ui.workingSet";
-
public static String TASK_WORKING_SET_TEXT_LABEL = "Select and Edit Working Sets";
private Menu dropDownMenu = null;
@@ -104,10 +101,10 @@ public class TaskWorkingSetAction extends Action implements IMenuCreator {
@SuppressWarnings("unchecked")
private void addActionsToMenu() {
- IWorkingSet[] workingSets = getAllWorkingSets();
+ IWorkingSet[] workingSets = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
if (doTaskWorkingSetsExist()) {
- ActionContributionItem itemAll = new ActionContributionItem(new ToggleAllWorkingSetsAction());
+ ActionContributionItem itemAll = new ActionContributionItem(new ToggleAllWorkingSetsAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()));
// ActionContributionItem itemNone = new ActionContributionItem(new ToggleNoWorkingSetsAction());
List<IWorkingSet> sortedWorkingSets = Arrays.asList(workingSets);
@@ -116,7 +113,7 @@ public class TaskWorkingSetAction extends Action implements IMenuCreator {
Iterator<IWorkingSet> iter = sortedWorkingSets.iterator();
while (iter.hasNext()) {
IWorkingSet workingSet = iter.next();
- if (workingSet != null && workingSet.getId().equalsIgnoreCase(ID_TASK_WORKING_SET)) {
+ if (workingSet != null && workingSet.getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
ActionContributionItem itemSet = new ActionContributionItem(new ToggleWorkingSetAction(workingSet));
itemSet.fill(dropDownMenu, -1);
}
@@ -131,58 +128,10 @@ public class TaskWorkingSetAction extends Action implements IMenuCreator {
editItem.fill(dropDownMenu, -1);
}
- private IWorkbenchWindow getWindow() {
- return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- }
-
- private IWorkingSet[] getAllWorkingSets() {
- return PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
- }
-
- private IWorkingSet[] getEnabledSets() {
- return getWindow().getActivePage().getWorkingSets();
- }
-
- private boolean isWorkingSetEnabled(IWorkingSet set) {
- IWorkingSet[] enabledSets = getEnabledSets();
- for (int i = 0; i < enabledSets.length; i++) {
- if (enabledSets[i].equals(set)) {
- return true;
- }
- }
- return false;
- }
-
- private boolean isOnlyTaskWorkingSetEnabled(IWorkingSet set) {
- if (!isWorkingSetEnabled(set)) {
- return false;
- }
-
- IWorkingSet[] enabledSets = getEnabledSets();
- for (int i = 0; i < enabledSets.length; i++) {
- if (!enabledSets[i].equals(set) && enabledSets[i].getId().equalsIgnoreCase(ID_TASK_WORKING_SET)) {
- return false;
- }
- }
- return true;
- }
-
- private boolean areNoTaskWorkingSetsEnabled() {
- IWorkingSet[] workingSets = getAllWorkingSets();
- for (IWorkingSet workingSet : workingSets) {
- if (workingSet != null && workingSet.getId().equalsIgnoreCase(ID_TASK_WORKING_SET)) {
- if (isWorkingSetEnabled(workingSet)) {
- return false;
- }
- }
- }
- return true;
- }
-
private boolean doTaskWorkingSetsExist() {
- IWorkingSet[] workingSets = getAllWorkingSets();
+ IWorkingSet[] workingSets = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
for (IWorkingSet workingSet : workingSets) {
- if (workingSet != null && workingSet.getId().equalsIgnoreCase(ID_TASK_WORKING_SET)) {
+ if (workingSet != null && workingSet.getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
return true;
}
}
@@ -192,8 +141,8 @@ public class TaskWorkingSetAction extends Action implements IMenuCreator {
@Override
public void run() {
String[] ids = new String[1];
- ids[0] = ID_TASK_WORKING_SET;
- ConfigureWindowWorkingSetsDialog dialog = new ConfigureWindowWorkingSetsDialog(getWindow(), ids);
+ ids[0] = TaskWorkingSetUpdater.ID_TASK_WORKING_SET;
+ ConfigureWindowWorkingSetsDialog dialog = new ConfigureWindowWorkingSetsDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), ids);
dialog.open();
}
@@ -204,7 +153,7 @@ public class TaskWorkingSetAction extends Action implements IMenuCreator {
public void run(IWorkingSet editWorkingSet) {
IWorkingSetManager manager = WorkbenchPlugin.getDefault().getWorkingSetManager();
IWorkingSetEditWizard wizard = manager.createWorkingSetEditWizard(editWorkingSet);
- WizardDialog dialog = new WizardDialog(getWindow().getShell(), wizard);
+ WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
// dialog.create();
dialog.open();
@@ -232,31 +181,6 @@ public class TaskWorkingSetAction extends Action implements IMenuCreator {
}
// TODO: remove?
- protected class ToggleAllWorkingSetsAction extends Action {
-
- ToggleAllWorkingSetsAction() {
- super("Show All", IAction.AS_CHECK_BOX);
- setChecked(areNoTaskWorkingSetsEnabled());
- }
-
- @Override
- public void runWithEvent(Event event) {
- Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(getEnabledSets()));
-
- Set<IWorkingSet> tempList = new HashSet<IWorkingSet>();
- Iterator<IWorkingSet> iter = newList.iterator();
- while (iter.hasNext()) {
- IWorkingSet workingSet = iter.next();
- if (workingSet != null && workingSet.getId().equalsIgnoreCase(ID_TASK_WORKING_SET)) {
- tempList.add(workingSet);
- }
- }
- newList.removeAll(tempList);
- getWindow().getActivePage().setWorkingSets(newList.toArray(new IWorkingSet[newList.size()]));
- }
- }
-
- // TODO: remove?
protected class ToggleEnableAllSetsAction extends Action {
ToggleEnableAllSetsAction() {
@@ -267,103 +191,28 @@ public class TaskWorkingSetAction extends Action implements IMenuCreator {
@Override
public void runWithEvent(Event event) {
- Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(getEnabledSets()));
+ Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(TaskWorkingSetUpdater.getEnabledSets()));
Set<IWorkingSet> tempList = new HashSet<IWorkingSet>();
Iterator<IWorkingSet> iter = newList.iterator();
while (iter.hasNext()) {
IWorkingSet workingSet = iter.next();
- if (workingSet != null && workingSet.getId().equalsIgnoreCase(ID_TASK_WORKING_SET)) {
+ if (workingSet != null && workingSet.getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
tempList.add(workingSet);
}
}
newList.removeAll(tempList);
if (isChecked()) {
- IWorkingSet[] allWorkingSets = getAllWorkingSets();
+ IWorkingSet[] allWorkingSets = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
for (IWorkingSet workingSet : allWorkingSets) {
- if (workingSet != null && workingSet.getId().equalsIgnoreCase(ID_TASK_WORKING_SET)) {
+ if (workingSet != null && workingSet.getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
newList.add(workingSet);
}
}
}
- getWindow().getActivePage().setWorkingSets(newList.toArray(new IWorkingSet[newList.size()]));
- }
-
- }
-
- private class ToggleWorkingSetAction extends Action {
- private IWorkingSet set;
-
- ToggleWorkingSetAction(IWorkingSet set) {
- super(set.getLabel(), IAction.AS_CHECK_BOX);
- setImageDescriptor(set.getImageDescriptor());
- this.set = set;
- setChecked(isWorkingSetEnabled(set));
- }
-
-// public void runWithEvent(Event event) {
-//
-// Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(getWindow().getActivePage()
-// .getWorkingSets()));
-//
-// if (isChecked()) {
-// // if the primary modifier key is down then clear the list
-// // first. this makes the selection exclusive rather than
-// // additive.
-// boolean modified = (event.stateMask & KeyLookupFactory.getDefault().formalModifierLookup(
-// IKeyLookup.M1_NAME)) != 0;
-//
-// if (modified)
-// newList.clear();
-// newList.add(set);
-// } else {
-// newList.remove(set);
-// }
-//
-// getWindow().getActivePage()
-// .setWorkingSets((IWorkingSet[]) newList.toArray(new IWorkingSet[newList.size()]));
-// }
-
- @Override
- public void runWithEvent(Event event) {
- Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(getEnabledSets()));
-
- boolean modified = (event.stateMask & KeyLookupFactory.getDefault()
- .formalModifierLookup(IKeyLookup.M1_NAME)) != 0;
-
- if (!modified) {
- // Default behavior is to act as a radio button.
- Set<IWorkingSet> tempList = new HashSet<IWorkingSet>();
- Iterator<IWorkingSet> iter = newList.iterator();
- while (iter.hasNext()) {
- IWorkingSet workingSet = iter.next();
- if (workingSet != null && workingSet.getId().equalsIgnoreCase(ID_TASK_WORKING_SET)) {
- tempList.add(workingSet);
- }
- }
- newList.removeAll(tempList);
-
- if (isChecked()) {
- newList.add(set);
- } else {
- // If multiples were previously selected, make this action active
- if (!isOnlyTaskWorkingSetEnabled(set)) {
- newList.add(set);
- }
- }
-
- } else {
- // If modifier key is pressed, de/selections are additive.
- if (isChecked()) {
- newList.add(set);
- } else {
- newList.remove(set);
- }
- }
-
- getWindow().getActivePage().setWorkingSets(newList.toArray(new IWorkingSet[newList.size()]));
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setWorkingSets(newList.toArray(new IWorkingSet[newList.size()]));
}
}
@@ -449,7 +298,7 @@ public class TaskWorkingSetAction extends Action implements IMenuCreator {
@Override
protected void okPressed() {
- Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(getEnabledSets()));
+ Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(TaskWorkingSetUpdater.getEnabledSets()));
Set<IWorkingSet> tempList = new HashSet<IWorkingSet>();
for (IWorkingSet workingSet : newList) {
for (String id : taskWorkingSetIds) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/ToggleAllWorkingSetsAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/ToggleAllWorkingSetsAction.java
new file mode 100644
index 000000000..06f3db17f
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/ToggleAllWorkingSetsAction.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 University Of British Columbia 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:
+ * University Of British Columbia - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui.actions;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.mylyn.internal.tasks.ui.workingsets.TaskWorkingSetUpdater;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkingSet;
+
+/**
+ * @author Mik Kersten
+ */
+public class ToggleAllWorkingSetsAction extends Action {
+
+ private IWorkbenchWindow window;
+
+ public ToggleAllWorkingSetsAction(IWorkbenchWindow window) {
+ super("Show All", IAction.AS_CHECK_BOX);
+ super.setChecked(TaskWorkingSetUpdater.areNoTaskWorkingSetsEnabled());
+ this.window = window;
+ }
+
+ @Override
+ public void run() {
+ Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(TaskWorkingSetUpdater.getEnabledSets()));
+
+ Set<IWorkingSet> tempList = new HashSet<IWorkingSet>();
+ Iterator<IWorkingSet> iter = newList.iterator();
+ while (iter.hasNext()) {
+ IWorkingSet workingSet = iter.next();
+ if (workingSet != null && workingSet.getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
+ tempList.add(workingSet);
+ }
+ }
+ newList.removeAll(tempList);
+ window.getActivePage().setWorkingSets(newList.toArray(new IWorkingSet[newList.size()]));
+ }
+
+ @Override
+ public void runWithEvent(Event event) {
+ run();
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/ToggleWorkingSetAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/ToggleWorkingSetAction.java
new file mode 100644
index 000000000..a826d020a
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/ToggleWorkingSetAction.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 University Of British Columbia 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:
+ * University Of British Columbia - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui.actions;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.bindings.keys.IKeyLookup;
+import org.eclipse.jface.bindings.keys.KeyLookupFactory;
+import org.eclipse.mylyn.internal.tasks.ui.workingsets.TaskWorkingSetUpdater;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author Mik Kersten
+ */
+public class ToggleWorkingSetAction extends Action {
+
+ private IWorkingSet workingSet;
+
+ public ToggleWorkingSetAction(IWorkingSet set) {
+ super(set.getLabel(), IAction.AS_CHECK_BOX);
+ setImageDescriptor(set.getImageDescriptor());
+ this.workingSet = set;
+ setChecked(TaskWorkingSetUpdater.isWorkingSetEnabled(set));
+ }
+
+ @Override
+ public void run() {
+ runWithEvent(null);
+ }
+
+ @Override
+ public void runWithEvent(Event event) {
+ Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(TaskWorkingSetUpdater.getEnabledSets()));
+
+ boolean modified = false;
+ if (event != null) {
+ modified = (event.stateMask & KeyLookupFactory.getDefault().formalModifierLookup(IKeyLookup.M1_NAME)) != 0;
+ }
+
+ if (!modified) {
+ // Default behavior is to act as a radio button.
+ Set<IWorkingSet> tempList = new HashSet<IWorkingSet>();
+ Iterator<IWorkingSet> iter = newList.iterator();
+ while (iter.hasNext()) {
+ IWorkingSet workingSet = iter.next();
+ if (workingSet != null
+ && workingSet.getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
+ tempList.add(workingSet);
+ }
+ }
+ newList.removeAll(tempList);
+
+ if (isChecked()) {
+ newList.add(workingSet);
+ } else {
+ // If multiples were previously selected, make this action active
+ if (!TaskWorkingSetUpdater.isOnlyTaskWorkingSetEnabled(workingSet)) {
+ newList.add(workingSet);
+ }
+ }
+ } else {
+ // If modifier key is pressed, de/selections are additive.
+ if (isChecked()) {
+ newList.add(workingSet);
+ } else {
+ newList.remove(workingSet);
+ }
+ }
+
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setWorkingSets(
+ newList.toArray(new IWorkingSet[newList.size()]));
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
index 948f648d6..f6e7559d0 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
@@ -86,9 +86,9 @@ import org.eclipse.mylyn.internal.tasks.ui.actions.SynchronizeAutomaticallyActio
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskActivateAction;
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskDeactivateAction;
import org.eclipse.mylyn.internal.tasks.ui.actions.TaskListElementPropertiesAction;
-import org.eclipse.mylyn.internal.tasks.ui.actions.TaskWorkingSetAction;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListTableSorter.SortByIndex;
import org.eclipse.mylyn.internal.tasks.ui.wizards.NewLocalTaskWizard;
+import org.eclipse.mylyn.internal.tasks.ui.workingsets.TaskWorkingSetUpdater;
import org.eclipse.mylyn.monitor.core.StatusHandler;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery;
import org.eclipse.mylyn.tasks.core.AbstractTask;
@@ -1775,7 +1775,7 @@ public class TaskListView extends ViewPart implements IPropertyChangeListener {
.getWorkingSets()));
Set<IWorkingSet> tasksSets = new HashSet<IWorkingSet>(allSets);
for (IWorkingSet workingSet : allSets) {
- if (!workingSet.getId().equalsIgnoreCase(TaskWorkingSetAction.ID_TASK_WORKING_SET)) {
+ if (!workingSet.getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
tasksSets.remove(workingSet);
}
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/workingsets/TaskWorkingSetUpdater.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/workingsets/TaskWorkingSetUpdater.java
index 43aa2a173..2e2eb565f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/workingsets/TaskWorkingSetUpdater.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/workingsets/TaskWorkingSetUpdater.java
@@ -10,6 +10,7 @@ package org.eclipse.mylyn.internal.tasks.ui.workingsets;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -18,6 +19,8 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
+import org.eclipse.mylyn.internal.tasks.ui.actions.ToggleAllWorkingSetsAction;
+import org.eclipse.mylyn.internal.tasks.ui.actions.ToggleWorkingSetAction;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryQuery;
import org.eclipse.mylyn.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.AbstractTaskContainer;
@@ -27,6 +30,7 @@ import org.eclipse.mylyn.tasks.core.TaskContainerDelta;
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetUpdater;
+import org.eclipse.ui.PlatformUI;
/**
* @author Eugene Kuleshov
@@ -34,13 +38,15 @@ import org.eclipse.ui.IWorkingSetUpdater;
*/
public class TaskWorkingSetUpdater implements IWorkingSetUpdater, ITaskListChangeListener, ITaskActivityListener {
+ public static String ID_TASK_WORKING_SET = "org.eclipse.mylyn.tasks.ui.workingSet";
+
private List<IWorkingSet> workingSets = new ArrayList<IWorkingSet>();
public TaskWorkingSetUpdater() {
TasksUiPlugin.getTaskListManager().getTaskList().addChangeListener(this);
TasksUiPlugin.getTaskListManager().addActivityListener(this);
}
-
+
public void dispose() {
TasksUiPlugin.getTaskListManager().getTaskList().removeChangeListener(this);
TasksUiPlugin.getTaskListManager().removeActivityListener(this);
@@ -120,7 +126,50 @@ public class TaskWorkingSetUpdater implements IWorkingSetUpdater, ITaskListChang
}
public void taskActivated(AbstractTask task) {
-
+ Set<AbstractTaskContainer> taskContainers = new HashSet<AbstractTaskContainer>(
+ TasksUiPlugin.getTaskListManager().getTaskList().getQueriesForHandle(task.getHandleIdentifier()));
+ taskContainers.addAll(task.getParentContainers());
+
+ Set<AbstractTaskContainer> allActiveWorkingSetContainers = new HashSet<AbstractTaskContainer>();
+ for (IWorkingSet workingSet : PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getActivePage()
+ .getWorkingSets()) {
+ ArrayList<IAdaptable> elements = new ArrayList<IAdaptable>(Arrays.asList(workingSet.getElements()));
+ for (IAdaptable adaptable : elements) {
+ if (adaptable instanceof AbstractTaskContainer) {
+ allActiveWorkingSetContainers.add((AbstractTaskContainer) adaptable);
+ }
+ }
+ }
+ boolean isContained = false;
+ for (AbstractTaskContainer taskContainer : allActiveWorkingSetContainers) {
+ if (taskContainers.contains(taskContainer)) {
+ isContained = true;
+ break;
+ }
+ }
+
+ ;
+ if (!isContained) {
+ IWorkingSet matchingWorkingSet = null;
+ for (IWorkingSet workingSet : PlatformUI.getWorkbench().getWorkingSetManager().getAllWorkingSets()) {
+ ArrayList<IAdaptable> elements = new ArrayList<IAdaptable>(Arrays.asList(workingSet.getElements()));
+ for (IAdaptable adaptable : elements) {
+ if (adaptable instanceof AbstractTaskContainer) {
+ if (((AbstractTaskContainer)adaptable).contains(task.getHandleIdentifier())) {
+ matchingWorkingSet = workingSet;
+ }
+ }
+ }
+ }
+
+ if (matchingWorkingSet != null) {
+ new ToggleWorkingSetAction(matchingWorkingSet).run();
+ } else {
+ new ToggleAllWorkingSetsAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run();
+ }
+ }
}
public void taskDeactivated(AbstractTask task) {
@@ -130,4 +179,47 @@ public class TaskWorkingSetUpdater implements IWorkingSetUpdater, ITaskListChang
public void taskListRead() {
// ignore
}
+
+ public static IWorkingSet[] getEnabledSets() {
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getWorkingSets();
+ }
+
+ /**
+ * TODO: move
+ */
+ public static boolean areNoTaskWorkingSetsEnabled() {
+ IWorkingSet[] workingSets = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
+ for (IWorkingSet workingSet : workingSets) {
+ if (workingSet != null && workingSet.getId().equalsIgnoreCase(ID_TASK_WORKING_SET)) {
+ if (isWorkingSetEnabled(workingSet)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static boolean isWorkingSetEnabled(IWorkingSet set) {
+ IWorkingSet[] enabledSets = TaskWorkingSetUpdater.getEnabledSets();
+ for (int i = 0; i < enabledSets.length; i++) {
+ if (enabledSets[i].equals(set)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean isOnlyTaskWorkingSetEnabled(IWorkingSet set) {
+ if (!TaskWorkingSetUpdater.isWorkingSetEnabled(set)) {
+ return false;
+ }
+
+ IWorkingSet[] enabledSets = TaskWorkingSetUpdater.getEnabledSets();
+ for (int i = 0; i < enabledSets.length; i++) {
+ if (!enabledSets[i].equals(set) && enabledSets[i].getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
+ return false;
+ }
+ }
+ return true;
+ }
}

Back to the top