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.*;
|
---|
42 | import javax.swing.JPopupMenu;
|
---|
43 | import java.awt.event.*;
|
---|
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
|
---|
53 | */
|
---|
54 | public class GEMSNode
|
---|
55 | extends DefaultMutableTreeNode{
|
---|
56 | private AttributeTableModel model = null;
|
---|
57 | public int type = 0;
|
---|
58 | private String text = null;
|
---|
59 | static final public int COLLECTION = 0;
|
---|
60 | static final public int ELEMENT = 1;
|
---|
61 | static final public int PROFILER = 2;
|
---|
62 | static final public int ROOT = 3;
|
---|
63 | static final public int SET = 4;
|
---|
64 |
|
---|
65 | public GEMSNode() {
|
---|
66 | this.type = ROOT;
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 | public GEMSNode(int type, Object object, GEMSNode parent) {
|
---|
71 | this.userObject = object;
|
---|
72 | this.parent = parent;
|
---|
73 | this.type = type;
|
---|
74 | this.text = null;
|
---|
75 | }
|
---|
76 |
|
---|
77 | public Enumeration children() {
|
---|
78 | if(children == null) {
|
---|
79 | mapChildren();
|
---|
80 | }
|
---|
81 | return children.elements();
|
---|
82 | }
|
---|
83 |
|
---|
84 | public boolean getAllowsChildren() {
|
---|
85 | return true;
|
---|
86 | }
|
---|
87 |
|
---|
88 | public TreeNode getChildAt(int index) {
|
---|
89 | if(children == null) {
|
---|
90 | mapChildren();
|
---|
91 | }
|
---|
92 | return (TreeNode) children.get(index);
|
---|
93 | }
|
---|
94 | public int getChildCount() {
|
---|
95 | if(children == null) {
|
---|
96 | mapChildren();
|
---|
97 | }
|
---|
98 | return children.size();
|
---|
99 | }
|
---|
100 | public ElementWrapper getElement() {
|
---|
101 | ElementWrapper result = null;
|
---|
102 | if(type == ELEMENT) {
|
---|
103 | result = (ElementWrapper) userObject;
|
---|
104 | }
|
---|
105 | return result;
|
---|
106 | }
|
---|
107 | public int getIndex(TreeNode node) {
|
---|
108 | if(children == null) {
|
---|
109 | mapChildren();
|
---|
110 | }
|
---|
111 | return children.indexOf(node);
|
---|
112 | }
|
---|
113 | public AttributeTableModel getModel() {
|
---|
114 | return model;
|
---|
115 | }
|
---|
116 | public TreeNode getParent() {
|
---|
117 | return parent;
|
---|
118 | }
|
---|
119 | public MetadataSet getSet() {
|
---|
120 | MetadataSet result = null;
|
---|
121 | if(type == SET) {
|
---|
122 | result = (MetadataSet) userObject;
|
---|
123 | }
|
---|
124 | return result;
|
---|
125 | }
|
---|
126 | public int getType() {
|
---|
127 | return type;
|
---|
128 | }
|
---|
129 | public boolean isLeaf() {
|
---|
130 | if(children == null) {
|
---|
131 | mapChildren();
|
---|
132 | }
|
---|
133 | return children.size() == 0;
|
---|
134 | }
|
---|
135 | public void setModel(AttributeTableModel model) {
|
---|
136 | this.model = model;
|
---|
137 | }
|
---|
138 |
|
---|
139 | public String toString() {
|
---|
140 | if(text == null) {
|
---|
141 | if(userObject != null) {
|
---|
142 | if(userObject instanceof ElementWrapper) {
|
---|
143 | text = ((ElementWrapper)userObject).getName();
|
---|
144 | }
|
---|
145 | // In the case of a 'collection' source path we need to examine the path closely. If it is a descendant of the greenstone collections path then supress everything but the collection name
|
---|
146 | // else if(type == COLLECTION) {
|
---|
147 | // try {
|
---|
148 | // boolean is_descendant = false;
|
---|
149 | // File source_path = new File((String)userObject);
|
---|
150 | // File collect_path;
|
---|
151 | // if (Gatherer.GS3) {
|
---|
152 | // collect_path = new File(Utility.getCollectDir(Configuration.gsdl3_path, Configuration.site_name));
|
---|
153 | // } else {
|
---|
154 | // collect_path = new File(Utility.getCollectDir(Configuration.gsdl_path));
|
---|
155 | // }
|
---|
156 | // File current_path = source_path;
|
---|
157 | // while(!is_descendant && current_path != null) {
|
---|
158 | // is_descendant = current_path.equals(collect_path);
|
---|
159 | // current_path = current_path.getParentFile();
|
---|
160 | // }
|
---|
161 | // current_path = null;
|
---|
162 | // collect_path = null;
|
---|
163 | // // We've either found we are a descendant, or run out of path
|
---|
164 | // if(is_descendant) {
|
---|
165 | // // Create a basic config class
|
---|
166 | // File config_file = new File(source_path, Utility.CONFIG_FILE);
|
---|
167 | // if (config_file.exists()) {
|
---|
168 | // BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
|
---|
169 | // text = config.toString();
|
---|
170 | // config = null;
|
---|
171 | // } else {
|
---|
172 | // text = source_path.getAbsolutePath();
|
---|
173 | // }
|
---|
174 | // config_file = null;
|
---|
175 | // }
|
---|
176 | // else {
|
---|
177 | // text = source_path.getAbsolutePath();
|
---|
178 | // }
|
---|
179 | // }
|
---|
180 | // catch(Exception exception) {
|
---|
181 | // DebugStream.println("Exception in GEMSNode.toString() - exception is unexpected");
|
---|
182 | // DebugStream.printStackTrace(exception);
|
---|
183 | // text = userObject.toString();
|
---|
184 | // }
|
---|
185 | // }
|
---|
186 | else {
|
---|
187 | text = userObject.toString();
|
---|
188 | }
|
---|
189 | }
|
---|
190 | else {
|
---|
191 | text = "error";
|
---|
192 | }
|
---|
193 | }
|
---|
194 | return text;
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | private void mapChildren()
|
---|
199 | {
|
---|
200 | children = new Vector();
|
---|
201 |
|
---|
202 | // How we build children depends on the node type
|
---|
203 | if (type == SET) {
|
---|
204 | // Add the elements as children
|
---|
205 | MetadataSet set = (MetadataSet) userObject;
|
---|
206 | NodeList elements = set.getElements();
|
---|
207 | for (int i = 0; i < elements.getLength(); i++) {
|
---|
208 |
|
---|
209 | children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element) elements.item(i)), this));
|
---|
210 | }
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | class GemsNodeMouseAdapter
|
---|
215 | extends MouseAdapter {
|
---|
216 |
|
---|
217 |
|
---|
218 |
|
---|
219 | public void mouseClicked(MouseEvent e) {
|
---|
220 | JPopupMenu setPopup = new JPopupMenu("asdf");
|
---|
221 | if (e.isPopupTrigger()) {
|
---|
222 |
|
---|
223 | setPopup.show(e.getComponent(),
|
---|
224 | e.getX(), e.getY());
|
---|
225 |
|
---|
226 |
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | public void mouseEntered(MouseEvent e) {
|
---|
231 | }
|
---|
232 |
|
---|
233 | public void mouseExited(MouseEvent e) {
|
---|
234 | }
|
---|
235 |
|
---|
236 | public void mousePressed(MouseEvent e) {
|
---|
237 | JPopupMenu setPopup = new JPopupMenu("asdf");
|
---|
238 | if (e.isPopupTrigger()) {
|
---|
239 |
|
---|
240 | setPopup.show(e.getComponent(),
|
---|
241 | e.getX(), e.getY());
|
---|
242 |
|
---|
243 |
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | public void mouseReleased(MouseEvent e) {
|
---|
248 | JPopupMenu setPopup = new JPopupMenu("asdf");
|
---|
249 | if (e.isPopupTrigger()) {
|
---|
250 |
|
---|
251 | setPopup.show(e.getComponent(),
|
---|
252 | e.getX(), e.getY());
|
---|
253 |
|
---|
254 |
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 |
|
---|
259 | }
|
---|
260 |
|
---|
261 | }
|
---|