KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > monitors > MonitorAction


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.monitors;
12
13
14 import org.eclipse.debug.core.model.IDebugElement;
15 import org.eclipse.debug.ui.IDebugUIConstants;
16 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
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.ui.IViewActionDelegate;
21 import org.eclipse.ui.IViewPart;
22 import org.eclipse.ui.texteditor.IUpdate;
23
24 public abstract class MonitorAction implements IViewActionDelegate, IUpdate {
25
26     protected MonitorsView fView;
27     protected IAction fAction;
28     
29     /**
30      * Returns the current selection in the debug view or <code>null</code>
31      * if there is no selection.
32      *
33      * @return IStructuredSelection
34      */

35     protected IStructuredSelection getDebugViewSelection() {
36         if (fView != null) {
37             ISelection s =fView.getViewSite().getPage().getSelection(IDebugUIConstants.ID_DEBUG_VIEW);
38             
39             if (s instanceof IStructuredSelection) {
40                 return (IStructuredSelection)s;
41             }
42         }
43         return null;
44     }
45     
46     protected IJavaDebugTarget getDebugTarget() {
47         IStructuredSelection ss= getDebugViewSelection();
48         if (ss == null || ss.isEmpty() || ss.size() > 1) {
49             return null;
50         }
51         Object JavaDoc element= ss.getFirstElement();
52         if (element instanceof IDebugElement) {
53             return (IJavaDebugTarget)((IDebugElement)element).getDebugTarget().getAdapter(IJavaDebugTarget.class);
54         }
55         
56         return null;
57     }
58     
59     /**
60      * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
61      */

62     public void init(IViewPart view) {
63         fView= (MonitorsView)view;
64         fView.add(this);
65     }
66
67     /**
68      * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
69      */

70     public void selectionChanged(IAction action, ISelection selection) {
71         fAction= action;
72     }
73 }
Popular Tags