📄 mapcombobindedtablecolumn.java
字号:
/**
*
*/
package net.sf.component.table;
import java.util.Map;
/**
* $Id: MapComboBindedTableColumn.java 844 2005-09-12 03:18:14Z yflei $
* Created Date: 2005-7-19
* @author SimonLei
*/
public class MapComboBindedTableColumn extends ComboBindedTableColumn {
private Map map;
/**
* @param name
*/
public MapComboBindedTableColumn(String name) {
super(name);
}
@Override
public Object getValue(Object obj) {
if ( obj == null) return -1;
Object keyValue = getKeyByValue(obj);
int index = 0;
for (Object item: items) {
if ( item.equals( keyValue)) return new Integer( index);
index++;
}
return -1;
}
private Object getKeyByValue(Object obj) {
for (Object key : map.keySet()) {
if ( obj.equals( map.get(key))) {
return key;
}
}
return -1;
}
@Override
public Object getModifiedValue(Object obj) {
Integer intValue = (Integer)obj;
if ( intValue == -1) return null;
return map.get( items[intValue]);
}
public String[] getItemsFromComboItems() {
return items;
}
private String[] items;
public void setMap(Map map) {
this.map = map;
this.items = getItemsFromMap();
}
private String[] getItemsFromMap() {
String[] strs = new String[ map.size()];
map.keySet().toArray( strs);
return strs;
}
public String getLabelText( Object obj) {
if ( obj == null) return "";
final Object keyByValue = getKeyByValue( obj);
return keyByValue == null ? "" : keyByValue.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -