public static void addPluginMenuItems(Composite composite,
MenuItem[] items, Menu parent, boolean prev_was_separator,
boolean enable_items, PluginMenuController controller) {
for (int i = 0; i < items.length; i++) {
final MenuItemImpl az_menuitem = (MenuItemImpl) items[i];
controller.notifyFillListeners(az_menuitem);
if (!az_menuitem.isVisible()) {continue;}
final int style = az_menuitem.getStyle();
final int swt_style;
boolean this_is_separator = false;
// Do we have any children? If so, we override any manually defined
// style.
boolean is_container = false;
if (style == TableContextMenuItem.STYLE_MENU) {
swt_style = SWT.CASCADE;
is_container = true;
} else if (style == TableContextMenuItem.STYLE_PUSH) {
swt_style = SWT.PUSH;
} else if (style == TableContextMenuItem.STYLE_CHECK) {
swt_style = SWT.CHECK;
} else if (style == TableContextMenuItem.STYLE_RADIO) {
swt_style = SWT.RADIO;
} else if (style == TableContextMenuItem.STYLE_SEPARATOR) {
this_is_separator = true;
swt_style = SWT.SEPARATOR;
} else {
swt_style = SWT.PUSH;
}
final org.eclipse.swt.widgets.MenuItem menuItem = new org.eclipse.swt.widgets.MenuItem(
parent, swt_style);
if (swt_style == SWT.SEPARATOR) {continue;}
if (prev_was_separator && this_is_separator) {continue;} // Skip contiguous separators
if (this_is_separator && i == items.length - 1) {continue;} // Skip trailing separator
prev_was_separator = this_is_separator;
if (enable_items) {
if (style == TableContextMenuItem.STYLE_CHECK
|| style == TableContextMenuItem.STYLE_RADIO) {
Boolean selection_value = (Boolean) az_menuitem.getData();
if (selection_value == null) {
throw new RuntimeException(
"MenuItem with resource name \""
+ az_menuitem.getResourceKey()
+ "\" needs to have a boolean value entered via setData before being used!");
}
menuItem.setSelection(selection_value.booleanValue());
}
}
final Listener main_listener = controller.makeSelectionListener(az_menuitem);
menuItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
if (az_menuitem.getStyle() == MenuItem.STYLE_CHECK
|| az_menuitem.getStyle() == MenuItem.STYLE_RADIO) {
if (!menuItem.isDisposed()) {
az_menuitem.setData(new Boolean(menuItem.getSelection()));
}
}
main_listener.handleEvent(e);
}
});
if (is_container) {
Menu this_menu = new Menu(composite.getShell(), SWT.DROP_DOWN);
menuItem.setMenu(this_menu);
addPluginMenuItems(composite, az_menuitem.getItems(), this_menu, false,
enable_items, controller);
}
String custom_title = az_menuitem.getText();
menuItem.setText(custom_title);
Graphic g = az_menuitem.getGraphic();
if (g instanceof UISWTGraphic) {
Utils.setMenuItemImage(menuItem, ((UISWTGraphic) g).getImage());
}
menuItem.setEnabled(enable_items && az_menuitem.isEnabled());
}
}