Coverage Report - org.jtheque.films.view.impl.actions.auto.add.AcChooseSite
 
Classes in this File Line Coverage Branch Coverage Complexity
AcChooseSite
0 %
0/8
0 %
0/2
1.286
AcChooseSite$1
0 %
0/4
N/A
1.286
AcChooseSite$ChooseSiteRunnable
0 %
0/8
0 %
0/2
1.286
AcChooseSite$ChooseSiteRunnable$1
0 %
0/3
N/A
1.286
AcChooseSite$ChooseSiteRunnable$2
0 %
0/3
N/A
1.286
AcChooseSite$ChooseSiteRunnable$3
0 %
0/3
N/A
1.286
 
 1  
 package org.jtheque.films.view.impl.actions.auto.add;
 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.beans.IBeansManager;
 21  
 import org.jtheque.core.managers.view.able.IViewManager;
 22  
 import org.jtheque.core.managers.view.edt.SimpleTask;
 23  
 import org.jtheque.core.managers.view.impl.actions.JThequeSimpleAction;
 24  
 import org.jtheque.films.services.able.IFilmAutoService;
 25  
 import org.jtheque.films.services.impl.utils.web.FilmResult;
 26  
 import org.jtheque.films.view.able.IAutoAddView;
 27  
 
 28  
 import javax.annotation.Resource;
 29  
 import java.awt.event.ActionEvent;
 30  
 import java.util.Collection;
 31  
 
 32  
 /**
 33  
  * Action to choose the site.
 34  
  *
 35  
  * @author Baptiste Wicht
 36  
  */
 37  0
 public final class AcChooseSite extends JThequeSimpleAction {
 38  
     @Resource
 39  
     private IFilmAutoService filmAutoService;
 40  
 
 41  
     @Resource
 42  
     private IAutoAddView autoAddView;
 43  
 
 44  
     /**
 45  
      * Construct a new <code>AcChooseSite</code>.
 46  
      */
 47  
     public AcChooseSite() {
 48  0
         super();
 49  
 
 50  0
         setText(">>");
 51  
         
 52  0
         Managers.getManager(IBeansManager.class).inject(this);
 53  0
     }
 54  
 
 55  
     @Override
 56  
     public void actionPerformed(ActionEvent event) {
 57  0
         if (autoAddView.validateContent(IAutoAddView.PHASE_1)) {
 58  0
             Managers.getManager(IViewManager.class).execute(new SimpleTask() {
 59  
                 @Override
 60  
                 public void run() {
 61  0
                     autoAddView.startWait();
 62  
 
 63  0
                     new Thread(new ChooseSiteRunnable()).start();
 64  0
                 }
 65  
             });
 66  
         }
 67  0
     }
 68  
 
 69  
     /**
 70  
      * A runnable for choose site.
 71  
      *
 72  
      * @author Baptiste Wicht
 73  
      */
 74  0
     private final class ChooseSiteRunnable implements Runnable {
 75  
         @Override
 76  
         public void run() {
 77  0
             Managers.getManager(IViewManager.class).execute(new SimpleTask() {
 78  
                 @Override
 79  
                 public void run() {
 80  0
                     autoAddView.getModelListFilms().clear();
 81  0
                 }
 82  
             });
 83  
 
 84  0
             final Collection<FilmResult> results = filmAutoService.getFilms(
 85  
                     autoAddView.getSelectedSite(),
 86  
                     autoAddView.getFieldTitle().getText());
 87  
 
 88  0
             for (final FilmResult result : results) {
 89  0
                 Managers.getManager(IViewManager.class).execute(new SimpleTask() {
 90  
                     @Override
 91  
                     public void run() {
 92  0
                         autoAddView.getModelListFilms().addElement(result.getTitre());
 93  0
                     }
 94  
                 });
 95  
             }
 96  
 
 97  0
             Managers.getManager(IViewManager.class).execute(new SimpleTask() {
 98  
                 @Override
 99  
                 public void run() {
 100  0
                     autoAddView.getModel().setResults(results);
 101  0
                 }
 102  
             });
 103  
 
 104  0
             autoAddView.stopWait();
 105  0
         }
 106  
     }
 107  
 }