-1

Can anyone suggest how I might to create a database driven Tree Menu which will call a form?

I have created a Tree Menu, but it is hard coded (not dynamic). I also have to introduce some click events for each menu item to call a form. But I am unsure how to go about doing this.

So my questions are how can I create a tree menu dynamically and what is the technique for handling click events to call any form (also dynamic)?

Leigh
  • 28,765
  • 10
  • 55
  • 103
Tanvir
  • 1
  • 1
  • 2
  • Your question is a bit too broad. [What have you tried](http://mattgemmell.com/2008/12/08/what-have-you-tried/) with regard to dynamic trees? What problems are you having? – Leigh Jun 18 '12 at 02:54

2 Answers2

0

first of all, you need some parts of the tree that are as you said hard coded. you can query your database, get the data you need, and the create whatever you want (checkboxes,treeitems etc) using this data and add it to your tree. you don't have to worry about giving different names to everything, just make sure that your listeners are correct.

mariosk89
  • 944
  • 1
  • 11
  • 31
0

please find the code to create dynamic tree. in this i am taking data from text box and adding it to tree.

HorizontalPanel hpanl = new HorizontalPanel();

    tree.addSelectionHandler( new SelectionHandler<TreeItem>() {

        @Override
        public void onSelection( SelectionEvent<TreeItem> event ) {

            tbox.setText( getChildToParentRoot( event ) );
            System.out.println("Height::"+event.getSelectedItem().getOffsetHeight()+"Weight::"+event.getSelectedItem().getOffsetWidth());
            System.out.println( "Selected::" + event.getSelectedItem().getParentItem() );
            Window.alert( "Selected Item:" + event.getSelectedItem().getParentItem().getText() );

        }

        private String getChildToParentRoot( SelectionEvent<TreeItem> event ) {
            TreeItem child = event.getSelectedItem();
            String st = null;
            while ( child.getParentItem() != null ) {
                st = st + child.getText();
                child = child.getParentItem();
            }
            st = st + child.getText();

            return st;
        }

    } );

    hpanl.setBorderWidth( 1 );
    hpanl.setSpacing( 5 );
    hpanl.add( option );
    Button subtbtn = new Button( "Add" );
    subtbtn.addClickHandler( new ClickHandler() {

        @Override
        public void onClick( ClickEvent event ) {
            String option1 = option.getText();
            System.out.println( "TextBox Value::" + option1 );
            if ( tree.getSelectedItem() == null ) {
                tree.addItem( new TreeItem( option1 ) );
            }
            else {

                TreeItem current = tree.getSelectedItem();

                current.setSelected( false );
                current.addItem( new TreeItem( option1 ) );
            }

        }
    } );
    Button delete = new Button( "Delete" );
    delete.addClickHandler( new ClickHandler() {

        @Override
        public void onClick( ClickEvent event ) {
            tree.getSelectedItem().remove();

        }
    } );
    hpanl.add( subtbtn );
    hpanl.add( delete );
    VerticalPanel vpanel = new VerticalPanel();

    vpanel.add( tree );
    hpanl.add( tbox );
    hpanl.add( vpanel );
    RootPanel.get().add( hpanl );