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();
}
Aggregations