Comments (20)
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.
Reported by gwt.team.ecc
on 2006-10-03 19:06:03
from gwt.
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.
Reported by gwt.team.ecc
on 2006-10-09 12:09:48
- Status changed:
Accepted
from gwt.
...
Reported by edgrolan722
on 2006-11-14 22:45:18
from gwt.
xcxc
Reported by chandi.rajan
on 2007-01-16 02:45:47
from gwt.
Reported by gwt.team.morrildl
on 2007-02-01 14:20:08
- Labels added: Category-UI
- Labels removed: Release-1.1.10
from gwt.
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.
Reported by [email protected]
on 2008-04-08 15:09:44
- Labels added: Milestone-Planned
from gwt.
Reported by [email protected]
on 2008-04-28 22:59:06
from gwt.
Reported by [email protected]
on 2008-10-21 21:54:58
- Labels removed: priority-low
from gwt.
Reported by ecc%[email protected]
on 2009-01-05 15:16:58
from gwt.
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.
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.
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.
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.
Reported by [email protected]
on 2011-01-13 03:09:43
- Labels added: Type-Feature
- Labels removed: Type-Enhancement
from gwt.
Reported by [email protected]
on 2011-01-13 03:16:18
- Status changed:
PatchesWelcome
- Labels removed: Milestone-Planned
from gwt.
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.
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)
- DialogBox has issues when it is hidden and the browser is resized. HOT 3
- Replace document.write('<script ...>') with document.createElement('script') HOT 2
- GWT 2.10.0 Super Dev Mode is not working in eclipse HOT 1
- CSP inline-script issue in nocache.js HOT 2
- Gwt emulation issue with java 11 HOT 5
- CompileReport exception HOT 5
- NPE when configuration property missing in SuperDevMode HOT 8
- Super dev mode fails with jetty-web.xml HOT 9
- Integrating gwt into OSS-Fuzz
- Ensure Java 8/9/10/11 tests are run HOT 3
- Is it possible to use the greater sign (>) with pseudoclasses in gss? HOT 5
- Update tapestry version HOT 1
- Investigate removing of chunking behavior from installScriptEarlyDownload
- Update ezt tool so GWT build can run under Java 17
- Update copyright entries, style check to reference GWT Project Authors
- Allow listening for request cancelation and possibly completion HOT 2
- Bound mismatch compilation error HOT 1
- Java 11 JRE emulation HOT 1
- Plan for a new official release - oficial maven dependency HOT 2
- 2.10 artifacts on maven repositories seem to be broken. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gwt.