package com.vci.client.tool.panel; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import com.vci.corba.omd.atm.AttribItem; import com.vci.corba.omd.btm.BtmAndApName; import com.vci.corba.omd.btm.BtmItem; import com.vci.mw.ClientContextVariable; import com.vci.client.omd.attribpool.ui.APClient; import com.vci.client.omd.btm.ui.BtmClient; import com.vci.client.omd.btm.wrapper.BtmItemWrapper; import com.vci.client.omd.linktype.LinkTypeWrapper; import com.vci.client.tool.FormAttrSettingPanel; import com.vci.client.tool.dialog.UIContexBuilderWrapperDialog; import com.vci.client.tool.wrapper.AttribItemWrapperEx; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJButton; import com.vci.client.ui.swing.components.VCIJOptionPane; import com.vci.client.ui.swing.components.VCIJPanel; import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider; import com.vci.client.ui.swing.components.table.VCIJTableNode; import com.vci.client.ui.swing.components.table.VCIJTablePanel; import com.vci.corba.common.VCIError; /** * 业务类型 拥有的属性列表面板 * @author xiongchao * */ public class BtmItemAttrTablePanel extends VCIJPanel implements ActionListener { /** * */ private static final long serialVersionUID = 4485213175457227347L; class DataProvider extends AbstractVCIJTableDataProvider{ @Override public AttribItemWrapperEx[] getDatas(int arg0, int arg1) { AttribItemWrapperEx[] res = getAttrItems(); total = res.length; return res; } public VCIJTableNode getNewRowNode(AttribItemWrapperEx obj) { VCIJTableNode node = new VCIJTableNode(obj); int i = 0; String[] names = getSpecialColumns(); AttribItem ai = obj.getAttribItem(); node.setPropertyValue(names[i++], obj.getOwnedType()); node.setPropertyValue(names[i++], ai.name); node.setPropertyValue(names[i++], ai.label); node.setPropertyValue(names[i++], ai.description); //modify by zgy 2015-03-10 node.setPropertyValue(names[i++], ai.vtDataType); node.setPropertyValue(names[i++], obj.getRefBtmType()); node.setPropertyValue(names[i++], obj.getAllowNull()); node.setPropertyValue(names[i++], obj.getLength()); node.setPropertyValue(names[i++], obj.getEnumName()); node.setPropertyValue(names[i++], ai.other); return node; } @Override public String[] getSpecialColumns() { return "业务类型,名称,标签,描述,数据类型,参照类型,允许为空,长度,枚举类型,其它, ".split(","); } @Override public int getTotal() { return super.total; } } private boolean isBtm = false; private BtmItemWrapper btmItemWrapper = null; private LinkTypeWrapper linkTypeWrapper = null; private Map map = new LinkedHashMap(); private FormAttrSettingPanel ownedPanel = null; private AttribItemWrapperEx[] getAttrItems(){ map.clear(); AttribItemWrapperEx[] res = new AttribItemWrapperEx[0]; try{ List list = new LinkedList(){ /** * */ private static final long serialVersionUID = 6917342504818179154L; @Override public boolean contains(Object o) { AttribItemWrapperEx aiwe = (AttribItemWrapperEx)o; return map.containsKey(aiwe.getOwnedType() + "." + aiwe.abItem.name); } }; BtmItemWrapper biw = null; if(isBtm){ biw = getBtmItemWrapper(); if(biw == null) { return res; } String btmName = biw.btmItem.name; addBtmItemToList(btmName, "", list, true); } else { // LINKTYPE LinkTypeWrapper ltwe = getLinkTypeWrapper(); if(ltwe == null){ return res; } addLinkTypeAttrToList(ltwe.linkType.name, ltwe.linkType.attributes, list); addLinkTypeBtmToList("f_oid.", ltwe.linkType.btmItemsFrom, list); addLinkTypeBtmToList("t_oid.", ltwe.linkType.btmItemsTo, list); } res = list.toArray(res); Arrays.sort(res, new Comparator() { @Override public int compare(AttribItemWrapperEx o1, AttribItemWrapperEx o2) { return o1.getPingYing().compareTo(o2.getPingYing()); } }); }catch(Exception ex){ ex.printStackTrace(); } return res; } private void addLinkTypeAttrToList(String linkType, String[] attrs, List list) throws VCIError{ for(String attr : attrs){ AttribItem ai = APClient.getService().getAttribItemByName(attr); AttribItemWrapperEx aiwe = new AttribItemWrapperEx(linkType, ai); list.add(aiwe); } } private void addLinkTypeBtmToList(String refPrefix, String[] btmNames, List list) throws VCIError{ for(String btmName : btmNames){ addBtmItemToList(btmName, refPrefix, list, false); } } private void addFixedCommonAttrToList(String btmName, String refPrefix, List list){ //(String oid, String ts, String creator, String createTime, String modifier, String modifyTime, String name, String label, String description, String vtDataType, String defValue, String rage, String other) AttribItem attribItem = new AttribItem(); attribItem.name = refPrefix + "id"; //modify by zgy 2015-03-10 attribItem.label = "编号"; attribItem.vtDataType = "VTString"; AttribItemWrapperEx id = new AttribItemWrapperEx(btmName, attribItem);//new AttribItem(refPrefix + "id", "编号", "", "VTString", "", "", "") if(!list.contains(id)){ list.add(id); map.put(btmName + "." + id.abItem.name, id); } attribItem = new AttribItem(); attribItem.name = refPrefix + "name"; attribItem.label = "名称"; attribItem.vtDataType = "VTString"; AttribItemWrapperEx name = new AttribItemWrapperEx(btmName,attribItem); // new AttribItem(refPrefix + "name", "名称", "", "VTString", "", "", "") if(!list.contains(name)){ list.add(name); map.put(btmName + "." + name.abItem.name, name); } attribItem = new AttribItem(); attribItem.name = refPrefix + "description"; attribItem.label = "描述"; attribItem.vtDataType = "VTString"; AttribItemWrapperEx desc = new AttribItemWrapperEx(btmName,attribItem );//new AttribItem(refPrefix + "description", "描述", "", "VTString", "", "", "") if(!list.contains(desc)){ list.add(desc); map.put(btmName + "." + desc.abItem.name, desc); } } private void addBtmItemToList(String btmName, String refPrefix, List list, boolean recurrsion) throws VCIError{ //BtmAndApName[] btmAndApNameArray = BtmClient.getService().getBtmAndApNameArray(btmName); BtmItem bt = BtmClient.getService().getBtmItemByName(btmName); BtmAndApName ban = new BtmAndApName(bt.name, bt.apNameArray); //for(BtmAndApName ban : btmAndApNameArray){ AttribItem[] ais = APClient.getService().getAttribItemsByNames(ban.apName); addFixedCommonAttrToList(btmName, refPrefix, list); for (int i = 0; i < ais.length; i++) { AttribItem ai = ais[i]; AttribItemWrapperEx aiw = new AttribItemWrapperEx(btmName, ai); aiw.abItem.name = refPrefix + aiw.abItem.name; if(list.contains(aiw)){ continue; } list.add(aiw); map.put(btmName + "." + aiw.abItem.name, aiw); if(recurrsion && !"".equals(aiw.getRefBtmType()) && !btmName.equals(aiw.getRefBtmType())){ addBtmItemToList(aiw.getRefBtmType(), refPrefix + aiw.abItem.name + ".", list, recurrsion); } } //} } private VCIJTablePanel tablePanel = null; public BtmItemAttrTablePanel(FormAttrSettingPanel ownedPanel){ this.ownedPanel = ownedPanel; initActionMap(); setLayout(new BorderLayout()); tablePanel = new VCIJTablePanel(new DataProvider()); tablePanel.setShowColumnSetting(false); tablePanel.setColumnDefaultWidth(150); List custombButtons = new LinkedList(); custombButtons.add(VCISwingUtil.createVCIJButton("buildForm", "生成表单", "生成表单", "wand.png", this)); tablePanel.setCustomButtons(custombButtons); tablePanel.buildTablePanel(); add(tablePanel, BorderLayout.CENTER); } public VCIJTablePanel getTablePanel() { return tablePanel; } public void setTablePanel(VCIJTablePanel tablePanel) { this.tablePanel = tablePanel; } private void showBuildForm(){ VCISwingUtil.invokeLater(new Runnable() { @Override public void run() { showDialog(); } }, 0); } private String showType = ""; public String getShowType() { return showType; } public void setShowType(String showType) { this.showType = showType; } private void showDialog(){ List list = getOwnedPanel().getBtmItemAttrTablePanel().getTablePanel().getSelectedRowObjectsList(); if(list.size() <= 0){ VCIJOptionPane.showMessage(getOwnedPanel(), "请至少选择一个属性!"); return; } if(!getOwnedPanel().isBtmType()){ String showType = getShowType(list); setShowType(showType); if((showType == null || "".equals(showType))){ VCIJOptionPane.showMessage(getOwnedPanel(), "当是生成链接类型表单&上下文时,必须选择业务(且只能选择一个)!"); return; } } UIContexBuilderWrapperDialog dialog = new UIContexBuilderWrapperDialog(ClientContextVariable.getFrame()); dialog.setBtmItemAttrItemTablePanel(this); dialog.setBtmItemWrapper(getOwnedPanel().getSelectedBtm()); dialog.setAttribItemWrapper(list); dialog.buildDialog(); dialog.setVisible(true); } private String getShowType(List list){ String showType = ""; String linkType = getLinkTypeWrapper().linkType.name; Map map = new HashMap(); for(AttribItemWrapperEx aiwe : list){ String name = aiwe.getOwnedType(); if(name.equals(linkType)){ continue; } if(!map.containsKey(name)){ map.put(name, aiwe); showType = name; } if(map.size() > 1){ showType = ""; break; } } return showType; } private Map actionMap = new HashMap(); private void initActionMap(){ actionMap.put("buildForm", new Runnable() { @Override public void run() { showBuildForm(); } }); } @Override public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); if(actionMap.containsKey(actionCommand)){ actionMap.get(actionCommand).run(); } } public boolean isBtm() { return isBtm; } public void setBtm(boolean isBtm) { this.isBtm = isBtm; } public BtmItemWrapper getBtmItemWrapper() { return btmItemWrapper; } public void setBtmItemWrapper(BtmItemWrapper btmItemWrapper) { this.btmItemWrapper = btmItemWrapper; } public FormAttrSettingPanel getOwnedPanel() { return ownedPanel; } public void setOwnedPanel(FormAttrSettingPanel ownedPanel) { this.ownedPanel = ownedPanel; } public LinkTypeWrapper getLinkTypeWrapper() { return linkTypeWrapper; } public void setLinkTypeWrapper(LinkTypeWrapper linkTypeWrapper) { this.linkTypeWrapper = linkTypeWrapper; } }