KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > activities > ActivityCategoryPreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ui.activities;
12
13 import java.util.Collections JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.Hashtable JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Properties JavaDoc;
18 import java.util.Set JavaDoc;
19
20 import org.eclipse.core.runtime.IConfigurationElement;
21 import org.eclipse.core.runtime.IExecutableExtension;
22 import org.eclipse.jface.dialogs.Dialog;
23 import org.eclipse.jface.dialogs.IDialogConstants;
24 import org.eclipse.jface.dialogs.IDialogSettings;
25 import org.eclipse.jface.dialogs.TrayDialog;
26 import org.eclipse.jface.preference.PreferencePage;
27 import org.eclipse.jface.resource.DeviceResourceException;
28 import org.eclipse.jface.resource.ImageDescriptor;
29 import org.eclipse.jface.resource.JFaceResources;
30 import org.eclipse.jface.resource.LocalResourceManager;
31 import org.eclipse.jface.viewers.CheckboxTableViewer;
32 import org.eclipse.jface.viewers.ISelectionChangedListener;
33 import org.eclipse.jface.viewers.IStructuredContentProvider;
34 import org.eclipse.jface.viewers.IStructuredSelection;
35 import org.eclipse.jface.viewers.ITableLabelProvider;
36 import org.eclipse.jface.viewers.LabelProvider;
37 import org.eclipse.jface.viewers.LabelProviderChangedEvent;
38 import org.eclipse.jface.viewers.SelectionChangedEvent;
39 import org.eclipse.jface.viewers.TableViewer;
40 import org.eclipse.jface.viewers.Viewer;
41 import org.eclipse.jface.viewers.ViewerComparator;
42 import org.eclipse.jface.viewers.ViewerFilter;
43 import org.eclipse.osgi.util.NLS;
44 import org.eclipse.swt.SWT;
45 import org.eclipse.swt.events.SelectionAdapter;
46 import org.eclipse.swt.events.SelectionEvent;
47 import org.eclipse.swt.graphics.Image;
48 import org.eclipse.swt.graphics.ImageData;
49 import org.eclipse.swt.graphics.Point;
50 import org.eclipse.swt.layout.GridData;
51 import org.eclipse.swt.layout.GridLayout;
52 import org.eclipse.swt.widgets.Button;
53 import org.eclipse.swt.widgets.Composite;
54 import org.eclipse.swt.widgets.Control;
55 import org.eclipse.swt.widgets.Label;
56 import org.eclipse.swt.widgets.Shell;
57 import org.eclipse.swt.widgets.Table;
58 import org.eclipse.swt.widgets.TableItem;
59 import org.eclipse.swt.widgets.Text;
60 import org.eclipse.ui.IWorkbench;
61 import org.eclipse.ui.IWorkbenchPreferencePage;
62 import org.eclipse.ui.PlatformUI;
63 import org.eclipse.ui.internal.IPreferenceConstants;
64 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
65 import org.eclipse.ui.internal.OverlayIcon;
66 import org.eclipse.ui.internal.WorkbenchPlugin;
67 import org.eclipse.ui.internal.activities.ws.ActivityEnabler;
68 import org.eclipse.ui.internal.activities.ws.ActivityMessages;
69 import org.eclipse.ui.plugin.AbstractUIPlugin;
70
71 /**
72  * Activities preference page that primarily shows categories and can optionally
73  * show an advanced dialog that allows fine-tune adjustmenet of activities. This
74  * page may be used by product developers to provide basic ability to tweak the
75  * enabled activity set. You may provide certain strings to this class via
76  * method #2 of {@link org.eclipse.core.runtime.IExecutableExtension}.
77  *
78  * @see #ACTIVITY_NAME
79  * @see #ALLOW_ADVANCED
80  * @see #CAPTION_MESSAGE
81  * @see #CATEGORY_NAME
82  * @see #ACTIVITY_PROMPT_BUTTON
83  * @see #ACTIVITY_PROMPT_BUTTON_TOOLTIP
84  *
85  * @since 3.1
86  */

