intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.css.core / src / net / sourceforge / phpeclipse / css / core / CssCore.java
1 /*
2  * Copyright (c) 2004 Christopher Lenz 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  *     Christopher Lenz - initial API and implementation
10  * 
11  * $Id: CssCore.java,v 1.1 2004-09-02 18:07:13 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.css.core;
15
16 import net.sourceforge.phpeclipse.css.core.internal.CssCorePreferences;
17 import net.sourceforge.phpeclipse.css.core.internal.profiles.ProfileManager;
18 import net.sourceforge.phpeclipse.css.core.profiles.IProfileManager;
19
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.Plugin;
22 import org.eclipse.core.runtime.Status;
23
24 /**
25  * The main plugin class to be used in the desktop.
26  */
27 public class CssCore extends Plugin {
28
29         // Class Variables ---------------------------------------------------------
30
31         /** The shared instance. */
32         private static CssCore plugin;
33
34         // Instance Variables ------------------------------------------------------
35
36         /**
37          * The profile manager.
38          */
39         private IProfileManager profileManager;
40
41         // Constructors ------------------------------------------------------------
42
43         /**
44          * Constructor.
45          */
46         public CssCore() {
47                 plugin = this;
48         }
49
50         // Public Methods ----------------------------------------------------------
51
52         /**
53          * Returns the shared instance.
54          */
55         public static CssCore getDefault() {
56                 return plugin;
57         }
58
59         /**
60          * Returns the plugin ID.
61          * 
62          * @return the plugin ID
63          */
64         public static String getPluginId() {
65                 return getDefault().getBundle().getSymbolicName();
66         }
67
68         /**
69          * Returns the object that manages the CSS profiles.
70          * 
71          * @return the profile manager
72          */
73         public synchronized IProfileManager getProfileManager() {
74                 if (profileManager == null) {
75                         profileManager = new ProfileManager(getPluginPreferences());
76                 }
77                 return profileManager;
78         }
79
80         /**
81          * Writes a status message and the associated exception stack trace (if
82          * provided) to the error log.
83          * 
84          * @param status the status to log
85          */
86         public static void log(IStatus status) {
87                 getDefault().getLog().log(status);
88                 if (status.getException() != null) {
89                         status.getException().printStackTrace(System.err);
90                 }
91         }
92
93         /**
94          * Writes the specified error message and exception stack trace to the error
95          * log.
96          * 
97          * @param message the error message
98          * @param e the exception that caused the error, or <tt>null</tt> to omit
99          *        the stack trace in the log
100          */
101         public static void log(String message, Throwable e) {
102                 IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR,
103                         message, e); 
104                 log(status);
105         }
106
107         /**
108          * Writes the specified error message to the error log.
109          * 
110          * @param message the error message
111          */
112         public static void log(String message) {
113                 IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR,
114                         message, null); 
115                 log(status);
116         }
117
118         /**
119          * Writes the stack trace of the given exception to the error log.
120          * 
121          * @param e the exception that caused the error
122          */
123         public static void log(Throwable e) {
124                 log(e.getMessage(), e);
125         }
126
127         // Plugin Implementation ---------------------------------------------------
128
129         /* 
130          * @see Plugin#initializeDefaultPluginPreferences()
131          */
132         protected void initializeDefaultPluginPreferences() {
133                 CssCorePreferences.initializeDefaultValues(getPluginPreferences());
134         }
135
136 }