commit 16b25d07530e14341c5c03a78ca3d4231b2668a4 Author: xiongcz Date: Fri Jun 6 14:11:46 2025 +0800 澶囦唤 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..b2675a3 --- /dev/null +++ b/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..a974258 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com.connor.jd.DtoE + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ae3efb0 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: DtoE +Bundle-SymbolicName: com.connor.jd.DtoE;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Vendor: CONNOR +Require-Bundle: org.eclipse.ui, + com.teamcenter.rac.kernel;bundle-version="13000.1.0", + com.teamcenter.rac.util;bundle-version="13000.1.0", + com.teamcenter.rac.common;bundle-version="13000.1.0", + com.teamcenter.rac.aifrcp;bundle-version="13000.1.0", + org.eclipse.core.runtime;bundle-version="3.15.100", + TcSoaStructureManagementLoose;bundle-version="13000.1.0", + org.apache.poi.39;bundle-version="3.9.0" +Automatic-Module-Name: com.connor.jd.DtoE +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Import-Package: com.teamcenter.rac.kernel +Export-Package: com.connor.ml.tcm.outfile.ML_01 +Bundle-ClassPath: lib/hutool-all-5.8.25.jar, + lib/mssql-jdbc-7.0.0.jre8.jar, + lib/ojdbc8.jar, + lib/swingx-1.6.1.jar, + . diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/BomValBean.class b/bin/com/connor/ml/tcm/outfile/ML_01/BomValBean.class new file mode 100644 index 0000000..665988f Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/BomValBean.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand$1.class b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand$1.class new file mode 100644 index 0000000..732ad52 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand$1.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand.class b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand.class new file mode 100644 index 0000000..80ee6a7 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog$1.class b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog$1.class new file mode 100644 index 0000000..92fc104 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog$1.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog.class b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog.class new file mode 100644 index 0000000..69976f7 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomHandler.class b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomHandler.class new file mode 100644 index 0000000..aefcfae Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomHandler.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTable.class b/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTable.class new file mode 100644 index 0000000..6f21e1d Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTable.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTableModel.class b/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTableModel.class new file mode 100644 index 0000000..5002d7e Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/JTreeTableModel.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/ProcessBarDialog.class b/bin/com/connor/ml/tcm/outfile/ML_01/ProcessBarDialog.class new file mode 100644 index 0000000..e1315b2 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/ProcessBarDialog.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/TableCellCheckboxRenderer.class b/bin/com/connor/ml/tcm/outfile/ML_01/TableCellCheckboxRenderer.class new file mode 100644 index 0000000..bc50667 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/TableCellCheckboxRenderer.class differ diff --git a/bin/com/connor/ml/tcm/outfile/ML_01/Test.class b/bin/com/connor/ml/tcm/outfile/ML_01/Test.class new file mode 100644 index 0000000..2d84ef1 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/ML_01/Test.class differ diff --git a/bin/com/connor/ml/tcm/outfile/bean/NodeBean.class b/bin/com/connor/ml/tcm/outfile/bean/NodeBean.class new file mode 100644 index 0000000..f0ab494 Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/bean/NodeBean.class differ diff --git a/bin/com/connor/ml/tcm/outfile/util/Adapter.class b/bin/com/connor/ml/tcm/outfile/util/Adapter.class new file mode 100644 index 0000000..1d08b2c Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/util/Adapter.class differ diff --git a/bin/com/connor/ml/tcm/outfile/util/AutoCompleter.class b/bin/com/connor/ml/tcm/outfile/util/AutoCompleter.class new file mode 100644 index 0000000..9fdfb6e Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/util/AutoCompleter.class differ diff --git a/bin/com/connor/ml/tcm/outfile/util/JAutoCompleteComboBox.class b/bin/com/connor/ml/tcm/outfile/util/JAutoCompleteComboBox.class new file mode 100644 index 0000000..bbb1c6b Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/util/JAutoCompleteComboBox.class differ diff --git a/bin/com/connor/ml/tcm/outfile/util/MethodUtil.class b/bin/com/connor/ml/tcm/outfile/util/MethodUtil.class new file mode 100644 index 0000000..a2969ec Binary files /dev/null and b/bin/com/connor/ml/tcm/outfile/util/MethodUtil.class differ diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..72bcbd2 --- /dev/null +++ b/build.properties @@ -0,0 +1,11 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + lib/hutool-all-5.8.25.jar,\ + lib/mssql-jdbc-7.0.0.jre8.jar,\ + lib/ojdbc8.jar,\ + lib/swingx-1.6.1.jar +src.includes = lib/ diff --git a/icons/sample.png b/icons/sample.png new file mode 100644 index 0000000..02c4b79 Binary files /dev/null and b/icons/sample.png differ diff --git a/icons/sample@2x.png b/icons/sample@2x.png new file mode 100644 index 0000000..c1224d1 Binary files /dev/null and b/icons/sample@2x.png differ diff --git a/lib/dom4j-2.1.1.jar b/lib/dom4j-2.1.1.jar new file mode 100644 index 0000000..cda47db Binary files /dev/null and b/lib/dom4j-2.1.1.jar differ diff --git a/lib/hutool-all-5.8.25.jar b/lib/hutool-all-5.8.25.jar new file mode 100644 index 0000000..c0d7831 Binary files /dev/null and b/lib/hutool-all-5.8.25.jar differ diff --git a/lib/mssql-jdbc-7.0.0.jre8.jar b/lib/mssql-jdbc-7.0.0.jre8.jar new file mode 100644 index 0000000..9f68c4d Binary files /dev/null and b/lib/mssql-jdbc-7.0.0.jre8.jar differ diff --git a/lib/ojdbc8.jar b/lib/ojdbc8.jar new file mode 100644 index 0000000..8517287 Binary files /dev/null and b/lib/ojdbc8.jar differ diff --git a/lib/poi-4.0.1.jar b/lib/poi-4.0.1.jar new file mode 100644 index 0000000..be09297 Binary files /dev/null and b/lib/poi-4.0.1.jar differ diff --git a/lib/poi-examples-3.7-20101029.jar b/lib/poi-examples-3.7-20101029.jar new file mode 100644 index 0000000..914243d Binary files /dev/null and b/lib/poi-examples-3.7-20101029.jar differ diff --git a/lib/poi-ooxml-3.7-20101029.jar b/lib/poi-ooxml-3.7-20101029.jar new file mode 100644 index 0000000..5f36eb4 Binary files /dev/null and b/lib/poi-ooxml-3.7-20101029.jar differ diff --git a/lib/poi-ooxml-schemas-3.7-20101029.jar b/lib/poi-ooxml-schemas-3.7-20101029.jar new file mode 100644 index 0000000..82282b5 Binary files /dev/null and b/lib/poi-ooxml-schemas-3.7-20101029.jar differ diff --git a/lib/swingx-1.6.1.jar b/lib/swingx-1.6.1.jar new file mode 100644 index 0000000..b0bcc87 Binary files /dev/null and b/lib/swingx-1.6.1.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..d48c680 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/com/connor/ml/tcm/outfile/ML_01/BomValBean.java b/src/com/connor/ml/tcm/outfile/ML_01/BomValBean.java new file mode 100644 index 0000000..3b2e9ff --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/ML_01/BomValBean.java @@ -0,0 +1,34 @@ +package com.connor.ml.tcm.outfile.ML_01; + +public class BomValBean { + + private String bl_czbh; + private String bl_jdjz; + + private String bl_quantity; + public String getBl_quantity() { + return bl_quantity; + } + public void setBl_quantity(String bl_quantity) { + this.bl_quantity = bl_quantity; + } + public String getBl_czbh() { + return bl_czbh; + } + public void setBl_czbh(String bl_czbh) { + this.bl_czbh = bl_czbh; + } + public String getBl_jdjz() { + return bl_jdjz; + } + public void setBl_jdjz(String bl_jdjz) { + this.bl_jdjz = bl_jdjz; + } + @Override + public String toString() { + return "BomValBean [bl_czbh=" + bl_czbh + ", bl_jdjz=" + bl_jdjz + ", bl_quantity=" + bl_quantity + "]"; + } + + + +} diff --git a/src/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand.java b/src/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand.java new file mode 100644 index 0000000..b78da53 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomCommand.java @@ -0,0 +1,483 @@ +package com.connor.ml.tcm.outfile.ML_01; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; + +import com.connor.ml.tcm.outfile.bean.NodeBean; +import com.teamcenter.rac.aif.AbstractAIFCommand; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCAccessControlService; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class DbomTransitionToEbomCommand extends AbstractAIFCommand { + + private InterfaceAIFComponent comp; + private TCSession session; + private TCComponentBOMLine bomLine = null; + static ArrayList preList = new ArrayList(); + private TCAccessControlService acs; + private TCComponent[] user; + private String[] props; + + public DbomTransitionToEbomCommand(InterfaceAIFComponent comp, TCSession session) { + // Auto-generated constructor stub + this.comp = comp; + this.session = session; + } + private List ebomList; + @Override + public void executeModal() throws Exception { + // Auto-generated method stub +// TCComponentType compType = session.getTypeComponent("ML8_Washing"); +// String[] allProperties=compType.getPropertyNames();//获取类所有属性 + //TCProperty[] allProperties=compType.getPropertyNames();//获取类所有属性 + acs = session.getTCAccessControlService(); + user = new TCComponent[]{ session.getUser(), session.getGroup(), session.getRole() }; + //获取选中的对象 + if(!(comp instanceof TCComponentBOMLine)) + { + MessageBox.post("请在结构管理器中选中BOMLine对象!", "错误", MessageBox.ERROR); + return; + } + //System.out.println("11111111111"); + bomLine = (TCComponentBOMLine) comp; + + //判断对象类型 + TCComponentItem item = bomLine.getItem(); +// boolean isTypeof=false; + String[] prefValues = session.getPreferenceService().getStringValues("Pma0_Part_Design_Type"); + String[] ebomType = session.getPreferenceService().getStringValues("Pma0_EBOM_Type"); + + ebomList = Arrays.asList(ebomType); + System.out.println("ebomList==>"+ebomList); + List dtypeList = new ArrayList(); + Map DETypeMap = new HashMap(); + for(String pref : prefValues) { + String[] split = pref.split(","); + String etypeString = split[0]; + String dtypeString = split[1]; + DETypeMap.put(dtypeString.replaceAll("DesignType:", ""), etypeString.replaceAll("PartType:", "")); + dtypeList.add(dtypeString.replaceAll("DesignType:", "")); + preList.add(dtypeString.replaceAll("DesignType:", "")); +// if(pref.equals(item.getType())) { +// isTypeof = true; +// } + } + System.out.println(item.getType()+"dtypeList==>"+dtypeList.toString()); + if(!dtypeList.contains(item.getType())) { + MessageBox.post("请选中设计对象", "提示", 2); + return; + } + //lidy20240923界面中,BOM属性列的显示做成可配置,配置属性为BOMline属性的真实值 + String[] options = session.getPreferenceService().getStringValues("Pma0_Table_Columns"); +// if(options == null || options.length == 0) { +// MessageBox.post("首选项配置不正确", "提示", 2); +// return; +// } + String[] header = new String[options.length + 5]; + props = new String[options.length]; + header[0] = "DBOM对象"; + header[1] = "对应父节点"; + header[2] = "EBOM对象"; + header[3] = "发布状态"; + header[4] = "选中"; + for(int i = 0; i < options.length; i++) { + String[] split = options[i].split("="); + header[i + 5] = split[0]; + props[i] = split[1]; + } + + new Thread() { + @Override + public void run() { + ProcessBarDialog progress = new ProcessBarDialog("正在加载BOM转换页面..."); + progress.open(); + try { + DefaultMutableTreeTableNode node = getBomPropertyToNode(session, bomLine); + progress.close(); +// DbomTransitionToEbomDialog dialog = + new DbomTransitionToEbomDialog(comp, session, node, preList, progress, header); + } catch (Exception e) { + // Auto-generated catch block + e.printStackTrace(); + progress.close(); + } + } + }.start(); +// super.executeModal(); + } +// private Map> bomValMap = new HashMap>(); + + /** + * 全部打包 + * + * @param topBomline + + private void packAll(TCComponentBOMLine topBomline) throws Exception { + TCComponentBOMLine[] bomlines = new TCComponentBOMLine[1]; + bomlines[0] = topBomline; + StructureService structureService = StructureService.getService(session.getSoaConnection()); +// ServiceData serviceData = + structureService.packOrUnpack(bomlines, 2); +// serviceDat +// TCServiceExceptionUtils.validateServiceException(serviceData); + }*/ + /** + * 获取BOM属性 + * @throws TCException + */ + private DefaultMutableTreeTableNode getBomPropertyToNode(TCSession session, TCComponentBOMLine topBomLine) + throws Exception { + // Auto-generated method stub + + NodeBean nodeBean = new NodeBean(); + + //对象ID + nodeBean.setDbom("顶层"); + nodeBean.setEbom(""); +// nodeBean.setEbomId(""); + nodeBean.setNum(""); + nodeBean.setLabel(""); + nodeBean.setRefreshStatus(""); + nodeBean.setParentString(""); + + DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode(nodeBean); + //获取BOM + try { + //getRepresentationPropertysToNode(topBomLine, rootNode, ""); + getBomPropertysToNode(topBomLine, rootNode, "",null); + return rootNode; + } catch (Exception e) { + // : handle exception + e.printStackTrace(); + } + return null; + } + /*** + * 获取表示下的对象 + * @param bomLine + * @param rootNode + * @param parentID + * @throws TCException + */ + private Boolean getRepresentationPropertysToNode(TCComponentBOMLine bomLine, DefaultMutableTreeTableNode rootNode) + throws Exception { +// , String parentID,String quantity,String blJz) throws Exception { + Boolean jxZk = false; + TCComponentItemRevision itemRevision = bomLine.getItemRevision(); + //刷新表示关系 + //TCComponent referenceProperty = itemRevision.getReferenceProperty("representation_for"); + //referenceProperty.refresh(); + //获取表示关系下的对象 + itemRevision.refresh(); + TCComponent[] tcComponents = itemRevision.getReferenceListProperty("representation_for"); + for (TCComponent tcComponent : tcComponents) { + + TCProperty refreshStatusProperty = tcComponent.getTCProperty("release_status_list"); + TCComponent[] refreshStatus = refreshStatusProperty.getReferenceValueArray(); + TCProperty processProperty = tcComponent.getTCProperty("process_stage_list"); + TCComponent[] processStage = processProperty.getReferenceValueArray(); + + NodeBean nodeBean = new NodeBean(); + String stringProperty = tcComponent.getStringProperty("object_string"); + nodeBean.setDbom(""); + nodeBean.setEbom(stringProperty); +// nodeBean.setEbomId(tcComponent.getStringProperty("item_id")); +// nodeBean.setEbomDesc(tcComponent.getStringProperty("object_desc")); + nodeBean.setNum(bomLine.getStringProperty("bl_quantity")); + nodeBean.setBom(bomLine); + for(int i = 0; i < props.length; i++) { + System.out.println("setValueAt" + (i + 5) + "==" + props[i] + "==" + bomLine.getProperty(props[i])); + nodeBean.setValueAt(i + 5, tcComponent.getProperty(props[i]));//TODO lidy20240925D转E需要显示的属性调整成物料版本属性 + } + nodeBean.setTcComponent(tcComponent); + nodeBean.setpRev(itemRevision); + nodeBean.setLabel("0"); +// nodeBean.setBl_plmxml_abs_xform(bomLine.getProperty("bl_plmxml_occ_xform")); + if(refreshStatus.length > 0) { + StringBuffer stringBuffer = new StringBuffer(); + //添加发布状态 + for (int i = 0; i < refreshStatus.length; i++) { + stringBuffer.append(refreshStatus[i].toString()); + if(i < refreshStatus.length - 1) { + stringBuffer.append(","); + } + } + nodeBean.setRefreshStatus(stringBuffer.toString()); + }else if(processStage.length > 0) { + nodeBean.setRefreshStatus("流程中"); + }else { + nodeBean.setRefreshStatus(""); + } + nodeBean.setParentString(itemRevision.getStringProperty("object_string")); + + DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(nodeBean); + rootNode.add(node); + + if(tcComponents.length == 1) { + if(getTopRefresh(node)) { + nodeBean.setLabel("0"); + }else { + nodeBean.setLabel("1"); + } + } + +// String property = tcComponent.getProperty("j6_processtype"); + if(!acs.checkAccessorsPrivilege(user, tcComponent, "WRITE")){ // || stringProperty.contains("55") + System.out.println(stringProperty + "=====stringProperty"); +// jxZk = false; +// }else if(property!=null && (property.equals("外购件") || property.equals("外协件"))) { +// jxZk = false; + }else { + //一图多物的情况,只要对一个物具有写权限,就允许展开下级 + jxZk = true; + } + } + return jxZk; + } + /*** + * 判断上级是否勾选已发布对象 + * @param node + * @return + */ + private static boolean getTopRefresh(DefaultMutableTreeTableNode node) { + boolean result = false; + //判断上层是否勾选已发布的对象 + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) { + for (int i = 0; i < rootNode.getChildCount();) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && childBean.getRefreshStatus().indexOf("发布") >= 0) { + //MessageBox.post("上层["+childBean.getEbom()+"]已勾选发布的对象,下层不允许勾选!", "错误", MessageBox.ERROR); + return true; + } + else { + return getTopRefresh(childNode); + } + } + } + } + return result; + } + + + /** + * 获取BOM信息 + * @param bomLine + * @param bomPropertyList + * @param parentID + */ + private void getBomPropertysToNode(TCComponentBOMLine bomLine, DefaultMutableTreeTableNode rootNode, + String parentID, TCComponentBOMLine pLine) { + try { + + NodeBean nodeBean = new NodeBean(); + String itemType = bomLine.getStringProperty("bl_item_object_type"); + System.out.println(itemType); +// if(bomLine.getStringProperty("bl_item_object_type").equals("LD6_3Ddesign")) { +// return; +// } + nodeBean.setDbom(bomLine.getStringProperty("bl_item_object_string")); + nodeBean.setNum(bomLine.getStringProperty("bl_quantity")); + nodeBean.setEbom(""); +// nodeBean.setEbomId(""); + for(int i = 0; i < props.length; i++) { + nodeBean.setValueAt(i + 5, bomLine.getProperty(props[i])); + } + if(preList.contains(itemType)) { + nodeBean.setLabel("3"); + }else { + nodeBean.setLabel(""); + } + nodeBean.setRev(bomLine.getItemRevision()); + nodeBean.setRefreshStatus(""); + nodeBean.setParentString(""); + nodeBean.setBom(bomLine); + + String type = bomLine.getItem().getType(); + if(ebomList.contains(type) || "EDAComp".equals(itemType) || "J6_ZX".equals(itemType) ) { + nodeBean.setpRev(pLine.getItemRevision()); + nodeBean.setRootNode(rootNode); + nodeBean.setIsTw(true); + } + +// nodeBean.setBl_plmxml_abs_xform(bomLine.getProperty("bl_plmxml_abs_xform")); + DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(nodeBean); + rootNode.add(node); + + getPackMessage(nodeBean, bomLine); + + Boolean jxZk = getRepresentationPropertysToNode(bomLine, node);//, bomLine.getStringProperty("bl_item_item_id"), +// bomLine.getStringProperty("bl_quantity"), bomLine.getProperty("bl_plmxml_occ_xform")); + if(jxZk && bomLine.getChildren().length > 0) {//TODO + AIFComponentContext aif[] = bomLine.getChildren(); + for (int i = 0; i < aif.length; i++) { + TCComponentBOMLine subline = (TCComponentBOMLine) aif[i].getComponent(); + if(subline.getLogicalProperty("bl_is_occ_suppressed"))//lidy20240925抑制的事例不应在D转E功能中被转化出来 + continue; + getBomPropertysToNode(subline, node, bomLine.getStringProperty("bl_item_item_id"), bomLine); + } + } + } catch (Exception e) { + // Auto-generated catch block + e.printStackTrace(); + } + } + + private void getPackMessage(NodeBean nodeBean, TCComponentBOMLine bomLine) { + // Auto-generated method stub + try { + Map> bomValMap = new HashMap>(); + AIFComponentContext[] children = bomLine.getChildren(); +// boolean hasPack = false; +// unpack + for (int i = 0; i < children.length; i++) { + TCComponentBOMLine cLine = (TCComponentBOMLine) children[i].getComponent(); + System.out.println(cLine + " 是否打包:" + cLine.isPacked()); + if (cLine.isPacked()) { + String bl_quantity2 = cLine.getStringProperty("bl_quantity"); + if(bl_quantity2.isEmpty()) { + bl_quantity2 = "1"; + } + BigDecimal bigDecimal2 = new BigDecimal(bl_quantity2); + TCComponentBOMLine[] packedLines = cLine.getPackedLines(); + for(TCComponentBOMLine ccLine : packedLines) { +// TCComponentBOMLine cLine = (TCComponentBOMLine) children2[i].getComponent(); + TCComponentItemRevision itemRevision = ccLine.getItemRevision(); + String bl_sequence_no = ccLine.getStringProperty("bl_sequence_no"); + String bl_plmxml_abs_xform = ccLine.getStringProperty("bl_plmxml_abs_xform");//bl_plmxml_occ_xform + String bl_quantity = ccLine.getStringProperty("bl_quantity"); + if(bl_quantity.isEmpty()) { + bl_quantity = "1"; + } + bigDecimal2 = bigDecimal2.subtract(new BigDecimal(bl_quantity)); + BomValBean bean = new BomValBean(); + bean.setBl_czbh(bl_sequence_no); + bean.setBl_jdjz(bl_plmxml_abs_xform); + bean.setBl_quantity(bl_quantity); + if(bomValMap.containsKey(itemRevision)) { + List list = bomValMap.get(itemRevision); + list.add(bean); + }else { + List list = new ArrayList(); + list.add(bean); + bomValMap.put(itemRevision, list); + } + } + cLine.unpack(); + cLine.refresh(); + TCComponentItemRevision itemRevision = cLine.getItemRevision(); + String bl_sequence_no = cLine.getStringProperty("bl_sequence_no"); + String bl_plmxml_abs_xform = cLine.getStringProperty("bl_plmxml_abs_xform"); + + BomValBean bean = new BomValBean(); + bean.setBl_czbh(bl_sequence_no); + bean.setBl_jdjz(bl_plmxml_abs_xform); + bean.setBl_quantity(bigDecimal2.toString()); + if(bomValMap.containsKey(itemRevision)) { + List list = bomValMap.get(itemRevision); + list.add(bean); + }else { + List list = new ArrayList(); + list.add(bean); + bomValMap.put(itemRevision, list); + } + cLine.pack(); + }else { +// TCComponentBOMLine cLine = (TCComponentBOMLine) children[i].getComponent(); + TCComponentItemRevision itemRevision = cLine.getItemRevision(); + String bl_sequence_no = cLine.getStringProperty("bl_sequence_no"); + String bl_plmxml_abs_xform = cLine.getStringProperty("bl_plmxml_abs_xform"); + String bl_quantity = cLine.getStringProperty("bl_quantity"); + BomValBean bean = new BomValBean(); + bean.setBl_czbh(bl_sequence_no); + bean.setBl_jdjz(bl_plmxml_abs_xform); + bean.setBl_quantity(bl_quantity); + if(bomValMap.containsKey(itemRevision)) { + List list = bomValMap.get(itemRevision); + list.add(bean); + }else { + List list = new ArrayList(); + list.add(bean); + bomValMap.put(itemRevision, list); + } + } + } + +// AIFComponentContext[] children2 = null; +// if (hasPack) { +// bomLine.refresh(); +// children2 = bomLine.getChildren(); +// for(int i = 0; i < children2.length; i++) { +// TCComponentBOMLine cLine = (TCComponentBOMLine) children2[i].getComponent(); +// TCComponentItemRevision itemRevision = cLine.getItemRevision(); +// String bl_sequence_no = cLine.getStringProperty("bl_sequence_no"); +// String bl_plmxml_abs_xform = cLine.getStringProperty("bl_plmxml_abs_xform"); +// String bl_quantity = cLine.getStringProperty("bl_quantity"); +// BomValBean bean = new BomValBean(); +// bean.setBl_czbh(bl_sequence_no); +// bean.setBl_jdjz(bl_plmxml_abs_xform); +// bean.setBl_quantity(bl_quantity); +// if(bomValMap.containsKey(itemRevision)) { +// List list = bomValMap.get(itemRevision); +// list.add(bean); +// }else { +// List list = new ArrayList(); +// list.add(bean); +// bomValMap.put(itemRevision, list); +// } +// } +// }else { +// for(int i = 0; i < children.length; i++) { +// TCComponentBOMLine cLine = (TCComponentBOMLine) children[i].getComponent(); +// TCComponentItemRevision itemRevision = cLine.getItemRevision(); +// String bl_sequence_no = cLine.getStringProperty("bl_sequence_no"); +// String bl_plmxml_abs_xform = cLine.getStringProperty("bl_plmxml_abs_xform"); +// String bl_quantity = cLine.getStringProperty("bl_quantity"); +// BomValBean bean = new BomValBean(); +// bean.setBl_czbh(bl_sequence_no); +// bean.setBl_jdjz(bl_plmxml_abs_xform); +// bean.setBl_quantity(bl_quantity); +// if(bomValMap.containsKey(itemRevision)) { +// List list = bomValMap.get(itemRevision); +// list.add(bean); +// }else { +// List list = new ArrayList(); +// list.add(bean); +// bomValMap.put(itemRevision, list); +// } +// } +// } + nodeBean.setBomValMap(bomValMap); + +// try { +// if(hasPack) { +// packAll(bomLine); +// bomLine.refresh(); +// } +// } catch (Exception e1) { +// // Auto-generated catch block +// e1.printStackTrace(); +// } + }catch (Exception e) { + // : handle exception + e.printStackTrace(); + } + } +} diff --git a/src/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog.java b/src/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog.java new file mode 100644 index 0000000..53ffe96 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomDialog.java @@ -0,0 +1,1000 @@ +package com.connor.ml.tcm.outfile.ML_01; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.ListSelectionModel; +import javax.swing.tree.TreePath; +import com.teamcenter.rac.kernel.TCAccessControlService; + +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.decorator.HighlighterFactory; +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; + +import com.connor.ml.tcm.outfile.bean.NodeBean; +import com.connor.ml.tcm.outfile.util.MethodUtil; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +//import com.teamcenter.soa.exceptions.NotLoadedException; + +public class DbomTransitionToEbomDialog extends JFrame implements ActionListener, MouseListener { + //AbstractAIFDialog + + /** + * + */ + private static final long serialVersionUID = 1L; + private TCSession session; + private InterfaceAIFComponent comp; + //private InterfaceAIFComponent comp;//获取选中的对象 + + private List isNotEditableRow = new ArrayList(); + //private TCComponentBOMLine bomLine; + private DefaultMutableTreeTableNode node; + + private String[] header = new String[] { "DBOM对象", "EBOM对象","选中", "EBOMID", "物料描述","数量","发布状态","对应父节点"}; + + private JPanel titlePanel; + private JLabel titleLabel; + private JTreeTable table; + private JTreeTableModel map; + + private JPanel rootPanel; + private JButton okButton; + private JButton celButton; + private JButton refreshButton; +// private Map> bomValMap; + private ArrayList preList; + private StringBuilder builder = new StringBuilder(""); +// private ProcessBarDialog progress; + private Boolean falg1 = true; + private TCAccessControlService acs; + private TCComponent[] user; + private StringBuilder msg2; + private List items = new ArrayList(); + public DbomTransitionToEbomDialog(InterfaceAIFComponent comp, TCSession session, DefaultMutableTreeTableNode node, + ArrayList preList, ProcessBarDialog progress, String[] header) { + // Auto-generated constructor stub +// super(false); + this.session = session; + this.comp = comp; + this.node = node; + this.preList = preList; +// this.progress = progress; + this.header = header; + + acs = session.getTCAccessControlService(); + user = new TCComponent[]{ session.getUser(), session.getGroup(), session.getRole() }; + msg2 = new StringBuilder(""); +// this.bomValMap = bomValMap; +// System.out.println("bomValMap==>"+bomValMap.toString()); + init(); + } + + private void init() { + // Auto-generated method stub + this.setTitle("DBOM转EBOM"); + this.setPreferredSize(new Dimension(800, 600)); + // 初始化标题部分控件 + this.titlePanel = new JPanel(); + this.titleLabel = new JLabel("DBOM转EBOM"); + this.titleLabel.setFont(new Font("宋体", 1, 18)); + this.titlePanel.add(titleLabel); + + JPanel panel = new JPanel(); + panel.add(this.titlePanel,BorderLayout.NORTH); + + getJTreeTable(); + + this.table.addMouseListener(this); +// Adapter adapter = new Adapter(table); + + this.rootPanel = new JPanel(new FlowLayout()); + this.okButton = new JButton("确认"); + this.celButton = new JButton("取消"); + this.refreshButton = new JButton("刷新"); + + this.rootPanel.add(okButton); + this.rootPanel.add(celButton); + this.rootPanel.add(refreshButton); + //this.rootPanel.add(celValueButton); + + // 添加鼠标监听 + this.createActionEvent(); + this.setLayout(new BorderLayout()); + // this.add(centerPanel, BorderLayout.NORTH); + this.add(panel, BorderLayout.NORTH); + this.add(new JScrollPane(this.table), BorderLayout.CENTER); + // dialog.add(tablePanel, BorderLayout.CENTER); + this.add(rootPanel, BorderLayout.SOUTH); + //this.setAlwaysOnTop(true); + this.pack(); + this.setLocationRelativeTo(null); + this.setVisible(true); +// this.setAlwaysOnTop(true); + } + + //添加监听 + private void createActionEvent() { + this.okButton.addActionListener(this); + this.celButton.addActionListener(this); + this.refreshButton.addActionListener(this); + //this.celValueButton.addActionListener(this); + } + + //Jtable通用方法 + private void getJTreeTable() { +// int simpleLen = 100; +// int totleLen = 1500; + if (table == null) { + this.map = new JTreeTableModel(this.node, header); + this.map.setIsNotEditableRow(this.isNotEditableRow); + //map.setColumnIdentifiers(titleNames); + + table = new JTreeTable(map); + table.setIsNotEditableRow(this.isNotEditableRow); + table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + // partsTable.setRowHeight(1, 50); + // partsTable.setRowHeight(2, 100); + table.setRowHeight(30); + table.expandAll(); // 展开全部节点 + // 隐藏列 +// partsTable.HiddenCell(0); + + table.getColumnModel().getColumn(NodeBean.DBOM).setPreferredWidth(188); // 设置第一列宽度 + table.getColumnModel().getColumn(NodeBean.EBOM).setPreferredWidth(150); // 设置第二列宽度 + table.getColumnModel().getColumn(NodeBean.LABEL).setPreferredWidth(55); // 设置第三列宽度 + + table.setHighlighters(HighlighterFactory.createSimpleStriping()); + +// if (simpleLen * header.length >= totleLen) { +// for (int i = 0; i < header.length; i++) { +// table.getColumnModel().getColumn(i).setPreferredWidth(simpleLen); +// } +// table.setAutoResizeMode(JXTable.AUTO_RESIZE_OFF);//AUTO_RESIZE_OFF +// } else { +// table.setAutoResizeMode(JXTable.AUTO_RESIZE_OFF);//AUTO_RESIZE_NEXT_COLUMN +// } + table.setAutoResizeMode(JXTable.AUTO_RESIZE_OFF); + } + } + + @Override + public void mouseClicked(MouseEvent e) { + // Auto-generated method stub + if(e.getClickCount() == 2) { + TreePath treePath = table.getPathForLocation(e.getX(),e.getY()); + if (treePath != null) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) treePath.getLastPathComponent(); + NodeBean nodeBean = (NodeBean) node.getUserObject(); + String itemId = nodeBean.getDbom(); + if(itemId != null && !itemId.isEmpty()) { + try { + //获取对象 + TCComponentItemType itemType = (TCComponentItemType) this.session.getTypeComponent("Item"); + TCComponentItem item = itemType.findItems(itemId.split("-")[0])[0]; + + com.teamcenter.rac.common.Activator.getDefault() + .openPerspective("com.teamcenter.rac.ui.perspectives.navigatorPerspective"); + com.teamcenter.rac.common.Activator.getDefault() + .openComponents("com.teamcenter.rac.ui.perspectives.navigatorPerspective", + new InterfaceAIFComponent[] { item }); + } catch (Exception e2) { + // : handle exception + e2.printStackTrace(); + } + } + } + } else if (e.getClickCount() > 0) { + // 获得选中列 + int selectColumn = table.getTableHeader().columnAtPoint(e.getPoint()); + + if(selectColumn != NodeBean.LABEL) { + return; + } + TreePath treePath = table.getPathForLocation(e.getX(),e.getY()); + if (treePath != null) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) treePath.getLastPathComponent(); + NodeBean nodeBean = (NodeBean) node.getUserObject(); + + try { + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + //TODO 勾选事件 + if(nodeBean.getLabel().equals("0")) { + String status = nodeBean.getRefreshStatus(); + boolean access = !acs.checkAccessorsPrivilege(user, nodeBean.getTcComponent(), "WRITE") + || !status.equals("属性发布") && !status.equals("流程中") && !status.isEmpty(); + if(access && getChildRefresh(parentNode, false)) { + MessageBox.post("下层已勾选,上层不允许勾选已发布或没权限对象!", "错误", MessageBox.ERROR); + return; + } + if(getTopRefresh(node)) { + MessageBox.post("上层已勾选发布或无权限的对象,下层不允许勾选!", "错误", MessageBox.ERROR); + return; + } + //判断同一层是否已勾选 + if(parentNode != null) { + for (int i = 0; i < parentNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) parentNode.getChildAt(i); +// for (DefaultMutableTreeTableNode childNode : backMap.get(parentNode)) { + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && !childBean.getEbom().isEmpty() && !nodeBean.getEbom().isEmpty()) { + MessageBox.post(this, "同一层级只允许选中一个!", "错误", MessageBox.ERROR); + return; + } + } + } + nodeBean.setLabel("1"); + if(!access && parentNode != null) + autoCheck(parentNode, "1"); + //isHaveBom(node, nodeBean.getEbomId(), "1", itemType); + }else if(nodeBean.getLabel().equals("1")) { + nodeBean.setLabel("0"); + if(parentNode != null) + autoCheck(parentNode, "0"); + //isHaveBom(node, nodeBean.getEbomId(), "0", itemType); + } + this.repaint(); +// Robot robot = new Robot(); +// robot.keyPress(KeyEvent.VK_TAB); +// robot.keyRelease(KeyEvent.VK_TAB); + } catch (Exception e2) { + // : handle exception + e2.printStackTrace(); + MessageBox.post("错误:" + e2, "错误", MessageBox.ERROR); + } + } + } + } + + /*** + * 判断上级是否勾选 + * @param node + * @return + * @throws TCException + */ +// private void isHaveBom(DefaultMutableTreeTableNode node,String parentID,String status,TCComponentItemType itemType) +// throws Exception { +// TCComponentItem item = itemType.findItems(parentID)[0]; +// TCComponentItemRevision itemRevision = item.getLatestItemRevision(); +// +// TCComponent[] tcComponents = itemRevision.getReferenceListProperty("view"); +// if(tcComponents.length > 0) +// { +// for (int ii = 0; ii < node.getParent().getChildCount(); ii++) { +// DefaultMutableTreeTableNode tableNode = (DefaultMutableTreeTableNode)node.getParent().getChildAt(ii); +// +// if(tableNode.getChildCount() > 0) +// { +// for (int i = 0; i < tcComponents.length; i++) { +// TCComponent childBomLine = tcComponents[i]; +// List haveItemID = new ArrayList(); +// for (int j = 0; j < tableNode.getChildCount(); j++) { +// String childItemId = childBomLine.getStringProperty("item_id"); +// NodeBean childNodeBean = (NodeBean) tableNode.getChildAt(j).getUserObject(); +// if(childItemId.equals(childNodeBean.getEbomId()) && !haveItemID.contains(childNodeBean.getEbomId())) +// { +// haveItemID.add(childNodeBean.getEbomId()); +// childNodeBean.setLabel(status); +// isHaveBom((DefaultMutableTreeTableNode)(tableNode.getChildAt(j)), childNodeBean.getEbomId(), status, itemType); +// } +// } +// } +// } +// } +// } +// } + + /*** + * 判断上级是否勾选 + * @param node + * @return + */ +// private boolean getTop(DefaultMutableTreeTableNode node) { +// boolean result = false; +// +// //判断上层是否勾选已发布的对象 +// DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); +// if(parentNode != null) +// { +// DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); +// if(rootNode != null) +// { +// for (int i = 0; i < rootNode.getChildCount(); i++) { +// DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); +// NodeBean childBean = (NodeBean) childNode.getUserObject(); +// if(childBean.getLabel().equals("1") && !childBean.getEbom().isEmpty()) +// { +// //MessageBox.post("上层["+childBean.getEbom()+"]已勾选发布的对象,下层不允许勾选!", "错误", MessageBox.ERROR); +// return true; +// } +// } +// } +// } +// +// return result; +// } + + /*** + * 判断上级是否勾选已发布对象 + * @param node + * @return + */ + private boolean getTopRefresh(DefaultMutableTreeTableNode node) throws Exception { + boolean result = false; + + //判断上层是否勾选已发布的对象 + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) { + for (int i = 0; i < rootNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + + if(childBean.getLabel().equals("1")) { + TCComponent tcComponent = childBean.getTcComponent(); +// String property = tcComponent.getProperty("j6_processtype"); + String status = childBean.getRefreshStatus(); + if(!status.equals("属性发布") && !status.equals("流程中") && !status.isEmpty()) { + System.out.println("发布:" + tcComponent); + result = true; + break; +// }else if(property != null && (property.equals("外购件") || property.equals("外协件"))) { +// result = true; +// break; + }else if(!acs.checkAccessorsPrivilege(user, tcComponent, "WRITE")) { + System.out.println("无权:" + tcComponent); + result = true; + break; + } + }else{ + if(getTopRefresh(childNode)) { + result = true; + break; + } + } + } + } + } + + return result; + } + + /*** + * 判断下级是否勾选 + * @param node 父级树节点 + * @param p 是否检查当前层 + * @return 下级是否勾选 + */ + private boolean getChildRefresh(DefaultMutableTreeTableNode node, boolean p) throws Exception { + if(node == null) + return false; + boolean result = false; + int count = node.getChildCount(); + for(int i = 0; !result && i < count; i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) node.getChildAt(i); + if(p) { + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1")) { + return true; + } + } + result = getChildRefresh(childNode, true); + } + return result; + } + /*** + * 上级取消勾选,下级同时取消勾选;上级勾选,下级同时勾选。对一图多物目前是不默认勾选,保持现状即可 + * @param parentNode 父级树节点 + * @param val 设置勾选值0或1 + */ + private void autoCheck(DefaultMutableTreeTableNode parentNode, String val) { + for (int i = 0; i < parentNode.getChildCount(); i++) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) parentNode.getChildAt(i); + NodeBean bean = (NodeBean) node.getUserObject(); + if(!bean.getDbom().isEmpty()) { + boolean change = true; + NodeBean eBean = null; + for (int j = 0; j < node.getChildCount(); j++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) node.getChildAt(j); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(!childBean.getEbom().isEmpty()) { + if(val.equals("0")) { + childBean.setLabel(val); + }else if(eBean == null) { + eBean = childBean; + }else { + change = false; + } + } + } + System.out.println("autoCheck:" + bean.getDbom() + "==" + change + "==" + eBean + ">>" + val); + if(val.equals("1") && eBean != null && change) { + eBean.setLabel(val); + } + autoCheck(node, val); + } + } + } + + /*** + * 判断上级是否勾选流程中对象 + * @param node + * @return + */ +// private boolean getTopProcessRefresh(DefaultMutableTreeTableNode node) { +// boolean result = false; +// //判断上层是否勾选已发布的对象 +// DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); +// if(parentNode != null) { +// DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); +// if(rootNode != null) { +// for (int i = 0; i < rootNode.getChildCount(); i++) { +// DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); +// NodeBean childBean = (NodeBean) childNode.getUserObject(); +// if(childBean.getLabel().equals("1") && childBean.getRefreshStatus().equals("流程中")) { +// result = true; +// break; +// }else { +// if(getTopProcessRefresh(childNode)) { +// result = true; +// break; +// } +// } +// } +// } +// } +// return result; +// } + + @Override + public void mousePressed(MouseEvent e) { + // Auto-generated method stub + + } + + @Override + public void mouseReleased(MouseEvent e) { + // Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) { + // Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // Auto-generated method stub + + } + + @Override + public void actionPerformed(ActionEvent e) { + // Auto-generated method stub + Object source = e.getSource(); + if (source.equals(this.okButton)) + { + //获取选中的EBOM对象 + new Thread() { + @Override + public void run() { + try { + topLineItem = null; + builder.setLength(0); + falg1 = true; +// MethodUtil.openByPass(session); + TCComponentItemType itemType = (TCComponentItemType) session + .getTypeComponent("Item"); + bomStructMap.clear(); + msg2.setLength(0); + items.clear(); + + //lidy20240914增加权限检查,避免其他人将对象发布 + DefaultMutableTreeTableNode top = (DefaultMutableTreeTableNode) node.getChildAt(0); + for(int i = 0, size = top.getChildCount(); i < size; i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) top.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1")) { + TCComponent comp = childBean.getTcComponent(); + comp.refresh(); + TCComponent[] bom = comp.getRelatedComponents("structure_revisions"); + System.out.println("top:" + comp + "==" + Arrays.toString(bom)); + if(!acs.checkAccessorsPrivilege(user, comp, "WRITE") || + bom.length > 0 && !acs.checkAccessorsPrivilege(user, bom[0], "WRITE")) { + MessageBox.post(comp + " 无编辑权限,已跳过BOM转换!", "成功", MessageBox.INFORMATION); + dispose(); + return; + } + } + } + + adaptiveVariants(top, itemType,true); + if(!builder.toString().equals("")) { + JTextArea jTextArea = new JTextArea(builder.toString()); + jTextArea.setEditable(false); + JScrollPane jScrollPane = new JScrollPane(jTextArea); + jScrollPane.setBorder(BorderFactory.createTitledBorder("存在以下情况,是否继续创建")); + jScrollPane.setPreferredSize(new Dimension(300, 100)); + int option = JOptionPane.showOptionDialog(null, jScrollPane, "", 0, 1, null, null, + Integer.valueOf(0)); + if(option!=0) { + MethodUtil.closeByPass(session); + return; + } + } +// builder.append("是否继续转换?"); + + if(!falg1) { + return; + } +// MethodUtil.closeByPass(session); + ProcessBarDialog progress = new ProcessBarDialog("正在进行BOM转换..."); + progress.open(); + + reBuildBOM(); + + progress.close(); + StringBuilder m = new StringBuilder("对象:\n"); + if(msg2.length()>0) { + m.append(msg2.deleteCharAt(msg2.length() - 1)).append(" 无编辑权限,已跳过BOM转换!"); + MessageBox.post(m.toString(), "成功", MessageBox.INFORMATION); + }else { + MessageBox.post("转换成功!", "成功", MessageBox.INFORMATION); + } + dispose(); + } catch (Exception e1) { + // Auto-generated catch block + e1.printStackTrace(); + } + + } + }.start(); + + } + else if(source.equals(this.refreshButton)) + { + this.dispose(); + try { + DbomTransitionToEbomCommand command = new DbomTransitionToEbomCommand(comp, session); + command.executeModal(); + } catch (Exception e1) { + // Auto-generated catch block + e1.printStackTrace(); + } + } + else + { + this.dispose(); + } + } + Map>> bomStructMap = + new HashMap>>(); + TCComponentBOMLine resultTopline = null; + + TCComponentItem topLineItem = null; + + + /** + * 重新搭建BOM + * + * @param topItem + * @throws TCException + */ + private void adaptiveVariants(DefaultMutableTreeTableNode tableNode, TCComponentItemType itemType, + boolean ifCreate) throws Exception { + TCComponentItem topItem = null; + //存放id相同时,更新数量 +// LinkedHashMap countMap = +// new LinkedHashMap(); +// 存放id相同时,更新数量 +// List +// LinkedHashMap pcMap = +// new LinkedHashMap(); +// ArrayList itemList = new ArrayList(); +// Map itemNumMap = new HashMap(); + + NodeBean pBean = (NodeBean) tableNode.getUserObject(); + Map> bomValMap = pBean.getBomValMap(); + System.out.println("bomValMap:" + bomValMap.toString()); + TCComponentItemRevision parentRev = pBean.getRev(); + Map> childMap = + new HashMap>(); + boolean topFlag = false; + for (int i = 0; i < tableNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) tableNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && !childBean.getEbom().isEmpty()) { + topFlag = true; +// topItem = itemType.findItems(childBean.getEbomId())[0]; + TCComponentItemRevision comp = (TCComponentItemRevision) childBean.getTcComponent(); + System.out.println("childBean:" + comp); + topItem = comp.getItem(); + for (int j = 0; j < tableNode.getChildCount(); j++) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) tableNode.getChildAt(j); + NodeBean topBean = (NodeBean) node.getUserObject(); + + if(topBean.getIsTw()) { + System.out.println("================="); + DefaultMutableTreeTableNode rootNode = topBean.getRootNode(); + NodeBean rootBean = (NodeBean) rootNode.getUserObject(); + Map> rootValMap = rootBean.getBomValMap(); +// System.out.println(topBean.getpRev()); + System.out.println(topBean.getRev()); + if(rootValMap.containsKey(topBean.getRev())) { + List list = rootValMap.get(topBean.getRev()); + childMap.put(topBean.getRev(), list); + System.out.println("list==" + list.toString()); + } + System.out.println(rootValMap.toString()); + if(topLineItem == null) { + topLineItem = topItem; + } + continue; + } + +// System.out.println(bomValMap.toString() + "pBean==" + pBean.getDbom()); + System.out.println("topBean==" + topBean.getDbom() + "==>" + topBean.getTcComponent()); + TCComponentBOMLine dbom = topBean.getBom(); + System.out.println("dbom:" + dbom + "==>" + dbom.isPacked()); + BomValBean pValBean = new BomValBean(); + pValBean.setBl_czbh(dbom.getStringProperty("bl_sequence_no")); + pValBean.setBl_jdjz(dbom.getStringProperty("bl_plmxml_abs_xform")); + pValBean.setBl_quantity(dbom.getProperty("bl_quantity")); + if(pValBean.getBl_quantity().isEmpty()) + pValBean.setBl_quantity("1"); + int index = 0; + for (int k = 0; k < node.getChildCount(); k++) { + DefaultMutableTreeTableNode childTableNode = (DefaultMutableTreeTableNode) node.getChildAt(k); + NodeBean childNodeBean = (NodeBean) childTableNode.getUserObject(); + if(childNodeBean.getLabel().equals("1")) { + if(index > 0) { + builder.append(pBean.getDbom()).append("勾选了多个物料;\n"); + } + index = index + 1; + TCComponentItemRevision nodeComp = (TCComponentItemRevision) childNodeBean.getTcComponent(); + TCComponentItem item = nodeComp.getItem(); + System.out.println("childNodeBean:" + nodeComp); +// if(childNodeBean.getEbomId() == null || childNodeBean.getEbomId().isEmpty()) { +// String dbom = childNodeBean.getDbom(); +// String id = ""; +// if(dbom.contains("-")) { +// id = dbom.substring(0, dbom.indexOf("-")); +// }else { +// id = dbom; +// } +// item = itemType.findItems(id)[0]; +// }else { +// item = itemType.findItems(childNodeBean.getEbomId())[0]; +// } + if(preList.contains(item.getType())){ + continue; + } + String num = childNodeBean.getNum(); + if(num == null || num.isEmpty() || num.equals("0")) { + num = "1"; + } +// TCComponentItemRevision latestItemRevision = item.getLatestItemRevision(); + + TCComponentItemRevision pRev = childNodeBean.getpRev(); + System.out.println("pRev:" + pRev); + if(dbom.isPacked() && bomValMap.containsKey(pRev)) { + List list = bomValMap.get(pRev); + childMap.put(nodeComp, list); + }else if(childMap.containsKey(nodeComp)) {//TODO lidy20250221 + childMap.get(nodeComp).add(pValBean); + }else { + // lidy20241211 + List list = new ArrayList<>(); + list.add(pValBean); + childMap.put(nodeComp, list); + } + + TCComponent tcComponent = childNodeBean.getTcComponent(); + Boolean jxzjBoolean = true; + if(parentRev != null) { + TCComponent rev = tcComponent; + jxzjBoolean = acs.checkAccessorsPrivilege(user, rev, "WRITE"); + if(!jxzjBoolean ) { //|| childNodeBean.getEbom().contains("55") +// System.out.println(topItem+"权限检查iiiiiiii"); + //lidy20240914没有子级的对象不提示 + boolean has = false; + for (int l = 0; l < node.getChildCount(); l++) { + DefaultMutableTreeTableNode cn = (DefaultMutableTreeTableNode) node.getChildAt(l); + NodeBean cnb = (NodeBean) cn.getUserObject(); + if(!cnb.getDbom().isEmpty()) { + has = true; + break; + } + } + if(has) + msg2.append(rev).append("、"); + if(rev instanceof TCComponentItemRevision) { + items.add(((TCComponentItemRevision)rev).getItem()); + }else if(rev instanceof TCComponentItem){ + items.add((TCComponentItem)rev); + } + } + } + if(topLineItem == null) { + topLineItem = topItem; + } + System.out.println(tcComponent + "权限检查" + jxzjBoolean); + if(!jxzjBoolean) { + continue; + } + String status = childNodeBean.getRefreshStatus(); + if(status.equals("属性发布") || status.equals("流程中") || status.equals("")) { + adaptiveVariants((DefaultMutableTreeTableNode)(childTableNode.getParent()), + itemType,true); + } + } + } + if(!topBean.getDbom().equals("") && index == 0) { + builder.append(topBean.getDbom()).append("没有勾选物料;\n"); + } + } + } + } + if(!topFlag) { + falg1 = false; + MessageBox.post("未选择顶层物料,无法创建","提示",2); + } + if(topItem != null) { + bomStructMap.put(topItem, childMap); + } + } + @SuppressWarnings("deprecation") + private void reBuildBOM() throws Exception { + + System.out.println("reBuildBOM==>" + bomStructMap.toString()); + + if(topLineItem != null) { + Map> map2 = bomStructMap.get(topLineItem); + + TCComponentBOMWindow bomWindow = null; + try { + TCComponentBOMWindowType bomWindowType = (TCComponentBOMWindowType) session + .getTypeComponent("BOMWindow"); + bomWindow = bomWindowType.create(null); + TCComponentBOMLine topline = bomWindow.setWindowTopLine(topLineItem, + topLineItem.getLatestItemRevision(), null, null); + bomWindow.lock(); + recreateBom2(topLineItem, map2, topline, bomWindow); + }catch(Exception e) { + e.printStackTrace(); + } + + bomWindow.save(); + bomWindow.unlock(); + bomWindow.refresh(); + } + + } + /** + * 重新搭建BOM遍历 + * @param bomWindow + * + * @param item + * @param itemlists + * @throws TCException + */ + @SuppressWarnings("deprecation") + private void recreateBom2(TCComponentItem topItem, + Map> map2, TCComponentBOMLine topline, TCComponentBOMWindow bomWindow) + throws Exception { +// TCComponentBOMWindow bomWindow = null; + try { + topline.refresh(); + topline.lock(); + System.out.println("items==>" + items.toString()); + List bomLines = new ArrayList(); + Set set = map2.keySet(); + + if (topline.hasChildren()) { + System.out.println(topItem); + if(items.contains(topItem)) { + return; + } + AIFComponentContext[] childrens = topline.getChildren(); + for (AIFComponentContext children : childrens) { + TCComponentBOMLine bLine = (TCComponentBOMLine) children.getComponent(); + if(bLine.isPacked()) + bLine.unpack(); + } + topline.refresh(); + childrens = topline.getChildren(); + for (AIFComponentContext children : childrens) { + TCComponentBOMLine bLine = (TCComponentBOMLine) children.getComponent(); + System.out.println("addorcut===>" + bLine); + if(bLine.getStringProperty("J6_BOM_DTE").equals("DBOM转换")) { //J6_BOM_DTE bl_ref_designator + System.out.println("cut"); + bLine.cut(); + }else { + System.out.println("add"); + bomLines.add(bLine); + } + } + }else if(set.size() > 0) {//lidy20250225 不包含BOM视图版本无法设置精确 + TCComponentItemRevision rev = (TCComponentItemRevision) set.toArray()[0]; + TCComponentItem item = rev.getItem(); + TCComponentBOMLine line = topline.add(item, rev, null, false, ""); + bomWindow.save(); + line.cut(); + bomWindow.save(); + } + String maxSeq = ""; + + System.out.println("topline===>" + topline); + topline.setPrecision(true); + for(TCComponentItemRevision rev : set) { + List list = map2.get(rev); + System.out.println("list===>" + list.toString()); + for(BomValBean bean : list) { + TCComponentItem item = rev.getItem(); + TCComponentBOMLine add = topline.add(item, rev, null, false, ""); + add.lock(); + add.setStringProperty("bl_quantity", bean.getBl_quantity()); + add.setStringProperty("bl_plmxml_abs_xform", bean.getBl_jdjz());//bl_plmxml_occ_xform + add.setStringProperty("bl_sequence_no", bean.getBl_czbh()); + System.out.println("add===>" + add + ">>>" + bean.getBl_quantity());//TODO add +// System.out.println("bean.getBl_czbh()==>" + bean.getBl_czbh()); +// System.out.println("maxSeq==>" + maxSeq); + if(maxSeq.compareTo(bean.getBl_czbh())<0) { +// System.out.println(maxSeq); + maxSeq = bean.getBl_czbh(); + } + add.setStringProperty("J6_BOM_DTE", "DBOM转换"); ////J6_BOM_DTE + add.save(); + add.unlock(); + if(bomStructMap.containsKey(item)) { + Map> map3 = bomStructMap.get(item); + recreateBom2(item, map3, add, bomWindow); + } + + } + } + if(!maxSeq.equals("")) { + Integer valueOf = Integer.valueOf(maxSeq); + for(TCComponentBOMLine bomLine : bomLines) { + bomLine.lock(); + valueOf = valueOf + 10; + bomLine.setStringProperty("bl_sequence_no", String.valueOf(valueOf)); + bomLine.save(); + bomLine.unlock(); + } + } + + topline.save(); + topline.unlock(); + topline.refresh(); + } catch (Exception e) { + // : handle exception + e.printStackTrace(); + } + + } + + /** + * 重新搭建BOM + * + * @param item + * @param itemlists + * @throws Exception + + @SuppressWarnings("deprecation") + private void recreateBom(TCComponentItemRevision topItemRev, + boolean isDelete,Map> map2) + throws Exception { + TCComponentBOMWindow bomWindow = null; + try { + TCComponentBOMWindowType bomWindowType = (TCComponentBOMWindowType) session + .getTypeComponent("BOMWindow"); + bomWindow = bomWindowType.create(null); + TCComponentBOMLine topline = bomWindow.setWindowTopLine(topItemRev.getItem(), + topItemRev, null, null); + resultTopline = topline; + bomWindow.lock(); + topline.lock(); + System.out.println("items==>"+items.toString()); + List bomLines = new ArrayList(); + if (isDelete) { + if (topline.hasChildren()) { + System.out.println(topItemRev.getItem()); + if(items.contains(topItemRev.getItem())) { + return; + } + AIFComponentContext[] childrens = topline.getChildren(); + for (AIFComponentContext children : childrens) { + TCComponentBOMLine bLine = (TCComponentBOMLine) children.getComponent(); + if(bLine.getStringProperty("J6_BOM_DTE").equals("DBOM转换")) { + bLine.cut(); + }else { + bomLines.add(bLine); + } + } + } + } + String maxSeq = ""; + for(TCComponentItemRevision rev:map2.keySet()) { + List list = map2.get(rev); + for(BomValBean bean:list) { + TCComponentBOMLine add = topline.add(rev.getItem(), rev, null, false, ""); + add.lock(); + add.setStringProperty("bl_quantity", bean.getBl_quantity()); + add.setStringProperty("bl_plmxml_occ_xform", bean.getBl_jdjz()); + add.setStringProperty("bl_sequence_no", bean.getBl_czbh()); + System.out.println("bean.getBl_czbh()==>"+bean.getBl_czbh()); + System.out.println("maxSeq==>"+maxSeq); + if(maxSeq.compareTo(bean.getBl_czbh())<0) { +// System.out.println(maxSeq); + maxSeq = bean.getBl_czbh(); + } + + add.setStringProperty("J6_BOM_DTE","DBOM转换"); + add.save(); + add.unlock(); + } + } + if(!maxSeq.equals("")) { + Integer valueOf = Integer.valueOf(maxSeq); + for(TCComponentBOMLine bomLine : bomLines) { + bomLine.lock(); + valueOf = valueOf + 10; + bomLine.setStringProperty("bl_sequence_no", String.valueOf(valueOf)); + bomLine.save(); + bomLine.unlock(); + } + } + + topline.save(); + topline.unlock(); + topline.refresh(); + if(topline.getBOMView() != null) + { + topline.getBOMView().save(); + topline.getBOMView().refresh(); + } + } catch (Exception e) { + // : handle exception + e.printStackTrace(); + } + bomWindow.save(); + bomWindow.unlock(); + bomWindow.refresh(); + }*/ + +} diff --git a/src/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomHandler.java b/src/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomHandler.java new file mode 100644 index 0000000..1bf70ff --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/ML_01/DbomTransitionToEbomHandler.java @@ -0,0 +1,30 @@ +package com.connor.ml.tcm.outfile.ML_01; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; + + +public class DbomTransitionToEbomHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + try { + DbomTransitionToEbomCommand command = new DbomTransitionToEbomCommand(app.getTargetComponent(),session); + command.executeModal(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + +} diff --git a/src/com/connor/ml/tcm/outfile/ML_01/JTreeTable.java b/src/com/connor/ml/tcm/outfile/ML_01/JTreeTable.java new file mode 100644 index 0000000..dea08e9 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/ML_01/JTreeTable.java @@ -0,0 +1,93 @@ +package com.connor.ml.tcm.outfile.ML_01; + +import java.awt.event.MouseEvent; +import java.util.List; + +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; + +import org.jdesktop.swingx.JXTreeTable; + +import com.connor.ml.tcm.outfile.bean.NodeBean; + +public class JTreeTable extends JXTreeTable { + + + /** + * + */ + private static final long serialVersionUID = 1L; + + private List isNotEditableRow; + //CheckBoxCellEditor checkBoxCellEditor = new CheckBoxCellEditor(this); + private TableCellCheckboxRenderer checkboxRenderer = new TableCellCheckboxRenderer(this); + + public List getIsNotEditableRow() { + return isNotEditableRow; + } + + public void setIsNotEditableRow(List isNotEditableRow) { + this.isNotEditableRow = isNotEditableRow; + } + + public JTreeTable(JTreeTableModel testTreeTableModel) { + // Auto-generated constructor stub + super(testTreeTableModel); + } + + @Override + public boolean isCellEditable(int arg0, int arg1) { + // Auto-generated method stub + return true;//super.isCellEditable(arg0, arg1); + } + + @Override + public TableCellEditor getCellEditor(int row, int column) { + // Auto-generated method stub + //if(isNotEditableRow.contains(row) && column == 2) + + + return cellEditor; + //return super.getCellEditor(row, column); + } + + public String getToolTipText(MouseEvent e) { + int row = this.rowAtPoint(e.getPoint()); + int col = this.columnAtPoint(e.getPoint()); + String tiptextString = null; + if (row > -1 && col > -1) { + Object value = this.getValueAt(row, col); + if (null != value && !"".equals(value)) + tiptextString = value.toString();// 悬浮显示单元格内容 + } + return tiptextString; + } + + @Override + public TableCellRenderer getCellRenderer(int row, int column) { + // Auto-generated method stub + Object val = getValueAt(row, NodeBean.LABEL); + if(column == NodeBean.LABEL && val != null && (val.equals("0") || val.equals("1"))) + { + return checkboxRenderer; + } + else + { + return super.getCellRenderer(row, column); + } + } + + // 隐藏列 + public void HiddenCell(int column) { + TableColumn tc = this.getTableHeader().getColumnModel() + .getColumn(column); + tc.setMaxWidth(0); + tc.setPreferredWidth(0); + tc.setWidth(0); + tc.setMinWidth(0); + this.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(0); + this.getTableHeader().getColumnModel().getColumn(column).setMinWidth(0); + } + +} diff --git a/src/com/connor/ml/tcm/outfile/ML_01/JTreeTableModel.java b/src/com/connor/ml/tcm/outfile/ML_01/JTreeTableModel.java new file mode 100644 index 0000000..572ed89 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/ML_01/JTreeTableModel.java @@ -0,0 +1,130 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.connor.ml.tcm.outfile.ML_01; + +import java.util.List; + +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; +import org.jdesktop.swingx.treetable.DefaultTreeTableModel; +import org.jdesktop.swingx.treetable.TreeTableNode; + +import com.connor.ml.tcm.outfile.bean.NodeBean; + +/** + * + * @author vearn + */ +public class JTreeTableModel extends DefaultTreeTableModel { + + private String[] _names = { "DBOM对象", "EBOM对象","选中", "EBOMID", "物料描述","数量","发布状态","对应父节点"}; + + + private List isNotEditableRow; + + + + public JTreeTableModel(TreeTableNode node, String[] names) { + super(node); + + _names = names; + } + + + public List getIsNotEditableRow() { + return isNotEditableRow; + } + + public void setIsNotEditableRow(List isNotEditableRow) { + this.isNotEditableRow = isNotEditableRow; + } + + /** + * 列的数量 + */ + @Override + public int getColumnCount() { + return _names.length; + } + + /** + * 表头显示的内容 + */ + @Override + public String getColumnName(int column) { + return _names[column]; + } + + /** + * 返回在单元格中显示的Object + */ + @Override + public Object getValueAt(Object node, int column) { + Object value = null; + if (node instanceof DefaultMutableTreeTableNode) { + DefaultMutableTreeTableNode mutableNode = (DefaultMutableTreeTableNode) node; + Object o = mutableNode.getUserObject(); + if (o != null && o instanceof NodeBean) { + NodeBean bean = (NodeBean) o; + value = bean.getValueAt(column); + if(column == NodeBean.LABEL && value.equals("3")) { + value = ""; + } +// if(column > 4) +// System.out.println("getValueAt" + column + "==" + value); + /*switch (column) { + case 0: + value = bean.getDbom(); + break; + case 1: + value = bean.getEbom(); + break; + case 2: + value = bean.getLabel(); + if(value.equals("3")) { + value = ""; + } + break; + case 3: + value = bean.getEbomId(); + break; + case 4: + value = bean.getEbomDesc(); + break; + case 5: + value = bean.getNum(); + break; + case 6: + value = bean.getRefreshStatus(); + break; + case 7: + value = bean.getParentString(); + break; + }*/ + } + } + return value; + } + + /** + * 设置所有单元格都不能编辑 + * + * @param the node (i.e. row) for which editing is to be determined + * @param the column for which editing is to be determined + * @return false + */ + @Override + public boolean isCellEditable(Object node, int column) { + //if(column == 5) + //{ + return true; + //} + //else + //{ + // return false; + //} + } + + +} diff --git a/src/com/connor/ml/tcm/outfile/ML_01/ProcessBarDialog.java b/src/com/connor/ml/tcm/outfile/ML_01/ProcessBarDialog.java new file mode 100644 index 0000000..de2b168 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/ML_01/ProcessBarDialog.java @@ -0,0 +1,53 @@ +package com.connor.ml.tcm.outfile.ML_01; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; + +import java.awt.Dimension; +import java.util.TimerTask; +import java.util.Timer; +import javax.swing.*; + +public class ProcessBarDialog extends JFrame { + + private JProgressBar progressBar = new JProgressBar(); + + private Box box = Box.createVerticalBox(); + + private Box box2 = Box.createHorizontalBox(); + private String name; + + public ProcessBarDialog(String name) { + this.name = name; + } + + public void open() { + this.setTitle("加载中..."); + + //需要用进程调用 + + setBounds(200, 200, 300, 100); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setLocationRelativeTo(null); + progressBar.setIndeterminate(true);// 设置进度条的样式为不确定的进度条样式(进度条来回滚动),false为确定的进度条样式(即进度条从头到尾显示) + + progressBar.setStringPainted(true);// 设置进度条显示提示信息 + + progressBar.setString(name);// 设置提示信息 + progressBar.setPreferredSize(new Dimension(300, 100)); + + box2.add(progressBar); + box.add(box2); + add(box); + this.setAlwaysOnTop(true); + setVisible(true); + } + + public void close() { + this.dispose(); + } + +} diff --git a/src/com/connor/ml/tcm/outfile/ML_01/TableCellCheckboxRenderer.java b/src/com/connor/ml/tcm/outfile/ML_01/TableCellCheckboxRenderer.java new file mode 100644 index 0000000..71895cf --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/ML_01/TableCellCheckboxRenderer.java @@ -0,0 +1,76 @@ +package com.connor.ml.tcm.outfile.ML_01; + +import java.awt.Component; +import java.util.List; + +import javax.swing.JCheckBox; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.EventListenerList; +import javax.swing.table.TableCellRenderer; + + +public class TableCellCheckboxRenderer extends JCheckBox implements + TableCellRenderer { + /** + * + */ + private static final long serialVersionUID = 1L; + private List processRows; + protected EventListenerList listenerList = new EventListenerList(); + protected ChangeEvent changeEvent = new ChangeEvent(this); + //private TestTreeTableModel tableModel; + + public List getProcessRows() { + return processRows; + } + + public void setProcessRows(List processRows) { + this.processRows = processRows; + + } + + public TableCellCheckboxRenderer(final JTreeTable table) { + + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) { + // TODO Auto-generated method stub + this.setHorizontalAlignment(SwingConstants.CENTER);// 表头标签剧中 + this.setBorderPainted(true); + + if(value != null) + { +// if(value.toString().equals("1")) +// { +// if(table.getColumnName(column).equals("改制") && hasFocus) +// { +// if(table.getValueAt(row, column + 1).toString().equals("1")) +// { +// table.setValueAt(0, row, column + 1); +// } +// } +// else if(table.getColumnName(column).equals("删除") && hasFocus) +// { +// if(table.getValueAt(row, column - 1).toString().equals("1")) +// { +// table.setValueAt(0, row, column - 1); +// } +// } +// } +// if(value.toString().equals("1")) +// { +// System.out.println(value.toString().equals("1") + "===="); +// } + this.setSelected(value.toString().equals("1")); + } + else + { + this.setSelected(false); + } + return this; + } +} \ No newline at end of file diff --git a/src/com/connor/ml/tcm/outfile/ML_01/Test.java b/src/com/connor/ml/tcm/outfile/ML_01/Test.java new file mode 100644 index 0000000..dc41215 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/ML_01/Test.java @@ -0,0 +1,8 @@ +package com.connor.ml.tcm.outfile.ML_01; + +public class Test { + public static void main(String[] args) { + String s = "11111112-32222222-4444"; + System.out.println(s.substring(0, s.indexOf("-"))); + } +} diff --git a/src/com/connor/ml/tcm/outfile/bean/NodeBean.java b/src/com/connor/ml/tcm/outfile/bean/NodeBean.java new file mode 100644 index 0000000..628a6e9 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/bean/NodeBean.java @@ -0,0 +1,165 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.connor.ml.tcm.outfile.bean; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; + +import com.connor.ml.tcm.outfile.ML_01.BomValBean; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItemRevision; + +/** + * + * @author vearn + */ +public class NodeBean { + + private String dbom;//对象ID + private String ebom;//对象名称 +// private String ebomId;//对象名称 +// private String ebomDesc;//物料描述 + private String num;//数量 + private String label;//对象名称 + private String refreshStatus;//发布状态 + private String parentString;//对应父节点 +// private String bl_plmxml_abs_xform ;//绝对变换矩阵 + private TCComponentItemRevision pRev;//对应父节点 + private TCComponentItemRevision rev;//对应父节点 + private TCComponent tcComponent; + private Boolean isTw = false; + private DefaultMutableTreeTableNode rootNode; + private Map> bomValMap = new HashMap>(); + + public static int DBOM = 0; + public static int PARENT = 1; + public static int EBOM = 2; + public static int STATUS = 3; + public static int LABEL = 4; + + private HashMap values = new HashMap<>(); + private TCComponentBOMLine bomLine; + + public Boolean getIsTw() { + return isTw; + } + public DefaultMutableTreeTableNode getRootNode() { + return rootNode; + } + public void setRootNode(DefaultMutableTreeTableNode rootNode) { + this.rootNode = rootNode; + } + public void setIsTw(Boolean isTw) { + this.isTw = isTw; + } + public TCComponent getTcComponent() { + return tcComponent; + } + public void setTcComponent(TCComponent tcComponent) { + this.tcComponent = tcComponent; + } + public TCComponentItemRevision getRev() { + return rev; + } + public void setRev(TCComponentItemRevision rev) { + this.rev = rev; + } + public TCComponentItemRevision getpRev() { + return pRev; + } + public Map> getBomValMap() { + return bomValMap; + } + public void setBomValMap(Map> bomValMap) { + this.bomValMap = bomValMap; + } + public void setpRev(TCComponentItemRevision pRev) { + this.pRev = pRev; + } +// public String getBl_plmxml_abs_xform() { +// return bl_plmxml_abs_xform; +// } +// public void setBl_plmxml_abs_xform(String bl_plmxml_abs_xform) { +// this.bl_plmxml_abs_xform = bl_plmxml_abs_xform; +// } + + public String getDbom() {//0 + return dbom; + } + public void setDbom(String dbom) {//0 + this.dbom = dbom; + setValueAt(DBOM, dbom); + } + public String getEbom() {//1 + return ebom; + } + public void setEbom(String ebom) {//1 + this.ebom = ebom; + setValueAt(EBOM, ebom); + } + public String getLabel() {//2 + return label; + } + public void setLabel(String label) {//2 + this.label = label; + setValueAt(LABEL, label); + } +// public String getEbomId() {//3 +// return ebomId; +// } +// public void setEbomId(String ebomId) {//3 +// this.ebomId = ebomId; +// } +// public String getEbomDesc() {//4 +// return ebomDesc; +// } +// public void setEbomDesc(String ebomDesc) {//4 +// this.ebomDesc = ebomDesc; +// } + public String getNum() {//5 + return num; + } + public void setNum(String num) {//5 + this.num = num; + } + public String getRefreshStatus() {//6 + return refreshStatus; + } + public void setRefreshStatus(String refreshStatus) {//6 + this.refreshStatus = refreshStatus; + setValueAt(STATUS, refreshStatus); + } + public String getParentString() {//7 + return parentString; + } + public void setParentString(String parentString) {//7 + this.parentString = parentString; + setValueAt(PARENT, parentString); + } + + public String getValueAt(int i) { + if(values.containsKey(i)) + return values.get(i); + return ""; + } + public void setValueAt(int i, String val) { + values.put(i, val); + } + + public TCComponentBOMLine getBom() { + return bomLine; + } + public void setBom(TCComponentBOMLine bomLine) { + this.bomLine = bomLine; + } + + public String toString() { + return dbom + "--" + ebom; + } +} \ No newline at end of file diff --git a/src/com/connor/ml/tcm/outfile/util/Adapter.java b/src/com/connor/ml/tcm/outfile/util/Adapter.java new file mode 100644 index 0000000..c654807 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/util/Adapter.java @@ -0,0 +1,299 @@ +package com.connor.ml.tcm.outfile.util; + +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JTable; +import javax.swing.KeyStroke; + +/** + * Adapter 实现 JTables 中的复制粘贴 剪贴板功能。 适配器所用的剪贴板数据格式 与 Excel 所用的剪贴板格式兼容。这提供了 + * 支持的 JTables 和 Excel 间的互操作。 + */ +public class Adapter implements ActionListener { + private String rowstring, value; + private Clipboard system; + private StringSelection stsel; + private JTable jTable1; + private List> selectValue = new ArrayList>(); + + /** + * Excel 适配器由 JTable 构成, 它实现了 JTable 上的复制粘贴 功能,并充当剪贴板监听程序。 + */ + + public Adapter(JTable myJTable) { + jTable1 = myJTable; + KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, + ActionEvent.CTRL_MASK, false); + + // 确定复制按键用户可以对其进行修改 + // 以实现其它按键组合的复制功能。 + KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, + ActionEvent.CTRL_MASK, false); + + // 确定粘贴按键用户可以对其进行修改 + // 以实现其它按键组合的复制功能。 + + jTable1.registerKeyboardAction(this, "Copy", copy, + JComponent.WHEN_FOCUSED); + + jTable1.registerKeyboardAction(this, "Paste", paste, + JComponent.WHEN_FOCUSED); + + system = Toolkit.getDefaultToolkit().getSystemClipboard(); + } + + /** + * 此适配器运行图表的公共读方法。 + */ + public JTable getJTable() { + return jTable1; + } + + public void setJTable(JTable jTable1) { + this.jTable1 = jTable1; + } + + /** + * 在我们监听此实现的按键上激活这种方法。 此处,它监听复制和粘贴 ActionCommands。 包含不相邻单元格的选择导致选择无效, + * 而且此后复制动作无法执行。 粘贴的方法是将选定内容的左上角与 JTable 的当前选定内容的第一个元素对齐。 + */ + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().compareTo("Copy") == 0) { + StringBuffer sbf = new StringBuffer(); + + selectValue.clear(); + // 检查以确保我们仅选择了单元格的 + // 相邻块 + int numcols = jTable1.getSelectedColumnCount(); + int numrows = jTable1.getSelectedRowCount(); + int[] rowsselected = jTable1.getSelectedRows(); + int[] colsselected = jTable1.getSelectedColumns(); + +// if (!((numrows - 1 == rowsselected[rowsselected.length - 1] +// - rowsselected[0] && numrows == rowsselected.length) && (numcols - 1 == colsselected[colsselected.length - 1] +// - colsselected[0] && numcols == colsselected.length))) { +// JOptionPane.showMessageDialog(null, "Invalid Copy Selection", +// "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE); +// +// return; +// } + + for (int i=0;i= 0) + { + sbf.append("\""); + sbf.append(jTable1.getValueAt(rowsselected[i],colsselected[j])); + sbf.append("\""); + } + else if(jTable1.getValueAt(rowsselected[i],colsselected[j]) == null) + { + sbf.append(""); + } + else + { + sbf.append(jTable1.getValueAt(rowsselected[i],colsselected[j])); + } + if (j= 0) + { + sb.append(values[i].replace("\n", " $")); + } + else + { + sb.append(values[i]); + } + //System.out.println(i+s[i]); + } + System.out.println("sb======"+sb.toString()); + String copyValue = sb.toString(); + String[] st1=copyValue.split("\\$"); //new StringTokenizer(sb.toString(),"$".toString()); + + + + int[] rows = jTable1.getSelectedRows(); + int[] columns = jTable1.getSelectedColumns(); + int startRow = rows[0]; + int startCol = columns[0]; + if(rows.length ==1 ) + { + for(int i=0;i= 0) + { + String[] cellValue = rowstring.split("\t"); + for(int j=0;j= 0) + { + String[] cellValue = rowstring.split("\t"); + for (int k = 0; k < cellValue.length; k++) { + value=(String)cellValue[k]; + System.out.println("value============"+value); + jTable1.setValueAt(value.trim(),rows[i],startCol+k); + System.out.println("Putting "+ value+"atrow="+startRow+i+"column="+startCol+k); + } + } + else + { + jTable1.setValueAt(rowstring.trim(),rows[i],startCol); + } + //} + //} + } + } + else //写入选中行内容 + { + for(int i=0;i= 0) + { + String[] cellValue = rowstring.split("\t"); + for(int j=0;j st1.length) + { + for (int i = 0; i < rows.length; i++) { + for (int j = 0; j < columns.length; j++) { + rowstring=st1[(i+st1.length)%st1.length]; + System.out.println("rowstring============"+rowstring); + if(rowstring.indexOf("\t") >= 0) + { + String[] cellValue = rowstring.split("\t"); + for (int k = 0; k < cellValue.length; k++) { + value=(String)cellValue[(j+cellValue.length)%cellValue.length]; + System.out.println("value============"+value); + jTable1.setValueAt(value.trim(),rows[i],columns[j]); + System.out.println("Putting "+ value+"atrow="+startRow+i+"column="+startCol+k); + } + } + else + { + jTable1.setValueAt(rowstring.trim(),rows[i],columns[j]); + } + } + } + } + else + { + for (int i = 0; i < st1.length; i++) { + for (int j = 0; j < columns.length; j++) { + rowstring=st1[(i+st1.length)%st1.length]; + System.out.println("rowstring============"+rowstring); + if(rowstring.indexOf("\t") >= 0) + { + String[] cellValue = rowstring.split("\t"); + for (int k = 0; k < cellValue.length; k++) { + value=(String)cellValue[(j+cellValue.length)%cellValue.length]; + System.out.println("value============"+value); + jTable1.setValueAt(value.trim(),startRow+i,columns[j]); + System.out.println("Putting "+ value+"atrow="+startRow+i+"column="+startCol+k); + } + } + else + { + jTable1.setValueAt(rowstring.trim(),startRow+i,columns[j]); + } + } + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + } + } +} \ No newline at end of file diff --git a/src/com/connor/ml/tcm/outfile/util/JAutoCompleteComboBox.java b/src/com/connor/ml/tcm/outfile/util/JAutoCompleteComboBox.java new file mode 100644 index 0000000..3024722 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/util/JAutoCompleteComboBox.java @@ -0,0 +1,171 @@ +package com.connor.ml.tcm.outfile.util; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.util.List; +import java.util.Vector; + +import javax.swing.ComboBoxModel; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JTextField; + +@SuppressWarnings({ "serial", "rawtypes", "unchecked" }) +public class JAutoCompleteComboBox extends JComboBox { + private AutoCompleter completer; + private String propName; + + public JAutoCompleteComboBox() { + super(); + addCompleter(); + } + + public JAutoCompleteComboBox(ComboBoxModel cm) { + super(cm); + addCompleter(); + } + + public JAutoCompleteComboBox(Object[] items) { + super(items); + addCompleter(); + } + + public JAutoCompleteComboBox(List v) { + super((Vector) v); + addCompleter(); + } + + + + public String getPropName() { + return propName; + } + + public void setPropName(String propName) { + this.propName = propName; + } + + private void addCompleter() { + setEditable(true); + completer = new AutoCompleter(this); + } + + public void autoComplete(String str) { + this.completer.autoComplete(str, str.length()); + } + + public String getText() { + return ((JTextField) getEditor().getEditorComponent()).getText(); + } + + public void setText(String text) { + ((JTextField) getEditor().getEditorComponent()).setText(text); + } + + public boolean containsItem(String itemString) { + for (int i = 0; i < this.getModel().getSize(); i++) { + String _item = " " + this.getModel().getElementAt(i); + if (_item.equals(itemString)) + return true; + } + return false; + } + +} + +@SuppressWarnings({"rawtypes"}) +class AutoCompleter implements KeyListener, ItemListener { + + private JComboBox owner = null; + private JTextField editor = null; + + private ComboBoxModel model = null; + + public AutoCompleter(JComboBox comboBox) { + owner = comboBox; + editor = (JTextField) comboBox.getEditor().getEditorComponent(); + editor.addKeyListener(this); + model = comboBox.getModel(); + owner.addItemListener(this); + } + + public void keyTyped(KeyEvent e) { + } + + public void keyPressed(KeyEvent e) { + } + + @SuppressWarnings("unused") + public void keyReleased(KeyEvent e) { + char ch = e.getKeyChar(); + // if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch) + // || ch == KeyEvent.VK_DELETE) + // return; + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + int caretPosition = editor.getCaretPosition(); + String str = editor.getText(); + if (str.length() == 0) + return; + autoComplete(str, caretPosition); + } + } + + @SuppressWarnings({ "unchecked", "unused" }) + protected void autoComplete(String strf, int caretPosition) { + Object[] opts; + opts = getMatchingOptions(strf.substring(0, caretPosition)); + if (owner != null) { + model = new DefaultComboBoxModel(opts); + owner.setModel(model); + } + if (opts.length > 0) { + String str = opts[0].toString(); + editor.setCaretPosition(caretPosition); + if (owner != null) { + try { + owner.showPopup(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + } + + @SuppressWarnings("unchecked") + protected Object[] getMatchingOptions(String str) { + List v = new Vector(); + List v1 = new Vector(); + // v.add(str); + for (int k = 0; k < model.getSize(); k++) { + Object itemObj = model.getElementAt(k); + if (itemObj != null) { + String item = itemObj.toString().toLowerCase(); + if (item.indexOf((str.toLowerCase())) > -1) + v.add(model.getElementAt(k)); + else + v1.add(model.getElementAt(k)); + } else + v1.add(model.getElementAt(k)); + } + for (int i = 0; i < v1.size(); i++) { + v.add(v1.get(i)); + } + // if (v.isEmpty()) + return v.toArray(); + } + + public void itemStateChanged(ItemEvent event) { + if (event.getStateChange() == ItemEvent.SELECTED) { + int caretPosition = editor.getCaretPosition(); + if (caretPosition != -1) { + try { + editor.moveCaretPosition(caretPosition); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } + } + } + } +} \ No newline at end of file diff --git a/src/com/connor/ml/tcm/outfile/util/MethodUtil.java b/src/com/connor/ml/tcm/outfile/util/MethodUtil.java new file mode 100644 index 0000000..8df1412 --- /dev/null +++ b/src/com/connor/ml/tcm/outfile/util/MethodUtil.java @@ -0,0 +1,868 @@ +package com.connor.ml.tcm.outfile.util; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +import javax.swing.JOptionPane; + + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +import com.teamcenter.rac.kernel.TCClassificationService; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentICO; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCComponentProcess; +import com.teamcenter.rac.kernel.TCComponentProcessType; +import com.teamcenter.rac.kernel.TCComponentTaskTemplate; +import com.teamcenter.rac.kernel.TCComponentTaskTemplateType; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.kernel.ics.ICSKeyLov; +import com.teamcenter.rac.kernel.ics.ICSProperty; +import com.teamcenter.rac.kernel.ics.ICSPropertyDescription; +import com.teamcenter.rac.kernel.ics.ICSSearchResult; +import com.teamcenter.rac.util.MessageBox; +//import com.teamcenter.services.rac.core.DataManagementService; + +//import net.sf.json.JSONArray; +//import net.sf.json.JSONObject; + +public class MethodUtil { + + private static final String SEP1 = ","; + + /** + * 同步超级BOM + * + * @param session session + * @param process 流程对象 + * @param processUser 节点负责人首选项的值 + * @param arctic 车型 + * @throws TCException + */ + public static void sendBom(TCSession session, TCComponentItemRevision itemRevision) throws TCException { + + TCUserService userservice = session.getUserService(); + + Object[] obj = new Object[1]; + obj[0] = itemRevision; + userservice.call("Super_Bom_Appent_Data", obj); + } + + /** + * 根据规则获取ID + * + * @param oldItemID 旧的ID + * @return 新的ID + */ + public static String getRuleItemID(TCSession session, String oldItemID) { + // String[] oldItemIDs = oldItemID.split("-"); + DecimalFormat df = new DecimalFormat("000"); + // String newID = oldItemIDs[0] + "-" + oldItemIDs[1] + "-001"; + String newID = oldItemID + "-001"; + // String idTemp = + TCComponentItemType tccomponentitemtype; + try { + tccomponentitemtype = (TCComponentItemType) (session.getTypeComponent("Item")); + + tccomponentitemtype.getNewID(); + int i = 1; + while (tccomponentitemtype.find(newID) != null) { + i++; + // newID = oldItemIDs[0] + "-" + oldItemIDs[1] + "-"+ df.format(i); + newID = oldItemID + "-" + df.format(i); + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return newID; + } + + /** + * List转换String + * + * @param list :需要转换的List + * @return String转换后的字符串 + */ + public static String ListToString(List list) { + + StringBuffer sb = new StringBuffer(); + if (list != null && list.size() > 0) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i) == null || list.get(i) == "") { + continue; + } + // 如果值是list类型则调用自己 + if (list.get(i) instanceof List) { + sb.append(ListToString((List) list.get(i))); + sb.append(SEP1); + } else { + sb.append(list.get(i)); + sb.append(SEP1); + } + } + } + return sb.toString(); + } + +// // 获取组的lov值 +// public static String getGroupLov(TCSession session, String lovName, String key) { +// try { +// // 获取lov +// TCComponentListOfValues rtlistOfValues = TCLOVUtil.findLOVByName(session, "TM2_GROUP"); +// ListOfValuesInfo rtlistOfValuesInfo = rtlistOfValues.getListOfValues(); +// String[] groupName = rtlistOfValuesInfo.getStringListOfValues(); +// String[] groupDisplayName = rtlistOfValuesInfo.getLOVDisplayValues(); +// for (int i = 0; i < groupName.length; i++) { +// if (groupName[i].equals(key)) { +// return groupDisplayName[i]; +// } +// +// } +// } catch (TCException e) { +// MessageBox.post("获取组的LOV错误!请联系系统管理员!", "错误!", MessageBox.ERROR); +// e.printStackTrace(); +// } +// return ""; +// } + + /** + * 获取模板文件 + * @param session session + * @param fileName 文件名 + * @param Filetype 文件类型 + * @return + */ + public static File getFile(TCSession session,String fileName,String Filetype) { + // TODO Auto-generated method stub + try { + TCPreferenceService service = session.getPreferenceService(); + String[] modelFiles = service.getStringValues("ML_Doc_Teamplate"); + if (modelFiles == null) + { + System.out.println("未找到首选项"); + return null; + } + String itemId = ""; + for (int i = 0; i < modelFiles.length; i++) { + if(modelFiles[i].split(":")[0].equals(fileName)) + { + itemId = modelFiles[i].split(":")[1]; + } + } + TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent("Item"); + TCComponentItem fileItem = itemType.find(itemId); + TCComponentDataset dat = null; + TCComponentItemRevision fileItemLastRev = getLastItemRevision(fileItem); + TCComponent[] comps = fileItemLastRev.getReferenceListProperty("IMAN_specification"); + System.out.println("count =" + comps == null ? "null" + : comps.length); + // 遍历TC_Attaches关系下的所有对象 + for (TCComponent compt : comps) { + // 获取对象类型 + String type = compt.getType(); + System.out.println(" TYPE = " + type); + // 判断类型 + if (type.equals(type)) { + dat = (TCComponentDataset)compt; + } + } + TCComponentTcFile[] tcFile = dat.getTcFiles(); + if(tcFile != null && tcFile.length == 0) + { + System.out.println("未找到配置文件"); + } + else + { + return tcFile[0].getFmsFile(); + } + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + return null; + } + + /** + * 获取最新的已发布的版本 + * + * @param item + * @return + */ + public static TCComponentItemRevision getLastItemRevision(TCComponentItem item) { + // TODO Auto-generated method stub + try { + TCComponentItemRevision[] items = item.getReleasedItemRevisions(); + int revId = 0; + TCComponentItemRevision itemRevision = null; + for (int i = 0; i < items.length; i++) { + String revisionId = items[i].getStringProperty("item_revision_id"); + if (letterToNumber(revisionId) >= revId) { + itemRevision = items[i]; + revId = letterToNumber(revisionId); + } + } + return itemRevision; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + // 字母转数字 A-Z :1-26 + public static int letterToNumber(String letter) { + int length = letter.length(); + int num = 0; + int number = 0; + for (int i = 0; i < length; i++) { + char ch = letter.charAt(length - i - 1); + num = (int) (ch - 'A' + 1); + num *= Math.pow(26, i); + number += num; + } + return number; + } + + /** + * 根据LOV名称获取LOV + * + * @param tcsession + * @param s + * @return + */ + + + /** + * 根据LOV Key获取LOV值 + * + * @param tcsession + * @param s + * @return + */ + public static String findLovValueByKey(TCSession tcsession, String s, String key) { + TCComponentListOfValues tccomponentlistofvalues = null; + String resultValue = null; + try { + TCComponentListOfValuesType tccomponentlistofvaluestype = (TCComponentListOfValuesType) tcsession + .getTypeComponent("ListOfValues"); + TCComponentListOfValues atccomponentlistofvalues[] = tccomponentlistofvaluestype.find(s); + if (atccomponentlistofvalues != null && atccomponentlistofvalues.length > 0) { + tccomponentlistofvalues = atccomponentlistofvalues[0]; + + ListOfValuesInfo rtlistOfValuesInfo = tccomponentlistofvalues.getListOfValues(); + + String[] groupName = rtlistOfValuesInfo.getStringListOfValues(); + String[] groupDisplayName = rtlistOfValuesInfo.getLOVDisplayValues(); + + for (int i = 0; i < groupName.length; i++) { + // resultMap.put(groupDisplayName[i],groupName[i]); + if (groupName[i].equals(key)) { + resultValue = groupDisplayName[i]; + } + } + } + } catch (TCException tcexception) { + tccomponentlistofvalues = null; + } + return resultValue; + } + + /** + * 指派流程负责人 + * + * @param session session + * @param process 流程对象 + * @param processUser 节点负责人首选项的值 + * @param arctic 车型 + * @throws TCException + */ + public static void setProcess(TCSession session, TCComponentProcess process, String processUser, String arctic) + throws TCException { + + TCUserService userservice = session.getUserService(); + + Object[] obj = new Object[3]; + obj[0] = process; + obj[1] = processUser; + obj[2] = arctic; + userservice.call("DMU_Review_Process", obj); + } + + /** + * 指派适应性改型流程负责人 + * + * @param session session + * @param process 流程对象 + * @param processUser 节点负责人 + * @param arctic 车型 + * @throws TCException + */ + public static void setRemodelProcess(TCSession session, TCComponentProcess process, String processUser, + String arctic) throws TCException { + + TCUserService userservice = session.getUserService(); + + Object[] obj = new Object[3]; + obj[0] = process; + obj[1] = processUser; + obj[2] = arctic; + userservice.call("Create_Remodel_Process", obj); + } + + /** + * 获取单值得首选项 + * + * @param prefName + * @return + */ + public static String getPrefStr(String prefName) { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + TCPreferenceService service = session.getPreferenceService(); + String str = service.getString(TCPreferenceService.TC_preference_site, prefName); + if (str == null) { + str = new String(""); + } + return str; + } + + /*** + * 获取首选项 + * + * @param session 会话 + * @param preferenceName 首选项名称 + * @return + */ + public static String[] getPreferenceValues(String preferenceName) { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + if (preferenceName == null || session == null) { + System.out.println(""); + return null; + } + String[] values = null; + TCPreferenceService service = session.getPreferenceService(); + values = service.getStringArray(TCPreferenceService.TC_preference_site, preferenceName); + String[] resultValues = new String[values.length]; + for (int i = 0; i < values.length; i++) { + if (values[i].indexOf("\\n") >= 0) { + resultValues[i] = values[i].replace("\\n", "\n"); + } else { + resultValues[i] = values[i]; + } + } + return resultValues; + } + + /*** + * 获取首选项 + * + * @param session 会话 + * @param preferenceName 首选项名称 + * @return + */ + public static String getPreferenceValue(String preferenceName) { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + if (preferenceName == null || session == null) { + System.out.println(""); + return null; + } + TCPreferenceService service = session.getPreferenceService(); + return service.getString(TCPreferenceService.TC_preference_site, preferenceName); + } + + public static void setByPass(boolean val,TCSession session) { + try { + TCUserService userservice = session.getUserService(); + userservice.call(val ? "CONNOR_open_bypass" : "CONNOR_close_bypass", new Object[] { "" }); + System.out.println(val ? "Open Bypass" : "Close Bypass"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void openByPass(TCSession session) throws TCException { + TCUserService userservice = session.getUserService(); + Object[] obj = new Object[1]; + obj[0] = "origin"; + userservice.call("CONNOR_open_bypass", obj); + } + + public static void closeByPass(TCSession session) throws TCException { + TCUserService userservice = session.getUserService(); + Object[] obj = new Object[1]; + obj[0] = "origin"; + userservice.call("CONNOR_close_bypass", obj); + } + public static void setProperty(TCSession session,TCComponent[] items,String propname,String propvalue) throws TCException { + TCUserService userservice = session.getUserService(); + Object[] obj = new Object[3]; + obj[0] = items; + obj[1] = propname; + obj[2] = propvalue; + userservice.call("connor_set_prop_value", obj); + } + + /*** + * 发送对象到分类(通过webService) + * + * @param codeRemark 分类ID + * @param rev 版本对象 + * @param propList 分类属性 + */ + + + /*** + * 将对象从分类中移除(通过webService) + * + * @param codeRemark 分类对象的UID + */ + + + /*** + * @param matnr 物料号 + * @param ddlx 订单类型 + * @param type 流程中订单、历史订单、废弃订单 + * @return 返回分类id + */ + public static String getClassficationId(String matnr, String ddlx, String type) { + // String classId = "jlcs01010101"; + String classId = ""; + if (ddlx.equals("车身") || ddlx.equals("KD")) { + String[] values = getPreferenceValues("JL_number_to_className"); + String className = null; + + for (String s : values) { + String[] split = s.split("="); + if (split[0].equals(matnr)) { + className = split[1]; + break; + } + } + String[] values2 = getPreferenceValues("JL_name_to_id"); + // split[1]--历史,split[2]--流程 split[3]--废弃 + for (String t : values2) { + String[] split = t.split("="); + if (split[0].equals(className)) { + if (type.equals("历史订单")) { + classId = split[1]; + } else if (type.equals("流程中订单")) { + classId = split[2]; + } else if (type.equals("废弃订单")) { + classId = split[3]; + } + } + } + } else if (ddlx.equals("配件")) { + classId = "jlcs01010201"; + String name = matnr.substring(0, 2) + "配件"; + String[] values = getPreferenceValues("JL_name_to_id"); + for (String t : values) { + String[] split = t.split("="); + if (split[0].equals(name)) { + if (type.equals("历史订单")) { + classId = split[1]; + } else if (type.equals("流程中订单")) { + classId = split[2]; + } else if (type.equals("废弃订单")) { + classId = split[3]; + } + } + } + } + + return classId; + } + + /** + * 获取分类属性LOV显示值 + * + * @param icsD + * @return + */ + public static String getClassDisplayableValue(String value, ICSPropertyDescription icsD) { + String result = ""; + ICSKeyLov lov1 = icsD.getFormat().getKeyLov(); + if (lov1 != null) { + String[] keys = lov1.getKeys(); + for (String key : keys) { + if (value.equals(key)) { + result = lov1.getValueOfKey(key); + return result; + } + } + } + return result; + } + + public static boolean isDouble(String value) { + try { + Double.parseDouble(value); + return true; + } catch (Exception e) { + // TODO: handle exception + return false; + } + } + + /*** + * 判断是否有权限 + * + * @param session session + * @param value 首选项名称 + * @param userId 用户ID + * @return + */ + public static boolean havePrivilege(TCSession session, String commandName, String userId) { + TCPreferenceService service = session.getPreferenceService(); + + String[] values = service.getStringArray(TCPreferenceService.TC_preference_site, "JL_User_Rights"); + if (values == null || values.length == 0) { + MessageBox.post("请配置首选项(管理权限)!请联系管理员", "错误", MessageBox.ERROR); + return false; + } + for (String value : values) { + // value = commandName + "——" + userId + String[] split = value.split("——"); + if (split[0].equals(commandName)) { + if (split.length == 1) { + return true; + } else { + if (split[1].indexOf(userId) >= 0) { + return true; + } else { + return false; + } + } + } + } + return false; + } + + public static int getCount(String mainStr, String subStr) { + int minLength = mainStr.length(); + int subLength = subStr.length(); + int count = 0; + int index = 0; + + if (minLength >= subLength) { + while ((index = mainStr.indexOf(subStr, index)) != -1) { + count++; + index += subLength; + } + return count; + } + return 0; + } + + /** + * 添加命名的引用 + * + * @param session + * @param item 对象的版本 + * @param fileName 数据集名称 + * @param tcResource 文件的物理路径 + * @param isDelete 是否删除文件 + * @param isReplace 是否删除原因数据集 + */ + public static void setExcelToItem(TCSession session, TCComponentItemRevision item,String fileName, String tcResource, + boolean isDelete,boolean isReplace) { + try { + String as1[] = { tcResource };// 文件的物理路径 + String as2[] = { "excel" }; + String as3[] = { "MSExcelX" }; + String as4[] = { "Plain" }; + TCComponentDatasetType tccomponentDatasetType = (TCComponentDatasetType) session + .getTypeComponent("Dataset"); + TCComponentDataset tccomponentDataset = tccomponentDatasetType.create(fileName, "excel", "MSExcelX"); + tccomponentDataset.setFiles(as1, as3, as4, as2); + //是否替換 + if(isReplace) + { + AIFComponentContext[] zyzdsChildrens = item.getChildren(); + TCComponentItemRevision zyzdsRev = item; + for (AIFComponentContext zyzdsChildren : zyzdsChildrens) { + if ("MSExcelX".equals(zyzdsChildren.getComponent().getType())) { + TCComponentDataset dateSet = (TCComponentDataset) zyzdsChildren.getComponent(); + zyzdsRev.remove("IMAN_specification", dateSet); + dateSet.delete(); + } + } + } + item.add("IMAN_specification", tccomponentDataset); + if (isDelete) { + new File(tcResource).delete(); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static Object getTCPropertyValue(TCComponent item,String propertyName) + { + Object result = ""; + + try { + TCProperty tcProperty = item.getTCProperty(propertyName); + if(tcProperty == null) + { + System.out.println("未获取属性:"+propertyName); + return result; + } + switch (tcProperty.getPropertyType()) { + case TCProperty.PROP_double: + result = tcProperty.getDoubleValue(); + break; + case TCProperty.PROP_int: + result = tcProperty.getIntValue(); + break; + case TCProperty.PROP_string: + result = tcProperty.getStringValue(); + break; + case TCProperty.PROP_date: + result = tcProperty.getDateValue(); + break; + default: + break; + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return result; + } + public static void setTCPropertyValue(TCComponent item,String propertyName,Object value) + { + try { + TCProperty tcProperty = item.getTCProperty(propertyName); + switch (tcProperty.getPropertyType()) { + case TCProperty.PROP_double: + if(value instanceof Double) + { + tcProperty.setDoubleValue((double) value); + } + else + { + tcProperty.setDoubleValue(Double.parseDouble(value.toString())); + } + break; + case TCProperty.PROP_int: + if(value instanceof Integer) + { + tcProperty.setIntValue((int) value); + } + else + { + tcProperty.setIntValue(Integer.parseInt(value.toString())); + } + break; + case TCProperty.PROP_string: + tcProperty.setStringValue(value.toString()); + break; + case TCProperty.PROP_date: + if(value instanceof Date) + { + tcProperty.setDateValue((Date) value); + } + else + { + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-M-dd HH:mm"); + tcProperty.setDateValue(sdf.parse(value.toString())); + } + break; + default: + break; + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** + * 获取选取的ITEM的目标的信息 + * + * @param itemList + * @return + */ + + + /** + * 获取存放的文件夹 + * + * @param item + * @param name + * @return + */ + public static TCComponentFolder getParentFolder(TCComponentItem item, + String name) { + TCComponentFolder folder = null; + try { + AIFComponentContext[] comtexts = item.whereReferenced(); + if (comtexts != null) { + for (int i = 0; i < comtexts.length; i++) { + if (comtexts[i].getComponent() instanceof TCComponentFolder) { + String nameT = ((TCComponentFolder) comtexts[i] + .getComponent()) + .getStringProperty("object_name"); + if (name.equals("工艺图纸") && nameT.equals("工艺图纸")) { + folder = (TCComponentFolder) comtexts[i] + .getComponent(); + } + else if(nameT.equals(name)) + { + folder = (TCComponentFolder) comtexts[i] + .getComponent(); + } + } + } + } + } catch (TCException e) { + e.printStackTrace(); + } + return folder; + } + + /** + * 过滤掉所有不需要显示的属性的 + * + * @param session + * @return + */ + + + /** + * 通过SOA创建ITEM对象 + * + * @param session + * 会话 + * @param itemID + * 创建对象的ID + * @param itemRev + * 创建对象的版本 + * @param itemType + * 创建对象的类型 + * @param itemName + * 创建对象的名称 + * @param itemDesc + * 创建对象的描述 + * @param unit + * 创建对象的单位 + * @param itemPropMap + * 创建对象的ITEM属性 + * @param itemRevPropMap + * 创建对象的版本属性 + * @param itemRevMasterPropMap + * 创建对象的版本表单属性 + */ + + + public static void CreateProcess(TCSession session,TCComponent target,String processName) throws TCException { + try { + TCComponentProcessType processType = (TCComponentProcessType) session.getTypeComponent("Job"); + TCComponentTaskTemplateType taskTemplateType = (TCComponentTaskTemplateType) session.getTypeComponent("EPMTaskTemplate"); + TCComponentTaskTemplate taskTemplate = taskTemplateType.find(processName, TCComponentTaskTemplate.PROCESS_TEMPLATE_TYPE); + if (taskTemplate == null) { + return; + } + // 创建一个流程 流程名称、描述、流程模板、目标对象、附件数 + String name = target.getProperty("object_string"); + processType.create(processName + ":" + name, "", taskTemplate, new TCComponent[] { target }, new int[] { 1 }); + } catch (TCException e) { + e.printStackTrace(); + throw e; + } + } + + public static void CreateProcess(TCSession session,TCComponent[] targets,int[] type,String processName) throws TCException { + try { + TCComponentProcessType processType = (TCComponentProcessType) session.getTypeComponent("Job"); + TCComponentTaskTemplateType taskTemplateType = (TCComponentTaskTemplateType) session.getTypeComponent("EPMTaskTemplate"); + TCComponentTaskTemplate taskTemplate = taskTemplateType.find(processName, TCComponentTaskTemplate.PROCESS_TEMPLATE_TYPE); + if (taskTemplate == null) { + return; + } + // 创建一个流程 流程名称、描述、流程模板、目标对象、附件数 + String name = targets[0].getProperty("object_string"); + processType.create(processName + ":" + name, "", taskTemplate, targets, type); + } catch (TCException e) { + e.printStackTrace(); + throw e; + } + } + + + + + /** + * 读取EXCEL表 + * + * @param File excel_file + * @return List 返回的信息 + * @throws IOException + * @throws FileNotFoundException + */ + + + + + /** + * 读取EXCEL表 + * + * @param File excel_file + * @return List 返回的信息 + * @throws IOException + * @throws FileNotFoundException + */ + + + + + /** + * 读取EXCEL表 + * + * @param File excel_file + * @return List 返回的信息 + * @throws IOException + * @throws FileNotFoundException + */ + + +}