KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > presentations > BrowserIntroPartImplementation


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.intro.impl.presentations;
12
13 import java.io.PrintWriter JavaDoc;
14 import java.io.StringWriter JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.Properties JavaDoc;
17
18 import org.eclipse.core.runtime.IRegistryChangeEvent;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.jface.action.IToolBarManager;
21 import org.eclipse.jface.action.Separator;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.browser.Browser;
24 import org.eclipse.swt.browser.LocationAdapter;
25 import org.eclipse.swt.browser.LocationEvent;
26 import org.eclipse.swt.browser.ProgressEvent;
27 import org.eclipse.swt.browser.ProgressListener;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Event;
30 import org.eclipse.swt.widgets.Listener;
31 import org.eclipse.ui.IActionBars;
32 import org.eclipse.ui.IMemento;
33 import org.eclipse.ui.IPropertyListener;
34 import org.eclipse.ui.actions.ActionFactory;
35 import org.eclipse.ui.internal.intro.impl.IIntroConstants;
36 import org.eclipse.ui.internal.intro.impl.IntroPlugin;
37 import org.eclipse.ui.internal.intro.impl.Messages;
38 import org.eclipse.ui.internal.intro.impl.html.HTMLElement;
39 import org.eclipse.ui.internal.intro.impl.html.IIntroHTMLConstants;
40 import org.eclipse.ui.internal.intro.impl.html.IntroHTMLGenerator;
41 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
42 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPartImplementation;
43 import org.eclipse.ui.internal.intro.impl.model.History;
44 import org.eclipse.ui.internal.intro.impl.model.IntroContentProvider;
45 import org.eclipse.ui.internal.intro.impl.model.IntroHomePage;
46 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
47 import org.eclipse.ui.internal.intro.impl.model.loader.ContentProviderManager;
48 import org.eclipse.ui.internal.intro.impl.model.loader.IntroContentParser;
49 import org.eclipse.ui.internal.intro.impl.model.util.ModelUtil;
50 import org.eclipse.ui.internal.intro.impl.util.Log;
51 import org.eclipse.ui.internal.intro.impl.util.Util;
52 import org.eclipse.ui.intro.config.IIntroContentProvider;
53 import org.eclipse.ui.intro.config.IIntroContentProviderSite;
54 import org.eclipse.ui.intro.config.IIntroXHTMLContentProvider;
55 import org.eclipse.ui.intro.config.IntroConfigurer;
56 import org.w3c.dom.Document JavaDoc;
57 import org.w3c.dom.Element JavaDoc;
58 import org.w3c.dom.Node JavaDoc;
59 import org.w3c.dom.NodeList JavaDoc;
60
61 public class BrowserIntroPartImplementation extends
62         AbstractIntroPartImplementation implements IPropertyListener,
63         IIntroContentProviderSite {
64  
65
66     // the browser widget that will display the intro content
67
protected Browser browser = null;
68
69     // the HTML generator used to generate dynamic content
70
private IntroHTMLGenerator htmlGenerator = null;
71
72     protected BrowserIntroPartLocationListener urlListener = new BrowserIntroPartLocationListener(
73         this);
74
75     // internal performance test hook
76
private boolean isFinishedLoading;
77
78     protected void updateNavigationActionsState() {
79         if (getModel().isDynamic()) {
80             forwardAction.setEnabled(history.canNavigateForward());
81             backAction.setEnabled(history.canNavigateBackward());
82             return;
83         }
84
85         // in static html intro, use browser history.
86
forwardAction.setEnabled(browser.isForwardEnabled());
87         backAction.setEnabled(browser.isBackEnabled());
88     }
89
90
91     /**
92      * create the browser and set it's contents
93      */

94     public void createPartControl(Composite parent) {
95         long start = 0;
96         if (Log.logPerformance)
97             start = System.currentTimeMillis();
98
99         browser = new Browser(parent, SWT.NONE);
100
101         // add a location listener on the browser so we can intercept
102
// LocationEvents. Responsible for intercepting URLs and updating UI
103
// with history.
104
browser.addLocationListener(urlListener);
105
106         // add a location listener that will clear a flag at the end of any
107
// navigation to a page. This is used in conjunction with the location
108
// listener to filter out redundant navigations due to frames.
109
browser.addProgressListener(new ProgressListener() {
110
111             public void changed(ProgressEvent event) {
112                 // no-op
113
}
114
115             public void completed(ProgressEvent event) {
116                 urlListener.flagEndOfNavigation();
117                 urlListener.flagEndOfFrameNavigation();
118                 urlListener.flagRemovedTempUrl();
119                 if (!getModel().isDynamic())
120                     updateNavigationActionsState();
121             }
122         });
123
124         // Enable IE pop-up menu only in debug mode.
125
browser.addListener(SWT.MenuDetect, new Listener() {
126
127             public void handleEvent(Event event) {
128                 if (IntroPlugin.getDefault().isDebugging())
129                     event.doit = true;
130                 else
131                     event.doit = false;
132             }
133         });
134
135         // if we are logging performance, log actual UI creation time for
136
// browser.
137
if (Log.logPerformance)
138             Util.logPerformanceTime("creating a new Browser() took:", start); //$NON-NLS-1$
139

140         addToolBarActions();
141
142         if (!getModel().hasValidConfig()) {
143             browser.setText(Messages.Browser_invalidConfig);
144             return;
145         }
146         
147          // root page is what decides if the model is dynamic or not.
148
if (getModel().isDynamic())
149             handleDynamicIntro();
150         else
151             handleStaticIntro();
152     }
153
154
155
156     private void handleDynamicIntro() {
157         IntroHomePage homePage = getModel().getHomePage();
158         // check cache state, and populate url page if needed.
159
String JavaDoc cachedPage = getCachedCurrentPage();
160         if (cachedPage != null) {
161             // we have a cached state. handle appropriately
162
if (History.isURL(cachedPage)) {
163                 // set the URL the browser should display
164
boolean success = browser.setUrl(cachedPage);
165                 if (!success) {
166                     Log.error("Unable to set the following ULR in browser: " //$NON-NLS-1$
167
+ cachedPage, null);
168                     return;
169                 }
170                 history.updateHistory(cachedPage);
171             } else {
172                 // Generate HTML for the cached page, and set it on the browser.
173
getModel().setCurrentPageId(cachedPage, false);
174                 // generateDynamicContentForPage(getModel().getCurrentPage());
175
history.updateHistory(getModel().getCurrentPage());
176             }
177
178         } else {
179             // No cached page. Generate HTML for the home page, and set it
180
// on the browser.
181
// generateDynamicContentForPage(homePage);
182
history.updateHistory(homePage);
183         }
184         // INTRO: all setText calls above are commented out because calling
185
// setText twice causes problems. revisit when swt bug is fixed.
186

187         // Add this presentation as a listener to model
188
// only in dynamic case, for now.
189
getModel().addPropertyListener(this);
190     }
191
192
193     /**
194      * Generate dynamic HTML for the provided page, and set it in the browser
195      * widget. A cache is used for performance and for having a correct dynamic
196      * content life cycle. This method also updates the navigation history.
197      *
198      * @param page
199      * the page to generate HTML for
200      */

201     private boolean generateDynamicContentForPage(AbstractIntroPage page) {
202         String JavaDoc content = null;
203
204         if (page.isXHTMLPage())
205             content = generateXHTMLPage(page, this);
206         else {
207             HTMLElement html = getHTMLGenerator().generateHTMLforPage(page,
208                 this);
209             if (html != null) {
210                 IntroModelRoot root = getModel();
211                 if (root!=null) {
212                     Map JavaDoc props = root.getTheme()!=null?root.getTheme().getProperties():null;
213                     if (props!=null) {
214                         String JavaDoc value = (String JavaDoc)props.get("standardSupport"); //$NON-NLS-1$
215
String JavaDoc doctype=null;
216                         if ("strict".equalsIgnoreCase(value)) //$NON-NLS-1$
217
doctype = generateDoctype(true);
218                         else if ("loose".equalsIgnoreCase(value)) //$NON-NLS-1$
219
doctype = generateDoctype(false);
220                         if (doctype!=null)
221                             content = doctype+html.toString();
222                     }
223                 }
224                 if (content==null)
225                     content = html.toString();
226             }
227         }
228
229
230         if (content == null) {
231             // there was an error generating the html. log an error
232
Log.error("Error generating HTML content for page", null); //$NON-NLS-1$
233
return false;
234         }
235
236         // set the browser's HTML.
237
boolean success = false;
238         if (browser != null) {
239             long start = 0;
240             if (Log.logPerformance)
241                 start = System.currentTimeMillis();
242             browser.addLocationListener(new LocationAdapter() {
243                 public void changed(LocationEvent event) {
244                     if (event.top) {
245                         isFinishedLoading = true;
246                     }
247                 }
248             });
249             success = browser.setText(content);
250             if (Log.logPerformance)
251                 Util
252                     .logPerformanceTime("setText() on the browser took:", start); //$NON-NLS-1$
253

254             if (!success)
255                 Log.error("Unable to set HTML on the browser", null); //$NON-NLS-1$
256
}
257
258
259         // print the HTML if we are in debug mode and have tracing turned on
260
if (IntroPlugin.getDefault().isDebugging()) {
261             String JavaDoc printHtml = Platform
262                 .getDebugOption("org.eclipse.ui.intro/trace/printHTML"); //$NON-NLS-1$
263
if (printHtml != null && printHtml.equalsIgnoreCase("true")) { //$NON-NLS-1$
264
System.out.println(content);
265             }
266         }
267         return success;
268     }
269
270     /**
271      * Generate an XHTML page as a string.
272      * <ul>
273      * <li> Create any dynamic content providers, if there are any. We do this
274      * by replacing each content provider with a div with the same id. The div
275      * is the parent of the dynamic content.</li>
276      * <li>Use xslt to flatten the DOM for the page, and create a string.</li>
277      * <li>Re-inject the contentProviders into the DOM to recreate the original
278      * state of the DOM. DOM could not have been cloned since cloning a DOM
279      * removes the docType.</li>
280      * </ul>
281      * Note: Resolving dynamic content is done at the UI level, consistant with
282      * SWT presentation.
283      */

284     public String JavaDoc generateXHTMLPage(AbstractIntroPage page,
285             IIntroContentProviderSite site) {
286         // get/cache all content provider elements in DOM.
287
Document JavaDoc dom = page.getResolvedDocument();
288         NodeList JavaDoc nodes = dom.getElementsByTagNameNS("*", //$NON-NLS-1$
289
IntroContentProvider.TAG_CONTENT_PROVIDER);
290         // get the array version of the nodelist to work around DOM api design.
291
Node JavaDoc[] contentProviderElements = ModelUtil.getArray(nodes);
292
293         // this modifies the DOM.
294
resolveDynamicContent(page, site);
295         String JavaDoc content = IntroContentParser.convertToString(dom);
296
297         // this restores the DOM to its original state.
298
reinjectDynamicContent(dom, contentProviderElements);
299         return content;
300     }
301     
302     private String JavaDoc generateDoctype(boolean strict) {
303         StringWriter JavaDoc swriter = new StringWriter JavaDoc();
304         PrintWriter JavaDoc writer = new PrintWriter JavaDoc(swriter);
305         if (strict) {
306             writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""); //$NON-NLS-1$
307
writer.println("\t\t\t\"http://www.w3.org/TR/html4/strict.dtd\">"); //$NON-NLS-1$
308
}
309         else {
310             writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""); //$NON-NLS-1$
311
writer.println("\t\t\t\"http://www.w3.org/TR/html4/loose.dtd\">"); //$NON-NLS-1$
312
}
313         writer.close();
314         return swriter.toString();
315     }
316
317     /**
318      * Resolve the dynamic content in the page. Resolving dynamic content will
319      * alter the original page DOM. Dynamic content tags are removed once
320      * resolved to have clean xhtml.
321      */

