Search in sources :

Example 1 with AbstractInOutTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.

the class XmlmapBranchContent method createContent.

@Override
protected void createContent() {
    super.createContent();
    statusFigure = new Label();
    statusFigure.setForegroundColor(ColorConstants.red);
    statusFigure.setText(getStatus());
    defaultValue = new Label();
    defaultValue.setForegroundColor(ColorConstants.blue);
    defaultValue.setText(getDefaultValue());
    ImageInfo infor = ImageInfo.SETLOOPFUNCTION_BUTTON;
    if (treeNode instanceof OutputTreeNode) {
        InputLoopNodesTable inputLoopNodesTable = ((OutputTreeNode) treeNode).getInputLoopNodesTable();
        infor = (inputLoopNodesTable == null || inputLoopNodesTable.getInputloopnodes().isEmpty()) ? ImageInfo.SETLOOPFUNCTION_BUTTON_ERROR : ImageInfo.SETLOOPFUNCTION_BUTTON;
    }
    loopButtonFigure = new ToolBarButtonImageFigure(ImageProviderMapper.getImage(infor));
    loopButtonFigure.addMouseListener(new MouseListener.Stub() {

        @Override
        public void mousePressed(MouseEvent me) {
            OutputTreeNode outputTreeNode = (OutputTreeNode) treeNode;
            List<TreeNode> loopNodes = new ArrayList<TreeNode>();
            if (manager.isMainTableMultiLoop()) {
                loopNodes.addAll(XmlMapUtil.getMultiLoopsForXmlTree(manager.getMainInputTree()));
            }
            InputLoopNodesTable inputLoopNodesTable = null;
            if (outputTreeNode.getInputLoopNodesTable() != null) {
                inputLoopNodesTable = outputTreeNode.getInputLoopNodesTable();
            } else {
                inputLoopNodesTable = XmlmapFactory.eINSTANCE.createInputLoopNodesTable();
                outputTreeNode.setInputLoopNodesTable(inputLoopNodesTable);
                AbstractInOutTree abstractInOutTree = XmlMapUtil.getAbstractInOutTree(outputTreeNode);
                if (abstractInOutTree != null) {
                    ((OutputXmlTree) abstractInOutTree).getInputLoopNodesTables().add(inputLoopNodesTable);
                }
            }
            SetLoopFunctionDialog nsDialog = new SetLoopFunctionDialog(null, outputTreeNode.getInputLoopNodesTable(), loopNodes);
            if (nsDialog.open() == Window.OK) {
                manager.getProblemsAnalyser().checkProblems(XmlMapUtil.getAbstractInOutTree(outputTreeNode));
                manager.getMapperUI().updateStatusBar();
            }
        }
    });
    if (treeNode != null && treeNode instanceof OutputTreeNode) {
        // display loop setup button only when input main is multiloop
        if (treeNode.isLoop() && manager.isMainTableMultiLoop()) {
            this.add(loopButtonFigure);
        }
    }
    this.add(statusFigure);
    this.add(defaultValue);
}
Also used : InputLoopNodesTable(org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable) ToolBarButtonImageFigure(org.talend.designer.gefabstractmap.figures.treetools.ToolBarButtonImageFigure) MouseEvent(org.eclipse.draw2d.MouseEvent) Label(org.eclipse.draw2d.Label) SetLoopFunctionDialog(org.talend.designer.xmlmap.ui.dialog.SetLoopFunctionDialog) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) MouseListener(org.eclipse.draw2d.MouseListener) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) List(java.util.List) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) ImageInfo(org.talend.designer.gefabstractmap.resource.ImageInfo)

Example 2 with AbstractInOutTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.

the class SetLoopAction method run.

