Search in sources :

Example 16 with FOXTreeNode

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.

the class CreateElementAction method selectionChanged.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
     */
@Override
public void selectionChanged(IStructuredSelection selection) {
    FOXTreeNode node = (FOXTreeNode) this.getStructuredSelection().getFirstElement();
    if (node == null) {
        this.setEnabled(false);
        return;
    }
    if (node instanceof Attribute) {
        this.setEnabled(false);
        return;
    }
    if (node instanceof NameSpaceNode) {
        this.setEnabled(false);
        return;
    }
    // let user can add more children to a root.
    // Element e = (Element) node;
    // if (e.getParent() == null) {
    // if (e.getElementChildren().size() >= 1) {
    // this.setEnabled(false);
    // return;
    // }
    // }
    this.setEnabled(true);
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute)

Example 17 with FOXTreeNode

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.

the class CreateElementAction method createChildNode.

/**
     * Create the child node of the input node
     * 
     * @param node
     */
private boolean createChildNode(FOXTreeNode node) {
    if (node.getColumn() != null) {
        if (!//$NON-NLS-1$
        MessageDialog.openConfirm(//$NON-NLS-1$
        xmlViewer.getControl().getShell(), //$NON-NLS-1$
        Messages.getString("CreateElementAction.0"), //$NON-NLS-1$
        Messages.getString("CreateElementAction.1") + node.getLabel() + "\"?")) {
            //$NON-NLS-1$
            return false;
        }
        node.setColumn(null);
    }
    //$NON-NLS-1$
    String label = "";
    while (!StringUtil.validateLabelForXML(label)) {
        InputDialog dialog = new InputDialog(null, //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("CreateElementAction.4"), //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("CreateElementAction.5"), "", //$NON-NLS-1$
        null);
        int status = dialog.open();
        if (status == InputDialog.OK) {
            label = dialog.getValue().trim();
        }
        if (status == InputDialog.CANCEL) {
            return false;
        }
    }
    FOXTreeNode child = new Element(label);
    // add by wzhang. set the row name
    child.setRow(node.getRow());
    node.addChild(child);
    this.xmlViewer.refresh();
    this.xmlViewer.expandToLevel(node, 1);
    return true;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) InputDialog(org.eclipse.jface.dialogs.InputDialog) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 18 with FOXTreeNode

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.

the class FOXManager method getOriginalNodes.

/**
     * 
     * DOC wzhang Comment method "getOriginalNodes".
     * 
     * @return
     */
protected List<FOXTreeNode> getOriginalNodes() {
    List<FOXTreeNode> tmpTreeData = new ArrayList<FOXTreeNode>();
    List<? extends IConnection> incomingConnections = NodeUtil.getIncomingConnections(this.getFoxComponent(), IConnectionCategory.FLOW);
    if (incomingConnections.size() > 0) {
        for (IConnection conn : incomingConnections) {
            String uniqueName = conn.getUniqueName();
            List<FOXTreeNode> list = contents.get(uniqueName);
            tmpTreeData.addAll(list);
        }
    }
    return tmpTreeData;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection)

Example 19 with FOXTreeNode

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.

the class MultiFOXManager method initModel.