87 public final class ActivityCategoryPreferencePage extends PreferencePage implements
88         IWorkbenchPreferencePage, IExecutableExtension {
89
90     /**
91      * The name to use for the activities. Ie: "Capabilities".
92      */

93     public static final String JavaDoc ACTIVITY_NAME = "activityName"; //$NON-NLS-1$
94

95     /**
96      * The parameter to use if you want the page to show the allow button. Must
97      * be true or false.
98      */

99     public static final String JavaDoc ALLOW_ADVANCED = "allowAdvanced"; //$NON-NLS-1$
100

101     /**
102      * The string to use for the message at the top of the preference page.
103      */

104     public static final String JavaDoc CAPTION_MESSAGE = "captionMessage"; //$NON-NLS-1$
105

106     /**
107      * The name to use for the activity categories. Ie: "Roles".
108      */

109     public static final String JavaDoc CATEGORY_NAME = "categoryName"; //$NON-NLS-1$
110

111     /**
112      * The label to be used for the prompt button. Ie: "&Prompt when enabling capabilities".
113      */

114     public static final String JavaDoc ACTIVITY_PROMPT_BUTTON = "activityPromptButton"; //$NON-NLS-1$
115

116     /**
117      * The tooltip to be used for the prompt button. Ie: "Prompt when a feature is first used that requires enablement of capabilities".
118      */

119     public static final String JavaDoc ACTIVITY_PROMPT_BUTTON_TOOLTIP = "activityPromptButtonTooltip"; //$NON-NLS-1$
120

121     private class AdvancedDialog extends TrayDialog {
122
123         private static final String JavaDoc DIALOG_SETTINGS_SECTION = "ActivityCategoryPreferencePageAdvancedDialogSettings"; //$NON-NLS-1$
124

125         
126         ActivityEnabler enabler;
127         /**
128          * @param parentShell
129          */

130         protected AdvancedDialog(Shell parentShell) {
131             super(parentShell);
132             setShellStyle(getShellStyle() | SWT.RESIZE);
133         }
134         
135         /* (non-Javadoc)
136          * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
137          */

138         protected void configureShell(Shell newShell) {
139             super.configureShell(newShell);
140             String JavaDoc activityName = strings.getProperty(ACTIVITY_NAME, ActivityMessages.ActivityEnabler_activities);
141             activityName = activityName.replaceAll("&", ""); //strips possible mnemonic //$NON-NLS-1$ //$NON-NLS-2$
142
newShell.setText(NLS.bind(
143                     ActivityMessages.ActivitiesPreferencePage_advancedDialogTitle,
144                     activityName
145             ));
146         }
147         
148         /* (non-Javadoc)
149          * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
150          */

151         protected Control createDialogArea(Composite parent) {
152             Composite composite = (Composite) super.createDialogArea(parent);
153             enabler = new ActivityEnabler(workingCopy, strings);
154             Control enablerControl = enabler.createControl(composite);
155             enablerControl.setLayoutData(new GridData(GridData.FILL_BOTH));
156             return composite;
157         }
158
159         /* (non-Javadoc)
160          * @see org.eclipse.jface.dialogs.Dialog#okPressed()
161          */

162         protected void okPressed() {
163             enabler.updateActivityStates();
164             super.okPressed();
165         }
166         
167         /* (non-Javadoc)
168          * @see org.eclipse.jface.window.Dialog#getDialogBoundsSettings()
169          *
170          * @since 3.2
171          */

172         protected IDialogSettings getDialogBoundsSettings() {
173             IDialogSettings settings = WorkbenchPlugin.getDefault().getDialogSettings();
174             IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION);
175             if (section == null) {
176                 section = settings.addNewSection(DIALOG_SETTINGS_SECTION);
177             }
178             return section;
179         }
180     }
181     private class CategoryLabelProvider extends LabelProvider implements
182             ITableLabelProvider, IActivityManagerListener {
183
184         private LocalResourceManager manager = new LocalResourceManager(
185                 JFaceResources.getResources());
186
187         private ImageDescriptor lockDescriptor;
188
189         private boolean decorate;
190
191         /**
192          * @param decorate
193          */

194         public CategoryLabelProvider(boolean decorate) {
195             this.decorate = decorate;
196             lockDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
197                     PlatformUI.PLUGIN_ID, "icons/full/ovr16/lock_ovr.gif"); //$NON-NLS-1$
198
}
199
200         /*
201          * (non-Javadoc)
202          *
203          * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object,
204          * int)
205          */

