Browse Source

REPORT-29149 基础控件-复选下拉列表可不显示“全选”

research/11.0
hades 5 years ago
parent
commit
d5388b0040
  1. 15
      designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java
  2. 41
      designer-base/src/test/java/com/fr/design/gui/icombocheckbox/UICheckListPopupTest.java

15
designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java

@ -192,7 +192,8 @@ public class UICheckListPopup extends UIPopupMenu {
List<Object> allValue = Arrays.asList(values);
for (Object value : selectedValues.keySet()) {
int index = allValue.indexOf(value);
checkBoxList.get(index + 1).setSelected(selectedValues.get(value));
index = supportSelectAll ? index + 1 : index;
checkBoxList.get(index).setSelected(selectedValues.get(value));
}
}
@ -204,15 +205,19 @@ public class UICheckListPopup extends UIPopupMenu {
public Object[] getSelectedValues() {
List<Object> selectedValues = new ArrayList<Object>();
int selectCount = 0;
for (int i = 1; i < checkBoxList.size(); i++) {
int startIndex = supportSelectAll ? 1 : 0;
for (int i = startIndex; i < checkBoxList.size(); i++) {
if (checkBoxList.get(i).isSelected()) {
selectedValues.add(values[i - 1]);
int valueIndex = supportSelectAll ? i - 1 : i;
selectedValues.add(values[valueIndex]);
selectCount++;
}
}
//全选半选切换
switchSelectIcon(selectCount);
if (supportSelectAll) {
switchSelectIcon(selectCount);
}
return selectedValues.toArray(new Object[selectedValues.size()]);
}

41
designer-base/src/test/java/com/fr/design/gui/icombocheckbox/UICheckListPopupTest.java

@ -0,0 +1,41 @@
package com.fr.design.gui.icombocheckbox;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/**
* @author hades
* @version 10.0
* Created by hades on 2020/4/3
*/
public class UICheckListPopupTest extends TestCase {
@Test
public void testGetSelectedValues() {
Object[] values = new Object[]{"a", "b", "c"};
Map<Object, Boolean> map = new TreeMap<>();
map.put("a", true);
map.put("b", false);
map.put("c", true);
List<Object> list = new ArrayList<>();
for (Map.Entry<Object, Boolean> entry : map.entrySet()) {
if (entry.getValue()) {
list.add(entry.getKey());
}
}
Object[] selectValues = list.toArray();
UICheckListPopup uiCheckListPopup1 = new UICheckListPopup(values);
uiCheckListPopup1.setSelectedValue(map);
Assert.assertArrayEquals(selectValues, uiCheckListPopup1.getSelectedValues());
UICheckListPopup uiCheckListPopup2 = new UICheckListPopup(values, false);
uiCheckListPopup2.setSelectedValue(map);
Assert.assertArrayEquals(selectValues, uiCheckListPopup2.getSelectedValues());
}
}
Loading…
Cancel
Save