package com.vci.client.uif.engine.client.objopt;
|
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
import java.awt.FlowLayout;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.LinkedHashMap;
|
import java.util.Map;
|
|
import com.vci.client.bof.ClientBusinessObject;
|
import com.vci.client.bof.ClientLinkObject;
|
import com.vci.client.omd.provider.BtmProvider;
|
import com.vci.client.portal.utility.DataModelFactory;
|
import com.vci.client.portal.utility.PLDefination;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJDialog;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
|
import com.vci.client.uif.actions.client.AbstractBatchBusionessOperationAction;
|
import com.vci.client.uif.actions.client.BusinessOperationAction;
|
import com.vci.client.uif.engine.client.AbstractDataModel;
|
import com.vci.client.uif.engine.client.AbstractRegionPanel;
|
import com.vci.client.uif.engine.client.BasePanel;
|
import com.vci.client.uif.engine.client.IDataModel;
|
import com.vci.client.uif.engine.client.IRegionPanel;
|
import com.vci.client.uif.engine.client.tableArea.TablePanel;
|
import com.vci.client.uif.engine.client.tableArea.TablePanelDataModel;
|
import com.vci.client.uif.engine.common.IDataNode;
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.portal.data.PLPageDefination;
|
import com.vci.corba.portal.data.PLUILayout;
|
import com.vci.corba.portal.data.PLTabPage;
|
import com.vci.corba.portal.data.PortalVI;
|
import com.vci.mw.ClientContextVariable;
|
|
/**
|
* 对象 add 窗口
|
* @author VCI-STGK002
|
*
|
*/
|
public class ObjectDBClickAddEditDialog extends VCIJDialog {
|
|
public enum OperateType{
|
ADD,
|
EDIT,
|
BROWSER,
|
SELECT
|
}
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 6400165410571370254L;
|
|
private String btmType = "";
|
private String context = "";
|
private PLDefination defination = null;
|
private PortalVI portalVI = null;
|
private DataModelFactory factory = new DataModelFactory();;
|
private Map<String, String> paramsMap = new HashMap<String, String>();
|
private OperateType operateType = OperateType.ADD;
|
private VCIJTablePanel<IDataNode> dataTablePanel = null;
|
/**
|
* 如果OperateType是SELECT时记录用户选择的数据
|
* 其余时selectedDatas为空
|
*/
|
private Object[] selectedDatas = null;
|
|
/**
|
* 当前窗口的表单类型
|
* 0:业务类型,1:链接类型
|
* 对于不同类型的表单,窗口中属性的命名规则不同
|
*/
|
private int typeFlag = 0;
|
/**
|
* 在创建link时:sourceDataNode
|
* 如果传入的是BO对象,则作为创建link的From端,如果传入的是LO对象,
|
* 则使用LO的t_oid所对应的BO对象作为Form
|
* 在修改link时:sourceDataNode
|
* 为用户选择的数据,数据的类型有可能是LO,也有可能是BO
|
*/
|
private IDataNode sourceDataNode = null;
|
|
private IDataNode inputDataNode = null;
|
|
|
/**
|
* 如果是基于表格中选择的数据弹出对话框
|
* selectObjects用于存储选中的数据
|
*/
|
private Object[] selectObjects = null;
|
|
/**
|
* 判断是正向还是反响向
|
*/
|
private boolean direction = true;
|
|
private BusinessOperationAction boa = null;
|
|
|
private VCIJButton btnPrev = VCISwingUtil.createVCIJButton("viewPrevData", "上一条", "上一条", "pagination_previous.png", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
changeViewDataPrev();
|
}
|
});
|
private VCIJButton btnNext = VCISwingUtil.createVCIJButton("viewNextData", "下一条", "下一条", "pagination_next.png", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
changeViewDataNext();
|
}
|
});
|
|
|
private boolean thisBOAOwnedIsTablePanel(){
|
if(this.boa.getRegionPanel() instanceof TablePanel){
|
return true;
|
}
|
return false;
|
}
|
|
private void resetRowIndex(){
|
//TablePanel tablePanel = (TablePanel)this.boa.getRegionPanel();
|
if(rowIndex == -1){
|
rowIndex = dataTablePanel.getSelectedRowIndexs()[0];
|
}
|
}
|
private int rowIndex = -1;
|
private void changeViewDataPrev(){
|
rowIndex -= 1;
|
if(rowIndex < 0){
|
rowIndex = 0;
|
}
|
changeViewData(rowIndex);
|
}
|
private void changeViewDataNext(){
|
rowIndex += 1;
|
int maxIndex = dataTablePanel.getTable().getRowCount();
|
if(rowIndex >= maxIndex){
|
rowIndex = maxIndex - 1;
|
}
|
changeViewData(rowIndex);
|
}
|
private void changeViewData(int rowIndex){
|
IDataNode dataNode = dataTablePanel.getSpecialObjectByRowIndex(rowIndex);
|
if(dataNode.getMaterObject() instanceof ClientBusinessObject){
|
this.oaep.setValueToUIControl(dataNode.getMaterObject());
|
}else if(dataNode.getMaterObject() instanceof ClientLinkObject){
|
this.oaep.setValueToUIControl(dataNode.getMaterObject()); //add by caill 增加当数据时lo类型时的判断
|
}
|
}
|
|
/**
|
* 创建和编辑窗口不对控件处理,
|
* 如果是浏览窗口,所有控件禁用
|
* 如果是选择窗口,所有to端对象的属性控件都禁用
|
* @param type
|
* @param context
|
* @param defination
|
* @param paramsMap
|
* @param operateType
|
* @param actionExecute
|
* @param dataTablePanel
|
*/
|
public ObjectDBClickAddEditDialog(String type, String context,
|
PLDefination defination,PortalVI portalVI, Map<String, String> paramsMap,
|
OperateType operateType, ObjectAddEditDialogExecute actionExecute,
|
BusinessOperationAction boa, VCIJTablePanel<IDataNode> dataTablePanel) {
|
|
super(ClientContextVariable.getFrame(), true);
|
this.btmType = type;
|
this.context = context;
|
this.defination = defination;
|
this.portalVI = portalVI;
|
this.paramsMap = paramsMap;
|
this.operateType = operateType;
|
this.dataTablePanel = dataTablePanel;
|
//this.actionExecute = actionExecute;
|
this.boa = boa;
|
}
|
|
public void init(){
|
//***************
|
//setTitle(this.getBoa().getButton().plDesc);
|
setLayout(new BorderLayout());
|
// add(new VCIJScrollPane(getCenterPanel()), BorderLayout.CENTER);
|
add(getCenterPanel(), BorderLayout.CENTER);
|
add(getSouthButtonPanel(), BorderLayout.SOUTH);
|
/*String widthStr = paramsMap.get("width");
|
String heightStr = paramsMap.get("height");
|
if(widthStr != null && widthStr.length() > 0 && widthStr.matches("[0-9]*")
|
&& heightStr != null && heightStr.length() > 0 && heightStr.matches("[0-9]*")) {
|
int width = Integer.parseInt(widthStr);
|
int height = Integer.parseInt(heightStr);
|
this.setSizeAndLocation(width, height);
|
}*/
|
}
|
|
private AbstractBatchBusionessOperationAction getSourceBtm(){
|
if (this.getBoa() != null && this.getBoa() instanceof AbstractBatchBusionessOperationAction) {
|
return (AbstractBatchBusionessOperationAction)this.getBoa();
|
}else {
|
return null;
|
}
|
}
|
|
private ObjectDBClickAddEditPanel oaep = null;
|
private ObjectDBClickAddEditPanel getCenterPanel(){
|
oaep = new ObjectDBClickAddEditPanel(btmType, context, defination,portalVI,
|
factory, paramsMap, operateType, this.getBoa().getRegionPanel());
|
oaep.setTypeFlag(typeFlag);
|
oaep.setDirection(direction);
|
oaep.init();
|
// 仅在添加模式下处理默认值
|
//***************
|
/*if(operateType == OperateType.ADD || operateType == OperateType.SELECT || operateType == OperateType.EDIT){
|
String needselect = paramsMap.get("needselect");
|
Object[] objs = null;
|
if(needselect != null && needselect.equalsIgnoreCase("true")){
|
objs = this.boa.getDataModel().getSelectObjects();
|
} else {
|
objs = new Object[]{this.boa.getRegionPanel().getSourceData()};
|
}
|
if(objs != null && objs.length > 0 && objs[0] instanceof IDataNode){
|
//oaep.setUIControlDefaultValue((IDataNode)objs[0]);
|
oaep.setUIFormFieldDefaultValue(this.getSourceBtm(),(IDataNode)objs[0]);
|
} else {
|
//oaep.setUIGloableDefaultValue();
|
oaep.setUIFormFieldDefaultValue(this.getSourceBtm(),null);
|
}
|
}*/
|
return oaep;
|
}
|
private VCIJPanel getSouthButtonPanel(){
|
VCIJPanel pal = new VCIJPanel();
|
// //修改当为浏览时显示关闭按钮
|
// if(this.operateType.equals(OperateType.BROWSER)){
|
// pal.add(btnClose);
|
// } else {
|
// if(this.operateType.equals(OperateType.SELECT)){
|
// pal.add(btnSelect);
|
// }
|
// pal.add(btnSave);
|
// pal.add(btnCancel);
|
// }
|
//if(thisBOAOwnedIsTablePanel() && this.operateType == OperateType.BROWSER){
|
resetRowIndex();
|
pal.add(btnPrev);
|
pal.add(btnNext);
|
//}
|
addFormButtonsToUI(pal);
|
pal.setLayout(new FlowLayout());
|
return pal;
|
}
|
|
//private IDataModel dataModel = null;
|
private IRegionPanel regionPanel = null;
|
private void addFormButtonsToUI(VCIJPanel pal){
|
String tabId = "";
|
//dataModel = new ObjectAddEditDataModel();
|
regionPanel = new ObjectAddEditRegionPanel();
|
//regionPanel.setDataModel(dataModel);
|
try {
|
PLUILayout plDef = getContext(getBtmType(), getContext());
|
|
//this.setTitle("");
|
|
BasePanel basePal = new BasePanel();
|
// get form definations
|
Map<PLTabPage, PLPageDefination> pageDefinition = new HashMap<PLTabPage, PLPageDefination>();
|
Map<PLTabPage, PLDefination> tabPageMap = getTabPage(plDef.plOId, (short)2, pageDefinition);
|
Iterator<PLTabPage> it = tabPageMap.keySet().iterator();
|
while(it.hasNext()){
|
PLTabPage tabPage = it.next();
|
PLDefination btnOwnDefinatio = tabPageMap.get(tabPage);
|
tabId = tabPage.plOId;
|
regionPanel.setTab(tabPage);
|
regionPanel.setTabId(tabId);
|
// 设置Form中的Buttong与Defination之间的关联关系
|
regionPanel.setDefination(tabPageMap.get(tabPage));
|
regionPanel.setPageDefinition(pageDefinition.get(tabPage));
|
// TODO
|
// 将Button上配置的type\context对应的一个唯一(约定、必须)设置到Action
|
this.oaep.setDefination(btnOwnDefinatio);
|
// 添加Button到Panel
|
/*VCIJButton[] btns = basePal.getButtonsByTabPageId(tabId, regionPanel);
|
for(VCIJButton btn : btns){
|
pal.add(btn);
|
for(ActionListener al : btn.getActionListeners()){
|
// 设置Action所在的Dialog
|
if(al instanceof ButtonActionListener){
|
ButtonActionListener bal = (ButtonActionListener)al;
|
bal.setOwnerDialog(this);
|
}
|
}
|
}*/
|
}
|
} catch (Exception e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
} catch (Throwable e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 获取当前context的详细信息
|
* @return
|
* @throws Throwable
|
* @throws Exception
|
*/
|
private PLUILayout getContext(String type, String context) throws Exception, Throwable {
|
DataModelFactory factory = new DataModelFactory();
|
PLUILayout contextDef = factory.getContextDefination(
|
type, context);
|
if (contextDef == null || contextDef.plOId.equals("")) {
|
BtmItem item = BtmProvider.getInstance().getBtmItemByName(type);
|
if (item.fName == null || item.fName.equals("")) {
|
return null;
|
}
|
return getContext(item.fName, item.fName);
|
}
|
return contextDef;
|
}
|
|
/**
|
* 获得当前上下文的所有tab page
|
* @return
|
* @throws Throwable
|
*/
|
private Map<PLTabPage, PLDefination> getTabPage(String contextOid, short areaType,
|
Map<PLTabPage, PLPageDefination> pageDefinition) throws Throwable {
|
PLTabPage[] tabs = UITools.getService().getTabPagesByContextIdAndType(contextOid, areaType);
|
Map<PLTabPage, PLDefination> defMap = new LinkedHashMap<PLTabPage, PLDefination>();
|
for (int i = 0; i < tabs.length; i++) {
|
PLPageDefination[] definations = UITools.getService().getPLPageDefinationsByPageContextOId(tabs[i].plOId);
|
if (definations != null && definations.length < 1) {
|
continue;
|
}
|
pageDefinition.put(tabs[i], definations[0]);
|
PLDefination defination = UITools.getPLDefination(definations[0].plDefination);
|
defMap.put(tabs[i], defination);
|
}
|
return defMap;
|
}
|
|
/**
|
* 添加到本窗口中的ActionButton所在的RegionPanel
|
* @author xiongchao
|
*
|
*/
|
private class ObjectAddEditRegionPanel extends AbstractRegionPanel{
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 3800158389231268060L;
|
|
public ObjectAddEditRegionPanel(){
|
IDataModel dataModel = new ObjectAddEditDataModel();
|
this.setDataModel(dataModel);
|
}
|
|
@Override
|
public Component init() {
|
setComponentPanel(this);
|
setBuilt(true);
|
return this;
|
}
|
|
@Override
|
public void refreshUI() {
|
// TODO Auto-generated method stub
|
|
}
|
}
|
|
/**
|
* 直接调用dataModel中的getRootObject()方法获得数据
|
* @param isCheck 判断获得form中的数据时是否需要进行数据校验
|
* @return
|
*/
|
public Object getRootObject(boolean isCheck){
|
return ((ObjectAddEditDataModel)this.regionPanel.getDataModel()).getRootObject(isCheck);
|
}
|
|
/**
|
* 添加到本窗口中的ActionButton所在的DataModel
|
* @author xiongchao
|
*
|
*/
|
private class ObjectAddEditDataModel extends AbstractDataModel {
|
@Override
|
public int[] getSelectObjectRowIndexs() {
|
return new int[]{0};
|
}
|
|
@Override
|
public Object[] getSelectObjects() {
|
return new Object[]{oaep.getDataNodeObject(true)};
|
}
|
|
@Override
|
public void refresh(IDataModel fromDataModel) {
|
// 添加到Dialog中的Button的刷新,是向上刷新
|
// 即 调用 调用显示此Dialog的Action的dataModel.refresh(fromDataModel)
|
if(fromDataModel == null && getBoa() != null){
|
getBoa().getDataModel().refresh(fromDataModel);
|
}
|
|
// update by xchao 2014.03.26 begin
|
// 修复来自Dialog底部的button执行完成后
|
// 刷新 调用弹出此窗口的button所在的table的数据时,刷新失败的BUG
|
if(fromDataModel instanceof ObjectAddEditDataModel){
|
if(getBoa().getDataModel() instanceof TablePanelDataModel){
|
((TablePanelDataModel)getBoa().getDataModel()).setClickObject(
|
getBoa().getRegionPanel().getSourceData());
|
}
|
}
|
// update by xchao 2014.03.26 end
|
}
|
|
@Override
|
public Object getRootObject() {
|
return getRootObject(true);
|
}
|
|
/**
|
* 判断是否需要进行校验
|
* @param ischeck
|
* @return
|
*/
|
public Object getRootObject(boolean isCheck){
|
return oaep.getDataNodeObject(isCheck);
|
}
|
|
/**
|
* 将属性值发生更改后业务对象或链接对象刷新到UIPanel
|
* @param clientObject
|
*/
|
@Override
|
public void refreshCache(Object clientObject){
|
// default is nothing
|
getOaep().setValueToUIControlByAttrValChange(clientObject);
|
}
|
}
|
|
|
public VCIJTablePanel<IDataNode> getDataTablePanel() {
|
return dataTablePanel;
|
}
|
|
public void setDataTablePanel(VCIJTablePanel<IDataNode> dataTablePanel) {
|
this.dataTablePanel = dataTablePanel;
|
}
|
|
public PortalVI getPortalVI() {
|
return portalVI;
|
}
|
|
public void setPortalVI(PortalVI portalVI) {
|
this.portalVI = portalVI;
|
}
|
|
public String getBtmType() {
|
return btmType;
|
}
|
|
public void setBtmType(String type) {
|
this.btmType = type;
|
}
|
|
public String getContext() {
|
return context;
|
}
|
|
public void setContext(String context) {
|
this.context = context;
|
}
|
|
public PLDefination getDefination() {
|
return defination;
|
}
|
|
public void setDefination(PLDefination defination) {
|
this.defination = defination;
|
}
|
|
public DataModelFactory getFactory() {
|
return factory;
|
}
|
|
public void setFactory(DataModelFactory factory) {
|
this.factory = factory;
|
}
|
|
public Map<String, String> getParamsMap() {
|
return paramsMap;
|
}
|
|
public void setParamsMap(Map<String, String> paramsMap) {
|
this.paramsMap = paramsMap;
|
}
|
|
public HashMap<String, Component> getCtrlComptMap() {
|
return oaep.getCtrlComptMap();
|
}
|
|
public void setCtrlComptMap(HashMap<String, Component> ctrlComptMap) {
|
this.oaep.setCtrlComptMap(ctrlComptMap);
|
}
|
|
public Map<String, String> getValueMapNew() {
|
return oaep.getValueMapNew();
|
}
|
|
public void setValueMapNew(Map<String, String> valueMapNew) {
|
this.oaep.setValueMapNew(valueMapNew);
|
}
|
|
public Map<String, String> getValueMapOriginal() {
|
return oaep.getValueMapOriginal();
|
}
|
|
public void setValueMapOriginal(HashMap<String, String> valueMapOriginal) {
|
this.oaep.setValueMapOriginal(valueMapOriginal);
|
}
|
|
public OperateType getOperateType() {
|
return oaep.getOperateType();
|
}
|
|
// public ObjectAddEditDialogExecute getActionExecute() {
|
// return actionExecute;
|
// }
|
//
|
// public void setActionExecute(ObjectAddEditDialogExecute actionExecute) {
|
// this.actionExecute = actionExecute;
|
// }
|
|
public ObjectDBClickAddEditPanel getOaep() {
|
return oaep;
|
}
|
|
public void setOaep(ObjectDBClickAddEditPanel oaep) {
|
this.oaep = oaep;
|
}
|
|
public Object[] getSelectedDatas() {
|
return selectedDatas;
|
}
|
|
public void setSelectedDatas(Object[] selectedDatas) {
|
this.selectedDatas = selectedDatas;
|
this.oaep.setSelectedDatas(selectedDatas);
|
}
|
|
public int getTypeFlag() {
|
return typeFlag;
|
}
|
|
public void setTypeFlag(int typeFlag) {
|
this.typeFlag = typeFlag;
|
}
|
|
public BusinessOperationAction getBoa() {
|
return boa;
|
}
|
|
public void setBoa(BusinessOperationAction boa) {
|
this.boa = boa;
|
}
|
|
public IDataNode getSourceDataNode() {
|
return sourceDataNode;
|
}
|
|
public void setSourceDataNode(IDataNode sourceDataNode) {
|
this.sourceDataNode = sourceDataNode;
|
}
|
|
public IDataNode getInputDataNode() {
|
return inputDataNode;
|
}
|
|
public void setInputDataNode(IDataNode inputDataNode) {
|
this.inputDataNode = inputDataNode;
|
}
|
|
public boolean isDirection() {
|
return direction;
|
}
|
|
public void setDirection(boolean direction) {
|
this.direction = direction;
|
}
|
|
public Object[] getSelectObjects() {
|
return selectObjects;
|
}
|
|
public void setSelectObjects(Object[] selectObjects) {
|
this.selectObjects = selectObjects;
|
}
|
|
public void setSize(int width, int height){
|
super.setSize(width, height);
|
//如果paramsMap中传递长宽参数了,则自定义dialog的大小,并位置是居中的,lmh20150925
|
/*String widthStr = paramsMap.get("width");
|
String heightStr = paramsMap.get("height");
|
if(widthStr != null && widthStr.length() > 0 && widthStr.matches("[0-9]*")
|
&& heightStr != null && heightStr.length() > 0 && heightStr.matches("[0-9]*")) {
|
width = Integer.parseInt(widthStr);
|
height = Integer.parseInt(heightStr);
|
this.setSizeAndLocation(width, height);
|
} else {
|
super.setSize(width, height);
|
}*/
|
}
|
}
|