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