KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.runtime.IAdaptable;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.jface.action.IStatusLineManager;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.ui.IActionBars;
18 import org.eclipse.ui.IEditorInput;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IEditorSite;
21 import org.eclipse.ui.IMemento;
22 import org.eclipse.ui.PartInitException;
23 import org.eclipse.ui.internal.components.framework.ComponentException;
24 import org.eclipse.ui.internal.components.framework.FactoryMap;
25 import org.eclipse.ui.internal.components.framework.ServiceFactory;
26 import org.eclipse.ui.internal.part.components.services.IPartActionBars;
27 import org.eclipse.ui.internal.part.components.services.IPartDescriptor;
28 import org.eclipse.ui.internal.part.components.services.IWorkbenchPartFactory;
29 import org.eclipse.ui.internal.part.services.NullEditorInput;
30 import org.eclipse.ui.internal.part.services.NullPartActionBars;
31
32 /**
33  * Wraps a new-style Part in an IEditorPart. The wrapper creates and manages
34  * the lifecycle of the Part. If you are interested in adapting an existing
35  * part, use <code>NewPartToOldAdapter</code> instead.
36  *
37  * @since 3.1
38  */

39 public class NewEditorToOldWrapper extends NewPartToOldWrapper implements
40         IEditorPart {
41
42     private IAdaptable additionalServices = new IAdaptable() {
43         /* (non-Javadoc)
44          * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
45          */

46         public Object JavaDoc getAdapter(Class JavaDoc adapter) {
47             if (adapter == IEditorInput.class) {
48                 return getPropertyProvider().getEditorInput();
49             }
50             if (adapter == IActionBars.class) {
51                 return getEditorSite().getActionBars();
52             }
53             return null;
54         }
55     };
56
57     public NewEditorToOldWrapper(IPartDescriptor descriptor) {
58         super(new PartPropertyProvider(null, null, null, descriptor, new NullEditorInput()));
59     }
60     
61     /* (non-Javadoc)
62      * @see org.eclipse.ui.internal.part.compatibility.NewPartToOldAdapter#getMemento()
63      */

64     protected IMemento getMemento() {
65         return null;
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.ui.internal.part.compatibility.NewPartToOldAdapter#createPart(org.eclipse.swt.widgets.Composite, org.eclipse.core.component.IContainerContext)
70      */

71     protected Part createPart(Composite parent, ServiceFactory args) throws ComponentException {
72         IWorkbenchPartFactory factory = getFactory();
73         return factory.createEditor(getSite().getId(), parent, getPropertyProvider().getEditorInput(),
74                 getMemento(), args);
75     }
76
77     /* (non-Javadoc)
78      * @see org.eclipse.ui.internal.part.compatibility.NewPartToOldAdapter#getSecondaryId()
79      */

80     protected String JavaDoc getSecondaryId() {
81         return null;
82     }
83
84     /* (non-Javadoc)
85      * @see org.eclipse.ui.IEditorPart#getEditorSite()
86      */

87     public IEditorSite getEditorSite() {
88         return (IEditorSite)getSite();
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.addInstance(additionalServices);
98     }
99     
100     /* (non-Javadoc)
101      * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
102      */

103     public void init(IEditorSite site, IEditorInput input)
104             throws PartInitException {
105
106         ((PartPropertyProvider)getPropertyProvider()).setEditorInput(input);
107         setSite(site);
108     }
109
110     /* (non-Javadoc)
111      * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
112      */

113     public void doSave(IProgressMonitor monitor) {
114
115     }
116
117     /* (non-Javadoc)
118      * @see org.eclipse.ui.ISaveablePart#doSaveAs()
119      */

120     public void doSaveAs() {
121
122     }
123
124     /* (non-Javadoc)
125      * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
126      */

127     public boolean isSaveAsAllowed() {
128         return false;
129     }
130
131     /* (non-Javadoc)
132      * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
133      */

134     public boolean isSaveOnCloseNeeded() {
135         return false;
136     }
137
138     protected IPartActionBars createPartActionBars() {
139         return new NullPartActionBars();
140     }
141     
142     protected IStatusLineManager getStatusLineManager() {
143         return getEditorSite().getActionBars().getStatusLineManager();
144     }
145 }
146
Popular Tags