Package gov.nasa.arc.mct.gui

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


                                popupMenu.addSeparator();
                            lastPopulatedIndex = sectionIndex;
                           
                            popupMenu.add(submenu);
                        } else {
                            ContextAwareAction action = ActionManager.getAction(info.getCommandKey(), context);

                            if (action == null) continue;

                            action.putValue(Action.ACTION_COMMAND_KEY, info.getCommandKey());
                           
                            // Add a separator between sections
                            if (lastPopulatedIndex >= 0 && lastPopulatedIndex < sectionIndex)
                                popupMenu.addSeparator();
                            lastPopulatedIndex = sectionIndex;
View Full Code Here


                            if (submenu == null) continue;

                            addSeparatorIfNecessary(index);
                            menu.add(submenu);
                        } else {
                            ContextAwareAction action = ActionManager.getAction(info.getCommandKey(), context);

                            if (action == null) continue;
                           
                            action.putValue(Action.ACTION_COMMAND_KEY, info.getCommandKey());
                           
                            addSeparatorIfNecessary(index);
                            boolean autoStartTransaction = isMenuInDirectoryArea(context);
                           
                            // Add menu item(s) by type
View Full Code Here

    }
   
    @Test
    public void testIsEnabled() {
        // Should always be enabled if canHandle
        ContextAwareAction refresh = new RefreshAction();
       
        // Verify precondition (also verifed in previous test)
        // canHandle is a necessary part of ContextAwareAction life cycle
        Assert.assertTrue(refresh.canHandle(mockContext));
       
        // Verify that refresh menu item is enabled
        Assert.assertTrue(refresh.isEnabled());
    }
View Full Code Here

        // Similarly, newer version of the view
        View newerView = Mockito.mock(View.class);
        Mockito.when(mockViewInfo.createView(newerComponent)).thenReturn(newerView);
       
        // Create refresh action, obey life cycle
        ContextAwareAction refresh = new RefreshAction();
        Assert.assertTrue(refresh.canHandle(mockContext));
       
        // Verify preconditions
        Mockito.verifyZeroInteractions(mockWindowManager);
        Mockito.verifyZeroInteractions(mockContentArea);
        Mockito.verifyZeroInteractions(mockViewInfo);
       
        // Perform action
        refresh.actionPerformed(mockEvent);
       
        // Verify that view was updated
        Mockito.verify(mockViewInfo).createView(newerComponent);
        Mockito.verify(mockContentArea).setOwnerComponentCanvasManifestation(newerView);
       
View Full Code Here

                return confirmed ? options[0] : options[1]; // options[0] presumed to mean "OK"
            }
        });
       
        // Create refresh action, obey life cycle
        ContextAwareAction refresh = new RefreshAction();
        Assert.assertTrue(refresh.canHandle(mockContext));
       
        // Verify preconditions
        Mockito.verifyZeroInteractions(mockWindowManager);
        Mockito.verifyZeroInteractions(mockContentArea);
        Mockito.verifyZeroInteractions(mockViewInfo);       
              
        // Perform action
        refresh.actionPerformed(mockEvent);

        // Verify that dialog was invoked
        Mockito.verify(mockWindowManager).showInputDialog(Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.<Map<String,Object>>any());
       
        // Verify that view was updated only if confirmed
View Full Code Here

    public void testInspector() {
        // Verify interactions with a mock inspector
        Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockInspector);
       
        // Verify that refresh can handle, is enabled for an Inspector
        ContextAwareAction refresh = new RefreshAction();
        Assert.assertTrue(refresh.canHandle(mockContext));
        Assert.assertTrue(refresh.isEnabled());
       
        // Verify actionPerformed triggers appropriate method
        refresh.actionPerformed(mockEvent);
        Mockito.verify(mockInspector).setHousedViewManifestation(mockViewInfo);
    }
View Full Code Here

  
    @Test (dataProvider = "generateTestCases")
    public void testQuitEnabled(boolean confirmed, int housings) {
        // Verifies that QuitAction is available in appropriate cases
        initializeRegistry(housings);
        ContextAwareAction quit = new QuitAction();
   
        // Should only handle or be enabled when there are windows open
        Assert.assertEquals(quit.canHandle(mockActionContext), housings > 0);
        Assert.assertEquals(quit.isEnabled(), housings > 0);
    }
View Full Code Here

    @Test (dataProvider = "generateTestCases")
    public void testActionPerformed(final boolean confirmed, int housings) throws Exception {
        // Verifies that performing a QuitAction closes all windows, stops OSGI
        // (except where user input indicates otherwise)
        MCTAbstractHousing[] mockHousings = initializeRegistry(housings);
        ContextAwareAction quit = new QuitAction();
        Mockito.reset(mockRuntime);
       
        // Set up window manager to support dialog call
        // Act as though the user clicked "OK" or "Cancel" (depending on argument "confirmed")
        WindowManager mockWindowManager = Mockito.mock(WindowManager.class);
        Mockito.when(mockPlatform.getWindowManager()).thenReturn(mockWindowManager);
        Mockito.when(mockWindowManager.showInputDialog(Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.<Map<String,Object>>any())).thenAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                Object[] options = (Object[]) invocation.getArguments()[2];
                return confirmed ? options[0] : options[1]; // options[0] presumed to mean "OK"
            }
        });
       
        // Already tested in testQuitEnabled, but also need to obey action's life cycle
        Assert.assertEquals(quit.canHandle(mockActionContext), housings > 0);
       
        // Trigger the action - this is the method we are testing
        quit.actionPerformed(mockEvent);
       
        // A dialog should have been requested
        Mockito.verify(mockWindowManager, Mockito.times(1)).showInputDialog(Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.<Map<String,Object>>any());
       
        // All housings should be closed, iff dialog was confirmed
View Full Code Here

       
        // Suppress housing removal (as though user had kept window open)
        doRemoveHousings = false;
       
        MCTAbstractHousing[] mockHousings = initializeRegistry(housings);
        ContextAwareAction quit = new QuitAction();
        Mockito.reset(mockRuntime);
       
        // Set up window manager to support dialog call
        // Act as though the user clicked "OK" or "Cancel" (depending on argument "confirmed")
        WindowManager mockWindowManager = Mockito.mock(WindowManager.class);
        Mockito.when(mockPlatform.getWindowManager()).thenReturn(mockWindowManager);
        Mockito.when(mockWindowManager.showInputDialog(Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.<Map<String,Object>>any())).thenAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                Object[] options = (Object[]) invocation.getArguments()[2];
                return confirmed ? options[0] : options[1]; // options[0] presumed to mean "OK"
            }
        });
       
        // Already tested in testQuitEnabled, but also need to obey action's life cycle
        Assert.assertEquals(quit.canHandle(mockActionContext), housings > 0);
       
        // Trigger the action - this is the method we are testing
        quit.actionPerformed(mockEvent);
       
        // A dialog should have been requested
        Mockito.verify(mockWindowManager, Mockito.times(1)).showInputDialog(Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.<Map<String,Object>>any());
       
        // All housings should be closed, iff dialog was confirmed
View Full Code Here

        if (actionClassList == null)
            return null;

        for (Class<? extends ContextAwareAction> actionClass : actionClassList) {
            try {
                ContextAwareAction action = actionClass.newInstance();
                if (action.canHandle(context))
                    return action;
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
View Full Code Here

TOP

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

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.