1 | /*
|
---|
2 | * QueryHistoryModel.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 | */
|
---|
19 |
|
---|
20 |
|
---|
21 | package org.nzdl.gsdl.SimpleGraphicalClient;
|
---|
22 |
|
---|
23 | import java.util.*;
|
---|
24 | import javax.swing.event.*;
|
---|
25 | import javax.swing.*;
|
---|
26 | import javax.swing.table.*;
|
---|
27 |
|
---|
28 | class QueryHistoryModel extends AbstractTableModel implements Constants {
|
---|
29 |
|
---|
30 | private ArrayList historyItems;
|
---|
31 | private ArrayList columnTitles;
|
---|
32 |
|
---|
33 | private String COLLECTION = "Collection";
|
---|
34 | private String DATE_TIME = "Date/Time";
|
---|
35 | private String TERMS = "Terms";
|
---|
36 | private String HITS = "Hits";
|
---|
37 | private String QUERYTYPE = "Type";
|
---|
38 | private String STEMMED = "Stemmed?";
|
---|
39 | private String CASEMATCHED = "Case match?";
|
---|
40 |
|
---|
41 |
|
---|
42 | public QueryHistoryModel() {
|
---|
43 | super();
|
---|
44 | historyItems = new ArrayList();
|
---|
45 | columnTitles = new ArrayList();
|
---|
46 | columnTitles.add( DATE_TIME);
|
---|
47 | columnTitles.add( COLLECTION);
|
---|
48 | columnTitles.add( TERMS);
|
---|
49 | columnTitles.add(QUERYTYPE);
|
---|
50 | columnTitles.add(STEMMED);
|
---|
51 | columnTitles.add(CASEMATCHED);
|
---|
52 | columnTitles.add( HITS);
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | public void add(QueryHistoryItem queryHistoryItem) {
|
---|
57 | historyItems.add(0,queryHistoryItem); //add at the top!
|
---|
58 | //fireTableDataChanged(); //too general
|
---|
59 | fireTableRowsInserted(0,0);
|
---|
60 | }
|
---|
61 |
|
---|
62 | public int getColumnCount() {
|
---|
63 | return columnTitles.size();
|
---|
64 | }
|
---|
65 |
|
---|
66 | public Class getColumnClass(int c) {
|
---|
67 | return getValueAt(0, c).getClass();
|
---|
68 | }
|
---|
69 |
|
---|
70 | public int getRowCount() {
|
---|
71 | return historyItems.size();
|
---|
72 | }
|
---|
73 |
|
---|
74 | public String getColumnName(int column) {
|
---|
75 | return (String) columnTitles.get(column);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public Object getValueAt( int row, int column ) {
|
---|
79 | QueryHistoryItem historyItem = (QueryHistoryItem)historyItems.get(row);
|
---|
80 | if (column == columnTitles.indexOf(DATE_TIME)) return historyItem.getDate();
|
---|
81 | if (column == columnTitles.indexOf(COLLECTION)) return new CollectionName(historyItem.getCollectionName());
|
---|
82 | if (column == columnTitles.indexOf(TERMS)) return new Query(historyItem.getQuery().toString());
|
---|
83 | if (column == columnTitles.indexOf(HITS)) return new Long(historyItem.getNumOfHits());
|
---|
84 | if (column == columnTitles.indexOf(QUERYTYPE)) return new String(historyItem.getQueryType());
|
---|
85 | if (column == columnTitles.indexOf(STEMMED)) return new Boolean(historyItem.getStemmed());
|
---|
86 | if (column == columnTitles.indexOf(CASEMATCHED)) return new Boolean( historyItem.getCaseMatched());
|
---|
87 |
|
---|
88 | // something has gone wrong if we get here!
|
---|
89 | // but display something anyway...
|
---|
90 | return "row" + row + "col" + column;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 | public class CollectionName extends Object {
|
---|
96 | String string;
|
---|
97 |
|
---|
98 | CollectionName(String newString) {
|
---|
99 | string = newString;
|
---|
100 | }
|
---|
101 |
|
---|
102 | public String toString() {
|
---|
103 | return string;
|
---|
104 | }
|
---|
105 |
|
---|
106 | } // CollectionName
|
---|
107 |
|
---|
108 |
|
---|
109 | } //QueryHistoryModel
|
---|