use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.
the class MenuFactory method ensureNexusCascade.
// createNexusCascade
protected static Menu ensureNexusCascade(Menu windowMenu, MenuItem[] windowMenuItems, IWindowMenuData<?> menuData) {
String nexusLabel = menuData.getNexusLabel();
Class<?> nexusType = menuData.getNexusType();
Object nexusData = menuData.getNexusData();
int i;
for (i = windowMenuItems.length; i > 0; i--) {
MenuItem windowItem = windowMenuItems[i - 1];
if ((windowItem.getStyle() == SWT.CASCADE) && (nexusType != null) && nexusType.isInstance(windowItem.getData())) {
if (windowItem.getData() == nexusData) {
return windowItem.getMenu();
}
// Check if the current nexus item comes after nexusLabel
if (windowItem.getText().compareToIgnoreCase(nexusLabel) < 0) {
break;
}
} else {
// no longer within the group of nexus cascades
break;
}
}
return createNexusCascade(windowMenu, i, menuData);
}
use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.
the class MenuFactory method copyExistingNexusWindows.
protected static void copyExistingNexusWindows(MenuItem existingNexusItem, Menu newWindowMenu) {
MenuItem newNexusItem = new MenuItem(newWindowMenu, SWT.CASCADE);
newNexusItem.setText(existingNexusItem.getText());
newNexusItem.setImage(existingNexusItem.getImage());
// the nexus!
newNexusItem.setData(existingNexusItem.getData());
Menu newNexusMenu = new Menu(newWindowMenu.getShell(), SWT.DROP_DOWN);
newNexusItem.setMenu(newNexusMenu);
MenuItem[] nestedNexusItems = existingNexusItem.getMenu().getItems();
for (MenuItem nestedNexusItem : nestedNexusItems) {
MenuItem newNestedItem = new MenuItem(newNexusMenu, nestedNexusItem.getStyle());
newNestedItem.setText(nestedNexusItem.getText());
newNestedItem.setImage(nestedNexusItem.getImage());
Object windowLID = nestedNexusItem.getData();
if (windowLID != null) {
newNestedItem.setData(windowLID);
newNestedItem.addListener(SWT.Selection, windowItemSelectionListener);
}
}
}
use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.
the class MenuFactory method createNexusCascade.
// copyExistingWindows
protected static Menu createNexusCascade(Menu windowMenu, int index, IWindowMenuData<?> menuData) {
MenuItem newNexusItem = (index != -1) ? new MenuItem(windowMenu, SWT.CASCADE, index) : new MenuItem(windowMenu, SWT.CASCADE);
Menu cascadeParent = new Menu(windowMenu.getShell(), SWT.DROP_DOWN);
newNexusItem.setMenu(cascadeParent);
newNexusItem.setText(menuData.getNexusLabel());
// the nexus!
newNexusItem.setData(menuData.getNexusData());
return cascadeParent;
}
use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.
the class MenuFactory method addWindowMenu.
// addToCascade
protected static void addWindowMenu(Menu newWindowMenu, IWindowMenuData<?> menuData) {
if (windowMenus.size() > 0) {
copyExistingWindows(windowMenus.get(0), newWindowMenu);
}
// Add to global registry
windowMenus.add(newWindowMenu);
newWindowMenu.setData(menuData);
// i.e. the RootView will not be added!
if (menuData.getNexusData() != null) {
Iterator<Menu> menus = windowMenus.iterator();
while (menus.hasNext()) {
Menu windowMenu = menus.next();
Menu nexusCascade = null;
// Remove the last item if it is the NO_WINDOWS_SENTINEL
MenuItem[] nexusItems = windowMenu.getItems();
if (nexusItems.length > 0) {
MenuItem lastItem = nexusItems[nexusItems.length - 1];
if (lastItem.getData() == NO_WINDOWS_SENTINEL) {
lastItem.dispose();
nexusCascade = createNexusCascade(windowMenu, -1, menuData);
}
}
if (nexusCascade == null) {
nexusCascade = ensureNexusCascade(windowMenu, nexusItems, menuData);
}
addToCascade(nexusCascade, menuData);
}
newWindowMenu.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
removeWindowMenu((Menu) e.getSource());
}
});
} else {
newWindowMenu.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
windowMenus.remove(e.getSource());
}
});
}
}
use of org.eclipse.swt.widgets.MenuItem in project cogtool by cogtool.
the class MenuFactory method removeNexusCascadeItem.
// Returns true if it removed the last item from the cascade
protected static boolean removeNexusCascadeItem(Menu fromNexusMenu, IWindowMenuData<?> menuData) {
ListenerIdentifier itemLID = menuData.getLID();
boolean precedingWasSeparator = false;
MenuItem[] windowMenuItems = fromNexusMenu.getItems();
int originalItemCount = windowMenuItems.length;
int i;
for (i = 0; i < originalItemCount; i++) {
MenuItem windowItem = windowMenuItems[i];
Object itemData = windowItem.getData();
if (itemData == null) {
// indicates a SEPARATOR
precedingWasSeparator = true;
} else if (itemData == itemLID) {
windowItem.dispose();
break;
} else {
precedingWasSeparator = false;
}
}
if (i == originalItemCount) {
throw new RcvrUIException("Cannot find window item");
}
// Check if we need to remove a SEPARATOR
if (i == 0) {
if ((originalItemCount > 1) && (windowMenuItems[1].getData() == null)) {
// Removed first and second was a SEPARATOR; remove it
windowMenuItems[1].dispose();
}
} else if (precedingWasSeparator) {
// following item is also a SEPARATOR; if so, remove preceding.
if (((i + 1) == originalItemCount) || (windowMenuItems[i + 1].getData() == null)) {
windowMenuItems[i - 1].dispose();
}
}
// Return true if no items remain
return fromNexusMenu.getItems().length == 0;
}
Aggregations