322     private Document JavaDoc resolveDynamicContent(AbstractIntroPage page,
323             IIntroContentProviderSite site) {
324         Document JavaDoc dom = page.getResolvedDocument();
325
326         // get all content provider elements in DOM.
327
NodeList JavaDoc contentProviders = dom.getElementsByTagNameNS("*", //$NON-NLS-1$
328
IntroContentProvider.TAG_CONTENT_PROVIDER);
329
330         // get the array version of the nodelist to work around DOM api design.
331
Node JavaDoc[] nodes = ModelUtil.getArray(contentProviders);
332         for (int i = 0; i < nodes.length; i++) {
333             Element contentProviderElement = (Element) nodes[i];
334             IntroContentProvider provider = new IntroContentProvider(
335                 contentProviderElement, page.getBundle());
336             provider.setParent(page);
337             // If we've already loaded the content provider for this element,
338
// retrieve it, otherwise load the class.
339
IIntroXHTMLContentProvider providerClass = (IIntroXHTMLContentProvider) ContentProviderManager
340                 .getInst().getContentProvider(provider);
341             if (providerClass == null)
342                 // content provider never created before, create it.
343
providerClass = (IIntroXHTMLContentProvider) ContentProviderManager
344                     .getInst().createContentProvider(provider, site);
345
346             if (providerClass != null) {
347                 // create a div with the same id as the contentProvider, pass it
348
// as the parent to create the specialized content, and then
349
// replace the contentProvider element with this div.
350
Properties JavaDoc att = new Properties JavaDoc();
351                 att.setProperty(IIntroHTMLConstants.ATTRIBUTE_ID, provider
352                     .getId());
353                 Element contentDiv = ModelUtil.createElement(dom,
354                     ModelUtil.TAG_DIV, att);
355                 providerClass.createContent(provider.getId(), contentDiv);
356
357                 contentProviderElement.getParentNode().replaceChild(contentDiv,
358                     contentProviderElement);
359             } else {
360                 // we couldn't load the content provider, so add any alternate
361
// text content if there is any.
362
// INTRO: do it. 3.0 intro content style uses text element as
363
// alt text. We can load XHTML content here.
364
}
365         }
366         return dom;
367     }
368
369
370     private void reinjectDynamicContent(Document JavaDoc dom,
371             Node JavaDoc[] contentProviderElements) {
372         for (int i = 0; i < contentProviderElements.length; i++) {
373             // for each cached contentProvider, find replacement div in DOM and
374
// re-subsitute.
375
Element contentProviderElement = (Element) contentProviderElements[i];
376             Element contentProviderDiv = ModelUtil.getElementById(dom,
377                 contentProviderElement
378                     .getAttribute(IIntroHTMLConstants.ATTRIBUTE_ID),
379                 ModelUtil.TAG_DIV);
380             contentProviderDiv.getParentNode().replaceChild(
381                 contentProviderElement, contentProviderDiv);
382         }
383     }
384
385
386
387     /**
388      * Return the cached IntroHTMLGenerator
389      *
390      * @return
391      */

