Search in sources :

Example 6 with VarNodeEditPart

use of org.talend.designer.xmlmap.parts.VarNodeEditPart in project tdi-studio-se by Talend.

the class UpdateFilterExpressionCommand method execute.

@Override
public void execute() {
    AbstractInOutTree targetTree = (AbstractInOutTree) targetEditPart.getModel();
    String expression = targetTree.getExpressionFilter();
    if (objects.getToTransfer() != null) {
        for (Object obj : objects.getToTransfer()) {
            AbstractNode sourceNode = null;
            // INPUT == FILTER
            if (objects.getType() == TransferdType.INPUT) {
                TreeNodeEditPart part = (TreeNodeEditPart) obj;
                sourceNode = (TreeNode) part.getModel();
                if (expression == null) {
                    expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
                } else {
                    expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
                }
            } else // VARE == FILTER
            if (objects.getType() == TransferdType.VAR) {
                String tableName = "Var";
                VarNodeEditPart part = (VarNodeEditPart) obj;
                sourceNode = (VarNode) part.getModel();
                if (sourceNode.eContainer() instanceof VarTable) {
                    tableName = ((VarTable) sourceNode.eContainer()).getName();
                }
                if (expression == null) {
                    expression = tableName + "." + sourceNode.getName();
                } else {
                    expression = expression + " " + tableName + "." + sourceNode.getName();
                }
            }
            if (sourceNode != null) {
                targetTree.setExpressionFilter(expression);
                FilterConnection connection = XmlmapFactory.eINSTANCE.createFilterConnection();
                connection.setSource(sourceNode);
                connection.setTarget(targetTree);
                targetTree.getFilterIncomingConnections().add(connection);
                sourceNode.getFilterOutGoingConnections().add(connection);
                xmlMapData.getConnections().add(connection);
            }
        // check if need update outputTree InputLoopNodesTable
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 7 with VarNodeEditPart

use of org.talend.designer.xmlmap.parts.VarNodeEditPart 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 8 with VarNodeEditPart

use of org.talend.designer.xmlmap.parts.VarNodeEditPart in project tdi-studio-se by Talend.

the class XmlDropTargetListener method handleDrop.

@Override
protected void handleDrop() {
    final Object object = TemplateTransfer.getInstance().getObject();
    if (object == null || !(object instanceof TransferedObject)) {
        return;
    }
    updateTargetRequest();
    updateTargetEditPart();
    DropContextAnalyzer analyzer = new DropContextAnalyzer((TransferedObject) object, (AbstractGraphicalEditPart) getTargetEditPart(), getDropLocation());
    if (analyzer.isDropValid()) {
        NodeType selectedNodeType = NodeType.ELEMENT;
        DropType dropType = analyzer.getDropType();
        if (dropType == DropType.DROP_OUTPUT_DOC_CHILD && getTargetEditPart() instanceof OutputTreeNodeEditPart) {
            OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) getTargetEditPart()).getModel();
            Shell shell = getViewer().getControl().getShell();
            // if allNamespace , create output as namespace , if allsubTree , create output subtree , no need prompt
            boolean needPrompt = false;
            boolean hasSubTree = false;
            for (Object o : ((TransferedObject) object).getToTransfer()) {
                if (o instanceof VarNodeEditPart) {
                    needPrompt = true;
                } else if (o instanceof TreeNodeEditPart) {
                    TreeNode treeNode = (TreeNode) ((TreeNodeEditPart) o).getModel();
                    if (NodeType.ATTRIBUT.equals(treeNode.getNodeType())) {
                        needPrompt = true;
                    }
                    if (NodeType.ELEMENT.equals(treeNode.getNodeType())) {
                        if (treeNode.getChildren().isEmpty()) {
                            needPrompt = true;
                        } else {
                            hasSubTree = true;
                        }
                    }
                }
            }
            if (needPrompt) {
                DragAndDrogDialog selectDialog = new DragAndDrogDialog(shell, !targetOutputNode.getChildren().isEmpty());
                int open = selectDialog.open();
                if (open == Window.OK) {
                    if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
                        selectedNodeType = NodeType.ELEMENT;
                    } else if (DragAndDrogDialog.CREATE_AS_ATTRIBUTE.equals(selectDialog.getSelectValue())) {
                        selectedNodeType = NodeType.ATTRIBUT;
                    } else if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
                        selectedNodeType = NodeType.NAME_SPACE;
                    } else if (DragAndDrogDialog.CREATE_AS_TEXT.equals(selectDialog.getSelectValue())) {
                        dropType = DropType.DROP_EXPRESSION;
                    }
                } else {
                    return;
                }
            }
            if (dropType != DropType.DROP_EXPRESSION) {
                if (!targetOutputNode.getIncomingConnections().isEmpty() && ((selectedNodeType != NodeType.ATTRIBUT && selectedNodeType != NodeType.NAME_SPACE) || hasSubTree)) {
                    boolean canContinue = MessageDialog.openConfirm(null, "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element ?");
                    if (canContinue) {
                        MapperManager mapperManager = ((XmlMapGraphicViewer) getViewer()).getMapperManager();
                        if (mapperManager != null && mapperManager.getExternalData() != null) {
                            XmlMapUtil.detachNodeConnections(targetOutputNode, mapperManager.getExternalData(), false);
                        }
                    } else {
                        return;
                    }
                }
            }
        }
        NewNodeCreationFactory factory = new NewNodeCreationFactory(dropType, selectedNodeType);
        getCreateRequest().setFactory(factory);
    }
    if (getTargetEditPart() != null) {
        Command command = getCommand();
        if (command != null && command.canExecute()) {
            getViewer().getEditDomain().getCommandStack().execute(command);
        } else {
            getCurrentEvent().detail = DND.DROP_NONE;
        }
    } else {
        getCurrentEvent().detail = DND.DROP_NONE;
    }
    selectAddedObject();
}
Also used : VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) MapperManager(org.talend.designer.xmlmap.ui.tabs.MapperManager) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) Point(org.eclipse.draw2d.geometry.Point) Shell(org.eclipse.swt.widgets.Shell) Command(org.eclipse.gef.commands.Command) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) NodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) XmlMapGraphicViewer(org.talend.designer.xmlmap.editor.XmlMapGraphicViewer)

