KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.internal.dialogs;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.HashSet JavaDoc;
15
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.jface.preference.PreferencePage;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Table;
26 import org.eclipse.swt.widgets.TableItem;
27 import org.eclipse.ui.IWorkbench;
28 import org.eclipse.ui.IWorkbenchPreferencePage;
29 import org.eclipse.ui.PlatformUI;
30 import org.eclipse.ui.internal.IPreferenceConstants;
31 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
32 import org.eclipse.ui.internal.Workbench;
33 import org.eclipse.ui.internal.WorkbenchMessages;
34 import org.eclipse.ui.internal.util.PrefUtil;
35 import org.osgi.framework.Constants;
36
37 /**
38  * The Startup preference page.
39  */

40 public class StartupPreferencePage extends PreferencePage implements
41         IWorkbenchPreferencePage {
42     private Table pluginsList;
43
44     private Workbench workbench;
45
46     /**
47      * @see PreferencePage#createContents(Composite)
48      */

49     protected Control createContents(Composite parent) {
50         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
51                 IWorkbenchHelpContextIds.STARTUP_PREFERENCE_PAGE);
52
53         Composite composite = createComposite(parent);
54
55         createEarlyStartupSelection(composite);
56
57         return composite;
58     }
59
60     protected Composite createComposite(Composite parent) {
61         Composite composite = new Composite(parent, SWT.NULL);
62         GridLayout layout = new GridLayout();
63         layout.marginWidth = 0;
64         layout.marginHeight = 0;
65         composite.setLayout(layout);
66         GridData data = new GridData(GridData.FILL_BOTH
67                 | GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
68         composite.setLayoutData(data);
69         composite.setFont(parent.getFont());
70
71         return composite;
72     }
73
74     protected void createEarlyStartupSelection(Composite parent) {
75         Label label = new Label(parent, SWT.NONE);
76         label.setText(WorkbenchMessages.StartupPreferencePage_label);
77         label.setFont(parent.getFont());
78         GridData data = new GridData(GridData.FILL_HORIZONTAL);
79         label.setLayoutData(data);
80         pluginsList = new Table(parent, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL
81                 | SWT.V_SCROLL);
82         data = new GridData(GridData.FILL_BOTH);
83         pluginsList.setFont(parent.getFont());
84         pluginsList.setLayoutData(data);
85         populatePluginsList();
86     }
87
88     private void populatePluginsList() {
89         String JavaDoc pluginIds[] = workbench.getEarlyActivatedPlugins();
90         HashSet JavaDoc disabledPlugins = new HashSet JavaDoc(Arrays.asList(workbench.getDisabledEarlyActivatedPlugins()));
91         for (int i = 0; i < pluginIds.length; i++) {
92             String JavaDoc pluginId = pluginIds[i];
93             TableItem item = new TableItem(pluginsList, SWT.NONE);
94             item.setText((String JavaDoc) Platform.getBundle(pluginId).getHeaders().get(
95                     Constants.BUNDLE_NAME));
96             item.setData(pluginId);
97             item.setChecked(!disabledPlugins.contains(pluginId));
98         }
99     }
100
101     /**
102      * @see IWorkbenchPreferencePage
103      */

104     public void init(IWorkbench workbench) {
105         this.workbench = (Workbench) workbench;
106     }
107
108     /**
109      * @see PreferencePage
110      */

111     protected void performDefaults() {
112         TableItem items[] = pluginsList.getItems();
113         for (int i = 0; i < items.length; i++) {
114             items[i].setChecked(true);
115         }
116     }
117
118     /**
119      * @see PreferencePage
120      */

121     public boolean performOk() {
122         StringBuffer JavaDoc preference = new StringBuffer JavaDoc();
123         TableItem items[] = pluginsList.getItems();
124         for (int i = 0; i < items.length; i++) {
125             if (!items[i].getChecked()) {
126                 preference.append((String JavaDoc) items[i].getData());
127                 preference.append(IPreferenceConstants.SEPARATOR);
128             }
129         }
130         String JavaDoc pref = preference.toString();
131         IPreferenceStore store = PrefUtil.getInternalPreferenceStore();
132         store.putValue(IPreferenceConstants.PLUGINS_NOT_ACTIVATED_ON_STARTUP,
133                 pref);
134         PrefUtil.savePrefs();
135         return true;
136     }
137 }
138
Popular Tags