Search in sources :

Example 1 with ExpressionFilterEntry

use of org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry in project tdi-studio-se by Talend.

the class MapperManager method replaceLocation.

/**
     * 
     * DOC amaumont Comment method "replaceLocation".
     * 
     * @param previousLocation
     * @param newLocation
     * @param dataMapExpressionParser
     * @param table
     * @param entry
     * @return true if expression of entry has changed
     */
private boolean replaceLocation(final TableEntryLocation previousLocation, final TableEntryLocation newLocation, DataMapExpressionParser dataMapExpressionParser, IDataMapTable table, ITableEntry entry) {
    if (entry.getExpression() == null || entry.getExpression().trim().length() == 0) {
        return false;
    }
    boolean expressionHasChanged = false;
    String currentExpression = entry.getExpression();
    TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(currentExpression);
    // loop on all locations of current expression
    for (TableEntryLocation currentLocation : tableEntryLocations) {
        if (currentLocation.equals(previousLocation)) {
            currentExpression = dataMapExpressionParser.replaceLocation(currentExpression, previousLocation, newLocation);
            expressionHasChanged = true;
        }
    }
    if (expressionHasChanged) {
        entry.setExpression(currentExpression);
        DataMapTableView dataMapTableView = retrieveAbstractDataMapTableView(table);
        TableViewerCreator tableViewerCreator = null;
        if (entry instanceof IColumnEntry || entry instanceof FilterTableEntry) {
            if (entry instanceof IColumnEntry) {
                tableViewerCreator = dataMapTableView.getTableViewerCreatorForColumns();
            } else if (entry instanceof FilterTableEntry) {
                tableViewerCreator = dataMapTableView.getTableViewerCreatorForFilters();
            }
            tableViewerCreator.getTableViewer().refresh(entry);
        } else if (entry instanceof ExpressionFilterEntry) {
            dataMapTableView.getExpressionFilterText().setText(currentExpression);
        }
        uiManager.parseExpression(currentExpression, entry, false, true, false);
        return true;
    }
    return false;
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) FilterTableEntry(org.talend.designer.mapper.model.tableentry.FilterTableEntry) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry)

Example 2 with ExpressionFilterEntry

use of org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry in project tdi-studio-se by Talend.

the class LinkManager method registerLevelForNewLink.

/**
     * DOC amaumont Comment method "registerLevelForNewLink".
     * 
     * @param link
     * @param graphicalLinksFromTarget
     */
public void registerLevelForNewLink(IMapperLink link, Set<IMapperLink> graphicalLinksFromTarget) {
    boolean hasAlreadyInputTarget = false;
    boolean hasAlreadyVarTarget = false;
    ITableEntry sourceEntry = link.getPointLinkDescriptor1().getTableEntry();
    ITableEntry targetEntry = link.getPointLinkDescriptor2().getTableEntry();
    boolean hasSameZone = sourceEntry.getParent().getClass() == targetEntry.getParent().getClass();
    if (hasSameZone) {
        boolean isInputTarget = targetEntry instanceof InputColumnTableEntry || targetEntry instanceof ExpressionFilterEntry || targetEntry instanceof GlobalMapEntry && targetEntry.getParent() instanceof InputTable;
        boolean isVarTarget = targetEntry instanceof VarTableEntry;
        List<List<IMapperLink>> leveledLinks = null;
        if (isInputTarget) {
            leveledLinks = getInputLinksForLevels();
        }
        if (isVarTarget) {
            leveledLinks = getVarLinksForLevels();
        }
        int lstSize = leveledLinks.size();
        for (int indexOfLeveledLink = 0; indexOfLeveledLink < lstSize; indexOfLeveledLink++) {
            List<IMapperLink> linksFromLevelsList = leveledLinks.get(indexOfLeveledLink);
            if (linksFromLevelsList != null && linksFromLevelsList.size() > 0) {
                IMapperLink linkFromLevelsList = linksFromLevelsList.get(0);
                ITableEntry sourceTableEntry = linkFromLevelsList.getPointLinkDescriptor1().getTableEntry();
                ITableEntry targetTableEntry = linkFromLevelsList.getPointLinkDescriptor2().getTableEntry();
                if (targetEntry == targetTableEntry) {
                    if (sourceTableEntry instanceof InputColumnTableEntry && (targetTableEntry instanceof InputColumnTableEntry || targetEntry instanceof ExpressionFilterEntry && targetEntry.getParent() instanceof InputTable)) {
                        hasAlreadyInputTarget = true;
                    }
                    if (sourceTableEntry instanceof VarTableEntry && targetTableEntry instanceof VarTableEntry) {
                        hasAlreadyVarTarget = true;
                    }
                    if (hasAlreadyInputTarget || hasAlreadyVarTarget) {
                        linksFromLevelsList.add(link);
                        link.setLevel(indexOfLeveledLink + 1);
                        break;
                    }
                }
            }
        }
        if (isInputTarget && !hasAlreadyInputTarget || isVarTarget && !hasAlreadyVarTarget) {
            ArrayList<IMapperLink> list = new ArrayList<IMapperLink>();
            int firstEmptyIndex = searchFirstEmptyIndexLeveledList(leveledLinks);
            link.setLevel(firstEmptyIndex + 1);
            list.add(link);
            if (firstEmptyIndex < leveledLinks.size()) {
                leveledLinks.set(firstEmptyIndex, list);
            } else {
                leveledLinks.add(list);
            }
        }
    }
}
Also used : ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ArrayList(java.util.ArrayList) VarTableEntry(org.talend.designer.mapper.model.tableentry.VarTableEntry) InputTable(org.talend.designer.mapper.model.table.InputTable) IMapperLink(org.talend.designer.abstractmap.ui.visualmap.link.IMapperLink) List(java.util.List) ArrayList(java.util.ArrayList) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry)

