1 11 package org.eclipse.ui.internal.contexts; 12 13 import java.util.Collection ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 import org.eclipse.core.commands.contexts.ContextManager; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.ui.ISources; 21 import org.eclipse.ui.LegacyHandlerSubmissionExpression; 22 import org.eclipse.ui.contexts.EnabledSubmission; 23 import org.eclipse.ui.contexts.IContextActivation; 24 import org.eclipse.ui.contexts.IContextManager; 25 import org.eclipse.ui.contexts.IContextService; 26 import org.eclipse.ui.contexts.IWorkbenchContextSupport; 27 import org.eclipse.ui.internal.Workbench; 28 import org.eclipse.ui.keys.IBindingService; 29 30 36 public class WorkbenchContextSupport implements IWorkbenchContextSupport { 37 38 43 private Map activationsBySubmission = null; 44 45 49 private IBindingService bindingService; 50 51 55 private IContextService contextService; 56 57 60 private ContextManagerLegacyWrapper contextManagerWrapper; 61 62 66 private final Workbench workbench; 67 68 80 public WorkbenchContextSupport(final Workbench workbenchToSupport, 81 final ContextManager contextManager) { 82 workbench = workbenchToSupport; 83 contextService = (IContextService) workbench.getService(IContextService.class); 84 bindingService = (IBindingService) workbench.getService(IBindingService.class); 85 contextManagerWrapper = ContextManagerFactory 86 .getContextManagerWrapper(contextManager); 87 } 88 89 public final void addEnabledSubmission( 90 final EnabledSubmission enabledSubmission) { 91 95 int sourcePriorities = 0; 96 if (enabledSubmission.getActivePartId() != null) { 97 sourcePriorities |= ISources.ACTIVE_PART_ID; 98 } 99 if (enabledSubmission.getActiveShell() != null) { 100 sourcePriorities |= (ISources.ACTIVE_SHELL | ISources.ACTIVE_WORKBENCH_WINDOW); 101 } 102 if (enabledSubmission.getActiveWorkbenchPartSite() != null) { 103 sourcePriorities |= ISources.ACTIVE_SITE; 104 } 105 106 final IContextActivation activation = contextService.activateContext( 107 enabledSubmission.getContextId(), 108 new LegacyHandlerSubmissionExpression(enabledSubmission 109 .getActivePartId(), enabledSubmission.getActiveShell(), 110 enabledSubmission.getActiveWorkbenchPartSite())); 111 if (activationsBySubmission == null) { 112 activationsBySubmission = new HashMap (); 113 } 114 activationsBySubmission.put(enabledSubmission, activation); 115 } 116 117 public final void addEnabledSubmissions(final Collection enabledSubmissions) { 118 final Iterator submissionItr = enabledSubmissions.iterator(); 119 while (submissionItr.hasNext()) { 120 addEnabledSubmission((EnabledSubmission) submissionItr.next()); 121 } 122 } 123 124 public final IContextManager getContextManager() { 125 return contextManagerWrapper; 126 } 127 128 public final int getShellType(Shell shell) { 129 return contextService.getShellType(shell); 130 } 131 132 public final boolean isKeyFilterEnabled() { 133 return bindingService.isKeyFilterEnabled(); 134 } 135 136 public final void openKeyAssistDialog() { 137 bindingService.openKeyAssistDialog(); 138 } 139 140 public final boolean registerShell(final Shell shell, final int type) { 141 return contextService.registerShell(shell, type); 142 } 143 144 public final void removeEnabledSubmission( 145 final EnabledSubmission enabledSubmission) { 146 if (activationsBySubmission == null) { 147 return; 148 } 149 150 final Object value = activationsBySubmission.remove(enabledSubmission); 151 if (value instanceof IContextActivation) { 152 final IContextActivation activation = (IContextActivation) value; 153 contextService.deactivateContext(activation); 154 } 155 } 156 157 public final void removeEnabledSubmissions( 158 final Collection enabledSubmissions) { 159 final Iterator submissionItr = enabledSubmissions.iterator(); 160 while (submissionItr.hasNext()) { 161 removeEnabledSubmission((EnabledSubmission) submissionItr.next()); 162 } 163 } 164 165 public final void setKeyFilterEnabled(final boolean enabled) { 166 bindingService.setKeyFilterEnabled(enabled); 167 } 168 169 public final boolean unregisterShell(final Shell shell) { 170 return contextService.unregisterShell(shell); 171 } 172 } 173 | Popular Tags |