1 11 package org.eclipse.ui.internal.part; 12 13 import org.eclipse.swt.events.DisposeEvent; 14 import org.eclipse.swt.events.DisposeListener; 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Control; 17 import org.eclipse.ui.IMemento; 18 import org.eclipse.ui.IWorkbenchPage; 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.IServiceProvider; 22 import org.eclipse.ui.internal.components.framework.ServiceFactory; 23 import org.eclipse.ui.internal.part.multiplexer.SiteServices; 24 import org.osgi.framework.Bundle; 25 26 38 public abstract class PartWrapper extends Part { 39 40 private Part wrappedPart; 41 private SiteServices container; 42 43 public PartWrapper(Composite parentControl, Bundle bundle, IWorkbenchPage page, PartGenerator gen, ServiceFactory context) throws ComponentException { 44 45 container = new SiteServices(parentControl, bundle, page, context); 46 IPartPropertyProvider provider; 47 48 try { 49 provider = (IPartPropertyProvider)container.getService(IPartPropertyProvider.class); 50 51 FactoryMap childContext = new FactoryMap() 52 .addInstance(provider) 53 .add(container); 54 55 wrappedPart = gen.createPart(parentControl, childContext); 56 wrappedPart.getControl().addDisposeListener(new DisposeListener() { 57 public void widgetDisposed(DisposeEvent e) { 58 disposed(); 59 } 60 }); 61 62 } catch (ComponentException e1) { 63 container.dispose(); 64 throw e1; 65 } 66 } 67 68 protected Part getWrappedPart() { 69 return wrappedPart; 70 } 71 72 protected IServiceProvider getContainer() { 73 return container; 74 } 75 76 79 public Control getControl() { 80 return wrappedPart.getControl(); 81 } 82 83 86 public void saveState(IMemento memento) { 87 wrappedPart.saveState(memento); 88 } 89 90 private void disposed() { 91 container.dispose(); 92 } 93 94 97 public Object getService(Object key) throws ComponentException { 98 return wrappedPart.getService(key); 99 } 100 101 104 public boolean hasService(Object key) { 105 return wrappedPart.hasService(key); 106 } 107 } 108 | Popular Tags |