Java Code Examples for org.eclipse.swt.widgets.Menu#setLocation()

The following examples show how to use org.eclipse.swt.widgets.Menu#setLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultNavigatorActionProvider.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The default behavior is to show the same content as clicking the dropdown arrow. Subclass could override.
 * 
 * @param parent
 *            the parent toolbar
 */
protected void run(ToolBar parent)
{
	if (!isEnabled())
	{
		return;
	}
	Point toolbarLocation = parent.getLocation();
	toolbarLocation = parent.getParent().toDisplay(toolbarLocation.x, toolbarLocation.y);
	Point toolbarSize = parent.getSize();
	MenuManager menuManager = new MenuManager(null, getMenuId());
	IMenuService menuService = (IMenuService) partSite.getService(IMenuService.class);
	menuService.populateContributionManager(menuManager, MenuUtil.menuUri(menuManager.getId()));
	fillMenu(menuManager);
	Menu menu = menuManager.createContextMenu(parent);
	menu.setLocation(toolbarLocation.x, toolbarLocation.y + toolbarSize.y + 2);
	menu.setVisible(true);
}
 
Example 2
Source File: FindBarDecorator.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
void showOptions(boolean useMousePos)
{
	Menu menu = new Menu(UIUtils.getActiveShell(), SWT.POP_UP);

	for (FindBarOption option : fFindBarOptions)
	{
		option.createMenuItem(menu);
	}

	Point location;
	if (useMousePos)
	{
		Display current = UIUtils.getDisplay();
		location = current.getCursorLocation();
	}
	else
	{
		Rectangle bounds = options.getBounds();
		location = options.getParent().toDisplay(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
	}

	menu.setLocation(location);
	menu.setVisible(true);
}
 
Example 3
Source File: DropDownAction.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void runWithEvent(final Event event) {
	if (event.widget instanceof ToolItem) {
		final ToolItem toolItem = (ToolItem) event.widget;
		final Control control = toolItem.getParent();
		@SuppressWarnings("hiding")
		final Menu menu = getMenu(control);
		final Rectangle bounds = toolItem.getBounds();
		final Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
		menu.setLocation(control.toDisplay(topLeft));
		menu.setVisible(true);
	}
}
 
Example 4
Source File: ProjectFileDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void showViewMenu( )
{
	Menu menu = menuManager.createContextMenu( getShell( ) );
	Rectangle bounds = toolItem.getBounds( );
	Point topLeft = new Point( bounds.x, bounds.y + bounds.height );
	topLeft = toolBar.toDisplay( topLeft );
	menu.setLocation( topLeft.x, topLeft.y );
	menu.setVisible( true );
}
 
Example 5
Source File: CustomPopupMenu.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean show(Control parent) {
	Menu menu = new Menu(parent);

	Assert.isNotNull(getContent());
	Assert.isNotNull(getLabelProvider());
	final ArrayList<Object> resultThusFar = new ArrayList<Object>();
	for (Iterator<?> iter = getContent().iterator(); iter.hasNext();) {		
		Object contentObject = iter.next();
		createItem(menu, resultThusFar, contentObject);
	}
	menu.setLocation(Display.getCurrent().getCursorLocation().x + 20,Display.getCurrent().getCursorLocation().y  + 20 );
	menu.setVisible(true);


	Display display = menu.getDisplay();
	while (!menu.isDisposed() && menu.isVisible()) {
		if (!display.readAndDispatch())
			display.sleep();
	}

	if (!menu.isDisposed()) {
		menu.dispose();

		if (getResult() != null) {
			return true;
		}
	}

	return false;
}
 
Example 6
Source File: StandardEditorSystemMenu.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void show(Control parent, Point displayCoordinates, IPresentablePart currentSelection) {
    restore.update();
    move.setTarget(currentSelection);
    move.update();
    minimize.update();
    maximize.update();
    close.setTarget(currentSelection);
    closeOthers.setTarget(currentSelection);
    closeAll.update();
    
    Menu aMenu = menuManager.createContextMenu(parent);
    menuManager.update(true);
    aMenu.setLocation(displayCoordinates.x, displayCoordinates.y);
    aMenu.setVisible(true);
}
 
Example 7
Source File: TypeSelectionComponent.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void showViewMenu() {
	Menu menu = fMenuManager.createContextMenu(getShell());
	Rectangle bounds = fToolItem.getBounds();
	Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
	topLeft = fToolBar.toDisplay(topLeft);
	menu.setLocation(topLeft.x, topLeft.y);
	menu.setVisible(true);
}
 
Example 8
Source File: ParameterExpandBar.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
void onContextualMenu(final Event event) {
	final int x = event.x;
	final int y = event.y;
	for (int i = 0; i < itemCount; i++) {
		final ParameterExpandItem item = items[i];
		final boolean hover = item.x <= x && x < item.x + item.width && item.y <= y && y < item.y + bandHeight;
		if (!hover) {
			continue;
		}
		if (underlyingObjects != null) {
			ignoreMouseUp = true;
			final Point p = toDisplay(x, y);
			final Map<String, Runnable> menuContents = underlyingObjects.handleMenu(item.getData(), p.x, p.y);
			if (menuContents == null) {
				return;
			} else {
				final Menu menu = new Menu(getShell(), SWT.POP_UP);

				for (final Map.Entry<String, Runnable> entry : menuContents.entrySet()) {
					final MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
					menuItem.setText(entry.getKey());
					menuItem.addListener(SWT.Selection, e -> entry.getValue().run());
				}
				menu.setLocation(p.x, p.y);
				menu.setVisible(true);
				while (!menu.isDisposed() && menu.isVisible()) {
					if (!WorkbenchHelper.getDisplay().readAndDispatch()) {
						WorkbenchHelper.getDisplay().sleep();
					}
				}
				menu.dispose();
			}
		}
	}
}
 
Example 9
Source File: OpenWithQuickMenu.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private void show( Control focusControl, Point location ) {
  Menu quickMenu = new Menu( focusControl.getShell() );
  OpenWithMenu openWithMenu = new OpenWithMenu( workbenchPage, file );
  openWithMenu.fill( quickMenu, 0 );
  quickMenu.setLocation( location );
  quickMenu.addListener( SWT.Hide, createMenuCloseListener( openWithMenu ) );
  quickMenu.setVisible( true );
}
 
Example 10
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 5 votes vote down vote up
private void showViewMenu() {
	Menu menu = menuManager.createContextMenu(getShell());
	Rectangle bounds = toolItem.getBounds();
	Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
	topLeft = toolBar.toDisplay(topLeft);
	menu.setLocation(topLeft.x, topLeft.y);
	menu.setVisible(true);
}
 
Example 11
Source File: XFindPanel.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public void showHistoryMenu() {
        if (bHistory.isEnabled()) {
            final MenuManager manager = new MenuManager();
            fillHistoryMenu(manager);
            final Menu menu = manager.createContextMenu(toolBar);

//          menu.setLocation(toolBar.getDisplay().getCursorLocation());
            menu.setLocation(getToolItemLocation(bHistory));

            menu.setVisible(true);
        }
    }
 
Example 12
Source File: XFindPanel.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public void showSettings() {
        final MenuManager manager = new MenuManager();
        fillSettingsMenu(manager);
        final Menu menu = manager.createContextMenu(toolBar);

//        menu.setLocation(toolBar.getDisplay().getCursorLocation());
        menu.setLocation(getToolItemLocation(bSettings));
        
        menu.setVisible(true);
    }
 
Example 13
Source File: ShowHistoryAction.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void runWithEvent(Event event) {
	if (event.widget instanceof ToolItem) {
		final ToolItem toolItem = (ToolItem) event.widget;
		final Control control = toolItem.getParent();
		final Menu menu = getMenuCreator().getMenu(control);

		final Rectangle bounds = toolItem.getBounds();
		final Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
		menu.setLocation(control.toDisplay(topLeft));
		menu.setVisible(true);
	}
}
 
Example 14
Source File: RenameInformationPopup.java    From typescript.java with MIT License 4 votes vote down vote up
private void showMenu(ToolBar toolBar) {
	Menu menu= getMenuManager().createContextMenu(toolBar);
	menu.setLocation(toolBar.toDisplay(0, toolBar.getSize().y));
	fIsMenuUp= true;
	menu.setVisible(true);
}
 
Example 15
Source File: RenameInformationPopup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void showMenu(ToolBar toolBar) {
	Menu menu= getMenuManager().createContextMenu(toolBar);
	menu.setLocation(toolBar.toDisplay(0, toolBar.getSize().y));
	fIsMenuUp= true;
	menu.setVisible(true);
}
 
Example 16
Source File: TransGraph.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void addCandidateAsHop( int mouseX, int mouseY ) {

    boolean forward = startHopStep != null;

    StepMeta fromStep = candidate.getFromStep();
    StepMeta toStep = candidate.getToStep();

    // See what the options are.
    // - Does the source step has multiple stream options?
    // - Does the target step have multiple input stream options?
    //
    List<StreamInterface> streams = new ArrayList<>();

    StepIOMetaInterface fromIoMeta = fromStep.getStepMetaInterface().getStepIOMeta();
    List<StreamInterface> targetStreams = fromIoMeta.getTargetStreams();
    if ( forward ) {
      streams.addAll( targetStreams );
    }

    StepIOMetaInterface toIoMeta = toStep.getStepMetaInterface().getStepIOMeta();
    List<StreamInterface> infoStreams = toIoMeta.getInfoStreams();
    if ( !forward ) {
      streams.addAll( infoStreams );
    }

    if ( forward ) {
      if ( fromIoMeta.isOutputProducer() && toStep.equals( currentStep ) ) {
        streams.add( new Stream( StreamType.OUTPUT, fromStep, BaseMessages
          .getString( PKG, "Spoon.Hop.MainOutputOfStep" ), StreamIcon.OUTPUT, null ) );
      }

      if ( fromStep.supportsErrorHandling() && toStep.equals( currentStep ) ) {
        streams.add( new Stream( StreamType.ERROR, fromStep, BaseMessages.getString( PKG,
          "Spoon.Hop.ErrorHandlingOfStep" ), StreamIcon.ERROR, null ) );
      }
    } else {
      if ( toIoMeta.isInputAcceptor() && fromStep.equals( currentStep ) ) {
        streams.add( new Stream( StreamType.INPUT, toStep, BaseMessages.getString( PKG, "Spoon.Hop.MainInputOfStep" ),
          StreamIcon.INPUT, null ) );
      }

      if ( fromStep.supportsErrorHandling() && fromStep.equals( currentStep ) ) {
        streams.add( new Stream( StreamType.ERROR, fromStep, BaseMessages.getString( PKG,
          "Spoon.Hop.ErrorHandlingOfStep" ), StreamIcon.ERROR, null ) );
      }
    }

    // Targets can be dynamically added to this step...
    //
    if ( forward ) {
      streams.addAll( fromStep.getStepMetaInterface().getOptionalStreams() );
    } else {
      streams.addAll( toStep.getStepMetaInterface().getOptionalStreams() );
    }

    // Show a list of options on the canvas...
    //
    if ( streams.size() > 1 ) {
      // Show a pop-up menu with all the possible options...
      //
      Menu menu = new Menu( canvas );
      for ( final StreamInterface stream : streams ) {
        MenuItem item = new MenuItem( menu, SWT.NONE );
        item.setText( Const.NVL( stream.getDescription(), "" ) );
        item.setImage( getImageFor( stream ) );
        item.addSelectionListener( new SelectionAdapter() {
          @Override
          public void widgetSelected( SelectionEvent e ) {
            addHop( stream );
          }
        } );
      }
      menu.setLocation( canvas.toDisplay( mouseX, mouseY ) );
      menu.setVisible( true );

      return;
    }
    if ( streams.size() == 1 ) {
      addHop( streams.get( 0 ) );
    } else {
      return;
    }

    /*
     *
     * if (transMeta.findTransHop(candidate) == null) { spoon.newHop(transMeta, candidate); } if (startErrorHopStep) {
     * addErrorHop(); } if (startTargetHopStream != null) { // Auto-configure the target in the source step... //
     * startTargetHopStream.setStepMeta(candidate.getToStep());
     * startTargetHopStream.setStepname(candidate.getToStep().getName()); startTargetHopStream = null; }
     */
    candidate = null;
    selectedSteps = null;
    startHopStep = null;
    endHopLocation = null;
    startErrorHopStep = false;

    // redraw();
  }
 
Example 17
Source File: JaretTable.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
private void dispContextMenu(Menu contextMenu, int x, int y) {
    Shell shell = Display.getCurrent().getActiveShell();
    Point coords = Display.getCurrent().map(this, shell, x, y);
    contextMenu.setLocation(coords.x + shell.getLocation().x, coords.y + shell.getLocation().y);
    contextMenu.setVisible(true);
}
 
Example 18
Source File: JaretTable.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private void dispContextMenu(Menu contextMenu, int x, int y) {
    Shell shell = Display.getCurrent().getActiveShell();
    Point coords = Display.getCurrent().map(this, shell, x, y);
    contextMenu.setLocation(coords.x + shell.getLocation().x, coords.y + shell.getLocation().y);
    contextMenu.setVisible(true);
}
 
Example 19
Source File: HopGuiPipelineGraph.java    From hop with Apache License 2.0 4 votes vote down vote up
private void addCandidateAsHop( int mouseX, int mouseY ) {

    boolean forward = startHopTransform != null;

    TransformMeta fromTransform = candidate.getFromTransform();
    TransformMeta toTransform = candidate.getToTransform();
    if ( fromTransform.equals( toTransform ) ) {
      return; // Don't add
    }

    // See what the options are.
    // - Does the source transform has multiple stream options?
    // - Does the target transform have multiple input stream options?
    //
    List<IStream> streams = new ArrayList<>();

    ITransformIOMeta fromIoMeta = fromTransform.getTransform().getTransformIOMeta();
    List<IStream> targetStreams = fromIoMeta.getTargetStreams();
    if ( forward ) {
      streams.addAll( targetStreams );
    }

    ITransformIOMeta toIoMeta = toTransform.getTransform().getTransformIOMeta();
    List<IStream> infoStreams = toIoMeta.getInfoStreams();
    if ( !forward ) {
      streams.addAll( infoStreams );
    }

    if ( forward ) {
      if ( fromIoMeta.isOutputProducer() && toTransform.equals( currentTransform ) ) {
        streams.add( new Stream( StreamType.OUTPUT, fromTransform, BaseMessages
          .getString( PKG, "HopGui.Hop.MainOutputOfTransform" ), StreamIcon.OUTPUT, null ) );
      }

      if ( fromTransform.supportsErrorHandling() && toTransform.equals( currentTransform ) ) {
        streams.add( new Stream( StreamType.ERROR, fromTransform, BaseMessages.getString( PKG,
          "HopGui.Hop.ErrorHandlingOfTransform" ), StreamIcon.ERROR, null ) );
      }
    } else {
      if ( toIoMeta.isInputAcceptor() && fromTransform.equals( currentTransform ) ) {
        streams.add( new Stream( StreamType.INPUT, toTransform, BaseMessages.getString( PKG, "HopGui.Hop.MainInputOfTransform" ),
          StreamIcon.INPUT, null ) );
      }

      if ( fromTransform.supportsErrorHandling() && fromTransform.equals( currentTransform ) ) {
        streams.add( new Stream( StreamType.ERROR, fromTransform, BaseMessages.getString( PKG,
          "HopGui.Hop.ErrorHandlingOfTransform" ), StreamIcon.ERROR, null ) );
      }
    }

    // Targets can be dynamically added to this transform...
    //
    if ( forward ) {
      streams.addAll( fromTransform.getTransform().getOptionalStreams() );
    } else {
      streams.addAll( toTransform.getTransform().getOptionalStreams() );
    }

    // Show a list of options on the canvas...
    //
    if ( streams.size() > 1 ) {
      // Show a pop-up menu with all the possible options...
      //
      Menu menu = new Menu( canvas );
      for ( final IStream stream : streams ) {
        MenuItem item = new MenuItem( menu, SWT.NONE );
        item.setText( Const.NVL( stream.getDescription(), "" ) );
        item.setImage( getImageFor( stream ) );
        item.addSelectionListener( new SelectionAdapter() {
          @Override
          public void widgetSelected( SelectionEvent e ) {
            addHop( stream );
          }
        } );
      }
      menu.setLocation( canvas.toDisplay( mouseX, mouseY ) );
      menu.setVisible( true );

      return;
    }
    if ( streams.size() == 1 ) {
      addHop( streams.get( 0 ) );
    } else {
      return;
    }

    /*
     *
     * if (pipelineMeta.findPipelineHop(candidate) == null) { spoon.newHop(pipelineMeta, candidate); } if (startErrorHopTransform) {
     * addErrorHop(); } if (startTargetHopStream != null) { // Auto-configure the target in the source transform... //
     * startTargetHopStream.setTransformMeta(candidate.getToTransform());
     * startTargetHopStream.setTransformName(candidate.getToTransform().getName()); startTargetHopStream = null; }
     */
    candidate = null;
    selectedTransforms = null;
    startHopTransform = null;
    endHopLocation = null;
    startErrorHopTransform = false;

    // redraw();
  }
 
Example 20
Source File: TabbedPropertyTitle.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void handleWidgetSelection( Event e, ToolItem item )
{

	boolean selection = item.getSelection( );

	int style = item.getStyle( );
	IAction action = (IAction) actionMap.get( item );

	if ( ( style & ( SWT.TOGGLE | SWT.CHECK ) ) != 0 )
	{
		if ( action.getStyle( ) == IAction.AS_CHECK_BOX )
		{
			action.setChecked( selection );
		}
	}
	else if ( ( style & SWT.RADIO ) != 0 )
	{
		if ( action.getStyle( ) == IAction.AS_RADIO_BUTTON )
		{
			action.setChecked( selection );
		}
	}
	else if ( ( style & SWT.DROP_DOWN ) != 0 )
	{
		if ( e.detail == 4 )
		{ // on drop-down button
			if ( action.getStyle( ) == IAction.AS_DROP_DOWN_MENU )
			{
				IMenuCreator mc = action.getMenuCreator( );
				ToolItem ti = (ToolItem) item;
				if ( mc != null )
				{
					Menu m = mc.getMenu( ti.getParent( ) );
					if ( m != null )
					{
						Point point = ti.getParent( )
								.toDisplay( new Point( e.x, e.y ) );
						m.setLocation( point.x, point.y ); // waiting
						m.setVisible( true );
						return; // we don't fire the action
					}
				}
			}
		}
	}

	action.runWithEvent( e );
}