Coverage Report - org.jtheque.films.view.impl.frames.SearchView
 
Classes in this File Line Coverage Branch Coverage Complexity
SearchView
0 %
0/31
0 %
0/6
1.3
 
 1  
 package org.jtheque.films.view.impl.frames;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque 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 JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.error.JThequeError;
 21  
 import org.jtheque.core.managers.view.able.IViewManager;
 22  
 import org.jtheque.core.managers.view.able.controller.Controller;
 23  
 import org.jtheque.core.managers.view.impl.frame.abstraction.SwingDialogView;
 24  
 import org.jtheque.core.utils.ui.PanelBuilder;
 25  
 import org.jtheque.films.controllers.able.IActorController;
 26  
 import org.jtheque.films.controllers.able.IFilmController;
 27  
 import org.jtheque.films.controllers.able.IRealizerController;
 28  
 import org.jtheque.films.services.impl.utils.search.Searcher;
 29  
 import org.jtheque.films.view.able.ISearchView;
 30  
 import org.jtheque.films.view.impl.actions.CloseViewAction;
 31  
 import org.jtheque.films.view.impl.actions.search.AcValidateSearchView;
 32  
 import org.jtheque.films.view.impl.panels.search.JPanelSearch;
 33  
 import org.jtheque.primary.od.able.Data;
 34  
 
 35  
 import javax.annotation.PostConstruct;
 36  
 import java.awt.Container;
 37  
 import java.awt.Frame;
 38  
 import java.util.Collection;
 39  
 
 40  
 /**
 41  
  * The GUI of search. From this view, we can search datas in JTheque.
 42  
  *
 43  
  * @author Baptiste Wicht
 44  
  */
 45  
 public final class SearchView extends SwingDialogView implements ISearchView {
 46  
     private static final long serialVersionUID = -8315962232919880990L;
 47  
 
 48  
     private JPanelSearch filmSearchPanel;
 49  
     private JPanelSearch actorSearchPanel;
 50  
     private JPanelSearch realizerSearchPanel;
 51  
 
 52  
     private JPanelSearch currentPanel;
 53  
 
 54  
     /**
 55  
      * Construct a new SearchView.
 56  
      *
 57  
      * @param parent The parent frame.
 58  
      */
 59  
     public SearchView(Frame parent) {
 60  0
         super(parent);
 61  0
     }
 62  
 
 63  
     /**
 64  
      * Build the view.
 65  
      */
 66  
     @PostConstruct
 67  
     private void build() {
 68  0
         currentPanel = filmSearchPanel;
 69  
 
 70  0
         reload();
 71  
 
 72  0
         setLocationRelativeTo(getOwner());
 73  0
     }
 74  
 
 75  
     /**
 76  
      * Reload the GUI.
 77  
      */
 78  
     private void reload() {
 79  0
         setTitle(currentPanel.getTitle());
 80  0
         setContentPane(buildContentPane());
 81  
 
 82  0
         pack();
 83  0
     }
 84  
 
 85  
     /**
 86  
      * Build the content pane.
 87  
      *
 88  
      * @return the content pane.
 89  
      */
 90  
     private Container buildContentPane() {
 91  0
         PanelBuilder builder = new PanelBuilder();
 92  
 
 93  0
         builder.add(currentPanel, builder.gbcSet(0, 0));
 94  
 
 95  0
         builder.addButtonBar(builder.gbcSet(0, 1), new AcValidateSearchView(), new CloseViewAction("generic.view.actions.cancel", this));
 96  
 
 97  0
         return builder.getPanel();
 98  
     }
 99  
 
 100  
     @Override
 101  
     public Searcher<? extends Data> buildSearcher() {
 102  0
         return currentPanel.getSearcher();
 103  
     }
 104  
 
 105  
     @Override
 106  
     public void setContentController(Controller content) {
 107  0
         if (IFilmController.class.isAssignableFrom(content.getClass())) {
 108  0
             currentPanel = filmSearchPanel;
 109  
         }
 110  
 
 111  0
         if (IActorController.class.isAssignableFrom(content.getClass())) {
 112  0
             currentPanel = actorSearchPanel;
 113  
         }
 114  
 
 115  0
         if (IRealizerController.class.isAssignableFrom(content.getClass())) {
 116  0
             currentPanel = realizerSearchPanel;
 117  
         }
 118  
 
 119  0
         reload();
 120  
 
 121  0
         Managers.getManager(IViewManager.class).refresh(this);
 122  0
     }
 123  
 
 124  
     @Override
 125  
     protected void validate(Collection<JThequeError> errors) {
 126  0
     }
 127  
 
 128  
     /**
 129  
      * Set the panel to search films.
 130  
      *
 131  
      * @param filmSearchPanel The panel to search films.
 132  
      */
 133  
     public void setFilmSearchPanel(JPanelSearch filmSearchPanel) {
 134  0
         this.filmSearchPanel = filmSearchPanel;
 135  0
     }
 136  
 
 137  
     /**
 138  
      * Set the panel to search actors.
 139  
      *
 140  
      * @param actorSearchPanel The panel to search actors.
 141  
      */
 142  
     public void setActorSearchPanel(JPanelSearch actorSearchPanel) {
 143  0
         this.actorSearchPanel = actorSearchPanel;
 144  0
     }
 145  
 
 146  
     /**
 147  
      * Set the panel to search realizers.
 148  
      *
 149  
      * @param realizerSearchPanel The panel to search realizers.
 150  
      */
 151  
     public void setRealizerSearchPanel(JPanelSearch realizerSearchPanel) {
 152  0
         this.realizerSearchPanel = realizerSearchPanel;
 153  0
     }
 154  
 }