use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.
the class JSONFileOutputStep2Form method updateConnection.
public void updateConnection() {
ConnectionHelper.getTables(getConnection());
EList root = getConnection().getRoot();
EList loop = getConnection().getLoop();
EList group = getConnection().getGroup();
root.clear();
loop.clear();
group.clear();
List<FOXTreeNode> node = (List<FOXTreeNode>) JSONViewer.getInput();
FOXTreeNode foxTreeNode = node.get(0);
if (foxTreeNode != null) {
initNodeOrder(foxTreeNode);
if (!foxTreeNode.isLoop()) {
tableLoader((Element) foxTreeNode, "", root, foxTreeNode.getDefaultValue());
}
Element loopNode = (Element) TreeUtil.getLoopNode(foxTreeNode);
if (loopNode != null) {
String path = TreeUtil.getPath(loopNode);
tableLoader(loopNode, path.substring(0, path.lastIndexOf("/")), loop, loopNode.getDefaultValue());
}
Element groupNode = (Element) TreeUtil.getGroupNode(foxTreeNode);
if (groupNode != null) {
String path = TreeUtil.getPath(groupNode);
tableLoader(groupNode, path.substring(0, path.lastIndexOf("/")), group, groupNode.getDefaultValue());
}
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.
the class JSONFileOutputStep2Form method addElement.
protected FOXTreeNode addElement(FOXTreeNode current, String currentPath, String newPath, String defaultValue) {
//$NON-NLS-1$
String name = newPath.substring(newPath.lastIndexOf("/") + 1);
//$NON-NLS-1$
String parentPath = newPath.substring(0, newPath.lastIndexOf("/"));
FOXTreeNode temp = new Element(name, defaultValue);
if (current == null) {
// root node
return temp;
}
if (currentPath.equals(parentPath)) {
current.addChild(temp);
} else {
//$NON-NLS-1$
String[] nods = currentPath.split("/");
//$NON-NLS-1$
String[] newNods = parentPath.split("/");
int parentLevel = 0;
int checkLength = nods.length < newNods.length ? nods.length : newNods.length;
for (int i = 1; i < checkLength; i++) {
if (nods[i].equals(newNods[i])) {
parentLevel = i;
}
}
FOXTreeNode parent = current;
for (int i = 0; i < nods.length - (parentLevel + 1); i++) {
FOXTreeNode tmpParent = parent.getParent();
if (tmpParent == null) {
break;
}
parent = tmpParent;
}
if (parent != null)
parent.addChild(temp);
}
return temp;
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.
the class AbstractJSONFileStepForm method initMetadataTable.
protected void initMetadataTable(List<FOXTreeNode> list, EList columnList) {
int maxColumnsNumber = CoreUIPlugin.getDefault().getPreferenceStore().getInt(ITalendCorePrefConstants.MAXIMUM_AMOUNT_OF_COLUMNS_FOR_XML);
for (FOXTreeNode node : list) {
if (columnList.size() > maxColumnsNumber) {
return;
}
MetadataEmfTableEditor editor = new MetadataEmfTableEditor();
if (node instanceof Element) {
String label = node.getLabel();
if (!node.hasChildren() && label != null && !label.equals("")) {
String columnName = label;
if (columnName.contains(":")) {
//$NON-NLS-1$
//$NON-NLS-1$
columnName = columnName.split(":")[1];
}
columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
String dataType = node.getDataType();
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
metadataColumn.setOriginalField(label);
metadataColumn.setTalendType(dataType);
columnList.add(metadataColumn);
node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
}
}
if (node instanceof Attribute) {
String label = node.getLabel();
if (label != null && !label.equals("")) {
String columnName = label;
if (columnName.contains(":")) {
//$NON-NLS-1$
//$NON-NLS-1$
columnName = columnName.split(":")[1];
}
columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
String dataType = node.getDataType();
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
metadataColumn.setOriginalField(label);
metadataColumn.setTalendType(dataType);
columnList.add(metadataColumn);
node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
}
}
if (node.hasChildren()) {
List<FOXTreeNode> children = node.getChildren();
initMetadataTable(children, columnList);
}
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.
the class JSONFileOutputStep2Form method initJSONTreeData.
private void initJSONTreeData() {
treeData.clear();
// metadataColumnList.clear();
EList root = getConnection().getRoot();
EList loop = getConnection().getLoop();
EList group = getConnection().getGroup();
// initialMetadataColumn();
FOXTreeNode rootNode = null;
FOXTreeNode current = null;
FOXTreeNode temp = null;
FOXTreeNode mainNode = null;
String mainPath = null;
String currentPath = null;
String defaultValue = null;
int nodeOrder = 0;
boolean haveOrder = true;
// build root tree
for (int i = 0; i < root.size(); i++) {
JSONFileNode node = (JSONFileNode) root.get(i);
String newPath = node.getJSONPath();
defaultValue = node.getDefaultValue();
String type = node.getType();
String orderValue = String.valueOf(node.getOrder());
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = node.getOrder();
}
if (node.getAttribute().equals("attri")) {
temp = new Attribute(newPath);
temp.setDefaultValue(defaultValue);
temp.setAttribute(true);
temp.setDataType(type);
current.addChild(temp);
} else if (node.getAttribute().equals("ns")) {
temp = new NameSpaceNode(newPath);
temp.setDefaultValue(defaultValue);
temp.setNameSpace(true);
temp.setDataType(type);
current.addChild(temp);
} else {
temp = this.addElement(current, currentPath, newPath, defaultValue);
temp.setDataType(type);
if (rootNode == null) {
rootNode = temp;
}
if (node.getAttribute().equals("main")) {
temp.setMain(true);
mainNode = temp;
mainPath = newPath;
}
current = temp;
currentPath = newPath;
}
if (haveOrder) {
temp.setOrder(nodeOrder);
}
String columnName = node.getRelatedColumn();
if (columnName != null && columnName.length() > 0) {
temp.setColumn(getColumn(columnName));
}
}
// build group tree
current = mainNode;
currentPath = mainPath;
boolean isFirst = true;
for (int i = 0; i < group.size(); i++) {
JSONFileNode node = (JSONFileNode) group.get(i);
String newPath = node.getJSONPath();
defaultValue = node.getDefaultValue();
String type = node.getType();
String orderValue = String.valueOf(node.getOrder());
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = node.getOrder();
}
if (node.getAttribute().equals("attri")) {
temp = new Attribute(newPath);
temp.setDefaultValue(defaultValue);
temp.setAttribute(true);
temp.setDataType(type);
current.addChild(temp);
} else if (node.getAttribute().equals("ns")) {
temp = new NameSpaceNode(newPath);
temp.setDefaultValue(defaultValue);
temp.setNameSpace(true);
temp.setDataType(type);
current.addChild(temp);
} else {
temp = this.addElement(current, currentPath, newPath, defaultValue);
temp.setDataType(type);
if (node.getAttribute().equals("main")) {
temp.setMain(true);
mainNode = temp;
mainPath = newPath;
}
if (isFirst) {
temp.setGroup(true);
isFirst = false;
}
current = temp;
currentPath = newPath;
}
if (haveOrder) {
temp.setOrder(nodeOrder);
}
String columnName = node.getRelatedColumn();
if (columnName != null && columnName.length() > 0) {
temp.setColumn(getColumn(columnName));
}
}
// build loop tree
current = mainNode;
currentPath = mainPath;
isFirst = true;
for (int i = 0; i < loop.size(); i++) {
JSONFileNode node = (JSONFileNode) loop.get(i);
String newPath = node.getJSONPath();
defaultValue = node.getDefaultValue();
String type = node.getType();
String orderValue = String.valueOf(node.getOrder());
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = node.getOrder();
}
if (node.getAttribute().equals("attri")) {
temp = new Attribute(newPath);
temp.setDefaultValue(defaultValue);
temp.setAttribute(true);
temp.setDataType(type);
temp.setDataType(type);
current.addChild(temp);
} else if (node.getAttribute().equals("ns")) {
temp = new NameSpaceNode(newPath);
temp.setDefaultValue(defaultValue);
temp.setNameSpace(true);
temp.setDataType(type);
current.addChild(temp);
} else {
temp = this.addElement(current, currentPath, newPath, defaultValue);
temp.setDataType(type);
// fix for TDI-18802 , if root node is loop
if (rootNode == null) {
rootNode = temp;
}
if (node.getAttribute().equals("main")) {
temp.setMain(true);
mainNode = temp;
mainPath = newPath;
}
if (isFirst) {
temp.setLoop(true);
isFirst = false;
}
current = temp;
currentPath = newPath;
}
if (haveOrder) {
temp.setOrder(nodeOrder);
}
String columnName = node.getRelatedColumn();
if (columnName != null && columnName.length() > 0) {
temp.setColumn(getColumn(columnName));
}
}
if (rootNode == null) {
rootNode = new Element("rootTag");
}
rootNode.setParent(null);
if (haveOrder) {
orderNode(rootNode);
}
treeData.add(rootNode);
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.
the class ImportTreeFromXml method prepareEmfTreeNode.
private void prepareEmfTreeNode(List<FOXTreeNode> list, TreeNode parent) {
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 = null;
if (input) {
createTreeNode = XmlmapFactory.eINSTANCE.createTreeNode();
} else {
createTreeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
}
String label = foxNode.getLabel();
createTreeNode.setName(label);
createTreeNode.setOptional(foxNode.isOptional());
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()));
if (foxNode.getDataType() != null && !"".equals(foxNode.getDataType())) {
if (foxNode.getDataType().equals("id_Date")) {
//$NON-NLS-1$
createTreeNode.setPattern("\"dd-MM-yyyy\"");
}
createTreeNode.setType(foxNode.getDataType());
} else {
createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
}
parent.getChildren().add(createTreeNode);
if (foxNode.getChildren() != null && !foxNode.getChildren().isEmpty()) {
prepareEmfTreeNode(foxNode.getChildren(), createTreeNode);
}
}
}
Aggregations