392     private IntroHTMLGenerator getHTMLGenerator() {
393         if (htmlGenerator == null)
394             htmlGenerator = new IntroHTMLGenerator();
395
396         return htmlGenerator;
397     }
398
399     protected void addToolBarActions() {
400         // Handle menus:
401
IActionBars actionBars = getIntroPart().getIntroSite().getActionBars();
402         IToolBarManager toolBarManager = actionBars.getToolBarManager();
403         actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(),
404             forwardAction);
405         actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(),
406             backAction);
407         toolBarManager.add(new Separator(IntroConfigurer.TB_ADDITIONS));
408         toolBarManager.add(homeAction);
409         toolBarManager.add(backAction);
410         toolBarManager.add(forwardAction);
411         toolBarManager.update(true);
412         actionBars.updateActionBars();
413         updateNavigationActionsState();
414     }
415
416     public void dynamicStandbyStateChanged(boolean standby,
417             boolean isStandbyPartNeeded) {
418
419         if (isStandbyPartNeeded)
420             // we have a standby part, nothing more to do in presentation.
421
return;
422
423         if (history.currentLocationIsUrl())
424             // last page disaplyed was a url. It is already set in the browser
425
// and stored in history. Nothing more to do.
426
return;
427
428
429
430         // presentation is shown here. toggle standby page. No need to update
431
// history here.
432
IntroHomePage homePage = getModel().getHomePage();
433         IntroHomePage standbyPage = getModel().getStandbyPage();
434         if (standbyPage == null)
435             standbyPage = homePage;
436
437         if (standby) {
438             generateDynamicContentForPage(standbyPage);
439         } else {
440             // REVISIT: If cached page is the standby page and we are not
441
// initially in standby mode, it means standby was forced on
442
// intro view on close. react.
443
if (getModel().getCurrentPage().equals(standbyPage.getId()))
444                 getModel().setCurrentPageId(getModel().getHomePage().getId());
445             generateDynamicContentForPage(getModel().getCurrentPage());
446         }
447     }
448
449
450
451     /**
452      * Handle model property changes. Property listeners are only added in the
453      * dynamic case.
454      *
455      * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object,
456      * int)
457      */

