Search in sources :

Example 1 with IListenableListListener

use of org.talend.commons.utils.data.list.IListenableListListener in project tdi-studio-se by Talend.

the class DataMapTableView method createTableForColumns.

/**
     * DOC amaumont Comment method "createTableForColumns".
     * 
     * @param parent
     */
private void createTableForColumns(Composite parent) {
    this.extendedTableViewerForColumns = new AbstractExtendedTableViewer<IColumnEntry>(abstractDataMapTable.getTableColumnsEntriesModel(), parent) {

        @Override
        protected void createColumns(TableViewerCreator<IColumnEntry> tableViewerCreator, Table table) {
            initColumnsOfTableColumns(tableViewerCreator);
        }

        /*
             * (non-Javadoc)
             * 
             * @see org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer#initTableListeners()
             */
        @Override
        protected void initTableListeners() {
            super.initTableListeners();
            getTableViewerCreator().addCellValueModifiedListener(new ITableCellValueModifiedListener() {

                @Override
                public void cellValueModified(TableCellValueModifiedEvent e) {
                    // System.out.println();
                    // System.out.println(getTable().hashCode());
                    // System.out.println(e.tableItem.getParent().hashCode());
                    // if (e.tableItem.getParent().isFocusControl()) {
                    // only if table of item is actually the focus control
                    getTableViewerCreator().getSelectionHelper().deselectAll();
                    getTable().forceFocus();
                // }
                }
            });
        }

        /*
             * (non-Javadoc)
             * 
             * @see
             * org.talend.commons.ui.swt.extended.macrotable.AbstractExtendedTableViewer#setTableViewerCreatorOptions
             * (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)
             */
        @Override
        protected void setTableViewerCreatorOptions(final TableViewerCreator<IColumnEntry> newTableViewerCreator) {
            super.setTableViewerCreatorOptions(newTableViewerCreator);
            newTableViewerCreator.setColumnsResizableByDefault(true);
            newTableViewerCreator.setBorderVisible(false);
            newTableViewerCreator.setLayoutMode(LAYOUT_MODE.FILL_HORIZONTAL);
            newTableViewerCreator.setKeyboardManagementForCellEdition(false);
            // tableViewerCreatorForColumns.setUseCustomItemColoring(this.getDataMapTable() instanceof
            // AbstractInOutTable);
            newTableViewerCreator.setFirstColumnMasked(true);
            if (getDataMapTable() instanceof AbstractInOutTable) {
                if (imageKey == null) {
                    imageKey = org.talend.commons.ui.runtime.image.ImageProvider.getImage(EImage.KEY_ICON);
                }
                if (imageEmpty == null) {
                    imageEmpty = org.talend.commons.ui.runtime.image.ImageProvider.getImage(EImage.EMPTY);
                }
            }
            newTableViewerCreator.setLabelProvider(new DefaultTableLabelProvider(newTableViewerCreator) {

                @Override
                public Color getBackground(Object element, int columnIndex) {
                    Color backgroundCellColor = getBackgroundCellColor(newTableViewerCreator, element, columnIndex);
                    if (backgroundCellColor != null) {
                        return backgroundCellColor;
                    }
                    return super.getBackground(element, columnIndex);
                }

                @Override
                public Color getForeground(Object element, int columnIndex) {
                    Color foregroundCellColor = getForegroundCellColor(newTableViewerCreator, element, columnIndex);
                    if (foregroundCellColor != null) {
                        return foregroundCellColor;
                    }
                    return getForegroundCellColor(newTableViewerCreator, element, columnIndex);
                }

                @Override
                public Image getColumnImage(Object element, int columnIndex) {
                    return getColumnImageExecute(element, columnIndex);
                }

                /**
                     * DOC amaumont Comment method "getColumnImageExecute".
                     * 
                     * @param element
                     * @param columnIndex
                     * @return
                     */
                private Image getColumnImageExecute(Object element, int columnIndex) {
                    if (getDataMapTable() instanceof AbstractInOutTable) {
                        AbstractInOutTableEntry entry = (AbstractInOutTableEntry) element;
                        TableViewerCreatorColumnNotModifiable column = newTableViewerCreator.getColumns().get(columnIndex);
                        if (column.getId().equals(ID_NAME_COLUMN)) {
                            if (entry.getMetadataColumn().isKey()) {
                                return imageKey;
                            } else {
                                return imageEmpty;
                            }
                        }
                    }
                    return null;
                }
            });
        }

        /*
             * (non-Javadoc)
             * 
             * @see org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer#initModelListeners()
             */
        @Override
        protected void initModelListeners() {
            super.initModelListeners();
            getExtendedTableModel().addAfterOperationListListener(100, new IListenableListListener<IColumnEntry>() {

                @Override
                public void handleEvent(ListenableListEvent<IColumnEntry> event) {
                    if (tableViewerCreator.getTable() != null && !tableViewerCreator.getTable().isDisposed()) {
                        if (event.type == TYPE.ADDED) {
                            Collection<IColumnEntry> addedObjects = event.addedObjects;
                            for (IColumnEntry tableEntry : addedObjects) {
                                mapperManager.getProblemsManager().checkProblemsForTableEntry(tableEntry, false);
                            }
                        }
                    }
                }
            });
        }
    };
    tableViewerCreatorForColumns = this.extendedTableViewerForColumns.getTableViewerCreator();
    this.extendedTableViewerForColumns.setCommandStack(mapperManager.getCommandStack());
    tableForEntries = tableViewerCreatorForColumns.getTable();
    GridData tableEntriesGridData = new GridData(GridData.FILL_BOTH);
    tableEntriesGridData.grabExcessVerticalSpace = true;
    tableEntriesGridData.minimumHeight = tableForEntries.getHeaderHeight() + tableForEntries.getItemHeight();
    // tableEntriesGridData.heightHint = 50;
    // tableEntriesGridData.grabExcessVerticalSpace = false;
    tableForEntries.setLayoutData(tableEntriesGridData);
    addTablesListeners();
}
Also used : ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) AbstractInOutTable(org.talend.designer.dbmap.model.table.AbstractInOutTable) OutputTable(org.talend.designer.dbmap.model.table.OutputTable) Table(org.eclipse.swt.widgets.Table) Color(org.eclipse.swt.graphics.Color) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) AbstractInOutTable(org.talend.designer.dbmap.model.table.AbstractInOutTable) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) DefaultTableLabelProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.DefaultTableLabelProvider) GridData(org.eclipse.swt.layout.GridData) AbstractInOutTableEntry(org.talend.designer.dbmap.model.tableentry.AbstractInOutTableEntry)

