Coverage Report - org.jtheque.primary.controller.impl.PrincipalController
 
Classes in this File Line Coverage Branch Coverage Complexity
PrincipalController
0 %
0/49
0 %
0/18
1.562
 
 1  
 package org.jtheque.primary.controller.impl;
 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.view.able.IViewManager;
 21  
 import org.jtheque.core.managers.view.able.components.TabComponent;
 22  
 import org.jtheque.core.managers.view.able.controller.AbstractController;
 23  
 import org.jtheque.primary.controller.able.ControllerState;
 24  
 import org.jtheque.primary.controller.able.FormBean;
 25  
 import org.jtheque.primary.controller.able.IPrincipalController;
 26  
 import org.jtheque.primary.od.able.Data;
 27  
 
 28  
 import javax.swing.JTree;
 29  
 import javax.swing.event.TreeSelectionEvent;
 30  
 import javax.swing.tree.TreePath;
 31  
 import java.util.Collection;
 32  
 
 33  
 /**
 34  
  * An abstract principal Controller.
 35  
  *
 36  
  * @author Baptiste Wicht
 37  
  */
 38  
 public abstract class PrincipalController<T extends Data> extends AbstractController implements IPrincipalController<T> {
 39  
         private ControllerState state;
 40  
         private final ControllerState viewState;
 41  
         private final ControllerState modifyState;
 42  
         private final ControllerState newObjectState;
 43  
         private final ControllerState autoAddState;
 44  
 
 45  
         /**
 46  
          * Construct a new PrincipalController.
 47  
          *
 48  
          * @param viewState The view state.
 49  
          * @param modifyState The modify state.
 50  
          * @param newObjectState The new state.
 51  
          * @param autoAddState The auto add state.
 52  
          */
 53  
         protected PrincipalController(ControllerState viewState, ControllerState modifyState,
 54  
                                                                   ControllerState newObjectState, ControllerState autoAddState){
 55  0
                 super();
 56  
 
 57  0
                 this.viewState = viewState;
 58  0
                 this.modifyState = modifyState;
 59  0
                 this.newObjectState = newObjectState;
 60  0
                 this.autoAddState = autoAddState;
 61  
 
 62  0
                 state = viewState;
 63  0
         }
 64  
 
 65  
         @Override
 66  
         public final void displayView(){
 67  0
                 Managers.getManager(IViewManager.class).getViews().setSelectedView((TabComponent) getView());
 68  
 
 69  0
                 super.displayView();
 70  0
         }
 71  
 
 72  
         @Override
 73  
         public final void valueChanged(TreeSelectionEvent event){
 74  0
                 TreePath current = ((JTree) event.getSource()).getSelectionPath();
 75  
 
 76  0
                 if (current != null && current.getLastPathComponent() instanceof Data){
 77  0
                         T data = (T) current.getLastPathComponent();
 78  
 
 79  0
                         if (data != null){
 80  0
                                 view(data);
 81  
                         }
 82  
                 }
 83  0
         }
 84  
 
 85  
         @Override
 86  
         public final void save(FormBean formBean){
 87  0
                 ControllerState newState = state.save(formBean);
 88  
 
 89  0
                 if (newState != null){
 90  0
                         setAndApplyState(newState);
 91  
                 }
 92  0
         }
 93  
 
 94  
         @Override
 95  
         public final void view(T data){
 96  0
                 ControllerState newState = state.view(data);
 97  
 
 98  0
                 if (newState != null){
 99  0
                         setAndApplyState(newState);
 100  
                 }
 101  0
         }
 102  
 
 103  
         @Override
 104  
         public final void manualEdit(){
 105  0
                 ControllerState newState = state.manualEdit();
 106  
 
 107  0
                 if (newState != null){
 108  0
                         setAndApplyState(newState);
 109  
                 }
 110  0
         }
 111  
 
 112  
         @Override
 113  
         public final void create(){
 114  0
                 ControllerState newState = state.create();
 115  
 
 116  0
                 if (newState != null){
 117  0
                         setAndApplyState(newState);
 118  
                 }
 119  0
         }
 120  
 
 121  
         @Override
 122  
         public final void deleteCurrent(){
 123  0
                 ControllerState newState = state.delete();
 124  
 
 125  0
                 if (newState != null){
 126  0
                         setAndApplyState(newState);
 127  
                 }
 128  0
         }
 129  
 
 130  
         @Override
 131  
         public final void cancel(){
 132  0
                 ControllerState newState = state.cancel();
 133  
 
 134  0
                 if (newState != null){
 135  0
                         setAndApplyState(newState);
 136  
                 }
 137  0
         }
 138  
 
 139  
         @Override
 140  
         public final ControllerState getViewState(){
 141  0
                 return viewState;
 142  
         }
 143  
 
 144  
         @Override
 145  
         public final ControllerState getAutoAddState(){
 146  0
                 return autoAddState;
 147  
         }
 148  
 
 149  
         @Override
 150  
         public final ControllerState getModifyState(){
 151  0
                 return modifyState;
 152  
         }
 153  
 
 154  
         @Override
 155  
         public final ControllerState getNewObjectState(){
 156  0
                 return newObjectState;
 157  
         }
 158  
 
 159  
         @Override
 160  
         public Collection<T> getDisplayList(){
 161  0
                 return getViewModel().getDisplayList();
 162  
         }
 163  
 
 164  
         /**
 165  
          * Return the state of the controller.
 166  
          *
 167  
          * @return The state of the controller.
 168  
          */
 169  
         protected final ControllerState getState(){
 170  0
                 return state;
 171  
         }
 172  
 
 173  
         /**
 174  
          * Set the state of the controller.
 175  
          *
 176  
          * @param state The new state to apply.
 177  
          */
 178  
         protected final void setAndApplyState(ControllerState state){
 179  0
                 this.state = state;
 180  
 
 181  0
                 state.apply();
 182  0
         }
 183  
 }