KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > part > multiplexer > Multiplexer


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
21  * @since 3.1
22  */

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 JavaDoc inputScope, String JavaDoc outputScope, String JavaDoc parentScope) {
35         this.sharedComponents = sharedComponents;
36         this.context = ComponentUtil.getContext(inputScope);
37         this.delegatingContext = new DelegatingServiceFactory(ComponentUtil.getContext(outputScope));
38         
39         // Check to make sure the shared components provider is in the correct scope
40
ServiceFactory parentContext = ComponentUtil.getContext(parentScope);
41         Assert.isTrue(sharedComponents.hasService(parentContext));
42     }
43     
44     /**
45      * Returns a nested context for a child of this multiplexer. Each child should have its
46      * own NestedContext instance.
47      *
48      * @return a new NestedContext for use with this multiplexer
49      */

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     /**
72      * Returns a context that delegates the implementation of every interface
73      * to the active part.
74      *
75      * @return
76      */

77     public ServiceFactory getDelegatingContext() {
78         return delegatingContext;
79     }
80     
81 }
82
Popular Tags