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:
parent
cd49661d10
commit
6e961ba094
|
@ -721,7 +721,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
});
|
||||
|
||||
if (grid == null) {
|
||||
|
||||
Log.debug("Setup grid null");
|
||||
reader = new DataRowPagingReader(tableDefinition);
|
||||
|
||||
String path = GWT.getModuleBaseURL() + "tdwxdata";
|
||||
|
@ -824,6 +824,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
}
|
||||
|
||||
} else {
|
||||
Log.debug("Setup grid not null");
|
||||
// TODO we need to manually reset the sort
|
||||
loader.clearSortInfo();
|
||||
reader.setDefinition(tableDefinition);
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
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;
|
||||
|
@ -34,7 +29,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
private CellSelection<M> cellSelected;
|
||||
private boolean focusCellCalled;
|
||||
private int indexOnSelectNoShift;
|
||||
private List<M> totalSelected = new ArrayList<M>();
|
||||
//private List<M> totalSelected = new ArrayList<M>();
|
||||
|
||||
|
||||
public GridAndCellSelectionModel() {
|
||||
|
@ -237,173 +232,26 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
@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
|
||||
.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
|
||||
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));
|
||||
protected void onRemove(M model) {
|
||||
Log.debug("Selection Model Called OnRemove(): ");
|
||||
}
|
||||
|
||||
@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){
|
||||
|
||||
ModelKeyProvider<? super M> mod = grid.getStore().getKeyProvider();
|
||||
for(M item: selected){
|
||||
Log.debug("Selected: "+mod.getKey(item));
|
||||
}
|
||||
|
||||
|
@ -413,7 +261,7 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
boolean notChanged;
|
||||
for (M model : gridView.getCacheStore().getAll()) {
|
||||
notChanged=true;
|
||||
for (M item : totalSelected) {
|
||||
for (M item : selected) {
|
||||
if (mod.getKey(model).compareTo(mod.getKey(item)) == 0) {
|
||||
onSelectChange(model, true);
|
||||
notChanged=false;
|
||||
|
|
|
@ -2,9 +2,6 @@ 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;
|
||||
|
@ -130,7 +127,7 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
if (grid != null) {
|
||||
ExtendedLiveGridView<?> view = (ExtendedLiveGridView<?>) grid
|
||||
.getView();
|
||||
final DataRowModelKeyProvider modelKeyProvider = (DataRowModelKeyProvider)grid.getStore().getKeyProvider();
|
||||
//final DataRowModelKeyProvider modelKeyProvider = (DataRowModelKeyProvider)grid.getStore().getKeyProvider();
|
||||
|
||||
view.addLiveGridViewUpdateHandler(new LiveGridViewUpdateHandler() {
|
||||
@Override
|
||||
|
@ -138,10 +135,7 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
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);
|
||||
}
|
||||
});
|
||||
|
@ -159,10 +153,6 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
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