KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > activities > ActivityPropertyTester


1 /*******************************************************************************
2  * Copyright (c) 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.internal.activities;
12
13 import org.eclipse.core.expressions.PropertyTester;
14 import org.eclipse.ui.IWorkbench;
15 import org.eclipse.ui.activities.IActivityManager;
16 import org.eclipse.ui.activities.IWorkbenchActivitySupport;
17 import org.eclipse.ui.activities.WorkbenchActivityHelper;
18
19 /**
20  * An expressions property tester that tests whether or not an activity or
21  * category of activities is enabled. Useful for cross-component links and to
22  * control discoverability of functionality.
23  *
24  * @since 3.3
25  */

26 public class ActivityPropertyTester extends PropertyTester {
27
28     private static final String JavaDoc PROPERTY_IS_ACTIVITY_ENABLED = "isActivityEnabled"; //$NON-NLS-1$
29
private static final String JavaDoc PROPERTY_IS_CATEGORY_ENABLED = "isCategoryEnabled"; //$NON-NLS-1$
30

31     /*
32      * (non-Javadoc)
33      *
34      * @see org.eclipse.core.expressions.PropertyTester#test(java.lang.Object,
35      * java.lang.String, java.lang.Object[], java.lang.Object)
36      */

37     public boolean test(Object JavaDoc receiver, String JavaDoc property, Object JavaDoc[] args,
38             Object JavaDoc expectedValue) {
39         if (args.length == 1 && receiver instanceof IWorkbench && args[0] instanceof String JavaDoc) {
40             if (PROPERTY_IS_ACTIVITY_ENABLED.equals(property)) {
41                 return isActivityEnabled((String JavaDoc) args[0], (IWorkbench)receiver);
42             } else if (PROPERTY_IS_CATEGORY_ENABLED.equals(property)) {
43                 return isCategoryEnabled((String JavaDoc) args[0], (IWorkbench)receiver);
44             }
45         }
46         return false;
47     }
48
49     private static boolean isActivityEnabled(String JavaDoc activityId, IWorkbench workbench) {
50         try {
51             IWorkbenchActivitySupport workbenchActivitySupport =
52                     workbench.getActivitySupport();
53             IActivityManager activityManager = workbenchActivitySupport
54                     .getActivityManager();
55             return activityManager.getActivity(activityId).isEnabled();
56         } catch (Exception JavaDoc e) {
57             // workbench not yet activated; nothing enabled yet
58
}
59         return false;
60     }
61
62     private static boolean isCategoryEnabled(String JavaDoc categoryId, IWorkbench workbench) {
63         try {
64             IWorkbenchActivitySupport workbenchActivitySupport =
65                     workbench.getActivitySupport();
66             IActivityManager activityManager = workbenchActivitySupport
67                     .getActivityManager();
68             return WorkbenchActivityHelper.isEnabled(activityManager,
69                     categoryId);
70         } catch (Exception JavaDoc e) {
71             // workbench not yet activated; nothing enabled yet
72
}
73         return false;
74     }
75 }
76
Popular Tags