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

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

Removed unnecessary imports of org.greenstone.gatherer.Gatherer.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 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.cdm.CollectionConfiguration;
34import org.greenstone.gatherer.cdm.CollectionDesignManager;
35import org.greenstone.gatherer.cdm.DOMProxyListEntry;
36import org.w3c.dom.*;
37
38/** 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.
39 * @author John Thompson, Greenstone Digital Library, University of Waikato
40 * @version 2.4
41 */
42public class SearchType
43 implements DOMProxyListEntry {
44
45 /** The Element this searchtype object will source its information from. */
46 private Element element;
47 /** A cached version of the string representation, for speed of painting (given toString() might be called several times during a list repaint). */
48 private String text;
49
50 /** Constructor used only during DOMProxyListModel initialization. */
51 public SearchType() {
52 }
53
54 /** Normal constructor.
55 * @param element the Element this object will find its data from
56 */
57 public SearchType(Element element) {
58 this.element = element;
59 }
60
61 /** Creation of a brand new SearchType
62 * @param name the name of this type as a String
63 */
64 public SearchType(String name) {
65 element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT);
66 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
67 text = null;
68 }
69
70 /** Compare two objects for ordering.
71 * @param object the other Object to compare to
72 * @return <0 if this searchtype should be before the given object, 0 if they are equal, and >0 if it should be after
73 */
74 public int compareTo(Object object) {
75 if(object == null) {
76 return -1;
77 }
78 return toString().compareTo(object.toString());
79 }
80
81 /** Factory-like method to allow DOMProxyListModel to generate new entries.
82 * @param element the Element the new searchtype should be based on
83 * @return a newly created DOMProxyListEntry for the given element
84 */
85 public DOMProxyListEntry create(Element element) {
86 return new SearchType(element);
87 }
88
89 /** Determine if this searchtype is equavilent to another object.
90 * @param object the other Other to match against
91 * @return true if the two are equal, false otherwise
92 */
93 public boolean equals(Object object) {
94 return (compareTo(object) == 0);
95 }
96
97 /** Retrieve the element this DOMProxyListEntry is based upon. Specified by the interface.
98 * @return the Element in question
99 */
100 public Element getElement() {
101 return element;
102 }
103
104 /** Retrieve the name of this searchtype.
105 * @return the name as a String
106 */
107 public String getName() {
108 return toString();
109 }
110
111 /** 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!)
112 * @return true if this command has been assigned, false otherwise
113 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
114 * @see org.greenstone.gatherer.util.StaticStrings
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 * @see org.greenstone.gatherer.util.StaticStrings
124 */
125 public void setAssigned(boolean assigned) {
126 if(element != null) {
127 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
128 }
129 }
130
131 /** Set the element that this DOMProxyListEntry is base on.
132 * @param element the new Element that this entry should source informatin from
133 */
134 public void setElement(Element element) {
135 this.element = element;
136 this.text = null;
137 }
138
139 /** Set the name of this searchtype.
140 * @param name the new name for this searchtype, as a String
141 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
142 * @see org.greenstone.gatherer.util.StaticStrings
143 */
144 public void setName(String name) {
145 if(element != null) {
146 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
147 this.text = null;
148 }
149 }
150
151 /** Produce a text representation of this searchtype.
152 * @return a String showing this searchtype
153 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
154 * @see org.greenstone.gatherer.util.StaticStrings
155 */
156 public String toString() {
157 if(text == null && element != null) {
158 text = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
159 }
160 return text;
161 }
162}
Note: See TracBrowser for help on using the repository browser.