use of org.talend.datatools.xml.utils.ATreeNode in project tdi-studio-se by Talend.
the class ImportTreeFromXMLAction method treeNodeAdapt.
private List<FOXTreeNode> treeNodeAdapt(String file) {
List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
try {
ATreeNode treeNode = SchemaPopulationUtil.getSchemaTree(file, true, 0);
String schemaName = getSelectedSchema();
String rootName = "";
if (treeNode.getValue() instanceof String) {
rootName += "/" + treeNode.getValue();
}
FOXTreeNode root = cloneATreeNode(treeNode, schemaName, rootName);
Element rootElement = (Element) root;
if (rootElement.getElementChildren() != null && rootElement.getElementChildren().size() > 0) {
for (FOXTreeNode foxTreeNode : rootElement.getElementChildren()) {
foxTreeNode.setParent(null);
list.add(foxTreeNode);
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
return list;
}
use of org.talend.datatools.xml.utils.ATreeNode in project tdi-studio-se by Talend.
the class ImportTreeFromXMLAction method cloneATreeNode.
private FOXTreeNode cloneATreeNode(ATreeNode treeNode, String schemaName, String currentPath) throws Exception {
FOXTreeNode node = null;
if (treeNode.getType() == ATreeNode.ATTRIBUTE_TYPE) {
node = new Attribute();
} else {
node = new Element();
}
// zli fixed for bug 7414
if (treeNode.getType() == ATreeNode.NAMESPACE_TYPE) {
node = new NameSpaceNode();
//$NON-NLS-1$
node.setLabel("");
node.setDefaultValue((String) treeNode.getValue());
} else {
node.setLabel((String) treeNode.getValue());
}
Object[] children = treeNode.getChildren();
if (children != null) {
for (Object element : children) {
if (element instanceof ATreeNode) {
ATreeNode child = (ATreeNode) element;
String newPath = currentPath + "/";
if (child.getValue() instanceof String) {
String elementName = (String) child.getValue();
if (currentPath.contains("/" + elementName + "/")) {
ExceptionHandler.process(new Exception("XSD ERROR: loop found. Item: " + elementName + " is already in the currentPath (" + currentPath + ")."));
continue;
}
newPath += elementName;
} else {
newPath += "unknownElement";
}
FOXTreeNode foxChild = cloneATreeNode(child, schemaName, newPath);
foxChild.setRow(schemaName);
node.addChild(foxChild);
}
}
}
return node;
}
use of org.talend.datatools.xml.utils.ATreeNode 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();
}
}
use of org.talend.datatools.xml.utils.ATreeNode in project tdi-studio-se by Talend.
the class AbstractJSONFileStepForm method getDefaultRootNode.
protected ATreeNode getDefaultRootNode(List<ATreeNode> rootNodes) {
if (rootNodes != null && rootNodes.size() > 0) {
EList<JSONFileNode> root = getConnection().getRoot();
JSONFileNode selectedNode = null;
if (root != null && root.size() > 0) {
selectedNode = root.get(0);
} else {
EList<JSONFileNode> loop = getConnection().getLoop();
if (loop != null && loop.size() > 0) {
selectedNode = loop.get(0);
}
}
if (selectedNode != null) {
String JSONPath = selectedNode.getJSONPath();
if (JSONPath != null && JSONPath.length() > 0) {
JSONPath = JSONPath.substring(JSONPath.lastIndexOf("/") + 1);
for (int i = 0; i < rootNodes.size(); i++) {
ATreeNode node = rootNodes.get(i);
if (JSONPath.equals(node.getValue())) {
return node;
}
}
}
}
}
return null;
}
use of org.talend.datatools.xml.utils.ATreeNode in project tdi-studio-se by Talend.
the class ATreeNodeUtil method findTreeNode.
private static ATreeNode findTreeNode(String nodeName, ATreeNode rootTreeNode) {
Object[] childNodes = rootTreeNode.getChildren();
ATreeNode aTreeNode = null;
for (Object node : childNodes) {
if (nodeName.equals(((ATreeNode) node).getValue())) {
return (ATreeNode) node;
} else {
continue;
}
}
return aTreeNode;
}
Aggregations