KickJava   Java API By Example, From Geeks To Geeks.

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


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.CoreException;
14 import org.eclipse.ui.IActionBars;
15 import org.eclipse.ui.IEditorActionBarContributor;
16 import org.eclipse.ui.IEditorInput;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.IWorkbenchPart;
19 import org.eclipse.ui.IWorkbenchPart2;
20 import org.eclipse.ui.PartInitException;
21 import org.eclipse.ui.internal.components.framework.ComponentException;
22 import org.eclipse.ui.internal.components.framework.Components;
23 import org.eclipse.ui.internal.part.components.services.IActionBarContributor;
24 import org.eclipse.ui.internal.part.services.NullActionBars;
25
26 /**
27  * @since 3.1
28  */

29 public class OldEditorToNewWrapper extends OldPartToNewWrapper {
30     private CompatibilityPartSite site;
31     
32     private IEditorPart part;
33     
34     private IActionBarContributor actionBarContributor;
35     
36     public OldEditorToNewWrapper(IEditorPart part, StandardWorkbenchServices services) throws CoreException, ComponentException {
37         super(services);
38         
39         this.part = part;
40         actionBarContributor = services.getActionBarContributorFactory().getContributor(services.getDescriptor());
41         
42         IActionBars actionBars = (IActionBars)Components.getAdapter(actionBarContributor, IActionBars.class);
43         
44         if (actionBars == null) {
45             actionBars = new NullActionBars();
46         }
47         
48         site = new CompatibilityPartSite(
49                 services, part,
50                 (IEditorActionBarContributor)Components.getAdapter(actionBarContributor, IEditorActionBarContributor.class),
51                 actionBars);
52                 
53         try {
54             part.init(site, services.getEditorInput());
55         } catch (PartInitException e) {
56             throw new ComponentException(part.getClass(), e);
57         }
58
59         part.createPartControl(services.getParentComposite());
60         
61         setPart(part);
62     }
63     
64     /* (non-Javadoc)
65      * @see org.eclipse.ui.internal.part.IPartPropertyProvider#getContentDescription()
66      */

67     public String JavaDoc getContentDescription() {
68         IWorkbenchPart part = getPart();
69         if (part instanceof IWorkbenchPart2) {
70             IWorkbenchPart2 wbp2 = (IWorkbenchPart2)part;
71             
72             return wbp2.getContentDescription();
73         }
74         
75         return ""; //$NON-NLS-1$
76
}
77     
78     /* (non-Javadoc)
79      * @see org.eclipse.ui.internal.part.IPartPropertyProvider#getEditorInput()
80      */

81     public IEditorInput getEditorInput() {
82         IEditorPart part = (IEditorPart)getPart();
83         return part.getEditorInput();
84     }
85     
86     /* (non-Javadoc)
87      * @see org.eclipse.ui.internal.part.IPartPropertyProvider#getPartName()
88      */

89     public String JavaDoc getPartName() {
90         IWorkbenchPart part = getPart();
91         if (part instanceof IWorkbenchPart2) {
92             IWorkbenchPart2 wbp2 = (IWorkbenchPart2)part;
93             
94             return wbp2.getPartName();
95         }
96         
97         return ""; //$NON-NLS-1$
98
}
99     
100     /* (non-Javadoc)
101      * @see org.eclipse.ui.internal.part.IPartPropertyProvider#isDirty()
102      */

103     public boolean isDirty() {
104         IEditorPart part = (IEditorPart)getPart();
105         return part.isDirty();
106     }
107     
108     public void dispose() {
109         super.dispose();
110         
111         actionBarContributor.dispose();
112     }
113 }
114
Popular Tags