Search in sources :

Example 6 with TableEvent

use of org.eclipse.scout.rt.client.ui.basic.table.TableEvent in project scout.rt by eclipse.

the class TableProposalChooser method createModel.

@Override
protected IContentAssistFieldTable createModel() {
    IContentAssistFieldTable<LOOKUP_KEY> table = createConfiguredOrDefaultModel(IContentAssistFieldTable.class);
    table.addTableListener(new TableAdapter() {

        @Override
        public void tableChanged(TableEvent e) {
            if (e.getType() == TableEvent.TYPE_ROW_CLICK) {
                try {
                    execResultTableRowClicked(CollectionUtility.firstElement(e.getRows()));
                } catch (RuntimeException e1) {
                    LOG.warn("could not handle smart table selection.", e1);
                }
            }
        }
    });
    return table;
}
Also used : TableEvent(org.eclipse.scout.rt.client.ui.basic.table.TableEvent) TableAdapter(org.eclipse.scout.rt.client.ui.basic.table.TableAdapter)

Example 7 with TableEvent

use of org.eclipse.scout.rt.client.ui.basic.table.TableEvent in project scout.rt by eclipse.

the class JsonTable method preprocessBufferedEvents.

protected void preprocessBufferedEvents() {
    List<TableEvent> bufferInternal = m_eventBuffer.getBufferInternal();
    for (int i = 0; i < bufferInternal.size(); i++) {
        TableEvent event = bufferInternal.get(i);
        if (event.getType() != TableEvent.TYPE_ROW_FILTER_CHANGED) {
            continue;
        }
        // Convert the "filter changed" event to a ROWS_DELETED and a ROWS_INSERTED event. This prevents sending unnecessary
        // data to the UI. We convert the event before adding it to the event buffer to allow coalescing on UI-level.
        // NOTE: This may lead to a temporary inconsistent situation, where row events exist in the buffer after the
        // row itself is deleted. This is because the row is not really deleted from the model. However, when processing
        // the buffered events, the "wrong" events will be ignored and everything is fixed again.
        List<ITableRow> rowsToInsert = new ArrayList<>();
        List<ITableRow> rowsToDelete = new ArrayList<>();
        for (ITableRow row : getModel().getRows()) {
            String existingRowId = getTableRowId(row);
            if (row.isFilterAccepted()) {
                if (existingRowId == null) {
                    // Row is not filtered but JsonTable does not know it yet --> handle as insertion event
                    rowsToInsert.add(row);
                }
            } else if (!row.isRejectedByUser() && existingRowId != null) {
                // Row is filtered, but JsonTable has it in its list --> handle as deletion event
                rowsToDelete.add(row);
            }
        }
        // Put at the same position as the row_filter_changed event (replace it) to keep the order of multiple insert events
        bufferInternal.set(i, new TableEvent(getModel(), TableEvent.TYPE_ROWS_INSERTED, rowsToInsert));
        if (!rowsToInsert.isEmpty()) {
            // Generate an artificial "row order changed" event so that the inserted rows are at the correct position in the UI
            bufferInternal.add(i + 1, new TableEvent(getModel(), TableEvent.TYPE_ROW_ORDER_CHANGED, getModel().getRows()));
        }
        // Make sure no previous event contains the newly inserted rows
        for (int j = i - 1; j >= 0; j--) {
            bufferInternal.get(j).removeRows(rowsToInsert);
        }
        // Put at the beginning to make sure no subsequent event contains the deleted row
        bufferInternal.add(0, new TableEvent(getModel(), TableEvent.TYPE_ROWS_DELETED, rowsToDelete));
        // NOSONAR
        i++;
    }
}
Also used : TableEvent(org.eclipse.scout.rt.client.ui.basic.table.TableEvent) ArrayList(java.util.ArrayList) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Example 8 with TableEvent

use of org.eclipse.scout.rt.client.ui.basic.table.TableEvent in project scout.rt by eclipse.

the class JsonTable method init.

@Override
public void init() {
    super.init();
    // Replay missed events
    IEventHistory<TableEvent> eventHistory = getModel().getEventHistory();
    if (eventHistory != null) {
        for (TableEvent event : eventHistory.getRecentEvents()) {
            // Immediately execute events (no buffering), because this method is not called
            // from the model but from the JSON layer. If Response.toJson() is in progress,
            // adding this adapter to the list of buffered event providers would cause
            // an exception.
            processEvent(event);
        }
    }
}
Also used : TableEvent(org.eclipse.scout.rt.client.ui.basic.table.TableEvent)

Example 9 with TableEvent

use of org.eclipse.scout.rt.client.ui.basic.table.TableEvent in project scout.rt by eclipse.

the class AbstractListBox method initConfig.

