1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IExtension; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Status; 17 import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler; 18 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; 19 import org.eclipse.ui.IPerspectiveDescriptor; 20 import org.eclipse.ui.IViewPart; 21 import org.eclipse.ui.IViewReference; 22 import org.eclipse.ui.IWorkbenchPage; 23 import org.eclipse.ui.IWorkbenchWindow; 24 import org.eclipse.ui.PartInitException; 25 import org.eclipse.ui.internal.intro.IIntroConstants; 26 import org.eclipse.ui.internal.intro.IntroDescriptor; 27 import org.eclipse.ui.internal.intro.IntroMessages; 28 import org.eclipse.ui.intro.IIntroManager; 29 import org.eclipse.ui.intro.IIntroPart; 30 import org.eclipse.ui.intro.IntroContentDetector; 31 32 37 public class WorkbenchIntroManager implements IIntroManager { 38 39 private final Workbench workbench; 40 41 46 WorkbenchIntroManager(Workbench workbench) { 47 this.workbench = workbench; 48 workbench.getExtensionTracker().registerHandler(new IExtensionChangeHandler(){ 49 50 53 public void addExtension(IExtensionTracker tracker,IExtension extension) { 54 } 56 57 60 public void removeExtension(IExtension source, Object [] objects) { 61 for (int i = 0; i < objects.length; i++) { 62 if (objects[i] instanceof IIntroPart) { 63 closeIntro((IIntroPart) objects[i]); 64 } 65 } 66 67 }}, null); 68 69 } 70 71 74 private IIntroPart introPart; 75 76 79 public boolean closeIntro(IIntroPart part) { 80 if (introPart == null || !introPart.equals(part)) { 81 return false; 82 } 83 84 IViewPart introView = getViewIntroAdapterPart(); 85 if (introView != null) { 86 IWorkbenchPage page = introView.getSite().getPage(); 89 IViewReference reference = page 90 .findViewReference(IIntroConstants.INTRO_VIEW_ID); 91 page.hideView(introView); 92 if (reference == null || reference.getPart(false) == null) { 93 introPart = null; 94 return true; 95 } 96 return false; 97 } 98 99 introPart = null; 101 102 return true; 103 } 104 105 108 public IIntroPart showIntro(IWorkbenchWindow preferredWindow, 109 boolean standby) { 110 if (preferredWindow == null) { 111 preferredWindow = this.workbench.getActiveWorkbenchWindow(); 112 } 113 114 if (preferredWindow == null) { 115 return null; 116 } 117 118 ViewIntroAdapterPart viewPart = getViewIntroAdapterPart(); 119 if (viewPart == null) { 120 createIntro(preferredWindow); 121 } else { 122 try { 123 IWorkbenchPage page = viewPart.getSite().getPage(); 124 IWorkbenchWindow window = page.getWorkbenchWindow(); 125 if (!window.equals(preferredWindow)) { 126 window.getShell().setActive(); 127 } 128 129 page.showView(IIntroConstants.INTRO_VIEW_ID); 130 } catch (PartInitException e) { 131 WorkbenchPlugin 132 .log( 133 "Could not open intro", new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, "Could not open intro", e)); } 135 } 136 setIntroStandby(introPart, standby); 137 return introPart; 138 } 139 140 144 boolean isIntroInWindow(IWorkbenchWindow testWindow) { 145 ViewIntroAdapterPart viewPart = getViewIntroAdapterPart(); 146 if (viewPart == null) { 147 return false; 148 } 149 150 IWorkbenchWindow window = viewPart.getSite().getWorkbenchWindow(); 151 if (window.equals(testWindow)) { 152 return true; 153 } 154 return false; 155 } 156 157 163 private void createIntro(IWorkbenchWindow preferredWindow) { 164 if (this.workbench.getIntroDescriptor() == null) { 165 return; 166 } 167 168 IWorkbenchPage workbenchPage = preferredWindow.getActivePage(); 169 if (workbenchPage == null) { 170 return; 171 } 172 try { 173 workbenchPage.showView(IIntroConstants.INTRO_VIEW_ID); 174 } catch (PartInitException e) { 175 WorkbenchPlugin 176 .log( 177 IntroMessages.Intro_could_not_create_part, new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, IntroMessages.Intro_could_not_create_part, e)); 178 } 179 } 180 181 184 public void setIntroStandby(IIntroPart part, boolean standby) { 185 if (introPart == null || !introPart.equals(part)) { 186 return; 187 } 188 189 ViewIntroAdapterPart viewIntroAdapterPart = getViewIntroAdapterPart(); 190 if (viewIntroAdapterPart == null) { 191 return; 192 } 193 194 PartPane pane = ((PartSite) viewIntroAdapterPart.getSite()).getPane(); 195 if (standby == !pane.isZoomed()) { 196 viewIntroAdapterPart.setStandby(standby); 198 return; 199 } 200 201 viewIntroAdapterPart.getSite().getPage().toggleZoom( 202 pane.getPartReference()); 203 } 204 205 210 public boolean isIntroStandby(IIntroPart part) { 211 if (introPart == null || !introPart.equals(part)) { 212 return false; 213 } 214 215 ViewIntroAdapterPart viewIntroAdapterPart = getViewIntroAdapterPart(); 216 if (viewIntroAdapterPart == null) { 217 return false; 218 } 219 220 return !((PartSite) viewIntroAdapterPart.getSite()).getPane() 221 .isZoomed(); 222 } 223 224 227 public IIntroPart getIntro() { 228 return introPart; 229 } 230 231 235 ViewIntroAdapterPart getViewIntroAdapterPart() { 236 IWorkbenchWindow[] windows = this.workbench.getWorkbenchWindows(); 237 for (int i = 0; i < windows.length; i++) { 238 IWorkbenchWindow window = windows[i]; 239 WorkbenchPage page = (WorkbenchPage) window.getActivePage(); 240 if (page == null) { 241 continue; 242 } 243 IPerspectiveDescriptor[] perspDescs = page.getOpenPerspectives(); 244 for (int j = 0; j < perspDescs.length; j++) { 245 IPerspectiveDescriptor descriptor = perspDescs[j]; 246 IViewReference reference = page.findPerspective(descriptor) 247 .findView(IIntroConstants.INTRO_VIEW_ID); 248 if (reference != null) { 249 IViewPart part = reference.getView(false); 250 if (part != null && part instanceof ViewIntroAdapterPart) { 251 return (ViewIntroAdapterPart) part; 252 } 253 } 254 } 255 } 256 return null; 257 } 258 259 263 IIntroPart createNewIntroPart() throws CoreException { 264 IntroDescriptor introDescriptor = workbench.getIntroDescriptor(); 265 introPart = introDescriptor == null ? null 266 : introDescriptor.createIntro(); 267 if (introPart != null) { 268 workbench.getExtensionTracker().registerObject( 269 introDescriptor.getConfigurationElement() 270 .getDeclaringExtension(), introPart, 271 IExtensionTracker.REF_WEAK); 272 } 273 return introPart; 274 } 275 276 279 public boolean hasIntro() { 280 return workbench.getIntroDescriptor() != null; 281 } 282 283 public boolean isNewContentAvailable() { 284 IntroDescriptor introDescriptor = workbench.getIntroDescriptor(); 285 if (introDescriptor == null) { 286 return false; 287 } 288 try { 289 IntroContentDetector contentDetector = introDescriptor 290 .getIntroContentDetector(); 291 if (contentDetector != null) { 292 return contentDetector.isNewContentAvailable(); 293 } 294 } catch (CoreException ex) { 295 WorkbenchPlugin.log(new Status(IStatus.WARNING, 296 WorkbenchPlugin.PI_WORKBENCH, IStatus.WARNING, 297 "Could not load intro content detector", ex)); } 299 return false; 300 } 301 } 302 | Popular Tags |