1 | package org.greenstone.gatherer.checklist;
|
---|
2 |
|
---|
3 | import javax.swing.JCheckBox;
|
---|
4 | import org.greenstone.gatherer.Dictionary;
|
---|
5 | import org.greenstone.gatherer.Gatherer;
|
---|
6 | import org.greenstone.gatherer.msm.MetadataSet;
|
---|
7 | import org.greenstone.gatherer.msm.MSMUtils;
|
---|
8 | import org.greenstone.gatherer.util.Utility;
|
---|
9 | import org.w3c.dom.Element;
|
---|
10 |
|
---|
11 | /** An Entry encapsulates a single row of the list, both its check box and the object the row represents. */
|
---|
12 | public class Entry
|
---|
13 | extends JCheckBox
|
---|
14 | implements Comparable {
|
---|
15 |
|
---|
16 | /** Is this checkboxes state fixed. */
|
---|
17 | private boolean fixed = false;
|
---|
18 | /** The original object this row is based on, and whose toString() is used to generate the check box label. */
|
---|
19 | private Object object = null;
|
---|
20 | /** A sundry string for storing original values (rather than strings retrieved from dictionary). */
|
---|
21 | private String property;
|
---|
22 | /** Constructor. */
|
---|
23 | public Entry(Object object) {
|
---|
24 | super(object.toString());
|
---|
25 | this.object = object;
|
---|
26 | // We also build a special tool tip for metadata sets.
|
---|
27 | if(object instanceof MetadataSet) {
|
---|
28 | MetadataSet set = (MetadataSet) object;
|
---|
29 | // Build tooltip
|
---|
30 | StringBuffer tip = new StringBuffer(Dictionary.get("NewCollectionPrompt.Set_Contains"));
|
---|
31 | tip.append(":\n");
|
---|
32 | for(int i = 0; i < set.size(); i++) {
|
---|
33 | Element element = set.getElement(i);
|
---|
34 | tip.append(MSMUtils.getIdentifier(element));
|
---|
35 | if(i < set.size() - 1) {
|
---|
36 | tip.append(", ");
|
---|
37 | }
|
---|
38 | }
|
---|
39 | setToolTipText(Utility.formatHTMLWidth(tip.toString(), 60));
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | /** Constructor. */
|
---|
44 | public Entry(String text, boolean is_selected) {
|
---|
45 | super(text);
|
---|
46 | setSelected(is_selected);
|
---|
47 | }
|
---|
48 |
|
---|
49 | /** Test this Entry against an Object for ordering.
|
---|
50 | * @param obj the other Object.
|
---|
51 | * @return <0, 0 or >0 if this Entry is before, equal to or after the given object.
|
---|
52 | */
|
---|
53 | public int compareTo(Object obj) {
|
---|
54 | return toString().toLowerCase().compareTo(obj.toString().toLowerCase());
|
---|
55 | }
|
---|
56 | /** Test this Entry against an Object for equality.
|
---|
57 | * @param obj the other Object.
|
---|
58 | * @return true if the two are equal, false otherwise.
|
---|
59 | */
|
---|
60 | public boolean equals(Object obj) {
|
---|
61 | return toString().equalsIgnoreCase(obj.toString());
|
---|
62 | }
|
---|
63 |
|
---|
64 | /** Retrieve the object associated with this entry.
|
---|
65 | * @return An <strong>Object</strong>.
|
---|
66 | */
|
---|
67 | public Object getObject() {
|
---|
68 | //Gatherer.println("Retrieving the object for " + toString());
|
---|
69 | if(object == null) {
|
---|
70 | return getText();
|
---|
71 | }
|
---|
72 | return object;
|
---|
73 | }
|
---|
74 |
|
---|
75 | public String getProperty() {
|
---|
76 | return property;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public boolean isFixed() {
|
---|
80 | return fixed;
|
---|
81 | }
|
---|
82 |
|
---|
83 | public void setFixed(boolean fixed) {
|
---|
84 | this.fixed = fixed;
|
---|
85 | }
|
---|
86 |
|
---|
87 | public void setProperty(String property) {
|
---|
88 | this.property = property;
|
---|
89 | }
|
---|
90 |
|
---|
91 | public String toString() {
|
---|
92 | if(object == null) {
|
---|
93 | return getText();
|
---|
94 | }
|
---|
95 | return object.toString();
|
---|
96 | }
|
---|
97 | }
|
---|