Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7516155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:02:47+00:00 2026-05-30T01:02:47+00:00

The problem is that I don’t want a user to be able to close

  • 0

The problem is that I don’t want a user to be able to close a branch of the tree if that branch has the currently selected node. The main problem is, that GWT Tree seems to forget the selection once you close a branch. This is confusing. I was looking at event handlers like CloseHandler, but I don’t think I can prevent the close from happening (or should I attempt to immediately re-open the same node?)

For context, here’s the tree I’m talking about:

http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/user/client/ui/Tree.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:02:48+00:00Added an answer on May 30, 2026 at 1:02 am

    From reading how Tree and TreeItem work, it looks like the best option is to subclass TreeItem and override setState(boolean, boolean) to return early if some condition is true.

    public class CustomTreeItem extends TreeItem {
        @Override
        public void setState(boolean open, boolean fireEvents) {
            //check if we want to allow the item to close
            if (!open && !mayClose()) {
                return;
            }
            super.setState(boolean open, boolean fireEvents);
        }
        /**
         * Returns true if the item may be closed, due to some specific rules
         */
        public boolean mayClose() {
            // your check goes here
        }
    }
    

    The downside of this is that you will need to create one of your own instances where ever you want this logic to work. One way to make that easier would be to override the various addItem(...) and addTextItem(...) methods as well, to always create instances of this subclass.


    The CloseEvent is fired (looking at GWT 2.4.0, this may be different in older versions) from within the method Tree.fireStateChanged(TreeItem, boolean. This is a package protected method, so not accessible, and not the method which doesnt the actual heavy lifting of changing the dom.

    Tree.fireStateChanged is called from TreeItem.setState, the method overridden above. This method appears responsible not only for checking if it makes sense to open, but also avoiding redraw if not needed, and performing the actual redraw. It calls to the Tree to ask it to fire the events. Changing this code will ensure that even in the cases where events are not fired (not found in the GWT code, you may have some), it will still perform your logic.

    TreeItem.setState(boolean,boolean) is called from two places within GWT, one from TreeItem.setState(boolean), as a convenience methods, and once when the user clicks an element (see Tree.elementClicked(Element)). The other override, TreeItem.setState(boolean) is called from three places, all concerned with keyboard navigation. From this, we can be sure that this is the main methods concerned with changing the tree expand/collapse status, and we can be confident that changing it will correctly affect the tree’s behavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings SO, I have a weird problem that I don't seem to be able
I have problem that I don't seem to be able to solve. I have
So I have a problem that I don't really know how to go about.
I'm a newbie on Java EE and got a problem that I don't understand
I like using LINQ to SQL. The only problem is that I don't like
One problem that I come across regularly and yet don't have a solution to
i have a problem, that i don't know how to solve it. i have
So, one problem pattern that I keep coming across and don't have a good
I have a problem drawing something quickly in .NET. I don't think that any
The problem that I am having has to do with the need to keep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.