aboutsummaryrefslogtreecommitdiff
path: root/src/uk/org/ury/library/viewer/LibraryViewerPanel.java
blob: d6c2f7976a303eaab36190952f42d1d634bba47b (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
/**
 * 
 */
package uk.org.ury.library.viewer;


import java.net.URL;

import javax.swing.JTable;
import javax.swing.JTextField;

import org.swixml.SwingEngine;

import uk.org.ury.frontend.FrontendError;
import uk.org.ury.frontend.FrontendPanel;
import uk.org.ury.frontend.HintField;
import uk.org.ury.library.LibraryTableModel;


/**
 * Frontend panel providing access to an underlying library viewer.
 * 
 * @author Matt Windsor, Nathan Lasseter
 */

public class LibraryViewerPanel extends FrontendPanel
{
  /**
   * 
   */
  private static final long serialVersionUID = -2441616418398056712L;
 
  
  /**
   * Action method for performing a search, bound by the UI XML
   * manifest to the search field and button
   */
  
  public void
  search ()
  {
    // TODO: SwingWorker?
    
    master.doSearch (searchField.getText ());
    
    // This is necessary to force the table to update with the new results.
    
    resultsTable.setModel (new LibraryTableModel (master.getLibraryList ()));
  }
  

  /* Controller of this panel. */
  private LibraryViewer master;
  
  /* Panel widgets exposed by the SwiXML user interface. */
  
  private JTable resultsTable;
  private JTextField searchField;
  
  /**
   * Construct a new LibraryViewerPanel.
   * 
   * @param inMaster  The LibraryViewer controlling this LibraryViewerPanel.
   */
  
  public
  LibraryViewerPanel (LibraryViewer inMaster)
  {
    super ();
    
    master = inMaster;
   
    
    URL path = getClass ().getResource ("library_viewer_gui.xml");
    
    if (path == null)
      throw new IllegalArgumentException ("XML file does not exist.");
  
    SwingEngine se = new SwingEngine (this);
    se.getTaglib ().registerTag ("hint", HintField.class);
    
    
    /* The UI implementation is contained in library_viewer_gui.xml.
     *
     * It is hooked into the object resultsTable and the action 
     * method search.
     * 
     * See the XML file for more details.
     */
    
    try
      {
        se.insert (path, this);
      }
    catch (Exception e)
      {
        FrontendError.reportFatal ("UI creation failure: " + e.getMessage (), null);
      }
  }
  
  
  /**
   * @return  the name of the panel.
   * 
   * @see     uk.org.ury.frontend.FrontendPanel#getName()
   */
  
  @Override
  public String
  getName ()
  {
    return "Library Viewer Demo";
  }

}