use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element 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.metadata.managment.ui.wizard.metadata.xml.node.Element 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.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.
the class UIManager method validateRootElement.
public boolean validateRootElement() {
List<FOXTreeNode> treeData = foxManager.getTreeData();
for (int i = 0; i < treeData.size() - 1; i++) {
Object obj1 = treeData.get(i);
Object obj2 = treeData.get(i + 1);
if (obj1 instanceof Element && obj2 instanceof Element) {
Element elem1 = (Element) obj1;
Element elem2 = (Element) obj2;
if (!elem1.getLabel().equals(elem2.getLabel())) {
return false;
}
}
}
return true;
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.
the class CreateElementAction method createChildNode.
/**
* Create the child node of the input node
*
* @param node
*/
private boolean createChildNode(FOXTreeNode node) {
if (node.getColumn() != null) {
if (!//$NON-NLS-1$
MessageDialog.openConfirm(//$NON-NLS-1$
xmlViewer.getControl().getShell(), //$NON-NLS-1$
Messages.getString("CreateElementAction.0"), //$NON-NLS-1$
Messages.getString("CreateElementAction.1") + node.getLabel() + "\"?")) {
//$NON-NLS-1$
return false;
}
node.setColumn(null);
}
//$NON-NLS-1$
String label = "";
while (!StringUtil.validateLabelForXML(label)) {
InputDialog dialog = new InputDialog(null, //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("CreateElementAction.4"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("CreateElementAction.5"), "", //$NON-NLS-1$
null);
int status = dialog.open();
if (status == InputDialog.OK) {
label = dialog.getValue().trim();
}
if (status == InputDialog.CANCEL) {
return false;
}
}
FOXTreeNode child = new Element(label);
// add by wzhang. set the row name
child.setRow(node.getRow());
node.addChild(child);
this.xmlViewer.refresh();
this.xmlViewer.expandToLevel(node, 1);
return true;
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element in project tdi-studio-se by Talend.
the class MultiFOXManager method initModel.
public void initModel() {
int i = 0;
List<? extends IConnection> incomingConnections = NodeUtil.getIncomingConnections(foxComponent, IConnectionCategory.FLOW);
for (IConnection connection : incomingConnections) {
IMetadataTable metadataTable = connection.getMetadataTable();
metadataTable.setLabel(connection.getUniqueName());
treeData = new ArrayList<FOXTreeNode>();
if (// the first schema as current
i == 0)
currentSchema = metadataTable.getLabel();
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;
//$NON-NLS-1$
String schemaId = metadataTable.getLabel() + ":";
// build root tree
List<Map<String, String>> rootTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.ROOT);
if (rootTable != null) {
for (Map<String, String> rootMap : rootTable) {
String newPath = rootMap.get(FileOutputXMLComponent.PATH);
String columnName = rootMap.get(FileOutputXMLComponent.COLUMN);
defaultValue = rootMap.get(FileOutputXMLComponent.VALUE);
String orderValue = rootMap.get(FileOutputXMLComponent.ORDER);
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = Integer.valueOf(rootMap.get(FileOutputXMLComponent.ORDER)).intValue();
}
//$NON-NLS-1$
String flag = columnName + ":";
if (columnName != null && columnName.length() > 0 && !flag.startsWith(metadataTable.getLabel() + ":")) {
//$NON-NLS-1$
continue;
}
if (rootMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("attri")) {
//$NON-NLS-1$
temp = new Attribute(newPath);
temp.setDefaultValue(defaultValue);
temp.setAttribute(true);
current.addChild(temp);
} else if (rootMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("ns")) {
//$NON-NLS-1$
temp = new NameSpaceNode(newPath);
temp.setDefaultValue(defaultValue);
temp.setNameSpace(true);
current.addChild(temp);
} else {
temp = addElement(current, currentPath, newPath, defaultValue);
if (rootNode == null) {
rootNode = temp;
}
if (rootMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("main")) {
//$NON-NLS-1$
temp.setMain(true);
mainNode = temp;
mainPath = newPath;
}
current = temp;
currentPath = newPath;
}
if (haveOrder) {
temp.setOrder(nodeOrder);
}
temp.setRow(metadataTable.getLabel());
if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
//$NON-NLS-1$
columnName = columnName.replace(schemaId, "");
temp.setColumn(metadataTable.getColumn(columnName));
temp.setTable(metadataTable);
}
}
}
// build group tree
current = mainNode;
currentPath = mainPath;
boolean isFirst = true;
List<Map<String, String>> groupTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.GROUP);
if (groupTable != null) {
for (Map<String, String> groupMap : groupTable) {
String newPath = groupMap.get(FileOutputXMLComponent.PATH);
String columnName = groupMap.get(FileOutputXMLComponent.COLUMN);
defaultValue = groupMap.get(FileOutputXMLComponent.VALUE);
String orderValue = groupMap.get(FileOutputXMLComponent.ORDER);
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = Integer.valueOf(groupMap.get(FileOutputXMLComponent.ORDER)).intValue();
}
//$NON-NLS-1$
String flag = columnName + ":";
if (columnName != null && columnName.length() > 0 && !flag.startsWith(metadataTable.getLabel() + ":")) {
//$NON-NLS-1$
continue;
}
if (groupMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("attri")) {
//$NON-NLS-1$
temp = new Attribute(newPath);
temp.setDefaultValue(defaultValue);
temp.setAttribute(true);
current.addChild(temp);
} else if (groupMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("ns")) {
//$NON-NLS-1$
temp = new NameSpaceNode(newPath);
temp.setDefaultValue(defaultValue);
temp.setNameSpace(true);
current.addChild(temp);
} else {
temp = this.addElement(current, currentPath, newPath, defaultValue);
if (groupMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("main")) {
//$NON-NLS-1$
temp.setMain(true);
mainNode = temp;
mainPath = newPath;
}
if (isFirst) {
temp.setGroup(true);
isFirst = false;
}
current = temp;
currentPath = newPath;
}
if (haveOrder) {
temp.setOrder(nodeOrder);
}
temp.setRow(metadataTable.getLabel());
if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
//$NON-NLS-1$
columnName = columnName.replace(schemaId, "");
temp.setColumn(metadataTable.getColumn(columnName));
temp.setTable(metadataTable);
}
}
}
// build loop tree
current = mainNode;
currentPath = mainPath;
isFirst = true;
List<Map<String, String>> loopTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.LOOP);
if (loopTable != null) {
for (Map<String, String> loopMap : loopTable) {
String newPath = loopMap.get(FileOutputXMLComponent.PATH);
String columnName = loopMap.get(FileOutputXMLComponent.COLUMN);
defaultValue = loopMap.get(FileOutputXMLComponent.VALUE);
String orderValue = loopMap.get(FileOutputXMLComponent.ORDER);
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = Integer.valueOf(loopMap.get(FileOutputXMLComponent.ORDER)).intValue();
}
//$NON-NLS-1$
String flag = columnName + ":";
if (columnName != null && columnName.length() > 0 && !flag.startsWith(metadataTable.getLabel() + ":")) {
//$NON-NLS-1$
continue;
}
if (loopMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("attri")) {
//$NON-NLS-1$
temp = new Attribute(newPath);
temp.setDefaultValue(defaultValue);
temp.setAttribute(true);
current.addChild(temp);
} else if (loopMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("ns")) {
//$NON-NLS-1$
temp = new NameSpaceNode(newPath);
temp.setDefaultValue(defaultValue);
temp.setNameSpace(true);
current.addChild(temp);
} else {
temp = this.addElement(current, currentPath, newPath, defaultValue);
if (loopMap.get(FileOutputXMLComponent.ATTRIBUTE).equals("main")) {
//$NON-NLS-1$
temp.setMain(true);
}
if (isFirst) {
temp.setLoop(true);
isFirst = false;
}
current = temp;
currentPath = newPath;
}
if (haveOrder) {
temp.setOrder(nodeOrder);
}
temp.setRow(metadataTable.getLabel());
if (columnName != null && columnName.length() > 0 && columnName.startsWith(schemaId)) {
//$NON-NLS-1$
columnName = columnName.replace(schemaId, "");
temp.setColumn(metadataTable.getColumn(columnName));
temp.setTable(metadataTable);
}
}
if (rootNode == null) {
//$NON-NLS-1$
rootNode = new Element("rootTag");
}
rootNode.setParent(null);
if (haveOrder) {
orderNode(rootNode);
}
treeData.add(rootNode);
rootNode.setRow(metadataTable.getLabel());
contents.put(metadataTable.getLabel(), treeData);
i++;
}
}
}
Aggregations