Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2007-06-26 09:53:47 -0400
committermkersten2007-06-26 09:53:47 -0400
commitd40ef3ea343a86748d5f64a8eee18f7bfecb162c (patch)
tree9d18517a93d23e9be1398a770e0202916e999b68
parentf51e0b4f12a6a49f1f334b2f3478021ed534c124 (diff)
downloadorg.eclipse.mylyn.tasks-d40ef3ea343a86748d5f64a8eee18f7bfecb162c.tar.gz
org.eclipse.mylyn.tasks-d40ef3ea343a86748d5f64a8eee18f7bfecb162c.tar.xz
org.eclipse.mylyn.tasks-d40ef3ea343a86748d5f64a8eee18f7bfecb162c.zip
NEW - bug 144161: Use trim bar to show currently active task
https://bugs.eclipse.org/bugs/show_bug.cgi?id=144161
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryDropDown.java194
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryHandler.java33
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskTrimWidget.java51
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPreferenceConstants.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java1
5 files changed, 262 insertions, 19 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryDropDown.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryDropDown.java
new file mode 100644
index 000000000..df9c8ab5c
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryDropDown.java
@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers 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
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.mylyn.internal.tasks.ui.actions.ActivateTaskDialogAction;
+import org.eclipse.mylyn.internal.tasks.ui.actions.TaskActivateAction;
+import org.eclipse.mylyn.internal.tasks.ui.views.TaskActivationHistory;
+import org.eclipse.mylyn.internal.tasks.ui.views.TaskElementLabelProvider;
+import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
+import org.eclipse.mylyn.tasks.core.AbstractTask;
+import org.eclipse.mylyn.tasks.core.AbstractTaskContainer;
+import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.CompoundContributionItem;
+
+/**
+ * Copied from ActivateTaskHistoryDropDownAction
+ *
+ * TODO: refactor that one into command contribution
+ */
+public class TaskHistoryDropDown extends CompoundContributionItem {
+
+ private final static int MAX_ITEMS_TO_DISPLAY = 12;
+
+ private boolean scopeToWorkingSet;
+
+ private TaskActivationHistory taskHistory;
+
+ private TaskElementLabelProvider labelProvider = new TaskElementLabelProvider(false);
+
+ public TaskHistoryDropDown() {
+ this(null);
+ }
+
+ public TaskHistoryDropDown(String id) {
+ super(id);
+ scopeToWorkingSet = false;
+ taskHistory = TasksUiPlugin.getTaskListManager().getTaskActivationHistory();
+ }
+
+ protected IContributionItem[] getContributionItems() {
+ List<AbstractTask> tasks = new ArrayList<AbstractTask>(taskHistory.getPreviousTasks());
+ Set<IWorkingSet> sets = TaskListView.getActiveWorkingSets();
+ if (scopeToWorkingSet && !sets.isEmpty()) {
+ Set<AbstractTask> allWorkingSetTasks = new HashSet<AbstractTask>();
+ for (IWorkingSet workingSet : sets) {
+ IAdaptable[] elements = workingSet.getElements();
+ for (IAdaptable adaptable : elements) {
+ if (adaptable instanceof AbstractTaskContainer) {
+ allWorkingSetTasks.addAll(((AbstractTaskContainer) adaptable).getChildren());
+ }
+ }
+ }
+ List<AbstractTask> allScopedTasks = new ArrayList<AbstractTask>(tasks);
+ for (AbstractTask task : tasks) {
+ if (!allWorkingSetTasks.contains(task)) {
+ allScopedTasks.remove(task);
+ }
+ }
+ tasks = allScopedTasks;
+ }
+
+ if (tasks.size() > MAX_ITEMS_TO_DISPLAY) {
+ tasks = tasks.subList(tasks.size() - MAX_ITEMS_TO_DISPLAY, tasks.size());
+ }
+
+ List<IContributionItem> items = new ArrayList<IContributionItem>();
+ for (int i = tasks.size() - 1; i >= 0; i--) {
+ AbstractTask currTask = tasks.get(i);
+ Action taskNavAction = new TaskNavigateAction(currTask);
+ ActionContributionItem item = new ActionContributionItem(taskNavAction);
+ if (currTask.isActive()) {
+ taskNavAction.setChecked(true);
+ }
+ items.add(item);
+ }
+
+ Separator separator = new Separator();
+ items.add(separator);
+
+ AbstractTask active = TasksUiPlugin.getTaskListManager().getTaskList().getActiveTask();
+ if (active != null) {
+ Action deactivateAction = new DeactivateTaskAction();
+ ActionContributionItem item = new ActionContributionItem(deactivateAction);
+ items.add(item);
+ } else {
+ Action activateDialogAction = new ActivateDialogAction(new ActivateTaskDialogAction());
+ ActionContributionItem item = new ActionContributionItem(activateDialogAction);
+ items.add(item);
+ }
+
+ return items.toArray(new IContributionItem[items.size()]);
+ }
+
+ /**
+ * Action for navigating to a specified task. This class should be protected but has been made public for testing
+ * only
+ */
+ public class TaskNavigateAction extends Action {
+
+ private static final int MAX_LABEL_LENGTH = 40;
+
+ private AbstractTask targetTask;
+
+ public TaskNavigateAction(AbstractTask task) {
+ targetTask = task;
+ String taskDescription = task.getSummary();
+ if (taskDescription.length() > MAX_LABEL_LENGTH) {
+ taskDescription = taskDescription.subSequence(0, MAX_LABEL_LENGTH - 3) + "...";
+ }
+ setText(taskDescription);
+ setEnabled(true);
+ setToolTipText(task.getSummary());
+ Image image = labelProvider.getImage(task);
+ setImageDescriptor(ImageDescriptor.createFromImage(image));
+ }
+
+ @Override
+ public void run() {
+ if (targetTask.isActive()) {
+ return;
+ }
+ new TaskActivateAction().run(targetTask);
+ // taskHistory.navigatedToTask(targetTask);
+ taskHistory.addTask(targetTask);
+// setButtonStatus();
+// view.refreshAndFocus(false);
+// TasksUiUtil.refreshAndOpenTaskListElement(targetTask);
+ }
+ }
+
+ public class ActivateDialogAction extends Action {
+
+ private ActivateTaskDialogAction dialogAction;
+
+ public ActivateDialogAction(ActivateTaskDialogAction action) {
+ dialogAction = action;
+ dialogAction.init(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
+
+ setText("Activate Task...");
+ setToolTipText("Activate Task...");
+ setEnabled(true);
+ setChecked(false);
+ setImageDescriptor(null);
+ //TasksUiImages.TASK_ACTIVE);
+ }
+
+ @Override
+ public void run() {
+ dialogAction.run(null);
+ }
+ }
+
+ public class DeactivateTaskAction extends Action {
+
+ public DeactivateTaskAction() {
+ setText("Deactivate Task");
+ setToolTipText("Deactivate Task");
+ setEnabled(true);
+ setChecked(false);
+ setImageDescriptor(null);
+ //TasksUiImages.TASK_INACTIVE);
+ }
+
+ @Override
+ public void run() {
+ AbstractTask active = TasksUiPlugin.getTaskListManager().getTaskList().getActiveTask();
+ if (active != null) {
+ TasksUiPlugin.getTaskListManager().deactivateTask(active);
+ }
+ }
+
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryHandler.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryHandler.java
new file mode 100644
index 000000000..6881d6021
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskHistoryHandler.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers 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
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.mylyn.internal.tasks.ui.actions.TaskActivateAction;
+import org.eclipse.mylyn.internal.tasks.ui.views.TaskActivationHistory;
+import org.eclipse.mylyn.tasks.core.AbstractTask;
+import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
+
+/**
+ * @author Eugene Kuleshov
+ */
+public class TaskHistoryHandler extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TaskActivationHistory taskHistory = TasksUiPlugin.getTaskListManager().getTaskActivationHistory();
+ if (taskHistory.hasPrevious()) {
+ AbstractTask previousTask = taskHistory.getPreviousTask();
+ new TaskActivateAction().run(previousTask);
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskTrimWidget.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskTrimWidget.java
index 94c018948..3b948d51d 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskTrimWidget.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskTrimWidget.java
@@ -15,14 +15,14 @@ import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
-import org.eclipse.mylyn.internal.tasks.ui.actions.ActivateTaskHistoryDropDownAction;
import org.eclipse.mylyn.internal.tasks.ui.actions.CopyTaskDetailsAction;
import org.eclipse.mylyn.internal.tasks.ui.actions.OpenTaskListElementAction;
import org.eclipse.mylyn.internal.tasks.ui.actions.OpenWithBrowserAction;
@@ -46,9 +46,12 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.internal.ObjectActionContributorManager;
+import org.eclipse.ui.internal.WorkbenchWindow;
+import org.eclipse.ui.internal.layout.IWindowTrim;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
/**
@@ -71,8 +74,6 @@ public class TaskTrimWidget extends WorkbenchWindowControlContribution {
private TaskListHyperlink activeTaskLabel;
- private ActivateTaskHistoryDropDownAction navigateAction;
-
private OpenWithBrowserAction openWithBrowserAction = new OpenWithBrowserAction();
private CopyTaskDetailsAction copyTaskDetailsAction = new CopyTaskDetailsAction(false);
@@ -98,12 +99,30 @@ public class TaskTrimWidget extends WorkbenchWindowControlContribution {
}
};
+ private IPropertyChangeListener SHOW_TRIM_LISTENER = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ String property = event.getProperty();
+ if(property.equals(TasksUiPreferenceConstants.SHOW_TRIM)) {
+ setTrimVisible((Boolean) event.getNewValue());
+ }
+ }
+ };
+
public TaskTrimWidget() {
- super();
TasksUiPlugin.getTaskListManager().addActivityListener(TASK_CHANGE_LISTENER);
+ TasksUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(SHOW_TRIM_LISTENER);
hookContextMenu();
}
+ private void setTrimVisible(boolean visible) {
+ IWorkbenchWindow window = TasksUiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
+ IWindowTrim trim = ((WorkbenchWindow) window).getTrimManager().getTrim(
+ "org.eclipse.mylyn.tasks.ui.trim.container");
+ if (trim != null) {
+ ((WorkbenchWindow) window).getTrimManager().setTrimVisible(trim, visible);
+ }
+ }
+
@Override
public void dispose() {
if (composite != null && !composite.isDisposed()) {
@@ -123,7 +142,7 @@ public class TaskTrimWidget extends WorkbenchWindowControlContribution {
menu = null;
TasksUiPlugin.getTaskListManager().removeActivityListener(TASK_CHANGE_LISTENER);
- super.dispose();
+ TasksUiPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(SHOW_TRIM_LISTENER);
}
@Override
@@ -131,21 +150,14 @@ public class TaskTrimWidget extends WorkbenchWindowControlContribution {
composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.horizontalSpacing = 2;
+ layout.numColumns = 1;
+ layout.horizontalSpacing = 0;
layout.marginHeight = 0;
- layout.marginWidth = 0;
+ layout.marginLeft = 2;
+ layout.marginRight = 0;
composite.setLayout(layout);
- GridData gridData = new GridData(SWT.NONE, SWT.CENTER, false, false);
- composite.setLayoutData(gridData);
-
- navigateAction = new ActivateTaskHistoryDropDownAction(TasksUiPlugin.getTaskListManager()
- .getTaskActivationHistory(), false);
-
- ToolBarManager manager = new ToolBarManager(SWT.FLAT);
- manager.add(navigateAction);
- manager.createControl(composite);
+ composite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
createStatusComposite(composite);
@@ -197,7 +209,8 @@ public class TaskTrimWidget extends WorkbenchWindowControlContribution {
if (TaskListView.getFromActivePerspective().getDrilledIntoCategory() != null) {
TaskListView.getFromActivePerspective().goUpToRoot();
}
- TasksUiUtil.refreshAndOpenTaskListElement((TasksUiPlugin.getTaskListManager().getTaskList().getActiveTask()));
+ TasksUiUtil.refreshAndOpenTaskListElement((TasksUiPlugin.getTaskListManager().getTaskList()
+ .getActiveTask()));
}
});
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPreferenceConstants.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPreferenceConstants.java
index b88866483..103b73b98 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPreferenceConstants.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksUiPreferenceConstants.java
@@ -17,6 +17,8 @@ public final class TasksUiPreferenceConstants {
public static final String ACTIVATE_WHEN_OPENED = "org.eclipse.mylyn.tasks.ui.activate.when.opened";
+ public static final String SHOW_TRIM = "org.eclipse.mylyn.tasks.ui.show.trim";
+
public static final String BACKUP_LAST = "org.eclipse.mylyn.tasks.ui.backup.last";
public static final String BACKUP_MAXFILES = "org.eclipse.mylyn.tasks.ui.backup.maxfiles";
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java
index c7e2ed2aa..eeffdb50d 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java
@@ -570,6 +570,7 @@ public class TasksUiPlugin extends AbstractUIPlugin implements IStartup {
store.setDefault(TasksUiPreferenceConstants.FILTER_PRIORITY, PriorityLevel.P5.toString());
store.setDefault(TasksUiPreferenceConstants.EDITOR_TASKS_RICH, true);
store.setDefault(TasksUiPreferenceConstants.ACTIVATE_WHEN_OPENED, false);
+ store.setDefault(TasksUiPreferenceConstants.SHOW_TRIM, false);
store.setDefault(TasksUiPreferenceConstants.REPOSITORY_SYNCH_SCHEDULE_ENABLED, true);
store.setDefault(TasksUiPreferenceConstants.REPOSITORY_SYNCH_SCHEDULE_MILISECONDS, "" + (20 * 60 * 1000));

Back to the top