KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > ActivitiesPreferencePage


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

11 package org.eclipse.ui.internal.dialogs;
12
13 import org.eclipse.jface.preference.PreferencePage;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Button;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.IWorkbenchPreferencePage;
22 import org.eclipse.ui.internal.IPreferenceConstants;
23 import org.eclipse.ui.internal.WorkbenchPlugin;
24 import org.eclipse.ui.internal.activities.ws.ActivityEnabler;
25 import org.eclipse.ui.internal.activities.ws.ActivityMessages;
26
27
28 /**
29  * Preference page that allows configuration of the activity set.
30
31  * @since 3.0
32  */

33 public class ActivitiesPreferencePage
34     extends PreferencePage
35     implements IWorkbenchPreferencePage {
36
37
38     private Button activityPromptButton;
39     private IWorkbench workbench;
40     private ActivityEnabler enabler;
41     
42     /**
43      * Create the prompt for activity enablement.
44      *
45      * @param composite the parent
46      */

47     protected void createActivityPromptPref(Composite composite) {
48         activityPromptButton = new Button(composite, SWT.CHECK);
49         activityPromptButton.setText(ActivityMessages
50                 .getString("activityPromptButton")); //$NON-NLS-1$
51
activityPromptButton.setToolTipText(ActivityMessages
52                 .getString("activityPromptToolTip")); //$NON-NLS-1$
53

54         activityPromptButton.setFont(composite.getFont());
55         setActivityButtonState();
56     }
57
58     
59     /**
60      * Sets the state of the activity prompt button from preferences.
61      */

62     private void setActivityButtonState() {
63         activityPromptButton.setSelection(getPreferenceStore().getBoolean(
64                 IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
65     }
66
67
68     /* (non-Javadoc)
69      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
70      */

71     protected Control createContents(Composite parent) {
72         Composite composite = new Composite(parent, SWT.NONE);
73         GridLayout layout = new GridLayout();
74         layout.marginHeight = 0;
75         layout.marginWidth = 0;
76         composite.setLayout(layout);
77         composite.setFont(parent.getFont());
78         
79         createActivityPromptPref(composite);
80         GridData data = new GridData(GridData.FILL_HORIZONTAL);
81         activityPromptButton.setLayoutData(data);
82         
83         data = new GridData(GridData.FILL_BOTH);
84         enabler = new ActivityEnabler(workbench.getActivitySupport());
85         enabler.createControl(composite).setLayoutData(data);
86
87         return composite;
88     }
89
90     /* (non-Javadoc)
91      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
92      */

93     public void init(IWorkbench aWorkbench) {
94         this.workbench = aWorkbench;
95         setPreferenceStore(WorkbenchPlugin.getDefault().getPreferenceStore());
96     }
97     
98     /* (non-Javadoc)
99      * @see org.eclipse.jface.preference.IPreferencePage#performOk()
100      */

101     public boolean performOk() {
102         enabler.updateActivityStates();
103
104         getPreferenceStore().setValue(IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT, activityPromptButton
105                 .getSelection());
106         
107         return true;
108     }
109     /* (non-Javadoc)
110      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
111      */

112     protected void performDefaults() {
113         enabler.restoreDefaults();
114         activityPromptButton.setSelection(getPreferenceStore().getDefaultBoolean(IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
115         super.performDefaults();
116     }
117 }
118
Popular Tags