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

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

Removed all occurrences of classes explicitly importing other classes in the same package.

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