Example 3 with ExpressionFilterEntry

use of org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry in project tdi-studio-se by Talend.

the class UIManager method getTableEntryPosition.

/**
     * DOC amaumont Comment method "getTableEntryPosition".
     * 
     * @param manager TODO
     * @param tableEntry
     * @param forceRecalculate TODO
     * @return
     */
public Point getTableEntryPosition(ITableEntry tableEntry, boolean forceRecalculate) {
    DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(tableEntry);
    int entriesSize = 0;
    int minHeight = dataMapTableView.getTableViewerCreatorForColumns().getTable().getHeaderHeight() + dataMapTableView.getTableViewerCreatorForColumns().getTable().getItemHeight();
    TableItem[] tableItems = new TableItem[0];
    if (tableEntry instanceof InputColumnTableEntry || tableEntry instanceof OutputColumnTableEntry) {
        tableItems = dataMapTableView.getTableViewerCreatorForColumns().getTable().getItems();
        AbstractInOutTable abstractInOutTable = (AbstractInOutTable) dataMapTableView.getDataMapTable();
        if (dataMapTableView.getZone() == Zone.OUTPUTS) {
            OutputTable outputTable = (OutputTable) abstractInOutTable;
            List<IColumnEntry> oldOuputEntries = outputTable.getDataMapTableEntries();
            entriesSize = oldOuputEntries.size();
        }
        if (dataMapTableView.getZone() == Zone.INPUTS) {
            InputTable inputTable = (InputTable) abstractInOutTable;
            List<IColumnEntry> oldOuputEntries = inputTable.getDataMapTableEntries();
            entriesSize = oldOuputEntries.size();
        }
    }
    Rectangle tableViewBounds = dataMapTableView.getBounds();
    Point pointFromTableViewOrigin = null;
    Display display = dataMapTableView.getDisplay();
    Point returnedPoint = new Point(0, 0);
    TableEntryProperties tableEntryProperties = null;
    int itemIndex = 0;
    if (tableEntry instanceof IColumnEntry || tableEntry instanceof FilterTableEntry || tableEntry instanceof GlobalMapEntry) {
        tableEntryProperties = mapperManager.getTableEntryProperties(tableEntry);
        returnedPoint = tableEntryProperties.position;
        if (forceRecalculate || returnedPoint == null) {
            int y;
            TableItem tableItem = mapperManager.retrieveTableItem(tableEntry);
            boolean isOutputEntry = tableEntry instanceof OutputColumnTableEntry;
            boolean isIntputEntry = tableEntry instanceof InputColumnTableEntry;
            boolean checked = false;
            for (int i = 0; i < tableItems.length; i++) {
                if (tableItems[i].getData() == tableEntry) {
                    itemIndex = i;
                    break;
                }
            }
            boolean allIsNull = false;
            if (tableItem == null && (isIntputEntry || isOutputEntry)) {
                if (tableItems.length > 0) {
                    tableItem = tableItems[0];
                    checked = true;
                } else {
                    allIsNull = true;
                }
            }
            if (!allIsNull) {
                Table table = tableItem.getParent();
                // FIX for issue 1225 ("1" parameter added)
                Rectangle boundsTableItem = tableItem.getBounds(1);
                y = boundsTableItem.y + table.getItemHeight() / 2 + dataMapTableView.getBorderWidth();
                if (isOutputEntry || isIntputEntry) {
                    if (entriesSize != tableItems.length) {
                        y = boundsTableItem.y + table.getItemHeight() / 2 + dataMapTableView.getBorderWidth();
                    }
                }
                if (checked) {
                    y = boundsTableItem.y + dataMapTableView.getBorderWidth();
                    checked = false;
                }
                int x = 0;
                if (y < 0) {
                    y = 0;
                }
                Point point = new Point(x, y);
                pointFromTableViewOrigin = display.map(tableItem.getParent(), dataMapTableView, point);
            } else {
                Text columnFilterText = dataMapTableView.getColumnNameFilterText();
                Point point = new Point(-dataMapTableView.getBorderWidth() - 19, minHeight);
                pointFromTableViewOrigin = display.map(columnFilterText, dataMapTableView, point);
            }
        }
    } else if (tableEntry instanceof ExpressionFilterEntry) {
        StyledText expressionFilterText = dataMapTableView.getExpressionFilterText();
        //            dataMapTableView.getex
        Point point = new Point(-dataMapTableView.getBorderWidth() - 19, 16);
        pointFromTableViewOrigin = display.map(expressionFilterText, dataMapTableView, point);
    } else {
        //$NON-NLS-1$
        throw new IllegalStateException("Case not found");
    }
    if (pointFromTableViewOrigin.y > tableViewBounds.height - TableEntriesManager.HEIGHT_REACTION) {
        pointFromTableViewOrigin.y = tableViewBounds.height - TableEntriesManager.HEIGHT_REACTION;
    }
    returnedPoint = convertPointToReferenceOrigin(getReferenceComposite(), pointFromTableViewOrigin, dataMapTableView);
    if (tableEntryProperties != null) {
        tableEntryProperties.position = returnedPoint;
    }
    return returnedPoint;
}
Also used : IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) InputTable(org.talend.designer.mapper.model.table.InputTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) OutputTable(org.talend.designer.mapper.model.table.OutputTable) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) Table(org.eclipse.swt.widgets.Table) AbstractDataMapTable(org.talend.designer.mapper.model.table.AbstractDataMapTable) StyledText(org.eclipse.swt.custom.StyledText) TableItem(org.eclipse.swt.widgets.TableItem) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) Rectangle(org.eclipse.swt.graphics.Rectangle) FilterTableEntry(org.talend.designer.mapper.model.tableentry.FilterTableEntry) InputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) OutputColumnTableEntry(org.talend.designer.mapper.model.tableentry.OutputColumnTableEntry) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) TableEntryProperties(org.talend.designer.mapper.ui.visualmap.TableEntryProperties) Point(org.eclipse.swt.graphics.Point) OutputTable(org.talend.designer.mapper.model.table.OutputTable) InputTable(org.talend.designer.mapper.model.table.InputTable) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry) Display(org.eclipse.swt.widgets.Display)

