KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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.swt.widgets.Composite;
14 import org.eclipse.ui.IWorkbenchPage;
15 import org.eclipse.ui.internal.components.ComponentUtil;
16 import org.eclipse.ui.internal.components.framework.ComponentException;
17 import org.eclipse.ui.internal.components.framework.Container;
18 import org.eclipse.ui.internal.components.framework.FactoryMap;
19 import org.eclipse.ui.internal.components.framework.IDisposable;
20 import org.eclipse.ui.internal.components.framework.IServiceProvider;
21 import org.eclipse.ui.internal.components.framework.ServiceFactory;
22 import org.eclipse.ui.internal.part.IWorkbenchScopeConstants;
23 import org.osgi.framework.Bundle;
24
25 /**
26  * Provides all the standard services available from a part's site.
27  *
28  * @since 3.1
29  */

30 public class SiteServices implements IServiceProvider, IDisposable {
31
32     private ServiceFactory args;
33     private Container container;
34     
35     private static FactoryMap createContext(ServiceFactory args) {
36         return new FactoryMap()
37                 .add(args)
38                 .add(ComponentUtil.getContext(IWorkbenchScopeConstants.SITE_SCOPE))
39                 .add(ComponentUtil.getContext(IWorkbenchScopeConstants.PLUGIN_SCOPE));
40     }
41     
42     /**
43      * Creates services with the given set of overrides
44      *
45      * @param args
46      */

47     public SiteServices(ServiceFactory args) {
48         container = new Container(createContext(args));
49     }
50     
51     /**
52      * Creates services with the given set of overrides.
53      *
54      * @param composite main control for the part
55      * @param pluginBundle the part's plugin bundle
56      * @param page workbench page
57      * @param args overrides
58      */

59     public SiteServices(Composite composite, Bundle pluginBundle, IWorkbenchPage page, ServiceFactory args) {
60         container = new Container(createContext(args)
61                 .mapInstance(Composite.class, composite)
62                 .mapInstance(Bundle.class, pluginBundle)
63                 .mapInstance(IWorkbenchPage.class, page));
64     }
65     
66     /* (non-Javadoc)
67      * @see org.eclipse.core.components.IComponentProvider#getComponent(java.lang.Object)
68      */

69     public Object JavaDoc getService(Object JavaDoc key) throws ComponentException {
70         return container.getService(key);
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.core.components.IComponentProvider#hasKey(java.lang.Object)
75      */

76     public boolean hasService(Object JavaDoc key) {
77         return container.hasService(key);
78     }
79     
80     /* (non-Javadoc)
81      * @see org.eclipse.core.components.IDisposable#dispose()
82      */

83     public void dispose() {
84         container.dispose();
85     }
86
87 }
88
Popular Tags