001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 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.activities;
011:
012: import java.util.Hashtable;
013: import java.util.Properties;
014: import java.util.Set;
015:
016: import org.eclipse.core.runtime.IConfigurationElement;
017: import org.eclipse.core.runtime.IExecutableExtension;
018: import org.eclipse.jface.window.Window;
019: import org.eclipse.ui.internal.IPreferenceConstants;
020: import org.eclipse.ui.internal.WorkbenchPlugin;
021: import org.eclipse.ui.internal.activities.ws.EnablementDialog;
022: import org.eclipse.ui.internal.util.PrefUtil;
023: import org.eclipse.ui.internal.util.Util;
024:
025: /**
026: *
027: * Workbench implementation prompts the user with a dialog unless they've said
028: * that they don't want to be prompted. You may provide the certain strings to
029: * this class via method #2 of
030: * {@link org.eclipse.core.runtime.IExecutableExtension}. This is provided as
031: * API so that non-SDK Eclipse applications can reuse and augment the default
032: * SDK trigger point behaviour.
033: *
034: * @see #PROCEED_MULTI
035: * @see #PROCEED_SINGLE
036: * @see #DONT_ASK
037: * @see #NO_DETAILS
038: * @since 3.1
039: */
040: public class WorkbenchTriggerPointAdvisor implements
041: ITriggerPointAdvisor, IExecutableExtension {
042:
043: /**
044: * The string to be used when prompting to proceed with multiple activities.
045: * Ie: "Enable the selected activities?"
046: */
047: public static String PROCEED_MULTI = "proceedMulti"; //$NON-NLS-1$
048:
049: /**
050: * The string to be used when prompting to proceed with a single activity.
051: * Ie: "Enable the required activity?"
052: */
053: public static String PROCEED_SINGLE = "proceedSingle"; //$NON-NLS-1$
054:
055: /**
056: * The string to be used to label the "don't ask" button.
057: * Ie: "&Always enable activities and don't ask me again"
058: */
059: public static String DONT_ASK = "dontAsk"; //$NON-NLS-1$
060:
061: /**
062: * The string to be used when no activities are selected and Details are shown.
063: * Ie: "Select an activity to view its description."
064: */
065: public static String NO_DETAILS = "noDetails"; //$NON-NLS-1$
066:
067: private Properties strings = new Properties();
068:
069: /**
070: * Create a new instance of this advisor.
071: */
072: public WorkbenchTriggerPointAdvisor() {
073: super ();
074: }
075:
076: /* (non-Javadoc)
077: * @see org.eclipse.ui.activities.ITriggerPointAdvisor#allow(org.eclipse.ui.activities.ITriggerPoint, org.eclipse.ui.activities.IIdentifier)
078: */
079: public Set allow(ITriggerPoint triggerPoint, IIdentifier identifier) {
080: if (!PrefUtil.getInternalPreferenceStore().getBoolean(
081: IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT)) {
082: return identifier.getActivityIds();
083: }
084:
085: //If it's a non-interactive point activate all activities
086: if (!triggerPoint
087: .getBooleanHint(ITriggerPoint.HINT_INTERACTIVE)) {
088: return identifier.getActivityIds();
089: }
090:
091: EnablementDialog dialog = new EnablementDialog(Util
092: .getShellToParentOn(), identifier.getActivityIds(),
093: strings);
094: if (dialog.open() == Window.OK) {
095: Set activities = dialog.getActivitiesToEnable();
096: if (dialog.getDontAsk()) {
097: PrefUtil
098: .getInternalPreferenceStore()
099: .setValue(
100: IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT,
101: false);
102: WorkbenchPlugin.getDefault().savePluginPreferences();
103: }
104:
105: return activities;
106: }
107:
108: return null;
109: }
110:
111: /* (non-Javadoc)
112: * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
113: */
114: public void setInitializationData(IConfigurationElement config,
115: String propertyName, Object data) {
116: if (data instanceof Hashtable) {
117: strings.putAll((Hashtable) data);
118: }
119: }
120: }
|