KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > activities > WorkbenchTriggerPointAdvisor


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.activities;
12
13 import java.util.Hashtable JavaDoc;
14 import java.util.Properties JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IExecutableExtension;
19 import org.eclipse.jface.window.Window;
20 import org.eclipse.ui.internal.IPreferenceConstants;
21 import org.eclipse.ui.internal.WorkbenchPlugin;
22 import org.eclipse.ui.internal.activities.ws.EnablementDialog;
23 import org.eclipse.ui.internal.util.PrefUtil;
24 import org.eclipse.ui.internal.util.Util;
25
26 /**
27  *
28  * Workbench implementation prompts the user with a dialog unless they've said
29  * that they don't want to be prompted. You may provide the certain strings to
30  * this class via method #2 of
31  * {@link org.eclipse.core.runtime.IExecutableExtension}. This is provided as
32  * API so that non-SDK Eclipse applications can reuse and augment the default
33  * SDK trigger point behaviour.
34  *
35  * @see #PROCEED_MULTI
36  * @see #PROCEED_SINGLE
37  * @see #DONT_ASK
38  * @see #NO_DETAILS
39  * @since 3.1
40  */

41 public class WorkbenchTriggerPointAdvisor implements ITriggerPointAdvisor,
42         IExecutableExtension {
43
44     /**
45      * The string to be used when prompting to proceed with multiple activities.
46      * Ie: "Enable the selected activities?"
47      */

48     public static String JavaDoc PROCEED_MULTI = "proceedMulti"; //$NON-NLS-1$
49

50     /**
51      * The string to be used when prompting to proceed with a single activity.
52      * Ie: "Enable the required activity?"
53      */

54     public static String JavaDoc PROCEED_SINGLE = "proceedSingle"; //$NON-NLS-1$
55

56     /**
57      * The string to be used to label the "don't ask" button.
58      * Ie: "&Always enable activities and don't ask me again"
59      */

60     public static String JavaDoc DONT_ASK = "dontAsk"; //$NON-NLS-1$
61

62     /**
63      * The string to be used when no activities are selected and Details are shown.
64      * Ie: "Select an activity to view its description."
65      */

66     public static String JavaDoc NO_DETAILS = "noDetails"; //$NON-NLS-1$
67

68     
69     private Properties JavaDoc strings = new Properties JavaDoc();
70     
71     /**
72      * Create a new instance of this advisor.
73      */

74     public WorkbenchTriggerPointAdvisor() {
75         super();
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.ui.activities.ITriggerPointAdvisor#allow(org.eclipse.ui.activities.ITriggerPoint, org.eclipse.ui.activities.IIdentifier)
80      */

81     public Set JavaDoc allow(ITriggerPoint triggerPoint, IIdentifier identifier) {
82         if (!PrefUtil.getInternalPreferenceStore().getBoolean(
83                 IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT)) {
84             return identifier.getActivityIds();
85         }
86         
87         //If it's a non-interactive point activate all activities
88
if (!triggerPoint.getBooleanHint(ITriggerPoint.HINT_INTERACTIVE)) {
89             return identifier.getActivityIds();
90         }
91         
92         EnablementDialog dialog = new EnablementDialog(Util.getShellToParentOn(), identifier
93                 .getActivityIds(), strings);
94         if (dialog.open() == Window.OK) {
95             Set JavaDoc activities = dialog.getActivitiesToEnable();
96             if (dialog.getDontAsk()) {
97                 PrefUtil.getInternalPreferenceStore().setValue(
98                         IPreferenceConstants.SHOULD_PROMPT_FOR_ENABLEMENT,
99                         false);
100                 WorkbenchPlugin.getDefault().savePluginPreferences();
101             }
102
103             return activities;
104         }
105         
106         return null;
107     }
108
109     /* (non-Javadoc)
110      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
111      */

112     public void setInitializationData(IConfigurationElement config, String JavaDoc propertyName, Object JavaDoc data) {
113         if (data instanceof Hashtable JavaDoc) {
114             strings.putAll((Hashtable JavaDoc)data);
115         }
116     }
117 }
118
Popular Tags