blob: b1296a3a134504e37d0dfab00a86a44f1671f600 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004, 2018 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.activities;
import java.util.Hashtable;
import java.util.Properties;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.PreferencePage;
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.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.internal.IPreferenceConstants;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.activities.ws.ActivityEnabler;
import org.eclipse.ui.internal.activities.ws.ActivityMessages;
/**
* Preference page that allows configuration of the activity set. This page may
* be used by product developers to provide basic ability to tweak the enabled
* activity set. You may provide the certain strings to this class via method #2
* of {@link org.eclipse.core.runtime.IExecutableExtension}.
*
* @see #ACTIVITY_NAME
* @see #ACTIVITY_PROMPT_BUTTON
* @see #ACTIVITY_PROMPT_BUTTON_TOOLTIP
* @since 3.1
*/
public final class ActivitiesPreferencePage extends PreferencePage implements
IWorkbenchPreferencePage, IExecutableExtension {
/**
* The name to use for the activities. Ie: "Capabilities".
*/
public static final String ACTIVITY_NAME = "activityName"; //$NON-NLS-1$
/**
* The label to be used for the prompt button. Ie: "&Prompt when enabling
* capabilities".
*/
public static final String ACTIVITY_PROMPT_BUTTON = "activityPromptButton"; //$NON-NLS-1$
/**
* The tooltip to be used for the prompt button. Ie: "Prompt when a feature is first used that requires enablement of capabilities".
*/
public static final String ACTIVITY_PROMPT_BUTTON_TOOLTIP = "activityPromptButtonTooltip"; //$NON-NLS-1$
private Button activityPromptButton;
private IWorkbench workbench;
private ActivityEnabler enabler;
private Properties strings = new Properties();
private IMutableActivityManager workingCopy;
/**
* Create the prompt for activity enablement.
*
* @param composite the parent
*/
protected void createActivityPromptPref(Composite composite) {
activityPromptButton = new Button(composite, SWT.CHECK);
activityPromptButton.setText(strings.getProperty(ACTIVITY_PROMPT_BUTTON, ActivityMessages.activityPromptButton));
activityPromptButton.setToolTipText(strings.getProperty(ACTIVITY_PROMPT_BUTTON_TOOLTIP, ActivityMessages.activityPromptToolTip));
setActivityButtonState();
}
/**
* Sets the state of the activity prompt button from preferences.
*/
private void setActivityButtonState() {
activityPromptButton.setSelection(getPreferenceStore().getBoolean(
IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
}
@Override
protected Control createContents(Composite parent) {
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
composite.setLayout(layout);
createActivityPromptPref(composite);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
activityPromptButton.setLayoutData(data);
data = new GridData(GridData.FILL_BOTH);
workingCopy = workbench.getActivitySupport().createWorkingCopy();
enabler = new ActivityEnabler(workingCopy, strings);
enabler.createControl(composite).setLayoutData(data);
Dialog.applyDialogFont(composite);
return composite;
}
@Override
public void init(IWorkbench aWorkbench) {
this.workbench = aWorkbench;
setPreferenceStore(WorkbenchPlugin.getDefault().getPreferenceStore());
}
@Override
public boolean performOk() {
enabler.updateActivityStates();
workbench.getActivitySupport().setEnabledActivityIds(workingCopy.getEnabledActivityIds());
getPreferenceStore().setValue(
IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT,
activityPromptButton.getSelection());
return true;
}
@Override
protected void performDefaults() {
enabler.restoreDefaults();
activityPromptButton.setSelection(getPreferenceStore()
.getDefaultBoolean(
IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT));
super.performDefaults();
}
@Override
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) {
if (data instanceof Hashtable) {
strings.putAll((Hashtable<?, ?>) data);
}
}
}