use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute 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.Attribute in project tdi-studio-se by Talend.
the class CreateAttributeAction method createChildNode.
/**
* Create the child node of the input node
*
* @param node
*/
private void createChildNode(FOXTreeNode node) {
//$NON-NLS-1$
String label = "";
while (!org.talend.metadata.managment.ui.wizard.metadata.xml.utils.StringUtil.validateLabelForXML(label)) {
InputDialog dialog = new //$NON-NLS-1$
InputDialog(//$NON-NLS-1$
null, //$NON-NLS-1$
Messages.getString("CreateAttributeAction.1"), Messages.getString("CreateAttributeAction.2"), "", //$NON-NLS-1$ //$NON-NLS-2$
null);
int status = dialog.open();
if (status == InputDialog.OK) {
label = dialog.getValue().trim();
}
if (status == InputDialog.CANCEL) {
return;
}
}
FOXTreeNode child = new Attribute(label);
// add by wzhang. set the row name
child.setRow(node.getRow());
node.addChild(child);
this.xmlViewer.refresh();
this.xmlViewer.expandToLevel(node, 1);
foxui.redrawLinkers();
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute in project tdi-studio-se by Talend.
the class CreateElementAction method selectionChanged.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override
public void selectionChanged(IStructuredSelection selection) {
FOXTreeNode node = (FOXTreeNode) this.getStructuredSelection().getFirstElement();
if (node == null) {
this.setEnabled(false);
return;
}
if (node instanceof Attribute) {
this.setEnabled(false);
return;
}
if (node instanceof NameSpaceNode) {
this.setEnabled(false);
return;
}
// let user can add more children to a root.
// Element e = (Element) node;
// if (e.getParent() == null) {
// if (e.getElementChildren().size() >= 1) {
// this.setEnabled(false);
// return;
// }
// }
this.setEnabled(true);
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute 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++;
}
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute in project tdi-studio-se by Talend.
the class SetGroupAction method selectionChanged.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
*/
@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.value) {
this.setEnabled(TreeUtil.checkTreeGoupNode(node));
return;
}
if (node instanceof NameSpaceNode) {
this.setEnabled(false);
return;
}
this.setEnabled(TreeUtil.checkTreeGoupNode(node));
}
Aggregations