Minor update
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@102157 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
45bebc35f6
commit
a65aa9ac9e
|
@ -16,6 +16,7 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.grid.model.RowRaw;
|
|||
import org.gcube.portlets.user.tdwx.client.config.ExtendedLiveGridView;
|
||||
import org.gcube.portlets.user.tdwx.client.config.GridAndCellSelectionModel;
|
||||
import org.gcube.portlets.user.tdwx.client.config.Row;
|
||||
import org.gcube.portlets.user.tdwx.client.config.TDXLiveToolItem;
|
||||
import org.gcube.portlets.user.tdwx.client.config.TableViewConfig;
|
||||
import org.gcube.portlets.user.tdwx.client.config.TabularDataGridViewConfig;
|
||||
import org.gcube.portlets.user.tdwx.client.event.CloseTableEvent;
|
||||
|
@ -76,7 +77,6 @@ import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent.HeaderMouseD
|
|||
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
|
||||
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
|
||||
import com.sencha.gxt.widget.core.client.grid.Grid;
|
||||
import com.sencha.gxt.widget.core.client.grid.LiveToolItem;
|
||||
import com.sencha.gxt.widget.core.client.grid.filters.Filter;
|
||||
import com.sencha.gxt.widget.core.client.menu.Item;
|
||||
import com.sencha.gxt.widget.core.client.menu.Menu;
|
||||
|
@ -800,7 +800,8 @@ 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");
|
||||
|
||||
|
|
|
@ -94,7 +94,6 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,7 +211,6 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
|
||||
mouseDown = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public CellSelection<M> getCellSelected() {
|
||||
|
@ -223,4 +221,127 @@ public class GridAndCellSelectionModel<M> extends GridSelectionModel<M> {
|
|||
this.cellSelected = cellSelected;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
protected void doDeselect(List<M> models, boolean suppressEvent) {
|
||||
if (locked)
|
||||
return;
|
||||
boolean change = false;
|
||||
for (M m : models) {
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
selected.add(model);
|
||||
lastSelected = model;
|
||||
onSelectChange(model, true);
|
||||
setLastFocused(lastSelected);
|
||||
|
||||
if (!suppressEvent) {
|
||||
SelectionEvent.fire(this, model);
|
||||
}
|
||||
|
||||
if (change && !suppressEvent) {
|
||||
fireSelectionChange();
|
||||
}
|
||||
}
|
||||
**/
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.List;
|
|||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.sencha.gxt.messages.client.DefaultMessages;
|
||||
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;
|
||||
|
@ -28,39 +27,58 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
*/
|
||||
public interface TDXLiveToolItemMessages extends LiveToolItemMessages {
|
||||
|
||||
String displayMessage(int selected, int start, int end, int total);
|
||||
String displayMessage(int selected);
|
||||
|
||||
}
|
||||
|
||||
protected static class DefaultTDXLiveToolItemMessages implements TDXLiveToolItemMessages {
|
||||
protected static class DefaultTDXLiveToolItemMessages implements
|
||||
TDXLiveToolItemMessages {
|
||||
|
||||
private int end;
|
||||
private int start;
|
||||
private int total;
|
||||
private int selected;
|
||||
|
||||
public String displayMessage(int selected, int start, int end, int total) {
|
||||
String msg="";
|
||||
if(selected>0){
|
||||
if(selected>1){
|
||||
msg=new String("Selected "+selected+" rows, Displaying "+start+" - "+end+" of "+total);
|
||||
} else {
|
||||
msg=new String("Selected "+selected+" row, Displaying "+start+" - "+end+" of "+total);
|
||||
}
|
||||
} else {
|
||||
msg=new String("Displaying "+start+" - "+end+" of "+total);
|
||||
}
|
||||
return msg;
|
||||
public String displayMessage(int selected) {
|
||||
this.selected = selected;
|
||||
return buildMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayMessage(int start, int end, int total) {
|
||||
return DefaultMessages.getMessages().pagingToolBar_displayMsg(start, end, total);
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.total = total;
|
||||
|
||||
return buildMessage();
|
||||
}
|
||||
|
||||
protected String buildMessage() {
|
||||
String msg = "";
|
||||
if (selected > 0) {
|
||||
if (selected > 1) {
|
||||
msg = new String("Selected " + selected
|
||||
+ " rows, Displaying " + start + " - " + end
|
||||
+ " of " + total);
|
||||
} else {
|
||||
msg = new String("Selected " + selected
|
||||
+ " row, Displaying " + start + " - " + end
|
||||
+ " of " + total);
|
||||
}
|
||||
} else {
|
||||
msg = new String("Displaying " + start + " - " + end + " of "
|
||||
+ total);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private HandlerRegistration handlerRegistration;
|
||||
private TDXLiveToolItemMessages messages;
|
||||
private List<?> lastSelected;
|
||||
|
||||
|
||||
public TDXLiveToolItem(Grid<?> grid) {
|
||||
super(grid);
|
||||
|
||||
|
@ -81,13 +99,13 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
/**
|
||||
* Sets the tool item messages.
|
||||
*
|
||||
* @param messages the messages
|
||||
* @param messages
|
||||
* the messages
|
||||
*/
|
||||
public void setMessages(TDXLiveToolItemMessages messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onUpdate(LiveGridViewUpdateEvent be) {
|
||||
int pageSize = be.getRowCount();
|
||||
|
@ -97,11 +115,10 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
if (i > totalCount) {
|
||||
i = totalCount;
|
||||
}
|
||||
setLabel(getMessages().displayMessage(lastSelected.size(),
|
||||
setLabel(getMessages().displayMessage(
|
||||
totalCount == 0 ? 0 : viewIndex + 1, i, (int) totalCount));
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public void bindGrid(Grid<?> grid) {
|
||||
|
@ -119,20 +136,29 @@ public class TDXLiveToolItem extends LiveToolItem {
|
|||
});
|
||||
|
||||
|
||||
GridSelectionModel<?> selectionModel = (GridSelectionModel<?>)grid.getSelectionModel();
|
||||
|
||||
selectionModel.addSelectionChangedHandler(new SelectionChangedHandler(){
|
||||
GridSelectionModel<?> selectionModel = (GridSelectionModel<?>) grid
|
||||
.getSelectionModel();
|
||||
|
||||
selectionModel
|
||||
.addSelectionChangedHandler(new SelectionChangedHandler() {
|
||||
|
||||
@Override
|
||||
public void onSelectionChanged(
|
||||
SelectionChangedEvent event) {
|
||||
if (event.getSelection() != null) {
|
||||
Log.debug("Selected List Items: "+event.getSelection().size());
|
||||
Log.debug("Selected List Items: "
|
||||
+ event.getSelection().size());
|
||||
lastSelected = event.getSelection();
|
||||
|
||||
setLabel(getMessages().displayMessage(
|
||||
lastSelected.size()));
|
||||
} else {
|
||||
lastSelected = null;
|
||||
setLabel(getMessages().displayMessage(0));
|
||||
}
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue