Search in sources :

Example 26 with HL7TreeNode

use of org.talend.designer.hl7.ui.data.HL7TreeNode 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)

Example 27 with HL7TreeNode

use of org.talend.designer.hl7.ui.data.HL7TreeNode 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);
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 28 with HL7TreeNode

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

Example 29 with HL7TreeNode

use of org.talend.designer.hl7.ui.data.HL7TreeNode 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 30 with HL7TreeNode

use of org.talend.designer.hl7.ui.data.HL7TreeNode 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)

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