1 12 package org.eclipse.debug.internal.ui.stringsubstitution; 13 14 import com.ibm.icu.text.MessageFormat; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.core.variables.IDynamicVariable; 20 import org.eclipse.core.variables.IDynamicVariableResolver; 21 import org.eclipse.debug.core.DebugException; 22 import org.eclipse.debug.internal.ui.DebugUIPlugin; 23 import org.eclipse.swt.widgets.Shell; 24 25 29 abstract class PromptingResolver implements IDynamicVariableResolver { 30 31 36 protected String promptHint = null; 37 40 protected String dialogMessage = null; 41 44 protected String defaultValue = null; 45 48 protected String lastValue = null; 49 52 protected String dialogResultString = null; 53 54 58 public abstract void prompt(); 59 60 68 protected void setupDialog(String varValue) { 69 promptHint = null; 70 defaultValue = null; 71 dialogResultString = null; 72 if (varValue != null) { 73 int idx = varValue.indexOf(':'); 74 if (idx != -1) { 75 promptHint = varValue.substring(0, idx); 76 defaultValue = varValue.substring(idx + 1); 77 } else { 78 promptHint = varValue; 79 } 80 } 81 82 if (promptHint != null) { 83 dialogMessage = MessageFormat.format(StringSubstitutionMessages.PromptExpanderBase_0, new String [] {promptHint}); 84 } else { 85 dialogMessage = StringSubstitutionMessages.PromptExpanderBase_1; 86 } 87 } 88 89 92 public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { 93 String value = null; 94 setupDialog(argument); 95 96 DebugUIPlugin.getStandardDisplay().syncExec(new Runnable () { 97 public void run() { 98 prompt(); 99 } 100 }); 101 if (dialogResultString != null) { 102 value = dialogResultString; 103 lastValue = dialogResultString; 104 } else { 105 throw new DebugException(new Status(IStatus.CANCEL, DebugUIPlugin.getUniqueIdentifier(), IStatus.CANCEL, MessageFormat.format(StringSubstitutionMessages.PromptingResolver_0, new String [] { variable.getName() }), null)); 107 } 108 return value; 109 } 110 111 protected Shell getShell() { 112 return DebugUIPlugin.getShell(); 113 } 114 115 } 116 | Popular Tags |