source: trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/CSModel.java@ 2281

Last change on this file since 2281 was 2281, checked in by daven, 23 years ago

turned on the BerryBasket. Try right-clicking on a result in the results List
to add one - no delete yet. Re-sizing maybe improved as well - no
guarantees yet though.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/*
2 * SimpleGraphicalClient.java
3 * Copyright (C) 2001 New Zealand Digital Library Project
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.nzdl.gsdl.SimpleGraphicalClient;
20
21import java.util.*;
22import java.util.Set;
23import java.util.TreeSet;
24import java.util.Iterator;
25import java.util.Vector;
26
27// local libraries
28
29import org.nzdl.gsdl.service.NzdlService;
30import org.nzdl.gsdl.service.NzdlCollectionInfo;
31
32/**
33 * Class
34 *
35 * A class to
36 *
37 * @author Dave Nichols ([email protected])
38 * @author stuart yeates ([email protected])
39 * @version $Revision: 2281 $
40 * @see org.nzdl.gsdl.service.SimpleGraphicalClient.SimpleGraphicalClient
41 */
42
43class CSModel extends Object {
44
45 Vector collectionList;
46 TreeMap collectionInfoMap;
47 HashMap collectionNameMap;
48 String currentCollection;
49 ResultModel results;
50 NzdlService nzdl;
51 QueryHistoryModel queryHistoryModel;
52 BerryBasketModel berryBasketModel;
53
54
55 public CSModel(NzdlService newNzdl)
56 {
57 nzdl = newNzdl;
58 results = new ResultModel();
59 collectionList = new Vector();
60 collectionInfoMap = new TreeMap();
61 collectionNameMap = new HashMap();
62 queryHistoryModel = new QueryHistoryModel();
63 berryBasketModel = new BerryBasketModel();
64 currentCollection = "";
65 initialiseCollection();
66 }
67
68
69 public NzdlService getNzdlService()
70 {
71 return nzdl;
72 }
73
74 public QueryHistoryModel getQueryHistoryModel() {
75 return queryHistoryModel;
76 }
77
78 public BerryBasketModel getBerryBasketModel() {
79 return berryBasketModel;
80 }
81
82 /* Result methods */
83
84 public ResultModel getResultsModel()
85 {
86 return results;
87 }
88
89 public void addResult(Result result)
90 {
91 results.add(result);
92 }
93
94 public void clearResults()
95 {
96 //System.out.println("Clearing resultModel");
97 results.clear();
98 }
99
100 /* collectionList methods */
101
102 public Vector getCollectionList() {
103 return new Vector(collectionInfoMap.keySet());
104 }
105
106 public Collection getCollectionAsCollection() {
107 return (Collection)collectionInfoMap;
108 }
109
110 public int getCollectionListSize() {
111 return collectionInfoMap.size();
112 }
113
114 public NzdlCollectionInfo getCollectionInfo(String collectionName) {
115 return (NzdlCollectionInfo) collectionInfoMap.get(collectionName);
116 }
117
118
119 public String getLongCollectionName(String collectionName) {
120 return (String) collectionNameMap.get(collectionName);
121 }
122
123
124 public String getCollectionDescription(String collectionName) {
125 Set descSet = nzdl.getMetaData(collectionName, "collection", "collectionextra");
126 if (descSet.size() == 1)
127 return (String) descSet.toArray()[0];
128 else
129 return "collectionName has more than 1 collectionextra entry";
130 }
131
132
133 public void setCurrentCollection(String collection )
134 {
135 currentCollection = collection;
136 }
137
138 public String getCurrentCollection()
139 {
140 return currentCollection;
141 }
142
143 public String getFirstCollection()
144 {
145 if (getCollectionListSize() > 0)
146 return (String)collectionInfoMap.firstKey();
147 else
148 return "no collections";
149 }
150 /**
151 *
152 */
153 public void initialiseCollection()
154 {
155 Set collectionSet = nzdl.getCollectionSet(); // set of strings of collection titles
156 TreeSet orderedCollectionSet = new TreeSet(collectionSet);
157 // TreeSet automatically puts strings in alphabetical order
158 System.out.println("Number of collections on the server: " +
159 orderedCollectionSet.size());
160 Iterator collectionSetIterator = orderedCollectionSet.iterator();
161 while (collectionSetIterator.hasNext() ) {
162 // object -> String
163 String collectionName = (String)collectionSetIterator.next();
164 NzdlCollectionInfo info = nzdl.getCollectionInfo(collectionName);
165
166 if (info != null &&
167 info.getBuildDate() != 0 &&
168 nzdl.pingCollection(collectionName)) {
169 collectionInfoMap.put(collectionName, info);
170 String longCollectionName = "";
171 Set n = nzdl.getMetaData(collectionName, "collection", "collectionname");
172 if (n != null) {
173 if (n.size() == 1)
174 longCollectionName = (String) n.toArray()[0];
175 else
176 longCollectionName = collectionName + " has more than 1 collectionname";
177 collectionNameMap.put(collectionName,longCollectionName );
178 System.err.println("Adding " + collectionName + " to collection list...");
179 }
180 } // end if
181 else {
182 System.err.println("Collection " + collectionName + " getBuildDate() returned 0");
183 } // end else
184 } // end while
185 setCurrentCollection(getFirstCollection()); //assume at least one collection
186
187 }
188
189
190}
Note: See TracBrowser for help on using the repository browser.