/** @see ca.uvic.csr.shrimp.usercontrols.UserAction#startAction() */ public void startAction() { try { DisplayBean displayBean = (DisplayBean) tool.getBean(ShrimpTool.DISPLAY_BEAN); Vector selectedNodes = getSelectedNodes(); Vector newSelectedNodes = new Vector(); if (!selectedNodes.isEmpty()) { if (displayBean.getCprels().length == 0) { newSelectedNodes = displayBean.getDataDisplayBridge().getRootNodes(); newSelectedNodes.removeAll(selectedNodes); } else { // Group all the sibling together Map parentNodeIdToSelectedChildrenMap = new HashMap(); for (int i = 0; i < selectedNodes.size(); i++) { ShrimpNode node = (ShrimpNode) selectedNodes.get(i); ShrimpNode parentNode = node.getParentShrimpNode(); if (parentNode != null) { // weeds out the root Long parentNodeId = new Long(node.getParentShrimpNode().getID()); Vector nodes = (Vector) parentNodeIdToSelectedChildrenMap.get(parentNodeId); if (nodes == null) { nodes = new Vector(); parentNodeIdToSelectedChildrenMap.put(parentNodeId, nodes); } nodes.add(node); } } for (Iterator iter = parentNodeIdToSelectedChildrenMap.values().iterator(); iter.hasNext(); ) { Vector nodes = (Vector) iter.next(); ShrimpNode firstNode = (ShrimpNode) nodes.firstElement(); ShrimpNode parentNode = firstNode.getParentShrimpNode(); Vector siblings = displayBean.getDataDisplayBridge().getChildNodes(parentNode); siblings.removeAll(nodes); newSelectedNodes.addAll(siblings); } } setSelectedNodes(newSelectedNodes); } } catch (BeanNotFoundException e) { e.printStackTrace(); } }
/** This method handles all of the mouse events first */ public boolean handleAnyMouseEvent(ShrimpMouseEvent e) { if (tool == null) { return false; } // tool.clearOutputText(); try { selectorBean = (SelectorBean) tool.getBean(ShrimpTool.SELECTOR_BEAN); } catch (BeanNotFoundException bnfe) { bnfe.printStackTrace(); return false; } // in case the system didn't throw all the events, this clears the modifiers for us if (e.getModifiers() == 0) { isCtrlPressed = false; isShiftPressed = false; isAltPressed = false; } // set the current target Object targetObj = e.getTarget(); if (targetObj != null) { selectorBean.setSelected(SelectorBeanConstants.TARGET_OBJECT, targetObj); } else { selectorBean.clearSelected(SelectorBeanConstants.TARGET_OBJECT); } // set the current mouse coordinates Vector coords = new Vector(); coords.addElement(new Double(e.getX())); coords.addElement(new Double(e.getY())); selectorBean.setSelected(SelectorBeanConstants.MOUSE_COORDINATES, coords); return true; }