Example 4 with ExpressionFilterEntry

use of org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry in project tdi-studio-se by Talend.

the class TableEntriesManager method remove.

public void remove(ITableEntry dataMapTableEntry) {
    if (dataMapTableEntry != null) {
        mapperManager.removeLinksOf(dataMapTableEntry);
        tableEntries.remove(TableEntriesManager.buildLocation(dataMapTableEntry));
        dataMapTableEntryToProperties.remove(dataMapTableEntry);
        IDataMapTable dataMapTable = dataMapTableEntry.getParent();
        if (dataMapTableEntry instanceof IColumnEntry) {
            dataMapTableEntry.getParent().removeColumnEntry((IColumnEntry) dataMapTableEntry);
        } else if (dataMapTableEntry instanceof GlobalMapEntry) {
            if (dataMapTable instanceof OutputTable) {
                ((InputTable) dataMapTable).removeGlobalMapEntry((GlobalMapEntry) dataMapTableEntry);
            }
        } else if (dataMapTableEntry instanceof FilterTableEntry) {
            if (dataMapTable instanceof OutputTable) {
                ((OutputTable) dataMapTable).removeFilterEntry((FilterTableEntry) dataMapTableEntry);
            }
        } else if (dataMapTableEntry instanceof ExpressionFilterEntry) {
        // nothing
        } else {
            String exceptionMessage = //$NON-NLS-1$
            Messages.getString(//$NON-NLS-1$
            "TableEntriesManager.exceptionMessage.typeIsNotValid", dataMapTableEntry.getClass().toString());
            throw new IllegalArgumentException(exceptionMessage);
        }
    }
}
Also used : FilterTableEntry(org.talend.designer.mapper.model.tableentry.FilterTableEntry) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry) OutputTable(org.talend.designer.mapper.model.table.OutputTable)

