From cd49661d1061dcacff60c4107328b2f1d308260e Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 18 Dec 2014 18:17:43 +0000 Subject: [PATCH] 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 --- .../tdwx/client/TabularDataXGridPanel.java | 14 +-- .../client/config/ExtendedLiveGridView.java | 11 ++- .../config/GridAndCellSelectionModel.java | 95 ++++++++++++++++++- .../tdwx/client/config/TDXLiveToolItem.java | 28 ++++-- 4 files changed, 125 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java index 93383c9..544d038 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java @@ -132,6 +132,8 @@ public class TabularDataXGridPanel extends ContentPanel { private boolean errorNotColored = false; + private ColumnModel columnModel; + /** * @param eventBus */ @@ -690,8 +692,7 @@ public class TabularDataXGridPanel extends ContentPanel { // LiveRowNumberer(identity); // columnsConfig.add(numberer); - ColumnModel columnModel = new ColumnModel( - columnsConfig); + columnModel = new ColumnModel(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"); diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/config/ExtendedLiveGridView.java b/src/main/java/org/gcube/portlets/user/tdwx/client/config/ExtendedLiveGridView.java index 63b519e..c902608 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/config/ExtendedLiveGridView.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/config/ExtendedLiveGridView.java @@ -12,7 +12,8 @@ import com.sencha.gxt.widget.core.client.grid.LiveGridView; */ public class ExtendedLiveGridView extends LiveGridView { // TODO bug in gxt3 3.0.0 fixed in future - + + @Override public void refresh(boolean headerToo) { preventScrollToTopOnRefresh = true; @@ -34,11 +35,11 @@ public class ExtendedLiveGridView extends LiveGridView { public void setCacheStore(ListStore list) { cacheStore = list; } + + + - /* - * Scroll key fixed in 3.1.1 - * - */ + } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/config/GridAndCellSelectionModel.java b/src/main/java/org/gcube/portlets/user/tdwx/client/config/GridAndCellSelectionModel.java index 79c1234..c76d221 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/config/GridAndCellSelectionModel.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/config/GridAndCellSelectionModel.java @@ -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 extends GridSelectionModel { - protected CellSelection cellSelected; + private CellSelection cellSelected; private boolean focusCellCalled; private int indexOnSelectNoShift; + private List totalSelected = new ArrayList(); + public GridAndCellSelectionModel() { super(); @@ -221,13 +232,28 @@ public class GridAndCellSelectionModel extends GridSelectionModel { 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 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 extends GridSelectionModel { change = true; lastSelected = m; + totalSelected.add(m); selected.add(m); setLastFocused(lastSelected); @@ -280,7 +307,7 @@ public class GridAndCellSelectionModel extends GridSelectionModel { fireSelectionChange(); } } - + @Override protected void doSelect(List models, boolean keepExisting, boolean suppressEvent) { @@ -295,7 +322,7 @@ public class GridAndCellSelectionModel extends GridSelectionModel { doMultiSelect(models, keepExisting, suppressEvent); } } - + @Override protected void doSingleSelect(M model, boolean suppressEvent) { if (locked) @@ -330,6 +357,7 @@ public class GridAndCellSelectionModel extends GridSelectionModel { if (selected.size() == 0) { change = true; } + totalSelected.add(model); selected.add(model); lastSelected = model; onSelectChange(model, true); @@ -343,5 +371,62 @@ public class GridAndCellSelectionModel extends GridSelectionModel { fireSelectionChange(); } } - **/ + + @Override + protected void onClear(StoreClearEvent 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 mod = grid.getStore().getKeyProvider(); + + Log.debug("Selection Model Called OnRemove(): "+mod.getKey(model)); + } + + @Override + protected void onAdd(List models) { + ModelKeyProvider 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 gridView = (ExtendedLiveGridView) 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); + } + } + + + } + } diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/config/TDXLiveToolItem.java b/src/main/java/org/gcube/portlets/user/tdwx/client/config/TDXLiveToolItem.java index 49d722f..5fd3f0a 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/config/TDXLiveToolItem.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/config/TDXLiveToolItem.java @@ -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; @@ -77,7 +79,6 @@ public class TDXLiveToolItem extends LiveToolItem { private HandlerRegistration handlerRegistration; 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) source.getCacheStore() + .getAll()) { + //Log.debug("Item:" + modelKeyProvider.getKey(dataRow)); + } TDXLiveToolItem.this.onUpdate(event); } }); - - - + GridSelectionModel selectionModel = (GridSelectionModel) grid .getSelectionModel(); @@ -146,11 +155,16 @@ 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) event.getSelection()) { + //Log.debug("Item:" + modelKeyProvider.getKey(dataRow)); + } + lastSelected = event.getSelection(); - + setLabel(getMessages().displayMessage( lastSelected.size())); } else {