blob: d86b433c9d3b8186a750afba8ff5291d47b40b5e (
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*******************************************************************************
* Copyright (c) 2009 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.tasks.ui.actions;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.ITaskContainer;
import org.eclipse.ui.part.DrillDownAdapter;
/**
* @author Steffen Pingel
*/
public class TaskListViewActionGroup extends RepositoryElementActionGroup {
private final RenameAction renameAction;
private final TaskListView view;
private final GoIntoAction goIntoAction;
private final GoUpAction goUpAction;
private final DrillDownAdapter drillDownAdapter;
public TaskListViewActionGroup(TaskListView view, DrillDownAdapter drillDownAdapter) {
this.view = view;
this.drillDownAdapter = drillDownAdapter;
goIntoAction = new GoIntoAction();
goUpAction = new GoUpAction(drillDownAdapter);
renameAction = new RenameAction(view);
view.getViewer().addSelectionChangedListener(renameAction);
setSelectionProvider(view.getViewer());
}
public void updateDrillDownActions() {
if (drillDownAdapter.canGoBack()) {
goUpAction.setEnabled(true);
} else {
goUpAction.setEnabled(false);
}
}
@Override
public void fillContextMenu(final IMenuManager manager) {
super.fillContextMenu(manager);
updateDrillDownActions();
Object element = ((IStructuredSelection) view.getViewer().getSelection()).getFirstElement();
if (element instanceof ITaskContainer && !(element instanceof ITask)) {
ITaskContainer cat = (ITaskContainer) element;
if (cat.getChildren().size() > 0) {
goIntoAction.setEnabled(true);
} else {
goIntoAction.setEnabled(false);
}
} else {
goIntoAction.setEnabled(false);
}
if (goIntoAction.isEnabled()) {
manager.appendToGroup(ID_SEPARATOR_NAVIGATE, goIntoAction);
}
if (goUpAction.isEnabled()) {
manager.appendToGroup(ID_SEPARATOR_NAVIGATE, goUpAction);
}
if (!(element instanceof ITask) && renameAction.isEnabled() && element != null) {
manager.appendToGroup(ID_SEPARATOR_EDIT, renameAction);
}
}
public GoUpAction getGoUpAction() {
return goUpAction;
}
public GoIntoAction getGoIntoAction() {
return goIntoAction;
}
public RenameAction getRenameAction() {
return renameAction;
}
}
|