01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.core.runtime.IConfigurationElement;
13: import org.eclipse.jface.viewers.ISelectionProvider;
14: import org.eclipse.ui.IWorkbenchPart;
15:
16: /**
17: * This class adds to the PluginAction support by
18: * setting itself up for work within a WorkbenchPart.
19: * The main difference is that it is capable of
20: * processing local selection changes within a part.
21: */
22: public class PartPluginAction extends PluginAction {
23: /**
24: * PartPluginAction constructor.
25: */
26: public PartPluginAction(IConfigurationElement actionElement,
27: String id, int style) {
28: super (actionElement, id, style);
29: }
30:
31: /**
32: * Registers this action as a listener of the workbench part.
33: */
34: protected void registerSelectionListener(IWorkbenchPart aPart) {
35: ISelectionProvider selectionProvider = aPart.getSite()
36: .getSelectionProvider();
37: if (selectionProvider != null) {
38: selectionProvider.addSelectionChangedListener(this );
39: selectionChanged(selectionProvider.getSelection());
40: }
41: }
42:
43: /**
44: * Unregisters this action as a listener of the workbench part.
45: */
46: protected void unregisterSelectionListener(IWorkbenchPart aPart) {
47: ISelectionProvider selectionProvider = aPart.getSite()
48: .getSelectionProvider();
49: if (selectionProvider != null) {
50: selectionProvider.removeSelectionChangedListener(this);
51: }
52: }
53: }
|