Example 9 with VarNodeEditPart

use of org.talend.designer.xmlmap.parts.VarNodeEditPart in project tdi-studio-se by Talend.

the class SearchZoneMapper method moveScrollBarZoneAtSelectedTableItem.

public void moveScrollBarZoneAtSelectedTableItem(Figure entry) {
    if (entry != null) {
        Rectangle bounds = entry.getBounds();
        int selection = bounds.y - 100;
        if (entry instanceof XmlmapTreeNodeFigure) {
            XmlmapTreeNodeFigure xmlMapTreeNodeFigure = (XmlmapTreeNodeFigure) entry;
            TreeNode treeNode = xmlMapTreeNodeFigure.getTreeNode();
            if (treeNode != null) {
                for (Adapter adapter : treeNode.eAdapters()) {
                    TreeNodeEditPart part = (TreeNodeEditPart) adapter;
                    XmlMapDataEditPart xmlMapDataEditPart = part.getMapDataEditPart();
                    if (adapter instanceof OutputTreeNodeEditPart) {
                        Viewport viewport = xmlMapDataEditPart.getOutputScroll().getViewport();
                        viewport.setViewLocation(viewport.getViewLocation().translate(bounds.x, selection));
                    } else if (adapter instanceof TreeNodeEditPart) {
                        Viewport viewport = xmlMapDataEditPart.getInputScroll().getViewport();
                        viewport.setViewLocation(viewport.getViewLocation().translate(bounds.x, selection));
                    }
                }
            }
        } else if (entry instanceof VarNodeFigure) {
            VarNodeFigure varNodeFigure = (VarNodeFigure) entry;
            VarNode varNode = varNodeFigure.getVarNode();
            if (varNode != null) {
                for (Adapter adapter : varNode.eAdapters()) {
                    VarNodeEditPart part = (VarNodeEditPart) adapter;
                    XmlMapDataEditPart xmlMapDataEditPart = part.getMapDataEditPart();
                    Viewport viewport = xmlMapDataEditPart.getVarScroll().getViewport();
                    viewport.setViewLocation(viewport.getViewLocation().translate(bounds.x, selection));
                }
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) VarNodeFigure(org.talend.designer.xmlmap.figures.varnode.VarNodeFigure) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Viewport(org.eclipse.draw2d.Viewport) Adapter(org.eclipse.emf.common.notify.Adapter) XmlmapTreeNodeFigure(org.talend.designer.xmlmap.figures.treeNode.XmlmapTreeNodeFigure) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) XmlMapDataEditPart(org.talend.designer.xmlmap.parts.XmlMapDataEditPart) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)

Example 10 with VarNodeEditPart

use of org.talend.designer.xmlmap.parts.VarNodeEditPart in project tdi-studio-se by Talend.

the class VarToolBarFigure method removeVar.

@Override
protected void removeVar() {
    CommandStack commandStack = getTableManager().getGraphicalViewer().getEditDomain().getCommandStack();
    commandStack.execute(new Command() {

        @Override
        public void execute() {
            List selectedEditParts = getTableManager().getGraphicalViewer().getSelectedEditParts();
            final List<VarNode> toRemove = new ArrayList<VarNode>();
            int minIndex = parentTable.getNodes().size() - 1;
            for (Object obj : selectedEditParts) {
                if (obj instanceof VarNodeEditPart) {
                    VarNode model = (VarNode) ((VarNodeEditPart) obj).getModel();
                    toRemove.add(model);
                    XmlMapUtil.detachNodeConnections(model, (XmlMapData) parentTable.eContainer(), true);
                    int index = parentTable.getNodes().indexOf(model);
                    if (index < minIndex) {
                        minIndex = index;
                    }
                }
            }
            parentTable.getNodes().removeAll(toRemove);
            if (!tablePart.getChildren().isEmpty()) {
                if (minIndex > tablePart.getChildren().size() - 1) {
                    minIndex = tablePart.getChildren().size() - 1;
                }
                tablePart.getViewer().select((EditPart) tablePart.getChildren().get(minIndex));
            } else {
                remove.setEnabled(false);
            }
        }
    });
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) CommandStack(org.eclipse.gef.commands.CommandStack) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) Command(org.eclipse.gef.commands.Command) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) EditPart(org.eclipse.gef.EditPart) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Aggregations

VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)12 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)10 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)9 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)9 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)7 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)7 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)6 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)6 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 EditPart (org.eclipse.gef.EditPart)4 Command (org.eclipse.gef.commands.Command)4 EList (org.eclipse.emf.common.util.EList)3 CommandStack (org.eclipse.gef.commands.CommandStack)3 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)3 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)3 Point (org.eclipse.draw2d.geometry.Point)2 Shell (org.eclipse.swt.widgets.Shell)2 TableEntityPart (org.talend.designer.gefabstractmap.part.TableEntityPart)2