Search in sources :

Example 16 with Element

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

the class MoveDownTreeNodeButton 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 Element

use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element 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 18 with Element

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

the class DeleteJSONNodeAction method run.

@Override
public void run() {
    List<FOXTreeNode> objectToRemove = new ArrayList<FOXTreeNode>();
    final Iterator iterator = this.getStructuredSelection().iterator();
    while (iterator.hasNext()) {
        FOXTreeNode selectedNode = (FOXTreeNode) iterator.next();
        objectToRemove.add(selectedNode);
    }
    for (FOXTreeNode node : objectToRemove) {
        if (node == null) {
            return;
        }
        FOXTreeNode parent = node.getParent();
        if (parent == null) {
            return;
        }
        if (node instanceof Element) {
            disconnectSubTree(node);
        }
        parent.removeChild(node);
        if (node.isLoop() || node.isGroup()) {
            form.updateStatus();
        }
        jsonViewer.refresh(parent);
    }
    jsonViewer.expandAll();
    form.updateConnection();
    form.redrawLinkers();
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 19 with Element

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

the class AbstractJSONFileStepForm method updateConnectionProperties.

protected void updateConnectionProperties(FOXTreeNode foxTreeNode) {
    EList root = getConnection().getRoot();
    EList loop = getConnection().getLoop();
    EList group = getConnection().getGroup();
    root.clear();
    loop.clear();
    group.clear();
    if (foxTreeNode != null) {
        initNodeOrder(foxTreeNode);
        tableLoader((Element) foxTreeNode, "", root, foxTreeNode.getDefaultValue());
        Element loopNode = (Element) TreeUtil.getLoopNode(foxTreeNode);
        if (loopNode != null) {
            String path = TreeUtil.getPath(loopNode);
            tableLoader(loopNode, path.substring(0, path.lastIndexOf("/")), loop, loopNode.getDefaultValue());
        }
        Element groupNode = (Element) TreeUtil.getGroupNode(foxTreeNode);
        if (groupNode != null) {
            String path = TreeUtil.getPath(groupNode);
            tableLoader(groupNode, path.substring(0, path.lastIndexOf("/")), group, groupNode.getDefaultValue());
        }
    }
}
Also used : EList(org.eclipse.emf.common.util.EList) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)

Example 20 with Element

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

the class CreateJSONElementAction method createChildNode.

private boolean createChildNode(FOXTreeNode node) {
    if (node.getColumn() != null) {
        if (!MessageDialog.openConfirm(jsonViewer.getControl().getShell(), "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element " + node.getLabel() + " \"?")) {
            return false;
        }
        node.setColumn(null);
    }
    String label = "";
    while (!JSONUtil.validateLabelForJSON(label)) {
        InputDialog dialog = new InputDialog(null, "Input element's label", "Input the new element's valid label", "", null);
        int status = dialog.open();
        if (status == InputDialog.OK) {
            label = dialog.getValue().trim();
        }
        if (status == InputDialog.CANCEL) {
            return false;
        }
    }
    FOXTreeNode child = new Element(label);
    // child.setRow(node.getRow());
    node.addChild(child);
    // fix for TDI-18802
    if (node.getParent() == null && node.isLoop()) {
        node.setLoop(false);
    }
    this.jsonViewer.refresh();
    this.jsonViewer.expandAll();
    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)

Aggregations

Element (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element)32 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)29 Attribute (org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute)18 NameSpaceNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode)17 ArrayList (java.util.ArrayList)15 Iterator (java.util.Iterator)10 HashMap (java.util.HashMap)6 Map (java.util.Map)6 TreePath (org.eclipse.jface.viewers.TreePath)4 List (java.util.List)3 EList (org.eclipse.emf.common.util.EList)3 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)3 InputDialog (org.eclipse.jface.dialogs.InputDialog)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 ATreeNode (org.talend.datatools.xml.utils.ATreeNode)2 MetadataTable (org.talend.core.model.metadata.MetadataTable)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 MetadataEmfTableEditor (org.talend.core.ui.metadata.editor.MetadataEmfTableEditor)1