| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 110 (110) |
Complexity: 35 |
Complexity Density: 0.57 |
|
| 21 |
|
public class MenuEditableSectionController extends MenuSectionController{ |
| 22 |
|
|
| 23 |
|
private boolean editMode = false; |
| 24 |
|
private boolean isEditable = true; |
| 25 |
|
|
| 26 |
|
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 6 |
Complexity Density: 0.75 |
|
| 35 |
0
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
0
|
public MenuEditableSectionController() {... |
| 53 |
0
|
super(); |
| 54 |
|
} |
| 55 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 56 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 64 |
0
|
public void attachEditLink(final View v){... |
| 65 |
0
|
readOnlyViews.add(v); |
| 66 |
0
|
createEditLink(v); |
| 67 |
|
} |
| 68 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 69 |
0
|
public KSButton generateEditLink(final View v){... |
| 70 |
0
|
KSButton editLink = new KSButton(Application.getApplicationContext().getMessage("edit"), ButtonStyle.DEFAULT_ANCHOR, new ClickHandler(){ |
| 71 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 72 |
0
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 85 |
0
|
private void createEditLink(final View v){... |
| 86 |
0
|
if(isEditable){ |
| 87 |
0
|
KSButton editLink = generateEditLink(v); |
| 88 |
|
|
| 89 |
0
|
if(v instanceof SectionView){ |
| 90 |
|
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 105 |
0
|
private void detachEditLinks(){... |
| 106 |
0
|
for(KSButton b: editLinks){ |
| 107 |
0
|
b.removeFromParent(); |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 111 |
0
|
@Override... |
| 112 |
|
public <V extends Enum<?>> void showView(V viewType, Callback<Boolean> onReadyCallback){ |
| 113 |
|
|
| 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 |
|
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 5 |
Complexity Density: 0.71 |
|
| 135 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 148 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 153 |
0
|
@Override... |
| 154 |
|
public void exec(Boolean result) { |
| 155 |
0
|
if(false){ |
| 156 |
0
|
MenuEditableSectionController.this.editMode = !editMode; |
| 157 |
|
} |
| 158 |
|
} |
| 159 |
|
}); |
| 160 |
|
} |
| 161 |
|
} |
| 162 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.71 |
|
| 163 |
0
|
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 |
|
} |