Package gov.nasa.arc.mct.gui

Examples of gov.nasa.arc.mct.gui.ContextAwareMenu


    }
   
    private List<ContextAwareMenu> getMenusByContext(String[] menuKeys, ActionContextImpl context) {
        List<ContextAwareMenu> list = new ArrayList<ContextAwareMenu>();
        for (String menuKey : menuKeys) {
            ContextAwareMenu menu = ActionManager.getMenu(menuKey, context);
            if (menu != null)
                list.add(menu);
        }
        return list;
    }   
View Full Code Here


        List<ContextAwareMenu> userObjectMenus = mBar.getUserObjectMenus(context);
        return createPopupMenu(context, userObjectMenus);
    }
   
   public static JPopupMenu createIconPopupMenu(ActionContextImpl context) {       
       ContextAwareMenu iconMenu = ActionManager.getMenu("Icon", context);
       return createPopupMenu(context, Collections.singletonList(iconMenu));
    }
View Full Code Here

       ContextAwareMenu iconMenu = ActionManager.getMenu("Icon", context);
       return createPopupMenu(context, Collections.singletonList(iconMenu));
    }
  
    public static JPopupMenu createViewPopupMenu(ActionContextImpl context) {
        ContextAwareMenu viewMenu = ActionManager.getMenu("VIEW_MENU", context);
        return createPopupMenu(context, Collections.singletonList(viewMenu));
    }
