Search in sources :

Example 1 with StopHandler

use of edu.uah.rsesc.aadlsimulator.ui.handlers.StopHandler in project AGREE by loonwerks.

the class SimulationLaunchShortcut method launch.

public ILaunch launch(final ComponentImplementation componentImplementation, String engineTypeId, final String mode) throws CoreException {
    if (engineTypeId == null) {
        final SimulationService simulationService = Objects.requireNonNull(PlatformUI.getWorkbench().getService(SimulationService.class), "Unable to retrieve simulation service");
        final EngineType engineType = simulationService.getCompatibleEngineType(componentImplementation);
        if (engineType == null) {
            StatusManager.getManager().handle(new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Unable to find compatible simulation engine for " + componentImplementation.getQualifiedName()), StatusManager.BLOCK);
            return null;
        }
        engineTypeId = engineType.getId();
    }
    // Stop the current simulation
    new StopHandler().execute();
    final ILaunchConfigurationType configType = getLaunchConfigurationType();
    // Search for an existing launch configuration
    final List<ILaunchConfiguration> launchConfigs = getLaunchConfigurations(configType, componentImplementation, engineTypeId);
    ILaunchConfiguration launchConfig = launchConfigs.size() > 0 ? launchConfigs.get(0) : null;
    if (launchConfig == null) {
        final ILaunchConfigurationWorkingCopy wcLaunchConf = configType.newInstance(null, DebugPlugin.getDefault().getLaunchManager().generateLaunchConfigurationName(componentImplementation.getQualifiedName()));
        // Set attributes, etc for the launch configuration
        wcLaunchConf.setAttribute(SimulationLaunchConfigurationAttributes.COMPONENT_IMPLEMENTATION_NAME, componentImplementation.getQualifiedName());
        wcLaunchConf.setAttribute(SimulationLaunchConfigurationAttributes.PROJECT_NAME, getProjectName(componentImplementation.eResource()));
        if (engineTypeId != null) {
            wcLaunchConf.setAttribute(SimulationLaunchConfigurationAttributes.ENGINE_TYPE_ID, engineTypeId);
        }
        launchConfig = wcLaunchConf;
    }
    // Launch the launch configuration
    return DebugUITools.buildAndLaunch(launchConfig, mode, new NullProgressMonitor());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) StopHandler(edu.uah.rsesc.aadlsimulator.ui.handlers.StopHandler) EngineType(edu.uah.rsesc.aadlsimulator.services.EngineType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService)

Aggregations

EngineType (edu.uah.rsesc.aadlsimulator.services.EngineType)1 SimulationService (edu.uah.rsesc.aadlsimulator.services.SimulationService)1 StopHandler (edu.uah.rsesc.aadlsimulator.ui.handlers.StopHandler)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1