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