KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.jdt.internal.debug.ui.actions;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.jdt.debug.core.IJavaStackFrame;
16 import org.eclipse.jdt.internal.debug.ui.ExceptionHandler;
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.swt.widgets.Event;
21 import org.eclipse.ui.IActionDelegate2;
22 import org.eclipse.ui.IViewActionDelegate;
23 import org.eclipse.ui.IViewPart;
24
25 /**
26  * Local toolbar drop to frame action
27  */

28 public class DropToFrameButton implements IViewActionDelegate, IActionDelegate2 {
29     
30     private IJavaStackFrame fFrame = null;
31
32     /* (non-Javadoc)
33      * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
34      */

35     public void init(IViewPart view) {
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
40      */

41     public void run(IAction action) {
42         try {
43             fFrame.dropToFrame();
44         } catch (DebugException e) {
45             String JavaDoc title= ActionMessages.getString("DropToFrameAction.Drop_to_Frame_1"); //$NON-NLS-1$
46
String JavaDoc message= ActionMessages.getString("DropToFrameAction.Exceptions_occurred_attempting_to_drop_to_frame._2"); //$NON-NLS-1$
47
ExceptionHandler.handle(e, title, message);
48         }
49     }
50
51     /* (non-Javadoc)
52      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
53      */

54     public void selectionChanged(IAction action, ISelection selection) {
55         fFrame = null;
56         if (selection instanceof IStructuredSelection) {
57             IStructuredSelection ss = (IStructuredSelection) selection;
58             if (ss.size() == 1) {
59                 Object JavaDoc object = ss.getFirstElement();
60                 if (object instanceof IAdaptable) {
61                     IJavaStackFrame frame = (IJavaStackFrame) ((IAdaptable)object).getAdapter(IJavaStackFrame.class);
62                     if (frame != null && frame.supportsDropToFrame()) {
63                         action.setEnabled(true);
64                         fFrame = frame;
65                         return;
66                     }
67                 }
68             }
69         }
70         action.setEnabled(false);
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
75      */

76     public void init(IAction action) {
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.ui.IActionDelegate2#dispose()
81      */

82     public void dispose() {
83         fFrame = null;
84     }
85
86     /* (non-Javadoc)
87      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
88      */

89     public void runWithEvent(IAction action, Event event) {
90         run(action);
91     }
92
93 }
94
Popular Tags