summaryrefslogtreecommitdiff
path: root/org.tizen.common/src/org/tizen/common/util/HelpBrowser.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.tizen.common/src/org/tizen/common/util/HelpBrowser.java')
-rw-r--r--org.tizen.common/src/org/tizen/common/util/HelpBrowser.java120
1 files changed, 120 insertions, 0 deletions
diff --git a/org.tizen.common/src/org/tizen/common/util/HelpBrowser.java b/org.tizen.common/src/org/tizen/common/util/HelpBrowser.java
new file mode 100644
index 000000000..58db9e3a8
--- /dev/null
+++ b/org.tizen.common/src/org/tizen/common/util/HelpBrowser.java
@@ -0,0 +1,120 @@
+/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Ho Namkoong <ho.namkoong@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.util;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.browser.LocationEvent;
+import org.eclipse.swt.browser.LocationListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.help.IWorkbenchHelpSystem;
+import org.tizen.common.CommonPlugin;
+
+public class HelpBrowser {
+
+ private static final String HELP_PAGE_PREFIX = "help:/";
+ private static final String BACK_ICON = "icons/back.gif";
+ private static final String FORWARD_ICON = "icons/forward.gif";
+
+ private Browser browser;
+
+ public Browser getBrowser() {
+ return browser;
+ }
+
+ public HelpBrowser(Composite parent, int style) {
+ this(parent, style, false);
+ }
+
+ public HelpBrowser(Composite parent, int style, boolean hasToolbar) {
+ if(hasToolbar == true) {
+ generateToolBar(parent);
+ }
+ this.browser = new Browser(parent, style);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ this.browser.setLayoutData(gd);
+ enableHelpPage();
+ }
+
+ private void generateToolBar(Composite parent) {
+ ToolBar toolbar = new ToolBar(parent, SWT.None);
+
+ ToolItem backButton = new ToolItem(toolbar, SWT.PUSH);
+ Image backIcon = ImageUtil.getImage(CommonPlugin.PLUGIN_ID, BACK_ICON);
+ backButton.setImage(backIcon);
+
+ ToolItem forwardButton = new ToolItem(toolbar, SWT.PUSH);
+ Image forwardIcon = ImageUtil.getImage(CommonPlugin.PLUGIN_ID, FORWARD_ICON);
+ forwardButton.setImage(forwardIcon);
+
+ forwardButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ browser.forward();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ backButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ browser.back();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ }
+
+ private void enableHelpPage() {
+ this.getBrowser().addLocationListener(new LocationListener() {
+ @Override
+ public void changing(LocationEvent event) {
+ String url = event.location;
+ if(url.startsWith(HELP_PAGE_PREFIX)) {
+ Browser browser = ((Browser)event.widget);
+ String tempUrl = url.substring(HELP_PAGE_PREFIX.length(), url.length());
+ IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem();
+ browser.setUrl(helpSystem.resolve(tempUrl, false).toString());
+ }
+ }
+ @Override
+ public void changed(LocationEvent event) {
+ }
+ });
+ }
+}