@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)); }
@Override public boolean canHandle(ActionContext context) { actionContext = (ActionContextImpl) context; MCTHousing activeHousing = actionContext.getTargetHousing(); if (activeHousing == null) return false; if (!(activeHousing.getDirectoryArea() instanceof MCTDirectoryArea)) { return false; } directoryArea = MCTDirectoryArea.class.cast(activeHousing.getDirectoryArea()); Collection<View> selectedManifestationsInDirectory = directoryArea.getSelectedManifestations(); if (selectedManifestationsInDirectory == null || selectedManifestationsInDirectory.isEmpty()) return false; MCTMutableTreeNode firstSelectedNode = directoryArea.getSelectedDirectoryNode(); if (firstSelectedNode == null) return false; if (!isComponentCreatable(actionContext.getTargetComponent())) { return false; } JTree tree = firstSelectedNode.getParentTree(); selectedTreePaths = tree.getSelectionPaths(); if (selectedTreePaths.length > 1) return false; MCTMutableTreeNode selectedNode = (MCTMutableTreeNode) selectedTreePaths[0].getLastPathComponent(); MCTMutableTreeNode parentNode = (MCTMutableTreeNode) selectedNode.getParent(); AbstractComponent parentComponent = ((View) parentNode.getUserObject()).getManifestedComponent(); return isParentComponentModifiable(parentComponent); }
DuplicateAction extends ContextAwareAction { @Override public boolean canHandle(ActionContext context) { actionContext = (ActionContextImpl) context; MCTHousing activeHousing = actionContext.getTargetHousing(); if (activeHousing == null) return false; if (!(activeHousing.getDirectoryArea() instanceof MCTDirectoryArea)) { return false; } directoryArea = MCTDirectoryArea.class.cast(activeHousing.getDirectoryArea()); Collection<View> selectedManifestationsInDirectory = directoryArea.getSelectedManifestations(); if (selectedManifestationsInDirectory == null || selectedManifestationsInDirectory.isEmpty()) return false; MCTMutableTreeNode firstSelectedNode = directoryArea.getSelectedDirectoryNode(); if (firstSelectedNode == null) return false; if (!isComponentCreatable(actionContext.getTargetComponent())) { return false; } JTree tree = firstSelectedNode.getParentTree(); selectedTreePaths = tree.getSelectionPaths(); if (selectedTreePaths.length > 1) return false; MCTMutableTreeNode selectedNode = (MCTMutableTreeNode) selectedTreePaths[0].getLastPathComponent(); MCTMutableTreeNode parentNode = (MCTMutableTreeNode) selectedNode.getParent(); AbstractComponent parentComponent = ((View) parentNode.getUserObject()).getManifestedComponent(); return isParentComponentModifiable(parentComponent); } }
DuplicateAction extends ContextAwareAction { @Override public boolean canHandle(ActionContext context) { actionContext = (ActionContextImpl) context; MCTHousing activeHousing = actionContext.getTargetHousing(); if (activeHousing == null) return false; if (!(activeHousing.getDirectoryArea() instanceof MCTDirectoryArea)) { return false; } directoryArea = MCTDirectoryArea.class.cast(activeHousing.getDirectoryArea()); Collection<View> selectedManifestationsInDirectory = directoryArea.getSelectedManifestations(); if (selectedManifestationsInDirectory == null || selectedManifestationsInDirectory.isEmpty()) return false; MCTMutableTreeNode firstSelectedNode = directoryArea.getSelectedDirectoryNode(); if (firstSelectedNode == null) return false; if (!isComponentCreatable(actionContext.getTargetComponent())) { return false; } JTree tree = firstSelectedNode.getParentTree(); selectedTreePaths = tree.getSelectionPaths(); if (selectedTreePaths.length > 1) return false; MCTMutableTreeNode selectedNode = (MCTMutableTreeNode) selectedTreePaths[0].getLastPathComponent(); MCTMutableTreeNode parentNode = (MCTMutableTreeNode) selectedNode.getParent(); AbstractComponent parentComponent = ((View) parentNode.getUserObject()).getManifestedComponent(); return isParentComponentModifiable(parentComponent); } DuplicateAction(); }
DuplicateAction extends ContextAwareAction { @Override public boolean canHandle(ActionContext context) { actionContext = (ActionContextImpl) context; MCTHousing activeHousing = actionContext.getTargetHousing(); if (activeHousing == null) return false; if (!(activeHousing.getDirectoryArea() instanceof MCTDirectoryArea)) { return false; } directoryArea = MCTDirectoryArea.class.cast(activeHousing.getDirectoryArea()); Collection<View> selectedManifestationsInDirectory = directoryArea.getSelectedManifestations(); if (selectedManifestationsInDirectory == null || selectedManifestationsInDirectory.isEmpty()) return false; MCTMutableTreeNode firstSelectedNode = directoryArea.getSelectedDirectoryNode(); if (firstSelectedNode == null) return false; if (!isComponentCreatable(actionContext.getTargetComponent())) { return false; } JTree tree = firstSelectedNode.getParentTree(); selectedTreePaths = tree.getSelectionPaths(); if (selectedTreePaths.length > 1) return false; MCTMutableTreeNode selectedNode = (MCTMutableTreeNode) selectedTreePaths[0].getLastPathComponent(); MCTMutableTreeNode parentNode = (MCTMutableTreeNode) selectedNode.getParent(); AbstractComponent parentComponent = ((View) parentNode.getUserObject()).getManifestedComponent(); return isParentComponentModifiable(parentComponent); } DuplicateAction(); @Override void actionPerformed(ActionEvent e); @Override boolean canHandle(ActionContext context); @Override boolean isEnabled(); }
DuplicateAction extends ContextAwareAction { @Override public boolean canHandle(ActionContext context) { actionContext = (ActionContextImpl) context; MCTHousing activeHousing = actionContext.getTargetHousing(); if (activeHousing == null) return false; if (!(activeHousing.getDirectoryArea() instanceof MCTDirectoryArea)) { return false; } directoryArea = MCTDirectoryArea.class.cast(activeHousing.getDirectoryArea()); Collection<View> selectedManifestationsInDirectory = directoryArea.getSelectedManifestations(); if (selectedManifestationsInDirectory == null || selectedManifestationsInDirectory.isEmpty()) return false; MCTMutableTreeNode firstSelectedNode = directoryArea.getSelectedDirectoryNode(); if (firstSelectedNode == null) return false; if (!isComponentCreatable(actionContext.getTargetComponent())) { return false; } JTree tree = firstSelectedNode.getParentTree(); selectedTreePaths = tree.getSelectionPaths(); if (selectedTreePaths.length > 1) return false; MCTMutableTreeNode selectedNode = (MCTMutableTreeNode) selectedTreePaths[0].getLastPathComponent(); MCTMutableTreeNode parentNode = (MCTMutableTreeNode) selectedNode.getParent(); AbstractComponent parentComponent = ((View) parentNode.getUserObject()).getManifestedComponent(); return isParentComponentModifiable(parentComponent); } DuplicateAction(); @Override void actionPerformed(ActionEvent e); @Override boolean canHandle(ActionContext context); @Override boolean isEnabled();  }