KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > AbstractMemoryAction


1 /*******************************************************************************
2  * Copyright (c) 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
12
13 package org.eclipse.debug.internal.ui.views.memory;
14
15 import org.eclipse.debug.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.ui.IViewPart;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.IWorkbenchPart;
21 import org.eclipse.ui.PartInitException;
22
23
24 /**
25  * Abstract action class for Memory View Action.
26  * This allows action contribution to both toolbar actions
27  * and context menu actions without having two seperate
28  * implementations. "getViewTab" gets called whenever the view
29  * tab is required to run the action.
30  *
31  * @since 3.0
32  */

33 abstract public class AbstractMemoryAction extends Action
34 {
35     public AbstractMemoryAction()
36     {
37         super();
38     }
39     
40     public AbstractMemoryAction(String JavaDoc label)
41     {
42         super(label);
43     }
44     
45     public AbstractMemoryAction(String JavaDoc label, int style){
46         super(label, style);
47     }
48     
49     /**
50      * @return the view tab for which the action should act on.
51      */

52     abstract IMemoryViewTab getViewTab();
53     
54     /**
55      * Given a view id, return the top view tab from the view.
56      * Returns null if the view cannot be opened or a top view tab is not found.
57      * @param viewId
58      * @return
59      */

60     public IMemoryViewTab getTopViewTabFromView(String JavaDoc viewId){
61         
62         if (viewId.equals(IInternalDebugUIConstants.ID_MEMORY_VIEW))
63         {
64             // open a new view if necessary
65
IWorkbenchPage p= DebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
66             if (p == null) {
67                 return null;
68             }
69             IViewPart view = null;
70             view= p.findView(viewId);
71             
72             if (view == null) {
73                 try {
74                     IWorkbenchPart activePart= p.getActivePart();
75                     view= (MemoryView) p.showView(viewId);
76                     p.activate(activePart);
77                 } catch (PartInitException e) {
78                     return null;
79                 }
80                 
81             }
82             
83             if (view instanceof IMemoryView)
84             {
85                 IMemoryViewTab topTap = ((IMemoryView)view).getTopMemoryTab();
86                 
87                 return topTap;
88             }
89             else
90             {
91                 return null;
92             }
93         }
94         else
95             return null;
96     }
97 }
98
Popular Tags