Search in sources :

Example 1 with IUIMatchingMode

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

the class InputDataMapTableView method initColumnsOfTableColumns.

@Override
public void initColumnsOfTableColumns(final TableViewerCreator tableViewerCreatorForColumns) {
    boolean isMainConnection = ((InputTable) getDataMapTable()).isMainConnection();
    TableViewerCreatorColumn column = null;
    if (!isMainConnection) {
        column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
        //$NON-NLS-1$
        column.setTitle(Messages.getString("InputDataMapTableView.columnTitle.Expr"));
        column.setId(DataMapTableView.ID_EXPRESSION_COLUMN);
        expressionCellEditor = createExpressionCellEditor(tableViewerCreatorForColumns, column, new Zone[] { Zone.INPUTS }, false);
        column.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {

            public String get(InputColumnTableEntry bean) {
                return bean.getExpression();
            }

            public void set(InputColumnTableEntry bean, String value) {
                // System.out.println("value='" + value + "'");
                bean.setExpression(value);
                InputTable inputTable = getInputTable();
                boolean tableHasAtLeastOneHashKey = mapperManager.isTableHasAtLeastOneHashKey(inputTable);
                if (!tableHasAtLeastOneHashKey) {
                    IUIMatchingMode matchingMode = inputTable.getMatchingMode();
                    if (matchingMode != TMAP_MATCHING_MODE.ALL_ROWS) {
                        inputTable.setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS);
                        refreshCondensedImage(inputTable, MATCH_MODEL_SETTING);
                    }
                } else {
                    IUIMatchingMode matchingMode = inputTable.getMatchingMode();
                    if (matchingMode == TMAP_MATCHING_MODE.ALL_ROWS) {
                        IUIMatchingMode newMatchModel = previousMatchingModeSelected == null || previousMatchingModeSelected == TMAP_MATCHING_MODE.ALL_ROWS ? TMAP_MATCHING_MODE.UNIQUE_MATCH : previousMatchingModeSelected;
                        inputTable.setMatchingMode(newMatchModel);
                        refreshCondensedImage(inputTable, MATCH_MODEL_SETTING);
                    }
                    mapperManager.getUiManager().setStatusBarValues(STATUS.EMPTY, null);
                }
                mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true, true);
                if (!mapperManager.isCheckSyntaxEnabled()) {
                    mapperManager.getUiManager().applyActivatedCellEditors(tableViewerCreatorForColumns);
                    Display.getDefault().asyncExec(new Runnable() {

                        public void run() {
                            mapperManager.getProblemsManager().checkLookupExpressionProblem();
                        }
                    });
                }
            }
        });
        column.setModifiable(!mapperManager.componentIsReadOnly());
        //$NON-NLS-1$
        column.setDefaultInternalValue("");
        column.setWeight(COLUMN_EXPRESSION_SIZE_WEIGHT);
        column.setImageProvider(new IColumnImageProvider<InputColumnTableEntry>() {

            public Image getImage(InputColumnTableEntry bean) {
                if (bean.getExpression() != null && !bean.getExpression().trim().equals("")) {
                    //$NON-NLS-1$
                    if (mapperManager.isAdvancedMap()) {
                        return ImageProviderMapper.getImage(ImageInfo.LOOKUP_KEY_ICON);
                    } else {
                        return null;
                    }
                } else {
                    return null;
                }
            }
        });
    }
    column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    column.setTitle(DataMapTableView.COLUMN_NAME);
    column.setId(DataMapTableView.ID_NAME_COLUMN);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {

        public String get(InputColumnTableEntry bean) {
            return bean.getMetadataColumn().getLabel();
        }

        public void set(InputColumnTableEntry bean, String value) {
            bean.getMetadataColumn().setLabel(value);
        }
    });
    column.setWeight(COLUMN_NAME_SIZE_WEIGHT);
    if (isMainConnection && PluginChecker.isTraceDebugPluginLoaded() && mapperManager.isTracesActive()) {
        column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
        column.setTitle("Preview");
        column.setId(DataMapTableView.PREVIEW_COLUMN);
        column.setWeight(COLUMN_NAME_SIZE_WEIGHT);
        column.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {

            public String get(InputColumnTableEntry bean) {
                IMetadataColumn metadataColumn = bean.getMetadataColumn();
                if (metadataColumn != null) {
                    String label = metadataColumn.getLabel();
                    TraceData preview = bean.getPreviewValue();
                    if (preview != null && preview.getData() != null) {
                        return preview.getData().get(label);
                    }
                }
                return "";
            }

            public void set(InputColumnTableEntry bean, String value) {
            // do nothing
            }
        });
    }
}
Also used : Zone(org.talend.designer.mapper.ui.visualmap.zone.Zone) IUIMatchingMode(org.talend.designer.mapper.model.table.IUIMatchingMode) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Image(org.eclipse.swt.graphics.Image) EImage(org.talend.commons.ui.runtime.image.EImage) InputTable(org.talend.designer.mapper.model.table.InputTable) TraceData(org.talend.core.model.process.TraceData) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)

