KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > part > ViewWrapper


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;
12
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.ui.IViewPart;
15 import org.eclipse.ui.IWorkbenchPage;
16 import org.eclipse.ui.internal.components.framework.ComponentException;
17 import org.eclipse.ui.internal.components.framework.Components;
18 import org.eclipse.ui.internal.components.framework.IServiceProvider;
19 import org.eclipse.ui.internal.components.framework.ServiceFactory;
20 import org.osgi.framework.Bundle;
21
22 /**
23  * Wraps a given Part in a form that can be converted into an IViewPart.
24  *
25  * @since 3.1
26  */

27 public class ViewWrapper extends PartWrapper {
28     private IViewPart part;
29     
30     /**
31      *
32      */

33     public ViewWrapper(Composite parentControl, Bundle bundle, IWorkbenchPage page, PartGenerator gen, ServiceFactory context) throws ComponentException {
34         super(parentControl, bundle, page, gen, context);
35
36         try {
37             part = (IViewPart)getWrappedPart().getService(IViewPart.class);
38             if (part == null) {
39                 IServiceProvider container = getContainer();
40                 StandardWorkbenchServices services = new StandardWorkbenchServices(container);
41                 IPartPropertyProvider provider = (IPartPropertyProvider)Components.queryInterface( getWrappedPart(), IPartPropertyProvider.class);
42                 part = new NewPartToOldAdapter(services, provider, true);
43             }
44         } catch (ComponentException e) {
45             getWrappedPart().getControl().dispose();
46             throw e;
47         }
48     }
49     
50     public IViewPart getViewPart() {
51         return part;
52     }
53 }
54
Popular Tags