001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.activities;
011:
012: import java.util.Collections;
013: import java.util.HashSet;
014: import java.util.Hashtable;
015: import java.util.Iterator;
016: import java.util.Properties;
017: import java.util.Set;
018:
019: import org.eclipse.core.runtime.IConfigurationElement;
020: import org.eclipse.core.runtime.IExecutableExtension;
021: import org.eclipse.jface.dialogs.Dialog;
022: import org.eclipse.jface.dialogs.IDialogConstants;
023: import org.eclipse.jface.dialogs.IDialogSettings;
024: import org.eclipse.jface.dialogs.TrayDialog;
025: import org.eclipse.jface.preference.PreferencePage;
026: import org.eclipse.jface.resource.DeviceResourceException;
027: import org.eclipse.jface.resource.ImageDescriptor;
028: import org.eclipse.jface.resource.JFaceResources;
029: import org.eclipse.jface.resource.LocalResourceManager;
030: import org.eclipse.jface.viewers.CheckboxTableViewer;
031: import org.eclipse.jface.viewers.ISelectionChangedListener;
032: import org.eclipse.jface.viewers.IStructuredContentProvider;
033: import org.eclipse.jface.viewers.IStructuredSelection;
034: import org.eclipse.jface.viewers.ITableLabelProvider;
035: import org.eclipse.jface.viewers.LabelProvider;
036: import org.eclipse.jface.viewers.LabelProviderChangedEvent;
037: import org.eclipse.jface.viewers.SelectionChangedEvent;
038: import org.eclipse.jface.viewers.TableViewer;
039: import org.eclipse.jface.viewers.Viewer;
040: import org.eclipse.jface.viewers.ViewerComparator;
041: import org.eclipse.jface.viewers.ViewerFilter;
042: import org.eclipse.osgi.util.NLS;
043: import org.eclipse.swt.SWT;
044: import org.eclipse.swt.events.SelectionAdapter;
045: import org.eclipse.swt.events.SelectionEvent;
046: import org.eclipse.swt.graphics.Image;
047: import org.eclipse.swt.graphics.ImageData;
048: import org.eclipse.swt.graphics.Point;
049: import org.eclipse.swt.layout.GridData;
050: import org.eclipse.swt.layout.GridLayout;
051: import org.eclipse.swt.widgets.Button;
052: import org.eclipse.swt.widgets.Composite;
053: import org.eclipse.swt.widgets.Control;
054: import org.eclipse.swt.widgets.Label;
055: import org.eclipse.swt.widgets.Shell;
056: import org.eclipse.swt.widgets.Table;
057: import org.eclipse.swt.widgets.TableItem;
058: import org.eclipse.swt.widgets.Text;
059: import org.eclipse.ui.IWorkbench;
060: import org.eclipse.ui.IWorkbenchPreferencePage;
061: import org.eclipse.ui.PlatformUI;
062: import org.eclipse.ui.internal.IPreferenceConstants;
063: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
064: import org.eclipse.ui.internal.OverlayIcon;
065: import org.eclipse.ui.internal.WorkbenchPlugin;
066: import org.eclipse.ui.internal.activities.ws.ActivityEnabler;
067: import org.eclipse.ui.internal.activities.ws.ActivityMessages;
068: import org.eclipse.ui.plugin.AbstractUIPlugin;
069:
070: /**
071: * Activities preference page that primarily shows categories and can optionally
072: * show an advanced dialog that allows fine-tune adjustmenet of activities. This
073: * page may be used by product developers to provide basic ability to tweak the
074: * enabled activity set. You may provide certain strings to this class via
075: * method #2 of {@link org.eclipse.core.runtime.IExecutableExtension}.
076: *
077: * @see #ACTIVITY_NAME
078: * @see #ALLOW_ADVANCED
079: * @see #CAPTION_MESSAGE
080: * @see #CATEGORY_NAME
081: * @see #ACTIVITY_PROMPT_BUTTON
082: * @see #ACTIVITY_PROMPT_BUTTON_TOOLTIP
083: *
084: * @since 3.1
085: */
086: public final class ActivityCategoryPreferencePage extends
087: PreferencePage implements IWorkbenchPreferencePage,
088: IExecutableExtension {
089:
090: /**
091: * The name to use for the activities. Ie: "Capabilities".
092: */
093: public static final String ACTIVITY_NAME = "activityName"; //$NON-NLS-1$
094:
095: /**
096: * The parameter to use if you want the page to show the allow button. Must
097: * be true or false.
098: */
099: public static final String 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 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 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 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 ACTIVITY_PROMPT_BUTTON_TOOLTIP = "activityPromptButtonTooltip"; //$NON-NLS-1$
120:
121: private class AdvancedDialog extends TrayDialog {
122:
123: private static final String DIALOG_SETTINGS_SECTION = "ActivityCategoryPreferencePageAdvancedDialogSettings"; //$NON-NLS-1$
124:
125: ActivityEnabler enabler;
126:
127: /**
128: * @param parentShell
129: */
130: protected AdvancedDialog(Shell parentShell) {
131: super (parentShell);
132: }
133:
134: /* (non-Javadoc)
135: * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
136: */
137: protected void configureShell(Shell newShell) {
138: super .configureShell(newShell);
139: String activityName = strings.getProperty(ACTIVITY_NAME,
140: ActivityMessages.ActivityEnabler_activities);
141: activityName = activityName.replaceAll("&", ""); //strips possible mnemonic //$NON-NLS-1$ //$NON-NLS-2$
142: newShell
143: .setText(NLS
144: .bind(
145: ActivityMessages.ActivitiesPreferencePage_advancedDialogTitle,
146: activityName));
147: }
148:
149: /* (non-Javadoc)
150: * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
151: */
152: protected Control createDialogArea(Composite parent) {
153: Composite composite = (Composite) super
154: .createDialogArea(parent);
155: enabler = new ActivityEnabler(workingCopy, strings);
156: Control enablerControl = enabler.createControl(composite);
157: enablerControl.setLayoutData(new GridData(
158: GridData.FILL_BOTH));
159: return composite;
160: }
161:
162: /* (non-Javadoc)
163: * @see org.eclipse.jface.dialogs.Dialog#okPressed()
164: */
165: protected void okPressed() {
166: enabler.updateActivityStates();
167: super .okPressed();
168: }
169:
170: /* (non-Javadoc)
171: * @see org.eclipse.jface.window.Dialog#getDialogBoundsSettings()
172: *
173: * @since 3.2
174: */
175: protected IDialogSettings getDialogBoundsSettings() {
176: IDialogSettings settings = WorkbenchPlugin.getDefault()
177: .getDialogSettings();
178: IDialogSettings section = settings
179: .getSection(DIALOG_SETTINGS_SECTION);
180: if (section == null) {
181: section = settings
182: .addNewSection(DIALOG_SETTINGS_SECTION);
183: }
184: return section;
185: }
186:
187: /*
188: * (non-Javadoc)
189: * @see org.eclipse.jface.dialogs.Dialog#isResizable()
190: */
191: protected boolean isResizable() {
192: return true;
193: }
194: }
195:
196: private class CategoryLabelProvider extends LabelProvider implements
197: ITableLabelProvider, IActivityManagerListener {
198:
199: private LocalResourceManager manager = new LocalResourceManager(
200: JFaceResources.getResources());
201:
202: private ImageDescriptor lockDescriptor;
203:
204: private boolean decorate;
205:
206: /**
207: * @param decorate
208: */
209: public CategoryLabelProvider(boolean decorate) {
210: this .decorate = decorate;
211: lockDescriptor = AbstractUIPlugin
212: .imageDescriptorFromPlugin(PlatformUI.PLUGIN_ID,
213: "icons/full/ovr16/lock_ovr.gif"); //$NON-NLS-1$
214: }
215:
216: /*
217: * (non-Javadoc)
218: *
219: * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object,
220: * int)
221: */
222: public Image getColumnImage(Object element, int columnIndex) {
223: ICategory category = (ICategory) element;
224: ImageDescriptor descriptor = PlatformUI.getWorkbench()
225: .getActivitySupport().getImageDescriptor(category);
226: if (descriptor != null) {
227: try {
228: if (decorate) {
229: if (isLocked(category)) {
230: ImageData originalImageData = descriptor
231: .getImageData();
232: OverlayIcon overlay = new OverlayIcon(
233: descriptor, lockDescriptor,
234: new Point(originalImageData.width,
235: originalImageData.height));
236: return manager.createImage(overlay);
237: }
238: }
239:
240: return manager.createImage(descriptor);
241: } catch (DeviceResourceException e) {
242: WorkbenchPlugin.log(e);
243: }
244: }
245: return null;
246: }
247:
248: /* (non-Javadoc)
249: * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
250: */
251: public String getText(Object element) {
252: String name = null;
253: ICategory category = (ICategory) element;
254: try {
255: name = category.getName();
256: } catch (NotDefinedException e) {
257: name = category.getId();
258: }
259: if (decorate && isLocked(category)) {
260: name = NLS
261: .bind(
262: ActivityMessages.ActivitiesPreferencePage_lockedMessage,
263: name);
264: }
265: return name;
266: }
267:
268: /* (non-Javadoc)
269: * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
270: */
271: public String getColumnText(Object element, int columnIndex) {
272: return getText(element);
273: }
274:
275: /*
276: * (non-Javadoc)
277: *
278: * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
279: */
280: public void dispose() {
281: super .dispose();
282: manager.dispose();
283: }
284:
285: /*
286: * (non-Javadoc)
287: *
288: * @see org.eclipse.ui.activities.IActivityManagerListener#activityManagerChanged(org.eclipse.ui.activities.ActivityManagerEvent)
289: */
290: public void activityManagerChanged(
291: ActivityManagerEvent activityManagerEvent) {
292: if (activityManagerEvent.haveEnabledActivityIdsChanged()) {
293: updateCategoryCheckState();
294: fireLabelProviderChanged(new LabelProviderChangedEvent(
295: this ));
296: }
297: }
298: }
299:
300: private class CategoryContentProvider implements
301: IStructuredContentProvider {
302:
303: /*
304: * (non-Javadoc)
305: *
306: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
307: */
308: public Object[] getElements(Object inputElement) {
309: // convert to category objects
310: return WorkbenchActivityHelper.resolveCategories(
311: workingCopy, (Set) inputElement);
312: }
313:
314: /*
315: * (non-Javadoc)
316: *
317: * @see org.eclipse.jface.viewers.IContentProvider#dispose()
318: */
319: public void dispose() {
320:
321: }
322:
323: /*
324: * (non-Javadoc)
325: *
326: * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
327: * java.lang.Object, java.lang.Object)
328: */
329: public void inputChanged(Viewer viewer, Object oldInput,
330: Object newInput) {
331:
332: }
333: }
334:
335: private class EmptyCategoryFilter extends ViewerFilter {
336:
337: /*
338: * (non-Javadoc)
339: *
340: * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer,
341: * java.lang.Object, java.lang.Object)
342: */
343: public boolean select(Viewer viewer, Object parentElement,
344: Object element) {
345: ICategory category = (ICategory) element;
346: if (WorkbenchActivityHelper.getActivityIdsForCategory(
347: category).isEmpty()) {
348: return false;
349: }
350: return true;
351: }
352: }
353:
354: protected IWorkbench workbench;
355:
356: private CheckboxTableViewer categoryViewer;
357:
358: private TableViewer dependantViewer;
359:
360: private Text descriptionText;
361:
362: private IMutableActivityManager workingCopy;
363:
364: private Button activityPromptButton;
365:
366: private boolean allowAdvanced = false;
367:
368: private Button advancedButton;
369:
370: private Properties strings = new Properties();
371:
372: /*
373: * (non-Javadoc)
374: *
375: * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
376: */
377: protected Control createContents(Composite parent) {
378: initializeDialogUnits(parent);
379:
380: Composite composite = new Composite(parent, SWT.NONE);
381: GridLayout layout = new GridLayout(2, false);
382: layout.marginHeight = layout.marginWidth = 0;
383: layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
384: layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
385: composite.setLayout(layout);
386: Label label = new Label(composite, SWT.WRAP);
387: label
388: .setText(strings
389: .getProperty(
390: CAPTION_MESSAGE,
391: ActivityMessages.ActivitiesPreferencePage_captionMessage));
392: GridData data = new GridData(GridData.FILL_HORIZONTAL);
393: data.widthHint = 400;
394: data.horizontalSpan = 2;
395: label.setLayoutData(data);
396: label = new Label(composite, SWT.NONE); //spacer
397: data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
398: data.horizontalSpan = 2;
399: label.setLayoutData(data);
400: createPromptButton(composite);
401: createCategoryArea(composite);
402: createDetailsArea(composite);
403: createButtons(composite);
404:
405: workbench.getHelpSystem().setHelp(parent,
406: IWorkbenchHelpContextIds.CAPABILITY_PREFERENCE_PAGE);
407:
408: Dialog.applyDialogFont(composite);
409:
410: return composite;
411: }
412:
413: /**
414: * @param composite
415: */
416: private void createPromptButton(Composite composite) {
417: activityPromptButton = new Button(composite, SWT.CHECK);
418: activityPromptButton.setText(strings.getProperty(
419: ACTIVITY_PROMPT_BUTTON,
420: ActivityMessages.activityPromptButton));
421: activityPromptButton.setToolTipText(strings.getProperty(
422: ACTIVITY_PROMPT_BUTTON_TOOLTIP,
423: ActivityMessages.activityPromptToolTip));
424: GridData data = new GridData();
425: data.horizontalSpan = 2;
426: activityPromptButton.setLayoutData(data);
427: activityPromptButton
428: .setSelection(getPreferenceStore()
429: .getBoolean(
430: IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
431: }
432:
433: private void createButtons(final Composite parent) {
434: Composite composite = new Composite(parent, SWT.NONE);
435: GridLayout layout = new GridLayout(4, false);
436: layout.marginHeight = layout.marginWidth = 0;
437: layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
438: layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
439: composite.setLayout(layout);
440: GridData data = new GridData(GridData.FILL_HORIZONTAL);
441: data.horizontalSpan = 2;
442: composite.setLayoutData(data);
443:
444: Button enableAll = new Button(composite, SWT.PUSH);
445: enableAll.addSelectionListener(new SelectionAdapter() {
446:
447: /*
448: * (non-Javadoc)
449: *
450: * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
451: */
452: public void widgetSelected(SelectionEvent e) {
453: workingCopy.setEnabledActivityIds(workingCopy
454: .getDefinedActivityIds());
455: }
456: });
457: enableAll.setText(ActivityMessages.ActivityEnabler_selectAll);
458: setButtonLayoutData(enableAll);
459:
460: Button disableAll = new Button(composite, SWT.PUSH);
461: disableAll.addSelectionListener(new SelectionAdapter() {
462: /*
463: * (non-Javadoc)
464: *
465: * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
466: */
467: public void widgetSelected(SelectionEvent e) {
468: workingCopy
469: .setEnabledActivityIds(Collections.EMPTY_SET);
470: }
471: });
472: disableAll
473: .setText(ActivityMessages.ActivityEnabler_deselectAll);
474: setButtonLayoutData(disableAll);
475:
476: if (allowAdvanced) {
477: Label spacer = new Label(composite, SWT.NONE);
478: data = new GridData(GridData.GRAB_HORIZONTAL);
479: spacer.setLayoutData(data);
480: advancedButton = new Button(composite, SWT.PUSH);
481: advancedButton.addSelectionListener(new SelectionAdapter() {
482:
483: /*
484: * (non-Javadoc)
485: *
486: * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
487: */
488: public void widgetSelected(SelectionEvent e) {
489: AdvancedDialog dialog = new AdvancedDialog(parent
490: .getShell());
491: dialog.open(); // logic for updating the working copy is in the dialog class.
492: }
493: });
494: advancedButton
495: .setText(ActivityMessages.ActivitiesPreferencePage_advancedButton);
496: setButtonLayoutData(advancedButton);
497: }
498: }
499:
500: /**
501: * @param parent
502: */
503: private void createDetailsArea(Composite parent) {
504: Composite composite = new Composite(parent, SWT.NONE);
505: GridLayout layout = new GridLayout();
506: layout.marginHeight = layout.marginWidth = 0;
507: layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
508: layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
509: composite.setLayout(layout);
510: composite.setLayoutData(new GridData(GridData.FILL_BOTH));
511:
512: new Label(composite, SWT.NONE)
513: .setText(ActivityMessages.ActivityEnabler_description);
514: descriptionText = new Text(composite, SWT.WRAP | SWT.READ_ONLY
515: | SWT.BORDER);
516: GridData data = new GridData(GridData.FILL_BOTH);
517: data.heightHint = 100;
518: data.widthHint = 200;
519: descriptionText.setLayoutData(data);
520:
521: new Label(composite, SWT.NONE)
522: .setText(ActivityMessages.ActivitiesPreferencePage_requirements);
523: dependantViewer = new TableViewer(composite, SWT.BORDER);
524: dependantViewer.getControl().setLayoutData(
525: new GridData(GridData.FILL_BOTH));
526: dependantViewer
527: .setContentProvider(new CategoryContentProvider());
528: dependantViewer.addFilter(new EmptyCategoryFilter());
529: dependantViewer.setLabelProvider(new CategoryLabelProvider(
530: false));
531: dependantViewer.setInput(Collections.EMPTY_SET);
532: }
533:
534: /**
535: * @param parent
536: */
537: private void createCategoryArea(Composite parent) {
538: Composite composite = new Composite(parent, SWT.NONE);
539: GridLayout layout = new GridLayout();
540: layout.marginHeight = layout.marginWidth = 0;
541: layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
542: layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
543: composite.setLayout(layout);
544: GridData data = new GridData(GridData.FILL_BOTH);
545: data.widthHint = 200;
546: composite.setLayoutData(data);
547: Label label = new Label(composite, SWT.NONE);
548: label.setText(strings.getProperty(CATEGORY_NAME,
549: ActivityMessages.ActivityEnabler_categories) + ':');
550: Table table = new Table(composite, SWT.CHECK | SWT.BORDER
551: | SWT.SINGLE);
552: table.addSelectionListener(new SelectionAdapter() {
553:
554: /*
555: * (non-Javadoc)
556: *
557: * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
558: */
559: public void widgetSelected(SelectionEvent e) {
560: if (e.detail == SWT.CHECK) {
561: TableItem tableItem = (TableItem) e.item;
562:
563: ICategory category = (ICategory) tableItem
564: .getData();
565: if (isLocked(category)) {
566: tableItem.setChecked(true);
567: e.doit = false; // veto the check
568: return;
569: }
570: Set activitySet = WorkbenchActivityHelper
571: .getActivityIdsForCategory(category);
572: if (tableItem.getChecked()) {
573: activitySet.addAll(workingCopy
574: .getEnabledActivityIds());
575: } else {
576: HashSet newSet = new HashSet(workingCopy
577: .getEnabledActivityIds());
578: newSet.removeAll(activitySet);
579: activitySet = newSet;
580: }
581:
582: workingCopy.setEnabledActivityIds(activitySet);
583: updateCategoryCheckState(); // even though we're reacting to
584: // a check change we may need to
585: // refresh a greying change.
586: // Just process the whole thing.
587: }
588: }
589: });
590: categoryViewer = new CheckboxTableViewer(table);
591: categoryViewer.getControl().setLayoutData(
592: new GridData(GridData.FILL_BOTH));
593: categoryViewer
594: .setContentProvider(new CategoryContentProvider());
595: CategoryLabelProvider categoryLabelProvider = new CategoryLabelProvider(
596: true);
597: workingCopy.addActivityManagerListener(categoryLabelProvider);
598: categoryViewer.setLabelProvider(categoryLabelProvider);
599: categoryViewer.setComparator(new ViewerComparator());
600: categoryViewer.addFilter(new EmptyCategoryFilter());
601:
602: categoryViewer
603: .addSelectionChangedListener(new ISelectionChangedListener() {
604:
605: /*
606: * (non-Javadoc)
607: *
608: * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
609: */
610: public void selectionChanged(
611: SelectionChangedEvent event) {
612: ICategory element = (ICategory) ((IStructuredSelection) event
613: .getSelection()).getFirstElement();
614: setDetails(element);
615: }
616: });
617: categoryViewer.setInput(workingCopy.getDefinedCategoryIds());
618:
619: updateCategoryCheckState();
620: }
621:
622: /**
623: * Updates the check and grey state of the categories in the category viewer.
624: *
625: * @since 3.2
626: */
627: private void updateCategoryCheckState() {
628: ICategory[] enabledCategories = getEnabledCategories();
629: ICategory[] partiallyEnabledCategories = getPartialCategories();
630: Object[] allChecked = new Object[enabledCategories.length
631: + partiallyEnabledCategories.length];
632: System.arraycopy(enabledCategories, 0, allChecked, 0,
633: enabledCategories.length);
634: System.arraycopy(partiallyEnabledCategories, 0, allChecked,
635: enabledCategories.length,
636: partiallyEnabledCategories.length);
637: categoryViewer.setCheckedElements(allChecked);
638: categoryViewer.setGrayedElements(partiallyEnabledCategories);
639: }
640:
641: private ICategory[] getPartialCategories() {
642: return WorkbenchActivityHelper.resolveCategories(workingCopy,
643: WorkbenchActivityHelper
644: .getPartiallyEnabledCategories(workingCopy));
645: }
646:
647: private ICategory[] getEnabledCategories() {
648: return WorkbenchActivityHelper.resolveCategories(workingCopy,
649: WorkbenchActivityHelper
650: .getEnabledCategories(workingCopy));
651: }
652:
653: protected void setDetails(ICategory category) {
654: if (category == null) {
655: clearDetails();
656: return;
657: }
658: Set categories = null;
659: if (WorkbenchActivityHelper.isEnabled(workingCopy, category
660: .getId())) {
661: categories = WorkbenchActivityHelper.getDisabledCategories(
662: workingCopy, category.getId());
663:
664: } else {
665: categories = WorkbenchActivityHelper.getEnabledCategories(
666: workingCopy, category.getId());
667: }
668:
669: categories = WorkbenchActivityHelper.getContainedCategories(
670: workingCopy, category.getId());
671: dependantViewer.setInput(categories);
672: try {
673: descriptionText.setText(category.getDescription());
674: } catch (NotDefinedException e) {
675: descriptionText.setText(""); //$NON-NLS-1$
676: }
677: }
678:
679: /**
680: * Clear the details area.
681: */
682: protected void clearDetails() {
683: dependantViewer.setInput(Collections.EMPTY_SET);
684: descriptionText.setText(""); //$NON-NLS-1$
685: }
686:
687: /*
688: * (non-Javadoc)
689: *
690: * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
691: */
692: public void init(IWorkbench workbench) {
693: this .workbench = workbench;
694: workingCopy = workbench.getActivitySupport()
695: .createWorkingCopy();
696: setPreferenceStore(WorkbenchPlugin.getDefault()
697: .getPreferenceStore());
698: }
699:
700: /**
701: * Return whether the category is locked.
702: *
703: * @param category
704: * the category to test
705: * @return whether the category is locked
706: */
707: protected boolean isLocked(ICategory category) {
708: return !WorkbenchActivityHelper.getDisabledCategories(
709: workingCopy, category.getId()).isEmpty();
710: }
711:
712: /*
713: * (non-Javadoc)
714: *
715: * @see org.eclipse.jface.preference.PreferencePage#performOk()
716: */
717: public boolean performOk() {
718: workbench.getActivitySupport().setEnabledActivityIds(
719: workingCopy.getEnabledActivityIds());
720: getPreferenceStore().setValue(
721: IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT,
722: activityPromptButton.getSelection());
723: return true;
724: }
725:
726: /* (non-Javadoc)
727: * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
728: */
729: protected void performDefaults() {
730: super .performDefaults();
731: activityPromptButton
732: .setSelection(getPreferenceStore()
733: .getDefaultBoolean(
734: IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
735:
736: Set defaultEnabled = new HashSet();
737: Set activityIds = workingCopy.getDefinedActivityIds();
738: for (Iterator i = activityIds.iterator(); i.hasNext();) {
739: String activityId = (String) i.next();
740: IActivity activity = workingCopy.getActivity(activityId);
741: try {
742: if (activity.isDefaultEnabled()) {
743: defaultEnabled.add(activityId);
744: }
745: } catch (NotDefinedException e) {
746: // this can't happen - we're iterating over defined activities.
747: }
748: }
749:
750: workingCopy.setEnabledActivityIds(defaultEnabled);
751: }
752:
753: /*
754: * (non-Javadoc)
755: *
756: * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
757: * java.lang.String, java.lang.Object)
758: */
759: public void setInitializationData(IConfigurationElement config,
760: String propertyName, Object data) {
761: if (data instanceof Hashtable) {
762: Hashtable table = (Hashtable) data;
763: allowAdvanced = Boolean.valueOf(
764: (String) table.remove(ALLOW_ADVANCED))
765: .booleanValue();
766: strings.putAll(table);
767: }
768: }
769: }
|