1 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 26 public class ActivityPropertyTester extends PropertyTester { 27 28 private static final String PROPERTY_IS_ACTIVITY_ENABLED = "isActivityEnabled"; private static final String PROPERTY_IS_CATEGORY_ENABLED = "isCategoryEnabled"; 31 37 public boolean test(Object receiver, String property, Object [] args, 38 Object expectedValue) { 39 if (args.length == 1 && receiver instanceof IWorkbench && args[0] instanceof String ) { 40 if (PROPERTY_IS_ACTIVITY_ENABLED.equals(property)) { 41 return isActivityEnabled((String ) args[0], (IWorkbench)receiver); 42 } else if (PROPERTY_IS_CATEGORY_ENABLED.equals(property)) { 43 return isCategoryEnabled((String ) args[0], (IWorkbench)receiver); 44 } 45 } 46 return false; 47 } 48 49 private static boolean isActivityEnabled(String 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 e) { 57 } 59 return false; 60 } 61 62 private static boolean isCategoryEnabled(String 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 e) { 71 } 73 return false; 74 } 75 } 76 | Popular Tags |