KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > model > url > ShowHelpURLHandler


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
12
13 package org.eclipse.ui.internal.intro.impl.model.url;
14
15 import org.eclipse.ui.PlatformUI;
16 import org.eclipse.ui.internal.intro.impl.IntroPlugin;
17 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroElement;
18 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
19 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
20 import org.eclipse.ui.internal.intro.impl.model.IntroPartPresentation;
21 import org.eclipse.ui.internal.intro.impl.presentations.BrowserIntroPartImplementation;
22 import org.eclipse.ui.internal.intro.impl.util.Log;
23
24 public class ShowHelpURLHandler {
25     private IntroURL introURL = null;
26
27     ShowHelpURLHandler(IntroURL url) {
28         this.introURL = url;
29     }
30
31
32
33     public boolean showHelpTopic(String JavaDoc href, String JavaDoc embed, String JavaDoc embedTarget) {
34         if (href == null)
35             return false;
36
37         boolean isEmbedded = (embed != null && embed
38             .equals(IntroURL.VALUE_TRUE)) ? true : false;
39         if (isEmbedded == false)
40             // still false, check the embedTarget. If embedTarget is set, then
41
// we
42
// have embedded by default.
43
isEmbedded = (embedTarget != null) ? true : false;
44
45         IntroPartPresentation presentation = IntroPlugin.getDefault()
46             .getIntroModelRoot().getPresentation();
47         String JavaDoc presentationStyle = presentation.getImplementationKind();
48
49         if (isEmbedded
50                 && presentationStyle
51                     .equals(IntroPartPresentation.BROWSER_IMPL_KIND)) {
52
53             // Embedded is true and we have HTML presentation, show href
54
// embedded, either in full page, or in div.
55
BrowserIntroPartImplementation impl = (BrowserIntroPartImplementation) presentation
56                 .getIntroPartImplementation();
57             // INTRO: maybe add support for navigation
58
href = PlatformUI.getWorkbench().getHelpSystem()
59                 .resolve(href, true).toExternalForm();
60
61             if (embedTarget == null)
62                 return impl.getBrowser().setUrl(href);
63
64             // embedded in Div case.
65
IntroModelRoot model = IntroPlugin.getDefault().getIntroModelRoot();
66             return handleEmbedURLInDiv(href, embedTarget, model
67                 .getCurrentPage());
68         }
69
70         // show href in Help window. SWT presentation is handled here.
71
// WorkbenchHelp takes care of error handling.
72
PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(href);
73         return true;
74     }
75
76
77     /*
78      * Handles the embedded url case. Clone page and insert an IFrame in the
79      * target embed div. Note that only one div per page can be specified as an
80      * embed div. This is because we need to mangle the name for the cloned
81      * page, and the mangled name id pageId_embedTarget.
82      */

83     private boolean handleEmbedURLInDiv(String JavaDoc href, String JavaDoc embedTarget,
84             AbstractIntroPage currentPage) {
85
86         // re-use a runtime generated page, if found. Create the mangled id for
87
// the page and check if page exists first. If not, create one.
88
IntroModelRoot model = (IntroModelRoot) currentPage.getParentPage()
89             .getParent();
90         String JavaDoc currentPageId = null;
91         if (currentPage.isIFramePage())
92             currentPageId = currentPage.getUnmangledId();
93         else
94             currentPageId = currentPage.getId();
95         String JavaDoc mangledPageId = currentPageId + "_" + "WITH_IFRAME"; //$NON-NLS-1$ //$NON-NLS-2$
96

97         // get current standby state.
98
boolean standby = IntroPlugin.isIntroStandby();
99         String JavaDoc standbyAsString = standby ? IntroURL.VALUE_TRUE : "false"; //$NON-NLS-1$
100

101         AbstractIntroPage pageWithIFrame = (AbstractIntroPage) model.findChild(
102             mangledPageId, AbstractIntroElement.ABSTRACT_PAGE);
103         if (pageWithIFrame != null) {
104             pageWithIFrame.setIFrameURL(href);
105             return introURL.showPage(mangledPageId, standbyAsString);
106         }
107
108         // Page never generated, clone and create.
109
AbstractIntroPage clonedPage = null;
110         try {
111             clonedPage = (AbstractIntroPage) currentPage.clone();
112         } catch (CloneNotSupportedException JavaDoc ex) {
113             // should never be here.
114
Log.error("Failed to clone Intro page: " + currentPage.getId(), ex); //$NON-NLS-1$
115
return false;
116         }
117
118         // embed url as IFrame in target div. We need to find target div in
119
// cloned page not in the original page.
120
boolean canInjectFrame = clonedPage.injectIFrame(href, embedTarget);
121         if (!canInjectFrame)
122             // Called method handles error.
123
return false;
124
125         clonedPage.setId(mangledPageId);
126         model.addChild(clonedPage);
127         return introURL.showPage(clonedPage.getId(), standbyAsString);
128     }
129
130 }
131
Popular Tags