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

The following examples show how to use org.eclipse.swt.widgets.Menu#addListener() . 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: GamlReferenceMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public void installSubMenuIn(final Menu menu) {
	final MenuItem builtInItem = new MenuItem(menu, SWT.CASCADE);
	builtInItem.setText(getTitle());
	builtInItem.setImage(getImage());
	mainMenu = new Menu(builtInItem);
	builtInItem.setMenu(mainMenu);
	mainMenu.addListener(SWT.Show, e -> {
		if (mainMenu.getItemCount() > 0) {
			for (final MenuItem item : mainMenu.getItems()) {
				item.dispose();
			}
		}
		fillMenu();
	});

}
 
Example 2
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param menu
 */
private void createOtherExperiments(final Menu menu) {

	final MenuItem usedIn = new MenuItem(menu, SWT.CASCADE);
	usedIn.setText(" Other experiments...");
	usedIn.setImage(GamaIcons.create("other.experiments").image());
	final Menu sub = new Menu(usedIn);
	usedIn.setMenu(sub);
	sub.addListener(SWT.Show, e -> {
		for (final MenuItem item : sub.getItems()) {
			item.dispose();
		}
		createOtherSubMenu(sub, getEditor());
	});

}
 
Example 3
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 4
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 5
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param menu
 */
private void createUsedIn(final Menu menu) {
	final MenuItem usedIn = new MenuItem(menu, SWT.CASCADE);
	usedIn.setText(" Imported in...");
	usedIn.setImage(GamaIcons.create("imported.in").image());
	final Menu sub = new Menu(usedIn);
	usedIn.setMenu(sub);
	sub.addListener(SWT.Show, e -> {
		for (final MenuItem item : sub.getItems()) {
			item.dispose();
		}
		createImportedSubMenu(sub, getEditor());
	});
}
 
Example 6
Source File: GroupPage.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void createMoveMenu() {
	Menu menu = new Menu(processViewer.getTable());
	processViewer.getTable().setMenu(menu);
	MenuItem item = new MenuItem(menu, SWT.CASCADE);
	item.setText(M.Move);
	groupMoveMenu = new Menu(item);
	item.setMenu(groupMoveMenu);
	groupMoveMenu.addListener(SWT.Show, new MenuGroupListener());
}
 
Example 7
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void fill(final Menu m, final int index) {

	final MenuItem menuItem = new MenuItem(m, SWT.CASCADE);
	menuItem.setText("Model");
	final Menu menu = new Menu(menuItem);
	if (menuItem.getMenu() != null) {
		menuItem.getMenu().dispose();
	}
	menuItem.setMenu(menu);
	menu.addListener(SWT.Show, e -> {
		markPref = GamaPreferences.get("pref_editor_mark_occurrences", Boolean.class);
		for (final MenuItem item : menu.getItems()) {
			item.dispose();
		}
		if (getEditor() != null) {
			GamaMenu.separate(menu, "Presentation");
			GamaMenu.separate(menu);
			createLineToggle(menu);
			createFoldingToggle(menu);
			createMarkToggle(menu);
			createBoxToggle(menu);
			createOverviewToggle(menu);
			GamaMenu.separate(menu);
			GamaMenu.separate(menu, "Insert");
			GamaMenu.separate(menu);
			createReferenceMenus(menu);
			GamaMenu.separate(menu);
			GamaMenu.separate(menu, "Model");
			GamaMenu.separate(menu);
			createUsedIn(menu);
			createOtherExperiments(menu);
			GamaMenu.separate(menu);
			createValidate(menu);
			// line.setSelection(getEditor().isLineNumberRulerVisible());
			// folding.setSelection(getEditor().isRangeIndicatorEnabled());
			// box.setSelection(getEditor().isDecorationEnabled());
			initializePreferences();
			// mark.setSelection(markPref.getValue());
		}
		createValidateAll(menu);
	});

}
 
Example 8
Source File: AgentsMenu.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public static void fillPopulationSubMenu(final Menu menu, final Collection<? extends IAgent> species,
		final MenuAction... actions) {
	final boolean isSimulations = species instanceof SimulationPopulation;
	int subMenuSize = GamaPreferences.Interface.CORE_MENU_SIZE.getValue();
	if (subMenuSize < 2) {
		subMenuSize = 2;
	}
	final List<IAgent> agents = new ArrayList<>(species);
	final int size = agents.size();
	if (size > 1 && !isSimulations) {
		GamaMenu.separate(menu, "Actions");
	}

	if (size > 1) {
		browsePopulationMenuItem(menu, species, GamaIcons.create(IGamaIcons.MENU_BROWSE).image());
	}

	if (size > 1 && !isSimulations) {
		GamaMenu.separate(menu);
		GamaMenu.separate(menu, "Agents");
	}
	if (size < subMenuSize) {
		for (final IAgent agent : agents) {
			cascadingAgentMenuItem(menu, agent, agent.getName(), actions);
		}
	} else {
		final int nb = size / subMenuSize + 1;
		for (int i = 0; i < nb; i++) {
			final int begin = i * subMenuSize;
			final int end = Math.min((i + 1) * subMenuSize, size);
			if (begin >= end) {
				break;
			}
			final MenuItem rangeItem = new MenuItem(menu, SWT.CASCADE);
			final Menu rangeMenu = new Menu(rangeItem);
			rangeItem.setMenu(rangeMenu);
			rangeItem.setText("" + begin + " to " + (end - 1));
			rangeItem.setImage(GamaIcons.create(IGamaIcons.MENU_POPULATION).image());
			rangeMenu.addListener(SWT.Show, e -> {
				if (!menu.isVisible()) { return; }
				final MenuItem[] items = rangeMenu.getItems();
				for (final MenuItem item : items) {
					item.dispose();
				}
				for (int j = begin; j < end; j++) {
					final IAgent ag = agents.get(j);
					if (ag != null && !ag.dead()) {
						cascadingAgentMenuItem(rangeMenu, ag, ag.getName(), actions);
					}
				}
			});

		}
	}
}