KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > DropToFrameActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 2005 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.debug.internal.ui.actions;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.core.runtime.jobs.Job;
17 import org.eclipse.debug.core.DebugException;
18 import org.eclipse.debug.core.model.IDropToFrame;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.viewers.ISelection;
21
22 /**
23  * Action delegate which performs a drop to frame.
24  */

25 public class DropToFrameActionDelegate extends AbstractListenerActionDelegate {
26
27     class UpdateJob extends Job {
28         IAction fAction;
29         ISelection fSelection;
30         
31         UpdateJob() {
32             super("Update Action Enablement"); //$NON-NLS-1$ System Job. Never intended to be seen by users.
33
}
34         
35         void setAction(IAction action) {
36             fAction = action;
37         }
38         void setSelection(ISelection selection) {
39             fSelection = selection;
40         }
41
42         protected IStatus run(IProgressMonitor monitor) {
43             DropToFrameActionDelegate.super.update(fAction, fSelection);
44             return Status.OK_STATUS;
45         }
46         
47     }
48     
49     private UpdateJob fUpdateJob = new UpdateJob();
50     
51     public DropToFrameActionDelegate() {
52         super();
53         fUpdateJob.setSystem(true);
54     }
55     
56     /**
57      * Performs the drop to frame.
58      * @see AbstractDebugActionDelegate#doAction(Object)
59      */

60     protected void doAction(Object JavaDoc element) throws DebugException {
61         if (element instanceof IDropToFrame) {
62             IDropToFrame dropToFrame= (IDropToFrame) element;
63             if (dropToFrame.canDropToFrame()) {
64                 dropToFrame.dropToFrame();
65             }
66         }
67     }
68
69     /**
70      * @see AbstractDebugActionDelegate#isRunInBackground()
71      */

72     protected boolean isRunInBackground() {
73         return true;
74     }
75
76     /**
77      * Enable the action for implementers of IDropToFrame which are able to perform
78      * the drop to frame operation.
79      */

80     protected boolean isEnabledFor(Object JavaDoc element) {
81         return element instanceof IDropToFrame && ((IDropToFrame) element).canDropToFrame();
82     }
83
84     protected void update(IAction action, ISelection selection) {
85         fUpdateJob.setAction(action);
86         fUpdateJob.setSelection(selection);
87         fUpdateJob.schedule();
88     }
89 }
90
Popular Tags