Search in sources :

Example 1 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService in project AGREE by loonwerks.

the class StepBackwardHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        final SimulationUIService simulationUIService = Objects.requireNonNull((SimulationUIService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(SimulationUIService.class), "Unable to retrieve simulation UI service");
        final SimulatorState simulatorState = simulationUIService.getCurrentState();
        final SimulationEngine engine = simulatorState.getSimulationEngine();
        if (engine != null && engine.getCurrentState().canStepBackward()) {
            engine.stepBackward();
        }
    } catch (final Exception ex) {
        final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Error", ex);
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
    }
    return null;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) SimulatorState(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService in project AGREE by loonwerks.

the class StopHandler method execute.

public void execute() {
    try {
        final SimulationService simulationService = Objects.requireNonNull((SimulationService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(SimulationService.class), "Unable to retrieve simulation service");
        final SimulationUIService simulationUIService = Objects.requireNonNull((SimulationUIService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(SimulationUIService.class), "Unable to retrieve simulation UI service");
        final SimulatorState simulatorState = simulationUIService.getCurrentState();
        final SimulationEngine engine = simulatorState.getSimulationEngine();
        if (engine != null) {
            simulationService.dispose(engine);
        }
    } catch (final Exception ex) {
        final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Error", ex);
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
    }
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) SimulatorState(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState) SimulationService(edu.uah.rsesc.aadlsimulator.services.SimulationService) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 3 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService in project AGREE by loonwerks.

the class SimulatorHandlerHelper method startSimulator.

public static Object startSimulator(final ExecutionEvent event, final String engineTypeId) {
    try {
        final SimulationUIService simulationUiService = Objects.requireNonNull(EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(SimulatorHandlerHelper.class).getBundleContext()).get(SimulationUIService.class), "unable to get simulation UI service");
        if (simulationUiService.getCurrentState().getSimulationEngine() != null) {
            final MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
            messageBox.setMessage("A simulation is already active. Do you want to stop the current simulation?");
            messageBox.setText("Stop Current Simulation");
            if (messageBox.open() == SWT.NO) {
                return null;
            }
        }
        if (event.getApplicationContext() instanceof IEvaluationContext) {
            final IEvaluationContext appContext = (IEvaluationContext) event.getApplicationContext();
            final ISelection selection = (ISelection) appContext.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
            final SimulationLaunchShortcut launchShortcut = new SimulationLaunchShortcut();
            launchShortcut.launch(selection, engineTypeId, ILaunchManager.RUN_MODE);
        }
    } catch (final Exception ex) {
        final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(SimulatorHandlerHelper.class).getSymbolicName(), "Error", ex);
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
    }
    return null;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ISelection(org.eclipse.jface.viewers.ISelection) SimulationLaunchShortcut(edu.uah.rsesc.aadlsimulator.ui.launch.SimulationLaunchShortcut) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 4 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService in project AGREE by loonwerks.

the class SimulatorTooltipContributor method addTooltipContents.

@Override
public void addTooltipContents(final TooltipContributorContext ctx) {
    final Object bo = ctx.getBusinessObjectContext().getBusinessObject();
    final SimulationUIService simulationUiService = Objects.requireNonNull(EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationUIService.class), "unable to get simulation UI service");
    final SimulatorState simulatorState = simulationUiService.getCurrentState();
    if (simulatorState.getEngineState() != null) {
        final SimulationEngineState engineState = simulatorState.getEngineState();
        if (engineState.getNumberOfFrames() > 0) {
            if (bo instanceof FeatureInstance || bo instanceof ComponentInstance) {
                final InstanceObject io = (InstanceObject) bo;
                // Compare the references from the diagram and simulation system instances. Only show tooltip if they match
                // This will ensure that the tooltips only appear for diagrams of instances of the same component implementation
                final URI diagramSystemInstanceUri = getResourceUri(io.getSystemInstance());
                final URI simulationSystemInstanceUri = getResourceUri(simulatorState.getSimulationEngine().getSystemInstance());
                if (diagramSystemInstanceUri != null && diagramSystemInstanceUri.equals(simulationSystemInstanceUri)) {
                    final int frameIndex = simulatorState.getSelectedFrameIndex() == SimulatorState.NO_FRAME_INDEX_SELECTED ? engineState.getNumberOfFrames() - 1 : simulatorState.getSelectedFrameIndex();
                    if (frameIndex < engineState.getNumberOfFrames()) {
                        // Handle the root instance object as a special case because there will not be a state element for it.
                        if (io == io.getSystemInstance()) {
                            final StyledText st = new StyledText(ctx.getTooltip(), SWT.NONE);
                            st.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                            addTooltipInfo(st, engineState, frameIndex, io.getName(), null, engineState.getRootElements(), io, INDENT_SIZE);
                        } else {
                            final Object stateElement = engineState.findElement(io);
                            if (stateElement != null) {
                                final StyledText st = new StyledText(ctx.getTooltip(), SWT.NONE);
                                st.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                                addStateElementsInfo(st, engineState, frameIndex, Collections.singleton(stateElement), io, INDENT_SIZE);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) InstanceObject(org.osate.aadl2.instance.InstanceObject) StyledText(org.eclipse.swt.custom.StyledText) SimulationEngineState(edu.uah.rsesc.aadlsimulator.SimulationEngineState) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) SimulatorState(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) URI(org.eclipse.emf.common.util.URI)

Example 5 with SimulationUIService

use of edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService in project AGREE by loonwerks.

the class OpenGraphicalViewHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        // Open the graphical editor
        final SimulationUIService simulationUiService = (SimulationUIService) Objects.requireNonNull(PlatformUI.getWorkbench().getService(SimulationUIService.class), "unable to get simulation UI service");
        final GraphicalEditorService editorService = Objects.requireNonNull((GraphicalEditorService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(GraphicalEditorService.class), "unable to retrieve Graphical Editor Service");
        final SimulationEngine engine = simulationUiService.getCurrentState().getSimulationEngine();
        if (engine != null && engine.getSystemInstance() != null) {
            editorService.openBusinessObject(engine.getSystemInstance());
        }
        ;
    } catch (final Exception ex) {
        final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Error", ex);
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
    }
    return null;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) GraphicalEditorService(org.osate.ge.services.GraphicalEditorService) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

SimulationUIService (edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService)16 IStatus (org.eclipse.core.runtime.IStatus)9 Status (org.eclipse.core.runtime.Status)9 SimulatorState (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState)8 ExecutionException (org.eclipse.core.commands.ExecutionException)8 SimulationEngine (edu.uah.rsesc.aadlsimulator.SimulationEngine)6 SimulationEngineState (edu.uah.rsesc.aadlsimulator.SimulationEngineState)4 AGREESimulationEngine (edu.uah.rsesc.aadlsimulator.agree.engine.AGREESimulationEngine)3 SimulationService (edu.uah.rsesc.aadlsimulator.services.SimulationService)3 SimulatorStateListener (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener)3 Shell (org.eclipse.swt.widgets.Shell)3 InstanceObject (org.osate.aadl2.instance.InstanceObject)3 SelectStepsDialog (edu.uah.rsesc.aadlsimulator.ui.dialogs.SelectStepsDialog)2 SimulationLaunchShortcut (edu.uah.rsesc.aadlsimulator.ui.launch.SimulationLaunchShortcut)2 StepForwardCanceledException (edu.uah.rsesc.aadlsimulator.ui.services.StepForwardCanceledException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 URI (org.eclipse.emf.common.util.URI)2 PartInitException (org.eclipse.ui.PartInitException)2 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)2