KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > variables > JavaVariableCellModifier


1 /*******************************************************************************
2  * Copyright (c) 2006, 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 package org.eclipse.jdt.internal.debug.ui.variables;
12
13 import org.eclipse.debug.core.DebugException;
14 import org.eclipse.debug.internal.ui.elements.adapters.DefaultVariableCellModifier;
15 import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnPresentation;
16 import org.eclipse.jdt.core.Signature;
17 import org.eclipse.jdt.debug.core.IJavaVariable;
18
19 /**
20  * @since 3.2
21  *
22  */

23 public class JavaVariableCellModifier extends DefaultVariableCellModifier {
24     
25     /*
26      * (non-Javadoc)
27      *
28      * @see org.eclipse.debug.internal.ui.elements.adapters.DefaultVariableCellModifier#canModify(java.lang.Object,
29      * java.lang.String)
30      */

31     public boolean canModify(Object JavaDoc element, String JavaDoc property) {
32         if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
33             if (element instanceof IJavaVariable) {
34                 IJavaVariable var = (IJavaVariable) element;
35                 if (var.supportsValueModification()){
36                     try {
37                         String JavaDoc signature = var.getSignature();
38                         if (signature != null) {
39                             if (signature.length() == 1) {
40                                 // primitive
41
return true;
42                             }
43                             return signature.equals("Ljava/lang/String;"); //$NON-NLS-1$
44
}
45                     } catch (DebugException e) {
46                     }
47                 }
48             }
49         }
50         return false;
51     }
52
53     /*
54      * (non-Javadoc)
55      *
56      * @see org.eclipse.debug.internal.ui.elements.adapters.DefaultVariableCellModifier#getValue(java.lang.Object,
57      * java.lang.String)
58      */

59     public Object JavaDoc getValue(Object JavaDoc element, String JavaDoc property) {
60         if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
61             if (element instanceof IJavaVariable) {
62                 IJavaVariable var = (IJavaVariable) element;
63                 if (isBoolean(var)) {
64                     try {
65                         if (var.getValue().getValueString().equals(Boolean.toString(true))) {
66                             return new Integer JavaDoc(0);
67                         } else {
68                             return new Integer JavaDoc(1);
69                         }
70                     } catch (DebugException e) {
71                     }
72                 }
73             }
74         }
75         return super.getValue(element, property);
76     }
77
78     public void modify(Object JavaDoc element, String JavaDoc property, Object JavaDoc value) {
79         Object JavaDoc oldValue = getValue(element, property);
80         if (!value.equals(oldValue)) {
81             if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
82                 if (element instanceof IJavaVariable) {
83                     IJavaVariable var = (IJavaVariable) element;
84                     if (isBoolean(var)) {
85                         if (value instanceof Integer JavaDoc) {
86                             switch (((Integer JavaDoc) value).intValue()) {
87                             case 0:
88                                 super.modify(element, property, Boolean.toString(true));
89                                 return;
90                             case 1:
91                                 super.modify(element, property, Boolean.toString(false));
92                                 return;
93                             default:
94                                 // invalid value
95
return;
96                             }
97                         } else {
98                             // invalid value
99
return;
100                         }
101                     }
102                 }
103             }
104             super.modify(element, property, value);
105         }
106     }
107
108     /**
109      * Returns whether the given variable is a boolean.
110      *
111      * @param variable
112      * @return
113      */

114     public static boolean isBoolean(IJavaVariable variable) {
115         try {
116             String JavaDoc signature = variable.getSignature();
117             return (signature.length() == 1 && signature.charAt(0) == Signature.C_BOOLEAN);
118         } catch (DebugException e) {
119         }
120         return false;
121     }
122
123 }
124
Popular Tags