1 11 package org.eclipse.ui.internal.activities.ws; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 import java.util.Set ; 17 18 import org.eclipse.jface.viewers.ITreeContentProvider; 19 import org.eclipse.jface.viewers.Viewer; 20 import org.eclipse.ui.activities.IActivity; 21 import org.eclipse.ui.activities.IActivityManager; 22 import org.eclipse.ui.activities.IActivityRequirementBinding; 23 import org.eclipse.ui.activities.ICategory; 24 import org.eclipse.ui.activities.ICategoryActivityBinding; 25 26 38 public class ActivityCategoryContentProvider implements ITreeContentProvider { 39 40 43 private IActivityManager manager; 44 45 48 public void dispose() { 49 manager = null; 50 } 51 52 56 private IActivity[] getCategoryActivities(ICategory category) { 57 Set activityBindings = category.getCategoryActivityBindings(); 58 List categoryActivities = new ArrayList (activityBindings.size()); 59 for (Iterator j = activityBindings.iterator(); j.hasNext();) { 60 ICategoryActivityBinding binding = (ICategoryActivityBinding) j 61 .next(); 62 String activityId = binding.getActivityId(); 63 IActivity activity = manager.getActivity(activityId); 64 if (activity.isDefined()) { 65 categoryActivities.add(new CategorizedActivity(category, 66 activity)); 67 } 68 } 69 return (IActivity[]) categoryActivities 70 .toArray(new IActivity[categoryActivities.size()]); 71 } 72 73 80 public Object [] getDuplicateCategoryActivities( 81 CategorizedActivity categorizedActivity) { 82 ArrayList duplicateCategorizedactivities = new ArrayList (); 83 Set categoryIds = manager.getDefinedCategoryIds(); 84 ICategory currentCategory = null; 85 String currentActivityId = null; 86 IActivity[] categoryActivities = null; 87 String currentCategoryId = null; 88 for (Iterator i = categoryIds.iterator(); i.hasNext();) { 90 currentCategoryId = (String ) i.next(); 91 if (!currentCategoryId.equals(categorizedActivity.getCategory() 92 .getId())) { 93 currentCategory = manager.getCategory(currentCategoryId); 94 categoryActivities = getCategoryActivities(currentCategory); 95 for (int index = 0; index < categoryActivities.length; index++) { 97 currentActivityId = categoryActivities[index].getId(); 98 if (currentActivityId.equals(categorizedActivity 99 .getActivity().getId())) { 100 duplicateCategorizedactivities 101 .add(new CategorizedActivity(currentCategory, 102 manager.getActivity(currentActivityId))); 103 break; 106 } 107 } 108 109 } 110 111 } 112 return duplicateCategorizedactivities.toArray(); 113 } 114 115 122 public Object [] getChildRequiredActivities(String activityId) { 123 ArrayList childRequiredActivities = new ArrayList (); 124 IActivity activity = manager.getActivity(activityId); 125 Set actvitiyRequirementBindings = activity 126 .getActivityRequirementBindings(); 127 String requiredActivityId = null; 128 IActivityRequirementBinding currentActivityRequirementBinding = null; 129 Object [] currentCategoryIds = null; 130 for (Iterator i = actvitiyRequirementBindings.iterator(); i.hasNext();) { 131 currentActivityRequirementBinding = (IActivityRequirementBinding) i 132 .next(); 133 requiredActivityId = currentActivityRequirementBinding 134 .getRequiredActivityId(); 135 currentCategoryIds = getActivityCategories(requiredActivityId); 136 for (int index = 0; index < currentCategoryIds.length; index++) { 137 childRequiredActivities.add(new CategorizedActivity(manager 138 .getCategory((String ) currentCategoryIds[index]), 139 manager.getActivity(requiredActivityId))); 140 } 141 142 } 143 144 return childRequiredActivities.toArray(); 145 } 146 147 154 public Object [] getParentRequiredActivities(String activityId) { 155 ArrayList parentRequiredActivities = new ArrayList (); 156 Set definedActivities = manager.getDefinedActivityIds(); 157 String currentActivityId = null; 158 Set activityRequirementBindings = null; 159 IActivityRequirementBinding currentActivityRequirementBinding = null; 160 Object [] currentCategoryIds = null; 161 for (Iterator i = definedActivities.iterator(); i.hasNext();) { 162 currentActivityId = (String ) i.next(); 163 activityRequirementBindings = manager 164 .getActivity(currentActivityId) 165 .getActivityRequirementBindings(); 166 for (Iterator j = activityRequirementBindings.iterator(); j 167 .hasNext();) { 168 currentActivityRequirementBinding = (IActivityRequirementBinding) j 169 .next(); 170 if (currentActivityRequirementBinding.getRequiredActivityId() 171 .equals(activityId)) { 172 currentCategoryIds = getActivityCategories(currentActivityId); 174 for (int index = 0; index < currentCategoryIds.length; index++) { 175 parentRequiredActivities 176 .add(new CategorizedActivity( 177 manager 178 .getCategory((String ) currentCategoryIds[index]), 179 manager.getActivity(currentActivityId))); 180 } 181 } 182 } 183 184 } 185 return parentRequiredActivities.toArray(); 186 } 187 188 195 private Object [] getActivityCategories(String activityId) { 196 ArrayList activityCategories = new ArrayList (); 197 Set categoryIds = manager.getDefinedCategoryIds(); 198 String currentCategoryId = null; 199 IActivity[] categoryActivities = null; 200 for (Iterator i = categoryIds.iterator(); i.hasNext();) { 201 currentCategoryId = (String ) i.next(); 202 categoryActivities = getCategoryActivities(manager 203 .getCategory(currentCategoryId)); 204 for (int index = 0; index < categoryActivities.length; index++) { 205 if (categoryActivities[index].getId().equals(activityId)) { 206 activityCategories.add(currentCategoryId); 207 break; 208 } 209 } 210 } 211 return activityCategories.toArray(); 212 } 213 214 217 public Object [] getChildren(Object parentElement) { 218 if (parentElement instanceof IActivityManager) { 219 Set categoryIds = manager.getDefinedCategoryIds(); 220 ArrayList categories = new ArrayList (categoryIds.size()); 221 for (Iterator i = categoryIds.iterator(); i.hasNext();) { 222 String categoryId = (String ) i.next(); 223 ICategory category = manager.getCategory(categoryId); 224 if (getCategoryActivities(category).length > 0) { 225 categories.add(category); 226 } 227 } 228 return categories.toArray(); 229 } else if (parentElement instanceof ICategory) { 230 return getCategoryActivities((ICategory) parentElement); 231 } 232 return new Object [0]; 233 } 234 235 238 public Object [] getElements(Object inputElement) { 239 return getChildren(inputElement); 240 } 241 242 245 public Object getParent(Object element) { 246 if (element instanceof CategorizedActivity) { 247 return ((CategorizedActivity) element).getCategory(); 248 } 249 return null; 250 } 251 252 255 public boolean hasChildren(Object element) { 256 if (element instanceof IActivityManager || element instanceof ICategory) { 257 return true; 258 } 259 return false; 260 } 261 262 265 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 266 manager = (IActivityManager) newInput; 267 } 268 } 269 | Popular Tags |