source: trunk/org.modelica.mdt/src/org/modelica/mdt/MdtPlugin.java @ 36

Last change on this file since 36 was 35, checked in by boris, 19 years ago
  • added some error handling
File size: 1.6 KB
Line 
1package org.modelica.mdt;
2import org.eclipse.core.resources.IProject;
3import org.eclipse.core.resources.IProjectDescription;
4import org.eclipse.core.runtime.CoreException;
5import org.eclipse.ui.plugin.AbstractUIPlugin;
6import org.osgi.framework.BundleContext;
7
8public class MdtPlugin extends AbstractUIPlugin
9{
10
11    public static final String MODELICA_NATURE = 
12        "org.modelica.mdt.ModelicaNature";
13   
14    //The shared instance.
15    private static MdtPlugin plugin;
16   
17    /**
18     * The constructor.
19     */
20    public MdtPlugin()
21    {
22        plugin = this;
23    }
24
25   
26    public static void addModelicaNature(IProject project) throws CoreException
27    {
28        if (project.hasNature(MODELICA_NATURE)) 
29            return;
30
31        IProjectDescription description = project.getDescription();
32        String[] ids= description.getNatureIds();
33        String[] newIds= new String[ids.length + 1];
34        System.arraycopy(ids, 0, newIds, 0, ids.length);
35        newIds[ids.length]= MODELICA_NATURE;
36        description.setNatureIds(newIds);
37        project.setDescription(description, null);
38    }
39   
40    /**
41     * Returns the shared instance.
42     */
43    public static MdtPlugin getDefault()
44    {
45        return plugin;
46    }
47   
48    /**
49     * This method is called upon plug-in activation
50     */
51    public void start(BundleContext context) throws Exception
52    {
53        super.start(context);
54    }
55
56    /**
57     * This method is called when the plug-in is stopped
58     */
59    public void stop(BundleContext context) throws Exception
60    {
61        super.stop(context);
62        plugin = null;
63    }
64
65    /**
66     * @return returns this plugins symbolic name e.g. stuff like org.foo.bar
67     */
68    public static String getSymbolicName()
69    {
70        return getDefault().getBundle().getSymbolicName();
71    }
72
73   
74}
Note: See TracBrowser for help on using the repository browser.