Skip to main content
summaryrefslogtreecommitdiffstats
blob: 72ffd7a9cc0569615316e830aa4aae00439dec89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*******************************************************************************
 * Copyright (c) 2004, 2011 Eugene Kuleshov 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:
 *     Eugene Kuleshov - initial API and implementation
 *     Tasktop Technologies - improvements
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui;

import java.util.Map;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.core.TaskActivationHistory;
import org.eclipse.mylyn.internal.tasks.ui.actions.ActivateTaskDialogAction;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.menus.UIElement;

/**
 * @author Eugene Kuleshov
 * @author Steffen Pingel
 */
public class TaskHistoryHandler extends AbstractHandler implements IElementUpdater {

	public Object execute(final ExecutionEvent event) throws ExecutionException {
		if (TasksUi.getTaskActivityManager().getActiveTask() != null) {
			TasksUi.getTaskActivityManager().deactivateActiveTask();
		} else {
			TaskActivationHistory taskHistory = TasksUiPlugin.getTaskActivityManager().getTaskActivationHistory();
			if (taskHistory.hasPrevious()) {
				AbstractTask previousTask = taskHistory.getPreviousTask();
				if (previousTask != null && !previousTask.isActive()) {
					TasksUiInternal.activateTaskThroughCommand(previousTask);
				}
			} else {
				IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
				if (window != null) {
					ActivateTaskDialogAction action = new ActivateTaskDialogAction();
					action.init(window);
					action.run(null);
				}
			}
		}
		return null;
	}

	@SuppressWarnings("rawtypes")
	public void updateElement(UIElement element, Map parameters) {
		if (TasksUi.getTaskActivityManager().getActiveTask() == null) {
			element.setIcon(TasksUiImages.CONTEXT_HISTORY_PREVIOUS);
		} else {
			element.setIcon(TasksUiImages.CONTEXT_HISTORY_PREVIOUS_ACTIVE);
		}
	}

}

Back to the top