KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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.Hashtable JavaDoc;
14 import java.util.Properties JavaDoc;
15
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.core.runtime.IExecutableExtension;
18 import org.eclipse.jface.dialogs.Dialog;
19 import org.eclipse.jface.dialogs.IDialogConstants;
20 import org.eclipse.jface.preference.PreferencePage;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.ui.IWorkbench;
28 import org.eclipse.ui.IWorkbenchPreferencePage;
29 import org.eclipse.ui.internal.IPreferenceConstants;
30 import org.eclipse.ui.internal.WorkbenchPlugin;
31 import org.eclipse.ui.internal.activities.ws.ActivityEnabler;
32 import org.eclipse.ui.internal.activities.ws.ActivityMessages;
33
34 /**
35  * Preference page that allows configuration of the activity set. This page may
36  * be used by product developers to provide basic ability to tweak the enabled
37  * activity set. You may provide the certain strings to this class via method #2
38  * of {@link org.eclipse.core.runtime.IExecutableExtension}.
39  *
40  * @see #ACTIVITY_NAME
41  * @see #ACTIVITY_PROMPT_BUTTON
42  * @see #ACTIVITY_PROMPT_BUTTON_TOOLTIP
43  * @since 3.1
44  */

45 public final class ActivitiesPreferencePage extends PreferencePage implements
46         IWorkbenchPreferencePage, IExecutableExtension {
47
48     /**
49      * The name to use for the activities. Ie: "Capabilities".
50      */

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

53     /**
54      * The label to be used for the prompt button. Ie: "&Prompt when enabling capabilities".
55      */

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

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

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

63     private Button activityPromptButton;
64
65     private IWorkbench workbench;
66
67     private ActivityEnabler enabler;
68     
69     private Properties JavaDoc strings = new Properties JavaDoc();
70
71     private IMutableActivityManager workingCopy;
72     
73     /**
74      * Create the prompt for activity enablement.
75      *
76      * @param composite the parent
77      */

78     protected void createActivityPromptPref(Composite composite) {
79         activityPromptButton = new Button(composite, SWT.CHECK);
80         activityPromptButton.setText(strings.getProperty(ACTIVITY_PROMPT_BUTTON, ActivityMessages.activityPromptButton));
81         activityPromptButton.setToolTipText(strings.getProperty(ACTIVITY_PROMPT_BUTTON_TOOLTIP, ActivityMessages.activityPromptToolTip));
82
83         setActivityButtonState();
84     }
85
86     /**
87      * Sets the state of the activity prompt button from preferences.
88      */

89     private void setActivityButtonState() {
90         activityPromptButton.setSelection(getPreferenceStore().getBoolean(
91                 IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
92     }
93
94     /* (non-Javadoc)
95      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
96      */

97     protected Control createContents(Composite parent) {
98         initializeDialogUnits(parent);
99         
100         Composite composite = new Composite(parent, SWT.NONE);
101         GridLayout layout = new GridLayout();
102         layout.marginHeight = 0;
103         layout.marginWidth = 0;
104         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
105         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
106         composite.setLayout(layout);
107
108         createActivityPromptPref(composite);
109         GridData data = new GridData(GridData.FILL_HORIZONTAL);
110         activityPromptButton.setLayoutData(data);
111
112         data = new GridData(GridData.FILL_BOTH);
113         workingCopy = workbench.getActivitySupport().createWorkingCopy();
114         enabler = new ActivityEnabler(workingCopy, strings);
115         enabler.createControl(composite).setLayoutData(data);
116         
117         Dialog.applyDialogFont(composite);
118
119         return composite;
120     }
121
122     /* (non-Javadoc)
123      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
124      */

125     public void init(IWorkbench aWorkbench) {
126         this.workbench = aWorkbench;
127         setPreferenceStore(WorkbenchPlugin.getDefault().getPreferenceStore());
128     }
129
130     /* (non-Javadoc)
131      * @see org.eclipse.jface.preference.IPreferencePage#performOk()
132      */

133     public boolean performOk() {
134         enabler.updateActivityStates();
135         workbench.getActivitySupport().setEnabledActivityIds(workingCopy.getEnabledActivityIds());
136         
137         getPreferenceStore().setValue(
138                 IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT,
139                 activityPromptButton.getSelection());
140
141         return true;
142     }
143
144     /* (non-Javadoc)
145      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
146      */

147     protected void performDefaults() {
148         enabler.restoreDefaults();
149         activityPromptButton.setSelection(getPreferenceStore()
150                 .getDefaultBoolean(
151                         IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
152         super.performDefaults();
153     }
154
155     /* (non-Javadoc)
156      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
157      */

158     public void setInitializationData(IConfigurationElement config, String JavaDoc propertyName, Object JavaDoc data) {
159         if (data instanceof Hashtable JavaDoc) {
160             strings.putAll((Hashtable JavaDoc)data);
161         }
162     }
163 }
164
Popular Tags