use of org.eclipse.gef.GraphicalViewer in project yamcs-studio by yamcs.
the class SelectParentHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
GraphicalViewer viewer = HandlerUtil.getActivePart(event).getAdapter(GraphicalViewer.class);
if (viewer == null)
return null;
ISelection currentSelection = viewer.getSelection();
if (currentSelection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) currentSelection).getFirstElement();
if (element instanceof AbstractBaseEditPart && !(element instanceof DisplayEditpart)) {
if (((AbstractBaseEditPart) element).getParent().isSelectable())
((AbstractBaseEditPart) element).getViewer().select(((AbstractBaseEditPart) element).getParent());
else
ConsoleUtil.writeWarning("Parent of the selected widget is unselectable. Its grandparent may be locked.");
}
}
return null;
}
use of org.eclipse.gef.GraphicalViewer in project yamcs-studio by yamcs.
the class LockUnlockChildrenHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
GraphicalViewer viewer = HandlerUtil.getActivePart(event).getAdapter(GraphicalViewer.class);
if (viewer == null)
return null;
ISelection currentSelection = viewer.getSelection();
if (currentSelection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) currentSelection).getFirstElement();
if (element instanceof GroupingContainerEditPart) {
CommandStack commandStack = HandlerUtil.getActivePart(event).getAdapter(CommandStack.class);
if (commandStack != null)
commandStack.execute(LockUnlockChildrenAction.createLockUnlockCommand(((GroupingContainerEditPart) element).getWidgetModel()));
}
}
return null;
}
use of org.eclipse.gef.GraphicalViewer in project yamcs-studio by yamcs.
the class LinkingContainerModel method scaleChildren.
/**
* Scale its children.
*/
@Override
public void scaleChildren() {
if (isAutoFit())
return;
// The linking container model doesn't hold its children actually, so it
// has to ask editpart to get its children.
GraphicalViewer viewer = getRootDisplayModel().getViewer();
if (viewer == null)
return;
LinkingContainerEditpart editpart = (LinkingContainerEditpart) viewer.getEditPartRegistry().get(this);
Dimension size = getSize();
double newWidthRatio = size.width / (double) getOriginSize().width;
double newHeightRatio = size.height / (double) getOriginSize().height;
boolean allowScale = true;
if (getDisplayModel() != null) {
allowScale = getDisplayModel().getDisplayScaleData().isAutoScaleWidgets();
if (allowScale) {
int minWidth = getDisplayModel().getDisplayScaleData().getMinimumWidth();
if (minWidth < 0) {
minWidth = getDisplayModel().getWidth();
}
int minHeight = getDisplayModel().getDisplayScaleData().getMinimumHeight();
if (minHeight < 0) {
minHeight = getDisplayModel().getHeight();
}
if (getWidth() * newWidthRatio < minWidth)
newWidthRatio = minWidth / (double) getOriginSize().width;
if (getHeight() * newHeightRatio < minHeight)
newHeightRatio = minHeight / (double) getOriginSize().height;
}
}
if (allowScale)
for (Object child : editpart.getChildren()) ((AbstractBaseEditPart) child).getWidgetModel().scale(newWidthRatio, newHeightRatio);
}
use of org.eclipse.gef.GraphicalViewer in project yamcs-studio by yamcs.
the class ExecuteJavaScriptJdkAction method run.
@Override
public void run() {
if (scriptEngine == null) {
try {
scriptEngine = ScriptStoreFactory.getJavaScriptEngine();
} catch (Exception exception) {
ErrorHandlerUtil.handleError("Failed to get Script Context", exception);
return;
}
scriptScope = scriptEngine.createBindings();
GraphicalViewer viewer = getWidgetModel().getRootDisplayModel().getViewer();
if (viewer != null) {
Object obj = viewer.getEditPartRegistry().get(getWidgetModel());
if (obj != null && obj instanceof AbstractBaseEditPart) {
scriptScope.put(ScriptService.DISPLAY, viewer.getContents());
scriptScope.put(ScriptService.WIDGET, obj);
}
}
}
Job job = new Job("Execute JavaScript") {
@Override
protected IStatus run(IProgressMonitor monitor) {
String taskName = isEmbedded() ? "Execute JavaScript" : "Connecting to " + getAbsolutePath();
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
runTask();
monitor.done();
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
use of org.eclipse.gef.GraphicalViewer in project yamcs-studio by yamcs.
the class ExecuteJavaScriptRhinoAction method run.
@Override
public void run() {
if (scriptContext == null) {
try {
scriptContext = ScriptStoreFactory.getRhinoContext();
} catch (Exception exception) {
ErrorHandlerUtil.handleError("Failed to get Script Context", exception);
return;
}
scriptScope = new ImporterTopLevel(scriptContext);
GraphicalViewer viewer = getWidgetModel().getRootDisplayModel().getViewer();
if (viewer != null) {
Object obj = viewer.getEditPartRegistry().get(getWidgetModel());
if (obj != null && obj instanceof AbstractBaseEditPart) {
Object displayObject = Context.javaToJS(viewer.getContents(), scriptScope);
Object widgetObject = Context.javaToJS(obj, scriptScope);
ScriptableObject.putProperty(scriptScope, ScriptService.DISPLAY, displayObject);
ScriptableObject.putProperty(scriptScope, ScriptService.WIDGET, widgetObject);
}
}
}
Job job = new Job("Execute JavaScript") {
@Override
protected IStatus run(IProgressMonitor monitor) {
String taskName = isEmbedded() ? "Execute JavaScript" : "Connecting to " + getAbsolutePath();
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
runTask();
monitor.done();
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
Aggregations