1 11 12 package org.eclipse.ui.internal.services; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.expressions.Expression; 18 import org.eclipse.core.expressions.ExpressionInfo; 19 import org.eclipse.ui.ISources; 20 21 46 public final class SourcePriorityNameMapping implements ISources { 47 48 51 public static final String LEGACY_LEGACY_NAME = "LEGACY"; 53 58 public static final int NO_SOURCE_PRIORITY = 0; 59 60 64 private static final Map sourcePrioritiesByName = new HashMap (); 65 66 static { 67 addMapping(ACTIVE_ACTION_SETS_NAME, ACTIVE_ACTION_SETS); 68 addMapping(ACTIVE_CONTEXT_NAME, ACTIVE_CONTEXT); 69 addMapping(ACTIVE_CURRENT_SELECTION_NAME, ACTIVE_CURRENT_SELECTION); 70 addMapping(ACTIVE_EDITOR_NAME, ACTIVE_EDITOR); 71 addMapping(ACTIVE_EDITOR_ID_NAME, ACTIVE_EDITOR_ID); 72 addMapping(ACTIVE_MENU_NAME, ACTIVE_MENU); 73 addMapping(ACTIVE_MENU_SELECTION_NAME, ACTIVE_MENU); 74 addMapping(ACTIVE_MENU_EDITOR_INPUT_NAME, ACTIVE_MENU); 75 addMapping(ACTIVE_FOCUS_CONTROL_ID_NAME, ACTIVE_MENU); 76 addMapping(ACTIVE_FOCUS_CONTROL_NAME, ACTIVE_MENU); 77 addMapping(ACTIVE_PART_NAME, ACTIVE_PART); 78 addMapping(ACTIVE_PART_ID_NAME, ACTIVE_PART_ID); 79 addMapping(ACTIVE_SHELL_NAME, ACTIVE_SHELL); 80 addMapping(ACTIVE_SITE_NAME, ACTIVE_SITE); 81 addMapping(ACTIVE_WORKBENCH_WINDOW_NAME, ACTIVE_WORKBENCH_WINDOW); 82 addMapping(ACTIVE_WORKBENCH_WINDOW_SHELL_NAME, 83 ACTIVE_WORKBENCH_WINDOW_SHELL); 84 addMapping(ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME, 85 ACTIVE_WORKBENCH_WINDOW_SUBORDINATE); 86 addMapping(ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME, 87 ACTIVE_WORKBENCH_WINDOW_SUBORDINATE); 88 addMapping(LEGACY_LEGACY_NAME, LEGACY_LEGACY); 89 } 90 91 106 public static final void addMapping(final String sourceName, 107 final int sourcePriority) { 108 if (sourceName == null) { 109 throw new NullPointerException ("The source name cannot be null."); } 111 112 final Integer priority = new Integer (sourcePriority); 113 114 sourcePrioritiesByName.put(sourceName, priority); 115 } 116 117 131 public static final int computeSourcePriority(final Expression expression) { 132 int sourcePriority = ISources.WORKBENCH; 133 134 if (expression == null) { 135 return sourcePriority; 136 } 137 138 final ExpressionInfo info = expression.computeExpressionInfo(); 139 140 if (info.hasDefaultVariableAccess()) { 142 sourcePriority |= ISources.ACTIVE_CURRENT_SELECTION; 143 } 144 145 final String [] sourceNames = info.getAccessedVariableNames(); 147 for (int i = 0; i < sourceNames.length; i++) { 148 final String sourceName = sourceNames[i]; 149 sourcePriority |= getMapping(sourceName); 150 } 151 152 return sourcePriority; 153 } 154 155 164 public static final int getMapping(final String sourceName) { 165 final Object object = sourcePrioritiesByName.get(sourceName); 166 if (object instanceof Integer ) { 167 return ((Integer ) object).intValue(); 168 } 169 170 return NO_SOURCE_PRIORITY; 171 } 172 173 176 private SourcePriorityNameMapping() { 177 } 179 } 180 | Popular Tags |