KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > ide > HelpIdePlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal.ide;
12 import org.eclipse.core.runtime.*;
13 import org.eclipse.help.internal.base.*;
14 import org.eclipse.help.ui.internal.util.*;
15 import org.eclipse.help.ui.internal.workingset.*;
16 import org.eclipse.ui.*;
17 import org.eclipse.ui.plugin.*;
18 import org.osgi.framework.*;
19
20 /**
21  * This class is a Help IDE plugin.
22  */

23 public class HelpIdePlugin extends AbstractUIPlugin {
24     public final static String JavaDoc PLUGIN_ID = "org.eclipse.help.ide"; //$NON-NLS-1$
25
// debug options
26
public static boolean DEBUG = false;
27
28     private static HelpIdePlugin plugin;
29     private static BundleContext bundleContext;
30     private HelpWorkingSetSynchronizer workingSetListener;
31
32     /**
33      * Logs an Error message with an exception. Note that the message should
34      * already be localized to proper locale. ie: Resources.getString() should
35      * already have been called
36      */

37     public static synchronized void logError(String JavaDoc message, Throwable JavaDoc ex) {
38         if (message == null)
39             message = ""; //$NON-NLS-1$
40
Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK,
41                 message, ex);
42         HelpBasePlugin.getDefault().getLog().log(errorStatus);
43     }
44     /**
45      * Logs a Warning message with an exception. Note that the message should
46      * already be localized to proper local. ie: Resources.getString() should
47      * already have been called
48      */

49     public static synchronized void logWarning(String JavaDoc message) {
50         if (HelpBasePlugin.DEBUG) {
51             if (message == null)
52                 message = ""; //$NON-NLS-1$
53
Status warningStatus = new Status(IStatus.WARNING, PLUGIN_ID,
54                     IStatus.OK, message, null);
55             HelpBasePlugin.getDefault().getLog().log(warningStatus);
56         }
57     }
58
59     /**
60      * Provides access to singleton
61      *
62      * @return HelpIDEPlugin
63      */

64     public static HelpIdePlugin getDefault() {
65         return plugin;
66     }
67     /*
68      * (non-Javadoc)
69      *
70      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
71      */

72     public void stop(BundleContext context) throws Exception JavaDoc {
73         if (BaseHelpSystem.getMode() == BaseHelpSystem.MODE_WORKBENCH) {
74             if (PlatformUI.isWorkbenchRunning()) {
75                 PlatformUI.getWorkbench().getWorkingSetManager()
76                         .removePropertyChangeListener(workingSetListener);
77             }
78             BaseHelpSystem.getWorkingSetManager().removePropertyChangeListener(
79                     workingSetListener);
80         }
81         plugin = null;
82         bundleContext = null;
83         super.stop(context);
84     }
85
86     /*
87      * (non-Javadoc)
88      *
89      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
90      */

91     public void start(BundleContext context) throws Exception JavaDoc {
92         super.start(context);
93         plugin = this;
94         bundleContext = context;
95         // Setup debugging options
96
DEBUG = isDebugging();
97
98         BaseHelpSystem.setDefaultErrorUtil(new ErrorUtil());
99         if (BaseHelpSystem.getMode() == BaseHelpSystem.MODE_WORKBENCH) {
100             if (PlatformUI.isWorkbenchRunning()) {
101                 // register the working set listener to keep the ui and the help
102
// working sets in sych
103
workingSetListener = new HelpWorkingSetSynchronizer();
104                 PlatformUI.getWorkbench().getWorkingSetManager()
105                         .addPropertyChangeListener(workingSetListener);
106                 BaseHelpSystem.getWorkingSetManager()
107                         .addPropertyChangeListener(workingSetListener);
108             } else {
109                 // running tests, workbench not running
110
}
111         }
112     }
113
114     public HelpWorkingSetSynchronizer getWorkingSetSynchronizer() {
115         return workingSetListener;
116     }
117 }
118
Popular Tags