KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > base > HelpBasePlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.help.internal.base;
12
13 import java.io.File JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Platform;
18 import org.eclipse.core.runtime.Plugin;
19 import org.eclipse.core.runtime.Status;
20 import org.eclipse.osgi.service.datalocation.Location;
21 import org.osgi.framework.BundleContext;
22
23 /**
24  * Help Base plug-in.
25  */

26 public class HelpBasePlugin extends Plugin {
27
28     public final static String JavaDoc PLUGIN_ID = "org.eclipse.help.base"; //$NON-NLS-1$
29
private static HelpBasePlugin plugin;
30     private File JavaDoc configurationDirectory;
31     private BundleContext context;
32
33     private IHelpActivitySupport helpActivitySupport = new IHelpActivitySupport() {
34         public boolean isEnabled(String JavaDoc href) {
35             return true;
36         }
37         public boolean isRoleEnabled(String JavaDoc href) {
38             return true;
39         }
40         public boolean isEnabledTopic(String JavaDoc href, String JavaDoc locale) {
41             return true;
42         }
43         public void enableActivities(String JavaDoc href) {
44         }
45         public boolean isFilteringEnabled() {
46             return false;
47         }
48         public void setFilteringEnabled(boolean enabled) {
49         }
50         public boolean isUserCanToggleFiltering() {
51             return false;
52         }
53         public String JavaDoc getShowAllMessage() {
54             return null;
55         }
56         public String JavaDoc getDocumentMessage(boolean embedded) {
57             return null;
58         }
59         public boolean getDocumentMessageUsesLiveHelp(boolean embedded) {
60             return false;
61         }
62         public String JavaDoc getLocalScopeCheckboxLabel() {
63             return null;
64         }
65     };
66
67     public static synchronized void logError(String JavaDoc message, Throwable JavaDoc ex) {
68         if (message == null) {
69             message = ""; //$NON-NLS-1$
70
}
71         Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, ex);
72         HelpBasePlugin.getDefault().getLog().log(errorStatus);
73     }
74
75     public static synchronized void logStatus(IStatus errorStatus) {
76         HelpBasePlugin.getDefault().getLog().log(errorStatus);
77     }
78
79     public static HelpBasePlugin getDefault() {
80         return plugin;
81     }
82
83     public void stop(BundleContext context) throws Exception JavaDoc {
84         plugin.savePluginPreferences();
85         BaseHelpSystem.shutdown();
86         this.context = null;
87         plugin = null;
88         super.stop(context);
89     }
90
91     public void start(BundleContext context) throws Exception JavaDoc {
92         super.start(context);
93         plugin = this;
94         this.context = context;
95
96         // determine configuration location for this plug-in
97
Location location = Platform.getConfigurationLocation();
98         if (location != null) {
99             URL JavaDoc configURL = location.getURL();
100             if (configURL != null && configURL.getProtocol().startsWith("file")) { //$NON-NLS-1$
101
configurationDirectory = new File JavaDoc(configURL.getFile(), PLUGIN_ID);
102             }
103         }
104         if (configurationDirectory == null) {
105             configurationDirectory = getStateLocation().toFile();
106         }
107         BaseHelpSystem.startup();
108     }
109
110     public static File JavaDoc getConfigurationDirectory() {
111         return getDefault().configurationDirectory;
112     }
113
114     public static IHelpActivitySupport getActivitySupport() {
115         return getDefault().helpActivitySupport;
116     }
117
118     public static void setActivitySupport(IHelpActivitySupport activitySupport) {
119         getDefault().helpActivitySupport = activitySupport;
120     }
121     
122     public static BundleContext getBundleContext() {
123         return getDefault().context;
124     }
125 }
126
Popular Tags