KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > JavaVariableValueEditor


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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 implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.actions;
12
13 import org.eclipse.debug.core.DebugException;
14 import org.eclipse.debug.core.model.IVariable;
15 import org.eclipse.debug.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.ui.actions.IVariableValueEditor;
17 import org.eclipse.jdt.debug.core.IJavaVariable;
18 import org.eclipse.jdt.internal.debug.ui.JDIModelPresentation;
19 import org.eclipse.swt.widgets.Shell;
20
21 /**
22  * Variable editor that prompts the user to edit Java variables
23  */

24 public class JavaVariableValueEditor implements IVariableValueEditor {
25
26     /* (non-Javadoc)
27      * @see org.eclipse.debug.ui.actions.IVariableValueEditor#editVariable(org.eclipse.debug.core.model.IVariable, org.eclipse.swt.widgets.Shell)
28      */

29     public boolean editVariable(IVariable variable, Shell shell) {
30         String JavaDoc signature= null;
31         try {
32             signature= getSignature(variable);
33         } catch (DebugException e) {
34             DebugUIPlugin.errorDialog(shell, ActionMessages.JavaVariableValueEditor_0, ActionMessages.JavaVariableValueEditor_1, e); //
35
}
36         if (signature == null) {
37             return false;
38         }
39         IVariableValueEditor editor;
40         if (JDIModelPresentation.isObjectValue(signature)) {
41             editor= new JavaObjectValueEditor();
42         } else {
43             // Primitive variable
44
editor= new JavaPrimitiveValueEditor(signature);
45         }
46         return editor.editVariable(variable, shell);
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.debug.ui.actions.IVariableValueEditor#saveVariable(org.eclipse.debug.core.model.IVariable, java.lang.String, org.eclipse.swt.widgets.Shell)
51      */

52     public boolean saveVariable(IVariable variable, String JavaDoc expression, Shell shell) {
53         try {
54             if (JDIModelPresentation.isObjectValue(getSignature(variable))) {
55                 IVariableValueEditor editor= new JavaObjectValueEditor();
56                 return editor.saveVariable(variable, expression, shell);
57             }
58         } catch (DebugException e) {
59             DebugUIPlugin.errorDialog(shell, ActionMessages.JavaVariableValueEditor_0, ActionMessages.JavaVariableValueEditor_1, e); //
60
}
61         return false;
62     }
63     
64     public static String JavaDoc getSignature(IVariable variable) throws DebugException {
65         String JavaDoc signature= null;
66         IJavaVariable javaVariable = (IJavaVariable) variable.getAdapter(IJavaVariable.class);
67         if (javaVariable != null) {
68                 signature = javaVariable.getSignature();
69         }
70         return signature;
71     }
72
73 }
74
Popular Tags