Java Code Examples for org.eclipse.swt.SWT#POP_UP

The following examples show how to use org.eclipse.swt.SWT#POP_UP . These examples are extracted from open source projects. 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
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 2
public ClassSelectionButton( Composite parent, int style,
		IMenuButtonProvider provider )
{
	button = new MenuButton( parent, style );
	button.addSelectionListener( listener );
	button.addSelectionListener( new SelectionAdapter( ) {

		public void widgetSelected( SelectionEvent e )
		{
			refreshMenuItems( );
		}

	} );

	menu = new Menu( parent.getShell( ), SWT.POP_UP );
	button.setDropDownMenu( menu );

	setMenuButtonProvider( provider );
	refresh( );
}
 
Example 3
Source Project: nebula   File: DateChooser.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates the header of the calendar. The header contains the label
 * displaying the current month and year, and the two buttons for navigation :
 * previous and next month.
 */
private void createHeader() {
	monthPanel = new Composite(this, SWT.NONE);
	GridLayoutFactory.fillDefaults().numColumns(3).spacing(HEADER_SPACING, 0).margins(HEADER_SPACING, 2).applyTo(monthPanel);
	GridDataFactory.fillDefaults().applyTo(monthPanel);
	monthPanel.addListener(SWT.MouseDown, listener);

	prevMonth = new Button(monthPanel, SWT.ARROW | SWT.LEFT | SWT.FLAT);
	prevMonth.addListener(SWT.MouseUp, listener);
	prevMonth.addListener(SWT.FocusIn, listener);

	currentMonth = new Label(monthPanel, SWT.CENTER);
	currentMonth.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	currentMonth.addListener(SWT.MouseDown, listener);

	nextMonth = new Button(monthPanel, SWT.ARROW | SWT.RIGHT | SWT.FLAT);
	nextMonth.addListener(SWT.MouseUp, listener);
	nextMonth.addListener(SWT.FocusIn, listener);

	monthsMenu = new Menu(getShell(), SWT.POP_UP);
	currentMonth.setMenu(monthsMenu);
	for (int i = 0; i < 12; i++) {
		final MenuItem item = new MenuItem(monthsMenu, SWT.PUSH);
		item.addListener(SWT.Selection, listener);
		item.setData(new Integer(i));
	}
	monthsMenu.addListener(SWT.Show, listener);
}
 
Example 4
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 5
Source Project: Rel   File: Visualiser.java    License: Apache License 2.0 5 votes vote down vote up
protected void setupPopupMenu() {
	Menu menuBar = new Menu(getShell(), SWT.POP_UP);

	new IconMenuItem(menuBar, "Disconnect", null, SWT.PUSH, e -> disconnect());
	new IconMenuItem(menuBar, "Delete", null, SWT.PUSH, e -> delete());

	lblTitle.setMenu(menuBar);
}
 
Example 6
Source Project: birt   File: ExpressionButton.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public ExpressionButton( Composite parent, int style, boolean allowConstant )
{
	button = new MenuButton( parent, style );
	button.addSelectionListener( listener );

	menu = new Menu( parent.getShell( ), SWT.POP_UP );
	button.setDropDownMenu( menu );

	setExpressionButtonProvider( new ExpressionButtonProvider( allowConstant ) );
	refresh( );
}
 
Example 7
/**
 * Creates the Menu that stores each of the available IAnalysisViews for
 * each of the data sources.
 */
