1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 18 import org.eclipse.debug.core.ILaunchDelegate; 19 import org.eclipse.debug.internal.ui.DebugUIPlugin; 20 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 21 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 22 import org.eclipse.debug.internal.ui.SWTFactory; 23 import org.eclipse.debug.ui.IDebugUIConstants; 24 import org.eclipse.jface.dialogs.IDialogConstants; 25 import org.eclipse.jface.dialogs.IDialogSettings; 26 import org.eclipse.jface.viewers.CheckStateChangedEvent; 27 import org.eclipse.jface.viewers.CheckboxTableViewer; 28 import org.eclipse.jface.viewers.IBaseLabelProvider; 29 import org.eclipse.jface.viewers.ICheckStateListener; 30 import org.eclipse.jface.viewers.ILabelProvider; 31 import org.eclipse.jface.viewers.ILabelProviderListener; 32 import org.eclipse.jface.viewers.ISelectionChangedListener; 33 import org.eclipse.jface.viewers.IStructuredSelection; 34 import org.eclipse.jface.viewers.SelectionChangedEvent; 35 import org.eclipse.jface.viewers.StructuredSelection; 36 import org.eclipse.swt.SWT; 37 import org.eclipse.swt.events.SelectionEvent; 38 import org.eclipse.swt.events.SelectionListener; 39 import org.eclipse.swt.graphics.Image; 40 import org.eclipse.swt.graphics.Point; 41 import org.eclipse.swt.layout.GridData; 42 import org.eclipse.swt.widgets.Button; 43 import org.eclipse.swt.widgets.Composite; 44 import org.eclipse.swt.widgets.Group; 45 import org.eclipse.swt.widgets.Link; 46 import org.eclipse.swt.widgets.Shell; 47 import org.eclipse.swt.widgets.Text; 48 49 55 public class SelectLaunchersDialog extends AbstractDebugCheckboxSelectionDialog { 56 57 60 class DelegatesLabelProvider implements ILabelProvider { 61 public Image getImage(Object element) {return null;} 62 public String getText(Object element) { 63 if(element instanceof ILaunchDelegate) { 64 ILaunchDelegate ldp = (ILaunchDelegate) element; 65 String name = ldp.getName(); 66 if(name == null) { 67 name = ldp.getContributorName(); 68 } 69 return name; 70 } 71 return element.toString(); 72 } 73 public void addListener(ILabelProviderListener listener) {} 74 public void dispose() {} 75 public boolean isLabelProperty(Object element, String property) {return false;} 76 public void removeListener(ILabelProviderListener listener) {} 77 } 78 79 private Text fDescriptionText = null; 80 private ILaunchDelegate[] fDelegates = null; 81 private Button fUseSystemLauncher = null; 82 private ILaunchConfigurationWorkingCopy fConfiguration = null; 83 private String fLaunchMode = null; 84 85 89 public SelectLaunchersDialog(Shell parentShell, ILaunchDelegate[] delegates, ILaunchConfigurationWorkingCopy configuration, String launchmode) { 90 super(parentShell); 91 super.setTitle(LaunchConfigurationsMessages.SelectLaunchersDialog_0); 92 setShellStyle(getShellStyle() | SWT.RESIZE); 93 fDelegates = delegates; 94 fConfiguration = configuration; 95 fLaunchMode = launchmode; 96 } 97 98 101 protected Point getInitialSize() { 102 IDialogSettings settings = getDialogBoundsSettings(); 103 if(settings != null) { 104 try { 105 int width = settings.getInt("DIALOG_WIDTH"); int height = settings.getInt("DIALOG_HEIGHT"); if(width > 0 & height > 0) { 108 return new Point(width, height); 109 } 110 } 111 catch (NumberFormatException nfe) { 112 return new Point(450, 450); 113 } 114 } 115 return new Point(450, 450); 116 } 117 118 121 protected String getDialogSettingsId() { 122 return IDebugUIConstants.PLUGIN_ID + ".SELECT_LAUNCHERS_DIALOG"; } 124 125 128 protected String getHelpContextId() { 129 return IDebugHelpContextIds.SELECT_LAUNCHERS_DIALOG; 130 } 131 132 135 protected IBaseLabelProvider getLabelProvider() { 136 return new DelegatesLabelProvider(); 137 } 138 139 142 protected Object getViewerInput() { 143 return fDelegates; 144 } 145 146 149 protected void createButtonsForButtonBar(Composite parent) { 150 super.createButtonsForButtonBar(parent); 151 getButton(IDialogConstants.OK_ID).setEnabled(true); 153 } 154 155 158 protected void addCustomHeaderControls(Composite parent) { 159 SWTFactory.createWrapLabel(parent, LaunchConfigurationsMessages.SelectLaunchersDialog_2, 1); 160 Link link = new Link(parent, SWT.WRAP); 161 link.setText(LaunchConfigurationsMessages.SelectLaunchersDialog_4); 162 link.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); 163 link.addSelectionListener(new SelectionListener() { 164 public void widgetDefaultSelected(SelectionEvent e) {} 165 public void widgetSelected(SelectionEvent e) { 166 SWTFactory.showPreferencePage("org.eclipse.debug.ui.LaunchDelegatesPreferencePage"); if(!fUseSystemLauncher.getSelection()) { 168 resetDelegate(); 169 } 170 } 171 }); 172 fUseSystemLauncher = SWTFactory.createCheckButton(parent, LaunchConfigurationsMessages.SelectLaunchersDialog_1, null, true, 1); 173 fUseSystemLauncher.addSelectionListener(new SelectionListener() { 174 public void widgetDefaultSelected(SelectionEvent e) {} 175 public void widgetSelected(SelectionEvent e) { 176 boolean checked = ((Button)e.widget).getSelection(); 177 getCheckBoxTableViewer().getTable().setEnabled(checked); 178 resetDelegate(); 179 } 180 }); 181 } 182 183 187 protected ILaunchDelegate getSelectedDelegate() { 188 Object [] checked = getCheckBoxTableViewer().getCheckedElements(); 189 if(checked.length > 0) { 190 return (ILaunchDelegate) checked[0]; 191 } 192 return null; 193 } 194 195 198 protected void okPressed() { 199 ILaunchDelegate delegate = null; 200 Set modes = getCurrentModeSet(); 201 if(fUseSystemLauncher.getSelection()) { 202 delegate = getSelectedDelegate(); 203 if(delegate != null) { 204 fConfiguration.setPreferredLaunchDelegate(modes, delegate.getId()); 205 } 206 } 207 else { 208 fConfiguration.setPreferredLaunchDelegate(modes, null); 209 } 210 if(fConfiguration.isDirty()) { 211 try { 212 fConfiguration.doSave(); 213 } 214 catch (CoreException e) {DebugUIPlugin.log(e);} 215 } 216 super.okPressed(); 217 } 218 219 222 private void resetDelegate() { 223 if(!fUseSystemLauncher.getSelection()) { 224 try { 225 ILaunchDelegate preferred = fConfiguration.getType().getPreferredDelegate(getCurrentModeSet()); 226 CheckboxTableViewer viewer = getCheckBoxTableViewer(); 227 if(preferred != null) { 228 viewer.setSelection(new StructuredSelection(preferred)); 229 viewer.setCheckedElements(new Object [] {preferred}); 230 } 231 else { 232 viewer.setSelection(new StructuredSelection()); 233 viewer.setAllChecked(false); 234 } 235 } 236 catch (CoreException ce) {DebugUIPlugin.log(ce);} 237 } 238 } 239 240 243 protected void addCustomFooterControls(Composite parent) { 244 Group group = SWTFactory.createGroup(parent, LaunchConfigurationsMessages.SelectLaunchersDialog_5, 1, 1, GridData.FILL_BOTH); 245 fDescriptionText = SWTFactory.createText(group, SWT.WRAP | SWT.READ_ONLY, 1, GridData.FILL_BOTH); 246 fDescriptionText.setBackground(group.getBackground()); 247 } 248 249 252 protected Set getCurrentModeSet() { 253 Set modes = new HashSet (); 254 try { 255 modes = fConfiguration.getModes(); 256 modes.add(fLaunchMode); 257 } 258 catch (CoreException ce) {DebugUIPlugin.log(ce);} 259 return modes; 260 } 261 262 265 protected void initializeControls() { 266 final CheckboxTableViewer viewer = getCheckBoxTableViewer(); 267 viewer.addCheckStateListener(new ICheckStateListener() { 268 public void checkStateChanged(CheckStateChangedEvent event) { 269 viewer.setCheckedElements(new Object []{event.getElement()}); 270 } 271 }); 272 viewer.addSelectionChangedListener(new ISelectionChangedListener() { 273 public void selectionChanged(SelectionChangedEvent event) { 274 IStructuredSelection ss = (IStructuredSelection) event.getSelection(); 275 if(ss != null && !ss.isEmpty()) { 276 fDescriptionText.setText(((ILaunchDelegate)ss.getFirstElement()).getDescription()); 277 } 278 else { 279 fDescriptionText.setText(IInternalDebugUIConstants.EMPTY_STRING); 280 } 281 } 282 }); 283 try { 284 ILaunchDelegate delegate = fConfiguration.getPreferredDelegate(getCurrentModeSet()); 285 boolean custom = delegate != null; 286 fUseSystemLauncher.setSelection(custom); 287 if(custom) { 288 viewer.setSelection(new StructuredSelection(delegate)); 289 viewer.setCheckedElements(new Object [] {delegate}); 290 } 291 else { 292 resetDelegate(); 293 getCheckBoxTableViewer().getTable().setEnabled(false); 294 } 295 } 296 catch (CoreException ce) {DebugUIPlugin.log(ce);} 297 } 298 299 302 protected String getViewerLabel() { 303 return null; 304 } 305 } 306 | Popular Tags |