Ver código fonte

Client now recognizes server-side selection model changes. (#13334)

Change-Id: Ic42e0e96871620fde6b9ce17dd5b487b1d6b8370
tags/7.4.0.beta1
Henrik Paul 10 anos atrás
pai
commit
1f94f03f56

+ 17
- 0
client/src/com/vaadin/client/ui/grid/GridConnector.java Ver arquivo

@@ -25,10 +25,12 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.annotations.OnStateChange;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.data.RpcDataSourceConnector.RpcDataSource;
import com.vaadin.client.ui.AbstractComponentConnector;
@@ -43,6 +45,7 @@ import com.vaadin.shared.ui.grid.GridClientRpc;
import com.vaadin.shared.ui.grid.GridColumnState;
import com.vaadin.shared.ui.grid.GridServerRpc;
import com.vaadin.shared.ui.grid.GridState;
import com.vaadin.shared.ui.grid.GridState.SharedSelectionMode;
import com.vaadin.shared.ui.grid.ScrollDestination;

/**
@@ -444,4 +447,18 @@ public class GridConnector extends AbstractComponentConnector {
this.dataSource = dataSource;
getWidget().setDataSource(this.dataSource);
}

@OnStateChange("selectionMode")
private void onSelectionModeChange() {
SharedSelectionMode mode = getState().selectionMode;
if (mode == null) {
getLogger().warning("ignored mode change");
return;
}
getLogger().warning(mode.toString());
}

private Logger getLogger() {
return Logger.getLogger(getClass().getName());
}
}

+ 13
- 0
server/src/com/vaadin/ui/components/grid/Grid.java Ver arquivo

@@ -44,6 +44,7 @@ import com.vaadin.shared.ui.grid.GridClientRpc;
import com.vaadin.shared.ui.grid.GridColumnState;
import com.vaadin.shared.ui.grid.GridServerRpc;
import com.vaadin.shared.ui.grid.GridState;
import com.vaadin.shared.ui.grid.GridState.SharedSelectionMode;
import com.vaadin.shared.ui.grid.HeightMode;
import com.vaadin.shared.ui.grid.ScrollDestination;
import com.vaadin.ui.AbstractComponent;
@@ -830,6 +831,18 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier {
this.selectionModel = selectionModel;
this.selectionModel.setGrid(this);
this.selectionModel.reset();

if (selectionModel.getClass().equals(SingleSelectionModel.class)) {
getState().selectionMode = SharedSelectionMode.SINGLE;
} else if (selectionModel.getClass().equals(
MultiSelectionModel.class)) {
getState().selectionMode = SharedSelectionMode.MULTI;
} else if (selectionModel.getClass().equals(NoSelectionModel.class)) {
getState().selectionMode = SharedSelectionMode.NONE;
} else {
throw new UnsupportedOperationException("Grid currently "
+ "supports only its own bundled selection models");
}
}
}


+ 37
- 0
shared/src/com/vaadin/shared/ui/grid/GridState.java Ver arquivo

@@ -30,6 +30,42 @@ import com.vaadin.shared.annotations.DelegateToWidget;
*/
public class GridState extends AbstractComponentState {

/**
* A description of which of the three bundled SelectionModels is currently
* in use.
* <p>
* Used as a data transfer object instead of the client/server ones, because
* they don't know about each others classes.
*
* @see com.vaadin.ui.components.grid.Grid.SelectionMode
* @see com.vaadin.client.ui.grid.Grid.SelectionMode
*/
public enum SharedSelectionMode {
/**
* Representation of a single selection mode
*
* @see com.vaadin.ui.components.grid.Grid.SelectionMode#SINGLE
* @see com.vaadin.client.ui.grid.Grid.SelectionMode#SINGLE
*/
SINGLE,

/**
* Representation of a multiselection mode
*
* @see com.vaadin.ui.components.grid.Grid.SelectionMode#MULTI
* @see com.vaadin.client.ui.grid.Grid.SelectionMode#MULTI
*/
MULTI,

/**
* Representation of a no-selection mode
*
* @see com.vaadin.ui.components.grid.Grid.SelectionMode#NONE
* @see com.vaadin.client.ui.grid.Grid.SelectionMode#NONE
*/
NONE;
}

/**
* The default value for height-by-rows for both GWT widgets
* {@link com.vaadin.ui.components.grid Grid} and
@@ -95,4 +131,5 @@ public class GridState extends AbstractComponentState {
// instantiated just to avoid NPEs
public List<String> selectedKeys = new ArrayList<String>();

public SharedSelectionMode selectionMode;
}

+ 14
- 0
uitest/src/com/vaadin/tests/components/grid/GridBasicFeatures.java Ver arquivo

@@ -31,6 +31,7 @@ import com.vaadin.tests.components.AbstractComponentTest;
import com.vaadin.ui.components.grid.ColumnGroup;
import com.vaadin.ui.components.grid.ColumnGroupRow;
import com.vaadin.ui.components.grid.Grid;
import com.vaadin.ui.components.grid.Grid.SelectionMode;
import com.vaadin.ui.components.grid.GridColumn;
import com.vaadin.ui.components.grid.renderers.DateRenderer;
import com.vaadin.ui.components.grid.renderers.HtmlRenderer;
@@ -159,6 +160,19 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {

}
}, primaryStyleNames.get("v-grid"));

LinkedHashMap<String, SelectionMode> selectionModes = new LinkedHashMap<String, Grid.SelectionMode>();
selectionModes.put("single", SelectionMode.SINGLE);
selectionModes.put("multi", SelectionMode.MULTI);
selectionModes.put("none", SelectionMode.NONE);
createSelectAction("Selection mode", "State", selectionModes, "multi",
new Command<Grid, Grid.SelectionMode>() {
@Override
public void execute(Grid grid, SelectionMode selectionMode,
Object data) {
grid.setSelectionMode(selectionMode);
}
});
}

protected void createHeaderActions() {

Carregando…
Cancelar
Salvar