Package gov.nasa.arc.mct.gui

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


        Assert.assertTrue(rootNode.isProxy());
    }

    @Test
    public void testGetParentView() {
        MCTMutableTreeNode mockTreeNode = Mockito.mock(MCTMutableTreeNode.class);
        MCTMutableTreeNode mockParentNode = Mockito.mock(MCTMutableTreeNode.class);
        View mockView = Mockito.mock(View.class);
        Mockito.when(mockTreeNode.getParent()).thenReturn(mockParentNode);
        Mockito.when(mockParentNode.getUserObject()).thenReturn(mockView);
        nodeViewManifestation.addMonitoredGUI(mockTreeNode);
       
        // Should not matter whether or not node is a proxy
        // nasa/mct#261
        for (boolean truth : new boolean[]{false, true}) {
View Full Code Here


        if (!(activeHousing.getDirectoryArea() instanceof MCTDirectoryArea)) {
            return false;
        }
       
        MCTDirectoryArea directory = MCTDirectoryArea.class.cast(activeHousing.getDirectoryArea());
        MCTMutableTreeNode firstSelectedNode = directory.getSelectedDirectoryNode();
       
        if (firstSelectedNode == null)
            return false;
       
        JTree tree = firstSelectedNode.getParentTree();
        selectedTreePaths = tree.getSelectionPaths();
        return selectedTreePaths != null && selectedTreePaths.length > 0;
    }
View Full Code Here

   
    @Override
    public void actionPerformed(ActionEvent e) {
        Set<String> deleteComponents = new HashSet<String>();
        for (TreePath path : selectedTreePaths) {
            MCTMutableTreeNode selectedNode = (MCTMutableTreeNode) path.getLastPathComponent();           
            AbstractComponent selectedComponent = ((View) selectedNode.getUserObject()).getManifestedComponent();
           
            // If has children, 
            if (selectedComponent.getComponents().size() > 0) {
                handleWarnings(false, deleteComponents);
                return;
View Full Code Here

        warning.add(scrollPane2);
        return warning;
    }
   
    private boolean isRemovable(TreePath path) {
        MCTMutableTreeNode lastPathComponent = (MCTMutableTreeNode) path.getLastPathComponent();
        AbstractComponent selectedComponent = View.class.cast(lastPathComponent.getUserObject()).getManifestedComponent();

        MCTMutableTreeNode parentNode = (MCTMutableTreeNode) lastPathComponent.getParent();
        if (parentNode == null)
            return false;

        AbstractComponent parentComponent = ((View) parentNode.getUserObject()).getManifestedComponent();       
        if (!selectedComponent.canBeDeleted()) {
            return false;
        }
       
       
View Full Code Here

                visibleChildComponents.add(childComponent);
            }
            if (visibleChildComponents.size() == node.getChildCount()) {
                boolean changed = false; // Same number of children - but have any changed or moved?
                for (int index = 0; index < visibleChildComponents.size(); index++) {
                    MCTMutableTreeNode treeNode = (MCTMutableTreeNode) node.getChildAt(index);
                    AbstractComponent nodeComponent = ((View) treeNode.getUserObject()).getManifestedComponent();
                    if (!nodeComponent.getComponentId().equals(visibleChildComponents.get(index).getComponentId())) {
                        changed = true;
                        break;
                    }
                }
                if (!changed) return; // Don't continue with refresh if children are unchanged.
            }               

            // Note currently expanded nodes to restore state after re-ordering
            Set<String> expanded = new HashSet<String>();
            for (int index = 0; index < node.getChildCount(); index++) {
                MCTMutableTreeNode childNode = (MCTMutableTreeNode) node.getChildAt(index);
                View childView = (View) childNode.getUserObject();
                if (parentTree.isExpanded(childNode.getTreePath()))
                    expanded.add(childView.getManifestedComponent().getComponentId());              
            }
           
            // Insert nodes at the bottom which reflect current structure...
            for (AbstractComponent childComponent : visibleChildComponents) {
                Set<ViewInfo> viewInfos = childComponent.getViewInfos(ViewType.NODE);

                if (!node.isProxy()) {
                    MCTMutableTreeNode childNode = GUIUtil.cloneTreeNode(childComponent,viewInfos.iterator()
                            .next());
                    node.addChild(node.getChildCount(), childNode, objectStaleListener);
                }
            }
           
            // ...and then remove the old nodes from the top. (Removing first would cause node to collapse.)
            while (node.getChildCount() > visibleChildComponents.size()) {
                node.removeChild((MCTMutableTreeNode) node.getChildAt(0), objectStaleListener);
            }
           
            // Finally, restore selection paths.
            for (int index = 0; index < node.getChildCount(); index++) {
                MCTMutableTreeNode childNode = (MCTMutableTreeNode) node.getChildAt(index);
                View childView = (View) childNode.getUserObject();
                if (expanded.contains(childView.getManifestedComponent().getComponentId())) {
                    parentTree.expandPath(childNode.getTreePath());
                    childNode.setProxy(false); // If expanded node is mislabeled as proxy, it will lose updates
                }
            }

            treeModel.nodeChanged(node);
        }
View Full Code Here

            AbstractComponent childComponent = event.getChildComponent();
            Set<ViewInfo> viewInfos = childComponent.getViewInfos(ViewType.NODE);

            if (!node.isProxy()) {
                MCTMutableTreeNode childNode = GUIUtil.cloneTreeNode(childComponent, viewInfos.iterator()
                        .next());
                node.addChild(event.getChildIndex(), childNode, objectStaleListener);
            }
        }
View Full Code Here

    @Override
    public void updateMonitoredGUI(RemoveChildEvent event) {
        if (node != null && !node.isProxy()) {
            AbstractComponent targetChildComponent = event.getChildComponent();
            for (int i = 0; i < node.getChildCount(); i++) {
                MCTMutableTreeNode childNode = (MCTMutableTreeNode) node.getChildAt(i);
                AbstractComponent childComponent = ((View) childNode.getUserObject()).getManifestedComponent();
                if (targetChildComponent.equals(childComponent)) {
                    node.removeChild(childNode, objectStaleListener);
                }
            }
        }
View Full Code Here

    public void updateMonitoredGUI(FocusEvent event) {
        JTree tree = node.getParentTree();
        DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
        List<TreePath> treePaths = new ArrayList<TreePath>();
        for (int i = 0; i < node.getChildCount(); i++) {
            MCTMutableTreeNode childNode = (MCTMutableTreeNode) node.getChildAt(i);
            View childGUIComponent = (View) childNode.getUserObject();
            AbstractComponent childComponent = childGUIComponent.getManifestedComponent();
            for (AbstractComponent focusComponent : event.getFocusComponents()) {
                if (focusComponent.getComponentId().equals(childComponent.getComponentId())) {
                    treePaths.add(new TreePath(treeModel.getPathToRoot(childNode)));
                }
View Full Code Here

    public void updateMonitoredGUI(ReloadEvent event) {
        updateMonitoredGUI();
    
        if (node != null && node.getChildCount() == 0) {
            node.setProxy(true);
            node.add(new MCTMutableTreeNode(View.NULL_VIEW_MANIFESTATION));
        }
    }
View Full Code Here

    @Test
    public void cannotHandle() {
        PolicyManagerImpl.getInstance().refreshExtendedPolicies(Collections.<ExtendedComponentProvider>singletonList(new ExtendedComponentProviderTest()));
        MCTHousing housing = Mockito.mock(MCTHousing.class);
        MCTDirectoryArea directoryArea = Mockito.mock(MCTDirectoryArea.class);
        MCTMutableTreeNode selectedNode = Mockito.mock(MCTMutableTreeNode.class);
        MCTMutableTreeNode parentNode = Mockito.mock(MCTMutableTreeNode.class);
        AbstractComponent ac = Mockito.mock(AbstractComponent.class);
        AbstractComponent parent = Mockito.mock(AbstractComponent.class);
        JTree tree = Mockito.mock(JTree.class);
        TreePath treePath = Mockito.mock(TreePath.class);
       
        ActionContextImpl actionContext = Mockito.mock(ActionContextImpl.class);
        NodeViewManifestation selectedNodeView = Mockito.mock(NodeViewManifestation.class);       
        NodeViewManifestation parentNodeView = Mockito.mock(NodeViewManifestation.class);       
        Mockito.when(actionContext.getTargetHousing()).thenReturn(housing);
        Mockito.when(actionContext.getTargetComponent()).thenReturn(ac);
        Mockito.when(housing.getDirectoryArea()).thenReturn(directoryArea);
        Mockito.when(directoryArea.getSelectedManifestations()).thenReturn(Collections.<View>singleton(selectedNodeView));
        Mockito.when(directoryArea.getSelectedDirectoryNode()).thenReturn(selectedNode);
        Mockito.when(selectedNode.getParentTree()).thenReturn(tree);
        Mockito.when(tree.getSelectionPaths()).thenReturn(Arrays.array(treePath));
        Mockito.when(treePath.getLastPathComponent()).thenReturn(selectedNode);
        Mockito.when(selectedNode.getParent()).thenReturn(parentNode);
        Mockito.when(parentNode.getUserObject()).thenReturn(parentNodeView);
        Mockito.when(parentNodeView.getManifestedComponent()).thenReturn(parent);
       
        Assert.assertFalse(action.canHandle(actionContext));
    }
View Full Code Here

TOP

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

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.