Search in sources :

Example 1 with TreeNodeData

use of org.talend.componentdesigner.ui.composite.xmltree.TreeNodeData in project tdi-studio-se by Talend.

the class AbstractXMLConfigPage method initialize.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.componentdesigner.ui.wizard.creatcomponent.AbstractComponentPage#initialize()
     */
protected void initialize() {
    availableXmlTree.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            if (availableXmlTree.getMenu() != null) {
                availableXmlTree.getMenu().dispose();
            }
            final TreeItem[] treeItem = ((Tree) event.getSource()).getSelection();
            Menu popMenu = new Menu(availableXmlTree);
            MenuItem itemNew = new MenuItem(popMenu, SWT.CASCADE);
            //$NON-NLS-1$
            itemNew.setText(Messages.getString("AbstractXMLConfigPage.New"));
            MenuItem itemDel = new MenuItem(popMenu, SWT.CASCADE);
            //$NON-NLS-1$
            itemDel.setText(Messages.getString("AbstractXMLConfigPage.Delete"));
            itemDel.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    TreeNodeData currentNodeData = (TreeNodeData) treeItem[0].getParentItem().getData();
                    currentNodeData.getXMLNode().removeChild(((TreeNodeData) treeItem[0].getData()).getXMLNode());
                    treeItem[0].dispose();
                }
            });
            final TreeNodeData treeNodeData = ((TreeNodeData) treeItem[0].getData());
            if (treeNodeData.isHasChildTreeNode()) {
                Menu subNewMenu = new Menu(itemNew);
                itemNew.setMenu(subNewMenu);
                Object[] subNodeNames = treeNodeData.getChildNodeNames();
                for (Object nodeName : subNodeNames) {
                    final MenuItem nodeMenuItem = new MenuItem(subNewMenu, SWT.CASCADE);
                    final String itemName = (String) nodeName;
                    nodeMenuItem.setText(itemName);
                    nodeMenuItem.addSelectionListener(new SelectionAdapter() {

                        public void widgetSelected(SelectionEvent e) {
                            TreeItem newItem = new TreeItem(treeItem[0], 0);
                            newItem.setText(itemName);
                            TreeNodeData newNodeData = null;
                            newNodeData = new TreeNodeData();
                            Node parentNode = treeNodeData.getXMLNode();
                            newNodeData.setXMLNode(parentNode.appendChild(parentNode.getOwnerDocument().createElement(itemName)));
                            //$NON-NLS-1$
                            newNodeData.setTreePath(treeNodeData.getTreePath() + "/" + itemName);
                            newNodeData.setTreeNode(ATreeNodeUtil.getTreeNodeByPath(newNodeData.getTreePath()));
                            newItem.setData(newNodeData);
                        }
                    });
                }
            } else {
                itemNew.setEnabled(false);
            }
            availableXmlTree.setMenu(popMenu);
            if (nodeAttrCompsite != null) {
                nodeAttrCompsite.dispose();
            }
            rebuildAttrComposite(treeNodeData);
            setComponentMinSize(treeNodeData.getTreeNode().getLabel());
            rightComposite.layout();
        }
    });
}
Also used : TreeNodeData(org.talend.componentdesigner.ui.composite.xmltree.TreeNodeData) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Node(org.w3c.dom.Node) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 2 with TreeNodeData

use of org.talend.componentdesigner.ui.composite.xmltree.TreeNodeData in project tdi-studio-se by Talend.

the class JavaXMLConfigWizardPage method fillImportItems.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.componentdesigner.ui.wizard.creatcomponent.AbstractXMLConfigPage#fillImportItems()
     */
