Search in sources :

Example 11 with Element

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

the class ImportHL7StructureAction method treeNodeAdapt.

private List treeNodeAdapt() {
    List<HL7TreeNode> treeData = new ArrayList<HL7TreeNode>();
    FileDialog f = null;
    if (hl7ui != null) {
        f = new FileDialog(hl7ui.getHl7UIParent().getShell());
    } else if (form != null) {
        f = new FileDialog(form.getShell());
    }
    String file = f.open();
    if (file == null) {
        return treeData;
    }
    HL7Parse hl7Parse = new HL7Parse();
    List<String> msgContentList = new ArrayList<String>();
    List<Message> messageList = hl7Parse.doParse(file, "'\\u000b'", "'\\u001c'");
    List<HL7TreeNode> nodeList = hl7Util.getHL7TreeNodes(messageList);
    if (!nodeList.isEmpty()) {
        HL7TreeNode hl7TreeNode = nodeList.get(0);
        List<HL7FileNode> table = new ArrayList<HL7FileNode>();
        if (hl7Connection != null) {
            EList root = hl7Connection.getRoot();
            root.clear();
            if (hl7TreeNode != null) {
                hl7Util.initNodeOrder(hl7TreeNode, orderMap);
                hl7Util.tableLoader((Element) hl7TreeNode, "", root, hl7TreeNode.getDefaultValue(), orderMap);
            }
            table.addAll(root);
        } else {
            if (hl7TreeNode != null) {
                hl7Util.initNodeOrder(hl7TreeNode, orderMap);
                hl7Util.tableLoader((Element) hl7TreeNode, "", table, hl7TreeNode.getDefaultValue(), orderMap);
            }
        }
        List<String> schemaList = new ArrayList<String>();
        for (HL7FileNode node : table) {
            String columnName = node.getRelatedColumn();
            if (columnName.contains(":")) {
                columnName = columnName.substring(0, columnName.indexOf(":"));
            }
            if (!schemaList.contains(columnName) && !"".equals(columnName)) {
                schemaList.add(columnName);
            }
        }
        initXmlTreeData(schemaList, table, treeData);
    }
    return treeData;
}
Also used : EList(org.eclipse.emf.common.util.EList) Message(ca.uhn.hl7v2.model.Message) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) ArrayList(java.util.ArrayList) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) FileDialog(org.eclipse.swt.widgets.FileDialog) HL7Parse(org.talend.designer.hl7.ui.header.HL7Parse)

Example 12 with Element

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

the class ImportHL7StructureAction 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;
}
Also used : Element(org.talend.designer.hl7.ui.data.Element) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode)

Example 13 with Element

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

the class DeleteHL7NodeAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    HL7TreeNode node = (HL7TreeNode) this.getStructuredSelection().getFirstElement();
    if (node == null) {
        return;
    }
    HL7TreeNode parent = node.getParent();
    if (parent == null) {
        return;
    }
    if (node instanceof Element) {
        disconnectSubTree(node);
    }
    parent.removeChild(node);
    xmlViewer.refresh(parent);
}
Also used : Element(org.talend.designer.hl7.ui.data.Element) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode)

Example 14 with Element

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

the class HL7PublicUtil method tableLoader.

public void tableLoader(Element element, String parentPath, List<HL7FileNode> table, String defaultValue, Map<String, Integer> orderMap) {
    HL7FileNode hl7FileNode = ConnectionFactory.eINSTANCE.createHL7FileNode();
    String currentPath = parentPath + "/" + element.getLabel();
    hl7FileNode.setFilePath(currentPath);
    hl7FileNode.setRelatedColumn(element.getColumnLabel());
    hl7FileNode.setAttribute(element.isMain() ? "main" : "branch");
    hl7FileNode.setDefaultValue(defaultValue);
    // xmlFileNode.setType(element.getDataType());
    hl7FileNode.setOrder(getNodeOrder(element, orderMap));
    hl7FileNode.setRepeatable(element.isRepetable());
    table.add(hl7FileNode);
    for (HL7TreeNode att : element.getAttributeChildren()) {
        hl7FileNode = ConnectionFactory.eINSTANCE.createHL7FileNode();
        hl7FileNode.setFilePath(att.getLabel());
        hl7FileNode.setRelatedColumn(att.getColumnLabel());
        hl7FileNode.setAttribute("attri");
        hl7FileNode.setDefaultValue(att.getDefaultValue());
        // xmlFileNode.setType(att.getDataType());
        hl7FileNode.setOrder(getNodeOrder(att, orderMap));
        hl7FileNode.setRepeatable(att.isRepetable());
        table.add(hl7FileNode);
    }
    for (HL7TreeNode att : element.getNameSpaceChildren()) {
        hl7FileNode = ConnectionFactory.eINSTANCE.createHL7FileNode();
        hl7FileNode.setFilePath(att.getLabel());
        hl7FileNode.setRelatedColumn(att.getColumnLabel());
        hl7FileNode.setAttribute("ns");
        hl7FileNode.setDefaultValue(att.getDefaultValue());
        // xmlFileNode.setType(att.getDataType());
        hl7FileNode.setOrder(getNodeOrder(att, orderMap));
        hl7FileNode.setRepeatable(att.isRepetable());
        table.add(hl7FileNode);
    }
    List<HL7TreeNode> children = element.getElementChildren();
    for (HL7TreeNode child : children) {
        // if (!child.isGroup() && !child.isLoop()) {
        tableLoader((Element) child, currentPath, table, child.getDefaultValue(), orderMap);
    // }
    }
}
Also used : HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode)

