blob: 970235adf9453a9bbd5d0f505a25d77d0cc5da17 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
package uk.org.ury.library.viewer;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.SwingUtilities;
import uk.org.ury.config.ConfigReader;
import uk.org.ury.database.DatabaseDriver;
import uk.org.ury.database.UserClass;
import uk.org.ury.database.exceptions.MissingCredentialsException;
import uk.org.ury.database.exceptions.QueryFailureException;
import uk.org.ury.frontend.AbstractFrontendModule;
import uk.org.ury.frontend.FrontendError;
import uk.org.ury.frontend.FrontendFrame;
import uk.org.ury.library.LibraryItem;
import uk.org.ury.library.LibraryUtils;
public class LibraryViewer extends AbstractFrontendModule
{
/**
*
*/
private static final long serialVersionUID = -2782366476480563739L;
private DatabaseDriver dd;
private List<LibraryItem> libraryList;
private LibraryViewerPanel panel;
private FrontendFrame frame;
/**
* Main function, for running this module as a standalone
* application.
*
* @param args The command-line argument array.
*/
public static void
main (String[] args)
{
new ConfigReader();
LibraryViewer lv = new LibraryViewer ();
lv.runFrontendInFrame ();
}
/**
* Construct a new LibraryViewer.
*/
public
LibraryViewer ()
{
frame = null;
libraryList = new ArrayList<LibraryItem> ();
panel = new LibraryViewerPanel (this);
}
/**
* Initialise the library viewer frontend as an applet.
*/
public void
init ()
{
frame = null;
libraryList = new ArrayList<LibraryItem> ();
panel = new LibraryViewerPanel (this);
try
{
SwingUtilities.invokeAndWait (new Runnable ()
{
public void
run ()
{
panel.setOpaque (true);
setContentPane (panel);
runFrontend ();
}
});
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace ();
}
catch (InvocationTargetException e)
{
// TODO Auto-generated catch block
e.printStackTrace ();
}
}
/**
* Run the library viewer frontend as an applet.
*/
public void
start ()
{
frame = null;
panel = new LibraryViewerPanel (this);
add (panel);
}
/**
* Run the library viewer frontend in a FrontendFrame.
*/
public void
runFrontendInFrame ()
{
FrontendFrame frame = new FrontendFrame (panel);
this.frame = frame;
runFrontend ();
}
/**
* Run the library viewer frontend.
*/
private void
runFrontend ()
{
dd = null;
try
{
dd = new DatabaseDriver (UserClass.READ_ONLY);
}
catch (MissingCredentialsException e)
{
// TODO: Privilege de-escalation
FrontendError.reportFatal (e.getMessage (), frame);
}
catch (Exception f)
{
FrontendError.reportFatal (f.getMessage (), frame);
}
}
/**
* Do a library search.
*
* This will update the library list to reflect the results of the
* search.
*
* @param title The title fragment to include in the search.
* Can be empty or null.
*
* @param artist The artist fragment to include in the search.
* Can be empty or null.
*/
public void
doSearch (String search)
{
try
{
libraryList = LibraryUtils.search (dd, search);
}
catch (QueryFailureException e)
{
FrontendError.reportFatal (e.getMessage (), frame);
}
}
/**
* @return the current library list.
*/
public List<LibraryItem>
getLibraryList ()
{
return libraryList;
}
}
|