1 11 12 package org.eclipse.ui.internal.menus; 13 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 import org.eclipse.core.expressions.Expression; 20 import org.eclipse.jface.action.IContributionItem; 21 import org.eclipse.ui.internal.expressions.AlwaysEnabledExpression; 22 import org.eclipse.ui.menus.IContributionRoot; 23 24 29 final class ContributionRoot implements 30 IContributionRoot { 31 32 private List topLevelItems = new ArrayList (); 33 private List itemsToExpressions = new ArrayList (); 34 private InternalMenuService menuService; 35 private Expression restriction; 36 private String namespace; 37 38 public ContributionRoot(InternalMenuService menuService, Expression restriction, String namespace) { 39 this.menuService = menuService; 40 this.restriction = restriction; 41 this.namespace = namespace; 42 } 43 44 47 public void addContributionItem(IContributionItem item, 48 Expression visibleWhen) { 49 if (item == null) 50 throw new IllegalArgumentException (); 51 topLevelItems.add(item); 52 if (visibleWhen == null) 53 visibleWhen = AlwaysEnabledExpression.INSTANCE; 54 55 menuService.registerVisibleWhen(item, visibleWhen, restriction, 56 createIdentifierId(item)); 57 itemsToExpressions.add(item); 58 } 59 60 66 private String createIdentifierId(IContributionItem item) { 67 String identifierID = namespace != null ? namespace + '/' 68 + item.getId() : null; return identifierID; 72 } 73 74 public Collection getItems() { 75 return topLevelItems; 76 } 77 78 81 public void release() { 82 for (Iterator itemIter = itemsToExpressions.iterator(); itemIter.hasNext();) { 83 IContributionItem item = (IContributionItem) itemIter.next(); 84 menuService.unregisterVisibleWhen(item); 85 } 86 } 87 88 95 public void registerVisibilityForChild(IContributionItem item, 96 Expression visibleWhen) { 97 if (item == null) 98 throw new IllegalArgumentException (); 99 if (visibleWhen == null) 100 visibleWhen = AlwaysEnabledExpression.INSTANCE; 101 menuService.registerVisibleWhen(item, visibleWhen, restriction, 102 createIdentifierId(item)); 103 itemsToExpressions.add(item); 104 } 105 } 106 | Popular Tags |