public void initModel() {
    int i = 0;
    List<? extends IConnection> incomingConnections = NodeUtil.getIncomingConnections(foxComponent, IConnectionCategory.FLOW);
    for (IConnection connection : incomingConnections) {
        IMetadataTable metadataTable = connection.getMetadataTable();
        metadataTable.setLabel(connection.getUniqueName());
        treeData = new ArrayList<FOXTreeNode>();
        if (// the first schema as current
        i == 0)
            currentSchema = metadataTable.getLabel();
        FOXTreeNode rootNode = null;
        FOXTreeNode current = null;
        FOXTreeNode temp = null;
        FOXTreeNode mainNode = null;
        String mainPath = null;
        String currentPath = null;
        String defaultValue = null;
        int nodeOrder = 0;
        boolean haveOrder = true;
        //$NON-NLS-1$
        String schemaId = metadataTable.getLabel() + ":";
        // build root tree
        List<Map<String, String>> rootTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.ROOT);
        if (rootTable != null) {
            for (Map<String, String> rootMap : rootTable) {
                String newPath = rootMap.get(FileOutputXMLComponent.PATH);
                String columnName = rootMap.get(FileOutputXMLComponent.COLUMN);
                defaultValue = rootMap.get(FileOutputXMLComponent.VALUE);
                String orderValue = rootMap.get(FileOutputXMLComponent.ORDER);
                if (orderValue == null || "".equals(orderValue)) {
                    haveOrder = false;
                }
                if (haveOrder) {
                    nodeOrder = Integer.valueOf(rootMap.get(FileOutputXMLComponent.ORDER)).intValue();
                }
                //$NON-NLS-1$
                String flag = columnName + ":";
                if (columnName != null && columnName.length() > 0 && !flag.startsWith(metadataTable.getLabel() + ":")) {
                    //$NON-NLS-1$
                    continue;
                }
                if (rootMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("attri")) {
                    //$NON-NLS-1$
                    temp = new Attribute(newPath);
                    temp.setDefaultValue(defaultValue);
                    temp.setAttribute(true);
                    current.addChild(temp);
                } else if (rootMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("ns")) {
                    //$NON-NLS-1$
                    temp = new NameSpaceNode(newPath);
                    temp.setDefaultValue(defaultValue);
                    temp.setNameSpace(true);
                    current.addChild(temp);
                } else {
                    temp = addElement(current, currentPath, newPath, defaultValue);
                    if (rootNode == null) {
                        rootNode = temp;
                    }
                    if (rootMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("main")) {
                        //$NON-NLS-1$
                        temp.setMain(true);
                        mainNode = temp;
                        mainPath = newPath;
                    }
                    current = temp;
                    currentPath = newPath;
                }
                if (haveOrder) {
                    temp.setOrder(nodeOrder);
                }
                temp.setRow(metadataTable.getLabel());
                if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
                    //$NON-NLS-1$
                    columnName = columnName.replace(schemaId, "");
                    temp.setColumn(metadataTable.getColumn(columnName));
                    temp.setTable(metadataTable);
                }
            }
        }
        // build group tree
        current = mainNode;
        currentPath = mainPath;
        boolean isFirst = true;
        List<Map<String, String>> groupTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.GROUP);
        if (groupTable != null) {
            for (Map<String, String> groupMap : groupTable) {
                String newPath = groupMap.get(FileOutputXMLComponent.PATH);
                String columnName = groupMap.get(FileOutputXMLComponent.COLUMN);
                defaultValue = groupMap.get(FileOutputXMLComponent.VALUE);
                String orderValue = groupMap.get(FileOutputXMLComponent.ORDER);
                if (orderValue == null || "".equals(orderValue)) {
                    haveOrder = false;
                }
                if (haveOrder) {
                    nodeOrder = Integer.valueOf(groupMap.get(FileOutputXMLComponent.ORDER)).intValue();
                }
                //$NON-NLS-1$
                String flag = columnName + ":";
                if (columnName != null && columnName.length() > 0 && !flag.startsWith(metadataTable.getLabel() + ":")) {
                    //$NON-NLS-1$
                    continue;
                }
                if (groupMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("attri")) {
                    //$NON-NLS-1$
                    temp = new Attribute(newPath);
                    temp.setDefaultValue(defaultValue);
                    temp.setAttribute(true);
                    current.addChild(temp);
                } else if (groupMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("ns")) {
                    //$NON-NLS-1$
                    temp = new NameSpaceNode(newPath);
                    temp.setDefaultValue(defaultValue);
                    temp.setNameSpace(true);
                    current.addChild(temp);
                } else {
                    temp = this.addElement(current, currentPath, newPath, defaultValue);
                    if (groupMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("main")) {
                        //$NON-NLS-1$
                        temp.setMain(true);
                        mainNode = temp;
                        mainPath = newPath;
                    }
                    if (isFirst) {
                        temp.setGroup(true);
                        isFirst = false;
                    }
                    current = temp;
                    currentPath = newPath;
                }
                if (haveOrder) {
                    temp.setOrder(nodeOrder);
                }
                temp.setRow(metadataTable.getLabel());
                if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
                    //$NON-NLS-1$
                    columnName = columnName.replace(schemaId, "");
                    temp.setColumn(metadataTable.getColumn(columnName));
                    temp.setTable(metadataTable);
                }
            }
        }
        // build loop tree
        current = mainNode;
        currentPath = mainPath;
        isFirst = true;
        List<Map<String, String>> loopTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.LOOP);
        if (loopTable != null) {
            for (Map<String, String> loopMap : loopTable) {
                String newPath = loopMap.get(FileOutputXMLComponent.PATH);
                String columnName = loopMap.get(FileOutputXMLComponent.COLUMN);
                defaultValue = loopMap.get(FileOutputXMLComponent.VALUE);
                String orderValue = loopMap.get(FileOutputXMLComponent.ORDER);
                if (orderValue == null || "".equals(orderValue)) {
                    haveOrder = false;
                }
                if (haveOrder) {
                    nodeOrder = Integer.valueOf(loopMap.get(FileOutputXMLComponent.ORDER)).intValue();
                }
                //$NON-NLS-1$
                String flag = columnName + ":";
                if (columnName != null && columnName.length() > 0 && !flag.startsWith(metadataTable.getLabel() + ":")) {
                    //$NON-NLS-1$
                    continue;
                }
                if (loopMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("attri")) {
                    //$NON-NLS-1$
                    temp = new Attribute(newPath);
                    temp.setDefaultValue(defaultValue);
                    temp.setAttribute(true);
                    current.addChild(temp);
                } else if (loopMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("ns")) {
                    //$NON-NLS-1$
                    temp = new NameSpaceNode(newPath);
                    temp.setDefaultValue(defaultValue);
                    temp.setNameSpace(true);
                    current.addChild(temp);
                } else {
                    temp = this.addElement(current, currentPath, newPath, defaultValue);
                    if (loopMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("main")) {
                        //$NON-NLS-1$
                        temp.setMain(true);
                    }
                    if (isFirst) {
                        temp.setLoop(true);
                        isFirst = false;
                    }
                    current = temp;
                    currentPath = newPath;
                }
                if (haveOrder) {
                    temp.setOrder(nodeOrder);
                }
                temp.setRow(metadataTable.getLabel());
                if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
                    //$NON-NLS-1$
                    columnName = columnName.replace(schemaId, "");
                    temp.setColumn(metadataTable.getColumn(columnName));
                    temp.setTable(metadataTable);
                }
            }
            if (rootNode == null) {
                //$NON-NLS-1$
                rootNode = new Element("rootTag");
            }
            rootNode.setParent(null);
            if (haveOrder) {
                orderNode(rootNode);
            }
            treeData.add(rootNode);
            rootNode.setRow(metadataTable.getLabel());
            contents.put(metadataTable.getLabel(), treeData);
            i++;
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with FOXTreeNode

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.

