use of edu.uah.rsesc.aadlsimulator.ui.ext.SimpleCommandContext 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.ui.ext.SimpleCommandContext in project AGREE by loonwerks.
the class PropertiesView method createView.
@PostConstruct
void createView(final Composite parent) {
propertiesStateViewer = new PropertiesStateViewer(parent);
propertiesStateViewer.addPropertyMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(final IMenuManager manager) {
// Only populate the menu if a single property is selected
final IStructuredSelection selection = propertiesStateViewer.getSelection();
if (selection.size() == 1 && engineState != null && engine != null) {
final Object selectedProperty = selection.getFirstElement();
// Populate context menu using command extensions
final CommandContext cmdCtx = new SimpleCommandContext(selectedProperty, engineState, engine);
for (final Command cmd : extService.getCommands()) {
if (cmd.isAvailable(cmdCtx)) {
manager.add(new Action(cmd.getLabel(cmdCtx)) {
@Override
public boolean isEnabled() {
return cmd.isActivatable(cmdCtx);
}
@Override
public void run() {
cmd.activate(cmdCtx);
}
});
}
}
}
}
});
// Add listener and populate UI with current state
simulationUiService.addStateChangeListener(stateListener);
stateListener.onSimulatorStateChanged(simulationUiService.getCurrentState());
}
Aggregations