Coverage Report - org.jtheque.core.managers.view.impl.components.model.ModuleListModel
 
Classes in this File Line Coverage Branch Coverage Complexity
ModuleListModel
0 %
0/15
N/A
1
 
 1  
 package org.jtheque.core.managers.view.impl.components.model;
 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.module.IModuleManager;
 21  
 import org.jtheque.core.managers.module.ModuleListener;
 22  
 import org.jtheque.core.managers.module.beans.ModuleContainer;
 23  
 import org.jtheque.utils.collections.CollectionUtils;
 24  
 
 25  
 import javax.swing.DefaultListModel;
 26  
 import java.util.List;
 27  
 
 28  
 /**
 29  
  * A List model to display the modules.
 30  
  *
 31  
  * @author Baptiste Wicht
 32  
  */
 33  
 public final class ModuleListModel extends DefaultListModel implements ModuleListener {
 34  
     private final List<ModuleContainer> modules;
 35  
 
 36  
     /**
 37  
      * Construct a new ModuleListModel.
 38  
      */
 39  
     public ModuleListModel() {
 40  0
         super();
 41  
 
 42  0
         Managers.getManager(IModuleManager.class).addModuleListener(this);
 43  
 
 44  
 
 45  0
         modules = CollectionUtils.copyOf(Managers.getManager(IModuleManager.class).getModules());
 46  0
     }
 47  
 
 48  
     @Override
 49  
     public Object getElementAt(int index) {
 50  0
         return modules.get(index);
 51  
     }
 52  
 
 53  
     @Override
 54  
     public Object get(int index) {
 55  0
         return modules.get(index);
 56  
     }
 57  
 
 58  
     @Override
 59  
     public int getSize() {
 60  0
         return modules.size();
 61  
     }
 62  
 
 63  
     @Override
 64  
     public void moduleAdded() {
 65  0
         modules.clear();
 66  0
         modules.addAll(Managers.getManager(IModuleManager.class).getModules());
 67  
 
 68  0
         fireContentsChanged(this, 0, modules.size());
 69  0
     }
 70  
 
 71  
     @Override
 72  
     public void moduleRemoved(ModuleContainer module) {
 73  0
         int index = modules.indexOf(module);
 74  
 
 75  0
         modules.remove(module);
 76  
 
 77  0
         fireIntervalRemoved(this, index, index);
 78  0
     }
 79  
 }