Package org.eclipse.swt.widgets

Examples of org.eclipse.swt.widgets.CoolBar


   * and update the coolbar.
   */
  public void advise(boolean fromUpdate) {

    /* Retrieve Control if available */
    CoolBar barControl = null;
    if (fManager instanceof CoolBarManager)
      barControl = ((CoolBarManager) fManager).getControl();

    /* Disable Redraw to avoid Flicker */
    if (barControl != null && fromUpdate)
      barControl.getShell().setRedraw(false);

    try {

      /* First Remove All */
      fManager.removeAll();

      /* Load Toolbar Mode */
      CoolBarMode mode = CoolBarMode.values()[fPreferences.getInteger(DefaultPreferences.TOOLBAR_MODE)];

      /* Load and Add Items */
      int[] items = fPreferences.getIntegers(DefaultPreferences.TOOLBAR_ITEMS);
      if (items == null || items.length == 0)
        items = new int[] { CoolBarItem.SPACER.ordinal() };

      ToolBarManager currentToolBar = new ToolBarManager(mode == CoolBarMode.IMAGE_TEXT_HORIZONTAL ? (SWT.FLAT | SWT.RIGHT) : SWT.FLAT);
      for (int id : items) {
        final CoolBarItem item = CoolBarItem.values()[id];
        if (item != null) {

          /* Separator: Start a new Toolbar */
          if (item == CoolBarItem.SEPARATOR) {
            fManager.add(currentToolBar);
            currentToolBar = new ToolBarManager(mode == CoolBarMode.IMAGE_TEXT_HORIZONTAL ? (SWT.FLAT | SWT.RIGHT) : SWT.FLAT);
          }

          /* Spacer */
          else if (item == CoolBarItem.SPACER) {
            ActionContributionItem contribItem = new ActionContributionItem(new Action("") { //$NON-NLS-1$
                  @Override
                  public boolean isEnabled() {
                    return false;
                  }
                });
            currentToolBar.add(contribItem);
          }

          /* Any other Item */
          else {
            ActionContributionItem contribItem = new CoolBarActionContributionitem(item, getAction(item, mode, currentToolBar));
            contribItem.setId(item.getId());
            if (mode == CoolBarMode.IMAGE_TEXT_HORIZONTAL || mode == CoolBarMode.IMAGE_TEXT_VERTICAL)
              contribItem.setMode(ActionContributionItem.MODE_FORCE_TEXT);

            /* Add to Toolbar */
            currentToolBar.add(contribItem);
          }
        }
      }

      /* Add latest Toolbar Manager to Coolbar too */
      fManager.add(currentToolBar);

      /* Ensure Updates are properly Propagated */
      if (fromUpdate) {

        /* Update Overall Coolbar UI */
        fManager.update(true);
        if (barControl != null) {
          boolean isLocked = barControl.getLocked();
          barControl.setLocked(!isLocked);
          barControl.setLocked(isLocked);
        }

        /* Update Action UI */
        updateActions(OwlUI.getActivePart(fWindow));
      }
    } finally {
      if (barControl != null && fromUpdate)
        barControl.getShell().setRedraw(true);
    }
  }
