Example #1
0
  public FolderBrowser(FileSystemModel fsm) {
    if (fsm == null) {
      throw new NullPointerException("fsm");
    }

    this.fsm = fsm;
    this.model = new FolderModel();
    this.listbox = new ListBox<Object>(model);
    this.curFolderGroup = new BoxLayout();

    curFolderGroup.setTheme("currentpathbox");
    curFolderGroup.setScroll(true);
    curFolderGroup.setClip(true);
    curFolderGroup.setAlignment(Alignment.BOTTOM);

    listbox.addCallback(
        new CallbackWithReason<ListBox.CallbackReason>() {
          private Object lastSelection;

          public void callback(ListBox.CallbackReason reason) {
            if (listbox.getSelected() != ListBox.NO_SELECTION) {
              if (reason.actionRequested()) {
                setCurrentFolder(model.getFolder(listbox.getSelected()));
              }
            }
            Object selection = getSelectedFolder();
            if (selection != lastSelection) {
              lastSelection = selection;
              fireSelectionChangedCallback();
            }
          }
        });

    add(listbox);
    add(curFolderGroup);

    setCurrentFolder(null);
  }