Search in sources :

Example 1 with HL7OutputManager

use of org.talend.designer.hl7.managers.HL7OutputManager in project tdi-studio-se by Talend.

the class SchemaXMLLinker method createLinks.

/**
     * amaumont Comment method "createLinks".
     */
public void createLinks() {
    removeAllLinks();
    getBackgroundRefresher().refreshBackground();
    ProgressDialog progressDialog = new ProgressDialog(getSource().getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) {
            TreeItem root = xmlViewer.getTree().getItem(0);
            //
            List<HL7TreeNode> mappableNodes = new ArrayList<HL7TreeNode>();
            if (getManager().getHl7Component().isHL7Output()) {
                if (getManager() instanceof HL7OutputManager) {
                    //$NON-NLS-1$
                    mappableNodes = ((HL7OutputManager) getManager()).getTreeData("");
                    createLoopLinks(mappableNodes);
                    xmlViewer.refresh();
                    getBackgroundRefresher().refreshBackground();
                }
            } else {
                List<TreeItem> allItems = TreeUtils.collectAllItems(root);
                monitorWrap = new EventLoopProgressMonitor(monitor);
                //$NON-NLS-1$
                String taskName = Messages.getString("XmlToXPathLinker.Loop");
                int totalWork = allItems.size();
                monitorWrap.beginTask(taskName, totalWork);
                for (int i = 0; i < totalWork; i++) {
                    if (monitorWrap.isCanceled()) {
                        return;
                    }
                    TreeItem treeItem = allItems.get(i);
                    HL7TreeNode node = (HL7TreeNode) treeItem.getData();
                    if (node.getColumn() == null) {
                        continue;
                    }
                    // add now parameter for bug 9279
                    createLoopLinks(node.getColumn().getLabel(), treeItem, monitorWrap, i == totalWork - 1);
                    monitorWrap.worked(1);
                }
                monitorWrap.done();
            }
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        // Nothing to do
        ExceptionHandler.process(e);
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ArrayList(java.util.ArrayList) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) HL7OutputManager(org.talend.designer.hl7.managers.HL7OutputManager)

Example 2 with HL7OutputManager

use of org.talend.designer.hl7.managers.HL7OutputManager 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;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) HashMap(java.util.HashMap) Element(org.talend.designer.hl7.ui.data.Element) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) HL7OutputManager(org.talend.designer.hl7.managers.HL7OutputManager) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 3 with HL7OutputManager

use of org.talend.designer.hl7.managers.HL7OutputManager 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();
        }
    }
}
Also used : HashMap(java.util.HashMap) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) 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) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) Command(org.eclipse.gef.commands.Command) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) HL7OutputManager(org.talend.designer.hl7.managers.HL7OutputManager) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 4 with HL7OutputManager

use of org.talend.designer.hl7.managers.HL7OutputManager in project tdi-studio-se by Talend.

the class UIManager method autoMap.

/**
     * 
     * DOC xzhang Comment method "autoMap".
     */
public void autoMap(String currentSchema) {
    if (this.hl7Manager instanceof HL7OutputManager) {
        List<HL7TreeNode> roots = this.hl7Manager.getTreeData("");
        List<HL7TreeNode> mappableNodes = new ArrayList<HL7TreeNode>();
        for (HL7TreeNode root : roots) {
            getMappableNode((Element) root, mappableNodes);
        }
        List<IMetadataColumn> schemaData = this.hl7Manager.getSchemaData(currentSchema);
        for (HL7TreeNode node : mappableNodes) {
            for (IMetadataColumn column : schemaData) {
                if (node.getLabel().equals(column.getLabel())) {
                    node.setDefaultValue(null);
                    node.setColumn(column);
                    break;
                }
            // String[] splits = node.getColumnLabel().split(":");
            // for (String s : splits) {
            // if (s.equals(column.getLabel())) {
            // node.setDefaultValue(null);
            // node.setColumn(column);
            // break;
            // }
            // }
            }
        }
        // this.hl7UI.refreshXMLViewer(root);
        this.hl7UI.redrawLinkers();
        return;
    }
    this.hl7UI.autoMap();
}
Also used : ArrayList(java.util.ArrayList) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Aggregations

HL7TreeNode (org.talend.designer.hl7.ui.data.HL7TreeNode)4 ArrayList (java.util.ArrayList)3 HL7OutputManager (org.talend.designer.hl7.managers.HL7OutputManager)3 HashMap (java.util.HashMap)2 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)2 Element (org.talend.designer.hl7.ui.data.Element)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Map (java.util.Map)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Command (org.eclipse.gef.commands.Command)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 EventLoopProgressMonitor (org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor)1 ProgressDialog (org.talend.commons.ui.swt.dialogs.ProgressDialog)1 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 MetadataTable (org.talend.core.model.metadata.MetadataTable)1 HL7FileNode (org.talend.core.model.metadata.builder.connection.HL7FileNode)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1