Example 2 with IListenableListListener

use of org.talend.commons.utils.data.list.IListenableListListener in project tdi-studio-se by Talend.

the class DataMapTableView method addTablesListeners.

/**
     * DOC amaumont Comment method "addTableForColumnsListeners".
     */
private void addTablesListeners() {
    tableViewerCreatorForColumns.addCellValueModifiedListener(new ITableCellValueModifiedListener() {

        @Override
        public void cellValueModified(TableCellValueModifiedEvent e) {
            unselectAllEntriesIfErrorDetected(e);
        }
    });
    abstractDataMapTable.getTableColumnsEntriesModel().addAfterOperationListListener(new IListenableListListener<FilterTableEntry>() {

        @Override
        public void handleEvent(ListenableListEvent<FilterTableEntry> event) {
            mapperManager.getUiManager().refreshSqlExpression();
        }
    });
    final TableViewer tableViewerForEntries = tableViewerCreatorForColumns.getTableViewer();
    tableViewerForEntries.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int[] selectionIndices = tableViewerForEntries.getTable().getSelectionIndices();
            if (selectionIndices.length > 0) {
                selectThisDataMapTableView();
                onSelectedEntries(event.getSelection(), selectionIndices);
                // bug 18414
                MetadataTableEditorView metadataTableEditorView = null;
                if (getZone() == Zone.INPUTS) {
                    metadataTableEditorView = mapperManager.getUiManager().getInputMetaEditorView();
                } else if (getZone() == Zone.OUTPUTS) {
                    metadataTableEditorView = mapperManager.getUiManager().getOutputMetaEditorView();
                }
                if (metadataTableEditorView != null) {
                    metadataTableEditorView.getTableViewerCreator().refresh();
                }
            }
        }
    });
    tableForEntries.addListener(SWT.DragDetect, new Listener() {

        @Override
        public void handleEvent(Event event) {
            onSelectedEntries(tableViewerForEntries.getSelection(), tableViewerForEntries.getTable().getSelectionIndices());
        }
    });
    tableViewerCreatorForColumns.getSelectionHelper().addAfterSelectionListener(new ILineSelectionListener() {

        @Override
        public void handle(LineSelectionEvent e) {
            if (forceExecuteSelectionEvent) {
                forceExecuteSelectionEvent = false;
                onSelectedEntries(tableViewerForEntries.getSelection(), tableViewerForEntries.getTable().getSelectionIndices());
            }
        }
    });
    tableForEntries.addListener(SWT.KeyDown, new Listener() {

        @Override
        public void handleEvent(Event event) {
            processEnterKeyDown(tableViewerCreatorForColumns, event);
        }
    });
    abstractDataMapTable.getTableColumnsEntriesModel().addModifiedBeanListener(new IModifiedBeanListener<IColumnEntry>() {

        @Override
        public void handleEvent(ModifiedBeanEvent<IColumnEntry> event) {
            TableViewerCreator tableViewerCreator = tableViewerCreatorForColumns;
            ITableEntry tableEntry = event.bean;
            parseExpressionIfNeeded(event, tableViewerCreator, tableEntry);
            mapperManager.getUiManager().refreshSqlExpression();
        }
    });
    if (abstractDataMapTable instanceof OutputTable) {
        OutputTable outputTable = (OutputTable) abstractDataMapTable;
        outputTable.getWhereTableFiltersEntriesModel().addAfterOperationListListener(new IListenableListListener<FilterTableEntry>() {

            @Override
            public void handleEvent(ListenableListEvent<FilterTableEntry> event) {
                resizeAtExpandedSize();
                mapperManager.getUiManager().refreshSqlExpression();
            }
        });
        outputTable.getWhereTableFiltersEntriesModel().addModifiedBeanListener(new IModifiedBeanListener<FilterTableEntry>() {

            @Override
            public void handleEvent(ModifiedBeanEvent<FilterTableEntry> event) {
                onOutputTableFiltersModified(event, extendedTableViewerForFilters);
                mapperManager.getUiManager().refreshSqlExpression();
            }
        });
        outputTable.getOtherTableFiltersEntriesModel().addAfterOperationListListener(new IListenableListListener<FilterTableEntry>() {

            @Override
            public void handleEvent(ListenableListEvent<FilterTableEntry> event) {
                resizeAtExpandedSize();
                mapperManager.getUiManager().refreshSqlExpression();
            }
        });
        outputTable.getOtherTableFiltersEntriesModel().addModifiedBeanListener(new IModifiedBeanListener<FilterTableEntry>() {

            @Override
            public void handleEvent(ModifiedBeanEvent<FilterTableEntry> event) {
                onOutputTableFiltersModified(event, entendedTableViewerForOtherClauses);
                mapperManager.getUiManager().refreshSqlExpression();
            }
        });
    }
}
Also used : SelectionListener(org.eclipse.swt.events.SelectionListener) ControlListener(org.eclipse.swt.events.ControlListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) DisposeListener(org.eclipse.swt.events.DisposeListener) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) IModifiedBeanListener(org.talend.commons.ui.swt.tableviewer.IModifiedBeanListener) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) FocusListener(org.eclipse.swt.events.FocusListener) ILineSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener) KeyListener(org.eclipse.swt.events.KeyListener) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FilterTableEntry(org.talend.designer.dbmap.model.tableentry.FilterTableEntry) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) ILineSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) OutputTable(org.talend.designer.dbmap.model.table.OutputTable) LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) ModifiedBeanEvent(org.talend.commons.ui.swt.tableviewer.ModifiedBeanEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) AbstractExtendedTableViewer(org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer) MetadataTableEditorView(org.talend.core.ui.metadata.editor.MetadataTableEditorView)