protected void fillImportItems() {
    for (int i = 0; i < availableXmlTree.getItems().length; i++) {
        TreeItem item = availableXmlTree.getItem(i);
        if (item.getText().equals(CODEGENERATION)) {
            Node codeGenNode = ((TreeNodeData) item.getData()).getXMLNode();
            TreeItem importsItem = new TreeItem(item, SWT.CASCADE);
            importsItem.setText(IMPORTS);
            Element importsEle = codeGenNode.getOwnerDocument().createElement(IMPORTS);
            codeGenNode.appendChild(importsEle);
            TreeNodeData importsData = new TreeNodeData();
            importsData.setXMLNode(importsEle);
            importsData.setTreeNode(ATreeNodeUtil.getTreeNodeByPath(IMPORTSITEMPATH));
            importsItem.setData(importsData);
            List<Node> jarImportNodes = new ArrayList<Node>();
            List<Node> pmImportNodes = new ArrayList<Node>();
            for (ILibEntry libEntry : componentPref.getLibEntries()) {
                TreeItem importItem = new TreeItem(importsItem, SWT.CASCADE);
                importItem.setText(IMPORT);
                Element importEle = importsEle.getOwnerDocument().createElement(IMPORT);
                importsEle.appendChild(importEle);
                importEle.setAttribute(NAME, libEntry.getNamePrefix());
                importEle.setAttribute(MODULE, libEntry.getName());
                //$NON-NLS-1$
                importEle.setAttribute(REQUIRED, "true");
                TreeNodeData nodeData = new TreeNodeData();
                nodeData.putAttrValue(NAME, libEntry.getNamePrefix());
                nodeData.putAttrValue(MODULE, libEntry.getName());
                //$NON-NLS-1$
                nodeData.putAttrValue(REQUIRED, "true");
                nodeData.setXMLNode(importEle);
                nodeData.setTreeNode(ATreeNodeUtil.getTreeNodeByPath(IMPORTITEMPATH));
                importItem.setData(nodeData);
                if (libEntry instanceof JarLibEntry) {
                    jarImportNodes.add(importEle);
                } else {
                    pmImportNodes.add(importEle);
                }
            }
            this.componentPref.setJavaImportNodes(jarImportNodes.toArray(new Node[jarImportNodes.size()]));
        }
    }
}
Also used : ILibEntry(org.talend.componentdesigner.model.ILibEntry) JarLibEntry(org.talend.componentdesigner.model.libentry.JarLibEntry) TreeNodeData(org.talend.componentdesigner.ui.composite.xmltree.TreeNodeData) TreeItem(org.eclipse.swt.widgets.TreeItem) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 3 with TreeNodeData

use of org.talend.componentdesigner.ui.composite.xmltree.TreeNodeData in project tdi-studio-se by Talend.

the class PerlXMLConfigWizardPage method fillImportItems.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.componentdesigner.ui.wizard.creatcomponent.AbstractXMLConfigPage#fillImportItems()
     */
protected void fillImportItems() {
    for (int i = 0; i < availableXmlTree.getItems().length; i++) {
        TreeItem item = availableXmlTree.getItem(i);
        if (item.getText().equals(CODEGENERATION)) {
            Node codeGenNode = ((TreeNodeData) item.getData()).getXMLNode();
            TreeItem importsItem = new TreeItem(item, SWT.CASCADE);
            importsItem.setText(IMPORTS);
            Element importsEle = codeGenNode.getOwnerDocument().createElement(IMPORTS);
            codeGenNode.appendChild(importsEle);
            TreeNodeData importsData = new TreeNodeData();
            importsData.setXMLNode(importsEle);
            importsData.setTreeNode(ATreeNodeUtil.getTreeNodeByPath(IMPORTSITEMPATH));
            importsItem.setData(importsData);
            List<Node> jarImportNodes = new ArrayList<Node>();
            List<Node> pmImportNodes = new ArrayList<Node>();
            for (ILibEntry libEntry : componentPref.getLibEntries()) {
                TreeItem importItem = new TreeItem(importsItem, SWT.CASCADE);
                importItem.setText(IMPORT);
                Element importEle = importsEle.getOwnerDocument().createElement(IMPORT);
                importsEle.appendChild(importEle);
                importEle.setAttribute(NAME, libEntry.getNamePrefix());
                importEle.setAttribute(MODULE, libEntry.getName());
                //$NON-NLS-1$
                importEle.setAttribute(REQUIRED, "true");
                TreeNodeData nodeData = new TreeNodeData();
                nodeData.putAttrValue(NAME, libEntry.getNamePrefix());
                nodeData.putAttrValue(MODULE, libEntry.getName());
                //$NON-NLS-1$
                nodeData.putAttrValue(REQUIRED, "true");
                nodeData.setXMLNode(importEle);
                nodeData.setTreeNode(ATreeNodeUtil.getTreeNodeByPath(IMPORTITEMPATH));
                importItem.setData(nodeData);
                if (libEntry instanceof JarLibEntry) {
                    jarImportNodes.add(importEle);
                } else {
                    pmImportNodes.add(importEle);
                }
            }
            this.componentPref.setPerlImportNodes(pmImportNodes.toArray(new Node[pmImportNodes.size()]));
        }
    }
}
Also used : ILibEntry(org.talend.componentdesigner.model.ILibEntry) JarLibEntry(org.talend.componentdesigner.model.libentry.JarLibEntry) TreeNodeData(org.talend.componentdesigner.ui.composite.xmltree.TreeNodeData) TreeItem(org.eclipse.swt.widgets.TreeItem) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Aggregations

TreeItem (org.eclipse.swt.widgets.TreeItem)3 TreeNodeData (org.talend.componentdesigner.ui.composite.xmltree.TreeNodeData)3 Node (org.w3c.dom.Node)3 ArrayList (java.util.ArrayList)2 ILibEntry (org.talend.componentdesigner.model.ILibEntry)2 JarLibEntry (org.talend.componentdesigner.model.libentry.JarLibEntry)2 Element (org.w3c.dom.Element)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Menu (org.eclipse.swt.widgets.Menu)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1