Search in sources :

Example 1 with Menu

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);
        }
    }
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 2 with Menu

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;
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 3 with Menu

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());
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 4 with Menu

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();
    }
}
Also used : Menu(org.eclipse.swt.widgets.Menu)

Example 5 with Menu

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);
            }
        }
    }
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Menu(org.eclipse.swt.widgets.Menu)

Aggregations

Menu (org.eclipse.swt.widgets.Menu)685 MenuManager (org.eclipse.jface.action.MenuManager)301 MenuItem (org.eclipse.swt.widgets.MenuItem)266 IMenuManager (org.eclipse.jface.action.IMenuManager)238 SelectionEvent (org.eclipse.swt.events.SelectionEvent)218 IMenuListener (org.eclipse.jface.action.IMenuListener)187 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)185 Point (org.eclipse.swt.graphics.Point)116 Composite (org.eclipse.swt.widgets.Composite)96 GridLayout (org.eclipse.swt.layout.GridLayout)79 GridData (org.eclipse.swt.layout.GridData)76 Separator (org.eclipse.jface.action.Separator)61 Rectangle (org.eclipse.swt.graphics.Rectangle)60 Label (org.eclipse.swt.widgets.Label)59 Button (org.eclipse.swt.widgets.Button)55 ArrayList (java.util.ArrayList)49 Event (org.eclipse.swt.widgets.Event)49 SelectionListener (org.eclipse.swt.events.SelectionListener)46 Shell (org.eclipse.swt.widgets.Shell)46 List (java.util.List)43