blob: a4f65458c94c4bb83570a91c3f2e492c1f76f0da (
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
97
98
99
100
101
102
103
104
105
106
|
/*******************************************************************************
* 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.mylar.internal.tasks.ui.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.mylar.internal.tasks.ui.TasksUiImages;
import org.eclipse.mylar.internal.tasks.ui.views.ITaskListPresentation;
import org.eclipse.mylar.internal.tasks.ui.views.TaskListView;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
/**
* @author Rob Elves
*/
public class PresentationDropDownSelectionAction extends Action implements IMenuCreator {
private static final String LABEL_NAME = "Task Presentation";
public static final String ID = "org.eclipse.mylar.tasklist.actions.presentationselection";
private TaskListView view;
protected Menu dropDownMenu = null;
private ITaskListPresentation[] presentations;
public PresentationDropDownSelectionAction(TaskListView view, ITaskListPresentation[] presentations) {
super();
this.view = view;
this.presentations = presentations;
setMenuCreator(this);
setText(LABEL_NAME);
setToolTipText(LABEL_NAME);
setId(ID);
setEnabled(true);
setImageDescriptor(TasksUiImages.TASKLIST_MODE);
}
protected void addActionsToMenu() {
for (ITaskListPresentation presentation : presentations) {
PresentationSelectionAction action = new PresentationSelectionAction(presentation);
ActionContributionItem item = new ActionContributionItem(action);
action.setText(presentation.getPresentationName());
action.setImageDescriptor(presentation.getImageDescriptor());
action.setChecked(view.getCurrentPresentation().getPresentationName().equals(
presentation.getPresentationName()));
item.fill(dropDownMenu, -1);
}
}
@Override
public void run() {
// ignore
}
public void dispose() {
if (dropDownMenu != null) {
dropDownMenu.dispose();
dropDownMenu = null;
}
}
public Menu getMenu(Control parent) {
if (dropDownMenu != null) {
dropDownMenu.dispose();
}
dropDownMenu = new Menu(parent);
addActionsToMenu();
return dropDownMenu;
}
public Menu getMenu(Menu parent) {
if (dropDownMenu != null) {
dropDownMenu.dispose();
}
dropDownMenu = new Menu(parent);
addActionsToMenu();
return dropDownMenu;
}
private class PresentationSelectionAction extends Action {
private ITaskListPresentation presentation;
public PresentationSelectionAction(ITaskListPresentation presentation) {
this.presentation = presentation;
setText(presentation.getPresentationName());
}
@Override
public void run() {
view.applyPresentation(presentation);
}
}
}
|