Package de.innovationgate.eclipse.wgadesigner.actions

Source Code of de.innovationgate.eclipse.wgadesigner.actions.RestartWGARuntime

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.actions;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;
import de.innovationgate.eclipse.wgadesigner.tomcat.TomcatUtils;

public class RestartWGARuntime implements IWorkbenchWindowActionDelegate {
 
  public void dispose() {
  }

  public void init(IWorkbenchWindow window) {
  }
 
  public void run(IAction action){
    call();
  }

  public static void call() {
    final WGARuntime temp = TomcatUtils.getInstance().getCurrentRuntime();
    if (temp != null && TomcatUtils.getInstance().isRunning(temp)) {
      Job job = new Job("WGA Runtime restart") {
 
        @Override
        protected IStatus run(IProgressMonitor monitor) {
          try {
            monitor.beginTask("Restarting WGA runtime '" + temp.getName() + "'.", 2);
            TomcatUtils.getInstance().stop(new SubProgressMonitor(monitor, 1));   
            TomcatUtils.getInstance().start(temp, new SubProgressMonitor(monitor, 1));
            return Status.OK_STATUS;
          } catch (Exception e) {
            return new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "Unable to restart WGA runtime '" + temp.getName() + "'.", e);
          } finally {
            monitor.done();
          }
        }
       
      };
      job.setPriority(Job.SHORT);
      job.schedule();
    }
  }

  public void selectionChanged(IAction action, ISelection selection) {
    action.setEnabled(TomcatUtils.getInstance().isRunning());
  }



}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.actions.RestartWGARuntime

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.