1 11 package org.eclipse.debug.ui; 12 13 import org.eclipse.core.variables.IDynamicVariable; 14 import org.eclipse.core.variables.IStringVariable; 15 import org.eclipse.core.variables.VariablesPlugin; 16 import org.eclipse.debug.internal.ui.DebugUIPlugin; 17 import org.eclipse.debug.internal.ui.SWTFactory; 18 import org.eclipse.debug.internal.ui.preferences.StringVariablePreferencePage; 19 import org.eclipse.debug.internal.ui.stringsubstitution.IArgumentSelector; 20 import org.eclipse.debug.internal.ui.stringsubstitution.StringSubstitutionMessages; 21 import org.eclipse.debug.internal.ui.stringsubstitution.StringVariableLabelProvider; 22 import org.eclipse.debug.internal.ui.stringsubstitution.StringVariablePresentationManager; 23 import org.eclipse.jface.dialogs.IDialogConstants; 24 import org.eclipse.jface.dialogs.IDialogSettings; 25 import org.eclipse.jface.preference.IPreferenceNode; 26 import org.eclipse.jface.preference.PreferenceDialog; 27 import org.eclipse.jface.preference.PreferenceManager; 28 import org.eclipse.jface.preference.PreferenceNode; 29 import org.eclipse.jface.preference.PreferencePage; 30 import org.eclipse.swt.SWT; 31 import org.eclipse.swt.custom.BusyIndicator; 32 import org.eclipse.swt.events.SelectionAdapter; 33 import org.eclipse.swt.events.SelectionEvent; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.layout.GridLayout; 36 import org.eclipse.swt.widgets.Button; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Control; 39 import org.eclipse.swt.widgets.Display; 40 import org.eclipse.swt.widgets.Label; 41 import org.eclipse.swt.widgets.Shell; 42 import org.eclipse.swt.widgets.Text; 43 import org.eclipse.ui.dialogs.ElementListSelectionDialog; 44 45 53 public class StringVariableSelectionDialog extends ElementListSelectionDialog { 54 55 private Button fArgumentButton; 57 private Text fDescriptionText; 59 private Text fArgumentText; 61 private String fArgumentValue; 62 private Button fEditVariablesButton; 63 64 69 public StringVariableSelectionDialog(Shell parent) { 70 super(parent, new StringVariableLabelProvider()); 71 setShellStyle(getShellStyle() | SWT.RESIZE); 72 setTitle(StringSubstitutionMessages.StringVariableSelectionDialog_2); 73 setMessage(StringSubstitutionMessages.StringVariableSelectionDialog_3); 74 setMultipleSelection(false); 75 setElements(VariablesPlugin.getDefault().getStringVariableManager().getVariables()); 76 } 77 78 85 public String getVariableExpression() { 86 Object [] selected = getResult(); 87 if (selected != null && selected.length == 1) { 88 IStringVariable variable = (IStringVariable)selected[0]; 89 StringBuffer buffer = new StringBuffer (); 90 buffer.append("${"); buffer.append(variable.getName()); 92 if (fArgumentValue != null && fArgumentValue.length() > 0) { 93 buffer.append(":"); buffer.append(fArgumentValue); 95 } 96 buffer.append("}"); return buffer.toString(); 98 } 99 return null; 100 } 101 102 105 protected Control createDialogArea(Composite parent) { 106 Control control = super.createDialogArea(parent); 107 createArgumentArea((Composite)control); 108 return control; 109 } 110 111 117 private void createArgumentArea(Composite parent) { 118 Composite container = new Composite(parent, SWT.NONE); 119 GridLayout layout = new GridLayout(); 120 layout.numColumns = 2; 121 layout.makeColumnsEqualWidth = false; 122 layout.marginHeight = 0; 123 layout.marginWidth = 0; 124 container.setLayout(layout); 125 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 126 container.setLayoutData(gd); 127 container.setFont(parent.getFont()); 128 129 fEditVariablesButton = new Button(container, SWT.PUSH); 130 fEditVariablesButton.setFont(container.getFont()); 131 fEditVariablesButton.setText(StringSubstitutionMessages.StringVariableSelectionDialog_0); 132 gd = new GridData(GridData.HORIZONTAL_ALIGN_END); 133 gd.horizontalSpan = 2; 134 fEditVariablesButton.setLayoutData(gd); 135 fEditVariablesButton.addSelectionListener(new SelectionAdapter() { 136 public void widgetSelected(SelectionEvent e) { 137 editVariables(); 138 } 139 }); 140 141 Label desc = new Label(container, SWT.NONE); 142 desc.setFont(parent.getFont()); 143 desc.setText(StringSubstitutionMessages.StringVariableSelectionDialog_6); 144 gd = new GridData(GridData.FILL_HORIZONTAL); 145 gd.horizontalSpan = 2; 146 desc.setLayoutData(gd); 147 148 Composite args = new Composite(container, SWT.NONE); 149 layout = new GridLayout(2, false); 150 layout.marginHeight = 0; 151 layout.marginWidth = 0; 152 args.setLayout(layout); 153 gd = new GridData(GridData.FILL_HORIZONTAL); 154 gd.horizontalSpan = 2; 155 args.setLayoutData(gd); 156 args.setFont(container.getFont()); 157 158 fArgumentText = new Text(args, SWT.BORDER); 159 fArgumentText.setFont(container.getFont()); 160 gd = new GridData(GridData.FILL_HORIZONTAL); 161 fArgumentText.setLayoutData(gd); 162 163 fArgumentButton = new Button(args, SWT.PUSH); 164 fArgumentButton.setFont(parent.getFont()); 165 fArgumentButton.setText(StringSubstitutionMessages.StringVariableSelectionDialog_7); 166 gd = new GridData(GridData.HORIZONTAL_ALIGN_END); 167 gd.widthHint = SWTFactory.getButtonWidthHint(fArgumentButton); 168 fArgumentButton.setLayoutData(gd); 169 fArgumentButton.addSelectionListener(new SelectionAdapter() { 170 public void widgetSelected(SelectionEvent e) { 171 configureArgument(); 172 } 173 }); 174 175 176 desc = new Label(container, SWT.NONE); 177 desc.setFont(parent.getFont()); 178 desc.setText(StringSubstitutionMessages.StringVariableSelectionDialog_8); 179 gd = new GridData(GridData.FILL_HORIZONTAL); 180 gd.horizontalSpan = 2; 181 desc.setLayoutData(gd); 182 183 fDescriptionText = new Text(container, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); 184 fDescriptionText.setFont(container.getFont()); 185 fDescriptionText.setEditable(false); 186 gd = new GridData(GridData.FILL_HORIZONTAL); 187 gd.horizontalSpan = 2; 188 gd.heightHint = 50; 189 fDescriptionText.setLayoutData(gd); 190 } 191 192 protected void editVariables() { 193 PreferencePage page = new StringVariablePreferencePage(); 194 page.setTitle(StringSubstitutionMessages.StringVariableSelectionDialog_1); 195 final IPreferenceNode targetNode = new PreferenceNode("org.eclipse.debug.ui.StringVariablePreferencePage", page); 197 PreferenceManager manager = new PreferenceManager(); 198 manager.addToRoot(targetNode); 199 final PreferenceDialog dialog = new PreferenceDialog(getShell(), manager); 200 201 final Display display = DebugUIPlugin.getStandardDisplay(); 202 BusyIndicator.showWhile(display, new Runnable () { 203 public void run() { 204 dialog.create(); 205 dialog.setMessage(targetNode.getLabelText()); 206 if(dialog.open() == IDialogConstants.OK_ID) { 207 final IStringVariable[] elements = VariablesPlugin.getDefault().getStringVariableManager().getVariables(); 208 display.asyncExec(new Runnable () { 209 public void run() { 210 setListElements(elements); 211 } 212 }); 213 } 214 } 215 }); 216 } 217 218 221 protected void configureArgument() { 222 Object [] objects = getSelectedElements(); 223 IStringVariable variable = (IStringVariable)objects[0]; 224 IArgumentSelector selector = StringVariablePresentationManager.getDefault().getArgumentSelector(variable); 225 String value = selector.selectArgument(variable, getShell()); 226 if (value != null) { 227 fArgumentText.setText(value); 228 } 229 } 230 231 236 protected void handleSelectionChanged() { 237 super.handleSelectionChanged(); 238 Object [] objects = getSelectedElements(); 239 boolean buttonEnabled = false; 240 boolean argEnabled = false; 241 String text = null; 242 if (objects.length == 1) { 243 IStringVariable variable = (IStringVariable)objects[0]; 244 IArgumentSelector selector = StringVariablePresentationManager.getDefault().getArgumentSelector(variable); 245 if (variable instanceof IDynamicVariable) { 246 argEnabled = ((IDynamicVariable)variable).supportsArgument(); 247 } 248 buttonEnabled = argEnabled && selector != null; 249 text = variable.getDescription(); 250 } 251 if (text == null) { 252 text = ""; } 254 fArgumentText.setEnabled(argEnabled); 255 fArgumentButton.setEnabled(buttonEnabled); 256 fDescriptionText.setText(text); 257 } 258 259 262 protected void okPressed() { 263 fArgumentValue = fArgumentText.getText().trim(); 264 super.okPressed(); 265 } 266 267 272 private String getDialogSettingsSectionName() { 273 return IDebugUIConstants.PLUGIN_ID + ".STRING_VARIABLE_SELECTION_DIALOG_SECTION"; } 275 276 279 protected IDialogSettings getDialogBoundsSettings() { 280 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 281 IDialogSettings section = settings.getSection(getDialogSettingsSectionName()); 282 if (section == null) { 283 section = settings.addNewSection(getDialogSettingsSectionName()); 284 } 285 return section; 286 } 287 } 288 | Popular Tags |