@Override
public void run() {
    TreeNode model = (TreeNode) nodePart.getModel();
    TreeNode docRoot = XmlMapUtil.getTreeNodeRoot(model);
    AbstractInOutTree abstractTree = (AbstractInOutTree) docRoot.eContainer();
    boolean isLookup = abstractTree != mapperManager.getMainInputTree() && !(abstractTree instanceof OutputXmlTree);
    // remove old group
    if (model instanceof OutputTreeNode) {
        OutputTreeNode outputNode = (OutputTreeNode) model;
        if (docRoot != null) {
            XmlMapUtil.cleanSubGroup(outputNode);
            List<TreeNode> newLoopUpGroups = new ArrayList<TreeNode>();
            findUpGroupNode(newLoopUpGroups, outputNode);
            // clean all groups except the ancestor of new loop
            XmlMapUtil.cleanSubGroup(docRoot, newLoopUpGroups);
            // reset the group in case some element ancestor of loop element are not group but under the group
            if (!newLoopUpGroups.isEmpty()) {
                TreeNode rootGroup = newLoopUpGroups.get(newLoopUpGroups.size() - 1);
                upsetGroup(outputNode, rootGroup);
            }
        }
    }
    if (!isLookup) {
        // TDI-20147
        List<TreeNode> loopNodes = new ArrayList<TreeNode>();
        checkSubElementIsLoop(model, loopNodes);
        checkParentElementIsLoop(model, loopNodes);
        if (!loopNodes.isEmpty()) {
            if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("SetLoopAction.cleanSubLoopTitle"), Messages.getString("SetLoopAction.cleanSubLoopMessages"))) {
            } else {
                return;
            }
        }
        for (TreeNode treeNode : loopNodes) {
            treeNode.setLoop(false);
        }
        model.setLoop(true);
        XmlMapUtil.clearMainNode(model);
        XmlMapUtil.upsetMainNode(model);
        abstractTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(abstractTree));
        if (input) {
            // check if child is mapped to output remove the old loop in output node
            XmlMapUtil.removeloopInOutputTree(mapperManager, loopNodes);
        // disable the function to add sourceloop into InputLoopNodesTable automatically
        // add input loopNodes to InputLoopNodesTable
        // addInputLoopNodesToOutput(model, model);
        } else {
            // clean the InputLoopNodesTable for the old loops
            InputXmlTree mainInput = mapperManager.getMainInputTree();
            XmlMapUtil.removeLoopTableForOutput((OutputXmlTree) abstractTree, loopNodes, mainInput == null ? false : mainInput.isMultiLoops());
        }
    } else {
        if (docRoot != null) {
            cleanSubLoop(docRoot);
        }
        model.setLoop(true);
        XmlMapUtil.clearMainNode(docRoot);
        XmlMapUtil.upsetMainNode(model);
    }
    if (abstractTree != null) {
        mapperManager.getProblemsAnalyser().checkProblems(abstractTree);
        mapperManager.getMapperUI().updateStatusBar();
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)

Example 3 with AbstractInOutTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.

the class SetAggregateAction method calculateEnabled.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
     */
