1 11 package org.eclipse.debug.internal.ui.preferences; 12 13 import java.util.HashMap ; 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 import java.util.Set ; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.debug.core.DebugPlugin; 21 import org.eclipse.debug.core.ILaunchConfigurationType; 22 import org.eclipse.debug.core.ILaunchDelegate; 23 import org.eclipse.debug.internal.core.LaunchManager; 24 import org.eclipse.debug.internal.ui.DebugUIPlugin; 25 import org.eclipse.debug.internal.ui.DefaultLabelProvider; 26 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 27 import org.eclipse.debug.internal.ui.SWTFactory; 28 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPresentationManager; 29 import org.eclipse.jface.preference.PreferencePage; 30 import org.eclipse.jface.viewers.ArrayContentProvider; 31 import org.eclipse.jface.viewers.CheckStateChangedEvent; 32 import org.eclipse.jface.viewers.CheckboxTableViewer; 33 import org.eclipse.jface.viewers.ICheckStateListener; 34 import org.eclipse.jface.viewers.ISelectionChangedListener; 35 import org.eclipse.jface.viewers.IStructuredSelection; 36 import org.eclipse.jface.viewers.ITreeContentProvider; 37 import org.eclipse.jface.viewers.SelectionChangedEvent; 38 import org.eclipse.jface.viewers.TreeViewer; 39 import org.eclipse.jface.viewers.Viewer; 40 import org.eclipse.swt.SWT; 41 import org.eclipse.swt.layout.GridData; 42 import org.eclipse.swt.widgets.Composite; 43 import org.eclipse.swt.widgets.Control; 44 import org.eclipse.swt.widgets.Group; 45 import org.eclipse.swt.widgets.Table; 46 import org.eclipse.swt.widgets.Text; 47 import org.eclipse.swt.widgets.Tree; 48 import org.eclipse.ui.IWorkbench; 49 import org.eclipse.ui.IWorkbenchPreferencePage; 50 import org.eclipse.ui.PlatformUI; 51 import org.eclipse.ui.model.WorkbenchViewerComparator; 52 53 65 public class LaunchersPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 66 67 70 class DuplicateDelegate { 71 private ILaunchConfigurationType fType = null; 72 private ILaunchDelegate[] fDelegates = null; 73 private Set fModes = null; 74 75 public DuplicateDelegate(ILaunchConfigurationType type, ILaunchDelegate[] delegates, Set modes) { 76 fModes = modes; 77 fType = type; 78 fDelegates = delegates; 79 } 80 81 public ILaunchConfigurationType getType() { 82 return fType; 83 } 84 public ILaunchDelegate[] getDelegates() { 85 return fDelegates; 86 } 87 public Set getModeSet() { 88 return fModes; 89 } 90 } 91 92 95 class LabelProvider extends DefaultLabelProvider { 96 public String getText(Object element) { 97 if(element instanceof ILaunchConfigurationType) { 98 return super.getText(element); 99 } 100 else if(element instanceof DuplicateDelegate) { 101 DuplicateDelegate dd = (DuplicateDelegate) element; 102 return LaunchConfigurationPresentationManager.getDefault().getLaunchModeNames(dd.getModeSet()).toString(); 103 } 104 else if(element instanceof ILaunchDelegate){ 105 return ((ILaunchDelegate) element).getName(); 106 } 107 return element.toString(); 108 } 109 } 110 111 114 class TreeProvider implements ITreeContentProvider { 115 public Object [] getChildren(Object parentElement) { 116 if(parentElement instanceof ILaunchConfigurationType) { 117 ILaunchConfigurationType type = (ILaunchConfigurationType) parentElement; 118 Set dupes = (Set ) fDuplicates.get(type); 119 if(dupes != null) { 120 return dupes.toArray(); 121 } 122 return null; 123 } 124 return null; 125 } 126 public boolean hasChildren(Object element) { 127 return element instanceof ILaunchConfigurationType; 128 } 129 public Object [] getElements(Object inputElement) { 130 if(inputElement instanceof Map ) { 131 return ((Map )inputElement).keySet().toArray(); 132 } 133 return null; 134 } 135 public Object getParent(Object element) {return null;} 136 public void dispose() {} 137 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} 138 } 139 140 private TreeViewer fTreeViewer = null; 141 private CheckboxTableViewer fTableViewer = null; 142 private Map fDuplicates = null; 143 private Map fDupeSelections = null; 144 private boolean fDirty = false; 145 private Text fDescription = null; 146 147 150 public LaunchersPreferencePage() { 151 setTitle(DebugPreferencesMessages.LaunchDelegatesPreferencePage_0); 152 } 153 154 157 public void createControl(Composite parent) { 158 super.createControl(parent); 159 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_DELEGATES_PREFERENCE_PAGE); 160 } 161 162 165 protected Control createContents(Composite parent) { 166 Composite comp = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_BOTH); 167 SWTFactory.createWrapLabel(comp, DebugPreferencesMessages.LaunchDelegatesPreferencePage_1, 2, 300); 168 169 boolean enabled = fDuplicates.size() > 0; 170 if(!enabled) { 171 SWTFactory.createVerticalSpacer(comp, 1); 172 SWTFactory.createWrapLabel(comp, DebugPreferencesMessages.LaunchersPreferencePage_0, 2, 300); 173 } 174 175 SWTFactory.createVerticalSpacer(comp, 1); 176 Composite comp1 = SWTFactory.createComposite(comp, 1, 1, GridData.FILL_VERTICAL); 178 SWTFactory.createLabel(comp1, DebugPreferencesMessages.LaunchDelegatesPreferencePage_2, 1); 179 Tree tree = new Tree(comp1, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE); 180 tree.setEnabled(enabled); 181 GridData gd = new GridData(GridData.FILL_BOTH); 182 gd.grabExcessHorizontalSpace = false; 183 tree.setLayoutData(gd); 184 fTreeViewer = new TreeViewer(tree); 185 fTreeViewer.setComparator(new WorkbenchViewerComparator()); 186 fTreeViewer.setContentProvider(new TreeProvider()); 187 fTreeViewer.setLabelProvider(new LabelProvider()); 188 fTreeViewer.setInput(fDuplicates); 189 fTreeViewer.expandToLevel(2); 190 fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { 191 public void selectionChanged(SelectionChangedEvent event) { 192 Object obj = ((IStructuredSelection) event.getSelection()).getFirstElement(); 193 if(obj instanceof DuplicateDelegate) { 194 fTableViewer.setAllChecked(false); 195 DuplicateDelegate dd = (DuplicateDelegate) obj; 196 fTableViewer.setInput(dd.getDelegates()); 197 obj = fDupeSelections.get(dd); 198 if(obj != null) { 199 fTableViewer.setChecked(obj, true); 200 } 201 } 202 else { 203 fTableViewer.setInput(null); 204 } 205 } 206 }); 207 208 Composite comp2 = SWTFactory.createComposite(comp, comp.getFont(), 1, 1, GridData.FILL_BOTH); 210 SWTFactory.createLabel(comp2, DebugPreferencesMessages.LaunchDelegatesPreferencePage_3, 1); 211 Table table = new Table(comp2, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK | SWT.SINGLE); 212 table.setEnabled(enabled); 213 table.setLayoutData(new GridData(GridData.FILL_BOTH)); 214 fTableViewer = new CheckboxTableViewer(table); 215 fTableViewer.setComparator(new WorkbenchViewerComparator()); 216 fTableViewer.setLabelProvider(new LabelProvider()); 217 fTableViewer.setContentProvider(new ArrayContentProvider()); 218 fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { 219 public void selectionChanged(SelectionChangedEvent event) { 220 IStructuredSelection ss = (IStructuredSelection) event.getSelection(); 221 if(ss != null && !ss.isEmpty()) { 222 fDescription.setText(((ILaunchDelegate)ss.getFirstElement()).getDescription()); 223 } 224 else { 225 fDescription.setText(""); } 227 } 228 }); 229 fTableViewer.addCheckStateListener(new ICheckStateListener() { 230 public void checkStateChanged(CheckStateChangedEvent event) { 231 fDirty = true; 232 Object element = event.getElement(); 233 boolean checked = event.getChecked(); 234 fTableViewer.setAllChecked(false); 235 fTableViewer.setChecked(element, true); 239 Object obj = ((IStructuredSelection) fTreeViewer.getSelection()).getFirstElement(); 241 if(obj instanceof DuplicateDelegate) { 242 fDupeSelections.remove(obj); 243 if(checked) { 244 fDupeSelections.put(obj, element); 245 } 246 } 247 } 248 }); 249 Group group = SWTFactory.createGroup(comp, DebugPreferencesMessages.LaunchDelegatesPreferencePage_4, 1, 2, GridData.FILL_BOTH); 250 fDescription = SWTFactory.createText(group, SWT.WRAP | SWT.READ_ONLY, 1, GridData.FILL_BOTH); 251 fDescription.setEnabled(enabled); 252 fDescription.setBackground(group.getBackground()); 253 return comp; 254 } 255 256 259 public boolean performOk() { 260 if(fDirty && fDupeSelections != null && fDupeSelections.size() > 0) { 261 fDirty = false; 262 DuplicateDelegate dd = null; 263 ILaunchDelegate delegate = null; 264 for(Iterator iter = fDupeSelections.keySet().iterator(); iter.hasNext();) { 265 dd = (DuplicateDelegate) iter.next(); 266 delegate = (ILaunchDelegate) fDupeSelections.get(dd); 267 try { 268 dd.getType().setPreferredDelegate(dd.getModeSet(), delegate); 269 } 270 catch (CoreException e) {DebugUIPlugin.log(e);} 271 } 272 } 273 return super.performOk(); 274 } 275 276 279 public void init(IWorkbench workbench) { 280 try { 282 setPreferenceStore(DebugUIPlugin.getDefault().getPreferenceStore()); 283 LaunchManager lm = (LaunchManager) DebugPlugin.getDefault().getLaunchManager(); 284 ILaunchConfigurationType[] types = lm.getLaunchConfigurationTypes(); 285 fDuplicates = new HashMap (); 286 fDupeSelections = new HashMap (); 287 Set modes = null; 288 ILaunchDelegate[] delegates = null; 289 Set modeset = null; 290 Set tmp = null; 291 ILaunchDelegate prefdelegate = null; 292 DuplicateDelegate dd = null; 293 for(int i = 0; i < types.length; i++) { 294 modes = types[i].getSupportedModeCombinations(); 295 for(Iterator iter = modes.iterator(); iter.hasNext();) { 296 modeset = (Set ) iter.next(); 297 delegates = types[i].getDelegates(modeset); 298 if(delegates.length > 1) { 299 tmp = (Set ) fDuplicates.get(types[i]); 300 if(tmp == null) { 301 tmp = new HashSet (); 302 } 303 dd = new DuplicateDelegate(types[i], delegates, modeset); 304 tmp.add(dd); 305 fDuplicates.put(types[i], tmp); 306 prefdelegate = types[i].getPreferredDelegate(modeset); 307 if(prefdelegate != null) { 308 fDupeSelections.put(dd, prefdelegate); 309 } 310 } 311 } 312 } 313 } 314 catch(CoreException e) {DebugUIPlugin.log(e);} 315 } 316 317 } 318 | Popular Tags |