KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > HelpPlugin


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;
12
13 import java.io.InputStream JavaDoc;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Plugin;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.help.internal.context.ContextManager;
19 import org.eclipse.help.internal.extension.ContentExtensionManager;
20 import org.eclipse.help.internal.index.IndexManager;
21 import org.eclipse.help.internal.toc.TocManager;
22 import org.osgi.framework.BundleContext;
23
24 /**
25  * Help System Core plug-in
26  */

27 public class HelpPlugin extends Plugin {
28
29     public final static String JavaDoc PLUGIN_ID = "org.eclipse.help"; //$NON-NLS-1$
30
public final static String JavaDoc HELP_DATA_KEY = "HELP_DATA"; //$NON-NLS-1$
31
public final static String JavaDoc BASE_TOCS_KEY = "baseTOCS"; //$NON-NLS-1$
32
public final static String JavaDoc IGNORED_TOCS_KEY = "ignoredTOCS"; //$NON-NLS-1$
33
public final static String JavaDoc IGNORED_INDEXES_KEY = "ignoredIndexes"; //$NON-NLS-1$
34

35     private static HelpPlugin plugin;
36     private static Object JavaDoc tocManagerCreateLock = new Object JavaDoc();
37     
38     private TocManager tocManager;
39     private ContextManager contextManager;
40     private ContentExtensionManager contentExtensionManager;
41     private IndexManager indexManager;
42     private IHelpProvider helpProvider;
43
44     public static void logWarning(String JavaDoc message) {
45         Status errorStatus = new Status(IStatus.WARNING, PLUGIN_ID, IStatus.OK, message, null);
46         logStatus(errorStatus);
47     }
48
49     public static void logError(String JavaDoc message) {
50         Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, null);
51         logStatus(errorStatus);
52     }
53
54     public static void logError(String JavaDoc message, Throwable JavaDoc ex) {
55         if (message == null) {
56             message = ""; //$NON-NLS-1$
57
}
58         Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, ex);
59         logStatus(errorStatus);
60     }
61
62     private static synchronized void logStatus(IStatus errorStatus) {
63         HelpPlugin.getDefault().getLog().log(errorStatus);
64     }
65
66     /**
67      * @return the singleton instance of the plugin
68      */

69     public static HelpPlugin getDefault() {
70         return plugin;
71     }
72
73     /**
74      * Used to obtain Toc Naviagiont Manager
75      *
76      * @return instance of TocManager
77      */

78     public static TocManager getTocManager() {
79         if (getDefault().tocManager == null) {
80             synchronized (tocManagerCreateLock) {
81                 if (getDefault().tocManager == null) {
82                     getDefault().tocManager = new TocManager();
83                 }
84             }
85         }
86         return getDefault().tocManager;
87     }
88
89     /**
90      * Used to obtain Context Manager returns an instance of ContextManager
91      */

92     public static ContextManager getContextManager() {
93         if (getDefault().contextManager == null)
94             getDefault().contextManager = new ContextManager();
95         return getDefault().contextManager;
96     }
97
98     /**
99      * Used to obtain the ContentExtensionManager
100      */

101     public static ContentExtensionManager getContentExtensionManager() {
102         if (getDefault().contentExtensionManager == null)
103             getDefault().contentExtensionManager = new ContentExtensionManager();
104         return getDefault().contentExtensionManager;
105     }
106
107     public static IndexManager getIndexManager() {
108         if (getDefault().indexManager == null)
109             getDefault().indexManager = new IndexManager();
110         return getDefault().indexManager;
111     }
112
113     /*
114      * Returns the provider responsible for serving help documents.
115      */

116     public IHelpProvider getHelpProvider() {
117         return helpProvider;
118     }
119     
120     /*
121      * Sets the provider responsible for serving help documents. Called
122      * on startup.
123      */

124     public void setHelpProvider(IHelpProvider helpProvider) {
125         this.helpProvider = helpProvider;
126     }
127
128     /* (non-Javadoc)
129      * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
130      */

131     public void start(BundleContext context) throws Exception JavaDoc {
132         super.start(context);
133         plugin = this;
134     }
135
136     /* (non-Javadoc)
137      * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
138      */

139     public void stop(BundleContext context) throws Exception JavaDoc {
140         plugin = null;
141         super.stop(context);
142     }
143
144     /*
145      * An interface by which higher plug-ins can serve help content.
146      */

147     public static interface IHelpProvider {
148         public InputStream JavaDoc getHelpContent(String JavaDoc href, String JavaDoc locale);
149     }
150 }
151
Popular Tags