Search in sources :

Example 16 with NameSpaceNode

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

the class MoveUpTreeNodeButton method handleSelectionEvent.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.fileoutputJSON.ui.footer.AbstractTreeNodeButton#handleSelectionEvent()
     */
@Override
protected void handleSelectionEvent(TreeSelection selection) {
    if (!selection.isEmpty()) {
        FOXTreeNode foxNode = (FOXTreeNode) selection.getFirstElement();
        if (!(foxNode.getParent() instanceof Element)) {
            return;
        }
        final Element parentNode = (Element) foxNode.getParent();
        final List<? extends FOXTreeNode> attrChildren = parentNode.getAttributeChildren();
        final List<? extends FOXTreeNode> nameSpaceChildren = parentNode.getNameSpaceChildren();
        final List<FOXTreeNode> elementChildren = parentNode.getElementChildren();
        List<Integer> attrIndices = new ArrayList<Integer>();
        List<Integer> nameSpaceIndices = new ArrayList<Integer>();
        List<Integer> elementIndices = new ArrayList<Integer>();
        final Iterator iterator = selection.iterator();
        while (iterator.hasNext()) {
            final Object next = iterator.next();
            if (next instanceof Attribute) {
                if (attrChildren.contains(next)) {
                    attrIndices.add(attrChildren.indexOf(next));
                }
            } else if (next instanceof NameSpaceNode) {
                if (nameSpaceChildren.contains(next)) {
                    nameSpaceIndices.add(nameSpaceChildren.indexOf(next));
                }
            } else if (next instanceof Element) {
                if (elementChildren.contains(next)) {
                    elementIndices.add(elementChildren.indexOf(next));
                }
            }
        }
        Collections.sort(attrIndices);
        Collections.sort(nameSpaceIndices);
        Collections.sort(elementIndices);
        swapElements(attrChildren, attrIndices);
        swapElements(nameSpaceChildren, nameSpaceIndices);
        swapElements(elementChildren, elementIndices);
        treeViewer.refresh(parentNode);
        treeViewer.expandAll();
        form.redrawLinkers();
        treeViewer.setSelection(selection);
        form.updateConnection();
    }
}
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) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 17 with NameSpaceNode

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

the class RemoveJSONGroupAction method selectionChanged.

@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;
    }
    this.setEnabled(node.isGroup());
}
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 18 with NameSpaceNode

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

the class CreateJSONElementAction method selectionChanged.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.ISelection)
     */
@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;
    }
    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 19 with NameSpaceNode

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

the class FOXManager method initModel.

public void initModel() {
    IMetadataTable metadataTable = foxComponent.getMetadataTable();
    if (metadataTable == null) {
        metadataTable = new MetadataTable();
    }
    String componentName = foxComponent.getComponent().getName();
    //        if (componentName.equals("tWriteXMLField")) { //$NON-NLS-1$ //$NON-NLS-2$
    IConnection inConn = null;
    for (IConnection conn : foxComponent.getIncomingConnections()) {
        if ((conn.getLineStyle().equals(EConnectionType.FLOW_MAIN)) || (conn.getLineStyle().equals(EConnectionType.FLOW_REF))) {
            inConn = conn;
            break;
        }
    }
    if (inConn != null) {
        metadataTable = inConn.getMetadataTable();
    }
    // }
    treeData = new ArrayList<FOXTreeNode>();
    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;
    // build root tree
    List<Map<String, String>> rootTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.ROOT);
    for (Map<String, String> rootMap : rootTable) {
        String newPath = rootMap.get(FileOutputXMLComponent.PATH);
        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();
        }
        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 = this.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);
        }
        String columnName = rootMap.get(FileOutputXMLComponent.COLUMN);
        if (columnName != null && columnName.length() > 0) {
            temp.setColumn(metadataTable.getColumn(columnName));
        }
    }
    // build group tree
    current = mainNode;
    currentPath = mainPath;
    boolean isFirst = true;
    List<Map<String, String>> groupTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.GROUP);
    for (Map<String, String> groupMap : groupTable) {
        String newPath = groupMap.get(FileOutputXMLComponent.PATH);
        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();
        }
        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);
        }
        String columnName = groupMap.get(FileOutputXMLComponent.COLUMN);
        if (columnName != null && columnName.length() > 0) {
            temp.setColumn(metadataTable.getColumn(columnName));
        }
    }
    // build loop tree
    current = mainNode;
    currentPath = mainPath;
    isFirst = true;
    List<Map<String, String>> loopTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.LOOP);
    for (Map<String, String> loopMap : loopTable) {
        String newPath = loopMap.get(FileOutputXMLComponent.PATH);
        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();
        }
        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 (rootNode == null) {
                rootNode = temp;
            }
            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);
        }
        String columnName = loopMap.get(FileOutputXMLComponent.COLUMN);
        if (columnName != null && columnName.length() > 0) {
            temp.setColumn(metadataTable.getColumn(columnName));
        }
    }
    if (rootNode == null) {
        //$NON-NLS-1$
        rootNode = new Element("rootTag");
    }
    rootNode.setParent(null);
    if (haveOrder) {
        orderNode(rootNode);
    }
    treeData.add(rootNode);
}
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) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with NameSpaceNode

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

the class CreateNameSpaceAction method createChildNode.

/**
     * Create the child node of the input node
     * 
     * @param node
     */
private void createChildNode(FOXTreeNode node) {
    String label = null;
    String defaultValue = null;
    while (!StringUtil.validateLabelForNameSpace(label) || !StringUtil.validateLabelForFixedValue(defaultValue)) {
        NameSpaceDialog nsDialog = new NameSpaceDialog(null);
        int status = nsDialog.open();
        if (status == nsDialog.OK) {
            defaultValue = nsDialog.getNSValue();
            if (defaultValue != null) {
                defaultValue = defaultValue.trim();
            }
            label = nsDialog.getPrefix().trim();
        }
        if (status == nsDialog.CANCEL) {
            return;
        }
    }
    FOXTreeNode child = new NameSpaceNode(label);
    child.setDefaultValue(defaultValue);
    // add by wzhang. set the row name
    child.setRow(node.getRow());
    node.addChild(child);
    this.xmlViewer.refresh();
    xmlViewer.expandToLevel(node, 1);
    foxui.redrawLinkers();
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) NameSpaceDialog(org.talend.metadata.managment.ui.wizard.metadata.xml.dialog.NameSpaceDialog) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode)

Aggregations

FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)28 NameSpaceNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode)28 Attribute (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute)26 Element (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)17 Iterator (java.util.Iterator)8 ArrayList (java.util.ArrayList)7 TreePath (org.eclipse.jface.viewers.TreePath)4 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)2 XMLFileNode (org.talend.core.model.metadata.builder.connection.XMLFileNode)2 IConnection (org.talend.core.model.process.IConnection)2 NameSpaceDialog (org.talend.metadata.managment.ui.wizard.metadata.xml.dialog.NameSpaceDialog)2 EList (org.eclipse.emf.common.util.EList)1 MetadataTable (org.talend.core.model.metadata.MetadataTable)1 ATreeNode (org.talend.datatools.xml.utils.ATreeNode)1 NodeType (org.talend.designer.xmlmap.model.emf.xmlmap.NodeType)1 JSONFileNode (org.talend.repository.model.json.JSONFileNode)1