summaryrefslogtreecommitdiffstats
path: root/compatibility-server
diff options
context:
space:
mode:
authorDenis <denis@vaadin.com>2016-12-15 17:03:07 +0200
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2016-12-15 17:03:07 +0200
commit6185ad5d4e8d81fe9e59580b48343ec9d74bc8dc (patch)
tree739fd9fd0bca3e6b9f41b71f6e1d36be0c4b9c52 /compatibility-server
parentca049c845d26a7106699715071b5cc9df0425c73 (diff)
downloadvaadin-framework-6185ad5d4e8d81fe9e59580b48343ec9d74bc8dc.tar.gz
vaadin-framework-6185ad5d4e8d81fe9e59580b48343ec9d74bc8dc.zip
Move old Sort related classes into compatibility module. (#7999)
Fixes vaadin/framework8-issues#563
Diffstat (limited to 'compatibility-server')
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/data/sort/Sort.java154
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/data/sort/SortOrder.java107
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/data/util/GeneratedPropertyContainer.java2
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/data/util/PropertyValueGenerator.java2
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/event/SortEvent.java116
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java10
-rw-r--r--compatibility-server/src/test/java/com/vaadin/v7/data/util/GeneratedPropertyContainerTest.java2
-rw-r--r--compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/sort/SortTest.java8
8 files changed, 389 insertions, 12 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/sort/Sort.java b/compatibility-server/src/main/java/com/vaadin/v7/data/sort/Sort.java
new file mode 100644
index 0000000000..701c7d317e
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/sort/Sort.java
@@ -0,0 +1,154 @@
+/*
+ * 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.v7.data.sort;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.shared.data.sort.SortDirection;
+
+/**
+ * Fluid Sort API. Provides a convenient, human-readable way of specifying
+ * multi-column sort order.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Deprecated
+public class Sort implements Serializable {
+
+ private final Sort previous;
+ private final SortOrder order;
+
+ /**
+ * Initial constructor, called by the static by() methods.
+ *
+ * @param propertyId
+ * a property ID, corresponding to a property in the data source
+ * @param direction
+ * a sort direction value
+ */
+ private Sort(Object propertyId, SortDirection direction) {
+ previous = null;
+ order = new SortOrder(propertyId, direction);
+ }
+
+ /**
+ * Chaining constructor, called by the non-static then() methods. This
+ * constructor links to the previous Sort object.
+ *
+ * @param previous
+ * the sort marker that comes before this one
+ * @param propertyId
+ * a property ID, corresponding to a property in the data source
+ * @param direction
+ * a sort direction value
+ */
+ private Sort(Sort previous, Object propertyId, SortDirection direction) {
+ this.previous = previous;
+ order = new SortOrder(propertyId, direction);
+
+ Sort s = previous;
+ while (s != null) {
+ if (s.order.getPropertyId() == propertyId) {
+ throw new IllegalStateException(
+ "Can not sort along the same property (" + propertyId
+ + ") twice!");
+ }
+ s = s.previous;
+ }
+
+ }
+
+ /**
+ * Start building a Sort order by sorting a provided column in ascending
+ * order.
+ *
+ * @param propertyId
+ * a property id, corresponding to a data source property
+ * @return a sort object
+ */
+ public static Sort by(Object propertyId) {
+ return by(propertyId, SortDirection.ASCENDING);
+ }
+
+ /**
+ * Start building a Sort order by sorting a provided column.
+ *
+ * @param propertyId
+ * a property id, corresponding to a data source property
+ * @param direction
+ * a sort direction value
+ * @return a sort object
+ */
+ public static Sort by(Object propertyId, SortDirection direction) {
+ return new Sort(propertyId, direction);
+ }
+
+ /**
+ * Continue building a Sort order. The provided property is sorted in
+ * ascending order if the previously added properties have been evaluated as
+ * equals.
+ *
+ * @param propertyId
+ * a property id, corresponding to a data source property
+ * @return a sort object
+ */
+ public Sort then(Object propertyId) {
+ return then(propertyId, SortDirection.ASCENDING);
+ }
+
+ /**
+ * Continue building a Sort order. The provided property is sorted in
+ * specified order if the previously added properties have been evaluated as
+ * equals.
+ *
+ * @param propertyId
+ * a property id, corresponding to a data source property
+ * @param direction
+ * a sort direction value
+ * @return a sort object
+ */
+ public Sort then(Object propertyId, SortDirection direction) {
+ return new Sort(this, propertyId, direction);
+ }
+
+ /**
+ * Build a sort order list, ready to be passed to Grid
+ *
+ * @return a sort order list.
+ */
+ public List<SortOrder> build() {
+
+ int count = 1;
+ Sort s = this;
+ while (s.previous != null) {
+ s = s.previous;
+ ++count;
+ }
+
+ List<SortOrder> order = new ArrayList<>(count);
+
+ s = this;
+ do {
+ order.add(0, s.order);
+ s = s.previous;
+ } while (s != null);
+
+ return order;
+ }
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/sort/SortOrder.java b/compatibility-server/src/main/java/com/vaadin/v7/data/sort/SortOrder.java
new file mode 100644
index 0000000000..4d8e297ca7
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/sort/SortOrder.java
@@ -0,0 +1,107 @@
+/*
+ * 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.v7.data.sort;
+
+import java.io.Serializable;
+
+import com.vaadin.shared.data.sort.SortDirection;
+
+/**
+ * Sort order descriptor. Links together a {@link SortDirection} value and a
+ * Vaadin container property ID.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Deprecated
+public class SortOrder implements Serializable {
+
+ private final Object propertyId;
+ private final SortDirection direction;
+
+ /**
+ * Create a SortOrder object. Both arguments must be non-null.
+ *
+ * @param propertyId
+ * id of the data source property to sort by
+ * @param direction
+ * value indicating whether the property id should be sorted in
+ * ascending or descending order
+ */
+ public SortOrder(Object propertyId, SortDirection direction) {
+ if (propertyId == null) {
+ throw new IllegalArgumentException("Property ID can not be null!");
+ }
+ if (direction == null) {
+ throw new IllegalArgumentException(
+ "Direction value can not be null!");
+ }
+ this.propertyId = propertyId;
+ this.direction = direction;
+ }
+
+ /**
+ * Returns the property ID.
+ *
+ * @return a property ID
+ */
+ public Object getPropertyId() {
+ return propertyId;
+ }
+
+ /**
+ * Returns the {@link SortDirection} value.
+ *
+ * @return a sort direction value
+ */
+ public SortDirection getDirection() {
+ return direction;
+ }
+
+ @Override
+ public String toString() {
+ return propertyId + " " + direction;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + direction.hashCode();
+ result = prime * result + propertyId.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ } else if (obj == null) {
+ return false;
+ } else if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ SortOrder other = (SortOrder) obj;
+ if (direction != other.direction) {
+ return false;
+ } else if (!propertyId.equals(other.propertyId)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/GeneratedPropertyContainer.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/GeneratedPropertyContainer.java
index f27b651b50..ac0c44d8f1 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/data/util/GeneratedPropertyContainer.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/GeneratedPropertyContainer.java
@@ -27,11 +27,11 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import com.vaadin.data.sort.SortOrder;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.Property;
+import com.vaadin.v7.data.sort.SortOrder;
import com.vaadin.v7.data.util.filter.UnsupportedFilterException;
/**
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/PropertyValueGenerator.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/PropertyValueGenerator.java
index e49da158f8..ce5e6738e9 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/data/util/PropertyValueGenerator.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/PropertyValueGenerator.java
@@ -17,8 +17,8 @@ package com.vaadin.v7.data.util;
import java.io.Serializable;
-import com.vaadin.data.sort.SortOrder;
import com.vaadin.v7.data.Container.Filter;
+import com.vaadin.v7.data.sort.SortOrder;
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.Property;
import com.vaadin.v7.data.util.filter.UnsupportedFilterException;
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/event/SortEvent.java b/compatibility-server/src/main/java/com/vaadin/v7/event/SortEvent.java
new file mode 100644
index 0000000000..044b42b10f
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/event/SortEvent.java
@@ -0,0 +1,116 @@
+/*
+ * 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.v7.event;
+
+import java.io.Serializable;
+import java.util.List;
+
+import com.vaadin.shared.Registration;
+import com.vaadin.ui.Component;
+import com.vaadin.v7.data.sort.SortOrder;
+
+/**
+ * Event describing a change in sorting of a {@link Container}. Fired by
+ * {@link SortNotifier SortNotifiers}.
+ *
+ * @see SortListener
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Deprecated
+public class SortEvent extends Component.Event {
+
+ private final List<SortOrder> sortOrder;
+ private final boolean userOriginated;
+
+ /**
+ * Creates a new sort order change event with a sort order list.
+ *
+ * @param source
+ * the component from which the event originates
+ * @param sortOrder
+ * the new sort order list
+ * @param userOriginated
+ * <code>true</code> if event is a result of user interaction,
+ * <code>false</code> if from API call
+ */
+ public SortEvent(Component source, List<SortOrder> sortOrder,
+ boolean userOriginated) {
+ super(source);
+ this.sortOrder = sortOrder;
+ this.userOriginated = userOriginated;
+ }
+
+ /**
+ * Gets the sort order list.
+ *
+ * @return the sort order list
+ */
+ public List<SortOrder> getSortOrder() {
+ return sortOrder;
+ }
+
+ /**
+ * Returns whether this event originated from actions done by the user.
+ *
+ * @return true if sort event originated from user interaction
+ */
+ public boolean isUserOriginated() {
+ return userOriginated;
+ }
+
+ /**
+ * Listener for sort order change events.
+ */
+ @FunctionalInterface
+ @Deprecated
+ public interface SortListener extends Serializable {
+ /**
+ * Called when the sort order has changed.
+ *
+ * @param event
+ * the sort order change event
+ */
+ public void sort(SortEvent event);
+ }
+
+ /**
+ * The interface for adding and removing listeners for {@link SortEvent
+ * SortEvents}.
+ */
+ @Deprecated
+ public interface SortNotifier extends Serializable {
+ /**
+ * Adds a sort order change listener that gets notified when the sort
+ * order changes.
+ *
+ * @param listener
+ * the sort order change listener to add
+ * @return a registration object for removing the listener
+ */
+ public Registration addSortListener(SortListener listener);
+
+ /**
+ * Removes a sort order change listener previously added using
+ * {@link #addSortListener(SortListener)}.
+ *
+ * @param listener
+ * the sort order change listener to remove
+ */
+ public void removeSortListener(SortListener listener);
+ }
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
index e48e58824f..75915e1bc6 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
@@ -42,16 +42,11 @@ import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
-import com.vaadin.data.sort.Sort;
-import com.vaadin.data.sort.SortOrder;
import com.vaadin.event.ContextClickEvent;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
-import com.vaadin.event.SortEvent;
-import com.vaadin.event.SortEvent.SortListener;
-import com.vaadin.event.SortEvent.SortNotifier;
import com.vaadin.server.AbstractClientConnector;
import com.vaadin.server.AbstractExtension;
import com.vaadin.server.EncodeResult;
@@ -90,6 +85,8 @@ import com.vaadin.v7.data.Validator.InvalidValueException;
import com.vaadin.v7.data.fieldgroup.DefaultFieldGroupFieldFactory;
import com.vaadin.v7.data.fieldgroup.FieldGroup;
import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException;
+import com.vaadin.v7.data.sort.Sort;
+import com.vaadin.v7.data.sort.SortOrder;
import com.vaadin.v7.data.fieldgroup.FieldGroupFieldFactory;
import com.vaadin.v7.data.util.IndexedContainer;
import com.vaadin.v7.data.util.converter.Converter;
@@ -100,8 +97,11 @@ import com.vaadin.v7.event.ItemClickEvent;
import com.vaadin.v7.event.ItemClickEvent.ItemClickListener;
import com.vaadin.v7.event.ItemClickEvent.ItemClickNotifier;
import com.vaadin.v7.event.SelectionEvent;
+import com.vaadin.v7.event.SortEvent;
import com.vaadin.v7.event.SelectionEvent.SelectionListener;
import com.vaadin.v7.event.SelectionEvent.SelectionNotifier;
+import com.vaadin.v7.event.SortEvent.SortListener;
+import com.vaadin.v7.event.SortEvent.SortNotifier;
import com.vaadin.v7.server.communication.data.DataGenerator;
import com.vaadin.v7.server.communication.data.RpcDataProviderExtension;
import com.vaadin.v7.shared.ui.grid.ColumnResizeMode;
diff --git a/compatibility-server/src/test/java/com/vaadin/v7/data/util/GeneratedPropertyContainerTest.java b/compatibility-server/src/test/java/com/vaadin/v7/data/util/GeneratedPropertyContainerTest.java
index 6196af79d4..ef4aac49f5 100644
--- a/compatibility-server/src/test/java/com/vaadin/v7/data/util/GeneratedPropertyContainerTest.java
+++ b/compatibility-server/src/test/java/com/vaadin/v7/data/util/GeneratedPropertyContainerTest.java
@@ -23,13 +23,13 @@ import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
-import com.vaadin.data.sort.SortOrder;
import com.vaadin.v7.data.Container.Filter;
import com.vaadin.v7.data.Container.Indexed;
import com.vaadin.v7.data.Container.ItemSetChangeEvent;
import com.vaadin.v7.data.Container.ItemSetChangeListener;
import com.vaadin.v7.data.Container.PropertySetChangeEvent;
import com.vaadin.v7.data.Container.PropertySetChangeListener;
+import com.vaadin.v7.data.sort.SortOrder;
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.util.GeneratedPropertyContainer.GeneratedPropertyItem;
import com.vaadin.v7.data.util.filter.Compare;
diff --git a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/sort/SortTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/sort/SortTest.java
index b0100d46a3..cc209c025e 100644
--- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/sort/SortTest.java
+++ b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/sort/SortTest.java
@@ -23,12 +23,12 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import com.vaadin.data.sort.Sort;
-import com.vaadin.data.sort.SortOrder;
-import com.vaadin.event.SortEvent;
-import com.vaadin.event.SortEvent.SortListener;
import com.vaadin.shared.data.sort.SortDirection;
+import com.vaadin.v7.data.sort.Sort;
+import com.vaadin.v7.data.sort.SortOrder;
import com.vaadin.v7.data.util.IndexedContainer;
+import com.vaadin.v7.event.SortEvent;
+import com.vaadin.v7.event.SortEvent.SortListener;
import com.vaadin.v7.ui.Grid;
public class SortTest {