Clover Coverage Report - Kuali Student 1.3.0-SNAPSHOT (Aggregated)
Coverage timestamp: Thu Apr 28 2011 05:03:32 EDT
../../../../../../../../../img/srcFileCovDistChart0.png 2% of files have more coverage
61   177   35   4.69
36   148   0.57   13
13     2.69  
1    
 
Line # 21 61 0% 35 110 0% 0.0
 
No Tests
 
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.application.Application;
9    import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
10    import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView;
11    import org.kuali.student.common.ui.client.mvc.Callback;
12    import org.kuali.student.common.ui.client.mvc.View;
13    import org.kuali.student.common.ui.client.widgets.KSButton;
14    import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
15    import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData;
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.ui.FlowPanel;
20   
 
21    public class MenuEditableSectionController extends MenuSectionController{
22   
23    private boolean editMode = false;
24    private boolean isEditable = true;
25   
26    //better way to do this other than 2 maps?
27    private Map<Enum<?>, Enum<?>> readOnlyToEditMap = new HashMap<Enum<?>, Enum<?>>();
28    private Map<Enum<?>, Enum<?>> editToReadOnlyMap = new HashMap<Enum<?>, Enum<?>>();
29   
30    private List<View> readOnlyViews = new ArrayList<View>();
31    private List<KSButton> editLinks = new ArrayList<KSButton>();
32   
33    private Callback<Boolean> editLinkCallback = new Callback<Boolean>(){
34   
 
35  0 toggle @Override
36    public void exec(Boolean result) {
37  0 if(result == true){
38  0 KSMenuItemData item = viewMenuItemMap.get(getCurrentView().getViewEnum());
39  0 if(item == null){
40  0 Enum<?> readOnlyEnum = editToReadOnlyMap.get(getCurrentView().getViewEnum());
41  0 if(readOnlyEnum != null){
42  0 item = viewMenuItemMap.get(readOnlyEnum);
43    }
44    }
45  0 if(item != null && !item.isSelected()){
46  0 item.setSelected(true, false);
47    }
48    }
49    }
50    };
51   
 
52  0 toggle public MenuEditableSectionController() {
53  0 super();
54    }
55   
 
56  0 toggle public void addMenuItem(String parentMenu, final View readOnlyView, final View editView){
57  0 super.addMenuItem(parentMenu, readOnlyView);
58  0 this.addView(editView);
59  0 readOnlyToEditMap.put(readOnlyView.getViewEnum(), editView.getViewEnum());
60  0 editToReadOnlyMap.put(editView.getViewEnum(), readOnlyView.getViewEnum());
61  0 attachEditLink(readOnlyView);
62    }
63   
 
64  0 toggle public void attachEditLink(final View v){
65  0 readOnlyViews.add(v);
66  0 createEditLink(v);
67    }
68   
 
69  0 toggle public KSButton generateEditLink(final View v){
70  0 KSButton editLink = new KSButton(Application.getApplicationContext().getMessage("edit"), ButtonStyle.DEFAULT_ANCHOR, new ClickHandler(){
71   
 
72  0 toggle @Override
73    public void onClick(ClickEvent event) {
74  0 editMode = true;
75  0 showView(v.getViewEnum(), editLinkCallback);
76    }
77    });
78  0 editLinks.add(editLink);
79   
80  0 editLink.addStyleName("ks-header-edit-link");
81   
82  0 return editLink;
83    }
84   
 
85  0 toggle private void createEditLink(final View v){
86  0 if(isEditable){
87  0 KSButton editLink = generateEditLink(v);
88   
89  0 if(v instanceof SectionView){
90    //TODO Change to put in section header
91  0 SectionTitle title = ((SectionView) v).getLayout().getLayoutTitle();
92  0 if(title != null){
93  0 title.add(editLink);
94    }
95    else{
96  0 ((SectionView) v).getLayout().insert(editLink, 0);
97    }
98    }
99  0 else if(v.asWidget() instanceof FlowPanel){
100  0 ((FlowPanel)v.asWidget()).insert(editLink, 0);
101    }
102    }
103    }
104   
 
105  0 toggle private void detachEditLinks(){
106  0 for(KSButton b: editLinks){
107  0 b.removeFromParent();
108    }
109    }
110   
 
111  0 toggle @Override
112    public <V extends Enum<?>> void showView(V viewType, Callback<Boolean> onReadyCallback){
113    //show the edit view only
114  0 if(editMode && isEditable){
115  0 Enum<?> editViewEnum = readOnlyToEditMap.get(viewType);
116  0 if(editViewEnum != null){
117  0 super.showView(editViewEnum, onReadyCallback);
118    }
119    else{
120  0 super.showView(viewType, onReadyCallback);
121    }
122    }
123    //show the read only view only
124    else{
125  0 Enum<?> readOnlyEnum = editToReadOnlyMap.get(viewType);
126  0 if(readOnlyEnum != null){
127  0 super.showView(readOnlyEnum, onReadyCallback);
128    }
129    else{
130  0 super.showView(viewType, onReadyCallback);
131    }
132    }
133    }
134   
 
135  0 toggle public void setEditable(boolean editable){
136  0 if(editable && this.isEditable != true){
137  0 this.isEditable = editable;
138  0 for(View v: readOnlyViews){
139  0 createEditLink(v);
140    }
141    }
142  0 else if(!editable && this.isEditable == true){
143  0 this.isEditable = editable;
144  0 detachEditLinks();
145    }
146    }
147   
 
148  0 toggle public void setEditMode(final boolean editMode){
149  0 if(this.editMode != editMode){
150  0 this.editMode = editMode;
151  0 this.showView(this.getCurrentViewEnum(), new Callback<Boolean>(){
152   
 
153  0 toggle @Override
154    public void exec(Boolean result) {
155  0 if(false){
156  0 MenuEditableSectionController.this.editMode = !editMode;
157    }
158    }
159    });
160    }
161    }
162   
 
163  0 toggle public void addCommonEditButton(String parentMenu, KSButton button){
164  0 if(parentMenu != null){
165  0 List<View> views = menuViewMap.get(parentMenu);
166  0 if(views != null){
167  0 for(int i=0; i < views.size(); i++){
168  0 Enum<?> editEnum = readOnlyToEditMap.get(views.get(i).getViewEnum());
169  0 if(editEnum != null){
170  0 addButtonForView(editEnum, button);
171    }
172    }
173    }
174    }
175    }
176   
177    }