source: trunk/gli/src/org/greenstone/gatherer/cdm/Level.java@ 7457

Last change on this file since 7457 was 5590, checked in by mdewsnip, 21 years ago

Could it be I've finished adding tooltips?? Why yes, very nearly... and a big "hallelulah" for that.

  • 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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
28
29/**************************************************************************************
30 * Written: 16/07/03
31 * Revised:
32 **************************************************************************************/
33import org.greenstone.gatherer.Gatherer;
34import org.greenstone.gatherer.cdm.CollectionConfiguration;
35import org.greenstone.gatherer.cdm.CollectionDesignManager;
36import org.greenstone.gatherer.cdm.DOMProxyListEntry;
37import org.w3c.dom.*;
38
39/** This class represents a single search type setting which means that, at the moment, it is either based on an Content element containing the string 'plain' or one on the string 'form'. The ordering of these elements within the Level element is important.
40 * @author John Thompson, Greenstone Digital Library, University of Waikato
41 * @version 2.4
42 */
43public class Level
44 implements DOMProxyListEntry {
45
46 /** The Element this level object will source its information from. */
47 private Element element;
48 /** A cached version of the string representation, for speed of painting (given toString() might be called several times during a list repaint). */
49 private String text;
50
51 /** Constructor used only during DOMProxyListModel initialization. */
52 public Level() {
53 }
54
55 /** Normal constructor.
56 * @param element the Element this object will find its data from
57 */
58 public Level(Element element) {
59 this.element = element;
60 }
61
62 /** Creation of a brand new Level
63 * @param name the name of this type as a String
64 */
65 public Level(String name) {
66 element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT);
67 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
68 text = null;
69 }
70
71 /** Compare two objects for ordering.
72 * @param object the other Object to compare to
73 * @return <0 if this level should be before the given object, 0 if they are equal, and >0 if it should be after
74 */
75 public int compareTo(Object object) {
76 if(object == null) {
77 return -1;
78 }
79 return toString().compareTo(object.toString());
80 }
81
82 /** Factory-like method to allow DOMProxyListModel to generate new entries.
83 * @param element the Element the new level should be based on
84 * @return a newly created DOMProxyListEntry for the given element
85 */
86 public DOMProxyListEntry create(Element element) {
87 return new Level(element);
88 }
89
90 /** Determine if this level is equavilent to another object.
91 * @param object the other Other to match against
92 * @return true if the two are equal, false otherwise
93 */
94 public boolean equals(Object object) {
95 return (compareTo(object) == 0);
96 }
97
98 /** Retrieve the element this DOMProxyListEntry is based upon. Specified by the interface.
99 * @return the Element in question
100 */
101 public Element getElement() {
102 return element;
103 }
104
105 /** Retrieve the name of this level.
106 * @return the name as a String
107 */
108 public String getName() {
109 return element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
110 }
111
112 /** Determine is this command has been assigned, either because it already existed in the collection configuration, or because it has been explicitly set by the user. Non-assigned entries imply they have been added by the GLI to ensure consistancy (and avoid NPE's!)
113 * @return true if this command has been assigned, false otherwise
114 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
115 */
116 public boolean isAssigned() {
117 return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
118 }
119
120 /** Set the assigned state.
121 * @param assigned the desired state of assigned as a boolean
122 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
123 */
124 public void setAssigned(boolean assigned) {
125 if(element != null) {
126 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
127 }
128 }
129
130 /** Set the element that this DOMProxyListEntry is base on.
131 * @param element the new Element that this entry should source informatin from
132 */
133 public void setElement(Element element) {
134 this.element = element;
135 this.text = null;
136 }
137
138 /** Set the name of this level.
139 * @param name the new name for this level, as a String
140 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
141 */
142 public void setName(String name) {
143 if(element != null) {
144 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
145 this.text = null;
146 }
147 }
148
149 /** Produce a text representation of this level.
150 * @return a String showing this level
151 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
152 */
153 public String toString() {
154 if(text == null) {
155 if(element == null) {
156 text = "#Error";
157 }
158 else {
159 String name = getName();
160 StringBuffer text_buffer = new StringBuffer(name);
161 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + name, false);
162 if(metadatum != null) {
163 text_buffer.append(" \"");
164 text_buffer.append(metadatum.getValue(CollectionMeta.TEXT));
165 text_buffer.append("\"");
166 }
167 text = text_buffer.toString();
168 text_buffer = null;
169 }
170 }
171 return text;
172 }
173}
Note: See TracBrowser for help on using the repository browser.