Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9add875e3048f9d6c33a62a2a61af74752f3bf05 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ote.ui.internal;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.core.operation.AbstractOperation;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.plugin.core.IWorkbenchUserService;
import org.eclipse.osee.framework.ui.plugin.OseeFormActivator;
import org.eclipse.osee.framework.ui.plugin.workspace.SafeWorkspaceAccess;
import org.eclipse.osee.ote.ui.IOteConsoleService;
import org.eclipse.osee.ote.ui.RemoteConsoleLauncher;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;

/**
 * The main plugin class to be used in the desktop.
 */
public class TestCoreGuiPlugin extends OseeFormActivator {

   public static final String PLUGIN_ID = "org.eclipse.osee.ote.ui";

   private static TestCoreGuiPlugin pluginInstance;

   private ServiceRegistration oteConsoleServiceRegistration;
   private ServiceTracker workbenchUserServiceTracker;

   private ServiceTracker workspaceStartTracker;
   private OteConsoleServiceImpl oteConsoleService;


   public TestCoreGuiPlugin() {
      super(PLUGIN_ID);
      pluginInstance = this;
   }

   @Override
   public void start(final BundleContext context) throws Exception {
      super.start(context);

      workspaceStartTracker =
         new ServiceTracker(context, SafeWorkspaceAccess.class.getName(), null) {
        	   private RemoteConsoleLauncher tracker;
        	   
            @Override
            public void removedService(ServiceReference reference, Object service) {
               if (oteConsoleService != null) {
                  oteConsoleServiceRegistration.unregister();
                  oteConsoleService.close();
                  oteConsoleService = null;
               }
               if (tracker != null) {
            	   tracker.close();
               }
               super.removedService(reference, service);
            }
      
            @Override
			public void close() {
				if (tracker != null) {
					tracker.close();
				}
				super.close();
			}


			@Override
            public void modifiedService(ServiceReference reference, Object service) {
               // TODO Auto-generated method stub

            }


            @Override
            public Object addingService(ServiceReference reference) {
               oteConsoleService = new OteConsoleServiceImpl();
               oteConsoleServiceRegistration =
                  context.registerService(IOteConsoleService.class.getName(), oteConsoleService, null);
               if (System.getProperty("NO_OTE_REMOTE_CONSOLE") == null) {
                   tracker = new RemoteConsoleLauncher(oteConsoleService);
                   tracker.open(true);
                }
               return super.addingService(reference);
            }
         };
      workspaceStartTracker.open(true);

      workbenchUserServiceTracker = new ServiceTracker(context, IWorkbenchUserService.class.getName(), null);
      workbenchUserServiceTracker.open();



      if (System.getProperty("NO_OTE_ARTIFACT_BULK_LOAD") == null) {
         startOTEArtifactBulkLoad();
      }
   }

   @Override
   public void stop(BundleContext context) throws Exception {
      if (workbenchUserServiceTracker != null) {
         workbenchUserServiceTracker.close();
      }
      if (oteConsoleServiceRegistration != null) {
         oteConsoleServiceRegistration.unregister();
         oteConsoleService.close();
         oteConsoleService = null;
      }
      workspaceStartTracker.close();
      pluginInstance = null;

      super.stop(context);
   }

   private void startOTEArtifactBulkLoad() {
      Operations.executeAsJob(new AbstractOperation("OTE Persistance Bulk Load", PLUGIN_ID) {

         @Override
         protected void doWork(IProgressMonitor monitor) throws Exception {
            if (getWorkbenchUserService() != null) {
               getWorkbenchUserService().getUser();
            }
         }
      }, false);
   }

   private IWorkbenchUserService getWorkbenchUserService() throws OseeCoreException {
      IWorkbenchUserService service = null;
      try {
         service = (IWorkbenchUserService) workbenchUserServiceTracker.waitForService(3000);
      } catch (InterruptedException ex) {
         OseeExceptions.wrapAndThrow(ex);
      }
      return service;
   }

   public static TestCoreGuiPlugin getDefault() {
      return pluginInstance;
   }

   @Override
   protected String getPluginName() {
      return PLUGIN_ID;
   }

   public IOteConsoleService getOteConsoleService() {
      return oteConsoleService;
   }

}

Back to the top