Java Code Examples for org.eclipse.swt.widgets.MenuItem#setData()

The following examples show how to use org.eclipse.swt.widgets.MenuItem#setData() . 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: EditorMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static Menu createOtherSubMenu(final Menu parentMenu, final GamlEditor editor) {
	final Map<URI, List<String>> map = grabProjectModelsAndExperiments(editor);
	if (map.isEmpty()) {
		final MenuItem nothing = new MenuItem(parentMenu, SWT.PUSH);
		nothing.setText("No experiments defined");
		nothing.setEnabled(false);
		return parentMenu;
	}
	for (final URI uri : map.keySet()) {
		final MenuItem modelItem = new MenuItem(parentMenu, SWT.CASCADE);
		modelItem.setText(URI.decode(uri.lastSegment()));
		modelItem.setImage(GamaIcons.create(IGamaIcons.FILE_ICON).image());
		final Menu expMenu = new Menu(modelItem);
		modelItem.setMenu(expMenu);
		final List<String> expNames = map.get(uri);
		for (final String name : expNames) {
			final MenuItem expItem = new MenuItem(expMenu, SWT.PUSH);
			expItem.setText(name);
			expItem.setData("uri", uri);
			expItem.setData("exp", name);
			expItem.setImage(GamaIcons.create(IGamaIcons.BUTTON_GUI).image());
			expItem.addSelectionListener(OtherAdapter);
		}
	}
	return parentMenu;
}
 
Example 2
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static Menu createImportedSubMenu(final Menu parentMenu, final GamlEditor editor) {
	final Set<URI> importers = getImporters(editor);
	if (importers.isEmpty()) {
		final MenuItem nothing = new MenuItem(parentMenu, SWT.PUSH);
		nothing.setText("No importers");
		nothing.setEnabled(false);
		return parentMenu;
	}
	for (final URI uri : importers) {
		final MenuItem modelItem = new MenuItem(parentMenu, SWT.CASCADE);
		modelItem.setText(URI.decode(uri.lastSegment()));
		modelItem.setImage(GamaIcons.create(IGamaIcons.FILE_ICON).image());
		modelItem.setData("uri", uri);
		modelItem.addSelectionListener(UsedInAdapter);
	}
	return parentMenu;
}
 
Example 3
Source File: ClassSelectionButton.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void populateMenuItems( )
{
	for ( int i = 0; i < menu.getItemCount( ); i++ )
	{
		menu.getItem( i ).dispose( );
		i--;
	}

	String[] types = this.provider.getMenuItems( );
	for ( int i = 0; i < types.length; i++ )
	{
		MenuItem item = new MenuItem( menu, SWT.PUSH );
		item.setText( provider.getMenuItemText( types[i] ) );
		item.setData( types[i] );
		item.setImage( this.provider.getMenuItemImage( types[i] ) );
		item.addSelectionListener( listener );
	}

	if ( menu.getItemCount( ) <= 0 )
	{
		button.setDropDownMenu( null );
	}

	button.setText( provider.getButtonText( ) );
	refresh( );
}
 
Example 4
Source File: ContactSorterSwitcher.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void fill(Menu menu, int index){
	for (final ContactSelectorViewerComparator.sorter sortMethod : ContactSelectorViewerComparator.sorter
		.values()) {
		MenuItem temp = new MenuItem(menu, SWT.CHECK, index);
		temp.setData(sortMethod);
		temp.setText(sortMethod.label);
		temp.setSelection(ContactSelectorViewerComparator.getSelectedSorter()
			.equals(sortMethod));
		temp.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e){
				ContactSelectorViewerComparator.setSelectedSorter(sortMethod);
			}
		});
	}
}
 
Example 5
Source File: GroupPage.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Executed when the menu is shown: fills the group-menu
 */
@Override
public void handleEvent(Event event) {
	ProcessGrouping group = Viewers.getFirstSelected(groupViewer);
	if (group == null)
		return;
	for (MenuItem item : groupMoveMenu.getItems()) {
		item.removeSelectionListener(this);
		item.dispose();
	}
	List<ProcessGrouping> other = getOther(group);
	for (ProcessGrouping g : other) {
		MenuItem menuItem = new MenuItem(groupMoveMenu, SWT.PUSH);
		menuItem.setText(g.name);
		menuItem.setData(g);
		menuItem.addSelectionListener(this);
	}
}
 
Example 6
Source File: DateChooser.java    From nebula with 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 7
Source File: BarManager.java    From pmTrans with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MenuItem addMenuItem(Menu menu, String text, int accelerator,
		Object data, SelectionListener listener) {
	MenuItem item = new MenuItem(menu, SWT.NONE);
	item.setText(text);
	item.addSelectionListener(listener);
	if (accelerator != SWT.NONE)
		item.setAccelerator(accelerator);
	item.setData(data);
	return item;
}
 
