source: trunk/gli/src/org/greenstone/gatherer/cdm/SearchType.java@ 7454

Last change on this file since 7454 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.4 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 SearchType element is important.
40 * @author John Thompson, Greenstone Digital Library, University of Waikato
41 * @version 2.4
42 */
43public class SearchType
44 implements DOMProxyListEntry {
45
46 /** The Element this searchtype 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 SearchType() {
53 }
54
55 /** Normal constructor.
56 * @param element the Element this object will find its data from
57 */
58 public SearchType(Element element) {
59 this.element = element;
60 }
61
62 /** Creation of a brand new SearchType
63 * @param name the name of this type as a String
64 */
65 public SearchType(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 searchtype 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 searchtype should be based on
84 * @return a newly created DOMProxyListEntry for the given element
85 */
86 public DOMProxyListEntry create(Element element) {
87 return new SearchType(element);
88 }
89
90 /** Determine if this searchtype 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 searchtype.
106 * @return the name as a String
107 */
108 public String getName() {
109 return toString();
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 * @see org.greenstone.gatherer.util.StaticStrings
116 */
117 public boolean isAssigned() {
118 return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
119 }
120
121 /** Set the assigned state.
122 * @param assigned the desired state of assigned as a boolean
123 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
124 * @see org.greenstone.gatherer.util.StaticStrings
125 */
126 public void setAssigned(boolean assigned) {
127 if(element != null) {
128 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
129 }
130 }
131
132 /** Set the element that this DOMProxyListEntry is base on.
133 * @param element the new Element that this entry should source informatin from
134 */
135 public void setElement(Element element) {
136 this.element = element;
137 this.text = null;
138 }
139
140 /** Set the name of this searchtype.
141 * @param name the new name for this searchtype, as a String
142 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
143 * @see org.greenstone.gatherer.util.StaticStrings
144 */
145 public void setName(String name) {
146 if(element != null) {
147 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
148 this.text = null;
149 }
150 }
151
152 /** Produce a text representation of this searchtype.
153 * @return a String showing this searchtype
154 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
155 * @see org.greenstone.gatherer.util.StaticStrings
156 */
157 public String toString() {
158 if(text == null && element != null) {
159 text = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
160 }
161 return text;
162 }
163}
Note: See TracBrowser for help on using the repository browser.