@Override
protected void initConfig() {
    m_fields = CollectionUtility.emptyArrayList();
    m_movedFormFieldsByClass = new HashMap<Class<? extends IFormField>, IFormField>();
    super.initConfig();
    setFilterActiveRows(getConfiguredFilterActiveRows());
    setFilterActiveRowsValue(TriState.TRUE);
    setFilterCheckedRows(getConfiguredFilterCheckedRows());
    setFilterCheckedRowsValue(getConfiguredFilterCheckedRows());
    List<ITable> contributedTables = m_contributionHolder.getContributionsByClass(ITable.class);
    m_table = CollectionUtility.firstElement(contributedTables);
    if (m_table == null) {
        Class<? extends ITable> configuredTable = getConfiguredTable();
        if (configuredTable != null) {
            m_table = ConfigurationUtility.newInnerInstance(this, configuredTable);
        }
    }
    if (m_table != null) {
        if (m_table instanceof AbstractTable) {
            ((AbstractTable) m_table).setContainerInternal(this);
        }
        updateActiveRowsFilter();
        updateCheckedRowsFilter();
        m_table.addTableListener(new TableAdapter() {

            @Override
            public void tableChanged(TableEvent e) {
                switch(e.getType()) {
                    case TableEvent.TYPE_ROWS_SELECTED:
                        {
                            if (!getTable().isCheckable()) {
                                syncTableToValue();
                            }
                            break;
                        }
                    case TableEvent.TYPE_ROWS_CHECKED:
                        {
                            if (getTable().isCheckable()) {
                                syncTableToValue();
                            }
                            break;
                        }
                }
            }
        });
        // default icon
        if (m_table.getDefaultIconId() == null && this.getConfiguredIconId() != null) {
            m_table.setDefaultIconId(this.getConfiguredIconId());
        }
        m_table.setEnabled(isEnabled());
    } else {
        LOG.warn("there is no inner class of type ITable in {}", getClass().getName());
    }
    // lookup call
    Class<? extends ILookupCall<KEY>> lookupCallClass = getConfiguredLookupCall();
    if (lookupCallClass != null) {
        ILookupCall<KEY> call = BEANS.get(lookupCallClass);
        setLookupCall(call);
    }
    // code type
    if (getConfiguredCodeType() != null) {
        setCodeTypeClass(getConfiguredCodeType());
    }
    // local property listener
    addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if (m_table == null) {
                return;
            }
            String name = e.getPropertyName();
            if (PROP_ENABLED_COMPUTED.equals(name)) {
                boolean newEnabled = ((Boolean) e.getNewValue()).booleanValue();
                m_table.setEnabled(newEnabled);
            } else if (PROP_FILTER_CHECKED_ROWS_VALUE.equals(name)) {
                updateCheckedRowsFilter();
            } else if (PROP_FILTER_ACTIVE_ROWS_VALUE.equals(name)) {
                updateActiveRowsFilter();
            }
        }
    });
    // add fields
    List<Class<? extends IFormField>> fieldClasses = getConfiguredFields();
    List<IFormField> contributedFields = m_contributionHolder.getContributionsByClass(IFormField.class);
    List<IFormField> fieldList = new ArrayList<IFormField>(fieldClasses.size() + contributedFields.size());
    for (Class<? extends IFormField> fieldClazz : fieldClasses) {
        IFormField f = ConfigurationUtility.newInnerInstance(this, fieldClazz);
        fieldList.add(f);
    }
    fieldList.addAll(contributedFields);
    Collections.sort(fieldList, new OrderedComparator());
    for (IFormField f : fieldList) {
        f.setParentFieldInternal(this);
    }
    m_fields = fieldList;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ArrayList(java.util.ArrayList) TableAdapter(org.eclipse.scout.rt.client.ui.basic.table.TableAdapter) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) AbstractTable(org.eclipse.scout.rt.client.ui.basic.table.AbstractTable) TableEvent(org.eclipse.scout.rt.client.ui.basic.table.TableEvent) OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable)

Example 10 with TableEvent

use of org.eclipse.scout.rt.client.ui.basic.table.TableEvent in project scout.rt by eclipse.

the class OrganizeColumnsFormRegressionTest method givenAProfilesTable.

private void givenAProfilesTable() {
    ITable table = mock(ITable.class);
    OrganizeColumnsForm form = new OrganizeColumnsForm(table);
    profilesTable = form.getProfilesTableField().getTable();
    profilesTable.addTableListener(new TableListener() {

        @Override
        public void tableChangedBatch(List<? extends TableEvent> batch) {
            for (TableEvent e : batch) {
                tableChanged(e);
            }
        }

        @Override
        public void tableChanged(TableEvent e) {
            if (e.getType() == TableEvent.TYPE_REQUEST_FOCUS_IN_CELL) {
                IColumn focusedColumn = CollectionUtility.firstElement(e.getColumns());
                ITableRow focusedRow = CollectionUtility.firstElement(e.getRows());
                if (focusedColumn.equals(profilesTable.getConfigNameColumn())) {
                    lastFocusedRowIndex.setValue(focusedRow.getRowIndex());
                }
            }
        }
    });
    profilesTable.deselectAllRows();
}
Also used : TableEvent(org.eclipse.scout.rt.client.ui.basic.table.TableEvent) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) TableListener(org.eclipse.scout.rt.client.ui.basic.table.TableListener)

Aggregations

TableEvent (org.eclipse.scout.rt.client.ui.basic.table.TableEvent)10 ArrayList (java.util.ArrayList)3 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)3 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)2 TableAdapter (org.eclipse.scout.rt.client.ui.basic.table.TableAdapter)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 AbstractTable (org.eclipse.scout.rt.client.ui.basic.table.AbstractTable)1 TableListener (org.eclipse.scout.rt.client.ui.basic.table.TableListener)1 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)1 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)1 OrderedComparator (org.eclipse.scout.rt.platform.OrderedComparator)1