Search in sources :

Example 1 with ListenerIdentifier

use of edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier 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;
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) ListenerIdentifier(edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier) RcvrUIException(edu.cmu.cs.hcii.cogtool.util.RcvrUIException)

Example 2 with ListenerIdentifier

use of edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier in project cogtool by cogtool.

the class DefaultUI method buildLeadItems.

/**
     * Support for creating the lead items for the Window menu.
     *
     * @param p the project either to restore or as the parent of the
     *          given design
     * @param d the design either to restore or <code>null</code> if
     *          restoring the project's window
     * @author mlh
     */
protected static MenuItemDefinition[] buildLeadItems(Project p, Design d) {
    ListenerIdentifier openProjectLID = null;
    ListenerIdentifier openDesignLID = null;
    boolean openProjectEnabled = MenuUtil.DISABLED;
    boolean openDesignEnabled = MenuUtil.DISABLED;
    String openProjectLabel = OPEN_PROJECT_LABEL;
    String openDesignLabel = OPEN_DESIGN_LABEL;
    // Check to create standard LID's for opening design & project
    if (p != null) {
        openProjectLID = new RestoreParentControllerLID(p, null);
        openProjectEnabled = MenuUtil.ENABLED;
        openProjectLabel = openProjectLabel + ": " + p.getName();
        if (d != null) {
            openDesignLID = new RestoreParentControllerLID(p, d);
            openDesignEnabled = MenuUtil.ENABLED;
            openDesignLabel = openDesignLabel + ": " + d.getName();
        }
    }
    return new MenuItemDefinition[] { new SimpleMenuItemDefinition(openProjectLabel, openProjectLID, openProjectEnabled), new SimpleMenuItemDefinition(openDesignLabel, openDesignLID, openDesignEnabled), MenuUtil.SEPARATOR };
}
Also used : SimpleMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition) SimpleMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition) MenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition) ListenerIdentifier(edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier)

Example 3 with ListenerIdentifier

use of edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier in project cogtool by cogtool.

the class MenuFactory method updateNexusCascadeItem.

protected static void updateNexusCascadeItem(Menu inNexusMenu, IWindowMenuData<?> menuData) {
    ListenerIdentifier itemLID = menuData.getLID();
    MenuItem[] windowMenuItems = inNexusMenu.getItems();
    int originalItemCount = windowMenuItems.length;
    for (int i = 0; i < originalItemCount; i++) {
        if (windowMenuItems[i].getData() == itemLID) {
            windowMenuItems[i].setText(menuData.getEntryLabel());
            return;
        }
    }
    throw new RcvrUIException("Cannot find window item");
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) ListenerIdentifier(edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier) RcvrUIException(edu.cmu.cs.hcii.cogtool.util.RcvrUIException)

Example 4 with ListenerIdentifier

use of edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier in project cogtool by cogtool.

the class ProjectUI method transmute.

/**
     * Transforms an "object-oriented" <code>ListenerIdentifier</code>
     * into a more specific value representing an actual, concrete
     * application function, depending upon the internal state of the
     * application itself (such as, based on what application elements
     * are currently selected).
     * <p>
     * If there is no more specific value for the given <code>id</code>,
     * the input value should be returned unchanged.
     *
     * @param id the key specifying the semantic nature of the
     *           action to be performed
     * @return the specific value representing an actual, concrete
     *         application function, or, if none exists, the input value
     * @author mlh
     */
@Override
public ListenerIdentifier transmute(ListenerIdentifier id, boolean isContextSelection) {
    ListenerIdentifier specificLID = super.transmute(id, isContextSelection);
    // Check if super has already specialized this
    if (specificLID != id) {
        return specificLID;
    }
    ProjectSelectionState sel;
    if (isContextSelection) {
        sel = contextSelection;
    } else {
        sel = selection;
    }
    // Give priority to design stuff
    if (sel.getSelectedDesign() != null) {
        if (sel.getSelectedTaskCount() == 1) {
            specificLID = ProjectLID.scriptLIDs.get(id);
            if (ProjectLID.EditScript.equals(specificLID)) {
                if (sel.getSelectedTaskCount() == 1) {
                    AUndertaking t = sel.getSelectedTask();
                    if (sel.getSelectedTask().isTaskGroup()) {
                        if (((TaskGroup) t).getNature() == GroupNature.SUM) {
                            specificLID = ProjectLID.ViewGroupScript;
                        }
                    }
                }
            }
        } else {
            specificLID = ProjectLID.designLIDs.get(id);
        }
    } else // Fallback to undertaking stuff if necessary
    {
        specificLID = ProjectLID.taskLIDs.get(id);
    }
    return (specificLID != null) ? specificLID : id;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) ListenerIdentifier(edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier)

Example 5 with ListenerIdentifier

use of edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier in project cogtool by cogtool.

the class DesignEditorUI method transmute.

// LID Transmuter Stuff
@Override
public ListenerIdentifier transmute(ListenerIdentifier id, boolean isContextSelection) {
    ListenerIdentifier specificLID = super.transmute(id, isContextSelection);
    // Check if super has already specialized this
    if (specificLID != id) {
        return specificLID;
    }
    DesignEditorSelectionState seln = isContextSelection ? contextSelection : selection;
    // Give priority to frame stuff
    if (seln.getSelectedFrameCount() > 0) {
        if ((id == CogToolLID.Paste) && ClipboardUtil.hasImageData()) {
            return CogToolLID.PasteBackgroundImage;
        }
        specificLID = DesignEditorLID.frameLIDs.get(id);
    } else // Fallback to undertaking stuff if necessary
    {
        specificLID = DesignEditorLID.transitionLIDs.get(id);
    }
    return (specificLID != null) ? specificLID : id;
}
Also used : ListenerIdentifier(edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier)

Aggregations

ListenerIdentifier (edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier)5 RcvrUIException (edu.cmu.cs.hcii.cogtool.util.RcvrUIException)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)1 MenuItemDefinition (edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition)1 SimpleMenuItemDefinition (edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition)1