Updated EditRow to manage to more than one row
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@111330 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9152ce10e1
commit
99146fa0c0
|
@ -75,7 +75,6 @@ import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent.HeaderCont
|
||||||
import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent;
|
import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent;
|
||||||
import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent.HeaderMouseDownHandler;
|
import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent.HeaderMouseDownHandler;
|
||||||
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
|
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
|
||||||
import com.sencha.gxt.widget.core.client.grid.ColumnHeader;
|
|
||||||
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
|
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
|
||||||
import com.sencha.gxt.widget.core.client.grid.Grid;
|
import com.sencha.gxt.widget.core.client.grid.Grid;
|
||||||
import com.sencha.gxt.widget.core.client.grid.filters.Filter;
|
import com.sencha.gxt.widget.core.client.grid.filters.Filter;
|
||||||
|
@ -286,10 +285,11 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return Selected Row as RowRaw
|
* @return Selected Rows as List<RowRaw>
|
||||||
*/
|
*/
|
||||||
public RowRaw getSelectedRowAsRaw() {
|
public ArrayList<RowRaw> getSelectedRowsAsRaw() {
|
||||||
if (grid != null && grid.getSelectionModel() != null) {
|
if (grid != null && grid.getSelectionModel() != null) {
|
||||||
|
ArrayList<RowRaw> listRowRaw = new ArrayList<RowRaw>();
|
||||||
List<DataRow> dataRows = grid.getSelectionModel()
|
List<DataRow> dataRows = grid.getSelectionModel()
|
||||||
.getSelectedItems();
|
.getSelectedItems();
|
||||||
List<Row> rows = new ArrayList<Row>();
|
List<Row> rows = new ArrayList<Row>();
|
||||||
|
@ -299,14 +299,12 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RowRaw r = null;
|
|
||||||
|
|
||||||
if (rows.size() > 0) {
|
for(Row row:rows) {
|
||||||
HashMap<String, String> map = new HashMap<String, String>();
|
HashMap<String, String> map = new HashMap<String, String>();
|
||||||
ColumnModel<DataRow> columnModel = grid.getColumnModel();
|
ColumnModel<DataRow> columnModel = grid.getColumnModel();
|
||||||
List<ColumnConfig<DataRow, ?>> columns = columnModel
|
List<ColumnConfig<DataRow, ?>> columns = columnModel
|
||||||
.getColumns();
|
.getColumns();
|
||||||
Row rowFirst = rows.get(0);
|
|
||||||
DataRowColumnConfig<?> columnDataRow = null;
|
DataRowColumnConfig<?> columnDataRow = null;
|
||||||
String rowId = null;
|
String rowId = null;
|
||||||
for (ColumnConfig<DataRow, ?> col : columns) {
|
for (ColumnConfig<DataRow, ?> col : columns) {
|
||||||
|
@ -315,10 +313,10 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
if (colDef != null) {
|
if (colDef != null) {
|
||||||
String value;
|
String value;
|
||||||
if (colDef.getColumnDataType().compareTo("Date") == 0) {
|
if (colDef.getColumnDataType().compareTo("Date") == 0) {
|
||||||
value = rowFirst.getFieldAsDate(colDef
|
value = row.getFieldAsDate(colDef
|
||||||
.getColumnLocalId());
|
.getColumnLocalId());
|
||||||
} else {
|
} else {
|
||||||
value = rowFirst.getFieldAsText(colDef
|
value = row.getFieldAsText(colDef
|
||||||
.getColumnLocalId());
|
.getColumnLocalId());
|
||||||
}
|
}
|
||||||
map.put(colDef.getColumnLocalId(), value);
|
map.put(colDef.getColumnLocalId(), value);
|
||||||
|
@ -330,11 +328,12 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rowId != null && !rowId.isEmpty() && map.size() > 0) {
|
if (rowId != null && !rowId.isEmpty() && map.size() > 0) {
|
||||||
r = new RowRaw(rowId, map);
|
RowRaw rr = new RowRaw(rowId, map);
|
||||||
|
listRowRaw.add(rr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return r;
|
return listRowRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -12,19 +12,9 @@ import com.sencha.gxt.widget.core.client.grid.LiveGridView;
|
||||||
*/
|
*/
|
||||||
public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
||||||
|
|
||||||
//private boolean isLoading;
|
|
||||||
//private boolean isMasked;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private int viewIndexReload = -1;
|
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
|
@Override
|
||||||
public void refresh(boolean headerToo) {
|
public void refresh(boolean headerToo) {
|
||||||
|
@ -49,191 +39,4 @@ public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
int newIndex = (int) Math.ceil((double) liveScroller.getScrollTop()
|
|
||||||
/ getRowHeight());
|
|
||||||
|
|
||||||
|
|
||||||
Log.debug("HandleComponentEvent: totalCount:" + totalCount
|
|
||||||
+ ", scrollHeight:" + liveScroller.getScrollHeight()
|
|
||||||
+ ", scrollTop:" + liveScroller.getScrollTop()
|
|
||||||
+ ", rowHeight:" + getRowHeight() + ", newIndex:"
|
|
||||||
+ newIndex);
|
|
||||||
|
|
||||||
updateRows(newIndex, 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;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue