]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java
merged svn revision 33114 and added desktop and help plugins
[simantics/platform.git] / bundles / org.simantics.help.core / src / org / simantics / help / core / Activator.java
1 package org.simantics.help.core;\r
2 \r
3 import java.net.URL;\r
4 import java.nio.file.Files;\r
5 import java.nio.file.Path;\r
6 import java.nio.file.Paths;\r
7 import java.nio.file.StandardCopyOption;\r
8 \r
9 import org.eclipse.core.runtime.IPath;\r
10 import org.eclipse.core.runtime.Platform;\r
11 import org.eclipse.ui.plugin.AbstractUIPlugin;\r
12 import org.osgi.framework.Bundle;\r
13 import org.osgi.framework.BundleContext;\r
14 \r
15 /**\r
16  * The activator class controls the plug-in life cycle\r
17  */\r
18 public class Activator extends AbstractUIPlugin {\r
19 \r
20         // The plug-in ID\r
21         public static final String PLUGIN_ID = "org.simantics.help.core"; //$NON-NLS-1$\r
22 \r
23         public static final String HTML_FOLDER = "html";\r
24         \r
25         // The shared instance\r
26         private static Activator plugin;\r
27         private static Path directory;\r
28         \r
29         /**\r
30          * The constructor\r
31          */\r
32         public Activator() {\r
33         }\r
34 \r
35         /*\r
36          * (non-Javadoc)\r
37          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)\r
38          */\r
39         public void start(BundleContext context) throws Exception {\r
40                 super.start(context);\r
41                 plugin = this;\r
42         Bundle bundle = context.getBundle();\r
43         IPath path = Platform.getStateLocation(bundle);\r
44         Path p = Paths.get(path.toOSString());\r
45         directory = p.resolve(HTML_FOLDER);\r
46         if (!Files.exists(directory))\r
47             Files.createDirectories(directory);\r
48         \r
49         // Ensure that style.css is inside the html directory\r
50         Path css = directory.resolve("style.css");\r
51         if (!Files.exists(css)) {\r
52             Files.createFile(css);\r
53             URL url = bundle.getEntry("css/style.css");\r
54             Files.copy(url.openStream(), css, StandardCopyOption.REPLACE_EXISTING);\r
55         }\r
56         }\r
57 \r
58         /*\r
59          * (non-Javadoc)\r
60          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)\r
61          */\r
62         public void stop(BundleContext context) throws Exception {\r
63                 plugin = null;\r
64                 super.stop(context);\r
65         }\r
66 \r
67         /**\r
68          * Returns the shared instance\r
69          *\r
70          * @return the shared instance\r
71          */\r
72         public static Activator getDefault() {\r
73                 return plugin;\r
74         }\r
75         \r
76     public static Path getHtmlDirectory() {\r
77         return directory;\r
78     }\r
79 \r
80 }\r