Example 2 with IUIMatchingMode

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

the class InputDataMapTableView method getMatchModel.

private IUIMatchingMode[] getMatchModel() {
    IUIMatchingMode[] allMatchingModel = TMAP_MATCHING_MODE.values();
    List<IUIMatchingMode> avilable = new ArrayList<IUIMatchingMode>();
    for (IUIMatchingMode matchingMode : allMatchingModel) {
        final String text = matchingMode.getLabel();
        if (matchingMode == TMAP_MATCHING_MODE.LAST_MATCH) {
            continue;
        }
        if (getMapperManager().isBigDataProcess() && matchingMode == TMAP_MATCHING_MODE.FIRST_MATCH) {
            continue;
        }
        if (text.length() != 0) {
            if (getMapperManager().isMRProcess() && matchingMode == TMAP_MATCHING_MODE.ALL_MATCHES) {
                // set ALL_MATCHES as default value for m/r process
                avilable.add(0, matchingMode);
            } else {
                avilable.add(matchingMode);
            }
        }
    }
    return avilable.toArray(new IUIMatchingMode[avilable.size()]);
}
Also used : ArrayList(java.util.ArrayList) IUIMatchingMode(org.talend.designer.mapper.model.table.IUIMatchingMode)

Example 3 with IUIMatchingMode

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

the class InputDataMapTableView method openCustomCellDialog.

@Override
protected Object openCustomCellDialog(Shell shell, CellValueType type) {
    if (type == CellValueType.LOOKUP_MODEL) {
        IUILookupMode[] availableJoins = { TMAP_LOOKUP_MODE.LOAD_ONCE, TMAP_LOOKUP_MODE.RELOAD, TMAP_LOOKUP_MODE.CACHE_OR_RELOAD };
        List<String> names = new ArrayList<String>();
        for (IUILookupMode availableJoin : availableJoins) {
            names.add(availableJoin.getLabel());
        }
        ListStringValueDialog<String> dialog = new ListStringValueDialog<String>(shell, names);
        if (dialog.open() == IDialogConstants.OK_ID) {
            return dialog.getSelectStr();
        }
    } else if (type == CellValueType.MATCH_MODEL) {
        IUIMatchingMode[] matchModel = getMatchModel();
        List<String> names = new ArrayList<String>();
        for (IUIMatchingMode element : matchModel) {
            names.add(element.getLabel());
        }
        ListStringValueDialog<String> dialog = new ListStringValueDialog<String>(shell, names);
        if (dialog.open() == IDialogConstants.OK_ID) {
            return dialog.getSelectStr();
        }
    } else if (type == CellValueType.JOIN_MODEL) {
        String[] items = new String[] { INNER_JOIN, LEFT_OUTER_JOIN };
        ListStringValueDialog<String> dialog = new ListStringValueDialog<String>(shell, items);
        if (dialog.open() == IDialogConstants.OK_ID) {
            return dialog.getSelectStr();
        }
    }
    return null;
}
Also used : IUILookupMode(org.talend.designer.mapper.model.table.IUILookupMode) ArrayList(java.util.ArrayList) IUIMatchingMode(org.talend.designer.mapper.model.table.IUIMatchingMode) List(java.util.List) ArrayList(java.util.ArrayList) ListStringValueDialog(org.talend.designer.mapper.ui.dialog.ListStringValueDialog)

