Package es.upm.dit.gsi.eclipse.jadex.adfmanager.actions

Source Code of es.upm.dit.gsi.eclipse.jadex.adfmanager.actions.LaunchWizardAction

/*******************************************************************************
* Copyright (c) 2011 Grupo de Sistemas Inteligentes (GSI) - DIT UPM
*
* 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
*******************************************************************************/
package es.upm.dit.gsi.eclipse.jadex.adfmanager.actions;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.progress.WorkbenchJob;
import es.upm.dit.gsi.eclipse.jadex.navigator.Child;

public class LaunchWizardAction implements IActionDelegate{
  ISelection _selection;

  public LaunchWizardAction()  {
    super();
  }
 
  @Override
  public void run(IAction action) {
    final IFile agentFile = getSelectedAgentFile();
    final IActionDelegate wizard = getActionToRun();
    WorkbenchJob job = new WorkbenchJob(Display.getCurrent(),"Launch Wizard") {
     
      @Override
      public IStatus runInUIThread(IProgressMonitor monitor) {
        final Action action = new Action() {};
        wizard.selectionChanged(action, new StructuredSelection(agentFile));
          wizard.run(action);
      return Status.OK_STATUS;
      }
    };
    job.schedule();
  }

  @Override
  public void selectionChanged(IAction action, ISelection selection) {
    _selection = selection;
  }
 
  private IActionDelegate getActionToRun(){
    String childType = getSelectedChild().getName();
    if(childType.equals("beliefs")){
      return new NewBeliefAction();
    }
    else if(childType.equals("capabilities")){
      return new NewCapability();
    }
    else if(childType.equals("configurations")){
      return new NewConfigurationAction();
    }
    else if(childType.equals("events")){
      return new NewEventAction();
    }
    else if(childType.equals("expressions")){
      return new NewExpressionAction();
    }
    else if(childType.equals("goals")){
      return new NewGoalAction();
    }
    else if(childType.equals("imports")){
      return null;
    }
    else if(childType.equals("plans")){
      return new NewPlanAction();
    }
    else if(childType.equals("properties")){
      return new NewPropertyAction();
    }
    return null;           
  }
 
  private IFile getSelectedAgentFile(){
    Child selChild = getSelectedChild();
    if(selChild != null){
      return selChild.getContainer();
    }
    return null;
  }
 
 
  private Child getSelectedChild(){
    if(_selection instanceof TreeSelection){
      Object selectedObject = ((TreeSelection) _selection).getFirstElement();
      if(selectedObject instanceof Child){
        return (Child) selectedObject;
      }
    }
    return null;
  }
}
TOP

Related Classes of es.upm.dit.gsi.eclipse.jadex.adfmanager.actions.LaunchWizardAction

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.