Fixed Selection bug

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@102171 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-12-19 09:39:49 +00:00 committed by Giancarlo Panichi
parent cd49661d10
commit 6e961ba094
3 changed files with 12 additions and 173 deletions

View File

@ -721,7 +721,7 @@ public class TabularDataXGridPanel extends ContentPanel {
}); });
if (grid == null) { if (grid == null) {
Log.debug("Setup grid null");
reader = new DataRowPagingReader(tableDefinition); reader = new DataRowPagingReader(tableDefinition);
String path = GWT.getModuleBaseURL() + "tdwxdata"; String path = GWT.getModuleBaseURL() + "tdwxdata";
@ -824,6 +824,7 @@ public class TabularDataXGridPanel extends ContentPanel {
} }
} else { } else {
Log.debug("Setup grid not null");
// TODO we need to manually reset the sort // TODO we need to manually reset the sort
loader.clearSortInfo(); loader.clearSortInfo();
reader.setDefinition(tableDefinition); reader.setDefinition(tableDefinition);

View File

@ -1,18 +1,13 @@
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 java.util.List;
import com.allen_sauer.gwt.log.client.Log; 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.ModelKeyProvider;
import com.sencha.gxt.data.shared.TreeStore;
import com.sencha.gxt.data.shared.event.StoreClearEvent; 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;
@ -34,7 +29,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
private 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>(); //private List<M> totalSelected = new ArrayList<M>();
public GridAndCellSelectionModel() { public GridAndCellSelectionModel() {
@ -237,173 +232,26 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
@Override @Override
public void refresh() { public void refresh() {
Log.debug("Selection Model Called 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
.size() - 1) : null;
}
onSelectChange(m, false);
change = true;
}
}
if (!suppressEvent && change) {
fireSelectionChange();
}
}
@Override
protected void doMultiSelect(List<M> models, boolean keepExisting,
boolean suppressEvent) {
if (locked)
return;
boolean change = false;
if (!keepExisting && selected.size() > 0) {
change = true;
doDeselect(new ArrayList<M>(selected), true);
}
for (M m : models) {
boolean isSelected = isSelected(m);
if (!suppressEvent && !isSelected) {
BeforeSelectionEvent<M> evt = BeforeSelectionEvent
.fire(this, m);
if (evt != null && evt.isCanceled()) {
continue;
}
}
change = true;
lastSelected = m;
totalSelected.add(m);
selected.add(m);
setLastFocused(lastSelected);
if (!isSelected) {
onSelectChange(m, true);
if (!suppressEvent) {
SelectionEvent.fire(this, m);
}
}
}
if (change && !suppressEvent) {
fireSelectionChange();
}
}
@Override
protected void doSelect(List<M> models, boolean keepExisting,
boolean suppressEvent) {
if (locked)
return;
if (selectionMode == SelectionMode.SINGLE) {
M m = models.size() > 0 ? models.get(0) : null;
if (m != null) {
doSingleSelect(m, suppressEvent);
}
} else {
doMultiSelect(models, keepExisting, suppressEvent);
}
}
@Override
protected void doSingleSelect(M model, boolean suppressEvent) {
if (locked)
return;
int index = -1;
if (store instanceof ListStore) {
ListStore<M> ls = (ListStore<M>) store;
index = ls.indexOf(model);
}
if (store instanceof TreeStore) {
TreeStore<M> ls = (TreeStore<M>) store;
index = ls.indexOf(model);
}
if (index == -1 || isSelected(model)) {
return;
} else {
if (!suppressEvent) {
BeforeSelectionEvent<M> evt = BeforeSelectionEvent.fire(this,
model);
if (evt != null && evt.isCanceled()) {
return;
}
}
}
boolean change = false;
if (selected.size() > 0 && !isSelected(model)) {
doDeselect(Collections.singletonList(lastSelected), true);
change = true;
}
if (selected.size() == 0) {
change = true;
}
totalSelected.add(model);
selected.add(model);
lastSelected = model;
onSelectChange(model, true);
setLastFocused(lastSelected);
if (!suppressEvent) {
SelectionEvent.fire(this, model);
}
if (change && !suppressEvent) {
fireSelectionChange();
}
}
@Override @Override
protected void onClear(StoreClearEvent<M> event) { protected void onClear(StoreClearEvent<M> event) {
Log.debug("Selection Model Called OnClear()"); Log.debug("Selection Model Called OnClear()");
/*int oldSize = selected.size();
selected.clear();
totalSelected.clear();
lastSelected = null;
setLastFocused(null);
if (oldSize > 0)
fireSelectionChange();*/
} }
@Override @Override
protected void onRemove(M model) { protected void onRemove(M model) {
ModelKeyProvider<? super M> mod = grid.getStore().getKeyProvider(); Log.debug("Selection Model Called OnRemove(): ");
Log.debug("Selection Model Called OnRemove(): "+mod.getKey(model));
} }
@Override @Override
protected void onAdd(List<? extends M> models) { 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); super.onAdd(models);
selected.clear(); ModelKeyProvider<? super M> mod = grid.getStore().getKeyProvider();
selected.addAll(totalSelected); for(M item: selected){
for(M item: totalSelected){
Log.debug("Selected: "+mod.getKey(item)); Log.debug("Selected: "+mod.getKey(item));
} }
@ -413,7 +261,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
boolean notChanged; boolean notChanged;
for (M model : gridView.getCacheStore().getAll()) { for (M model : gridView.getCacheStore().getAll()) {
notChanged=true; notChanged=true;
for (M item : totalSelected) { for (M item : selected) {
if (mod.getKey(model).compareTo(mod.getKey(item)) == 0) { if (mod.getKey(model).compareTo(mod.getKey(item)) == 0) {
onSelectChange(model, true); onSelectChange(model, true);
notChanged=false; notChanged=false;

View File

@ -2,9 +2,6 @@ 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;
@ -130,7 +127,7 @@ public class TDXLiveToolItem extends LiveToolItem {
if (grid != null) { if (grid != null) {
ExtendedLiveGridView<?> view = (ExtendedLiveGridView<?>) grid ExtendedLiveGridView<?> view = (ExtendedLiveGridView<?>) grid
.getView(); .getView();
final DataRowModelKeyProvider modelKeyProvider = (DataRowModelKeyProvider)grid.getStore().getKeyProvider(); //final DataRowModelKeyProvider modelKeyProvider = (DataRowModelKeyProvider)grid.getStore().getKeyProvider();
view.addLiveGridViewUpdateHandler(new LiveGridViewUpdateHandler() { view.addLiveGridViewUpdateHandler(new LiveGridViewUpdateHandler() {
@Override @Override
@ -138,10 +135,7 @@ public class TDXLiveToolItem extends LiveToolItem {
ExtendedLiveGridView<?> source = (ExtendedLiveGridView<?>) event ExtendedLiveGridView<?> source = (ExtendedLiveGridView<?>) event
.getSource(); .getSource();
Log.debug("CacheStore List Items: " + source.getCacheSize()); 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);
} }
}); });
@ -159,10 +153,6 @@ public class TDXLiveToolItem extends LiveToolItem {
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(