/**
   * Creates an instance of a ControlExample embedded inside the supplied parent Composite.
   *
   * @param parent the container of the example
   */
  public ControlExample(Composite parent) {
    initResources();
    tabFolder = new TabFolder(parent, SWT.NONE);
    tabs = createTabs();
    for (Tab tab : tabs) {
      TabItem item = new TabItem(tabFolder, SWT.NONE);
      item.setText(tab.getTabText());
      item.setControl(tab.createTabFolderPage(tabFolder));
      item.setData(tab);
    }

    /* Workaround: if the tab folder is wider than the screen,
     * Mac platforms clip instead of somehow scrolling the tab items.
     * We try to recover some width by using shorter tab names. */
    Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = parent.getMonitor().getClientArea();
    boolean isMac = SWT.getPlatform().equals("cocoa");
    if (size.x > monitorArea.width && isMac) {
      TabItem[] tabItems = tabFolder.getItems();
      for (int i = 0; i < tabItems.length; i++) {
        tabItems[i].setText(tabs[i].getShortTabText());
      }
    }
    startup = false;
  }
Example #2
0
 @Override
 public void handleMessage(int code, Object data) {
   switch (code) {
       // First re-check visibility of all tabs.
       // While tab deletion can be made on the fly,
       // tabs adding will be made by re-creation
       // of all elements, to preserve their order
     case ICPropertyTab.MANAGEDBUILDSTATE:
       if (folder == null) {
         if (itabs == null || itabs.size() == 0) return;
         ICPropertyTab t = itabs.get(0).tab;
         if (!t.canBeVisible()) t.handleTabEvent(ICPropertyTab.VISIBLE, null);
         return;
       }
       boolean willAdd = false;
       TabItem[] ts = folder.getItems();
       int x = folder.getSelectionIndex();
       String currHeader = (x == -1) ? null : ts[x].getText();
       for (int i = 0; i < itabs.size(); i++) {
         InternalTab itab = itabs.get(i);
         TabItem ti = null;
         for (TabItem element2 : ts) {
           if (element2.isDisposed()) continue;
           if (element2.getData() == itab.tab) {
             ti = element2;
             break;
           }
         }
         if (itab.tab.canBeVisible()) {
           if (ti == null) {
             willAdd = true;
             break;
           }
         } else {
           if (ti != null) ti.dispose();
         }
       }
       // in case of new tab added,
       // we have to dispose and re-create all tabs
       if (willAdd) {
         for (int j = 0; j < ts.length; j++)
           if (ts[j] != null && !ts[j].isDisposed()) ts[j].dispose();
         TabItem ti = null;
         for (int i = 0; i < itabs.size(); i++) {
           InternalTab itab = itabs.get(i);
           if (itab.tab.canBeVisible()) {
             TabItem currTI = itab.createOn(folder);
             if (currHeader != null && currHeader.equals(itab.text)) ti = currTI;
           }
         }
         if (ti != null) folder.setSelection(ti);
       }
       break;
   }
 }
  /**
   * Returns the tab for the given part, or null if there is no such tab
   *
   * @param part the part being searched for
   * @return the tab for the given part, or null if there is no such tab
   */
  protected final TabItem getTab(IPresentablePart part) {
    TabItem[] items = tabFolder.getItems();

    int idx = indexOf(part);

    if (idx < items.length) {
      return items[idx];
    }

    return null;
  }
Example #4
0
  /** Adjust the layout of the field editors so that they are properly aligned. */
  protected void adjustGridLayout() {
    if (folder != null) {
      TabItem[] items = folder.getItems();
      for (int j = 0; j < items.length; j++) {
        GridLayout layout = ((GridLayout) ((Composite) items[j].getControl()).getLayout());
        layout.numColumns = 3;
        layout.marginHeight = 5;
        layout.marginWidth = 5;
      }
    }

    // need to call super.adjustGridLayout() since fieldEditor.adjustForNumColumns() is protected
    super.adjustGridLayout();

    // reset the main container to a single column
    ((GridLayout) super.getFieldEditorParent().getLayout()).numColumns = 1;
  }
  /**
   * Returns the index of the tab for the given part, or returns tabFolder.getItemCount() if there
   * is no such tab.
   *
   * @param part part being searched for
   * @return the index of the tab for the given part, or the number of tabs if there is no such tab
   */
  private final int indexOf(IPresentablePart part) {
    if (part == null) {
      return tabFolder.getItemCount();
    }

    TabItem[] items = tabFolder.getItems();

    for (int idx = 0; idx < items.length; idx++) {
      IPresentablePart tabPart = getPartForTab(items[idx]);

      if (part == tabPart) {
        return idx;
      }
    }

    return items.length;
  }
Example #6
0
  public void createWidgets(Composite c) {
    GridData gd;
    parentComposite = new Composite(c, SWT.NONE);
    parentComposite.setLayoutData(gd = new GridData(GridData.FILL_BOTH));
    gd.widthHint = 800;
    itabs.clear();
    if (!isSingle()) {
      parentComposite.setLayout(new FillLayout());
      folder = new TabFolder(parentComposite, SWT.NONE);
      //			folder.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));
    }
    loadExtensionsSynchronized(parentComposite);

    // Set listener after data load, to avoid firing
    // selection event on not-initialized tab items
    if (folder != null) {
      folder.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
              if (folder.getSelection().length > 0) {
                updateSelectedTab();
              }
            }
          });
      if (folder.getItemCount() > 0) {
        int selectedTab = 0;
        Class<? extends ICPropertyTab> recentTab = recentTabs.get(getClass());
        if (recentTab != null) {
          TabItem[] tabs = folder.getItems();
          for (int i = 0; i < tabs.length; i++) {
            TabItem control = tabs[i];
            if (recentTab.isInstance(control.getData())) {
              selectedTab = i;
              break;
            }
          }
        }
        folder.setSelection(selectedTab);
        updateSelectedTab();
      }
    }
  }
Example #7
0
 /**
  * Gets the "Example" widget children's items, if any.
  *
  * @return an array containing the example widget children's items
  */
 Item[] getExampleWidgetItems() {
   return tabFolder1.getItems();
 }