| 1 |
|
package org.kuali.student.lum.common.client.widgets; |
| 2 |
|
|
| 3 |
|
import java.util.ArrayList; |
| 4 |
|
import java.util.HashMap; |
| 5 |
|
import java.util.Iterator; |
| 6 |
|
import java.util.List; |
| 7 |
|
|
| 8 |
|
import org.kuali.student.common.ui.client.application.Application; |
| 9 |
|
import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection; |
| 10 |
|
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
| 11 |
|
import org.kuali.student.common.ui.client.configurable.mvc.sections.SwapSection; |
| 12 |
|
import org.kuali.student.common.ui.client.event.SectionUpdateEvent; |
| 13 |
|
import org.kuali.student.common.ui.client.widgets.dialog.ConfirmationDialog; |
| 14 |
|
import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout; |
| 15 |
|
import org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract; |
| 16 |
|
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent; |
| 17 |
|
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler; |
| 18 |
|
|
| 19 |
|
import com.google.gwt.event.dom.client.ClickEvent; |
| 20 |
|
import com.google.gwt.event.dom.client.ClickHandler; |
| 21 |
|
|
|
|
|
| 0% |
Uncovered Elements: 125 (125) |
Complexity: 34 |
Complexity Density: 0.47 |
|
| 22 |
|
public class SwitchSection extends BaseSection { |
| 23 |
|
private HashMap<String, Section> swapSectionMap = new HashMap<String, Section>(); |
| 24 |
|
private KSSelectItemWidgetAbstract selectableWidget; |
| 25 |
|
private List<Section> deleted = new ArrayList<Section>(); |
| 26 |
|
private ConfirmationDialog dialog; |
| 27 |
|
private boolean showConfirmation = true; |
| 28 |
|
private List<String> lastSelection = new ArrayList<String>(); |
| 29 |
|
private List<String> deletionParentKeys; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@param |
| 36 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 37 |
0
|
public SwitchSection(KSSelectItemWidgetAbstract selectableWidget){... |
| 38 |
0
|
this.init(selectableWidget); |
| 39 |
|
} |
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 41 |
0
|
public SwitchSection(KSSelectItemWidgetAbstract selectableWidget, ConfirmationDialog dialog){... |
| 42 |
0
|
this.dialog = dialog; |
| 43 |
0
|
this.init(selectableWidget); |
| 44 |
|
} |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 46 |
0
|
private void init(KSSelectItemWidgetAbstract selectableWidget){... |
| 47 |
0
|
this.selectableWidget = selectableWidget; |
| 48 |
|
|
| 49 |
0
|
if(dialog == null){ |
| 50 |
0
|
dialog = |
| 51 |
|
new ConfirmationDialog(Application.getApplicationContext().getMessage("fieldDeletionTitle"), |
| 52 |
|
Application.getApplicationContext().getMessage("fieldDeletionConfirmMessage")); |
| 53 |
|
} |
| 54 |
0
|
dialog.getConfirmButton().addClickHandler(new ClickHandler(){ |
| 55 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 56 |
0
|
@Override... |
| 57 |
|
public void onClick(ClickEvent event) { |
| 58 |
0
|
handleUserSelection(); |
| 59 |
0
|
dialog.hide(); |
| 60 |
|
} |
| 61 |
|
}); |
| 62 |
|
|
| 63 |
0
|
selectableWidget.addSelectionChangeHandler(new SelectionChangeHandler(){ |
| 64 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 65 |
0
|
@Override... |
| 66 |
|
public void onSelectionChange(SelectionChangeEvent event) { |
| 67 |
0
|
if(event.isUserInitiated() && showConfirmation){ |
| 68 |
0
|
if(SwitchSection.this.selectableWidget.getSelectedItems().size() < lastSelection.size()){ |
| 69 |
0
|
dialog.show(); |
| 70 |
|
} |
| 71 |
0
|
else if(!SwitchSection.this.selectableWidget.getSelectedItems().containsAll(lastSelection)){ |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
0
|
dialog.show(); |
| 83 |
|
} |
| 84 |
|
else{ |
| 85 |
0
|
handleUserSelection(); |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
0
|
else if(event.isUserInitiated()){ |
| 89 |
0
|
handleUserSelection(); |
| 90 |
|
} |
| 91 |
|
else{ |
| 92 |
0
|
handleSelection(); |
| 93 |
|
} |
| 94 |
0
|
lastSelection.clear(); |
| 95 |
0
|
lastSelection.addAll(SwitchSection.this.selectableWidget.getSelectedItems()); |
| 96 |
|
} |
| 97 |
|
}); |
| 98 |
0
|
layout = new VerticalFieldLayout(); |
| 99 |
0
|
this.add(layout); |
| 100 |
|
} |
| 101 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 102 |
0
|
private void handleUserSelection(){... |
| 103 |
0
|
List<String> selected = SwitchSection.this.selectableWidget.getSelectedItems(); |
| 104 |
0
|
for(int i = 0; i < selected.size(); i++){ |
| 105 |
0
|
String key = selected.get(i); |
| 106 |
0
|
showSwappableSection(key); |
| 107 |
|
} |
| 108 |
|
|
| 109 |
0
|
Iterator<String> it = swapSectionMap.keySet().iterator(); |
| 110 |
0
|
while(it.hasNext()){ |
| 111 |
0
|
String key = it.next(); |
| 112 |
0
|
if(!selected.contains(key)){ |
| 113 |
0
|
removeSwappableSection(key); |
| 114 |
|
} |
| 115 |
|
} |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 123 |
0
|
private void handleSelection(){... |
| 124 |
0
|
List<String> selected = SwitchSection.this.selectableWidget.getSelectedItems(); |
| 125 |
0
|
for(int i = 0; i < selected.size(); i++){ |
| 126 |
0
|
String key = selected.get(i); |
| 127 |
0
|
showSwappableSection(key); |
| 128 |
|
} |
| 129 |
|
|
| 130 |
0
|
Iterator<String> it = swapSectionMap.keySet().iterator(); |
| 131 |
0
|
while(it.hasNext()){ |
| 132 |
0
|
String key = it.next(); |
| 133 |
0
|
if(!selected.contains(key)){ |
| 134 |
0
|
removeSwappableSection(key); |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
|
} |
| 138 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 139 |
0
|
private void showSwappableSection(String key){... |
| 140 |
0
|
Section section = swapSectionMap.get(key); |
| 141 |
0
|
if(section != null){ |
| 142 |
0
|
if(deleted.contains(section)){ |
| 143 |
0
|
deleted.remove(section); |
| 144 |
|
} |
| 145 |
0
|
if(!section.getLayout().isVisible()){ |
| 146 |
0
|
section.enableValidation(true); |
| 147 |
0
|
section.getLayout().setVisible(true); |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
|
} |
| 151 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 152 |
0
|
private void removeSwappableSection(String key){... |
| 153 |
0
|
Section section = swapSectionMap.get(key); |
| 154 |
0
|
if(section != null){ |
| 155 |
0
|
if(!deleted.contains(section)){ |
| 156 |
0
|
deleted.add(section); |
| 157 |
|
} |
| 158 |
0
|
if(section.getLayout().isVisible()){ |
| 159 |
0
|
section.enableValidation(false); |
| 160 |
0
|
section.getLayout().setVisible(false); |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
} |
| 164 |
|
} |
| 165 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 166 |
0
|
public void enableConfirmation(boolean enable){... |
| 167 |
0
|
showConfirmation = enable; |
| 168 |
|
} |
| 169 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 170 |
0
|
public String addSection(Section section, String swapKey){... |
| 171 |
0
|
swapSectionMap.put(swapKey, section); |
| 172 |
0
|
String key = layout.addLayout(section.getLayout()); |
| 173 |
0
|
section.getLayout().setVisible(false); |
| 174 |
0
|
if(selectableWidget.getSelectedItems().contains(swapKey)){ |
| 175 |
0
|
handleSelection(); |
| 176 |
|
} |
| 177 |
0
|
sections.add(section); |
| 178 |
0
|
return key; |
| 179 |
|
} |
| 180 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 181 |
0
|
public String addSection(String key, Section section, String swapKey){... |
| 182 |
0
|
swapSectionMap.put(swapKey, section); |
| 183 |
0
|
section.getLayout().setKey(key); |
| 184 |
0
|
String rkey = layout.addLayout(section.getLayout()); |
| 185 |
0
|
section.getLayout().setVisible(false); |
| 186 |
0
|
if(selectableWidget.getSelectedItems().contains(swapKey)){ |
| 187 |
0
|
handleSelection(); |
| 188 |
|
} |
| 189 |
0
|
sections.add(section); |
| 190 |
0
|
return rkey; |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 194 |
0
|
@Override... |
| 195 |
|
public String addSection(Section section) { |
| 196 |
0
|
throw new UnsupportedOperationException("Sections can be added to swappable section only through " + |
| 197 |
|
"the addSection(Section section, String swapKey) method"); |
| 198 |
|
|
| 199 |
|
} |
| 200 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 201 |
0
|
@Override... |
| 202 |
|
public String addSection(String key, Section section) { |
| 203 |
0
|
throw new UnsupportedOperationException("Sections can be added to swappable section only through " + |
| 204 |
|
"the addSection(Section section, String swapKey) method"); |
| 205 |
|
} |
| 206 |
|
} |