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