use of org.talend.designer.hl7.ui.data.Element in project tdi-studio-se by Talend.
the class HL7OutputUI method initLinker.
private void initLinker(TreeItem node, TableItem[] tableItems) {
HL7TreeNode treeNode = (HL7TreeNode) node.getData();
IMetadataColumn column = null;
if (treeNode != null) {
column = treeNode.getColumn();
}
if (column != null) {
if (this.gethl7Manager().getHl7Component().isHL7Output() && treeNode.getChildren().size() <= 0) {
for (TableItem tableItem : tableItems) {
IMetadataColumn mColumn = (IMetadataColumn) tableItem.getData();
if (mColumn.getLabel().equals(column.getLabel())) {
linker.addLoopLink(tableItem, tableItem.getData(), xmlViewer.getTree(), treeNode, true);
break;
}
}
}
for (TableItem tableItem : tableItems) {
IMetadataColumn mColumn = (IMetadataColumn) tableItem.getData();
if (mColumn.getLabel().equals(column.getLabel())) {
linker.addLoopLink(tableItem, tableItem.getData(), xmlViewer.getTree(), treeNode, true);
break;
}
}
}
TreeItem[] children = node.getItems();
for (TreeItem element : children) {
initLinker(element, tableItems);
}
}
use of org.talend.designer.hl7.ui.data.Element in project tdi-studio-se by Talend.
the class SchemaXMLDragAndDropHandler method setTreeNodeRow.
// reset all the treenode add row to relative column
// private void resetTree(HL7TreeNode root, String row) {
// root.getChildren();
// for (TreeItem item : items) {
// setTreeNodeRow(item, row);
// }
// }
// reset all the treeNode add row to relative column
private void setTreeNodeRow(HL7TreeNode root, String row) {
if (root == null)
return;
root.setRow(row);
if (root instanceof Element) {
Element element = (Element) root;
List<HL7TreeNode> children = element.getElementChildren();
for (HL7TreeNode child : children) {
setTreeNodeRow(child, row);
}
children = element.getNameSpaceChildren();
for (HL7TreeNode child : children) {
setTreeNodeRow(child, row);
}
}
List<HL7TreeNode> children = root.getChildren();
for (HL7TreeNode child : children) {
setTreeNodeRow(child, row);
}
}
use of org.talend.designer.hl7.ui.data.Element in project tdi-studio-se by Talend.
the class CreateHL7ElementAction method createChildNode.
/**
* Create the child node of the input node
*
* @param node
*/
private boolean createChildNode(final HL7TreeNode node) {
if (node.getColumn() != null) {
if (!MessageDialog.openConfirm(xmlViewer.getControl().getShell(), "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element" + node.getLabel() + "\"?")) {
return false;
}
node.setColumn(null);
}
String label = "";
final String nodeLabel = node.getLabel() + "-";
while (!StringUtil.validateLabelForXML(label)) {
// add validator
IInputValidator validator = new IInputValidator() {
@Override
public String isValid(String newText) {
if (newText != null) {
String text = newText.trim();
for (HL7TreeNode children : node.getChildren()) {
if (text.equals(children.getLabel())) {
//$NON-NLS-1$
return "The name already existed.";
}
}
}
return null;
}
};
InputDialog dialog = new InputDialog(null, "Input element's label", "Input the new element's valid label", nodeLabel, validator) {
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override
protected void okPressed() {
super.okPressed();
}
};
dialog.setErrorMessage("name is error");
int status = dialog.open();
if (status == InputDialog.OK) {
label = dialog.getValue().trim();
}
if (status == InputDialog.CANCEL) {
return false;
}
}
HL7TreeNode child = new Element(label);
// if the root not have CurSchema
if (node.getRow() == null || node.getRow().equals("")) {
if (hl7ui != null && hl7ui.gethl7Manager() instanceof HL7OutputManager) {
if (label.length() == 3) {
child.setRow(label);
IMetadataTable table = null;
for (IMetadataTable curTable : hl7ui.gethl7Manager().getHl7Component().getMetadataList()) {
if (label.equals(curTable.getLabel())) {
table = curTable;
break;
}
}
if (table == null) {
table = new MetadataTable();
table.setLabel(label);
table.setTableName(label);
hl7ui.gethl7Manager().getHl7Component().getMetadataList().add(table);
}
List<Map<String, String>> maps = (List<Map<String, String>>) hl7ui.gethl7Manager().getHl7Component().getElementParameter("SCHEMAS").getValue();
boolean found = false;
for (Map<String, String> map : maps) {
if (map.get("SCHEMA").equals(table.getTableName())) {
found = true;
}
}
if (!found) {
Map<String, String> hl7Schema = new HashMap<String, String>();
maps.add(hl7Schema);
hl7Schema.put("SCHEMA", table.getTableName());
}
}
} else if (label.length() == 3) {
child.setRow(label);
}
} else {
child.setRow(node.getRow());
}
node.addChild(child);
this.xmlViewer.refresh();
return true;
}
use of org.talend.designer.hl7.ui.data.Element in project tdi-studio-se by Talend.
the class ImportHL7StructureAction method initXmlTreeData.
private void initXmlTreeData(List<String> schemaList, List<HL7FileNode> root, List<HL7TreeNode> treeData) {
Map<String, HL7TreeNode> mapNodes = new HashMap<String, HL7TreeNode>();
List<? extends IConnection> incomingConnections = new ArrayList<IConnection>();
if (hl7ui != null) {
if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
((HL7OutputManager) hl7ui.gethl7Manager()).getContents().clear();
incomingConnections = NodeUtil.getIncomingConnections(hl7ui.gethl7Manager().getHl7Component(), IConnectionCategory.FLOW);
}
}
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
List<MetadataTable> iMetadataTables = new ArrayList<MetadataTable>();
HL7TreeNode rootNode = null;
Map<String, IMetadataTable> schemaNameToInputTable = new HashMap<String, IMetadataTable>();
Map<String, MetadataTable> schemaNameToOutputTable = new HashMap<String, MetadataTable>();
for (String schemaName : schemaList) {
IMetadataTable metadataTable = null;
for (IConnection connection : incomingConnections) {
if (connection.getUniqueName().equals(schemaName)) {
metadataTable = connection.getMetadataTable();
metadataTable.setLabel(connection.getUniqueName());
schemaNameToInputTable.put(schemaName, metadataTable);
break;
}
}
MetadataTable targetMetadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
targetMetadataTable.setId(factory.getNextId());
schemaNameToOutputTable.put(schemaName, targetMetadataTable);
targetMetadataTable.setLabel(schemaName);
iMetadataTables.add(targetMetadataTable);
}
HL7TreeNode current = null;
HL7TreeNode temp = null;
String currentPath = null;
String defaultValue = null;
int nodeOrder = 0;
boolean haveOrder = true;
// build root tree
for (int i = 0; i < root.size(); i++) {
HL7FileNode node = root.get(i);
String newPath = node.getFilePath();
defaultValue = node.getDefaultValue();
String columnName = node.getRelatedColumn();
// String type = node.getType();
String orderValue = String.valueOf(node.getOrder());
if (orderValue == null || "".equals(orderValue)) {
haveOrder = false;
}
if (haveOrder) {
nodeOrder = node.getOrder();
}
String rowName = columnName;
if (columnName != null && columnName.contains(":")) {
String[] names = columnName.split(":");
rowName = names[0];
columnName = names[1];
} else {
columnName = null;
}
temp = this.addElement(current, currentPath, newPath, defaultValue, mapNodes);
if (temp == null) {
// should not happen
continue;
}
// temp.setDataType(type);
if (rootNode == null) {
rootNode = temp;
}
if (node.getAttribute().equals("main")) {
temp.setMain(true);
}
current = temp;
currentPath = newPath;
if (haveOrder) {
temp.setOrder(nodeOrder);
}
if (rowName != null && rowName.length() > 0) {
temp.setRow(rowName);
}
if (columnName != null) {
IMetadataTable metadataTable = schemaNameToInputTable.get(rowName);
// group node can not get the metadata table
if (metadataTable == null) {
IMetadataTable metadataTableTemp = null;
for (IConnection connection : incomingConnections) {
metadataTableTemp = connection.getMetadataTable();
String connectionName = metadataTableTemp.getLabel();
if (connectionName == null) {
connectionName = connection.getUniqueName();
}
if (columnName.startsWith(connectionName)) {
break;
}
}
temp.setColumnName(columnName);
if (metadataTableTemp != null) {
temp.setColumn(metadataTableTemp.getColumn(columnName));
temp.setTable(metadataTableTemp);
}
} else {
temp.setColumnName(columnName);
temp.setColumn(metadataTable.getColumn(columnName));
temp.setTable(metadataTable);
}
//
if (!temp.isMain()) {
MetadataColumn newColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
newColumn.setLabel(columnName);
newColumn.setName(temp.getLabel());
newColumn.setLength(226);
newColumn.setTalendType("id_String");
schemaNameToOutputTable.get(rowName).getColumns().add(newColumn);
}
}
}
if (rootNode == null) {
rootNode = new Element("rootTag");
}
if (haveOrder) {
orderNode(rootNode);
}
if (rootNode != null) {
treeData.add(rootNode);
}
if (hl7ui != null) {
if (hl7ui.gethl7Manager() instanceof HL7OutputManager) {
((HL7OutputManager) hl7ui.gethl7Manager()).getContents().put(rootNode.getColumnLabel(), treeData);
}
} else if (form != null) {
for (HL7TreeNode hl7Node : treeData) {
form.getContents().put(rootNode.getColumnLabel(), hl7Node);
}
}
if (hl7ui != null) {
// execute the commands,initialize the propertiesView .
List<Command> commands = new ArrayList<Command>();
for (MetadataTable tableTemp : iMetadataTables) {
Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(hl7ui.gethl7Manager().getHl7Component(), IHL7Constant.TABLE_SCHEMAS, tableTemp.getLabel(), ConvertionHelper.convert(tableTemp));
commands.add(hl7Cmd);
}
for (Command command : commands) {
command.execute();
}
}
}
use of org.talend.designer.hl7.ui.data.Element in project tdi-studio-se by Talend.
the class HL7OutputManager method addElement.
protected HL7TreeNode addElement(HL7TreeNode current, String currentPath, String newPath, String defaultValue, Map<String, HL7TreeNode> mapNodes) {
HL7TreeNode temp = mapNodes.get(newPath);
if (temp == null) {
// if node is not existing, create it.
//$NON-NLS-1$
String name = newPath.substring(newPath.lastIndexOf("/") + 1);
temp = new Element(name, defaultValue);
if (current == null) {
// root node
mapNodes.put(newPath, temp);
return temp;
}
mapNodes.put(newPath, temp);
//$NON-NLS-1$
String parentPath = newPath.substring(0, newPath.lastIndexOf("/"));
HL7TreeNode parentNode = mapNodes.get(parentPath);
if (parentNode != null) {
parentNode.addChild(temp);
} else {
ExceptionHandler.log("Error when parsing the HL7 data, parent not existing for:" + parentPath);
}
}
return temp;
}
Aggregations