Skip to main content
summaryrefslogtreecommitdiffstats
blob: 81a529c7cff69feba68f94f0a6ec9b293c90af06 (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
package org.eclipse.debug.internal.ui;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */
 
import org.eclipse.debug.core.ILaunch;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

/**
 * Superclass of run & debug pulldown actions.
 */
public abstract class LaunchDropDownAction implements IWorkbenchWindowPulldownDelegate {
	

	private ExecutionAction fLaunchAction;
	
	/**
	 * Create a new instance of this class
	 */
	public LaunchDropDownAction(ExecutionAction launchAction) {
		fLaunchAction= launchAction;		
	}

	private void createMenuForAction(Menu parent, Action action) {
		ActionContributionItem item= new ActionContributionItem(action);
		item.fill(parent, -1);
	}

	/**
	 * @see IWorkbenchWindowActionDelegate
	 */
	public void dispose() {
	}

	/**
	 * @see IWorkbenchWindowPulldownDelegate
	 */
	public Menu getMenu(Control parent) {
		Menu menu= new Menu(parent);
		LaunchHistoryElement[] historyList= getHistory();
		int count= 0;
		for (int i = 0; i < historyList.length; i++) {
			LaunchHistoryElement launch= historyList[i];
			RelaunchHistoryLaunchAction newAction= new RelaunchHistoryLaunchAction(launch);
			createMenuForAction(menu, newAction);
			count++;
		}
		if (count > 0) {
			new MenuItem(menu, SWT.SEPARATOR);
		}
		createMenuForAction(menu, new LaunchWithAction(getMode()));

		return menu;
	}

	/**
	 * @see IActionDelegate
	 */
	public void run(IAction action) {
		fLaunchAction.run();
	}
	
	/**
	 * @see IActionDelegate
	 */
	public void selectionChanged(IAction action, ISelection selection){
	}
	
	/**
	 * @see IWorkbenchWindowActionDelegate
	 */
	public void init(IWorkbenchWindow window){
	}
	
	/**
	 * Returns an array of previous launches applicable to this drop down
	 */
	public abstract LaunchHistoryElement[] getHistory();
	
	/**
	 * Returns the mode (e.g., 'run' or 'debug') of this drop down
	 */
	public abstract String getMode();

}

Back to the top