KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.views.memory;
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.internal.ui.actions.ActionMessages;
19 import org.eclipse.debug.ui.DebugUITools;
20 import org.eclipse.debug.ui.actions.IAddMemoryBlocksTarget;
21 import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
22
23 /**
24  * This is the retargettable add memory block action in the Memory View.
25  * All AddMemoryBlock actions in the view will use this action to make sure
26  * that clients can override the "Add Memory Monitor" dialog.
27  *
28  */

29 public class RetargetAddMemoryBlockAction extends AddMemoryBlockAction {
30
31     public RetargetAddMemoryBlockAction(IMemoryRenderingSite site)
32     {
33         super(site);
34     }
35     
36     public RetargetAddMemoryBlockAction(IMemoryRenderingSite site, boolean addDefaultRenderings)
37     {
38         super(site, addDefaultRenderings);
39     }
40     
41     public RetargetAddMemoryBlockAction(String JavaDoc text, int style, IMemoryRenderingSite site)
42     {
43         super(text, style, site);
44     }
45
46     public void run() {
47         // get current selection from Debug View
48
Object JavaDoc debugContext = DebugUITools.getDebugContext();
49         IAddMemoryBlocksTarget target = getAddMemoryBlocksTarget(debugContext);
50         
51         if (target != null)
52         {
53             try {
54                 if (target.supportsAddMemoryBlocks(getMemoryView()))
55                 {
56                     target.addMemoryBlocks(getMemoryView(), getMemoryView().getSite().getSelectionProvider().getSelection());
57                 }
58                 else
59                     super.run();
60             } catch (CoreException e) {
61                 DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), ActionMessages.RetargetAddMemoryBlockAction_0, ActionMessages.RetargetAddMemoryBlockAction_1, e);
62             }
63         }
64         else
65         {
66             super.run();
67         }
68     }
69
70     protected void updateAction(Object JavaDoc debugContext) {
71         
72         try {
73             IAddMemoryBlocksTarget target = getAddMemoryBlocksTarget(debugContext);
74             
75             if (target != null)
76             {
77                 if (target.supportsAddMemoryBlocks(getMemoryView()))
78                 {
79                     if (getMemoryView().getSite().getSelectionProvider() != null)
80                         setEnabled(target.canAddMemoryBlocks(getMemoryView(), getMemoryView().getSite().getSelectionProvider().getSelection()));
81                     else
82                         super.updateAction(debugContext);
83                 }
84                 else
85                     super.updateAction(debugContext);
86             }
87             else
88             {
89                 super.updateAction(debugContext);
90             }
91         } catch (CoreException e) {
92             DebugUIPlugin.log(e);
93         }
94     }
95     
96     private IAddMemoryBlocksTarget getAddMemoryBlocksTarget(Object JavaDoc debugContext)
97     {
98         IMemoryBlockRetrieval standardMemRetrieval = MemoryViewUtil.getMemoryBlockRetrieval(debugContext);
99         
100         if (standardMemRetrieval == null)
101             return null;
102         
103         IAddMemoryBlocksTarget target = null;
104         
105         if (standardMemRetrieval instanceof IAddMemoryBlocksTarget)
106         {
107             target = (IAddMemoryBlocksTarget) standardMemRetrieval;
108         }
109         else if (standardMemRetrieval instanceof IAdaptable)
110         {
111             target = (IAddMemoryBlocksTarget)((IAdaptable)standardMemRetrieval).getAdapter(IAddMemoryBlocksTarget.class);
112         }
113         return target;
114     }
115 }
116
Popular Tags