"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "flow-data/src/main/java/com/vaadin/flow/data/provider/hierarchy/HierarchicalDataCommunicator.java" between
vaadin-flow-4.0.5.tar.gz and vaadin-flow-4.0.6.tar.gz

About: Vaadin flow is a Java framework binding Vaadin web components to Java.

HierarchicalDataCommunicator.java  (vaadin-flow-4.0.5):HierarchicalDataCommunicator.java  (vaadin-flow-4.0.6)
skipping to change at line 21 skipping to change at line 21
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under * License for the specific language governing permissions and limitations under
* the License. * the License.
*/ */
package com.vaadin.flow.data.provider.hierarchy; package com.vaadin.flow.data.provider.hierarchy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.vaadin.flow.data.provider.CompositeDataGenerator; import com.vaadin.flow.data.provider.CompositeDataGenerator;
import com.vaadin.flow.data.provider.DataChangeEvent; import com.vaadin.flow.data.provider.DataChangeEvent;
import com.vaadin.flow.data.provider.DataCommunicator; import com.vaadin.flow.data.provider.DataCommunicator;
import com.vaadin.flow.data.provider.DataGenerator; import com.vaadin.flow.data.provider.DataGenerator;
import com.vaadin.flow.data.provider.DataProvider; import com.vaadin.flow.data.provider.DataProvider;
skipping to change at line 161 skipping to change at line 163
if (!dataControllers.isEmpty()) { if (!dataControllers.isEmpty()) {
dataControllers.values().forEach( dataControllers.values().forEach(
HierarchicalCommunicationController::unregisterPassivatedKey s); HierarchicalCommunicationController::unregisterPassivatedKey s);
dataControllers.clear(); dataControllers.clear();
} }
if (getHierarchyMapper() != null) { if (getHierarchyMapper() != null) {
HierarchicalUpdate update = arrayUpdater HierarchicalUpdate update = arrayUpdater
.startUpdate(getHierarchyMapper().getRootSize()); .startUpdate(getHierarchyMapper().getRootSize());
update.enqueue("$connector.ensureHierarchy"); update.enqueue("$connector.ensureHierarchy");
Collection<T> expandedItems = getHierarchyMapperExpandedItems();
if (!expandedItems.isEmpty()) {
update.enqueue("$connector.expandItems",
expandedItems
.stream()
.map(getKeyMapper()::key)
.map(key -> {
JsonObject json = Json.createObject();
json.put("key", key);
return json;
}).collect(
JsonUtils.asArray()));
}
requestFlush(update); requestFlush(update);
} }
} }
@Override @Override
protected void handleDataRefreshEvent(DataChangeEvent.DataRefreshEvent<T> ev ent) { protected void handleDataRefreshEvent(DataChangeEvent.DataRefreshEvent<T> ev ent) {
if (event.isRefreshChildren()) { if (event.isRefreshChildren()) {
T item = event.getItem(); T item = event.getItem();
if (isExpanded(item)) { if (isExpanded(item)) {
String parentKey = uniqueKeyProviderSupplier.get().apply(item); String parentKey = uniqueKeyProviderSupplier.get().apply(item);
skipping to change at line 230 skipping to change at line 247
* the initial filter value to use, or <code>null</code> to not * the initial filter value to use, or <code>null</code> to not
* use any initial filter value * use any initial filter value
* *
* @param <F> * @param <F>
* the filter type * the filter type
* *
* @return a consumer that accepts a new filter value to use * @return a consumer that accepts a new filter value to use
*/ */
public <F> SerializableConsumer<F> setDataProvider( public <F> SerializableConsumer<F> setDataProvider(
HierarchicalDataProvider<T, F> dataProvider, F initialFilter) { HierarchicalDataProvider<T, F> dataProvider, F initialFilter) {
SerializableConsumer<F> consumer = super.setDataProvider(dataProvider, // Remove old mapper before super.setDataProvider(...) prevents calling
initialFilter); // reset() before clearing the already expanded items:
// Remove old mapper
if (mapper != null) { if (mapper != null) {
mapper.destroyAllData(); mapper.destroyAllData();
} }
mapper = createHierarchyMapper(dataProvider); mapper = createHierarchyMapper(dataProvider);
SerializableConsumer<F> consumer = super.setDataProvider(dataProvider,
initialFilter);
// Set up mapper for requests // Set up mapper for requests
mapper.setBackEndSorting(getBackEndSorting()); mapper.setBackEndSorting(getBackEndSorting());
mapper.setInMemorySorting(getInMemorySorting()); mapper.setInMemorySorting(getInMemorySorting());
mapper.setFilter(getFilter()); mapper.setFilter(getFilter());
return consumer; return consumer;
} }
/** /**
* Create new {@code HierarchyMapper} for the given data provider. May be * Create new {@code HierarchyMapper} for the given data provider. May be
skipping to change at line 548 skipping to change at line 566
protected HierarchyMapper<T, ?> getHierarchyMapper() { protected HierarchyMapper<T, ?> getHierarchyMapper() {
return mapper; return mapper;
} }
private JsonValue generateJsonForExpandedOrCollapsedItem(T item) { private JsonValue generateJsonForExpandedOrCollapsedItem(T item) {
JsonObject json = Json.createObject(); JsonObject json = Json.createObject();
json.put("key", getKeyMapper().key(item)); json.put("key", getKeyMapper().key(item));
return json; return json;
} }
private Collection<T> getHierarchyMapperExpandedItems() {
HierarchyMapper<T, ?> hierarchyMapper = getHierarchyMapper();
if (!hierarchyMapper.hasExpandedItems()) {
return Collections.emptySet();
}
Collection<T> expandedItems = new HashSet<>();
getHierarchyMapper().fetchRootItems(null)
.forEach(root -> expandedItems.addAll(getExpandedItems(root)));
return Collections.unmodifiableCollection(expandedItems);
}
private Collection<T> getExpandedItems(T parent) {
Collection<T> expandedItems = new HashSet<>();
HierarchyMapper<T, ?> hierarchyMapper = getHierarchyMapper();
if (hierarchyMapper.isExpanded(parent)) {
expandedItems.add(parent);
}
hierarchyMapper.fetchChildItems(parent, null)
.forEach(child -> expandedItems.addAll(getExpandedItems(child)))
;
return expandedItems;
}
} }
 End of changes. 6 change blocks. 
4 lines changed or deleted 46 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)