[8270] | 1 | /**
|
---|
| 2 | *#########################################################################
|
---|
| 3 | *
|
---|
| 4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
| 5 | * library suite from the New Zealand Digital Library Project at the
|
---|
| 6 | * University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * <BR><BR>
|
---|
| 9 | *
|
---|
| 10 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
| 11 | *
|
---|
| 12 | * <BR><BR>
|
---|
| 13 | *
|
---|
| 14 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 15 | *
|
---|
| 16 | * <BR><BR>
|
---|
| 17 | *
|
---|
| 18 | * This program is free software; you can redistribute it and/or modify
|
---|
| 19 | * it under the terms of the GNU General Public License as published by
|
---|
| 20 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 21 | * (at your option) any later version.
|
---|
| 22 | *
|
---|
| 23 | * <BR><BR>
|
---|
| 24 | *
|
---|
| 25 | * This program is distributed in the hope that it will be useful,
|
---|
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 28 | * GNU General Public License for more details.
|
---|
| 29 | *
|
---|
| 30 | * <BR><BR>
|
---|
| 31 | *
|
---|
| 32 | * You should have received a copy of the GNU General Public License
|
---|
| 33 | * along with this program; if not, write to the Free Software
|
---|
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 35 | *########################################################################
|
---|
| 36 | */
|
---|
| 37 | package org.greenstone.gatherer.gems;
|
---|
| 38 |
|
---|
| 39 | import java.io.*;
|
---|
| 40 | import java.util.*;
|
---|
| 41 | import javax.swing.tree.*;
|
---|
[8375] | 42 | import javax.swing.JPopupMenu;
|
---|
| 43 | import java.awt.event.*;
|
---|
[8270] | 44 | import org.greenstone.gatherer.Configuration;
|
---|
| 45 | import org.greenstone.gatherer.DebugStream;
|
---|
| 46 | import org.greenstone.gatherer.Dictionary;
|
---|
| 47 | import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
|
---|
| 48 | import org.greenstone.gatherer.util.Utility;
|
---|
| 49 | import org.w3c.dom.*;
|
---|
| 50 | /**
|
---|
| 51 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
| 52 | * @version 2.3
|
---|
[8971] | 53 | * Modified 2/02/05 by Matthew Whyte
|
---|
[8270] | 54 | */
|
---|
| 55 | public class GEMSNode
|
---|
[8375] | 56 | extends DefaultMutableTreeNode{
|
---|
[8270] | 57 | private AttributeTableModel model = null;
|
---|
[8375] | 58 | public int type = 0;
|
---|
[8270] | 59 | private String text = null;
|
---|
| 60 | static final public int COLLECTION = 0;
|
---|
| 61 | static final public int ELEMENT = 1;
|
---|
| 62 | static final public int PROFILER = 2;
|
---|
| 63 | static final public int ROOT = 3;
|
---|
| 64 | static final public int SET = 4;
|
---|
[8971] | 65 | //static final public int SUBELEMENT = 5;
|
---|
[8270] | 66 |
|
---|
| 67 | public GEMSNode() {
|
---|
| 68 | this.type = ROOT;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | public GEMSNode(int type, Object object, GEMSNode parent) {
|
---|
| 72 | this.userObject = object;
|
---|
| 73 | this.parent = parent;
|
---|
| 74 | this.type = type;
|
---|
| 75 | this.text = null;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | public Enumeration children() {
|
---|
| 79 | if(children == null) {
|
---|
| 80 | mapChildren();
|
---|
| 81 | }
|
---|
| 82 | return children.elements();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | public boolean getAllowsChildren() {
|
---|
| 86 | return true;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | public TreeNode getChildAt(int index) {
|
---|
| 90 | if(children == null) {
|
---|
| 91 | mapChildren();
|
---|
| 92 | }
|
---|
| 93 | return (TreeNode) children.get(index);
|
---|
| 94 | }
|
---|
| 95 | public int getChildCount() {
|
---|
| 96 | if(children == null) {
|
---|
| 97 | mapChildren();
|
---|
| 98 | }
|
---|
| 99 | return children.size();
|
---|
| 100 | }
|
---|
| 101 | public ElementWrapper getElement() {
|
---|
| 102 | ElementWrapper result = null;
|
---|
| 103 | if(type == ELEMENT) {
|
---|
| 104 | result = (ElementWrapper) userObject;
|
---|
| 105 | }
|
---|
[8930] | 106 | return result;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[8270] | 109 | public int getIndex(TreeNode node) {
|
---|
| 110 | if(children == null) {
|
---|
| 111 | mapChildren();
|
---|
| 112 | }
|
---|
| 113 | return children.indexOf(node);
|
---|
| 114 | }
|
---|
| 115 | public AttributeTableModel getModel() {
|
---|
| 116 | return model;
|
---|
| 117 | }
|
---|
| 118 | public TreeNode getParent() {
|
---|
| 119 | return parent;
|
---|
| 120 | }
|
---|
| 121 | public MetadataSet getSet() {
|
---|
| 122 | MetadataSet result = null;
|
---|
| 123 | if(type == SET) {
|
---|
| 124 | result = (MetadataSet) userObject;
|
---|
| 125 | }
|
---|
| 126 | return result;
|
---|
| 127 | }
|
---|
| 128 | public int getType() {
|
---|
| 129 | return type;
|
---|
| 130 | }
|
---|
| 131 | public boolean isLeaf() {
|
---|
| 132 | if(children == null) {
|
---|
| 133 | mapChildren();
|
---|
| 134 | }
|
---|
| 135 | return children.size() == 0;
|
---|
| 136 | }
|
---|
| 137 | public void setModel(AttributeTableModel model) {
|
---|
| 138 | this.model = model;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[8971] | 141 | public String toString()
|
---|
| 142 | {
|
---|
| 143 | if(text == null)
|
---|
| 144 | {
|
---|
| 145 | if(userObject != null)
|
---|
| 146 | {
|
---|
| 147 | if(userObject instanceof ElementWrapper)
|
---|
| 148 | {
|
---|
| 149 | text = ((ElementWrapper)userObject).getName();
|
---|
| 150 | }
|
---|
| 151 | else
|
---|
| 152 | {
|
---|
| 153 | text = userObject.toString();
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 | else
|
---|
| 157 | {
|
---|
| 158 | text = "error";
|
---|
| 159 | }
|
---|
[8270] | 160 | }
|
---|
| 161 | return text;
|
---|
| 162 | }
|
---|
[8274] | 163 |
|
---|
[8932] | 164 | public void mapChildren()
|
---|
[8274] | 165 | {
|
---|
[8270] | 166 | children = new Vector();
|
---|
[8274] | 167 |
|
---|
[8270] | 168 | // How we build children depends on the node type
|
---|
[8930] | 169 | if (type == SET)
|
---|
| 170 | {
|
---|
| 171 | // Add the elements as children
|
---|
| 172 | MetadataSet set = (MetadataSet) userObject;
|
---|
[8932] | 173 | ArrayList elements = set.getElements();
|
---|
| 174 | for (int i = 0; i < elements.size(); i++)
|
---|
[8930] | 175 | {
|
---|
[8932] | 176 | children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element) elements.get(i)), this));
|
---|
[8930] | 177 | }
|
---|
[8270] | 178 | }
|
---|
[8971] | 179 | if (type == ELEMENT) //Add subelements. As elements and subelements are identical, this process continues.
|
---|
[8930] | 180 | {
|
---|
[8932] | 181 | ArrayList subelements = this.getElement().getSubelements();
|
---|
| 182 | for(int j = 0; j < subelements.size(); j++)
|
---|
[8930] | 183 | {
|
---|
[8971] | 184 | children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element)subelements.get(j)), this));
|
---|
[8930] | 185 | }
|
---|
| 186 | }
|
---|
[8270] | 187 | }
|
---|
[8375] | 188 |
|
---|
| 189 | class GemsNodeMouseAdapter
|
---|
| 190 | extends MouseAdapter {
|
---|
[8971] | 191 |
|
---|
[8375] | 192 | public void mouseClicked(MouseEvent e) {
|
---|
| 193 | JPopupMenu setPopup = new JPopupMenu("asdf");
|
---|
[8971] | 194 | if (e.isPopupTrigger()) {
|
---|
| 195 | setPopup.show(e.getComponent(),
|
---|
[8375] | 196 | e.getX(), e.getY());
|
---|
[8971] | 197 | }
|
---|
[8375] | 198 | }
|
---|
| 199 |
|
---|
| 200 | public void mouseEntered(MouseEvent e) {
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | public void mouseExited(MouseEvent e) {
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | public void mousePressed(MouseEvent e) {
|
---|
| 207 | JPopupMenu setPopup = new JPopupMenu("asdf");
|
---|
[8971] | 208 | if (e.isPopupTrigger()) {
|
---|
| 209 | setPopup.show(e.getComponent(),
|
---|
[8375] | 210 | e.getX(), e.getY());
|
---|
[8971] | 211 | }
|
---|
[8375] | 212 | }
|
---|
[8971] | 213 |
|
---|
[8375] | 214 | public void mouseReleased(MouseEvent e) {
|
---|
| 215 | JPopupMenu setPopup = new JPopupMenu("asdf");
|
---|
[8971] | 216 | if (e.isPopupTrigger()) {
|
---|
| 217 | setPopup.show(e.getComponent(),
|
---|
| 218 | e.getX(), e.getY());
|
---|
| 219 | }
|
---|
[8375] | 220 | }
|
---|
| 221 | }
|
---|
[8270] | 222 | }
|
---|