Search in sources :

Example 6 with AbstractGraphicalEditPart

use of org.eclipse.gef.editparts.AbstractGraphicalEditPart in project tdi-studio-se by Talend.

the class XmlDragSourceListener method getTemplate.

/**
     * 
     * DOC talend Comment method "getTemplate".
     * 
     * @param event
     * @return the validate drag able node list
     */
@Override
protected Object getTemplate(DragSourceEvent event) {
    final RootEditPart rootEditPart = getViewer().getRootEditPart();
    if (rootEditPart instanceof AbstractGraphicalEditPart) {
        AbstractGraphicalEditPart graphicPart = (AbstractGraphicalEditPart) rootEditPart;
        final IFigure figure = graphicPart.getFigure();
        final IFigure findFigureAt = figure.findFigureAt(new Point(event.x, event.y));
        if (findFigureAt instanceof ISash) {
            return findFigureAt;
        }
    }
    List<EditPart> filtedSelection = new ArrayList<EditPart>();
    for (Object part : getViewer().getSelectedEditParts()) {
        if (part instanceof TreeNodeEditPart || part instanceof VarNodeEditPart) {
            filtedSelection.add((EditPart) part);
        }
    }
    if (filtedSelection == null || filtedSelection.isEmpty()) {
        return null;
    }
    List toTransfer = new ArrayList();
    TransferdType type = null;
    List<TableEntityPart> partList = new ArrayList<TableEntityPart>();
    EditPart lastSelection = filtedSelection.get(filtedSelection.size() - 1);
    if (lastSelection instanceof TreeNodeEditPart && !(lastSelection instanceof OutputTreeNodeEditPart)) {
        type = TransferdType.INPUT;
    } else if (lastSelection instanceof VarNodeEditPart) {
        type = TransferdType.VAR;
    }
    if (type != null) {
        if (filtedSelection.size() > 1) {
            partList.addAll(lastSelection.getParent().getChildren());
            Map<EditPart, Integer> partAndIndex = new HashMap<EditPart, Integer>();
            if (type == TransferdType.INPUT) {
                for (EditPart treePart : filtedSelection) {
                    if (!XmlMapUtil.isDragable((TreeNode) treePart.getModel())) {
                        return null;
                    }
                }
                MapperTablePart abstractInOutTreePart = MapperUtils.getMapperTablePart((TableEntityPart) lastSelection);
                if (abstractInOutTreePart != null) {
                    partList = MapperUtils.getFlatChildrenPartList(abstractInOutTreePart);
                }
            } else {
                partList.addAll(lastSelection.getParent().getChildren());
            }
            for (EditPart selected : filtedSelection) {
                int indexOf = partList.indexOf(selected);
                if (indexOf != -1) {
                    partAndIndex.put(selected, indexOf);
                    int index = 0;
                    for (int i = 0; i < toTransfer.size(); i++) {
                        if (indexOf > partAndIndex.get(toTransfer.get(i))) {
                            index = i + 1;
                        }
                    }
                    toTransfer.add(index, selected);
                }
            }
        } else {
            if (lastSelection.getModel() instanceof TreeNode && !XmlMapUtil.isDragable((TreeNode) lastSelection.getModel())) {
                return null;
            }
            toTransfer.add(lastSelection);
        }
        return new TransferedObject(toTransfer, type);
    }
    return null;
}
Also used : VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) TableEntityPart(org.talend.designer.gefabstractmap.part.TableEntityPart) HashMap(java.util.HashMap) ISash(org.talend.designer.gefabstractmap.figures.sash.ISash) ArrayList(java.util.ArrayList) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) RootEditPart(org.eclipse.gef.RootEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point) MapperTablePart(org.talend.designer.gefabstractmap.part.MapperTablePart) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) Point(org.eclipse.draw2d.geometry.Point) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) ArrayList(java.util.ArrayList) List(java.util.List) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) RootEditPart(org.eclipse.gef.RootEditPart) IFigure(org.eclipse.draw2d.IFigure) TransferdType(org.talend.designer.gefabstractmap.dnd.TransferdType)

Example 7 with AbstractGraphicalEditPart

use of org.eclipse.gef.editparts.AbstractGraphicalEditPart in project tdi-studio-se by Talend.

the class DragAndDropEditPolicy method showTargetFeedback.

@Override
public void showTargetFeedback(Request request) {
    if (request instanceof CreateNodeConnectionRequest) {
        CreateNodeConnectionRequest rq = (CreateNodeConnectionRequest) request;
        AbstractGraphicalEditPart targetEditPart = (AbstractGraphicalEditPart) rq.getTargetEditPart();
        // show feedback when insert new column
        if (rq.getNewObjectType() != null && targetEditPart != null) {
            Object model = targetEditPart.getModel();
            switch(rq.getNewObjectType()) {
                case DROP_INSERT_OUTPUT:
                case DROP_INSERT_VAR:
                    if (model instanceof OutputTreeNode || model instanceof VarNode) {
                        IFigure targetFigure = targetEditPart.getFigure();
                        if (targetFigure != null) {
                            if (indicator == null) {
                                indicator = new InsertionIndicator();
                            }
                            Rectangle copy = targetFigure.getBounds().getCopy();
                            Rectangle bounds = new Rectangle();
                            bounds.x = copy.x - 5;
                            bounds.y = copy.y - 5;
                            bounds.width = copy.width + 10;
                            bounds.height = 10;
                            indicator.setBounds(bounds);
                            getFeedbackLayer().add(indicator);
                        }
                    } else {
                        if (indicator != null && getFeedbackLayer() != null && indicator.getParent() == getFeedbackLayer()) {
                            getFeedbackLayer().remove(indicator);
                        }
                    }
                    break;
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) CreateNodeConnectionRequest(org.talend.designer.xmlmap.dnd.CreateNodeConnectionRequest) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)7 EditPart (org.eclipse.gef.EditPart)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IFigure (org.eclipse.draw2d.IFigure)2 Point (org.eclipse.draw2d.geometry.Point)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)2 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)2 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)2 CreateNodeConnectionRequest (org.talend.designer.xmlmap.dnd.CreateNodeConnectionRequest)2 HashMap (java.util.HashMap)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 ConnectionEditPart (org.eclipse.gef.ConnectionEditPart)1 NodeEditPart (org.eclipse.gef.NodeEditPart)1 RootEditPart (org.eclipse.gef.RootEditPart)1 AbstractConnectionEditPart (org.eclipse.gef.editparts.AbstractConnectionEditPart)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 ISubjobContainer (org.talend.core.model.process.ISubjobContainer)1