458     public void propertyChanged(Object JavaDoc source, int propId) {
459         if (propId == IntroModelRoot.CURRENT_PAGE_PROPERTY_ID) {
460             String JavaDoc pageId = getModel().getCurrentPageId();
461             if (pageId == null || pageId.equals("")) //$NON-NLS-1$
462
// page ID was not set properly. exit.
463
return;
464             // update the presentation's content based on the model changes
465
updateContent();
466         }
467     }
468
469     public void setFocus() {
470         browser.setFocus();
471     }
472
473     public void dispose() {
474         browser.dispose();
475     }
476
477     /**
478      * Regenerate the dynamic content for the current page
479      */

480     protected void updateContent() {
481         generateDynamicContentForPage(getModel().getCurrentPage());
482     }
483
484     /**
485      *
486      * @see org.eclipse.ui.internal.intro.impl.model.AbstractIntroPartImplementation#reflow()
487      */

488     public void reflow(IIntroContentProvider provider, boolean incremental) {
489         updateContent();
490     }
491
492     /**
493      * Override parent behavior to handle the case when we have a static page.
494      * This can happen in both the static intro case, or in the dynamic when the
495      * last visited page is the dynamic browser is an http: page, and not an
496      * intro page.
497      */

498     protected void saveCurrentPage(IMemento memento) {
499         if (memento == null)
500             return;
501         // Handle the case where we are on a static page.
502
// browser.getURL() returns the empty string if there is no current URL
503
// and returns "about:blank" if we are on a dynamic page
504
if (browser != null && browser.getUrl() != null
505                 && browser.getUrl().length() > 0
506                 && !(browser.getUrl().equals("about:blank")) //$NON-NLS-1$
507
&& !(browser.getUrl().equals("file:///"))) { //$NON-NLS-1$
508

509             String JavaDoc currentURL = browser.getUrl();
510             if (currentURL != null) {
511                 memento.putString(IIntroConstants.MEMENTO_CURRENT_PAGE_ATT,
512                     currentURL);
513             }
514         } else {
515             super.saveCurrentPage(memento);
516         }
517     }
518
519
520     /*
521      * (non-Javadoc)
522      *
523      * @see org.eclipse.ui.internal.intro.impl.model.AbstractIntroPartImplementation#navigateBackward()
524      */

