use of org.eclipse.swt.widgets.Menu 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.Menu 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.Menu 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.Menu in project cogtool by cogtool.
the class MenuFactory method rebuildAllMenus.
public static void rebuildAllMenus() {
Menu[] menus = windowMenus.toArray(new Menu[windowMenus.size()]);
for (Menu menu : menus) {
IWindowMenuData<?> menuData = (IWindowMenuData<?>) menu.getData();
menuData.getView().rebuildMenus();
menuData.setInitiallyEnabledItems();
}
}
use of org.eclipse.swt.widgets.Menu in project cogtool by cogtool.
the class ProjectUI method showContextMenu.
// Override to set the correct context menu on the frame
// item item-selected column design where selection to use
//(a) ok n/a ok ok cell temporary cell
//(b) ok yes ok null task normal selection
//(c) ok no ok null task temporary task
//(d) ok n/a null n/a right of cells temporary task
//(e) null n/a ok ok design temporary design
//(f) null n/a ok null bottom-left no selection
//(g) null n/a null n/a bottom-right no selection
// TODO: dfm -- make the code match the above!!!!!
@Override
public void showContextMenu(int x, int y) {
// Clear any stale state
contextSelection.deselectAll();
// Check which region of the frame was hit
TreeItem item = tree.getItem(new Point(x, y));
TreeColumn column = findColumn(x);
// See if the context invocation was made beyond all designs
if (column == null) {
if (item == null) {
// see (g) above
showContextMenu();
} else {
// see (d) above
selectOverBox(item.getBounds());
contextSelection.addSelectedTask((AUndertaking) item.getData());
showContextMenu(contextSelection, View.CONTEXT);
}
} else // If not, the invocation occurred somewhere within the table
{
Design design = (Design) column.getData();
// Detect a context invocation in the table header/footer
if (item == null) {
// Detect a context invocation under the "tasks" heading
if (design == null) {
// see (f) above
showContextMenu();
} else // Otherwise the invocation lies under a design heading
{
// see (e) above
// TODO: Really? What if something else was selected?
selectOverBox(computeColumnArea(column));
contextSelection.setSelectedDesign(design);
showContextMenu(contextSelection, View.CONTEXT);
}
} else // Detect a context invocation inside the table body
{
AUndertaking undertaking = (AUndertaking) item.getData();
// Check for context invocation under the "tasks" column
if (design == null) {
// Set up the contextual selection state as necessary
if (selection.isTaskSelected(undertaking)) {
// see (b) above
showContextMenu();
} else {
// see (c) above
selectOverBox(item.getBounds());
contextSelection.addSelectedTask(undertaking);
showContextMenu(contextSelection, View.CONTEXT);
}
} else // Otherwise at the intersection of a task and a design
{
// see (a) above
selection.setSelectedCell(item, column);
Rectangle bounds = item.getBounds(tree.indexOf(column));
if (OSUtils.MACOSX) {
// XXX: DIRTY HACK TO fix SWT bug.
bounds.y -= 1;
bounds.height += 1;
}
selectOverBox(bounds);
// TODO: instead of the following, pass undertaking and
// design in to showContextMenuForIntersection()
Menu contextMenu = view.getContextMenuForIntersection(project, undertaking, design);
// Set up the contextual selection state as necessary
contextSelection.setSelectedDesign(design);
contextSelection.addSelectedTask(undertaking);
setViewEnabledState(contextSelection, ListenerIdentifierMap.CONTEXT);
contextMenu.setVisible(true);
}
}
}
}
Aggregations