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

Last change on this file since 85 was 72, checked in by boris, 19 years ago
  • packages are now displayed in modelica projects view with icon and everything
File size: 4.8 KB
Line 
1/*
2 * This file is part of Modelica Development Tooling.
3 *
4 * Copyright (c) 2005, Linköpings universitet, Department of
5 * Computer and Information Science, PELAB
6 *
7 * All rights reserved.
8 *
9 * (The new BSD license, see also
10 * http://www.opensource.org/licenses/bsd-license.php)
11 *
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are
15 * met:
16 *
17 * * Redistributions of source code must retain the above copyright
18 *   notice, this list of conditions and the following disclaimer.
19 *
20 * * Redistributions in binary form must reproduce the above copyright
21 *   notice, this list of conditions and the following disclaimer in
22 *   the documentation and/or other materials provided with the
23 *   distribution.
24 *
25 * * Neither the name of Linköpings universitet nor the names of its
26 *   contributors may be used to endorse or promote products derived from
27 *   this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42package org.modelica.mdt;
43import org.eclipse.core.resources.IProject;
44import org.eclipse.core.resources.IProjectDescription;
45import org.eclipse.core.runtime.CoreException;
46import org.eclipse.core.runtime.IStatus;
47import org.eclipse.core.runtime.Status;
48import org.eclipse.swt.widgets.Display;
49import org.eclipse.swt.widgets.Widget;
50import org.eclipse.ui.plugin.AbstractUIPlugin;
51import org.osgi.framework.BundleContext;
52
53public class MdtPlugin extends AbstractUIPlugin
54{
55
56    public static final String MODELICA_NATURE = 
57        "org.modelica.mdt.ModelicaNature";
58
59    private static final int INTERNAL_ERROR = 0;
60   
61    //The shared instance.
62    private static MdtPlugin plugin;
63   
64    /**
65     * The constructor.
66     */
67    public MdtPlugin()
68    {
69        plugin = this;
70    }
71
72   
73    public static void addModelicaNature(IProject project) throws CoreException
74    {
75        if (project.hasNature(MODELICA_NATURE)) 
76            return;
77
78        IProjectDescription description = project.getDescription();
79        String[] ids= description.getNatureIds();
80        String[] newIds= new String[ids.length + 1];
81        System.arraycopy(ids, 0, newIds, 0, ids.length);
82        newIds[ids.length]= MODELICA_NATURE;
83        description.setNatureIds(newIds);
84        project.setDescription(description, null);
85    }
86   
87    /**
88     * Returns the shared instance.
89     */
90    public static MdtPlugin getDefault()
91    {
92        return plugin;
93    }
94   
95    /**
96     * This method is called upon plug-in activation
97     */
98    public void start(BundleContext context) throws Exception
99    {
100        super.start(context);
101    }
102
103    /**
104     * This method is called when the plug-in is stopped
105     */
106    public void stop(BundleContext context) throws Exception
107    {
108        super.stop(context);
109        plugin = null;
110    }
111
112    /**
113     * @return returns this plugins symbolic name e.g. stuff like org.foo.bar
114     */
115    public static String getSymbolicName()
116    {
117        return getDefault().getBundle().getSymbolicName();
118    }
119
120    public static void tag(Widget widget, String tag)
121    {
122        widget.setData("name", tag);
123    }
124   
125//  /**
126//   * convinience wrapper method for loggin to plugin logger
127//   * @param exception the exception to log
128//   */
129//  public static void log(CoreException exception)
130//  {
131//      plugin.getLog().log(exception.getStatus());
132//  }
133   
134    /**
135     * convinience wrapper method for loggin to plugin logger
136     */
137    public static void log(IStatus stat)
138    {
139        plugin.getLog().log(stat);
140    }
141
142
143    /**
144     * Returns the standard display to be used. The method first checks, if
145     * the thread calling this method has an associated display. If so, this
146     * display is returned. Otherwise the method returns the default display.
147     */
148    public static Display getStandardDisplay() 
149    {
150        Display display;
151        display= Display.getCurrent();
152        if (display == null)
153            display= Display.getDefault();
154        return display;     
155    }
156   
157    /**
158     * Logs an internal error with the specified throwable
159     *
160     * @param e the exception to be logged
161     */ 
162    public static void log(Throwable e) 
163    {
164        log(new Status(IStatus.ERROR, getSymbolicName(), 
165                INTERNAL_ERROR,
166                "Internal Error", e));
167    }
168}
Note: See TracBrowser for help on using the repository browser.