Example 15 with Element

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

the class HL7OutputUI method addXMLViewer.

/**
     * create xml viewer.
     *
     * @param mainComposite
     * @param form
     * @param width
     * @param height
     */
private void addXMLViewer(final Composite mainComposite, final int width, final int height) {
    // Group Schema Viewer
    Group group = Form.createGroup(mainComposite, 1, "Linker Target", height);
    // group.setBackgroundMode(SWT.INHERIT_FORCE);
    xmlViewer = new TreeViewer(group, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    xmlViewer.getControl().setLayoutData(gridData);
    xmlViewer.setUseHashlookup(true);
    Tree tree = xmlViewer.getTree();
    if (canModify || isRespo) {
        tree.setEnabled(false);
    }
    tree.setLinesVisible(true);
    tree.setBackground(tree.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("HL7 Structure");
    column1.setWidth(170);
    // Related Column
    TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
    column2.setText("Related Column");
    column2.setWidth(100);
    TreeColumn column3 = new TreeColumn(tree, SWT.CENTER);
    column3.setText("Node Status");
    column3.setWidth(90);
    TreeColumn column4 = new TreeColumn(tree, SWT.CENTER);
    column4.setText("Default Value");
    column4.setWidth(90);
    tree.setHeaderVisible(true);
    // tree.setBackgroundMode(SWT.INHERIT_NONE);
    HL7TargetTreeViewerProvider provider = new HL7TargetTreeViewerProvider();
    xmlViewer.setLabelProvider(provider);
    xmlViewer.setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(Object element, String property) {
            HL7TreeNode node = (HL7TreeNode) element;
            if (property.equals("C1")) {
                if (node.getLabel() != null && node.getLabel().length() > 0) {
                    return true;
                }
            }
            if (property.equals("C4")) {
                if (node.getDefaultValue() != null && node.getDefaultValue().length() > 0) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public Object getValue(Object element, String property) {
            HL7TreeNode node = (HL7TreeNode) element;
            if (property.equals("C1")) {
                return node.getLabel();
            }
            if (property.equals("C4")) {
                return node.getDefaultValue();
            }
            return null;
        }

        @Override
        public void modify(Object element, String property, Object value) {
            TreeItem treeItem = (TreeItem) element;
            HL7TreeNode node = (HL7TreeNode) treeItem.getData();
            if (property.equals("C1")) {
                if (value != null && value.toString().length() == 0) {
                    value = node.getLabel();
                }
                node.setLabel((String) value);
            }
            if (property.equals("C4")) {
                node.setDefaultValue((String) value);
            }
            xmlViewer.refresh(node);
        }
    });
    //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    xmlViewer.setColumnProperties(new String[] { "C1", "C2", "C3", "C4" });
    CellEditor editor = new TextCellEditor(xmlViewer.getTree());
    editor.addListener(new DialogErrorXMLLabelCellEditor(editor, "C1"));
    // add by wzhang for bug 8572. set Default value column to be edit.
    CellEditor editorDefault = new TextCellEditor(xmlViewer.getTree());
    editorDefault.addListener(new DialogErrorXMLLabelCellEditor(editorDefault, "C4"));
    xmlViewer.setCellEditors(new CellEditor[] { editor, null, null, editorDefault });
    xmlViewer.setContentProvider(provider);
    xmlViewer.setInput(this.hl7Manager.getTreeData());
    xmlViewer.expandAll();
    createAction();
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            HL7OutputUI.this.fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(xmlViewer.getControl());
    xmlViewer.getControl().setMenu(menu);
    xmlViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
        // TODO Auto-generated method stub
        }
    });
    refreshXMLViewer(null);
}
Also used : Group(org.eclipse.swt.widgets.Group) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) TreeColumn(org.eclipse.swt.widgets.TreeColumn) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Tree(org.eclipse.swt.widgets.Tree) HL7TargetTreeViewerProvider(org.talend.designer.hl7.ui.edit.HL7TargetTreeViewerProvider) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Aggregations

HL7TreeNode (org.talend.designer.hl7.ui.data.HL7TreeNode)20 Element (org.talend.designer.hl7.ui.data.Element)13 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 Map (java.util.Map)4 Group (ca.uhn.hl7v2.model.Group)3 List (java.util.List)3 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 HL7FileNode (org.talend.core.model.metadata.builder.connection.HL7FileNode)3 Message (ca.uhn.hl7v2.model.Message)2 GridData (org.eclipse.swt.layout.GridData)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)2 IConnection (org.talend.core.model.process.IConnection)2 HL7OutputManager (org.talend.designer.hl7.managers.HL7OutputManager)2 SegmentModel (org.talend.designer.hl7.model.SegmentModel)2 Structure (ca.uhn.hl7v2.model.Structure)1 Type (ca.uhn.hl7v2.model.Type)1 EList (org.eclipse.emf.common.util.EList)1 Command (org.eclipse.gef.commands.Command)1