예제 #1
0
 TabItem findItem(String value, TabItem[] items) {
   for (int i = 0; i < items.length; i++) {
     TabItem item = items[i];
     if (item.getText().equals(value)) return item;
   }
   return null;
 }
예제 #2
0
  /**
   * Creates all the tabs in the detail pane to display the information for a given node.
   *
   * @param composite
   * @param node
   */
  public static void createTabs(Composite composite, INode node) {

    List<IDetailTab> tabs = getTabs(node);

    if (tabs == null || tabs.size() == 0) {
      // no detail found..

      Label label = new Label(composite, SWT.FILL);
      label.setText(
          Messages.getString("DatabaseDetailView.Tab.Unavailable") + " " + node.getLabelText());
      label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

      return;
    }

    // create tabs
    TabFolder tabFolder = new TabFolder(composite, SWT.NULL);

    // only init tabs when the tab becomes active
    tabFolder.addSelectionListener(
        new SelectionListener() {

          public void widgetDefaultSelected(SelectionEvent e) {

            // noop
          }

          public void widgetSelected(SelectionEvent e) {

            TabItem tabItem = (TabItem) e.item;
            IDetailTab tab = (IDetailTab) tabItem.getData();
            if (tab != null) {

              // create composite on tab and fill it..
              Composite detailComposite = new Composite(tabItem.getParent(), SWT.FILL);
              tabItem.setControl(detailComposite);
              detailComposite.setLayout(new FillLayout());
              tab.fillComposite(detailComposite);
              detailComposite.layout();

              // store tab name, so we can reselect when other node is
              // chosen
              DetailTabManager.setActiveTabName(tabItem.getText());
            }
          }
        });

    // add tabs to folder
    int tabIndex = 0;
    for (IDetailTab detailTab : tabs) {

      // create tab
      TabItem tabItem = new TabItem(tabFolder, SWT.NULL);
      tabItem.setText(detailTab.getLabelText());
      tabItem.setToolTipText(detailTab.getLabelToolTipText());

      // store tab so we can fill later
      tabItem.setData(detailTab);

      // reselect same tab as was previous selected
      if (tabItem.getText() != null && _activeTabName != null) {
        if (tabItem.getText().equals(_activeTabName)) {
          tabFolder.setSelection(tabIndex);
        }
      }

      tabIndex++;
    }

    // load data for active tab, default to first one if none is selected
    tabIndex = tabFolder.getSelectionIndex();
    if (tabIndex == -1) {
      tabIndex = 0;
    }

    TabItem tabItem = tabFolder.getItem(tabIndex);
    if (tabItem != null) {
      Composite detailComposite = new Composite(tabItem.getParent(), SWT.FILL);
      tabItem.setControl(detailComposite);
      detailComposite.setLayout(new FillLayout());
      IDetailTab tab = (IDetailTab) tabItem.getData();
      tab.fillComposite(detailComposite);
      detailComposite.layout();
    }

    tabFolder.layout();
  }