KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > context > DropToFrameAdapter


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.debug.internal.ui.actions.context;
13
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.core.runtime.jobs.Job;
19 import org.eclipse.debug.core.DebugException;
20 import org.eclipse.debug.core.model.IDropToFrame;
21 import org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousDropToFrameAdapter;
22 import org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor;
23 import org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousRequestMonitor;
24 import org.eclipse.debug.ui.IDebugUIConstants;
25
26 public class DropToFrameAdapter extends StandardActionAdapter implements IAsynchronousDropToFrameAdapter {
27
28     public void canDropToFrame(final Object JavaDoc element, final IBooleanRequestMonitor monitor) {
29         Job job = new Job("canDropToFrame") { //$NON-NLS-1$
30
protected IStatus run(IProgressMonitor pm) {
31                 if (!pm.isCanceled()) {
32                     IDropToFrame dropToFrame = getTarget(element);
33                     if (dropToFrame != null) {
34                         monitor.setResult(dropToFrame.canDropToFrame());
35                     } else {
36                         monitor.setResult(false);
37                     }
38                     monitor.done();
39                 }
40                 return Status.OK_STATUS;
41             }
42         };
43         job.setSystem(true);
44         job.setRule(createUpdateSchedulingRule());
45         job.schedule();
46     }
47
48     public void dropToFrame(final Object JavaDoc element, final IAsynchronousRequestMonitor monitor) {
49         Job job = new Job("dropToFrame") { //$NON-NLS-1$
50
protected IStatus run(IProgressMonitor pm) {
51                 if (!pm.isCanceled()) {
52                     IDropToFrame dropToFrame = getTarget(element);
53                     if (dropToFrame != null) {
54                         try {
55                             dropToFrame.dropToFrame();
56                         } catch (DebugException e) {
57                             monitor.setStatus(e.getStatus());
58                         }
59                     } else {
60                         monitor.setStatus(new Status(IStatus.ERROR, IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.INTERNAL_ERROR, "element must be an instance of or adapt to IDropToFrame", //$NON-NLS-1$
61
null));
62                     }
63                     monitor.done();
64                 }
65                 return Status.OK_STATUS;
66             }
67         };
68         job.setSystem(true);
69         job.schedule();
70     }
71
72     private IDropToFrame getTarget(Object JavaDoc element) {
73         if (element instanceof IDropToFrame) {
74             return (IDropToFrame) element;
75         } else if (element instanceof IAdaptable) {
76             return (IDropToFrame) ((IAdaptable) element).getAdapter(IDropToFrame.class);
77         }
78         return null;
79     }
80
81 }
82
Popular Tags