Client side doesn't use selection model anymore.
Fixes vaadin/framework8-issues#421
Change-Id: If3ecb1c2f3a0024df9bfdfd182eaf8cf8625ac75
import com.google.gwt.event.dom.client.HasAllFocusHandlers;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ui.ConnectorFocusAndBlurHandler;
-import com.vaadin.shared.data.selection.SelectionModel;
/**
* Abstract class for listing widget connectors that contains focusable children
*
* @param <WIDGET>
* widget type which has to allow to register focus/blur handlers
- * @param <SELECTIONMODEL>
- * the client-side selection model type
*/
-public abstract class AbstractFocusableListingConnector<WIDGET extends Widget & HasAllFocusHandlers, SELECTIONMODEL extends SelectionModel<?>>
- extends AbstractListingConnector<SELECTIONMODEL> {
+public abstract class AbstractFocusableListingConnector<WIDGET extends Widget & HasAllFocusHandlers>
+ extends AbstractListingConnector {
private ConnectorFocusAndBlurHandler handler;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.ui.AbstractListing;
import elemental.json.JsonObject;
*
* @author Vaadin Ltd.
*
- * @param <SELECTIONMODEL>
- * the client-side selection model type
- *
* @since 8.0
*/
-public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionModel<?>>
- extends AbstractFieldConnector implements HasDataSource {
+public abstract class AbstractListingConnector extends AbstractFieldConnector
+ implements HasDataSource {
private DataSource<JsonObject> dataSource = null;
- private SELECTIONMODEL selectionModel = null;
-
@Override
public void setDataSource(DataSource<JsonObject> dataSource) {
this.dataSource = dataSource;
return dataSource;
}
- /**
- * Sets the selection model to use. Passing {@code null} disables selection.
- *
- * @param selectionModel
- * the selection model or null to disable
- */
- public void setSelectionModel(SELECTIONMODEL selectionModel) {
- this.selectionModel = selectionModel;
- }
-
- /**
- * Returns the selection model instance used.
- *
- * @return the selection model
- */
- public SELECTIONMODEL getSelectionModel() {
- return selectionModel;
- }
-
/**
* Returns the key of the given data row.
*
import com.vaadin.shared.Range;
import com.vaadin.shared.Registration;
import com.vaadin.shared.data.selection.MultiSelectServerRpc;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.shared.ui.ListingJsonConstants;
import elemental.json.JsonObject;
* @since 8.0
*/
public abstract class AbstractMultiSelectConnector
- extends AbstractListingConnector<SelectionModel.Multi<?>>
- implements HasRequiredIndicator {
+ extends AbstractListingConnector implements HasRequiredIndicator {
/**
* Abstraction layer to help populate different multiselect widgets based on
import com.google.gwt.event.dom.client.HasAllFocusHandlers;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ui.HasRequiredIndicator;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.shared.ui.AbstractSingleSelectState;
/**
* @since 8.0.0
*/
public abstract class AbstractSingleSelectConnector<WIDGET extends Widget & HasAllFocusHandlers>
- extends
- AbstractFocusableListingConnector<WIDGET, SelectionModel.Single<?>>
+ extends AbstractFocusableListingConnector<WIDGET>
implements HasRequiredIndicator {
@Override
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
import com.google.gwt.dom.client.Element;
import com.vaadin.client.connectors.AbstractListingConnector;
import com.vaadin.client.connectors.grid.ColumnConnector.CustomColumn;
import com.vaadin.client.data.DataSource;
+import com.vaadin.client.data.SelectionModel;
import com.vaadin.client.ui.SimpleManagedLayout;
import com.vaadin.client.widget.grid.CellReference;
import com.vaadin.client.widget.grid.EventCellReference;
import com.vaadin.client.widgets.Grid.HeaderRow;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.shared.data.selection.SelectionServerRpc;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.Connect;
* @since 8.0
*/
@Connect(com.vaadin.ui.Grid.class)
-public class GridConnector
- extends AbstractListingConnector<SelectionModel<JsonObject>>
+public class GridConnector extends AbstractListingConnector
implements HasComponentsConnector, SimpleManagedLayout, DeferredWorker {
private class ItemClickHandler
/* Item click events */
getWidget().addBodyClickHandler(itemClickHandler);
getWidget().addBodyDoubleClickHandler(itemClickHandler);
- getWidget().setSelectionModel(new SelectionModel.Single<JsonObject>() {
+ getWidget().setSelectionModel(new SelectionModel<JsonObject>() {
@Override
public void select(JsonObject item) {
}
@Override
- public Optional<JsonObject> getSelectedItem() {
+ public Set<JsonObject> getSelectedItems() {
throw new UnsupportedOperationException(
"Selected item not known on the client side");
}
return item.hasKey(DataCommunicatorConstants.SELECTED)
&& item.getBoolean(DataCommunicatorConstants.SELECTED);
}
+
});
layout();
getWidget().setDataSource(dataSource);
}
- @Override
- public void setSelectionModel(SelectionModel<JsonObject> selectionModel) {
- throw new UnsupportedOperationException(
- "Cannot set a selection model for GridConnector");
- }
-
/**
* Adds a column to the Grid widget. For each column a communication id
* stored for client to server communication.
import com.vaadin.client.connectors.AbstractListingConnector;
import com.vaadin.client.extensions.AbstractExtensionConnector;
import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
import elemental.json.JsonObject;
*
* @author Vaadin Ltd.
*
- * @param <SELECTIONMODEL>
- * the supported client-side selection model
* @since 8.0
*/
-public abstract class AbstractSelectionConnector<SELECTIONMODEL extends SelectionModel<?>>
+public abstract class AbstractSelectionConnector
extends AbstractExtensionConnector {
- private SELECTIONMODEL model = null;
-
@Override
@SuppressWarnings("unchecked")
protected void extend(ServerConnector target) {
"Cannot extend a connector that is not an "
+ AbstractListingConnector.class.getSimpleName());
}
- model = createSelectionModel();
- ((AbstractListingConnector<SELECTIONMODEL>) target)
- .setSelectionModel(model);
}
- /**
- * Creates a selection model object to be used by the Connector.
- *
- * @return created selection model
- */
- protected abstract SELECTIONMODEL createSelectionModel();
-
@Override
@SuppressWarnings("unchecked")
- public AbstractListingConnector<SELECTIONMODEL> getParent() {
- return (AbstractListingConnector<SELECTIONMODEL>) super.getParent();
- }
-
- /**
- * Returns the client-side selection model associated with this connector.
- *
- * @return the selection model in use
- */
- protected SELECTIONMODEL getSelectionModel() {
- return model;
+ public AbstractListingConnector getParent() {
+ return (AbstractListingConnector) super.getParent();
}
/**
--- /dev/null
+/*
+ * 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.data;
+
+import java.util.Set;
+
+/**
+ * Models the selection logic of a {@code Grid} component. Determines how items
+ * can be selected and deselected.
+ *
+ * @author Vaadin Ltd.
+ *
+ * @param <T>
+ * the type of the items to select
+ * @since 8.0
+ */
+public interface SelectionModel<T> {
+
+ /**
+ * Selects the given item. If another item was already selected, that item
+ * is deselected.
+ *
+ * @param item
+ * the item to select, not null
+ */
+ void select(T item);
+
+ /**
+ * Deselects the given item. If the item is not currently selected, does
+ * nothing.
+ *
+ * @param item
+ * the item to deselect, not null
+ */
+ void deselect(T item);
+
+ /**
+ * Returns a set of the currently selected items. It is safe to invoke other
+ * {@code SelectionModel} methods while iterating over the set.
+ *
+ * @return the items in the current selection, not null
+ */
+ Set<T> getSelectedItems();
+
+ /**
+ * Returns whether the given item is currently selected.
+ *
+ * @param item
+ * the item to check, not null
+ * @return {@code true} if the item is selected, {@code false} otherwise
+ */
+ boolean isSelected(T item);
+
+ /**
+ * Deselects all currently selected items.
+ */
+ default void deselectAll() {
+ getSelectedItems().forEach(this::deselect);
+ }
+}
import com.vaadin.shared.Registration;
import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc;
import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.shared.data.selection.SelectionServerRpc;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.combobox.ComboBoxConstants;
import elemental.json.JsonObject;
@Connect(ComboBox.class)
-public class ComboBoxConnector
- extends AbstractListingConnector<SelectionModel.Single<?>>
+public class ComboBoxConnector extends AbstractListingConnector
implements HasRequiredIndicator, HasDataSource, SimpleManagedLayout,
HasErrorIndicator {
import com.vaadin.client.ui.HasRequiredIndicator;
import com.vaadin.client.ui.VCheckBoxGroup;
import com.vaadin.shared.data.selection.MultiSelectServerRpc;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.optiongroup.CheckBoxGroupState;
import com.vaadin.ui.CheckBoxGroup;
// We don't care about the framework-provided selection model at this point
// TODO refactor to extend AbstractMultiSelectConnector, maybe when
// SelectionModel is removed from client side framwork8-issues#421
-public class CheckBoxGroupConnector extends
- AbstractFocusableListingConnector<VCheckBoxGroup, SelectionModel<?>>
+public class CheckBoxGroupConnector
+ extends AbstractFocusableListingConnector<VCheckBoxGroup>
implements HasRequiredIndicator {
@Override
package com.vaadin.client.widget.grid.events;
import com.google.gwt.event.shared.GwtEvent;
-import com.vaadin.shared.data.selection.SelectionModel;
+import com.vaadin.client.data.SelectionModel;
/**
* A select all event, fired by the Grid when it needs all rows in data source
*/
private final static Type<SelectAllHandler<?>> TYPE = new Type<>();;
- private SelectionModel.Multi<T> selectionModel;
+ private SelectionModel selectionModel;
- public SelectAllEvent(SelectionModel.Multi<T> selectionModel) {
+ public SelectAllEvent(SelectionModel selectionModel) {
this.selectionModel = selectionModel;
}
handler.onSelectAll(this);
}
- public SelectionModel.Multi<T> getSelectionModel() {
+ public SelectionModel getSelectionModel() {
return selectionModel;
}
}
package com.vaadin.client.widget.grid.selection;
import com.vaadin.client.renderers.Renderer;
-import com.vaadin.shared.data.selection.SelectionModel;
/**
* Interface for SelectionModels that wants Grid to display a selection column.
* @author Vaadin Ltd
* @since 8.0
*
- * @param <T>
- * selected item type
- *
* @see Renderer
*/
-public interface SelectionModelWithSelectionColumn<T>
- extends SelectionModel<T> {
+public interface SelectionModelWithSelectionColumn {
/**
* Returns a new instance of the Renderer for selection column.
import com.vaadin.client.data.DataChangeHandler;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.data.DataSource.RowHandle;
+import com.vaadin.client.data.SelectionModel;
import com.vaadin.client.renderers.ComplexRenderer;
import com.vaadin.client.renderers.Renderer;
import com.vaadin.client.renderers.WidgetRenderer;
import com.vaadin.client.widgets.Grid.StaticSection.StaticRow;
import com.vaadin.shared.Range;
import com.vaadin.shared.Registration;
-import com.vaadin.shared.data.selection.SelectionModel;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.grid.GridConstants;
import com.vaadin.shared.ui.grid.GridConstants.Section;
* Later on this could be fixed so that it check such handlers
* exist.
*/
- final SelectionModel.Multi<T> model = (Multi<T>) getSelectionModel();
+ final SelectionModel<T> model = getSelectionModel();
if (selectAllCheckBox == null) {
selectAllCheckBox = GWT.create(CheckBox.class);
public void deselect(T item) {
}
+ @Override
+ public boolean isSelected(T item) {
+ return false;
+ }
+
});
escalator.getBody().setSpacerUpdater(gridSpacerUpdater);
this.selectionModel = selectionModel;
if (selectionModel instanceof SelectionModelWithSelectionColumn) {
setSelectColumnRenderer(
- ((SelectionModelWithSelectionColumn<T>) selectionModel)
+ ((SelectionModelWithSelectionColumn) selectionModel)
.getRenderer());
} else {
setSelectColumnRenderer(null);
columnHider.updateTogglesOrder();
- fireEvent(new ColumnReorderEvent<T>(oldOrder, newOrder,
- isUserOriginated));
+ fireEvent(
+ new ColumnReorderEvent<>(oldOrder, newOrder, isUserOriginated));
}
/**
import java.util.Set;
import com.vaadin.server.data.DataSource;
-import com.vaadin.shared.data.selection.SelectionModel;
/**
* A generic interface for components that show a list of data.
--- /dev/null
+/*
+ * 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.data;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Stream;
+
+/**
+ * Models the selection logic of a {@code Listing} component. Determines how
+ * items can be selected and deselected.
+ *
+ * @author Vaadin Ltd.
+ *
+ * @param <T>
+ * the type of the items to select
+ * @since 8.0
+ */
+public interface SelectionModel<T> extends Serializable {
+
+ /**
+ * A selection model in which at most one item can be selected at a time.
+ * Selecting another item deselects the originally selected item.
+ *
+ * @param <T>
+ * the type of the items to select
+ */
+ public interface Single<T> extends SelectionModel<T> {
+
+ /**
+ * Selects the given item. If another item was already selected, that
+ * item is deselected.
+ */
+ @Override
+ public void select(T item);
+
+ /**
+ * Returns the currently selected item, or an empty optional if no item
+ * is selected.
+ *
+ * @return an optional of the selected item if any, an empty optional
+ * otherwise
+ */
+ public Optional<T> getSelectedItem();
+
+ /**
+ * Sets the current selection to the given item, or clears selection if
+ * given {@code null}.
+ *
+ * @param item
+ * the item to select or {@code null} to clear selection
+ */
+ public default void setSelectedItem(T item) {
+ if (item != null) {
+ select(item);
+ } else {
+ deselectAll();
+ }
+ }
+
+ /**
+ * Returns a singleton set of the currently selected item or an empty
+ * set if no item is selected.
+ *
+ * @return a singleton set of the selected item if any, an empty set
+ * otherwise
+ *
+ * @see #getSelectedItem()
+ */
+ @Override
+ public default Set<T> getSelectedItems() {
+ return getSelectedItem().map(Collections::singleton)
+ .orElse(Collections.emptySet());
+ }
+ }
+
+ /**
+ * A selection model in which multiple items can be selected at the same
+ * time. Selecting an item adds it to the selection.
+ *
+ * @param <T>
+ * the type of the items to select
+ */
+ public interface Multi<T> extends SelectionModel<T> {
+
+ /**
+ * Adds the given item to the set of currently selected items.
+ * <p>
+ * By default this does not clear any previous selection. To do that,
+ * use {@link #deselectAll()}.
+ * <p>
+ * If the the item was already selected, this is a NO-OP.
+ *
+ * @param item
+ * the item to add to selection, not {@code null}
+ */
+ @Override
+ public default void select(T item) {
+ Objects.requireNonNull(item);
+ selectItems(item);
+ };
+
+ /**
+ * Adds the given items to the set of currently selected items.
+ * <p>
+ * By default this does not clear any previous selection. To do that,
+ * use {@link #deselectAll()}.
+ * <p>
+ * If the all the items were already selected, this is a NO-OP.
+ * <p>
+ * This is a short-hand for {@link #updateSelection(Set, Set)} with
+ * nothing to deselect.
+ *
+ * @param items
+ * to add to selection, not {@code null}
+ */
+ public default void selectItems(T... items) {
+ Objects.requireNonNull(items);
+ Stream.of(items).forEach(Objects::requireNonNull);
+
+ updateSelection(new LinkedHashSet<>(Arrays.asList(items)),
+ Collections.emptySet());
+ }
+
+ /**
+ * Removes the given items from the set of currently selected items.
+ * <p>
+ * If the none of the items were selected, this is a NO-OP.
+ * <p>
+ * This is a short-hand for {@link #updateSelection(Set, Set)} with
+ * nothing to select.
+ *
+ * @param items
+ * to remove from selection, not {@code null}
+ */
+ public default void deselectItems(T... items) {
+ Objects.requireNonNull(items);
+ Stream.of(items).forEach(Objects::requireNonNull);
+
+ updateSelection(Collections.emptySet(),
+ new LinkedHashSet<>(Arrays.asList(items)));
+ }
+
+ /**
+ * Updates the selection by adding and removing the given items from it.
+ * <p>
+ * If all the added items were already selected and the removed items
+ * were not selected, this is a NO-OP.
+ * <p>
+ * Duplicate items (in both add & remove sets) are ignored.
+ *
+ * @param addedItems
+ * the items to add, not {@code null}
+ * @param removedItems
+ * the items to remove, not {@code null}
+ */
+ public void updateSelection(Set<T> addedItems, Set<T> removedItems);
+ }
+
+ /**
+ * Returns an immutable set of the currently selected items. It is safe to
+ * invoke other {@code SelectionModel} methods while iterating over the set.
+ * <p>
+ * <em>Implementation note:</em> the iteration order of the items in the
+ * returned set should be well-defined and documented by the implementing
+ * class.
+ *
+ * @return the items in the current selection, not null
+ */
+ public Set<T> getSelectedItems();
+
+ /**
+ * Selects the given item. Depending on the implementation, may cause other
+ * items to be deselected. If the item is already selected, does nothing.
+ *
+ * @param item
+ * the item to select, not null
+ */
+ public void select(T item);
+
+ /**
+ * Deselects the given item. If the item is not currently selected, does
+ * nothing.
+ *
+ * @param item
+ * the item to deselect, not null
+ */
+ public void deselect(T item);
+
+ /**
+ * Deselects all currently selected items.
+ */
+ public default void deselectAll() {
+ getSelectedItems().forEach(this::deselect);
+ }
+
+ /**
+ * Returns whether the given item is currently selected.
+ *
+ * @param item
+ * the item to check, not null
+ * @return {@code true} if the item is selected, {@code false} otherwise
+ */
+ public default boolean isSelected(T item) {
+ return getSelectedItems().contains(item);
+ }
+}
*/
package com.vaadin.data.selection;
+import com.vaadin.data.SelectionModel;
import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.ui.AbstractListing.AbstractListingExtension;
import elemental.json.JsonObject;
/**
* Event fired when the the selection changes in a
- * {@link com.vaadin.shared.data.selection.SelectionModel.Multi}.
+ * {@link com.vaadin.data.SelectionModel.Multi}.
*
* @author Vaadin Ltd
*
/**
* Listens to changes from a
- * {@link com.vaadin.shared.data.selection.SelectionModel.Multi}.
+ * {@link com.vaadin.data.SelectionModel.Multi}.
*
* @author Vaadin Ltd
*
import java.util.Objects;
import com.vaadin.data.Listing;
+import com.vaadin.data.SelectionModel;
import com.vaadin.server.AbstractExtension;
import com.vaadin.server.data.DataCommunicator;
import com.vaadin.server.data.DataGenerator;
import com.vaadin.server.data.DataSource;
-import com.vaadin.shared.data.selection.SelectionModel;
/**
* A base class for listing components. Provides common handling for fetching
import java.util.stream.Collectors;
import com.vaadin.data.HasValue;
+import com.vaadin.data.SelectionModel;
+import com.vaadin.data.SelectionModel.Multi;
import com.vaadin.event.selection.MultiSelectionEvent;
import com.vaadin.event.selection.MultiSelectionListener;
import com.vaadin.server.Resource;
import com.vaadin.shared.AbstractFieldState;
import com.vaadin.shared.Registration;
import com.vaadin.shared.data.selection.MultiSelectServerRpc;
-import com.vaadin.shared.data.selection.SelectionModel;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
import com.vaadin.shared.ui.ListingJsonConstants;
import com.vaadin.util.ReflectTools;
import java.util.Optional;
import com.vaadin.data.HasValue;
+import com.vaadin.data.SelectionModel;
+import com.vaadin.data.SelectionModel.Single;
import com.vaadin.event.selection.SingleSelectionChangeEvent;
import com.vaadin.event.selection.SingleSelectionListener;
import com.vaadin.server.data.DataCommunicator;
import com.vaadin.shared.Registration;
-import com.vaadin.shared.data.selection.SelectionModel;
-import com.vaadin.shared.data.selection.SelectionModel.Single;
import com.vaadin.shared.data.selection.SelectionServerRpc;
import com.vaadin.shared.ui.AbstractSingleSelectState;
import com.vaadin.util.ReflectTools;
* @param <T>
* the item date type
*
- * @see com.vaadin.shared.data.selection.SelectionModel.Single
+ * @see com.vaadin.data.SelectionModel.Single
*
* @since 8.0
*/
import org.mockito.Mockito;
import com.vaadin.data.HasValue.ValueChangeEvent;
+import com.vaadin.data.SelectionModel.Multi;
import com.vaadin.event.selection.MultiSelectionEvent;
import com.vaadin.event.selection.MultiSelectionListener;
import com.vaadin.server.data.DataSource;
import com.vaadin.shared.Registration;
import com.vaadin.shared.data.selection.MultiSelectServerRpc;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
@RunWith(Parameterized.class)
public class AbstractMultiSelectTest {
import org.mockito.Mockito;
import com.vaadin.data.HasValue.ValueChangeEvent;
+import com.vaadin.data.SelectionModel.Multi;
import com.vaadin.event.selection.SingleSelectionChangeEvent;
import com.vaadin.event.selection.SingleSelectionListener;
import com.vaadin.server.data.datasource.bov.Person;
import com.vaadin.shared.Registration;
import com.vaadin.shared.data.DataCommunicatorClientRpc;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
import com.vaadin.ui.AbstractSingleSelect.AbstractSingleSelection;
/**
import org.junit.Before;
import org.junit.Test;
+import com.vaadin.data.SelectionModel;
+import com.vaadin.data.SelectionModel.Multi;
import com.vaadin.server.data.DataSource;
-import com.vaadin.shared.data.selection.SelectionModel;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
import com.vaadin.shared.data.selection.SelectionServerRpc;
public class RadioButtonGroupTest {
+++ /dev/null
-/*
- * 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.shared.data.selection;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Stream;
-
-/**
- * Models the selection logic of a {@code Listing} component. Determines how
- * items can be selected and deselected.
- *
- * @author Vaadin Ltd.
- *
- * @param <T>
- * the type of the items to select
- * @since 8.0
- */
-public interface SelectionModel<T> extends Serializable {
-
- /**
- * A selection model in which at most one item can be selected at a time.
- * Selecting another item deselects the originally selected item.
- *
- * @param <T>
- * the type of the items to select
- */
- public interface Single<T> extends SelectionModel<T> {
-
- /**
- * Selects the given item. If another item was already selected, that
- * item is deselected.
- */
- @Override
- public void select(T item);
-
- /**
- * Returns the currently selected item, or an empty optional if no item
- * is selected.
- *
- * @return an optional of the selected item if any, an empty optional
- * otherwise
- */
- public Optional<T> getSelectedItem();
-
- /**
- * Sets the current selection to the given item, or clears selection if
- * given {@code null}.
- *
- * @param item
- * the item to select or {@code null} to clear selection
- */
- public default void setSelectedItem(T item) {
- if (item != null) {
- select(item);
- } else {
- deselectAll();
- }
- }
-
- /**
- * Returns a singleton set of the currently selected item or an empty
- * set if no item is selected.
- *
- * @return a singleton set of the selected item if any, an empty set
- * otherwise
- *
- * @see #getSelectedItem()
- */
- @Override
- public default Set<T> getSelectedItems() {
- return getSelectedItem().map(Collections::singleton)
- .orElse(Collections.emptySet());
- }
- }
-
- /**
- * A selection model in which multiple items can be selected at the same
- * time. Selecting an item adds it to the selection.
- *
- * @param <T>
- * the type of the items to select
- */
- public interface Multi<T> extends SelectionModel<T> {
-
- /**
- * Adds the given item to the set of currently selected items.
- * <p>
- * By default this does not clear any previous selection. To do that,
- * use {@link #deselectAll()}.
- * <p>
- * If the the item was already selected, this is a NO-OP.
- *
- * @param item
- * the item to add to selection, not {@code null}
- */
- @Override
- public default void select(T item) {
- Objects.requireNonNull(item);
- selectItems(item);
- };
-
- /**
- * Adds the given items to the set of currently selected items.
- * <p>
- * By default this does not clear any previous selection. To do that,
- * use {@link #deselectAll()}.
- * <p>
- * If the all the items were already selected, this is a NO-OP.
- * <p>
- * This is a short-hand for {@link #updateSelection(Set, Set)} with
- * nothing to deselect.
- *
- * @param items
- * to add to selection, not {@code null}
- */
- public default void selectItems(T... items) {
- Objects.requireNonNull(items);
- Stream.of(items).forEach(Objects::requireNonNull);
-
- updateSelection(new LinkedHashSet<>(Arrays.asList(items)),
- Collections.emptySet());
- }
-
- /**
- * Removes the given items from the set of currently selected items.
- * <p>
- * If the none of the items were selected, this is a NO-OP.
- * <p>
- * This is a short-hand for {@link #updateSelection(Set, Set)} with
- * nothing to select.
- *
- * @param items
- * to remove from selection, not {@code null}
- */
- public default void deselectItems(T... items) {
- Objects.requireNonNull(items);
- Stream.of(items).forEach(Objects::requireNonNull);
-
- updateSelection(Collections.emptySet(),
- new LinkedHashSet<>(Arrays.asList(items)));
- }
-
- /**
- * Updates the selection by adding and removing the given items from it.
- * <p>
- * If all the added items were already selected and the removed items
- * were not selected, this is a NO-OP.
- * <p>
- * Duplicate items (in both add & remove sets) are ignored.
- *
- * @param addedItems
- * the items to add, not {@code null}
- * @param removedItems
- * the items to remove, not {@code null}
- */
- public void updateSelection(Set<T> addedItems, Set<T> removedItems);
- }
-
- /**
- * Returns an immutable set of the currently selected items. It is safe to
- * invoke other {@code SelectionModel} methods while iterating over the set.
- * <p>
- * <em>Implementation note:</em> the iteration order of the items in the
- * returned set should be well-defined and documented by the implementing
- * class.
- *
- * @return the items in the current selection, not null
- */
- public Set<T> getSelectedItems();
-
- /**
- * Selects the given item. Depending on the implementation, may cause other
- * items to be deselected. If the item is already selected, does nothing.
- *
- * @param item
- * the item to select, not null
- */
- public void select(T item);
-
- /**
- * Deselects the given item. If the item is not currently selected, does
- * nothing.
- *
- * @param item
- * the item to deselect, not null
- */
- public void deselect(T item);
-
- /**
- * Deselects all currently selected items.
- */
- public default void deselectAll() {
- getSelectedItems().forEach(this::deselect);
- }
-
- /**
- * Returns whether the given item is currently selected.
- *
- * @param item
- * the item to check, not null
- * @return {@code true} if the item is selected, {@code false} otherwise
- */
- public default boolean isSelected(T item) {
- return getSelectedItems().contains(item);
- }
-}
import java.util.stream.IntStream;
import com.googlecode.gentyref.GenericTypeReflector;
+import com.vaadin.data.SelectionModel;
import com.vaadin.event.FieldEvents.BlurNotifier;
import com.vaadin.event.FieldEvents.FocusNotifier;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.ui.AbstractListing;
/**
import java.util.stream.Collectors;
import java.util.stream.IntStream;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
+import com.vaadin.data.SelectionModel.Multi;
import com.vaadin.ui.AbstractMultiSelect;
import com.vaadin.ui.ItemCaptionGenerator;
*/
package com.vaadin.tests.components.checkboxgroup;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
+import com.vaadin.data.SelectionModel.Multi;
import com.vaadin.tests.components.AbstractListingFocusBlurTest;
import com.vaadin.ui.CheckBoxGroup;
*/
package com.vaadin.tests.components.radiobutton;
+import com.vaadin.data.SelectionModel;
import com.vaadin.server.FontAwesome;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.tests.components.abstractlisting.AbstractListingTestUI;
import com.vaadin.ui.ItemCaptionGenerator;
import com.vaadin.ui.RadioButtonGroup;
import java.util.stream.Stream;
import com.vaadin.annotations.Widgetset;
+import com.vaadin.data.SelectionModel;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.data.DataCommunicator;
import com.vaadin.server.data.ListDataSource;
import com.vaadin.server.data.Query;
import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.tests.widgetset.TestingWidgetSet;
import com.vaadin.ui.AbstractListing;
import com.vaadin.client.connectors.AbstractListingConnector;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.ui.VLabel;
-import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.shared.ui.Connect;
import com.vaadin.tests.data.DummyData.DummyComponent;
import elemental.json.JsonObject;
@Connect(DummyComponent.class)
-public class DummyComponentConnector extends
- AbstractListingConnector<SelectionModel<?>> {
+public class DummyComponentConnector extends AbstractListingConnector {
@Override
public FlowPanel getWidget() {