KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > elements > adapters > DefaultVariableCellModifier


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.debug.internal.ui.elements.adapters;
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.internal.ui.DefaultLabelProvider;
17 import org.eclipse.debug.internal.ui.actions.variables.details.DetailPaneAssignValueAction;
18 import org.eclipse.jface.viewers.ICellModifier;
19
20 /**
21  * @since 3.2
22  *
23  */

24 public class DefaultVariableCellModifier implements ICellModifier {
25     
26     /* (non-Javadoc)
27      * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
28      */

29     public boolean canModify(Object JavaDoc element, String JavaDoc property) {
30         if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
31             if (element instanceof IVariable) {
32                 return ((IVariable) element).supportsValueModification();
33             }
34         }
35         return false;
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
40      */

41     public Object JavaDoc getValue(Object JavaDoc element, String JavaDoc property) {
42         if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
43             if (element instanceof IVariable) {
44                 IVariable variable = (IVariable) element;
45                 try {
46                     return DefaultLabelProvider.escapeSpecialChars(variable.getValue().getValueString());
47                 } catch (DebugException e) {
48                     DebugUIPlugin.log(e);
49                 }
50             }
51         }
52         return null;
53     }
54
55     /* (non-Javadoc)
56      * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
57      */

58     public void modify(Object JavaDoc element, String JavaDoc property, Object JavaDoc value) {
59         Object JavaDoc oldValue = getValue(element, property);
60         if (!value.equals(oldValue)) {
61             if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
62                 if (element instanceof IVariable) {
63                     if (value instanceof String JavaDoc) {
64                         // The value column displays special characters escaped, so encode the string with any special characters escaped properly
65
String JavaDoc valueExpression = DefaultLabelProvider.encodeEsacpedChars((String JavaDoc)value);
66                         IVariable variable = (IVariable) element;
67                         DetailPaneAssignValueAction.assignValue(DebugUIPlugin.getShell(), variable, valueExpression);
68                     }
69                 }
70             }
71         }
72     }
73
74 }
75
Popular Tags