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

Last change on this file since 8971 was 8971, checked in by mdewsnip, 19 years ago

More GEMS fixes, by Matthew Whyte. Can now create subelements of subelements.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 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 javax.swing.JPopupMenu;
43import java.awt.event.*;
44import org.greenstone.gatherer.Configuration;
45import org.greenstone.gatherer.DebugStream;
46import org.greenstone.gatherer.Dictionary;
47import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
48import org.greenstone.gatherer.util.Utility;
49import org.w3c.dom.*;
50/**
51 * @author John Thompson, Greenstone Digital Library, University of Waikato
52 * @version 2.3
53 * Modified 2/02/05 by Matthew Whyte
54 */
55public class GEMSNode
56 extends DefaultMutableTreeNode{
57 private AttributeTableModel model = null;
58 public int type = 0;
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;
65 //static final public int SUBELEMENT = 5;
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 }
106 return result;
107 }
108
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
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 }
160 }
161 return text;
162 }
163
164 public void mapChildren()
165 {
166 children = new Vector();
167
168 // How we build children depends on the node type
169 if (type == SET)
170 {
171 // Add the elements as children
172 MetadataSet set = (MetadataSet) userObject;
173 ArrayList elements = set.getElements();
174 for (int i = 0; i < elements.size(); i++)
175 {
176 children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element) elements.get(i)), this));
177 }
178 }
179 if (type == ELEMENT) //Add subelements. As elements and subelements are identical, this process continues.
180 {
181 ArrayList subelements = this.getElement().getSubelements();
182 for(int j = 0; j < subelements.size(); j++)
183 {
184 children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element)subelements.get(j)), this));
185 }
186 }
187 }
188
189 class GemsNodeMouseAdapter
190 extends MouseAdapter {
191
192 public void mouseClicked(MouseEvent e) {
193 JPopupMenu setPopup = new JPopupMenu("asdf");
194 if (e.isPopupTrigger()) {
195 setPopup.show(e.getComponent(),
196 e.getX(), e.getY());
197 }
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");
208 if (e.isPopupTrigger()) {
209 setPopup.show(e.getComponent(),
210 e.getX(), e.getY());
211 }
212 }
213
214 public void mouseReleased(MouseEvent e) {
215 JPopupMenu setPopup = new JPopupMenu("asdf");
216 if (e.isPopupTrigger()) {
217 setPopup.show(e.getComponent(),
218 e.getX(), e.getY());
219 }
220 }
221 }
222}
Note: See TracBrowser for help on using the repository browser.