Search in sources :

Example 1 with RootNodeSelectDialog

use of org.talend.metadata.managment.ui.dialog.RootNodeSelectDialog in project tdi-studio-se by Talend.

the class ImportTreeFromXMLAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    List<FOXTreeNode> newInput = new ArrayList<FOXTreeNode>();
    String filePath = getFilePath();
    if (filePath == null) {
        return;
    }
    boolean changed = true;
    try {
        if (XmlUtil.isXSDFile(filePath)) {
            XSDSchema xsdSchema = TreeUtil.getXSDSchema(filePath);
            List<ATreeNode> list = new XSDPopulationUtil2().getAllRootNodes(xsdSchema);
            if (list.size() > 1) {
                RootNodeSelectDialog dialog = new RootNodeSelectDialog(xmlViewer.getControl().getShell(), list);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    ATreeNode selectedNode = dialog.getSelectedNode();
                    newInput = TreeUtil.getFoxTreeNodesByRootNode(xsdSchema, selectedNode);
                    changed = true;
                } else {
                    changed = false;
                }
            } else {
                newInput = TreeUtil.getFoxTreeNodesByRootNode(xsdSchema, list.get(0));
                changed = true;
            }
        } else {
            newInput = treeNodeAdapt(filePath);
            changed = true;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    if (newInput.size() == 0) {
        return;
    }
    if (changed) {
        // updateNode
        for (FOXTreeNode node : newInput) {
            foxui.updateNode(node, getSelectedSchema());
        }
        List<FOXTreeNode> treeData = foxui.getFoxManager().getTreeData(getSelectedSchema());
        treeData.clear();
        treeData.addAll(newInput);
        xmlViewer.setInput(foxui.getFoxManager().getTreeData());
        // TreeUtil.guessAndSetLoopNode((FOXTreeNode) xmlViewer.getTree().getItem(0).getData());
        xmlViewer.refresh();
        xmlViewer.expandToLevel(3);
        foxui.updateStatus();
        foxui.redrawLinkers();
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) ATreeNode(org.talend.datatools.xml.utils.ATreeNode) RootNodeSelectDialog(org.talend.metadata.managment.ui.dialog.RootNodeSelectDialog) ArrayList(java.util.ArrayList) XSDPopulationUtil2(org.talend.datatools.xml.utils.XSDPopulationUtil2) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

ArrayList (java.util.ArrayList)1 XSDSchema (org.eclipse.xsd.XSDSchema)1 ATreeNode (org.talend.datatools.xml.utils.ATreeNode)1 XSDPopulationUtil2 (org.talend.datatools.xml.utils.XSDPopulationUtil2)1 RootNodeSelectDialog (org.talend.metadata.managment.ui.dialog.RootNodeSelectDialog)1 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)1