use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute in project tdi-studio-se by Talend.
the class SetJSONGroupAction method selectionChanged.
@Override
public void selectionChanged(IStructuredSelection selection) {
FOXTreeNode node = (FOXTreeNode) this.getStructuredSelection().getFirstElement();
if (node == null) {
this.setEnabled(false);
return;
}
if (((node instanceof Attribute) || node.hasLink())) {
this.setEnabled(TreeUtil.checkTreeGoupNode(node));
return;
}
if (node instanceof NameSpaceNode) {
this.setEnabled(false);
return;
}
this.setEnabled(TreeUtil.checkTreeGoupNode(node));
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute 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.Attribute 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.Attribute 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);
}
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method isMappedChoiceSubsOutput.
private boolean isMappedChoiceSubsOutput(FOXTreeNode node, String pXpath) {
List<FOXTreeNode> children = node.getChildren();
List<FOXTreeNode> subsChoice = new ArrayList<FOXTreeNode>();
XMLFileNode found = null;
for (FOXTreeNode child : children) {
if (child.isSubstitution() || child.isChoice()) {
subsChoice.add(child);
} else {
String childXpath = "";
if (child instanceof Element) {
childXpath = XmlMapUtil.getXPath(pXpath, child.getLabel(), NodeType.ELEMENT);
} else if (child instanceof Attribute) {
childXpath = XmlMapUtil.getXPath(pXpath, child.getLabel(), NodeType.ATTRIBUT);
} else if (child instanceof NameSpaceNode) {
childXpath = XmlMapUtil.getXPath(pXpath, child.getLabel(), NodeType.NAME_SPACE);
}
found = findXmlFileNode(childXpath, root);
if (found == null) {
found = findXmlFileNode(childXpath, group);
}
if (found == null) {
found = findXmlFileNode(childXpath, loop);
}
if (found != null) {
break;
}
}
}
if (found != null) {
return true;
}
if (!subsChoice.isEmpty()) {
for (FOXTreeNode foxNode : subsChoice) {
boolean isChildMapped = isMappedChoiceSubsOutput(foxNode, pXpath);
if (isChildMapped) {
return true;
}
}
}
return found != null;
}
Aggregations