1 11 package org.eclipse.ui.activities; 12 13 import java.util.Hashtable ; 14 import java.util.Properties ; 15 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExecutableExtension; 18 import org.eclipse.jface.dialogs.Dialog; 19 import org.eclipse.jface.dialogs.IDialogConstants; 20 import org.eclipse.jface.preference.PreferencePage; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.layout.GridLayout; 24 import org.eclipse.swt.widgets.Button; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.ui.IWorkbench; 28 import org.eclipse.ui.IWorkbenchPreferencePage; 29 import org.eclipse.ui.internal.IPreferenceConstants; 30 import org.eclipse.ui.internal.WorkbenchPlugin; 31 import org.eclipse.ui.internal.activities.ws.ActivityEnabler; 32 import org.eclipse.ui.internal.activities.ws.ActivityMessages; 33 34 45 public final class ActivitiesPreferencePage extends PreferencePage implements 46 IWorkbenchPreferencePage, IExecutableExtension { 47 48 51 public static final String ACTIVITY_NAME = "activityName"; 53 56 public static final String ACTIVITY_PROMPT_BUTTON = "activityPromptButton"; 58 61 public static final String ACTIVITY_PROMPT_BUTTON_TOOLTIP = "activityPromptButtonTooltip"; 63 private Button activityPromptButton; 64 65 private IWorkbench workbench; 66 67 private ActivityEnabler enabler; 68 69 private Properties strings = new Properties (); 70 71 private IMutableActivityManager workingCopy; 72 73 78 protected void createActivityPromptPref(Composite composite) { 79 activityPromptButton = new Button(composite, SWT.CHECK); 80 activityPromptButton.setText(strings.getProperty(ACTIVITY_PROMPT_BUTTON, ActivityMessages.activityPromptButton)); 81 activityPromptButton.setToolTipText(strings.getProperty(ACTIVITY_PROMPT_BUTTON_TOOLTIP, ActivityMessages.activityPromptToolTip)); 82 83 setActivityButtonState(); 84 } 85 86 89 private void setActivityButtonState() { 90 activityPromptButton.setSelection(getPreferenceStore().getBoolean( 91 IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT)); 92 } 93 94 97 protected Control createContents(Composite parent) { 98 initializeDialogUnits(parent); 99 100 Composite composite = new Composite(parent, SWT.NONE); 101 GridLayout layout = new GridLayout(); 102 layout.marginHeight = 0; 103 layout.marginWidth = 0; 104 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 105 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 106 composite.setLayout(layout); 107 108 createActivityPromptPref(composite); 109 GridData data = new GridData(GridData.FILL_HORIZONTAL); 110 activityPromptButton.setLayoutData(data); 111 112 data = new GridData(GridData.FILL_BOTH); 113 workingCopy = workbench.getActivitySupport().createWorkingCopy(); 114 enabler = new ActivityEnabler(workingCopy, strings); 115 enabler.createControl(composite).setLayoutData(data); 116 117 Dialog.applyDialogFont(composite); 118 119 return composite; 120 } 121 122 125 public void init(IWorkbench aWorkbench) { 126 this.workbench = aWorkbench; 127 setPreferenceStore(WorkbenchPlugin.getDefault().getPreferenceStore()); 128 } 129 130 133 public boolean performOk() { 134 enabler.updateActivityStates(); 135 workbench.getActivitySupport().setEnabledActivityIds(workingCopy.getEnabledActivityIds()); 136 137 getPreferenceStore().setValue( 138 IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT, 139 activityPromptButton.getSelection()); 140 141 return true; 142 } 143 144 147 protected void performDefaults() { 148 enabler.restoreDefaults(); 149 activityPromptButton.setSelection(getPreferenceStore() 150 .getDefaultBoolean( 151 IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT)); 152 super.performDefaults(); 153 } 154 155 158 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) { 159 if (data instanceof Hashtable ) { 160 strings.putAll((Hashtable )data); 161 } 162 } 163 } 164 | Popular Tags |