Example #1
0
  public Ribbon(RibbonDef conf, final RibbonCallback callback) {
    this.callback = callback;
    m_conf = conf;

    FlowPanel panel = new FlowPanel();

    m_tabBar =
        new TabBar(
            new TabBar.Callback() {
              @Override
              public void onSelection(int index) {
                m_tabPanel.setWidget(m_tabs.get(index));
              }
            });
    panel.add(m_tabBar);

    m_tabPanel = new SimplePanel();
    panel.add(m_tabPanel);

    /*
     * Definition of the Ribbon
     */

    m_tabs = new ArrayList<Widget>();
    for (int i = 0; i < conf.tabs.size(); i++) {
      m_tabBar.addTab(conf.tabs.get(i).name);

      final ButtonBar bar = new ButtonBar();
      for (int j = 0; j < conf.tabs.get(i).buttons.size(); j++) {
        final Object obj = conf.tabs.get(i).buttons.get(j).obj;

        Button button =
            new Button(
                conf.tabs.get(i).buttons.get(j).name,
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                    callback.onRibbonChange(obj);
                  }
                });

        bar.addButton(button, obj);
      }
      m_tabs.add(bar);
    }

    initWidget(panel);
    panel.setSize("100%", "100%");

    setStyleName("Ribbon");
    m_tabPanel.setStyleName("RibbonPanel");

    if (m_tabBar.getTabCount() > 0) m_tabBar.selectTab(0);
  }
Example #2
0
  @Override
  public void setTabText(String id, String text) {
    int index = -1;
    for (int i = 0; i < m_conf.tabs.size(); i++)
      if (m_conf.tabs.get(i).id.equals(id)) {
        index = i;
        break;
      }
    if (index < 0) return;

    m_tabBar.setTabText(index, text);
  }
Example #3
0
  @Override
  public void selectButton(Object obj) {
    for (int i = 0; i < m_conf.tabs.size(); i++) {
      ButtonBar bar = (ButtonBar) m_tabs.get(i);
      bar.selectButton(obj);

      for (int j = 0; j < m_conf.tabs.get(i).buttons.size(); j++) {
        if (m_conf.tabs.get(i).buttons.get(j).obj == obj) {
          m_tabBar.selectTab(i);
        }
      }
    }
  }