the class MultiFOXManager method tableLoader.

protected void tableLoader(Element element, String parentPath, List<Map<String, String>> table, String defaultValue) {
    Map<String, String> newMap = new HashMap<String, String>();
    //$NON-NLS-1$
    String currentPath = parentPath + "/" + element.getLabel();
    newMap.put(FileOutputXMLComponent.PATH, currentPath);
    newMap.put(FileOutputXMLComponent.COLUMN, element.getColumnLabel());
    //$NON-NLS-1$ //$NON-NLS-2$
    newMap.put(FileOutputXMLComponent.ATTRIBUTE, element.isMain() ? "main" : "branch");
    //$NON-NLS-1$
    newMap.put(FileOutputXMLComponent.VALUE, defaultValue);
    newMap.put(FileOutputXMLComponent.ORDER, String.valueOf(getNodeOrder(element)));
    table.add(newMap);
    for (FOXTreeNode att : element.getAttributeChildren()) {
        newMap = new HashMap<String, String>();
        newMap.put(FileOutputXMLComponent.PATH, att.getLabel());
        newMap.put(FileOutputXMLComponent.COLUMN, att.getColumnLabel());
        //$NON-NLS-1$
        newMap.put(FileOutputXMLComponent.ATTRIBUTE, "attri");
        //$NON-NLS-1$
        newMap.put(FileOutputXMLComponent.VALUE, att.getDefaultValue());
        newMap.put(FileOutputXMLComponent.ORDER, String.valueOf(getNodeOrder(att)));
        table.add(newMap);
    }
    for (FOXTreeNode att : element.getNameSpaceChildren()) {
        newMap = new HashMap<String, String>();
        newMap.put(FileOutputXMLComponent.PATH, att.getLabel());
        newMap.put(FileOutputXMLComponent.COLUMN, att.getColumnLabel());
        //$NON-NLS-1$
        newMap.put(FileOutputXMLComponent.ATTRIBUTE, "ns");
        //$NON-NLS-1$
        newMap.put(FileOutputXMLComponent.VALUE, att.getDefaultValue());
        newMap.put(FileOutputXMLComponent.ORDER, String.valueOf(getNodeOrder(att)));
        table.add(newMap);
    }
    List<FOXTreeNode> children = element.getElementChildren();
    for (FOXTreeNode child : children) {
        if (!child.isGroup() && !child.isLoop()) {
            tableLoader((Element) child, currentPath, table, child.getDefaultValue());
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) HashMap(java.util.HashMap)

Aggregations

FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)93 Attribute (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute)29 Element (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)29 NameSpaceNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode)28 ArrayList (java.util.ArrayList)23 Iterator (java.util.Iterator)10 HashMap (java.util.HashMap)8 TreeItem (org.eclipse.swt.widgets.TreeItem)7 Map (java.util.Map)6 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)5 List (java.util.List)4 InputDialog (org.eclipse.jface.dialogs.InputDialog)4 TreePath (org.eclipse.jface.viewers.TreePath)4 EList (org.eclipse.emf.common.util.EList)3 TableItem (org.eclipse.swt.widgets.TableItem)3 Tree (org.eclipse.swt.widgets.Tree)3 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 IConnection (org.talend.core.model.process.IConnection)3 ATreeNode (org.talend.datatools.xml.utils.ATreeNode)3