Search in sources :

Example 31 with GraphicalViewer

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;
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Example 32 with GraphicalViewer

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;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) GraphicalViewer(org.eclipse.gef.GraphicalViewer) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GroupingContainerEditPart(org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart)

Example 33 with GraphicalViewer

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);
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) LinkingContainerEditpart(org.csstudio.opibuilder.widgets.editparts.LinkingContainerEditpart) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 34 with GraphicalViewer

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphicalViewer(org.eclipse.gef.GraphicalViewer) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) Job(org.eclipse.core.runtime.jobs.Job)

Example 35 with GraphicalViewer

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();
}
Also used : ImporterTopLevel(org.mozilla.javascript.ImporterTopLevel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphicalViewer(org.eclipse.gef.GraphicalViewer) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ScriptableObject(org.mozilla.javascript.ScriptableObject) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

GraphicalViewer (org.eclipse.gef.GraphicalViewer)36 ArrayList (java.util.ArrayList)11 List (java.util.List)10 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)10 EditPart (org.eclipse.gef.EditPart)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)7 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)6 IGraphicalNode (org.talend.core.ui.process.IGraphicalNode)5 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)4 ZoomManager (org.eclipse.gef.editparts.ZoomManager)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IProcess (org.talend.core.model.process.IProcess)4 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)4 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 Process (org.talend.designer.core.ui.editor.process.Process)4 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 PlatformObject (org.eclipse.core.runtime.PlatformObject)3