View Full Code Here


     * @return the cool bar control
     */
    public CoolBar createControl(Composite parent) {
        Assert.isNotNull(parent);
        if (!coolBarExist()) {
            coolBar = new CoolBar(parent, itemStyle);
            coolBar.setMenu(getContextMenuControl());
            coolBar.setLocked(false);
            update(false);
        }
        return coolBar;
View Full Code Here

    if (!horizontal && verticalHandleSize != -1) {
      return verticalHandleSize;
    }

    // Must be the first time, calculate the value
    CoolBar bar = new CoolBar(layoutComposite, horizontal ? SWT.HORIZONTAL
        : SWT.VERTICAL);

    CoolItem item = new CoolItem(bar, SWT.NONE);

    Label ctrl = new Label(bar, SWT.PUSH);
    ctrl.setText("Button 1"); //$NON-NLS-1$
    Point size = ctrl.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    Point ps = item.computeSize(size.x, size.y);
    item.setPreferredSize(ps);
    item.setControl(ctrl);

    bar.pack();

    // OK, now the difference between the location of the CB and the
    // location of the
    Point bl = ctrl.getLocation();
    Point cl = bar.getLocation();

    // Toss them now...
    ctrl.dispose();
    item.dispose();
    bar.dispose();

    // The 'size' is the difference between the start of teh CoolBar and
    // start of its first control
    int length;
    if (horizontal) {
View Full Code Here

    private void createControlForTop() {
        perspectiveBar = createBarManager(SWT.HORIZONTAL);

        perspectiveCoolBarWrapper = new CacheWrapper(topBar);
        perspectiveCoolBar = new CoolBar(
                perspectiveCoolBarWrapper.getControl(), SWT.FLAT);
        coolItem = new CoolItem(perspectiveCoolBar, SWT.DROP_DOWN);
        toolbarWrapper = new CacheWrapper(perspectiveCoolBar);
        perspectiveBar.createControl(toolbarWrapper.getControl());
        coolItem.setControl(toolbarWrapper.getControl());
View Full Code Here

        CoolItem item = (CoolItem) event.widget;
        Control control = item.getControl();
        if ((control instanceof ToolBar) == false) {
            return;
        }
        CoolBar coolBar = item.getParent();
        ToolBar toolBar = (ToolBar) control;
        Rectangle toolBarBounds = toolBar.getBounds();
        ToolItem[] items = toolBar.getItems();
        ArrayList hidden = new ArrayList();
        for (int i = 0; i < items.length; ++i) {
            Rectangle itemBounds = items[i].getBounds();
            if (!((itemBounds.x + itemBounds.width <= toolBarBounds.width) && (itemBounds.y
                    + itemBounds.height <= toolBarBounds.height))) {
                hidden.add(items[i]);
            }
        }

        // Create a pop-up menu with items for each of the hidden buttons.
        if (chevronMenuManager != null) {
            chevronMenuManager.dispose();
        }
        chevronMenuManager = new MenuManager();
        for (Iterator i = hidden.iterator(); i.hasNext();) {
            ToolItem toolItem = (ToolItem) i.next();
            IContributionItem data = (IContributionItem) toolItem.getData();
            if (data instanceof ActionContributionItem) {
                ActionContributionItem contribution = new ActionContributionItem(
                        ((ActionContributionItem) data).getAction());
                chevronMenuManager.add(contribution);
            } else if (data instanceof SubContributionItem) {
                IContributionItem innerData = ((SubContributionItem) data)
                        .getInnerItem();
                if (innerData instanceof ActionContributionItem) {
                    ActionContributionItem contribution = new ActionContributionItem(
                            ((ActionContributionItem) innerData).getAction());
                    chevronMenuManager.add(contribution);
                }
            } else if (data.isSeparator()) {
                chevronMenuManager.add(new Separator());
            }
        }
        Menu popup = chevronMenuManager.createContextMenu(coolBar);
        Point chevronPosition = coolBar.toDisplay(event.x, event.y);
        popup.setLocation(chevronPosition.x, chevronPosition.y);
        popup.setVisible(true);
    }
View Full Code Here

        if (coolItem == null) {
      return;
    }

        //1. Save current size
        CoolBar coolBar = coolItem.getParent();
        boolean isLastOnRow = false;
        int lastIndex = coolBar.getItemCount() - 1;
        int coolItemIndex = coolBar.indexOf(coolItem);
        int[] wrapIndicies = getAdjustedWrapIndices(coolBar.getWrapIndices());
        // Traverse through all wrap indicies backwards
        for (int row = wrapIndicies.length - 1; row >= 0; row--) {
            if (wrapIndicies[row] <= coolItemIndex) {

                int nextRow = row + 1;
View Full Code Here

        // cannot set size if coolItem is null
        if (coolItem == null || coolItem.isDisposed()) {
            return;
        }
        boolean locked = false;
        CoolBar coolBar = coolItem.getParent();
        try {
            // Fix odd behaviour with locked tool bars
            if (coolBar != null) {
                if (coolBar.getLocked()) {
                    coolBar.setLocked(false);
                    locked = true;
                }
            }
            ToolBar toolBar = (ToolBar) coolItem.getControl();
            if ((toolBar == null) || (toolBar.isDisposed())
                    || (toolBar.getItemCount() <= 0)) {
                // if the toolbar does not contain any items then dispose of
                // coolItem
                coolItem.setData(null);
                Control control = coolItem.getControl();
                if ((control != null) && !control.isDisposed()) {
                    control.dispose();
                    coolItem.setControl(null);
                }
                if (!coolItem.isDisposed()) {
                    coolItem.dispose();
                }
            } else {
                // If the toolbar item exists then adjust the size of the cool
                // item
                Point toolBarSize = toolBar.computeSize(SWT.DEFAULT,
                        SWT.DEFAULT);
                // Set the preffered size to the size of the toolbar plus trim
                Point preferredSize = coolItem.computeSize(toolBarSize.x,
                        toolBarSize.y);
                coolItem.setPreferredSize(preferredSize);
                // note setMinimumSize must be called before setSize, see PR
                // 15565
                // Set minimum size
                if (getMinimumItemsToShow() != SHOW_ALL_ITEMS) {
                    int toolItemWidth = toolBar.getItems()[0].getWidth();
                    int minimumWidth = toolItemWidth * getMinimumItemsToShow();
                    coolItem.setMinimumSize(minimumWidth, toolBarSize.y);
                } else {
                    coolItem.setMinimumSize(toolBarSize.x, toolBarSize.y);
                }
                if (changeCurrentSize) {
                    // Set current size to preferred size
                    coolItem.setSize(preferredSize);
                }
            }
        } finally {
            // If the cool bar was locked, then set it back to locked
            if ((locked) && (coolBar != null)) {
                coolBar.setLocked(true);
            }
        }
    }
View Full Code Here

      // OK, we need to re-layout the TB
      layoutBar.getParent().layout();
     
      // Now, if we're in a CoolBar then change the CoolItem size as well
      if (layoutBar.getParent() instanceof CoolBar) {
        CoolBar cb = (CoolBar) layoutBar.getParent();
        CoolItem[] items = cb.getItems();
        for (int i = 0; i < items.length; i++) {
          if (items[i].getControl() == layoutBar) {
            Point curSize = items[i].getSize();
            items[i].setSize(curSize.x+ (afterPack.x - beforePack.x),
                  curSize.y+ (afterPack.y - beforePack.y));
View Full Code Here

    if (orientation == SWT.VERTICAL && verticalHandleSize != -1) {
      return verticalHandleSize;
    }
       
    // Must be the first time, calculate the value
    CoolBar bar = new CoolBar (trim.getControl().getParent(), orientation);
   
    CoolItem item = new CoolItem (bar, SWT.NONE);
   
    Label ctrl = new Label (bar, SWT.PUSH);
    ctrl.setText ("Button 1"); //$NON-NLS-1$
      Point size = ctrl.computeSize (SWT.DEFAULT, SWT.DEFAULT);
   
      Point ps = item.computeSize (size.x, size.y);
    item.setPreferredSize (ps);
    item.setControl (ctrl);

    bar.pack ();

    // OK, now the difference between the location of the CB and the
    // location of the
    Point bl = ctrl.getLocation();
    Point cl = bar.getLocation();

    // Toss them now...
    ctrl.dispose();
    item.dispose();
    bar.dispose();
 
    // The 'size' is the difference between the start of teh CoolBar and
    // start of its first control
    int length;
    if (orientation == SWT.HORIZONTAL) {
View Full Code Here

          PresentationUtil.removeDragListener(cb, dragListener);
      cb.dispose();
    }
   
    // Create the necessary parts...
    cb = new CoolBar(this, orientation | SWT.FLAT);
    cb.setLocation(0,0);
    ci = new CoolItem(cb, SWT.FLAT);
   
    // Create a composite in order to get the handles to appear
    Composite comp = new Composite(cb, SWT.NONE);
View Full Code Here

TOP

Related Classes of org.eclipse.swt.widgets.CoolBar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.