@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    }
    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 OutputTreeNodeEditPart) {
            nodePart = (OutputTreeNodeEditPart) obj;
            OutputTreeNode model = (OutputTreeNode) nodePart.getModel();
            // root can't be aggregate
            if (NodeType.NAME_SPACE.equals(model.getNodeType()) || !(model.eContainer() instanceof OutputTreeNode) || model.isChoice() || model.isSubstitution()) {
                return false;
            }
            if (!XmlMapUtil.isExpressionEditable(model)) {
                return false;
            }
            boolean isInputMultiLoops = false;
            if (mapperManager.getMainInputTree() != null && mapperManager.getMainInputTree().isMultiLoops()) {
                isInputMultiLoops = true;
            }
            AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(model);
            if (abstractTree instanceof OutputXmlTree) {
                OutputXmlTree outputTree = ((OutputXmlTree) abstractTree);
                if (outputTree.isAllInOne()) {
                    return false;
                }
                // fixed for TDI-20808 ,disable group and aggregate for 501
                if (isInputMultiLoops && outputTree.isMultiLoops()) {
                    return false;
                }
            }
            if (!model.isAggregate()) {
                setText("As aggregate element");
            } else {
                setText("Remove aggregate element");
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) List(java.util.List) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 4 with AbstractInOutTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.

the class SetGroupAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    subGroupTraceNames.clear();
    if (getSelectedObjects().isEmpty()) {
        return false;
    }
    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 OutputTreeNodeEditPart) {
            nodePart = (OutputTreeNodeEditPart) obj;
            OutputTreeNode model = (OutputTreeNode) nodePart.getModel();
            if (model.eContainer() instanceof TreeNode && XmlMapUtil.DOCUMENT.equals(((TreeNode) model.eContainer()).getType())) {
                return false;
            }
            if (NodeType.ATTRIBUT.equals(model.getNodeType()) || NodeType.NAME_SPACE.equals(model.getNodeType()) || !(model.eContainer() instanceof TreeNode) || model.isChoice() || model.isSubstitution()) {
                //$NON-NLS-N$
                return false;
            }
            // fixed for TDI-20808 ,disable group and aggregate for 501
            AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(model);
            if (abstractTree instanceof OutputXmlTree) {
                OutputXmlTree outputTree = ((OutputXmlTree) abstractTree);
                if (outputTree.isMultiLoops()) {
                    return false;
                }
            }
            OutputTreeNode findDownLoopNode = findDownLoopNode(model);
            if (findDownLoopNode == null) {
                return false;
            }
            if (!model.isGroup()) {
                setText("As group element");
                isRemove = false;
            } else {
                setText("Remove group element");
                isRemove = true;
            }
            if (isRemove) {
                if (model.isGroup()) {
                    return true;
                } else {
                    return false;
                }
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) List(java.util.List) ArrayList(java.util.ArrayList) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 5 with AbstractInOutTree

use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.

the class ImportTreeFromRepository method run.

@Override
public void run() {
    targetAbsolutePath = null;
    loopNode = null;
    xpathAndOrder.clear();
    RepositoryXmlSelectionDialog reviewDialog = new RepositoryXmlSelectionDialog(shell, new String[] { "XML", "MDM" });
    if (reviewDialog.open() == Window.OK) {
        TreeNode treeNodeRoot = XmlMapUtil.getTreeNodeRoot(schemaNode);
        XmlMapUtil.detachNodeConnections(treeNodeRoot, mapperManager.getExternalData(), true);
        RepositoryNode repositoryNode = reviewDialog.getResult();
        Item item = repositoryNode.getObject().getProperty().getItem();
        String detailedMessage = "";
        try {
            if (item instanceof XmlFileConnectionItem) {
                XmlFileConnectionItem xmlitem = (XmlFileConnectionItem) item;
                XmlFileConnection connection = (XmlFileConnection) xmlitem.getConnection();
                prepareEmfTreeFromXml(connection);
            } else if (item instanceof MDMConnectionItem) {
                String selectedSchema = (String) repositoryNode.getProperties(EProperties.LABEL);
                MDMConnection connection = (MDMConnection) ((MDMConnectionItem) item).getConnection();
                prepareEmfTreeFromMdm(connection, selectedSchema);
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
            StringBuffer sb = new StringBuffer();
            sb.append(e.toString());
            sb.append("\n");
            if (e.getStackTrace() != null) {
                for (StackTraceElement trace : e.getStackTrace()) {
                    sb.append(trace.toString());
                    sb.append("\n");
                }
            }
            detailedMessage = sb.toString();
        }
        boolean childrenEmpty = false;
        if (schemaNode.getChildren().isEmpty()) {
            childrenEmpty = true;
            TreeNode rootNode = createModel();
            rootNode.setName("root");
            rootNode.setNodeType(NodeType.ELEMENT);
            rootNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
            rootNode.setXpath(XmlMapUtil.getXPath(schemaNode.getXpath(), "root", NodeType.ELEMENT));
            schemaNode.getChildren().add(rootNode);
            if (loopNode == null) {
                schemaNode.getChildren().get(0).setLoop(true);
                schemaNode.getChildren().get(0).setMain(true);
            }
        }
        if (childrenEmpty || (detailedMessage != null && !"".equals(detailedMessage))) {
            showError(detailedMessage);
        }
        AbstractInOutTree tree = null;
        if (schemaNode.eContainer() instanceof InputXmlTree) {
            XmlMapConnectionBuilder connectionBuilder = new XmlMapConnectionBuilder();
            connectionBuilder.setCheckRootNodePrefix(true);
            connectionBuilder.rebuildLinks(schemaNode, mapperManager.getExternalData());
            mapperManager.refreshTreeSchemaEditor((InputXmlTree) schemaNode.eContainer());
            // mapperManager.inputTreeSchemaBeanListModified();
            tree = (InputXmlTree) schemaNode.eContainer();
        } else if (schemaNode.eContainer() instanceof OutputXmlTree) {
            // mapperManager.outputTreeSchemaBeanListModified();
            mapperManager.refreshTreeSchemaEditor((OutputXmlTree) schemaNode.eContainer());
            tree = (OutputXmlTree) schemaNode.eContainer();
        }
        if (tree != null) {
            mapperManager.getProblemsAnalyser().checkProblems(tree);
            mapperManager.getMapperUI().updateStatusBar();
        }
    }
}
Also used : RepositoryXmlSelectionDialog(org.talend.designer.xmlmap.ui.dialog.RepositoryXmlSelectionDialog) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) Item(org.talend.core.model.properties.Item) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) XmlMapConnectionBuilder(org.talend.designer.xmlmap.util.XmlMapConnectionBuilder) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Aggregations

AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)32 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)25 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)23 ArrayList (java.util.ArrayList)15 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)13 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)12 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)8 List (java.util.List)6 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)6 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)6 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)5 InputLoopNodesTable (org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable)4 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)4 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)4 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)3 XmlmapTreeNodeFigure (org.talend.designer.xmlmap.figures.treeNode.XmlmapTreeNodeFigure)3 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)3 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)3 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)3 Iterator (java.util.Iterator)2