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

The following examples show how to use org.eclipse.swt.widgets.MenuItem#getData() . 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: AgentsMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void widgetSelected(final SelectionEvent e) {
	final MenuItem source = (MenuItem) e.widget;
	final IAgent a = (IAgent) source.getData("agent");
	final IStatement c = (IStatement) source.getData("command");
	// final ILocation p = (ILocation) source.getData("location");

	// We run into the scope provided by the simulation to which this
	// agent belongs

	if (c != null && a != null && !a.dead()) {
		final IScope runningScope = a.getScope();
		runningScope.getSimulation().executeAction(scope -> {
			final Arguments args = new Arguments();
			final ExecutionResult result = scope.execute(c, a, args);
			GAMA.getExperiment().refreshAllOutputs();
			return result.getValue();
		});

	}
}
 
Example 2
Source File: MainMenu.java    From arx with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the menu
 * @param menu
 * @param model
 */
private void update(Menu menu, Model model) {

    // Check
    if (menu == null) return;
    
    // For each item
    for (final MenuItem item : menu.getItems()) {

        // Check group
        if (item.getData() instanceof MainMenuGroup) {

            MainMenuGroup group = (MainMenuGroup) item.getData();
            item.setEnabled(group.isEnabled(model));
            update(item.getMenu(), model);

            // Check item
        } else {
            MainMenuItem mItem = (MainMenuItem) item.getData();
            item.setEnabled(mItem == null || mItem.isEnabled(model));
        }
    }        
}
 
Example 3
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 4
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 5
Source File: ClipboardCopy.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public static void
 removeCopyToClipMenu(
final Menu					menu )
 {
  for ( MenuItem e: menu.getItems()){
	  
	  if ( e.getData( MENU_ITEM_KEY ) != null ){
		  
		  e.dispose();
	  }
  }	
 }
 
Example 6
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void widgetSelected(final SelectionEvent e) {
	final MenuItem mi = (MenuItem) e.widget;
	final URI uri = (URI) mi.getData("uri");
	final String exp = (String) mi.getData("exp");
	if (uri != null && exp != null) {
		GAMA.getGui().runModel(uri, exp);
	}
}
 
Example 7
Source File: DisplaySurfaceMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void widgetSelected(final SelectionEvent e) {
	final MenuItem mi = (MenuItem) e.widget;
	final IAgent a = (IAgent) mi.getData("agent");
	if (a != null && !a.dead()) {
		surface.runAndUpdate(() -> {
			if (!a.dead()) {
				surface.focusOn(a);
			}
		});
	}
}
 
Example 8
Source File: AgentsMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void widgetSelected(final SelectionEvent e) {
	final MenuItem mi = (MenuItem) e.widget;
	final IAgent a = (IAgent) mi.getData("agent");
	if (a != null && !a.dead()) {
		a.getScope().getGui().setSelectedAgent(a);
	}
}
 
Example 9
Source File: AgentsMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void widgetSelected(final SelectionEvent e) {
	final MenuItem mi = (MenuItem) e.widget;
	final IAgent a = (IAgent) mi.getData("agent");
	if (a != null && !a.dead()) {
		final IGui gui = a.getScope().getGui();
		if (gui.getHighlightedAgent() != a) {
			gui.setHighlightedAgent(a);
		} else {
			gui.setHighlightedAgent(null);
		}
		GAMA.getExperiment().refreshAllOutputs();
	}
}
 
Example 10
Source File: AgentsMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void widgetSelected(final SelectionEvent e) {
	final List<IDisplaySurface> surfaces = SwtGui.allDisplaySurfaces();
	final MenuItem mi = (MenuItem) e.widget;
	final IAgent a = (IAgent) mi.getData("agent");
	for (final IDisplaySurface surface : surfaces) {
		if (a instanceof ITopLevelAgent) {
			surface.zoomFit();
		} else if (a != null && !a.dead()) {
			surface.focusOn(a);
		}
	}
	GAMA.getExperiment().refreshAllOutputs();
}
 
Example 11
Source File: AgentsMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void widgetSelected(final SelectionEvent e) {
	final MenuItem mi = (MenuItem) e.widget;
	final IAgent a = (IAgent) mi.getData("agent");
	if (a != null && !a.dead()) {
		a.dispose();
		GAMA.getExperiment().refreshAllOutputs();
	}
}
 
Example 12
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void widgetSelected(final SelectionEvent e) {
	final MenuItem mi = (MenuItem) e.widget;
	final URI uri = (URI) mi.getData("uri");
	GAMA.getGui().editModel(null, uri);
}
 
Example 13
Source File: GamaColorMenu.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void widgetSelected(final SelectionEvent e) {
	final MenuItem item = (MenuItem) e.widget;
	colorComp = (Comparator) item.getData();
	reset();
}