Skip to main content
summaryrefslogtreecommitdiffstats
blob: a2f3cc884517791fdb2df1673574df3fc2e45f4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
 * Copyright (c) 2000, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.help.internal.browser;
import org.eclipse.help.browser.*;
/**
 * Wrapper for individual browsers contributed through extension point.
 */
public class CurrentBrowser implements IBrowser {
	private IBrowser browserAdapter;
	private String browserAdapterId;
	/**
	 * new adapter selected in preferences but not yet shown
	 */
	private IBrowser newBrowserAdapter = null;
	private String newBrowserAdapterId = null;
	private boolean locationSet = false;
	private boolean sizeSet = false;
	private int x;
	private int y;
	private int width;
	private int height;
	boolean external;
	public CurrentBrowser(IBrowser browserImpl, String browserAdapterId,
			boolean externalBrowser) {
		this.browserAdapter = browserImpl;
		this.browserAdapterId = browserAdapterId;
		this.external = externalBrowser;
	}
	/**
	 * @see org.eclipse.help.browser.IBrowser#close()
	 */
	@Override
	public void close() {
		browserAdapter.close();
	}
	/**
	 * @see org.eclipse.help.browser.IBrowser#isCloseSupported()
	 */
	@Override
	public boolean isCloseSupported() {
		return browserAdapter.isCloseSupported();
	}
	/**
	 * @see org.eclipse.help.browser.IBrowser#displayURL(java.lang.String)
	 */
	@Override
	public void displayURL(String url) throws Exception {
		checkDefaultAdapter();
		if (newBrowserAdapter != null) {
			browserAdapter.close();
			browserAdapter = newBrowserAdapter;
			newBrowserAdapter = null;
			browserAdapterId = newBrowserAdapterId;
			newBrowserAdapterId = null;
			if (locationSet) {
				browserAdapter.setLocation(x, y);
			}
			if (sizeSet) {
				browserAdapter.setSize(width, height);
			}
		}
		browserAdapter.displayURL(url);
	}
	/**
	 * @see org.eclipse.help.browser.IBrowser#isSetLocationSupported()
	 */
	@Override
	public boolean isSetLocationSupported() {
		checkDefaultAdapter();
		if (newBrowserAdapterId == null) {
			return browserAdapter.isSetLocationSupported();
		}
		return browserAdapter.isSetLocationSupported()
				|| newBrowserAdapter.isSetLocationSupported();
	}
	/**
	 * @see org.eclipse.help.browser.IBrowser#isSetSizeSupported()
	 */
	@Override
	public boolean isSetSizeSupported() {
		checkDefaultAdapter();
		if (newBrowserAdapterId == null) {
			return browserAdapter.isSetSizeSupported();
		}
		return browserAdapter.isSetSizeSupported()
				|| newBrowserAdapter.isSetSizeSupported();
	}
	/**
	 * @see org.eclipse.help.browser.IBrowser#setLocation(int, int)
	 */
	@Override
	public void setLocation(int x, int y) {
		checkDefaultAdapter();
		browserAdapter.setLocation(x, y);
		locationSet = true;
		this.x = x;
		this.y = y;
	}
	/**
	 * @see org.eclipse.help.browser.IBrowser#setSize(int, int)
	 */
	@Override
	public void setSize(int width, int height) {
		checkDefaultAdapter();
		browserAdapter.setSize(width, height);
		sizeSet = true;
		this.width = width;
		this.height = height;
	}
	/*
	 * Checks wheter default adapter has changed. If yes, sets the
	 * newBrowserAdapterId field
	 */
	private void checkDefaultAdapter() {
		if (external) {
			if (browserAdapterId != BrowserManager.getInstance()
					.getCurrentBrowserID()) {
				newBrowserAdapter = BrowserManager.getInstance().createBrowser(
						true);
				newBrowserAdapterId = BrowserManager.getInstance()
						.getCurrentBrowserID();
			}
		} else {
			if (browserAdapterId != BrowserManager.getInstance()
					.getCurrentInternalBrowserID()) {
				newBrowserAdapter = BrowserManager.getInstance().createBrowser(
						false);
				newBrowserAdapterId = BrowserManager.getInstance()
						.getCurrentInternalBrowserID();
			}
		}
	}
}

Back to the top