Package org.eclipse.swt.widgets

Examples of org.eclipse.swt.widgets.ToolItem


        }
    }

    public void fill(ToolBar toolbar, int index) {
        if (index >= 0) {
            new ToolItem(toolbar, SWT.SEPARATOR, index);
        } else {
            new ToolItem(toolbar, SWT.SEPARATOR);
        }
    }
View Full Code Here


    labels.setLayoutData(gd);
  }

  private void createViewMenu(Composite parent) {
    toolBar = new ToolBar(parent, SWT.FLAT);
    toolItem = new ToolItem(toolBar, SWT.PUSH, 0);

    GridData data = new GridData();
    data.horizontalAlignment = GridData.END;
    toolBar.setLayoutData(data);
View Full Code Here

          /* (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);
View Full Code Here

      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();
        }
        if (toolItem == null
                || !(data instanceof PerspectiveBarContributionItem)) {
            if (genericMenu == null) {
                Menu menu = new Menu(toolBar);
View Full Code Here

        menuItem.setText(WorkbenchMessages.WorkbenchWindow_close);
        window.getWorkbench().getHelpSystem().setHelp(menuItem,
            IWorkbenchHelpContextIds.CLOSE_PAGE_ACTION);
        menuItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                ToolItem perspectiveToolItem = (ToolItem) popupMenu
                        .getData();
                if (perspectiveToolItem != null
                        && !perspectiveToolItem.isDisposed()) {
                    PerspectiveBarContributionItem item = (PerspectiveBarContributionItem) perspectiveToolItem
                            .getData();
                    item.getPage().closePerspective(item.getPerspective(),
                            true, true);
                }
            }
View Full Code Here

         *
         * @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)));
            }
View Full Code Here

          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 final void fill(final ToolBar parent, final int index) {
    if ((widget != null) && (parent == null)) {
      return;
    }

    final ToolItem toolItem;
    if (index >= 0) {
      toolItem = new ToolItem(parent, SWT.DROP_DOWN, index);
    } else {
      toolItem = new ToolItem(parent, SWT.DROP_DOWN);
    }
    toolItem.setData(this);
    widget = toolItem;

    // Attach some listeners.
    toolItem.addDisposeListener(disposeListener);
    toolItem.addListener(SWT.Selection, selectionListener);

    // TODO Needs a way to be linked to a command.
    // toolItem.addListener(SWT.Selection, getToolItemListener());
    // action.addPropertyChangeListener(propertyListener);
    // if (action != null) {
View Full Code Here

    }
    if (widget != null || parent == null) {
      return;
    }

    ToolItem item = null;
    if (index >= 0) {
      item = new ToolItem(parent, style, index);
    } else {
      item = new ToolItem(parent, style);
    }

    item.setData(this);

    item.addListener(SWT.Selection, getItemListener());
    item.addListener(SWT.Dispose, getItemListener());
    widget = item;

    update(null);
  }
View Full Code Here

        boolean shouldBeEnabled = isEnabled();
        if (item.getEnabled() != shouldBeEnabled) {
          item.setEnabled(shouldBeEnabled);
        }
      } else if (widget instanceof ToolItem) {
        ToolItem item = (ToolItem) widget;

        if (icon != null) {
          updateIcons();
        } else if (label != null) {
          item.setText(label);
        }

        if (tooltip != null)
          item.setToolTipText(tooltip);
        else {
          String text = label;
          if (text == null) {
            if (command != null) {
              try {
                text = command.getCommand().getName();
              } catch (NotDefinedException e) {
                WorkbenchPlugin.log("Update item failed " //$NON-NLS-1$
                    + getId(), e);
              }
            }
          }
          if (text != null) {
            item.setToolTipText(text);
          }
        }

        if (item.getSelection() != checkedState) {
          item.setSelection(checkedState);
        }

        boolean shouldBeEnabled = isEnabled();
        if (item.getEnabled() != shouldBeEnabled) {
          item.setEnabled(shouldBeEnabled);
        }
      }
    }
  }
View Full Code Here

TOP

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

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.