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

/*
 * Licensed Materials - Property of IBM,
 * WebSphere Studio Workbench
 * (c) Copyright IBM Corp 2000
 */

import org.eclipse.ui.actions.SelectionProviderAction;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;

/**
 * Provides the common functionality of the control actions.
 * In order to avoid duplication of code, ControlActions defer to 
 * delegates to perform all of the real work.  This is necessary so that 
 * these actions can be used as regular SelectionProviderActions,
 * but also be used as contributed IWorkbenchWindowActionDelegates,
 * which must have zero-argument constructors.
 */
public class ControlAction extends SelectionProviderAction {

	/**
	 * The delegate does all of the real work.  This class only responds to
	 * run() requests and selectionChanged notifications.  In both cases,
	 * it defers to the delegate.
	 */
	protected ControlActionDelegate fDelegate;

	public ControlAction(ISelectionProvider selectionProvider, ControlActionDelegate delegate) {
		super(selectionProvider, "");
		fDelegate= delegate;
		fDelegate.initializeForOwner(this);
		setText(DebugUIUtils.getResourceString(fDelegate.getPrefix() + TEXT));
		setToolTipText(DebugUIUtils.getResourceString(fDelegate.getPrefix() + TOOL_TIP_TEXT));		
	}

	/**
	 * @see Action
	 * The actual work is deferred to the delegate.
	 */
	public void run() {
		fDelegate.selectionChanged(this, getStructuredSelection());
		fDelegate.run();
	}	

	/**
	 * @see SelectionProviderAction
	 * Updates the enable state based on what and how much is selected.
	 */
	public void selectionChanged(IStructuredSelection sel) {
		setEnabled(fDelegate.getEnableStateForSelection(sel));		
	}

}

Back to the top