Updated Selection Model
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@102169 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a65aa9ac9e
commit
cd49661d10
|
@ -132,6 +132,8 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
|
||||
private boolean errorNotColored = false;
|
||||
|
||||
private ColumnModel<DataRow> columnModel;
|
||||
|
||||
/**
|
||||
* @param eventBus
|
||||
*/
|
||||
|
@ -690,8 +692,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
// LiveRowNumberer<DataRow>(identity);
|
||||
// columnsConfig.add(numberer);
|
||||
|
||||
ColumnModel<DataRow> columnModel = new ColumnModel<DataRow>(
|
||||
columnsConfig);
|
||||
columnModel = new ColumnModel<DataRow>(columnsConfig);
|
||||
|
||||
columnModel = checkOnlyColumn(columnModel);
|
||||
columnModel
|
||||
|
@ -706,11 +707,12 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
DataRowColumnConfig<?> columnDataRow = (DataRowColumnConfig<?>) col;
|
||||
ColumnDefinition colDef = columnDataRow.getDefinition();
|
||||
|
||||
Log.debug("Column Reordering", "Index: "
|
||||
+ columnIndex + " Label: " + colDef.getLabel()
|
||||
Log.debug("Column Reordering", "Index: " + columnIndex
|
||||
+ " Label: " + colDef.getLabel()
|
||||
+ " Position: " + colDef.getPosition()
|
||||
+ " ColumnId: " + colDef.getColumnLocalId());
|
||||
ColumnsReorderingConfig columnsReorderingConfig = new ColumnsReorderingConfig(columnIndex, colDef);
|
||||
ColumnsReorderingConfig columnsReorderingConfig = new ColumnsReorderingConfig(
|
||||
columnIndex, colDef);
|
||||
ColumnsReorderingEvent columnsReorderingEvent = new ColumnsReorderingEvent(
|
||||
columnsReorderingConfig);
|
||||
eventBus.fireEvent(columnsReorderingEvent);
|
||||
|
@ -800,7 +802,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
|
||||
|
||||
toolBar = new ToolBar();
|
||||
//toolBar.add(new LiveToolItem(grid));
|
||||
// toolBar.add(new LiveToolItem(grid));
|
||||
toolBar.add(new TDXLiveToolItem(grid));
|
||||
toolBar.addStyleName(ThemeStyles.get().style().borderTop());
|
||||
toolBar.getElement().getStyle().setProperty("borderBottom", "none");
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.sencha.gxt.widget.core.client.grid.LiveGridView;
|
|||
public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
||||
// TODO bug in gxt3 3.0.0 fixed in future
|
||||
|
||||
|
||||
@Override
|
||||
public void refresh(boolean headerToo) {
|
||||
preventScrollToTopOnRefresh = true;
|
||||
|
@ -35,10 +36,10 @@ public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
|||
cacheStore = list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scroll key fixed in 3.1.1
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,10 +1,19 @@
|
|||
package org.gcube.portlets.user.tdwx.client.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.event.logical.shared.BeforeSelectionEvent;
|
||||
import com.google.gwt.event.logical.shared.SelectionEvent;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.sencha.gxt.core.client.Style.SelectionMode;
|
||||
import com.sencha.gxt.data.shared.ListStore;
|
||||
import com.sencha.gxt.data.shared.ModelKeyProvider;
|
||||
import com.sencha.gxt.data.shared.TreeStore;
|
||||
import com.sencha.gxt.data.shared.event.StoreClearEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.RowClickEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.RowMouseDownEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.XEvent;
|
||||
|
@ -22,9 +31,11 @@ import com.sencha.gxt.widget.core.client.selection.CellSelection;
|
|||
*/
|
||||
public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
||||
|
||||
protected CellSelection<M> cellSelected;
|
||||
private CellSelection<M> cellSelected;
|
||||
private boolean focusCellCalled;
|
||||
private int indexOnSelectNoShift;
|
||||
private List<M> totalSelected = new ArrayList<M>();
|
||||
|
||||
|
||||
public GridAndCellSelectionModel() {
|
||||
super();
|
||||
|
@ -221,13 +232,28 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
this.cellSelected = cellSelected;
|
||||
}
|
||||
|
||||
/*
|
||||
/*************************/
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
Log.debug("Selection Model Called Refresh()");
|
||||
selected.clear();
|
||||
selected.addAll(totalSelected);
|
||||
|
||||
|
||||
if (!selected.isEmpty()) {
|
||||
setLastFocused(selected.get(selected.size() - 1));
|
||||
doSelect(selected, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDeselect(List<M> models, boolean suppressEvent) {
|
||||
if (locked)
|
||||
return;
|
||||
boolean change = false;
|
||||
for (M m : models) {
|
||||
totalSelected.remove(m);
|
||||
if (selected.remove(m)) {
|
||||
if (lastSelected == m) {
|
||||
lastSelected = selected.size() > 0 ? selected.get(selected
|
||||
|
@ -265,6 +291,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
change = true;
|
||||
lastSelected = m;
|
||||
|
||||
totalSelected.add(m);
|
||||
selected.add(m);
|
||||
setLastFocused(lastSelected);
|
||||
|
||||
|
@ -330,6 +357,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
if (selected.size() == 0) {
|
||||
change = true;
|
||||
}
|
||||
totalSelected.add(model);
|
||||
selected.add(model);
|
||||
lastSelected = model;
|
||||
onSelectChange(model, true);
|
||||
|
@ -343,5 +371,62 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
fireSelectionChange();
|
||||
}
|
||||
}
|
||||
**/
|
||||
|
||||
@Override
|
||||
protected void onClear(StoreClearEvent<M> event) {
|
||||
Log.debug("Selection Model Called OnClear()");
|
||||
/*int oldSize = selected.size();
|
||||
selected.clear();
|
||||
totalSelected.clear();
|
||||
lastSelected = null;
|
||||
setLastFocused(null);
|
||||
if (oldSize > 0)
|
||||
fireSelectionChange();*/
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRemove(M model) {
|
||||
ModelKeyProvider<? super M> mod = grid.getStore().getKeyProvider();
|
||||
|
||||
Log.debug("Selection Model Called OnRemove(): "+mod.getKey(model));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAdd(List<? extends M> models) {
|
||||
ModelKeyProvider<? super M> mod = grid.getStore().getKeyProvider();
|
||||
for(M m:models){
|
||||
Log.debug("Selection Model Called OnAdd(): "+mod.getKey(m));
|
||||
}
|
||||
super.onAdd(models);
|
||||
|
||||
selected.clear();
|
||||
selected.addAll(totalSelected);
|
||||
|
||||
|
||||
for(M item: totalSelected){
|
||||
Log.debug("Selected: "+mod.getKey(item));
|
||||
}
|
||||
|
||||
|
||||
ExtendedLiveGridView<M> gridView = (ExtendedLiveGridView<M>) grid
|
||||
.getView();
|
||||
boolean notChanged;
|
||||
for (M model : gridView.getCacheStore().getAll()) {
|
||||
notChanged=true;
|
||||
for (M item : totalSelected) {
|
||||
if (mod.getKey(model).compareTo(mod.getKey(item)) == 0) {
|
||||
onSelectChange(model, true);
|
||||
notChanged=false;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if(notChanged){
|
||||
onSelectChange(model, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,13 +2,15 @@ package org.gcube.portlets.user.tdwx.client.config;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.tdwx.client.model.grid.DataRowModelKeyProvider;
|
||||
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.sencha.gxt.widget.core.client.event.LiveGridViewUpdateEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.LiveGridViewUpdateEvent.LiveGridViewUpdateHandler;
|
||||
import com.sencha.gxt.widget.core.client.grid.Grid;
|
||||
import com.sencha.gxt.widget.core.client.grid.GridSelectionModel;
|
||||
import com.sencha.gxt.widget.core.client.grid.LiveGridView;
|
||||
import com.sencha.gxt.widget.core.client.grid.LiveToolItem;
|
||||
import com.sencha.gxt.widget.core.client.selection.SelectionChangedEvent;
|
||||
import com.sencha.gxt.widget.core.client.selection.SelectionChangedEvent.SelectionChangedHandler;
|
||||
|
@ -78,7 +80,6 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
private TDXLiveToolItemMessages messages;
|
||||
private List<?> lastSelected;
|
||||
|
||||
|
||||
public TDXLiveToolItem(Grid<?> grid) {
|
||||
super(grid);
|
||||
|
||||
|
@ -127,16 +128,24 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
handlerRegistration = null;
|
||||
}
|
||||
if (grid != null) {
|
||||
LiveGridView<?> view = (LiveGridView<?>) grid.getView();
|
||||
ExtendedLiveGridView<?> view = (ExtendedLiveGridView<?>) grid
|
||||
.getView();
|
||||
final DataRowModelKeyProvider modelKeyProvider = (DataRowModelKeyProvider)grid.getStore().getKeyProvider();
|
||||
|
||||
view.addLiveGridViewUpdateHandler(new LiveGridViewUpdateHandler() {
|
||||
@Override
|
||||
public void onUpdate(LiveGridViewUpdateEvent event) {
|
||||
ExtendedLiveGridView<?> source = (ExtendedLiveGridView<?>) event
|
||||
.getSource();
|
||||
Log.debug("CacheStore List Items: " + source.getCacheSize());
|
||||
for (DataRow dataRow : (List<DataRow>) source.getCacheStore()
|
||||
.getAll()) {
|
||||
//Log.debug("Item:" + modelKeyProvider.getKey(dataRow));
|
||||
}
|
||||
TDXLiveToolItem.this.onUpdate(event);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
GridSelectionModel<?> selectionModel = (GridSelectionModel<?>) grid
|
||||
.getSelectionModel();
|
||||
|
||||
|
@ -146,9 +155,14 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
@Override
|
||||
public void onSelectionChanged(
|
||||
SelectionChangedEvent event) {
|
||||
|
||||
if (event.getSelection() != null) {
|
||||
Log.debug("Selected List Items: "
|
||||
+ event.getSelection().size());
|
||||
for (DataRow dataRow : (List<DataRow>) event.getSelection()) {
|
||||
//Log.debug("Item:" + modelKeyProvider.getKey(dataRow));
|
||||
}
|
||||
|
||||
lastSelected = event.getSelection();
|
||||
|
||||
setLabel(getMessages().displayMessage(
|
||||
|
|
Loading…
Reference in New Issue