Search in sources :

Example 1 with XmlMapExpressionManager

use of org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager in project tdi-studio-se by Talend.

the class XmlMapUtilTest method testUpdateXPathAndExpression.

@Test
public void testUpdateXPathAndExpression() {
    XmlMapData data = XmlmapFactory.eINSTANCE.createXmlMapData();
    InputXmlTree inputTree = XmlmapFactory.eINSTANCE.createInputXmlTree();
    inputTree.setName("row1");
    OutputXmlTree outputTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
    outputTree.setName("out1");
    data.getInputTrees().add(inputTree);
    data.getOutputTrees().add(outputTree);
    TreeNode doc = XmlmapFactory.eINSTANCE.createTreeNode();
    initTreeNode(doc, "doc", "id_Document", NodeType.ELEMENT, "row1/doc", "");
    inputTree.getNodes().add(doc);
    TreeNode school = XmlmapFactory.eINSTANCE.createTreeNode();
    initTreeNode(school, "school", "id_String", NodeType.ELEMENT, "row1.doc:/school", "");
    doc.getChildren().add(school);
    TreeNode student = XmlmapFactory.eINSTANCE.createTreeNode();
    initTreeNode(student, "student", "id_String", NodeType.ELEMENT, "row1.doc:/school/student", "");
    school.getChildren().add(student);
    TreeNode name = XmlmapFactory.eINSTANCE.createTreeNode();
    initTreeNode(name, "name", "id_String", NodeType.ATTRIBUT, "row1.doc:/school/student/@name", "");
    student.getChildren().add(name);
    OutputTreeNode outColumn = XmlmapFactory.eINSTANCE.createOutputTreeNode();
    initTreeNode(outColumn, "outColumn", "id_String", NodeType.ELEMENT, "out1/outColumn", "[row1.doc:/school/student/@name]");
    outputTree.getNodes().add(outColumn);
    createConnection(data, name, outColumn);
    // rename schema column
    doc.setName("document");
    XmlMapUtil.updateXPathAndExpression(data, new XmlMapExpressionManager(), doc, "document", 2, true);
    assertTrue(doc.getXpath().equals("row1/document"));
    assertTrue(school.getXpath().equals("row1.document:/school"));
    assertTrue(student.getXpath().equals("row1.document:/school/student"));
    assertTrue(name.getXpath().equals("row1.document:/school/student/@name"));
    assertTrue(outColumn.getExpression().equals("[row1.document:/school/student/@name]"));
    // rename doc child
    school.setName("kindergarten");
    XmlMapUtil.updateXPathAndExpression(data, new XmlMapExpressionManager(), school, "kindergarten", 3, true);
    assertTrue(doc.getXpath().equals("row1/document"));
    assertTrue(school.getXpath().equals("row1.document:/kindergarten"));
    assertTrue(student.getXpath().equals("row1.document:/kindergarten/student"));
    assertTrue(name.getXpath().equals("row1.document:/kindergarten/student/@name"));
    assertTrue(outColumn.getExpression().equals("[row1.document:/kindergarten/student/@name]"));
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) XmlMapExpressionManager(org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData) Test(org.junit.Test)

Example 2 with XmlMapExpressionManager

use of org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager in project tdi-studio-se by Talend.

the class XmlTreeSchemaTableView method createColumns.