206         public Image getColumnImage(Object JavaDoc element, int columnIndex) {
207             ICategory category = (ICategory) element;
208             ImageDescriptor descriptor = PlatformUI.getWorkbench()
209                     .getActivitySupport().getImageDescriptor(category);
210             if (descriptor != null) {
211                 try {
212                     if (decorate) {
213                         if (isLocked(category)) {
214                             ImageData originalImageData = descriptor
215                                     .getImageData();
216                             OverlayIcon overlay = new OverlayIcon(
217                                     descriptor, lockDescriptor, new Point(
218                                             originalImageData.width,
219                                             originalImageData.height));
220                             return manager.createImage(overlay);
221                         }
222                     }
223
224                     return manager.createImage(descriptor);
225                 } catch (DeviceResourceException e) {
226                     WorkbenchPlugin.log(e);
227                 }
228             }
229             return null;
230         }
231       
232         /* (non-Javadoc)
233          * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
234          */

235         public String JavaDoc getText(Object JavaDoc element) {
236             String JavaDoc name = null;
237             ICategory category = (ICategory) element;
238             try {
239                 name = category.getName();
240             } catch (NotDefinedException e) {
241                 name = category.getId();
242             }
243             if (decorate && isLocked(category)) {
244                 name = NLS.bind(ActivityMessages.ActivitiesPreferencePage_lockedMessage, name);
245             }
246             return name;
247         }
248        
249         /* (non-Javadoc)
250          * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
251          */

252         public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
253             return getText(element);
254         }
255
256         /*
257          * (non-Javadoc)
258          *
259          * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
260          */

261         public void dispose() {
262             super.dispose();
263             manager.dispose();
264         }
265
266         /*
267          * (non-Javadoc)
268          *
269          * @see org.eclipse.ui.activities.IActivityManagerListener#activityManagerChanged(org.eclipse.ui.activities.ActivityManagerEvent)
270          */

271         public void activityManagerChanged(
272                 ActivityManagerEvent activityManagerEvent) {
273             if (activityManagerEvent.haveEnabledActivityIdsChanged()) {
274                 updateCategoryCheckState();
275                 fireLabelProviderChanged(new LabelProviderChangedEvent(this));
276             }
277         }
278     }
279
280     private class CategoryContentProvider implements IStructuredContentProvider {
281
282         /*
283          * (non-Javadoc)
284          *
285          * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
286          */

287         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
288             // convert to category objects
289
return WorkbenchActivityHelper.resolveCategories(workingCopy,
290                     (Set JavaDoc) inputElement);
291         }
292
293         /*
294          * (non-Javadoc)
295          *
296          * @see org.eclipse.jface.viewers.IContentProvider#dispose()
297          */

298         public void dispose() {
299
300         }
301
302         /*
303          * (non-Javadoc)
304          *
305          * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
306          * java.lang.Object, java.lang.Object)
307          */

308         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
309
310         }
311     }
312
313     private class EmptyCategoryFilter extends ViewerFilter {
314
315         /*
316          * (non-Javadoc)
317          *
318          * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer,
319          * java.lang.Object, java.lang.Object)
320          */

321         public boolean select(Viewer viewer, Object JavaDoc parentElement,
322                 Object JavaDoc element) {
323             ICategory category = (ICategory) element;
324             if (WorkbenchActivityHelper.getActivityIdsForCategory(category)
325                     .isEmpty()) {
326                 return false;
327             }
328             return true;
329         }
330     }
331
332     protected IWorkbench workbench;
333
334     private CheckboxTableViewer categoryViewer;
335
336     private TableViewer dependantViewer;
337
338     private Text descriptionText;
339
340     private IMutableActivityManager workingCopy;
341
342     private Button activityPromptButton;
343
344     private boolean allowAdvanced = false;
345
346     private Button advancedButton;
347     
348     private Properties JavaDoc strings = new Properties JavaDoc();
349
350     /*
351      * (non-Javadoc)
352      *
353      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
354      */

