001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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.internal.dialogs;
011:
012: import java.util.Arrays;
013: import java.util.HashSet;
014:
015: import org.eclipse.core.runtime.Platform;
016: import org.eclipse.jface.preference.IPreferenceStore;
017: import org.eclipse.jface.preference.PreferencePage;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.layout.GridData;
020: import org.eclipse.swt.layout.GridLayout;
021: import org.eclipse.swt.widgets.Composite;
022: import org.eclipse.swt.widgets.Control;
023: import org.eclipse.swt.widgets.Label;
024: import org.eclipse.swt.widgets.Table;
025: import org.eclipse.swt.widgets.TableItem;
026: import org.eclipse.ui.IWorkbench;
027: import org.eclipse.ui.IWorkbenchPreferencePage;
028: import org.eclipse.ui.PlatformUI;
029: import org.eclipse.ui.internal.IPreferenceConstants;
030: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
031: import org.eclipse.ui.internal.Workbench;
032: import org.eclipse.ui.internal.WorkbenchMessages;
033: import org.eclipse.ui.internal.util.PrefUtil;
034: import org.osgi.framework.Constants;
035:
036: /**
037: * The Startup preference page.
038: */
039: public class StartupPreferencePage extends PreferencePage implements
040: IWorkbenchPreferencePage {
041: private Table pluginsList;
042:
043: private Workbench workbench;
044:
045: /**
046: * @see PreferencePage#createContents(Composite)
047: */
048: protected Control createContents(Composite parent) {
049: PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
050: IWorkbenchHelpContextIds.STARTUP_PREFERENCE_PAGE);
051:
052: Composite composite = createComposite(parent);
053:
054: createEarlyStartupSelection(composite);
055:
056: return composite;
057: }
058:
059: protected Composite createComposite(Composite parent) {
060: Composite composite = new Composite(parent, SWT.NULL);
061: GridLayout layout = new GridLayout();
062: layout.marginWidth = 0;
063: layout.marginHeight = 0;
064: composite.setLayout(layout);
065: GridData data = new GridData(GridData.FILL_BOTH
066: | GridData.VERTICAL_ALIGN_FILL
067: | GridData.HORIZONTAL_ALIGN_FILL);
068: composite.setLayoutData(data);
069: composite.setFont(parent.getFont());
070:
071: return composite;
072: }
073:
074: protected void createEarlyStartupSelection(Composite parent) {
075: Label label = new Label(parent, SWT.NONE);
076: label.setText(WorkbenchMessages.StartupPreferencePage_label);
077: label.setFont(parent.getFont());
078: GridData data = new GridData(GridData.FILL_HORIZONTAL);
079: label.setLayoutData(data);
080: pluginsList = new Table(parent, SWT.BORDER | SWT.CHECK
081: | SWT.H_SCROLL | SWT.V_SCROLL);
082: data = new GridData(GridData.FILL_BOTH);
083: pluginsList.setFont(parent.getFont());
084: pluginsList.setLayoutData(data);
085: populatePluginsList();
086: }
087:
088: private void populatePluginsList() {
089: String pluginIds[] = workbench.getEarlyActivatedPlugins();
090: HashSet disabledPlugins = new HashSet(Arrays.asList(workbench
091: .getDisabledEarlyActivatedPlugins()));
092: for (int i = 0; i < pluginIds.length; i++) {
093: String pluginId = pluginIds[i];
094: TableItem item = new TableItem(pluginsList, SWT.NONE);
095: item.setText((String) Platform.getBundle(pluginId)
096: .getHeaders().get(Constants.BUNDLE_NAME));
097: item.setData(pluginId);
098: item.setChecked(!disabledPlugins.contains(pluginId));
099: }
100: }
101:
102: /**
103: * @see IWorkbenchPreferencePage
104: */
105: public void init(IWorkbench workbench) {
106: this .workbench = (Workbench) workbench;
107: }
108:
109: /**
110: * @see PreferencePage
111: */
112: protected void performDefaults() {
113: TableItem items[] = pluginsList.getItems();
114: for (int i = 0; i < items.length; i++) {
115: items[i].setChecked(true);
116: }
117: }
118:
119: /**
120: * @see PreferencePage
121: */
122: public boolean performOk() {
123: StringBuffer preference = new StringBuffer();
124: TableItem items[] = pluginsList.getItems();
125: for (int i = 0; i < items.length; i++) {
126: if (!items[i].getChecked()) {
127: preference.append((String) items[i].getData());
128: preference.append(IPreferenceConstants.SEPARATOR);
129: }
130: }
131: String pref = preference.toString();
132: IPreferenceStore store = PrefUtil.getInternalPreferenceStore();
133: store.putValue(
134: IPreferenceConstants.PLUGINS_NOT_ACTIVATED_ON_STARTUP,
135: pref);
136: PrefUtil.savePrefs();
137: return true;
138: }
139: }
|