]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.equation/src/org/simantics/equation/Activator.java
Remove usage of deprecated SimanticsUI-methods
[simantics/platform.git] / bundles / org.simantics.equation / src / org / simantics / equation / 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.equation;
13
14 import org.eclipse.ui.plugin.AbstractUIPlugin;
15 import org.osgi.framework.BundleContext;
16 import org.simantics.Simantics;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.common.request.ReadRequest;
19 import org.simantics.db.management.ISessionContext;
20 import org.simantics.db.management.ISessionContextChangedListener;
21 import org.simantics.db.management.SessionContextChangedEvent;
22
23 /**
24  * The activator class controls the plug-in life cycle
25  */
26 public class Activator extends AbstractUIPlugin {
27
28         // The plug-in ID
29         public static final String PLUGIN_ID = "org.simantics.equation";
30
31         // The shared instance
32         private static Activator plugin;
33         
34         /**
35          * The constructor
36          */
37         public Activator() {
38         }
39
40         /*
41          * (non-Javadoc)
42          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
43          */
44         public void start(BundleContext context) throws Exception {
45                 super.start(context);
46                 plugin = this;
47                 
48                 Simantics.getSessionContextProvider().addContextChangedListener(new ISessionContextChangedListener() {
49                         @Override
50                         public void sessionContextChanged(SessionContextChangedEvent event) {
51                                 ISessionContext ctx = event.getNewValue();
52                                 if (ctx != null) {
53                                         ctx.getSession().asyncRequest(new ReadRequest() {
54                                             @Override
55                                             public void run(ReadGraph g) {
56                                                 EquationResources.initialize(g);
57                                             };
58                                         });
59                                 } else {
60                                         EquationResources.deinitialize();
61                                 }
62                         }
63                 });
64                 
65                 try {
66                         Simantics.getSession().syncRequest(new ReadRequest() {
67                             @Override
68                             public void run(ReadGraph g) {
69                                 EquationResources.initialize(g);
70                             }
71                         });
72                 } catch (Exception e) {
73
74                 }
75                 
76                 
77         }
78
79         /*
80          * (non-Javadoc)
81          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
82          */
83         public void stop(BundleContext context) throws Exception {
84                 plugin = null;
85                 super.stop(context);
86         }
87
88         /**
89          * Returns the shared instance
90          *
91          * @return the shared instance
92          */
93         public static Activator getDefault() {
94                 return plugin;
95         }
96
97 }