View Full Code Here

    }
   
    public static JPopupMenu createPopupMenu(ActionContextImpl context, List<ContextAwareMenu> menus) {
        JPopupMenu popupMenu = new JPopupMenu();
        for (int menuIndex = 0; menuIndex < menus.size(); menuIndex++) {
            ContextAwareMenu menu = menus.get(menuIndex);
           
            menu.initialize();

            if (menuIndex > 0)
                popupMenu.addSeparator();
           
            if (menu.canHandle(context)) {
                int lastPopulatedIndex = -1;
                List<MenuSection> sections = menu.getMenuSections();
                for (int sectionIndex = 0; sectionIndex < sections.size(); sectionIndex++) {
                    MenuSection section = sections.get(sectionIndex);
                    List<MenuItemInfo> menuItemInfoList = section.getMenuItemInfoList();
                   
                    for (MenuItemInfo info : menuItemInfoList) {
                        MenuItemType type = info.getType();
                        if (type == MenuItemType.SUBMENU) {
                            ContextAwareMenu submenu = ActionManager.getMenu(info.getCommandKey(), context);
                            if (submenu == null) continue;
                           
                            // Add a separator between sections
                            if (lastPopulatedIndex >= 0 && lastPopulatedIndex < sectionIndex)
                                popupMenu.addSeparator();
View Full Code Here

                    List<MenuItemInfo> menuItemInfoList = section.getMenuItemInfoList();
                   
                    for (MenuItemInfo info : menuItemInfoList) {
                        MenuItemType type = info.getType();
                        if (type == MenuItemType.SUBMENU) {
                            ContextAwareMenu submenu = ActionManager.getMenu(info.getCommandKey(), context);
                            if (submenu == null) continue;

                            addSeparatorIfNecessary(index);
                            menu.add(submenu);
                        } else {
View Full Code Here

    public static ContextAwareMenu getMenu(String commandKey, ActionContextImpl context) {
        List<Class<? extends ContextAwareMenu>> menuList = commandMenuMap.get(commandKey);
        if (menuList != null) {
            for (Class<? extends ContextAwareMenu> menuClass : menuList) {
                try {
                    ContextAwareMenu menu = menuClass.newInstance();
                    if (menu.canHandle(context)) {
                        menu.addMenuListener(MenuFactory.createMenuListener(menu));
                        // Populate built-in menus and/or menu items
                        menu.initialize();
                        // Populate extended menus and/or menu items
                        MenuExtensionManager manager = MenuExtensionManager.getInstance();
                        for (String menubarPath : menu.getExtensionMenubarPaths()) {
                            List<MenuItemInfo> extendedMenus = manager.getExtendedMenus(menubarPath);
                            menu.addMenuItemInfos(menubarPath, extendedMenus);                           
                        }
                        if (MENU_TOOLTIP_LOGGER.isDebugEnabled())
                            menu.setToolTipText(menu.getClass().getName());
                        return menu;
                    }
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
View Full Code Here

    }
   
    @Test
    public void testExportMenus() {
        // Create test objects
        ContextAwareMenu thisMenu = new ThisExportMenu();
        ContextAwareMenu objsMenu = new ObjectsExportMenu();
        thisMenu.initialize();
        objsMenu.initialize();       
       
        // Name is specified in code, so verify it
        Assert.assertEquals(thisMenu.getText(), "Export");
        Assert.assertEquals(objsMenu.getText(), "Export");
       
        // Should always return true to canHandle
        Assert.assertTrue(thisMenu.canHandle(null));
        Assert.assertTrue(objsMenu.canHandle(null));
       
        // Verify that expected extension points are published
        String[] thisExts = thisMenu.getExtensionMenubarPaths();
        String[] objsExts = objsMenu.getExtensionMenubarPaths();
        Assert.assertEquals(thisExts[0], "/this/export.ext");
        Assert.assertEquals(objsExts[0], "/objects/export.ext");
       
        // Verify that export to image is included
        Assert.assertTrue(find("EXPORT_THIS_TO_IMAGE", thisMenu));
View Full Code Here

    }

    @Test
    public void testImportMenus() {
        // Create test objects
        ContextAwareMenu thisMenu = new ThisImportMenu();
        ContextAwareMenu objsMenu = new ObjectsImportMenu();
        thisMenu.initialize();
        objsMenu.initialize();
       
        // Name is specified in code, so verify it
        Assert.assertEquals(thisMenu.getText(), "Import");
        Assert.assertEquals(objsMenu.getText(), "Import");
       
        // Verify that expected extension points are published
        String[] thisExts = thisMenu.getExtensionMenubarPaths();
        String[] objsExts = objsMenu.getExtensionMenubarPaths();
        Assert.assertEquals(thisExts[0], "/this/import.ext");
        Assert.assertEquals(objsExts[0], "/objects/import.ext");       

       
        // Should only handle single, writable targets...
       
        // Set up mocks
        ActionContext mockContext = Mockito.mock(ActionContext.class);
        PolicyManager mockPolicy = Mockito.mock(PolicyManager.class);
        AbstractComponent mockComponent = Mockito.mock(AbstractComponent.class);
        View mockView = Mockito.mock(View.class);
        String compositionKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY.getKey();
       
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicy);
       
        // First, This's Import menu
        // No window active - should disallow
        Mockito.when(mockContext.getWindowManifestation()).thenReturn(null);
        Assert.assertFalse(thisMenu.canHandle(mockContext));
       
        // Active window but component is null - should disallow
        Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockView);
        Mockito.when(mockView.getManifestedComponent()).thenReturn(null);
        Assert.assertFalse(thisMenu.canHandle(mockContext));
       
        // Has a window, but policy says no - should disallow
        Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockView);
        Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, false, ""));
        Assert.assertFalse(thisMenu.canHandle(mockContext));
       
        // If policy allows, then canHandle should be true
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, true, ""));
        Assert.assertTrue(thisMenu.canHandle(mockContext));
       
       
        // Second, Objects's Import menu
        // Null selections - should disallow
        Mockito.when(mockContext.getSelectedManifestations()).thenReturn(null);
        Assert.assertFalse(objsMenu.canHandle(mockContext));

        // Empty selections - should disallow
        Mockito.when(mockContext.getSelectedManifestations())
            .thenReturn(Collections.<View>emptyList());
        Assert.assertFalse(objsMenu.canHandle(mockContext));
       
        // One selection but policy says no - should disallow
        Mockito.when(mockContext.getSelectedManifestations())
            .thenReturn(Arrays.asList(mockView));
        Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);       
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, false, ""));              
        Assert.assertFalse(objsMenu.canHandle(mockContext));
       
        // One selection but policy says yes - should allow!
        Mockito.when(mockContext.getSelectedManifestations())
            .thenReturn(Arrays.asList(mockView));
        Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);       
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, true, ""));              
        Assert.assertTrue(objsMenu.canHandle(mockContext));
       
        // Multiple selections, even though policy says yes - should disallow
        Mockito.when(mockContext.getSelectedManifestations())
            .thenReturn(Arrays.asList(mockView, mockView));
        Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);       
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, true, ""));              
        Assert.assertFalse(objsMenu.canHandle(mockContext));

    }
View Full Code Here

        Assert.assertEquals(new ThisMenu().getText(), "This");
    }

    @Test
    public void testThisOrder() {
        ContextAwareMenu thisMenu = new ThisMenu() {
            private static final long serialVersionUID = 1L;
            {
                populate();
            }
        };
        List<MenuSection> menuSections = thisMenu.getMenuSections();
       
        // Should have multiple sections (quit should be in its own)
        Assert.assertTrue(menuSections.size() > 1);
       
        // Quit should be at the bottom of the last section
View Full Code Here

TOP

Related Classes of gov.nasa.arc.mct.gui.ContextAwareMenu

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.