Search in sources :

Example 61 with EditPart

use of org.eclipse.gef.EditPart in project knime-core by knime.

the class PortGraphicalRoleEditPolicy method getConnectionCompleteCommand.

/**
 * This tries to complete the command to create a connection.
 *
 * {@inheritDoc}
 */
@Override
protected Command getConnectionCompleteCommand(final CreateConnectionRequest request) {
    // get the previously started command
    CreateConnectionCommand cmd = (CreateConnectionCommand) request.getStartCommand();
    if (cmd == null) {
        return null;
    }
    EditPart target = request.getTargetEditPart();
    if ((target instanceof NodeOutPortEditPart) || target instanceof WorkflowInPortEditPart) {
        return null;
    } else if (target instanceof NodeInPortEditPart || target instanceof WorkflowOutPortEditPart) {
        cmd.setTargetPortID(((AbstractPortEditPart) target).getIndex());
        cmd.setTargetNode((ConnectableEditPart) target.getParent());
    } else if (target instanceof NodeContainerEditPart) {
        if (cmd.wasStartedOnOutPort()) {
            cmd.setTargetPortID(-1);
            cmd.setTargetNode((NodeContainerEditPart) target);
        } else {
            cmd.setSourcePortID(-1);
            cmd.setSourceNode((NodeContainerEditPart) target);
        }
    } else {
        return null;
    }
    return cmd;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart)

Example 62 with EditPart

use of org.eclipse.gef.EditPart in project yamcs-studio by yamcs.

the class RuntimePatchedSelectionTool method handleButtonUp.

/**
 * Intercept middle clicks and restore original cursor if it has changed.
 */
@Override
protected boolean handleButtonUp(int button) {
    if (button == 2) {
        EditPart editPart = getTargetEditPart();
        if (editPart instanceof AbstractPVWidgetEditPart) {
            AbstractPVWidgetEditPart apvwep = (AbstractPVWidgetEditPart) editPart;
            IFigure figure = apvwep.getFigure();
            if (cursorChanged) {
                figure.setCursor(oldCursor);
                oldCursor = null;
                cursorChanged = false;
            }
        }
        return true;
    } else {
        return super.handleButtonUp(button);
    }
}
Also used : AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) EditPart(org.eclipse.gef.EditPart) IFigure(org.eclipse.draw2d.IFigure)

Example 63 with EditPart

use of org.eclipse.gef.EditPart in project yamcs-studio by yamcs.

the class RuntimePatchedSelectionTool method handleButtonDown.

/**
 * Intercept middle clicks and copy PV name to pastebuffer if available.
 * Change cursor to copy symbol.
 */
@Override
protected boolean handleButtonDown(int button) {
    if (button == 2) {
        EditPart editPart = getTargetEditPart();
        if (editPart instanceof AbstractPVWidgetEditPart) {
            AbstractPVWidgetEditPart apvwep = (AbstractPVWidgetEditPart) editPart;
            String pvName = ((AbstractPVWidgetModel) editPart.getModel()).getPVName();
            if (pvName != "" && pvName != null) {
                Display display = Display.getCurrent();
                Clipboard clipboard = new Clipboard(display);
                // Copies to middle button paste buffer,
                // to be pasted via another middle-button click
                clipboard.setContents(new Object[] { pvName }, new Transfer[] { TextTransfer.getInstance() }, DND.SELECTION_CLIPBOARD);
                // Copies to normal clipboard,
                // to be pasted via Ctrl-V or Edit/Paste
                clipboard.setContents(new String[] { pvName }, new Transfer[] { TextTransfer.getInstance() });
                clipboard.dispose();
                IFigure figure = apvwep.getFigure();
                oldCursor = figure.getCursor();
                figure.setCursor(ResourceUtil.getCopyPvCursor());
                cursorChanged = true;
            }
        }
        return true;
    } else {
        return super.handleButtonDown(button);
    }
}
Also used : AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) EditPart(org.eclipse.gef.EditPart) AbstractPVWidgetModel(org.csstudio.opibuilder.model.AbstractPVWidgetModel) Clipboard(org.eclipse.swt.dnd.Clipboard) Display(org.eclipse.swt.widgets.Display) IFigure(org.eclipse.draw2d.IFigure)

