1 11 package org.eclipse.jdt.internal.debug.ui.launcher; 12 13 14 import org.eclipse.debug.ui.StringVariableSelectionDialog; 15 import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants; 16 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 17 import org.eclipse.jdt.internal.debug.ui.actions.RuntimeClasspathAction; 18 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 19 import org.eclipse.jdt.launching.JavaRuntime; 20 import org.eclipse.jface.action.IAction; 21 import org.eclipse.jface.dialogs.Dialog; 22 import org.eclipse.jface.dialogs.IDialogConstants; 23 import org.eclipse.jface.dialogs.IDialogSettings; 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.events.SelectionAdapter; 26 import org.eclipse.swt.events.SelectionEvent; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Button; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Label; 33 import org.eclipse.swt.widgets.Shell; 34 import org.eclipse.swt.widgets.Text; 35 36 39 public class RuntimeClasspathAdvancedDialog extends Dialog { 40 41 private IAction[] fActions; 42 private Button[] fButtons; 43 44 private IClasspathViewer fViewer; 45 private Button fAddVariableStringButton; 46 private Text fVariableString; 47 48 55 public RuntimeClasspathAdvancedDialog(Shell parentShell, IAction[] actions, IClasspathViewer viewer) { 56 super(parentShell); 57 setShellStyle(SWT.RESIZE | getShellStyle()); 58 fActions = actions; 59 fViewer = viewer; 60 } 61 62 65 protected Control createDialogArea(Composite parent) { 66 Composite inner= new Composite(parent, SWT.NONE); 67 GridLayout layout= new GridLayout(); 68 inner.setLayout(layout); 69 70 GridData gd = new GridData(GridData.FILL_BOTH); 71 inner.setLayoutData(gd); 72 73 Label l = new Label(inner, SWT.NONE); 74 l.setText(LauncherMessages.RuntimeClasspathAdvancedDialog_Select_an_advanced_option__1); 75 gd = new GridData(GridData.FILL_HORIZONTAL); 76 l.setLayoutData(gd); 77 78 fButtons = new Button[fActions.length]; 79 for (int i = 0; i < fActions.length; i++) { 80 IAction action= fActions[i]; 81 fButtons[i] = new Button(inner, SWT.RADIO); 82 fButtons[i].setText(action.getText()); 83 fButtons[i].setData(action); 84 fButtons[i].setEnabled(action.isEnabled()); 85 fButtons[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 86 } 87 88 addVariableStringComposite(inner); 89 90 getShell().setText(LauncherMessages.RuntimeClasspathAdvancedDialog_Advanced_Options_1); 91 92 Dialog.applyDialogFont(parent); 93 return inner; 94 } 95 96 private void addVariableStringComposite(Composite composite) { 97 fAddVariableStringButton = new Button(composite, SWT.RADIO); 98 fAddVariableStringButton.setText(LauncherMessages.RuntimeClasspathAdvancedDialog_6); 99 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 100 fAddVariableStringButton.setLayoutData(gd); 101 102 final Composite inner = new Composite(composite, SWT.NONE); 103 inner.setLayout(new GridLayout(2, false)); 104 inner.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 105 106 fVariableString = new Text(inner, SWT.SINGLE | SWT.BORDER); 107 gd = new GridData(GridData.FILL_HORIZONTAL); 108 gd.grabExcessHorizontalSpace = true; 109 fVariableString.setLayoutData(gd); 110 111 final Button fVariablesButton = createButton(inner, IDialogConstants.IGNORE_ID, LauncherMessages.RuntimeClasspathAdvancedDialog_7, false); 112 gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 113 fVariablesButton.setLayoutData(gd); 114 115 fVariablesButton.addSelectionListener(new SelectionAdapter() { 116 public void widgetSelected(SelectionEvent e) { 117 StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); 118 dialog.open(); 119 String variable = dialog.getVariableExpression(); 120 if (variable != null) { 121 fVariableString.insert(variable); 122 } 123 } 124 }); 125 126 fAddVariableStringButton.addSelectionListener(new SelectionAdapter() { 127 public void widgetSelected(SelectionEvent e) { 128 boolean enabled = fAddVariableStringButton.getSelection(); 129 fVariableString.setEnabled(enabled); 130 fVariablesButton.setEnabled(enabled); 131 } 132 }); 133 boolean enabled = fAddVariableStringButton.getSelection(); 135 fVariableString.setEnabled(enabled); 136 fVariablesButton.setEnabled(enabled); 137 } 138 139 142 protected void okPressed() { 143 if (fAddVariableStringButton.getSelection()) { 144 String varString = fVariableString.getText().trim(); 145 if (varString.length() > 0) { 146 IRuntimeClasspathEntry entry = JavaRuntime.newStringVariableClasspathEntry(varString); 147 fViewer.addEntries(new IRuntimeClasspathEntry[] {entry}); 148 } 149 } else { 150 for (int i = 0; i < fButtons.length; i++) { 151 if (fButtons[i].getSelection()) { 152 IAction action = (IAction)fButtons[i].getData(); 153 if (action instanceof RuntimeClasspathAction) { 154 ((RuntimeClasspathAction)action).setShell(getShell()); 155 } 156 action.run(); 157 break; 158 } 159 } 160 } 161 super.okPressed(); 162 } 163 164 protected String getDialogSettingsSectionName() { 165 return IJavaDebugUIConstants.PLUGIN_ID + ".RUNTIME_CLASSPATH_ADVANCED_DIALOG"; } 167 168 171 protected IDialogSettings getDialogBoundsSettings() { 172 IDialogSettings settings = JDIDebugUIPlugin.getDefault().getDialogSettings(); 173 IDialogSettings section = settings.getSection(getDialogSettingsSectionName()); 174 if (section == null) { 175 section = settings.addNewSection(getDialogSettingsSectionName()); 176 } 177 return section; 178 } 179 } 180 | Popular Tags |