Example 5 with ExpressionFilterEntry

use of org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry in project tdi-studio-se by Talend.

the class UIManager method parseAllExpressions.

/**
     * DOC amaumont Comment method "processAllExpressions".
     * 
     * @param newLinksMustHaveSelectedState TODO
     */
@SuppressWarnings("unchecked")
public void parseAllExpressions(DataMapTableView dataMapTableView, boolean newLinksMustHaveSelectedState) {
    List<IColumnEntry> columnsEntriesList = dataMapTableView.getDataMapTable().getColumnEntries();
    parseAllExpressions(columnsEntriesList, newLinksMustHaveSelectedState);
    if (mapperManager.isAdvancedMap() && (dataMapTableView.getZone() == Zone.INPUTS || dataMapTableView.getZone() == Zone.OUTPUTS)) {
        AbstractInOutTable table = (AbstractInOutTable) dataMapTableView.getDataMapTable();
        if (dataMapTableView.getZone() == Zone.INPUTS) {
            InputTable inputTable = (InputTable) table;
            List<GlobalMapEntry> globalMapEntries = inputTable.getGlobalMapEntries();
            if (globalMapEntries != null && !inputTable.isMainConnection()) {
                parseAllExpressions(globalMapEntries, newLinksMustHaveSelectedState);
            }
        }
        if (table.isActivateExpressionFilter()) {
            ExpressionFilterEntry expressionFilter = table.getExpressionFilter();
            parseExpression(expressionFilter.getExpression(), expressionFilter, newLinksMustHaveSelectedState, false, false);
        }
    } else if (dataMapTableView.getZone() == Zone.OUTPUTS) {
        List<ITableEntry> constraintEntriesList = dataMapTableView.getTableViewerCreatorForFilters().getInputList();
        parseAllExpressions(constraintEntriesList, newLinksMustHaveSelectedState);
    }
}
Also used : InputTable(org.talend.designer.mapper.model.table.InputTable) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) ArrayList(java.util.ArrayList) List(java.util.List) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry)

Aggregations

ExpressionFilterEntry (org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry)12 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)8 FilterTableEntry (org.talend.designer.mapper.model.tableentry.FilterTableEntry)7 GlobalMapEntry (org.talend.designer.mapper.model.tableentry.GlobalMapEntry)7 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)6 InputTable (org.talend.designer.mapper.model.table.InputTable)4 ArrayList (java.util.ArrayList)3 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)3 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)3 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)3 AbstractInOutTable (org.talend.designer.mapper.model.table.AbstractInOutTable)3 OutputTable (org.talend.designer.mapper.model.table.OutputTable)3 HashMap (java.util.HashMap)2 List (java.util.List)2 TableItem (org.eclipse.swt.widgets.TableItem)2 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)2 InputColumnTableEntry (org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)2 TableEntryLocation (org.talend.designer.mapper.model.tableentry.TableEntryLocation)2 InputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView)2 OutputDataMapTableView (org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView)2