]> source.dussan.org Git - vaadin-framework.git/commitdiff
Move key mapper to super class and provide methods to customise it
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Mon, 8 Feb 2016 15:17:54 +0000 (17:17 +0200)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Mon, 8 Feb 2016 15:20:06 +0000 (17:20 +0200)
Adds a note to create methods of data provider to remind the developer
that the method is called from the constructor and should not depend
anything initialised on init or in the subclass constructor.

Change-Id: Ifb153d5e9ac382318f380e16a3552e316d8197d0

server/src/com/vaadin/server/communication/data/typed/DataProvider.java
server/src/com/vaadin/server/communication/data/typed/SimpleDataProvider.java

index 2c45c52ed5469e06c63a8cdb2e5710d1fe42b253..320c1b60b7ca4e4838eddfcb4d42fafa0436987d 100644 (file)
@@ -181,6 +181,7 @@ public abstract class DataProvider<T> extends AbstractExtension {
     protected DataSource<T> dataSource;
     private DataChangeHandler<T> dataChangeHandler;
     private DetachListener detachListener;
+    private DataKeyMapper<T> keyMapper;
 
     protected DataProvider(DataSource<T> dataSource) {
         addDataGenerator(handler);
@@ -189,6 +190,7 @@ public abstract class DataProvider<T> extends AbstractExtension {
         registerRpc(createRpc());
         dataChangeHandler = createDataChangeHandler();
         this.dataSource.addDataChangeHandler(dataChangeHandler);
+        keyMapper = createKeyMapper();
     }
 
     @Override
@@ -237,6 +239,17 @@ public abstract class DataProvider<T> extends AbstractExtension {
         generators.remove(generator);
     }
 
+    /**
+     * Gets the {@link DataKeyMapper} used by this {@link DataProvider}. Key
+     * mapper can be used to map keys sent to the client-side back to their
+     * respective data objects.
+     * 
+     * @return key mapper
+     */
+    public DataKeyMapper<T> getKeyMapper() {
+        return keyMapper;
+    }
+
     /**
      * Sends given collection of data objects to the client-side.
      * 
@@ -313,14 +326,18 @@ public abstract class DataProvider<T> extends AbstractExtension {
     }
 
     /**
-     * Gets the {@link DataKeyMapper} used by this {@link DataProvider}.
+     * Creates a {@link DataKeyMapper} to use with this {@link DataProvider}.
+     * <p>
+     * This method is called from the constructor.
      * 
      * @return key mapper
      */
-    protected abstract DataKeyMapper<T> getKeyMapper();
+    protected abstract DataKeyMapper<T> createKeyMapper();
 
     /**
-     * Creates a {@link DataRequestRpc} instance.
+     * Creates a {@link DataRequestRpc} used with this {@link DataProvider}.
+     * <p>
+     * This method is called from the constructor.
      * 
      * @return data request rpc implementation
      */
@@ -328,6 +345,8 @@ public abstract class DataProvider<T> extends AbstractExtension {
 
     /**
      * Creates a {@link DataChangeHandler} to use with the {@link DataSource}.
+     * <p>
+     * This method is called from the constructor.
      * 
      * @return data change handler
      */
index c82ed119e509b34ee9d40c499ddc840cdddfbf67..2d4073053013c137af56b7fe669a001ec0b14810 100644 (file)
@@ -65,9 +65,6 @@ public class SimpleDataProvider<T> extends DataProvider<T> {
     private boolean reset = false;
     private final Set<T> updatedData = new HashSet<T>();
 
-    // TODO: Allow customizing the used key mapper
-    private DataKeyMapper<T> keyMapper = new KeyMapper<T>();
-
     /**
      * Creates a new DataProvider with the given Collection.
      * 
@@ -105,11 +102,6 @@ public class SimpleDataProvider<T> extends DataProvider<T> {
         updatedData.clear();
     }
 
-    @Override
-    protected DataKeyMapper<T> getKeyMapper() {
-        return keyMapper;
-    }
-
     /**
      * Informs the DataProvider that a data object has been added. It is assumed
      * to be the last object in the collection.
@@ -160,6 +152,11 @@ public class SimpleDataProvider<T> extends DataProvider<T> {
         updatedData.add(data);
     }
 
+    @Override
+    protected DataKeyMapper<T> createKeyMapper() {
+        return new KeyMapper<T>();
+    }
+
     @Override
     protected DataRequestRpc createRpc() {
         return new SimpleDataRequestRpc();