525     public boolean navigateBackward() {
526         boolean success = false;
527         if (getModel().isDynamic()) {
528             // dynamic case. Uses navigation history.
529
if (history.canNavigateBackward()) {
530                 history.navigateHistoryBackward();
531                 // guard against unnecessary History updates.
532
urlListener.flagStartOfNavigation();
533                 if (history.currentLocationIsUrl()) {
534                     success = browser.setUrl(history.getCurrentLocationAsUrl());
535                 } else {
536                     // we need to regen HTML. We can not use setting current
537
// page to trigger regen for one case: navigating back from
538
// a url will not trigger regen since current page would be
539
// the same.
540
AbstractIntroPage page = history.getCurrentLocationAsPage();
541                     getModel().setCurrentPageId(page.getId(), false);
542                     success = generateDynamicContentForPage(page);
543                 }
544             } else
545                 success = false;
546             // update history only in dynamic case.
547
updateNavigationActionsState();
548         } else
549             // static HTML case. use browser real Back.
550
success = browser.back();
551
552         return success;
553     }
554
555
556     /*
557      * (non-Javadoc)
558      *
559      * @see org.eclipse.ui.internal.intro.impl.model.AbstractIntroPartImplementation#navigateForward()
560      */

561     public boolean navigateForward() {
562         boolean success = false;
563         if (getModel().isDynamic()) {
564             // dynamic case. Uses navigation history.
565
if (history.canNavigateForward()) {
566                 history.navigateHistoryForward();
567                 // guard against unnecessary History updates.
568
urlListener.flagStartOfNavigation();
569                 if (history.currentLocationIsUrl()) {
570                     success = browser.setUrl(history.getCurrentLocationAsUrl());
571                 } else {
572                     AbstractIntroPage page = history.getCurrentLocationAsPage();
573                     getModel().setCurrentPageId(page.getId(), false);
574                     success = generateDynamicContentForPage(page);
575                 }
576             } else
577                 success = false;
578             // update history only in dynamic case.
579
updateNavigationActionsState();
580         } else
581             // static HTML case. use browser real Forward.
582
success = browser.forward();
583
584         return success;
585     }
586
587     /*
588      * (non-Javadoc)
589      *
590      * @see org.eclipse.ui.internal.intro.impl.model.AbstractIntroPartImplementation#navigateHome()
591      */

