Coverage Report - org.jtheque.core.managers.view.impl.components.model.VersionsComboBoxModel
 
Classes in this File Line Coverage Branch Coverage Complexity
VersionsComboBoxModel
0 %
0/25
0 %
0/10
1.714
VersionsComboBoxModel$Mode
0 %
0/4
N/A
1.714
 
 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.beans.ModuleContainer;
 21  
 import org.jtheque.core.managers.update.IUpdateManager;
 22  
 import org.jtheque.core.managers.update.Updatable;
 23  
 import org.jtheque.utils.bean.Version;
 24  
 
 25  
 import javax.swing.DefaultComboBoxModel;
 26  
 import java.util.ArrayList;
 27  
 import java.util.List;
 28  
 
 29  
 /**
 30  
  * A combo box model to display versions.
 31  
  *
 32  
  * @author Baptiste Wicht
 33  
  */
 34  0
 public final class VersionsComboBoxModel extends DefaultComboBoxModel {
 35  
     private Mode mode;
 36  
     private ModuleContainer currentModule;
 37  
     private Updatable currentUpdatable;
 38  0
     private final List<Version> versions = new ArrayList<Version>(5);
 39  
 
 40  
     /**
 41  
      * The mode of the model.
 42  
      */
 43  0
     enum Mode {
 44  0
         KERNEL,
 45  0
         MODULE,
 46  0
         UPDATABLE
 47  
     }
 48  
 
 49  
     @Override
 50  
     public Object getElementAt(int index) {
 51  0
         return versions.get(index);
 52  
     }
 53  
 
 54  
     @Override
 55  
     public int getIndexOf(Object object) {
 56  0
         Version version = (Version) object;
 57  
 
 58  0
         return versions.indexOf(version);
 59  
     }
 60  
 
 61  
     @Override
 62  
     public int getSize() {
 63  0
         return versions.size();
 64  
     }
 65  
 
 66  
     /**
 67  
      * Load kernel versions into the model.
 68  
      */
 69  
     public void loadKernelVersions() {
 70  0
         if (mode != Mode.KERNEL) {
 71  0
             mode = Mode.KERNEL;
 72  
 
 73  0
             versions.clear();
 74  0
             versions.addAll(Managers.getManager(IUpdateManager.class).getVersions(Managers.getCore()));
 75  
         }
 76  0
     }
 77  
 
 78  
     /**
 79  
      * Load module versions into the model.
 80  
      *
 81  
      * @param value The module to load the versions from.
 82  
      */
 83  
     public void loadModuleVersions(ModuleContainer value) {
 84  0
         if (mode != Mode.MODULE || !currentModule.equals(value)) {
 85  0
             mode = Mode.MODULE;
 86  0
             currentModule = value;
 87  
 
 88  0
             versions.clear();
 89  0
             versions.addAll(Managers.getManager(IUpdateManager.class).getVersions(currentModule));
 90  
         }
 91  0
     }
 92  
 
 93  
     /**
 94  
      * Load module versions into the model.
 95  
      *
 96  
      * @param value The module to load the versions from.
 97  
      */
 98  
     public void loadUpdatableVersions(Updatable value) {
 99  0
         if (mode != Mode.UPDATABLE || !currentUpdatable.equals(value)) {
 100  0
             mode = Mode.UPDATABLE;
 101  0
             currentUpdatable = value;
 102  
 
 103  0
             versions.clear();
 104  0
             versions.addAll(Managers.getManager(IUpdateManager.class).getVersions(currentUpdatable));
 105  
         }
 106  0
     }
 107  
 
 108  
     /**
 109  
      * Return the selected version.
 110  
      *
 111  
      * @return The selected version.
 112  
      */
 113  
     public Version getSelectedVersion() {
 114  0
         return (Version) getSelectedItem();
 115  
     }
 116  
 }