Search in sources :

Example 1 with ComboxCellEditorImproved

use of org.talend.commons.ui.runtime.swt.celleditor.ComboxCellEditorImproved in project tdi-studio-se by Talend.

the class InputDataMapTableView method initColumnsOfTableColumns.

@Override
public void initColumnsOfTableColumns(final TableViewerCreator tableViewerCreatorForColumns) {
    TableViewerCreatorColumn column = null;
    //$NON-NLS-1$
    String useInJoinTitle = Messages.getString("InputDataMapTableView.columnTitle.ExplicitJoin");
    column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    column.setTitle(useInJoinTitle);
    column.setId(ID_EXPLICIT_JOIN);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, Boolean>() {

        public Boolean get(InputColumnTableEntry bean) {
            return bean.isJoin();
        }

        public void set(InputColumnTableEntry bean, Boolean value) {
            bean.setJoin(value);
            boolean enable = true;
            if (dropDownItem != null && !dropDownItem.isDisposed()) {
                enable = dropDownItem.isEnabled();
            }
            if (enable && value && mapperManager.getCurrentLanguage().unuseWithExplicitJoin().contains(getInputTable().getJoinType())) {
                if (menu != null) {
                    MenuItem[] menuItems = menu.getItems();
                    for (MenuItem mi : menuItems) {
                        if (mi.getImage() == null) {
                            continue;
                        }
                        if (mi.getText().equals(getInputTable().getJoinType().getLabel())) {
                            mi.setImage(null);
                        }
                    }
                    menuItems[1].setImage(ImageProviderMapper.getImage(ImageInfo.CHECKED_ICON));
                }
                getInputTable().setJoinType(JOIN.INNER_JOIN);
                refreshLabelForJoinDropDown();
                mapperManager.getUiManager().refreshSqlExpression();
            }
        }
    });
    column.setModifiable(true);
    // column.setWidth(12);
    column.setWidth(65);
    //$NON-NLS-1$
    column.setDisplayedValue("");
    // column.setResizable(false);
    CheckboxTableEditorContent checkboxTableEditorContent = new CheckboxTableEditorContent();
    checkboxTableEditorContent.setToolTipText(useInJoinTitle);
    column.setTableEditorContent(checkboxTableEditorContent);
    column.setToolTipHeader(useInJoinTitle);
    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);
    final TableViewerCreatorColumn columnOperator = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    //$NON-NLS-1$
    columnOperator.setTitle(Messages.getString("InputDataMapTableView.columnTitle.Operator"));
    columnOperator.setId(DataMapTableView.ID_OPERATOR);
    //$NON-NLS-1$
    columnOperator.setToolTipHeader(Messages.getString("InputDataMapTableView.Operator"));
    columnOperator.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {

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

        public void set(InputColumnTableEntry bean, String value) {
            bean.setOperator(value);
            mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
        }
    });
    columnOperator.setModifiable(true);
    columnOperator.setWidth(85);
    final IDbOperatorManager operatorsManager = mapperManager.getCurrentLanguage().getOperatorsManager();
    IDbOperator[] operators = operatorsManager.getOperators();
    String[] arrayOperators = new String[operators.length + 1];
    //$NON-NLS-1$
    arrayOperators[0] = "";
    for (int i = 0; i < operators.length; i++) {
        arrayOperators[i + 1] = operators[i].getOperator();
    }
    final ComboxCellEditorImproved typeComboEditor = new ComboxCellEditorImproved(tableViewerCreatorForColumns.getTable(), arrayOperators, SWT.NONE);
    typeComboEditor.addListener(new ICellEditorListener() {

        public void applyEditorValue() {
            ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
            InputColumnTableEntry currentInputEntry = (InputColumnTableEntry) modifiedObjectInfo.getCurrentModifiedBean();
            currentInputEntry.setOriginalExpression(null);
            Combo combo = (Combo) typeComboEditor.getControl();
            String selectedText = combo.getText();
            IDbOperator operatorFromValue = operatorsManager.getOperatorFromValue(selectedText);
            if (operatorFromValue != null && operatorFromValue.isMonoOperand()) {
                //$NON-NLS-1$
                currentInputEntry.setExpression("");
            }
        }

        public void cancelEditor() {
            ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
            InputColumnTableEntry currentInputEntry = (InputColumnTableEntry) modifiedObjectInfo.getCurrentModifiedBean();
        // currentInputEntry.setExpression(currentInputEntry.getOriginalExpression());
        }

        public void editorValueChanged(boolean oldValidState, boolean newValidState) {
            ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
            InputColumnTableEntry currentInputEntry = (InputColumnTableEntry) modifiedObjectInfo.getCurrentModifiedBean();
            if (modifiedObjectInfo.getCurrentModifiedColumn() == columnOperator) {
                if (currentInputEntry != modifiedObjectInfo.getPreviousModifiedBean()) {
                    currentInputEntry.setOriginalExpression(currentInputEntry.getExpression());
                }
                Combo combo = (Combo) typeComboEditor.getControl();
                String selectedText = combo.getText();
                if (//$NON-NLS-1$
                !selectedText.equals("") && (currentInputEntry.getExpression() == null || currentInputEntry.getExpression().trim().length() == 0)) {
                    IDbOperator operatorFromValue = operatorsManager.getOperatorFromValue(selectedText);
                    if (operatorFromValue.getAssociatedExpression() != null) {
                        currentInputEntry.setExpression(operatorFromValue.getAssociatedExpression());
                    }
                }
            }
        }
    });
    Combo typeCombo = (Combo) typeComboEditor.getControl();
    // typeCombo.setEditable(true);
    columnOperator.setCellEditor(typeComboEditor, CellEditorValueAdapterFactory.getComboAdapterForComboCellEditorImproved());
    columnOperator.setAlignment(ALIGNMENT.CENTER);
    final TableViewerCreatorColumn columnExpression = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    //$NON-NLS-1$
    columnExpression.setTitle(Messages.getString("InputDataMapTableView.columnTitle.Expr"));
    columnExpression.setId(DataMapTableView.ID_EXPRESSION_COLUMN);
    columnExpression.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {

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

        public void set(InputColumnTableEntry bean, String value) {
            bean.setExpression(value);
        // mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
        }
    });
    columnExpression.setModifiable(true);
    //$NON-NLS-1$
    columnExpression.setDefaultInternalValue("");
    createExpressionCellEditor(tableViewerCreatorForColumns, columnExpression, new Zone[] { Zone.INPUTS }, false);
    columnExpression.setWeight(COLUMN_EXPRESSION_SIZE_WEIGHT);
    columnExpression.setColorProvider(new IColumnColorProvider() {

        public Color getBackgroundColor(Object bean) {
            if (!cellModifier.canModify(bean, columnExpression.getId())) {
                return READONLY_CELL_BG_COLOR;
            }
            return null;
        }

        public Color getForegroundColor(Object bean) {
            return null;
        }
    });
    configureCellModifier(tableViewerCreatorForColumns);
}
Also used : Color(org.eclipse.swt.graphics.Color) MenuItem(org.eclipse.swt.widgets.MenuItem) Combo(org.eclipse.swt.widgets.Combo) Point(org.eclipse.swt.graphics.Point) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) CheckboxTableEditorContent(org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent) IDbOperator(org.talend.designer.dbmap.language.operator.IDbOperator) ModifiedObjectInfo(org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry) IColumnColorProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider) IDbOperatorManager(org.talend.designer.dbmap.language.operator.IDbOperatorManager) ComboxCellEditorImproved(org.talend.commons.ui.runtime.swt.celleditor.ComboxCellEditorImproved)

Aggregations

ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)1 Color (org.eclipse.swt.graphics.Color)1 Point (org.eclipse.swt.graphics.Point)1 Combo (org.eclipse.swt.widgets.Combo)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1 ComboxCellEditorImproved (org.talend.commons.ui.runtime.swt.celleditor.ComboxCellEditorImproved)1 IColumnColorProvider (org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider)1 ModifiedObjectInfo (org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo)1 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)1 CheckboxTableEditorContent (org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent)1 IDbOperator (org.talend.designer.dbmap.language.operator.IDbOperator)1 IDbOperatorManager (org.talend.designer.dbmap.language.operator.IDbOperatorManager)1 InputColumnTableEntry (org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry)1