592     public boolean navigateHome() {
593         // Home is URL of root page in static case, and root page in
594
// dynamic.
595
IntroHomePage rootPage = getModel().getHomePage();
596         boolean success = false;
597         if (getModel().isDynamic()) {
598             // special case for when workbench is started with a cached URL. We
599
// set the url in the browser, but current page is Home Page, and so
600
// setting the root page will not fire an event. So, force a
601
// generation
602
// of root page.
603
if (history.currentLocationIsUrl())
604                 generateDynamicContentForPage(rootPage);
605
606             success = getModel().setCurrentPageId(rootPage.getId());
607             updateHistory(rootPage);
608
609         } else {
610             String JavaDoc location = rootPage.getUrl();
611             success = browser.setUrl(location);
612             updateHistory(location);
613         }
614
615         return success;
616     }
617
618
619
620     /*
621      * (non-Javadoc)
622      *
623      * @see org.eclipse.ui.internal.intro.impl.model.AbstractIntroPartImplementation#handleRegistryChanged(org.eclipse.core.runtime.IRegistryChangeEvent)
624      */

625     protected void handleRegistryChanged(IRegistryChangeEvent event) {
626         if (getModel().isDynamic()) {
627             // null generator first.
628
htmlGenerator = null;
629             // Add this presentation as a listener to model only in dynamic
630
// case.
631
getModel().addPropertyListener(this);
632             getModel().firePropertyChange(
633                 IntroModelRoot.CURRENT_PAGE_PROPERTY_ID);
634         }
635     }
636
637
638     protected void doStandbyStateChanged(boolean standby,
639             boolean isStandbyPartNeeded) {
640         // if we have a standby part, regardless if standby state, disable
641
// actions. Same behavior for static html.
642
if (isStandbyPartNeeded | standby) {
643             homeAction.setEnabled(false);
644             forwardAction.setEnabled(false);
645             backAction.setEnabled(false);
646         } else {
647             homeAction.setEnabled(true);
648             updateNavigationActionsState();
649         }
650
651         if (getModel().isDynamic())
652             dynamicStandbyStateChanged(standby, isStandbyPartNeeded);
653         else
654             staticStandbyStateChanged(standby);
655     }
656
657
658
659     // ***************** Static Intro *****************
660
private void handleStaticIntro() {
661         // We have a static case. Set the url on the browser to be the url
662
// defined in the root page. But first check memento if we can
663
// restore last visited page.
664
String JavaDoc url = getCachedCurrentPage();
665         if (!History.isURL(url))
666             // no cached state, or invalid state.
667
url = getModel().getHomePage().getUrl();
668
669         if (url == null) {
670             // We have no content to display. log an error
671
Log.error("Url is null; no content to display in browser", null); //$NON-NLS-1$
672
return;
673         }
674         // set the URL the browser should display
675
boolean success = browser.setUrl(url);
676         if (!success) {
677             Log.error("Unable to set the following ULR in browser: " + url, //$NON-NLS-1$
678
null);
679             return;
680         }
681     }
682
683     public void staticStandbyStateChanged(boolean standby) {
684         IntroHomePage homePage = getModel().getHomePage();
685         IntroHomePage standbyPage = getModel().getStandbyPage();
686         if (standbyPage == null)
687             standbyPage = homePage;
688
689         if (standby)
690             browser.setUrl(standbyPage.getUrl());
691         else
692             browser.setUrl(homePage.getUrl());
693     }
694
695
696     public Browser getBrowser() {
697         return browser;
698     }
699
700     /*
701      * Internal performance test hook.
702      */

703     public boolean isFinishedLoading() {
704         return isFinishedLoading;
705     }
706 }
707
Popular Tags