1 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 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 67 public String getContentDescription() { 68 IWorkbenchPart part = getPart(); 69 if (part instanceof IWorkbenchPart2) { 70 IWorkbenchPart2 wbp2 = (IWorkbenchPart2)part; 71 72 return wbp2.getContentDescription(); 73 } 74 75 return ""; } 77 78 81 public IEditorInput getEditorInput() { 82 IEditorPart part = (IEditorPart)getPart(); 83 return part.getEditorInput(); 84 } 85 86 89 public String getPartName() { 90 IWorkbenchPart part = getPart(); 91 if (part instanceof IWorkbenchPart2) { 92 IWorkbenchPart2 wbp2 = (IWorkbenchPart2)part; 93 94 return wbp2.getPartName(); 95 } 96 97 return ""; } 99 100 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 |