]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graphviz/src/org/simantics/graphviz/Activator.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graphviz / src / org / simantics / graphviz / Activator.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.graphviz;
13
14 import java.io.File;
15 import java.io.IOException;
16 import java.net.URL;
17 import java.net.URLDecoder;
18
19 import org.eclipse.core.runtime.FileLocator;
20 import org.eclipse.core.runtime.Plugin;
21 import org.osgi.framework.Bundle;
22 import org.osgi.framework.BundleContext;
23
24 /**
25  * The activator class controls the plug-in life cycle
26  * 
27  * @author Hannu Niemistö
28  */
29 public class Activator extends Plugin {
30
31     // The plug-in ID
32     public static final String PLUGIN_ID = "org.simantics.graphviz";
33
34     // The shared instance
35     private static Activator plugin;
36
37     // private File stateDir;
38     private Bundle bundle;
39     private File DOT_EXE;
40
41     /*
42      * (non-Javadoc)
43      * 
44      * @see
45      * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
46      */
47     @Override
48     public void start(BundleContext context) throws Exception {
49         super.start(context);
50
51         bundle = context.getBundle();
52         URL url = FileLocator.toFileURL(bundle.getEntry("dot"));
53         DOT_EXE = new File(url.getPath(), "dot.exe");
54
55         plugin = this;
56     }
57
58     /*
59      * (non-Javadoc)
60      * 
61      * @see
62      * org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
63      */
64     @Override
65     public void stop(BundleContext context) throws Exception {
66         plugin = null;
67         super.stop(context);
68     }
69
70     /**
71      * Returns the shared instance
72      * 
73      * @return the shared instance
74      */
75     public static Activator getDefault() {
76         return plugin;
77     }
78
79     public static File getDotExe() {
80         Activator activator = getDefault();
81         if(activator != null)
82             return activator.DOT_EXE;
83         else
84             try {
85                 URL path = Activator.class.getResource(".");
86                 URL resource = new URL(path, "../../../../dot/dot.exe");
87                 return new File(URLDecoder.decode(resource.getPath(), "UTF-8"));
88             } catch (IOException e) {
89                 e.printStackTrace();
90                 return null;
91             }
92     }
93
94 }