2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
21 import org
.argeo
.slc
.BasicNameVersion
;
22 import org
.argeo
.slc
.NameVersion
;
23 import org
.argeo
.slc
.SlcException
;
24 import org
.argeo
.slc
.deploy
.ModulesManager
;
25 import org
.argeo
.slc
.jcr
.SlcNames
;
26 import org
.argeo
.slc
.jcr
.SlcTypes
;
27 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
28 import org
.eclipse
.core
.runtime
.IStatus
;
29 import org
.eclipse
.core
.runtime
.Status
;
30 import org
.eclipse
.core
.runtime
.jobs
.Job
;
31 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
32 import org
.eclipse
.swt
.graphics
.Image
;
33 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
34 import org
.osgi
.framework
.BundleContext
;
36 /** The activator class controls the plug-in life cycle */
37 public class ClientUiPlugin
extends AbstractUIPlugin
implements SlcNames
{
38 public static final String ID
= "org.argeo.slc.client.ui";
39 private static ClientUiPlugin plugin
;
41 public void start(BundleContext context
) throws Exception
{
46 public void stop(BundleContext context
) throws Exception
{
51 public static ClientUiPlugin
getDefault() {
55 /** Creates the image */
56 public static Image
img(String path
) {
57 return getImageDescriptor(path
).createImage();
60 public static ImageDescriptor
getImageDescriptor(String path
) {
61 return imageDescriptorFromPlugin(ID
, path
);
64 /** Start execution module if it was stopped and vice-versa */
65 public static void startStopExecutionModule(
66 final ModulesManager modulesManager
, Node node
) {
68 if (!node
.isNodeType(SlcTypes
.SLC_EXECUTION_MODULE
))
69 throw new SlcException(node
+ " is not an execution module");
71 String name
= node
.getProperty(SLC_NAME
).getString();
72 String version
= node
.getProperty(SLC_VERSION
).getString();
73 final NameVersion nameVersion
= new BasicNameVersion(name
, version
);
74 Boolean started
= node
.getProperty(SLC_STARTED
).getBoolean();
78 job
= new Job("Stop " + nameVersion
) {
79 protected IStatus
run(IProgressMonitor monitor
) {
80 monitor
.beginTask("Stop " + nameVersion
, 1);
81 modulesManager
.stop(nameVersion
);
83 return Status
.OK_STATUS
;
86 protected void canceling() {
87 getThread().interrupt();
92 job
= new Job("Start " + nameVersion
) {
93 protected IStatus
run(IProgressMonitor monitor
) {
94 monitor
.beginTask("Start " + nameVersion
, 1);
95 modulesManager
.start(nameVersion
);
97 return Status
.OK_STATUS
;
100 protected void canceling() {
101 getThread().interrupt();
108 } catch (RepositoryException e
) {
109 throw new SlcException("Cannot start " + node
, e
);