Minor update
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@102174 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a46239c8f3
commit
137c02ee88
|
@ -134,6 +134,8 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
|
||||
private ColumnModel<DataRow> columnModel;
|
||||
|
||||
private GridAndCellSelectionModel<DataRow> sm;
|
||||
|
||||
/**
|
||||
* @param eventBus
|
||||
*/
|
||||
|
@ -766,7 +768,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
// liveGridView.setRowHeight(19);
|
||||
|
||||
grid = new Grid<DataRow>(store, columnModel);
|
||||
GridAndCellSelectionModel<DataRow> sm = new GridAndCellSelectionModel<DataRow>();
|
||||
sm = new GridAndCellSelectionModel<DataRow>();
|
||||
|
||||
grid.setSelectionModel(sm);
|
||||
grid.setLoadMask(true);
|
||||
|
@ -826,11 +828,12 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
} else {
|
||||
Log.debug("Setup grid not null");
|
||||
// TODO we need to manually reset the sort
|
||||
sm.onChangeNumberOfRows();
|
||||
loader.clearSortInfo();
|
||||
reader.setDefinition(tableDefinition);
|
||||
|
||||
grid.reconfigure(store, columnModel);
|
||||
|
||||
|
||||
|
||||
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
|
||||
.generate(columnModel);
|
||||
gridFilters.removeAll();
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
package org.gcube.portlets.user.tdwx.client.config;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.EventTarget;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.sencha.gxt.core.client.GXTLogConfiguration;
|
||||
import com.sencha.gxt.data.shared.ListStore;
|
||||
import com.sencha.gxt.messages.client.DefaultMessages;
|
||||
import com.sencha.gxt.widget.core.client.event.LiveGridViewUpdateEvent;
|
||||
import com.sencha.gxt.widget.core.client.grid.LiveGridView;
|
||||
|
||||
/**
|
||||
|
@ -11,9 +18,21 @@ import com.sencha.gxt.widget.core.client.grid.LiveGridView;
|
|||
* @param <M>
|
||||
*/
|
||||
public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
||||
// TODO bug in gxt3 3.0.0 fixed in future
|
||||
|
||||
|
||||
|
||||
private boolean isLoading;
|
||||
private boolean isMasked;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private int viewIndexReload = -1;
|
||||
|
||||
private int lastViewIndex = -1;
|
||||
private int lastScrollDirection = 0;
|
||||
private int rowHeightAdjust;
|
||||
private boolean measureRowHeight = true;
|
||||
private boolean ignoreScroll;
|
||||
|
||||
// private boolean adjustScrollHeight;
|
||||
|
||||
@Override
|
||||
public void refresh(boolean headerToo) {
|
||||
preventScrollToTopOnRefresh = true;
|
||||
|
@ -35,11 +54,189 @@ public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
|||
public void setCacheStore(ListStore<M> list) {
|
||||
cacheStore = list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the total number of rows that are visible given the current grid
|
||||
* height.
|
||||
*
|
||||
* @return the visible row count
|
||||
*/
|
||||
@Override
|
||||
public int getVisibleRowCount() {
|
||||
int rh = getRowHeight();
|
||||
int visibleHeight = getLiveScrollerHeight();
|
||||
int result = (int) ((visibleHeight < 1) ? 0 : Math
|
||||
.floor((double) visibleHeight / rh));
|
||||
|
||||
int calcHeight = rh * result;
|
||||
|
||||
while (calcHeight < visibleHeight) {
|
||||
result++;
|
||||
calcHeight = rh * result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Log.debug("GetVisibleRowCount(): row height: " + rh +
|
||||
* " visibleHeight: " + visibleHeight + " visible rows: " + result +
|
||||
* " calcHeight: " + calcHeight);
|
||||
*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleComponentEvent(Event ge) {
|
||||
super.handleComponentEvent(ge);
|
||||
int type = ge.getTypeInt();
|
||||
EventTarget t = ge.getEventTarget();
|
||||
|
||||
if (ignoreScroll || !Element.is(t)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Element target = Element.as(t);
|
||||
|
||||
if (type == Event.ONMOUSEWHEEL && dataTable.isOrHasChild(target)) {
|
||||
int v = ge.getMouseWheelVelocityY() * getRowHeight();
|
||||
liveScroller.setScrollTop(liveScroller.getScrollTop() + v);
|
||||
} else if (type == Event.ONSCROLL && liveScroller.isOrHasChild(target)) {
|
||||
ge.stopPropagation();
|
||||
ge.preventDefault();
|
||||
Log.debug("HandleComponentEvent: scrollTop:"+liveScroller.getScrollTop()+", rowHeight:"+getRowHeight()+", newIndex:"+(int) Math.ceil((double) liveScroller.getScrollTop()
|
||||
/ getRowHeight()));
|
||||
updateRows(
|
||||
(int) Math.ceil((double) liveScroller.getScrollTop()
|
||||
/ getRowHeight()), false);
|
||||
}
|
||||
}
|
||||
|
||||
private void maskView() {
|
||||
if (!isMasked && grid.isLoadMask()) {
|
||||
grid.mask(DefaultMessages.getMessages().loadMask_msg());
|
||||
isMasked = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the rows based on the new index.
|
||||
*
|
||||
* @param newIndex
|
||||
* the new index
|
||||
* @param reload
|
||||
* true to reload the data
|
||||
*/
|
||||
@Override
|
||||
protected void updateRows(int newIndex, boolean reload) {
|
||||
Log.debug("updateRows(): newIndex: " + newIndex + " reload:" + reload);
|
||||
|
||||
// the number of rows visible within the grid's viewport
|
||||
int rowCount = getVisibleRowCount();
|
||||
|
||||
newIndex = Math.min(newIndex, Math.max(0, totalCount - rowCount));
|
||||
|
||||
int diff = newIndex - viewIndex;
|
||||
|
||||
// the difference from the view index and the new index
|
||||
int delta = Math.abs(diff);
|
||||
|
||||
Log.debug("updateRows(): totalCount:" + totalCount + " newIndex: "
|
||||
+ newIndex + " viewIndex: " + viewIndex + " visibleRows: "
|
||||
+ rowCount + " diff: " + diff);
|
||||
|
||||
// nothing has changed and we are not forcing a reload
|
||||
if (delta == 0 && !reload) {
|
||||
Log.debug("updateRows() nothing changed and not forcing reload");
|
||||
return;
|
||||
}
|
||||
|
||||
viewIndex = newIndex;
|
||||
int liveStoreIndex = Math.max(0, viewIndex - liveStoreOffset);
|
||||
|
||||
// load data if not already cached
|
||||
if (!isCached(viewIndex)) {
|
||||
Log.debug("updateRows() not cached, loading data");
|
||||
|
||||
maskView();
|
||||
if (loadLiveStore(getLiveStoreCalculatedIndex(viewIndex))) {
|
||||
viewIndexReload = viewIndex;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// do pre caching
|
||||
if (shouldCache(viewIndex) && !isLoading) {
|
||||
loadLiveStore(getLiveStoreCalculatedIndex(viewIndex));
|
||||
}
|
||||
|
||||
int rc = getVisibleRowCount();
|
||||
if (delta > rc - 1) {
|
||||
reload = true;
|
||||
}
|
||||
|
||||
if (reload) {
|
||||
Log.debug("updateRows() newIndex: " + newIndex + " viewIndex: "
|
||||
+ viewIndex + " visible rows: " + rowCount + " diff: "
|
||||
+ diff);
|
||||
|
||||
delta = diff = rc;
|
||||
if (ds.size() > 0) {
|
||||
boolean p = preventScrollToTopOnRefresh;
|
||||
preventScrollToTopOnRefresh = true;
|
||||
ds.clear();
|
||||
preventScrollToTopOnRefresh = p;
|
||||
}
|
||||
}
|
||||
|
||||
if (delta == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int count = ds.size();
|
||||
if (diff > 0) {
|
||||
// rolling forward
|
||||
for (int c = 0; c < delta && c < count; c++) {
|
||||
ds.remove(0);
|
||||
}
|
||||
count = ds.size();
|
||||
Log.debug("updateRows() forward adding to store from cache, liveStoreIndex: "
|
||||
+ liveStoreIndex + " count: " + count);
|
||||
|
||||
ds.addAll(cacheStore.subList(liveStoreIndex + count, liveStoreIndex
|
||||
+ count + delta));
|
||||
} else {
|
||||
// rolling back
|
||||
for (int c = 0; c < delta && c < count; c++) {
|
||||
ds.remove(count - c - 1);
|
||||
}
|
||||
|
||||
if (GXTLogConfiguration.loggingIsEnabled()) {
|
||||
Log.debug("updateRows() reverse adding to store from cache, liveStoreIndex: "
|
||||
+ liveStoreIndex + " count: " + count);
|
||||
}
|
||||
|
||||
ds.addAll(0,
|
||||
cacheStore.subList(liveStoreIndex, liveStoreIndex + delta));
|
||||
}
|
||||
|
||||
if (!measureRowHeight) {
|
||||
if (viewIndex > lastViewIndex) {
|
||||
scroller.setScrollTop(rowHeightAdjust);
|
||||
lastScrollDirection = 1;
|
||||
} else if (viewIndex < lastViewIndex) {
|
||||
lastScrollDirection = 0;
|
||||
scroller.setScrollTop(0);
|
||||
} else {
|
||||
scroller.setScrollTop(lastScrollDirection == 0 ? 0
|
||||
: rowHeightAdjust);
|
||||
}
|
||||
}
|
||||
|
||||
Log.debug("updateRows() fireEvent Update: offset:" + liveStoreOffset
|
||||
+ " viewIndex:" + viewIndex + " totalCount:" + totalCount
|
||||
+ " visibleRowCount:" + getVisibleRowCount());
|
||||
fireEvent(new LiveGridViewUpdateEvent(liveStoreOffset, viewIndex,
|
||||
totalCount, getVisibleRowCount()));
|
||||
lastViewIndex = viewIndex;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -277,4 +277,22 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
|
||||
}
|
||||
|
||||
public void onChangeNumberOfRows(){
|
||||
Log.debug("Selection Model Called OnChangeNumberOfRows()");
|
||||
if(selected!=null){
|
||||
Log.debug("Rows Selected: "+selected.size());
|
||||
}
|
||||
|
||||
deselectAll();
|
||||
fireSelectionChange();
|
||||
|
||||
if(selected!=null){
|
||||
Log.debug("After deselect Rows Selected: "+selected.size());
|
||||
} else{
|
||||
Log.debug("After deselect No Rows Selected");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue