KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > preferences > LaunchConfigurationsPreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.preferences;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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 /**
65  * Provides the Launch Configuration preference page to the Run/Debug preferences
66  *
67  * This page allows users to set filtering options as well as perform migration tasks.
68  * This class is not intended to be sub-classed
69  * @since 3.2
70  */

71 public class LaunchConfigurationsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
72
73     /**
74      * @since 3.2
75      */

76     class LaunchConfigurationMigrationSelectionDialog extends ListSelectionDialog {
77         
78         private String JavaDoc SETTINGS_ID = IDebugUIConstants.PLUGIN_ID + ".MIGRATION_SELECTION_DIALOG"; //$NON-NLS-1$
79

80         public LaunchConfigurationMigrationSelectionDialog(Shell parentShell, Object JavaDoc input, IStructuredContentProvider contentProvider, ILabelProvider labelProvider, String JavaDoc 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     /**
96      * Content provider for the launch configuration type table
97      */

98     class TableContentProvider implements IStructuredContentProvider {
99
100         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
101             return getLaunchConfigurationTypes();
102         }
103
104         public void dispose() {}
105
106         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {}
107     }
108     
109     /**
110      * describes the debug launch group
111      */

112     private static final String JavaDoc DEBUG_LAUNCH_GROUP = "org.eclipse.debug.ui.launchGroup.debug"; //$NON-NLS-1$
113

114     /**
115      * describes the external tools launch group
116      */

117     private static final String JavaDoc EXT_BUILDER_GROUP = "org.eclipse.ui.externaltools.launchGroup"; //$NON-NLS-1$
118

119     /**
120      * to monitor the progress of the migration process
121      */

122     private ProgressMonitorPart fMonitor;
123     
124     /**
125      * the migrate now button
126      */

127     private Button fMigrateNow;
128     
129     /**
130      * a list of the field editors
131      */

132     private List JavaDoc fFieldEditors;
133     
134     /**
135      * Boolean editor for debug core plug-in preference
136      */

137     private Button fDeleteConfigs;
138     
139     /**
140      * The table for the launch configuration types
141      */

142     private Table fTable;
143     
144     /**
145      * Constructor
146      */

147     public LaunchConfigurationsPreferencePage() {
148         super();
149         setPreferenceStore(DebugUIPlugin.getDefault().getPreferenceStore());
150         setTitle(DebugPreferencesMessages.LaunchConfigurationsPreferencePage_1);
151     }
152     
153     /* (non-Javadoc)
154      * @see org.eclipse.jface.preference.PreferencePage#createControl(org.eclipse.swt.widgets.Composite)
155      */

156     public void createControl(Composite parent) {
157         super.createControl(parent);
158         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_PREFERENCE_PAGE);
159     }
160
161     /* (non-Javadoc)
162      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
163      */

164     protected Control createContents(Composite parent) {
165         fFieldEditors = new ArrayList JavaDoc();
166         Composite comp = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, GridData.FILL_HORIZONTAL);
167         //filtering options
168
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         //add table options
179
createTypeFiltering(group);
180         
181         //migration
182
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         //init field editors
201
initFieldEditors();
202         fTable.setEnabled(getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES));
203         return comp;
204     }
205     
206     /**
207      * @param parent the parent to add this composite to
208      * @return the new composite with the type selection table in it
209      */

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 JavaDoc) {
217                     newvalue = ((Boolean JavaDoc)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 JavaDoc list = new ArrayList JavaDoc();
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     /**
256      * returns the launch configuration types
257      * @return the launch configuration types
258      */

259     private ILaunchConfigurationType[] getLaunchConfigurationTypes() {
260         return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes();
261     }
262     
263     /**
264      * handles the Migrate button being clicked
265      *
266      * @since 3.2
267      */

268     private void handleMigrateNowSelected() {
269         try {
270             ILaunchManager lmanager = DebugPlugin.getDefault().getLaunchManager();
271             ILaunchConfiguration[] configurations = lmanager.getMigrationCandidates();
272             //separate the private from the public
273
List JavaDoc pub = new ArrayList JavaDoc();
274             for(int i = 0; i < configurations.length; i++) {
275                 if(DebugUITools.isPrivate(configurations[i])) {
276                     //auto-migrate private ones
277
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 JavaDoc[] 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     /* (non-Javadoc)
312      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
313      */

314     public void init(IWorkbench workbench) {}
315
316     /**
317      * Initializes the field editors to their values
318      * @since 3.2
319      */

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         //restore the tables' checked state
330
String JavaDoc[] types = getPreferenceStore().getString(IInternalDebugUIConstants.PREF_FILTER_TYPE_LIST).split("\\,"); //$NON-NLS-1$
331
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     /* (non-Javadoc)
344      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
345      */

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     /* (non-Javadoc)
359      * @see org.eclipse.jface.preference.PreferencePage#performOk()
360      */

361     public boolean performOk() {
362         //save field editors
363
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         //save table
369
String JavaDoc types = ""; //$NON-NLS-1$
370
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()+","; //$NON-NLS-1$
376
}
377         }
378         getPreferenceStore().setValue(IInternalDebugUIConstants.PREF_FILTER_TYPE_LIST, types);
379         return super.performOk();
380     }
381 }
382
Popular Tags