Search in sources :

Example 11 with HL7TreeNode

use of org.talend.designer.hl7.ui.data.HL7TreeNode in project tdi-studio-se by Talend.

the class HL7OutputManager method sortOrder.

public void sortOrder(HL7TreeNode treeNode, HL7TreeNode node) {
    if (node != null) {
        List<HL7TreeNode> children = node.getChildren();
        if (treeNode != null) {
            int tmpOrder = 0;
            int attrNsCount = 0;
            for (HL7TreeNode child : children) {
                if (child.getOrder() < treeNode.getOrder()) {
                    tmpOrder++;
                }
                if (child.isAttribute() || child.isNameSpace()) {
                    attrNsCount++;
                }
            }
            if (tmpOrder > -1) {
                int oldOrder = children.indexOf(treeNode);
                if (oldOrder != -1 && oldOrder != tmpOrder) {
                    node.removeChild(treeNode);
                    if (children.size() > tmpOrder) {
                        node.addChild(tmpOrder - attrNsCount, treeNode);
                    } else {
                        node.addChild(treeNode);
                    }
                }
            }
        }
    }
}
Also used : HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode)

Example 12 with HL7TreeNode

use of org.talend.designer.hl7.ui.data.HL7TreeNode in project tdi-studio-se by Talend.

the class HL7OutputManager method tableLoader.

// public void initNodeOrder(HL7TreeNode node) {
// if (node == null) {
// return;
// }
// HL7TreeNode parent = node.getParent();
// if (parent == null) {
// node.setOrder(1);
// String path = TreeUtil.getPath(node);
// orderMap.put(path, order);
// order++;
// }
// List<HL7TreeNode> childNode = node.getChildren();
// for (HL7TreeNode child : childNode) {
// child.setOrder(order);
// String path = TreeUtil.getPath(child);
// orderMap.put(path, order);
// order++;
// if (child.getChildren().size() > 0) {
// initNodeOrder(child);
// }
// }
//
// }
protected void tableLoader(Element element, String parentPath, List<Map<String, String>> table, String defaultValue) {
    Map<String, String> newMap = new HashMap<String, String>();
    //$NON-NLS-1$
    String currentPath = parentPath + "/" + element.getLabel();
    newMap.put(HL7InputComponent.PATH, currentPath);
    newMap.put(HL7InputComponent.COLUMN, element.getColumnLabel());
    newMap.put(HL7InputComponent.ATTRIBUTE, element.isMain() ? "main" : "branch");
    newMap.put(HL7InputComponent.VALUE, defaultValue);
    newMap.put(HL7InputComponent.ORDER, String.valueOf(getNodeOrder(element)));
    newMap.put("REPEATABLE", String.valueOf(element.isRepetable()));
    table.add(newMap);
    for (HL7TreeNode att : element.getAttributeChildren()) {
        newMap = new HashMap<String, String>();
        newMap.put(HL7InputComponent.PATH, att.getLabel());
        newMap.put(HL7InputComponent.COLUMN, att.getColumnLabel());
        //$NON-NLS-1$
        newMap.put(HL7InputComponent.ATTRIBUTE, "attri");
        newMap.put(HL7InputComponent.VALUE, att.getDefaultValue());
        newMap.put(HL7InputComponent.ORDER, String.valueOf(getNodeOrder(att)));
        newMap.put("REPEATABLE", String.valueOf(att.isRepetable()));
        table.add(newMap);
    }
    for (HL7TreeNode att : element.getNameSpaceChildren()) {
        newMap = new HashMap<String, String>();
        newMap.put(HL7InputComponent.PATH, att.getLabel());
        newMap.put(HL7InputComponent.COLUMN, att.getColumnLabel());
        //$NON-NLS-1$
        newMap.put(HL7InputComponent.ATTRIBUTE, "ns");
        newMap.put(HL7InputComponent.VALUE, att.getDefaultValue());
        newMap.put("REPEATABLE", String.valueOf(att.isRepetable()));
        newMap.put(HL7InputComponent.ORDER, String.valueOf(getNodeOrder(att)));
        table.add(newMap);
    }
    List<HL7TreeNode> children = element.getElementChildren();
    for (HL7TreeNode child : children) {
        // if (!child.isGroup() && !child.isRepetable()) {// && !child.isRepetable()
        tableLoader((Element) child, currentPath, table, child.getDefaultValue());
    // }
    }
}
Also used : HashMap(java.util.HashMap) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode)

Example 13 with HL7TreeNode

use of org.talend.designer.hl7.ui.data.HL7TreeNode in project tdi-studio-se by Talend.

the class HL7OutputManager method initModel.

