view src/MPipeline2/src/mpipeline/ltpdapreferences/ExtensionsPrefGroup.java @ 9:fbbfcd56e449 database-connection-manager

Remove dead code
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mpipeline.ltpdapreferences;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.EventListener;
import java.util.EventObject;
import java.util.Iterator;
import javax.swing.event.EventListenerList;
import mpipeline.utils.MXMLUtils;
import mpipeline.utils.Utils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 *
 * @author hewitson
 */
public class ExtensionsPrefGroup extends LTPDAPrefGroup {

  public static final int EXTENSION_SEARCH_PATHS_CHANGED = 1;
  private ArrayList<String> searchPaths = new ArrayList<String>();
  private EventListenerList listenerList = new EventListenerList();

  public ExtensionsPrefGroup() {
  }

  public ExtensionsPrefGroup(Node node, float version) {

    NodeList nl = node.getChildNodes();
    for (int ii = 0; ii < nl.getLength(); ii++) {
      Node n = nl.item(ii);
      Utils.dmsg(" reading child node: " + n.getNodeName());
      if (n.getNodeName().equals("SearchPath")) {
        NamedNodeMap wbnm = n.getAttributes();
        String path = MXMLUtils.getStringFromNode("Path", wbnm, version, version);
        this.addSearchPath(path);
      }
    }
  }

  public void attachToDom(Document doc, Element tnode) {

    Element pnode = doc.createElement("Extensions");

    Iterator it = searchPaths.iterator();
    while (it.hasNext()) {
      String path = (String) it.next();
      Element snode = doc.createElement("SearchPath");
      snode.setAttribute("Path", path);
      pnode.appendChild(snode);
    }

    tnode.appendChild(pnode);

  }

  public void addSearchPath(String path) {
    fireAddExtensionPath(new AddExtensionPathEvent(this, path));
    searchPaths.add(path);
    this.setChanged();
    this.notifyObservers(EXTENSION_SEARCH_PATHS_CHANGED);
  }

  public ArrayList<String> getSearchPaths() {
    return searchPaths;
  }

  public void setSearchPaths(ArrayList<String> searchPaths) {
    this.searchPaths = searchPaths;
    setChanged();
    notifyObservers(EXTENSION_SEARCH_PATHS_CHANGED);
  }

  public void display() {
    System.out.println("Search Paths: " + searchPaths);
  }

  public void removePathAtIndex(int idx) {
    fireRemoveExtensionPath(new RemoveExtensionPathEvent(this, searchPaths.get(idx)));
    searchPaths.get(idx);
    this.searchPaths.remove(idx);
    this.setChanged();
    this.notifyObservers(EXTENSION_SEARCH_PATHS_CHANGED);
  }

  public void removePaths(Object paths[]) {
    searchPaths.removeAll(Arrays.asList(paths));
    this.setChanged();
    this.notifyObservers(EXTENSION_SEARCH_PATHS_CHANGED);
  }

  public synchronized void addAddExtensionPathListener(AddExtensionPathListener l) {
    listenerList.add(AddExtensionPathListener.class, l);
  }

  public synchronized void removeAddExtensionPathListener(AddExtensionPathListener l) {
    listenerList.remove(AddExtensionPathListener.class, l);
  }

  public void addRemoveExtensionPathListener(RemoveExtensionPathListener l) {
    listenerList.add(RemoveExtensionPathListener.class, l);
  }

  public void removeRemoveExtensionPathListener(RemoveExtensionPathListener l) {
    listenerList.remove(RemoveExtensionPathListener.class, l);
  }

  protected void fireAddExtensionPath(AddExtensionPathEvent propertyChangedEvent) {
    EventListener listenerListArray[] = listenerList.getListeners(AddExtensionPathListener.class);
    for (int i = 0, n = listenerListArray.length; i < n; i++) {
      ((AddExtensionPathListener) listenerListArray[i]).addPath(propertyChangedEvent);
    }
  }

  protected void fireRemoveExtensionPath(RemoveExtensionPathEvent propertyChangedEvent) {
    EventListener listenerListArray[] = listenerList.getListeners(RemoveExtensionPathListener.class);
    for (int i = 0, n = listenerListArray.length; i < n; i++) {
      ((RemoveExtensionPathListener) listenerListArray[i]).removePath(propertyChangedEvent);
    }
  }

  public class RemoveExtensionPathEvent extends EventObject {

    public String path;

    RemoveExtensionPathEvent(Object source, String path) {
      super(source);
      this.path = path;
    }
    public String getPath() {
      return path;
    }
  }

  public class AddExtensionPathEvent extends EventObject {

    public Object path;

    AddExtensionPathEvent(Object source, String path) {
      super(source);
      this.path = path;
    }

    public Object getPath() {
      return path;
    }
  }

  public interface AddExtensionPathListener extends EventListener {
    void addPath(AddExtensionPathEvent e);
  }

  public interface RemoveExtensionPathListener extends EventListener {
    void removePath(RemoveExtensionPathEvent e);
  }

}