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 boolean errorNotColored = false;
|
||||||
|
|
||||||
|
private ColumnModel<DataRow> columnModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param eventBus
|
* @param eventBus
|
||||||
*/
|
*/
|
||||||
|
@ -690,8 +692,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
// LiveRowNumberer<DataRow>(identity);
|
// LiveRowNumberer<DataRow>(identity);
|
||||||
// columnsConfig.add(numberer);
|
// columnsConfig.add(numberer);
|
||||||
|
|
||||||
ColumnModel<DataRow> columnModel = new ColumnModel<DataRow>(
|
columnModel = new ColumnModel<DataRow>(columnsConfig);
|
||||||
columnsConfig);
|
|
||||||
|
|
||||||
columnModel = checkOnlyColumn(columnModel);
|
columnModel = checkOnlyColumn(columnModel);
|
||||||
columnModel
|
columnModel
|
||||||
|
@ -706,11 +707,12 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
DataRowColumnConfig<?> columnDataRow = (DataRowColumnConfig<?>) col;
|
DataRowColumnConfig<?> columnDataRow = (DataRowColumnConfig<?>) col;
|
||||||
ColumnDefinition colDef = columnDataRow.getDefinition();
|
ColumnDefinition colDef = columnDataRow.getDefinition();
|
||||||
|
|
||||||
Log.debug("Column Reordering", "Index: "
|
Log.debug("Column Reordering", "Index: " + columnIndex
|
||||||
+ columnIndex + " Label: " + colDef.getLabel()
|
+ " Label: " + colDef.getLabel()
|
||||||
+ " Position: " + colDef.getPosition()
|
+ " Position: " + colDef.getPosition()
|
||||||
+ " ColumnId: " + colDef.getColumnLocalId());
|
+ " ColumnId: " + colDef.getColumnLocalId());
|
||||||
ColumnsReorderingConfig columnsReorderingConfig = new ColumnsReorderingConfig(columnIndex, colDef);
|
ColumnsReorderingConfig columnsReorderingConfig = new ColumnsReorderingConfig(
|
||||||
|
columnIndex, colDef);
|
||||||
ColumnsReorderingEvent columnsReorderingEvent = new ColumnsReorderingEvent(
|
ColumnsReorderingEvent columnsReorderingEvent = new ColumnsReorderingEvent(
|
||||||
columnsReorderingConfig);
|
columnsReorderingConfig);
|
||||||
eventBus.fireEvent(columnsReorderingEvent);
|
eventBus.fireEvent(columnsReorderingEvent);
|
||||||
|
@ -800,7 +802,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
|
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
|
||||||
|
|
||||||
toolBar = new ToolBar();
|
toolBar = new ToolBar();
|
||||||
//toolBar.add(new LiveToolItem(grid));
|
// toolBar.add(new LiveToolItem(grid));
|
||||||
toolBar.add(new TDXLiveToolItem(grid));
|
toolBar.add(new TDXLiveToolItem(grid));
|
||||||
toolBar.addStyleName(ThemeStyles.get().style().borderTop());
|
toolBar.addStyleName(ThemeStyles.get().style().borderTop());
|
||||||
toolBar.getElement().getStyle().setProperty("borderBottom", "none");
|
toolBar.getElement().getStyle().setProperty("borderBottom", "none");
|
||||||
|
|
|
@ -12,7 +12,8 @@ import com.sencha.gxt.widget.core.client.grid.LiveGridView;
|
||||||
*/
|
*/
|
||||||
public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
||||||
// TODO bug in gxt3 3.0.0 fixed in future
|
// TODO bug in gxt3 3.0.0 fixed in future
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh(boolean headerToo) {
|
public void refresh(boolean headerToo) {
|
||||||
preventScrollToTopOnRefresh = true;
|
preventScrollToTopOnRefresh = true;
|
||||||
|
@ -34,11 +35,11 @@ public class ExtendedLiveGridView<M> extends LiveGridView<M> {
|
||||||
public void setCacheStore(ListStore<M> list) {
|
public void setCacheStore(ListStore<M> list) {
|
||||||
cacheStore = list;
|
cacheStore = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Scroll key fixed in 3.1.1
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,10 +1,19 @@
|
||||||
package org.gcube.portlets.user.tdwx.client.config;
|
package org.gcube.portlets.user.tdwx.client.config;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
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.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.google.gwt.user.client.Event;
|
||||||
import com.sencha.gxt.core.client.Style.SelectionMode;
|
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.RowClickEvent;
|
||||||
import com.sencha.gxt.widget.core.client.event.RowMouseDownEvent;
|
import com.sencha.gxt.widget.core.client.event.RowMouseDownEvent;
|
||||||
import com.sencha.gxt.widget.core.client.event.XEvent;
|
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> {
|
public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
||||||
|
|
||||||
protected CellSelection<M> cellSelected;
|
private CellSelection<M> cellSelected;
|
||||||
private boolean focusCellCalled;
|
private boolean focusCellCalled;
|
||||||
private int indexOnSelectNoShift;
|
private int indexOnSelectNoShift;
|
||||||
|
private List<M> totalSelected = new ArrayList<M>();
|
||||||
|
|
||||||
|
|
||||||
public GridAndCellSelectionModel() {
|
public GridAndCellSelectionModel() {
|
||||||
super();
|
super();
|
||||||
|
@ -221,13 +232,28 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
||||||
this.cellSelected = cellSelected;
|
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
|
@Override
|
||||||
protected void doDeselect(List<M> models, boolean suppressEvent) {
|
protected void doDeselect(List<M> models, boolean suppressEvent) {
|
||||||
if (locked)
|
if (locked)
|
||||||
return;
|
return;
|
||||||
boolean change = false;
|
boolean change = false;
|
||||||
for (M m : models) {
|
for (M m : models) {
|
||||||
|
totalSelected.remove(m);
|
||||||
if (selected.remove(m)) {
|
if (selected.remove(m)) {
|
||||||
if (lastSelected == m) {
|
if (lastSelected == m) {
|
||||||
lastSelected = selected.size() > 0 ? selected.get(selected
|
lastSelected = selected.size() > 0 ? selected.get(selected
|
||||||
|
@ -265,6 +291,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
||||||
change = true;
|
change = true;
|
||||||
lastSelected = m;
|
lastSelected = m;
|
||||||
|
|
||||||
|
totalSelected.add(m);
|
||||||
selected.add(m);
|
selected.add(m);
|
||||||
setLastFocused(lastSelected);
|
setLastFocused(lastSelected);
|
||||||
|
|
||||||
|
@ -280,7 +307,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
||||||
fireSelectionChange();
|
fireSelectionChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doSelect(List<M> models, boolean keepExisting,
|
protected void doSelect(List<M> models, boolean keepExisting,
|
||||||
boolean suppressEvent) {
|
boolean suppressEvent) {
|
||||||
|
@ -295,7 +322,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
||||||
doMultiSelect(models, keepExisting, suppressEvent);
|
doMultiSelect(models, keepExisting, suppressEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doSingleSelect(M model, boolean suppressEvent) {
|
protected void doSingleSelect(M model, boolean suppressEvent) {
|
||||||
if (locked)
|
if (locked)
|
||||||
|
@ -330,6 +357,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
||||||
if (selected.size() == 0) {
|
if (selected.size() == 0) {
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
|
totalSelected.add(model);
|
||||||
selected.add(model);
|
selected.add(model);
|
||||||
lastSelected = model;
|
lastSelected = model;
|
||||||
onSelectChange(model, true);
|
onSelectChange(model, true);
|
||||||
|
@ -343,5 +371,62 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
||||||
fireSelectionChange();
|
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 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.allen_sauer.gwt.log.client.Log;
|
||||||
import com.google.gwt.event.shared.HandlerRegistration;
|
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;
|
||||||
import com.sencha.gxt.widget.core.client.event.LiveGridViewUpdateEvent.LiveGridViewUpdateHandler;
|
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.Grid;
|
||||||
import com.sencha.gxt.widget.core.client.grid.GridSelectionModel;
|
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.grid.LiveToolItem;
|
||||||
import com.sencha.gxt.widget.core.client.selection.SelectionChangedEvent;
|
import com.sencha.gxt.widget.core.client.selection.SelectionChangedEvent;
|
||||||
import com.sencha.gxt.widget.core.client.selection.SelectionChangedEvent.SelectionChangedHandler;
|
import com.sencha.gxt.widget.core.client.selection.SelectionChangedEvent.SelectionChangedHandler;
|
||||||
|
@ -77,7 +79,6 @@ public class TDXLiveToolItem extends LiveToolItem {
|
||||||
private HandlerRegistration handlerRegistration;
|
private HandlerRegistration handlerRegistration;
|
||||||
private TDXLiveToolItemMessages messages;
|
private TDXLiveToolItemMessages messages;
|
||||||
private List<?> lastSelected;
|
private List<?> lastSelected;
|
||||||
|
|
||||||
|
|
||||||
public TDXLiveToolItem(Grid<?> grid) {
|
public TDXLiveToolItem(Grid<?> grid) {
|
||||||
super(grid);
|
super(grid);
|
||||||
|
@ -127,16 +128,24 @@ public class TDXLiveToolItem extends LiveToolItem {
|
||||||
handlerRegistration = null;
|
handlerRegistration = null;
|
||||||
}
|
}
|
||||||
if (grid != 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() {
|
view.addLiveGridViewUpdateHandler(new LiveGridViewUpdateHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(LiveGridViewUpdateEvent event) {
|
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);
|
TDXLiveToolItem.this.onUpdate(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GridSelectionModel<?> selectionModel = (GridSelectionModel<?>) grid
|
GridSelectionModel<?> selectionModel = (GridSelectionModel<?>) grid
|
||||||
.getSelectionModel();
|
.getSelectionModel();
|
||||||
|
|
||||||
|
@ -146,11 +155,16 @@ public class TDXLiveToolItem extends LiveToolItem {
|
||||||
@Override
|
@Override
|
||||||
public void onSelectionChanged(
|
public void onSelectionChanged(
|
||||||
SelectionChangedEvent event) {
|
SelectionChangedEvent event) {
|
||||||
|
|
||||||
if (event.getSelection() != null) {
|
if (event.getSelection() != null) {
|
||||||
Log.debug("Selected List Items: "
|
Log.debug("Selected List Items: "
|
||||||
+ event.getSelection().size());
|
+ event.getSelection().size());
|
||||||
|
for (DataRow dataRow : (List<DataRow>) event.getSelection()) {
|
||||||
|
//Log.debug("Item:" + modelKeyProvider.getKey(dataRow));
|
||||||
|
}
|
||||||
|
|
||||||
lastSelected = event.getSelection();
|
lastSelected = event.getSelection();
|
||||||
|
|
||||||
setLabel(getMessages().displayMessage(
|
setLabel(getMessages().displayMessage(
|
||||||
lastSelected.size()));
|
lastSelected.size()));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue