/**
*#########################################################################
*
* A component of the Gatherer application, part of the Greenstone digital
* library suite from the New Zealand Digital Library Project at the
* University of Waikato, New Zealand.
*
*
*
* Author: John Thompson, Greenstone Digital Library, University of Waikato
*
*
*
* Copyright (C) 1999 New Zealand Digital Library Project
*
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*########################################################################
*/
package org.greenstone.gatherer.gems;
import javax.swing.tree.DefaultTreeModel;
import org.greenstone.gatherer.util.SynchronizedTreeModelTools;
/**
* @author John Thompson, Greenstone Digital Library, University of Waikato
* @version 2.3
*/
public class GEMSModel
extends DefaultTreeModel {
public GEMSModel() {
super(new GEMSNode());
}
public void add(GEMSNode parent, Object object, int type) {
if(parent == null) {
parent = (GEMSNode) root;
}
GEMSNode new_node = new GEMSNode(type, object, null);
SynchronizedTreeModelTools.insertNodeInto(this, parent, new_node);
}
public GEMSNode getProfileNode() {
GEMSNode node = (GEMSNode) root;
return (GEMSNode) node.getChildAt(node.getChildCount() - 1);
}
public void remove(String name, int type) {
GEMSNode current = (GEMSNode) root;
for(int i = 0; i < current.getChildCount(); i++) {
GEMSNode child = (GEMSNode) current.getChildAt(i);
if(child.toString().equals(name) && type == GEMSNode.SET) {
// Place on AWT event thread to avoid errors.
SynchronizedTreeModelTools.removeNodeFromParent(this, child);
return;
}
// This may be the profiler root node, in which case we descend into its children if we're looking for collection file matches.
else if(type == GEMSNode.COLLECTION && child.getType() == GEMSNode.PROFILER) {
for(int j = 0; j < child.getChildCount(); j++) {
GEMSNode inner_child = (GEMSNode) child.getChildAt(j);
if(inner_child.toString().equals(name)) {
// Place on AWT event thread to avoid errors.
SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
return;
}
}
}
// If this is a set and we are looking for an element, then iterate through its children. Can't really do this recursively.
else if(type == GEMSNode.ELEMENT && child.getType() == GEMSNode.SET) {
for(int j = 0; j < child.getChildCount(); j++) {
GEMSNode inner_child = (GEMSNode) child.getChildAt(j);
if(inner_child.toString().equals(name)) {
// Place on AWT event thread to avoid errors.
SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
return;
}
}
}
}
}
}