@Test public void testHandleNoSelectionInDirectory() { MCTHousing mockHousing = Mockito.mock(MCTHousing.class); MCTDirectoryArea mockDirectoryArea = Mockito.mock(MCTDirectoryArea.class); Mockito.when(mockHousing.getDirectoryArea()).thenReturn(mockDirectoryArea); Mockito.when(mockDirectoryArea.getSelectedManifestations()).thenReturn(Collections.<View>emptySet()); ActionContextImpl context = new ActionContextImpl(); context.setTargetHousing(mockHousing); Assert.assertFalse(action.canHandle(context)); }
@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();  }