Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.layouts.MenuSectionController
 
Classes in this File Line Coverage Branch Coverage Complexity
MenuSectionController
0%
0/143
0%
0/44
1.96
MenuSectionController$1
0%
0/6
0%
0/4
1.96
MenuSectionController$2
0%
0/3
N/A
1.96
MenuSectionController$2$1
0%
0/3
N/A
1.96
MenuSectionController$3
0%
0/3
N/A
1.96
MenuSectionController$3$1
0%
0/3
N/A
1.96
 
 1  
 package org.kuali.student.common.ui.client.configurable.mvc.layouts;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.HashMap;
 5  
 import java.util.List;
 6  
 import java.util.Map;
 7  
 
 8  
 import org.kuali.student.common.ui.client.configurable.mvc.LayoutController;
 9  
 import org.kuali.student.common.ui.client.mvc.Callback;
 10  
 import org.kuali.student.common.ui.client.mvc.View;
 11  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 12  
 import org.kuali.student.common.ui.client.widgets.headers.KSDocumentHeader;
 13  
 import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData;
 14  
 import org.kuali.student.common.ui.client.widgets.menus.impl.KSBlockMenuImpl;
 15  
 import org.kuali.student.common.ui.client.widgets.panels.collapsable.VerticalCollapsableDrawer;
 16  
 
 17  
 import com.google.gwt.event.dom.client.ClickEvent;
 18  
 import com.google.gwt.event.dom.client.ClickHandler;
 19  
 import com.google.gwt.user.client.Command;
 20  
 import com.google.gwt.user.client.DeferredCommand;
 21  
 import com.google.gwt.user.client.ui.FlowPanel;
 22  
 import com.google.gwt.user.client.ui.SimplePanel;
 23  
 import com.google.gwt.user.client.ui.VerticalPanel;
 24  
 import com.google.gwt.user.client.ui.Widget;
 25  
 
 26  
 /**
 27  
  * A layout controller which generates a menu for views that added to it through addMenuItem calls.
 28  
  * The user can click on items in the menu to show the view.
 29  
  * 
 30  
  * @author Kuali Student Team
 31  
  *
 32  
  */
 33  0
 public class MenuSectionController extends LayoutController implements ContentNavLayoutController {
 34  
 
 35  0
     private KSBlockMenuImpl menu = new KSBlockMenuImpl();
 36  0
     private List<KSMenuItemData> topLevelMenuItems = new ArrayList<KSMenuItemData>();
 37  0
     protected Map<String, List<View>> menuViewMap = new HashMap<String, List<View>>();
 38  0
     private Map<Enum<?>, List<KSButton>> viewButtonsMap = new HashMap<Enum<?>, List<KSButton>>();
 39  0
     protected Map<Enum<?>, KSMenuItemData> viewMenuItemMap = new HashMap<Enum<?>, KSMenuItemData>();
 40  0
     private List<View> menuOrder = new ArrayList<View>();
 41  0
     private FlowPanel layout = new FlowPanel();
 42  0
     private KSDocumentHeader header = new KSDocumentHeader();
 43  0
     private FlowPanel rightPanel = new FlowPanel();
 44  0
     private FlowPanel contentPanel = new FlowPanel();
 45  0
     private FlowPanel buttonPanel = new FlowPanel();
 46  0
     private VerticalPanel leftPanel = new VerticalPanel();
 47  0
     private SimplePanel sideBar = new SimplePanel();
 48  0
     private boolean refreshMenuOnAdd = true;
 49  0
     private VerticalCollapsableDrawer collapsablePanel = new VerticalCollapsableDrawer();
 50  
 
 51  0
     private Callback<Boolean> showViewCallback = new Callback<Boolean>() {
 52  
 
 53  
         @Override
 54  
         public void exec(Boolean result) {
 55  0
             if (result == false) {
 56  0
                 KSMenuItemData item = viewMenuItemMap.get(MenuSectionController.this.getCurrentView().getViewEnum());
 57  0
                 if (item != null) {
 58  0
                     item.setSelected(true, false);
 59  
                 }
 60  
             }
 61  0
         }
 62  
     };
 63  
 
 64  
     public MenuSectionController() {
 65  0
         super();
 66  0
         List<View> list = new ArrayList<View>();
 67  0
         menuViewMap.put("", list);
 68  0
         menu.setStyleName("ks-menu-layout-menu");
 69  0
         rightPanel.setStyleName("ks-menu-layout-rightColumn");
 70  0
         collapsablePanel.addStyleName("ks-menu-layout-leftColumn");
 71  0
         layout.addStyleName("ks-menu-layout");
 72  0
         menu.setTopLevelItems(topLevelMenuItems);
 73  0
         collapsablePanel.setContent(leftPanel);
 74  0
         leftPanel.add(menu);
 75  0
         leftPanel.add(sideBar);
 76  0
         rightPanel.add(header);
 77  0
         rightPanel.add(contentPanel);
 78  0
         rightPanel.add(buttonPanel);
 79  0
         layout.add(collapsablePanel);
 80  0
         layout.add(rightPanel);
 81  0
         header.setVisible(false);
 82  0
         this.showPrint(true);
 83  0
         this.initWidget(layout);
 84  0
     }
 85  
 
 86  
     public void removeMenuNavigation() {
 87  0
         collapsablePanel.removeFromParent();
 88  0
     }
 89  
 
 90  
     public void setContentTitle(String title) {
 91  0
         header.setTitle(title);
 92  0
         header.setVisible(true);
 93  0
     }
 94  
 
 95  
     public void addContentWidget(Widget w) {
 96  0
         header.addWidget(w);
 97  0
         header.setVisible(true);
 98  0
     }
 99  
 
 100  
     public void setSideBarWidget(Widget w) {
 101  0
         sideBar.setWidget(w);
 102  0
     }
 103  
 
 104  
     public void setContentInfo(String info) {
 105  0
         header.getInfoLabel().setHTML(info);
 106  0
         header.getInfoLabel().removeStyleName("content-warning");
 107  0
         header.getInfoLabel().addStyleName("content-info");
 108  0
     }
 109  
 
 110  
     public void setContentWarning(String info) {
 111  0
         header.getInfoLabel().setHTML(info);
 112  0
         header.getInfoLabel().removeStyleName("content-info");
 113  0
         header.getInfoLabel().addStyleName("content-warning");
 114  
 
 115  0
     }
 116  
     
 117  
     public void showPrint(boolean show){
 118  0
             header.showPrint(show);
 119  0
     }
 120  
 
 121  
     /**
 122  
      * @see org.kuali.student.common.ui.client.configurable.mvc.layouts.ContentNavLayoutController#addCommonButton(java.lang.String, org.kuali.student.common.ui.client.widgets.KSButton)
 123  
      */
 124  
     public void addCommonButton(String parentMenu, KSButton button) {
 125  0
         if (parentMenu != null) {
 126  0
             List<View> views = menuViewMap.get(parentMenu);
 127  0
             if (views != null) {
 128  0
                 for (int i = 0; i < views.size(); i++) {
 129  0
                     addButtonForView(views.get(i).getViewEnum(), button);
 130  
                 }
 131  
             }
 132  
         }
 133  0
     }
 134  
 
 135  
     /**
 136  
      * @see org.kuali.student.common.ui.client.configurable.mvc.layouts.ContentNavLayoutController#addCommonButton(java.lang.String, org.kuali.student.common.ui.client.widgets.KSButton, java.util.List)
 137  
      */
 138  
     public void addCommonButton(String parentMenu, KSButton button, List<Enum<?>> excludedViews) {
 139  0
         if (parentMenu != null) {
 140  0
             List<View> views = menuViewMap.get(parentMenu);
 141  0
             if (views != null) {
 142  0
                 for (int i = 0; i < views.size(); i++) {
 143  0
                     if (!excludedViews.contains(views.get(i).getViewEnum())) {
 144  0
                         addButtonForView(views.get(i).getViewEnum(), button);
 145  
                     }
 146  
                 }
 147  
             }
 148  
         }
 149  0
     }
 150  
 
 151  
     public void showNextViewOnMenu() {
 152  0
         int i = menuOrder.indexOf(this.getCurrentView());
 153  0
         if (i != -1 && i + 1 < menuOrder.size()) {
 154  0
             this.showView(menuOrder.get(i + 1).getViewEnum());
 155  
         }
 156  0
     }
 157  
 
 158  
     public void addButtonForView(Enum<?> viewType, KSButton button) {
 159  0
         List<KSButton> buttons = viewButtonsMap.get(viewType);
 160  0
         if (buttons == null) {
 161  0
             buttons = new ArrayList<KSButton>();
 162  0
             button.addStyleName("ks-button-spacing");
 163  0
             buttons.add(button);
 164  0
             viewButtonsMap.put(viewType, buttons);
 165  
         } else {
 166  0
             buttons.add(button);
 167  
         }
 168  0
     }
 169  
 
 170  
     @Override
 171  
     protected void hideView(View view) {
 172  0
         contentPanel.clear();
 173  0
         buttonPanel.clear();
 174  0
     }
 175  
 
 176  
     @Override
 177  
     protected void renderView(View view) {
 178  0
         contentPanel.add(view.asWidget());
 179  0
         List<KSButton> buttons = viewButtonsMap.get(view.getViewEnum());
 180  0
         if (buttons != null) {
 181  0
             for (KSButton button : buttons) {
 182  0
                 buttonPanel.add(button);
 183  
             }
 184  
         }
 185  0
         KSMenuItemData item = viewMenuItemMap.get(view.getViewEnum());
 186  0
         if (item != null) {
 187  0
             item.setSelected(true, false);
 188  
         }
 189  0
     }
 190  
 
 191  
     /* Adds 'name' of the menu above menu items. This menu name has no view */
 192  
 
 193  
     public void addMenu(String title) {
 194  0
         if (title != null && !title.equals("")) {
 195  0
             KSMenuItemData item = new KSMenuItemData(title);
 196  0
             topLevelMenuItems.add(item);
 197  0
             List<View> list = new ArrayList<View>();
 198  0
             menuViewMap.put(title, list);
 199  0
             if (refreshMenuOnAdd) {
 200  0
                 menu.refresh();
 201  
             }
 202  
         }
 203  0
     }
 204  
 
 205  
     /**
 206  
      * Adds a view whose view the menu at first.  addMenuItem() should not be called before this method if it is
 207  
      * intended for this to be the first view the user sees.  revealMenuItems()
 208  
      * must be called to show any items that were added after this call.
 209  
      * IMPORTANT: the order in which you call this method, addMenuItem and addSpecialMenuItem affects the order in which they appear
 210  
      * on the menu, but also the order in which they are shown when the showNextViewOnMenu is called.  Care must be
 211  
      * taken when calling these methods to insure a consistent/logical UI.
 212  
      */
 213  
     public void addStartMenuItem(String parentMenu, final View view) {
 214  0
         addMenuItem(parentMenu, view);
 215  0
         this.setDefaultView(view.getViewEnum());
 216  0
         refreshMenuOnAdd = false;
 217  0
         menu.refresh();
 218  0
     }
 219  
 
 220  
     public void revealMenuItems() {
 221  0
         menu.refresh();
 222  0
         refreshMenuOnAdd = true;
 223  0
     }
 224  
 
 225  
     /**
 226  
      * Adds a view whose view name will appear as a link on the menu, the view will be shown when this item is clicked.
 227  
      * IMPORTANT: the order in which you call addMenuItem and addSpecialMenuItem affects the order in which they appear
 228  
      * on the menu, but also the order in which they are shown when the showNextViewOnMenu is called.  Care must be
 229  
      * taken when calling these methods to insure a consistent/logical UI.
 230  
      */
 231  
     @Override
 232  
     public void addMenuItem(String parentMenu, final View view) {
 233  0
         super.addView(view);
 234  0
         KSMenuItemData parentItem = null;
 235  0
         for (int i = 0; i < topLevelMenuItems.size(); i++) {
 236  0
             if (topLevelMenuItems.get(i).getLabel().equals(parentMenu)) {
 237  0
                 parentItem = topLevelMenuItems.get(i);
 238  0
                 break;
 239  
             }
 240  
         }
 241  
 
 242  0
         KSMenuItemData item = new KSMenuItemData(view.getName());
 243  0
         viewMenuItemMap.put(view.getViewEnum(), item);
 244  0
         item.setClickHandler(new ClickHandler() {
 245  
 
 246  
             @Override
 247  
             public void onClick(ClickEvent event) {
 248  0
                 DeferredCommand.addCommand(new Command() {
 249  
                     @Override
 250  
                     public void execute() {
 251  0
                         MenuSectionController.this.showView(view.getViewEnum(), showViewCallback);
 252  0
                     }
 253  
                 });
 254  0
             }
 255  
 
 256  
         });
 257  
 
 258  0
         if (parentItem != null) {
 259  0
             menuOrder.add(view);
 260  0
             parentItem.addSubItem(item);
 261  0
             menuViewMap.get(parentMenu).add(view);
 262  
         } else {
 263  0
             menuOrder.add(view);
 264  0
             topLevelMenuItems.add(item);
 265  0
             menuViewMap.get("").add(view);
 266  
         }
 267  
 
 268  0
         if (refreshMenuOnAdd) {
 269  0
             menu.refresh();
 270  
         }
 271  0
     }
 272  
 
 273  
 
 274  
     /**
 275  
      * This adds a special item that is a top level menu item to the menu, this will appear directly below other
 276  
      * menus that are currently added to the menu.  This menu item has special styling to make it more apparent on
 277  
      * the menu visually.
 278  
      * IMPORTANT: the order in which you call addMenuItem and addSpecialMenuItem affects the order in which they appear
 279  
      * on the menu, but also the order in which they are shown when the showNextViewOnMenu is called.  Care must be
 280  
      * taken when calling these methods to insure a consistent/logical UI.
 281  
      */
 282  
     @Override
 283  
     public void addSpecialMenuItem(final View view, String description) {
 284  
         //TODO add description to the menu item
 285  0
         super.addView(view);
 286  0
         menuViewMap.get("").add(view);
 287  0
         menuOrder.add(view);
 288  0
         KSMenuItemData item = new KSMenuItemData(view.getName());
 289  0
         item.addSpecialStyle("ks-menu-layout-special-menu-item-panel");
 290  0
         viewMenuItemMap.put(view.getViewEnum(), item);
 291  0
         item.setClickHandler(new ClickHandler() {
 292  
 
 293  
             @Override
 294  
             public void onClick(ClickEvent event) {
 295  0
                 DeferredCommand.addCommand(new Command() {
 296  
                     @Override
 297  
                     public void execute() {
 298  0
                         MenuSectionController.this.showView(view.getViewEnum(), showViewCallback);
 299  0
                     }
 300  
                 });
 301  0
             }
 302  
 
 303  
         });
 304  0
         topLevelMenuItems.add(item);
 305  0
         if (refreshMenuOnAdd) {
 306  0
             menu.refresh();
 307  
         }
 308  0
     }
 309  
 
 310  
     /**
 311  
      * This version of updateModel only traverses views that can be accessed through its menu.
 312  
      * Views that are part of this controller, but not part of the menu, can update their views through
 313  
      * updateModelFromCurrentView and updateModelFromView methods.
 314  
      */
 315  
     @Override
 316  
     public void updateModel() {
 317  0
         for (View v : menuOrder) {
 318  0
             v.updateModel();
 319  
         }
 320  
 
 321  0
     }
 322  
 
 323  
 
 324  
 }