From d5388b0040c7c991e6a48e321d22d9bcdb8c5074 Mon Sep 17 00:00:00 2001 From: hades Date: Fri, 3 Apr 2020 15:00:54 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-29149=20=E5=9F=BA=E7=A1=80=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6-=E5=A4=8D=E9=80=89=E4=B8=8B=E6=8B=89=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8F=AF=E4=B8=8D=E6=98=BE=E7=A4=BA=E2=80=9C=E5=85=A8?= =?UTF-8?q?=E9=80=89=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/icombocheckbox/UICheckListPopup.java | 15 ++++--- .../icombocheckbox/UICheckListPopupTest.java | 41 +++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 designer-base/src/test/java/com/fr/design/gui/icombocheckbox/UICheckListPopupTest.java diff --git a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java index 9592eb517e..66f4bfcbcb 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java @@ -192,7 +192,8 @@ public class UICheckListPopup extends UIPopupMenu { List 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 selectedValues = new ArrayList(); 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()]); } diff --git a/designer-base/src/test/java/com/fr/design/gui/icombocheckbox/UICheckListPopupTest.java b/designer-base/src/test/java/com/fr/design/gui/icombocheckbox/UICheckListPopupTest.java new file mode 100644 index 0000000000..33a98e078d --- /dev/null +++ b/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 map = new TreeMap<>(); + map.put("a", true); + map.put("b", false); + map.put("c", true); + List list = new ArrayList<>(); + for (Map.Entry 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()); + } + +} \ No newline at end of file