private void createViewMenu() {
	// Instantiate viewMenu. POP_UP menus are used for context menus and
	// drop-downs from ToolItems.
	Menu menu = new Menu(this.getShell(), SWT.POP_UP);

	// Create the top-level of the view menu with a button for each possible
	// data source.
	for (DataSource dataSource : DataSource.values()) {
		// Create a disabled MenuItem with dataSource as its text.
		MenuItem item = new MenuItem(menu, SWT.CASCADE);
		item.setText(dataSource.toString());
		item.setEnabled(false);

		// Create the sub-menu that will show the view types for this data
		// source.
		Menu subMenu = new Menu(menu);
		item.setMenu(subMenu);

		// Put the MenuItem into a Map for quick access (it will need to be
		// enabled/disabled depending on whether or not there are views
		// available for the data source.
		dataSourceItems.put(dataSource, item);
	}

	// Add the view ToolItem that should make the view menu appear.
	final ToolItem viewItem = new ToolItem(rightToolBar, SWT.DROP_DOWN);
	viewItem.setText("Views");
	viewItem.setToolTipText("Select the view displayed below.");

	// We also need to add a listener to make viewMenu appear.
	viewItem.addListener(SWT.Selection,
			new ToolItemMenuListener(viewItem, menu));

	return;
}
 
Example 8
Source Project: nebula   File: ToolbarComposite.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public void mouseDown(MouseEvent event) {
	checkWidget();
	Rectangle bigArrowsBounds = new Rectangle(mArrowsBounds.x, 0, mArrowsBounds.width, CustomButton.BUTTON_HEIGHT);
	if (isInside(event.x, event.y, bigArrowsBounds)) {
		GC gc = new GC(this);
		Rectangle rect = new Rectangle(mArrowsBounds.x - mSettings.getToolBarLeftSpacer(), 0, mArrowsBounds.width + mSettings.getToolBarRightSpacer(),
				CustomButton.BUTTON_HEIGHT);
		mButtonPainter.paintBackground(gc, mColorManager, mSettings, rect, false, true);

		gc.drawImage(mArrowImage, mArrowsBounds.x, mArrowsBounds.y);

		gc.dispose();

		Menu mainMenu = new Menu(Display.getDefault().getActiveShell(), SWT.POP_UP);

		List<IMenuListener> menuListeners = mButtonComposite.getMenuListeners();
		for (int i = 0; i < menuListeners.size(); i++) {
			menuListeners.get(i).preMenuItemsCreated(mainMenu);
		}

		MenuItem menuShowMoreButtons = new MenuItem(mainMenu, SWT.PUSH);
		MenuItem menuShowFewerButtons = new MenuItem(mainMenu, SWT.PUSH);
		menuShowFewerButtons.addListener(SWT.Selection, e -> mButtonComposite.hideNextButton());
		menuShowMoreButtons.addListener(SWT.Selection, e-> mButtonComposite.showNextButton());

		menuShowMoreButtons.setText(mLanguage.getShowMoreButtonsText());
		menuShowFewerButtons.setText(mLanguage.getShowFewerButtonsText());

		new MenuItem(mainMenu, SWT.SEPARATOR);
		MenuItem more = new MenuItem(mainMenu, SWT.CASCADE);
		more.setText(mLanguage.getAddOrRemoveButtonsText());
		Menu moreMenu = new Menu(more);
		more.setMenu(moreMenu);

		List<CustomButton> cbs = mButtonComposite.getItems();
		for (int i = 0; i < cbs.size(); i++) {
			final CustomButton cb = cbs.get(i);
			final MenuItem temp = new MenuItem(moreMenu, SWT.CHECK);
			temp.setText(cb.getText());
			temp.setImage(cb.getToolBarImage());
			temp.setSelection(mButtonComposite.isVisible(cb));
			temp.addListener(SWT.Selection, e -> {
				if (mButtonComposite.isVisible(cb)) {
					mButtonComposite.permanentlyHideButton(cb);
					temp.setSelection(false);
				} else {
					mButtonComposite.permanentlyShowButton(cb);
					temp.setSelection(true);
				}
			});
		}

		for (int i = 0; i < menuListeners.size(); i++) {
			menuListeners.get(i).postMenuItemsCreated(mainMenu);
		}

		mainMenu.setVisible(true);
		return;
	}

	for (int i = 0; i < mToolBarItems.size(); i++) {
		TBItem item = mToolBarItems.get(i);
		if (item.getBounds() != null) {
			if (isInside(event.x, event.y, item.getBounds())) {
				mButtonComposite.selectItemAndLoad(item.getButton());
				break;
			}
		}
	}
}
 