Example 8
Source File: ClipboardCopy.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public static void
 addCopyToClipMenu(
final Menu		menu,
final String	text )
 {
  for ( MenuItem e: menu.getItems()){
	  
	  if ( e.getData( MENU_ITEM_KEY ) != null ){
		  
		  e.dispose();
	  }
  }
  
  MenuItem   item = new MenuItem( menu,SWT.NONE );

  item.setData( MENU_ITEM_KEY, "" );

  String	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(menu.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()});
		  }
	  });
 }
 
Example 9
Source File: ClipboardCopy.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public static void
 addCopyToClipMenu(
final Menu					menu,
final copyToClipProvider	provider )
 {
  for ( MenuItem e: menu.getItems()){
	  
	  if ( e.getData( MENU_ITEM_KEY ) != null ){
		  
		  e.dispose();
	  }
  }
  
  MenuItem   item = new MenuItem( menu,SWT.NONE );

  item.setData( MENU_ITEM_KEY, "" );
  
  String	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(menu.getDisplay()).setContents(new Object[] { provider.getText()}, new Transfer[] {TextTransfer.getInstance()});
		  }
	  });
 }
 
Example 10
Source File: PluginsMenuHelper.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Populates the client's menu bar
 * @param locales
 * @param parent
 */
private static void createViewInfoMenuItem(Menu parent,
		UISWTViewBuilderCore builder) {
	MenuItem item = new MenuItem(parent, SWT.NULL);
	item.setText(builder.getInitialTitle());
	item.setData("ViewID", builder.getViewID());
	item.addListener(SWT.Selection, e -> {
		UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
		if (uiFunctions != null) {
			uiFunctions.openPluginView(builder, true);
		}
	});
}
 
Example 11
Source File: AgentsMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private static MenuItem actionAgentMenuItem(final Menu parent, final IAgent agent, final SelectionListener listener,
		final Image image, final String prefix) {
	final MenuItem result = new MenuItem(parent, SWT.PUSH);
	result.setText(prefix /* + " " + agent.getName() */);
	result.addSelectionListener(listener);
	result.setImage(image);
	result.setData("agent", agent);
	return result;
}
 
Example 12
Source File: AgentsMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private static MenuItem actionAgentMenuItem(final Menu parent, final IAgent agent, final IStatement command,
		final String prefix) {
	final MenuItem result = new MenuItem(parent, SWT.PUSH);
	result.setText(prefix + " " + command.getName());
	result.setImage(GamaIcons.create(IGamaIcons.MENU_RUN_ACTION).image());
	result.addSelectionListener(runner);
	result.setData("agent", agent);
	result.setData("command", command);
	return result;
}
 
Example 13
Source File: ExpressionButton.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void setExpressionButtonProvider( IExpressionButtonProvider provider )
{
	if ( provider != null && provider != this.provider )
	{
		this.provider = provider;

		provider.setInput( this );

		for ( int i = 0; i < menu.getItemCount( ); i++ )
		{
			menu.getItem( i ).dispose( );
			i--;
		}

		String[] types = this.provider.getExpressionTypes( );
		for ( int i = 0; i < types.length; i++ )
		{
			MenuItem item = new MenuItem( menu, SWT.PUSH );
			item.setText( this.provider.getText( types[i] ) );
			item.setData( types[i] );
			item.setImage( this.provider.getImage( types[i] ) );
			item.addSelectionListener( listener );
		}

		if ( menu.getItemCount( ) <= 1 )
		{
			button.setDropDownMenu( null );
		}

		refresh( );
	}
}
 
Example 14
Source File: MenuManager.java    From pmTrans with GNU Lesser General Public License v3.0 4 votes vote down vote up
private MenuItem addMenuItem(Menu menu, String text, int accelerator,
		Object data, SelectionListener listener) {
	MenuItem item = addMenuItem(menu, text, accelerator, listener);
	item.setData(data);
	return item;
}
 
Example 15
Source File: ExpressionCellEditor.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void setExpressionCellEditorProvider(
		IExpressionCellEditorProvider provider )
{
	if ( provider != null && provider != this.provider )
	{
		this.provider = provider;

		provider.setInput( this );

		for ( int i = 0; i < menu.getItemCount( ); i++ )
		{
			menu.getItem( i ).dispose( );
			i--;
		}

		String[] types = this.provider.getExpressionTypes( );

		listener = new SelectionAdapter( ) {

			public void widgetSelected( SelectionEvent e )
			{
				Widget widget = e.widget;
				if ( widget instanceof MenuItem )
				{
					String exprType = (String) widget.getData( );
					ExpressionCellEditor.this.provider.handleSelectionEvent( exprType );
				}
				else if ( widget instanceof Button )
				{
					ExpressionCellEditor.this.provider.handleSelectionEvent( getExpressionType( ) );
				}
			}

		};

		for ( int i = 0; i < types.length; i++ )
		{
			MenuItem item = new MenuItem( menu, SWT.CHECK );
			item.setText( this.provider.getText( types[i] ) );
			item.setData( types[i] );
			item.addSelectionListener( listener );
		}

		if ( menu.getItemCount( ) <= 1 )
		{
			menu = null;
			button.addSelectionListener( listener );
		}

		refresh( );
	}
}