Package org.eclipse.swt.widgets

Examples of org.eclipse.swt.widgets.ToolBar


        dragListener = new Listener() {
          /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
      public void handleEvent(Event event) {
        ToolBar toolbar = perspectiveBar.getControl();
                ToolItem item = toolbar.getItem(new Point(event.x, event.y));
               
                if (item != null) {
                  //ignore the first item, which remains in position Zero
                    if (item.getData() instanceof PerspectiveBarNewContributionItem) {
            return;
          }
                   
                  Rectangle bounds = item.getBounds();
                  Rectangle parentBounds = toolbar.getBounds();
                  bounds.x += parentBounds.x;
                  bounds.y += parentBounds.y;
                  startDragging(item.getData(), toolbar.getDisplay().map(toolbar, null, bounds));
                } else {
                    //startDragging(toolbar, toolbar.getDisplay().map(toolbar, null, toolbar.getBounds()));
                }
            }
     
      private void startDragging(Object widget, Rectangle bounds) {
        if(!DragUtil.performDrag(widget, bounds, new Point(bounds.x, bounds.y), true)) {
               //currently do nothing on a failed drag
                }
        }
        };

    dragTarget = new IDragOverListener() {
      protected PerspectiveDropTarget perspectiveDropTarget;

      class PerspectiveDropTarget extends AbstractDropTarget {

        private PerspectiveBarContributionItem perspective;

        private Point location;

                /**
         * @param location
         * @param draggedObject
         */
        public PerspectiveDropTarget(Object draggedObject,
            Point location) {
          update(draggedObject, location);
        }

        /**
         *
         * @param draggedObject
         * @param location
         */
        private void update(Object draggedObject, Point location) {
          this.location = location;
          this.perspective = (PerspectiveBarContributionItem) draggedObject;
        }

        /*
         * (non-Javadoc)
         *
         * @see org.eclipse.ui.internal.dnd.IDropTarget#drop()
         */
        public void drop() {
          ToolBar toolBar = perspectiveBar.getControl();
          ToolItem item = toolBar.getItem(toolBar.getDisplay().map(
              null, toolBar, location));
          if (toolBar.getItem(0) == item) {
            return;
          }
          ToolItem[] items = toolBar.getItems();
          ToolItem droppedItem = null;
          int dropIndex = -1;
          for (int i = 0; i < items.length; i++) {
            if (item == items[i]) {
              dropIndex = i;
            }
            if (items[i].getData() == perspective) {
              droppedItem = items[i];
            }
          }
          if (dropIndex != -1 && droppedItem != null && (droppedItem != item)) {
            PerspectiveBarContributionItem barItem = (PerspectiveBarContributionItem) droppedItem.getData();
            // policy is to insert at the beginning so mirror the value when indicating a
            // new position for the perspective
            if (reorderListener != null) {
              reorderListener.reorder(barItem.getPerspective(), Math.abs(dropIndex - (items.length - 1)));
            }

            perspectiveBar.relocate(barItem, dropIndex);
          }
        }

        /*
         * (non-Javadoc)
         *
         * @see org.eclipse.ui.internal.dnd.IDropTarget#getCursor()
         */
        public Cursor getCursor() {
          return DragCursors.getCursor(DragCursors.CENTER);
        }

        boolean sameShell() {
          return perspective.getToolItem().getParent().getShell().equals(perspectiveBar.getControl().getShell());
        }
       
        public Rectangle getSnapRectangle() {
          ToolBar toolBar = perspectiveBar.getControl();
          ToolItem item = toolBar.getItem(toolBar.getDisplay().map(
              null, toolBar, location));
          Rectangle bounds;
          if (item != null && item != toolBar.getItem(0)) {
            bounds = item.getBounds();
          } else {
            // it should not be possible to start a drag with item 0
            return null;
          }
          return toolBar.getDisplay().map(toolBar, null, bounds);
        }
      }

      public IDropTarget drag(Control currentControl,
          Object draggedObject, Point position,
View Full Code Here


        // there is no coolItem when the bar is on the left
        if (currentLocation == LEFT) {
      return;
    }

        ToolBar toolbar = perspectiveBar.getControl();
        if (toolbar == null) {
      return;
    }

        int rowHeight = 0;
        ToolItem[] toolItems = toolbar.getItems();
        for (int i = 0; i < toolItems.length; i++) {
            rowHeight = Math.max(rowHeight, toolItems[i].getBounds().height);
        }

        Rectangle area = perspectiveCoolBar.getClientArea();
        int rows = rowHeight <= 0 ? 1 : (int) Math.max(1, Math
                .floor(area.height / rowHeight));
        if (rows == 1 || (toolbar.getStyle() & SWT.WRAP) == 0
                || currentLocation == TOP_LEFT) {
            Point p = toolbar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            coolItem.setSize(coolItem.computeSize(p.x, p.y));
            return;
        }
        Point offset = coolItem.computeSize(0, 0);
        Point wrappedSize = toolbar.computeSize(area.width - offset.x,
                SWT.DEFAULT);
        int h = rows * rowHeight;
        int w = wrappedSize.y <= h ? wrappedSize.x : wrappedSize.x + 1;
        coolItem.setSize(coolItem.computeSize(w, h));
    }
View Full Code Here

        if (perspectiveBar == null) {
      return;
    }

        // Get the tool item under the mouse.
        ToolBar toolBar = perspectiveBar.getControl();
        ToolItem toolItem = toolBar.getItem(toolBar.toControl(pt));
       
        // Get the action for the tool item.
        Object data = null;
        if (toolItem != null){
            data = toolItem.getData();
View Full Code Here

         * (non-Javadoc)
         *
         * @see org.eclipse.ui.internal.dnd.IDropTarget#drop()
         */
        public void drop() {
          ToolBar toolBar = perspectiveBar.getControl();
          ToolItem item = toolBar.getItem(toolBar.getDisplay().map(
              null, toolBar, location));
          if (toolBar.getItem(0) == item) {
            return;
          }
          ToolItem[] items = toolBar.getItems();
          ToolItem droppedItem = null;
          int dropIndex = -1;
          for (int i = 0; i < items.length; i++) {
            if (item == items[i]) {
              dropIndex = i;
View Full Code Here

        boolean sameShell() {
          return perspective.getToolItem().getParent().getShell().equals(perspectiveBar.getControl().getShell());
        }
       
        public Rectangle getSnapRectangle() {
          ToolBar toolBar = perspectiveBar.getControl();
          ToolItem item = toolBar.getItem(toolBar.getDisplay().map(
              null, toolBar, location));
          Rectangle bounds;
          if (item != null && item != toolBar.getItem(0)) {
            bounds = item.getBounds();
          } else {
            // it should not be possible to start a drag with item 0
            return null;
          }
          return toolBar.getDisplay().map(toolBar, null, bounds);
        }
View Full Code Here

    public PerspectiveBarManager(int style) {
        super(style);
    }

    public ToolBar createControl(Composite parent) {
        ToolBar control = super.createControl(parent);

        if (control != null && !control.isDisposed()) {
      control.setFont(getFont());
    }

        return control;
    }
View Full Code Here

        /* Convert to display coordinates (i.e. was relative to CoolBar). */
        Point pt = coolBar.toDisplay(new Point(itemBounds.x, itemBounds.y));
        itemBounds.x = pt.x;
        itemBounds.y = pt.y;
        /* Retrieve the total number of buttons in the toolbar. */
        ToolBar toolBar = (ToolBar) control;
        ToolItem[] tools = toolBar.getItems();
        int toolCount = tools.length;
        int i = 0;
        while (i < toolCount) {
            /*
             * Starting from the leftmost tool, retrieve the tool's bounding
             * rectangle.
             */
            Rectangle toolBounds = tools[i].getBounds();
            /* Convert to display coordinates (i.e. was relative to ToolBar). */
            pt = toolBar.toDisplay(new Point(toolBounds.x, toolBounds.y));
            toolBounds.x = pt.x;
            toolBounds.y = pt.y;
            /*
             * Figure out the visible portion of the tool by looking at the
             * intersection of the tool bounds with the cool item bounds.
View Full Code Here

    /**
     * Returns the toolbar item at the given position, in display coordinates
     * @param position
     */
    private ToolItem getToolItem(Point position) {
        ToolBar toolbar = tbm.getControl();
        Point local = toolbar.toControl(position);
        return toolbar.getItem(local);
    }
View Full Code Here

    /**
     * Returns the approximate location where the next fastview icon
     * will be drawn (display coordinates)
     */
    public Rectangle getLocationOfNextIcon() {
        ToolBar control = tbm.getControl();

        Rectangle result = control.getBounds();
        Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
        result.height = size.y;
        result.width = size.x;
       
        boolean horizontal = (control.getStyle() & SWT.VERTICAL) == 0;
        if (control.getItemCount() == 0) {
          Geometry.setDimension(result, horizontal, 0);
        }
       
        int hoverSide = horizontal ? SWT.RIGHT : SWT.BOTTOM;

        result = Geometry.getExtrudedEdge(result, -Geometry.getDimension(
                result, !horizontal), hoverSide);

        return Geometry.toDisplay(control.getParent(), result);
    }
View Full Code Here

  public List<SWTBotToolbarButton> getToolbarButtons() {
    return UIThreadRunnable.syncExec(new ListResult<SWTBotToolbarButton>() {

      public List<SWTBotToolbarButton> run() {
        ViewPane obj = (ViewPane) ((WorkbenchPartReference) partReference).getPane();
        ToolBar toolbar = (ToolBar) obj.getToolBar();
        List<SWTBotToolbarButton> l = new ArrayList<SWTBotToolbarButton>();

        if (toolbar == null)
          return l;

        ToolItem[] items = toolbar.getItems();
        for (int i = 0; i < items.length; i++) {
          try {
            l.add(new SWTBotToolbarButton(items[i]));
          } catch (WidgetNotFoundException e) {
            log.warn("Failed to find widget " + items[i].getText(), e); //$NON-NLS-1$
View Full Code Here

TOP

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

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.