vaadin / framework

Vaadin 6, 7, 8 is a Java framework for modern Java web applications.
http://vaadin.com/
Other
1.79k stars 729 forks source link

Event when a Table column is collapsed #1565

Closed vaadin-bot closed 9 years ago

vaadin-bot commented 13 years ago

Originally by @Artur-


API:

addListener(Table.ColumnCollapseListener listener)
removeListener(Table.ColumnCollapseListener listener)

Should be fired after a column has been collapsed/uncollapsed

Use case: Store Table configuration for the user

Split from #6187


Imported from https://dev.vaadin.com/ issue #6914

vaadin-bot commented 11 years ago

Originally by _personalsoftfabiano


I would like to have this listener, too

vaadin-bot commented 11 years ago

Originally by S73417H


This seems like a feature that should have been implemented by now. Our application also requires the ability to transparently persist user interface state. We would like to do this without the use of timers.

I've voted on this feature using our pro account. Hopefully it gets some traction soon as its been sitting here a while. Would very much like to see this in Vaadin 6.x.

vaadin-bot commented 11 years ago

Originally by @jdahlstrom


This is one of our most voted feature requests, and wouldn't be that hard to implement. We seriously considered it for 7.1 but unfortunately didn't have enough time in the end. Hopefully it does make it into Vaadin 7.2. However, the Vaadin 6 series is in maintenance mode and is not expected to get new features at this point.

vaadin-bot commented 11 years ago

Originally by santeriv-profit


Here is a more an idea or a comment than a real workaround because the UI cannot actually be updated during paintContent as seen in comments, if somebody tries to create a workaround for this .. (vaadin 7.1)

        MyTreeTable extends TreeTable
//
..
//
    public static interface ColumnCollapsedEventListener extends Serializable {
        /**
         - Triggered when collapsed columns amount changes
         - 
         - @param newCollapsedColumns
         -            - List of collapsed propertyIds
         -/
        void collapsedColumnsChanged(List<Object> newCollapsedColumns);
    }

    private ColumnCollapsedEventListener columnCollapsedEventListener;

    private List<Object> collapsedColumns = Lists.newArrayList();

    @Override
    public void paintContent(PaintTarget target) throws PaintException {
        super.paintContent(target);
        // For workaround of TreeTable/Table 'bug' to inform about collapse
        // event of columns
        List<Object> collapsedColumnPropertyIds = getCollapsedColumns();
        if (collapsedColumns.size() != collapsedColumnPropertyIds.size()) {
            LOGGER.debug("paintContent collapsedColumnsChanged");
            // then there was change in collapsed columns
            collapsedColumns = collapsedColumnPropertyIds;
            if (columnCollapsedEventListener != null) {
                //TODO: Because paintContent is part of uidl write response, we should wait until UI is ready
                /*
                java.lang.IllegalStateException: A connector should not be marked as dirty while a response is being written.
                at com.vaadin.ui.ConnectorTracker.markDirty(ConnectorTracker.java:346)
                -/
                //writing response is not done  
                columnCollapsedEventListener.collapsedColumnsChanged(collapsedColumns);
            }
        }
    }

    // would be nice if visibleColumns would read collapsedColumns also
    public List<Object> getCollapsedColumns() {
        List<Object> collapsedColumnPropertyIds = Lists.newArrayList();
        List<Object> propertyIds = Lists.newArrayList(getContainerPropertyIds());
        for (Object propertyId : propertyIds) {
            if (isColumnCollapsed(propertyId)) {
                collapsedColumnPropertyIds.add(propertyId);
            }
        }
        return collapsedColumnPropertyIds;
    }
vaadin-bot commented 10 years ago

Originally by geert3


Here is a more an idea or a comment than a real workaround because the UI cannot actually be updated during paintContent as seen in comments, if somebody tries to create a workaround for this .. (vaadin 7.1)

Your solution actually works quite well. To avoid the exception all you need is to wrap the event firing in "access()", like this:

if (columnCollapsedEventListener != null) {
    VaadinSession.getCurrent().access(new Runnable() {
        @Override
        public void run() {
            columnCollapsedEventListener.collapsedColumnsChanged(collapsedColumns);
        }
    });
}
vaadin-bot commented 9 years ago

Originally by @Artur-


https://dev.vaadin.com/review/11457