Search in sources :

Example 1 with ISupportsNeedEntireState

use of com.servoy.j2db.dataprocessing.ISupportsNeedEntireState in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method tableChanged.

/**
 * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
 */
public void tableChanged(TableModelEvent e) {
    // as changed, as it will be faster on the client the component replace
    if ((e.getType() == TableModelEvent.UPDATE) && (e.getFirstRow() == e.getLastRow()) && (nrUpdatedListItems < 20)) {
        Component component = table.get(Integer.toString(e.getFirstRow()));
        if (component instanceof ListItem) {
            ((ListItem) component).visitChildren(IProviderStylePropertyChanges.class, new IVisitor<Component>() {

                public Object component(Component comp) {
                    if ((comp instanceof IDisplayData) || !(comp instanceof ILabel)) {
                        if (comp instanceof ISupportsNeedEntireState && ((ISupportsNeedEntireState) comp).needEntireState()) {
                            // it if has tags - mark as changed; it could be enhanced further by also know what was last-rendered on tags, not just simple dataproviders
                            ((IProviderStylePropertyChanges) comp).getStylePropertyChanges().setChanged();
                        } else {
                            // try to mark cells as changed only if there was a real value change; otherwise there is no use to replace the whole row...
                            checkForValueChanges(comp);
                        }
                    }
                    // else labels/buttons that don't display data are not changed
                    return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            });
            nrUpdatedListItems++;
            IModel<IRecordInternal> newModel = table.getListItemModel(table.getModel(), e.getFirstRow());
            IModel oldModel = ((ListItem) component).getModel();
            if (newModel != null && oldModel != null && newModel.getObject() != null && !newModel.getObject().equals(oldModel.getObject())) {
                // refresh model if it changed
                ((ListItem) component).setModel(newModel);
            }
        }
    } else {
        if (!isRendering && (!isScrollMode() || !(scrollBehavior != null && scrollBehavior.isGettingRows()))) {
            if (isScrollMode())
                resetScrollParams();
            getStylePropertyChanges().setValueChanged();
        }
    }
    // This is just an heuristic for filtering out the sort event from all table changed events that are raised.
    if (currentData != null && e.getColumn() == TableModelEvent.ALL_COLUMNS && e.getFirstRow() == 0 && elementToColumnHeader.size() > 0) {
        List<SortColumn> sortCols = currentData.getSortColumns();
        if (sortCols != null && sortCols.size() > 0) {
            Map<String, Boolean> sortMap = new HashMap<String, Boolean>();
            for (IPersist persist : elementToColumnHeader.keySet()) {
                SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
                sortableCellViewHeader.setResizeImage(R_ARROW_OFF);
            }
            for (SortColumn sc : sortCols) {
                for (IPersist persist : elementToColumnHeader.keySet()) {
                    Component comp = elementToColumnIdentifierComponent.get(persist);
                    SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
                    if (comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null) {
                        IDisplayData dispComp = (IDisplayData) comp;
                        List<String> sortingProviders = null;
                        if (dispComp instanceof ISupportValueList && ((ISupportValueList) dispComp).getValueList() != null) {
                            try {
                                sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) dispComp).getValueList().getValueList(), (Table) currentData.getTable(), dispComp.getDataProviderID(), currentData.getFoundSetManager());
                            } catch (RepositoryException ex) {
                                Debug.error(ex);
                            }
                        }
                        if (sortingProviders == null) {
                            // no related sort, use sort on dataProviderID instead
                            sortingProviders = Collections.singletonList(dispComp.getDataProviderID());
                        }
                        for (String sortingProvider : sortingProviders) {
                            SortColumn existingSc;
                            try {
                                FoundSetManager fsm = (FoundSetManager) currentData.getFoundSetManager();
                                existingSc = fsm.getSortColumn(currentData.getTable(), sortingProvider, false);
                            } catch (RepositoryException ex) {
                                Debug.error(ex);
                                continue;
                            }
                            if (sc.equalsIgnoreSortorder(existingSc)) {
                                boolean descending = sc.getSortOrder() == SortColumn.DESCENDING;
                                sortableCellViewHeader.setResizeImage(descending ? R_ARROW_UP : R_ARROW_DOWN);
                                sortMap.put(sortableCellViewHeader.getId(), Boolean.valueOf(!descending));
                            }
                        }
                    }
                }
            }
            headers.recordSort(sortMap);
        }
    }
    MainPage mp = table.findParent(MainPage.class);
    if (mp != null)
        mp.triggerBrowserRequestIfNeeded();
}
Also used : ISupportsNeedEntireState(com.servoy.j2db.dataprocessing.ISupportsNeedEntireState) ILabel(com.servoy.j2db.ui.ILabel) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) IComponent(com.servoy.j2db.ui.IComponent) AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) MainPage(com.servoy.j2db.server.headlessclient.MainPage) IModel(org.apache.wicket.model.IModel) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) Table(com.servoy.j2db.persistence.Table) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IPersist(com.servoy.j2db.persistence.IPersist) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) ListItem(org.apache.wicket.markup.html.list.ListItem)

Aggregations

FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)1 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 ISupportsNeedEntireState (com.servoy.j2db.dataprocessing.ISupportsNeedEntireState)1 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)1 IPersist (com.servoy.j2db.persistence.IPersist)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 Table (com.servoy.j2db.persistence.Table)1 MainPage (com.servoy.j2db.server.headlessclient.MainPage)1 IComponent (com.servoy.j2db.ui.IComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 ILabel (com.servoy.j2db.ui.ILabel)1 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)1 IProviderStylePropertyChanges (com.servoy.j2db.ui.IProviderStylePropertyChanges)1 ISupportValueList (com.servoy.j2db.ui.ISupportValueList)1 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)1 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)1 HashMap (java.util.HashMap)1