use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method prepareEmfTree.
private void prepareEmfTree(List<FOXTreeNode> list, TreeNode parent, boolean ignoreMapped) {
if (list == null || list.isEmpty()) {
return;
}
String xPath = parent.getXpath();
TreeNode realParentNode = parent;
if (parent.isSubstitution() || parent.isChoice()) {
realParentNode = XmlMapUtil.getRealParentNode(parent);
if (realParentNode != null) {
xPath = realParentNode.getXpath();
}
}
for (FOXTreeNode foxNode : list) {
TreeNode createTreeNode = createModel();
createTreeNode.setOptional(foxNode.isOptional());
String label = foxNode.getLabel();
createTreeNode.setName(label);
if (foxNode instanceof Element) {
createTreeNode.setNodeType(NodeType.ELEMENT);
if (foxNode.isChoice()) {
createTreeNode.setChoice(foxNode.isChoice());
} else if (foxNode.isSubstitution()) {
createTreeNode.setSubstitution(foxNode.isSubstitution());
}
} else if (foxNode instanceof Attribute) {
createTreeNode.setNodeType(NodeType.ATTRIBUT);
} else if (foxNode instanceof NameSpaceNode) {
createTreeNode.setNodeType(NodeType.NAME_SPACE);
createTreeNode.setDefaultValue(foxNode.getDefaultValue());
if (createTreeNode.getName() == null || createTreeNode.getName().equals("")) {
createTreeNode.setName(XmlMapUtil.DEFAULT_NAME_SPACE_PREFIX);
}
}
createTreeNode.setXpath(XmlMapUtil.getXPath(xPath, label, createTreeNode.getNodeType()));
// tempXpath is current xpath remove schema node xpath like: row1:newColumn1
String tempXpath = createTreeNode.getXpath().substring(schemaNode.getXpath().length() + 1);
if (createTreeNode.isChoice() || createTreeNode.isSubstitution()) {
if (!isMappedChoiceSubs(foxNode, xPath)) {
continue;
}
} else if (!ignoreMapped && !isMappedChild(tempXpath)) {
continue;
}
// get talend type from metadata table
String dataType = null;
if (targetAbsolutePath != null) {
dataType = targetAbsolutePath.get(tempXpath);
}
if (dataType == null) {
dataType = foxNode.getDataType();
}
if (dataType != null && !"".equals(dataType)) {
if (dataType.equals("id_Date")) {
String datePattern = targetDatePattern.get(tempXpath);
if (datePattern == null || "".equals(datePattern)) {
//$NON-NLS-1$
//$NON-NLS-1$
datePattern = "\"dd-MM-yyyy\"";
}
createTreeNode.setPattern(datePattern);
}
createTreeNode.setType(dataType);
} else {
createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
}
if (tempXpath.equals(absoluteXPathQuery)) {
createTreeNode.setLoop(true);
createTreeNode.setOptional(foxNode.isOptional());
loopNode = createTreeNode;
}
parent.getChildren().add(createTreeNode);
if (createTreeNode.isLoop()) {
XmlMapUtil.upsetMainNode(createTreeNode);
}
if (foxNode.getChildren() != null && !foxNode.getChildren().isEmpty()) {
prepareEmfTree(foxNode.getChildren(), createTreeNode, ignoreMapped);
}
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method prepareEmfTreeFromXml.
private void prepareEmfTreeFromXml(XmlFileConnection connection) throws Exception {
if (!connection.isInputModel()) {
prepareEmfTreeFromConnection(connection);
// String file = connection.getXmlFilePath();
// List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
// // fix for TDI-20671 , root element is loop in output
// String rootXpath = null;
// if (!connection.getRoot().isEmpty()) {
// rootXpath = connection.getRoot().get(0).getXMLPath();
// } else if (!connection.getLoop().isEmpty()) {
// rootXpath = connection.getLoop().get(0).getXMLPath();
// }
// File xmlFile = new File(file);
// if (xmlFile.exists() && !file.endsWith(".zip")) {
// list = TreeUtil.getFoxTreeNodesForXmlMap(xmlFile.getAbsolutePath(), rootXpath, true);
// } else if (connection.getFileContent() != null && connection.getFileContent().length > 0) {
// String xsdFile = initFileContent(connection);
// if (xsdFile != null && new File(xsdFile).exists()) {
// String targetNameSpace = connection.getTargetNameSpace();
// list = TreeUtil.getFoxTreeNodesForXmlMap(xsdFile, rootXpath, targetNameSpace, true);
// } else {
// // for manually created output
// prepareEmfTreeFromConnection(connection);
// return;
//
// }
// } else {
// // for manually created output
// prepareEmfTreeFromConnection(connection);
// return;
// }
// schemaNode.getChildren().clear();
// root = connection.getRoot();
// loop = connection.getLoop();
// group = connection.getGroup();
// groupElements = new ArrayList<TreeNode>();
// prepareModelFromOutput(list, schemaNode);
// if (loopNode != null) {
// fillGroup(loopNode, groupElements);
// } else {
// if (!schemaNode.getChildren().isEmpty()) {
// schemaNode.getChildren().get(0).setLoop(true);
// }
// }
} else {
List<SchemaTarget> schemaTargets = null;
if (!connection.getSchema().isEmpty() && connection.getSchema().get(0) instanceof XmlXPathLoopDescriptorImpl) {
absoluteXPathQuery = ((XmlXPathLoopDescriptorImpl) connection.getSchema().get(0)).getAbsoluteXPathQuery();
schemaTargets = ((XmlXPathLoopDescriptorImpl) connection.getSchema().get(0)).getSchemaTargets();
metadataTable = ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0];
}
// fix for TDI-8707 : only import mapped elements from connection to xml map
if (schemaTargets == null || schemaTargets.isEmpty()) {
return;
}
this.schemaTargets = schemaTargets;
String file = connection.getXmlFilePath();
List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
File xmlFile = new File(file);
if (xmlFile.exists()) {
list = TreeUtil.getFoxTreeNodesForXmlMap(xmlFile.getAbsolutePath(), absoluteXPathQuery, true);
} else if (connection.getFileContent() != null && connection.getFileContent().length > 0) {
String xsdFile = initFileContent(connection);
if (xsdFile != null && new File(xsdFile).exists()) {
list = TreeUtil.getFoxTreeNodesForXmlMap(xsdFile, absoluteXPathQuery, true);
}
} else {
throw new FileNotFoundException();
}
schemaNode.getChildren().clear();
prepareEmfTree(list, schemaNode);
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.
the class JSONFileSchema2TreeLinker method createLinks.
public void createLinks() {
removeAllLinks();
getBackgroundRefresher().refreshBackground();
ProgressDialog progressDialog = new ProgressDialog(getSource().getShell(), 1000) {
private IProgressMonitor monitorWrap;
@Override
public void run(IProgressMonitor monitor) {
TreeItem root = jsonViewer.getTree().getItem(0);
// if (getManager().getFoxComponent().istFileOutputMSXML()) {
// List<FOXTreeNode> treeData = getManager().getTreeData(getManager().getCurrentSchema());
// if (treeData != null && treeData.size() > 0) {
// FOXTreeNode rootTreeData = treeData.get(0);
// for (TreeItem item : xmlViewer.getTree().getItems()) {
// if (rootTreeData == item.getData()) {
// root = item;
// break;
// }
// }
// }
// }
List<TreeItem> allItems = TreeUtils.collectAllItems(root);
monitorWrap = new EventLoopProgressMonitor(monitor);
String taskName = "Loop links creation ...";
int totalWork = allItems.size();
//$NON-NLS-1$
monitorWrap.beginTask(taskName, totalWork);
for (int i = 0; i < totalWork; i++) {
if (monitorWrap.isCanceled()) {
return;
}
TreeItem treeItem = allItems.get(i);
FOXTreeNode node = (FOXTreeNode) treeItem.getData();
if (node.getColumn() == null) {
//$NON-NLS-1$
continue;
}
createLoopLinks(node.getColumn().getLabel(), treeItem, monitorWrap, i == totalWork - 1);
monitorWrap.worked(1);
}
monitorWrap.done();
}
};
try {
progressDialog.executeProcess();
} catch (InvocationTargetException e) {
e.printStackTrace();
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.
the class JSONFileTreeViewerProvider method getChildren.
public Object[] getChildren(Object parentElement) {
FOXTreeNode treeNode = (FOXTreeNode) parentElement;
List<FOXTreeNode> children = treeNode.getChildren();
return children.toArray();
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.
the class MoveDownTreeNodeButton method updateStatus.
/*
* (non-Javadoc)
*
* @see org.talend.designer.fileoutputJSON.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
*/
@Override
protected void updateStatus(TreeSelection selection) {
if (selection.isEmpty()) {
getButton().setEnabled(false);
return;
}
final TreePath[] paths = selection.getPaths();
boolean sameSegment = true;
for (int i = 0; i < paths.length - 1; i++) {
if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
sameSegment = false;
}
}
if (sameSegment) {
getButton().setEnabled(true);
} else {
getButton().setEnabled(false);
return;
}
// if same segment ,they have the same parent and parent must be an element
FOXTreeNode foxNode = (FOXTreeNode) selection.getFirstElement();
if (foxNode.getParent() instanceof Element) {
final Element parent = (Element) foxNode.getParent();
final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
final List<FOXTreeNode> elementChildren = parent.getElementChildren();
final Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
final Object next = iterator.next();
if (next instanceof Attribute) {
if (attrChildren.contains(next) && attrChildren.indexOf(next) == attrChildren.size() - 1) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof NameSpaceNode) {
if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == nameSpaceChildren.size() - 1) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof Element) {
if (elementChildren.contains(next) && elementChildren.indexOf(next) == elementChildren.size() - 1) {
getButton().setEnabled(false);
return;
}
}
}
}
if (parent == null) {
getButton().setEnabled(false);
return;
}
}
Aggregations