Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0d0f056749ce0d337f9e591fc7c013f1dc96d1d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*******************************************************************************
 * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.internal.debug.ui;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.tcf.internal.debug.ui.model.TCFAnnotationManager;
import org.eclipse.tcf.internal.debug.ui.model.TCFModelManager;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {

    public static final String PLUGIN_ID = "org.eclipse.tcf.debug.ui";

    private static final Object lock = new Object();

    private static Activator plugin;
    private static TCFModelManager model_manager;
    private static TCFAnnotationManager annotation_manager;

    public void start(BundleContext context) throws Exception {
        synchronized (lock) {
            super.start(context);
            plugin = this;
            Protocol.invokeLater(new Runnable() {
                public void run() {
                    if (model_manager == null) {
                        model_manager = new TCFModelManager();
                    }
                }
            });
        }
    }

    public void stop(BundleContext context) throws Exception {
        Protocol.invokeAndWait(new Runnable() {
            public void run() {
                if (model_manager != null) {
                    model_manager.dispose();
                    model_manager = null;
                }
                if (annotation_manager != null) {
                    annotation_manager.dispose();
                    annotation_manager = null;
                }
            }
        });
        synchronized (lock) {
            plugin = null;
            super.stop(context);
        }
    }

    /**
     * Returns the shared instance
     * @return the shared instance
     */
    public static Activator getDefault() {
        return plugin;
    }

    /**
     * Returns the shared TCFModelManager instance
     * @return the shared TCFModelManager instance
     */
    public static TCFModelManager getModelManager() {
        assert Protocol.isDispatchThread();
        if (model_manager == null) model_manager = new TCFModelManager();
        return model_manager;
    }

    /**
     * Returns the shared TCFAnnotationManager instance
     * @return the shared TCFAnnotationManager instance
     */
    public static TCFAnnotationManager getAnnotationManager() {
        assert Protocol.isDispatchThread();
        if (annotation_manager == null) annotation_manager = new TCFAnnotationManager();
        return annotation_manager;
    }

    /**
     * Send error message into Eclipse log.
     * @param msg - error message test
     * @param err - exception
     */
    public static void log(String msg, Throwable err) {
        synchronized (lock) {
            if (plugin == null || plugin.getLog() == null) {
                err.printStackTrace();
            }
            else {
                plugin.getLog().log(new Status(IStatus.ERROR,
                        plugin.getBundle().getSymbolicName(), IStatus.OK, msg, err));
            }
        }
    }

    /**
     * Send error message into Eclipse log.
     * @param err - exception
     */
    public static void log(Throwable err) {
        synchronized (lock) {
            if (plugin == null || plugin.getLog() == null) {
                err.printStackTrace();
            }
            else {
                plugin.getLog().log(new Status(IStatus.ERROR,
                        plugin.getBundle().getSymbolicName(), IStatus.OK, "Unhandled exception in TCF UI", err));
            }
        }
    }
}

Back to the top