source: trunk/gli/src/org/greenstone/gatherer/gems/GEMSNode.java@ 8270

Last change on this file since 8270 was 8270, checked in by mdewsnip, 20 years ago

Source files for the Greenstone Editor for Metadata Sets (GEMS). This is currently just the old MetadataEditorManager, modified to run stand-alone. It will be substantially improved by Attila Aros.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
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 */
37package org.greenstone.gatherer.gems;
38
39import java.io.*;
40import java.util.*;
41import javax.swing.tree.*;
42import org.greenstone.gatherer.Configuration;
43import org.greenstone.gatherer.DebugStream;
44import org.greenstone.gatherer.Dictionary;
45import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
46import org.greenstone.gatherer.util.Utility;
47import org.w3c.dom.*;
48/**
49 * @author John Thompson, Greenstone Digital Library, University of Waikato
50 * @version 2.3
51 */
52public class GEMSNode
53 extends DefaultMutableTreeNode {
54 private AttributeTableModel model = null;
55 private int type = 0;
56 private String text = null;
57 static final public int COLLECTION = 0;
58 static final public int ELEMENT = 1;
59 static final public int PROFILER = 2;
60 static final public int ROOT = 3;
61 static final public int SET = 4;
62
63 public GEMSNode() {
64 this.type = ROOT;
65 }
66
67 public GEMSNode(int type, Object object, GEMSNode parent) {
68 this.userObject = object;
69 this.parent = parent;
70 this.type = type;
71 this.text = null;
72 }
73
74 public Enumeration children() {
75 if(children == null) {
76 mapChildren();
77 }
78 return children.elements();
79 }
80
81 public boolean getAllowsChildren() {
82 return true;
83 }
84
85 public TreeNode getChildAt(int index) {
86 if(children == null) {
87 mapChildren();
88 }
89 return (TreeNode) children.get(index);
90 }
91 public int getChildCount() {
92 if(children == null) {
93 mapChildren();
94 }
95 return children.size();
96 }
97 public ElementWrapper getElement() {
98 ElementWrapper result = null;
99 if(type == ELEMENT) {
100 result = (ElementWrapper) userObject;
101 }
102 return result;
103 }
104 public int getIndex(TreeNode node) {
105 if(children == null) {
106 mapChildren();
107 }
108 return children.indexOf(node);
109 }
110 public AttributeTableModel getModel() {
111 return model;
112 }
113 public TreeNode getParent() {
114 return parent;
115 }
116 public MetadataSet getSet() {
117 MetadataSet result = null;
118 if(type == SET) {
119 result = (MetadataSet) userObject;
120 }
121 return result;
122 }
123 public int getType() {
124 return type;
125 }
126 public boolean isLeaf() {
127 if(children == null) {
128 mapChildren();
129 }
130 return children.size() == 0;
131 }
132 public void setModel(AttributeTableModel model) {
133 this.model = model;
134 }
135
136 public String toString() {
137 if(text == null) {
138 if(userObject != null) {
139 if(userObject instanceof ElementWrapper) {
140 text = ((ElementWrapper)userObject).getName();
141 }
142 // 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
143// else if(type == COLLECTION) {
144// try {
145// boolean is_descendant = false;
146// File source_path = new File((String)userObject);
147// File collect_path;
148// if (Gatherer.GS3) {
149// collect_path = new File(Utility.getCollectDir(Configuration.gsdl3_path, Configuration.site_name));
150// } else {
151// collect_path = new File(Utility.getCollectDir(Configuration.gsdl_path));
152// }
153// File current_path = source_path;
154// while(!is_descendant && current_path != null) {
155// is_descendant = current_path.equals(collect_path);
156// current_path = current_path.getParentFile();
157// }
158// current_path = null;
159// collect_path = null;
160// // We've either found we are a descendant, or run out of path
161// if(is_descendant) {
162// // Create a basic config class
163// File config_file = new File(source_path, Utility.CONFIG_FILE);
164// if (config_file.exists()) {
165// BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
166// text = config.toString();
167// config = null;
168// } else {
169// text = source_path.getAbsolutePath();
170// }
171// config_file = null;
172// }
173// else {
174// text = source_path.getAbsolutePath();
175// }
176// }
177// catch(Exception exception) {
178// DebugStream.println("Exception in GEMSNode.toString() - exception is unexpected");
179// DebugStream.printStackTrace(exception);
180// text = userObject.toString();
181// }
182// }
183 else {
184 text = userObject.toString();
185 }
186 }
187 else {
188 text = "error";
189 }
190 }
191 return text;
192 }
193 private void mapChildren() {
194 ///ystem.err.println("Mapping the children of " + this);
195 children = new Vector();
196 // How we build children depends on the node type
197 switch(type) {
198 case PROFILER: // Add the collections as children
199 // ArrayList a = GEMS.msm.profiler.getCollections();
200 // for(int i = 0; i < a.size(); i++) {
201 // children.add(new GEMSNode(COLLECTION, a.get(i), this));
202 // }
203 // a = null;
204 break;
205 case ROOT:
206 Vector v = GEMS.msm.getSets();
207 for(int i = 0; i < v.size(); i++) {
208 children.add(new GEMSNode(SET, v.get(i), this));
209 }
210 v = null;
211 // Add the profile set.
212 children.add(new GEMSNode(PROFILER, Dictionary.get("MEM.Profiles"), this));
213 break;
214 case SET: // Add the elements as children
215 MetadataSet set = (MetadataSet) userObject;
216 NodeList elements = set.getElements();
217 set = null;
218 for(int i = 0; i < elements.getLength(); i++) {
219 children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element) elements.item(i)), this));
220 }
221 elements = null;
222 break;
223 case COLLECTION:
224 case ELEMENT:
225 default:
226 }
227 }
228}
Note: See TracBrowser for help on using the repository browser.