KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > PartPluginAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal;
12
13 import org.eclipse.core.runtime.IConfigurationElement;
14 import org.eclipse.jface.viewers.ISelectionProvider;
15 import org.eclipse.ui.IWorkbenchPart;
16
17 /**
18  * This class adds to the PluginAction support by
19  * setting itself up for work within a WorkbenchPart.
20  * The main difference is that it is capable of
21  * processing local selection changes within a part.
22  */

23 public class PartPluginAction extends PluginAction {
24     /**
25      * PartPluginAction constructor.
26      */

27     public PartPluginAction(IConfigurationElement actionElement, String JavaDoc id,
28             int style) {
29         super(actionElement, id, style);
30     }
31
32     /**
33      * Registers this action as a listener of the workbench part.
34      */

35     protected void registerSelectionListener(IWorkbenchPart aPart) {
36         ISelectionProvider selectionProvider = aPart.getSite()
37                 .getSelectionProvider();
38         if (selectionProvider != null) {
39             selectionProvider.addSelectionChangedListener(this);
40             selectionChanged(selectionProvider.getSelection());
41         }
42     }
43
44     /**
45      * Unregisters this action as a listener of the workbench part.
46      */

47     protected void unregisterSelectionListener(IWorkbenchPart aPart) {
48         ISelectionProvider selectionProvider = aPart.getSite()
49                 .getSelectionProvider();
50         if (selectionProvider != null) {
51             selectionProvider.removeSelectionChangedListener(this);
52         }
53     }
54 }
55
Popular Tags