Search in sources :

Example 1 with SimulationEngine

use of edu.uah.rsesc.aadlsimulator.SimulationEngine in project AGREE by loonwerks.

the class VariablesView method fillContextMenu.

// Fill context menu dynamically
private void fillContextMenu(final MenuManager contextMenu, final Tree tree) {
    if (treeSelectionTracker.isSelectionValid()) {
        final int selectedColumnIndex = treeSelectionTracker.getSelectedColumnIndex();
        final int valueColumnsSize = valueColumns.size();
        final int valueColumnIndex = selectedColumnIndex - (treeViewer.getTree().getColumnCount() - valueColumnsSize);
        final SimulationEngine engine = simulationUiService.getCurrentState().getSimulationEngine();
        // Create the Show in Graphical View Menu Item
        if (selectedColumnIndex == VARIABLE_NAME_COLUMN_INDEX) {
            final Object element = treeSelectionTracker.getSelectedTreeItemData();
            final InstanceObject io = (engine != null && engine.getCurrentState() != null) ? engine.getCurrentState().getElementInstanceObject(element) : null;
            if (io != null) {
                contextMenu.add(new Action("Show in Graphical View") {

                    @Override
                    public void run() {
                        showInGraphicalView(io);
                    }
                });
            }
            // Populate context menu using command extensions
            final CommandContext cmdCtx = new SimpleCommandContext(element, engine.getCurrentState(), engine);
            for (final Command cmd : extService.getCommands()) {
                if (cmd.isAvailable(cmdCtx)) {
                    contextMenu.add(new Action(cmd.getLabel(cmdCtx)) {

                        @Override
                        public boolean isEnabled() {
                            return cmd.isActivatable(cmdCtx);
                        }

                        @Override
                        public void run() {
                            cmd.activate(cmdCtx);
                        }
                    });
                }
            }
        }
        // Highlight Menu
        final MenuManager subMenu = new MenuManager("Highlight");
        if (valueColumnIndex >= 0) {
            final int frameIndex = valueColumns.get(valueColumnIndex).getFrameIndex();
            final Object treeItemData = treeSelectionTracker.getSelectedTreeItemData();
            ImageDescriptor imageDesc = ImageDescriptor.createFromImage(greenImage);
            subMenu.add(new Action("Green", imageDesc) {

                @Override
                public void run() {
                    highlightCell(treeItemData, frameIndex, green);
                }
            });
            imageDesc = ImageDescriptor.createFromImage(redImage);
            subMenu.add(new Action("Red", imageDesc) {

                @Override
                public void run() {
                    highlightCell(treeItemData, frameIndex, red);
                }
            });
            imageDesc = ImageDescriptor.createFromImage(yellowImage);
            subMenu.add(new Action("Yellow", imageDesc) {

                @Override
                public void run() {
                    highlightCell(treeItemData, frameIndex, yellow);
                }
            });
            if (customRgb != null) {
                fillColorIconImage(customColorImage, customRgb);
                imageDesc = ImageDescriptor.createFromImage(customColorImage);
                subMenu.add(new Action("Previous", imageDesc) {

                    @Override
                    public void run() {
                        highlightCell(treeItemData, frameIndex, customRgb);
                    }
                });
            }
            subMenu.add(new Action("Custom...") {

                @Override
                public void run() {
                    final Shell shell = new Shell();
                    final Rectangle rect = tree.getParent().getShell().getBounds();
                    // offset width and height of color dialog box from center of screen/parent shell
                    shell.setLocation((rect.x + rect.width / 2) - 150, (rect.y + rect.height / 2) - 250);
                    final ColorDialog colorDialog = new ColorDialog(shell);
                    colorDialog.open();
                    if (colorDialog.getRGB() != null) {
                        final RGB cellColor = colorDialog.getRGB();
                        highlightCell(treeItemData, frameIndex, cellColor);
                        customRgb = cellColor;
                    }
                }
            });
            contextMenu.add(subMenu);
            final CellColorInfo cellColorInfo = getCellColorInfo(treeItemData, frameIndex);
            if (cellColorInfo != null) {
                final CellColorInfo removeCellColorInfo = cellColorInfo;
                contextMenu.add(new Action("Reset Highlight") {

                    @Override
                    public void run() {
                        if (treeViewer != null) {
                            cellColorInfos.remove(removeCellColorInfo);
                            treeViewer.getTree().redraw();
                        }
                    }
                });
            }
        }
        // Reset all Highlights
        if (!cellColorInfos.isEmpty()) {
            // Resets tree, erases highlights
            contextMenu.add(new Action("Reset All Highlights") {

                @Override
                public void run() {
                    final MessageBox dialog = new MessageBox(tree.getShell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
                    dialog.setText("Reset All Highlights");
                    dialog.setMessage("Are you sure you want to reset all highlighted cells?");
                    if (dialog.open() == SWT.OK) {
                        if (treeViewer != null) {
                            cellColorInfos.clear();
                            treeViewer.getTree().redraw();
                        }
                    }
                }
            });
        }
    }
}
Also used : Action(org.eclipse.jface.action.Action) SimpleCommandContext(edu.uah.rsesc.aadlsimulator.ui.ext.SimpleCommandContext) CommandContext(edu.uah.rsesc.aadlsimulator.ui.ext.CommandContext) Rectangle(org.eclipse.swt.graphics.Rectangle) RGB(org.eclipse.swt.graphics.RGB) Point(org.eclipse.swt.graphics.Point) InputConstraint(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.InputConstraint) MessageBox(org.eclipse.swt.widgets.MessageBox) SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) InstanceObject(org.osate.aadl2.instance.InstanceObject) Shell(org.eclipse.swt.widgets.Shell) ColorDialog(org.eclipse.swt.widgets.ColorDialog) SimpleCommandContext(edu.uah.rsesc.aadlsimulator.ui.ext.SimpleCommandContext) Command(edu.uah.rsesc.aadlsimulator.ui.ext.Command) MenuManager(org.eclipse.jface.action.MenuManager) InstanceObject(org.osate.aadl2.instance.InstanceObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Example 2 with SimulationEngine

use of edu.uah.rsesc.aadlsimulator.SimulationEngine in project AGREE by loonwerks.

the class VariablesView method showInGraphicalView.

private void showInGraphicalView(final InstanceObject io) {
    assert (io != null);
    // Open the graphical editor
    final GraphicalEditorService editorService = Objects.requireNonNull(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(GraphicalEditorService.class), "unable to retrieve Graphical Editor Service");
    final SimulationEngine engine = simulationUiService.getCurrentState().getSimulationEngine();
    if (engine != null && engine.getSystemInstance() != null) {
        final GraphicalEditor editor = editorService.openBusinessObject(engine.getSystemInstance());
        editor.selectDiagramElementsForBusinessObject(io);
    }
    ;
}
Also used : SimulationEngine(edu.uah.rsesc.aadlsimulator.SimulationEngine) GraphicalEditorService(org.osate.ge.services.GraphicalEditorService) GraphicalEditor(org.osate.ge.GraphicalEditor)

Example 3 with SimulationEngine

use of edu.uah.rsesc.aadlsimulator.SimulationEngine 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 4 with SimulationEngine

use of edu.uah.rsesc.aadlsimulator.SimulationEngine 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 5 with SimulationEngine

use of edu.uah.rsesc.aadlsimulator.SimulationEngine 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

SimulationEngine (edu.uah.rsesc.aadlsimulator.SimulationEngine)11 SimulationUIService (edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 SimulatorState (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState)5 ExecutionException (org.eclipse.core.commands.ExecutionException)5 SimulationService (edu.uah.rsesc.aadlsimulator.services.SimulationService)4 SimulatorStateListener (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener)3 Shell (org.eclipse.swt.widgets.Shell)3 SimulationEngineState (edu.uah.rsesc.aadlsimulator.SimulationEngineState)2 SimulationEngineChangeListener (edu.uah.rsesc.aadlsimulator.services.SimulationEngineChangeListener)2 SelectStepsDialog (edu.uah.rsesc.aadlsimulator.ui.dialogs.SelectStepsDialog)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 EObject (org.eclipse.emf.ecore.EObject)2 GraphicalEditorService (org.osate.ge.services.GraphicalEditorService)2 NotificationHandler (edu.uah.rsesc.aadlsimulator.NotificationHandler)1 Rational (edu.uah.rsesc.aadlsimulator.Rational)1 SimulationEngineNotification (edu.uah.rsesc.aadlsimulator.SimulationEngineNotification)1