Skip to main content
summaryrefslogtreecommitdiffstats
blob: d71c6b7109c35b8b1296b3c2b4773c3d31d77e7a (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
/*******************************************************************************
 * Copyright (c) 2000, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.help.internal.base;

import java.io.File;
import java.net.URL;

import org.osgi.framework.BundleContext;

import org.eclipse.osgi.service.datalocation.Location;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;

/**
 * Help Base plug-in.
 */
public class HelpBasePlugin extends Plugin {

	public final static String PLUGIN_ID = "org.eclipse.help.base"; //$NON-NLS-1$
	private static HelpBasePlugin plugin;
	private File configurationDirectory;
	private BundleContext context;

	private IHelpActivitySupport helpActivitySupport = new IHelpActivitySupport() {
		public boolean isEnabled(String href) {
			return true;
		}
		public boolean isRoleEnabled(String href) {
			return true;
		}
		public boolean isEnabledTopic(String href, String locale) {
			return true;
		}
		public void enableActivities(String href) {
		}
		public boolean isFilteringEnabled() {
			return false;
		}
		public void setFilteringEnabled(boolean enabled) {
		}
		public boolean isUserCanToggleFiltering() {
			return false;
		}
		public String getShowAllMessage() {
			return null;
		}
		public String getDocumentMessage(boolean embedded) {
			return null;
		}
		public boolean getDocumentMessageUsesLiveHelp(boolean embedded) {
			return false;
		}
	};

	public static synchronized void logError(String message, Throwable ex) {
		if (message == null) {
			message = ""; //$NON-NLS-1$
		}
		Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, ex);
		HelpBasePlugin.getDefault().getLog().log(errorStatus);
	}

	public static synchronized void logStatus(IStatus errorStatus) {
		HelpBasePlugin.getDefault().getLog().log(errorStatus);
	}

	public static HelpBasePlugin getDefault() {
		return plugin;
	}

	public void stop(BundleContext context) throws Exception {
		BaseHelpSystem.shutdown();
		this.context = null;
		plugin = null;
		super.stop(context);
	}

	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
		this.context = context;

		// determine configuration location for this plug-in
		Location location = Platform.getConfigurationLocation();
		if (location != null) {
			URL configURL = location.getURL();
			if (configURL != null && configURL.getProtocol().startsWith("file")) { //$NON-NLS-1$
				configurationDirectory = new File(configURL.getFile(), PLUGIN_ID);
			}
		}
		if (configurationDirectory == null) {
			configurationDirectory = getStateLocation().toFile();
		}
		BaseHelpSystem.startup();
	}

	public static File getConfigurationDirectory() {
		return getDefault().configurationDirectory;
	}

	public static IHelpActivitySupport getActivitySupport() {
		return getDefault().helpActivitySupport;
	}

	public static void setActivitySupport(IHelpActivitySupport activitySupport) {
		getDefault().helpActivitySupport = activitySupport;
	}

	public static BundleContext getBundleContext() {
		return getDefault().context;
	}
}

Back to the top