KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 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.renderings;
13
14 import java.lang.reflect.Method JavaDoc;
15
16 import org.eclipse.debug.core.DebugException;
17 import org.eclipse.debug.internal.ui.DebugPluginImages;
18 import org.eclipse.debug.internal.ui.DebugUIMessages;
19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20 import org.eclipse.debug.internal.ui.views.memory.MemoryViewUtil;
21 import org.eclipse.debug.ui.IDebugUIConstants;
22 import org.eclipse.debug.ui.memory.AbstractTableRendering;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.ui.PlatformUI;
25
26 /**
27  * Reest MemoryViewTab to the base address of a memory block
28  *
29  * @since 3.0
30  */

31 public class ResetToBaseAddressAction extends Action {
32
33     private AbstractBaseTableRendering fRendering;
34
35     public ResetToBaseAddressAction(AbstractBaseTableRendering rendering) {
36         fRendering = rendering;
37         setText(DebugUIMessages.ResetMemoryBlockAction_title);
38         setToolTipText(DebugUIMessages.ResetMemoryBlockAction_tootip);
39
40         setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_RESET_MEMORY));
41         setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_LCL_RESET_MEMORY));
42         setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_RESET_MEMORY));
43         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugUIConstants.PLUGIN_ID + ".ResetBaseAddressContextAction_context"); //$NON-NLS-1$
44
}
45
46     /*
47      * (non-Javadoc)
48      *
49      * @see org.eclipse.jface.action.IAction#run()
50      */

51     public void run() {
52         
53         // check if client has overrode the #reset method
54
// if client has overrode #reset method, call old method
55
// otherwise, call new #resetRendering method
56
// This is done to ensure that client's code will continue to be executed until
57
// they have migrated to the new #resetRendering API
58
Class JavaDoc renderingClass = fRendering.getClass();
59         try {
60             Method JavaDoc method = renderingClass.getMethod("reset", new Class JavaDoc[]{}); //$NON-NLS-1$
61
if (method.getDeclaringClass().equals(AbstractTableRendering.class))
62             {
63                 // client has not overrode, call new method
64
try {
65                     fRendering.resetRendering();
66                 } catch (DebugException e) {
67                     MemoryViewUtil.openError(DebugUIMessages.AbstractTableRendering_12, DebugUIMessages.AbstractTableRendering_13, e); //
68
}
69                 return;
70             }
71         } catch (SecurityException JavaDoc e) {
72         } catch (NoSuchMethodException JavaDoc e) {
73             try {
74                 // if no such method, then it must be AbstractAsycTableRendering
75
fRendering.resetRendering();
76             } catch (DebugException e1) {
77                 MemoryViewUtil.openError(DebugUIMessages.AbstractTableRendering_12, DebugUIMessages.AbstractTableRendering_13, e); //
78
}
79         }
80         
81         if(fRendering instanceof AbstractTableRendering)
82         {
83             // call old method
84
((AbstractTableRendering)fRendering).reset();
85         }
86     }
87 }
88
Popular Tags