Example 9
Source Project: nebula   File: CTree.java    License: Eclipse Public License 2.0 4 votes vote down vote up
protected void handleMouseEvents(Event event) {
		CTreeItem item = null;
		if (event.widget == body) {
			item = getItem(event.x, event.y);
		} else if (event.item instanceof CTreeItem) {
			item = (CTreeItem) event.item;
		}
		
		switch (event.type) {
		case SWT.MouseDoubleClick:
			if(item != null && (selectOnToggle || !item.isToggle(event.x, event.y))) {
				fireSelectionEvent(true);
			}
			break;
		case SWT.MouseDown:
			if(!hasFocus) setFocus();
			if(item == null) {
				if(event.widget == body) {
					item = getItem(event.x, event.y);
				} else if(event.item instanceof CTreeItem) {
					item = (CTreeItem) event.item;
				}
			}
			switch(event.button) {
			// TODO - popup menu: not just for mouse down events!
			case 3:
				Menu menu = getMenu();
				if ((menu != null) && ((menu.getStyle() & SWT.POP_UP) != 0)) {
					menu.setVisible(true);
				}
			case 1:
				if(selectOnToggle || !item.isToggle(event.x, event.y)) {
					if(selectOnTreeToggle || !item.isTreeToggle(event.x,event.y)) {
						if((event.stateMask & SWT.SHIFT) != 0) {
							if(shiftSel == null) {
								if(selection.isEmpty()) selection.add(item);
								shiftSel = (CTreeItem) selection.get(selection.size() - 1);
							}
							setSelection(shiftSel, item);
						} else if((event.stateMask & SWT.CONTROL) != 0) {
							toggleSelection(item);
							shiftSel = null;
						} else {
							setSelection(item);
							shiftSel = null;
						}
					}
				}
				break;
			}
			break;
		case SWT.MouseMove:
			// TODO: make toggles more dynamic
			break;
		case SWT.MouseUp:
			if(item.isToggle(event.x,event.y)) {
				boolean open = item.isOpen(event.x,event.y);
				if(item.isTreeToggle(event.x,event.y)) {
//					visibleItems = null;
					item.setExpanded(!open);
					fireTreeEvent(item, !open);
				} else {
					item.getCell(event.x, event.y).setOpen(!open);
				}
			}
			break;
		}

	}
 
Example 10
public static void
 addCopyToClipMenu(
final Control				control,
final copyToClipProvider	provider )
 {
  MouseAdapter ml = (MouseAdapter)control.getData( MOUSE_LISTENER_KEY );
  
  if ( ml != null ){
  
	  control.removeMouseListener( ml );
  }
  
  ml =
	  new MouseAdapter()
	  {
		  @Override
		  public void
		  mouseDown(
			 MouseEvent e )
		  {
			  if ( control.isDisposed()){

				  return;
			  }

			  final String	text = provider.getText();

			  if ( control.getMenu() != null || text == null || text.length() == 0 ){

				  return;
			  }

			  if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))){

				  return;
			  }

			  final Menu menu = new Menu(control.getShell(),SWT.POP_UP);

			  MenuItem   item = new MenuItem( menu,SWT.NONE );

			  item.setData( MENU_ITEM_KEY, "" );

			  String	msg_text_id;

			  if ( provider instanceof copyToClipProvider2 ){

				  msg_text_id = ((copyToClipProvider2)provider).getMenuResource();

			  }else{

				  msg_text_id = "label.copy.to.clipboard";
			  }

			  item.setText( MessageText.getString( msg_text_id ));

			  item.addSelectionListener(
					  new SelectionAdapter()
					  {
						  @Override
						  public void
						  widgetSelected(
								  SelectionEvent arg0)
						  {
							  new Clipboard(control.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()});
						  }
					  });

			  control.setMenu( menu );

			  menu.addMenuListener(
					  new MenuAdapter()
					  {
						  @Override
						  public void
						  menuHidden(
								  MenuEvent arg0 )
						  {
							  if ( control.getMenu() == menu ){

								  control.setMenu( null );
							  }
						  }
					  });

			  menu.setVisible( true );
		  }
	  };
  
  control.setData( MOUSE_LISTENER_KEY, ml );
  
  control.addMouseListener( ml );
 }
 
