Hi David,

Out of curiosity I tried that one and it works. Actually you shud first set
the widget of the tree item as text box, then call the setSelected(true) for
the tree item and then set the focus to the text box. This works in FF.

*package* litty.test.client;



*import* com.google.gwt.core.client.EntryPoint;

*import* com.google.gwt.user.client.Window;

*import* com.google.gwt.user.client.ui.FocusListenerAdapter;

*import* com.google.gwt.user.client.ui.KeyboardListenerAdapter;

*import* com.google.gwt.user.client.ui.RootPanel;

*import* com.google.gwt.user.client.ui.TextBox;

*import* com.google.gwt.user.client.ui.Tree;

*import* com.google.gwt.user.client.ui.TreeItem;

*import* com.google.gwt.user.client.ui.TreeListener;

*import* com.google.gwt.user.client.ui.Widget;



*public* *class* Home *implements* EntryPoint, TreeListener {



      Tree homeTree;



      *public* *void* onModuleLoad() {

            init();

      }



      *private* *void* init() {

            homeTree = *new* Tree();

            TreeItem root1 = *new* TreeItem("ABC");

            root1.addItem("ABC1");

            root1.addItem("ABC2");

            root1.addItem("ABC3");

            TreeItem root2 = *new* TreeItem("DEF");

            root2.addItem("DEF1");

            root2.addItem("DEF2");

            TreeItem root3 = *new* TreeItem("EFG");

            root3.addItem("EFG1");

            root3.addItem("EFG2");

            root3.addItem("EFG3");

            homeTree.addItem(root1);

            homeTree.addItem(root2);

            homeTree.addItem(root3);

            homeTree.addTreeListener(*this*);

            RootPanel.*get*().add(homeTree);

      }



      *public* *void* onTreeItemSelected(*final* TreeItem item) {

            *if* (!(item.getWidget() != *null* && item.getWidget() *
instanceof* TextBox)) {

                  *final* String originalText = item.getText();

                  *final* TextBox box = *new* TextBox();

                  box.setText(originalText);

                  item.setWidget(box);

                  item.setSelected(*true*);

                  box.selectAll();

                  box.setFocus(*true*);

                  box.addKeyboardListener(*new* KeyboardListenerAdapter() {

                        *public* *void* onKeyPress(Widget sender, *char*keyCode,

                                    *int* modifiers) {

                              *if* (keyCode == *KEY_ENTER*) {

                                    item.setText(box.getText());

                              } *else* *if* (keyCode == *KEY_ESCAPE*) {

                                    item.setText(originalText);

                              }

                        }

                  });

                  box.addFocusListener(*new* FocusListenerAdapter() {

                        *public* *void* onLostFocus(Widget sender) {

                              Window.*alert*("Focus lost");

                              item.setText(box.getText());

                        }

                  });

            }

      }



      *public* *void* onTreeItemStateChanged(TreeItem item) {

            // *TODO* Auto-generated method stub

      }

}


Hope this helps.

- Litty Preeth

On Tue, Jan 20, 2009 at 9:46 PM, David Durham <[email protected]>wrote:

>
> On Mon, Jan 19, 2009 at 11:04 PM, Litty Preeth <[email protected]>
> wrote:
> > May be you should first select the treeitem and then change the String
> item
> > into a TextBox item.
>
> Yeah, maybe it would.  If anyone knows for sure, please say so.
> Otherwise, I've moved on to writing my own.
>
>
> -Dave
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to