1+ package io .cucumber .eclipse .editor ;
2+
3+ import java .util .HashSet ;
4+ import java .util .Set ;
5+
6+ import org .eclipse .ui .PlatformUI ;
7+ import org .eclipse .ui .activities .IWorkbenchActivitySupport ;
8+
9+ /**
10+ * Utility class for managing Eclipse activity enablement for Cucumber plugin features.
11+ * <p>
12+ * This class controls the visibility of various Cucumber-related UI elements through
13+ * Eclipse's activity framework. Activities can be enabled or disabled to show/hide
14+ * console output, launch configurations, property pages, and preference pages.
15+ * </p>
16+ */
17+ public class CucumberActivitySupport {
18+
19+ /** Activity ID for Cucumber console output */
20+ private static final String CONSOLE = "io.cucumber.eclipse.editor.console" ;
21+
22+ /** Activity ID for Cucumber launch configurations */
23+ private static final String LAUNCH = "io.cucumber.eclipse.editor.launch" ;
24+
25+ /** Activity ID for Cucumber property pages */
26+ private static final String PROPERTIES = "io.cucumber.eclipse.editor.properties" ;
27+
28+ /** Activity ID for Cucumber preference pages */
29+ private static final String PREFERENCES = "io.cucumber.eclipse.editor.preferences" ;
30+
31+ /**
32+ * Enables or disables a specific Eclipse activity.
33+ *
34+ * @param activityId the ID of the activity to enable or disable
35+ * @param enabled {@code true} to enable the activity, {@code false} to disable it
36+ */
37+ private static void setActivityEnabled (String activityId , boolean enabled ) {
38+ IWorkbenchActivitySupport activitySupport = PlatformUI .getWorkbench ().getActivitySupport ();
39+ Set <String > enabledActivities = new HashSet <>(activitySupport .getActivityManager ().getEnabledActivityIds ());
40+
41+ if (enabled ) {
42+ enabledActivities .add (activityId );
43+ } else {
44+ enabledActivities .remove (activityId );
45+ }
46+ activitySupport .setEnabledActivityIds (enabledActivities );
47+ }
48+
49+ /**
50+ * Disables all Cucumber-related activities.
51+ * <p>
52+ * This method disables preferences, properties, launch configurations, and console
53+ * output activities. It is typically called when no Cucumber support is needed.
54+ * </p>
55+ */
56+ public static void disableAllCucumberActivities () {
57+ enablePreferences (false );
58+ enableProperties (false );
59+ enableLaunch (false );
60+ enableConsole (false );
61+ }
62+
63+ /**
64+ * Enables or disables the Cucumber console activity.
65+ * <p>
66+ * When enabled, Cucumber console output will be visible in the Eclipse console view.
67+ * </p>
68+ *
69+ * @param enabled {@code true} to enable console output, {@code false} to disable it
70+ */
71+ public static void enableConsole (boolean enabled ) {
72+ setActivityEnabled (CONSOLE , enabled );
73+ }
74+
75+ /**
76+ * Enables or disables the Cucumber launch configuration activity.
77+ * <p>
78+ * When enabled, Cucumber launch configurations will be available in the Eclipse
79+ * launch configuration dialog and shortcuts.
80+ * </p>
81+ *
82+ * @param enabled {@code true} to enable launch configurations, {@code false} to disable them
83+ */
84+ public static void enableLaunch (boolean enabled ) {
85+ setActivityEnabled (LAUNCH , enabled );
86+ }
87+
88+ /**
89+ * Enables or disables the Cucumber property pages activity.
90+ * <p>
91+ * When enabled, Cucumber-related property pages will be visible in the project
92+ * and resource properties dialogs.
93+ * </p>
94+ *
95+ * @param enabled {@code true} to enable property pages, {@code false} to disable them
96+ */
97+ public static void enableProperties (boolean enabled ) {
98+ setActivityEnabled (PROPERTIES , enabled );
99+ }
100+
101+ /**
102+ * Enables or disables the Cucumber preference pages activity.
103+ * <p>
104+ * When enabled, Cucumber-related preference pages will be visible in the Eclipse
105+ * preferences dialog.
106+ * </p>
107+ *
108+ * @param enabled {@code true} to enable preference pages, {@code false} to disable them
109+ */
110+ public static void enablePreferences (boolean enabled ) {
111+ setActivityEnabled (PREFERENCES , enabled );
112+ }
113+
114+ }
0 commit comments