]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.shapeeditor/src/org/simantics/proconf/g3d/shapeeditor/Activator.java
git-svn-id: https://www.simantics.org/svn/simantics/3d/trunk@22282 ac1ea38d-2e2b...
[simantics/3d.git] / org.simantics.g3d.shapeeditor / src / org / simantics / proconf / g3d / shapeeditor / Activator.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.shapeeditor;\r
12 \r
13 import org.eclipse.ui.plugin.AbstractUIPlugin;\r
14 import org.osgi.framework.BundleContext;\r
15 import org.simantics.db.Graph;\r
16 import org.simantics.db.GraphRequestAdapter;\r
17 import org.simantics.db.GraphRequestStatus;\r
18 import org.simantics.db.management.ISessionContext;\r
19 import org.simantics.db.management.ISessionContextChangedListener;\r
20 import org.simantics.db.management.SessionContextChangedEvent;\r
21 import org.simantics.proconf.ui.ProConfUI;\r
22 \r
23 /**\r
24  * The activator class controls the plug-in life cycle\r
25  */\r
26 public class Activator extends AbstractUIPlugin {\r
27 \r
28         // The plug-in ID\r
29         public static final String PLUGIN_ID = "org.simantics.proconf.g3d.shapeeditor";\r
30 \r
31         // The shared instance\r
32         private static Activator plugin;\r
33         \r
34         /**\r
35          * The constructor\r
36          */\r
37         public Activator() {\r
38         }\r
39 \r
40         /*\r
41          * (non-Javadoc)\r
42          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)\r
43          */\r
44         public void start(BundleContext context) throws Exception {\r
45                 super.start(context);\r
46                 plugin = this;\r
47                 ProConfUI.getSessionContextProvider().addContextChangedListener(new ISessionContextChangedListener() {\r
48                         @Override\r
49                         public void sessionContextChanged(SessionContextChangedEvent event) {\r
50                                 ISessionContext ctx = event.getNewValue();\r
51                                 if (ctx != null) {\r
52                                         ctx.getSession().asyncRead(new GraphRequestAdapter() {\r
53                                                 public GraphRequestStatus perform(Graph g) throws Exception {\r
54                                                         ShapeEditorResources.initialize(g);\r
55                                                         return GraphRequestStatus.transactionComplete();\r
56                                                 };\r
57                                         });\r
58                                 } else {\r
59                                         ShapeEditorResources.deinitialize();\r
60                                 }\r
61                         }\r
62                 });\r
63                 try {\r
64                         ProConfUI.getSession().asyncRead(new GraphRequestAdapter() {\r
65                                 @Override\r
66                                 public GraphRequestStatus perform(Graph g) throws Exception {\r
67                                         ShapeEditorResources.initialize(g);\r
68                                         return GraphRequestStatus.transactionComplete();\r
69                                 }\r
70                         });\r
71                 } catch (Exception e) {\r
72                         \r
73                 }\r
74                 \r
75         }\r
76 \r
77         /*\r
78          * (non-Javadoc)\r
79          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)\r
80          */\r
81         public void stop(BundleContext context) throws Exception {\r
82                 plugin = null;\r
83                 super.stop(context);\r
84         }\r
85 \r
86         /**\r
87          * Returns the shared instance\r
88          *\r
89          * @return the shared instance\r
90          */\r
91         public static Activator getDefault() {\r
92                 return plugin;\r
93         }\r
94 \r
95 }\r