/**
   * Write out the state for the given attributes
   *
   * @param selectedRows
   * @return number of files successfully saved, the better way to do this would just be to throw
   *     the error and display a specific message for each failure, but oh well.
   * @throws IOException
   */
  public void writeAttributes() throws IOException {
    final String className;
    final byte dataType =
        cyAttributes.getMultiHashMapDefinition().getAttributeValueType(attributeName);

    if ((dataType == CyAttributes.TYPE_COMPLEX)
        || (dataType == CyAttributes.TYPE_SIMPLE_MAP)
        || (dataType == CyAttributes.TYPE_UNDEFINED))
      throw new IOException("Unsupported Datatype.");

    if (dataType == MultiHashMapDefinition.TYPE_BOOLEAN) className = "java.lang.Boolean";
    else if (dataType == MultiHashMapDefinition.TYPE_INTEGER) className = "java.lang.Integer";
    else if (dataType == MultiHashMapDefinition.TYPE_FLOATING_POINT) className = "java.lang.Double";
    else className = "java.lang.String";

    try {
      fileWriter.write(attributeName + " (class=" + className + ")" + newline);

      final MultiHashMap attributeMap = cyAttributes.getMultiHashMap();

      if (attributeMap != null) {
        final Iterator<String> keys = cyAttributes.getMultiHashMap().getObjectKeys(attributeName);

        String key;
        Object value;
        Iterator objIt;
        String vs;
        StringBuilder result = new StringBuilder();

        while (keys.hasNext()) {
          key = keys.next();

          if (cyAttributes.getType(attributeName) == CyAttributes.TYPE_SIMPLE_LIST)
            value = cyAttributes.getListAttribute(key, attributeName);
          else value = cyAttributes.getAttribute(key, attributeName);

          key = encodeString(key);

          if (value != null) {
            if (value instanceof List) {
              result.append(key + " = ");

              if (((Collection) value).size() > 0) {
                Object o;

                objIt = ((Collection) value).iterator();
                result.append("(");
                o = objIt.next();
                vs = o.toString();
                vs = slashEncodeString(vs);
                vs = encodeString(vs);
                result.append(vs);

                while (objIt.hasNext()) {

                  o = objIt.next();
                  vs = o.toString();
                  vs = slashEncodeString(vs);
                  vs = encodeString(vs);
                  result.append("::" + vs);
                }
                result.append(")" + newline);
                fileWriter.write(result.toString());
                result = new StringBuilder();
              }
            } else {
              vs = value.toString();
              vs = slashEncodeString(vs);
              vs = encodeString(vs);
              fileWriter.write(key + " = " + vs + newline);
            }
          }
        }

        fileWriter.flush();
      }
    } finally {
      if (fileWriter != null) {
        fileWriter.close();
      }
    }
  }
    @SuppressWarnings("unchecked")
    @Override
    public void actionPerformed(ActionEvent ae) {
      String action = ae.getActionCommand();

      LinkTriple[] addNodes = null;
      if (action.equals("Fetch")) {
        addNodes = iSparql.ExploreURI(urlText.getText());
        addLinks(addNodes);
        // Cytoscape.getCurrentNetwork().addNode( Cytoscape.getCyNode( urlText.getText(), true ) );
      }
      if (action.equals("Fetch Selected")) {
        CyNetwork network = Cytoscape.getCurrentNetwork();
        Set nodeset = network.getSelectedNodes();
        java.util.List<LinkTriple> nodeList = new LinkedList<LinkTriple>();
        for (Object o : nodeset) {
          CyNode node = (CyNode) o;
          for (LinkTriple newNode : iSparql.ExploreURI(node.getIdentifier())) {
            nodeList.add(newNode);
          }
        }
        if (filterCheckbox.getState())
          addLinks(iSparql.NodeFilter(null, nodeList.toArray(new LinkTriple[0])));
        else addLinks(nodeList.toArray(new LinkTriple[0]));
      }
      if (action.equals("Find Nodes")) {
        CyAttributes nodeAttr = Cytoscape.getNodeAttributes();

        CyNetwork network = Cytoscape.getCurrentNetwork();
        Set nodeset = network.getSelectedNodes();
        java.util.List<Map<String, Object>> nodeList = new LinkedList<Map<String, Object>>();
        for (Object o : nodeset) {
          CyNode node = (CyNode) o;
          Map<String, Object> map = new HashMap<String, Object>();
          String id = node.getIdentifier();
          map.put("ID", id);
          for (String attr : nodeAttr.getAttributeNames()) {
            if (nodeAttr.hasAttribute(id, attr)) {
              System.out.println(id + " " + attr + " " + nodeAttr.getType(attr));
              if (nodeAttr.getType(attr) == CyAttributes.TYPE_STRING) {
                Object iAttr = nodeAttr.getAttribute(id, attr);
                map.put(attr, iAttr);
              }
            }
          }
          nodeList.add(map);
        }
        LinkTriple[] links = iSparql.NodeSearch(null, nodeList, "ID");
        addLinks(links);
      }
      if (action.equals("Edit Namespaces")) {
        Map<String, String> nameMap = prefs.getNameSpaces();
        Map<String, String> newMap = NameSpaceEditor.EditDialog(nameMap);
        for (String key : nameMap.keySet()) {
          prefs.removeNameSpace(key);
        }
        for (String key : newMap.keySet()) {
          prefs.addNameSpace(key, newMap.get(key));
        }
      }
    }