Example 4 with IUIMatchingMode

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

the class InputDataMapTableView method checkChangementsAfterEntryModifiedOrAdded.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.dbmap.ui.visualmap.table.DataMapTableView#checkChangementsAfterNewExpressionApplied()
     */
@Override
public void checkChangementsAfterEntryModifiedOrAdded(boolean forceEvaluation) {
    super.checkChangementsAfterEntryModifiedOrAdded(forceEvaluation);
    if (!getInputTable().isMainConnection() && mapperManager.isAdvancedMap()) {
        boolean stateAtLeastOneHashKey = mapperManager.isTableHasAtLeastOneHashKey(getInputTable());
        if (forceEvaluation || previousStateAtLeastOneHashKey != stateAtLeastOneHashKey) {
            if (stateAtLeastOneHashKey) {
                IUIMatchingMode matchingMode = getInputTable().getMatchingMode();
                if (matchingMode == TMAP_MATCHING_MODE.ALL_ROWS) {
                    IUIMatchingMode newMatchModel = previousMatchingModeSelected == null || previousMatchingModeSelected == TMAP_MATCHING_MODE.ALL_ROWS ? TMAP_MATCHING_MODE.UNIQUE_MATCH : previousMatchingModeSelected;
                    getInputTable().setMatchingMode(newMatchModel);
                    refreshCondensedImage(getInputTable(), MATCH_MODEL_SETTING);
                }
            } else {
                if (getInputTable().getLookupMode() == TMAP_LOOKUP_MODE.CACHE_OR_RELOAD) {
                    String errorMessage = Messages.getString("InputDataMapTableView.invalidConfiguration", //$NON-NLS-1$
                    getInputTable().getName());
                    mapperManager.getUiManager().setStatusBarValues(STATUS.ERROR, errorMessage);
                } else {
                    mapperManager.getUiManager().setStatusBarValues(STATUS.EMPTY, null);
                // selectMatchingModeMenuItem(matchingMode);
                }
                IUIMatchingMode matchingMode = getInputTable().getMatchingMode();
                if (matchingMode != TMAP_MATCHING_MODE.ALL_ROWS) {
                    getInputTable().setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS);
                    refreshCondensedImage(getInputTable(), MATCH_MODEL_SETTING);
                }
                innerJoinCheckItemEditable = false;
            }
            previousStateAtLeastOneHashKey = stateAtLeastOneHashKey;
        }
        checkLookupTableProblems(stateAtLeastOneHashKey);
        mapSettingViewerCreator.refresh();
    }
}
Also used : IUIMatchingMode(org.talend.designer.mapper.model.table.IUIMatchingMode)

Example 5 with IUIMatchingMode

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

the class InputDataMapTableView method getMapSettingValueAccess.

