1 11 package org.eclipse.ui.internal.intro.impl.presentations; 12 13 import org.eclipse.core.runtime.IRegistryChangeEvent; 14 import org.eclipse.jface.action.IToolBarManager; 15 import org.eclipse.jface.action.Separator; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.graphics.Color; 18 import org.eclipse.swt.graphics.Image; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.layout.GridLayout; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.ui.IActionBars; 23 import org.eclipse.ui.IPropertyListener; 24 import org.eclipse.ui.actions.ActionFactory; 25 import org.eclipse.ui.forms.HyperlinkSettings; 26 import org.eclipse.ui.forms.events.HyperlinkAdapter; 27 import org.eclipse.ui.forms.events.HyperlinkEvent; 28 import org.eclipse.ui.forms.widgets.Form; 29 import org.eclipse.ui.forms.widgets.FormToolkit; 30 import org.eclipse.ui.forms.widgets.Hyperlink; 31 import org.eclipse.ui.forms.widgets.ScrolledPageBook; 32 import org.eclipse.ui.internal.intro.impl.IntroPlugin; 33 import org.eclipse.ui.internal.intro.impl.Messages; 34 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage; 35 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPartImplementation; 36 import org.eclipse.ui.internal.intro.impl.model.History; 37 import org.eclipse.ui.internal.intro.impl.model.IntroHomePage; 38 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot; 39 import org.eclipse.ui.internal.intro.impl.model.loader.ContentProviderManager; 40 import org.eclipse.ui.internal.intro.impl.swt.PageForm; 41 import org.eclipse.ui.internal.intro.impl.swt.PageFormWithNavigation; 42 import org.eclipse.ui.internal.intro.impl.swt.PageStyleManager; 43 import org.eclipse.ui.internal.intro.impl.swt.RootPageForm; 44 import org.eclipse.ui.internal.intro.impl.swt.SharedStyleManager; 45 import org.eclipse.ui.internal.intro.impl.util.ImageUtil; 46 import org.eclipse.ui.internal.intro.impl.util.Util; 47 import org.eclipse.ui.intro.config.CustomizableIntroPart; 48 import org.eclipse.ui.intro.config.IIntroContentProvider; 49 import org.eclipse.ui.intro.config.IIntroContentProviderSite; 50 import org.eclipse.ui.intro.config.IntroConfigurer; 51 52 55 public class FormIntroPartImplementation extends 56 AbstractIntroPartImplementation implements IIntroContentProviderSite, 57 IPropertyListener { 58 59 private FormToolkit toolkit; 60 private ScrolledPageBook mainPageBook; 61 private PageForm pageForm; 62 private PageFormWithNavigation pageFormWithNav; 63 private IntroModelRoot model = getModel(); 65 private SharedStyleManager sharedStyleManager; 66 67 private Hyperlink welcomeLink; 70 71 static { 72 ImageUtil.registerImage(ImageUtil.DEFAULT_ROOT_LINK, "overview_48.gif"); ImageUtil.registerImage(ImageUtil.DEFAULT_SMALL_ROOT_LINK, 77 "overview_32.gif"); ImageUtil.registerImage(ImageUtil.DEFAULT_FORM_BG, "form_banner.gif"); ImageUtil.registerImage(ImageUtil.DEFAULT_LINK, "welcome_item.gif"); } 81 82 83 protected void updateNavigationActionsState() { 84 if (getModel().isDynamic()) { 85 forwardAction.setEnabled(history.canNavigateForward()); 86 backAction.setEnabled(history.canNavigateBackward()); 87 return; 88 } 89 } 91 92 93 public FormIntroPartImplementation() { 94 sharedStyleManager = new SharedStyleManager(getModel()); 96 } 97 98 public void createPartControl(Composite container) { 99 if (getModel().isDynamic()) 100 dynamicCreatePartControl(container); 101 else { 102 staticCreatePartControl(container); 103 } 104 } 105 106 107 108 111 private void dynamicCreatePartControl(Composite container) { 112 toolkit = new FormToolkit(container.getDisplay()); 115 Color bg = sharedStyleManager.getColor(toolkit, "bg"); if (bg != null) { 118 toolkit.setBackground(bg); 119 } 120 toolkit.getHyperlinkGroup().setHyperlinkUnderlineMode( 121 HyperlinkSettings.UNDERLINE_HOVER); 122 123 Form mainForm = toolkit.createForm(container); 125 Color fg = sharedStyleManager.getColor(toolkit, "title.fg"); if (fg != null) 127 mainForm.setForeground(fg); 128 Image bgImage = sharedStyleManager.getImage("title.image", null, null); if (bgImage != null) { 130 mainForm.setBackgroundImage(bgImage); 131 String repeat = sharedStyleManager 132 .getProperty("title.image.repeat"); if (repeat != null && repeat.equalsIgnoreCase("true")) 135 mainForm.setBackgroundImageTiled(true); 136 } 137 138 mainPageBook = createMainPageBook(toolkit, mainForm); 139 getModel().addPropertyListener(this); 141 142 addToolBarActions(); 143 } 144 145 146 156 private ScrolledPageBook createMainPageBook(FormToolkit toolkit, Form form) { 157 Composite body = form.getBody(); 159 body.setLayout(new GridLayout()); 160 ScrolledPageBook pageBook = toolkit.createPageBook(body, SWT.V_SCROLL 162 | SWT.H_SCROLL); 163 pageBook.setLayoutData(new GridData(GridData.FILL_BOTH)); 164 165 if (sharedStyleManager.useCustomHomePagelayout()) { 167 RootPageForm rootPageForm = new RootPageForm(toolkit, model, form); 169 rootPageForm.createPartControl(pageBook, sharedStyleManager); 170 rootPageForm.setContentProviderSite(this); 171 } 172 173 pageForm = new PageForm(toolkit, model, form); 175 pageForm.setContentProviderSite(this); 176 pageForm.createPartControl(pageBook, sharedStyleManager); 177 178 pageFormWithNav = new PageFormWithNavigation(toolkit, model, form); 179 pageFormWithNav.setContentProviderSite(this); 180 pageFormWithNav.createPartControl(pageBook, sharedStyleManager); 181 182 String cachedPage = getCachedCurrentPage(); 186 if (cachedPage != null & !History.isURL(cachedPage)) 187 model.setCurrentPageId(cachedPage); 189 190 AbstractIntroPage pageToShow = getModel().getCurrentPage(); 191 PageStyleManager styleManager = new PageStyleManager(pageToShow, 193 sharedStyleManager.getProperties()); 194 boolean pageHasNavigation = styleManager.showHomePageNavigation(); 195 if (pageToShow != null) { 196 if (pageBook.hasPage(pageToShow.getId())) 197 pageBook.showPage(pageToShow.getId()); 199 else { 200 if (pageHasNavigation) { 201 pageFormWithNav.showPage(pageToShow, sharedStyleManager); 205 pageBook 207 .showPage(PageFormWithNavigation.PAGE_FORM_WITH_NAVIGATION_ID); 208 } else { 209 pageForm.showPage(pageToShow, sharedStyleManager); 213 pageBook.showPage(PageForm.PAGE_FORM_ID); 215 } 216 } 217 updateHistory(pageToShow); 218 } 219 220 return pageBook; 221 } 222 223 public void dispose() { 224 if (toolkit != null) 225 toolkit.dispose(); 226 } 227 228 236 public void propertyChanged(Object source, int propId) { 237 if (propId == IntroModelRoot.CURRENT_PAGE_PROPERTY_ID) { 238 String pageId = getModel().getCurrentPageId(); 239 if (pageId == null || pageId.equals("")) return; 242 243 showPage(getModel().getCurrentPage()); 244 } 245 } 246 247 protected void addToolBarActions() { 248 IActionBars actionBars = getIntroPart().getIntroSite().getActionBars(); 250 IToolBarManager toolBarManager = actionBars.getToolBarManager(); 251 actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(), 252 forwardAction); 253 actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(), 254 backAction); 255 toolBarManager.add(new Separator(IntroConfigurer.TB_ADDITIONS)); 256 toolBarManager.add(homeAction); 257 toolBarManager.add(backAction); 258 toolBarManager.add(forwardAction); 259 toolBarManager.update(true); 260 actionBars.updateActionBars(); 261 updateNavigationActionsState(); 262 } 263 264 265 266 protected void doStandbyStateChanged(boolean standby, 267 boolean isStandbyPartNeeded) { 268 if (getModel().isDynamic()) 269 dynamicStandbyStateChanged(standby, isStandbyPartNeeded); 270 else 271 staticStandbyStateChanged(standby); 272 } 273 274 275 public void dynamicStandbyStateChanged(boolean standby, 276 boolean isStandbyPartNeeded) { 277 if (isStandbyPartNeeded | standby) { 279 homeAction.setEnabled(false); 280 forwardAction.setEnabled(false); 281 backAction.setEnabled(false); 282 } else { 283 homeAction.setEnabled(true); 284 updateNavigationActionsState(); 285 } 286 287 if (isStandbyPartNeeded) 288 return; 290 291 AbstractIntroPage pageToShow = null; 293 if (standby) { 294 pageToShow = getModel().getStandbyPage(); 296 if (pageToShow == null) 297 pageToShow = getModel().getHomePage(); 298 } else 299 pageToShow = getModel().getCurrentPage(); 303 304 showPage(pageToShow); 305 } 306 307 private boolean showPage(AbstractIntroPage pageToShow) { 308 boolean pageisCached = showCachedPage(pageToShow); 309 310 if (!pageisCached) { 311 PageStyleManager styleManager = new PageStyleManager(pageToShow, 314 sharedStyleManager.getProperties()); 315 boolean pageHasNavigation = styleManager.showHomePageNavigation(); 316 if (pageHasNavigation) { 317 pageFormWithNav.showPage(pageToShow, sharedStyleManager); 321 mainPageBook 323 .showPage(PageFormWithNavigation.PAGE_FORM_WITH_NAVIGATION_ID); 324 } else { 325 pageForm.showPage(pageToShow, sharedStyleManager); 329 mainPageBook.showPage(PageForm.PAGE_FORM_ID); 331 } 332 } 333 334 return true; 335 } 336 337 private boolean showCachedPage(AbstractIntroPage page) { 338 String formPageId = null; 339 if (pageForm.hasPage(page.getId())) { 340 pageForm.showPage(page, sharedStyleManager); 341 formPageId = PageForm.PAGE_FORM_ID; 342 } else if (pageFormWithNav.hasPage(page.getId())) { 343 pageFormWithNav.showPage(page, sharedStyleManager); 344 formPageId = PageFormWithNavigation.PAGE_FORM_WITH_NAVIGATION_ID; 345 } else if (mainPageBook.hasPage(page.getId())) 346 formPageId = page.getId(); 347 else 348 return false; 349 350 mainPageBook.showPage(formPageId); 351 return true; 352 } 353 354 private void removeCachedPage(AbstractIntroPage page) { 355 if (pageForm.hasPage(page.getId())) 356 pageForm.removePage(page.getId()); 357 else if (pageFormWithNav.hasPage(page.getId())) 358 pageFormWithNav.removePage(page.getId()); 359 else if (mainPageBook.hasPage(page.getId())) 360 mainPageBook.removePage(page.getId()); 361 else 362 return; 363 } 364 365 366 375 public void reflow(IIntroContentProvider provider, boolean incremental) { 376 AbstractIntroPage page = ContentProviderManager.getInst() 377 .getContentProviderParentPage(provider); 378 if (incremental) { 379 if (pageForm.hasPage(page.getId())) 380 pageForm.reflow(); 381 else if (pageFormWithNav.hasPage(page.getId())) 382 pageFormWithNav.reflow(); 383 else if (mainPageBook.hasPage(page.getId())) 384 mainPageBook.reflow(true); 385 } 386 else { 387 removeCachedPage(page); 388 showPage(model.getCurrentPage()); 389 } 390 } 391 392 public void setFocus() { 393 if (model.isDynamic()) { 394 if (mainPageBook.getCurrentPage() != null) 395 mainPageBook.getCurrentPage().setFocus(); 396 } 397 } 398 399 400 405 public boolean navigateBackward() { 406 boolean success = false; 407 if (getModel().isDynamic()) { 408 if (history.canNavigateBackward()) { 410 history.navigateHistoryBackward(); 411 if (history.currentLocationIsUrl()) 412 success = Util.openBrowser(history 413 .getCurrentLocationAsUrl()); 414 else { 415 CustomizableIntroPart currentIntroPart = (CustomizableIntroPart) IntroPlugin 417 .getIntro(); 418 currentIntroPart.getControl().setRedraw(false); 419 success = getModel().setCurrentPageId( 420 history.getCurrentLocationAsPage().getId()); 421 currentIntroPart.getControl().setRedraw(true); 422 } 423 } 424 } 425 426 updateNavigationActionsState(); 427 return success; 428 } 429 430 431 436 public boolean navigateForward() { 437 boolean success = false; 438 439 if (getModel().isDynamic()) { 440 if (history.canNavigateForward()) { 442 history.navigateHistoryForward(); 443 if (history.currentLocationIsUrl()) 444 success = Util.openBrowser(history 445 .getCurrentLocationAsUrl()); 446 else { 447 CustomizableIntroPart currentIntroPart = (CustomizableIntroPart) IntroPlugin 449 .getIntro(); 450 currentIntroPart.getControl().setRedraw(false); 451 success = getModel().setCurrentPageId( 452 history.getCurrentLocationAsPage().getId()); 453 currentIntroPart.getControl().setRedraw(true); 454 } 455 } 456 } 457 updateNavigationActionsState(); 458 return success; 459 } 460 461 public boolean navigateHome() { 462 IntroHomePage rootPage = getModel().getHomePage(); 463 if (getModel().isDynamic()) { 464 CustomizableIntroPart currentIntroPart = (CustomizableIntroPart) IntroPlugin 465 .getIntro(); 466 currentIntroPart.getControl().setRedraw(false); 467 boolean success = false; 468 success = getModel().setCurrentPageId(rootPage.getId()); 469 updateHistory(rootPage); 470 currentIntroPart.getControl().setRedraw(true); 471 return success; 472 } 473 return false; 475 } 476 477 478 483 protected void handleRegistryChanged(IRegistryChangeEvent event) { 484 if (getModel().isDynamic()) { 485 IntroPlugin.closeIntro(); 486 IntroPlugin.showIntro(false); 487 } 488 } 489 490 491 492 497 private void staticCreatePartControl(Composite parent) { 498 toolkit = new FormToolkit(parent.getDisplay()); 499 toolkit.getHyperlinkGroup().setHyperlinkUnderlineMode( 500 HyperlinkSettings.UNDERLINE_HOVER); 501 502 welcomeLink = createStaticPage(parent); 505 } 506 507 508 private Hyperlink createStaticPage(Composite parent) { 509 Form mainForm = toolkit.createForm(parent); 510 Composite body = mainForm.getBody(); 511 512 GridLayout gl = new GridLayout(); 513 body.setLayout(gl); 514 String label = Messages.StaticHTML_welcome; 515 Hyperlink link = toolkit.createHyperlink(body, label, SWT.WRAP); 516 link.setFont(PageStyleManager.getHeaderFont()); 517 GridData gd = new GridData(GridData.GRAB_HORIZONTAL 518 | GridData.GRAB_VERTICAL); 519 gd.horizontalAlignment = GridData.CENTER; 520 gd.verticalAlignment = GridData.CENTER; 521 link.setLayoutData(gd); 522 link.addHyperlinkListener(new HyperlinkAdapter() { 523 524 public void linkActivated(HyperlinkEvent e) { 525 Hyperlink link = (Hyperlink) e.getSource(); 526 Util.openBrowser((String ) link.getHref()); 527 return; 528 } 529 }); 530 531 return link; 532 } 533 534 public void staticStandbyStateChanged(boolean standby) { 535 IntroHomePage homePage = getModel().getHomePage(); 536 IntroHomePage standbyPage = getModel().getStandbyPage(); 537 if (standbyPage == null) 538 standbyPage = homePage; 539 540 if (standby) { 541 welcomeLink.setHref(standbyPage.getUrl()); 542 welcomeLink.setToolTipText(standbyPage.getUrl()); 543 } else { 544 welcomeLink.setHref(homePage.getUrl()); 545 welcomeLink.setToolTipText(homePage.getUrl()); 546 } 547 } 548 549 550 } | Popular Tags |