FileDocCategorySizeDatePackage
Lists.javaAPI DocExample8316Mon Aug 27 20:12:26 BST 2007com.google.gwt.sample.kitchensink.client

Lists

public class Lists extends Sink implements com.google.gwt.user.client.ui.TreeListener, com.google.gwt.user.client.ui.ChangeListener
Demonstrates {@link com.google.gwt.user.client.ui.ListBox}.

Fields Summary
private static final String[]
stringLists
private static final String[]
words
private static Proto[]
fProto
private com.google.gwt.user.client.ui.ListBox
combo
private com.google.gwt.user.client.ui.ListBox
list
private com.google.gwt.user.client.ui.MultiWordSuggestOracle
oracle
private com.google.gwt.user.client.ui.SuggestBox
suggestBox
private com.google.gwt.user.client.ui.Tree
tree
Constructors Summary
public Lists(Sink.Images images)


     
    combo.setVisibleItemCount(1);
    combo.addChangeListener(this);
    list.setVisibleItemCount(10);
    list.setMultipleSelect(true);

    for (int i = 0; i < stringLists.length; ++i) {
      combo.addItem("List " + i);
    }
    combo.setSelectedIndex(0);
    fillList(0);

    list.addChangeListener(this);

    for (int i = 0; i < words.length; ++i) {
      oracle.add(words[i]);
    }
    
    VerticalPanel suggestPanel = new VerticalPanel();
    suggestPanel.add(new Label("Suggest box:"));
    suggestPanel.add(suggestBox);

    HorizontalPanel horz = new HorizontalPanel();
    horz.setVerticalAlignment(HorizontalPanel.ALIGN_TOP);
    horz.setSpacing(8);
    horz.add(combo);
    horz.add(list);
    horz.add(suggestPanel);

    VerticalPanel panel = new VerticalPanel();
    panel.setHorizontalAlignment(VerticalPanel.ALIGN_LEFT);
    panel.add(horz);
    initWidget(panel);

    tree = new Tree(images);
    for (int i = 0; i < fProto.length; ++i) {
      createItem(fProto[i]);
      tree.addItem(fProto[i].item);
    }

    tree.addTreeListener(this);
    tree.setWidth("20em");
    horz.add(tree);
  
Methods Summary
private voidcreateItem(com.google.gwt.sample.kitchensink.client.Lists$Proto proto)

    proto.item = new TreeItem(proto.text);
    proto.item.setUserObject(proto);
    if (proto.children != null) {
      proto.item.addItem(new PendingItem());
    }
  
private voidfillList(int idx)

    // Set the contents of the list box to reflect the combo selection.
    list.clear();
    String[] strings = stringLists[idx];
    for (int i = 0; i < strings.length; ++i) {
      list.addItem(strings[i]);
    }
  
public static SinkInfoinit(Sink.Images images)


        
    return new SinkInfo("Lists",
        "<h2>Lists and Trees</h2>" +
        "<p>GWT provides a number of ways to display lists and trees. This " +
        "includes the browser's built-in list and drop-down boxes, as well as " +
        "the more advanced suggestion combo-box and trees.</p><p>Try typing " +
        "some text in the SuggestBox below to see what happens!</p>") {

      public Sink createInstance() {
        return new Lists(images);
      }
    };
  
public voidonChange(com.google.gwt.user.client.ui.Widget sender)

    if (sender == combo) {
      fillList(combo.getSelectedIndex());
    } else if (sender == list) {
    }
  
public voidonShow()

  
public voidonTreeItemSelected(com.google.gwt.user.client.ui.TreeItem item)

  
public voidonTreeItemStateChanged(com.google.gwt.user.client.ui.TreeItem item)

    TreeItem child = item.getChild(0);
    if (child instanceof PendingItem) {
      item.removeItem(child);

      Proto proto = (Proto) item.getUserObject();
      for (int i = 0; i < proto.children.length; ++i) {
        createItem(proto.children[i]);
        item.addItem(proto.children[i].item);
      }
    }