public void initModel() {
    List<? extends IConnection> incomingConnections = NodeUtil.getIncomingConnections(hl7Component, IConnectionCategory.FLOW);
    // HL7Root root = new HL7Root("root");
    List<Map<String, String>> maps = (List<Map<String, String>>) ElementParameterParser.getObjectValue(hl7Component, //$NON-NLS-1$
    "__SCHEMAS__");
    List<String> schemaList = new ArrayList<String>();
    for (IMetadataTable table : hl7Component.getMetadataList()) {
        if (table.getLabel() != null) {
            schemaList.add(table.getLabel());
        }
    }
    List<Map<String, String>> rootTable = hl7Component.getTableList(HL7InputComponent.ROOT);
    Map<String, IMetadataTable> schemaNameToInputTable = new HashMap<String, IMetadataTable>();
    if (!maps.isEmpty()) {
        for (Map<String, String> map : maps) {
            String schemaName = map.get("SCHEMA");
            int first = schemaName.indexOf("_");
            int second = schemaName.lastIndexOf("_");
            if (first > 0 && first < second) {
                schemaName = schemaName.substring(first + 1, second);
            }
            IMetadataTable metadataTable = null;
            for (IConnection connection : incomingConnections) {
                if (connection.getUniqueName().equals(map.get("PARENT_ROW"))) {
                    metadataTable = connection.getMetadataTable();
                    metadataTable.setLabel(connection.getUniqueName());
                    schemaNameToInputTable.put(schemaName, metadataTable);
                    break;
                }
            }
        }
    } else {
        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);
                }
            }
        }
    }
    Map<String, HL7TreeNode> mapNodes = new HashMap<String, HL7TreeNode>();
    treeData = new ArrayList<HL7TreeNode>();
    HL7TreeNode rootNode = null;
    HL7TreeNode current = null;
    HL7TreeNode temp = null;
    String currentPath = null;
    String defaultValue = null;
    int nodeOrder = 0;
    boolean haveOrder = true;
    // build root tree
    for (Map<String, String> rootMap : rootTable) {
        String newPath = rootMap.get(HL7InputComponent.PATH);
        String columnName = rootMap.get(HL7InputComponent.COLUMN);
        defaultValue = rootMap.get(HL7InputComponent.VALUE);
        String orderValue = rootMap.get(HL7InputComponent.ORDER);
        boolean repeatable = Boolean.valueOf(rootMap.get("REPEATABLE"));
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        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;
        }
        if (rootNode == null) {
            rootNode = temp;
        }
        if (rootMap.get(HL7InputComponent.ATTRIBUTE).equals("main")) {
            //$NON-NLS-1$
            temp.setMain(true);
        }
        current = temp;
        currentPath = newPath;
        temp.setRepetable(repeatable);
        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 (rootNode == null) {
        rootNode = new Element("rootTag");
    }
    if (haveOrder) {
        orderNode(rootNode);
    }
    // the root node should not set the ColumnLabel
    if (rootNode.getRow() != null) {
        rootNode.setRow(null);
    }
    treeData.add(rootNode);
    contents.put(rootNode.getColumnLabel(), treeData);
    initCurrentSchema();
}
Also used : HashMap(java.util.HashMap) Element(org.talend.designer.hl7.ui.data.Element) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with HL7TreeNode

use of org.talend.designer.hl7.ui.data.HL7TreeNode in project tdi-studio-se by Talend.

the class HL7OutputManager method getPath.

public String getPath(HL7TreeNode treeNode) {
    StringBuffer path = new StringBuffer();
    HL7TreeNode tmp = treeNode;
    while (tmp != null) {
        //$NON-NLS-1$
        path.insert(0, "/" + tmp.getLabel());
        tmp = tmp.getParent();
    }
    return path.toString();
}
Also used : HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode)

Example 15 with HL7TreeNode

use of org.talend.designer.hl7.ui.data.HL7TreeNode in project tdi-studio-se by Talend.

the class SetRepetableAction method upsetMainNode.

public void upsetMainNode(HL7TreeNode node) {
    if (node instanceof Element) {
        HL7TreeNode parent = node;
        while (parent != null) {
            parent.setMain(true);
            parent = parent.getParent();
        }
    }
}
Also used : Element(org.talend.designer.hl7.ui.data.Element) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode)

Aggregations

HL7TreeNode (org.talend.designer.hl7.ui.data.HL7TreeNode)41 Element (org.talend.designer.hl7.ui.data.Element)13 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)6 List (java.util.List)4 Map (java.util.Map)4 TreeItem (org.eclipse.swt.widgets.TreeItem)4 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 HL7FileNode (org.talend.core.model.metadata.builder.connection.HL7FileNode)3 HL7OutputManager (org.talend.designer.hl7.managers.HL7OutputManager)3 Group (ca.uhn.hl7v2.model.Group)2 Message (ca.uhn.hl7v2.model.Message)2 TableItem (org.eclipse.swt.widgets.TableItem)2 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)2 IConnection (org.talend.core.model.process.IConnection)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 EList (org.eclipse.emf.common.util.EList)1 Command (org.eclipse.gef.commands.Command)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1