/** @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();
    }
  }
  /*
   * (non-Javadoc)
   * @see ca.uvic.csr.shrimp.DisplayBean.layout.Layout#applyLayout(java.util.Vector, java.awt.geom.Rectangle2D.Double, java.util.Vector, boolean,
   *      boolean)
   */
  public void setupAndApplyLayout(
      Vector nodes,
      Rectangle2D.Double bounds,
      Vector nodesToExclude,
      boolean showDialog,
      boolean animate,
      boolean separateComponents) {
    Vector nodesToInclude = new Vector(nodes.size());
    // Vector addedArcs = new Vector();

    for (Iterator iter = nodes.iterator(); iter.hasNext(); ) {
      ShrimpNode node = (ShrimpNode) iter.next();
      if (displayBean.isVisible(node)) {
        nodesToInclude.add(node);
      } else {
        if (!nodesToExclude.contains(node)) {
          nodesToExclude.add(node);
        }
      }
    }

    // if we are comparing by attribute, ask the user to choose an attribute
    if (comparator instanceof NodeAttributeComparator && showDialog) {
      // find a frame to "own" dialog
      ChooseAttributeDialog cad = new ChooseAttributeDialog(nodesToInclude);
      if (cad.isAccepted()) {
        String selectedAttribute = cad.getSelectedAttribute();
        if (selectedAttribute == null) {
          selectedAttribute = "";
        }
        ((NodeAttributeComparator) comparator).setAttribute(selectedAttribute);
        for (Iterator iter = ((Vector) nodesToInclude.clone()).iterator(); iter.hasNext(); ) {
          ShrimpNode node = (ShrimpNode) iter.next();
          if (node.getArtifact().getAttribute(selectedAttribute) == null) {
            nodesToInclude.remove(node);
            nodesToExclude.add(node);
          }
        }
      } else {
        return;
      }
    }
    if (nodesToInclude.isEmpty() && nodesToExclude.isEmpty()) {
      return;
    }

    displayBean.getStructuralGroupingManager().handleNodeGrouping(nodes);

    layoutAlgorithm.setEntityAspectRatio(
        ((Dimension) displayBean.getCanvasDimension()).getWidth()
            / ((Dimension) displayBean.getCanvasDimension()).getHeight());
    if (displayBean.getSwitchLabelling() && nodesToInclude.size() >= displayBean.getSwitchAtNum()) {
      displayBean.setLabelMode(nodesToInclude, DisplayConstants.LABEL_MODE_SCALE_BY_NODE_SIZE);
    } else {
      displayBean.setLabelMode(nodesToInclude, displayBean.getDefaultLabelMode());
      boolean atLeastOneInFixedSizeMode = false;
      for (Iterator iter = nodesToInclude.iterator();
          iter.hasNext() && !atLeastOneInFixedSizeMode; ) {
        ShrimpNode node = (ShrimpNode) iter.next();
        String labelMode = displayBean.getLabelMode(node);
        atLeastOneInFixedSizeMode =
            labelMode.equals(DisplayConstants.LABEL_MODE_FIXED)
                || labelMode.equals(DisplayConstants.LABEL_MODE_SCALE_BY_LEVEL);
      }
      if (atLeastOneInFixedSizeMode) {
        Font font = (Font) displayBean.getLabelFont();
        ((GridLayoutAlgorithm) layoutAlgorithm)
            .setRowPadding(displayBean.getFontHeightOnCanvas(font));
      } else {
        ((GridLayoutAlgorithm) layoutAlgorithm).setRowPadding(0);
      }
    }

    positionIncludedAndExcludedNodes(nodesToInclude, new Vector(), nodesToExclude, bounds, animate);
  }