4

i am new here and in GWT, and my english is not so good, so please excuse me. i need to create a web site, using GWT. the website has hierarchical structure: main global caption, and couple of buttons. each button opens new part of the application, which has its own sub tabs. each one of the sub-tab suppose to be navigatable. for example:

Main form

-> application issues

---> preferences ---> create something --->edit something

-> administration

---> user management --> policies

now, i want to understand what is the best option to use GWT. i thought of two options: 1. there will be in the entry point main activity. in its start function we will create ActivityManager for each sub-menu (= sub tab = child). each sub menu will create activity managers for each its sub menu, and so on. we will set a display for each activity manager, and fire change place event.

the problem is that i need to manage the places (all the places should go to the main activity, that should takes its params and delegate to the sub places, etc.) otherwise, when the user copy and paste the url, it will cause only the child activity to start, and the parent activity to be not initialized.

  1. i can create OOP hierarchy of widges, so - there will be an activity for each leaf in the hierarchy structure tree. there will be also matching widges hierarchy. each leaf widge contains its own components, and all its parent components (such as - the main caption of the form) in this option, there is only one active activity.

what is the best option? how would you implement hierarchy structure?

thanks....

yonatan
  • 177
  • 1
  • 2
  • 14
  • I may have misunderstood your question, and if so, I am sorry. I once wrote an answer describing how I implemented a gwt app using MVP. Maybe there are some ideas in there you can use? Find it here: http://stackoverflow.com/questions/2832779/is-there-a-recommended-way-to-use-the-observer-pattern-in-mvp-using-gwt/2832919#2832919 – Mia Clarke Mar 03 '11 at 11:08
  • Can you clarify your question? Are you already using MVP, but having trouble figuring out how to separate the different Activities? – Peter Wagener May 07 '11 at 12:40

1 Answers1

0

The best option for the hierarchy of menus is to use nested TabPanel widgets. These can go as deep as you need and is a great alternative to building menus.

I see you also want to manage two things:

  1. When the user inputs a URL, you want him to land on the correct tab.
  2. When the user navigates between tabs, you want the URL to change according to where he is going.

Landing the user on the correct tab

For #1, you need to manage the user arriving to your app in method onModuleLoad. See this piece of code for selecting the correct tab.

public void onModuleLoad() {
    tabPanel = new TabPanel();

    tabPanel.add(new HTML("<h1>Page 0 Content: Llamas</h1>"), " Page 0 ");
    tabPanel.add(new HTML("<h1>Page 1 Content: Alpacas</h1>"), " Page 1 ");
    tabPanel.add(new HTML("<h1>Page 2 Content: Camels</h1>"), " Page 2 ");

    String hash = Window.Location.getHash();
    if (hash != null && hash.startsWith("#page")) {
        int tabIndex = Integer.parseInt(hash.substring(5));
        tabPanel.selectTab(tabIndex);
    } else {
        tabPanel.selectTab(0);
    }
    RootPanel.get().add(tabPanel);
}

This code

Managing navigation history

See this page in GWT documentation. My code above was taken from this page, but in my example I removed History management.

In both cases, the key concept is to find the correct widget based on the url hash and selecting it.

Leonel
  • 28,541
  • 26
  • 76
  • 103