/** * Copyright 1999-2009 The Pegadi Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.articlesearch; import com.kitfox.svg.SVGCache; import com.kitfox.svg.app.beans.SVGIcon; import no.dusken.common.model.Person; import org.pegadi.model.*; import org.pegadi.sqlsearch.*; import org.pegadi.swing.PersonChooser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.net.URI; import java.util.*; import java.util.List; /** * This class implements a graphical user interface used to generate * SearchTerms. * * @author Eirik Bjorsnos <bjorsnos@underdusken.no> * @version $Revision$, $Date$ */ public class SearchPanel extends javax.swing.JPanel { private final Logger log = LoggerFactory.getLogger(getClass()); /** * Combobox containing terms to add */ private JComboBox termsCombo = new JComboBox(); /** * the strings representing all or any */ private String[] andOrStrings = {"All", "Any"}; /** * Is this an AND or OR query */ private JComboBox andOrCombo; /** * The "control panel" for the search */ private JPanel choicePanel = new JPanel(); /** * The panel containing the terms */ private TermsPanel termsPanel; /** * Button that fires the search */ private JButton searchButton; /** * The search panel strings resource bundle */ protected static ResourceBundle strings; /** * Tab for selecting simple or advanced search */ private JTabbedPane jtp; /** * The simple search panel */ private SimpleSearchPanel simplePanel; /** * The advanced search panel */ private AdvancedSearchPanel advancedPanel; /** * Constructor taking a reference to the server and a session key * as parameters */ public SearchPanel() { super(); SearchPanel.strings = ResourceBundle.getBundle("org.pegadi.articlesearch.SearchPanelStrings"); setLayout(new GridLayout(1, 1)); jtp = new JTabbedPane(); simplePanel = new SimpleSearchPanel(); advancedPanel = new AdvancedSearchPanel(); jtp.addTab(strings.getString("search.simple"), simplePanel); jtp.addTab(strings.getString("search.advanced"), advancedPanel); add(jtp); } public void addActionListener(ActionListener al) { simplePanel.addActionListener(al); advancedPanel.addActionListener(al); } /** * Return the SearchTerm reprensenting the user's current choices. * * @return the search term */ public SearchTerm getSearchTerm() { if (jtp.getSelectedComponent() instanceof SimpleSearchPanel) { return simplePanel.getSearchTerm(); } else { return advancedPanel.getSearchTerm(); } } class SimpleSearchPanel extends JPanel { /** * The GridBagLayout layout manager */ GridBagLayout gridBag = new GridBagLayout(); /** * Restrict search to current users articles */ JCheckBox myArticles = new JCheckBox(); /** * Restrict search to the active publication */ JCheckBox activePub = new JCheckBox(); /** * Restrict search to future publications */ JCheckBox futureArticles = new JCheckBox(); /** * Button to execute the search */ JButton searchButton; /** * ComboBox to select department */ JComboBox depsCombo; /** * ComboBox to select article status */ JComboBox statusCombo; /** * The active publication */ Publication activePublication = null; /** * Constructor taking a reference to the server and the session * key as parameters. */ public SimpleSearchPanel() { super(); setLayout(gridBag); java.util.List<Publication> activePubs = Collections.emptyList(); try { activePubs = LoginContext.server.getActivePublications(LoginContext.sessionKey); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error communicating with server. Connection broken?", "FATAL ERROR", JOptionPane.ERROR_MESSAGE); } if (activePubs.size() == 0) { activePublication = null; activePub.setEnabled(false); futureArticles.setEnabled(false); } else { this.activePublication = activePubs.get(0); activePub.setSelected(true); futureArticles.setSelected(true); } JPanel checkBoxPane = new JPanel(); checkBoxPane.setLayout(new BoxLayout(checkBoxPane, BoxLayout.Y_AXIS)); JPanel comboBoxPane = new JPanel(); comboBoxPane.setLayout(new BoxLayout(comboBoxPane, BoxLayout.Y_AXIS)); myArticles.setText(strings.getString("simple.myArticles")); activePub.setText(strings.getString("simple.activePub")); futureArticles.setText(strings.getString("simple.futureArticles")); checkBoxPane.add(myArticles); checkBoxPane.add(activePub); checkBoxPane.add(futureArticles); // Set selected by default myArticles.setSelected(true); GridBagConstraints constraints; constraints = new GridBagConstraints(); constraints.insets = new Insets(0, 5, 0, 5); constraints.gridwidth = 1; constraints.gridheight = 2; constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.NORTHWEST; gridBag.setConstraints(checkBoxPane, constraints); add(checkBoxPane); // departments depsCombo = new JComboBox(); depsCombo.addItem("<" + strings.getString("simple.section") + ">"); populateDepartmentCombo(); comboBoxPane.add(depsCombo); // Status statusCombo = new JComboBox(); statusCombo.addItem("<" + strings.getString("simple.status") + ">"); populateStatusCombo(); comboBoxPane.add(statusCombo); constraints = new GridBagConstraints(); constraints.insets = new Insets(0, 5, 0, 5); constraints.gridwidth = 1; constraints.gridheight = 2; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.CENTER; gridBag.setConstraints(comboBoxPane, constraints); add(comboBoxPane); // searchButton URI iconURI = SVGCache.getSVGUniverse().loadSVG(getClass().getResource(strings.getString("searchButton.imageIcon"))); SVGIcon searchIcon = new SVGIcon(); searchIcon.setSvgURI(iconURI); searchIcon.setAntiAlias(true); searchIcon.setPreferredSize(new Dimension(32,32)); searchIcon.setScaleToFit(true); iconURI = SVGCache.getSVGUniverse().loadSVG(getClass().getResource(strings.getString("searchButton.imageIcon-disabled"))); SVGIcon searchDisabledIcon = new SVGIcon(); searchDisabledIcon.setSvgURI(iconURI); searchDisabledIcon.setAntiAlias(true); searchDisabledIcon.setPreferredSize(new Dimension(32,32)); searchDisabledIcon.setScaleToFit(true); searchButton = new JButton(strings.getString("searchButton.text"), searchIcon); //new ImageIcon(getClass().getResource(strings.getString("searchButton.imageIcon")))); searchButton.setDisabledIcon(searchDisabledIcon); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ActionEvent ev = new ActionEvent(this, -1, "fire Search"); fireSearch(ev); } }); constraints = new GridBagConstraints(); constraints.insets = new Insets(0, 5, 0, 5); constraints.gridwidth = 1; constraints.gridheight = 2; constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; gridBag.setConstraints(searchButton, constraints); add(searchButton); } /** * The method populates the combobox with all statuses */ private void populateStatusCombo() { try { java.util.List<ArticleStatus> statuslist = LoginContext.server.getArticleStatuses(LoginContext.sessionKey); for (ArticleStatus aStatuslist : statuslist) { statusCombo.addItem(aStatuslist); } } catch (Exception e) { log.error("Error populating status combobox", e); } } /** * The method populates the combobox with the active publications */ private void populateDepartmentCombo() { try { java.util.List<Section> deplist = LoginContext.server.getDepartments(LoginContext.sessionKey); for (Section aDeplist : deplist) { depsCombo.addItem(aDeplist); } } catch (Exception e) { log.error("Error populating department combobox", e); } } /** * Return a SearchTerm representing the user's current * choice * * @return the SearchTerm */ public SearchTerm getSearchTerm() { List<SearchTerm> termsV = new ArrayList<SearchTerm>(); if (this.myArticles.isSelected()) { try { Person p = LoginContext.server.getSessionUser(LoginContext.sessionKey); JournalistTerm term1 = new JournalistTerm(p); PhotographerTerm term2 = new PhotographerTerm(p); termsV.add(new OrTerm(term1, term2)); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error communicating with server. Connection broken?", "FATAL ERROR", JOptionPane.ERROR_MESSAGE); } } SearchTerm activeTerm = null; SearchTerm futureTerm = null; if (this.activePub.isEnabled() && this.activePub.isSelected()) { activeTerm = new PublicationTerm(activePublication.getId()); } if (this.futureArticles.isSelected()) { futureTerm = new PublicationTerm(ComparisonTerm.Comparison.GT, activePublication.getReleaseDate()); } if (activeTerm != null && futureTerm != null) { termsV.add( new PublicationTerm(ComparisonTerm.Comparison.GE, activePublication.getReleaseDate())); } else if (activeTerm != null) { termsV.add(activeTerm); } else if (futureTerm != null) { termsV.add(futureTerm); } if (! (this.depsCombo.getSelectedItem() instanceof String)) { Section dep = (Section) depsCombo.getSelectedItem(); DepartmentTerm term = new DepartmentTerm(dep.getId()); termsV.add(term); } if (! (this.statusCombo.getSelectedItem() instanceof String)) { ArticleStatus status = (ArticleStatus) statusCombo.getSelectedItem(); StatusTerm term = new StatusTerm(status.getId()); termsV.add(term); } return new AndTerm(termsV); } void addActionListener(ActionListener al) { listenerList.add(ActionListener.class, al); } public void fireSearch(ActionEvent e) { Object[] listeners = listenerList.getListenerList(); for (Object listener : listeners) { if (listener instanceof ActionListener) { ((ActionListener) listener).actionPerformed(e); } } repaint(); } } class AdvancedSearchPanel extends JPanel { public AdvancedSearchPanel() { super(); SearchPanel.strings = ResourceBundle.getBundle("org.pegadi.articlesearch.SearchPanelStrings"); andOrStrings[0] = SearchPanel.strings.getString("all"); andOrStrings[1] = SearchPanel.strings.getString("any"); andOrCombo = new JComboBox(andOrStrings); URI iconURI = SVGCache.getSVGUniverse().loadSVG(getClass().getResource(strings.getString("searchButton.imageIcon"))); SVGIcon searchIcon = new SVGIcon(); searchIcon.setSvgURI(iconURI); searchIcon.setAntiAlias(true); searchIcon.setPreferredSize(new Dimension(32,32)); searchIcon.setScaleToFit(true); iconURI = SVGCache.getSVGUniverse().loadSVG(getClass().getResource(strings.getString("searchButton.imageIcon-disabled"))); SVGIcon searchDisabledIcon = new SVGIcon(); searchDisabledIcon.setSvgURI(iconURI); searchDisabledIcon.setAntiAlias(true); searchDisabledIcon.setPreferredSize(new Dimension(32,32)); searchDisabledIcon.setScaleToFit(true); searchButton = new JButton(strings.getString("searchButton.text"), searchIcon); //new ImageIcon(getClass().getResource(strings.getString("searchButton.imageIcon")))); searchButton.setDisabledIcon(searchDisabledIcon); setBorder(BorderFactory.createTitledBorder(strings.getString("panelBorder.title"))); setLayout(new BorderLayout()); termsCombo.addItem(SearchPanel.strings.getString("termsCombo.chooseTerm")); termsCombo.addItem(new TermComboContainer(NameTermPanel.class)); termsCombo.addItem(new TermComboContainer(TextTermPanel.class)); termsCombo.addItem(new TermComboContainer(DescriptionTermPanel.class)); termsCombo.addItem(new TermComboContainer(JournalistTermPanel.class)); termsCombo.addItem(new TermComboContainer(PhotographerTermPanel.class)); termsCombo.addItem(new TermComboContainer(PublicationTermPanel.class)); termsCombo.addItem(new TermComboContainer(LastSavedTermPanel.class)); termsCombo.addItem(new TermComboContainer(DepartmentTermPanel.class)); termsCombo.addItem(new TermComboContainer(ArticleTypeTermPanel.class)); termsCombo.addItem(new TermComboContainer(CharacterCountTermPanel.class)); termsCombo.addItem(new TermComboContainer(StatusTermPanel.class)); termsCombo.addItem(new TermComboContainer(KeywordTermPanel.class)); searchButton.setEnabled(false); termsCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object theObject = termsCombo.getSelectedItem(); if (theObject instanceof String) { return; } SearchTermPanel thePanel = ((TermComboContainer) (theObject)).getPanel(); termsPanel.addTermPanel(thePanel); revalidate(); repaint(); } }); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ActionEvent ev = new ActionEvent(this, -1, "fireSearch"); fireSearch(ev); } }); choicePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); choicePanel.add(termsCombo); choicePanel.add(andOrCombo); choicePanel.add(searchButton); add(choicePanel, BorderLayout.NORTH); termsPanel = new TermsPanel(); termsPanel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { termsPanel_actionPerformed(); } }); JScrollPane jsp = new JScrollPane(termsPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); add(jsp, BorderLayout.CENTER); } public SearchTerm getSearchTerm() { SearchTerm[] terms = termsPanel.getSearchTerms(); if (andOrCombo.getSelectedIndex() == 0) { return new AndTerm(terms); } else { return new OrTerm(terms); } } void termsPanel_actionPerformed() { searchButton.setEnabled(true); } public void addActionListener(ActionListener al) { listenerList.add(ActionListener.class, al); } public void fireSearch(ActionEvent e) { Object[] listeners = listenerList.getListenerList(); for (Object listener : listeners) { if (listener instanceof ActionListener) { ((ActionListener) listener).actionPerformed(e); } } repaint(); } } class TermsPanel extends JPanel { Vector panels = new Vector(); GridBagLayout gridBag = new GridBagLayout(); public TermsPanel() { setLayout(gridBag); /* As a small hack to beautify the search-component, an empty * panel is here added to the end of the list of search-criterias. * This makes sure all the SearchTermPanels line up nicely at the top. */ JPanel panel = new JPanel(); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridwidth = GridBagConstraints.REMAINDER; constraints.gridheight = GridBagConstraints.REMAINDER; constraints.fill = GridBagConstraints.BOTH; constraints.weighty = 1.0; constraints.weightx = 1.0; constraints.gridy = 500; // ~infinity gridBag.setConstraints(panel, constraints); add(panel); } void remPanel_actionPerformed(ActionEvent e) { SearchTermPanel stp = (SearchTermPanel) e.getSource(); remove(stp); panels.removeElement(stp); if (termsPanel.getSearchTerms().length == 0) { searchButton.setEnabled(false); } revalidate(); repaint(); } private int last_y = 0; public void addTermPanel(SearchTermPanel panel) { panels.addElement(panel); panel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { remPanel_actionPerformed(e); } }); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridwidth = GridBagConstraints.REMAINDER; constraints.gridheight = 1; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.NORTH; constraints.weighty = 0.0; constraints.weightx = 1.0; constraints.gridy = last_y++; gridBag.setConstraints(panel, constraints); add(panel); fireRemovedPanel(); } public void addActionListener(ActionListener al) { listenerList.add(ActionListener.class, al); } public void fireRemovedPanel() { ActionEvent ae = new ActionEvent(this, 0, "remove searchterm"); Object[] listeners = listenerList.getListenerList(); for (Object listener : listeners) { if (listener instanceof ActionListener) { ((ActionListener) listener).actionPerformed(ae); } } } public SearchTerm[] getSearchTerms() { SearchTerm[] terms = new SearchTerm[panels.size()]; for (int i = 0; i < terms.length; i++) { terms[i] = ((SearchTermPanel) panels.elementAt(i)).getSearchTerm(); } return terms; } } class TermComboContainer { Class panel; public TermComboContainer(Class panel) { this.panel = panel; } public String toString() { return SearchPanel.strings.getString(panel.getName()); } public SearchTermPanel getPanel() { try { return (SearchTermPanel) panel.newInstance(); } catch (Exception e) { return null; } } } } abstract class SearchTermPanel extends JPanel { public SearchTermPanel() { String borderString = SearchPanel.strings.getString(this.getClass().getName()); setBorder(BorderFactory.createTitledBorder(borderString)); setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); URI iconURI = SVGCache.getSVGUniverse().loadSVG(getClass().getResource(SearchPanel.strings.getString("searchTermPanel.removeButton.iconImage"))); SVGIcon removeIcon = new SVGIcon(); removeIcon.setSvgURI(iconURI); removeIcon.setAntiAlias(true); removeIcon.setPreferredSize(new Dimension(32,32)); removeIcon.setScaleToFit(true); iconURI = SVGCache.getSVGUniverse().loadSVG(getClass().getResource(SearchPanel.strings.getString("searchTermPanel.removeButton.iconImage-disabled"))); SVGIcon removeDisabledIcon = new SVGIcon(); removeDisabledIcon.setSvgURI(iconURI); removeDisabledIcon.setAntiAlias(true); removeDisabledIcon.setPreferredSize(new Dimension(32,32)); removeDisabledIcon.setScaleToFit(true); //JButton jb = new JButton(new ImageIcon(getClass().getResource(SearchPanel.strings.getString("searchTermPanel.removeButton.iconImage")))); JButton jb = new JButton(removeIcon); jb.setDisabledIcon(removeDisabledIcon); jb.setMargin(new Insets(0, 0, 0, 0)); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fireRemove(); } }); add(jb); add(new JLabel(" ")); // Adding some space before text. } public abstract SearchTerm getSearchTerm(); public void addActionListener(ActionListener al) { listenerList.add(ActionListener.class, al); } public void fireRemove() { ActionEvent ae = new ActionEvent(this, 0, "remove searchterm"); Object[] listeners = listenerList.getListenerList(); for (Object listener : listeners) { if (listener instanceof ActionListener) { ((ActionListener) listener).actionPerformed(ae); } } } } class NameTermPanel extends SearchTermPanel { JTextField textField = new JTextField(15); public NameTermPanel() { super(); add(new JLabel(SearchPanel.strings.getString("org.pegadi.articlesearch.NameTermPanel.label"))); add(new JLabel(" ")); add(textField); } public SearchTerm getSearchTerm() { return new NameTerm(textField.getText()); } } class JournalistTermPanel extends SearchTermPanel { PersonChooser personChooser; public JournalistTermPanel() { super(); add(new JLabel(SearchPanel.strings.getString("org.pegadi.articlesearch.JournalistTermPanel.writtenBy"))); personChooser = new PersonChooser(PersonChooser.JOURNALISTS); add(new JLabel(" ")); add(personChooser); } public SearchTerm getSearchTerm() { Person user = personChooser.getSelectedUser(); return new JournalistTerm(user); } } class PhotographerTermPanel extends SearchTermPanel { PersonChooser personChooser; public PhotographerTermPanel() { super(); add(new JLabel(SearchPanel.strings.getString("org.pegadi.articlesearch.PhotographerTermPanel.photoBy"))); personChooser = new PersonChooser(PersonChooser.PHOTOGRAPHERS); add(new JLabel(" ")); add(personChooser); } public SearchTerm getSearchTerm() { Person user = personChooser.getSelectedUser(); return new PhotographerTerm(user); } } class DescriptionTermPanel extends SearchTermPanel { JTextField textField = new JTextField(15); public DescriptionTermPanel() { super(); add(new JLabel(SearchPanel.strings.getString("org.pegadi.articlesearch.DescriptionTermPanel.contains"))); add(new JLabel(" ")); add(textField); } public SearchTerm getSearchTerm() { return new DescriptionTerm(textField.getText()); } } class TextTermPanel extends SearchTermPanel { JTextField textField = new JTextField(15); public TextTermPanel() { super(); add(new JLabel(SearchPanel.strings.getString("org.pegadi.articlesearch.TextTermPanel.contains"))); add(new JLabel(" ")); add(textField); } public SearchTerm getSearchTerm() { return new TextTerm(textField.getText()); } } class KeywordTermPanel extends SearchTermPanel { JTextField textField = new JTextField(15); public KeywordTermPanel() { super(); add(new JLabel(SearchPanel.strings.getString("org.pegadi.articlesearch.KeywordTermPanel.contains"))); add(new JLabel(" ")); add(textField); } public SearchTerm getSearchTerm() { return new KeywordTerm(textField.getText()); } } class CharacterCountTermPanel extends SearchTermPanel { JTextField textField = new JTextField(4); String[] operators = {" > ", " >= ", " < ", " <= ", " = ", " != "}; JComboBox operatorCombo = new JComboBox(operators); public CharacterCountTermPanel() { super(); add(new JLabel(SearchPanel.strings.getString("org.pegadi.articlesearch.CharacterCountTermPanel.label") + " ")); add(operatorCombo); add(textField); textField.setText("0"); // Default search value } public SearchTerm getSearchTerm() { ComparisonTerm.Comparison opInt = ComparisonTerm.Comparison.EQ; String opString = (String) operatorCombo.getSelectedItem(); if (opString.equals(" > ")) { opInt = ComparisonTerm.Comparison.GT; } else if (opString.equals(" >= ")) { opInt = ComparisonTerm.Comparison.GE; } else if (opString.equals(" < ")) { opInt = ComparisonTerm.Comparison.LT; } else if (opString.equals(" <= ")) { opInt = ComparisonTerm.Comparison.LE; } else if (opString.equals(" = ")) { opInt = ComparisonTerm.Comparison.EQ; } else if (opString.equals(" != ")) { opInt = ComparisonTerm.Comparison.NE; } return new CharacterCountTerm(opInt, Integer.parseInt(textField.getText())); } } class LastSavedTermPanel extends SearchTermPanel { JTextField month = new JTextField(2); JTextField year = new JTextField(4); JTextField day = new JTextField(2); JLabel lastSavedLabel = new JLabel(SearchPanel.strings.getString("org.pegadi.articlesearch.LastSavedTermPanel.label") + " "); String[] operators = {" > ", " >= ", " < ", " <= ", " = ", " != "}; JComboBox operatorCombo = new JComboBox(operators); public LastSavedTermPanel() { super(); add(lastSavedLabel); add(operatorCombo); add(year); add(new JLabel("-")); add(month); add(new JLabel("-")); add(day); Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); year.setText((new Integer(cal.get(Calendar.YEAR))).toString()); month.setText((new Integer(cal.get(Calendar.MONTH) + 1)).toString()); day.setText((new Integer(cal.get(Calendar.DAY_OF_MONTH))).toString()); } public SearchTerm getSearchTerm() { ComparisonTerm.Comparison opInt = ComparisonTerm.Comparison.EQ; String opString = (String) operatorCombo.getSelectedItem(); if (opString.equals(" > ")) { opInt = ComparisonTerm.Comparison.GT; } else if (opString.equals(" >= ")) { opInt = ComparisonTerm.Comparison.GE; } else if (opString.equals(" < ")) { opInt = ComparisonTerm.Comparison.LT; } else if (opString.equals(" <= ")) { opInt = ComparisonTerm.Comparison.LE; } else if (opString.equals(" = ")) { opInt = ComparisonTerm.Comparison.EQ; } else if (opString.equals(" != ")) { opInt = ComparisonTerm.Comparison.NE; } Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, Integer.parseInt(year.getText())); cal.set(Calendar.MONTH, Integer.parseInt(month.getText())); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day.getText())); return new LastSavedTerm(opInt, cal.getTime()); } } class PublicationTermPanel extends SearchTermPanel { private final Logger log = LoggerFactory.getLogger(getClass()); JComboBox publicationCombo = new JComboBox(); JLabel fromPubLabel = new JLabel(); String noPublication; String[] operators = {" = ", " > ", " < ", " != "}; JComboBox operatorCombo = new JComboBox(operators); public PublicationTermPanel() { super(); noPublication = SearchPanel.strings.getString("org.pegadi.articlesearch.PublicationTermPanel.loose"); fromPubLabel.setText(SearchPanel.strings.getString("org.pegadi.articlesearch.PublicationTermPanel.fromPub") + " "); publicationCombo.addItem(noPublication); populatePublicationCombo(); add(fromPubLabel); add(operatorCombo); add(publicationCombo); // Disable operators for "loose" articles. // Operators is disabled by default. operatorCombo.setEnabled(false); publicationCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { operatorCombo.setEnabled(publicationCombo.getSelectedItem() != noPublication); } }); } public SearchTerm getSearchTerm() { ComparisonTerm.Comparison opInt = ComparisonTerm.Comparison.EQ; String opString = (String) operatorCombo.getSelectedItem(); if (opString.equals(" > ")) { opInt = ComparisonTerm.Comparison.GT; } else if (opString.equals(" < ")) { opInt = ComparisonTerm.Comparison.LT; } else if (opString.equals(" = ")) { opInt = ComparisonTerm.Comparison.EQ; } else if (opString.equals(" != ")) { opInt = ComparisonTerm.Comparison.NE; } Object selectedObj = publicationCombo.getSelectedItem(); if (selectedObj == noPublication) { return new PublicationTerm(0); } else { Publication selected = (Publication) selectedObj; if (opInt == ComparisonTerm.Comparison.EQ) { return new PublicationTerm(selected.getId()); } else if (opInt == ComparisonTerm.Comparison.NE) { return new NotTerm(new PublicationTerm(opInt, selected.getReleaseDate())); } else { return new PublicationTerm(opInt, selected.getReleaseDate()); } } } /** * The method populates the combobox with the active publications */ private void populatePublicationCombo() { try { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); java.util.List<Publication> publist = LoginContext.server.getPublicationsByYear(cal.get(Calendar.YEAR), LoginContext.sessionKey); for (Publication aPublist : publist) { publicationCombo.addItem(aPublist); } } catch (Exception e) { log.error("Error populating publication combobox", e); } } } class DepartmentTermPanel extends SearchTermPanel { private final Logger log = LoggerFactory.getLogger(getClass()); JComboBox publicationCombo = new JComboBox(); JLabel fromPubLabel = new JLabel(); public DepartmentTermPanel() { super(); fromPubLabel.setText(SearchPanel.strings.getString("org.pegadi.articlesearch.DepartmentTermPanel.label") + " "); populateDepartmentCombo(); add(fromPubLabel); add(publicationCombo); } public SearchTerm getSearchTerm() { Section selected = (Section) publicationCombo.getSelectedItem(); return new DepartmentTerm(selected.getId()); } /** * The method populates the combobox with the active publications */ private void populateDepartmentCombo() { try { java.util.List<Section> publist = LoginContext.server.getDepartments(LoginContext.sessionKey); for (Section aPublist : publist) { publicationCombo.addItem(aPublist); } } catch (Exception e) { log.error("Error populating department combobox", e); } } } class ArticleTypeTermPanel extends SearchTermPanel { private final Logger log = LoggerFactory.getLogger(getClass()); JComboBox publicationCombo = new JComboBox(); JLabel statusLabel = new JLabel(); public ArticleTypeTermPanel() { super(); statusLabel.setText(SearchPanel.strings.getString("org.pegadi.articlesearch.ArticleTypeTermPanel.label") + " "); populateArticleTypeCombo(); add(statusLabel); add(publicationCombo); } public SearchTerm getSearchTerm() { ArticleType selected = (ArticleType) publicationCombo.getSelectedItem(); return new ArticleTypeTerm(selected.getId()); } /** * The method populates the combobox with the article types */ private void populateArticleTypeCombo() { try { java.util.List<ArticleType> publist = LoginContext.server.getArticleTypes(LoginContext.sessionKey); for (ArticleType aPublist : publist) { publicationCombo.addItem(aPublist); } } catch (Exception e) { log.error("Error populating articletype combobox", e); } } } class StatusTermPanel extends SearchTermPanel { private final Logger log = LoggerFactory.getLogger(getClass()); JComboBox publicationCombo = new JComboBox(); JLabel statusLabel = new JLabel(); public StatusTermPanel() { super(); statusLabel.setText(SearchPanel.strings.getString("org.pegadi.articlesearch.StatusTermPanel.label") + " "); populateStatusCombo(); add(statusLabel); add(publicationCombo); } public SearchTerm getSearchTerm() { ArticleStatus selected = (ArticleStatus) publicationCombo.getSelectedItem(); return new StatusTerm(selected.getId()); } /** * The method populates the combobox with the active publications */ private void populateStatusCombo() { try { java.util.List<ArticleStatus> publist = LoginContext.server.getArticleStatuses(LoginContext.sessionKey); for (ArticleStatus aPublist : publist) { publicationCombo.addItem(aPublist); } } catch (Exception e) { log.error("Error populating status combobox", e); } } }