001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 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.Hashtable;
013: import java.util.Properties;
014:
015: import org.eclipse.core.runtime.IConfigurationElement;
016: import org.eclipse.core.runtime.IExecutableExtension;
017: import org.eclipse.jface.dialogs.Dialog;
018: import org.eclipse.jface.dialogs.IDialogConstants;
019: import org.eclipse.jface.preference.PreferencePage;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.layout.GridData;
022: import org.eclipse.swt.layout.GridLayout;
023: import org.eclipse.swt.widgets.Button;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.swt.widgets.Control;
026: import org.eclipse.ui.IWorkbench;
027: import org.eclipse.ui.IWorkbenchPreferencePage;
028: import org.eclipse.ui.internal.IPreferenceConstants;
029: import org.eclipse.ui.internal.WorkbenchPlugin;
030: import org.eclipse.ui.internal.activities.ws.ActivityEnabler;
031: import org.eclipse.ui.internal.activities.ws.ActivityMessages;
032:
033: /**
034: * Preference page that allows configuration of the activity set. This page may
035: * be used by product developers to provide basic ability to tweak the enabled
036: * activity set. You may provide the certain strings to this class via method #2
037: * of {@link org.eclipse.core.runtime.IExecutableExtension}.
038: *
039: * @see #ACTIVITY_NAME
040: * @see #ACTIVITY_PROMPT_BUTTON
041: * @see #ACTIVITY_PROMPT_BUTTON_TOOLTIP
042: * @since 3.1
043: */
044: public final class ActivitiesPreferencePage extends PreferencePage
045: implements IWorkbenchPreferencePage, IExecutableExtension {
046:
047: /**
048: * The name to use for the activities. Ie: "Capabilities".
049: */
050: public static final String ACTIVITY_NAME = "activityName"; //$NON-NLS-1$
051:
052: /**
053: * The label to be used for the prompt button. Ie: "&Prompt when enabling capabilities".
054: */
055: public static final String ACTIVITY_PROMPT_BUTTON = "activityPromptButton"; //$NON-NLS-1$
056:
057: /**
058: * The tooltip to be used for the prompt button. Ie: "Prompt when a feature is first used that requires enablement of capabilities".
059: */
060: public static final String ACTIVITY_PROMPT_BUTTON_TOOLTIP = "activityPromptButtonTooltip"; //$NON-NLS-1$
061:
062: private Button activityPromptButton;
063:
064: private IWorkbench workbench;
065:
066: private ActivityEnabler enabler;
067:
068: private Properties strings = new Properties();
069:
070: private IMutableActivityManager workingCopy;
071:
072: /**
073: * Create the prompt for activity enablement.
074: *
075: * @param composite the parent
076: */
077: protected void createActivityPromptPref(Composite composite) {
078: activityPromptButton = new Button(composite, SWT.CHECK);
079: activityPromptButton.setText(strings.getProperty(
080: ACTIVITY_PROMPT_BUTTON,
081: ActivityMessages.activityPromptButton));
082: activityPromptButton.setToolTipText(strings.getProperty(
083: ACTIVITY_PROMPT_BUTTON_TOOLTIP,
084: ActivityMessages.activityPromptToolTip));
085:
086: setActivityButtonState();
087: }
088:
089: /**
090: * Sets the state of the activity prompt button from preferences.
091: */
092: private void setActivityButtonState() {
093: activityPromptButton
094: .setSelection(getPreferenceStore()
095: .getBoolean(
096: IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
097: }
098:
099: /* (non-Javadoc)
100: * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
101: */
102: protected Control createContents(Composite parent) {
103: initializeDialogUnits(parent);
104:
105: Composite composite = new Composite(parent, SWT.NONE);
106: GridLayout layout = new GridLayout();
107: layout.marginHeight = 0;
108: layout.marginWidth = 0;
109: layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
110: layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
111: composite.setLayout(layout);
112:
113: createActivityPromptPref(composite);
114: GridData data = new GridData(GridData.FILL_HORIZONTAL);
115: activityPromptButton.setLayoutData(data);
116:
117: data = new GridData(GridData.FILL_BOTH);
118: workingCopy = workbench.getActivitySupport()
119: .createWorkingCopy();
120: enabler = new ActivityEnabler(workingCopy, strings);
121: enabler.createControl(composite).setLayoutData(data);
122:
123: Dialog.applyDialogFont(composite);
124:
125: return composite;
126: }
127:
128: /* (non-Javadoc)
129: * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
130: */
131: public void init(IWorkbench aWorkbench) {
132: this .workbench = aWorkbench;
133: setPreferenceStore(WorkbenchPlugin.getDefault()
134: .getPreferenceStore());
135: }
136:
137: /* (non-Javadoc)
138: * @see org.eclipse.jface.preference.IPreferencePage#performOk()
139: */
140: public boolean performOk() {
141: enabler.updateActivityStates();
142: workbench.getActivitySupport().setEnabledActivityIds(
143: workingCopy.getEnabledActivityIds());
144:
145: getPreferenceStore().setValue(
146: IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT,
147: activityPromptButton.getSelection());
148:
149: return true;
150: }
151:
152: /* (non-Javadoc)
153: * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
154: */
155: protected void performDefaults() {
156: enabler.restoreDefaults();
157: activityPromptButton
158: .setSelection(getPreferenceStore()
159: .getDefaultBoolean(
160: IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
161: super .performDefaults();
162: }
163:
164: /* (non-Javadoc)
165: * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
166: */
167: public void setInitializationData(IConfigurationElement config,
168: String propertyName, Object data) {
169: if (data instanceof Hashtable) {
170: strings.putAll((Hashtable) data);
171: }
172: }
173: }
|