Example 64 with EditPart

use of org.eclipse.gef.EditPart in project yamcs-studio by yamcs.

the class AbstractContainerEditpart method registerBasePropertyChangeHandlers.

@Override
protected void registerBasePropertyChangeHandlers() {
    super.registerBasePropertyChangeHandlers();
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            MacrosInput macrosInput = (MacrosInput) newValue;
            LinkedHashMap<String, String> macrosMap = new LinkedHashMap<String, String>();
            if (macrosInput.isInclude_parent_macros()) {
                macrosMap.putAll(getWidgetModel().getParentMacroMap());
            }
            macrosMap.putAll(macrosInput.getMacrosMap());
            getWidgetModel().setMacroMap(macrosMap);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractContainerModel.PROP_MACROS, handler);
    layout();
    childrenPropertyChangeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getOldValue() instanceof Integer) {
                addChild(createChild(evt.getNewValue()), ((Integer) evt.getOldValue()).intValue());
                layout();
            } else if (evt.getOldValue() instanceof AbstractWidgetModel) {
                EditPart child = (EditPart) getViewer().getEditPartRegistry().get(evt.getOldValue());
                if (child != null) {
                    removeChild(child);
                    layout();
                }
            } else
                refreshChildren();
        }
    };
    getWidgetModel().getChildrenProperty().addPropertyChangeListener(childrenPropertyChangeListener);
    if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
        selectionPropertyChangeListener = new PropertyChangeListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                List<AbstractWidgetModel> widgets = (List<AbstractWidgetModel>) evt.getNewValue();
                List<EditPart> widgetEditparts = new ArrayList<EditPart>();
                for (AbstractWidgetModel w : widgets) {
                    EditPart e = (EditPart) getViewer().getEditPartRegistry().get(w);
                    if (e != null)
                        widgetEditparts.add(e);
                }
                if (!(Boolean) evt.getOldValue()) {
                    // append
                    getViewer().deselectAll();
                }
                for (EditPart editpart : widgetEditparts) {
                    if (editpart.isSelectable())
                        getViewer().appendSelection(editpart);
                }
            }
        };
        getWidgetModel().getSelectionProperty().addPropertyChangeListener(selectionPropertyChangeListener);
    }
}
Also used : MacrosInput(org.csstudio.opibuilder.util.MacrosInput) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) EditPart(org.eclipse.gef.EditPart) LinkedHashMap(java.util.LinkedHashMap) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) ArrayList(java.util.ArrayList) List(java.util.List) IFigure(org.eclipse.draw2d.IFigure)

Example 65 with EditPart

use of org.eclipse.gef.EditPart in project yamcs-studio by yamcs.

the class WidgetEditPartFactory method createEditPart.

@Override
public EditPart createEditPart(EditPart context, Object model) {
    EditPart part = getPartForModel(model);
    if (part != null) {
        part.setModel(model);
        if (part instanceof AbstractBaseEditPart) {
            ((AbstractBaseEditPart) part).setExecutionMode(executionMode);
            ((AbstractBaseEditPart) part).setSite(site);
        } else if (part instanceof WidgetConnectionEditPart)
            ((WidgetConnectionEditPart) part).setExecutionMode(executionMode);
    }
    return part;
}
Also used : EditPart(org.eclipse.gef.EditPart)

Aggregations

EditPart (org.eclipse.gef.EditPart)132 List (java.util.List)50 ArrayList (java.util.ArrayList)37 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)26 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)20 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)19 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)18 Point (org.eclipse.draw2d.geometry.Point)17 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)17 Command (org.eclipse.gef.commands.Command)16 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)16 ConnectionEditPart (org.eclipse.gef.ConnectionEditPart)15 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)14 Node (org.talend.designer.core.ui.editor.nodes.Node)13 RootEditPart (org.eclipse.gef.RootEditPart)11 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)11 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)11 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)10 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)10 INode (org.talend.core.model.process.INode)10