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