diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-05-02 18:26:11 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-05-02 18:26:11 +0300 |
commit | bb43a537e05d9d60ef82f1acac41cea6343c8cbb (patch) | |
tree | 12617ba2c0b076dbf33d4aa4399061487616e112 | |
parent | d5c7d4b68a2befa3ec874eae8a456614d0333233 (diff) | |
download | vaadin-framework-bb43a537e05d9d60ef82f1acac41cea6343c8cbb.tar.gz vaadin-framework-bb43a537e05d9d60ef82f1acac41cea6343c8cbb.zip |
Add an initial version of Tree component (#9212)
This patch introduces a Tree component, implemented as a Composite
using TreeGrid. As initial version of the component, some functionality
of the old Tree component has been left out for now.
Partly addresses #8617
64 files changed, 1365 insertions, 307 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/tree/TreeRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/tree/TreeRendererConnector.java new file mode 100644 index 0000000000..36d30626fb --- /dev/null +++ b/client/src/main/java/com/vaadin/client/connectors/tree/TreeRendererConnector.java @@ -0,0 +1,64 @@ +/* + * 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.google.gwt.safehtml.shared.SafeHtmlUtils; +import com.google.gwt.user.client.Element; +import com.vaadin.client.connectors.AbstractRendererConnector; +import com.vaadin.client.connectors.grid.ColumnConnector; +import com.vaadin.client.renderers.HtmlRenderer; +import com.vaadin.client.renderers.Renderer; +import com.vaadin.client.widget.grid.RendererCellReference; +import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.tree.TreeRendererState; +import com.vaadin.ui.Tree.TreeRenderer; + +import elemental.json.JsonObject; + +@Connect(TreeRenderer.class) +public class TreeRendererConnector extends AbstractRendererConnector<String> { + + @Override + public Renderer<String> createRenderer() { + return new HtmlRenderer() { + + @Override + public void render(RendererCellReference cell, String htmlString) { + String content = SafeHtmlUtils.htmlEscape(htmlString); + + JsonObject row = getParent().getParent().getDataSource() + .getRow(cell.getRowIndex()); + if (row != null && row.hasKey("itemIcon")) { + String resourceId = row.getString("itemIcon"); + Element element = getConnection() + .getIcon(getResourceUrl(resourceId)).getElement(); + content = element.getString() + " " + content; + } + super.render(cell, content); + } + }; + } + + @Override + public ColumnConnector getParent() { + return (ColumnConnector) super.getParent(); + } + + @Override + public TreeRendererState getState() { + return (TreeRendererState) super.getState(); + } +} diff --git a/client/src/main/java/com/vaadin/client/widget/treegrid/HierarchyRendererCellReferenceWrapper.java b/client/src/main/java/com/vaadin/client/widget/treegrid/HierarchyRendererCellReferenceWrapper.java index 9982ca4757..3f20daedba 100644 --- a/client/src/main/java/com/vaadin/client/widget/treegrid/HierarchyRendererCellReferenceWrapper.java +++ b/client/src/main/java/com/vaadin/client/widget/treegrid/HierarchyRendererCellReferenceWrapper.java @@ -24,7 +24,7 @@ import com.vaadin.client.widget.grid.RowReference; /** * Wrapper for cell references. Used by HierarchyRenderer to get the correct * inner element to render. - * + * * @author Vaadin Ltd * @since 8.1 */ @@ -37,7 +37,6 @@ public class HierarchyRendererCellReferenceWrapper Element element) { super(getRowReference(cell)); set(getFlyweightCell(cell), cell.getColumnIndex(), cell.getColumn()); - this.element = element; } @@ -47,12 +46,14 @@ public class HierarchyRendererCellReferenceWrapper } private native static RowReference<Object> getRowReference( - RendererCellReference cell)/*-{ - return cell.@com.vaadin.client.widget.grid.CellReference::getRowReference(); + RendererCellReference cell) + /*-{ + return cell.@com.vaadin.client.widget.grid.CellReference::getRowReference()(); }-*/; private native static FlyweightCell getFlyweightCell( - RendererCellReference cell)/*-{ - return cell.@com.vaadin.client.widget.grid.RendererCellReference::cell; + RendererCellReference cell) + /*-{ + return cell.@com.vaadin.client.widget.grid.RendererCellReference::cell; }-*/; } diff --git a/server/src/main/java/com/vaadin/event/CollapseEvent.java b/server/src/main/java/com/vaadin/event/CollapseEvent.java new file mode 100644 index 0000000000..ba740142e3 --- /dev/null +++ b/server/src/main/java/com/vaadin/event/CollapseEvent.java @@ -0,0 +1,97 @@ +/* + * 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.event; + +import java.io.Serializable; +import java.lang.reflect.Method; + +import com.vaadin.ui.Component; +import com.vaadin.util.ReflectTools; + +/** + * An event that is fired when an item is collapsed. Note that expanded subtrees + * of the collapsed item will not trigger collapse events. + * + * @author Vaadin Ltd + * @since 8.1 + * @param <T> + * collapsed item type + */ +public class CollapseEvent<T> extends Component.Event { + + private final T collapsedItem; + + private final boolean userOriginated; + + /** + * Construct a collapse event. + * + * @param source + * the hierarchical this event originated from + * @param collapsedItem + * the item that was collapsed + * @param userOriginated + * whether the collapse was triggered by a user interaction or + * the server + */ + public CollapseEvent(Component source, T collapsedItem, + boolean userOriginated) { + super(source); + this.collapsedItem = collapsedItem; + this.userOriginated = userOriginated; + } + + /** + * Get the collapsed item that triggered this event. + * + * @return the collapsed item + */ + public T getCollapsedItem() { + return collapsedItem; + } + + /** + * Returns whether this event was triggered by user interaction, on the + * client side, or programmatically, on the server side. + * + * @return {@code true} if this event originates from the client, + * {@code false} otherwise. + */ + public boolean isUserOriginated() { + return userOriginated; + } + + /** + * Item collapse event listener. + * + * @param <T> + * the collapsed item's type + */ + @FunctionalInterface + public interface CollapseListener<T> extends Serializable { + + public static final Method COLLAPSE_METHOD = ReflectTools.findMethod( + CollapseListener.class, "itemCollapse", CollapseEvent.class); + + /** + * Callback method for when an item has been collapsed. + * + * @param event + * the collapse event + */ + public void itemCollapse(CollapseEvent<T> event); + } +} diff --git a/server/src/main/java/com/vaadin/event/ExpandEvent.java b/server/src/main/java/com/vaadin/event/ExpandEvent.java new file mode 100644 index 0000000000..775c368a12 --- /dev/null +++ b/server/src/main/java/com/vaadin/event/ExpandEvent.java @@ -0,0 +1,96 @@ +/* + * 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.event; + +import java.io.Serializable; +import java.lang.reflect.Method; + +import com.vaadin.ui.Component; +import com.vaadin.util.ReflectTools; + +/** + * An event that is fired when an item is expanded. + * + * @author Vaadin Ltd + * @since 8.1 + * @param <T> + * the expanded item's type + */ +public class ExpandEvent<T> extends Component.Event { + + private final T expandedItem; + + private final boolean userOriginated; + + /** + * Construct an expand event. + * + * @param source + * the hierarchical component this event originated from + * @param expandedItem + * the item that was expanded + * @param userOriginated + * whether the expand was triggered by a user interaction or the + * server + */ + public ExpandEvent(Component source, T expandedItem, + boolean userOriginated) { + super(source); + this.expandedItem = expandedItem; + this.userOriginated = userOriginated; + } + + /** + * Get the expanded item that triggered this event. + * + * @return the expanded item + */ + public T getExpandedItem() { + return expandedItem; + } + + /** + * Returns whether this event was triggered by user interaction, on the + * client side, or programmatically, on the server side. + * + * @return {@code true} if this event originates from the client, + * {@code false} otherwise. + */ + public boolean isUserOriginated() { + return userOriginated; + } + + /** + * Item expand event listener. + * + * @param <T> + * the expanded item's type + */ + @FunctionalInterface + public interface ExpandListener<T> extends Serializable { + + public static final Method EXPAND_METHOD = ReflectTools.findMethod( + ExpandListener.class, "itemExpand", ExpandEvent.class); + + /** + * Callback method for when an item has been expanded. + * + * @param event + * the expand event + */ + public void itemExpand(ExpandEvent<T> event); + } +} diff --git a/server/src/main/java/com/vaadin/ui/Tree.java b/server/src/main/java/com/vaadin/ui/Tree.java new file mode 100644 index 0000000000..8b34fdb06e --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/Tree.java @@ -0,0 +1,364 @@ +/* + * 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.ui; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import com.vaadin.data.Binder; +import com.vaadin.data.HasDataProvider; +import com.vaadin.data.SelectionModel; +import com.vaadin.data.provider.DataGenerator; +import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.HierarchicalDataProvider; +import com.vaadin.event.CollapseEvent; +import com.vaadin.event.CollapseEvent.CollapseListener; +import com.vaadin.event.ExpandEvent; +import com.vaadin.event.ExpandEvent.ExpandListener; +import com.vaadin.event.selection.SelectionListener; +import com.vaadin.server.Resource; +import com.vaadin.shared.Registration; +import com.vaadin.shared.ui.grid.HeightMode; +import com.vaadin.shared.ui.tree.TreeRendererState; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.renderers.AbstractRenderer; + +import elemental.json.JsonObject; + +/** + * Tree component. A Tree can be used to select an item from a hierarchical set + * of items. + * + * @author Vaadin Ltd + * @since 8.1 + * + * @param <T> + * the data type + */ +public class Tree<T> extends Composite implements HasDataProvider<T> { + + /** + * String renderer that handles icon resources and stores their identifiers + * into data objects. + */ + public final class TreeRenderer extends AbstractRenderer<T, String> + implements DataGenerator<T> { + + /** + * Constructs a new TreeRenderer. + */ + protected TreeRenderer() { + super(String.class); + } + + private Map<T, String> resourceKeyMap = new HashMap<>(); + private int counter = 0; + + @Override + public void generateData(T item, JsonObject jsonObject) { + Resource resource = iconProvider.apply(item); + if (resource == null) { + destroyData(item); + return; + } + + if (!resourceKeyMap.containsKey(item)) { + resourceKeyMap.put(item, "icon" + (counter++)); + } + setResource(resourceKeyMap.get(item), resource); + jsonObject.put("itemIcon", resourceKeyMap.get(item)); + } + + @Override + public void destroyData(T item) { + if (resourceKeyMap.containsKey(item)) { + setResource(resourceKeyMap.get(item), null); + resourceKeyMap.remove(item); + } + } + + @Override + public void destroyAllData() { + Set<T> keys = new HashSet<>(resourceKeyMap.keySet()); + for (T key : keys) { + destroyData(key); + } + } + + @Override + protected TreeRendererState getState() { + return (TreeRendererState) super.getState(); + } + + @Override + protected TreeRendererState getState(boolean markAsDirty) { + return (TreeRendererState) super.getState(markAsDirty); + } + } + + private TreeGrid<T> treeGrid = new TreeGrid<>(); + private ItemCaptionGenerator<T> captionGenerator = String::valueOf; + private IconGenerator<T> iconProvider = t -> null; + + /** + * Constructs a new Tree Component. + */ + public Tree() { + setCompositionRoot(treeGrid); + TreeRenderer renderer = new TreeRenderer(); + treeGrid.getDataCommunicator().addDataGenerator(renderer); + treeGrid.addColumn(i -> captionGenerator.apply(i), renderer) + .setId("column"); + treeGrid.setHierarchyColumn("column"); + while (treeGrid.getHeaderRowCount() > 0) { + treeGrid.removeHeaderRow(0); + } + treeGrid.setPrimaryStyleName("v-newtree"); + + setWidth("100%"); + setHeightUndefined(); + treeGrid.setHeightMode(HeightMode.UNDEFINED); + + treeGrid.addExpandListener(e -> fireExpandEvent(e.getExpandedItem(), + e.isUserOriginated())); + treeGrid.addCollapseListener(e -> fireCollapseEvent( + e.getCollapsedItem(), e.isUserOriginated())); + } + + /** + * Constructs a new Tree Component. + * + * @param caption + * the caption for component + */ + public Tree(String caption) { + this(); + + setCaption(caption); + } + + @Override + public HierarchicalDataProvider<T, ?> getDataProvider() { + return treeGrid.getDataProvider(); + } + + @Override + public void setDataProvider(DataProvider<T, ?> dataProvider) { + treeGrid.setDataProvider(dataProvider); + } + + /** + * Adds an ExpandListener to this Tree. + * + * @see ExpandEvent + * + * @param listener + * the listener to add + * @return a registration for the listener + */ + public Registration addExpandListener(ExpandListener<T> listener) { + return addListener(ExpandEvent.class, listener, + ExpandListener.EXPAND_METHOD); + } + + /** + * Adds a CollapseListener to this Tree. + * + * @see CollapseEvent + * + * @param listener + * the listener to add + * @return a registration for the listener + */ + public Registration addCollapseListener(CollapseListener<T> listener) { + return addListener(CollapseEvent.class, listener, + CollapseListener.COLLAPSE_METHOD); + } + + /** + * Fires an expand event with given item. + * + * @param item + * the expanded item + * @param userOriginated + * whether the expand was triggered by a user interaction or the + * server + */ + protected void fireExpandEvent(T item, boolean userOriginated) { + fireEvent(new ExpandEvent<>(this, item, userOriginated)); + } + + /** + * Fires a collapse event with given item. + * + * @param item + * the collapsed item + * @param userOriginated + * whether the collapse was triggered by a user interaction or + * the server + */ + protected void fireCollapseEvent(T item, boolean userOriginated) { + fireEvent(new CollapseEvent<>(this, item, userOriginated)); + } + + /** + * Expands the given item. + * <p> + * If the item is currently expanded, does nothing. If the item does not + * have any children, does nothing. + * + * @param item + * the item to expand + */ + public void expand(T item) { + treeGrid.expand(item); + } + + /** + * Collapses the given item. + * <p> + * If the item is already collapsed, does nothing. + * + * @param item + * the item to collapse + */ + public void collapse(T item) { + treeGrid.collapse(item); + } + + /** + * This method is a shorthand that delegates to the currently set selection + * model. + * + * @see #getSelectionModel() + * + * @return set of selected items + */ + public Set<T> getSelectedItems() { + return treeGrid.getSelectedItems(); + } + + /** + * This method is a shorthand that delegates to the currently set selection + * model. + * + * @param item + * item to select + * + * @see SelectionModel#select(Object) + * @see #getSelectionModel() + */ + public void select(T item) { + treeGrid.select(item); + } + + /** + * This method is a shorthand that delegates to the currently set selection + * model. + * + * @param item + * item to deselect + * + * @see SelectionModel#deselect(Object) + * @see #getSelectionModel() + */ + public void deselect(T item) { + treeGrid.deselect(item); + } + + /** + * Adds a selection listener to the current selection model. + * <p> + * <strong>NOTE:</strong> If selection mode is switched with + * {@link setSelectionMode(SelectionMode)}, then this listener is not + * triggered anymore when selection changes! + * + * @param listener + * the listener to add + * @return a registration handle to remove the listener + * + * @throws UnsupportedOperationException + * if selection has been disabled with + * {@link SelectionMode.NONE} + */ + public Registration addSelectionListener(SelectionListener<T> listener) { + return treeGrid.addSelectionListener(listener); + } + + /** + * Use this tree as a single select in {@link Binder}. Throws + * {@link IllegalStateException} if the tree is not using + * {@link SelectionMode#SINGLE}. + * + * @return the single select wrapper that can be used in binder + */ + public SingleSelect<T> asSingleSelect() { + return treeGrid.asSingleSelect(); + } + + /** + * Returns the selection model for this Tree. + * + * @return the selection model, not <code>null</code> + */ + public SelectionModel<T> getSelectionModel() { + return treeGrid.getSelectionModel(); + } + + @Override + public void setItems(Collection<T> items) { + treeGrid.setItems(items); + } + + /** + * Sets the item caption generator that is used to produce the strings shown + * as the text for each item. By default, {@link String#valueOf(Object)} is + * used. + * + * @param captionGenerator + * the item caption provider to use, not <code>null</code> + */ + public void setItemCaptionGenerator( + ItemCaptionGenerator<T> captionGenerator) { + Objects.requireNonNull(captionGenerator, + "Caption generator must not be null"); + this.captionGenerator = captionGenerator; + treeGrid.getDataCommunicator().reset(); + } + + /** + * Sets the item icon generator that is used to produce custom icons for + * items. The generator can return <code>null</code> for items with no icon. + * + * @see IconGenerator + * + * @param iconGenerator + * the item icon generator to set, not <code>null</code> + * @throws NullPointerException + * if {@code itemIconGenerator} is {@code null} + */ + public void setItemIconGenerator(IconGenerator<T> iconGenerator) { + Objects.requireNonNull(iconGenerator, + "Item icon generator must not be null"); + this.iconProvider = iconGenerator; + treeGrid.getDataCommunicator().reset(); + } + +} diff --git a/server/src/main/java/com/vaadin/ui/TreeGrid.java b/server/src/main/java/com/vaadin/ui/TreeGrid.java index 4abad5e478..720bffaf3e 100644 --- a/server/src/main/java/com/vaadin/ui/TreeGrid.java +++ b/server/src/main/java/com/vaadin/ui/TreeGrid.java @@ -15,8 +15,6 @@ */ package com.vaadin.ui; -import java.io.Serializable; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -36,6 +34,10 @@ import com.vaadin.data.provider.HierarchicalDataCommunicator; import com.vaadin.data.provider.HierarchicalDataProvider; import com.vaadin.data.provider.HierarchicalQuery; import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; +import com.vaadin.event.CollapseEvent; +import com.vaadin.event.CollapseEvent.CollapseListener; +import com.vaadin.event.ExpandEvent; +import com.vaadin.event.ExpandEvent.ExpandListener; import com.vaadin.server.SerializablePredicate; import com.vaadin.shared.Registration; import com.vaadin.shared.ui.treegrid.FocusParentRpc; @@ -48,7 +50,6 @@ import com.vaadin.ui.declarative.DesignContext; import com.vaadin.ui.declarative.DesignFormatter; import com.vaadin.ui.renderers.AbstractRenderer; import com.vaadin.ui.renderers.Renderer; -import com.vaadin.util.ReflectTools; /** * A grid component for displaying hierarchical tabular data. @@ -61,159 +62,6 @@ import com.vaadin.util.ReflectTools; */ public class TreeGrid<T> extends Grid<T> { - /** - * Item expand event listener. - * - * @author Vaadin Ltd - * @since 8.1 - * @param <T> - * the expanded item's type - */ - @FunctionalInterface - public interface ExpandListener<T> extends Serializable { - - public static final Method EXPAND_METHOD = ReflectTools.findMethod( - ExpandListener.class, "itemExpand", ExpandEvent.class); - - /** - * Callback method for when an item has been expanded. - * - * @param event - * the expand event - */ - public void itemExpand(ExpandEvent<T> event); - } - - /** - * Item collapse event listener. - * - * @author Vaadin Ltd - * @since 8.1 - * @param <T> - * the collapsed item's type - */ - @FunctionalInterface - public interface CollapseListener<T> extends Serializable { - - public static final Method COLLAPSE_METHOD = ReflectTools.findMethod( - CollapseListener.class, "itemCollapse", CollapseEvent.class); - - /** - * Callback method for when an item has been collapsed. - * - * @param event - * the collapse event - */ - public void itemCollapse(CollapseEvent<T> event); - } - - /** - * An event that is fired when an item is expanded. - * - * @author Vaadin Ltd - * @since 8.1 - * @param <T> - * the expanded item's type - */ - public static class ExpandEvent<T> extends Component.Event { - - private final T expandedItem; - - private final boolean userOriginated; - - /** - * Construct an expand event. - * - * @param source - * the tree grid this event originated from - * @param expandedItem - * the item that was expanded - * @param userOriginated - * whether the expand was triggered by a user interaction or - * the server - */ - public ExpandEvent(TreeGrid<T> source, T expandedItem, - boolean userOriginated) { - super(source); - this.expandedItem = expandedItem; - this.userOriginated = userOriginated; - } - - /** - * Get the expanded item that triggered this event. - * - * @return the expanded item - */ - public T getExpandedItem() { - return expandedItem; - } - - /** - * Returns whether this event was triggered by user interaction, on the - * client side, or programmatically, on the server side. - * - * @return {@code true} if this event originates from the client, - * {@code false} otherwise. - */ - public boolean isUserOriginated() { - return userOriginated; - } - } - - /** - * An event that is fired when an item is collapsed. Note that expanded - * subtrees of the collapsed item will not trigger collapse events. - * - * @author Vaadin Ltd - * @since 8.1 - * @param <T> - * collapsed item type - */ - public static class CollapseEvent<T> extends Component.Event { - - private final T collapsedItem; - - private final boolean userOriginated; - - /** - * Construct a collapse event. - * - * @param source - * the tree grid this event originated from - * @param collapsedItem - * the item that was collapsed - * @param userOriginated - * whether the collapse was triggered by a user interaction - * or the server - */ - public CollapseEvent(TreeGrid<T> source, T collapsedItem, - boolean userOriginated) { - super(source); - this.collapsedItem = collapsedItem; - this.userOriginated = userOriginated; - } - - /** - * Get the collapsed item that triggered this event. - * - * @return the collapsed item - */ - public T getCollapsedItem() { - return collapsedItem; - } - - /** - * Returns whether this event was triggered by user interaction, on the - * client side, or programmatically, on the server side. - * - * @return {@code true} if this event originates from the client, - * {@code false} otherwise. - */ - public boolean isUserOriginated() { - return userOriginated; - } - } - public TreeGrid() { super(new HierarchicalDataCommunicator<>()); @@ -239,9 +87,11 @@ public class TreeGrid<T> extends Grid<T> { registerRpc(new FocusParentRpc() { @Override public void focusParent(int rowIndex, int cellIndex) { - Integer parentIndex = getDataCommunicator().getParentIndex(rowIndex); + Integer parentIndex = getDataCommunicator() + .getParentIndex(rowIndex); if (parentIndex != null) { - getRpcProxy(FocusRpc.class).focusCell(parentIndex, cellIndex); + getRpcProxy(FocusRpc.class).focusCell(parentIndex, + cellIndex); } } }); diff --git a/server/src/test/java/com/vaadin/server/DedicatedStateTest.java b/server/src/test/java/com/vaadin/server/DedicatedStateTest.java index 6d8fa485c6..3a21d136f7 100644 --- a/server/src/test/java/com/vaadin/server/DedicatedStateTest.java +++ b/server/src/test/java/com/vaadin/server/DedicatedStateTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import com.vaadin.navigator.Navigator; import com.vaadin.tests.VaadinClasses; +import com.vaadin.ui.Composite; import com.vaadin.ui.LegacyWindow; import com.vaadin.ui.components.colorpicker.ColorPickerHistory; import com.vaadin.ui.components.colorpicker.ColorPickerPopup; @@ -47,7 +48,8 @@ public class DedicatedStateTest { } private void checkState(Class<?> clazz) { - if (WHITE_LIST.contains(clazz.getCanonicalName())) { + if (WHITE_LIST.contains(clazz.getCanonicalName()) + || Composite.class.isAssignableFrom(clazz)) { return; } Method getStateNoArg = getStateNoArg(clazz); diff --git a/server/src/test/java/com/vaadin/tests/components/TreeTest.java b/server/src/test/java/com/vaadin/tests/components/TreeTest.java new file mode 100644 index 0000000000..13ef0acc49 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/components/TreeTest.java @@ -0,0 +1,75 @@ +package com.vaadin.tests.components; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.data.HierarchyData; +import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; +import com.vaadin.event.CollapseEvent; +import com.vaadin.event.CollapseEvent.CollapseListener; +import com.vaadin.event.ExpandEvent; +import com.vaadin.event.ExpandEvent.ExpandListener; +import com.vaadin.ui.Tree; + +public class TreeTest { + + private static class TreeCollapseExpandListener + implements ExpandListener<String>, CollapseListener<String> { + + private boolean collapsed = false; + private boolean expanded = false; + private final Tree<String> tree; + + public TreeCollapseExpandListener(Tree<String> tree) { + this.tree = tree; + } + + @Override + public void itemCollapse(CollapseEvent<String> event) { + Assert.assertEquals("Source component was incorrect", tree, + event.getComponent()); + Assert.assertFalse("Multiple collapse events", collapsed); + collapsed = true; + } + + @Override + public void itemExpand(ExpandEvent<String> event) { + Assert.assertEquals("Source component was incorrect", tree, + event.getComponent()); + Assert.assertFalse("Multiple expand events", expanded); + expanded = true; + } + + public boolean isExpanded() { + return expanded; + } + + public boolean isCollapsed() { + return collapsed; + } + } + + @Test + public void event_source_is_tree() { + Tree<String> tree = new Tree<>(); + HierarchyData<String> hierarchyData = new HierarchyData<>(); + hierarchyData.addItem(null, "Foo"); + hierarchyData.addItem("Foo", "Bar"); + hierarchyData.addItem("Foo", "Baz"); + tree.setDataProvider( + new InMemoryHierarchicalDataProvider<>(hierarchyData)); + + TreeCollapseExpandListener listener = new TreeCollapseExpandListener( + tree); + tree.addExpandListener(listener); + tree.addCollapseListener(listener); + + Assert.assertFalse(listener.isExpanded()); + tree.expand("Foo"); + Assert.assertTrue("Expand event not fired", listener.isExpanded()); + Assert.assertFalse(listener.isCollapsed()); + tree.collapse("Foo"); + Assert.assertTrue("Collapse event not fired", listener.isCollapsed()); + } + +} diff --git a/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridColumnTest.java b/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridColumnTest.java deleted file mode 100644 index a928a48a08..0000000000 --- a/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridColumnTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.vaadin.tests.components.treegrid; - -import org.junit.Test; - -import com.vaadin.ui.TreeGrid; -import com.vaadin.ui.renderers.TextRenderer; - -public class TreeGridColumnTest { - - private TreeGrid<String> treeGrid = new TreeGrid<>(); - - @Test(expected = IllegalStateException.class) - public void testChangeRendererOfHierarchyColumn() { - treeGrid.addColumn(Object::toString).setId("foo"); - treeGrid.setHierarchyColumn("foo"); - // This should not be allowed. - treeGrid.getColumn("foo").setRenderer(new TextRenderer()); - } -} diff --git a/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java b/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java new file mode 100644 index 0000000000..2e335f865e --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/components/treegrid/TreeGridTest.java @@ -0,0 +1,47 @@ +package com.vaadin.tests.components.treegrid; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.data.HierarchyData; +import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; +import com.vaadin.ui.TreeGrid; +import com.vaadin.ui.renderers.TextRenderer; + +public class TreeGridTest { + + private TreeGrid<String> treeGrid = new TreeGrid<>(); + private boolean expandEventFired = false; + private boolean collapseEventFired = false; + + @Test(expected = IllegalStateException.class) + public void testChangeRendererOfHierarchyColumn() { + treeGrid.addColumn(Object::toString).setId("foo"); + treeGrid.setHierarchyColumn("foo"); + // This should not be allowed. + treeGrid.getColumn("foo").setRenderer(new TextRenderer()); + } + + @Test + public void testExpandAndCollapseEvents() { + HierarchyData<String> hierarchyData = new HierarchyData<>(); + hierarchyData.addItem(null, "Foo"); + hierarchyData.addItem("Foo", "Bar"); + hierarchyData.addItem("Foo", "Baz"); + treeGrid.setDataProvider( + new InMemoryHierarchicalDataProvider<>(hierarchyData)); + + treeGrid.addExpandListener(e -> expandEventFired = true); + treeGrid.addCollapseListener(e -> collapseEventFired = true); + + // Test expand event + Assert.assertFalse(expandEventFired); + treeGrid.expand("Foo"); + Assert.assertTrue("Expand event not fired", expandEventFired); + + // Test collapse event + Assert.assertFalse(collapseEventFired); + treeGrid.collapse("Foo"); + Assert.assertTrue("Collapse event not fired", collapseEventFired); + } +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/StateGetDoesNotMarkDirtyTest.java b/server/src/test/java/com/vaadin/tests/server/component/StateGetDoesNotMarkDirtyTest.java index 29dd6638fa..99c686743c 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/StateGetDoesNotMarkDirtyTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/StateGetDoesNotMarkDirtyTest.java @@ -127,7 +127,8 @@ public class StateGetDoesNotMarkDirtyTest { if (component instanceof UI) { return component; } - if (component instanceof Composite) { + if (component.getClass().equals(Composite.class)) { + // Plain Composite needs a root. ComponentRootSetter.setRoot(component, new Label()); } emulateAttach(component); diff --git a/shared/src/main/java/com/vaadin/shared/ui/tree/TreeRendererState.java b/shared/src/main/java/com/vaadin/shared/ui/tree/TreeRendererState.java new file mode 100644 index 0000000000..0bc6a499f7 --- /dev/null +++ b/shared/src/main/java/com/vaadin/shared/ui/tree/TreeRendererState.java @@ -0,0 +1,22 @@ +/* + * 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.ui.tree; + +import com.vaadin.shared.ui.grid.renderers.AbstractRendererState; + +public class TreeRendererState extends AbstractRendererState { + +} diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/TreeElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/TreeElement.java index d879749c24..611bc95ff0 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/TreeElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/TreeElement.java @@ -15,29 +15,128 @@ */ package com.vaadin.testbench.elements; +import java.util.Arrays; import java.util.List; import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; +import com.vaadin.testbench.TestBenchElement; import com.vaadin.testbench.elementsbase.ServerClass; -@ServerClass("com.vaadin.ui.Tree") -@Deprecated -public class TreeElement extends AbstractSelectElement { +/** + * Testbench Element API for {@code Tree}. + * <p> + * <strong>Note:</strong> This TreeElement is for the Vaadin 8 version of Tree. + * Use {@link com.vaadin.v7.testbench.elements.TreeElement} for the + * compatibility version. + * + * @author Vaadin Ltd. + * @since 8.1 + */ +// TODO: Switch to com.vaadin.ui.Tree once inheritance finding is fixed +@ServerClass("com.vaadin.ui.Composite") +public class TreeElement extends AbstractComponentElement { + /** - * Returns selected item of the tree. In multiselect mode returns first - * selected item. If there is no selected item returns empty string + * Expands the row at the given index in the tree. * - * @return selected item of the tree + * @param index + * 0-based row index to expand */ - public String getValue() { - List<WebElement> selectedElements = findElements( - By.className("v-tree-node-selected")); - if (selectedElements.isEmpty()) { - return ""; - } else { - return selectedElements.get(0).getText(); + public void expand(int index) { + if (isExpanded(index)) { + throw new IllegalStateException( + "The element at row " + index + " was expanded already"); } + getExpandElement(index).click(); + } + + /** + * Returns whether the row at the given index is expanded or not. + * + * @param index + * 0-based row index + * @return {@code true} if expanded, {@code false} if collapsed + */ + public boolean isExpanded(int index) { + WebElement expandElement = getExpandElement(index); + List<String> classes = Arrays + .asList(expandElement.getAttribute("class").split(" ")); + return classes.contains("expanded") && !classes.contains("collapsed"); + } + + /** + * Returns whether the row at the given index is collapsed or not. + * + * @param rowIndex + * 0-based row index + * + * @return {@code true} if collapsed, {@code false} if expanded + */ + public boolean isCollapsed(int rowIndex) { + return !isExpanded(rowIndex); + } + + /** + * Gets the expand/collapse element for the given row. + * + * @param rowIndex + * 0-based row index + * @return the {@code span} element that is clicked for expanding/collapsing + * a row + * @throws NoSuchElementException + * if there is no expand element for this row + */ + public WebElement getExpandElement(int rowIndex) { + return asTreeGrid().getCell(rowIndex, 0) + .findElement(By.className("v-newtree-expander")); + + } + + /** + * Collapses the row at the given index in the tree. + * + * @param index + * 0-based row index to collapse + */ + public void collapse(int index) { + if (isCollapsed(index)) { + throw new IllegalStateException( + "The element at row " + index + " was collapsed already"); + } + getExpandElement(index).click(); + } + + /** + * Gets all items currently shown in this tree. + * + * @return list of all items + */ + public List<TestBenchElement> getAllItems() { + return TestBenchElement.wrapElements( + asTreeGrid().getBody().findElements(By.tagName("tr")), + getCommandExecutor()); + } + + /** + * Gets an item at given index. + * + * @param index + * 0-based row index + * @return item at given index + */ + public TestBenchElement getItem(int index) { + return asTreeGrid().getCell(index, 0); + } + + /** + * Convenience method for accessing the underlying TreeGrid. + * + * @return this tree element as a tree grid element. + */ + protected TreeGridElement asTreeGrid() { + return wrap(TreeGridElement.class); } } diff --git a/testbench-api/src/main/java/com/vaadin/v7/testbench/elements/TreeElement.java b/testbench-api/src/main/java/com/vaadin/v7/testbench/elements/TreeElement.java new file mode 100644 index 0000000000..c9aa9a695b --- /dev/null +++ b/testbench-api/src/main/java/com/vaadin/v7/testbench/elements/TreeElement.java @@ -0,0 +1,44 @@ +/* + * 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.testbench.elements; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.AbstractSelectElement; +import com.vaadin.testbench.elementsbase.ServerClass; + +@ServerClass("com.vaadin.ui.Tree") +@Deprecated +public class TreeElement extends AbstractSelectElement { + /** + * Returns selected item of the tree. In multiselect mode returns first + * selected item. If there is no selected item returns empty string + * + * @return selected item of the tree + */ + public String getValue() { + List<WebElement> selectedElements = findElements( + By.className("v-tree-node-selected")); + if (selectedElements.isEmpty()) { + return ""; + } else { + return selectedElements.get(0).getText(); + } + } +} diff --git a/themes/src/main/themes/VAADIN/themes/valo/components/_all.scss b/themes/src/main/themes/VAADIN/themes/valo/components/_all.scss index 552d0f035d..99514e2164 100644 --- a/themes/src/main/themes/VAADIN/themes/valo/components/_all.scss +++ b/themes/src/main/themes/VAADIN/themes/valo/components/_all.scss @@ -35,6 +35,7 @@ @import "textarea"; @import "tree"; @import "treegrid"; +@import "newtree"; @import "treetable"; @import "twincolselect"; @import "upload"; @@ -146,6 +147,10 @@ @include valo-tree; } + @if v-is-included(newtree) { + @include valo-newtree; + } + @if v-is-included(treegrid) { @include valo-treegrid; } diff --git a/themes/src/main/themes/VAADIN/themes/valo/components/_newtree.scss b/themes/src/main/themes/VAADIN/themes/valo/components/_newtree.scss new file mode 100644 index 0000000000..9929d7ef47 --- /dev/null +++ b/themes/src/main/themes/VAADIN/themes/valo/components/_newtree.scss @@ -0,0 +1,59 @@ +@import "treegrid"; + +$v-newtree-border-radius: 3px; + +@mixin valo-newtree ($primary-stylename: v-newtree) { + + @include valo-treegrid($primary-stylename); + + .#{$primary-stylename}-row > td { + background-color: transparent; + border: none; + } + + .#{$primary-stylename}-tablewrapper { + background-color: transparent; + border: none; + } + + .#{$primary-stylename}-row-selected > .#{$primary-stylename}-cell { + background-color: transparent; + background-image: none; + color: inherit; + text-shadow: none; + border: none; + } + + .#{$primary-stylename}:focus .#{$primary-stylename}-rowmode-row-focused:before { + display: none; + } + + .#{$primary-stylename}-cell-content { + border: $v-grid-cell-focused-border; + border-color: transparent; + border-radius: $v-newtree-border-radius; + padding: $v-grid-cell-padding; + } + + .#{$primary-stylename}:focus .#{$primary-stylename}-rowmode-cell-focused + > .#{$primary-stylename}-node > .#{$primary-stylename}-cell-content { + border: $v-grid-cell-focused-border; + } + + // Selected + .#{$primary-stylename}-row-selected { + $grid-sel-bg: $v-grid-row-selected-background-color; + + > .#{$primary-stylename}-cell > .#{$primary-stylename}-node > .#{$primary-stylename}-cell-content { + @include valo-gradient($grid-sel-bg); + color: valo-font-color($grid-sel-bg); + text-shadow: valo-text-shadow($font-color: valo-font-color($grid-sel-bg), $background-color: $grid-sel-bg); + border-color: adjust-color($grid-sel-bg, $lightness: -8%, $saturation: -8%); + } + + > .#{$primary-stylename}-cell-focused > .#{$primary-stylename}-node > .#{$primary-stylename}-cell-content { + border-color: adjust-color($grid-sel-bg, $lightness: 20%); + } + } +} + diff --git a/themes/src/main/themes/VAADIN/themes/valo/shared/_variables.scss b/themes/src/main/themes/VAADIN/themes/valo/shared/_variables.scss index cdeca2dd4b..2c70ebeee5 100644 --- a/themes/src/main/themes/VAADIN/themes/valo/shared/_variables.scss +++ b/themes/src/main/themes/VAADIN/themes/valo/shared/_variables.scss @@ -490,6 +490,7 @@ $v-included-components: textarea, richtextarea, tree, + newtree, treegrid, treetable, twincolselect, diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java new file mode 100644 index 0000000000..a2078c237e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java @@ -0,0 +1,112 @@ +package com.vaadin.tests.components.tree; + +import java.util.Arrays; +import java.util.List; + +import com.vaadin.annotations.Theme; +import com.vaadin.annotations.Widgetset; +import com.vaadin.data.HierarchyData; +import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; +import com.vaadin.icons.VaadinIcons; +import com.vaadin.server.ClassResource; +import com.vaadin.server.ThemeResource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.data.bean.HierarchicalTestBean; +import com.vaadin.ui.Component; +import com.vaadin.ui.IconGenerator; +import com.vaadin.ui.MenuBar; +import com.vaadin.ui.MenuBar.MenuItem; +import com.vaadin.ui.Tree; +import com.vaadin.ui.VerticalLayout; + +@Theme("tests-valo-disabled-animations") +@Widgetset("com.vaadin.DefaultWidgetSet") +public class TreeBasicFeatures extends AbstractTestUIWithLog { + + private Tree<HierarchicalTestBean> tree; + private InMemoryHierarchicalDataProvider<HierarchicalTestBean> inMemoryDataProvider; + private IconGenerator<HierarchicalTestBean> iconGenerator = i -> { + switch (i.getDepth()) { + case 0: + return new ThemeResource("../reindeer/common/icons/bullet.png"); + case 1: + return VaadinIcons.FLIGHT_TAKEOFF; + case 2: + return new ClassResource("/com/vaadin/tests/m.gif"); + default: + return null; + } + }; + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + tree = new Tree<>(); + setupDataProvider(); + tree.setDataProvider(inMemoryDataProvider); + + tree.addSelectionListener( + e -> log("SelectionEvent: " + e.getAllSelectedItems())); + + tree.addExpandListener(e -> log("ExpandEvent: " + e.getExpandedItem())); + tree.addCollapseListener( + e -> log("ExpandEvent: " + e.getCollapsedItem())); + + layout.addComponents(createMenu(), tree); + + addComponent(layout); + } + + private Component createMenu() { + MenuBar menu = new MenuBar(); + menu.setErrorHandler(error -> log("Exception occured, " + + error.getThrowable().getClass().getName() + ": " + + error.getThrowable().getMessage())); + MenuItem componentMenu = menu.addItem("Component", null); + createIconMenu(componentMenu.addItem("Icons", null)); + createCaptionMenu(componentMenu.addItem("Captions", null)); + return menu; + } + + private void createCaptionMenu(MenuItem captionMenu) { + captionMenu.addItem("String.valueOf", + menu -> tree.setItemCaptionGenerator(String::valueOf)); + captionMenu + .addItem("Custom caption", + menu -> tree.setItemCaptionGenerator(i -> "Id: " + + i.getId() + ", Depth: " + i.getDepth() + + ", Index: " + i.getIndex())); + } + + private void createIconMenu(MenuItem iconMenu) { + iconMenu.addItem("No icons", + menu -> tree.setItemIconGenerator(t -> null)); + iconMenu.addItem("By Depth", + menu -> tree.setItemIconGenerator(iconGenerator)); + } + + private void setupDataProvider() { + HierarchyData<HierarchicalTestBean> data = new HierarchyData<>(); + + List<Integer> ints = Arrays.asList(0, 1, 2); + + ints.stream().forEach(index -> { + HierarchicalTestBean bean = new HierarchicalTestBean(null, 0, + index); + data.addItem(null, bean); + ints.stream().forEach(childIndex -> { + HierarchicalTestBean childBean = new HierarchicalTestBean( + bean.getId(), 1, childIndex); + data.addItem(bean, childBean); + ints.stream() + .forEach(grandChildIndex -> data.addItem(childBean, + new HierarchicalTestBean(childBean.getId(), 2, + grandChildIndex))); + }); + }); + + inMemoryDataProvider = new InMemoryHierarchicalDataProvider<>(data); + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/treegrid/LazyHierarchicalDataProvider.java b/uitest/src/main/java/com/vaadin/tests/components/treegrid/LazyHierarchicalDataProvider.java index 33c8f15a47..1fe7202d8a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/treegrid/LazyHierarchicalDataProvider.java +++ b/uitest/src/main/java/com/vaadin/tests/components/treegrid/LazyHierarchicalDataProvider.java @@ -7,7 +7,7 @@ import java.util.stream.Stream; import com.vaadin.data.provider.AbstractHierarchicalDataProvider; import com.vaadin.data.provider.HierarchicalQuery; -import com.vaadin.tests.components.treegrid.TreeGridBasicFeatures.HierarchicalTestBean; +import com.vaadin.tests.data.bean.HierarchicalTestBean; public class LazyHierarchicalDataProvider extends AbstractHierarchicalDataProvider<HierarchicalTestBean, Void> { diff --git a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java index a8ce0a7489..8151aa8c88 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java +++ b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java @@ -16,6 +16,7 @@ import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; import com.vaadin.server.SerializablePredicate; import com.vaadin.shared.Range; import com.vaadin.tests.components.AbstractComponentTest; +import com.vaadin.tests.data.bean.HierarchicalTestBean; import com.vaadin.ui.TreeGrid; @Theme("valo") @@ -178,75 +179,14 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> { @SuppressWarnings("unchecked") private void createListenerMenu() { createListenerAction("Collapse listener", "State", - treeGrid -> treeGrid.addCollapseListener(event -> log( - "Item collapsed (user originated: " + treeGrid -> treeGrid.addCollapseListener( + event -> log("Item collapsed (user originated: " + event.isUserOriginated() + "): " + event.getCollapsedItem()))); createListenerAction("Expand listener", "State", - treeGrid -> treeGrid.addExpandListener(event -> log( - "Item expanded (user originated: " + treeGrid -> treeGrid.addExpandListener( + event -> log("Item expanded (user originated: " + event.isUserOriginated() + "): " + event.getExpandedItem()))); } - - static class HierarchicalTestBean { - - private final String id; - private final int depth; - private final int index; - - public HierarchicalTestBean(String parentId, int depth, int index) { - id = (parentId == null ? "" : parentId) + "/" + depth + "/" + index; - this.depth = depth; - this.index = index; - } - - public int getDepth() { - return depth; - } - - public int getIndex() { - return index; - } - - public String getId() { - return id; - } - - @Override - public String toString() { - return depth + " | " + index; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - HierarchicalTestBean other = (HierarchicalTestBean) obj; - if (id == null) { - if (other.id != null) { - return false; - } - } else if (!id.equals(other.id)) { - return false; - } - return true; - } - - } } diff --git a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridScrolling.java b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridScrolling.java index 8d859918b8..cc650705a8 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridScrolling.java +++ b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridScrolling.java @@ -3,7 +3,7 @@ package com.vaadin.tests.components.treegrid; import com.vaadin.annotations.Widgetset; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.components.treegrid.TreeGridBasicFeatures.HierarchicalTestBean; +import com.vaadin.tests.data.bean.HierarchicalTestBean; import com.vaadin.ui.TreeGrid; @Widgetset("com.vaadin.DefaultWidgetSet") diff --git a/uitest/src/main/java/com/vaadin/tests/data/bean/HierarchicalTestBean.java b/uitest/src/main/java/com/vaadin/tests/data/bean/HierarchicalTestBean.java new file mode 100644 index 0000000000..586d138039 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/data/bean/HierarchicalTestBean.java @@ -0,0 +1,62 @@ +package com.vaadin.tests.data.bean; + +public class HierarchicalTestBean { + + private final String id; + private final int depth; + private final int index; + + public HierarchicalTestBean(String parentId, int depth, int index) { + id = (parentId == null ? "" : parentId) + "/" + depth + "/" + index; + this.depth = depth; + this.index = index; + } + + public int getDepth() { + return depth; + } + + public int getIndex() { + return index; + } + + public String getId() { + return id; + } + + @Override + public String toString() { + return depth + " | " + index; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + HierarchicalTestBean other = (HierarchicalTestBean) obj; + if (id == null) { + if (other.id != null) { + return false; + } + } else if (!id.equals(other.id)) { + return false; + } + return true; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/CtrlShiftMultiselect.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/CtrlShiftMultiselect.java index bc53d0d88f..ca80a31e51 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/CtrlShiftMultiselect.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/CtrlShiftMultiselect.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import java.util.Set; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/DndTreeTargetDetails.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/DndTreeTargetDetails.java index 2dc698def5..14a31e2c5a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/DndTreeTargetDetails.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/DndTreeTargetDetails.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.table.DndTableTargetDetails; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/ExpandCollapseTree.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/ExpandCollapseTree.java index 08a45e07f9..85765384c0 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/ExpandCollapseTree.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/ExpandCollapseTree.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import java.util.Set; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/ItemStyleGenerator.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/ItemStyleGenerator.java index 8cb1bba8d6..1bd2decea6 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/ItemStyleGenerator.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/ItemStyleGenerator.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Component; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/PreselectedTreeVisible.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/PreselectedTreeVisible.java index 3c08324237..efe46daf88 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/PreselectedTreeVisible.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/PreselectedTreeVisible.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.TestBase; import com.vaadin.v7.ui.Tree; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/SelectItemAfterRemove.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/SelectItemAfterRemove.java index 954529cc1f..ef63ab20a5 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/SelectItemAfterRemove.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/SelectItemAfterRemove.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractReindeerTestUI; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/SimpleTree.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/SimpleTree.java index d1d295e055..49b790e85a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/SimpleTree.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/SimpleTree.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import java.util.Date; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeConnectors.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeConnectors.java index d06fbb85ee..e44d89fd88 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeConnectors.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeConnectors.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DropHandler; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeContainerChange.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeContainerChange.java index be260ef30f..6d9de4c412 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeContainerChange.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeContainerChange.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Button; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeDragAndDropFromTable.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeDragAndDropFromTable.java index d83f044de3..90110d39f6 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeDragAndDropFromTable.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeDragAndDropFromTable.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DropHandler; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeFiltering.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeFiltering.java index f4d90d6e9b..e4a39494d1 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeFiltering.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeFiltering.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Button; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeFocusGaining.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeFocusGaining.java index e3bb8d16e9..9dcc21d6dd 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeFocusGaining.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeFocusGaining.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.Log; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeHorizontalResize.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeHorizontalResize.java index 98289bf4eb..cb948b789e 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeHorizontalResize.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeHorizontalResize.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import java.util.Iterator; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeHtmlContentAllowed.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeHtmlContentAllowed.java index 106b5771a6..8b5ceaab27 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeHtmlContentAllowed.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeHtmlContentAllowed.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractReindeerTestUI; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeIconUpdate.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeIconUpdate.java index 03885d2dc5..fc8f6c5726 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeIconUpdate.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeIconUpdate.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.server.Resource; import com.vaadin.server.ThemeResource; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeItemClickListening.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeItemClickListening.java index ffb3f5bebf..8ba84d84db 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeItemClickListening.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeItemClickListening.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeItemDoubleClick.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeItemDoubleClick.java index cb235791df..490e857a09 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeItemDoubleClick.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeItemDoubleClick.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediate.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeItemSelectionWithoutImmediate.java index 1db1b97f16..98c9a8364a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediate.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeItemSelectionWithoutImmediate.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeKeyboardNavigationScrolls.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeKeyboardNavigationScrolls.java index c7b32e9d11..e6fc574c4e 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeKeyboardNavigationScrolls.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeKeyboardNavigationScrolls.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.AlwaysFailValidator; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeKeyboardNavigationToNone.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeKeyboardNavigationToNone.java index 0ff9d4b444..cacf3ec2e1 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeKeyboardNavigationToNone.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeKeyboardNavigationToNone.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractReindeerTestUI; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeKeyboardNavigationValidators.java index e9060f2827..d33683d2bb 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeKeyboardNavigationValidators.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeKeyboardNavigationValidators.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.AlwaysFailValidator; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeNodeCaptionWrapping.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeNodeCaptionWrapping.java index 7d20e53a0d..01b9685215 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeNodeCaptionWrapping.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeNodeCaptionWrapping.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.server.ThemeResource; import com.vaadin.tests.components.TestBase; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreePerformanceTest.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreePerformanceTest.java index 81f6539709..d1aa841544 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreePerformanceTest.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreePerformanceTest.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.AbstractTestCase; import com.vaadin.ui.Layout; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeScrolling.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeScrolling.java index c92b9ba252..b893238c66 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeScrolling.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeScrolling.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.AbstractTestCase; import com.vaadin.ui.LegacyWindow; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeScrollingOnRightClick.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeScrollingOnRightClick.java index 1d7bb5720b..4253d3b0d3 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeScrollingOnRightClick.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeScrollingOnRightClick.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.event.MouseEvents; import com.vaadin.server.VaadinRequest; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeScrollingOnSelection.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeScrollingOnSelection.java index ebb6c8a700..100cbd8e5d 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeScrollingOnSelection.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeScrollingOnSelection.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Label; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeToolTips.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeToolTips.java index 03dc8b174a..58fffc82d1 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeToolTips.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeToolTips.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Component; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeWithIcons.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeWithIcons.java index 916866038b..d11140c6e8 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeWithIcons.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/TreeWithIcons.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import java.util.Date; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/Trees.java b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/Trees.java index 9694ce66d9..b53c125be3 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/Trees.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/tree/Trees.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import java.util.ArrayList; import java.util.Iterator; diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java b/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java new file mode 100644 index 0000000000..455364eb41 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java @@ -0,0 +1,133 @@ +package com.vaadin.tests.components.tree; + +import java.io.IOException; +import java.util.function.Predicate; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.TreeElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TreeBasicFeaturesTest extends MultiBrowserTest { + + private static final Predicate<TestBenchElement> THEME_RESOURCE = e -> { + return e.isElementPresent(By.tagName("img")) + && e.findElement(By.tagName("img")).getAttribute("src") + .contains("bullet.png"); + }; + private static final Predicate<TestBenchElement> VAADIN_ICON = e -> { + return e.isElementPresent(By.className("v-icon")) + && e.findElement(By.className("v-icon")).getAttribute("class") + .contains("Vaadin-Icons"); + }; + private static final Predicate<TestBenchElement> CLASS_RESOURCE = e -> { + return e.isElementPresent(By.tagName("img")) + && e.findElement(By.tagName("img")).getAttribute("src") + .contains("m.gif"); + }; + + @Before + public void before() { + setDebug(true); + openTestURL(); + } + + @Test + public void tree_expand_and_collapse() { + TreeElement tree = $(TreeElement.class).first(); + tree.expand(0); + Assert.assertEquals("1 | 0", tree.getItem(1).getText()); + tree.collapse(0); + Assert.assertEquals("0 | 1", tree.getItem(1).getText()); + assertNoErrorNotifications(); + } + + @Test + public void tree_expand_all() throws IOException { + expandAll(); + assertAllExpanded(false); + assertNoErrorNotifications(); + } + + @Test + // TODO: Re-enable once cache issue is fixed. + @Ignore("Recent change to cache invalidation broke resource clean up.") + public void tree_expand_all_with_icons() throws IOException { + selectMenuPath("Component", "Icons", "By Depth"); + Assert.assertTrue("Icon not present", $(TreeElement.class).first() + .getItem(0).isElementPresent(By.tagName("img"))); + expandAll(); + assertAllExpanded(true); + assertNoErrorNotifications(); + } + + private void expandAll() { + TreeElement tree = $(TreeElement.class).first(); + for (int i = 0; i < 2; ++i) { + int max = tree.getAllItems().size(); + for (int j = 1; j <= max; ++j) { + if (tree.isExpanded(max - j)) { + continue; + } + tree.expand(max - j); + } + } + } + + private void assertAllExpanded(boolean shouldHaveIcon) { + TreeElement tree = $(TreeElement.class).first(); + TestBenchElement item; + int n = 0; + for (int i = 0; i < 3; ++i) { + item = tree.getItem(n++); + Assert.assertEquals("0 | " + i, item.getText()); + + Assert.assertEquals("Unexpected icon state", shouldHaveIcon, + THEME_RESOURCE.test(item)); + + for (int j = 0; j < 3; ++j) { + item = tree.getItem(n++); + Assert.assertEquals((shouldHaveIcon ? "юдн " : "") + "1 | " + j, + item.getText()); + + Assert.assertEquals("Unexpected icon state", shouldHaveIcon, + VAADIN_ICON.test(item)); + + for (int k = 0; k < 3; ++k) { + item = tree.getItem(n++); + Assert.assertEquals("2 | " + k, item.getText()); + + Assert.assertEquals("Unexpected icon state", shouldHaveIcon, + CLASS_RESOURCE.test(item)); + } + } + } + } + + @Test + public void tree_custom_caption() { + selectMenuPath("Component", "Captions", "Custom caption"); + TreeElement tree = $(TreeElement.class).first(); + Assert.assertEquals("Id: /0/0, Depth: 0, Index: 0", + tree.getItem(0).getText()); + Assert.assertEquals("Id: /0/1, Depth: 0, Index: 1", + tree.getItem(1).getText()); + tree.expand(0); + Assert.assertEquals("Id: /0/0/1/0, Depth: 1, Index: 0", + tree.getItem(1).getText()); + Assert.assertEquals("Id: /0/0/1/1, Depth: 1, Index: 1", + tree.getItem(2).getText()); + tree.expand(1); + Assert.assertEquals("Id: /0/0/1/0/2/0, Depth: 2, Index: 0", + tree.getItem(2).getText()); + Assert.assertEquals("Id: /0/0/1/0/2/1, Depth: 2, Index: 1", + tree.getItem(3).getText()); + + assertNoErrorNotifications(); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/dd/DnDOnSubtreeTest.java b/uitest/src/test/java/com/vaadin/tests/dd/DnDOnSubtreeTest.java index 2bceb905c4..0e92945190 100644 --- a/uitest/src/test/java/com/vaadin/tests/dd/DnDOnSubtreeTest.java +++ b/uitest/src/test/java/com/vaadin/tests/dd/DnDOnSubtreeTest.java @@ -8,8 +8,8 @@ import org.openqa.selenium.support.ui.ExpectedCondition; import com.vaadin.testbench.By; import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.TreeElement; import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.elements.TreeElement; public class DnDOnSubtreeTest extends MultiBrowserTest { diff --git a/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBaseTest.java b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBaseTest.java index e1e8c6ddaa..a44534102f 100644 --- a/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBaseTest.java +++ b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBaseTest.java @@ -30,10 +30,10 @@ import com.vaadin.testbench.elements.OptionGroupElement; import com.vaadin.testbench.elements.TableElement; import com.vaadin.testbench.elements.TextAreaElement; import com.vaadin.testbench.elements.TextFieldElement; -import com.vaadin.testbench.elements.TreeElement; import com.vaadin.testbench.elements.TreeTableElement; import com.vaadin.testbench.elements.TwinColSelectElement; import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.elements.TreeElement; /** * diff --git a/uitest/src/test/java/com/vaadin/tests/elements/TreeElementGetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/TreeElementGetValueTest.java index c7c0915dee..151992ce63 100644 --- a/uitest/src/test/java/com/vaadin/tests/elements/TreeElementGetValueTest.java +++ b/uitest/src/test/java/com/vaadin/tests/elements/TreeElementGetValueTest.java @@ -19,8 +19,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import com.vaadin.testbench.elements.TreeElement; import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.elements.TreeElement; public class TreeElementGetValueTest extends MultiBrowserTest { @Before diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/DndTreeTargetDetailsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/DndTreeTargetDetailsTest.java index e82701f3a5..428a398997 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/DndTreeTargetDetailsTest.java +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/DndTreeTargetDetailsTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import org.openqa.selenium.WebElement; diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/SelectItemAfterRemoveTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/SelectItemAfterRemoveTest.java index bb42cb0ad7..f94b04049f 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/SelectItemAfterRemoveTest.java +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/SelectItemAfterRemoveTest.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeContextMenuAndIconsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeContextMenuAndIconsTest.java index 873fe30b65..c404066473 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeContextMenuAndIconsTest.java +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeContextMenuAndIconsTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import java.util.List; @@ -26,6 +26,7 @@ import org.openqa.selenium.remote.DesiredCapabilities; import com.vaadin.testbench.By; import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.tests.components.tree.Trees; public class TreeContextMenuAndIconsTest extends MultiBrowserTest { diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeHtmlContentAllowedTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeHtmlContentAllowedTest.java index 613100078e..e0a5cb766b 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeHtmlContentAllowedTest.java +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeHtmlContentAllowedTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import java.util.List; @@ -23,8 +23,8 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import com.vaadin.testbench.elements.CheckBoxElement; -import com.vaadin.testbench.elements.TreeElement; import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.elements.TreeElement; public class TreeHtmlContentAllowedTest extends SingleBrowserTest { diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeItemClickListeningTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeItemClickListeningTest.java index f9df790205..87fc58d3bb 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeItemClickListeningTest.java +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeItemClickListeningTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeItemDoubleClickTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeItemDoubleClickTest.java index 0f641c5541..1acc9f2860 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeItemDoubleClickTest.java +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeItemDoubleClickTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediateTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeItemSelectionWithoutImmediateTest.java index a91dad96a3..971bcb1619 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediateTest.java +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeItemSelectionWithoutImmediateTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -24,6 +24,7 @@ import org.openqa.selenium.interactions.Actions; import com.vaadin.testbench.By; import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.tests.components.tree.TreeItemSelectionWithoutImmediate; public class TreeItemSelectionWithoutImmediateTest extends MultiBrowserTest { diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeKeyboardNavigationToNoneTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeKeyboardNavigationToNoneTest.java index ecafa27f48..8e84096aae 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeKeyboardNavigationToNoneTest.java +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeKeyboardNavigationToNoneTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import org.junit.Assert; import org.junit.Before; diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeScrollingOnRightClickTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeScrollingOnRightClickTest.java index 57ea640cf0..573a08e187 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeScrollingOnRightClickTest.java +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/tree/TreeScrollingOnRightClickTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.tree; +package com.vaadin.v7.tests.components.tree; import static org.junit.Assert.assertEquals; @@ -25,6 +25,7 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.tests.components.tree.TreeScrollingOnRightClick; /** * |