@ -1,6 +1,8 @@
package com.fr.design.data.datapane ;
import com.fr.design.constants.UIConstants ;
import java.awt.Component ;
import java.awt.Dimension ;
import java.awt.event.ItemEvent ;
import java.util.Iterator ;
import java.util.Map.Entry ;
@ -23,7 +25,7 @@ import com.fr.stable.StringUtils;
/ * *
* 包含所有数据集的下拉框
*
*
* @author zhou
* @since 2012 - 4 - 20上午10 : 34 : 30
* /
@ -43,22 +45,29 @@ public class TableDataComboBox extends UIComboBox implements Prepare4DataSourceC
this . treeName = treeName ;
this . setRenderer ( new UIComboBoxRenderer ( ) {
private static final long serialVersionUID = 1L ;
private boolean labelVisible = true ;
@Override
public Component getListCellRendererComponent ( JList list , Object value , int index , boolean isSelected , boolean cellHasFocus ) {
JLabel renderer = ( JLabel ) super . getListCellRendererComponent ( list , value , index , isSelected , cellHasFocus ) ;
if ( index = = - 1 & & value = = null ) {
// 显示空白
if ( value instanceof TableDataWrapper ) {
labelVisible = true ;
TableDataWrapper tableDataWrapper = ( TableDataWrapper ) value ;
renderer . setIcon ( tableDataWrapper . getIcon ( ) ) ;
renderer . setText ( tableDataWrapper . getTableDataName ( ) ) ;
renderer . setToolTipText ( tableDataWrapper . getTableDataName ( ) ) ;
} else {
labelVisible = false ;
renderer . setIcon ( null ) ;
renderer . setText ( StringUtils . EMPTY ) ;
} else if ( value instanceof TableDataWrapper ) {
TableDataWrapper tabledatawrappe = ( TableDataWrapper ) value ;
renderer . setIcon ( tabledatawrappe . getIcon ( ) ) ;
renderer . setText ( tabledatawrappe . getTableDataName ( ) ) ;
renderer . setToolTipText ( tabledatawrappe . getTableDataName ( ) ) ;
}
return renderer ;
}
@Override
public Dimension getPreferredSize ( ) {
return labelVisible ? super . getPreferredSize ( ) : new Dimension ( super . getPreferredSize ( ) . width , 0 ) ;
}
} ) ;
refresh ( source ) ;
registerDSChangeListener ( ) ;
@ -75,6 +84,7 @@ public class TableDataComboBox extends UIComboBox implements Prepare4DataSourceC
setDsMap ( ) ;
DefaultComboBoxModel model = new DefaultComboBoxModel ( ) ;
this . setModel ( model ) ;
model . addElement ( UIConstants . PENDING ) ;
// 遍历添加所有数据项到模型
Iterator < Entry < String , TableDataWrapper > > entryIt = dsMap . entrySet ( ) . iterator ( ) ;
while ( entryIt . hasNext ( ) ) {
@ -83,8 +93,6 @@ public class TableDataComboBox extends UIComboBox implements Prepare4DataSourceC
model . addElement ( tableDataWrapper ) ;
}
}
// 设置默认选项为空白
this . setSelectedItem ( null ) ;
if ( dataWrapper ! = null ) {
if ( DesignTableDataManager . isDsNameChanged ( dataWrapper . getTableDataName ( ) ) ) {
this . setSelectedTableDataByName ( DesignTableDataManager . getChangedDsNameByOldDsName ( dataWrapper . getTableDataName ( ) ) ) ;