/** * Copyright (c) 2015 INRIA. * 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: * - Fawaz PARAISO */ package org.occiware.clouddesigner.occi.hypervisor.design.services; import java.lang.reflect.InvocationTargetException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.xtext.xbase.lib.Exceptions; import org.occiware.clouddesigner.occi.Configuration; import org.occiware.clouddesigner.occi.hypervisor.HypervisorFactory; import org.occiware.clouddesigner.occi.hypervisor.Machine; import org.occiware.clouddesigner.occi.hypervisor.connector.libvirt.ExecutableHypervisorFactory; import org.occiware.clouddesigner.occi.hypervisor.connector.libvirt.ExecutableHypervisorModel; @SuppressWarnings("all") public class HypervisorServices { private final HypervisorFactory init = ExecutableHypervisorFactory.init(); public void start(final EObject eo) { try { IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if ((eo instanceof Machine)) { Machine machine = ((Machine) eo); final ExecutableHypervisorModel main = new ExecutableHypervisorModel(machine); main.start(); } } }; Shell _shell = this.getShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(_shell); dialog.run(false, true, runnable); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } public void stop(final EObject eo) { try { IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if ((eo instanceof Machine)) { Machine machine = ((Machine) eo); final ExecutableHypervisorModel main = new ExecutableHypervisorModel(machine); main.stop(); } } }; Shell _shell = this.getShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(_shell); dialog.run(false, true, runnable); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } /** * Popup menu restart action. */ public void restart(final EObject eo) { try { IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if ((eo instanceof Machine)) { Machine machine = ((Machine) eo); final ExecutableHypervisorModel main = new ExecutableHypervisorModel(machine); main.restart(); } } }; Shell _shell = this.getShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(_shell); dialog.run(false, true, runnable); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } /** * Popup menu importModel action. */ public void importModel(final Configuration conf) { try { IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { final ExecutableHypervisorModel main = new ExecutableHypervisorModel(conf); main.importModel(); } }; Shell _shell = this.getShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(_shell); dialog.run(false, true, runnable); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } public Shell getShell() { Display _current = Display.getCurrent(); return _current.getActiveShell(); } }