use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode 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.FOXTreeNode in project tdi-studio-se by Talend.
the class AbstractJSONFileStepForm method tableLoader.
protected void tableLoader(Element element, String parentPath, List<JSONFileNode> table, String defaultValue) {
JSONFileNode JSONFileNode = JsonFactory.eINSTANCE.createJSONFileNode();
String currentPath = parentPath + "/" + element.getLabel();
JSONFileNode.setJSONPath(currentPath);
JSONFileNode.setRelatedColumn(element.getColumnLabel());
JSONFileNode.setAttribute(element.isMain() ? "main" : "branch");
JSONFileNode.setDefaultValue(defaultValue);
JSONFileNode.setType(element.getDataType());
JSONFileNode.setOrder(getNodeOrder(element));
table.add(JSONFileNode);
for (FOXTreeNode att : element.getAttributeChildren()) {
JSONFileNode = JsonFactory.eINSTANCE.createJSONFileNode();
JSONFileNode.setJSONPath(att.getLabel());
JSONFileNode.setRelatedColumn(att.getColumnLabel());
JSONFileNode.setAttribute("attri");
JSONFileNode.setDefaultValue(att.getDefaultValue());
JSONFileNode.setType(att.getDataType());
JSONFileNode.setOrder(getNodeOrder(att));
table.add(JSONFileNode);
}
for (FOXTreeNode att : element.getNameSpaceChildren()) {
JSONFileNode = JsonFactory.eINSTANCE.createJSONFileNode();
JSONFileNode.setJSONPath(att.getLabel());
JSONFileNode.setRelatedColumn(att.getColumnLabel());
JSONFileNode.setAttribute("ns");
JSONFileNode.setDefaultValue(att.getDefaultValue());
JSONFileNode.setType(att.getDataType());
JSONFileNode.setOrder(getNodeOrder(att));
table.add(JSONFileNode);
}
List<FOXTreeNode> children = element.getElementChildren();
for (FOXTreeNode child : children) {
if (!child.isGroup() && !child.isLoop()) {
tableLoader((Element) child, currentPath, table, child.getDefaultValue());
}
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode 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.FOXTreeNode in project tdi-studio-se by Talend.
the class JSONFileOutputStep2Form method updateJSONTreeViewer.
private void updateJSONTreeViewer() {
LinksManager<Item, Object, Tree, Object> linkManager = linker.getLinkManager();
List<LinkDescriptor<Item, Object, Tree, Object>> links = linkManager.getLinks();
for (int i = 0; i < links.size(); i++) {
LinkDescriptor<Item, Object, Tree, Object> linkDescriptor = links.get(i);
IExtremityLink<Item, Object> ex1 = linkDescriptor.getExtremity1();
IExtremityLink<Tree, Object> ex2 = linkDescriptor.getExtremity2();
MetadataColumn metaColumn = (MetadataColumn) ex1.getDataItem();
FOXTreeNode node = (FOXTreeNode) ex2.getDataItem();
if (ex1.getGraphicalObject() != null) {
Item item = ex1.getGraphicalObject();
if (!item.isDisposed() && metaColumn.equals(item.getData())) {
node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metaColumn));
} else {
node.setColumn(null);
}
}
node.setDataType(metaColumn.getTalendType());
}
JSONViewer.refresh();
updateConnection();
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode in project tdi-studio-se by Talend.
the class JSONFileOutputStep2Form method checkFieldsValue.
@Override
protected boolean checkFieldsValue() {
int num = 0, rootNum = 0;
StringBuffer msgError = new StringBuffer();
List<FOXTreeNode> onLoopNodes = new ArrayList<FOXTreeNode>();
for (FOXTreeNode node : treeData) {
FOXTreeNode rootFOXTreeNode = TreeUtil.getRootFOXTreeNode(node);
if (rootFOXTreeNode != null) {
if (existedLoopNode(rootFOXTreeNode)) {
num++;
} else {
onLoopNodes.add(rootFOXTreeNode);
}
rootNum++;
}
}
if (num != rootNum) {
msgError.append("Require set as loop\n");
}
if (linker.isNoLinker()) {
msgError.append("No source and target linked");
}
if ("".equals(msgError.toString())) {
updateStatus(IStatus.OK, null);
return true;
}
updateStatus(IStatus.ERROR, msgError.toString());
return false;
}
Aggregations