|
|
@ -4,12 +4,12 @@ import com.fr.design.constants.UIConstants; |
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.event.ItemEvent; |
|
|
|
import java.awt.event.ItemEvent; |
|
|
|
import java.util.Iterator; |
|
|
|
|
|
|
|
import java.util.Map.Entry; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.DefaultComboBoxModel; |
|
|
|
import javax.swing.DefaultComboBoxModel; |
|
|
|
import javax.swing.JLabel; |
|
|
|
import javax.swing.JLabel; |
|
|
|
import javax.swing.JList; |
|
|
|
import javax.swing.JList; |
|
|
|
|
|
|
|
import javax.swing.event.AncestorEvent; |
|
|
|
|
|
|
|
import javax.swing.event.AncestorListener; |
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
|
|
|
|
|
|
|
@ -33,136 +33,217 @@ public class TableDataComboBox extends UIComboBox implements Prepare4DataSourceC |
|
|
|
protected java.util.Map<String, TableDataWrapper> resMap; |
|
|
|
protected java.util.Map<String, TableDataWrapper> resMap; |
|
|
|
private java.util.Map<String, TableDataWrapper> dsMap; |
|
|
|
private java.util.Map<String, TableDataWrapper> dsMap; |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private boolean refresModel = false; |
|
|
|
private boolean refreshModel = false; |
|
|
|
private String treeName; //树数据集本身的名字
|
|
|
|
private String treeName = StringUtils.EMPTY; //树数据集本身的名字
|
|
|
|
private ChangeListener changeListener; |
|
|
|
private ChangeListener changeListener; |
|
|
|
|
|
|
|
|
|
|
|
public TableDataComboBox(TableDataSource source){ |
|
|
|
/** |
|
|
|
this(source,StringUtils.EMPTY); |
|
|
|
* 兼容插件调用 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param source 插件中传入的数据源 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public TableDataComboBox(TableDataSource source) { |
|
|
|
|
|
|
|
this(); |
|
|
|
} |
|
|
|
} |
|
|
|
public TableDataComboBox(TableDataSource source, String treeName) { |
|
|
|
|
|
|
|
super(); |
|
|
|
/** |
|
|
|
|
|
|
|
* 兼容插件调用 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param source 插件中传入的数据源 |
|
|
|
|
|
|
|
* @param treeName 树数据集名称 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public TableDataComboBox(TableDataSource source, String treeName) { |
|
|
|
|
|
|
|
this(treeName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 根据树名称创建TableDataComboBox。 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param treeName 树数据集名称 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public TableDataComboBox(String treeName) { |
|
|
|
|
|
|
|
this(); |
|
|
|
|
|
|
|
// 传入树数据集名称
|
|
|
|
this.treeName = treeName; |
|
|
|
this.treeName = treeName; |
|
|
|
this.setRenderer(new UIComboBoxRenderer() { |
|
|
|
} |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
|
|
|
|
private boolean labelVisible = true; |
|
|
|
/** |
|
|
|
|
|
|
|
* 初始化TableDataComboBox |
|
|
|
@Override |
|
|
|
*/ |
|
|
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
|
|
|
public TableDataComboBox() { |
|
|
|
JLabel renderer = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
|
|
|
super(); |
|
|
|
if (value instanceof TableDataWrapper) { |
|
|
|
setListCellRenderer(); |
|
|
|
labelVisible = true; |
|
|
|
addListener(); |
|
|
|
TableDataWrapper tableDataWrapper = (TableDataWrapper)value; |
|
|
|
} |
|
|
|
renderer.setIcon(tableDataWrapper.getIcon()); |
|
|
|
|
|
|
|
renderer.setText(tableDataWrapper.getTableDataName()); |
|
|
|
/** |
|
|
|
renderer.setToolTipText(tableDataWrapper.getTableDataName()); |
|
|
|
* 设置渲染器 |
|
|
|
} else { |
|
|
|
*/ |
|
|
|
labelVisible = false; |
|
|
|
private void setListCellRenderer() { |
|
|
|
renderer.setIcon(null); |
|
|
|
this.setRenderer(new UIComboBoxRenderer() { |
|
|
|
renderer.setText(StringUtils.EMPTY); |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
} |
|
|
|
private boolean labelVisible = true; |
|
|
|
return renderer; |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
|
|
|
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
|
|
|
@Override |
|
|
|
JLabel renderer = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
|
|
|
public Dimension getPreferredSize() { |
|
|
|
if (value instanceof TableDataWrapper) { |
|
|
|
return labelVisible ? super.getPreferredSize() : new Dimension(super.getPreferredSize().width, 0); |
|
|
|
labelVisible = true; |
|
|
|
} |
|
|
|
TableDataWrapper tableDataWrapper = (TableDataWrapper) value; |
|
|
|
}); |
|
|
|
renderer.setIcon(tableDataWrapper.getIcon()); |
|
|
|
refresh(source); |
|
|
|
renderer.setText(tableDataWrapper.getTableDataName()); |
|
|
|
registerDSChangeListener(); |
|
|
|
renderer.setToolTipText(tableDataWrapper.getTableDataName()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
labelVisible = false; |
|
|
|
|
|
|
|
renderer.setIcon(null); |
|
|
|
|
|
|
|
renderer.setText(StringUtils.EMPTY); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return renderer; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Dimension getPreferredSize() { |
|
|
|
|
|
|
|
return labelVisible ? super.getPreferredSize() : new Dimension(super.getPreferredSize().width, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 在comboBox可见时添加下拉事件与数据集响应事件 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void addListener() { |
|
|
|
|
|
|
|
this.addAncestorListener(new AncestorListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void ancestorAdded(AncestorEvent event) { |
|
|
|
|
|
|
|
registerDSChangeListener(); |
|
|
|
|
|
|
|
refresh(DesignTableDataManager.getEditingTableDataSource()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void ancestorRemoved(AncestorEvent event) { |
|
|
|
|
|
|
|
DesignTableDataManager.removeDsChangeListener(changeListener); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void ancestorMoved(AncestorEvent event) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* refresh ComboBox |
|
|
|
* refresh ComboBox |
|
|
|
* @param source |
|
|
|
* |
|
|
|
|
|
|
|
* @param source 数据源 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void refresh(TableDataSource source) { |
|
|
|
public void refresh(TableDataSource source) { |
|
|
|
TableDataWrapper dataWrapper = getSelectedItem(); |
|
|
|
refreshModel = true; |
|
|
|
refresModel = true; |
|
|
|
setResMap(source); |
|
|
|
setResMap(source); |
|
|
|
|
|
|
|
setDsMap(); |
|
|
|
setDsMap(); |
|
|
|
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
|
|
// 获取当前选中的数据项
|
|
|
|
this.setModel(model); |
|
|
|
TableDataWrapper dataWrapper = getSelectedItem(); |
|
|
|
model.addElement(UIConstants.PENDING); |
|
|
|
// 更新下拉模型
|
|
|
|
// 遍历添加所有数据项到模型
|
|
|
|
refreshComboBoxModel(); |
|
|
|
Iterator<Entry<String, TableDataWrapper>> entryIt = dsMap.entrySet().iterator(); |
|
|
|
//处理已选中的数据项
|
|
|
|
while (entryIt.hasNext()) { |
|
|
|
updateSelectedItem(dataWrapper); |
|
|
|
TableDataWrapper tableDataWrapper = entryIt.next().getValue(); |
|
|
|
refreshModel = false; |
|
|
|
if (!ComparatorUtils.equals(tableDataWrapper.getTableDataName(), treeName)) { |
|
|
|
} |
|
|
|
model.addElement(tableDataWrapper); |
|
|
|
|
|
|
|
} |
|
|
|
protected void setResMap(TableDataSource source) { |
|
|
|
} |
|
|
|
this.resMap = DesignTableDataManager.getAllEditingDataSet(source); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setDsMap() { |
|
|
|
|
|
|
|
dsMap = DesignTableDataManager.getAllDataSetIncludingProcedure(resMap); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void refreshComboBoxModel() { |
|
|
|
|
|
|
|
//创建ComboBox模型并设置
|
|
|
|
|
|
|
|
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
|
|
|
|
|
|
this.setModel(model); |
|
|
|
|
|
|
|
model.addElement(UIConstants.PENDING); |
|
|
|
|
|
|
|
// 遍历添加所有数据项到模型,树数据集comboBox下拉模型中排除掉本身
|
|
|
|
|
|
|
|
dsMap.values().stream() |
|
|
|
|
|
|
|
.filter(tableDataWrapper -> tableDataWrapper != null && !ComparatorUtils.equals(tableDataWrapper.getTableDataName(), treeName)) |
|
|
|
|
|
|
|
.forEach(model::addElement); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateSelectedItem(TableDataWrapper dataWrapper) { |
|
|
|
if (dataWrapper != null) { |
|
|
|
if (dataWrapper != null) { |
|
|
|
if (DesignTableDataManager.isDsNameChanged(dataWrapper.getTableDataName())) { |
|
|
|
if (DesignTableDataManager.isDsNameChanged(dataWrapper.getTableDataName())) { |
|
|
|
this.setSelectedTableDataByName(DesignTableDataManager.getChangedDsNameByOldDsName(dataWrapper.getTableDataName())); |
|
|
|
this.setSelectedTableData(DesignTableDataManager.getChangedDsNameByOldDsName(dataWrapper.getTableDataName())); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.getModel().setSelectedItem(dataWrapper); |
|
|
|
this.getModel().setSelectedItem(dataWrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
refresModel = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void setResMap(TableDataSource source) { |
|
|
|
/** |
|
|
|
this.resMap = DesignTableDataManager.getAllEditingDataSet(source); |
|
|
|
* 向resMap中添加TableData信息 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param name 数据集名字 |
|
|
|
|
|
|
|
* @param templateTableDataWrapper 数据集 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void putTableDataIntoMap(String name, TemplateTableDataWrapper templateTableDataWrapper) { |
|
|
|
|
|
|
|
if (dsMap.containsKey(name)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.addItem(templateTableDataWrapper); |
|
|
|
|
|
|
|
dsMap.put(name, templateTableDataWrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setDsMap() { |
|
|
|
public void setSelectedTableDataByName(String name) { |
|
|
|
dsMap = DesignTableDataManager.getAllDataSetIncludingProcedure(resMap); |
|
|
|
setResMap(DesignTableDataManager.getEditingTableDataSource()); |
|
|
|
|
|
|
|
setDsMap(); |
|
|
|
|
|
|
|
// 数据集名称修改后控件传入的还是旧名称
|
|
|
|
|
|
|
|
if (DesignTableDataManager.isDsNameChanged(name)) { |
|
|
|
|
|
|
|
name = DesignTableDataManager.getChangedDsNameByOldDsName(name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setSelectedTableData(name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setSelectedTableData(String name) { |
|
|
|
|
|
|
|
TableDataWrapper tableDataWrapper = dsMap.get(name) == null ? dsMap.get(name + "_P_CURSOR") : dsMap.get(name); |
|
|
|
|
|
|
|
this.getModel().setSelectedItem(tableDataWrapper); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public TableDataWrapper getSelectedItem() { |
|
|
|
|
|
|
|
if (dataModel.getSelectedItem() instanceof TableDataWrapper) { |
|
|
|
|
|
|
|
return (TableDataWrapper) dataModel.getSelectedItem(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 向resMap中添加TableData信息 |
|
|
|
* august:addElement方法竟然会fireItemStateChanged,蛋疼 |
|
|
|
* @param name 数据集名字 |
|
|
|
* @param e the event of interest |
|
|
|
* @param templateTableDataWrappe 数据集 |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void putTableDataIntoMap(String name, TemplateTableDataWrapper templateTableDataWrappe) { |
|
|
|
@Override |
|
|
|
if (dsMap.containsKey(name)) { |
|
|
|
protected void fireItemStateChanged(ItemEvent e) { |
|
|
|
return; |
|
|
|
if (!refreshModel) { |
|
|
|
} |
|
|
|
super.fireItemStateChanged(e); |
|
|
|
this.addItem(templateTableDataWrappe); |
|
|
|
} |
|
|
|
dsMap.put(name, templateTableDataWrappe); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setSelectedTableDataByName(String name) { |
|
|
|
|
|
|
|
TableDataWrapper tableDataWrappe = dsMap.get(name) == null? dsMap.get(name + "_P_CURSOR") : dsMap.get(name); |
|
|
|
|
|
|
|
this.getModel().setSelectedItem(tableDataWrappe); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public TableDataWrapper getSelectedItem() { |
|
|
|
|
|
|
|
if (dataModel.getSelectedItem() instanceof TableDataWrapper) { |
|
|
|
|
|
|
|
return (TableDataWrapper)dataModel.getSelectedItem(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//august:addElement方法竟然会fireItemStateChanged,蛋疼
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void fireItemStateChanged(ItemEvent e) { |
|
|
|
|
|
|
|
if (!refresModel) { |
|
|
|
|
|
|
|
super.fireItemStateChanged(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
*注册listener,相应数据集改变 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void registerDSChangeListener() { |
|
|
|
|
|
|
|
changeListener = new ChangeListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
|
|
|
|
TableDataComboBox.this.refresh(DesignTableDataManager.getEditingTableDataSource()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
DesignTableDataManager.addDsChangeListener(changeListener); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void registerGlobalDSChangeListener() { |
|
|
|
|
|
|
|
DesignTableDataManager.addGlobalDsChangeListener(changeListener); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 注册listener,相应数据集改变 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void registerDSChangeListener() { |
|
|
|
|
|
|
|
changeListener = new ChangeListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
|
|
|
|
TableDataComboBox.this.refresh(DesignTableDataManager.getEditingTableDataSource()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
DesignTableDataManager.addDsChangeListener(changeListener); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 兼容插件调用 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void registerGlobalDSChangeListener() { |
|
|
|
|
|
|
|
DesignTableDataManager.addGlobalDsChangeListener(changeListener); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |