Git Product home page Git Product logo

Comments (20)

dankurka avatar dankurka commented on July 21, 2024
Example of code:

public void traverseTree(Tree tree) 
{   for(int i = 0; i < tree.getItemCount(); i++) 
    {    TreeItem item = tree.getItem(i); 
          // do action here 
          traverseTree(item); 
    } 
} 


public void traverseTree(TreeItem item) 
{    for(int i = 0; i < item.getChildCount(); i++) 
     {    TreeItem child = item.getChild(i); 
          // do action here 
          traverseTree(child); 
     } 
} 

Possible fix:

It would be much easier if both the Tree and the TreeItem implemented 
an interface called, for example, "HasTreeItemChildren" that would 
include methods "getChildCount" and "getChild". Then the above two ugly 
functions would become one elegant function that would accept both a 
Tree and a TreeItem as follows: 

public void traverseTree(HasTreeItemChildren item) 
{    for(int i = 0; i < item.getChildCount(); i++) 
     {    TreeItem child = item.getChild(i); 
          // do action here 
          traverseTree(child); 
     } 
}



Reported by euginelev on 2006-10-03 14:42:51

from gwt.

dankurka avatar dankurka commented on July 21, 2024

Reported by gwt.team.ecc on 2006-10-03 19:06:03

from gwt.

dankurka avatar dankurka commented on July 21, 2024
The problem we have here is that Tree and TreeItem actually use different API
methods, which means to implement this, we need to either maintain two seperate APIs
for the same method or depreciate the Tree API, examples are addItem/addChild, 
getItemCount/getChildCount).

Another solution which may work better is to expose the root of the tree to the users
so they may use it instead of the Tree interface.  Can you think of any unintended
consequences for doing that?

Finally, in the current release a depth-first treeItemIterator has been added to
support algorithms that are not sensitive to exact tree position.

Reported by gwt.team.ecc on 2006-10-09 12:09:31

from gwt.

dankurka avatar dankurka commented on July 21, 2024

Reported by gwt.team.ecc on 2006-10-09 12:09:48

  • Status changed: Accepted

from gwt.

dankurka avatar dankurka commented on July 21, 2024
...

Reported by edgrolan722 on 2006-11-14 22:45:18

from gwt.

dankurka avatar dankurka commented on July 21, 2024
xcxc

Reported by chandi.rajan on 2007-01-16 02:45:47

from gwt.

dankurka avatar dankurka commented on July 21, 2024

Reported by gwt.team.morrildl on 2007-02-01 14:20:08

  • Labels added: Category-UI
  • Labels removed: Release-1.1.10

from gwt.

dankurka avatar dankurka commented on July 21, 2024
I am voting for common interface for Tree and TreeItem. I would need this interface

to define addItem(...) method.

Reported by m.zdila on 2007-07-03 16:22:03

from gwt.

dankurka avatar dankurka commented on July 21, 2024

Reported by [email protected] on 2008-04-08 15:09:44

  • Labels added: Milestone-Planned

from gwt.

dankurka avatar dankurka commented on July 21, 2024

Reported by [email protected] on 2008-04-28 22:59:06

from gwt.

dankurka avatar dankurka commented on July 21, 2024

Reported by [email protected] on 2008-10-21 21:54:58

  • Labels removed: priority-low

from gwt.

dankurka avatar dankurka commented on July 21, 2024

Reported by ecc%[email protected] on 2009-01-05 15:16:58

from gwt.

dankurka avatar dankurka commented on July 21, 2024
What about something like this:

class TreeItemIterator implements Iterator {
    private Stack<TreeItem> tree;

    public TreeItemIterator(TreeItem t) {
       tree.push(t);
    }

    public boolean hasNext() {
       return tree.isEmpty();
    }

    public TreeItem next() {
       TreeItem retVal = tree.pop();

       if(retVal.hasChildren()) {
          tree.addAll(retVal.getChildren());
       }

       return retVal;
    }

    // rest omitted.
}

Reported by justin.thomas1 on 2010-02-18 01:34:46

from gwt.

dankurka avatar dankurka commented on July 21, 2024
Such an old issue..  Here's a patch of the solution I've been using, brought up to
GWT coding standards.  It uses a HasTreeItems interface to allow the same add/iterate
code to be used between Tree and Treeitem.  For naming consistency with exist add and
remove functions, I chose getItem* over getChild*, and deprecated TreeItem.getChild*.
 I also added an itemIterator method to iterate through the immediate children of a
node, separate from the treeItemIterator method of Tree that runs through the entire
tree, although this is not strictly necessary.

I think this is the right solution vs exposing the root TreeItem, as the latter
really would be an inelegant workaround.  So can we finally fix this issue?

Reported by kozura on 2010-02-28 04:57:55


- _Attachment: [Tree.diff](https://storage.googleapis.com/google-code-attachments/google-web-toolkit/issue-30/comment-19/Tree.diff)_ - _Attachment: [TreeItem.diff](https://storage.googleapis.com/google-code-attachments/google-web-toolkit/issue-30/comment-19/TreeItem.diff)_ - _Attachment: [HasTreeItems.java](https://storage.googleapis.com/google-code-attachments/google-web-toolkit/issue-30/comment-19/HasTreeItems.java)_

from gwt.

dankurka avatar dankurka commented on July 21, 2024
Is it really so difficult to resolve this issue? Give me developer rights on the GWT

project and I'll do it if you are short on resources.

Reported by m.zdila on 2010-05-26 07:36:47

from gwt.

dankurka avatar dankurka commented on July 21, 2024
I've been using an approach similar to kozura's with no problems...

Reported by tuckerpmt on 2010-10-02 18:18:55

from gwt.

dankurka avatar dankurka commented on July 21, 2024

Reported by [email protected] on 2011-01-13 03:09:43

  • Labels added: Type-Feature
  • Labels removed: Type-Enhancement

from gwt.

dankurka avatar dankurka commented on July 21, 2024

Reported by [email protected] on 2011-01-13 03:16:18

  • Status changed: PatchesWelcome
  • Labels removed: Milestone-Planned

from gwt.

dankurka avatar dankurka commented on July 21, 2024
Hmm I notice (since it conflicted with my own when updating) that the HasTreeItems interface
has been added in GWT 2.2.  However some methods are still missing from it that really
should be there to be complete:

getItem(int index)
getItemCount()
getItemIndex(TreeItem child)

I also happen to find itemIterator from my patch to be useful, but not required.

Reported by kozura on 2011-02-19 04:26:09

from gwt.

dankurka avatar dankurka commented on July 21, 2024
review in gerrit: https://gwt-review.googlesource.com/#/c/2520/

Reported by [email protected] on 2013-04-15 13:31:59

  • Status changed: ReviewPending

from gwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.