Coverage Report - org.jtheque.primary.PrimaryMenu
 
Classes in this File Line Coverage Branch Coverage Complexity
PrimaryMenu
0 %
0/18
0 %
0/2
1.167
 
 1  
 package org.jtheque.primary;
 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.feature.AbstractMenu;
 20  
 import org.jtheque.core.managers.feature.Feature;
 21  
 import org.jtheque.primary.od.able.SimpleData;
 22  
 import org.jtheque.primary.view.impl.actions.borrower.AcNewBorrower;
 23  
 import org.jtheque.primary.view.impl.actions.choice.ChoiceViewAction;
 24  
 import org.jtheque.primary.view.impl.actions.simple.NewSimpleDataAction;
 25  
 import org.jtheque.utils.collections.CollectionUtils;
 26  
 
 27  
 import java.util.Collection;
 28  
 import java.util.List;
 29  
 
 30  
 /**
 31  
  * The menu of the primary utils module.
 32  
  *
 33  
  * @author Baptiste Wicht
 34  
  */
 35  
 final class PrimaryMenu extends AbstractMenu {
 36  
         private final Collection<Feature> addFeatures;
 37  
         private final Collection<Feature> removeFeatures;
 38  
         private final Collection<Feature> editFeatures;
 39  
 
 40  
         /**
 41  
          * Construct a new PrimaryMenu.
 42  
          *
 43  
          * @param addFeatures The sub features of the add menu.
 44  
          * @param removeFeatures The sub features of the remove menu.
 45  
          * @param editFeatures The sub features of the edit menu.
 46  
          */
 47  
         public PrimaryMenu(Collection<Feature> addFeatures, Collection<Feature> removeFeatures, Collection<Feature> editFeatures){
 48  0
                 super();
 49  
 
 50  0
                 this.addFeatures = CollectionUtils.copyOf(addFeatures);
 51  0
                 this.removeFeatures = CollectionUtils.copyOf(removeFeatures);
 52  0
                 this.editFeatures = CollectionUtils.copyOf(editFeatures);
 53  0
         }
 54  
 
 55  
         @Override
 56  
         protected List<Feature> getMenuMainFeatures(){
 57  0
                 return features(
 58  
                                 createMainFeature(500, "menu.others",
 59  
                                                 createNewFeature(),
 60  
                                                 createDeleteFeature(),
 61  
                                                 createEditFeature())
 62  
                 );
 63  
         }
 64  
 
 65  
         /**
 66  
          * Create the new menu.
 67  
          *
 68  
          * @return The Feature for the new menu.
 69  
          */
 70  
         private Feature createNewFeature(){
 71  0
                 Feature newFeature = createSubFeature(1, "menu.others.new",
 72  
                                 createSubFeature(1, new NewSimpleDataAction("menu.others.kind", "kindController")),
 73  
                                 createSubFeature(2, new NewSimpleDataAction("menu.others.type", "typeController")),
 74  
                                 createSubFeature(3, new NewSimpleDataAction("menu.others.language", "languageController")),
 75  
                                 createSubFeature(4, new NewSimpleDataAction("menu.others.country", "countryController")),
 76  
                                 createSubFeature(5, new AcNewBorrower()),
 77  
                                 createSubFeature(6, new NewSimpleDataAction("menu.others.saga", "sagaController")));
 78  
 
 79  0
                 fillFeature(newFeature, addFeatures);
 80  
 
 81  0
                 return newFeature;
 82  
         }
 83  
 
 84  
         /**
 85  
          * Create the delete menu.
 86  
          *
 87  
          * @return The Feature for the delete menu.
 88  
          */
 89  
         private Feature createDeleteFeature(){
 90  0
                 Feature deleteFeature = createSubFeature(2, "menu.others.delete",
 91  
                                 createSubFeature(1, new ChoiceViewAction("menu.others.kind", PrimaryConstants.ChoiceActions.DELETE, SimpleData.DataType.KIND.getDataType())),
 92  
                                 createSubFeature(2, new ChoiceViewAction("menu.others.type", PrimaryConstants.ChoiceActions.DELETE, SimpleData.DataType.TYPE.getDataType())),
 93  
                                 createSubFeature(3, new ChoiceViewAction("menu.others.language", PrimaryConstants.ChoiceActions.DELETE, SimpleData.DataType.LANGUAGE.getDataType())),
 94  
                                 createSubFeature(4, new ChoiceViewAction("menu.others.country", PrimaryConstants.ChoiceActions.DELETE, SimpleData.DataType.COUNTRY.getDataType())),
 95  
                                 createSubFeature(5, new ChoiceViewAction("menu.others.borrower", PrimaryConstants.ChoiceActions.DELETE, "Borrowers")),
 96  
                                 createSubFeature(6, new ChoiceViewAction("menu.others.saga", PrimaryConstants.ChoiceActions.DELETE, SimpleData.DataType.SAGA.getDataType())));
 97  
 
 98  
 
 99  0
                 fillFeature(deleteFeature, removeFeatures);
 100  
 
 101  0
                 return deleteFeature;
 102  
         }
 103  
 
 104  
         /**
 105  
          * Create the edit menu.
 106  
          *
 107  
          * @return The Feature for the edit menu.
 108  
          */
 109  
         private Feature createEditFeature(){
 110  0
                 Feature editFeature = createSubFeature(3, "menu.others.edit",
 111  
                                 createSubFeature(1, new ChoiceViewAction("menu.others.kind", PrimaryConstants.ChoiceActions.EDIT, SimpleData.DataType.KIND.getDataType())),
 112  
                                 createSubFeature(2, new ChoiceViewAction("menu.others.type", PrimaryConstants.ChoiceActions.EDIT, SimpleData.DataType.TYPE.getDataType())),
 113  
                                 createSubFeature(3, new ChoiceViewAction("menu.others.language", PrimaryConstants.ChoiceActions.EDIT, SimpleData.DataType.LANGUAGE.getDataType())),
 114  
                                 createSubFeature(4, new ChoiceViewAction("menu.others.country", PrimaryConstants.ChoiceActions.EDIT, SimpleData.DataType.COUNTRY.getDataType())),
 115  
                                 createSubFeature(5, new ChoiceViewAction("menu.others.borrower", PrimaryConstants.ChoiceActions.EDIT, "Borrowers")),
 116  
                                 createSubFeature(6, new ChoiceViewAction("menu.others.saga", PrimaryConstants.ChoiceActions.EDIT, SimpleData.DataType.SAGA.getDataType())));
 117  
 
 118  0
                 fillFeature(editFeature, editFeatures);
 119  
 
 120  0
                 return editFeature;
 121  
         }
 122  
 
 123  
         /**
 124  
          * Fill the feature with all the features specified.
 125  
          *
 126  
          * @param feature The feature to fill.
 127  
          * @param features The sub features to add.
 128  
          */
 129  
         private static void fillFeature(Feature feature, Iterable<Feature> features){
 130  0
                 for (Feature f : features){
 131  0
                         feature.addSubFeature(f);
 132  
                 }
 133  0
         }
 134  
 }