1 11 package org.eclipse.ui.internal.dialogs; 12 13 import java.util.Arrays ; 14 import java.util.HashSet ; 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 40 public class StartupPreferencePage extends PreferencePage implements 41 IWorkbenchPreferencePage { 42 private Table pluginsList; 43 44 private Workbench workbench; 45 46 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 pluginIds[] = workbench.getEarlyActivatedPlugins(); 90 HashSet disabledPlugins = new HashSet (Arrays.asList(workbench.getDisabledEarlyActivatedPlugins())); 91 for (int i = 0; i < pluginIds.length; i++) { 92 String pluginId = pluginIds[i]; 93 TableItem item = new TableItem(pluginsList, SWT.NONE); 94 item.setText((String ) Platform.getBundle(pluginId).getHeaders().get( 95 Constants.BUNDLE_NAME)); 96 item.setData(pluginId); 97 item.setChecked(!disabledPlugins.contains(pluginId)); 98 } 99 } 100 101 104 public void init(IWorkbench workbench) { 105 this.workbench = (Workbench) workbench; 106 } 107 108 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 121 public boolean performOk() { 122 StringBuffer preference = new StringBuffer (); 123 TableItem items[] = pluginsList.getItems(); 124 for (int i = 0; i < items.length; i++) { 125 if (!items[i].getChecked()) { 126 preference.append((String ) items[i].getData()); 127 preference.append(IPreferenceConstants.SEPARATOR); 128 } 129 } 130 String 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 |