KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2003, 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 org.eclipse.swt.browser.Browser;
14 import org.eclipse.swt.browser.LocationEvent;
15 import org.eclipse.swt.browser.LocationListener;
16 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
17 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
18 import org.eclipse.ui.internal.intro.impl.model.url.IntroURL;
19 import org.eclipse.ui.internal.intro.impl.model.url.IntroURLParser;
20
21 /**
22  * A Location Listener that knows how to intercept OOBE action URLs. It also
23  * knows how to update UI navigation hisutory.
24  */

25 public class BrowserIntroPartLocationListener implements LocationListener {
26
27     private BrowserIntroPartImplementation implementation;
28
29     /**
30      * Takes the implementation as an input.
31      */

32     public BrowserIntroPartLocationListener(
33             BrowserIntroPartImplementation implementation) {
34         this.implementation = implementation;
35     }
36
37     /*
38      * (non-Javadoc)
39      *
40      * @see org.eclipse.swt.browser.LocationListener#changed(org.eclipse.swt.browser.LocationEvent)
41      */

42     public void changed(LocationEvent event) {
43         String JavaDoc url = event.location;
44         if (url == null)
45             return;
46
47         // guard against unnecessary History updates.
48
Browser browser = (Browser) event.getSource();
49         if (browser.getData("navigation") != null //$NON-NLS-1$
50
&& browser.getData("navigation").equals("true")) //$NON-NLS-1$ //$NON-NLS-2$
51
return;
52
53         IntroModelRoot model = implementation.getModel();
54         IntroURLParser parser = new IntroURLParser(url);
55         if (!parser.hasProtocol() || parser.getHost() == null
56                 || parser.getHost().equals("")) //$NON-NLS-1$
57
// This will filter out two navigation events fired by the browser
58
// on a setText. (about:blank and
59
// res://C:\WINDOWS\System32\shdoclc.dll/navcancl.htm on windows,
60
// and file:/// on Linux)
61
return;
62
63         if (model.isDynamic()) {
64             // Update the history even with real URLs. Note that if we have
65
// multiple embedded URL navigations due to frames, the
66
// frameNavigation flag filters them. This flag is set here, and is
67
// cleared by a progress listener, when all the frame navigation is
68
// completed. We need to update history only in dynamic case. In
69
// static case, the browser keeps the history.
70
if (browser.getData("frameNavigation") != null) { //$NON-NLS-1$
71
// this is at least the second frame navigation, remove last
72
// history since it was added just as a filler.
73
if (event.top == false && browser.getData("tempUrl") != null //$NON-NLS-1$
74
&& browser.getData("tempUrl").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$
75
implementation.getHistory().removeLastHistory();
76                     flagRemovedTempUrl();
77                 }
78             }
79
80             if (event.top == true) {
81                 // we are navigating to a regular fully qualified URL. Event.top
82
// is true.
83
flagStartOfFrameNavigation();
84                 implementation.updateHistory(url);
85             }
86
87             if (browser.getData("frameNavigation") == null //$NON-NLS-1$
88
&& event.top == false) {
89                 // a new url navigation that is not in a top frame. It can
90
// be a navigation url due to frames, it can be due to a true
91
// single Frame navigation (when you click on a link inside a
92
// Frame) or it is an embedded Help System topic navigation.
93
AbstractIntroPage currentPage = model.getCurrentPage();
94                 if (currentPage.isIFramePage()) {
95                     // it is an embedded Help System topic navigation. we are
96
// navigating to an injected iframe since event.top is
97
// false. Set the iframe url of the current iframe page, and
98
// add it
99
// to history.
100
currentPage.setIFrameURL(url);
101                     implementation.updateHistory(currentPage);
102                 } else {
103                     flagStartOfFrameNavigation();
104                     flagStoredTempUrl();
105                     implementation.updateHistory(url);
106                 }
107             }
108
109         }
110         return;
111     }
112
113     /**
114      * Intercept any LocationEvents on the browser. If the event location is a
115      * valid IntroURL, cancel the event and execute the intro action that is
116      * embedded in the URL
117      */

118     public void changing(LocationEvent event) {
119         String JavaDoc url = event.location;
120         if (url == null)
121             return;
122
123         IntroModelRoot model = implementation.getModel();
124         IntroURLParser parser = new IntroURLParser(url);
125         if (parser.hasIntroUrl()) {
126             // stop URL first.
127
event.doit = false;
128             // execute the action embedded in the IntroURL
129
IntroURL introURL = parser.getIntroURL();
130             introURL.execute();
131
132             // In the case of dynamic Intro, guard against extra Frame
133
// navigations. This can happen in the case of intro injected
134
// IFrames or Frames included through intro xml content.
135
// INTRO: user defined iframes in Intro pages are not properly
136
// supported here, only Help system injected iframes.
137
if (model.isDynamic()) {
138                 if ((introURL.getParameter(IntroURL.KEY_EMBED_TARGET) != null)
139                         && introURL.getAction().equals(IntroURL.SHOW_PAGE))
140                     flagStartOfNavigation();
141             }
142             return;
143         }
144
145
146     }
147
148
149
150
151     public void flagStartOfFrameNavigation() {
152         if (implementation.getBrowser().getData("frameNavigation") == null) //$NON-NLS-1$
153
implementation.getBrowser().setData("frameNavigation", "true"); //$NON-NLS-1$ //$NON-NLS-2$
154
}
155
156     public void flagEndOfFrameNavigation() {
157         implementation.getBrowser().setData("frameNavigation", null); //$NON-NLS-1$
158
}
159
160
161     public void flagStartOfNavigation() {
162         if (implementation.getBrowser().getData("navigation") == null) //$NON-NLS-1$
163
implementation.getBrowser().setData("navigation", "true"); //$NON-NLS-1$ //$NON-NLS-2$
164
}
165
166     public void flagEndOfNavigation() {
167         implementation.getBrowser().setData("navigation", null); //$NON-NLS-1$
168
}
169
170
171     public void flagStoredTempUrl() {
172         if (implementation.getBrowser().getData("tempUrl") == null) //$NON-NLS-1$
173
implementation.getBrowser().setData("tempUrl", "true"); //$NON-NLS-1$ //$NON-NLS-2$
174
}
175
176     public void flagRemovedTempUrl() {
177         implementation.getBrowser().setData("tempUrl", null); //$NON-NLS-1$
178
}
179
180
181 }
182
Popular Tags