diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-05-23 12:54:26 +0300 |
---|---|---|
committer | Aleksi Hietanen <aleksi@vaadin.com> | 2017-05-23 12:54:26 +0300 |
commit | 6b6dc9306a749e24f498507d0eddce10b5c6cbf5 (patch) | |
tree | a4be32a24c55a67d7c6c6682f15397273807ca7a /client | |
parent | e746334d6444bb16c099f31480919b9020a69bc7 (diff) | |
download | vaadin-framework-6b6dc9306a749e24f498507d0eddce10b5c6cbf5.tar.gz vaadin-framework-6b6dc9306a749e24f498507d0eddce10b5c6cbf5.zip |
Add MultiSelection support for Tree Component (#9354)
Diffstat (limited to 'client')
2 files changed, 84 insertions, 1 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/MultiSelectionModelConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/MultiSelectionModelConnector.java index 83008b5a88..92b858cb97 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/MultiSelectionModelConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/MultiSelectionModelConnector.java @@ -125,12 +125,24 @@ public class MultiSelectionModelConnector @Override protected void initSelectionModel() { - getGrid().setSelectionModel(new MultiSelectionModel()); + getGrid().setSelectionModel(createSelectionModel()); // capture current rows so that can show selection update immediately dataAvailable = getGrid().addDataAvailableHandler( event -> availableRows = event.getAvailableRows()); } + /** + * Creates an instance of MultiSelectionModel. Method provided overriding + * features of the selection model without copying all logic. + * + * @since 8.1 + * + * @return selection model instance, not {@code null} + */ + protected MultiSelectionModel createSelectionModel() { + return new MultiSelectionModel(); + } + @Override public void onUnregister() { super.onUnregister(); diff --git a/client/src/main/java/com/vaadin/client/connectors/tree/TreeMultiSelectionModelConnector.java b/client/src/main/java/com/vaadin/client/connectors/tree/TreeMultiSelectionModelConnector.java new file mode 100644 index 0000000000..bcb3a66faa --- /dev/null +++ b/client/src/main/java/com/vaadin/client/connectors/tree/TreeMultiSelectionModelConnector.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2016 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.tree; + +import com.vaadin.client.connectors.grid.MultiSelectionModelConnector; +import com.vaadin.client.renderers.Renderer; +import com.vaadin.client.widget.grid.selection.ClickSelectHandler; +import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.tree.TreeMultiSelectionModelState; +import com.vaadin.ui.Tree.TreeMultiSelectionModel; + +import elemental.json.JsonObject; + +/** + * Connector for the server side multiselection model of the tree component. + * <p> + * Implementation detail: The selection is updated immediately on client side, + * without waiting for the server response. + * + * @author Vaadin Ltd + * @since 8.1 + */ +@Connect(TreeMultiSelectionModel.class) +public class TreeMultiSelectionModelConnector + extends MultiSelectionModelConnector { + + private ClickSelectHandler<JsonObject> clickSelectHandler; + + @Override + protected MultiSelectionModel createSelectionModel() { + return new MultiSelectionModel() { + @Override + public Renderer<Boolean> getRenderer() { + // Prevent selection column. + return null; + } + }; + } + + @Override + public TreeMultiSelectionModelState getState() { + return (TreeMultiSelectionModelState) super.getState(); + } + + @Override + protected void initSelectionModel() { + super.initSelectionModel(); + clickSelectHandler = new ClickSelectHandler<>(getParent().getWidget()); + } + + @Override + public void onUnregister() { + super.onUnregister(); + if (clickSelectHandler != null) { + clickSelectHandler.removeHandler(); + } + } +} |