@Override
protected IBeanPropertyAccessors<GlobalMapEntry, Object> getMapSettingValueAccess(final CellEditor cellEditor) {
    return new IBeanPropertyAccessors<GlobalMapEntry, Object>() {

        public Object get(GlobalMapEntry bean) {
            IDataMapTable parent = bean.getParent();
            InputTable inputTable = (InputTable) parent;
            if (cellEditor instanceof ComboBoxCellEditor) {
                ComboBoxCellEditor functComboBox = (ComboBoxCellEditor) cellEditor;
                if (LOOKUP_MODEL_SETTING.equals(bean.getName())) {
                    IUILookupMode[] availableJoins = { TMAP_LOOKUP_MODE.LOAD_ONCE, TMAP_LOOKUP_MODE.RELOAD, TMAP_LOOKUP_MODE.CACHE_OR_RELOAD };
                    List<String> names = new ArrayList<String>();
                    for (IUILookupMode availableJoin : availableJoins) {
                        names.add(availableJoin.getLabel());
                    }
                    functComboBox.setItems(names.toArray(new String[names.size()]));
                    final IUILookupMode lookupMode = ((InputTable) parent).getLookupMode();
                    if (lookupMode != null) {
                        return lookupMode.getLabel();
                    }
                } else if (MATCH_MODEL_SETTING.equals(bean.getName())) {
                    IUIMatchingMode[] matchModel = getMatchModel();
                    List<String> names = new ArrayList<String>();
                    for (IUIMatchingMode element : matchModel) {
                        names.add(element.getLabel());
                    }
                    functComboBox.setItems(names.toArray(new String[names.size()]));
                    IUIMatchingMode matchingMode = ((InputTable) parent).getMatchingMode();
                    if (names.contains(matchingMode.getLabel())) {
                        return matchingMode.getLabel();
                    }
                } else if (JOIN_MODEL_SETTING.equals(bean.getName())) {
                    String[] items = new String[] { INNER_JOIN, LEFT_OUTER_JOIN };
                    functComboBox.setItems(items);
                    boolean innerJoin = ((InputTable) parent).isInnerJoin();
                    if (innerJoin) {
                        return items[0];
                    }
                    return items[1];
                } else if (PERSISTENCE_MODEL_SETTING.equals(bean.getName())) {
                    functComboBox.setItems(new String[] { "true", "false" });
                    boolean persistent = ((InputTable) parent).isPersistent();
                    return String.valueOf(persistent);
                }
            } else if (cellEditor instanceof CustomDialogCellEditor) {
                CustomDialogCellEditor customDialogCellEditor = (CustomDialogCellEditor) cellEditor;
                if (LOOKUP_MODEL_SETTING.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.LOOKUP_MODEL);
                    final IUILookupMode lookupMode = inputTable.getLookupMode();
                    if (lookupMode != null) {
                        return lookupMode.getLabel();
                    }
                } else if (MATCH_MODEL_SETTING.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.MATCH_MODEL);
                    IUIMatchingMode matchingMode = inputTable.getMatchingMode();
                    if (matchingMode != null) {
                        return matchingMode.getLabel();
                    }
                } else if (JOIN_MODEL_SETTING.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.JOIN_MODEL);
                    boolean innerJoin = inputTable.isInnerJoin();
                    return innerJoin ? INNER_JOIN : LEFT_OUTER_JOIN;
                } else if (PERSISTENCE_MODEL_SETTING.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.BOOL);
                    boolean persistent = inputTable.isPersistent();
                    return String.valueOf(persistent);
                } else if (SCHEMA_TYPE.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.SCHEMA_TYPE);
                    enableDiaplayViewer(inputTable.isRepository());
                    return inputTable.isRepository() ? REPOSITORY : BUILT_IN;
                } else if (SCHEMA_ID.equals(bean.getName())) {
                    customDialogCellEditor.setType(CellValueType.SCHEMA_ID);
                    return getSchemaDisplayName(inputTable.getId());
                }
            }
            return "";
        }

        public void set(GlobalMapEntry bean, Object value) {
            IDataMapTable parent = bean.getParent();
            InputTable inputTable = (InputTable) parent;
            if (LOOKUP_MODEL_SETTING.equals(bean.getName())) {
                IUILookupMode[] availableJoins = { TMAP_LOOKUP_MODE.LOAD_ONCE, TMAP_LOOKUP_MODE.RELOAD, TMAP_LOOKUP_MODE.CACHE_OR_RELOAD };
                for (final IUILookupMode lookupMode : availableJoins) {
                    if (value != null && value.equals(lookupMode.getLabel())) {
                        inputTable.setLookupMode(lookupMode);
                        if (TMAP_LOOKUP_MODE.CACHE_OR_RELOAD == lookupMode) {
                            persistentCheckEditable = false;
                        } else {
                            persistentCheckEditable = true;
                        }
                        if (lookupMode == TMAP_LOOKUP_MODE.RELOAD || lookupMode == TMAP_LOOKUP_MODE.CACHE_OR_RELOAD) {
                            showTableGlobalMap(true);
                        } else {
                            showTableGlobalMap(false);
                        }
                        enableDisablePersistentMode((TMAP_LOOKUP_MODE) lookupMode);
                        mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
                        checkChangementsAfterEntryModifiedOrAdded(true);
                    }
                }
            } else if (MATCH_MODEL_SETTING.equals(bean.getName())) {
                for (IUIMatchingMode model : TMAP_MATCHING_MODE.values()) {
                    if (value != null && value.equals(model.getLabel())) {
                        inputTable.setMatchingMode(model);
                        previousMatchingModeSelected = model;
                    }
                }
            } else if (JOIN_MODEL_SETTING.equals(bean.getName())) {
                if (LEFT_OUTER_JOIN.equals(value)) {
                    ((InputTable) parent).setInnerJoin(false);
                    previousInnerJoinSelection = false;
                } else {
                    ((InputTable) parent).setInnerJoin(true);
                    previousInnerJoinSelection = true;
                }
            } else if (PERSISTENCE_MODEL_SETTING.equals(bean.getName())) {
                if ("true".equals(value) || "false".equals(value)) {
                    ((InputTable) parent).setPersistent(Boolean.valueOf(value.toString()));
                    previousValidPersistentMode = Boolean.valueOf(value.toString());
                }
            } else if (SCHEMA_TYPE.equals(bean.getName())) {
                inputTable.setRepository(REPOSITORY.equals(value));
                showSchemaIDSetting(REPOSITORY.equals(value));
                enableDiaplayViewer(REPOSITORY.equals(value));
            } else if (SCHEMA_ID.equals(bean.getName())) {
                inputTable.setId(String.valueOf(value));
            }
            refreshCondensedImage((InputTable) bean.getParent(), bean.getName());
        }
    };
}
Also used : IUILookupMode(org.talend.designer.mapper.model.table.IUILookupMode) ArrayList(java.util.ArrayList) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) IUIMatchingMode(org.talend.designer.mapper.model.table.IUIMatchingMode) InputTable(org.talend.designer.mapper.model.table.InputTable) IBeanPropertyAccessors(org.talend.commons.utils.data.bean.IBeanPropertyAccessors) List(java.util.List) ArrayList(java.util.ArrayList) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry)

Aggregations

IUIMatchingMode (org.talend.designer.mapper.model.table.IUIMatchingMode)5 ArrayList (java.util.ArrayList)3 List (java.util.List)2 IUILookupMode (org.talend.designer.mapper.model.table.IUILookupMode)2 InputTable (org.talend.designer.mapper.model.table.InputTable)2 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)1 Image (org.eclipse.swt.graphics.Image)1 EImage (org.talend.commons.ui.runtime.image.EImage)1 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)1 IBeanPropertyAccessors (org.talend.commons.utils.data.bean.IBeanPropertyAccessors)1 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)1 TraceData (org.talend.core.model.process.TraceData)1 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)1 GlobalMapEntry (org.talend.designer.mapper.model.tableentry.GlobalMapEntry)1 InputColumnTableEntry (org.talend.designer.mapper.model.tableentry.InputColumnTableEntry)1 ListStringValueDialog (org.talend.designer.mapper.ui.dialog.ListStringValueDialog)1 Zone (org.talend.designer.mapper.ui.visualmap.zone.Zone)1