Search in sources :

Example 6 with TreeNodeEditPart

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

the class DeleteTreeNodeAction method run.

@Override
public void run() {
    try {
        TreeNode docRoot = null;
        Object s = getSelectedObjects().get(0);
        if (s instanceof List && !((List) s).isEmpty()) {
            List selectedarts = new ArrayList((List) s);
            Iterator iter = selectedarts.iterator();
            while (iter.hasNext()) {
                Object obj = iter.next();
                if (obj instanceof TreeNodeEditPart) {
                    TreeNodeEditPart nodePart = (TreeNodeEditPart) obj;
                    TreeNode treeNode = (TreeNode) nodePart.getModel();
                    if (treeNode.eContainer() instanceof TreeNode) {
                        TreeNode parent = (TreeNode) treeNode.eContainer();
                        if (docRoot == null) {
                            docRoot = XmlMapUtil.getTreeNodeRoot(parent);
                        }
                        XmlMapUtil.detachNodeConnections(treeNode, mapperManager.getExternalData(), true);
                        // if delete loop , clean group and main
                        if (treeNode.isLoop()) {
                            if (treeNode instanceof OutputTreeNode && XmlMapUtil.findUpGroupNode((OutputTreeNode) treeNode) != null) {
                                XmlMapUtil.cleanSubGroup(docRoot);
                            }
                            XmlMapUtil.clearMainNode(docRoot);
                        }
                        parent.getChildren().remove(treeNode);
                        // check if tree is multiloop
                        if (docRoot != null && docRoot.eContainer() instanceof AbstractInOutTree) {
                            AbstractInOutTree tree = (AbstractInOutTree) docRoot.eContainer();
                            tree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(tree));
                        }
                        if (input) {
                            // remove delete loops in InputLoopTable for outputs
                            List<TreeNode> subNodes = new ArrayList<TreeNode>();
                            checkSubElementIsLoop(treeNode, subNodes);
                            XmlMapUtil.removeloopInOutputTree(mapperManager, subNodes);
                        }
                    }
                }
            }
        }
        if (mapperManager != null) {
            mapperManager.beanListModified(input);
            // }
            if (docRoot != null && docRoot.eContainer() instanceof AbstractInOutTree) {
                mapperManager.getProblemsAnalyser().checkProblems((AbstractInOutTree) docRoot.eContainer());
                mapperManager.getMapperUI().updateStatusBar();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) List(java.util.List) ArrayList(java.util.ArrayList) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 7 with TreeNodeEditPart

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

the class FixValueAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    } else {
        // get the last selection to run the action
        Object s = getSelectedObjects().get(0);
        if (s instanceof List && !((List) s).isEmpty()) {
            List selectedarts = (List) s;
            Object object = selectedarts.get(selectedarts.size() - 1);
            if (object instanceof TreeNodeEditPart) {
                TreeNodeEditPart nodePart = (TreeNodeEditPart) object;
                this.selectedNode = (TreeNode) nodePart.getModel();
                boolean isNameSpace = NodeType.NAME_SPACE.equals(selectedNode.getNodeType());
                if (isNameSpace && (selectedNode.getExpression() == null || "".equals(selectedNode.getExpression()))) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : List(java.util.List) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 8 with TreeNodeEditPart

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

the class ImportTreeFromXml method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    } else {
        // get the last selection to run the action
        Object s = getSelectedObjects().get(0);
        if (s instanceof List && !((List) s).isEmpty()) {
            List selectedarts = (List) s;
            Object object = selectedarts.get(selectedarts.size() - 1);
            if (object instanceof TreeNodeEditPart) {
                TreeNodeEditPart parentPart = (TreeNodeEditPart) object;
                parentNode = (TreeNode) parentPart.getModel();
                if (parentNode.eContainer() instanceof AbstractInOutTree && XmlMapUtil.DOCUMENT.equals(parentNode.getType())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) ArrayList(java.util.ArrayList) List(java.util.List) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 9 with TreeNodeEditPart

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

the class RenameTreeNodeAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    } else {
        boolean enable = true;
        // get the last selection to run the action
        Object s = getSelectedObjects().get(0);
        if (s instanceof List && !((List) s).isEmpty()) {
            List selectedarts = (List) s;
            Object obj = selectedarts.get(selectedarts.size() - 1);
            if (obj instanceof TreeNodeEditPart) {
                TreeNodeEditPart nodePart = (TreeNodeEditPart) obj;
                this.selectedNode = (TreeNode) nodePart.getModel();
                if (NodeType.NAME_SPACE.equals(selectedNode.getNodeType()) || selectedNode.isChoice()) {
                    return false;
                }
                int xPathLength = XmlMapUtil.getXPathLength(selectedNode.getXpath());
                if (xPathLength <= 2) {
                    enable = false;
                }
            } else {
                enable = false;
            }
        }
        return enable;
    }
}
Also used : EList(org.eclipse.emf.common.util.EList) List(java.util.List) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 10 with TreeNodeEditPart

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

the class AddChoiceAction method run.

@Override
public void run() {
    TreeNode treeNode = null;
    boolean needWarning = false;
    if (input) {
        treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
        if (!parent.getOutgoingConnections().isEmpty()) {
            needWarning = true;
        }
    } else {
        treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
        EList<Connection> incomingConnections = parent.getIncomingConnections();
        if (!incomingConnections.isEmpty()) {
            needWarning = true;
        }
    }
    boolean canContinue = true;
    // Shell shell = this.part.getSite().getShell();
    if (needWarning) {
        canContinue = MessageDialog.openConfirm(null, "Warning", "Do you want to disconnect the existing linker and then add a choice for the selected element ?");
    }
    if (canContinue) {
        XmlMapUtil.detachNodeConnections(parent, mapperManager.getExternalData(), false);
        treeNode.setName(parent.getName() + XSDPopulationUtil2.CHOICE);
        treeNode.setNodeType(NodeType.ELEMENT);
        treeNode.setXpath(XmlMapUtil.getXPath(this.parent.getXpath(), treeNode.getName(), treeNode.getNodeType()));
        treeNode.setChoice(true);
        parent.getChildren().add(treeNode);
        if (!input) {
            OutputTreeNode output = (OutputTreeNode) parent;
            if (!XmlMapUtil.isExpressionEditable(output) && output.isAggregate()) {
                output.setAggregate(false);
            }
        }
        Object object = graphicViewer.getEditPartRegistry().get(treeNode);
        if (object instanceof TreeNodeEditPart) {
            graphicViewer.select((TreeNodeEditPart) object);
        }
    }
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Aggregations

TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)30 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)22 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)16 List (java.util.List)15 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)9 ArrayList (java.util.ArrayList)8 EList (org.eclipse.emf.common.util.EList)8 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)8 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)8 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)7 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)7 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)6 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)5 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)4 Point (org.eclipse.draw2d.geometry.Point)3 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)3 Iterator (java.util.Iterator)2 InputDialog (org.eclipse.jface.dialogs.InputDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 TableEntityPart (org.talend.designer.gefabstractmap.part.TableEntityPart)2