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;
}
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);
}
}
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;
}
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);
}
}
}
}
}
}
}
}
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;
}
Aggregations