@Override
protected void createColumns(final TableViewerCreator<TreeNode> tableViewerCreator, Table table) {
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("XPath");
    column.setId(ID_COLUMN_XPATH);
    column.setWeight(20);
    column.setModifiable(true);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, Object>() {

        @Override
        public Object get(TreeNode bean) {
            return bean.getXpath();
        }

        @Override
        public void set(TreeNode bean, Object value) {
            if (isValidName) {
                bean.setName((String) value);
                // String xPath = bean.getXPath();
                // xPath = xPath.substring(0, xPath.lastIndexOf(XmlMapUtil.XPATH_SEPARATOR) + 1);
                // NodeType nodeType = bean.getTreeNode().getNodeType();
                // String typedValue = null;
                // if (NodeType.ATTRIBUT.equals(nodeType)) {
                // typedValue = xPath + XmlMapUtil.XPATH_ATTRIBUTE + bean.getName();
                // } else if (NodeType.NAME_SPACE.equals(nodeType)) {
                // typedValue = xPath + XmlMapUtil.XPATH_NAMESPACE + bean.getName();
                // } else {
                // typedValue = xPath + bean.getName();
                // }
                // bean.setXPath(typedValue);
                XmlMapData mapperData = XmlMapUtil.getXmlMapData(bean);
                XmlMapExpressionManager expressionManager = new XmlMapExpressionManager();
                XmlMapUtil.updateXPathAndExpression(mapperData, expressionManager, bean, bean.getName(), XmlMapUtil.getXPathLength(bean.getXpath()), true);
                if (!bean.getChildren().isEmpty()) {
                    refresh();
                }
            }
        }
    });
    final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreator.getTable());
    cellEditor.addListener(new DialogErrorForCellEditorListener(cellEditor, column) {

        @Override
        public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
        }

        @Override
        public String validateValue(String newValue, int beanPosition) {
            return validateXPath(newValue, beanPosition);
        }
    });
    column.setCellEditor(cellEditor);
    column.setColumnCellModifier(new ColumnCellModifier(column) {

        @Override
        public Object getValue(Object bean) {
            TreeNode entry = (TreeNode) bean;
            return entry.getName();
        }

        @Override
        public boolean modify(Object bean, Object value) {
            return false;
        }
    });
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Key");
    column.setToolTipHeader("Key");
    column.setId(ID_COLUMN_KEY);
    //$NON-NLS-1$
    column.setDisplayedValue("");
    column.setWeight(10);
    column.setModifiable(true);
    CheckboxTableEditorContent checkbox = new CheckboxTableEditorContent();
    column.setTableEditorContent(checkbox);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, Boolean>() {

        @Override
        public Boolean get(TreeNode bean) {
            return bean.isKey();
        }

        @Override
        public void set(TreeNode bean, Boolean value) {
            bean.setKey(value);
        }
    });
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Type");
    column.setToolTipHeader("Type");
    column.setId(ID_COLUMN_TYPE);
    column.setBeanPropertyAccessors(getTalendTypeAccessor());
    column.setModifiable(true);
    column.setWeight(20);
    TreeSchemaJavaTypeComboValueAdapter comboValueAdapter = new TreeSchemaJavaTypeComboValueAdapter<TreeNode>(JavaTypesManager.getDefaultJavaType(), getNullableAccessor());
    ComboBoxCellEditor typeComboEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), comboValueAdapter.getTalendTypesLabels(), SWT.READ_ONLY);
    CCombo typeCombo = (CCombo) typeComboEditor.getControl();
    typeCombo.setEditable(false);
    column.setCellEditor(typeComboEditor, comboValueAdapter);
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Nullable");
    column.setToolTipHeader("Nullable");
    column.setId(ID_COLUMN_NULLABLE);
    column.setBeanPropertyAccessors(getNullableAccessor());
    column.setWeight(20);
    //$NON-NLS-1$
    column.setDisplayedValue("");
    column.setModifiable(true);
    column.setTableColumnSelectionListener(new CheckColumnSelectionListener(column, tableViewerCreator));
    column.setImageHeader(ImageProvider.getImage(EImage.CHECKED_ICON));
    CheckboxTableEditorContent nullableCheckbox = new CheckboxTableEditorContent();
    column.setTableEditorContent(nullableCheckbox);
    column = new TableViewerCreatorColumn(tableViewerCreator);
    column.setTitle("Pattern");
    column.setId(ID_COLUMN_PATTERN);
    column.setWeight(20);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, String>() {

        @Override
        public String get(TreeNode bean) {
            return bean.getPattern();
        }

        @Override
        public void set(TreeNode bean, String value) {
            bean.setPattern(value);
        }
    });
    final ColumnCellModifier columnCellModifier = new ColumnCellModifier(column) {

        @Override
        public boolean canModify(Object bean) {
            boolean typeIsDate = currentBeanHasJavaDateType(bean) && !isReadOnly();
            return typeIsDate;
        }
    };
    column.setColorProvider(new IColumnColorProvider() {

        @Override
        public Color getBackgroundColor(Object bean) {
            if (!columnCellModifier.canModify(bean)) {
                return READONLY_CELL_BG_COLOR;
            }
            return null;
        }

        @Override
        public Color getForegroundColor(Object bean) {
            return null;
        }
    });
    column.setLabelProvider(new IColumnLabelProvider() {

        /*
             * (non-Javadoc)
             * 
             * @see org.talend.commons.ui.swt.tableviewer.behavior.IColumnLabelProvider#getLabel(java.lang.Object)
             */
        @Override
        public String getLabel(Object bean) {
            if (!currentBeanHasJavaDateType(bean)) {
                //$NON-NLS-1$
                return "";
            }
            return null;
        }
    });
    column.setColumnCellModifier(columnCellModifier);
    JavaSimpleDateFormatProposalProvider proposalProvider = new JavaSimpleDateFormatProposalProvider();
    TextCellEditorWithProposal patternCellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), column);
    ContentProposalAdapterExtended contentProposalAdapter = patternCellEditor.getContentProposalAdapter();
    contentProposalAdapter.setFilterStyle(ContentProposalAdapterExtended.FILTER_NONE);
    contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapterExtended.PROPOSAL_INSERT);
    patternCellEditor.setContentProposalProvider(proposalProvider);
    column.setCellEditor(patternCellEditor, CellEditorValueAdapterFactory.getNullToEmptyStringTextAdapater());
    tableViewerCreator.setCellModifier(new XmlCellModifier(tableViewerCreator));
}
Also used : DialogErrorForCellEditorListener(org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener) CheckColumnSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CheckColumnSelectionListener) JavaSimpleDateFormatProposalProvider(org.talend.core.ui.proposal.JavaSimpleDateFormatProposalProvider) ColumnCellModifier(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ColumnCellModifier) ContentProposalAdapterExtended(org.talend.commons.ui.swt.proposal.ContentProposalAdapterExtended) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) XmlMapExpressionManager(org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager) IColumnColorProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData) IColumnLabelProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnLabelProvider) CELL_EDITOR_STATE(org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE) TextCellEditorWithProposal(org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal) Color(org.eclipse.swt.graphics.Color) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) CCombo(org.eclipse.swt.custom.CCombo) CheckboxTableEditorContent(org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

Example 3 with XmlMapExpressionManager

use of org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager in project tdi-studio-se by Talend.

the class XmlMapConnectionBuilder method rebuildLink.

private void rebuildLink(int inputTreeIndex, List<TreeNode> children, XmlMapData mapData) {
    for (TreeNode treeNode : children) {
        if (XmlMapUtil.isDragable(treeNode)) {
            String expression = XmlMapUtil.convertToExpression(treeNode.getXpath());
            XmlMapExpressionManager expressionManager = new XmlMapExpressionManager();
            TableEntryLocation sourceLocation = expressionManager.parseTableEntryLocation(expression).get(0);
            // LOOKUP ,FILTER
            for (int i = inputTreeIndex; i < mapData.getInputTrees().size(); i++) {
                InputXmlTree treeTarget = mapData.getInputTrees().get(i);
                if (hasMaptchedLocation(expressionManager, sourceLocation, treeTarget, ExpressionType.EXPRESSION_FILTER)) {
                    createFilterConnection(treeNode, treeTarget, mapData);
                }
                checkTargetChildren(expressionManager, treeTarget.getNodes(), treeNode, sourceLocation, mapData);
            }
            // VAR
            for (VarNode varNode : mapData.getVarTables().get(0).getNodes()) {
                if (hasMaptchedLocation(expressionManager, sourceLocation, varNode, ExpressionType.EXPRESSION)) {
                    createConnection(treeNode, varNode, mapData);
                }
            }
            // OUTPUT,FILTER
            for (int i = 0; i < mapData.getOutputTrees().size(); i++) {
                OutputXmlTree outputTree = mapData.getOutputTrees().get(i);
                if (hasMaptchedLocation(expressionManager, sourceLocation, outputTree, ExpressionType.EXPRESSION_FILTER)) {
                    createFilterConnection(treeNode, outputTree, mapData);
                }
                checkTargetChildren(expressionManager, outputTree.getNodes(), treeNode, sourceLocation, mapData);
            }
        }
        if (!treeNode.getChildren().isEmpty()) {
            rebuildLink(inputTreeIndex, treeNode.getChildren(), mapData);
        }
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) XmlMapExpressionManager(org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager) TableEntryLocation(org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 4 with XmlMapExpressionManager

use of org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager in project tdi-studio-se by Talend.

the class XmlMapService method checkExpression.

private boolean checkExpression(String oriExpression, String testExpression, Map<String, String> inputConnNameMap) {
    if (oriExpression == null && testExpression == null) {
        return false;
    }
    if (oriExpression == null || testExpression == null) {
        return true;
    }
    if (oriExpression.equals(testExpression)) {
        return false;
    }
    XmlMapExpressionManager expressionManager = new XmlMapExpressionManager();
    List<TableEntryLocation> oriMatchedLocations = expressionManager.parseTableEntryLocation(oriExpression);
    List<TableEntryLocation> testMatchedLocations = expressionManager.parseTableEntryLocation(testExpression);
    if (oriMatchedLocations.size() != testMatchedLocations.size()) {
        return true;
    }
    for (int i = 0; i < oriMatchedLocations.size(); i++) {
        TableEntryLocation currentLocation = oriMatchedLocations.get(i);
        TableEntryLocation testLocation = testMatchedLocations.get(i);
        if (!currentLocation.getColumnValue().equals(testLocation.getColumnValue())) {
            return true;
        } else if (inputConnNameMap.get(currentLocation.getTableName()) == null) {
            return true;
        } else if (!inputConnNameMap.get(currentLocation.getTableName()).equals(testLocation.getTableName())) {
            return true;
        }
    }
    if (oriMatchedLocations.isEmpty() && testMatchedLocations.isEmpty()) {
        if (!oriExpression.equals(testExpression)) {
            return true;
        }
    }
    return false;
}
Also used : XmlMapExpressionManager(org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager) TableEntryLocation(org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation)

Aggregations

XmlMapExpressionManager (org.talend.designer.xmlmap.ui.expressionutil.XmlMapExpressionManager)4 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)3 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)2 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)2 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)2 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)2 TableEntryLocation (org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation)2 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 CCombo (org.eclipse.swt.custom.CCombo)1 Color (org.eclipse.swt.graphics.Color)1 Test (org.junit.Test)1 CheckColumnSelectionListener (org.talend.commons.ui.runtime.swt.tableviewer.behavior.CheckColumnSelectionListener)1 ColumnCellModifier (org.talend.commons.ui.runtime.swt.tableviewer.behavior.ColumnCellModifier)1 IColumnColorProvider (org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider)1 IColumnLabelProvider (org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnLabelProvider)1 ContentProposalAdapterExtended (org.talend.commons.ui.swt.proposal.ContentProposalAdapterExtended)1 TextCellEditorWithProposal (org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal)1 CELL_EDITOR_STATE (org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE)1 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)1