1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.swt.custom.BusyIndicator; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.ui.IMemento; 21 import org.eclipse.ui.IPropertyListener; 22 import org.eclipse.ui.IViewSite; 23 import org.eclipse.ui.IWorkbenchPartSite; 24 import org.eclipse.ui.PartInitException; 25 import org.eclipse.ui.internal.intro.IntroMessages; 26 import org.eclipse.ui.intro.IIntroPart; 27 import org.eclipse.ui.intro.IIntroSite; 28 import org.eclipse.ui.part.ViewPart; 29 30 35 public final class ViewIntroAdapterPart extends ViewPart { 36 37 private IIntroPart introPart; 38 39 private IIntroSite introSite; 40 41 private boolean handleZoomEvents = true; 42 43 46 private void addPaneListener() { 47 IWorkbenchPartSite site = getSite(); 48 if (site instanceof PartSite) { 49 final WorkbenchPartReference ref = ((WorkbenchPartReference)((PartSite) site).getPartReference()); 50 ref.addInternalPropertyListener( 51 new IPropertyListener() { 52 public void propertyChanged(Object source, int propId) { 53 if (handleZoomEvents) { 54 if (propId == WorkbenchPartReference.INTERNAL_PROPERTY_ZOOMED) { 55 setStandby(!ref.getPane().isZoomed()); 56 } 57 } 58 } 59 }); 60 } 61 } 62 63 68 public void setStandby(final boolean standby) { 69 final Control control = ((PartSite) getSite()).getPane().getControl(); 70 BusyIndicator.showWhile(control.getDisplay(), new Runnable () { 71 public void run() { 72 try { 73 control.setRedraw(false); 74 introPart.standbyStateChanged(standby); 75 } finally { 76 control.setRedraw(true); 77 } 78 79 setBarVisibility(standby); 80 } 81 }); 82 } 83 84 89 public void setHandleZoomEvents(boolean handle) { 90 handleZoomEvents = handle; 91 } 92 93 96 public void createPartControl(Composite parent) { 97 addPaneListener(); 98 introPart.createPartControl(parent); 99 } 100 101 104 public void dispose() { 105 setBarVisibility(true); 106 super.dispose(); 107 getSite().getWorkbenchWindow().getWorkbench().getIntroManager() 108 .closeIntro(introPart); 109 introPart.dispose(); 110 } 111 112 115 public Object getAdapter(Class adapter) { 116 return introPart.getAdapter(adapter); 117 } 118 119 122 public Image getTitleImage() { 123 return introPart.getTitleImage(); 124 } 125 126 129 public String getTitle() { 130 return introPart == null ? super.getTitle() : introPart.getTitle(); 135 } 136 137 140 public void init(IViewSite site, IMemento memento) throws PartInitException { 141 super.init(site); 142 Workbench workbench = (Workbench) site.getWorkbenchWindow() 143 .getWorkbench(); 144 try { 145 introPart = workbench.getWorkbenchIntroManager() 146 .createNewIntroPart(); 147 setPartName(introPart.getTitle()); 149 introPart.addPropertyListener(new IPropertyListener() { 150 public void propertyChanged(Object source, int propId) { 151 firePropertyChange(propId); 152 } 153 }); 154 introSite = new ViewIntroAdapterSite(site, workbench 155 .getIntroDescriptor()); 156 introPart.init(introSite, memento); 157 158 } catch (CoreException e) { 159 WorkbenchPlugin 160 .log( 161 IntroMessages.Intro_could_not_create_proxy, new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, IntroMessages.Intro_could_not_create_proxy, e)); 162 } 163 } 164 165 170 public void setFocus() { 171 introPart.setFocus(); 172 } 173 174 177 public void saveState(IMemento memento) { 178 introPart.saveState(memento); 179 } 180 181 187 private void setBarVisibility(final boolean visible) { 188 WorkbenchWindow window = (WorkbenchWindow) getSite() 189 .getWorkbenchWindow(); 190 191 final boolean layout = (visible != window.getCoolBarVisible()) 192 || (visible != window.getPerspectiveBarVisible()); if (visible) { 194 window.setCoolBarVisible(true); 195 window.setPerspectiveBarVisible(true); 196 } else { 197 window.setCoolBarVisible(false); 198 window.setPerspectiveBarVisible(false); 199 } 200 201 if (layout) { 202 window.getShell().layout(); 203 } 204 } 205 } 206 | Popular Tags |