NC65 设置下拉列表框值,如人员任职信息的异动事件:
// 只有在入职登记时,才为异动事件下拉框过滤掉【离职】和【离职后变动】两个item
DefaultConstEnum[] enumItems = initTransevent();
BillItem item = getBillCardPanel().getHeadItem(PsnJobVO.getDefaultTableName() + "_" + PsnJobVO.TRNSEVENT);
UIComboBox combobox = (UIComboBox) item.getComponent();
combobox.removeAllItems();
combobox.addItems(enumItems);
/**
* 为异动事件下拉框过滤掉【离职】和【离职后变动】两个item
*
* @return
*/
private DefaultConstEnum[] initTransevent() {
List<DefaultConstEnum> items = new ArrayList<DefaultConstEnum>();
// 加载元数据中定义的“异动事件”枚举,初始化下拉列表框组件
try {
IComponent ibean = MDBaseQueryFacade.getInstance().getComponentByID("f57904bd-0037-4cea-842d-f33708084ab8");
List<IEnumType> enums = ibean.getEnums();
// 在返回的所有的枚举组件中查找指定名称的枚举
IConstEnum[] agreementTypeEnum = null;
for (IEnumType iet : enums) {
if ("trnsevent".equals(iet.getName())) {
agreementTypeEnum = iet.getConstEnums();
break;
}
}
// 根据枚举值,构造下拉列表框的值域对象
items = new ArrayList<DefaultConstEnum>();
for (IConstEnum pte : agreementTypeEnum) {
if ((Integer) pte.getValue() == 4/* 离职 */ || (Integer) pte.getValue() == 5/* 离职后变动 */) {
continue;
}
items.add(new DefaultConstEnum(pte.getValue(), pte.getName()));
}
} catch (Throwable t) {
Logger.error("[异动事件]枚举加载失败,可能是指定的元数据不存在,或注入的枚举名称错误。");
}
return items.toArray(new DefaultConstEnum[items.size()]);
}
private UIComboBox transMode;
private UIRefPane transType;
private TrnsTypeRefModel refModel;
private AbstractTrnPFAppModel model;
public AbstractTrnPFAppModel getModel() {
return model;
}
private TrnsTypeRefModel getRefModel() {
if (refModel == null) {
// 设置参照模型的“异动事件类型”。
// 当单据类型为调配时,异动事件类型为3;单据类型为离职时,异动事件类型为4;
int trnsEvent = TRNConst.TRNSEVENT_TRANS;
if (TRNConst.BUSITYPE_DIMISSION.equalsIgnoreCase(getModel().getBillType())) {
trnsEvent = TRNConst.TRNSEVENT_DIMIS;
}
refModel = new TrnsTypeRefModel(label.getText(), trnsEvent);
}
return refModel;
}
public UIComboBox getTransMode() {
if (transMode == null) {
transMode = new UIComboBox();
transMode.setPreferredSize(new Dimension(150, 18));
transMode.setShowMustInputHint(!getModel().isApproveSite());
try {
// modify at 20120628 改为读元数据枚举的方式
IComponent ibean = MDBaseQueryFacade.getInstance().getComponentByID("7b680d68-91e7-4306-a6af-565beccbca24");
List<IEnumType> enums = ibean.getEnums();
// 在返回的所有的枚举组件中查找指定名称的枚举
IConstEnum[] probationTypeEnum = null;
for (IEnumType iet : enums) {
if ("stapplymodeenum".equals(iet.getName())) {
probationTypeEnum = iet.getConstEnums();
break;
}
}
// 根据枚举值,构造下拉列表框的值域对象
ArrayList<DefaultConstEnum> items = new ArrayList<DefaultConstEnum>();
for (IConstEnum pte : probationTypeEnum) {
items.add(new DefaultConstEnum(pte.getValue(), pte.getName()));
}
transMode.addItems(HRConstEnum.getInstance().getWithEmptyFirst(items.toArray(new DefaultConstEnum[0])));
transMode.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
getModel().setStapply_mode((Integer) getTransMode().getSelectdItemValue());
}
});
transMode.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
}
@Override
public void focusGained(FocusEvent e) {
getTransMode().setShowWarning(false);
}
});
if (TRNConst.BUSITYPE_DIMISSION.equalsIgnoreCase(getModel().getBillType())) {
transMode.setVisible(false);
}
} catch (Exception ex) {
Logger.error(ex.getMessage(), ex);
Logger.error("[试用期类型]枚举加载失败,可能是指定的元数据不存在,或注入的枚举名称错误。");
}
}
return transMode;
}
package nc.ui.hi.ref;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.hr.utils.PubEnv;
import nc.hr.utils.ResHelper;
import nc.itf.hr.frame.IHRDataPermissionPubService;
import nc.ui.bd.ref.AbstractRefModel;
import nc.vo.bd.pub.IPubEnumConst;
import nc.vo.pub.BusinessException;
import nc.vo.util.VisibleUtil;
import org.apache.commons.lang.StringUtils;
public class TrnsTypeRefModel extends AbstractRefModel {
private static final String BEAN_ID = "d615df67-dc6c-4bb0-996b-f83342299fd3";
private String title;
private int trnsEvent = -1;
public TrnsTypeRefModel() {
super();
init();
}
public TrnsTypeRefModel(String _title, int trnsEve) {
super();
this.title = _title;
this.trnsEvent = trnsEve;
init();
}
@Override
protected String getEnvWherePart() {
IHRDataPermissionPubService hrDataPermissionPubService = NCLocator.getInstance().lookup(IHRDataPermissionPubService.class);
try {
String sqlWhere = hrDataPermissionPubService.getDataRefSQLWherePartByMDOperationCode(PubEnv.getPk_user(), getPk_group(), "60070_trnstype", "default", "hr_trnstype");
if (StringUtils.isBlank(sqlWhere)) {
return " (" + VisibleUtil.getRefVisibleCondition(getPk_group(), getPk_org(), BEAN_ID) + ")";
} else {
return " (" + VisibleUtil.getRefVisibleCondition(getPk_group(), getPk_org(), BEAN_ID) + ") and ( trnsevent in (1,2,4,5) or ( trnsevent = 3 and " + sqlWhere + "))";
}
} catch (BusinessException e) {
Logger.error(e.getMessage());
}
return super.getEnvWherePart();
}
private void init() {
this.setRefNodeName("异动类型"); /*-=notranslate=-*/
this.setTableName("hr_trnstype");
this.setFieldCode(new String[] { "trnstypecode", "trnstypename" });
this.setFieldName(new String[] { ResHelper.getString("6001ref", "06001ref0011")
/* @res "类型编码" */, ResHelper.getString("6001ref", "06001ref0012")
/* @res "类型名称" */ });
// , ResHelper.getString("6001ref", "06001ref0013") /* @res "类型主键" */}
this.setPkFieldCode("pk_trnstype");
this.setHiddenFieldCode(new String[] { "pk_trnstype" });
this.setDefaultFieldCount(2);
this.setRefTitle(title);
String sql = " 1=1 ";
if (!isDisabledDataShow()) {
sql += " and enablestate = " + IPubEnumConst.ENABLESTATE_ENABLE;
}
if (trnsEvent != -1) {
sql += " and trnsevent = " + trnsEvent;
}
setWherePart(sql);
}
@Override
public void setDisabledDataShow(boolean isDisabledDataShow) {
super.setDisabledDataShow(isDisabledDataShow);
init();
}
}