KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.eclipse.debug.internal.ui.views.memory;
13
14 import java.math.BigInteger JavaDoc;
15 import org.eclipse.debug.core.DebugException;
16 import org.eclipse.debug.internal.ui.DebugUIMessages;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.ui.IDebugUIConstants;
19 import org.eclipse.jface.action.Action;
20 import org.eclipse.jface.window.Window;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.help.WorkbenchHelp;
23
24
25 /**
26  * Go To Address Action for "MemoryViewTab"
27  *
28  * @since 3.0
29  */

30 public class GoToAddressAction extends Action
31 {
32     private ITableMemoryViewTab fViewTab;
33     
34     private static final String JavaDoc PREFIX = "GoToAddressAction."; //$NON-NLS-1$
35
private static final String JavaDoc TITLE = PREFIX + "title"; //$NON-NLS-1$
36
private static final String JavaDoc GO_TO_ADDRESS_FAILED = PREFIX + "Go_to_address_failed"; //$NON-NLS-1$
37
private static final String JavaDoc ADDRESS_IS_INVALID = PREFIX + "Address_is_invalid"; //$NON-NLS-1$
38
private static final String JavaDoc TOOLTIP = PREFIX + "tooltip"; //$NON-NLS-1$
39

40     public GoToAddressAction(ITableMemoryViewTab viewTab)
41     {
42         super(DebugUIMessages.getString(TITLE));
43         fViewTab = viewTab;
44         setToolTipText(DebugUIMessages.getString(TOOLTIP));
45         
46         WorkbenchHelp.setHelp(this, IDebugUIConstants.PLUGIN_ID + ".GoToAddressAction_context"); //$NON-NLS-1$
47

48         // TODO: set image
49
}
50     /* (non-Javadoc)
51      * @see org.eclipse.jface.action.IAction#run()
52      */

53     public void run()
54     {
55         try
56         {
57             Shell shell= DebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
58         
59             // create dialog to ask for expression/address to block
60
GoToAddressDialog dialog = new GoToAddressDialog(shell);
61             dialog.open();
62         
63             int returnCode = dialog.getReturnCode();
64         
65             if (returnCode == Window.CANCEL)
66             {
67                 return;
68             }
69         
70             // get expression from dialog
71
String JavaDoc expression = dialog.getExpression();
72             
73             expression = expression.toUpperCase();
74             expression = expression.trim();
75             
76             if (expression.startsWith("0X")) //$NON-NLS-1$
77
{
78                 expression = expression.substring(2);
79             }
80             
81             // convert expression to address
82
BigInteger JavaDoc address = new BigInteger JavaDoc(expression, 16);
83             
84             // go to specified address
85
fViewTab.goToAddress(address);
86         }
87         // open error in case of any error
88
catch (DebugException e)
89         {
90             MemoryViewUtil.openError(DebugUIMessages.getString(GO_TO_ADDRESS_FAILED),
91                 DebugUIMessages.getString(GO_TO_ADDRESS_FAILED), e);
92         }
93         catch (NumberFormatException JavaDoc e1)
94         {
95             MemoryViewUtil.openError(DebugUIMessages.getString(GO_TO_ADDRESS_FAILED),
96                 DebugUIMessages.getString(ADDRESS_IS_INVALID), null);
97         }
98     }
99
100 }
101
Popular Tags