KickJava   Java API By Example, From Geeks To Geeks.

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


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.jface.action.IStatusLineManager;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.ui.IActionBars;
16 import org.eclipse.ui.IMemento;
17 import org.eclipse.ui.IViewPart;
18 import org.eclipse.ui.IViewSite;
19 import org.eclipse.ui.internal.components.framework.ComponentException;
20 import org.eclipse.ui.internal.components.framework.FactoryMap;
21 import org.eclipse.ui.internal.components.framework.ServiceFactory;
22 import org.eclipse.ui.internal.part.components.services.IPartActionBars;
23 import org.eclipse.ui.internal.part.components.services.IPartDescriptor;
24 import org.eclipse.ui.internal.part.components.services.IWorkbenchPartFactory;
25 import org.eclipse.ui.internal.part.services.NullEditorInput;
26 import org.eclipse.ui.internal.part.services.ViewToPartActionBarsAdapter;
27
28 /**
29  * This class is used to wrap a new-style view inside something that implements
30  * the IViewPart interface. This is used by ViewDescriptor when the old-style
31  * API is used to create a view, but the view being referenced uses constructor
32  * injection for initialization.
33  * <p>
34  * The real part is only created when createPartControl is invoked.
35  * </p>
36  *
37  * @since 3.1
38  */

39 public class NewViewToOldWrapper extends NewPartToOldWrapper implements IViewPart {
40     
41     private IMemento viewMemento = null;
42     
43     /**
44      *
45      */

46     public NewViewToOldWrapper(IPartDescriptor descriptor) {
47         super(new PartPropertyProvider(null, null, null, descriptor, new NullEditorInput()));
48     }
49     
50     /* (non-Javadoc)
51      * @see org.eclipse.ui.IViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
52      */

53     public void init(IViewSite site, IMemento memento) {
54         init(site);
55         viewMemento = memento;
56     }
57     
58     /* (non-Javadoc)
59      * @see org.eclipse.ui.IViewPart#init(org.eclipse.ui.IViewSite)
60      */

61     public void init(IViewSite site) {
62         setSite(site);
63     }
64
65     public IViewSite getViewSite() {
66         return (IViewSite)getSite();
67     }
68     
69     protected Part createPart(Composite parent, ServiceFactory args) throws ComponentException {
70         IWorkbenchPartFactory factory = getFactory();
71         String JavaDoc id = getSite().getId();
72         
73         Part result = factory.createView(id, parent, getMemento(), args);
74         
75         return result;
76     }
77     
78     public void createPartControl(Composite parent) {
79         super.createPartControl(parent);
80         viewMemento = null;
81     }
82     
83     protected IMemento getMemento() {
84         return viewMemento;
85     }
86     
87     protected String JavaDoc getSecondaryId() {
88         return getViewSite().getSecondaryId();
89     }
90     
91     /* (non-Javadoc)
92      * @see org.eclipse.ui.internal.part.compatibility.NewPartToOldAdapter#addServices(org.eclipse.core.component.ContainerContext)
93      */

94     protected void addServices(FactoryMap context) {
95         super.addServices(context);
96         
97         context.mapInstance(IActionBars.class, getViewSite().getActionBars());
98     }
99     
100     /* (non-Javadoc)
101      * @see org.eclipse.ui.IViewPart#saveState(org.eclipse.ui.IMemento)
102      */

103     public void saveState(IMemento memento) {
104         Part part = getPart();
105         if (part != null) {
106             part.saveState(memento);
107         }
108     }
109     
110     protected IPartActionBars createPartActionBars() {
111         return new ViewToPartActionBarsAdapter(getViewSite().getActionBars());
112     }
113     
114     protected IStatusLineManager getStatusLineManager() {
115         return getViewSite().getActionBars().getStatusLineManager();
116     }
117 }
118
Popular Tags