diff --git a/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/dialogs/IDEStartupPreferencePage.java b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/dialogs/IDEStartupPreferencePage.java index 405f2b19178..46c80cf9606 100644 --- a/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/dialogs/IDEStartupPreferencePage.java +++ b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/dialogs/IDEStartupPreferencePage.java @@ -15,15 +15,9 @@ package org.eclipse.ui.internal.ide.application.dialogs; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.widgets.LabelFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.internal.IWorkbenchHelpContextIds; import org.eclipse.ui.internal.dialogs.StartupPreferencePage; import org.eclipse.ui.internal.ide.IDEInternalPreferences; import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; @@ -32,34 +26,26 @@ /** * Extends the Startup and Shutdown preference page with IDE-specific settings. * - * Note: want IDE settings to appear in main Workbench preference page (via subclassing), - * however the superclass, StartupPreferencePage, is internal + * Note: want IDE settings to appear in main Workbench preference page (via + * subclassing), however the superclass, StartupPreferencePage, is internal + * * @since 3.0 */ public class IDEStartupPreferencePage extends StartupPreferencePage implements IWorkbenchPreferencePage { private Button refreshButton; - private Button showProblemsButton; - private Button exitPromptButton; @Override - protected Control createContents(Composite parent) { - - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IWorkbenchHelpContextIds.STARTUP_PREFERENCE_PAGE); - - Composite composite = createComposite(parent); - - createRefreshWorkspaceOnStartupPref(composite); - createProblemsViewOnStartupPref(composite); - createExitPromptPref(composite); - - LabelFactory.newLabel(SWT.NONE).layoutData(new GridData()).create(composite); - - createEarlyStartupSelection(composite); - - return composite; + protected void createExtraContent(Composite composite) { + refreshButton = createCheckBox(IDEWorkbenchMessages.StartupPreferencePage_refreshButton, + IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP, composite); + showProblemsButton = createCheckBox(IDEWorkbenchMessages.StartupPreferencePage_showProblemsButton, + IDEInternalPreferences.SHOW_PROBLEMS_VIEW_DECORATIONS_ON_STARTUP, composite); + exitPromptButton = createCheckBox(IDEWorkbenchMessages.StartupPreferencePage_exitPromptButton, + IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, composite); + super.createExtraContent(composite); } /** @@ -69,16 +55,12 @@ protected Control createContents(Composite parent) { protected void performDefaults() { IPreferenceStore store = getIDEPreferenceStore(); - refreshButton - .setSelection(store - .getDefaultBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP)); + refreshButton.setSelection(store.getDefaultBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP)); showProblemsButton.setSelection( store.getDefaultBoolean(IDEInternalPreferences.SHOW_PROBLEMS_VIEW_DECORATIONS_ON_STARTUP)); - exitPromptButton - .setSelection(store - .getDefaultBoolean(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW)); + exitPromptButton.setSelection(store.getDefaultBoolean(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW)); super.performDefaults(); } @@ -91,50 +73,27 @@ public boolean performOk() { IPreferenceStore store = getIDEPreferenceStore(); // store the refresh workspace on startup setting - store.setValue(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP, - refreshButton.getSelection()); + store.setValue(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP, refreshButton.getSelection()); store.setValue(IDEInternalPreferences.SHOW_PROBLEMS_VIEW_DECORATIONS_ON_STARTUP, showProblemsButton.getSelection()); // store the exit prompt on last window close setting - store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, - exitPromptButton.getSelection()); + store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, exitPromptButton.getSelection()); IDEWorkbenchPlugin.getDefault().savePluginPreferences(); return super.performOk(); } - protected void createRefreshWorkspaceOnStartupPref(Composite composite) { - refreshButton = new Button(composite, SWT.CHECK); - refreshButton.setText(IDEWorkbenchMessages.StartupPreferencePage_refreshButton); - refreshButton.setFont(composite.getFont()); - refreshButton.setSelection(getIDEPreferenceStore().getBoolean( - IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP)); - } - - protected void createProblemsViewOnStartupPref(Composite composite) { - showProblemsButton = new Button(composite, SWT.CHECK); - showProblemsButton.setText(IDEWorkbenchMessages.StartupPreferencePage_showProblemsButton); - showProblemsButton.setFont(composite.getFont()); - showProblemsButton - .setSelection(getIDEPreferenceStore() - .getBoolean(IDEInternalPreferences.SHOW_PROBLEMS_VIEW_DECORATIONS_ON_STARTUP)); - } - - protected void createExitPromptPref(Composite composite) { - exitPromptButton = new Button(composite, SWT.CHECK); - exitPromptButton.setText(IDEWorkbenchMessages.StartupPreferencePage_exitPromptButton); - exitPromptButton.setFont(composite.getFont()); - exitPromptButton.setSelection(getIDEPreferenceStore().getBoolean( - IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW)); + private Button createCheckBox(String text, String preferenceKey, Composite composite) { + return createCheckBox(text, getIDEPreferenceStore().getBoolean(preferenceKey), composite); } /** * Returns the IDE preference store. */ - protected IPreferenceStore getIDEPreferenceStore() { + private static IPreferenceStore getIDEPreferenceStore() { return IDEWorkbenchPlugin.getDefault().getPreferenceStore(); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java index f295d9a78c7..dcf7a441628 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java @@ -15,16 +15,22 @@ import java.util.Arrays; import java.util.HashSet; +import java.util.Set; import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.widgets.ButtonFactory; +import org.eclipse.jface.widgets.CompositeFactory; +import org.eclipse.jface.widgets.LabelFactory; +import org.eclipse.jface.widgets.TableFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; @@ -53,37 +59,41 @@ public class StartupPreferencePage extends PreferencePage implements IWorkbenchP protected Control createContents(Composite parent) { PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IWorkbenchHelpContextIds.STARTUP_PREFERENCE_PAGE); - Composite composite = createComposite(parent); + Composite composite = CompositeFactory.newComposite(SWT.NONE) // + .layout(GridLayoutFactory.swtDefaults().margins(0, 0).create()) + .layoutData(new GridData(SWT.FILL, SWT.FILL, true, true)) // + .font(parent.getFont()).create(parent); + createExtraContent(composite); + if (composite.getChildren().length > 0) { + createSpacer(composite); + } createEarlyStartupSelection(composite); return composite; } - protected Composite createComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - GridData data = new GridData( - GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL); - composite.setLayoutData(data); - composite.setFont(parent.getFont()); + protected void createExtraContent(@SuppressWarnings("unused") Composite composite) { + // subclasses may override + } - return composite; + private static void createSpacer(Composite container) { + new Label(container, SWT.NONE); + } + + protected static Button createCheckBox(String text, boolean checked, Composite composite) { + Button button = ButtonFactory.newButton(SWT.CHECK).text(text).font(composite.getFont()).create(composite); + button.setSelection(checked); + return button; } protected void createEarlyStartupSelection(Composite parent) { - Label label = new Label(parent, SWT.NONE); - label.setText(WorkbenchMessages.StartupPreferencePage_label); - label.setFont(parent.getFont()); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - label.setLayoutData(data); - pluginsList = new Table(parent, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL); - data = new GridData(GridData.FILL_BOTH); - pluginsList.setFont(parent.getFont()); - pluginsList.setLayoutData(data); + LabelFactory.newLabel(SWT.NONE).text(WorkbenchMessages.StartupPreferencePage_label) // + .layoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)) // + .font(parent.getFont()).create(parent); + pluginsList = TableFactory.newTable(SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL) + .layoutData(new GridData(SWT.FILL, SWT.FILL, true, true)) // + .font(parent.getFont()).create(parent); TableViewer viewer = new TableViewer(pluginsList); viewer.setLabelProvider(new LabelProvider() { @Override @@ -99,7 +109,7 @@ public String getText(Object element) { } private void updateCheckState() { - HashSet disabledPlugins = new HashSet<>(Arrays.asList(workbench.getDisabledEarlyActivatedPlugins())); + Set disabledPlugins = new HashSet<>(Arrays.asList(workbench.getDisabledEarlyActivatedPlugins())); for (int i = 0; i < pluginsList.getItemCount(); i++) { TableItem item = pluginsList.getItem(i); String pluginId = ((ContributionInfo) item.getData()).getBundleId();