KickJava   Java API By Example, From Geeks To Geeks.

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


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.IProgressMonitor;
14 import org.eclipse.ui.IActionBars;
15 import org.eclipse.ui.IEditorInput;
16 import org.eclipse.ui.IEditorPart;
17 import org.eclipse.ui.IEditorSite;
18 import org.eclipse.ui.IMemento;
19 import org.eclipse.ui.IViewPart;
20 import org.eclipse.ui.IViewSite;
21 import org.eclipse.ui.IWorkbenchPartSite;
22 import org.eclipse.ui.PartInitException;
23 import org.eclipse.ui.internal.components.framework.ComponentException;
24 import org.eclipse.ui.internal.part.services.NullActionBars;
25 import org.eclipse.ui.internal.part.services.PartToViewActionBarsAdapter;
26
27 /**
28  * Can be used to convert an existing Part into an IEditorPart or IViewPart. The lifecycle
29  * is managed by the original Part, so all of the lifecycle methods on this class do nothing.
30  *
31  * @since 3.1
32  */

33 public class NewPartToOldAdapter extends NewPartToWorkbenchPartAdapter implements IViewPart, IEditorPart {
34
35     private CompatibilityPartSite site;
36     
37     /**
38      * @param services
39      * @param propertyProvider
40      * @param isView determines whether we want this to behave like an IViewPart or an IEditorPart (their
41      * IActionBars behave differently)
42      * @throws ComponentException
43      */

44     public NewPartToOldAdapter(
45             StandardWorkbenchServices services,
46             IPartPropertyProvider propertyProvider,
47             boolean isView) throws ComponentException {
48         super(propertyProvider);
49         
50         IActionBars actionBars;
51         
52         if (isView) {
53             actionBars = new PartToViewActionBarsAdapter(services.getActionBars(),
54                     services.getStatusHandler(), services.getStatusFactory());
55         } else {
56             actionBars = new NullActionBars();
57         }
58         
59         this.site = new CompatibilityPartSite(
60                 services, this, null, actionBars);
61     }
62     
63     /* (non-Javadoc)
64      * @see org.eclipse.ui.IWorkbenchPart#getSite()
65      */

66     public IWorkbenchPartSite getSite() {
67         return site;
68     }
69
70     /* (non-Javadoc)
71      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
72      */

73     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
74         if (adapter == IViewPart.class || adapter == IEditorPart.class) {
75             return this;
76         }
77         
78         return site.getAdapter(adapter);
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.ui.IViewPart#getViewSite()
83      */

84     public IViewSite getViewSite() {
85         return site;
86     }
87
88     /* (non-Javadoc)
89      * @see org.eclipse.ui.IViewPart#init(org.eclipse.ui.IViewSite)
90      */

91     public void init(IViewSite site) throws PartInitException {
92         // Lifecycle methods won't be called -- this object adapts an existing Part
93
}
94
95     /* (non-Javadoc)
96      * @see org.eclipse.ui.IViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
97      */

98     public void init(IViewSite site, IMemento memento) throws PartInitException {
99         // Lifecycle methods won't be called -- this object adapts an existing Part
100
}
101
102     /* (non-Javadoc)
103      * @see org.eclipse.ui.IViewPart#saveState(org.eclipse.ui.IMemento)
104      */

105     public void saveState(IMemento memento) {
106         // Lifecycle methods won't be called -- this object adapts an existing Part
107
}
108
109     /* (non-Javadoc)
110      * @see org.eclipse.ui.IEditorPart#getEditorSite()
111      */

112     public IEditorSite getEditorSite() {
113         return site;
114     }
115
116     /* (non-Javadoc)
117      * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
118      */

119     public void init(IEditorSite site, IEditorInput input) throws PartInitException {
120         // Lifecycle methods won't be called -- this object adapts an existing Part
121
}
122
123     /* (non-Javadoc)
124      * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
125      */

126     public void doSave(IProgressMonitor monitor) {
127         
128     }
129
130     /* (non-Javadoc)
131      * @see org.eclipse.ui.ISaveablePart#doSaveAs()
132      */

133     public void doSaveAs() {
134         
135     }
136
137     /* (non-Javadoc)
138      * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
139      */

140     public boolean isSaveAsAllowed() {
141         return false;
142     }
143
144     /* (non-Javadoc)
145      * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
146      */

147     public boolean isSaveOnCloseNeeded() {
148         return false;
149     }
150
151 }
152
Popular Tags