Search in sources :

Example 51 with FOXTreeNode

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

the class JSONFileOutputStep2Form method addJSONFileViewer.

private void addJSONFileViewer(final Composite mainComposite, final int width, final int height) {
    final Group group = Form.createGroup(mainComposite, 1, "Linker Target", height);
    GridData data = new GridData(GridData.FILL_BOTH);
    Composite composite = new Composite(group, SWT.BORDER);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(data);
    JSONViewer = new TreeViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    data = new GridData(GridData.FILL_BOTH);
    JSONViewer.getControl().setLayoutData(data);
    JSONViewer.setUseHashlookup(true);
    Tree tree = JSONViewer.getTree();
    if (isReadOnly()) {
        tree.setEnabled(false);
    }
    tree.setLinesVisible(true);
    tree.setBackground(tree.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("JSON Tree");
    column1.setWidth(120);
    TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
    column2.setText("Related Column");
    column2.setWidth(100);
    TreeColumn column3 = new TreeColumn(tree, SWT.CENTER);
    column3.setText("Node Status");
    column3.setWidth(100);
    TreeColumn column4 = new TreeColumn(tree, SWT.CENTER);
    column4.setText("Default Value");
    column4.setWidth(100);
    tree.setHeaderVisible(true);
    JSONFileTreeViewerProvider provider = new JSONFileTreeViewerProvider();
    JSONViewer.setLabelProvider(provider);
    JSONViewer.setCellModifier(new ICellModifier() {

        public void modify(Object element, String property, Object value) {
            TreeItem treeItem = (TreeItem) element;
            FOXTreeNode node = (FOXTreeNode) treeItem.getData();
            if (property.equals("C1")) {
                node.setLabel((String) value);
            }
            if (property.equals("C4")) {
                node.setDefaultValue((String) value);
            }
            JSONViewer.refresh(node);
        }

        public Object getValue(Object element, String property) {
            FOXTreeNode node = (FOXTreeNode) element;
            if (property.equals("C1")) {
                //$NON-NLS-1$
                return node.getLabel();
            }
            if (property.equals("C4")) {
                //$NON-NLS-1$
                return node.getDefaultValue();
            }
            return null;
        }

        public boolean canModify(Object element, String property) {
            FOXTreeNode node = (FOXTreeNode) element;
            if (property.equals("C1")) {
                if (node.getLabel() != null && node.getLabel().length() > 0) {
                    return true;
                }
            }
            if (property.equals("C4")) {
                if (node.getDefaultValue() != null && node.getDefaultValue().length() > 0) {
                    return true;
                }
            }
            return false;
        }
    });
    JSONViewer.setColumnProperties(new String[] { "C1", "C2", "C3", "C4" });
    CellEditor editor = new TextCellEditor(JSONViewer.getTree());
    editor.addListener(new DialogErrorJSONLabelCellEditor(editor, "C1"));
    CellEditor editorDefault = new TextCellEditor(JSONViewer.getTree());
    editorDefault.addListener(new DialogErrorJSONLabelCellEditor(editorDefault, "C4"));
    JSONViewer.setCellEditors(new CellEditor[] { editor, null, null, editorDefault });
    JSONViewer.setContentProvider(provider);
    // JSONViewer.setInput(treeData);
    JSONViewer.expandAll();
    createAction();
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(JSONViewer.getControl());
    JSONViewer.getControl().setMenu(menu);
    JSONViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
        }
    });
    initToolBar(composite);
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) GridLayout(org.eclipse.swt.layout.GridLayout) JSONFileTreeViewerProvider(org.talend.repository.json.ui.wizards.view.JSONFileTreeViewerProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Tree(org.eclipse.swt.widgets.Tree) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Example 52 with FOXTreeNode

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

the class JSONFileOutputStep2Form method sortOrder.

private void sortOrder(FOXTreeNode treeNode, FOXTreeNode node) {
    if (node != null) {
        List<FOXTreeNode> children = node.getChildren();
        if (treeNode != null) {
            int tmpOrder = 0;
            int attrNsCount = 0;
            for (FOXTreeNode child : children) {
                if (child.getOrder() < treeNode.getOrder()) {
                    tmpOrder++;
                }
                if (child.isAttribute() || child.isNameSpace()) {
                    attrNsCount++;
                }
            }
            if (tmpOrder > -1) {
                int oldOrder = children.indexOf(treeNode);
                if (oldOrder != -1 && oldOrder != tmpOrder) {
                    node.removeChild(treeNode);
                    if (children.size() > tmpOrder) {
                        node.addChild(tmpOrder - attrNsCount, treeNode);
                    } else {
                        node.addChild(treeNode);
                    }
                }
            }
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)

Example 53 with FOXTreeNode

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

the class AbstractJSONFileStepForm method initNodeOrder.

protected void initNodeOrder(FOXTreeNode node) {
    if (node == null) {
        return;
    }
    FOXTreeNode parent = node.getParent();
    if (parent == null) {
        node.setOrder(1);
        String path = TreeUtil.getPath(node);
        orderMap.put(path, order);
        order++;
    }
    List<FOXTreeNode> childNode = node.getChildren();
    for (FOXTreeNode child : childNode) {
        child.setOrder(order);
        String path = TreeUtil.getPath(child);
        orderMap.put(path, order);
        order++;
        if (child.getChildren().size() > 0) {
            initNodeOrder(child);
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)

Example 54 with FOXTreeNode

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

the class RemoveJSONGroupAction method run.

@Override
public void run() {
    FOXTreeNode node = (FOXTreeNode) this.getStructuredSelection().getFirstElement();
    node.setGroup(false);
    jsonViewer.refresh();
    form.updateStatus();
    form.updateConnection();
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)

Example 55 with FOXTreeNode

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

the class SetForJSONLoopAction method run.

@Override
public void run() {
    FOXTreeNode node = (FOXTreeNode) this.getStructuredSelection().getFirstElement();
    if (node.isLoop()) {
        return;
    }
    FOXTreeNode rootTreeData = TreeUtil.getRootFOXTreeNode(node);
    TreeUtil.clearSubGroupNode(node);
    // make sure group element is a ancestor of loop, or no group element.
    if (TreeUtil.findUpGroupNode(node) == null) {
        TreeUtil.clearSubGroupNode(rootTreeData);
    }
    TreeUtil.clearLoopNode(rootTreeData);
    TreeUtil.clearMainNode(rootTreeData);
    if (node.isGroup()) {
        node.setGroup(false);
    }
    node.setLoop(true);
    if (form != null) {
        form.updateStatus();
    }
    TreeUtil.upsetMainNode(node);
    jsonViewer.refresh();
    form.updateStatus();
    form.updateConnection();
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)

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