Example 3 with IListenableListListener

use of org.talend.commons.utils.data.list.IListenableListListener in project tdi-studio-se by Talend.

the class JSONFileOutputStep3Form method addFieldsListeners.

@Override
protected void addFieldsListeners() {
    metadataNameText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            MetadataToolHelper.validateSchema(metadataNameText.getText());
            metadataTable.setLabel(metadataNameText.getText());
            checkFieldsValue();
        }
    });
    metadataNameText.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            MetadataToolHelper.checkSchema(getShell(), e);
        }
    });
    metadataCommentText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            metadataTable.setComment(metadataCommentText.getText());
        }
    });
    tableEditorView.getMetadataEditor().addAfterOperationListListener(new IListenableListListener() {

        public void handleEvent(ListenableListEvent event) {
            checkFieldsValue();
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener)

Example 4 with IListenableListListener

use of org.talend.commons.utils.data.list.IListenableListListener in project tdi-studio-se by Talend.

the class TableByRowController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#
     * createControl(org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
public Control createControl(final Composite parentComposite, final IElementParameter param, final int numInRow, final int nbInRow, int top, final Control lastControlPrm) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    final Composite container = parentComposite;
    PropertiesTableEditorModel<Map<String, Object>> tableEditorModel = new PropertiesTableEditorModel<Map<String, Object>>();
    if (param.getValue() == null || param.getValue().equals("")) {
        param.setValue(new ArrayList<Map<String, Object>>());
    }
    init(elem, param);
    tableEditorModel.setData(elem, param, getProcess(elem, part));
    PropertiesTableByRowEditorView<Map<String, Object>> tableEditorView = new PropertiesTableByRowEditorView<Map<String, Object>>(parentComposite, SWT.NONE, tableEditorModel, true, false);
    tableEditorView.getExtendedTableViewer().setCommandStack(getCommandStack());
    tableEditorView.setReadOnly(param.isReadOnly() || param.isRepositoryValueUsed());
    tableEditorModel.setModifiedBeanListenable(tableEditorView.getTableViewerCreator());
    tableEditorModel.addModifiedBeanListenerForAggregateComponent();
    final Table table = tableEditorView.getTable();
    table.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    // add listener to tableMetadata (listen the event of the toolbars)
    tableEditorView.getExtendedTableModel().addAfterOperationListListener(new IListenableListListener() {

        @Override
        public void handleEvent(ListenableListEvent event) {
            if (elem instanceof Node) {
                Node node = (Node) elem;
                node.checkAndRefreshNode();
            }
        }
    });
    final Composite mainComposite = tableEditorView.getMainComposite();
    CLabel labelLabel2 = getWidgetFactory().createCLabel(container, param.getDisplayName());
    FormData formData = new FormData();
    if (lastControlPrm != null) {
        formData.left = new FormAttachment(lastControlPrm, 0);
    } else {
        formData.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    formData.top = new FormAttachment(0, top);
    labelLabel2.setLayoutData(formData);
    if (numInRow != 1) {
        labelLabel2.setAlignment(SWT.RIGHT);
    }
    // *********************
    formData = new FormData();
    int currentLabelWidth2 = STANDARD_LABEL_WIDTH;
    GC gc2 = new GC(labelLabel2);
    Point labelSize2 = gc2.stringExtent(param.getDisplayName());
    gc2.dispose();
    boolean needOffset = true;
    if ((labelSize2.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth2) {
        currentLabelWidth2 = labelSize2.x + ITabbedPropertyConstants.HSPACE;
        needOffset = false;
    }
    int tableHorizontalOffset = -5;
    if (numInRow == 1) {
        if (lastControlPrm != null) {
            if (needOffset) {
                formData.left = new FormAttachment(lastControlPrm, currentLabelWidth2 + tableHorizontalOffset);
            } else {
                formData.left = new FormAttachment(lastControlPrm, currentLabelWidth2);
            }
        } else {
            if (needOffset) {
                formData.left = new FormAttachment(0, currentLabelWidth2 + tableHorizontalOffset);
            } else {
                formData.left = new FormAttachment(0, currentLabelWidth2);
            }
        }
    } else {
        formData.left = new FormAttachment(labelLabel2, 0 + tableHorizontalOffset, SWT.RIGHT);
    }
    formData.right = new FormAttachment((numInRow * MAX_PERCENT) / nbInRow, 0);
    formData.top = new FormAttachment(0, top);
    int toolbarSize = 0;
    if (!param.isBasedOnSchema()) {
        Point size = tableEditorView.getExtendedToolbar().getToolbar().computeSize(SWT.DEFAULT, SWT.DEFAULT);
        toolbarSize = size.y + 5;
    }
    int currentHeightEditor = table.getHeaderHeight() + 1 * table.getItemHeight() + table.getItemHeight() + toolbarSize;
    int minHeightEditor = table.getHeaderHeight() + getNumberLines(param) * table.getItemHeight() + table.getItemHeight() + toolbarSize;
    int ySize2 = Math.max(currentHeightEditor, minHeightEditor);
    ySize2 = Math.min(ySize2, 500);
    formData.bottom = new FormAttachment(0, top + ySize2);
    mainComposite.setLayoutData(formData);
    hashCurControls.put(param.getName(), tableEditorView.getExtendedTableViewer().getTableViewerCreator());
    hashCurControls.put(TOOLBAR_NAME, tableEditorView.getToolBar());
    updateTableValues(param);
    this.dynamicProperty.setCurRowSize(ySize2 + ITabbedPropertyConstants.VSPACE);
    top += this.dynamicProperty.getCurRowSize();
    return null;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) FormData(org.eclipse.swt.layout.FormData) PropertiesTableEditorModel(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorModel) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Node(org.talend.designer.core.ui.editor.nodes.Node) Point(org.eclipse.swt.graphics.Point) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) Point(org.eclipse.swt.graphics.Point) PropertiesTableByRowEditorView(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableByRowEditorView) GC(org.eclipse.swt.graphics.GC) Map(java.util.Map) HashMap(java.util.HashMap) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 5 with IListenableListListener

use of org.talend.commons.utils.data.list.IListenableListListener in project tdi-studio-se by Talend.

the class UIManager method selectDataMapTableView.

/**
     * Select a table view.
     * 
     * @param dataMapTableView
     * @param useNewCommand
     * @param selectAllEntries TODO
     */
public void selectDataMapTableView(final DataMapTableView dataMapTableView, boolean useNewCommand, boolean selectAllEntries) {
    // reject table readonly
    IDataMapTable dataMapTable = dataMapTableView.getDataMapTable();
    if (dataMapTable instanceof OutputTable && ((OutputTable) dataMapTable).isErrorRejectTable()) {
        OutputTable table = (OutputTable) dataMapTable;
        if (table.getMetadataTable() != null) {
            for (IMetadataColumn column : table.getMetadataTable().getListColumns()) {
                if (mapperManager.ERROR_REJECT_MESSAGE.equals(column.getLabel()) || mapperManager.ERROR_REJECT_STACK_TRACE.equals(column.getLabel())) {
                    column.setCustom(true);
                }
            }
        }
        CustomTableManager.addCustomManagementToTable(getOutputMetaEditorView(), true);
    }
    TabFolderEditors tabFolderEditors = mapperUI.getTabFolderEditors();
    // tabFolderEditors.setSelection(TabFolderEditors.INDEX_TAB_METADATA_EDITOR);
    MetadataTableEditorView metadataTableEditorView = null;
    MetadataTableEditorView otherMetadataTableEditorView = null;
    final Zone currentZone = dataMapTableView.getZone();
    List<? extends AbstractDataMapTable> tables = null;
    DataMapTableView previousSelectedTableView = null;
    if (currentZone == Zone.INPUTS) {
        metadataTableEditorView = tabFolderEditors.getInputMetaEditorView();
        otherMetadataTableEditorView = tabFolderEditors.getOutputMetaEditorView();
        tables = mapperManager.getInputTables();
        previousSelectedTableView = this.currentSelectedInputTableView;
        this.currentSelectedInputTableView = (InputDataMapTableView) dataMapTableView;
        metadataTableEditorView.setReadOnly(this.currentSelectedInputTableView.getInputTable().hasReadOnlyMetadataColumns() || mapperManager.componentIsReadOnly() || this.currentSelectedInputTableView.getInputTable().isReadOnly());
    } else if (currentZone == Zone.OUTPUTS) {
        metadataTableEditorView = tabFolderEditors.getOutputMetaEditorView();
        otherMetadataTableEditorView = tabFolderEditors.getInputMetaEditorView();
        tables = mapperManager.getOutputTables();
        previousSelectedTableView = this.currentSelectedOutputTableView;
        this.currentSelectedOutputTableView = (OutputDataMapTableView) dataMapTableView;
        metadataTableEditorView.setReadOnly(this.currentSelectedOutputTableView.getOutputTable().hasReadOnlyMetadataColumns() || mapperManager.componentIsReadOnly());
    } else {
        this.currentSelectedVarsTableView = (VarsDataMapTableView) dataMapTableView;
    }
    if (currentZone != Zone.VARS) {
        updateToolbarButtonsStates(currentZone);
        final AbstractInOutTable abstractDataMapTable = (AbstractInOutTable) mapperManager.retrieveAbstractDataMapTable(dataMapTableView);
        MetadataTableEditor currentMetadataTableEditor = metadataTableEditorView.getMetadataTableEditor();
        final TableViewerCreator dataMapTVCreator = dataMapTableView.getTableViewerCreatorForColumns();
        final TableViewer dataMapTableViewer = dataMapTableView.getTableViewerCreatorForColumns().getTableViewer();
        if (currentMetadataTableEditor == null || currentMetadataTableEditor != null && oldSelectedView != dataMapTableView) {
            oldSelectedView = dataMapTableView;
            if (useNewCommand) {
                DataMapTableViewSelectedCommand command = new DataMapTableViewSelectedCommand(this, previousSelectedTableView, dataMapTableView);
                mapperManager.executeCommand(command);
            }
            currentMetadataTableEditor = new MetadataTableEditor(abstractDataMapTable.getMetadataTable(), abstractDataMapTable.getName());
            currentMetadataTableEditor.setModifiedBeanListenable(metadataTableEditorView.getTableViewerCreator());
            final MetadataTableEditorView metadataTableEditorViewFinal = metadataTableEditorView;
            final TableViewerCreator metadataTVCreator = metadataTableEditorViewFinal.getTableViewerCreator();
            final MetadataTableEditor metadataTableEditor = currentMetadataTableEditor;
            modifySelectionChangedListener(currentZone, metadataTableEditorViewFinal, metadataTVCreator, metadataTableEditor, dataMapTableView, previousSelectedTableView);
            // init actions listeners for list which contains metadata
            metadataTableEditor.addAfterOperationListListener(new IListenableListListener() {

                /**
                     * DOC acer Comment method "handleEvent".
                     * 
                     * @param event
                     */
                public void handleEvent(ListenableListEvent event) {
                    DataMapTableView view = mapperManager.retrieveAbstractDataMapTableView(abstractDataMapTable);
                    List<DataMapTableView> relatedOutputsTableView = getRelatedOutputsTableView(dataMapTableView);
                    if (event.type == TYPE.ADDED) {
                        // metadataEditorTableViewer.refresh();
                        List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.addedObjects;
                        lastCreatedInOutColumnEntries.clear();
                        if (event.index != null) {
                            int index = event.index;
                            for (IMetadataColumn metadataColumn : metadataColumns) {
                                lastCreatedInOutColumnEntries.add(mapperManager.addNewColumnEntry(dataMapTableView, metadataColumn, index));
                                // handle related table view
                                for (DataMapTableView tableView : relatedOutputsTableView) {
                                    // changed for bug TDI-26551 in July 2,2013 by fwang, should use original
                                    // expression for related table.
                                    IMetadataColumn relatedMetadata = metadataColumn;
                                    if (!oldMappingMap.isEmpty()) {
                                        IDataMapTable retrieveAbstractDataMapTable = mapperManager.retrieveAbstractDataMapTable(tableView);
                                        relatedMetadata = metadataColumn.clone();
                                        String label = relatedMetadata.getLabel();
                                        String expression = oldMappingMap.get(retrieveAbstractDataMapTable.getName() + "_" + label);
                                        relatedMetadata.setExpression(expression == null ? "" : expression);
                                    }
                                    mapperManager.addNewColumnEntry(tableView, relatedMetadata, index);
                                }
                                index = index + 1;
                            }
                        } else if (event.indicesTarget != null) {
                            List<Integer> indicesTarget = event.indicesTarget;
                            int lstSize = indicesTarget.size();
                            for (int i = 0; i < lstSize; i++) {
                                Integer indice = indicesTarget.get(i);
                                IMetadataColumn metadataColumn = metadataColumns.get(i);
                                lastCreatedInOutColumnEntries.add(mapperManager.addNewColumnEntry(dataMapTableView, metadataColumn, indice));
                                // handle related table view
                                for (DataMapTableView tableView : relatedOutputsTableView) {
                                    mapperManager.addNewColumnEntry(tableView, metadataColumn, indice);
                                }
                            }
                        } else {
                            //$NON-NLS-1$
                            throw new IllegalStateException(Messages.getString("UIManager.1"));
                        }
                        refreshBackground(false, false);
                        if (event.index != null) {
                            dataMapTableViewer.refresh();
                            dataMapTVCreator.getSelectionHelper().setSelection(event.index);
                            if (dataMapTableView.canBeResizedAtPreferedSize()) {
                                dataMapTableView.changeSize(view.getPreferredSize(true, false, false), true, true);
                            }
                            // resize ralated table
                            for (DataMapTableView tableView : relatedOutputsTableView) {
                                if (tableView.canBeResizedAtPreferedSize()) {
                                    tableView.changeSize(tableView.getPreferredSize(true, false, false), true, true);
                                }
                            }
                        } else if (event.indicesTarget != null) {
                            dataMapTableViewer.refresh();
                            dataMapTableView.changeSize(view.getPreferredSize(false, true, false), true, true);
                            int[] selection = ArrayUtils.toPrimitive((Integer[]) event.indicesTarget.toArray(new Integer[0]));
                            dataMapTVCreator.getSelectionHelper().setSelection(selection);
                            for (DataMapTableView tableView : relatedOutputsTableView) {
                                tableView.changeSize(tableView.getPreferredSize(false, true, false), true, true);
                            }
                        }
                    }
                    if (event.type == TYPE.REMOVED) {
                        // metadataEditorTableViewer.refresh();
                        List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.removedObjects;
                        for (IMetadataColumn metadataColumn : metadataColumns) {
                            ITableEntry metadataTableEntry = mapperManager.retrieveTableEntry(new TableEntryLocation(abstractDataMapTable.getName(), metadataColumn.getLabel()));
                            mapperManager.removeTableEntry(metadataTableEntry);
                            for (DataMapTableView tableView : relatedOutputsTableView) {
                                IDataMapTable retrieveAbstractDataMapTable = mapperManager.retrieveAbstractDataMapTable(tableView);
                                metadataTableEntry = mapperManager.retrieveTableEntry(new TableEntryLocation(retrieveAbstractDataMapTable.getName(), metadataColumn.getLabel()));
                                mapperManager.removeTableEntry(metadataTableEntry);
                                if (tableView.canBeResizedAtPreferedSize()) {
                                    tableView.resizeAtExpandedSize();
                                }
                            }
                        }
                        dataMapTableViewer.refresh();
                        if (dataMapTableView.canBeResizedAtPreferedSize()) {
                            dataMapTableView.resizeAtExpandedSize();
                        }
                        resizeTablesZoneViewAtComputedSize(dataMapTableView.getZone());
                        moveScrollBarZoneAtSelectedTable(dataMapTableView.getZone());
                        refreshBackground(true, false);
                    }
                    if (event.type == TYPE.SWAPED) {
                        List<Integer> listIndexTarget = event.indicesTarget;
                        abstractDataMapTable.swapColumnElements(event.indicesOrigin, listIndexTarget);
                        // handle related table view
                        for (DataMapTableView tableView : relatedOutputsTableView) {
                            AbstractDataMapTable relatedTable = (AbstractDataMapTable) tableView.getDataMapTable();
                            relatedTable.swapColumnElements(event.indicesOrigin, listIndexTarget);
                        }
                        // dataMapTableViewer.refresh();
                        refreshBackground(true, false);
                    }
                }
            });
            metadataTableEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(false);
            metadataTableEditorView.setMetadataTableEditor(metadataTableEditor);
            metadataTableEditorView.getTableViewerCreator().getSelectionHelper().setActiveFireSelectionChanged(true);
            metadataTableEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
            dataMapTVCreator.getSelectionHelper().setActiveFireSelectionChanged(false);
            metadataTableEditorView.getTableViewerCreator().getSelectionHelper().setSelection(dataMapTableViewer.getTable().getSelectionIndices());
            dataMapTVCreator.getSelectionHelper().setActiveFireSelectionChanged(true);
            // disable highlight for other DataMapTableView and highlight selected DataMapTableView
            for (IDataMapTable table : tables) {
                DataMapTableView otherDataMapTableView = mapperManager.retrieveAbstractDataMapTableView(table);
                otherDataMapTableView.setBackground(dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
            }
            dataMapTableView.setBackground(dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }
        if (selectAllEntries) {
            dataMapTVCreator.getTable().selectAll();
            selectAllLinks(dataMapTableView);
            if (currentZone != Zone.VARS) {
                metadataTableEditorView.getTableViewerCreator().getTable().selectAll();
                metadataTableEditorView.getToolBar().updateEnabledStateOfButtons();
            }
            if (currentZone == Zone.OUTPUTS) {
                dataMapTableView.getTableViewerCreatorForFilters().getTable().selectAll();
            }
        }
        boolean isMainSchemaRepository = false;
        if (abstractDataMapTable instanceof OutputTable) {
            OutputTable outputTable = (OutputTable) abstractDataMapTable;
            if (outputTable.getIsJoinTableOf() != null || !"".equals(outputTable.getIsJoinTableOf())) {
                final OutputTable outputTableByName = mapperManager.getOutputTableByName(outputTable.getIsJoinTableOf());
                if (outputTableByName != null && outputTableByName.getId() != null) {
                    isMainSchemaRepository = true;
                }
            }
        }
        dataMapTableView.enableDiaplayViewer(abstractDataMapTable.isRepository() || isMainSchemaRepository);
    }
    if (selectAllEntries && currentZone == Zone.VARS) {
        selectAllLinks(dataMapTableView);
        mapperManager.getUiManager().getVarsTablesView().get(0).getTableViewerCreatorForColumns().getTable().selectAll();
    }
    if (otherMetadataTableEditorView != null) {
        otherMetadataTableEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
    }
}
Also used : TabFolderEditors(org.talend.designer.mapper.ui.tabs.TabFolderEditors) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) MetadataTableEditor(org.talend.core.ui.metadata.editor.MetadataTableEditor) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) AbstractDataMapTable(org.talend.designer.mapper.model.table.AbstractDataMapTable) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) OutputTable(org.talend.designer.mapper.model.table.OutputTable) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) ArrayList(java.util.ArrayList) List(java.util.List) AbstractMetadataTableEditorView(org.talend.core.ui.metadata.editor.AbstractMetadataTableEditorView) MetadataTableEditorView(org.talend.core.ui.metadata.editor.MetadataTableEditorView) Zone(org.talend.designer.mapper.ui.visualmap.zone.Zone) InputsZone(org.talend.designer.mapper.ui.visualmap.zone.InputsZone) ToolbarOutputZone(org.talend.designer.mapper.ui.visualmap.zone.toolbar.ToolbarOutputZone) ToolbarZone(org.talend.designer.mapper.ui.visualmap.zone.toolbar.ToolbarZone) OutputsZone(org.talend.designer.mapper.ui.visualmap.zone.OutputsZone) 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) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) Point(org.eclipse.swt.graphics.Point) DataMapTableViewSelectedCommand(org.talend.designer.mapper.ui.commands.DataMapTableViewSelectedCommand) TableViewer(org.eclipse.jface.viewers.TableViewer) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView)

Aggregations

IListenableListListener (org.talend.commons.utils.data.list.IListenableListListener)14 ListenableListEvent (org.talend.commons.utils.data.list.ListenableListEvent)14 List (java.util.List)6 ArrayList (java.util.ArrayList)5 MetadataTableEditorView (org.talend.core.ui.metadata.editor.MetadataTableEditorView)5 HashMap (java.util.HashMap)4 KeyEvent (org.eclipse.swt.events.KeyEvent)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4 ModifyListener (org.eclipse.swt.events.ModifyListener)4 Point (org.eclipse.swt.graphics.Point)4 Table (org.eclipse.swt.widgets.Table)4 TableViewer (org.eclipse.jface.viewers.TableViewer)3 KeyAdapter (org.eclipse.swt.events.KeyAdapter)3 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)3 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)3 AbstractMetadataTableEditorView (org.talend.core.ui.metadata.editor.AbstractMetadataTableEditorView)3 MetadataTableEditor (org.talend.core.ui.metadata.editor.MetadataTableEditor)3 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)3 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)3 Map (java.util.Map)2