1 11 package org.eclipse.ui.internal.part.multiplexer; 12 13 import org.eclipse.jface.util.Assert; 14 import org.eclipse.ui.internal.components.ComponentUtil; 15 import org.eclipse.ui.internal.components.framework.IServiceProvider; 16 import org.eclipse.ui.internal.components.framework.ServiceFactory; 17 import org.eclipse.ui.internal.part.DelegatingServiceFactory; 18 import org.eclipse.ui.internal.part.IWorkbenchScopeConstants; 19 20 23 public class Multiplexer { 24 private MultiplexerChild activePart; 25 private IServiceProvider sharedComponents; 26 private ServiceFactory context; 27 private DelegatingServiceFactory delegatingContext; 28 29 public Multiplexer(IServiceProvider sharedComponents) { 30 this(sharedComponents, IWorkbenchScopeConstants.SITE_MULTIPLEXER_SCOPE, IWorkbenchScopeConstants.PART_DELEGATOR_SCOPE, 31 IWorkbenchScopeConstants.SITE_SCOPE); 32 } 33 34 public Multiplexer(IServiceProvider sharedComponents, String inputScope, String outputScope, String parentScope) { 35 this.sharedComponents = sharedComponents; 36 this.context = ComponentUtil.getContext(inputScope); 37 this.delegatingContext = new DelegatingServiceFactory(ComponentUtil.getContext(outputScope)); 38 39 ServiceFactory parentContext = ComponentUtil.getContext(parentScope); 41 Assert.isTrue(sharedComponents.hasService(parentContext)); 42 } 43 44 50 public NestedContext createNested() { 51 return new NestedContext(sharedComponents, context); 52 } 53 54 public void setActive(MultiplexerChild newActive) { 55 if (activePart != null) { 56 activePart.getContext().deactivate(newActive == null ? null : newActive.getContext()); 57 } 58 59 this.activePart = newActive; 60 61 if (activePart != null) { 62 activePart.getContext().activate(newActive.getPart()); 63 delegatingContext.setActive(activePart.getPart()); 64 } else { 65 delegatingContext.setActive(null); 66 } 67 68 69 } 70 71 77 public ServiceFactory getDelegatingContext() { 78 return delegatingContext; 79 } 80 81 } 82 | Popular Tags |