package com.vci.client.uif.engine.client.custom;
|
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
import java.awt.Image;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseListener;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.swing.text.JTextComponent;
|
|
import com.vci.client.bof.ClientBusinessObject;
|
import com.vci.client.bof.ClientLinkObject;
|
import com.vci.client.common.ConfigUtils;
|
import com.vci.client.common.PositionMessager;
|
import com.vci.client.portal.custom.ICustomDefine;
|
import com.vci.client.portal.utility.PRMItem;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJComboBox;
|
import com.vci.client.ui.swing.components.VCIJDialog;
|
import com.vci.client.ui.swing.components.VCIJOptionPane;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.ui.swing.components.VCIJTextField;
|
import com.vci.client.ui.swing.components.VCIJDialog.DialogResult;
|
import com.vci.client.uif.actions.client.UIFUtils;
|
import com.vci.client.uif.engine.client.UIHelper;
|
import com.vci.client.uif.engine.client.UILayoutPanel;
|
import com.vci.client.uif.engine.client.controls.AbstractCustomControl;
|
import com.vci.client.uif.engine.client.objopt.ObjectAddEditPanel;
|
import com.vci.client.uif.engine.client.tableArea.TablePanel;
|
import com.vci.client.uif.engine.client.tree.TreePanel;
|
import com.vci.client.uif.engine.common.CBOHelper;
|
import com.vci.client.uif.engine.common.IDataNode;
|
import com.vci.corba.common.VCIError;
|
import com.vci.mw.ClientContextVariable;
|
|
/**
|
* 参数值选择自定义控件
|
* @Title :ReferenceValueChooseCtl.java
|
* @Description :
|
* @Copyright :宏博远达科技有限公司
|
* @Author :平台与规划部/ZhongGY/E-mail:zhonggy@vci-tech.com
|
* @Date :2015-5-26
|
* @Version :1
|
* @Other :产生注释:Alt+Shift+J
|
*/
|
public class ReferenceValueChooseCtl extends AbstractCustomControl implements
|
ICustomDefine {
|
|
private static final long serialVersionUID = 1L;
|
//private PRMItem item;
|
private String value = "";
|
private VCIJTextField text = new VCIJTextField("");
|
private final Image img = VCISwingUtil.createImageIcon("search.png").getImage();
|
private VCIJButton button=VCISwingUtil.createVCIJButton("","", "选择参照对象", "search.png");//search.gif
|
/*@SuppressWarnings("unused")
|
private VCIJButton button = new VCIJButton("参照对象");*/
|
/*@SuppressWarnings("serial")
|
private final VCIJTextField txt = new VCIJTextField("") {
|
@Override
|
public void paintComponent(Graphics g) {
|
super.paintComponent(g);
|
Graphics2D g2 = (Graphics2D) g;
|
if (img != null) {
|
g2.drawImage(img, getWidth() - img.getWidth(null), getHeight()
|
- img.getHeight(null), img.getWidth(null),
|
img.getHeight(null), null);
|
}
|
ReferenceValueChooseCtl.this.drawRequiredFlag(g);
|
}
|
|
@Override
|
public void mouseClicked(MouseEvent e) {
|
super.mouseClicked(e);
|
if (!isEnabled() || !editable)
|
return;
|
if (isClickImage(e)) {
|
try {
|
showRefObjChooseDialog();
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
|
private boolean isClickImage(MouseEvent e) {
|
boolean res = false;
|
int imgWidth = img.getWidth(null);
|
int imgHeight = img.getHeight(null);
|
int width = getWidth();
|
int height = getHeight();
|
int pointX = e.getX();
|
int pointY = e.getY();
|
if (width - imgWidth < pointX && pointX < width
|
&& height - imgHeight < pointY && pointY < height) {
|
res = true;
|
}
|
// ignore cals
|
res = true;
|
return res;
|
}
|
};*/
|
//private ICustomAttributeInteceptor inteceptor = null;
|
//private VCIJFileChooser vciJFileChooser = null;
|
//private String filePath = "";
|
// private String localfilePath = "";
|
//private boolean fileChanged = false;
|
|
public ReferenceValueChooseCtl() {
|
}
|
|
//private boolean editable = false;
|
public ReferenceValueChooseCtl(PRMItem item) {
|
super(item);
|
/*init();
|
editable = item.getItemIsEditable().equals("1") ? false : true;
|
setEditable(editable);
|
if (editable) {
|
txt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
}*/
|
editable = item.getItemIsEditable().equals("1") ? false : true;
|
init();
|
setEditable(editable);
|
if (editable) {
|
//text.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
button.setEnabled(true);
|
}else {
|
text.setEditable(false);
|
button.setEnabled(false);
|
}
|
}
|
|
/* private void init() {
|
setLayout(new GridBagLayout());
|
add(txt,
|
getGBC(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHEAST,
|
GridBagConstraints.BOTH, 2));
|
txt.setEditable(false);
|
}*/
|
protected void init() {
|
setLayout(new BorderLayout());
|
add(this.text, "Center");
|
add(button, "East");
|
if (editable) {
|
button.addMouseListener(new MouseListener() {
|
@Override
|
public void mouseReleased(MouseEvent paramMouseEvent) {
|
}
|
@Override
|
public void mousePressed(MouseEvent paramMouseEvent) {
|
}
|
@Override
|
public void mouseExited(MouseEvent paramMouseEvent) {
|
}
|
@Override
|
public void mouseEntered(MouseEvent paramMouseEvent) {
|
}
|
@Override
|
public void mouseClicked(MouseEvent paramMouseEvent) {
|
try {
|
showRefObjChooseDialog();
|
} catch (Exception e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
});
|
}
|
}
|
|
@Override
|
public String getValue() {
|
return this.value;
|
}
|
|
@Override
|
public void setValue(String value) {
|
if (value == null || "".equals(value)){
|
this.text.setText("");
|
}else {
|
this.text.setText(value);
|
}
|
this.value = this.text.getText();
|
}
|
|
|
protected ICustomAttributeInteceptor getCustomInteceptorInstance() {
|
ICustomAttributeInteceptor res = null;
|
String className = getPRMItem().getItemValue();
|
try {
|
if (className == null || "".equals(className))
|
return res;
|
Object obj = Class.forName(className).getConstructor()
|
.newInstance();
|
if (obj == null)
|
return res;
|
if (obj instanceof ICustomAttributeInteceptor) {
|
res = (ICustomAttributeInteceptor) obj;
|
res.setCustomControl(this);
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
}
|
return res;
|
}
|
|
@Override
|
public void getCustomValue(String columnName,
|
Map<String, PRMItem> customItemMap, List<Map<String, String>> datas)
|
throws VCIError {
|
}
|
|
private RefObjChooseDailog dialog = null;
|
|
private Map<String, String> customExpDefMap = new HashMap<String, String>();
|
private String validDefEstimateContent = null; // 如果为空表示定义有效,否则提示无效定义提示
|
|
public void showRefObjChooseDialog() throws Exception {
|
if (validDefEstimateContent != null && !validDefEstimateContent.equals("")) {
|
VCIJOptionPane.showError(dialog, validDefEstimateContent);
|
return;
|
}
|
if (validDefEstimateContent == null) {
|
validDefEstimateContent = "";
|
//先判断当前自定义控件扩展定义的正确性,否则提示错误
|
PRMItem item = getPRMItem();
|
// 参照值自定义控件的"扩展定义"格式:type=业务类型名,context=UI上下文名称,fieldName0=refOBJAttr1,fieldName1=refOBJAttr1,fieldName2=refOBJAttr2,fieldName3=refOBJAttr3,...
|
String customExpDef = item.getItemStyle(); //"附加属性"定义
|
if (customExpDef == null || customExpDef.equals("")) {
|
validDefEstimateContent = "请在当前表单字段定义的\"附加属性\"中进行该自定义控件扩展定义;\r\n扩展定义格式:\"type=参照的业务类型名;context=UI上下文名称;当前对象字段0=参照对象属性0;当前对象字段1=参照对象属性1;...\"";
|
}else {
|
//customExpDef = customExpDef.trim().toLowerCase();
|
if(customExpDef.indexOf("type")<0 || customExpDef.indexOf("context")<0 || customExpDef.indexOf("=")<0 || customExpDef.indexOf(";")<0){
|
validDefEstimateContent = "当前表单字段在\"附加属性\"中进行该自定义控件的扩展定义有误;\r\n扩展定义格式:\"type=参照的业务类型名;context=UI上下文名称;当前对象字段0=参照对象属性0;当前对象字段1=参照对象属性1;...\"";
|
}else {
|
String[] strings = customExpDef.split(";");
|
for (int i = 0; i < strings.length; i++) {
|
String[] defItem = strings[i].trim().split("=");
|
if (defItem.length == 2) {
|
if (!customExpDefMap.containsKey(defItem[0].trim())) {
|
customExpDefMap.put(defItem[0].trim(), defItem[1].trim());
|
}
|
}
|
}
|
if (!customExpDefMap.containsKey("type") || !customExpDefMap.containsKey("context") || customExpDefMap.size() < 3) {
|
validDefEstimateContent = "当前表单字段在\"附加属性\"中进行该自定义控件的扩展定义有误;\r\n扩展定义格式:\"type=参照的业务类型名;context=UI上下文名称;当前对象字段0=参照对象属性0;当前对象字段1=参照对象属性1;...\"";
|
}
|
}
|
}
|
if (!validDefEstimateContent.equals("")) {
|
VCIJOptionPane.showError(dialog, validDefEstimateContent);
|
return;
|
}
|
}
|
VCISwingUtil.invokeLater(new Runnable() {
|
@Override
|
public void run() {
|
dialog = new RefObjChooseDailog();
|
dialog.init();
|
dialog.setSize(UIHelper.DIALOG_DEFAULT_WIDTH,
|
UIHelper.DIALOG_DEFAULT_HEIGHT);
|
dialog.setLocationRelativeTo(ClientContextVariable.getFrame());
|
dialog.setVisible(true);
|
}
|
}, 0);
|
}
|
|
public VCIJTextField getText() {
|
return text;
|
}
|
|
/**
|
* 在窗口右下角显示提示信息 *内部类,不可修改*
|
* @param message
|
*/
|
@SuppressWarnings("unused")
|
private static void showMessage(String message) {
|
// 获得弹出窗口显示时间
|
int displayTime = 3000;
|
String displayTimeStr = ConfigUtils
|
.getConfigValue("PromptMessage.DisplayTime");
|
if (displayTimeStr == null || displayTimeStr.trim().equals("")) {
|
displayTimeStr = "3000";
|
try {
|
displayTime = Integer.parseInt(displayTimeStr);
|
} catch (Exception e) {
|
}
|
}
|
PositionMessager msger = new PositionMessager();
|
// 消息显示停留时间,单位为毫秒
|
msger.setShowTimes(displayTime);
|
msger.show(message);
|
}
|
|
@SuppressWarnings("serial")
|
private class RefObjChooseDailog extends VCIJDialog {
|
public RefObjChooseDailog() {
|
super(ClientContextVariable.getFrame(), true);
|
}
|
public void init() {
|
setTitle("参照对象选择");
|
setIconImage(img);
|
setLayout(new BorderLayout());
|
add(getCenterDataPanel(), BorderLayout.CENTER);
|
add(getSouthButtonPanel(), BorderLayout.SOUTH);
|
}
|
}
|
|
private UILayoutPanel uipl = null;
|
|
private VCIJPanel getCenterDataPanel() {
|
VCIJPanel pal = new VCIJPanel(new BorderLayout());
|
/*PRMItem item = getPRMItem();*/
|
/*String type = item.getItemListTable(); //一级参照定义
|
String context = item.getItemStyle(); //"附加属性"定义
|
String refValueDef = item.getItemListVal(); //"参照值"定义
|
//统一修改为"附加属性"定义,格式:
|
type = "part";
|
context = "selectProducts";*/
|
HashMap<String, String> map = new HashMap<String, String>();
|
map.put(UIHelper.TYPE, customExpDefMap.get("type"));
|
map.put(UIHelper.CONTEXT, customExpDefMap.get("context"));
|
map.put(UIHelper.OID, map.get(UIHelper.OID));
|
// 加入来源参数
|
map.put("fromType", customExpDefMap.get("type"));
|
map.put("fromContext", customExpDefMap.get("context"));
|
map.put("fromObjectId", map.get(UIHelper.OID));
|
this.uipl = getUILayoutPanel(map);
|
pal.add(uipl, BorderLayout.CENTER);
|
return pal;
|
}
|
|
private UILayoutPanel getUILayoutPanel(HashMap<String, String> map) {
|
UILayoutPanel uipl = new UILayoutPanel(map) {
|
private static final long serialVersionUID = 7167045011920499526L;
|
|
@Override
|
public String getValue(String key) {
|
String value = super.getValue(key);
|
ObjectAddEditPanel compt = getOwnedObjectAddEditPanel();
|
if (compt != null && compt.getRegionPanel() != null
|
&& compt.getRegionPanel().getBaseLayoutPanel() != null) {
|
value = compt.getRegionPanel().getBaseLayoutPanel()
|
.getValue(key);
|
}
|
return value;
|
}
|
};
|
uipl.setDataValueMap(map);
|
uipl.prep();
|
uipl.initMainPanel();
|
return uipl;
|
}
|
|
private ObjectAddEditPanel getOwnedObjectAddEditPanel() {
|
ObjectAddEditPanel res = null;
|
Component compt = this.getParentComponent();
|
while (compt != null) {
|
if (compt instanceof ObjectAddEditPanel) {
|
res = (ObjectAddEditPanel) compt;
|
break;
|
}
|
compt = compt.getParent();
|
}
|
return res;
|
}
|
|
private VCIJPanel getSouthButtonPanel() {
|
VCIJPanel pal = new VCIJPanel();
|
VCIJButton btnOk = VCISwingUtil.createVCIJButton("ok", "确定", "确定",
|
"accept.png");
|
VCIJButton btnCancel = VCISwingUtil.createVCIJButton("cancel", "取消",
|
"取消", "cancel.png");
|
btnOk.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
ok();
|
}
|
});
|
btnCancel.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
cancel();
|
}
|
});
|
pal.add(btnOk);
|
pal.add(btnCancel);
|
return pal;
|
}
|
@SuppressWarnings("deprecation")
|
private void ok() {
|
Component compt = uipl.getMainDataPanel(); // 在定义参照上下文时三个UI区域原则上都可以定义,且获取优先级为“右上-->右下-->导航”
|
// //modify by ZhongGY
|
// 2015-05-26
|
if (compt == null) {
|
compt = uipl.getTabPanel();
|
if (compt == null) {
|
compt = uipl.getNavigatorPanel();
|
}
|
}
|
Object[] objs = null;
|
if (compt instanceof TablePanel) {
|
TablePanel tablePanel = (TablePanel) compt;
|
objs = tablePanel.getTablePanelModel().getSelectObjects();
|
} else if (compt instanceof TreePanel) {
|
TreePanel treePanel = (TreePanel) compt;
|
objs = treePanel.getDataModel().getSelectObjects();
|
// 判断选择的是否为根节点,如果跟为String类型,表示选择的是分类的根
|
// 因为下面做了非空的校验
|
if (objs != null && objs.length > 0) {
|
if (objs[0] instanceof IDataNode) {
|
if (((IDataNode) objs[0]).getMaterObject() instanceof String) {
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"不能选择根节点");
|
return;
|
}
|
}
|
}
|
}
|
Map<String, String> valueMap = new HashMap<String, String>();
|
if (objs == null || objs.length <= 0) {
|
VCIJOptionPane.showError(dialog, "请先选择数据!");
|
return;
|
}
|
if (objs.length > 1) {
|
VCIJOptionPane.showError(dialog, "一次只能选择一条数据!");
|
return;
|
}
|
if (objs[0] instanceof IDataNode) {
|
IDataNode dataNode = (IDataNode) objs[0];
|
valueMap = dataNode.getValueMap();
|
if (valueMap == null || valueMap.size() == 0) {
|
Object obj = dataNode.getMaterObject();
|
if (obj instanceof ClientLinkObject) {
|
valueMap = CBOHelper.getLOValueMap(((ClientLinkObject) obj)
|
.getLinkObject());
|
} else if (obj instanceof ClientBusinessObject) {
|
valueMap = CBOHelper
|
.getBOValueMap(((ClientBusinessObject) obj)
|
.getBusinessObject());
|
}
|
}
|
}
|
setChooseRecObjToControl(valueMap);
|
}
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
private void setChooseRecObjToControl(Map refObjValMap) {
|
//String ownOBJOID = "";
|
ObjectAddEditPanel compt = getOwnedObjectAddEditPanel();
|
/*if (compt != null && compt.getRegionPanel() != null
|
&& compt.getRegionPanel().getBaseLayoutPanel() != null) {
|
Object[] ownSelectObjects = compt.getRegionPanel().getDataModel()
|
.getSelectObjects();
|
if (ownSelectObjects != null) {
|
Object ownSelectObject = ownSelectObjects[0];
|
if (ownSelectObject instanceof DefaultTableNode) {
|
ownOBJOID = ((DefaultTableNode) ownSelectObject)
|
.getClientBusinessObject().getAttributeValue("oid");
|
}
|
}
|
}*/
|
/*if (refObjValMap.get("oid") != null && !ownOBJOID.equals("")
|
&& ownOBJOID.equals(refObjValMap.get("oid"))) {
|
// 不能参照自身
|
VCIJOptionPane.showError(dialog, "不能参照自身!"); // modify by ZhongGY
|
// 2015-05-26
|
return;
|
}*/
|
PRMItem item = getPRMItem();
|
Map<String, String> map = refObjValMap;
|
//customExpDefMap
|
String curfieldValue = item.getItemField().toLowerCase();
|
if (customExpDefMap.containsKey(curfieldValue)) {
|
String newVal = map.get(customExpDefMap.get(curfieldValue));
|
setValue(newVal);
|
}
|
HashMap<String, Component> ctrlComptMap= compt.getCtrlComptMap();
|
Iterator<String> it = ctrlComptMap.keySet().iterator();
|
while(it.hasNext()){
|
//如果设置原色在界面上显示并且设置为必填项
|
String itemFieldName = it.next();//comp.getPRMItem().getItemField();
|
Object obj = ctrlComptMap.get(itemFieldName);
|
if (obj != null && customExpDefMap.containsKey(itemFieldName.toLowerCase())) {
|
String attrName = customExpDefMap.get(itemFieldName.toLowerCase());
|
String newVal = "";
|
if (attrName != null && attrName.indexOf("@") > 0) {
|
//对参照属性特殊处理
|
String[] strs = attrName.split("@");
|
if(map.containsKey(strs[0]) && map.containsKey(strs[1])){
|
newVal = map.get(strs[0]) +"," + map.get(strs[1]);
|
}
|
}else {
|
newVal = map.get(attrName);
|
}
|
if (obj instanceof AbstractCustomControl) {
|
AbstractCustomControl comp = (AbstractCustomControl) obj;
|
comp.setValue(newVal);
|
}else if(obj instanceof JTextComponent){
|
((JTextComponent)obj).setText(newVal);
|
}else if(obj instanceof VCIJComboBox){
|
//((VCIJComboBox)obj).set (newVal);
|
}else {
|
//...
|
}
|
//comp.setValue(newVal);
|
}
|
/*if(obj != null && obj instanceof AbstractCustomControl){
|
AbstractCustomControl comp = (AbstractCustomControl) obj;
|
String itemFieldName = comp.getPRMItem().getItemField();
|
if (!curfieldValue.equals(itemFieldName.toLowerCase()) && customExpDefMap.containsKey(itemFieldName.toLowerCase())) {
|
comp.setValue(newVal);
|
}
|
}*/
|
}
|
close(DialogResult.OK);
|
//firePropertyChange(REF_OBJECT_CHANGED, null, refObjValMap);
|
}
|
|
public void firePropertyChangeManual(String propertyName, String oldValue,
|
Map<String, String> newValue) {
|
super.firePropertyChange(propertyName, oldValue, newValue);
|
}
|
|
private void cancel() {
|
close(DialogResult.CANCEL);
|
}
|
|
private void close(DialogResult dialogRes) {
|
dialog.setDialogResult(dialogRes);
|
dialog.setVisible(false);
|
}
|
|
private boolean editable = true;
|
|
@Override
|
public void setEditable(boolean editable) {
|
this.editable = editable;
|
}
|
|
@Override
|
public void setEnabled(boolean enabled) {
|
super.setEnabled(enabled);
|
setEditable(enabled);
|
text.setEnabled(enabled);
|
}
|
}
|