355     protected Control createContents(Composite parent) {
356         initializeDialogUnits(parent);
357         
358         Composite composite = new Composite(parent, SWT.NONE);
359         GridLayout layout = new GridLayout(2, false);
360         layout.marginHeight = layout.marginWidth = 0;
361         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
362         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
363         composite.setLayout(layout);
364         Label label = new Label(composite, SWT.WRAP);
365         label
366                 .setText(strings.getProperty(CAPTION_MESSAGE, ActivityMessages.ActivitiesPreferencePage_captionMessage));
367         GridData data = new GridData(GridData.FILL_HORIZONTAL);
368         data.widthHint = 400;
369         data.horizontalSpan = 2;
370         label.setLayoutData(data);
371         label = new Label(composite, SWT.NONE); //spacer
372
data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
373         data.horizontalSpan = 2;
374         label.setLayoutData(data);
375         createPromptButton(composite);
376         createCategoryArea(composite);
377         createDetailsArea(composite);
378         createButtons(composite);
379         
380         workbench.getHelpSystem().setHelp(parent,
381                 IWorkbenchHelpContextIds.CAPABILITY_PREFERENCE_PAGE);
382         
383         Dialog.applyDialogFont(composite);
384         
385         return composite;
386     }
387
388     /**
389      * @param composite
390      */

