1 11 package org.eclipse.debug.internal.ui.preferences; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.DebugPlugin; 18 import org.eclipse.debug.core.ILaunchConfiguration; 19 import org.eclipse.debug.core.ILaunchConfigurationType; 20 import org.eclipse.debug.core.ILaunchManager; 21 import org.eclipse.debug.internal.core.LaunchManager; 22 import org.eclipse.debug.internal.ui.DebugUIPlugin; 23 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 24 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 25 import org.eclipse.debug.internal.ui.SWTFactory; 26 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; 27 import org.eclipse.debug.internal.ui.launchConfigurations.MultiLaunchGroupFilter; 28 import org.eclipse.debug.ui.DebugUITools; 29 import org.eclipse.debug.ui.IDebugUIConstants; 30 import org.eclipse.jface.dialogs.IDialogConstants; 31 import org.eclipse.jface.dialogs.IDialogSettings; 32 import org.eclipse.jface.dialogs.MessageDialog; 33 import org.eclipse.jface.preference.BooleanFieldEditor; 34 import org.eclipse.jface.preference.FieldEditor; 35 import org.eclipse.jface.preference.PreferencePage; 36 import org.eclipse.jface.util.IPropertyChangeListener; 37 import org.eclipse.jface.util.PropertyChangeEvent; 38 import org.eclipse.jface.viewers.CheckboxTableViewer; 39 import org.eclipse.jface.viewers.ILabelProvider; 40 import org.eclipse.jface.viewers.IStructuredContentProvider; 41 import org.eclipse.jface.viewers.Viewer; 42 import org.eclipse.jface.wizard.ProgressMonitorPart; 43 import org.eclipse.swt.SWT; 44 import org.eclipse.swt.events.SelectionEvent; 45 import org.eclipse.swt.events.SelectionListener; 46 import org.eclipse.swt.layout.GridData; 47 import org.eclipse.swt.layout.GridLayout; 48 import org.eclipse.swt.widgets.Button; 49 import org.eclipse.swt.widgets.Composite; 50 import org.eclipse.swt.widgets.Control; 51 import org.eclipse.swt.widgets.Group; 52 import org.eclipse.swt.widgets.Label; 53 import org.eclipse.swt.widgets.Shell; 54 import org.eclipse.swt.widgets.Table; 55 import org.eclipse.swt.widgets.TableItem; 56 import org.eclipse.ui.IWorkbench; 57 import org.eclipse.ui.IWorkbenchPreferencePage; 58 import org.eclipse.ui.PlatformUI; 59 import org.eclipse.ui.dialogs.ListSelectionDialog; 60 import org.eclipse.ui.model.AdaptableList; 61 import org.eclipse.ui.model.WorkbenchContentProvider; 62 import org.eclipse.ui.model.WorkbenchViewerComparator; 63 64 71 public class LaunchConfigurationsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 72 73 76 class LaunchConfigurationMigrationSelectionDialog extends ListSelectionDialog { 77 78 private String SETTINGS_ID = IDebugUIConstants.PLUGIN_ID + ".MIGRATION_SELECTION_DIALOG"; 80 public LaunchConfigurationMigrationSelectionDialog(Shell parentShell, Object input, IStructuredContentProvider contentProvider, ILabelProvider labelProvider, String message) { 81 super(parentShell, input, contentProvider, labelProvider, message); 82 setShellStyle(getShellStyle() | SWT.RESIZE); 83 } 84 85 protected IDialogSettings getDialogBoundsSettings() { 86 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 87 IDialogSettings section = settings.getSection(SETTINGS_ID); 88 if (section == null) { 89 section = settings.addNewSection(SETTINGS_ID); 90 } 91 return section; 92 } 93 } 94 95 98 class TableContentProvider implements IStructuredContentProvider { 99 100 public Object [] getElements(Object inputElement) { 101 return getLaunchConfigurationTypes(); 102 } 103 104 public void dispose() {} 105 106 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} 107 } 108 109 112 private static final String DEBUG_LAUNCH_GROUP = "org.eclipse.debug.ui.launchGroup.debug"; 114 117 private static final String EXT_BUILDER_GROUP = "org.eclipse.ui.externaltools.launchGroup"; 119 122 private ProgressMonitorPart fMonitor; 123 124 127 private Button fMigrateNow; 128 129 132 private List fFieldEditors; 133 134 137 private Button fDeleteConfigs; 138 139 142 private Table fTable; 143 144 147 public LaunchConfigurationsPreferencePage() { 148 super(); 149 setPreferenceStore(DebugUIPlugin.getDefault().getPreferenceStore()); 150 setTitle(DebugPreferencesMessages.LaunchConfigurationsPreferencePage_1); 151 } 152 153 156 public void createControl(Composite parent) { 157 super.createControl(parent); 158 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_PREFERENCE_PAGE); 159 } 160 161 164 protected Control createContents(Composite parent) { 165 fFieldEditors = new ArrayList (); 166 Composite comp = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, GridData.FILL_HORIZONTAL); 167 Group group = SWTFactory.createGroup(comp, DebugPreferencesMessages.LaunchingPreferencePage_32, 1, 1, GridData.FILL_HORIZONTAL); 169 Composite spacer = SWTFactory.createComposite(group, group.getFont(), 1, 1, GridData.FILL_HORIZONTAL); 170 FieldEditor edit = new BooleanFieldEditor(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_CLOSED, DebugPreferencesMessages.LaunchingPreferencePage_33, SWT.NONE, spacer); 171 fFieldEditors.add(edit); 172 edit = new BooleanFieldEditor(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED, DebugPreferencesMessages.LaunchingPreferencePage_34, SWT.NONE, spacer); 173 fFieldEditors.add(edit); 174 edit = new BooleanFieldEditor(IInternalDebugUIConstants.PREF_FILTER_WORKING_SETS, DebugPreferencesMessages.LaunchConfigurationsPreferencePage_3, SWT.NONE, spacer); 175 fFieldEditors.add(edit); 176 fDeleteConfigs = SWTFactory.createCheckButton(comp, DebugPreferencesMessages.LaunchConfigurationsPreferencePage_2, null, false, 3); 177 178 createTypeFiltering(group); 180 181 group = SWTFactory.createGroup(comp, DebugPreferencesMessages.LaunchingPreferencePage_35, 1, 1, GridData.FILL_HORIZONTAL); 183 Label label = new Label(group, SWT.LEFT | SWT.WRAP); 184 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 185 gd.widthHint = 350; 186 label.setLayoutData(gd); 187 label.setText(DebugPreferencesMessages.LaunchingPreferencePage_26); 188 label.setFont(parent.getFont()); 189 fMigrateNow = SWTFactory.createPushButton(group, DebugPreferencesMessages.LaunchingPreferencePage_27, null); 190 gd = new GridData(SWT.BEGINNING); 191 192 fMigrateNow.setLayoutData(gd); 193 fMigrateNow.addSelectionListener(new SelectionListener() { 194 public void widgetDefaultSelected(SelectionEvent e) {} 195 public void widgetSelected(SelectionEvent e) { 196 handleMigrateNowSelected(); 197 } 198 }); 199 200 initFieldEditors(); 202 fTable.setEnabled(getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES)); 203 return comp; 204 } 205 206 210 private Composite createTypeFiltering(Composite parent) { 211 Composite comp = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, GridData.FILL_HORIZONTAL); 212 BooleanFieldEditor2 editor = new BooleanFieldEditor2(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES, DebugPreferencesMessages.LaunchConfigurationsPreferencePage_0, SWT.NONE, comp); 213 editor.setPropertyChangeListener(new IPropertyChangeListener() { 214 public void propertyChange(PropertyChangeEvent event) { 215 boolean newvalue = false; 216 if(event.getNewValue() instanceof Boolean ) { 217 newvalue = ((Boolean )event.getNewValue()).booleanValue(); 218 } 219 else { 220 newvalue = Boolean.valueOf(event.getNewValue().toString()).booleanValue(); 221 } 222 if(newvalue) { 223 fTable.setEnabled(true); 224 } 225 else { 226 fTable.setEnabled(false); 227 } 228 } 229 }); 230 fFieldEditors.add(editor); 231 fTable = new Table(comp, SWT.CHECK | SWT.BORDER); 232 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 233 gd.heightHint = 155; 234 fTable.setLayoutData(gd); 235 CheckboxTableViewer tviewer = new CheckboxTableViewer(fTable); 236 tviewer.setLabelProvider(DebugUITools.newDebugModelPresentation()); 237 tviewer.setContentProvider(new TableContentProvider()); 238 tviewer.setComparator(new WorkbenchViewerComparator()); 239 ArrayList list = new ArrayList (); 240 LaunchGroupExtension ext = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(DEBUG_LAUNCH_GROUP); 241 if(ext != null) { 242 list.add(ext); 243 } 244 ext = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(EXT_BUILDER_GROUP); 245 if(ext != null) { 246 list.add(ext); 247 } 248 tviewer.addFilter(new MultiLaunchGroupFilter((LaunchGroupExtension[]) list.toArray(new LaunchGroupExtension[list.size()]))); 249 list.clear(); 250 tviewer.setInput(getLaunchConfigurationTypes()); 251 fTable.setFont(parent.getFont()); 252 return comp; 253 } 254 255 259 private ILaunchConfigurationType[] getLaunchConfigurationTypes() { 260 return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes(); 261 } 262 263 268 private void handleMigrateNowSelected() { 269 try { 270 ILaunchManager lmanager = DebugPlugin.getDefault().getLaunchManager(); 271 ILaunchConfiguration[] configurations = lmanager.getMigrationCandidates(); 272 List pub = new ArrayList (); 274 for(int i = 0; i < configurations.length; i++) { 275 if(DebugUITools.isPrivate(configurations[i])) { 276 configurations[i].migrate(); 278 } 279 else { 280 pub.add(configurations[i]); 281 } 282 } 283 if(pub.size() == 0) { 284 MessageDialog.openInformation(getShell(), DebugPreferencesMessages.LaunchingPreferencePage_29, DebugPreferencesMessages.LaunchingPreferencePage_30); 285 return; 286 } 287 LaunchConfigurationMigrationSelectionDialog listd = new LaunchConfigurationMigrationSelectionDialog(getShell(), 288 new AdaptableList(pub), 289 new WorkbenchContentProvider(), 290 DebugUITools.newDebugModelPresentation(), 291 DebugPreferencesMessages.LaunchingPreferencePage_0); 292 listd.setTitle(DebugPreferencesMessages.LaunchingPreferencePage_28); 293 listd.setInitialSelections(configurations); 294 if(listd.open() == IDialogConstants.OK_ID) { 295 fMonitor = new ProgressMonitorPart(fMigrateNow.getParent(), new GridLayout()); 296 Object [] objs = listd.getResult(); 297 fMonitor.beginTask(DebugPreferencesMessages.LaunchingPreferencePage_31, objs.length); 298 for(int i = 0; i < objs.length; i++) { 299 if(objs[i] instanceof ILaunchConfiguration) { 300 ((ILaunchConfiguration)objs[i]).migrate(); 301 } 302 fMonitor.worked(1); 303 } 304 fMonitor.done(); 305 fMonitor.dispose(); 306 } 307 } 308 catch (CoreException e) {DebugUIPlugin.log(e);} 309 } 310 311 314 public void init(IWorkbench workbench) {} 315 316 320 private void initFieldEditors() { 321 FieldEditor editor; 322 for(int i = 0; i < fFieldEditors.size(); i++) { 323 editor = (FieldEditor)fFieldEditors.get(i); 324 editor.setPreferenceStore(getPreferenceStore()); 325 editor.load(); 326 } 327 fDeleteConfigs.setSelection(DebugPlugin.getDefault().getPluginPreferences().getBoolean( 328 LaunchManager.PREF_DELETE_CONFIGS_ON_PROJECT_DELETE)); 329 String [] types = getPreferenceStore().getString(IInternalDebugUIConstants.PREF_FILTER_TYPE_LIST).split("\\,"); TableItem[] items = fTable.getItems(); 332 ILaunchConfigurationType type; 333 for(int i = 0; i < types.length; i++) { 334 for(int j = 0; j < items.length; j++) { 335 type = (ILaunchConfigurationType)items[j].getData(); 336 if(type.getIdentifier().equals(types[i])) { 337 items[j].setChecked(true); 338 } 339 } 340 } 341 } 342 343 346 protected void performDefaults() { 347 FieldEditor editor = null; 348 for(int i = 0; i < fFieldEditors.size(); i++) { 349 editor = (FieldEditor)fFieldEditors.get(i); 350 editor.loadDefault(); 351 if(editor instanceof BooleanFieldEditor2) { 352 fTable.setEnabled(((BooleanFieldEditor2)editor).getBooleanValue()); 353 } 354 } 355 356 } 357 358 361 public boolean performOk() { 362 for(int i = 0; i < fFieldEditors.size(); i++) { 364 ((FieldEditor)fFieldEditors.get(i)).store(); 365 } 366 DebugPlugin.getDefault().getPluginPreferences().setValue( 367 LaunchManager.PREF_DELETE_CONFIGS_ON_PROJECT_DELETE, fDeleteConfigs.getSelection()); 368 String types = ""; TableItem[] items = fTable.getItems(); 371 ILaunchConfigurationType type; 372 for(int i = 0; i < items.length; i++) { 373 if(items[i].getChecked()) { 374 type = (ILaunchConfigurationType)items[i].getData(); 375 types += type.getIdentifier()+","; } 377 } 378 getPreferenceStore().setValue(IInternalDebugUIConstants.PREF_FILTER_TYPE_LIST, types); 379 return super.performOk(); 380 } 381 } 382 | Popular Tags |