1 11 package org.eclipse.debug.internal.ui.actions.variables; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 import java.util.Iterator ; 16 import org.eclipse.debug.core.DebugException; 17 import org.eclipse.debug.core.model.IValueModification; 18 import org.eclipse.debug.core.model.IVariable; 19 import org.eclipse.debug.internal.ui.DebugPluginImages; 20 import org.eclipse.debug.internal.ui.DebugUIPlugin; 21 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 22 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 23 import org.eclipse.debug.internal.ui.VariableValueEditorManager; 24 import org.eclipse.debug.internal.ui.actions.ActionMessages; 25 import org.eclipse.debug.internal.ui.views.variables.VariablesView; 26 import org.eclipse.debug.ui.IDebugUIConstants; 27 import org.eclipse.debug.ui.actions.IVariableValueEditor; 28 import org.eclipse.jface.dialogs.IInputValidator; 29 import org.eclipse.jface.viewers.IStructuredSelection; 30 import org.eclipse.jface.viewers.StructuredSelection; 31 import org.eclipse.swt.widgets.Shell; 32 import org.eclipse.ui.PlatformUI; 33 import org.eclipse.ui.actions.SelectionProviderAction; 34 35 41 public class ChangeVariableValueAction extends SelectionProviderAction { 42 43 protected IVariable fVariable; 44 private VariablesView fView; 45 private boolean fEditing= false; 46 47 51 public ChangeVariableValueAction(VariablesView view) { 52 super(view.getViewer(), ActionMessages.ChangeVariableValue_title); 53 setDescription(ActionMessages.ChangeVariableValue_toolTipText); 54 setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_CHANGE_VARIABLE_VALUE)); 55 setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_CHANGE_VARIABLE_VALUE)); 56 setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_CHANGE_VARIABLE_VALUE)); 57 PlatformUI.getWorkbench().getHelpSystem().setHelp( 58 this, 59 IDebugHelpContextIds.CHANGE_VALUE_ACTION); 60 fView= view; 61 } 62 63 66 protected void doActionPerformed(final IVariable variable) { 67 Shell shell = fView.getViewSite().getShell(); 68 if (fEditing) { 70 return; 71 } 72 fEditing= true; 73 fVariable = variable; 74 if (!delegateEdit(shell)) { 75 doDefaultEdit(shell); 76 } 77 fEditing= false; 78 } 79 80 89 private boolean delegateEdit(Shell shell) { 90 String modelIdentifier = fVariable.getModelIdentifier(); 91 IVariableValueEditor editor= VariableValueEditorManager.getDefault().getVariableValueEditor(modelIdentifier); 92 if (editor != null) { 93 return editor.editVariable(fVariable, shell); 94 } 95 return false; 96 } 97 98 102 protected void doDefaultEdit(Shell shell) { 103 String name= ""; String value= ""; try { 106 name= fVariable.getName(); 107 value= fVariable.getValue().getValueString(); 108 } catch (DebugException exception) { 109 DebugUIPlugin.errorDialog(shell, ActionMessages.ChangeVariableValue_errorDialogTitle,ActionMessages.ChangeVariableValue_errorDialogMessage, exception); return; 111 } 112 ChangeVariableValueInputDialog inputDialog= new ChangeVariableValueInputDialog(shell, ActionMessages.ChangeVariableValue_1, MessageFormat.format(ActionMessages.ChangeVariableValue_2, new String [] {name}), value, new IInputValidator() { 116 public String isValid(String input) { 117 try { 118 if (fVariable.verifyValue(input)) { 119 return null; } 121 } catch (DebugException exception) { 122 return ActionMessages.ChangeVariableValue_3; 123 } 124 return ActionMessages.ChangeVariableValue_4; 125 } 126 }); 127 128 inputDialog.open(); 129 String newValue= inputDialog.getValue(); 130 if (newValue != null) { 131 try { 133 fVariable.setValue(newValue); 134 getSelectionProvider().setSelection(new StructuredSelection(fVariable)); 135 } catch (DebugException de) { 136 DebugUIPlugin.errorDialog(shell, ActionMessages.ChangeVariableValue_errorDialogTitle,ActionMessages.ChangeVariableValue_errorDialogMessage, de); } 138 } 139 } 140 141 145 protected void update(IStructuredSelection sel) { 146 Iterator iter= sel.iterator(); 147 if (iter.hasNext()) { 148 Object object= iter.next(); 149 if (object instanceof IValueModification) { 150 IValueModification varMod= (IValueModification)object; 151 if (!varMod.supportsValueModification()) { 152 setEnabled(false); 153 return; 154 } 155 setEnabled(!iter.hasNext()); 156 return; 157 } 158 } 159 setEnabled(false); 160 } 161 162 165 public void run() { 166 Iterator iterator= getStructuredSelection().iterator(); 167 doActionPerformed((IVariable)iterator.next()); 168 } 169 170 173 public void selectionChanged(IStructuredSelection sel) { 174 update(sel); 175 } 176 } 177 178 | Popular Tags |