Browse Source
Merge in DESIGN/design from ~YVAN/design:release/11.0 to release/11.0 * commit '759e499060efb9c119cffa9ef86e71d497616138': REPORT-69422 && REPORT-69426 产品调整部分UI && 复制单元格会影响数据集的展开/收起状态 【问题原因】1.产品验收功能的时候改了一些UI;2.因为粘贴单元格的时候会获取当前数据集面板,getInstance方法里会refresh一次整个数据集树,然后将所有节点重置到收起状态 【改动思路】1.调整UI;2.提供一个获取数据集树面板单例不刷新自己的方法,粘贴时使用 【review建议】无bugfix/11.0
Yvan
3 years ago
10 changed files with 224 additions and 20 deletions
@ -0,0 +1,162 @@ |
|||||||
|
package com.fr.design.gui.ilist; |
||||||
|
|
||||||
|
import com.fr.design.event.StateChangeListener; |
||||||
|
import com.fr.design.gui.icheckbox.UICheckBox; |
||||||
|
import com.fr.design.gui.itree.checkboxtree.TristateCheckBox; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
|
||||||
|
import javax.swing.AbstractListModel; |
||||||
|
import javax.swing.DefaultListCellRenderer; |
||||||
|
import javax.swing.JList; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.ListCellRenderer; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.awt.event.MouseListener; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 支持全选、全不选、半选的CheckBoxList面板 |
||||||
|
* @author Yvan |
||||||
|
*/ |
||||||
|
public class CheckBoxListWithPartialSelect extends JPanel { |
||||||
|
|
||||||
|
private UICheckBox[] dataCheckBoxes; |
||||||
|
|
||||||
|
private TristateCheckBox chooseAllCheckBox; |
||||||
|
|
||||||
|
private UIList dataList; |
||||||
|
|
||||||
|
public CheckBoxListWithPartialSelect (Object[] data) { |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
init(data); |
||||||
|
this.add(chooseAllCheckBox, BorderLayout.NORTH); |
||||||
|
this.add(dataList, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
private void init(Object[] data) { |
||||||
|
// 复选框组
|
||||||
|
dataCheckBoxes = new UICheckBox[data.length]; |
||||||
|
for (int i = 0; i < dataCheckBoxes.length; i++) { |
||||||
|
dataCheckBoxes[i] = new UICheckBox(transferDataValue2Show(data[i])); |
||||||
|
dataCheckBoxes[i].setSelected(true); |
||||||
|
} |
||||||
|
|
||||||
|
// UIList
|
||||||
|
dataList = new UIList(dataCheckBoxes); |
||||||
|
dataList.setModel(getListModel()); |
||||||
|
dataList.setCellRenderer(getListCellRenderer()); |
||||||
|
|
||||||
|
// 全选框
|
||||||
|
chooseAllCheckBox = new TristateCheckBox(Toolkit.i18nText("Fine-Design_Basic_Remove_All_Selected")); |
||||||
|
chooseAllCheckBox.setState(TristateCheckBox.SELECTED); |
||||||
|
chooseAllCheckBox.setFocusable(false); |
||||||
|
chooseAllCheckBox.addStateChangeListener(getChooseAllCheckBoxStateChangeListener()); |
||||||
|
dataList.addMouseListener(getDataListMouseListener()); |
||||||
|
} |
||||||
|
|
||||||
|
public List<Object> getSelectedObjects() { |
||||||
|
return dataList.getSelectedValuesList(); |
||||||
|
} |
||||||
|
|
||||||
|
protected MouseListener getDataListMouseListener() { |
||||||
|
return new MouseAdapter() { |
||||||
|
@Override |
||||||
|
public void mousePressed(MouseEvent e) { |
||||||
|
super.mousePressed(e); |
||||||
|
int index = dataList.getSelectedIndex(); |
||||||
|
if (index < 0) { |
||||||
|
return; |
||||||
|
} |
||||||
|
UICheckBox checkBox = (UICheckBox) dataList.getModel().getElementAt(index); |
||||||
|
checkBox.setSelected(!checkBox.isSelected()); |
||||||
|
//根据CheckBoxes中的选择情况来更新全选框的状态
|
||||||
|
int selectedCount = calculateSelectedNum(); |
||||||
|
if (selectedCount == 0) { |
||||||
|
chooseAllCheckBox.setState(TristateCheckBox.NOT_SELECTED); |
||||||
|
} else if (selectedCount == dataCheckBoxes.length) { |
||||||
|
chooseAllCheckBox.setState(TristateCheckBox.SELECTED); |
||||||
|
} else { |
||||||
|
chooseAllCheckBox.setState(TristateCheckBox.DO_NOT_CARE); |
||||||
|
} |
||||||
|
dataList.repaint(); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取全选框状态改变监听 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
protected StateChangeListener getChooseAllCheckBoxStateChangeListener() { |
||||||
|
return () -> { |
||||||
|
if (chooseAllCheckBox.getState() == TristateCheckBox.DO_NOT_CARE) { |
||||||
|
return; |
||||||
|
} |
||||||
|
boolean isSelected = chooseAllCheckBox.isSelected(); |
||||||
|
for (int i = 0; i < dataList.getModel().getSize(); i++) { |
||||||
|
UICheckBox checkBox = (UICheckBox) dataList.getModel().getElementAt(i); |
||||||
|
checkBox.setSelected(isSelected); |
||||||
|
} |
||||||
|
dataList.repaint(); |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 计算CheckBox的选中情况,用来更新全选框的状态 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
protected int calculateSelectedNum() { |
||||||
|
int count = 0; |
||||||
|
for (UICheckBox dataCheckBox : dataCheckBoxes) { |
||||||
|
if (dataCheckBox.isSelected()) { |
||||||
|
count++; |
||||||
|
} |
||||||
|
} |
||||||
|
return count; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将传入的Object转化为字符串展示,默认调用toString方法 |
||||||
|
* @param object |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
protected String transferDataValue2Show(Object object) { |
||||||
|
return object.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
protected AbstractListModel getListModel() { |
||||||
|
return new SelectedListDataModel(); |
||||||
|
} |
||||||
|
|
||||||
|
protected ListCellRenderer getListCellRenderer() { |
||||||
|
return new SelectedListCellRender(); |
||||||
|
} |
||||||
|
|
||||||
|
private class SelectedListCellRender extends DefaultListCellRenderer { |
||||||
|
|
||||||
|
@Override |
||||||
|
public Component getListCellRendererComponent(JList list, Object value, int index, final boolean isSelected, boolean cellHasFocus) { |
||||||
|
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
||||||
|
dataCheckBoxes[index] = (UICheckBox) value; |
||||||
|
dataCheckBoxes[index].setBackground(list.getBackground()); |
||||||
|
return dataCheckBoxes[index]; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private class SelectedListDataModel extends AbstractListModel { |
||||||
|
@Override |
||||||
|
public int getSize() { |
||||||
|
return dataCheckBoxes.length; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getElementAt(int index) { |
||||||
|
return (index > getSize() - 1 || index < 0) ? null : dataCheckBoxes[index]; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.0 KiB |
Loading…
Reference in new issue