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 /client | |
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
Diffstat (limited to 'client')
2 files changed, 71 insertions, 6 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; }-*/; } |