1 11 package org.eclipse.debug.internal.ui.actions.variables; 12 13 import com.ibm.icu.text.MessageFormat; 14 15 import org.eclipse.core.runtime.IStatus; 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.DebugUIPlugin; 20 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 21 import org.eclipse.debug.internal.ui.VariableValueEditorManager; 22 import org.eclipse.debug.internal.ui.actions.ActionMessages; 23 import org.eclipse.debug.internal.ui.actions.StatusInfo; 24 import org.eclipse.debug.internal.ui.views.variables.VariablesView; 25 import org.eclipse.debug.ui.actions.IVariableValueEditor; 26 import org.eclipse.jface.dialogs.MessageDialog; 27 import org.eclipse.jface.text.BadLocationException; 28 import org.eclipse.jface.text.source.ISourceViewer; 29 import org.eclipse.jface.viewers.IStructuredSelection; 30 import org.eclipse.swt.graphics.Point; 31 import org.eclipse.swt.widgets.Shell; 32 import org.eclipse.ui.IWorkbenchWindow; 33 import org.eclipse.ui.PlatformUI; 34 import org.eclipse.ui.actions.SelectionProviderAction; 35 36 40 public class AssignValueAction extends SelectionProviderAction { 41 private VariablesView variablesView; 42 private ISourceViewer detailsViewer; 43 44 public AssignValueAction(VariablesView varView, ISourceViewer detailViewer) { 45 super(varView.getViewer(), ActionMessages.AssignValueAction_1); 46 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.ASSIGN_VALUE_ACTION); 47 variablesView = varView; 48 detailsViewer = detailViewer; 49 setEnabled(false); 50 variablesView.getSite().getKeyBindingService().registerAction(this); 51 } 52 53 56 public void selectionChanged(IStructuredSelection selection) { 57 boolean enabled = false; 58 if ((selection.size() == 1) && (selection.getFirstElement() instanceof IValueModification)) { 59 IValueModification valMod = (IValueModification) selection.getFirstElement(); 60 if (valMod.supportsValueModification()) { 61 super.selectionChanged(selection); 62 enabled = true; 63 } 64 } 65 setEnabled(enabled); 66 } 67 68 71 public void run() { 72 IVariable variable = (IVariable) getStructuredSelection().getFirstElement(); 73 74 Point selection = detailsViewer.getSelectedRange(); 75 String value = null; 76 if (selection.y == 0) { 77 value = detailsViewer.getDocument().get(); 78 } else { 79 try { 80 value = detailsViewer.getDocument().get(selection.x, selection.y); 81 } catch (BadLocationException e1) { 82 } 83 } 84 IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); 85 Shell activeShell= null; 86 if (window != null) { 87 activeShell= window.getShell(); 88 } 89 90 String modelIdentifier = variable.getModelIdentifier(); 91 IVariableValueEditor editor = VariableValueEditorManager.getDefault().getVariableValueEditor(modelIdentifier); 92 if (editor != null) { 93 if (editor.saveVariable(variable, value, activeShell)) { 94 return; 97 } 98 } 99 100 try { 101 if (variable.verifyValue(value)) { 103 variable.setValue(value); 104 } else { 105 if (activeShell != null) { 106 DebugUIPlugin.errorDialog(activeShell, ActionMessages.AssignValueAction_2, MessageFormat.format(ActionMessages.AssignValueAction_3, new String [] {value, variable.getName()}), new StatusInfo(IStatus.ERROR, ActionMessages.AssignValueAction_4)); } 108 } 109 } catch (DebugException e) { 110 MessageDialog.openError(activeShell, ActionMessages.AssignValueAction_0, ActionMessages.AssignValueAction_5); 111 } 112 113 } 114 115 118 public String getActionDefinitionId() { 119 return "org.eclipse.ui.file.save"; } 121 122 } 123 | Popular Tags |