Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Grid SelectionModels as extensions (#18624)
This patch removes all selection related variables and API from several core parts of Grid. Change-Id: Idb7aa48fda69ded1ef58a69c1f7dbc78b7f52a54
- Loading branch information
Teemu Suo-Anttila
committed
Sep 1, 2015
1 parent
9899aa2
commit 53a4b2c
Showing
21 changed files
with
1,135 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
client/src/com/vaadin/client/connectors/AbstractSelectionModelConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,82 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.client.connectors; | |||
|
|||
import java.util.Collection; | |||
|
|||
import com.vaadin.client.data.DataSource.RowHandle; | |||
import com.vaadin.client.extensions.AbstractExtensionConnector; | |||
import com.vaadin.client.widget.grid.selection.SelectionModel; | |||
import com.vaadin.client.widgets.Grid; | |||
import com.vaadin.shared.ui.grid.GridState; | |||
|
|||
import elemental.json.JsonObject; | |||
|
|||
/** | |||
* Base class for all selection model connectors. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public abstract class AbstractSelectionModelConnector<T extends SelectionModel<JsonObject>> | |||
extends AbstractExtensionConnector { | |||
|
|||
@Override | |||
public GridConnector getParent() { | |||
return (GridConnector) super.getParent(); | |||
} | |||
|
|||
protected Grid<JsonObject> getGrid() { | |||
return getParent().getWidget(); | |||
} | |||
|
|||
protected RowHandle<JsonObject> getRowHandle(JsonObject row) { | |||
return getGrid().getDataSource().getHandle(row); | |||
} | |||
|
|||
protected String getRowKey(JsonObject row) { | |||
return row != null ? getParent().getRowKey(row) : null; | |||
} | |||
|
|||
protected abstract T createSelectionModel(); | |||
|
|||
public abstract static class AbstractSelectionModel implements | |||
SelectionModel<JsonObject> { | |||
|
|||
@Override | |||
public boolean isSelected(JsonObject row) { | |||
return row.hasKey(GridState.JSONKEY_SELECTED); | |||
} | |||
|
|||
@Override | |||
public void setGrid(Grid<JsonObject> grid) { | |||
// NO-OP | |||
} | |||
|
|||
@Override | |||
public void reset() { | |||
// Should not need any actions. | |||
} | |||
|
|||
@Override | |||
public Collection<JsonObject> getSelectedRows() { | |||
throw new UnsupportedOperationException( | |||
"This client-side selection model " | |||
+ getClass().getSimpleName() | |||
+ " does not know selected rows."); | |||
} | |||
} | |||
} |
Oops, something went wrong.