1 11 package org.eclipse.debug.internal.ui.actions.variables.details; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.debug.core.DebugException; 15 import org.eclipse.debug.core.model.IValueModification; 16 import org.eclipse.debug.core.model.IVariable; 17 import org.eclipse.debug.internal.ui.DebugUIPlugin; 18 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 19 import org.eclipse.debug.internal.ui.VariableValueEditorManager; 20 import org.eclipse.debug.internal.ui.actions.ActionMessages; 21 import org.eclipse.debug.internal.ui.actions.StatusInfo; 22 import org.eclipse.debug.ui.actions.IVariableValueEditor; 23 import org.eclipse.jface.action.Action; 24 import org.eclipse.jface.commands.ActionHandler; 25 import org.eclipse.jface.dialogs.MessageDialog; 26 import org.eclipse.jface.text.BadLocationException; 27 import org.eclipse.jface.text.ITextViewer; 28 import org.eclipse.jface.viewers.IStructuredSelection; 29 import org.eclipse.swt.graphics.Point; 30 import org.eclipse.swt.widgets.Shell; 31 import org.eclipse.ui.IViewSite; 32 import org.eclipse.ui.IWorkbenchWindow; 33 import org.eclipse.ui.PlatformUI; 34 import org.eclipse.ui.handlers.IHandlerActivation; 35 import org.eclipse.ui.handlers.IHandlerService; 36 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; 37 38 import com.ibm.icu.text.MessageFormat; 39 40 44 public class DetailPaneAssignValueAction extends Action{ 45 46 private IHandlerActivation fHandlerActivation; 47 private IViewSite fViewSite; 48 private ITextViewer fTextViewer; 49 private IStructuredSelection fCurrentSelection; 50 51 63 public static void assignValue(Shell shell, IVariable variable, String newValueExpression){ 64 String modelIdentifier = variable.getModelIdentifier(); 65 IVariableValueEditor editor = VariableValueEditorManager.getDefault().getVariableValueEditor(modelIdentifier); 66 if (editor != null) { 67 if (editor.saveVariable(variable, newValueExpression, shell)) { 68 return; 71 } 72 } 73 74 try { 75 if (variable.verifyValue(newValueExpression)) { 77 variable.setValue(newValueExpression); 78 } else { 79 if (shell != null) { 80 DebugUIPlugin.errorDialog(shell, ActionMessages.DetailPaneAssignValueAction_2, MessageFormat.format(ActionMessages.DetailPaneAssignValueAction_3, new String [] {newValueExpression, variable.getName()}), new StatusInfo(IStatus.ERROR, ActionMessages.DetailPaneAssignValueAction_4)); } 82 } 83 } catch (DebugException e) { 84 MessageDialog.openError(shell, ActionMessages.DetailPaneAssignValueAction_0, e.getStatus().getMessage()); 85 } 86 } 87 88 public DetailPaneAssignValueAction(ITextViewer textViewer, IViewSite viewSite) { 89 super(ActionMessages.DetailPaneAssignValueAction_1); 90 91 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.DETAIL_PANE_ASSIGN_VALUE_ACTION); 92 93 fTextViewer = textViewer; 94 fViewSite = viewSite; 95 96 setEnabled(false); 97 IHandlerService service = (IHandlerService) fViewSite.getService(IHandlerService.class); 98 ActionHandler handler = new ActionHandler(this); 99 fHandlerActivation = service.activateHandler(getActionDefinitionId(), handler); 100 } 101 102 public void dispose() { 103 IHandlerService service = (IHandlerService) fViewSite.getService(IHandlerService.class); 104 service.deactivateHandler(fHandlerActivation); 105 } 106 107 public void updateCurrentVariable(IStructuredSelection selection) { 108 boolean enabled = false; 109 if ((selection.size() == 1) && (selection.getFirstElement() instanceof IValueModification)) { 110 IValueModification valMod = (IValueModification) selection.getFirstElement(); 111 if (valMod.supportsValueModification()) { 112 fCurrentSelection = selection; 113 enabled = true; 114 } 115 } 116 setEnabled(enabled); 117 } 118 119 122 public void run() { 123 IVariable variable = (IVariable) fCurrentSelection.getFirstElement(); 124 125 Point selection = fTextViewer.getSelectedRange(); 126 String value = null; 127 if (selection.y == 0) { 128 value = fTextViewer.getDocument().get(); 129 } else { 130 try { 131 value = fTextViewer.getDocument().get(selection.x, selection.y); 132 } catch (BadLocationException e1) { 133 } 134 } 135 IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); 136 Shell activeShell= null; 137 if (window != null) { 138 activeShell= window.getShell(); 139 } 140 141 assignValue(activeShell, variable, value); 142 } 143 144 147 public String getActionDefinitionId() { 148 return IWorkbenchActionDefinitionIds.SAVE; 149 } 150 151 } 152 | Popular Tags |