391     private void createPromptButton(Composite composite) {
392         activityPromptButton = new Button(composite, SWT.CHECK);
393         activityPromptButton.setText(strings.getProperty(ACTIVITY_PROMPT_BUTTON, ActivityMessages.activityPromptButton));
394         activityPromptButton.setToolTipText(strings.getProperty(ACTIVITY_PROMPT_BUTTON_TOOLTIP, ActivityMessages.activityPromptToolTip));
395         GridData data = new GridData();
396         data.horizontalSpan = 2;
397         activityPromptButton.setLayoutData(data);
398         activityPromptButton.setSelection(getPreferenceStore()
399                 .getBoolean(
400                         IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
401     }
402
403     private void createButtons(final Composite parent) {
404         Composite composite = new Composite(parent, SWT.NONE);
405         GridLayout layout = new GridLayout(4, false);
406         layout.marginHeight = layout.marginWidth = 0;
407         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
408         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
409         composite.setLayout(layout);
410         GridData data = new GridData(GridData.FILL_HORIZONTAL);
411         data.horizontalSpan = 2;
412         composite.setLayoutData(data);
413
414         Button enableAll = new Button(composite, SWT.PUSH);
415         enableAll.addSelectionListener(new SelectionAdapter() {
416
417             /*
418              * (non-Javadoc)
419              *
420              * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
421              */

422             public void widgetSelected(SelectionEvent e) {
423                 workingCopy.setEnabledActivityIds(workingCopy
424                         .getDefinedActivityIds());
425             }
426         });
427         enableAll.setText(ActivityMessages.ActivityEnabler_selectAll);
428         setButtonLayoutData(enableAll);
429
430         Button disableAll = new Button(composite, SWT.PUSH);
431         disableAll.addSelectionListener(new SelectionAdapter() {
432             /*
433              * (non-Javadoc)
434              *
435              * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
436              */

437             public void widgetSelected(SelectionEvent e) {
438                 workingCopy.setEnabledActivityIds(Collections.EMPTY_SET);
439             }
440         });
441         disableAll.setText(ActivityMessages.ActivityEnabler_deselectAll);
442         setButtonLayoutData(disableAll);
443         
444         if (allowAdvanced) {
445                 Label spacer = new Label(composite, SWT.NONE);
446                 data = new GridData(GridData.GRAB_HORIZONTAL);
447                 spacer.setLayoutData(data);
448             advancedButton = new Button(composite, SWT.PUSH);
449             advancedButton.addSelectionListener(new SelectionAdapter() {
450
451                 /*
452                  * (non-Javadoc)
453                  *
454                  * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
455                  */

456                 public void widgetSelected(SelectionEvent e) {
457                     AdvancedDialog dialog = new AdvancedDialog(parent.getShell());
458                     dialog.open(); // logic for updating the working copy is in the dialog class.
459
}
460             });
461             advancedButton.setText(ActivityMessages.ActivitiesPreferencePage_advancedButton);
462             setButtonLayoutData(advancedButton);
463         }
464     }
465
466     /**
467      * @param parent
468      */

469     private void createDetailsArea(Composite parent) {
470         Composite composite = new Composite(parent, SWT.NONE);
471         GridLayout layout = new GridLayout();
472         layout.marginHeight = layout.marginWidth = 0;
473         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
474         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
475         composite.setLayout(layout);
476         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
477
478         new Label(composite, SWT.NONE).setText(ActivityMessages.ActivityEnabler_description);
479         descriptionText = new Text(composite, SWT.WRAP | SWT.READ_ONLY | SWT.BORDER);
480         GridData data = new GridData(GridData.FILL_BOTH);
481         data.heightHint = 100;
482         data.widthHint = 200;
483         descriptionText.setLayoutData(data);
484
485         new Label(composite, SWT.NONE).setText(ActivityMessages.ActivitiesPreferencePage_requirements);
486         dependantViewer = new TableViewer(composite, SWT.BORDER);
487         dependantViewer.getControl().setLayoutData(
488                 new GridData(GridData.FILL_BOTH));
489         dependantViewer.setContentProvider(new CategoryContentProvider());
490         dependantViewer.addFilter(new EmptyCategoryFilter());
491         dependantViewer.setLabelProvider(new CategoryLabelProvider(false));
492         dependantViewer.setInput(Collections.EMPTY_SET);
493     }
494
495     /**
496      * @param parent
497      */

498     private void createCategoryArea(Composite parent) {
499         Composite composite = new Composite(parent, SWT.NONE);
500         GridLayout layout = new GridLayout();
501         layout.marginHeight = layout.marginWidth = 0;
502         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
503         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
504         composite.setLayout(layout);
505         GridData data = new GridData(GridData.FILL_BOTH);
506         data.widthHint = 200;
507         composite.setLayoutData(data);
508         Label label = new Label(composite, SWT.NONE);
509         label.setText(strings.getProperty(CATEGORY_NAME, ActivityMessages.ActivityEnabler_categories) + ':');
510         Table table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.SINGLE);
511         table.addSelectionListener(new SelectionAdapter() {
512
513             /*
514              * (non-Javadoc)
515              *
516              * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
517              */

518             public void widgetSelected(SelectionEvent e) {
519                 if (e.detail == SWT.CHECK) {
520                     TableItem tableItem = (TableItem) e.item;
521
522                     ICategory category = (ICategory) tableItem.getData();
523                     if (isLocked(category)) {
524                         tableItem.setChecked(true);
525                         e.doit = false; // veto the check
526
return;
527                     }
528                     Set JavaDoc activitySet = WorkbenchActivityHelper
529                             .getActivityIdsForCategory(category);
530                     if (tableItem.getChecked()) {
531                         activitySet.addAll(workingCopy.getEnabledActivityIds());
532                     } else {
533                         HashSet JavaDoc newSet = new HashSet JavaDoc(workingCopy
534                                 .getEnabledActivityIds());
535                         newSet.removeAll(activitySet);
536                         activitySet = newSet;
537                     }
538
539                     workingCopy.setEnabledActivityIds(activitySet);
540                     updateCategoryCheckState(); // even though we're reacting to
541
// a check change we may need to
542
// refresh a greying change.
543
// Just process the whole thing.
544
}
545             }
546         });
547         categoryViewer = new CheckboxTableViewer(table);
548         categoryViewer.getControl().setLayoutData(
549                 new GridData(GridData.FILL_BOTH));
550         categoryViewer.setContentProvider(new CategoryContentProvider());
551         CategoryLabelProvider categoryLabelProvider = new CategoryLabelProvider(
552                 true);
553         workingCopy.addActivityManagerListener(categoryLabelProvider);
554         categoryViewer.setLabelProvider(categoryLabelProvider);
555         categoryViewer.setComparator(new ViewerComparator());
556         categoryViewer.addFilter(new EmptyCategoryFilter());
557
558         categoryViewer
559                 .addSelectionChangedListener(new ISelectionChangedListener() {
560
561                     /*
562                      * (non-Javadoc)
563                      *
564                      * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
565                      */

566                     public void selectionChanged(SelectionChangedEvent event) {
567                         ICategory element = (ICategory) ((IStructuredSelection) event
568                                 .getSelection()).getFirstElement();
569                         setDetails(element);
570                     }
571                 });
572         categoryViewer.setInput(workingCopy.getDefinedCategoryIds());
573
574         updateCategoryCheckState();
575     }
576
577     /**
578      * Updates the check and grey state of the categories in the category viewer.
579      *
580      * @since 3.2
581      */

582     private void updateCategoryCheckState() {
583         ICategory[] enabledCategories = getEnabledCategories();
584         ICategory[] partiallyEnabledCategories = getPartialCategories();
585         Object JavaDoc[] allChecked = new Object JavaDoc[enabledCategories.length
586                 + partiallyEnabledCategories.length];
587         System.arraycopy(enabledCategories, 0, allChecked, 0, enabledCategories.length);
588         System.arraycopy(partiallyEnabledCategories, 0, allChecked, enabledCategories.length, partiallyEnabledCategories.length);
589         categoryViewer.setCheckedElements(allChecked);
590         categoryViewer.setGrayedElements(partiallyEnabledCategories);
591     }
592
593     private ICategory[] getPartialCategories() {
594         return WorkbenchActivityHelper.resolveCategories(workingCopy,
595                 WorkbenchActivityHelper
596                         .getPartiallyEnabledCategories(workingCopy));
597     }
598
599     private ICategory[] getEnabledCategories() {
600         return WorkbenchActivityHelper.resolveCategories(workingCopy,
601                 WorkbenchActivityHelper.getEnabledCategories(workingCopy));
602     }
603
604     protected void setDetails(ICategory category) {
605         if (category == null) {
606             clearDetails();
607             return;
608         }
609         Set JavaDoc categories = null;
610         if (WorkbenchActivityHelper.isEnabled(workingCopy, category.getId())) {
611             categories = WorkbenchActivityHelper.getDisabledCategories(
612                     workingCopy, category.getId());
613
614         } else {
615             categories = WorkbenchActivityHelper.getEnabledCategories(
616                     workingCopy, category.getId());
617         }
618
619         categories = WorkbenchActivityHelper.getContainedCategories(
620                 workingCopy, category.getId());
621         dependantViewer.setInput(categories);
622         try {
623             descriptionText.setText(category.getDescription());
624         } catch (NotDefinedException e) {
625             descriptionText.setText(""); //$NON-NLS-1$
626
}
627     }
628
629     /**
630      * Clear the details area.
631      */

632     protected void clearDetails() {
633         dependantViewer.setInput(Collections.EMPTY_SET);
634         descriptionText.setText(""); //$NON-NLS-1$
635
}
636
637     /*
638      * (non-Javadoc)
639      *
640      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
641      */

642     public void init(IWorkbench workbench) {
643         this.workbench = workbench;
644         workingCopy = workbench.getActivitySupport().createWorkingCopy();
645         setPreferenceStore(WorkbenchPlugin.getDefault().getPreferenceStore());
646     }
647
648     /**
649      * Return whether the category is locked.
650      *
651      * @param category
652      * the category to test
653      * @return whether the category is locked
654      */

655     protected boolean isLocked(ICategory category) {
656         return !WorkbenchActivityHelper.getDisabledCategories(workingCopy,
657                 category.getId()).isEmpty();
658     }
659
660     /*
661      * (non-Javadoc)
662      *
663      * @see org.eclipse.jface.preference.PreferencePage#performOk()
664      */

665     public boolean performOk() {
666         workbench.getActivitySupport().setEnabledActivityIds(
667                 workingCopy.getEnabledActivityIds());
668         getPreferenceStore().setValue(
669                 IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT,
670                 activityPromptButton.getSelection());
671         return true;
672     }
673
674     /* (non-Javadoc)
675      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
676      */

677     protected void performDefaults() {
678         super.performDefaults();
679         activityPromptButton.setSelection(getPreferenceStore()
680                 .getDefaultBoolean(
681                         IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
682         
683         Set JavaDoc defaultEnabled = new HashSet JavaDoc();
684         Set JavaDoc activityIds = workingCopy.getDefinedActivityIds();
685         for (Iterator JavaDoc i = activityIds.iterator(); i.hasNext();) {
686             String JavaDoc activityId = (String JavaDoc) i.next();
687             IActivity activity = workingCopy.getActivity(activityId);
688             try {
689                 if (activity.isDefaultEnabled()) {
690                     defaultEnabled.add(activityId);
691                 }
692             } catch (NotDefinedException e) {
693                 // this can't happen - we're iterating over defined activities.
694
}
695         }
696         
697         workingCopy.setEnabledActivityIds(defaultEnabled);
698     }
699     
700     /*
701      * (non-Javadoc)
702      *
703      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
704      * java.lang.String, java.lang.Object)
705      */

706     public void setInitializationData(IConfigurationElement config,
707             String JavaDoc propertyName, Object JavaDoc data) {
708         if (data instanceof Hashtable JavaDoc) {
709             Hashtable JavaDoc table = (Hashtable JavaDoc)data;
710             allowAdvanced = Boolean.valueOf((String JavaDoc) table.remove(ALLOW_ADVANCED)).booleanValue();
711             strings.putAll(table);
712         }
713     }
714 }
715
Popular Tags