KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > ObjectActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.jdt.internal.debug.ui.actions;
12
13
14 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.action.IStatusLineManager;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.swt.widgets.Display;
20 import org.eclipse.swt.widgets.Event;
21 import org.eclipse.ui.IActionDelegate2;
22 import org.eclipse.ui.IObjectActionDelegate;
23 import org.eclipse.ui.IViewPart;
24 import org.eclipse.ui.IViewSite;
25 import org.eclipse.ui.IWorkbenchPage;
26 import org.eclipse.ui.IWorkbenchPart;
27 import org.eclipse.ui.IWorkbenchWindow;
28
29 public abstract class ObjectActionDelegate implements IObjectActionDelegate, IActionDelegate2 {
30     
31     IWorkbenchPart fPart = null;
32     
33     /**
34      * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
35      */

36     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
37         fPart = targetPart;
38     }
39     
40     protected IWorkbenchPart getPart() {
41         return fPart;
42     }
43     
44     /**
45      * @see IActionDelegate#selectionChanged(IAction, ISelection)
46      */

47     public void selectionChanged(IAction action, ISelection sel) {
48     }
49     
50     /**
51      * Returns the currently selected item(s) from the current workbench page or <code>null</code>
52      * if the current active page could not be resolved.
53      * @return the currently selected item(s) or <code>null</code>
54      */

55     protected IStructuredSelection getCurrentSelection() {
56         IWorkbenchPage page = JDIDebugUIPlugin.getActivePage();
57         if (page != null) {
58             ISelection selection= page.getSelection();
59             if (selection instanceof IStructuredSelection) {
60                 return (IStructuredSelection)selection;
61             }
62         }
63         return null;
64     }
65     
66     /**
67      * Displays the given error message in the status line.
68      *
69      * @param message
70      */

71     protected void showErrorMessage(String JavaDoc message) {
72         if (fPart instanceof IViewPart) {
73             IViewSite viewSite = ((IViewPart)fPart).getViewSite();
74             IStatusLineManager manager = viewSite.getActionBars().getStatusLineManager();
75             manager.setErrorMessage(message);
76             Display.getCurrent().beep();
77         }
78     }
79     
80     /* (non-Javadoc)
81      * @see org.eclipse.ui.IActionDelegate2#dispose()
82      */

83     public void dispose() {
84         fPart = null;
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
89      */

90     public void init(IAction action) {
91     }
92
93     /* (non-Javadoc)
94      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
95      */

96     public void runWithEvent(IAction action, Event event) {
97         run(action);
98     }
99
100     /**
101      * Returns the workbench window this action is installed in, or <code>null</code>
102      */

103     protected IWorkbenchWindow getWorkbenchWindow() {
104         if (fPart != null) {
105             return fPart.getSite().getWorkbenchWindow();
106         }
107         return null;
108     }
109 }
110
Popular Tags