use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute in project tdi-studio-se by Talend.
the class FOXManager method initModel.
public void initModel() {
IMetadataTable metadataTable = foxComponent.getMetadataTable();
if (metadataTable == null) {
metadataTable = new MetadataTable();
}
String componentName = foxComponent.getComponent().getName();
// if (componentName.equals("tWriteXMLField")) { //$NON-NLS-1$ //$NON-NLS-2$
IConnection inConn = null;
for (IConnection conn : foxComponent.getIncomingConnections()) {
if ((conn.getLineStyle().equals(EConnectionType.FLOW_MAIN)) || (conn.getLineStyle().equals(EConnectionType.FLOW_REF))) {
inConn = conn;
break;
}
}
if (inConn != null) {
metadataTable = inConn.getMetadataTable();
}
// }
treeData = new ArrayList<FOXTreeNode>();
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
List<Map<String, String>> rootTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.ROOT);
for (Map<String, String> rootMap : rootTable) {
String newPath = rootMap.get(FileOutputXMLComponent.PATH);
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();
}
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 = this.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);
}
String columnName = rootMap.get(FileOutputXMLComponent.COLUMN);
if (columnName != null && columnName.length() > 0) {
temp.setColumn(metadataTable.getColumn(columnName));
}
}
// build group tree
current = mainNode;
currentPath = mainPath;
boolean isFirst = true;
List<Map<String, String>> groupTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.GROUP);
for (Map<String, String> groupMap : groupTable) {
String newPath = groupMap.get(FileOutputXMLComponent.PATH);
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();
}
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);
}
String columnName = groupMap.get(FileOutputXMLComponent.COLUMN);
if (columnName != null && columnName.length() > 0) {
temp.setColumn(metadataTable.getColumn(columnName));
}
}
// build loop tree
current = mainNode;
currentPath = mainPath;
isFirst = true;
List<Map<String, String>> loopTable = (List<Map<String, String>>) foxComponent.getTableList(FileOutputXMLComponent.LOOP);
for (Map<String, String> loopMap : loopTable) {
String newPath = loopMap.get(FileOutputXMLComponent.PATH);
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();
}
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 (rootNode == null) {
rootNode = temp;
}
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);
}
String columnName = loopMap.get(FileOutputXMLComponent.COLUMN);
if (columnName != null && columnName.length() > 0) {
temp.setColumn(metadataTable.getColumn(columnName));
}
}
if (rootNode == null) {
//$NON-NLS-1$
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 AddTreeNodeButton method updateStatus.
@Override
protected void updateStatus(TreeSelection selection) {
if (selection.getFirstElement() instanceof FOXTreeNode) {
FOXTreeNode node = (FOXTreeNode) selection.getFirstElement();
if (node == null) {
getButton().setEnabled(false);
return;
}
if (node instanceof Attribute) {
getButton().setEnabled(false);
return;
}
if (node instanceof NameSpaceNode) {
getButton().setEnabled(false);
return;
}
getButton().setEnabled(true);
} else {
getButton().setEnabled(false);
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute in project tdi-studio-se by Talend.
the class AddTreeNodeButton method updateStatus.
@Override
protected void updateStatus(TreeSelection selection) {
if (selection.getFirstElement() instanceof FOXTreeNode) {
FOXTreeNode node = (FOXTreeNode) selection.getFirstElement();
if (node == null) {
getButton().setEnabled(false);
return;
}
if (node instanceof Attribute) {
getButton().setEnabled(false);
return;
}
if (node instanceof NameSpaceNode) {
getButton().setEnabled(false);
return;
}
getButton().setEnabled(true);
} else {
getButton().setEnabled(false);
}
}
use of org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute in project tdi-studio-se by Talend.
the class MoveUpTreeNodeButton method updateStatus.
/*
* (non-Javadoc)
*
* @see org.talend.designer.fileoutputJSON.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
*/
@Override
protected void updateStatus(TreeSelection selection) {
if (selection.isEmpty()) {
getButton().setEnabled(false);
return;
}
final TreePath[] paths = selection.getPaths();
boolean sameSegment = true;
for (int i = 0; i < paths.length - 1; i++) {
if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
sameSegment = false;
}
}
if (sameSegment) {
getButton().setEnabled(true);
} else {
getButton().setEnabled(false);
return;
}
// if same segment ,they have the same parent and parent must be an element
FOXTreeNode foxNode = (FOXTreeNode) selection.getFirstElement();
if (foxNode.getParent() instanceof Element) {
final Element parent = (Element) foxNode.getParent();
if (parent == null) {
getButton().setEnabled(false);
return;
}
final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
final List<FOXTreeNode> elementChildren = parent.getElementChildren();
final Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
final Object next = iterator.next();
if (next instanceof Attribute) {
if (attrChildren.contains(next) && attrChildren.indexOf(next) == 0) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof NameSpaceNode) {
if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == 0) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof Element) {
if (elementChildren.contains(next) && elementChildren.indexOf(next) == 0) {
getButton().setEnabled(false);
return;
}
}
}
}
}
Aggregations