Example 11
public SWTPopupMenu(Shell shell) {
	super(shell, SWT.POP_UP);
	
	this.menuListener = new SWTMenuListenerManager(this);
}
 
Example 12
Source Project: Rel   File: Rev.java    License: Apache License 2.0 4 votes vote down vote up
private void refreshMenus() {
	if (getMenu() != null)
		getMenu().dispose();

	Menu menuBar = new Menu(getShell(), SWT.POP_UP);
	if (!isReadOnly())
		model.setMenu(menuBar);

	// Custom relvars
	IconMenuItem customRelvarsItem = new IconMenuItem(menuBar, "Variables", SWT.CASCADE);
	customRelvarsItem.setMenu(obtainRelvarsMenu(menuBar, false));

	// System relvars
	IconMenuItem systemRelvarsItem = new IconMenuItem(menuBar, "System variables", SWT.CASCADE);
	systemRelvarsItem.setMenu(obtainRelvarsMenu(menuBar, true));

	// Operators
	OpSelector[] queryOperators = getOperators();
	IconMenuItem insOperatorsItem = new IconMenuItem(menuBar, "Operators and constants", SWT.CASCADE);
	Menu insOperatorsMenu = new Menu(menuBar);
	for (int i = 0; i < queryOperators.length; i++) {
		OpSelector selector = queryOperators[i];
		if (selector.toString() == null)
			new MenuItem(insOperatorsMenu, SWT.SEPARATOR);
		else {
			new IconMenuItem(insOperatorsMenu, selector.getMenuTitle(), null, SWT.PUSH, e -> {
				Point lastMousePosition = model.getLastMousePosition();
				obtainOperatorForKind(selector.toString(), selector.toString() + getUniqueNumber(), 
						lastMousePosition.x, lastMousePosition.y);
			});
		}
	}
	insOperatorsItem.setMenu(insOperatorsMenu);

	new IconMenuItem(menuBar, "Refresh", null, SWT.PUSH, e -> refreshMenus());
	new IconMenuItem(menuBar, "Clear", null, SWT.PUSH, e -> {
		if (!MessageDialog.openConfirm(getShell(), "Rev", "Remove everything from this query?"))
			return;
		model.removeEverything();
	});
}
 
Example 13
Source Project: nebula   File: SplitButton.java    License: Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Constructs a new instance of this class given its parent
 * and a style value describing its behavior and appearance.
 * <p>
 * The style value is either one of the style constants defined in
 * class <code>SWT</code> which is applicable to instances of this
 * class, or must be built by <em>bitwise OR</em>'ing together
 * (that is, using the <code>int</code> "|" operator) two or more
 * of those <code>SWT</code> style constants. The class description
 * lists the style constants that are applicable to the class.
 * Style bits are also inherited from superclasses.
 * </p>
 *
 * @param parent a composite control which will be the parent of the new instance (cannot be null)
 * @param style the style of control to construct
 *
 * @exception IllegalArgumentException
 *                <ul>
 *                <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
 *                </ul>
 * @exception SWTException
 *                <ul>
 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
 *                <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
 *                </ul>
 *
 * @see SWT#PUSH
 * @see SWT#TOGGLE
 * @see Widget#getStyle
 */
public SplitButton(final Composite parent, final int style) {
	super(parent, checkStyle(style));
	setText(""); //$NON-NLS-1$
	addPaintListener();
	addMouseDownListener();
	menu = new Menu(getShell(), SWT.POP_UP);
}