commit 65e10fc4223e42391b1817ec535a4ab9f3bac840 Author: hongcj Date: Mon Apr 29 17:59:50 2024 +0800 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..0269a62 --- /dev/null +++ b/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..bf758ad --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/applauncher.xml b/.idea/libraries/applauncher.xml new file mode 100644 index 0000000..96785cd --- /dev/null +++ b/.idea/libraries/applauncher.xml @@ -0,0 +1,443 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/plugins.xml b/.idea/libraries/plugins.xml new file mode 100644 index 0000000..1dff864 --- /dev/null +++ b/.idea/libraries/plugins.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ba93b15 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..88bd588 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..71bae37 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com.fh.sap + + + + + + 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..9f6ece8 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +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.release=disabled +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..9e19762 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,89 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: fh.sap +Bundle-SymbolicName: com.fh.sap;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Vendor: fh +Require-Bundle: org.eclipse.ui, + com.teamcenter.rac.util;bundle-version="8000.3.0", + com.teamcenter.rac.aifrcp;bundle-version="8000.3.0", + TcSoaCoreRac;bundle-version="8000.3.0", + com.teamcenter.rac.common;bundle-version="8000.3.0", + com.teamcenter.rac.ui;bundle-version="8000.3.0", + com.teamcenter.rac.tcapps;bundle-version="8000.3.0", + com.teamcenter.rac.kernel;bundle-version="8000.3.0", + com.teamcenter.rac.workflow.processdesigner;bundle-version="8000.3.0", + org.eclipse.core.runtime;bundle-version="3.5.0", + org.eclipse.osgi.services;bundle-version="3.2.0" +Automatic-Module-Name: com.connor.ld.importSJ +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: lib/fastjson-1.2.66.jar, + ., + lib/okhttp-2.7.4.jar, + lib/okio-1.13.0.jar, + lib/sqljdbc4.jar, + lib/sapjco3.jar, + lib/fastjson2-2.0.34.jar, + lib/jackson-annotations-2.15.0.jar, + lib/jackson-core-2.15.2.jar, + lib/jackson-databind-2.15.0.jar, + lib/mssql-jdbc-7.0.0.jre8.jar, + lib/ojdbc7.jar, + lib/poi-3.7-20101029.jar, + lib/poi-4.1.2.jar, + lib/poi-examples-3.7-20101029.jar, + lib/poi-ooxml-3.7-20101029.jar, + lib/poi-ooxml-schemas-3.7-20101029.jar, + lib/gson-2.8.5.jar, + lib/datepicker.jar, + lib/mybatis-3.4.6.jar, + lib/activation-1.1.jar, + lib/antlr-2.7.7.jar, + lib/apache-commons-codec-1.4.jar, + lib/apache-mime4j-core-0.7.2.jar, + lib/axiom-api-1.2.13.jar, + lib/axiom-dom-1.2.13.jar, + lib/axiom-impl-1.2.13.jar, + lib/axis2-adb-1.6.2.jar, + lib/axis2-adb-codegen-1.6.2.jar, + lib/axis2-ant-plugin-1.6.2.jar, + lib/axis2-clustering-1.6.2.jar, + lib/axis2-codegen-1.6.2.jar, + lib/axis2-corba-1.6.2.jar, + lib/axis2-fastinfoset-1.6.2.jar, + lib/axis2-java2wsdl-1.6.2.jar, + lib/axis2-jaxbri-1.6.2.jar, + lib/axis2-jaxws-1.6.2.jar, + lib/axis2-jibx-1.6.2.jar, + lib/axis2-json-1.6.2.jar, + lib/axis2-kernel-1.6.2.jar, + lib/axis2-metadata-1.6.2.jar, + lib/axis2-mtompolicy-1.6.2.jar, + lib/axis2-saaj-1.6.2.jar, + lib/axis2-soapmonitor-servlet-1.6.2.jar, + lib/axis2-spring-1.6.2.jar, + lib/axis2-transport-http-1.6.2.jar, + lib/axis2-transport-local-1.6.2.jar, + lib/axis2-xmlbeans-1.6.2.jar, + lib/json-lib-2.2.2-jdk15.jar, + lib/aspose-cells-18.9.jar, + lib/commons-codec-1.13.jar, + lib/commons-collections4-4.4.jar, + lib/commons-compress-1.19.jar, + lib/commons-lang3-3.9.jar, + lib/commons-logging-1.2.jar, + lib/commons-math3-3.6.1.jar, + lib/fastjson-1.2.9.jar, + lib/hutool-all-5.0.7.jar, + lib/jaxb-api-2.3.1.jar, + lib/jaxb-core-2.3.0.1.jar, + lib/jaxb-impl-2.3.2.jar, + lib/jfxrt.jar, + lib/ojdbc6.jar, + lib/poi-4.1.1.jar, + lib/poi-examples-4.1.1.jar, + lib/poi-excelant-4.1.1.jar, + lib/poi-ooxml-4.1.1.jar, + lib/poi-ooxml-schemas-4.1.1.jar, + lib/poi-scratchpad-4.1.1.jar, + lib/xmlbeans-3.1.0.jar diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..c2d9872 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/com/ diff --git a/bin/sapconnect.properties b/bin/sapconnect.properties new file mode 100644 index 0000000..e3b241b --- /dev/null +++ b/bin/sapconnect.properties @@ -0,0 +1,13 @@ +#\u6D4B\u8BD5\u7CFB\u7EDF +JCO_ASHOST_STR=10.10.22.14 +JCO_SYSNR_STR=00 +JCO_CLIENT_STR=400 +JCO_USER_STR=LDIT001 +JCO_PASSWD_STR=LDIT@2022 +#JCO_ASHOST_STR=10.200.1.192 +#JCO_SYSNR_STR=00 +#JCO_CLIENT_STR=800 +#JCO_USER_STR=SAP_TC +#JCO_PASSWD_STR=Sap_RFC2020 + + diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..a5f727b --- /dev/null +++ b/build.properties @@ -0,0 +1,75 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + lib/fastjson-1.2.66.jar,\ + lib/okhttp-2.7.4.jar,\ + lib/okio-1.13.0.jar,\ + lib/sqljdbc4.jar,\ + lib/sapjco3.jar,\ + lib/fastjson2-2.0.34.jar,\ + lib/jackson-annotations-2.15.0.jar,\ + lib/jackson-core-2.15.2.jar,\ + lib/jackson-databind-2.15.0.jar,\ + lib/mssql-jdbc-7.0.0.jre8.jar,\ + lib/ojdbc7.jar,\ + lib/poi-3.7-20101029.jar,\ + lib/poi-4.1.2.jar,\ + lib/poi-examples-3.7-20101029.jar,\ + lib/poi-ooxml-3.7-20101029.jar,\ + lib/poi-ooxml-schemas-3.7-20101029.jar,\ + lib/gson-2.8.5.jar,\ + lib/datepicker.jar,\ + lib/mybatis-3.4.6.jar,\ + lib/activation-1.1.jar,\ + lib/antlr-2.7.7.jar,\ + lib/apache-commons-codec-1.4.jar,\ + lib/apache-mime4j-core-0.7.2.jar,\ + lib/axiom-api-1.2.13.jar,\ + lib/axiom-dom-1.2.13.jar,\ + lib/axiom-impl-1.2.13.jar,\ + lib/axis2-adb-1.6.2.jar,\ + lib/axis2-adb-codegen-1.6.2.jar,\ + lib/axis2-ant-plugin-1.6.2.jar,\ + lib/axis2-clustering-1.6.2.jar,\ + lib/axis2-codegen-1.6.2.jar,\ + lib/axis2-corba-1.6.2.jar,\ + lib/axis2-fastinfoset-1.6.2.jar,\ + lib/axis2-java2wsdl-1.6.2.jar,\ + lib/axis2-jaxbri-1.6.2.jar,\ + lib/axis2-jaxws-1.6.2.jar,\ + lib/axis2-jibx-1.6.2.jar,\ + lib/axis2-json-1.6.2.jar,\ + lib/axis2-kernel-1.6.2.jar,\ + lib/axis2-metadata-1.6.2.jar,\ + lib/axis2-mtompolicy-1.6.2.jar,\ + lib/axis2-saaj-1.6.2.jar,\ + lib/axis2-soapmonitor-servlet-1.6.2.jar,\ + lib/axis2-spring-1.6.2.jar,\ + lib/axis2-transport-http-1.6.2.jar,\ + lib/axis2-transport-local-1.6.2.jar,\ + lib/axis2-xmlbeans-1.6.2.jar,\ + lib/json-lib-2.2.2-jdk15.jar,\ + lib/aspose-cells-18.9.jar,\ + lib/commons-codec-1.13.jar,\ + lib/commons-collections4-4.4.jar,\ + lib/commons-compress-1.19.jar,\ + lib/commons-lang3-3.9.jar,\ + lib/commons-logging-1.2.jar,\ + lib/commons-math3-3.6.1.jar,\ + lib/fastjson-1.2.9.jar,\ + lib/hutool-all-5.0.7.jar,\ + lib/jaxb-api-2.3.1.jar,\ + lib/jaxb-core-2.3.0.1.jar,\ + lib/jaxb-impl-2.3.2.jar,\ + lib/jfxrt.jar,\ + lib/ojdbc6.jar,\ + lib/poi-4.1.1.jar,\ + lib/poi-examples-4.1.1.jar,\ + lib/poi-excelant-4.1.1.jar,\ + lib/poi-ooxml-4.1.1.jar,\ + lib/poi-ooxml-schemas-4.1.1.jar,\ + lib/poi-scratchpad-4.1.1.jar,\ + lib/xmlbeans-3.1.0.jar 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/aspose-cells-18.9.jar b/lib/aspose-cells-18.9.jar new file mode 100644 index 0000000..2cefe55 Binary files /dev/null and b/lib/aspose-cells-18.9.jar differ diff --git a/lib/axiom-api-1.2.13.jar b/lib/axiom-api-1.2.13.jar new file mode 100644 index 0000000..84cb42c Binary files /dev/null and b/lib/axiom-api-1.2.13.jar differ diff --git a/lib/axis2-kernel-1.6.2.jar b/lib/axis2-kernel-1.6.2.jar new file mode 100644 index 0000000..3ae5f7a Binary files /dev/null and b/lib/axis2-kernel-1.6.2.jar differ diff --git a/lib/commons-codec-1.13.jar b/lib/commons-codec-1.13.jar new file mode 100644 index 0000000..bf6ccb3 Binary files /dev/null and b/lib/commons-codec-1.13.jar differ diff --git a/lib/commons-collections4-4.4.jar b/lib/commons-collections4-4.4.jar new file mode 100644 index 0000000..da06c3e Binary files /dev/null and b/lib/commons-collections4-4.4.jar differ diff --git a/lib/commons-compress-1.19.jar b/lib/commons-compress-1.19.jar new file mode 100644 index 0000000..5c9f52a Binary files /dev/null and b/lib/commons-compress-1.19.jar differ diff --git a/lib/commons-lang3-3.9.jar b/lib/commons-lang3-3.9.jar new file mode 100644 index 0000000..0d89693 Binary files /dev/null and b/lib/commons-lang3-3.9.jar differ diff --git a/lib/commons-logging-1.2.jar b/lib/commons-logging-1.2.jar new file mode 100644 index 0000000..93a3b9f Binary files /dev/null and b/lib/commons-logging-1.2.jar differ diff --git a/lib/commons-math3-3.6.1.jar b/lib/commons-math3-3.6.1.jar new file mode 100644 index 0000000..0ff582c Binary files /dev/null and b/lib/commons-math3-3.6.1.jar differ diff --git a/lib/datepicker.jar b/lib/datepicker.jar new file mode 100644 index 0000000..8304d36 Binary files /dev/null and b/lib/datepicker.jar differ diff --git a/lib/fastjson-1.2.9.jar b/lib/fastjson-1.2.9.jar new file mode 100644 index 0000000..839cea3 Binary files /dev/null and b/lib/fastjson-1.2.9.jar differ diff --git a/lib/hutool-all-5.0.7.jar b/lib/hutool-all-5.0.7.jar new file mode 100644 index 0000000..0ed0b10 Binary files /dev/null and b/lib/hutool-all-5.0.7.jar differ diff --git a/lib/jaxb-api-2.3.1.jar b/lib/jaxb-api-2.3.1.jar new file mode 100644 index 0000000..4565865 Binary files /dev/null and b/lib/jaxb-api-2.3.1.jar differ diff --git a/lib/jaxb-core-2.3.0.1.jar b/lib/jaxb-core-2.3.0.1.jar new file mode 100644 index 0000000..431e143 Binary files /dev/null and b/lib/jaxb-core-2.3.0.1.jar differ diff --git a/lib/jaxb-impl-2.3.2.jar b/lib/jaxb-impl-2.3.2.jar new file mode 100644 index 0000000..58035e8 Binary files /dev/null and b/lib/jaxb-impl-2.3.2.jar differ diff --git a/lib/jfxrt.jar b/lib/jfxrt.jar new file mode 100644 index 0000000..49b7d90 Binary files /dev/null and b/lib/jfxrt.jar differ diff --git a/lib/json-lib-2.2.2-jdk15.jar b/lib/json-lib-2.2.2-jdk15.jar new file mode 100644 index 0000000..27e7c7c Binary files /dev/null and b/lib/json-lib-2.2.2-jdk15.jar differ diff --git a/lib/ojdbc6.jar b/lib/ojdbc6.jar new file mode 100644 index 0000000..ec3d6f1 Binary files /dev/null and b/lib/ojdbc6.jar differ diff --git a/lib/poi-4.1.1.jar b/lib/poi-4.1.1.jar new file mode 100644 index 0000000..5b12817 Binary files /dev/null and b/lib/poi-4.1.1.jar differ diff --git a/lib/poi-examples-4.1.1.jar b/lib/poi-examples-4.1.1.jar new file mode 100644 index 0000000..334db49 Binary files /dev/null and b/lib/poi-examples-4.1.1.jar differ diff --git a/lib/poi-excelant-4.1.1.jar b/lib/poi-excelant-4.1.1.jar new file mode 100644 index 0000000..f0eb13a Binary files /dev/null and b/lib/poi-excelant-4.1.1.jar differ diff --git a/lib/poi-ooxml-4.1.1.jar b/lib/poi-ooxml-4.1.1.jar new file mode 100644 index 0000000..bf3569d Binary files /dev/null and b/lib/poi-ooxml-4.1.1.jar differ diff --git a/lib/poi-ooxml-schemas-4.1.1.jar b/lib/poi-ooxml-schemas-4.1.1.jar new file mode 100644 index 0000000..d4d0292 Binary files /dev/null and b/lib/poi-ooxml-schemas-4.1.1.jar differ diff --git a/lib/poi-scratchpad-4.1.1.jar b/lib/poi-scratchpad-4.1.1.jar new file mode 100644 index 0000000..1b6a94f Binary files /dev/null and b/lib/poi-scratchpad-4.1.1.jar differ diff --git a/lib/xmlbeans-3.1.0.jar b/lib/xmlbeans-3.1.0.jar new file mode 100644 index 0000000..18e568f Binary files /dev/null and b/lib/xmlbeans-3.1.0.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..ed70bc1 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/connor/fh/plm/handlers/BOMBatchCreateHandler.java b/src/com/connor/fh/plm/handlers/BOMBatchCreateHandler.java new file mode 100644 index 0000000..1e990e7 --- /dev/null +++ b/src/com/connor/fh/plm/handlers/BOMBatchCreateHandler.java @@ -0,0 +1,33 @@ +package com.connor.fh.plm.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.fh.plm.operations.BOMBatchCreateOperation; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AbstractAIFSession; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; + +/** + * + * @ClassName: BOMBatchCreateHandler + * @Description: BOM批量创建 通过读取excel内容批量创建BOM + * @author hcj + * @date 2024年4月15日 + * + */ +public class BOMBatchCreateHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // 获取当前系统活动 + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession)app.getSession(); + session.queueOperation(new BOMBatchCreateOperation(session)); + return null; + } + +} diff --git a/src/com/connor/fh/plm/handlers/FlowBatchCreateHandler.java b/src/com/connor/fh/plm/handlers/FlowBatchCreateHandler.java new file mode 100644 index 0000000..ef33301 --- /dev/null +++ b/src/com/connor/fh/plm/handlers/FlowBatchCreateHandler.java @@ -0,0 +1,80 @@ +package com.connor.fh.plm.handlers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.fh.plm.operations.MateriaBatchCreateOperation; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.workflow.commands.newprocess.NewProcessCommand; + +/** + * + * @ClassName: FlowBatchCreateHandler + * @Description: 批量发起流程 + * @author hcj + * @date 2024年4月15日 + * + */ +public class FlowBatchCreateHandler extends AbstractHandler{ + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + new Thread() { + @Override + public void run() { + // TODO Auto-generated method stub + // 获取当前系统活动 + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + // 获取tc当前选择的操作 + InterfaceAIFComponent target = app.getTargetComponent(); + if (target instanceof TCComponentFolder) { + + TCComponentFolder folder = (TCComponentFolder) target; + //获取session + TCSession session = folder.getSession(); + List revisions = new ArrayList(); + //获取文件夹下所有未发布的最新版本 + try { + AIFComponentContext[] children = folder.getChildren(); + for(AIFComponentContext componentContext : children) { + TCComponent component = (TCComponent)componentContext.getComponent(); + if(component instanceof TCComponentItemRevision) { + TCComponentItemRevision revision = (TCComponentItemRevision)component; + TCProperty tcProperty = revision.getTCProperty("release_status_list"); + TCComponent[] refs = tcProperty.getReferenceValueArray(); + if (refs == null || refs.length == 0) { + revisions.add(revision); + } + } + + } + NewProcessCommand command = new NewProcessCommand(AIFUtility.getActiveDesktop(), app, + revisions.toArray(new TCComponentItemRevision[revisions.size()])); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + }else { + MessageBox.post("请选择文件夹进行操作", "提示", MessageBox.INFORMATION); + } + } + }.start(); + return null; + } + +} diff --git a/src/com/connor/fh/plm/handlers/MateriaBatchCreateHandler.java b/src/com/connor/fh/plm/handlers/MateriaBatchCreateHandler.java new file mode 100644 index 0000000..3fd6dfc --- /dev/null +++ b/src/com/connor/fh/plm/handlers/MateriaBatchCreateHandler.java @@ -0,0 +1,49 @@ +package com.connor.fh.plm.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.fh.plm.operations.MateriaBatchCreateOperation; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +/** + * + * @ClassName: MateriaBatchCreateHandler + * @Description: 批量创建物料 通过读取Excel批量创建物料 + * @author hcj + * @date 2024年4月15日 + * + */ +public class MateriaBatchCreateHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // 获取当前系统活动 + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + // 获取tc当前选择的操作 + InterfaceAIFComponent target = app.getTargetComponent(); + if (target instanceof TCComponentFolder) { + + TCComponentFolder folder = (TCComponentFolder) target; + //获取session + TCSession session = folder.getSession(); + + MateriaBatchCreateOperation materiaBatchCreateOperation = new MateriaBatchCreateOperation(session,folder); + session.queueOperation(materiaBatchCreateOperation); + + }else { + MessageBox.post("请选择文件夹进行操作", "提示", MessageBox.INFORMATION); + return null; + } + + + return null; + } + +} diff --git a/src/com/connor/fh/plm/operations/BOMBatchCreateOperation.java b/src/com/connor/fh/plm/operations/BOMBatchCreateOperation.java new file mode 100644 index 0000000..1bc5cb6 --- /dev/null +++ b/src/com/connor/fh/plm/operations/BOMBatchCreateOperation.java @@ -0,0 +1,752 @@ +package com.connor.fh.plm.operations; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.connor.jd.plm.util.Util; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +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.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.util.MessageBox; + +/** + * + * @ClassName: BOMBatchCreateOperation + * @Description: BOM批量创建 根据excel模版指定的父类和子类 批量创建BOM + * @author hcj + * @date 2024年4月23日 + * + */ +public class BOMBatchCreateOperation extends AbstractAIFOperation { + + private TCSession session; + private String path = null; + private JLabel label = new JLabel("数据文件:"); + private JTextField jtf = new JTextField(25); + private JButton button = new JButton("浏览"); + private JButton button2 = new JButton("确定"); + private JFrame jf; + private Map isMastSetMap = new HashMap(); + private Map itemAttrMap = new HashMap(); + private Map itemMasterAttrMap = new HashMap(); + private Map itemRevAttrMap = new HashMap(); + private Map attrTypeMap = new HashMap(); + private Map itemRevMasterAttrMap = new HashMap(); + private Map bomlineAttrMap = new HashMap(); + + public BOMBatchCreateOperation(TCSession session) { + this.session = session; + // 获取首选项的值 + getSXX(); + } + + /** + * + * @Title: getSXX + * @Description: 获取首选的值 + * @param 参数 + * @return void 返回类型 + * @throws + */ + private void getSXX() { + // TODO Auto-generated method stub + String[] sxx = Util.getSXX(session, "PHZD_BOM_create"); + for (String str : sxx) { + try { + String[] split = str.split("=");// 获取excel列名称 + String[] split2 = split[1].split(":");// 获取属性位置已经真实名称 是否必填 + // 判断属性是否必填和类型 + String[] split3 = split2[1].split("#"); + String[] split4 = split3[1].split("-"); + isMastSetMap.put(split[0], Boolean.parseBoolean(split4[0])); + attrTypeMap.put(split3[0], split4[1]); + // 判断属性位置 + if ("对象".equals(split2[0])) { + itemAttrMap.put(split[0], split3[0]); + } else if ("对象表单".equals(split2[0])) { + itemMasterAttrMap.put(split[0], split3[0]); + } else if ("版本".equals(split2[0])) { + itemRevAttrMap.put(split[0], split3[0]); + } else if ("版本表单".equals(split2[0])) { + itemRevMasterAttrMap.put(split[0], split3[0]); + } else if ("bomline".equals(split2[0])) { + bomlineAttrMap.put(split[0], split3[0]); + } + } catch (Exception e) { + // TODO Auto-generated catch block + MessageBox.post("首选项PHZD_materials_create【" + str + "】配置有误", "提示", MessageBox.ERROR); + return; + } + + } + } + + @Override + public void executeOperation() throws Exception { + // TODO Auto-generated method stub + + // TODO Auto-generated method stub + jf = new JFrame("导入BOM"); + jf.setBounds(400, 200, 700, 150); + JPanel panel = new JPanel(); + JPanel panel2 = new JPanel(); + panel.add(this.label); + panel.add(this.jtf); + panel.add(this.button); + panel2.add(this.button2); + jf.add(panel, "North"); + jf.add(panel2, "South"); + jf.setVisible(true); + jf.setDefaultCloseOperation(2); + + this.button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + try { + JFileChooser fc = new JFileChooser("C:\\"); + // 设置为仅选择文件模式 + fc.setFileSelectionMode(JFileChooser.FILES_ONLY); + int val = fc.showOpenDialog(null); + if (val == JFileChooser.APPROVE_OPTION) { // 对比值应为 JFileChooser.APPROVE_OPTION 而不是直接用 0 + + path = fc.getSelectedFile().getPath(); // 使用 getPath() 获取文件路径 + jtf.setText(path); + + // 获取选择文件类型是否为excel + File selectedFile = fc.getSelectedFile(); + // 检查文件扩展名 + String fileName = selectedFile.getName(); + String extension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); + boolean isExcelByExtension = (extension.equals("xls") || extension.equals("xlsx") + || extension.equals("xlsm")); + if (!isExcelByExtension) { + MessageBox.post("选择的文件不是excel文件 请重新选择", "提示", MessageBox.INFORMATION); + jtf.setText(""); + } + + } else { + jtf.setText("未选择文件"); + } + } catch (Exception var4) { + var4.printStackTrace(); + } + } + }); + this.button2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + try { + if (path != null && path != "" && !"未选择文件".equals(path)) { + String errString = ""; + Util.setByPass(true); + createBOM(errString); + Util.setByPass(false); + } else { + MessageBox.post("未选择文件!", "提示", MessageBox.INFORMATION); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + }); + } + + /** + * + * @Title: createBOM + * @Description: 创建BOM + * @param @throws TCException + * @param @throws IOException 参数 + * @return void 返回类型 + * @throws + */ + protected void createBOM(String err) throws TCException, IOException { + // TODO Auto-generated method stub + // 读取excel + Map> bomItemMap = new HashMap>(); + Map> lineattrMap = new HashMap>(); + Map>> readExcel = readExcel(path); + System.out.println("excel中的数据:" + readExcel); + // 校验数据 判断id是否存在 + for (Entry>> entry : readExcel.entrySet()) { + String fId = entry.getKey(); + System.out.println("父id:" + fId); + TCComponent itemById = Util.getItemById(fId); + if (itemById == null) { + MessageBox.post("excel中的父ID【" + fId + "】不存在", "提示", MessageBox.ERROR); + return; + } + if (itemById instanceof TCComponentItem) { + TCComponentItem fItem = (TCComponentItem) itemById; + // 判断父对象是否发布 + System.out.println("开始判断父对象是否发布"); + TCComponent[] tcProperty = fItem.getLatestItemRevision().getTCProperty("release_status_list") + .getReferenceValueArray(); + if (tcProperty != null && tcProperty.length > 0) { + MessageBox.post("父对象校验通过,对象" + fId + ",已发布,请升版再继续操作", "提示", MessageBox.ERROR); + return; + } + + List childItems = new ArrayList(); + + // 循环获取对应子行 + Map> childMap = entry.getValue(); + for (Entry> child : childMap.entrySet()) { + String cId = child.getKey(); + TCComponent itemById1 = Util.getItemById(cId); + if (itemById1 == null) { + MessageBox.post("excel中的子ID【" + cId + "】不存在", "提示", MessageBox.ERROR); + return; + } + if (itemById1 instanceof TCComponentItem) { + TCComponentItem cItem = (TCComponentItem) itemById1; + // 判断子对象是否发布 + TCComponent[] tcProperty1 = fItem.getLatestItemRevision().getTCProperty("release_status_list") + .getReferenceValueArray(); + if (tcProperty1 != null && tcProperty1.length > 0) { + MessageBox.post("子对象校验未通过,对象" + cId + ",已发布,请升版再继续操作", "提示", MessageBox.ERROR); + return; + } + // 获取属性 + Map attMap = child.getValue(); + System.out.println("attMap==>" + attMap); + + // 是否为必填 + System.out.println(isMastSetMap); + for (Entry entry1 : attMap.entrySet()) { + String key = entry1.getKey(); + System.out.println("key:" + key); + if (isMastSetMap.get(key)) { + String value = entry1.getValue(); + if (value == null || value.trim().equals("")) { + MessageBox.post("excel数据校验未通过," + key + ",为必填属性", "提示", MessageBox.ERROR); + return; + } + } + } + lineattrMap.put(cItem, attMap); + childItems.add(cItem); + } else { + MessageBox.post("子列sap物料编码填写错误,找不到item对象:" + cId, "提示", MessageBox.ERROR); + return; + } + } + bomItemMap.put(fItem, childItems); + } else { + System.out.println("填写的id不是itemID"); + } + + } + // 获取单位属性,如果单位需要更改,判断是否存在bom视图,不存在,则改,存在,则跳过 + for (Entry> entry : lineattrMap.entrySet()) { + TCComponentItem rev = entry.getKey(); + // 修改单位 + System.out.println("开始修改单位"); + System.out.println(entry.getValue()); + if (entry.getValue().containsKey("单位")) { + String uomName = entry.getValue().get("单位"); + try { + TCUserService userservice = session.getUserService(); + userservice.call("connor_set_uom", new Object[] { rev, uomName }); + entry.getValue().remove("单位"); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("【connor_set_uom】命名的方法未注册有用户服务"); + } + } + System.out.println("修改单位完毕"); + } + + System.out.println("搭建bom视图"); + // 搭建bom视图 + createBOMView(bomItemMap); + + // 循环bom视图 发送bom填充属性 + setPropertiesBOM(bomItemMap, lineattrMap); + + jf.dispose(); + MessageBox.post("BOM创建成功", "提示", MessageBox.INFORMATION); + return; + } + + /** + * + * @Title: setPropertiesBOM + * @Description: 循环bom视图 发送bom填充属性 + * @param @param bomItemMap + * @param @param lineattrMap 参数 + * @return void 返回类型 + * @throws TCException + * @throws + */ + private void setPropertiesBOM(Map> bomItemMap, + Map> lineattrMap) throws TCException { + // TODO Auto-generated method stub + for (Entry> entry : bomItemMap.entrySet()) { + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + TCComponentBOMWindow view = winType.create(null); + TCComponentBOMLine bomLine = view.setWindowTopLine(entry.getKey(), entry.getKey().getLatestItemRevision(), + null, null); + + for (AIFComponentContext componentContext : bomLine.getChildren()) { + TCComponentBOMLine childLine = (TCComponentBOMLine) componentContext.getComponent(); + if (lineattrMap.containsKey(childLine.getItem())) { + Map map = lineattrMap.get(childLine.getItem()); + // 给对象赋值 + Map itemattrs = getattrs(map, itemAttrMap); + System.out.println("itemattrs:" + itemattrs); + if (itemattrs.size() > 0) { +// item.setProperties(itemattrs); + childLine.getItem().lock(); + for (Entry entry1 : itemattrs.entrySet()) { + System.out.println(entry1.getKey()); + System.out.println(entry1.getValue()); + Object typeForAttr = getTypeForAttr(entry1.getKey(), entry1.getValue()); + Util.setTCPropertyValue(childLine.getItem(), entry1.getKey(), typeForAttr); + } + childLine.getItem().save(); + childLine.getItem().unlock(); + + } + + // 给对象表单赋值 + Map itemMasterattrs = getattrs(map, itemMasterAttrMap); + System.out.println("itemMasterattrs:" + itemMasterattrs); + if (itemMasterattrs.size() > 0) { + TCComponent[] masterFormItem = childLine.getItem().getReferenceListProperty("IMAN_master_form"); + TCComponentForm itemform = (TCComponentForm) masterFormItem[0]; +// itemform.setProperties(itemMasterattrs); + itemform.lock(); + for (Entry entry1 : itemMasterattrs.entrySet()) { + System.out.println(entry1.getKey()); + System.out.println(entry1.getValue()); + Object typeForAttr = getTypeForAttr(entry1.getKey(), entry1.getValue()); + Util.setTCPropertyValue(itemform, entry1.getKey(), typeForAttr); + } + itemform.save(); + itemform.unlock(); + + } + + // 给版本赋值 + Map revattrs = getattrs(map, itemRevAttrMap); + System.out.println("revattrs:" + revattrs); + if (revattrs.size() > 0) { +// item.getLatestItemRevision().setProperties(revattrs); + childLine.getItemRevision().lock(); + for (Entry entry1 : revattrs.entrySet()) { + System.out.println(entry1.getKey()); + System.out.println(entry1.getValue()); + Object typeForAttr = getTypeForAttr(entry1.getKey(), entry1.getValue()); + Util.setTCPropertyValue(childLine.getItemRevision(), entry1.getKey(), typeForAttr); + } + childLine.getItemRevision().save(); + childLine.getItemRevision().unlock(); + + } + + // 给版本表单赋值 + Map revMasterattrs = getattrs(map, itemRevMasterAttrMap); + System.out.println("revMasterattrs:" + revMasterattrs); + if (revMasterattrs.size() > 0) { + TCComponent[] referenceListProperty = childLine.getItemRevision() + .getReferenceListProperty("IMAN_master_form_rev"); + TCComponentForm revForm = (TCComponentForm) referenceListProperty[0]; +// revForm.setProperties(revMasterattrs); + revForm.lock(); + for (Entry entry1 : revMasterattrs.entrySet()) { + System.out.println(entry1.getKey()); + System.out.println(entry1.getValue()); + Object typeForAttr = getTypeForAttr(entry1.getKey(), entry1.getValue()); + Util.setTCPropertyValue(revForm, entry1.getKey(), typeForAttr); + + } + revForm.save(); + revForm.unlock(); + } + + // 给bomline赋值 + Map bomattrMap = getattrs(map, bomlineAttrMap); + System.out.println("bomattrMap:" + bomattrMap); + if (bomattrMap.size() > 0) { + childLine.lock(); + for (Entry entry1 : bomattrMap.entrySet()) { + System.out.println(entry1.getKey()); + System.out.println(entry1.getValue()); + Object typeForAttr = getTypeForAttr(entry1.getKey(), entry1.getValue()); + Util.setTCPropertyValue(childLine, entry1.getKey(), typeForAttr); + } + childLine.save(); + childLine.unlock(); + } + } + } + } + } + + /** + * + * @Title: createBOMView + * @Description: 根据map的对应关系创建bom + * @param @param bomItemMap 参数 + * @return void 返回类型 + * @throws TCException + * @throws + */ + private void createBOMView(Map> bomItemMap) throws TCException { + // TODO Auto-generated method stub + for (Entry> entry : bomItemMap.entrySet()) { + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + TCComponentBOMWindow view = winType.create(null); + TCComponentBOMLine bomLine = view.setWindowTopLine(entry.getKey(), entry.getKey().getLatestItemRevision(), + null, null); + // 获取bomline的子件,判断是新增还是替换 如果子行已经存在于bom中,则更新 否则创建子行 + AIFComponentContext[] children = bomLine.getChildren(); + Map childMap = new HashMap(); + if (children != null && children.length > 0) { + for (AIFComponentContext context : children) { + TCComponentBOMLine childLine = (TCComponentBOMLine) context.getComponent(); + childMap.put(childLine.getItemRevision().getStringProperty("item_id"), childLine); + } + } + view.lock(); + for (TCComponentItem childLine : entry.getValue()) { + if (childMap.size() > 0) { + if (childMap.containsKey(childLine.getLatestItemRevision().getStringProperty("item_id"))) { + // 替换bom行 + TCComponentBOMLine oldBomLine = childMap + .get(childLine.getLatestItemRevision().getStringProperty("item_id")); + oldBomLine.replace(childLine, childLine.getLatestItemRevision(), null); + continue; + } + } + // 新增bom行 + TCComponentItemRevision latestItemRevision = childLine.getLatestItemRevision(); + bomLine.add(childLine, childLine.getLatestItemRevision(), null, false, ""); + view.save(); + } + // 开始修改属性 + + // 关闭视图 + view.unlock(); + view.save(); + view.close(); + } + } + + /** + * + * @Title: getattrs + * @Description: 获取属性和属性名的对应map + * @param @param map + * @param @param itemAttrMap + * @param @return 参数 + * @return Map 返回类型 + * @throws + */ + protected Map getattrs(Map map, Map itemAttrMap) { + // 填充属性 + Map attrmap = new HashMap(); + for (Entry entry : itemAttrMap.entrySet()) { + if (map.containsKey(entry.getKey())) { + String string = map.get(entry.getKey()); + attrmap.put(entry.getValue(), removeTrailingZeros(string)); + } + + } + return attrmap; + } + + /** + * + * @Title: removeTrailingZeros + * @Description: 利用正则去掉末尾的0 + * @param @param input + * @param @return 参数 + * @return String 返回类型 + * @throws + */ + public String removeTrailingZeros(String input) { + if (input != null && !input.isEmpty()) { + // 正则表达式匹配末尾的零,以及可能的.00形式 + // $表示字符串的结束位置,\\.?表示可能存在的小数点,0+表示一个或多个零 + return input.replaceAll("(\\.0+|0+)$", ""); + } + return input; // 如果输入为空或者null,直接返回原值 + } + + /** + * + * @Title: setProperties + * @Description: 根据属性和属性名的对应map,给对象赋值 + * @param @param map + * @param @param item + * @param @throws TCException 参数 + * @return void 返回类型 + * @throws + */ + public void setProperties(Map map, TCComponentItem item) throws TCException { + // 给对象赋值 + Map itemattrs = getattrs(map, itemAttrMap); + System.out.println("itemattrs:" + itemattrs); + if (itemattrs.size() > 0) { +// item.setProperties(itemattrs); + item.lock(); + for (Entry entry : itemattrs.entrySet()) { + System.out.println(entry.getKey()); + System.out.println(entry.getValue()); + Object typeForAttr = getTypeForAttr(entry.getKey(), entry.getValue()); + Util.setTCPropertyValue(item, entry.getKey(), typeForAttr); + } + item.save(); + item.unlock(); + + } + + // 给对象表单赋值 + Map itemMasterattrs = getattrs(map, itemMasterAttrMap); + System.out.println("itemMasterattrs:" + itemMasterattrs); + if (itemMasterattrs.size() > 0) { + TCComponent[] masterFormItem = item.getReferenceListProperty("IMAN_master_form"); + TCComponentForm itemform = (TCComponentForm) masterFormItem[0]; +// itemform.setProperties(itemMasterattrs); + itemform.lock(); + for (Entry entry : itemMasterattrs.entrySet()) { + System.out.println(entry.getKey()); + System.out.println(entry.getValue()); + Object typeForAttr = getTypeForAttr(entry.getKey(), entry.getValue()); + Util.setTCPropertyValue(itemform, entry.getKey(), typeForAttr); + } + itemform.save(); + itemform.unlock(); + + } + + // 给版本赋值 + Map revattrs = getattrs(map, itemRevAttrMap); + System.out.println("revattrs:" + revattrs); + if (revattrs.size() > 0) { +// item.getLatestItemRevision().setProperties(revattrs); + item.getLatestItemRevision().lock(); + for (Entry entry : revattrs.entrySet()) { + System.out.println(entry.getKey()); + System.out.println(entry.getValue()); + Object typeForAttr = getTypeForAttr(entry.getKey(), entry.getValue()); + Util.setTCPropertyValue(item.getLatestItemRevision(), entry.getKey(), typeForAttr); + } + item.getLatestItemRevision().save(); + item.getLatestItemRevision().unlock(); + + } + + // 给版本表单赋值 + Map revMasterattrs = getattrs(map, itemRevMasterAttrMap); + System.out.println("revMasterattrs:" + revMasterattrs); + if (revMasterattrs.size() > 0) { + TCComponent[] referenceListProperty = item.getLatestItemRevision() + .getReferenceListProperty("IMAN_master_form_rev"); + TCComponentForm revForm = (TCComponentForm) referenceListProperty[0]; +// revForm.setProperties(revMasterattrs); + revForm.lock(); + for (Entry entry : revMasterattrs.entrySet()) { + System.out.println(entry.getKey()); + System.out.println(entry.getValue()); + Object typeForAttr = getTypeForAttr(entry.getKey(), entry.getValue()); + Util.setTCPropertyValue(revForm, entry.getKey(), typeForAttr); + + } + revForm.save(); + revForm.unlock(); + } + + // 给bomline赋值 + Map bomattrMap = getattrs(map, bomlineAttrMap); + System.out.println("bomattrMap:" + bomattrMap); + if (bomattrMap.size() > 0) { + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + TCComponentBOMWindow view = winType.create(null); + TCComponentItemRevision rev = item.getLatestItemRevision(); + TCComponentBOMLine line = view.setWindowTopLine(rev.getItem(), rev, null, null); + line.lock(); + for (Entry entry : bomattrMap.entrySet()) { + System.out.println(entry.getKey()); + System.out.println(entry.getValue()); + Object typeForAttr = getTypeForAttr(entry.getKey(), entry.getValue()); + Util.setTCPropertyValue(line, entry.getKey(), typeForAttr); + } + line.save(); + line.unlock(); + } + + } + + /** + * + * @Title: getTypeForAttr + * @Description: 根据首选项获取属性的类型 + * @param @param attrName + * @param @param attrProperty + * @param @return 参数 + * @return Object 返回类型 + * @throws + */ + public Object getTypeForAttr(String attrName, String attrProperty) { + if (attrTypeMap.containsKey(attrName)) { + String type = attrTypeMap.get(attrName); + if ("string".equals(type)) { + return attrProperty; // 直接返回字符串属性值 + } else if ("strings".equals(type)) { + // 假设attrProperty是一个逗号分隔的字符串,将其转换成字符串数组 + return attrProperty.split(","); + } else if ("int".equals(type)) { + try { + return Integer.parseInt(attrProperty); // 将字符串转换成整数 + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid integer value for attribute: " + attrName); + } + } else if ("double".equals(type)) { + try { + return Double.parseDouble(attrProperty); // 将字符串转换成浮点数 + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid double value for attribute: " + attrName); + } + } else if ("date".equals(type)) { + // 假设attrProperty是符合某种日期格式的字符串,这里简化处理,实际应用中应使用更健壮的日期解析 + try { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); // 根据实际格式调整 + return formatter.parse(attrProperty); + } catch (ParseException e) { + throw new IllegalArgumentException("Invalid date format for attribute: " + attrName); + } + } + } + + // 如果类型不匹配或不存在于map中,根据实际情况处理,这里简单返回null + return null; + } + + /** + * + * @Title: readExcel + * @Description: 读取excel文件 + * @param @param path excel文件路径 + * @param @return + * @param @throws IOException 参数 + * @return Map> 返回类型 + * @throws + */ + protected Map>> readExcel(String path) throws IOException { + // TODO Auto-generated method stub + FileInputStream fis = new FileInputStream(path); + XSSFWorkbook workbook = new XSSFWorkbook(fis); + XSSFSheet sheet = workbook.getSheetAt(0); // 获取第一个工作表 + + // 假设第一行是标题行 + XSSFRow headerRow = sheet.getRow(0); + Map>> bomMap = new HashMap>>(); + + for (int dataRowNum = 1; dataRowNum <= sheet.getLastRowNum(); dataRowNum++) { + XSSFRow dataRow = sheet.getRow(dataRowNum); + if (dataRow == null) { + continue; // 跳过空行 + } + + // 手动获取父件id 子件id + String fId = getCellValue(dataRow.getCell(0), dataRow); + + String cId = getCellValue(dataRow.getCell(2), dataRow); + Map> chileMap = new HashMap>(); + Map attrMap = new HashMap(); + // 从第五列开始读取 + for (int colNum = 4; colNum < headerRow.getLastCellNum(); colNum++) { + String key = getCellValue(headerRow.getCell(colNum), headerRow); + if (key == null || "".equals(key.trim())) { + break; + } + String value = getCellValue(dataRow.getCell(colNum), dataRow); + attrMap.put(key, value); + } + chileMap.put(cId, attrMap); + + Map childMap = new HashMap(); + // 获取单元格的内容 + + // 判断map中是否有父对象 + if (bomMap.containsKey(fId)) { + bomMap.get(fId).putAll(chileMap); + + } else { + + bomMap.put(fId, chileMap); + } + + } + workbook.close(); + fis.close(); + return bomMap; + } + + /** + * + * @Title: getCellValue + * @Description: 获取excel的单元值 + * @param @param dataCell + * @param @param dataRow + * @param @return 参数 + * @return String 返回类型 + * @throws + */ + public String getCellValue(XSSFCell dataCell, XSSFRow dataRow) { + Object value; + if (dataCell == null) { + return ""; + } + switch (dataCell.getCellType()) { + case STRING: + value = dataCell.getStringCellValue(); + break; + case NUMERIC: + value = Double.toString(dataCell.getNumericCellValue()); + break; + case BOOLEAN: + value = Boolean.toString(dataCell.getBooleanCellValue()); + break; + default: + System.out.println("Warning: Unexpected cell type encountered, skipping this cell. Cell at (" + + dataRow.getRowNum() + ")"); + return ""; + } + return value.toString(); + } + +} diff --git a/src/com/connor/fh/plm/operations/BatchBomCreate.java b/src/com/connor/fh/plm/operations/BatchBomCreate.java new file mode 100644 index 0000000..c81b7f4 --- /dev/null +++ b/src/com/connor/fh/plm/operations/BatchBomCreate.java @@ -0,0 +1,91 @@ +package com.connor.fh.plm.operations; + +import java.util.List; + +public class BatchBomCreate { + + private String fId; + private String fName; + private String fWork; + private String fPurpose; + private String fNum; + private String fProjId; + private String fProjType; + private ChildLine childLines; + public BatchBomCreate() { + super(); + } + + public BatchBomCreate(String fId, String fName, String fWork, String fPurpose, String fNum, String fProjId, + String fProjType, ChildLine childLines) { + super(); + this.fId = fId; + this.fName = fName; + this.fWork = fWork; + this.fPurpose = fPurpose; + this.fNum = fNum; + this.fProjId = fProjId; + this.fProjType = fProjType; + this.childLines = childLines; + } + + public String getfId() { + return fId; + } + public void setfId(String fId) { + this.fId = fId; + } + public String getfName() { + return fName; + } + public void setfName(String fName) { + this.fName = fName; + } + public String getfWork() { + return fWork; + } + public void setfWork(String fWork) { + this.fWork = fWork; + } + public String getfPurpose() { + return fPurpose; + } + public void setfPurpose(String fPurpose) { + this.fPurpose = fPurpose; + } + public String getfNum() { + return fNum; + } + public void setfNum(String fNum) { + this.fNum = fNum; + } + public String getfProjId() { + return fProjId; + } + public void setfProjId(String fProjId) { + this.fProjId = fProjId; + } + public String getfProjType() { + return fProjType; + } + public void setfProjType(String fProjType) { + this.fProjType = fProjType; + } + + public ChildLine getChildLines() { + return childLines; + } + + public void setChildLines(ChildLine childLines) { + this.childLines = childLines; + } + + @Override + public String toString() { + return "BatchBomCreate [fId=" + fId + ", fName=" + fName + ", fWork=" + fWork + ", fPurpose=" + fPurpose + + ", fNum=" + fNum + ", fProjId=" + fProjId + ", fProjType=" + fProjType + ", childLines=" + childLines + + "]"; + } + + +} diff --git a/src/com/connor/fh/plm/operations/ChildLine.java b/src/com/connor/fh/plm/operations/ChildLine.java new file mode 100644 index 0000000..63827d6 --- /dev/null +++ b/src/com/connor/fh/plm/operations/ChildLine.java @@ -0,0 +1,255 @@ +package com.connor.fh.plm.operations; + +public class ChildLine { + private String cId; + private String cName; + private String cNum; + private String cUnit; + private String cGXBFL; + private String cJId; + private String cGdz; + private String cFCKCDD; + private String cTSHQ; + private String cBZ; + private String cTDXMZ; + private String cYXJ; + private String cCL; + private String cCYKNX; + private String cWLGYBS; + private String cSZWL; + + + + public ChildLine() { + super(); + } + + + + public ChildLine(String cId, String cName, String cNum, String cUnit, String cGXBFL, String cJId, String cGdz, + String cFCKCDD, String cTSHQ, String cBZ, String cTDXMZ, String cYXJ, String cCL, String cCYKNX, + String cWLGYBS, String cSZWL) { + super(); + this.cId = cId; + this.cName = cName; + this.cNum = cNum; + this.cUnit = cUnit; + this.cGXBFL = cGXBFL; + this.cJId = cJId; + this.cGdz = cGdz; + this.cFCKCDD = cFCKCDD; + this.cTSHQ = cTSHQ; + this.cBZ = cBZ; + this.cTDXMZ = cTDXMZ; + this.cYXJ = cYXJ; + this.cCL = cCL; + this.cCYKNX = cCYKNX; + this.cWLGYBS = cWLGYBS; + this.cSZWL = cSZWL; + } + + + + public String getcId() { + return cId; + } + + + + public void setcId(String cId) { + this.cId = cId; + } + + + + public String getcName() { + return cName; + } + + + + public void setcName(String cName) { + this.cName = cName; + } + + + + public String getcNum() { + return cNum; + } + + + + public void setcNum(String cNum) { + this.cNum = cNum; + } + + + + public String getcUnit() { + return cUnit; + } + + + + public void setcUnit(String cUnit) { + this.cUnit = cUnit; + } + + + + public String getcGXBFL() { + return cGXBFL; + } + + + + public void setcGXBFL(String cGXBFL) { + this.cGXBFL = cGXBFL; + } + + + + public String getcJId() { + return cJId; + } + + + + public void setcJId(String cJId) { + this.cJId = cJId; + } + + + + public String getcGdz() { + return cGdz; + } + + + + public void setcGdz(String cGdz) { + this.cGdz = cGdz; + } + + + + public String getcFCKCDD() { + return cFCKCDD; + } + + + + public void setcFCKCDD(String cFCKCDD) { + this.cFCKCDD = cFCKCDD; + } + + + + public String getcTSHQ() { + return cTSHQ; + } + + + + public void setcTSHQ(String cTSHQ) { + this.cTSHQ = cTSHQ; + } + + + + public String getcBZ() { + return cBZ; + } + + + + public void setcBZ(String cBZ) { + this.cBZ = cBZ; + } + + + + public String getcTDXMZ() { + return cTDXMZ; + } + + + + public void setcTDXMZ(String cTDXMZ) { + this.cTDXMZ = cTDXMZ; + } + + + + public String getcYXJ() { + return cYXJ; + } + + + + public void setcYXJ(String cYXJ) { + this.cYXJ = cYXJ; + } + + + + public String getcCL() { + return cCL; + } + + + + public void setcCL(String cCL) { + this.cCL = cCL; + } + + + + public String getcCYKNX() { + return cCYKNX; + } + + + + public void setcCYKNX(String cCYKNX) { + this.cCYKNX = cCYKNX; + } + + + + public String getcWLGYBS() { + return cWLGYBS; + } + + + + public void setcWLGYBS(String cWLGYBS) { + this.cWLGYBS = cWLGYBS; + } + + + + public String getcSZWL() { + return cSZWL; + } + + + + public void setcSZWL(String cSZWL) { + this.cSZWL = cSZWL; + } + + + + @Override + public String toString() { + return "ChildLine [cId=" + cId + ", cName=" + cName + ", cNum=" + cNum + ", cUnit=" + cUnit + ", cGXBFL=" + + cGXBFL + ", cJId=" + cJId + ", cGdz=" + cGdz + ", cFCKCDD=" + cFCKCDD + ", cTSHQ=" + cTSHQ + ", cBZ=" + + cBZ + ", cTDXMZ=" + cTDXMZ + ", cYXJ=" + cYXJ + ", cCL=" + cCL + ", cCYKNX=" + cCYKNX + ", cWLGYBS=" + + cWLGYBS + ", cSZWL=" + cSZWL + "]"; + } + + + +} diff --git a/src/com/connor/fh/plm/operations/MateriaBatchCreateOperation.java b/src/com/connor/fh/plm/operations/MateriaBatchCreateOperation.java new file mode 100644 index 0000000..77a055d --- /dev/null +++ b/src/com/connor/fh/plm/operations/MateriaBatchCreateOperation.java @@ -0,0 +1,481 @@ +package com.connor.fh.plm.operations; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.eclipse.jface.bindings.keys.formatting.EmacsKeyFormatter; + +import com.connor.jd.plm.util.Util; + +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +/** + * + * @ClassName: MateriaBatchCreateOperation + * @Description: 批量创建物料实现类 + * @author hcj + * @date 2024年4月15日 + * + */ +public class MateriaBatchCreateOperation extends AbstractAIFOperation { + private TCSession session; + private TCComponentFolder folder; + private String path = null; + private JLabel label = new JLabel("数据文件:"); + private JTextField jtf = new JTextField(25); + private JButton button = new JButton("浏览"); + private JButton button2 = new JButton("确定"); + private JFrame jf; + private Map itemTypeMap = new HashMap(); + private Map isMastSetMap = new HashMap(); + private Map attrTypeMap = new HashMap(); + private Map itemAttrMap = new HashMap(); + private Map itemMasterAttrMap = new HashMap(); + private Map itemRevAttrMap = new HashMap(); + private Map itemRevMasterAttrMap = new HashMap(); + + public MateriaBatchCreateOperation(TCSession session, TCComponentFolder folder) { + this.session = session; + this.folder = folder; + // 获取首选项的值 + getSXX(); + } + + /** + * + * @Title: getSXX + * @Description: 获取首选项的值 + * @param 参数 + * @return void 返回类型 + * @throws + */ + private void getSXX() { + // TODO Auto-generated method stub + String[] sxx = Util.getSXX(session, "PHZD_materials_create"); + for (String str : sxx) { + try { + String[] split = str.split("=");// 获取excel列名称 + String[] split2 = split[1].split(":");// 获取属性位置已经真实名称 是否必填 + // 判断属性是否必填和类型 + String[] split3 = split2[1].split("#"); + String[] split4 = split3[1].split("-"); + isMastSetMap.put(split[0], Boolean.parseBoolean(split4[0])); + attrTypeMap.put(split3[0], split4[1]); + // 判断属性位置 + if ("对象".equals(split2[0])) { + itemAttrMap.put(split[0], split3[0]); + } else if ("对象表单".equals(split2[0])) { + itemMasterAttrMap.put(split[0], split3[0]); + } else if ("版本".equals(split2[0])) { + itemRevAttrMap.put(split[0], split3[0]); + } else if ("版本表单".equals(split2[0])) { + itemRevMasterAttrMap.put(split[0], split3[0]); + } + } catch (Exception e) { + // TODO Auto-generated catch block + MessageBox.post("首选项PHZD_materials_create【" + str + "】配置有误", "提示", MessageBox.ERROR); + return; + } + + } + + String[] sxx2 = Util.getSXX(session, "PHZD_Mtype_Itemtype"); + for (String str : sxx2) { + try { + String[] split = str.split("="); + itemTypeMap.put(split[0], split[1]); + } catch (Exception e) { + // TODO Auto-generated catch block + MessageBox.post("首选项PHZD_Mtype_Itemtype【" + str + "】配置有误", "提示", MessageBox.ERROR); + return; + } + } + } + + @Override + public void executeOperation() throws Exception { + // TODO Auto-generated method stub + jf = new JFrame("导入对象"); + jf.setBounds(400, 200, 700, 150); + JPanel panel = new JPanel(); + JPanel panel2 = new JPanel(); + panel.add(this.label); + panel.add(this.jtf); + panel.add(this.button); + panel2.add(this.button2); + jf.add(panel, "North"); + jf.add(panel2, "South"); + jf.setVisible(true); + jf.setDefaultCloseOperation(2); + + this.button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + try { + JFileChooser fc = new JFileChooser("C:\\"); + // 设置为仅选择文件模式 + fc.setFileSelectionMode(JFileChooser.FILES_ONLY); + int val = fc.showOpenDialog(null); + if (val == JFileChooser.APPROVE_OPTION) { // 对比值应为 JFileChooser.APPROVE_OPTION 而不是直接用 0 + + path = fc.getSelectedFile().getPath(); // 使用 getPath() 获取文件路径 + jtf.setText(path); + + // 获取选择文件类型是否为excel + File selectedFile = fc.getSelectedFile(); + // 检查文件扩展名 + String fileName = selectedFile.getName(); + String extension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); + boolean isExcelByExtension = (extension.equals("xls") || extension.equals("xlsx") + || extension.equals("xlsm")); + if (!isExcelByExtension) { + MessageBox.post("选择的文件不是excel文件 请重新选择", "提示", MessageBox.INFORMATION); + jtf.setText(""); + } + + } else { + jtf.setText("未选择文件"); + } + } catch (Exception var4) { + var4.printStackTrace(); + } + } + }); + this.button2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + try { + if (path != null && path != "" && !"未选择文件".equals(path)) { + createMaterial(); + + } else { + MessageBox.post("未选择文件!", "提示", MessageBox.INFORMATION); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + }); + } + + protected void createMaterial() throws TCException, IOException { + // TODO Auto-generated method stub + // 读取excel + System.out.println("开始读取Excel"); + List> readExcel = readExcel(path); + System.out.println("Excel数据:" + readExcel); + + // 校验数据,遍历excel数据,判断是否必填值为空 + System.out.println("校验数据,遍历excel数据,判断是否必填值为空"); + for (Map map : readExcel) { + for (Entry entry : map.entrySet()) { + String key = entry.getKey(); + System.out.println("key:" + key); + System.out.println("isMastSetMap:" + isMastSetMap); + if (isMastSetMap.get(key)) { + String value = entry.getValue(); + if (value == null || value.trim().equals("")) { + MessageBox.post("excel数据校验未通过," + key + ",为必填属性", "提示", MessageBox.ERROR); + return; + } + } + } + } + + // 判断excel是否有物料类型代码 + System.out.println("判断excel是否有物料类型代码"); + for (Map map : readExcel) { + System.out.println("map:" + map); + if (map == null || map.size() == 0) { + readExcel.remove(map); + continue; + } + if (map.containsKey("物料类型代码")) { + String string = map.get("物料类型代码"); + if (string == null || string.isEmpty()) { + MessageBox.post("物料类型代码不能为空", "提示", MessageBox.ERROR); + return; + } + } else { + MessageBox.post("物料类型代码不能为空", "提示", MessageBox.ERROR); + return; + } + + } + + // 创建对象 + System.out.println("开始创建对象"); + System.out.println("attrType"+attrTypeMap); + //获取单位 + Map uomTags = new HashMap(); + TCComponentType typeComponent = session.getTypeComponent("UnitOfMeasure"); + TCComponent[] extent = typeComponent.extent(); + for(int t=0;t map : readExcel) { + try { + + String code = map.get("物料类型代码"); + String type = itemTypeMap.get(code); + System.out.println("创建物料type:" + type); + + // 获取Item类型的type + TCComponentItemType tccomponentitemtype = (TCComponentItemType) (session.getTypeComponent(type)); + System.out.println("Item类型的type" + tccomponentitemtype); + // 获取流水码 + String itemId = tccomponentitemtype.getNewID(); + System.out.println("流水码" + itemId); + // 获取版本号 + String itemRev = tccomponentitemtype.getNewRev(null); + System.out.println("版本号" + itemRev); + + // 获取excel的名称 + String name = "物料名称"; + Map itemattrs = getattrs(map, itemAttrMap); + Map itemattrs2 = Util.convertValuesToUtf8(itemattrs); + System.out.println("item属性:" + itemattrs2); + if (itemattrs2.containsKey("object_name")) { + System.out.println("包含object_name"); + name = itemattrs2.get("object_name"); + System.out.println("name:" + name); + +// itemattrs2.remove("object_name"); + } + + // 获取单位,可以为null + String unit = null; + TCComponent[] uoms = null; + if (itemattrs2.containsKey("uom_tag")) { + System.out.println("包含uom_tag"); + System.out.println(itemattrs2.get("uom_tag") + "==>单位"); + unit = itemattrs2.get("uom_tag"); + +// itemattrs2.remove("uom_tag"); + } + //获取版本属性 + Map revattrs = getattrs(map, itemRevAttrMap); + Map revattrs2 = Util.convertValuesToUtf8(revattrs); + + //获取版本表单属性 + Map revMasterattrs = getattrs(map, itemRevMasterAttrMap); + Map revMasterattrs2 = Util.convertValuesToUtf8(revMasterattrs); + // Item的id,Item的版本号,Item的类型,零组件的名称,零组件的描述,零组件的单位(可以为null) +// TCComponentItem item = tccomponentitemtype.create(itemId, itemRev, type, name, "", null); + System.out.println("item属性:"+itemattrs2); + System.out.println("itemRev属性:"+revattrs2); + System.out.println("itemRevMast属性:"+revMasterattrs2); + TCComponentItem item = (TCComponentItem) Util.createMaterialBySOA(session, itemId, itemRev, type, name, "", unit,itemattrs2,revattrs2,revMasterattrs2,uomTags); + + System.out.println("对象【"+item.getStringProperty("item_id")+"】创建成功,开始赋值"); + + // 给对象表单赋值 + Map itemMasterattrs = getattrs(map, itemMasterAttrMap); + System.out.println("item表单属性:" + itemMasterattrs); + if (itemMasterattrs.size() > 0) { + TCComponent[] masterFormItem = item.getReferenceListProperty("IMAN_master_form"); + TCComponentForm itemform = (TCComponentForm) masterFormItem[0]; + itemform.lock(); + for (Entry entry : itemMasterattrs.entrySet()) { + System.out.println(entry.getKey() + "==>" + entry.getValue()); + Object typeForAttr = getTypeForAttr(entry.getKey(), entry.getValue()); + Util.setTCPropertyValue(itemform, entry.getKey(), typeForAttr); + } + itemform.save(); + itemform.unlock(); + + } + + + + + + folder.add("contents", item); + } catch (Exception e) { + System.out.println("属性赋值失败!"); + } + } + + // Util.setByPass(false); + jf.dispose(); + MessageBox.post("创建成功", "提示", MessageBox.INFORMATION); + return; + } + + + protected Map getattrs(Map map, Map itemAttrMap) { + // 填充属性 + Map attrmap = new HashMap(); + for (Entry entry : itemAttrMap.entrySet()) { + if (map.containsKey(entry.getKey())) { + String string = map.get(entry.getKey()); + attrmap.put(entry.getValue(), string); + } + + } + return attrmap; + } + + public Object getTypeForAttr(String attrName, String attrProperty) { + if (attrTypeMap.containsKey(attrName)) { + String type = attrTypeMap.get(attrName); + if ("string".equals(type)) { + System.out.println("string属性"); + return attrProperty; // 直接返回字符串属性值 + } else if ("strings".equals(type)) { + System.out.println("strings属性"); + // 假设attrProperty是一个逗号分隔的字符串,将其转换成字符串数组 + return attrProperty.split(","); + } else if ("int".equals(type)) { + System.out.println("int属性"); + try { + return Integer.parseInt(attrProperty); // 将字符串转换成整数 + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid integer value for attribute: " + attrName); + } + } else if ("double".equals(type)) { + System.out.println("double属性"); + try { + return Double.parseDouble(attrProperty); // 将字符串转换成浮点数 + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid double value for attribute: " + attrName); + } + } else if ("date".equals(type)) { + // 假设attrProperty是符合某种日期格式的字符串,这里简化处理,实际应用中应使用更健壮的日期解析 + System.out.println("date属性"); + try { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); // 根据实际格式调整 + return formatter.parse(attrProperty); + } catch (ParseException e) { + throw new IllegalArgumentException("Invalid date format for attribute: " + attrName); + } + } + } + + // 如果类型不匹配或不存在于map中,根据实际情况处理,这里简单返回null + return null; + } + + /** + * + * @Title: readExcel + * @Description: 读取excel文件 + * @param @param path excel文件路径 + * @return void 返回类型 + * @throws IOException + * @throws + */ + protected List> readExcel(String path) throws IOException { + // TODO Auto-generated method stub + FileInputStream fis = new FileInputStream(path); + XSSFWorkbook workbook = new XSSFWorkbook(fis); + XSSFSheet sheet = workbook.getSheetAt(0); // 获取第一个工作表 + + // 假设第一行是标题行 + XSSFRow headerRow = sheet.getRow(0); + List> list = new ArrayList<>(); + + for (int dataRowNum = 1; dataRowNum <= sheet.getLastRowNum(); dataRowNum++) { + XSSFRow dataRow = sheet.getRow(dataRowNum); + if (dataRow == null) { + break; + } + + Map dataMap = new HashMap<>(); + + // 从第二列开始读取 + for (int colNum = 1; colNum < headerRow.getLastCellNum(); colNum++) { + XSSFCell headerCell = headerRow.getCell(colNum); + XSSFCell dataCell = dataRow.getCell(colNum); + + if (headerCell != null && dataCell != null) { + String key; + Object value; + + switch (headerCell.getCellType()) { + case STRING: + key = headerCell.getStringCellValue(); + break; + // 如果假设标题行不可能是数字或其他类型,可以在这里直接抛异常或者给默认值 + default: + throw new IllegalStateException("Header cell type is not string"); + } + + switch (dataCell.getCellType()) { + case STRING: + value = dataCell.getStringCellValue(); + break; + case NUMERIC: + value = Double.toString(dataCell.getNumericCellValue()); + // 如果有可能包含日期,可以使用如下方式处理日期单元格 + // if (DateUtil.isCellDateFormatted(dataCell)) { + // value = new + // SimpleDateFormat("yyyy-MM-dd").format(dataCell.getDateCellValue()); + // } else { + // value = Double.toString(dataCell.getNumericCellValue()); + // } + break; + case BOOLEAN: + value = Boolean.toString(dataCell.getBooleanCellValue()); + break; + // 添加对其他类型的支持,例如 FORMULA + // case FORMULA: + // value = dataCell.getCellFormula(); + // break; + default: + // 对于未知或不支持的单元格类型,可以选择忽略、记录日志或者提供默认值 + // 这里我们选择打印警告并跳过此次循环 + System.out.println("Warning: Unexpected cell type encountered, skipping this cell. Cell at (" + + dataRow.getRowNum() + ", " + colNum + ")"); + continue; + } + + dataMap.put(key, value.toString()); + } + } + + list.add(dataMap); + } + + workbook.close(); + fis.close(); + + // 输出或处理生成的List> + System.out.println(list); + return list.stream().filter(map -> !map.isEmpty()).collect(Collectors.toList());// 去除这些里面的空map + } +} diff --git a/src/com/connor/jd/operations/CreateTableOperation.java b/src/com/connor/jd/operations/CreateTableOperation.java new file mode 100644 index 0000000..b100596 --- /dev/null +++ b/src/com/connor/jd/operations/CreateTableOperation.java @@ -0,0 +1,73 @@ +package com.connor.jd.operations; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import com.connor.jd.plm.utils.DBConnectionUtil; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; + +public class CreateTableOperation { + private static Connection con = null; + private static Statement ps = null; + private static ResultSet rs = null; + private static TCSession session; + + public static void create() { + session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + String createTable1 = "CREATE TABLE JD2_Component (test_type VARCHAR(255),test_project VARCHAR(255),test_time VARCHAR(255),test_num NUMBER,test_cost FLOAT, test_id NUMBER primary key)"; + String createSeq1 = "CREATE sequence component_id_seq minvalue 1 nomaxvalue INCREMENT BY 1 START WITH 1 nocache"; + String createTRG1 = "CREATE or REPLACE TRIGGER component_id_ins_trg before INSERT ON JD2_COMPONENT for each ROW BEGIN SELECT component_id_seq.Nextval into : new.TEST_ID from dual; END;"; + + String createTable2 = "CREATE TABLE JD2_Machine (test_type VARCHAR(255),test_project VARCHAR(255),test_cost FLOAT, test_id NUMBER primary key)"; + String createSeq2 = "CREATE sequence machine_id_seq minvalue 1 nomaxvalue INCREMENT BY 1 START WITH 1 nocache"; + String createTRG2 = "CREATE or REPLACE TRIGGER machine_id_ins_trg before INSERT ON JD2_MACHINE for each ROW BEGIN SELECT machine_id_seq.Nextval into : new.TEST_ID from dual; END;"; + String[] sqls = { createTable1, createSeq1, createTRG1, createTable2, createSeq2, createTRG2 }; + try { + con = DBConnectionUtil.dbConn(session); + String sqlString = "SELECT count(*) from user_tables WHERE table_name='JD2_COMPONENT'"; + if (con == null) { + System.out.print("连接失败"); + } else { + ps = con.createStatement(); + rs = ps.executeQuery(sqlString); + while (rs.next()) { + System.out.println(rs.getInt(1)); + if (rs.getInt(1) == 0) { + for (int i = 0; i < sqls.length; i++) { + ps = con.createStatement(); + ps.execute(sqls[i]); + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (ps != null) { + try { + ps.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + } +} diff --git a/src/com/connor/jd/operations/ExcelImportServiceImpl.java b/src/com/connor/jd/operations/ExcelImportServiceImpl.java new file mode 100644 index 0000000..3fb6ec0 --- /dev/null +++ b/src/com/connor/jd/operations/ExcelImportServiceImpl.java @@ -0,0 +1,203 @@ +package com.connor.jd.operations; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +public class ExcelImportServiceImpl { + + public String importExcel(InputStream inputStream, String fileName) throws Exception { + + String message = "Import success"; + + boolean isE2007 = false; + // 判断是否是excel2007格式 + if (fileName.endsWith("xlsx")) { + isE2007 = true; + } + + int rowIndex = 0; + try { + InputStream input = inputStream; // 建立输入流 + Workbook wb; + // 根据文件格式(2003或者2007)来初始化 + if (isE2007) { + wb = new XSSFWorkbook(input); + } else { + wb = new HSSFWorkbook(input); + } + Sheet sheet = wb.getSheetAt(0); // 获得第一个表单 + int rowCount = sheet.getLastRowNum() + 1; + + for (int i = 1; i < rowCount; i++) { + rowIndex = i; + Row row; + + for (int j = 0; j < 26; j++) { + if (isMergedRegion(sheet, i, j)) { + System.out.print(getMergedRegionValue(sheet, i, j) + "\t"); + } else { + row = sheet.getRow(i); + System.out.print(row.getCell(j) + "\t"); + } + } + System.out.print("\n"); + } + } catch (Exception ex) { + message = "Import failed, please check the data in " + rowIndex + " rows "; + } + return message; + } + + /** + * 获取单元格的值 + * + * @param cell + * @return + */ + public String getCellValue(Cell cell) { + if (cell == null) + return ""; + return cell.getStringCellValue(); + } + + /** + * 合并单元格处理,获取合并行 + * + * @param sheet + * @return List + */ + public List getCombineCell(Sheet sheet) { + List list = new ArrayList<>(); + // 获得一个 sheet 中合并单元格的数量 + int sheetmergerCount = sheet.getNumMergedRegions(); + // 遍历所有的合并单元格 + for (int i = 0; i < sheetmergerCount; i++) { + // 获得合并单元格保存进list中 + CellRangeAddress ca = sheet.getMergedRegion(i); + list.add(ca); + } + return list; + } + + private int getRowNum(List listCombineCell, Cell cell, Sheet sheet) { + int xr = 0; + int firstC = 0; + int lastC = 0; + int firstR = 0; + int lastR = 0; + for (CellRangeAddress ca : listCombineCell) { + // 获得合并单元格的起始行, 结束行, 起始列, 结束列 + firstC = ca.getFirstColumn(); + lastC = ca.getLastColumn(); + firstR = ca.getFirstRow(); + lastR = ca.getLastRow(); + if (cell.getRowIndex() >= firstR && cell.getRowIndex() <= lastR) { + if (cell.getColumnIndex() >= firstC && cell.getColumnIndex() <= lastC) { + xr = lastR; + } + } + + } + return xr; + + } + + /** + * 判断单元格是否为合并单元格,是的话则将单元格的值返回 + * + * @param listCombineCell 存放合并单元格的list + * @param cell 需要判断的单元格 + * @param sheet sheet + * @return + */ + public String isCombineCell(List listCombineCell, Cell cell, Sheet sheet) throws Exception { + int firstC = 0; + int lastC = 0; + int firstR = 0; + int lastR = 0; + String cellValue = null; + for (CellRangeAddress ca : listCombineCell) { + // 获得合并单元格的起始行, 结束行, 起始列, 结束列 + firstC = ca.getFirstColumn(); + lastC = ca.getLastColumn(); + firstR = ca.getFirstRow(); + lastR = ca.getLastRow(); + if (cell.getRowIndex() >= firstR && cell.getRowIndex() <= lastR) { + if (cell.getColumnIndex() >= firstC && cell.getColumnIndex() <= lastC) { + Row fRow = sheet.getRow(firstR); + Cell fCell = fRow.getCell(firstC); + cellValue = getCellValue(fCell); + break; + } + } else { + cellValue = ""; + } + } + return cellValue; + } + + /** + * 获取合并单元格的值 + * + * @param sheet + * @param row + * @param column + * @return + */ + public String getMergedRegionValue(Sheet sheet, int row, int column) { + int sheetMergeCount = sheet.getNumMergedRegions(); + + for (int i = 0; i < sheetMergeCount; i++) { + CellRangeAddress ca = sheet.getMergedRegion(i); + int firstColumn = ca.getFirstColumn(); + int lastColumn = ca.getLastColumn(); + int firstRow = ca.getFirstRow(); + int lastRow = ca.getLastRow(); + + if (row >= firstRow && row <= lastRow) { + if (column >= firstColumn && column <= lastColumn) { + Row fRow = sheet.getRow(firstRow); + Cell fCell = fRow.getCell(firstColumn); + return getCellValue(fCell); + } + } + } + + return null; + } + + /** + * 判断指定的单元格是否是合并单元格 + * + * @param sheet + * @param row 行下标 + * @param column 列下标 + * @return + */ + private boolean isMergedRegion(Sheet sheet, int row, int column) { + int sheetMergeCount = sheet.getNumMergedRegions(); + for (int i = 0; i < sheetMergeCount; i++) { + CellRangeAddress range = sheet.getMergedRegion(i); + int firstColumn = range.getFirstColumn(); + int lastColumn = range.getLastColumn(); + int firstRow = range.getFirstRow(); + int lastRow = range.getLastRow(); + if (row >= firstRow && row <= lastRow) { + if (column >= firstColumn && column <= lastColumn) { + return true; + } + } + } + return false; + } + +} \ No newline at end of file diff --git a/src/com/connor/jd/operations/ExcelOperation.java b/src/com/connor/jd/operations/ExcelOperation.java new file mode 100644 index 0000000..9d4dd09 --- /dev/null +++ b/src/com/connor/jd/operations/ExcelOperation.java @@ -0,0 +1,264 @@ +package com.connor.jd.operations; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.teamcenter.rac.kernel.TCComponent; + +public class ExcelOperation { + private static final String XLS = "xls"; + private static final String XLSX = "xlsx"; + + public static void writeExcel(File file, String outpath, Map> jfw) { + if (jfw.size() == 1) { + writeoneExcel(file, outpath, jfw); + } else { + writeallExcel(file, outpath, jfw); + } + } + + public static void writeallExcel(File file, String outpath, Map> jfw) { + Workbook workbook; + try { + workbook = getworkbook(file); + System.out.println("已有文件"); + Workbook newwb = getWorkbook(outpath); + Sheet newsheet = newwb.createSheet(); + Sheet sheet = workbook.getSheetAt(0); + CellStyle style = workbook.createCellStyle(); + Row row = sheet.getRow(0); + row.setRowStyle(style); + Row newrow0 = newsheet.createRow(0); + for (int i = 0; i < row.getLastCellNum(); i++) { +// Cell newCell = newrow0.createCell(i); +// newCell.setCellValue(row.getCell(i).getStringCellValue()); + } + List cellRangeList = getCombineCell(sheet); + for (Entry> ever : jfw.entrySet()) { + List itemList = ever.getValue(); + String sfname = ever.getKey(); + System.out.println("itemList长度" + itemList.size()); + for (int i = 0; i < cellRangeList.size(); i++) { + CellRangeAddress ca = cellRangeList.get(i); + int firstColumn = 0; + int firstRow = ca.getFirstRow(); + int lastRow = ca.getLastRow(); + Row fRow = sheet.getRow(firstRow); + Cell fCell = fRow.getCell(firstColumn); + String cellVelue = fCell.getStringCellValue(); + System.out.println("合并单元格的内容" + cellVelue); + System.out.println("起始行" + firstRow + "最后行" + lastRow); + if (sfname.equals(cellVelue)) { + for (int z = firstRow; z <= lastRow; z++) { + Row newRow = sheet.getRow(z); + String value = newRow.getCell(1).getStringCellValue(); + System.out.println("表格内容" + value); + for (int p = 0; p < itemList.size(); p++) { + if (itemList.get(p).getTCProperty("object_type").getDisplayableValue().equals(value)) { + TCComponent[] revlist = itemList.get(p).getTCProperty("revision_list") + .getReferenceValueArray(); + TCComponent component = null; + for (int revlength = 0; revlength < revlist.length; revlength++) { + String status = revlist[revlength].getProperty("release_status_list"); + if (!status.equals("")) { + component = revlist[revlength]; + } + } + String[] info = new String[4]; + if (component != null) { + info[0] = component.getProperty("owning_group"); + info[1] = component.getProperty("owning_user"); + info[2] = component.getProperty("creation_date"); + info[3] = component.getProperty("item_id"); + } else { + info[0] = ""; + info[1] = ""; + info[2] = ""; + info[3] = ""; + } + for (int v = 0; v < info.length; v++) { + Cell cellvalue = newRow.createCell(v + 2); +// cellvalue.setCellValue(info[v]); + System.out.println("内容是" + info[v]); + } + } + } + } + } + + } + } + FileOutputStream fos = new FileOutputStream(outpath); + workbook.write(fos); + workbook.close(); + fos.close(); + } catch (Exception e) { + } + } + + public static void writeoneExcel(File file, String outpath, Map> jfw) { + Workbook workbook; + try { + workbook = getworkbook(file); + System.out.println("已有文件"); + Workbook newwb = getWorkbook(outpath); + Sheet newsheet = newwb.createSheet(); + Sheet sheet = workbook.getSheetAt(0); + CellStyle style = newwb.createCellStyle(); + Row row = sheet.getRow(0); + Row newrow0 = newsheet.createRow(0); + for (int i = 0; i < row.getLastCellNum(); i++) { + Cell oldCell = row.getCell(i); + style.cloneStyleFrom(oldCell.getCellStyle()); + + Cell newCell = newrow0.createCell(i); + newCell.setCellStyle(style); +// newCell.setCellValue(oldCell.getStringCellValue()); + + } + List cellRangeList = getCombineCell(sheet); + for (Entry> ever : jfw.entrySet()) { + List itemList = ever.getValue(); + String sfname = ever.getKey(); + System.out.println("itemList长度" + itemList.size()); + for (int i = 0; i < cellRangeList.size(); i++) { + CellRangeAddress ca = cellRangeList.get(i); + int firstColumn = 0; + int firstRow = ca.getFirstRow(); + int lastRow = ca.getLastRow(); + Row fRow = sheet.getRow(firstRow); + Cell fCell = fRow.getCell(firstColumn); + String cellVelue = fCell.getStringCellValue(); + System.out.println("合并单元格的内容" + cellVelue); + System.out.println("起始行" + firstRow + "最后行" + lastRow); + + if (sfname.equals(cellVelue)) { + List valueList = new ArrayList(); + for (int z = firstRow; z <= lastRow; z++) { + Row oldRow = sheet.getRow(z); + String value = oldRow.getCell(1).getStringCellValue(); + + valueList.add(value); + } + + for (int j = 1; j <= lastRow - firstRow + 1; j++) { + Row newRow = newsheet.createRow(j); + Cell cell = newRow.createCell(0); +// cell.setCellValue(cellVelue); + Cell cell2 = newRow.createCell(1); +// cell2.setCellValue(valueList.get(j - 1)); + System.out.println("特殊表格内容" + valueList.get(j - 1)); + for (int p = 0; p < itemList.size(); p++) { + if (itemList.get(p).getTCProperty("object_type").getDisplayableValue() + .equals(valueList.get(j - 1))) { + System.out.println( + "类型:" + itemList.get(p).getTCProperty("object_type").getDisplayableValue()); + TCComponent[] revlist = itemList.get(p).getTCProperty("revision_list") + .getReferenceValueArray(); + TCComponent component = null; + for (int revlength = 0; revlength < revlist.length; revlength++) { + String status = revlist[revlength].getProperty("release_status_list"); + if (!status.equals("")) { + component = revlist[revlength]; + } + } + String[] info = new String[4]; + if (component != null) { + info[0] = component.getProperty("owning_group"); + info[1] = component.getProperty("owning_user"); + info[2] = component.getProperty("creation_date"); + info[3] = component.getProperty("item_id"); + } else { + info[0] = ""; + info[1] = ""; + info[2] = ""; + info[3] = ""; + } + for (int v = 0; v < info.length; v++) { + System.out.println("开始创建内容"); + Cell cellvalue = newRow.createCell(v + 2); +// cellvalue.setCellValue(info[v]); + System.out.println("内容是" + info[v]); + } + } + } + } + CellRangeAddress region = new CellRangeAddress(1, lastRow - firstRow + 1, 0, 0); + newsheet.addMergedRegion(region); + } + + } + } + FileOutputStream fos = new FileOutputStream(outpath); + newwb.write(fos); + newwb.close(); + fos.close(); + } catch (Exception e) { + } + } + + /** + * 合并单元格处理,获取合并行 + * + * @param sheet + * @return List + */ + public static List getCombineCell(Sheet sheet) { + List list = new ArrayList<>(); + // 获得一个 sheet 中合并单元格的数量 + int sheetmergerCount = sheet.getNumMergedRegions(); + // 遍历所有的合并单元格 + for (int i = 0; i < sheetmergerCount; i++) { + // 获得合并单元格保存进list中 + CellRangeAddress ca = sheet.getMergedRegion(i); + list.add(ca); + } + return list; + } + + public static Workbook getWorkbook(String file) throws IOException { + Workbook workbook = null; + // FileInputStream in = new FileInputStream(file); + if (file.endsWith(XLS)) { + System.out.println("xls"); + workbook = new HSSFWorkbook(); + } else if (file.endsWith(XLSX)) { + System.out.println("xlsx"); + workbook = new XSSFWorkbook(); + } else { + System.out.println("格式错误"); + } + return workbook; + } + + public static Workbook getworkbook(File file) throws IOException { + Workbook workbook = null; + FileInputStream in = new FileInputStream(file); + if (file.getName().endsWith(XLS)) { + System.out.println("xls"); + workbook = new HSSFWorkbook(in); + } else if (file.getName().endsWith(XLSX)) { + System.out.println("xlsx"); + workbook = new XSSFWorkbook(in); + } else { + System.out.println("格式错误"); + } + in.close(); + return workbook; + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/action/BOMManagementAction.java b/src/com/connor/jd/plm/action/BOMManagementAction.java new file mode 100644 index 0000000..4382d38 --- /dev/null +++ b/src/com/connor/jd/plm/action/BOMManagementAction.java @@ -0,0 +1,25 @@ +package com.connor.jd.plm.action; + +import com.connor.jd.plm.dialogs.BOMManagementFrame; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.common.actions.AbstractAIFAction; + +public class BOMManagementAction extends AbstractAIFAction { + + private AIFDesktop app; + private AbstractAIFApplication arg2; + public BOMManagementAction(AIFDesktop arg0, String arg1,AbstractAIFApplication arg2) { + super(arg0, arg1); + // TODO Auto-generated constructor stub + this.app = arg0; + this.arg2 = arg2; + } + + @Override + public void run() { + // TODO Auto-generated method stub + new BOMManagementFrame(arg2); + } + +} diff --git a/src/com/connor/jd/plm/action/package-info.java b/src/com/connor/jd/plm/action/package-info.java new file mode 100644 index 0000000..8e74581 --- /dev/null +++ b/src/com/connor/jd/plm/action/package-info.java @@ -0,0 +1 @@ +package com.connor.jd.plm.action; \ No newline at end of file diff --git a/src/com/connor/jd/plm/beans/BOMExportBean.java b/src/com/connor/jd/plm/beans/BOMExportBean.java new file mode 100644 index 0000000..3cb287e --- /dev/null +++ b/src/com/connor/jd/plm/beans/BOMExportBean.java @@ -0,0 +1,96 @@ +package com.connor.jd.plm.beans; + +import cn.hutool.core.util.StrUtil; + +public class BOMExportBean { + private String pid;// 父id + private String prev;// 父版本 + private String cid;// 子id + private String crev;// 子版本 + private String childCount;// 子数量 + private String childUnit;// 子单位 + private String HLCount;// 回料数量 + private String SN;// 编号 + + public BOMExportBean(String pid, String prev, String cid, String crev, String childCount, String childUnit, + String HLCount, String SN) { + super(); + this.pid = pid; + this.prev = prev; + this.cid = cid; + this.crev = crev; + this.childCount = childCount; + this.childUnit = childUnit; + this.HLCount = HLCount; + this.SN = SN; + } + + public String getPid() { + return pid; + } + + public void setPid(String pid) { + this.pid = pid; + } + + public String getPrev() { + return prev; + } + + public void setPrev(String prev) { + this.prev = prev; + } + + public String getCid() { + return cid; + } + + public void setCid(String cid) { + this.cid = cid; + } + + public String getCrev() { + return crev; + } + + public void setCrev(String crev) { + this.crev = crev; + } + + public String getChildCount() { + return childCount; + } + + public void setChildCount(String childCount) { + this.childCount = childCount; + } + + public String getChildUnit() { + return childUnit; + } + + public void setChildUnit(String childUnit) { + this.childUnit = childUnit; + } + + public String getHLCount() { + return HLCount; + } + + public void setHLCount(String HLCount) { + this.HLCount = HLCount; + } + + public String getSN() { + return SN; + } + + public void setSN(String SN) { + this.SN = SN; + } + + public int isNegative() { + return StrUtil.isBlank(HLCount) ? 0 : Integer.parseInt(HLCount) < 0 ? 1 : 0; + } + +} diff --git a/src/com/connor/jd/plm/beans/BOMLogBean.java b/src/com/connor/jd/plm/beans/BOMLogBean.java new file mode 100644 index 0000000..56555fc --- /dev/null +++ b/src/com/connor/jd/plm/beans/BOMLogBean.java @@ -0,0 +1,80 @@ +package com.connor.jd.plm.beans; + +public class BOMLogBean { + private String target1; + private String target2; + private String parent; + private String operation; + private String unit; + private String oldNum; + private String num; + + public BOMLogBean(String target1, String target2, String parent, String operation, String unit, String oldNum, + String num) { + super(); + this.target1 = target1; + this.target2 = target2; + this.parent = parent; + this.operation = operation; + this.unit = unit; + this.oldNum = oldNum; + this.num = num; + } + + public String getTarget1() { + return target1; + } + + public void setTarget1(String target1) { + this.target1 = target1; + } + + public String getTarget2() { + return target2; + } + + public void setTarget2(String target2) { + this.target2 = target2; + } + + public String getParent() { + return parent; + } + + public void setParent(String parent) { + this.parent = parent; + } + + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getOldNum() { + return oldNum; + } + + public void setOldNum(String oldNum) { + this.oldNum = oldNum; + } + + public String getNum() { + return num; + } + + public void setNum(String num) { + this.num = num; + } + +} diff --git a/src/com/connor/jd/plm/beans/BOMManageTableBean.java b/src/com/connor/jd/plm/beans/BOMManageTableBean.java new file mode 100644 index 0000000..0c7600d --- /dev/null +++ b/src/com/connor/jd/plm/beans/BOMManageTableBean.java @@ -0,0 +1,74 @@ +package com.connor.jd.plm.beans; + +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItemRevision; + +public class BOMManageTableBean { + + private String parentString; + private String childString; + private TCComponentItemRevision parentRev; + private TCComponentItemRevision childRev; + private TCComponentBOMLine parentLine; + private TCComponentBOMLine childLine; + + public BOMManageTableBean(String parentString, String childString, TCComponentItemRevision parentRev, + TCComponentItemRevision childRev, TCComponentBOMLine parentLine, TCComponentBOMLine childLine) { + super(); + this.parentString = parentString; + this.childString = childString; + this.parentRev = parentRev; + this.childRev = childRev; + this.parentLine = parentLine; + this.childLine = childLine; + } + + public String getParentString() { + return parentString; + } + + public void setParentString(String parentString) { + this.parentString = parentString; + } + + public String getChildString() { + return childString; + } + + public void setChildString(String childString) { + this.childString = childString; + } + + public TCComponentItemRevision getParentRev() { + return parentRev; + } + + public void setParentRev(TCComponentItemRevision parentRev) { + this.parentRev = parentRev; + } + + public TCComponentItemRevision getChildRev() { + return childRev; + } + + public void setChildRev(TCComponentItemRevision childRev) { + this.childRev = childRev; + } + + public TCComponentBOMLine getParentLine() { + return parentLine; + } + + public void setParentLine(TCComponentBOMLine parentLine) { + this.parentLine = parentLine; + } + + public TCComponentBOMLine getChildLine() { + return childLine; + } + + public void setChildLine(TCComponentBOMLine childLine) { + this.childLine = childLine; + } + +} diff --git a/src/com/connor/jd/plm/beans/CheckBoxPo.java b/src/com/connor/jd/plm/beans/CheckBoxPo.java new file mode 100644 index 0000000..b7c280c --- /dev/null +++ b/src/com/connor/jd/plm/beans/CheckBoxPo.java @@ -0,0 +1,14 @@ +package com.connor.jd.plm.beans; + +public class CheckBoxPo { + public Object value = null; + public String text = null; + + public CheckBoxPo() { + } + + public CheckBoxPo(String text, Object value) { + this.value = value; + this.text = text; + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/beans/ClassPropBean.java b/src/com/connor/jd/plm/beans/ClassPropBean.java new file mode 100644 index 0000000..12cf40a --- /dev/null +++ b/src/com/connor/jd/plm/beans/ClassPropBean.java @@ -0,0 +1,39 @@ +package com.connor.jd.plm.beans; + +public class ClassPropBean { + private int id; + private String name; + private String value; + + public ClassPropBean(int id, String name, String value) { + super(); + this.id = id; + this.name = name; + this.value = value; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/src/com/connor/jd/plm/beans/ComponentBean.java b/src/com/connor/jd/plm/beans/ComponentBean.java new file mode 100644 index 0000000..31c5cd8 --- /dev/null +++ b/src/com/connor/jd/plm/beans/ComponentBean.java @@ -0,0 +1,101 @@ +package com.connor.jd.plm.beans; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ObservableValue; + +public class ComponentBean { + + private int compId; + private SimpleStringProperty type; + private SimpleStringProperty project; + private SimpleStringProperty time; + private SimpleStringProperty number; + private SimpleStringProperty cost; + private int addId;// 只用于添加所用 + private int stage;// 状态 0为从数据库中取出的,1为新增的,2为从数据库取出但被修改了的 + + public int getAddId() { + return addId; + } + + public void setAddId(int addId) { + this.addId = addId; + } + + public int getStage() { + return stage; + } + + public void setStage(int stage) { + this.stage = stage; + } + + public ObservableValue typeProperty() { + return type; + } + + public ObservableValue projectProperty() { + return project; + } + + public ObservableValue timeProperty() { + return time; + } + + public ObservableValue numberProperty() { + return number; + } + + public ObservableValue costProperty() { + return cost; + } + + public int getCompId() { + return compId; + } + + public void setCompId(int compId) { + this.compId = compId; + } + + public String getType() { + return type.get(); + } + + public void setType(String type) { + this.type = new SimpleStringProperty(type); + } + + public String getProject() { + return project.get(); + } + + public void setProject(String project) { + this.project = new SimpleStringProperty(project); + } + + public String getTime() { + return time.get(); + } + + public void setTime(String time) { + this.time = new SimpleStringProperty(time); + } + + public String getNumber() { + return number.get(); + } + + public void setNumber(String number) { + this.number = new SimpleStringProperty(number); + } + + public String getCost() { + return cost.get(); + } + + public void setCost(String cost) { + this.cost = new SimpleStringProperty(cost); + } + +} diff --git a/src/com/connor/jd/plm/beans/CustomLovBean.java b/src/com/connor/jd/plm/beans/CustomLovBean.java new file mode 100644 index 0000000..75157ec --- /dev/null +++ b/src/com/connor/jd/plm/beans/CustomLovBean.java @@ -0,0 +1,38 @@ +package com.connor.jd.plm.beans; + +import java.util.ArrayList; +import java.util.List; + +public class CustomLovBean { + private List sub = new ArrayList(); + public String displayName = ""; + + public CustomLovBean(String displayName) { + super(); + this.displayName = displayName; + } + + public CustomLovBean(String displayName, String[] subArray) { + super(); + this.displayName = displayName; + translateArrayToSub(subArray); + } + + public void translateArrayToSub(String[] subArray) { + for (int i = 0; i < subArray.length; i++) { + sub.add(new CustomLovBean(subArray[i])); + } + } + + public List getSub() { + return sub; + } + + public boolean hasChild() { + return sub.size() != 0; + } + + public void addSub(CustomLovBean clb) { + sub.add(clb); + } +} diff --git a/src/com/connor/jd/plm/beans/JG.java b/src/com/connor/jd/plm/beans/JG.java new file mode 100644 index 0000000..cf10668 --- /dev/null +++ b/src/com/connor/jd/plm/beans/JG.java @@ -0,0 +1,38 @@ +package com.connor.jd.plm.beans; + +public class JG { + int row; + int times; + String jg; + + public JG(int row, int times, String jg) { + super(); + this.row = row; + this.times = times; + this.jg = jg; + } + + public int getTimes() { + return times; + } + + public void setTimes(int times) { + this.times = times; + } + + public String getJg() { + return jg; + } + + public void setJg(String jg) { + this.jg = jg; + } + + public int getRow() { + return row; + } + + public void setRow(int row) { + this.row = row; + } +} diff --git a/src/com/connor/jd/plm/beans/MachineBean.java b/src/com/connor/jd/plm/beans/MachineBean.java new file mode 100644 index 0000000..51ebd0f --- /dev/null +++ b/src/com/connor/jd/plm/beans/MachineBean.java @@ -0,0 +1,75 @@ +package com.connor.jd.plm.beans; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ObservableValue; + +public class MachineBean { + + private int macId; + private SimpleStringProperty type; + private SimpleStringProperty project; + private SimpleStringProperty cost; + private int addId;// 只用于添加所用 + private int stage;// 状态 0为从数据库中取出的,1为新增的,2为从数据库取出但被修改了的 + + public int getMacId() { + return macId; + } + + public void setMacId(int macId) { + this.macId = macId; + } + + public int getAddId() { + return addId; + } + + public void setAddId(int addId) { + this.addId = addId; + } + + public int getStage() { + return stage; + } + + public void setStage(int stage) { + this.stage = stage; + } + + public ObservableValue typeProperty() { + return type; + } + + public ObservableValue projectProperty() { + return project; + } + + public ObservableValue costProperty() { + return cost; + } + + public String getType() { + return type.get(); + } + + public void setType(String type) { + this.type = new SimpleStringProperty(type); + } + + public String getProject() { + return project.get(); + } + + public void setProject(String project) { + this.project = new SimpleStringProperty(project); + } + + public String getCost() { + return cost.get(); + } + + public void setCost(String cost) { + this.cost = new SimpleStringProperty(cost); + ; + } +} diff --git a/src/com/connor/jd/plm/beans/ResultData.java b/src/com/connor/jd/plm/beans/ResultData.java new file mode 100644 index 0000000..ac5430d --- /dev/null +++ b/src/com/connor/jd/plm/beans/ResultData.java @@ -0,0 +1,39 @@ +package com.connor.jd.plm.beans; + +public class ResultData { + private boolean res; + private String Message; + private Object data; + + public ResultData(boolean res, String message, Object data) { + super(); + this.res = res; + Message = message; + this.data = data; + } + + public boolean isRes() { + return res; + } + + public void setRes(boolean res) { + this.res = res; + } + + public String getMessage() { + return Message; + } + + public void setMessage(String message) { + Message = message; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + +} diff --git a/src/com/connor/jd/plm/beans/TransformBomBean.java b/src/com/connor/jd/plm/beans/TransformBomBean.java new file mode 100644 index 0000000..20de45b --- /dev/null +++ b/src/com/connor/jd/plm/beans/TransformBomBean.java @@ -0,0 +1,36 @@ +package com.connor.jd.plm.beans; + +import java.util.HashMap; +import java.util.Map; + +import javax.swing.Icon; + +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; + +public class TransformBomBean { + public String displayName; + public TCComponentBOMLine line; + public TCComponentItemRevision selectRev; + public Map map=new HashMap<>(); + + public TransformBomBean(TCComponentBOMLine line) { + // TODO Auto-generated constructor stub + try { + this.line = line; + this.displayName=line.getProperty("object_string"); + } catch (TCException e) { + // TODO Auto-generated catch blocks + e.printStackTrace(); + } + } + + @Override + public String toString() { + // TODO Auto-generated method stub + return displayName; + } + +} diff --git a/src/com/connor/jd/plm/dialog/DocumentTemplate.java b/src/com/connor/jd/plm/dialog/DocumentTemplate.java new file mode 100644 index 0000000..60a256a --- /dev/null +++ b/src/com/connor/jd/plm/dialog/DocumentTemplate.java @@ -0,0 +1,39 @@ +package com.connor.jd.plm.dialog; + +public class DocumentTemplate { + private String type;// 模板类型 + private String[] relation;// 数据集关系 + private String uid;// 模板uid + + public DocumentTemplate(String type, String uid, String[] relation) { + super(); + this.type = type; + this.relation = relation; + this.uid = uid; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String[] getRelation() { + return relation; + } + + public void setRelation(String[] relation) { + this.relation = relation; + } + + public String getUid() { + return uid; + } + + public void setUid(String uid) { + this.uid = uid; + } + +} diff --git a/src/com/connor/jd/plm/dialog/EditClassificationDialog.java b/src/com/connor/jd/plm/dialog/EditClassificationDialog.java new file mode 100644 index 0000000..2f83ae5 --- /dev/null +++ b/src/com/connor/jd/plm/dialog/EditClassificationDialog.java @@ -0,0 +1,399 @@ +package com.connor.jd.plm.dialog; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; + +import com.connor.jd.plm.beans.ClassPropBean; +import com.connor.jd.plm.utils.ExcelInfoScanner; +import com.connor.jd.plm.utils.JDMethodUtil; +import com.connor.jd.plm.utils.StringCreateUtil; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCClassificationService; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentICO; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.ics.ICSAdminClass; +import com.teamcenter.rac.kernel.ics.ICSProperty; +import com.teamcenter.rac.kernel.ics.ICSPropertyDescription; +import com.teamcenter.rac.util.MessageBox; + +import cn.hutool.json.JSONObject; + +/** + * 修改分类属性 + */ +public class EditClassificationDialog extends AbstractAIFDialog { + + private static final long serialVersionUID = 1L; + private AbstractAIFApplication app; + private TCSession session; + private TCComponent target; + private Map propMap; + private TCClassificationService myService; + final EditClassificationDialog DIALOG = this; + private TCComponentItemRevision rev; + private int[] ids; + private String[] values; + private String[] names; + private boolean finished; + + public EditClassificationDialog(AbstractAIFApplication app) throws TCException { + this.app = app; + this.session = (TCSession) app.getSession(); + this.myService = session.getClassificationService(); + this.target = (TCComponent) AIFUtility.getCurrentApplication().getTargetComponent(); + System.out.println(target.getType()); + System.out.println(target instanceof TCComponentItemRevision ? "是" : "否"); + + if (target instanceof TCComponentItemRevision) { + try { + rev = (TCComponentItemRevision) target; + boolean isAccess = session.getTCAccessControlService().checkPrivilege(rev, "WRITE"); + if (!isAccess) { + JOptionPane.showMessageDialog(this, "没有版本修改权限,请联系系统管理员", "提示", JOptionPane.WARNING_MESSAGE); + return; + } + initUI(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + MessageBox.post("请选择版本", "错误", MessageBox.ERROR); + } + } + + private void initUI() { + this.setTitle("修改分类属性"); + this.setAutoRequestFocus(true); + this.setResizable(false); + this.setAlwaysOnTop(true); + + JPanel rootPanel = new JPanel(); + rootPanel.setLayout(null); + rootPanel.setPreferredSize(new Dimension(300, 350)); + + Map displayMap = new LinkedHashMap(); + propMap = new HashMap(); + + try { + if (rev.getClassificationClass() != null && !"".equals(rev.getClassificationClass())) { + try { + rev.refresh(); + TCComponentICO ico = rev.getClassificationObjects()[0]; + ICSProperty[] props = ico.getICSProperties(true); + ICSPropertyDescription[] desc = ico.getICSPropertyDescriptors(); + for (int i = 0; i < props.length; i++) { + System.out.println(props[i].getId() + "===>" + props[i].getValue()); + displayMap.put(props[i].getId(), + new ClassPropBean(props[i].getId(), desc[i].getName(), props[i].getValue())); + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } else { + MessageBox.post("当前版本未被分类", "错误", MessageBox.ERROR); + return; + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + if (displayMap.size() == 0) { + return; + } + + String uid = JDMethodUtil.getPrefStr("jd_class_prop_option", session); + System.out.println("uid======>" + uid); + Map propOption = null; + try { + TCComponent comp = session.stringToComponent(uid); + if (comp != null) { + TCComponentDataset op = (TCComponentDataset) comp; + String temp = System.getenv("temp"); + String[] types = op.getProperty("ref_names").split(","); + File optionFile = op.getFiles(types[0], temp)[0]; + optionFile.deleteOnExit(); + System.out.println(rev.getItem().getProperty("object_type")); + propOption = ExcelInfoScanner.getClassPropOptions(optionFile.getPath(), + rev.getItem().getProperty("object_type")); + System.out.println("propOption count======>" + propOption.size()); + } + } catch (TCException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + + JPanel content = new JPanel(); + content.setLayout(null); + content.setPreferredSize(new Dimension(300, displayMap.size() * (25 + 10))); + + int num = 0; + for (Entry entry : displayMap.entrySet()) { + JLabel label = new JLabel(entry.getValue().getName() + ":"); + label.setBounds(10, num * 35 + 10, 100, 25); + if (propOption != null && propOption.containsKey(entry.getKey())) { + String[] items = propOption.get(entry.getKey()).split(","); + JComboBox combo = new JComboBox(); + combo.addItem(" "); + for (String s : items) { + combo.addItem(s); + } + String v = entry.getValue().getValue(); + combo.setSelectedItem(v); + if (!Arrays.asList(items).contains(v)) { + combo.addItem(v); + combo.setSelectedItem(v); + } + combo.setBounds(130, num * 35 + 10, 150, 25); + propMap.put(entry.getValue().getName(), combo); + content.add(combo); + } else { + JTextField text = new JTextField(entry.getValue().getValue()); + text.setBounds(130, num * 35 + 10, 150, 25); + propMap.put(entry.getValue().getName(), text); + content.add(text); + } + + content.add(label); + + num++; + } + + JButton okBtn = new JButton("确认"); + okBtn.setBounds(40, 310, 100, 25); + okBtn.setSelected(true); + okBtn.addActionListener(ok()); + JButton cancelBtn = new JButton("取消"); + cancelBtn.setBounds(160, 310, 100, 25); + cancelBtn.addActionListener(cancel()); + + JScrollPane jsp = new JScrollPane(content); + jsp.getVerticalScrollBar().setUnitIncrement(16); + jsp.setBounds(0, 0, 300, 300); + jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + rootPanel.add(jsp); + rootPanel.add(okBtn); + rootPanel.add(cancelBtn); + this.add(rootPanel); + this.pack(); + this.centerToScreen(); + this.showDialog(); + } + + private ActionListener ok() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + ((JButton) e.getSource()).setEnabled(false); + rev = (TCComponentItemRevision) target; + + new Thread(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + int i = 1; + while (!DIALOG.finished) { + try { + DIALOG.setTitle("正在修改分类属性 " + StringCreateUtil.createPoint(i++ % 3)); + Thread.sleep(200); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + }).start(); + saveClassification(rev); +// try { +// System.out.println(rev.getProperty("object_string")); +// if (rev.getType().equals("JD2_GTBJRevision")) { +// TCComponent[] comps = rev.getReferenceListProperty("TC_Is_Represented_By"); +// System.out.println(comps.length); +// for (int i = 0; i < comps.length; i++) { +// if (comps[i].getType().equals("JD2_XYJTZRevision")) { +// System.out.println("object_string:" + comps[i].getProperty("object_string")); +// TCComponentItemRevision tzrev = (TCComponentItemRevision) comps[i]; +// saveClassification(tzrev); +// } +// } +// } +// } catch (TCException e1) { +// // TODO Auto-generated catch block +// e1.printStackTrace(); +// } + } + }; + } + + private ActionListener cancel() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + DIALOG.disposeDialog(); + } + }; + } + + private boolean saveClassification(TCComponentItemRevision rev) { + + try { + TCComponentForm form = (TCComponentForm) rev.getRelatedComponents("IMAN_master_form_rev")[0]; + TCComponent[] status = form.getRelatedComponents("release_status_list"); + for (TCComponent comp : status) { + if (comp.getProperty("object_name").contains("正式")) { + JOptionPane.showMessageDialog(this, "版本表单已正式发布,不允许修改分类属性", "提示", JOptionPane.WARNING_MESSAGE); + return false; + } + } + TCComponentICO[] icoS = rev.getClassificationObjects(); + System.out.println("======>获取的分类对象有:" + icoS.length); + String classID = rev.getClassificationClass(); + if (icoS == null || icoS.length == 0) { + return false; + } + for (int i = 0; i < icoS.length; i++) { + TCComponentICO ico = icoS[i]; + ICSPropertyDescription[] desc = ico.getICSPropertyDescriptors(); + ICSProperty[] oldICSProps = ico.getICSProperties(true); + ids = new int[oldICSProps.length]; + values = new String[oldICSProps.length]; + names = new String[oldICSProps.length]; + for (int j = 0; j < oldICSProps.length; j++) { + ids[j] = oldICSProps[j].getId(); + if (propMap.get(desc[j].getName()) instanceof JComboBox) { + String str = ((JComboBox) propMap.get(desc[j].getName())).getSelectedItem().toString(); + values[j] = " ".equals(str) ? "" : str; + } else { + values[j] = ((JTextField) propMap.get(desc[j].getName())).getText(); + } + names[j] = desc[j].getName(); + } + + JSONObject obj = new JSONObject(); + obj.put("ids", ids); + obj.put("values", values); + String prop = obj.toString(); +// prop = prop.replace("\"", "\\\""); + String server = JDMethodUtil.getPrefStr("jd2_server_ip", session); + if (server == null || "".equals(server)) { + MessageBox.post("未配置jd2_server_ip首选项", "错误", MessageBox.ERROR); + return false; + } + String url = "http://" + server + ":8880/api/sendClassification"; + Map paramMap = new HashMap(); + String uid = rev.getUid(); + paramMap.put("uid", uid); + paramMap.put("cid", classID); + paramMap.put("prop", prop); + System.out.println(url); + System.out.println(prop); + final String URL = url; + final Map PARAMMAP = paramMap; + final TCComponentItemRevision REV = rev; + + new Thread(new Runnable() { + @Override + public void run() { + // TODO Auto-generated method stub + String res = cn.hutool.http.HttpUtil.post(URL, PARAMMAP); + System.out.println("uid===>" + "" + " res===>" + res); + finish(); + } + }).start(); + + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog(null, e1, "错误", JOptionPane.ERROR_MESSAGE); + } + return true; + } + + private void finish() { + try { + rev.refresh(); + String[] prefArr = JDMethodUtil.getPrefStrArray("jd2_custom_display_name", session); + String classAddress = getClassificationAddress(rev.getClassificationClass()); + System.out.println("classAddress=====>" + classAddress); + for (String pref : prefArr) { + String[] className = pref.split(":")[0].split("/"); + if (classAddress.contains(className[0]) && classAddress.contains(className[1])) { + String[] prefClassNamesArr = pref.split(":")[1].split(","); + System.out.println("pref class porp names=====>" + Arrays.toString(prefClassNamesArr)); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < prefClassNamesArr.length; i++) { + System.out.println(prefClassNamesArr[i]); + for (int ii = 0; ii < names.length; ii++) { + System.out.println(names[ii]); + if (prefClassNamesArr[i].equals(names[ii]) && !"".equals(values[ii].trim())) { + builder.append(values[ii] + ","); + } + } + } + String temp = builder.length() > 0 + ? builder.toString().substring(0, builder.toString().length() - 1) + : ""; + System.out.println("class porp values=====>" + temp); +// session.getUserService().call("bs_bypass", new Object[] { true }); + rev.lock(); + rev.setProperty("jd2_flfh", temp); + rev.save(); + rev.unlock(); + rev.refresh(); +// session.getUserService().call("bs_bypass", new Object[] { false }); + break; + } + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "首选项jd2_custom_display_name配置有误,请检查\r\n" + e.getMessage(), "提示", + JOptionPane.WARNING_MESSAGE); + return; + } + DIALOG.finished = true; + DIALOG.disposeDialog(); + JOptionPane.showMessageDialog(null, "修改分类成功", "提示", JOptionPane.WARNING_MESSAGE); + System.out.println("success"); + } + + private String getClassificationAddress(String classId) throws TCException { + ICSAdminClass clazz = session.getClassificationService().newICSAdminClass(); + clazz.load(classId); + if ("ICM".equals(clazz.askClassId())) { + return "根"; + } + return clazz.getName() + "=>" + getClassificationAddress(clazz.getParent()); + } +} diff --git a/src/com/connor/jd/plm/dialog/package-info.java b/src/com/connor/jd/plm/dialog/package-info.java new file mode 100644 index 0000000..803ca64 --- /dev/null +++ b/src/com/connor/jd/plm/dialog/package-info.java @@ -0,0 +1 @@ +package com.connor.jd.plm.dialog; \ No newline at end of file diff --git a/src/com/connor/jd/plm/dialogs/BOMManagementFrame.java b/src/com/connor/jd/plm/dialogs/BOMManagementFrame.java new file mode 100644 index 0000000..3a5d76e --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/BOMManagementFrame.java @@ -0,0 +1,2155 @@ +package com.connor.jd.plm.dialogs; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.Vector; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.RowSorter; +import javax.swing.filechooser.FileSystemView; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableRowSorter; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; + +import com.connor.jd.plm.beans.BOMManageTableBean; +import com.connor.jd.plm.beans.CheckBoxPo; +import com.connor.jd.plm.beans.CustomLovBean; +import com.connor.jd.plm.beans.ResultData; +import com.connor.jd.plm.table.MyCellEditor4; +import com.connor.jd.plm.table.MyCellRenderer; +import com.connor.jd.plm.utils.DBConnectionUtil; +import com.connor.jd.plm.utils.DBUtil; +import com.connor.jd.plm.utils.DatePickerUtil; +import com.connor.jd.plm.utils.DialogUtil; +import com.connor.jd.plm.utils.JDMethodUtil; +import com.connor.jd.plm.utils.KeyValComboBox; +import com.connor.jd.plm.utils.SimpleExcelUtil; +import com.connor.jd.plm.utils.StringCreateUtil; +import com.eltima.components.ui.DatePicker; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +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.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.workflow.commands.newprocess.NewProcessCommand; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.db.Db; +import cn.hutool.db.Entity; +import cn.hutool.db.sql.Condition; + +public class BOMManagementFrame extends JFrame { + private AbstractAIFApplication app; + private TCSession session; + private CardLayout rootSwitch = new CardLayout(); + private String[] colDisplayNames = new String[] { "选择", "组件对象", "子件对象", "单位", "数量", "状态" }; + private String[] colDisplayNames2 = new String[] { "序号", "修改用户", "更改时间", "更改内容" }; + private JPanel root; + private Map tableDataMap = new HashMap(); + private BOMManagementFrame $this; + private List logDataList; + private Map winMap = new HashMap(); + private TCComponentItemRevision targetRev; + private TCComponentItemRevision targetRev2; + private boolean isLogcreated = false; + private int doIndex = 0; + private boolean complate = false; + private List checkItemType = new ArrayList(); + private JButton[] topBtns; + private TCComponentBOMWindowType winType; + private int width = 1200; + private int height = 800; + private int widthOffset = 0; + private int heightOffset = 0; + private JLabel p1TargetLabel; + private JButton p1TargetBtn; + private JLabel p1ReplaceLabel; + private JButton p1ReplaceBtn; + private JLabel p1UnitLabel; + private KeyValComboBox p1UnitCombo; + private JLabel p1NumLabel; + private JTextField p1NumText; + private JCheckBox p1SelectAll; + private JTable p1Table; + private JScrollPane p1jsp; + private JButton p1BottomBtn1; + private JButton p1BottomBtn2; + private JButton p1BottomBtn3; + private JButton p1BottomBtn4; + private JPanel p1Left; + private JScrollPane p1TreePanel; + private JPanel p1Right; + private JLabel p2TargetLabel; + private JButton p2TargetBtn; + private JLabel p2ChangeNumLabel; + private JTextField p2NumText; + private JCheckBox p2SelectAll; + private JTable p2Table; + private JScrollPane p2jsp; + private JButton p2BottomBtn1; + private JButton p2BottomBtn2; + private JButton p2BottomBtn3; + private JButton p2BottomBtn4; + private JPanel p2Left; + private JScrollPane p2TreePanel; + private JPanel p2Right; + private JLabel p3TargetLabel; + private JButton p3TargetBtn; + private JLabel p3AddLabel; + private JButton p3AddBtn; + private JLabel p3UnitLabel; + private KeyValComboBox p3UnitCombo; + private JLabel p3NumLabel; + private JTextField p3NumText; + private JCheckBox p3SelectAll; + private JTable p3Table; + private JScrollPane p3jsp; + private JButton p3BottomBtn1; + private JButton p3BottomBtn2; + private JButton p3BottomBtn3; + private JButton p3BottomBtn4; + private JPanel p3Left; + private JScrollPane p3TreePanel; + private JPanel p3Right; + private JLabel p4TargetLabel; + private JButton p4TargetBtn; + private JCheckBox p4SelectAll; + private JTable p4Table; + private JScrollPane p4jsp; + private JButton p4BottomBtn1; + private JButton p4BottomBtn2; + private JButton p4BottomBtn3; + private JButton p4BottomBtn4; + private JPanel p4Left; + private JScrollPane p4TreePanel; + private JPanel p4Right; + private JLabel p5UserLabel; + private JTextField p5UserText; + private JLabel p5TimeLabel; + private DatePicker p5TimeStartText; + private JLabel toLabel; + private DatePicker p5TimeEndText; + private JLabel p5ContentLabel; + private JTextArea p5ContentText; + private JScrollPane p5Contentjsp; + private JButton p5Search; + private JComboBox p5Download; + private JTable p5Table; + private JScrollPane p5jsp; + private Map uiSize = new HashMap<>(); + private JPanel p1; + private JPanel p2; + private JPanel p3; + private JPanel p4; + private JPanel p5; + private Set addedBOMLine = new HashSet<>(); + + public BOMManagementFrame(AbstractAIFApplication app) { + super(); + this.app = app; + this.session = (TCSession) app.getSession(); + $this = this; + String[] prefArray = JDMethodUtil.getPrefStrArray("connor_bom_check_type", session); + if (prefArray != null) { + checkItemType = Arrays.asList(prefArray); + } + TCTypeService service = session.getTypeService(); + try { + this.winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + init(); + } + + private void init() { + this.setTitle("BOM管理"); + this.setSize(new Dimension(1200, 800)); + this.setLayout(new BorderLayout()); + this.setResizable(true); + this.setAlwaysOnTop(true); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setLocationRelativeTo(null); + this.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + // TODO Auto-generated method stub + super.componentResized(e); + Component comp = e.getComponent(); + $this.widthOffset = comp.getWidth() - $this.width; + $this.heightOffset = comp.getHeight() - $this.height; + if ($this.widthOffset != 0 || $this.heightOffset != 0) { + System.out.println("width===>" + comp.getWidth()); + System.out.println("height===>" + comp.getHeight()); + $this.width = comp.getWidth(); + $this.height = comp.getHeight(); + $this.resize(); + } + } + }); + this.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void focusGained(FocusEvent e) { + // TODO Auto-generated method stub + $this.setAlwaysOnTop(true); + } + }); + + Container container = this.getContentPane(); + container.setLayout(new BorderLayout()); + container.setSize(new Dimension(1200, 800)); + + TCTypeService typeService = session.getTypeService(); + Vector unitVector = new Vector(); + try { + TCComponent[] uomArray = typeService.getTypeComponent("UnitOfMeasure").extent(); + unitVector.add(new CheckBoxPo(" ", " ")); + for (TCComponent comp : uomArray) { + unitVector.add(new CheckBoxPo(comp.toString(), comp)); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // 头部 + JPanel topBtnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + topBtns = new JButton[5]; + topBtns[0] = new JButton("批量替换"); + topBtns[1] = new JButton("批量更改"); + topBtns[2] = new JButton("批量新增"); + topBtns[3] = new JButton("批量删除"); + topBtns[4] = new JButton("更新日志"); + topBtns[0].setSelected(true); + for (JButton btn : topBtns) { + topBtnPanel.add(btn); + btn.addActionListener(panelSwitch()); + } + container.add(topBtnPanel, BorderLayout.NORTH); + + // root + root = new JPanel(rootSwitch); + + // 批量替换 + p1 = new JPanel(); + p1.setLayout(null); + + // 批量替换左边 + p1Left = new JPanel(); + p1Left.setLayout(null); + p1Left.setBounds(0, 0, 800, 800); + p1Left.setBorder(BorderFactory.createEtchedBorder()); + + p1TargetLabel = new JLabel("目标物料编码"); + p1TargetLabel.setBounds(20, 20, 100, 25); + p1TargetBtn = new JButton(); + p1TargetBtn.setBounds(130, 20, 400, 25); + p1ReplaceLabel = new JLabel("替换物料编码"); + p1ReplaceLabel.setBounds(20, 60, 100, 25); + p1ReplaceBtn = new JButton(); + p1ReplaceBtn.setBounds(130, 60, 400, 25); + p1UnitLabel = new JLabel("单位"); + p1UnitLabel.setBounds(560, 60, 50, 25); + p1UnitCombo = new KeyValComboBox(unitVector); + p1UnitCombo.setBounds(610, 60, 50, 25); + p1NumLabel = new JLabel("数量"); + p1NumLabel.setBounds(680, 60, 50, 25); + p1NumText = new JTextField(); + p1NumText.setBounds(730, 60, 50, 25); + p1SelectAll = new JCheckBox("全选"); + p1SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p1model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p1Table = new JTable(p1model); + p1Table.getColumnModel().getColumn(0).setMinWidth(60); + p1Table.getColumnModel().getColumn(0).setMaxWidth(60); + p1Table.getColumnModel().getColumn(1).setMinWidth(200); + p1Table.getColumnModel().getColumn(2).setMinWidth(200); + p1Table.getColumnModel().getColumn(3).setMinWidth(100); + p1Table.getColumnModel().getColumn(4).setMinWidth(100); + p1Table.getColumnModel().getColumn(5).setMinWidth(100); + p1Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p1Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p1Table.setRowHeight(25); + p1Table.setAutoscrolls(true); + p1Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p1Table.getTableHeader().setReorderingAllowed(false); + p1Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p1sorter = new TableRowSorter(p1model); + p1Table.setRowSorter(p1sorter); + p1jsp = new JScrollPane(p1Table); + p1jsp.setBounds(20, 130, 760, 500); + + p1BottomBtn1 = new JButton("批量升版"); + p1BottomBtn1.setBounds(80, 650, 100, 25); + p1BottomBtn2 = new JButton("批量替换"); + p1BottomBtn2.setBounds(260, 650, 100, 25); + p1BottomBtn3 = new JButton("发起流程"); + p1BottomBtn3.setBounds(440, 650, 100, 25); + p1BottomBtn4 = new JButton("取消"); + p1BottomBtn4.setBounds(620, 650, 100, 25); + + p1Left.add(p1TargetLabel); + p1Left.add(p1TargetBtn); + p1Left.add(p1ReplaceLabel); + p1Left.add(p1ReplaceBtn); + p1Left.add(p1UnitLabel); + p1Left.add(p1UnitCombo); + p1Left.add(p1NumLabel); + p1Left.add(p1NumText); + p1Left.add(p1SelectAll); + p1Left.add(p1jsp); + p1Left.add(p1BottomBtn1); + p1Left.add(p1BottomBtn2); + p1Left.add(p1BottomBtn3); + p1Left.add(p1BottomBtn4); + + // 批量替换右边 + p1Right = new JPanel(); + p1Right.setLayout(null); + p1Right.setBounds(800, 0, 400, 800); + p1Right.setBorder(BorderFactory.createEtchedBorder()); + + p1TreePanel = new JScrollPane(); + p1TreePanel.setBounds(20, 130, 360, 500); + p1Right.add(p1TreePanel); + + // 绑定事件 + p1SelectAll.addItemListener(selectAll(p1Table)); + p1Table.addMouseListener(showTree(p1Right)); + p1BottomBtn4.addActionListener(cancel()); + p1BottomBtn1.addActionListener(batchRevise(p1Table, p1SelectAll)); + p1BottomBtn2.addActionListener(batchReplace()); + p1BottomBtn3.addActionListener(startWorkFlow(p1Table)); + p1TargetBtn.addActionListener(clickSearch(p1Table, p1SelectAll)); + p1ReplaceBtn.addActionListener(clickSearch(null, null)); + + p1.add(p1Left); + p1.add(p1Right); + + // 批量更改 + p2 = new JPanel(); + p2.setLayout(null); + + // 批量更改左边 + p2Left = new JPanel(); + p2Left.setLayout(null); + p2Left.setBounds(0, 0, 800, 800); + p2Left.setBorder(BorderFactory.createEtchedBorder()); + + p2TargetLabel = new JLabel("目标物料编码"); + p2TargetLabel.setBounds(20, 20, 100, 25); + p2TargetBtn = new JButton(); + p2TargetBtn.setBounds(130, 20, 400, 25); + p2ChangeNumLabel = new JLabel("更改用量"); + p2ChangeNumLabel.setBounds(20, 60, 100, 25); + p2NumText = new JTextField(); + p2NumText.setBounds(130, 60, 50, 25); + + p2SelectAll = new JCheckBox("全选"); + p2SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p2model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p2Table = new JTable(p2model); + p2Table.getColumnModel().getColumn(0).setMinWidth(60); + p2Table.getColumnModel().getColumn(0).setMaxWidth(60); + p2Table.getColumnModel().getColumn(1).setMinWidth(200); + p2Table.getColumnModel().getColumn(2).setMinWidth(200); + p2Table.getColumnModel().getColumn(3).setMinWidth(100); + p2Table.getColumnModel().getColumn(4).setMinWidth(100); + p2Table.getColumnModel().getColumn(5).setMinWidth(100); + p2Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p2Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p2Table.setRowHeight(25); + p2Table.setAutoscrolls(true); + p2Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p2Table.getTableHeader().setReorderingAllowed(false); + p2Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p2sorter = new TableRowSorter(p2model); + p2Table.setRowSorter(p2sorter); + p2jsp = new JScrollPane(p2Table); + p2jsp.setBounds(20, 130, 760, 500); + + p2BottomBtn1 = new JButton("批量升版"); + p2BottomBtn1.setBounds(80, 650, 100, 25); + p2BottomBtn2 = new JButton("批量更改"); + p2BottomBtn2.setBounds(260, 650, 100, 25); + p2BottomBtn3 = new JButton("发起流程"); + p2BottomBtn3.setBounds(440, 650, 100, 25); + p2BottomBtn4 = new JButton("取消"); + p2BottomBtn4.setBounds(620, 650, 100, 25); + + p2Left.add(p2TargetLabel); + p2Left.add(p2TargetBtn); + p2Left.add(p2ChangeNumLabel); + p2Left.add(p2NumText); + p2Left.add(p2SelectAll); + p2Left.add(p2jsp); + p2Left.add(p2BottomBtn1); + p2Left.add(p2BottomBtn2); + p2Left.add(p2BottomBtn3); + p2Left.add(p2BottomBtn4); + + // 批量更改右边 + p2Right = new JPanel(); + p2Right.setLayout(null); + p2Right.setBounds(800, 0, 400, 800); + p2Right.setBorder(BorderFactory.createEtchedBorder()); + + p2TreePanel = new JScrollPane(); + p2TreePanel.setBounds(20, 130, 360, 500); + p2Right.add(p2TreePanel); + + // 绑定事件 + p2SelectAll.addItemListener(selectAll(p2Table)); + p2Table.addMouseListener(showTree(p2Right)); + p2BottomBtn4.addActionListener(cancel()); + p2BottomBtn1.addActionListener(batchRevise(p2Table, p2SelectAll)); + p2BottomBtn2.addActionListener(batchModify()); + p2BottomBtn3.addActionListener(startWorkFlow(p2Table)); + p2TargetBtn.addActionListener(clickSearch(p2Table, p2SelectAll)); + + p2.add(p2Left); + p2.add(p2Right); + + // 批量新增 + p3 = new JPanel(); + p3.setLayout(null); + + // 批量新增左边 + p3Left = new JPanel(); + p3Left.setLayout(null); + p3Left.setBounds(0, 0, 800, 800); + p3Left.setBorder(BorderFactory.createEtchedBorder()); + + p3TargetLabel = new JLabel("参考物料编码"); + p3TargetLabel.setBounds(20, 20, 100, 25); + p3TargetBtn = new JButton(); + p3TargetBtn.setBounds(130, 20, 400, 25); + p3AddLabel = new JLabel("新增物料编码"); + p3AddLabel.setBounds(20, 60, 100, 25); + p3AddBtn = new JButton(); + p3AddBtn.setBounds(130, 60, 400, 25); + p3UnitLabel = new JLabel("单位"); + p3UnitLabel.setBounds(560, 60, 50, 25); + p3UnitCombo = new KeyValComboBox(unitVector); + p3UnitCombo.setBounds(610, 60, 50, 25); + p3NumLabel = new JLabel("数量"); + p3NumLabel.setBounds(680, 60, 50, 25); + p3NumText = new JTextField(); + p3NumText.setBounds(730, 60, 50, 25); + + p3SelectAll = new JCheckBox("全选"); + p3SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p3model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p3Table = new JTable(p3model); + p3Table.getColumnModel().getColumn(0).setMinWidth(60); + p3Table.getColumnModel().getColumn(0).setMaxWidth(60); + p3Table.getColumnModel().getColumn(1).setMinWidth(200); + p3Table.getColumnModel().getColumn(2).setMinWidth(200); + p3Table.getColumnModel().getColumn(3).setMinWidth(100); + p3Table.getColumnModel().getColumn(4).setMinWidth(100); + p3Table.getColumnModel().getColumn(5).setMinWidth(100); + p3Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p3Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p3Table.setRowHeight(25); + p3Table.setAutoscrolls(true); + p3Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p3Table.getTableHeader().setReorderingAllowed(false); + p3Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p3sorter = new TableRowSorter(p3model); + p3Table.setRowSorter(p3sorter); + p3jsp = new JScrollPane(p3Table); + p3jsp.setBounds(20, 130, 760, 500); + + p3BottomBtn1 = new JButton("批量升版"); + p3BottomBtn1.setBounds(80, 650, 100, 25); + p3BottomBtn2 = new JButton("批量新增"); + p3BottomBtn2.setBounds(260, 650, 100, 25); + p3BottomBtn3 = new JButton("发起流程"); + p3BottomBtn3.setBounds(440, 650, 100, 25); + p3BottomBtn4 = new JButton("取消"); + p3BottomBtn4.setBounds(620, 650, 100, 25); + + p3Left.add(p3TargetLabel); + p3Left.add(p3TargetBtn); + p3Left.add(p3AddLabel); + p3Left.add(p3AddBtn); + p3Left.add(p3UnitLabel); + p3Left.add(p3UnitCombo); + p3Left.add(p3NumLabel); + p3Left.add(p3NumText); + p3Left.add(p3SelectAll); + p3Left.add(p3jsp); + p3Left.add(p3BottomBtn1); + p3Left.add(p3BottomBtn2); + p3Left.add(p3BottomBtn3); + p3Left.add(p3BottomBtn4); + + // 批量新增右边 + p3Right = new JPanel(); + p3Right.setLayout(null); + p3Right.setBounds(800, 0, 400, 800); + p3Right.setBorder(BorderFactory.createEtchedBorder()); + + p3TreePanel = new JScrollPane(); + p3TreePanel.setBounds(20, 130, 360, 500); + p3Right.add(p3TreePanel); + + // 绑定事件 + p3SelectAll.addItemListener(selectAll(p3Table)); + p3Table.addMouseListener(showTree(p3Right)); + p3BottomBtn4.addActionListener(cancel()); + p3BottomBtn1.addActionListener(batchRevise(p3Table, p3SelectAll)); + p3BottomBtn2.addActionListener(batchAdd()); + p3BottomBtn3.addActionListener(startWorkFlow(p3Table)); + p3TargetBtn.addActionListener(clickSearch(p3Table, p3SelectAll)); + p3AddBtn.addActionListener(clickSearch(null, null)); + + p3.add(p3Left); + p3.add(p3Right); + + // 批量删除 + p4 = new JPanel(); + p4.setLayout(null); + + // 批量删除左边 + p4Left = new JPanel(); + p4Left.setLayout(null); + p4Left.setBounds(0, 0, 800, 800); + p4Left.setBorder(BorderFactory.createEtchedBorder()); + + p4TargetLabel = new JLabel("目标物料编码"); + p4TargetLabel.setBounds(20, 20, 100, 25); + p4TargetBtn = new JButton(); + p4TargetBtn.setBounds(130, 20, 400, 25); + + p4SelectAll = new JCheckBox("全选"); + p4SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p4model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p4Table = new JTable(p4model); + p4Table.getColumnModel().getColumn(0).setMinWidth(60); + p4Table.getColumnModel().getColumn(0).setMaxWidth(60); + p4Table.getColumnModel().getColumn(1).setMinWidth(200); + p4Table.getColumnModel().getColumn(2).setMinWidth(200); + p4Table.getColumnModel().getColumn(3).setMinWidth(100); + p4Table.getColumnModel().getColumn(4).setMinWidth(100); + p4Table.getColumnModel().getColumn(5).setMinWidth(100); + p4Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p4Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p4Table.setRowHeight(25); + p4Table.setAutoscrolls(true); + p4Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p4Table.getTableHeader().setReorderingAllowed(false); + p4Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p4sorter = new TableRowSorter(p4model); + p4Table.setRowSorter(p4sorter); + p4jsp = new JScrollPane(p4Table); + p4jsp.setBounds(20, 130, 760, 500); + + p4BottomBtn1 = new JButton("批量升版"); + p4BottomBtn1.setBounds(80, 650, 100, 25); + p4BottomBtn2 = new JButton("批量删除"); + p4BottomBtn2.setBounds(260, 650, 100, 25); + p4BottomBtn3 = new JButton("发起流程"); + p4BottomBtn3.setBounds(440, 650, 100, 25); + p4BottomBtn4 = new JButton("取消"); + p4BottomBtn4.setBounds(620, 650, 100, 25); + + p4Left.add(p4TargetLabel); + p4Left.add(p4TargetBtn); + p4Left.add(p4SelectAll); + p4Left.add(p4jsp); + p4Left.add(p4BottomBtn1); + p4Left.add(p4BottomBtn2); + p4Left.add(p4BottomBtn3); + p4Left.add(p4BottomBtn4); + + // 批量新增右边 + p4Right = new JPanel(); + p4Right.setLayout(null); + p4Right.setBounds(800, 0, 400, 800); + p4Right.setBorder(BorderFactory.createEtchedBorder()); + + p4TreePanel = new JScrollPane(); + p4TreePanel.setBounds(20, 130, 360, 500); + p4Right.add(p4TreePanel); + + // 绑定事件 + p4SelectAll.addItemListener(selectAll(p4Table)); + p4Table.addMouseListener(showTree(p4Right)); + p4BottomBtn4.addActionListener(cancel()); + p4BottomBtn1.addActionListener(batchRevise(p4Table, p4SelectAll)); + p4BottomBtn2.addActionListener(batchRemove()); + p4BottomBtn3.addActionListener(startWorkFlow(p4Table)); + p4TargetBtn.addActionListener(clickSearch(p4Table, p4SelectAll)); + + p4.add(p4Left); + p4.add(p4Right); + + // 更新日志 + p5 = new JPanel(); + p5.setLayout(null); + + p5UserLabel = new JLabel("修改用户"); + p5UserLabel.setBounds(20, 40, 70, 25); + p5UserText = new JTextField(); + p5UserText.setBounds(100, 40, 150, 25); + p5TimeLabel = new JLabel("修改时间"); + p5TimeLabel.setBounds(300, 40, 70, 25); + p5TimeStartText = DatePickerUtil.getDatePicker(null); + p5TimeStartText.setBounds(380, 40, 100, 25); + toLabel = new JLabel("到"); + toLabel.setBounds(490, 40, 20, 25); + p5TimeEndText = DatePickerUtil.getDatePicker(null); + p5TimeEndText.setBounds(520, 40, 100, 25); + p5ContentLabel = new JLabel("修改内容"); + p5ContentLabel.setBounds(670, 40, 70, 25); + p5ContentText = new JTextArea(); + p5ContentText.setLineWrap(true); + p5ContentText.setWrapStyleWord(true); + p5Contentjsp = new JScrollPane(p5ContentText); + p5Contentjsp.setBounds(750, 20, 200, 80); + p5Search = new JButton("搜索"); + p5Search.setBounds(1000, 40, 60, 25); + p5Download = new JComboBox(); + p5Download.addItem("导出日志"); + p5Download.addItem("导出为txt"); + p5Download.addItem("导出为excel"); + p5Download.setSelectedItem("导出日志"); + p5Download.setBounds(1080, 40, 100, 25); + + DefaultTableModel p5model = new DefaultTableModel(colDisplayNames2, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p5Table = new JTable(p5model); + p5Table.getColumnModel().getColumn(0).setMinWidth(60); + p5Table.getColumnModel().getColumn(0).setMaxWidth(60); + p5Table.getColumnModel().getColumn(1).setMinWidth(200); + p5Table.getColumnModel().getColumn(2).setMinWidth(200); + p5Table.getColumnModel().getColumn(3).setMinWidth(700); + p5Table.setRowHeight(25); + p5Table.setAutoscrolls(true); + p5Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p5Table.getTableHeader().setReorderingAllowed(false); + RowSorter p5sorter = new TableRowSorter(p5model); + p5Table.setRowSorter(p5sorter); + p5jsp = new JScrollPane(p5Table); + p5jsp.setBounds(20, 130, 1160, 580); + + // 绑定事件 + p5Search.addActionListener(searchLog()); + p5Download.addItemListener(downloadLog(p5Table)); + p5UserText.addKeyListener(logSearchEnter()); + p5TimeStartText.addKeyListener(logSearchEnter()); + p5TimeEndText.addKeyListener(logSearchEnter()); + + p5.add(p5UserLabel); + p5.add(p5UserText); + p5.add(p5TimeLabel); + p5.add(p5TimeStartText); + p5.add(toLabel); + p5.add(p5TimeEndText); + p5.add(p5ContentLabel); + p5.add(p5Contentjsp); + p5.add(p5Search); + p5.add(p5Download); + p5.add(p5jsp); + + root.add("batchReplace", p1); + root.add("batchModify", p2); + root.add("batchAdd", p3); + root.add("batchRemove", p4); + root.add("updateLog", p5); + + rootSwitch.show(root, "batchReplace"); + container.add(root, BorderLayout.CENTER); + this.setVisible(true); + } + + private ActionListener panelSwitch() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String text = ((JButton) e.getSource()).getText(); + for (int i = 0; i < topBtns.length; i++) { + topBtns[i].setSelected(topBtns[i].getText().equals(text)); + } + switch (text) { + case "批量替换": + clearTable(p1Table, p1SelectAll); + p1Right.removeAll(); + JScrollPane panel1 = new JScrollPane(); + panel1.setBounds(p1TreePanel.getX(), p1TreePanel.getY(), p1TreePanel.getWidth(), + p1TreePanel.getHeight()); + p1TreePanel = panel1; + p1Right.add(panel1); + p1Right.revalidate(); + p1Right.repaint(); + rootSwitch.show(root, "batchReplace"); + break; + case "批量更改": + clearTable(p2Table, p2SelectAll); + p2Right.removeAll(); + JScrollPane panel2 = new JScrollPane(); + panel2.setBounds(p2TreePanel.getX(), p2TreePanel.getY(), p2TreePanel.getWidth(), + p2TreePanel.getHeight()); + p2TreePanel = panel2; + p2Right.add(panel2); + p2Right.revalidate(); + p2Right.repaint(); + rootSwitch.show(root, "batchModify"); + break; + case "批量新增": + clearTable(p3Table, p3SelectAll); + p3Right.removeAll(); + JScrollPane panel3 = new JScrollPane(); + panel3.setBounds(p3TreePanel.getX(), p3TreePanel.getY(), p3TreePanel.getWidth(), + p3TreePanel.getHeight()); + p3TreePanel = panel3; + p3Right.add(panel3); + p3Right.revalidate(); + p3Right.repaint(); + rootSwitch.show(root, "batchAdd"); + break; + case "批量删除": + clearTable(p4Table, p4SelectAll); + p4Right.removeAll(); + JScrollPane panel4 = new JScrollPane(); + panel4.setBounds(p4TreePanel.getX(), p4TreePanel.getY(), p4TreePanel.getWidth(), + p4TreePanel.getHeight()); + p4TreePanel = panel4; + p4Right.add(panel4); + p4Right.revalidate(); + p4Right.repaint(); + rootSwitch.show(root, "batchRemove"); + break; + case "更新日志": + createLogDataSourceTable(); + clearTable(p5Table, null); + rootSwitch.show(root, "updateLog"); + break; + default: +// createLogDataSourceTable(); + } + } + }; + } + + private void showWhereUesd(JTable table, JCheckBox selectAll) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + // TODO Auto-generated method stub + clearTable(table, selectAll); + if (table == null || targetRev == null) { + return; + } + long startTime = System.currentTimeMillis(); + List tableDataList = new ArrayList(); + try { + String revString = targetRev.getProperty("object_string"); + TCComponent[] usedComps = targetRev.whereUsed((short) 0); + System.out.println("装配个数======>" + usedComps.length); + + tableDataMap.clear(); +// Map usedMap = usedFilter(usedComps); +// for (Entry entry : usedMap.entrySet()) { + for (TCComponentItemRevision parentRev : usedFilter(usedComps)) { +// TCComponentItemRevision parentRev = entry.getValue(); + String parentString = parentRev.getProperty("object_string"); + TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + TCComponentBOMWindow win = winType.create(null); + TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null); + winMap.put(parentString, win); + AIFComponentContext[] aifs = topLine.getChildren(); + for (AIFComponentContext aif : aifs) { + TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent(); + if (revString.equals(child.getItemRevision().getProperty("object_string"))) { + + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + + Object[] rowData = new Object[] { new JCheckBox(), parentString, revString, unit, num, status }; + rowPrint(rowData); + tableDataList.add(rowData); + tableDataMap.put(parentString, + new BOMManageTableBean(parentString, revString, parentRev, targetRev, topLine, child)); + // TODO 如果bom下有一样的child,可能会异常,操作只会影响第一个 + break; + } + } + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + if (tableDataList == null || tableDataList.size() == 0) { + JOptionPane.showMessageDialog($this, "找到编码对应对象,但该对象没有用于任何装配或者装配该对象的均不是最新版本,请确认编码是否正确", "提示", + JOptionPane.WARNING_MESSAGE); + return; + } + + for (Object[] rowData : tableDataList) { + model.addRow(rowData); + } + table.revalidate(); + table.repaint(); + System.out.println("装配显示完成,用时" + (System.currentTimeMillis() - startTime) + "ms"); + } + + private MouseAdapter showTree(final JPanel panelRight) { + return new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + JTable table = (JTable) e.getSource(); + String parentString = table.getValueAt(table.getSelectedRow(), 1).toString(); + System.out.println("select row=====>" + table.getSelectedRow()); + System.out.println("parentName=====>" + parentString); + CustomLovBean lovBean = null; + try { + lovBean = new CustomLovBean(tableDataMap.get(parentString).getChildString()); + CustomLovBean subBean = new CustomLovBean(parentString); + lovBean.addSub(subBean); + getTreeData(tableDataMap.get(parentString).getParentRev(), subBean); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + panelRight.removeAll(); + JTree tree = createTree(lovBean); + JScrollPane treePanel = new JScrollPane(tree); + treePanel.setBounds(20, 130, 360, 500); + panelRight.add(treePanel); + panelRight.revalidate(); + panelRight.repaint(); + } + } + }; + } + + private void getTreeData(TCComponent rev, CustomLovBean lov) throws TCException { + TCComponent[] comps = rev.whereUsed((short) 0); + if (comps == null || comps.length == 0) { + return; + } + for (TCComponent comp : comps) { + CustomLovBean sub = new CustomLovBean(comp.getProperty("object_string")); + System.out.println(sub.displayName); + lov.addSub(sub); + getTreeData(comp, sub); + } + } + + private void clearTable(JTable table, JCheckBox selectAll) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + int cnt = model.getRowCount(); + for (int i = 0; i < cnt; i++) { + model.removeRow(0); + } + table.revalidate(); + table.repaint(); + if (selectAll != null) { + selectAll.setSelected(false); + } + tableDataMap.clear(); + addedBOMLine.clear(); + try { + closeWin(); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private JTree createTree(CustomLovBean lovData) { + if (lovData == null || "".equals(lovData.displayName)) { + return new JTree(); + } + DefaultMutableTreeNode root = new DefaultMutableTreeNode(lovData.displayName); + DefaultMutableTreeNode parent = root; + DefaultTreeModel treeModel = new DefaultTreeModel(root); + + initTree(lovData, parent, treeModel); + + JTree tree = new JTree(treeModel); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); + cellRenderer.setTextNonSelectionColor(Color.black); + cellRenderer.setTextSelectionColor(Color.blue); + return tree; + } + + private void initTree(CustomLovBean lovData, DefaultMutableTreeNode parent, DefaultTreeModel treeModel) { + if (!lovData.hasChild()) { + return; + } + List subList = lovData.getSub(); + for (CustomLovBean sub : subList) { + DefaultMutableTreeNode temp = new DefaultMutableTreeNode(sub.displayName); + treeModel.insertNodeInto(temp, parent, parent.getChildCount()); + initTree(sub, temp, treeModel); + } + } + + private ItemListener selectAll(final JTable table) { + return new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + // TODO Auto-generated method stub + boolean select = ((JCheckBox) e.getSource()).isSelected(); + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox checkBox = (JCheckBox) table.getValueAt(i, 0); + checkBox.setSelected(select); + table.revalidate(); + table.repaint(); + } + } + }; + } + + private ActionListener cancel() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + $this.dispose(); + } + }; + } + + private ActionListener batchRevise(final JTable table, JCheckBox selectAll) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List selectedRowList = getselectedRow(table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkAccess(selectedRowList).isRes()) { + return; + } + List msgData = new ArrayList(); + for (int i = 0; i < selectedRowList.size(); i++) { + try { + TCComponentItemRevision newRev = selectedRowList.get(i).getParentRev().saveAs(null); + String parentString = newRev.getProperty("object_string"); + selectedRowList.get(i).setParentRev(newRev); + selectedRowList.get(i).setParentString(parentString); + msgData.add(new String[] { msgData.size() + 1 + "", selectedRowList.get(i).getParentString(), + newRev.getProperty("object_string"), "成功" }); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); +// JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + msgData.add(new String[] { msgData.size() + 1 + "", selectedRowList.get(i).getParentString(), + "", "升版失败:请检查是否重复升版以及更多日志:" + e1.getMessage() }); + } + } + +// showWhereUesd(table, selectAll); + updateSelectedRow(table, selectedRowList); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "序号", "版本名称(当前)", "版本名称(升版后)", "结果" }, + msgData).panel; + JOptionPane.showMessageDialog($this, jsp, "升版结果", JOptionPane.PLAIN_MESSAGE); + } + }; + } + + private List usedFilter(TCComponent[] comps) throws TCException { +// Map sameParentUsedMap = new HashMap(); + List list = new ArrayList<>(); + for (TCComponent comp : comps) { + if (comp instanceof TCComponentItemRevision) { + TCComponentItemRevision rev = (TCComponentItemRevision) comp; +// String itemId; +// if (sameParentUsedMap.containsKey(itemId = comp.getProperty("item_id"))) { +// if (sameParentUsedMap.get(itemId).getProperty("item_revision_id") +// .compareTo(comp.getProperty("item_revision_id")) < 0) { +// sameParentUsedMap.put(itemId, rev); +// } +// } else { + if (rev.getItem().getLatestItemRevision().getUid().equals(rev.getUid())) { + list.add(rev); + } +// sameParentUsedMap.put(itemId, rev); +// } + } + } + return list; + } + + private void createLogDataSourceTable() { + if (isLogcreated) { + return; + } + String sql1 = "CREATE TABLE JD2_BOMManageLog ( id NUMBER ( 38, 0 ) primary key, modify_user VARCHAR2 ( 200 ), modify_time DATE, modify_content VARCHAR2 ( 500 ))"; + String sql2 = "CREATE sequence JD2_BOMManageLog_seq minvalue 1 maxvalue 99999999 INCREMENT BY 1 START WITH 1"; + String sql3 = "CREATE OR REPLACE TRIGGER JD2_BOMManageLog_tri before INSERT ON JD2_BOMManageLog FOR each ROW BEGIN SELECT JD2_BOMManageLog_seq.nextval INTO : new.id FROM dual; END;"; + try { + List temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("user_tables", + new Condition("table_name", "JD2_BOMMANAGELOG")); + if (temp == null || temp.size() == 0) { + Db.use(DBUtil.getDataSource(session)).execute(sql1); + System.out.println("JD2_BOMMANAGELOG create success"); + } + temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("user_sequences", + new Condition("sequence_name", "JD2_BOMMANAGELOG_SEQ")); + if (temp == null || temp.size() == 0) { + Db.use(DBUtil.getDataSource(session)).execute(sql2); + System.out.println("JD2_BOMMANAGELOG_SEQ create success"); + } + temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("all_triggers", + new Condition("trigger_name", "JD2_BOMMANAGELOG_TRI")); + if (temp == null || temp.size() == 0) { + DBConnectionUtil.dbConn(session).createStatement().execute(sql3); + System.out.println("JD2_BOMManageLog_tri create success"); + } + isLogcreated = true; + System.out.println("init log success"); + } catch (Exception e) { + // TODO Auto-generated catch block + JOptionPane.showMessageDialog($this, "数据库连接失败,请检查首选项jd2_db_settings", "错误", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + } + } + + private ActionListener searchLog() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String username = p5UserText.getText().trim(); + String content = p5ContentText.getText(); + if (username == null || "".equals(username)) { + return; + } + + String sql = "select * from JD2_BOMMANAGELOG where "; + if (!"*".equals(username)) { + sql += "modify_user like '%" + username + "%' and"; + } + sql += " modify_time between to_date('" + p5TimeStartText.getText() + + " 00:00:00','yyyy-MM-dd hh24:mi:ss') and to_date('" + p5TimeEndText.getText() + + " 23:59:59','yyyy-MM-dd hh24:mi:ss')"; + if (content != null && !"".equals(content)) { + sql += " and modify_content like '%" + content + "%'"; + } + sql += "order by MODIFY_TIME asc"; + System.out.println(sql); + try { + logDataList = Db.use(DBUtil.getDataSource(session)).query(sql); + System.out.println("log size=====>" + logDataList.size()); + DefaultTableModel model = (DefaultTableModel) p5Table.getModel(); + for (Entity entity : logDataList) { + Object[] objArr = new Object[] { entity.get("ID"), entity.get("MODIFY_USER"), + entity.get("MODIFY_TIME"), entity.get("MODIFY_CONTENT") }; + model.addRow(objArr); + } + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return; + } + p5Table.revalidate(); + p5Table.repaint(); + } + }; + } + + private ItemListener downloadLog(final JTable table) { + return new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent paramItemEvent) { + // TODO Auto-generated method stub + if (paramItemEvent.getStateChange() == ItemEvent.DESELECTED) { + return; + } + String selectItem = ((JComboBox) paramItemEvent.getSource()).getSelectedItem().toString(); + System.out.println(selectItem); + if (!selectItem.contains("txt") && !selectItem.contains("excel")) { + return; + } + if (table.getRowCount() > 0) { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setMultiSelectionEnabled(false); + chooser.setCurrentDirectory(FileSystemView.getFileSystemView().getHomeDirectory()); + chooser.showOpenDialog($this); + File folder = chooser.getSelectedFile(); + if (folder == null) { + p5Download.setSelectedItem("导出日志"); + return; + } + String fileName = ""; + if (selectItem.contains("txt")) { + FileWriter fileWriter = null; + fileName = "批量更新BOM日志-" + new SimpleDateFormat("yyyyMMddHHmm").format(new Date()) + ".txt"; + try { + fileWriter = new FileWriter(folder.getPath() + File.separator + fileName);// 创建文本文件 + String temp; + System.out.println(logDataList.size()); + for (Entity entity : logDataList) { + fileWriter.write((temp = entity.get("ID").toString()) + + StringCreateUtil.createBlank(10 - temp.length()) + + (temp = entity.get("MODIFY_USER").toString()) + + StringCreateUtil.createBlank(20 - temp.length()) + + (temp = entity.get("MODIFY_TIME").toString()) + + StringCreateUtil.createBlank(30 - temp.length()) + + entity.get("MODIFY_CONTENT").toString() + "\r\n"); + } + fileWriter.flush(); + fileWriter.close(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return; + } + } else { + fileName = "批量更新BOM日志-" + new SimpleDateFormat("yyyyMMddHHmm").format(new Date()) + ".xlsx"; + String[] header = new String[] { "序号", "修改用户", "更改时间", "更改内容" }; + List data = new ArrayList<>(); + System.out.println(logDataList.size()); + for (Entity entity : logDataList) { + data.add(new String[] { entity.get("ID").toString(), entity.get("MODIFY_USER").toString(), + entity.get("MODIFY_TIME").toString(), entity.get("MODIFY_CONTENT").toString() }); + } + SimpleExcelUtil.exportExcel(folder.getPath() + File.separator + fileName, header, data); + + } + + JOptionPane.showMessageDialog($this, "日志导出成功\r\n路径:" + folder + File.separator + fileName, "提示", + JOptionPane.WARNING_MESSAGE); + p5Download.setSelectedItem("导出日志"); + } + } + }; + + } + + private ActionListener batchReplace() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p1NumText.getText().trim(); + //String text = p1UnitCombo.getSelectedText().trim(); + // Object value = p1UnitCombo.getSelectedValue(); + System.out.println(numStr); +// if ("".equals(numStr) || "".equals(text) || targetRev2 == null) { +// JOptionPane.showMessageDialog($this, "存在未填写的信息,请填写", "提示", JOptionPane.WARNING_MESSAGE); +// return; +// } + List selectedRowList = getselectedRow(p1Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + L1: for (int i = 0; i < selectedRowList.size(); i++) { + try { + doIndex++; + BOMManageTableBean bean = selectedRowList.get(i); + // System.out.println(value.toString()); + if (!addedBOMLine.add(bean.getParentRev().getUid() + targetRev2.getUid())) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), targetRev2.getProperty("object_string"), + numStr, "失败:此物料已替换过一次,请勿重替换" }); + continue L1; + } + AIFComponentContext[] aifs = bean.getParentLine().getChildren(); + for (AIFComponentContext aif : aifs) { + String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision() + .getProperty("object_string"); + if (objStr.equals(targetRev2.getProperty("object_string"))) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), targetRev2.getProperty("object_string"), + numStr, "失败:组件对象下已存在相同子件" }); + continue L1; + } + } + String seq = selectedRowList.get(i).getChildLine().getProperty("bl_sequence_no"); + bean.getParentLine().remove("", bean.getChildLine()); + TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null, + false, ""); + // childLine.setReferenceProperty("bl_uom", (TCComponent) value); + childLine.setProperties(new String[] { "bl_quantity", "bl_sequence_no" }, + new String[] { numStr, seq }); + msgData.add( + new String[] { msgData.size() + 1 + "", bean.getParentString(), bean.getChildString(), + targetRev2.getProperty("object_string"), numStr, "成功" }); + selectedRowList.get(i).setChildString(targetRev2.getProperty("object_string")); + selectedRowList.get(i).setChildRev(targetRev2); + selectedRowList.get(i).setChildLine(childLine); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("批量替换执行完毕,用时" + (endTime - startTime) + "ms"); + doLog("替换", msgData); + JScrollPane jsp = DialogUtil + .createTableMsg(new String[] { "序号", "父级组件", "原子件", "替换子件", "单位", "数量", "结果" }, msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "批量替换结果 成功(" + getResultNum(msgData, true) + ") 失败(" + + getResultNum(msgData, false) + ") 用时:" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); + updateSelectedRow2(p1Table, selectedRowList); + } + }; + } + + private ActionListener batchModify() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p2NumText.getText(); + List selectedRowList = getselectedRow(p2Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + for (BOMManageTableBean bean : selectedRowList) { + String oldNumStr = ""; + try { + doIndex++; + oldNumStr = bean.getChildLine().getProperty("bl_quantity"); + bean.getChildLine().setProperties(new String[] { "bl_quantity" }, new String[] { numStr }); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), oldNumStr, numStr, "成功" }); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("批量更改执行完毕,用时" + (endTime - startTime) + "ms"); + doLog("用量修改", msgData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "序号", "父级组件", "子件", "原数量", "现数量", "结果" }, + msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "批量更改结果 成功(" + getResultNum(msgData, true) + ") 失败(" + + getResultNum(msgData, false) + ") 用时:" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); + updateSelectedRow(p2Table, selectedRowList); + } + }; + } + + private ActionListener batchAdd() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p3NumText.getText().trim(); + String text = p3UnitCombo.getSelectedText().trim(); + Object value = p3UnitCombo.getSelectedValue(); + System.out.println(numStr); + if ("".equals(numStr) || "".equals(text) || targetRev2 == null) { + JOptionPane.showMessageDialog($this, "存在未填写的信息,请填写", "提示", JOptionPane.WARNING_MESSAGE); + return; + } + List selectedRowList = getselectedRow(p3Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + L1: for (BOMManageTableBean bean : selectedRowList) { + try { + doIndex++; + System.out.println(value.toString()); + if (!addedBOMLine.add(bean.getParentRev().getUid() + targetRev2.getUid())) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, + "失败:此物料已增加过一次,请勿重复增加" }); + continue L1; + } + AIFComponentContext[] aifs = bean.getParentLine().getChildren(); + for (AIFComponentContext aif : aifs) { + String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision() + .getProperty("object_string"); + if (objStr.equals(targetRev2.getProperty("object_string"))) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, + "失败:组件对象下已存在相同子件" }); + continue L1; + } + } + TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null, + false, ""); + childLine.setReferenceProperty("bl_uom", (TCComponent) value); + childLine.setProperties(new String[] { "bl_quantity" }, new String[] { numStr }); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, "成功" }); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("批量新增执行完毕,用时" + (endTime - startTime) + "ms"); + doLog("新增", msgData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "序号", "父级组件", "新增子件", "单位", "数量", "结果" }, + msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "批量新增结果 成功(" + getResultNum(msgData, true) + ") 失败(" + + getResultNum(msgData, false) + ") 用时:" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); +// showWhereUesd(p3Table, p3SelectAll); + } + }; + } + + private ActionListener batchRemove() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List selectedRowList = getselectedRow(p4Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + for (BOMManageTableBean bean : selectedRowList) { + try { + doIndex++; + if (bean.getChildLine() == null) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), "bomLine不存在,可能已经成功删除" }); + } else { + bean.getParentLine().remove("", bean.getChildLine()); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), "成功" }); + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("批量删除执行完毕,用时" + (endTime - startTime) + "ms"); + doLog("删除", msgData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "序号", "父级组件", "删除子件", "结果" }, msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "批量删除结果 成功(" + getResultNum(msgData, true) + ") 失败(" + + getResultNum(msgData, false) + ") 用时:" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); +// removeSelectRow(p4Table); + updateSelectedRow3(p4Table, selectedRowList); + } + }; + } + + private List getselectedRow(JTable table) { + List selectedList = new ArrayList(); + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + System.out.println("select=====>" + table.getValueAt(i, 1)); + selectedList.add(tableDataMap.get(table.getValueAt(i, 1))); + } + } + return selectedList; + } + + private void updateSelectedRow(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + try { + TCComponentItemRevision parentRev = newRowData.get(index).getParentRev(); + String parentString = newRowData.get(index).getParentString(); + TCComponentBOMWindow win = winType.create(null); + TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null); + winMap.get(table.getValueAt(i, 1).toString()).close(); + winMap.remove(table.getValueAt(i, 1)); + winMap.put(parentString, win); + tableDataMap.remove(table.getValueAt(i, 1).toString()); + TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + AIFComponentContext[] aifs = topLine.getChildren(); + for (AIFComponentContext aif : aifs) { + TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent(); + if (newRowData.get(index).getChildString() + .equals(child.getItemRevision().getProperty("object_string"))) { + + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + + JCheckBox selected = new JCheckBox(); + selected.setSelected(true); + Object[] rowData = new Object[] { selected, parentString, + newRowData.get(index).getChildString(), unit, num, status }; + rowPrint(rowData); + for (int ii = 0; ii < rowData.length; ii++) { + table.setValueAt(rowData[ii], i, ii); + } + tableDataMap.put(parentString, new BOMManageTableBean(parentString, + newRowData.get(index).getChildString(), parentRev, targetRev, topLine, child)); + break; + } + } + index++; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + table.revalidate(); + table.repaint(); + } + + private void updateSelectedRow2(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + BOMManageTableBean bean = newRowData.get(index); + try { + TCComponentBOMLine child = bean.getChildLine(); + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + table.setValueAt(bean.getChildString(), i, 2); + table.setValueAt(unit, index, 3); + table.setValueAt(num, index, 4); + tableDataMap.get(bean.getParentString()).setChildRev(bean.getChildRev()); + tableDataMap.get(bean.getParentString()).setChildString(bean.getChildString()); + tableDataMap.get(bean.getParentString()).setChildLine(child); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + index++; + } + } + table.revalidate(); + table.repaint(); + } + + private void updateSelectedRow3(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + BOMManageTableBean bean = newRowData.get(index); + table.setValueAt("", i, 2); + table.setValueAt("", index, 3); + table.setValueAt("", index, 4); + tableDataMap.get(bean.getParentString()).setChildLine(null); + index++; + } + } + table.revalidate(); + table.repaint(); + } + + private void removeSelectRow(JTable table) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + int i = 0; + while (i < table.getRowCount()) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + model.removeRow(i); + continue; + } + i++; + } + table.revalidate(); + table.repaint(); + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + new Thread(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + try { + closeWin(); + System.out.println("closed"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }).start(); + + super.dispose(); + } + + private void saveWin() throws TCException { + for (Entry entry : winMap.entrySet()) { + if (entry.getValue() != null) { + entry.getValue().save(); + } + + } + } + + private void closeWin() throws TCException { + saveWin(); + + for (Entry entry : winMap.entrySet()) { + entry.getValue().close(); + } + winMap.clear(); + } + + private void doLog(String operation, List msgData) { + createLogDataSourceTable(); + String content = ""; + if ("替换".equals(operation)) { + content = "组件%s中子件%s替换为%s;%s;%s"; + } else if ("用量修改".equals(operation)) { + content = "组件%s中子件%s数量由%s改为%s"; + } else if ("新增".equals(operation)) { + content = "组件%s新增子件%s;%s;%s"; + } else if ("删除".equals(operation)) { + content = "组件%s删除子件%s"; + } + String username = ""; + try { + username = session.getUser().getOSUserName() + "(" + session.getUser().getUserId() + ")"; + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + String datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + + List sqls = new ArrayList(); + int num = StrUtil.count(content, "%s"); + for (String[] arr : msgData) { + String temp; + String[] row = new String[num]; + for (int i = 0; i < num; i++) { + row[i] = arr[i + 1]; + } + temp = String.format(content, row); + String sql = "insert into JD2_BOMMANAGELOG (MODIFY_USER,MODIFY_TIME,MODIFY_CONTENT) VALUES ('" + username + + "',to_date('" + datetime + "','yyyy-MM-dd hh24:mi:ss'),'" + temp + "')"; + sqls.add(sql); + } + + try { + Db.use(DBUtil.getDataSource(session)).executeBatch(sqls.toArray(new String[sqls.size()])); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private ActionListener clickSearch(final JTable table, final JCheckBox selectAll) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + JDialog content = DialogUtil.createSearchAndSelectRevDialog($this, table, selectAll, + (JButton) e.getSource()); + } + }; + } + + public void okCallback(JTable revTable, JTable table, JCheckBox selectAll, JButton field) { + // TODO Auto-generated method stub + int rowIndex = revTable.getSelectedRow(); + if (rowIndex < 0) { + return; + } + String text = revTable.getValueAt(rowIndex, 0).toString(); + System.out.println(text); + field.setText(text); + if ("".equals(text)) { + return; + } + if (table != null) { + targetRev = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5); + showWhereUesd(table, selectAll); + } else { + targetRev2 = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5); + } + } + + private KeyAdapter logSearchEnter() { + return new KeyAdapter() { + @Override + public void keyTyped(KeyEvent e) { + // TODO Auto-generated method stub + super.keyTyped(e); + if (e.getKeyChar() == KeyEvent.VK_ENTER) { + p5Search.doClick(); + } + } + }; + } + + private void updateTitleShowProgress(final List list) { + new Thread(new Runnable() { + + @Override + public void run() { + int num = 1; + String temp; + doIndex = 0; + while (!complate) { + $this.setTitle("正在处理" + (temp = StringCreateUtil.createPoint(num % 3)) + + StringCreateUtil.createBlank(5 - temp.length()) + list.get(doIndex).getParentString() + + " " + (doIndex + 1) + "/" + list.size()); + try { + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + num++; + } + $this.setTitle("BOM管理"); + doIndex = -1; + complate = false; + } + }).start(); + } + + private boolean checkReleaseStatus(TCComponentItemRevision rev) { + try { + System.out.println("item type======>" + rev.getItem().getType()); + if (checkItemType.contains(rev.getItem().getType())) { + return true; + } + TCComponent form = rev.getRelatedComponents("IMAN_master_form_rev")[0]; + TCComponent[] statusArray = form.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + if ("".equals(status) || "JD2_DJJY".equals(status) || "JD2_DJKY".equals(status) || "TCM Released".equals(status)) { + return false; + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return true; + } + + private ResultData checkAccess(List data) { + for (BOMManageTableBean bean : data) { + boolean isAccess = true; + try { + isAccess = session.getTCAccessControlService().checkPrivilege(bean.getParentLine(), "WRITE"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (!isAccess) { + try { + return new ResultData(false, "当前用户没有对" + bean.getParentLine().getProperty("object_string") + "的写权限", + bean.getParentLine()); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return new ResultData(true, "", null); + } + + private boolean checkTargetAndSelect(TCComponentItemRevision rev, List data) { + if (!checkReleaseStatus(rev)) { + JOptionPane.showMessageDialog($this, "目标物料未发布或者处于冻结状态,无法保存BOM", "提示", JOptionPane.WARNING_MESSAGE); + return false; + } + ResultData res = checkAccess(data); + if (!res.isRes()) { + JOptionPane.showMessageDialog($this, res.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return false; + } + return true; + } + + private ActionListener startWorkFlow(final JTable table) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List select = getselectedRow(table); + List parentRev = new ArrayList<>(); + for (BOMManageTableBean bean : select) { + parentRev.add(bean.getParentRev()); + } + $this.setExtendedState(JFrame.ICONIFIED); + NewProcessCommand command = new NewProcessCommand(AIFUtility.getActiveDesktop(), app, + parentRev.toArray(new TCComponentItemRevision[parentRev.size()])); + } + }; + } + + private void rowPrint(Object[] arr) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + for (Object obj : arr) { + if (obj instanceof JCheckBox) { + sb.append(((JCheckBox) obj).isSelected()); + } else { + sb.append(obj.toString()); + } + sb.append(","); + } + if (sb.length() > 1) { + sb.deleteCharAt(sb.length() - 1); + } + sb.append("]"); + System.out.println(sb.toString()); + } + + private void resize() { + double left = 2 * this.widthOffset / 3.0; + double right = this.widthOffset - left; + + int bottom1 = p1BottomBtn2.getX() - p1BottomBtn1.getX() - p1BottomBtn1.getWidth(); + int bottom2 = p1BottomBtn3.getX() - p1BottomBtn2.getX() - p1BottomBtn2.getWidth(); + int botttom3 = p1BottomBtn4.getX() - p1BottomBtn3.getX() - p1BottomBtn3.getWidth(); + + // p1 + int p1x1 = p1TargetBtn.getX() - p1TargetLabel.getX() - p1TargetLabel.getWidth(); + int p1x2 = p1ReplaceBtn.getX() - p1ReplaceLabel.getX() - p1ReplaceLabel.getWidth(); + int p1x3 = p1UnitLabel.getX() - p1ReplaceBtn.getX() - p1ReplaceBtn.getWidth(); + int p1x4 = p1NumLabel.getX() - p1UnitCombo.getX() - p1UnitCombo.getWidth(); + p1TargetLabel.setBounds(p1TargetLabel.getX() + getOffset(left, 20, 800), 20, + p1TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p1TargetBtn.setBounds(p1TargetLabel.getX() + p1TargetLabel.getWidth() + p1x1 + getOffset(left, 10, 800), 20, + p1TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p1ReplaceLabel.setBounds(p1ReplaceLabel.getX() + getOffset(left, 20, 800), 60, + p1ReplaceLabel.getWidth() + getOffset(left, 100, 800), 25); + p1ReplaceBtn.setBounds(p1ReplaceLabel.getX() + p1ReplaceLabel.getWidth() + p1x2 + getOffset(left, 10, 800), 60, + p1ReplaceBtn.getWidth() + getOffset(left, 400, 800), 25); + p1UnitLabel.setBounds(p1ReplaceBtn.getX() + p1ReplaceBtn.getWidth() + p1x3 + getOffset(left, 30, 800), 60, + p1UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p1UnitCombo.setBounds(p1UnitLabel.getX() + p1UnitLabel.getWidth(), 60, + p1UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p1NumLabel.setBounds(p1ReplaceBtn.getX() + p1ReplaceBtn.getWidth() + p1x3 + getOffset(left, 30, 800), 60, + p1UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p1NumText.setBounds(p1UnitLabel.getX() + p1UnitLabel.getWidth(), 60, + p1UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p1SelectAll.setBounds(p1SelectAll.getX() + getOffset(left, 20, 800), 100, + p1SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p1jsp.setBounds(p1jsp.getX() + getOffset(left, 20, 800), p1jsp.getY(), + p1jsp.getWidth() + getOffset(left, 760, 800), p1jsp.getHeight() + this.heightOffset); + p1BottomBtn1.setBounds(p1BottomBtn1.getX() + getOffset(left, 80, 800), p1BottomBtn1.getY() + this.heightOffset, + p1BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn2.setBounds(p1BottomBtn1.getX() + p1BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p1BottomBtn2.getY() + this.heightOffset, p1BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); +// p1BottomBtn3.setBounds(p1BottomBtn2.getX() + p1BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), +// p1BottomBtn3.getY() + this.heightOffset, p1BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn4.setBounds(p1BottomBtn2.getX() + p1BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p1BottomBtn3.getY() + this.heightOffset, p1BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p1Left.setBounds(0, 0, p1Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p1Left.getHeight() + this.heightOffset); + p1TreePanel.setBounds(p1TreePanel.getX() + getOffset(right, 20, 400), 130, + p1TreePanel.getWidth() + getOffset(right, 360, 400), p1TreePanel.getHeight() + this.heightOffset); + p1Right.setBounds(p1Left.getX() + p1Left.getWidth(), 0, + p1Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p1Right.getHeight() + this.heightOffset); + p1.revalidate(); + p1.repaint(); + + // p2 + int p2x1 = p2TargetBtn.getX() - p2TargetLabel.getX() - p2TargetLabel.getWidth(); + int p2x2 = p2NumText.getX() - p2ChangeNumLabel.getX() - p2ChangeNumLabel.getWidth(); + p2TargetLabel.setBounds(p2TargetLabel.getX() + getOffset(left, 20, 800), 20, + p2TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p2TargetBtn.setBounds(p2TargetLabel.getX() + p2TargetLabel.getWidth() + p2x1 + getOffset(left, 10, 800), 20, + p2TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p2ChangeNumLabel.setBounds(p2ChangeNumLabel.getX() + getOffset(left, 20, 800), 60, + p2ChangeNumLabel.getWidth() + getOffset(left, 100, 800), 25); + p2NumText.setBounds(p2ChangeNumLabel.getX() + p2ChangeNumLabel.getWidth() + p2x2 + getOffset(left, 10, 800), 60, + p2NumText.getWidth() + getOffset(left, 50, 800), 25); + p2SelectAll.setBounds(p2SelectAll.getX() + getOffset(left, 20, 800), 100, + p2SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p2jsp.setBounds(p2jsp.getX() + getOffset(left, 20, 800), p2jsp.getY(), + p2jsp.getWidth() + getOffset(left, 760, 800), p2jsp.getHeight() + this.heightOffset); + p2BottomBtn1.setBounds(p2BottomBtn1.getX() + getOffset(left, 80, 800), p2BottomBtn1.getY() + this.heightOffset, + p2BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn2.setBounds(p2BottomBtn1.getX() + p2BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p2BottomBtn2.getY() + this.heightOffset, p2BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn3.setBounds(p2BottomBtn2.getX() + p2BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p2BottomBtn3.getY() + this.heightOffset, p2BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn4.setBounds(p2BottomBtn3.getX() + p2BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p2BottomBtn4.getY() + this.heightOffset, p2BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p2Left.setBounds(0, 0, p2Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p2Left.getHeight() + this.heightOffset); + p2TreePanel.setBounds(p2TreePanel.getX() + getOffset(right, 20, 400), 130, + p2TreePanel.getWidth() + getOffset(right, 360, 400), p2TreePanel.getHeight() + this.heightOffset); + p2Right.setBounds(p2Left.getX() + p2Left.getWidth(), 0, + p2Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p2Right.getHeight() + this.heightOffset); + p2.revalidate(); + p2.repaint(); + + // p3 + int p3x1 = p3TargetBtn.getX() - p3TargetLabel.getX() - p3TargetLabel.getWidth(); + int p3x2 = p3AddBtn.getX() - p3AddLabel.getX() - p3AddLabel.getWidth(); + int p3x3 = p3UnitLabel.getX() - p3AddBtn.getX() - p3AddBtn.getWidth(); + int p3x4 = p3NumLabel.getX() - p3UnitCombo.getX() - p3UnitCombo.getWidth(); + p3TargetLabel.setBounds(p3TargetLabel.getX() + getOffset(left, 20, 800), 20, + p3TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p3TargetBtn.setBounds(p3TargetLabel.getX() + p3TargetLabel.getWidth() + p3x1 + getOffset(left, 10, 800), 20, + p3TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p3AddLabel.setBounds(p3AddLabel.getX() + getOffset(left, 20, 800), 60, + p3AddLabel.getWidth() + getOffset(left, 100, 800), 25); + p3AddBtn.setBounds(p3AddLabel.getX() + p3AddLabel.getWidth() + p3x2 + getOffset(left, 10, 800), 60, + p3AddBtn.getWidth() + getOffset(left, 400, 800), 25); + p3UnitLabel.setBounds(p3AddBtn.getX() + p3AddBtn.getWidth() + p3x3 + getOffset(left, 30, 800), 60, + p3UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p3UnitCombo.setBounds(p3UnitLabel.getX() + p3UnitLabel.getWidth(), 60, + p3UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p3NumLabel.setBounds(p3UnitCombo.getX() + p3UnitCombo.getWidth() + p3x4 + getOffset(left, 20, 800), 60, + p3NumLabel.getWidth() + getOffset(left, 50, 800), 25); + p3NumText.setBounds(p3NumLabel.getX() + p3NumLabel.getWidth(), 60, + p3NumText.getWidth() + getOffset(left, 50, 800), 25); + p3SelectAll.setBounds(p3SelectAll.getX() + getOffset(left, 20, 800), 100, + p3SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p3jsp.setBounds(p3jsp.getX() + getOffset(left, 20, 800), p3jsp.getY(), + p3jsp.getWidth() + getOffset(left, 760, 800), p3jsp.getHeight() + this.heightOffset); + p3BottomBtn1.setBounds(p3BottomBtn1.getX() + getOffset(left, 80, 800), p3BottomBtn1.getY() + this.heightOffset, + p3BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn2.setBounds(p3BottomBtn1.getX() + p3BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p3BottomBtn2.getY() + this.heightOffset, p3BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn3.setBounds(p3BottomBtn2.getX() + p3BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p3BottomBtn3.getY() + this.heightOffset, p3BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn4.setBounds(p3BottomBtn3.getX() + p3BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p3BottomBtn4.getY() + this.heightOffset, p3BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p3Left.setBounds(0, 0, p3Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p3Left.getHeight() + this.heightOffset); + p3TreePanel.setBounds(p3TreePanel.getX() + getOffset(right, 20, 400), 130, + p3TreePanel.getWidth() + getOffset(right, 360, 400), p3TreePanel.getHeight() + this.heightOffset); + p3Right.setBounds(p3Left.getX() + p3Left.getWidth(), 0, + p3Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p3Right.getHeight() + this.heightOffset); + p3.revalidate(); + p3.repaint(); + + // p4 + int p4x1 = p4TargetBtn.getX() - p4TargetLabel.getX() - p4TargetLabel.getWidth(); + p4TargetLabel.setBounds(p4TargetLabel.getX() + getOffset(left, 20, 800), 20, + p4TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p4TargetBtn.setBounds(p4TargetLabel.getX() + p4TargetLabel.getWidth() + p4x1 + getOffset(left, 10, 800), 20, + p4TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p4SelectAll.setBounds(p4SelectAll.getX() + getOffset(left, 20, 800), 100, + p4SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p4jsp.setBounds(p4jsp.getX() + getOffset(left, 20, 800), p4jsp.getY(), + p4jsp.getWidth() + getOffset(left, 760, 800), p4jsp.getHeight() + this.heightOffset); + p4BottomBtn1.setBounds(p4BottomBtn1.getX() + getOffset(left, 80, 800), p4BottomBtn1.getY() + this.heightOffset, + p4BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn2.setBounds(p4BottomBtn1.getX() + p4BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p4BottomBtn2.getY() + this.heightOffset, p4BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn3.setBounds(p4BottomBtn2.getX() + p4BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p4BottomBtn3.getY() + this.heightOffset, p4BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn4.setBounds(p4BottomBtn3.getX() + p4BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p4BottomBtn4.getY() + this.heightOffset, p4BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p4Left.setBounds(0, 0, p4Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p4Left.getHeight() + this.heightOffset); + p4TreePanel.setBounds(p4TreePanel.getX() + getOffset(right, 20, 400), 130, + p4TreePanel.getWidth() + getOffset(right, 360, 400), p4TreePanel.getHeight() + this.heightOffset); + p4Right.setBounds(p4Left.getX() + p4Left.getWidth(), 0, + p4Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p4Right.getHeight() + this.heightOffset); + p4.revalidate(); + p4.repaint(); + + // p5 + int p5x1 = p5UserText.getX() - p5UserLabel.getX() - p5UserLabel.getWidth(); + int p5x2 = p5TimeLabel.getX() - p5UserText.getX() - p5UserText.getWidth(); + int p5x3 = p5TimeStartText.getX() - p5TimeLabel.getX() - p5TimeLabel.getWidth(); + int p5x4 = toLabel.getX() - p5TimeStartText.getX() - p5TimeStartText.getWidth(); + int p5x5 = p5TimeEndText.getX() - toLabel.getX() - toLabel.getWidth(); + int p5x6 = p5ContentLabel.getX() - p5TimeEndText.getX() - p5TimeEndText.getWidth(); + int p5x7 = p5Contentjsp.getX() - p5ContentLabel.getX() - p5ContentLabel.getWidth(); + int p5x8 = p5Search.getX() - p5Contentjsp.getX() - p5Contentjsp.getWidth(); + int p5x9 = p5Download.getX() - p5Search.getX() - p5Search.getWidth(); + p5UserLabel.setBounds(p5UserLabel.getX(), 40, p5UserLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), + 25); + p5UserText.setBounds(p5UserLabel.getX() + p5UserLabel.getWidth() + p5x1 + getOffset(this.widthOffset, 10, 1200), + 40, p5UserText.getWidth() + getOffset(this.widthOffset, 150, 1200), 25); + p5TimeLabel.setBounds(p5UserText.getX() + p5UserText.getWidth() + p5x2 + getOffset(this.widthOffset, 50, 1200), + 40, p5TimeLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25); + p5TimeStartText.setBounds( + p5TimeLabel.getX() + p5TimeLabel.getWidth() + p5x3 + getOffset(this.widthOffset, 10, 1200), 40, + p5TimeStartText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + toLabel.setBounds( + p5TimeStartText.getX() + p5TimeStartText.getWidth() + p5x4 + getOffset(this.widthOffset, 10, 1200), 40, + toLabel.getWidth() + getOffset(this.widthOffset, 20, 1200), 25); + p5TimeEndText.setBounds(toLabel.getX() + toLabel.getWidth() + p5x5 + getOffset(this.widthOffset, 10, 1200), 40, + p5TimeEndText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + p5ContentLabel.setBounds( + p5TimeEndText.getX() + p5TimeEndText.getWidth() + p5x6 + getOffset(this.widthOffset, 50, 1200), 40, + p5ContentLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25); + p5Contentjsp.setBounds( + p5ContentLabel.getX() + p5ContentLabel.getWidth() + p5x7 + getOffset(this.widthOffset, 10, 1200), 20, + p5Contentjsp.getWidth() + getOffset(this.widthOffset, 200, 1200), 80); + p5Search.setBounds(p5Contentjsp.getX() + p5Contentjsp.getWidth() + p5x8 + getOffset(this.widthOffset, 50, 1200), + 40, p5Search.getWidth() + getOffset(this.widthOffset, 60, 1200), 25); + p5Download.setBounds(p5Search.getX() + p5Search.getWidth() + p5x9 + getOffset(this.widthOffset, 20, 1200), 40, + p5Download.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + p5jsp.setBounds(p5jsp.getX() + getOffset(this.widthOffset, 20, 1200), p5jsp.getY(), + p5jsp.getWidth() + getOffset(this.widthOffset, 1160, 1200), p5jsp.getHeight() + this.heightOffset); + p5.revalidate(); + p5.repaint(); + } + + private int getOffset(double num1, int num2, int num3) { + return (int) (num1 * num2 / num3); + } + + private int getResultNum(List msgData, boolean success) { + int num = 0; + String str = success ? "成功" : "失败"; + for (String[] row : msgData) { + if (row[row.length - 1].contains(str)) { + num++; + } + } + return num; + } +} diff --git a/src/com/connor/jd/plm/dialogs/BOMManagementFrame20200826鏀筶og鏍煎紡.txt b/src/com/connor/jd/plm/dialogs/BOMManagementFrame20200826鏀筶og鏍煎紡.txt new file mode 100644 index 0000000..93f6146 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/BOMManagementFrame20200826鏀筶og鏍煎紡.txt @@ -0,0 +1,2145 @@ +package com.connor.jd.plm.dialogs; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.Vector; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.RowSorter; +import javax.swing.filechooser.FileSystemView; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableRowSorter; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; + +import com.connor.jd.plm.beans.BOMLogBean; +import com.connor.jd.plm.beans.BOMManageTableBean; +import com.connor.jd.plm.beans.CheckBoxPo; +import com.connor.jd.plm.beans.CustomLovBean; +import com.connor.jd.plm.beans.ResultData; +import com.connor.jd.plm.table.MyCellEditor4; +import com.connor.jd.plm.table.MyCellRenderer; +import com.connor.jd.plm.utils.DBConnectionUtil; +import com.connor.jd.plm.utils.DBUtil; +import com.connor.jd.plm.utils.DatePickerUtil; +import com.connor.jd.plm.utils.DialogUtil; +import com.connor.jd.plm.utils.JDMethodUtil; +import com.connor.jd.plm.utils.KeyValComboBox; +import com.connor.jd.plm.utils.StringCreateUtil; +import com.eltima.components.ui.DatePicker; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +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.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.workflow.commands.newprocess.NewProcessCommand; + +import cn.hutool.db.Db; +import cn.hutool.db.Entity; +import cn.hutool.db.sql.Condition; + +public class BOMManagementFrame extends JFrame { + private AbstractAIFApplication app; + private TCSession session; + private CardLayout rootSwitch = new CardLayout(); + private String[] colDisplayNames = new String[] { "选择", "组件对象", "子件对象", "单位", "数量", "状态" }; + private String[] colDisplayNames2 = new String[] { "序号", "修改用户", "更改时间", "更改内容" }; + private JPanel root; + private Map tableDataMap = new HashMap(); + private BOMManagementFrame $this; + private List logDataList; + private Map winMap = new HashMap(); + private TCComponentItemRevision targetRev; + private TCComponentItemRevision targetRev2; + private boolean isLogcreated = false; + private int doIndex = 0; + private boolean complate = false; + private List checkItemType = new ArrayList(); + private JButton[] topBtns; + private TCComponentBOMWindowType winType; + private int width = 1200; + private int height = 800; + private int widthOffset = 0; + private int heightOffset = 0; + private JLabel p1TargetLabel; + private JButton p1TargetBtn; + private JLabel p1ReplaceLabel; + private JButton p1ReplaceBtn; + private JLabel p1UnitLabel; + private KeyValComboBox p1UnitCombo; + private JLabel p1NumLabel; + private JTextField p1NumText; + private JCheckBox p1SelectAll; + private JTable p1Table; + private JScrollPane p1jsp; + private JButton p1BottomBtn1; + private JButton p1BottomBtn2; + private JButton p1BottomBtn3; + private JButton p1BottomBtn4; + private JPanel p1Left; + private JScrollPane p1TreePanel; + private JPanel p1Right; + private JLabel p2TargetLabel; + private JButton p2TargetBtn; + private JLabel p2ChangeNumLabel; + private JTextField p2NumText; + private JCheckBox p2SelectAll; + private JTable p2Table; + private JScrollPane p2jsp; + private JButton p2BottomBtn1; + private JButton p2BottomBtn2; + private JButton p2BottomBtn3; + private JButton p2BottomBtn4; + private JPanel p2Left; + private JScrollPane p2TreePanel; + private JPanel p2Right; + private JLabel p3TargetLabel; + private JButton p3TargetBtn; + private JLabel p3AddLabel; + private JButton p3AddBtn; + private JLabel p3UnitLabel; + private KeyValComboBox p3UnitCombo; + private JLabel p3NumLabel; + private JTextField p3NumText; + private JCheckBox p3SelectAll; + private JTable p3Table; + private JScrollPane p3jsp; + private JButton p3BottomBtn1; + private JButton p3BottomBtn2; + private JButton p3BottomBtn3; + private JButton p3BottomBtn4; + private JPanel p3Left; + private JScrollPane p3TreePanel; + private JPanel p3Right; + private JLabel p4TargetLabel; + private JButton p4TargetBtn; + private JCheckBox p4SelectAll; + private JTable p4Table; + private JScrollPane p4jsp; + private JButton p4BottomBtn1; + private JButton p4BottomBtn2; + private JButton p4BottomBtn3; + private JButton p4BottomBtn4; + private JPanel p4Left; + private JScrollPane p4TreePanel; + private JPanel p4Right; + private JLabel p5UserLabel; + private JTextField p5UserText; + private JLabel p5TimeLabel; + private DatePicker p5TimeStartText; + private JLabel toLabel; + private DatePicker p5TimeEndText; + private JLabel p5ContentLabel; + private JTextArea p5ContentText; + private JScrollPane p5Contentjsp; + private JButton p5Search; + private JButton p5Download; + private JTable p5Table; + private JScrollPane p5jsp; + private Map uiSize = new HashMap<>(); + private JPanel p1; + private JPanel p2; + private JPanel p3; + private JPanel p4; + private JPanel p5; + private Set addedBOMLine = new HashSet<>(); + + public BOMManagementFrame(AbstractAIFApplication app) { + super(); + this.app = app; + this.session = (TCSession) app.getSession(); + $this = this; + String[] prefArray = JDMethodUtil.getPrefStrArray("connor_bom_check_type", session); + if (prefArray != null) { + checkItemType = Arrays.asList(prefArray); + } + TCTypeService service = session.getTypeService(); + try { + this.winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + init(); + } + + private void init() { + this.setTitle("BOM管理"); + this.setSize(new Dimension(1200, 800)); + this.setLayout(new BorderLayout()); + this.setResizable(true); + this.setAlwaysOnTop(true); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setLocationRelativeTo(null); + this.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + // TODO Auto-generated method stub + super.componentResized(e); + Component comp = e.getComponent(); + $this.widthOffset = comp.getWidth() - $this.width; + $this.heightOffset = comp.getHeight() - $this.height; + if ($this.widthOffset != 0 || $this.heightOffset != 0) { + System.out.println("width===>" + comp.getWidth()); + System.out.println("height===>" + comp.getHeight()); + $this.width = comp.getWidth(); + $this.height = comp.getHeight(); + $this.resize(); + } + } + }); + this.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void focusGained(FocusEvent e) { + // TODO Auto-generated method stub + $this.setAlwaysOnTop(true); + } + }); + + Container container = this.getContentPane(); + container.setLayout(new BorderLayout()); + container.setSize(new Dimension(1200, 800)); + + TCTypeService typeService = session.getTypeService(); + Vector unitVector = new Vector(); + try { + TCComponent[] uomArray = typeService.getTypeComponent("UnitOfMeasure").extent(); + unitVector.add(new CheckBoxPo(" ", " ")); + for (TCComponent comp : uomArray) { + unitVector.add(new CheckBoxPo(comp.toString(), comp)); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // 头部 + JPanel topBtnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + topBtns = new JButton[5]; + topBtns[0] = new JButton("批量替换"); + topBtns[1] = new JButton("批量更改"); + topBtns[2] = new JButton("批量新增"); + topBtns[3] = new JButton("批量删除"); + topBtns[4] = new JButton("更新日志"); +// topBtns[5] = new JButton("测试按钮"); + topBtns[0].setSelected(true); + for (JButton btn : topBtns) { + topBtnPanel.add(btn); + btn.addActionListener(panelSwitch()); + } + container.add(topBtnPanel, BorderLayout.NORTH); + + // root + root = new JPanel(rootSwitch); + + // 批量替换 + p1 = new JPanel(); + p1.setLayout(null); + + // 批量替换左边 + p1Left = new JPanel(); + p1Left.setLayout(null); + p1Left.setBounds(0, 0, 800, 800); + p1Left.setBorder(BorderFactory.createEtchedBorder()); + + p1TargetLabel = new JLabel("目标物料编码"); + p1TargetLabel.setBounds(20, 20, 100, 25); + p1TargetBtn = new JButton(); + p1TargetBtn.setBounds(130, 20, 400, 25); + p1ReplaceLabel = new JLabel("替换物料编码"); + p1ReplaceLabel.setBounds(20, 60, 100, 25); + p1ReplaceBtn = new JButton(); + p1ReplaceBtn.setBounds(130, 60, 400, 25); + p1UnitLabel = new JLabel("单位"); + p1UnitLabel.setBounds(560, 60, 50, 25); + p1UnitCombo = new KeyValComboBox(unitVector); + p1UnitCombo.setBounds(610, 60, 50, 25); + p1NumLabel = new JLabel("数量"); + p1NumLabel.setBounds(680, 60, 50, 25); + p1NumText = new JTextField(); + p1NumText.setBounds(730, 60, 50, 25); + p1SelectAll = new JCheckBox("全选"); + p1SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p1model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p1Table = new JTable(p1model); + p1Table.getColumnModel().getColumn(0).setMinWidth(60); + p1Table.getColumnModel().getColumn(0).setMaxWidth(60); + p1Table.getColumnModel().getColumn(1).setMinWidth(200); + p1Table.getColumnModel().getColumn(2).setMinWidth(200); + p1Table.getColumnModel().getColumn(3).setMinWidth(100); + p1Table.getColumnModel().getColumn(4).setMinWidth(100); + p1Table.getColumnModel().getColumn(5).setMinWidth(100); + p1Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p1Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p1Table.setRowHeight(25); + p1Table.setAutoscrolls(true); + p1Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p1Table.getTableHeader().setReorderingAllowed(false); + p1Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p1sorter = new TableRowSorter(p1model); + p1Table.setRowSorter(p1sorter); + p1jsp = new JScrollPane(p1Table); + p1jsp.setBounds(20, 130, 760, 500); + + p1BottomBtn1 = new JButton("批量升版"); + p1BottomBtn1.setBounds(80, 650, 100, 25); + p1BottomBtn2 = new JButton("批量替换"); + p1BottomBtn2.setBounds(260, 650, 100, 25); + p1BottomBtn3 = new JButton("发起流程"); + p1BottomBtn3.setBounds(440, 650, 100, 25); + p1BottomBtn4 = new JButton("取消"); + p1BottomBtn4.setBounds(620, 650, 100, 25); + + p1Left.add(p1TargetLabel); + p1Left.add(p1TargetBtn); + p1Left.add(p1ReplaceLabel); + p1Left.add(p1ReplaceBtn); + p1Left.add(p1UnitLabel); + p1Left.add(p1UnitCombo); + p1Left.add(p1NumLabel); + p1Left.add(p1NumText); + p1Left.add(p1SelectAll); + p1Left.add(p1jsp); + p1Left.add(p1BottomBtn1); + p1Left.add(p1BottomBtn2); + p1Left.add(p1BottomBtn3); + p1Left.add(p1BottomBtn4); + + // 批量替换右边 + p1Right = new JPanel(); + p1Right.setLayout(null); + p1Right.setBounds(800, 0, 400, 800); + p1Right.setBorder(BorderFactory.createEtchedBorder()); + + p1TreePanel = new JScrollPane(); + p1TreePanel.setBounds(20, 130, 360, 500); + p1Right.add(p1TreePanel); + + // 绑定事件 + p1SelectAll.addItemListener(selectAll(p1Table)); + p1Table.addMouseListener(showTree(p1Right)); + p1BottomBtn4.addActionListener(cancel()); + p1BottomBtn1.addActionListener(batchRevise(p1Table, p1SelectAll)); + p1BottomBtn2.addActionListener(batchReplace()); + p1BottomBtn3.addActionListener(startWorkFlow(p1Table)); + p1TargetBtn.addActionListener(clickSearch(p1Table, p1SelectAll)); + p1ReplaceBtn.addActionListener(clickSearch(null, null)); + + p1.add(p1Left); + p1.add(p1Right); + + // 批量更改 + p2 = new JPanel(); + p2.setLayout(null); + + // 批量更改左边 + p2Left = new JPanel(); + p2Left.setLayout(null); + p2Left.setBounds(0, 0, 800, 800); + p2Left.setBorder(BorderFactory.createEtchedBorder()); + + p2TargetLabel = new JLabel("目标物料编码"); + p2TargetLabel.setBounds(20, 20, 100, 25); + p2TargetBtn = new JButton(); + p2TargetBtn.setBounds(130, 20, 400, 25); + p2ChangeNumLabel = new JLabel("更改用量"); + p2ChangeNumLabel.setBounds(20, 60, 100, 25); + p2NumText = new JTextField(); + p2NumText.setBounds(130, 60, 50, 25); + + p2SelectAll = new JCheckBox("全选"); + p2SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p2model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p2Table = new JTable(p2model); + p2Table.getColumnModel().getColumn(0).setMinWidth(60); + p2Table.getColumnModel().getColumn(0).setMaxWidth(60); + p2Table.getColumnModel().getColumn(1).setMinWidth(200); + p2Table.getColumnModel().getColumn(2).setMinWidth(200); + p2Table.getColumnModel().getColumn(3).setMinWidth(100); + p2Table.getColumnModel().getColumn(4).setMinWidth(100); + p2Table.getColumnModel().getColumn(5).setMinWidth(100); + p2Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p2Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p2Table.setRowHeight(25); + p2Table.setAutoscrolls(true); + p2Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p2Table.getTableHeader().setReorderingAllowed(false); + p2Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p2sorter = new TableRowSorter(p2model); + p2Table.setRowSorter(p2sorter); + p2jsp = new JScrollPane(p2Table); + p2jsp.setBounds(20, 130, 760, 500); + + p2BottomBtn1 = new JButton("批量升版"); + p2BottomBtn1.setBounds(80, 650, 100, 25); + p2BottomBtn2 = new JButton("批量更改"); + p2BottomBtn2.setBounds(260, 650, 100, 25); + p2BottomBtn3 = new JButton("发起流程"); + p2BottomBtn3.setBounds(440, 650, 100, 25); + p2BottomBtn4 = new JButton("取消"); + p2BottomBtn4.setBounds(620, 650, 100, 25); + + p2Left.add(p2TargetLabel); + p2Left.add(p2TargetBtn); + p2Left.add(p2ChangeNumLabel); + p2Left.add(p2NumText); + p2Left.add(p2SelectAll); + p2Left.add(p2jsp); + p2Left.add(p2BottomBtn1); + p2Left.add(p2BottomBtn2); + p2Left.add(p2BottomBtn3); + p2Left.add(p2BottomBtn4); + + // 批量更改右边 + p2Right = new JPanel(); + p2Right.setLayout(null); + p2Right.setBounds(800, 0, 400, 800); + p2Right.setBorder(BorderFactory.createEtchedBorder()); + + p2TreePanel = new JScrollPane(); + p2TreePanel.setBounds(20, 130, 360, 500); + p2Right.add(p2TreePanel); + + // 绑定事件 + p2SelectAll.addItemListener(selectAll(p2Table)); + p2Table.addMouseListener(showTree(p2Right)); + p2BottomBtn4.addActionListener(cancel()); + p2BottomBtn1.addActionListener(batchRevise(p2Table, p2SelectAll)); + p2BottomBtn2.addActionListener(batchModify()); + p2BottomBtn3.addActionListener(startWorkFlow(p2Table)); + p2TargetBtn.addActionListener(clickSearch(p2Table, p2SelectAll)); + + p2.add(p2Left); + p2.add(p2Right); + + // 批量新增 + p3 = new JPanel(); + p3.setLayout(null); + + // 批量新增左边 + p3Left = new JPanel(); + p3Left.setLayout(null); + p3Left.setBounds(0, 0, 800, 800); + p3Left.setBorder(BorderFactory.createEtchedBorder()); + + p3TargetLabel = new JLabel("参考物料编码"); + p3TargetLabel.setBounds(20, 20, 100, 25); + p3TargetBtn = new JButton(); + p3TargetBtn.setBounds(130, 20, 400, 25); + p3AddLabel = new JLabel("新增物料编码"); + p3AddLabel.setBounds(20, 60, 100, 25); + p3AddBtn = new JButton(); + p3AddBtn.setBounds(130, 60, 400, 25); + p3UnitLabel = new JLabel("单位"); + p3UnitLabel.setBounds(560, 60, 50, 25); + p3UnitCombo = new KeyValComboBox(unitVector); + p3UnitCombo.setBounds(610, 60, 50, 25); + p3NumLabel = new JLabel("数量"); + p3NumLabel.setBounds(680, 60, 50, 25); + p3NumText = new JTextField(); + p3NumText.setBounds(730, 60, 50, 25); + + p3SelectAll = new JCheckBox("全选"); + p3SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p3model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p3Table = new JTable(p3model); + p3Table.getColumnModel().getColumn(0).setMinWidth(60); + p3Table.getColumnModel().getColumn(0).setMaxWidth(60); + p3Table.getColumnModel().getColumn(1).setMinWidth(200); + p3Table.getColumnModel().getColumn(2).setMinWidth(200); + p3Table.getColumnModel().getColumn(3).setMinWidth(100); + p3Table.getColumnModel().getColumn(4).setMinWidth(100); + p3Table.getColumnModel().getColumn(5).setMinWidth(100); + p3Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p3Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p3Table.setRowHeight(25); + p3Table.setAutoscrolls(true); + p3Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p3Table.getTableHeader().setReorderingAllowed(false); + p3Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p3sorter = new TableRowSorter(p3model); + p3Table.setRowSorter(p3sorter); + p3jsp = new JScrollPane(p3Table); + p3jsp.setBounds(20, 130, 760, 500); + + p3BottomBtn1 = new JButton("批量升版"); + p3BottomBtn1.setBounds(80, 650, 100, 25); + p3BottomBtn2 = new JButton("批量新增"); + p3BottomBtn2.setBounds(260, 650, 100, 25); + p3BottomBtn3 = new JButton("发起流程"); + p3BottomBtn3.setBounds(440, 650, 100, 25); + p3BottomBtn4 = new JButton("取消"); + p3BottomBtn4.setBounds(620, 650, 100, 25); + + p3Left.add(p3TargetLabel); + p3Left.add(p3TargetBtn); + p3Left.add(p3AddLabel); + p3Left.add(p3AddBtn); + p3Left.add(p3UnitLabel); + p3Left.add(p3UnitCombo); + p3Left.add(p3NumLabel); + p3Left.add(p3NumText); + p3Left.add(p3SelectAll); + p3Left.add(p3jsp); + p3Left.add(p3BottomBtn1); + p3Left.add(p3BottomBtn2); + p3Left.add(p3BottomBtn3); + p3Left.add(p3BottomBtn4); + + // 批量新增右边 + p3Right = new JPanel(); + p3Right.setLayout(null); + p3Right.setBounds(800, 0, 400, 800); + p3Right.setBorder(BorderFactory.createEtchedBorder()); + + p3TreePanel = new JScrollPane(); + p3TreePanel.setBounds(20, 130, 360, 500); + p3Right.add(p3TreePanel); + + // 绑定事件 + p3SelectAll.addItemListener(selectAll(p3Table)); + p3Table.addMouseListener(showTree(p3Right)); + p3BottomBtn4.addActionListener(cancel()); + p3BottomBtn1.addActionListener(batchRevise(p3Table, p3SelectAll)); + p3BottomBtn2.addActionListener(batchAdd()); + p3BottomBtn3.addActionListener(startWorkFlow(p3Table)); + p3TargetBtn.addActionListener(clickSearch(p3Table, p3SelectAll)); + p3AddBtn.addActionListener(clickSearch(null, null)); + + p3.add(p3Left); + p3.add(p3Right); + + // 批量删除 + p4 = new JPanel(); + p4.setLayout(null); + + // 批量删除左边 + p4Left = new JPanel(); + p4Left.setLayout(null); + p4Left.setBounds(0, 0, 800, 800); + p4Left.setBorder(BorderFactory.createEtchedBorder()); + + p4TargetLabel = new JLabel("目标物料编码"); + p4TargetLabel.setBounds(20, 20, 100, 25); + p4TargetBtn = new JButton(); + p4TargetBtn.setBounds(130, 20, 400, 25); + + p4SelectAll = new JCheckBox("全选"); + p4SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p4model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p4Table = new JTable(p4model); + p4Table.getColumnModel().getColumn(0).setMinWidth(60); + p4Table.getColumnModel().getColumn(0).setMaxWidth(60); + p4Table.getColumnModel().getColumn(1).setMinWidth(200); + p4Table.getColumnModel().getColumn(2).setMinWidth(200); + p4Table.getColumnModel().getColumn(3).setMinWidth(100); + p4Table.getColumnModel().getColumn(4).setMinWidth(100); + p4Table.getColumnModel().getColumn(5).setMinWidth(100); + p4Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p4Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p4Table.setRowHeight(25); + p4Table.setAutoscrolls(true); + p4Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p4Table.getTableHeader().setReorderingAllowed(false); + p4Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p4sorter = new TableRowSorter(p4model); + p4Table.setRowSorter(p4sorter); + p4jsp = new JScrollPane(p4Table); + p4jsp.setBounds(20, 130, 760, 500); + + p4BottomBtn1 = new JButton("批量升版"); + p4BottomBtn1.setBounds(80, 650, 100, 25); + p4BottomBtn2 = new JButton("批量删除"); + p4BottomBtn2.setBounds(260, 650, 100, 25); + p4BottomBtn3 = new JButton("发起流程"); + p4BottomBtn3.setBounds(440, 650, 100, 25); + p4BottomBtn4 = new JButton("取消"); + p4BottomBtn4.setBounds(620, 650, 100, 25); + + p4Left.add(p4TargetLabel); + p4Left.add(p4TargetBtn); + p4Left.add(p4SelectAll); + p4Left.add(p4jsp); + p4Left.add(p4BottomBtn1); + p4Left.add(p4BottomBtn2); + p4Left.add(p4BottomBtn3); + p4Left.add(p4BottomBtn4); + + // 批量新增右边 + p4Right = new JPanel(); + p4Right.setLayout(null); + p4Right.setBounds(800, 0, 400, 800); + p4Right.setBorder(BorderFactory.createEtchedBorder()); + + p4TreePanel = new JScrollPane(); + p4TreePanel.setBounds(20, 130, 360, 500); + p4Right.add(p4TreePanel); + + // 绑定事件 + p4SelectAll.addItemListener(selectAll(p4Table)); + p4Table.addMouseListener(showTree(p4Right)); + p4BottomBtn4.addActionListener(cancel()); + p4BottomBtn1.addActionListener(batchRevise(p4Table, p4SelectAll)); + p4BottomBtn2.addActionListener(batchRemove()); + p4BottomBtn3.addActionListener(startWorkFlow(p4Table)); + p4TargetBtn.addActionListener(clickSearch(p4Table, p4SelectAll)); + + p4.add(p4Left); + p4.add(p4Right); + + // 更新日志 + p5 = new JPanel(); + p5.setLayout(null); + + p5UserLabel = new JLabel("修改用户"); + p5UserLabel.setBounds(20, 40, 70, 25); + p5UserText = new JTextField(); + p5UserText.setBounds(100, 40, 150, 25); + p5TimeLabel = new JLabel("修改时间"); + p5TimeLabel.setBounds(300, 40, 70, 25); + p5TimeStartText = DatePickerUtil.getDatePicker(null); + p5TimeStartText.setBounds(380, 40, 100, 25); + toLabel = new JLabel("到"); + toLabel.setBounds(490, 40, 20, 25); + p5TimeEndText = DatePickerUtil.getDatePicker(null); + p5TimeEndText.setBounds(520, 40, 100, 25); + p5ContentLabel = new JLabel("修改内容"); + p5ContentLabel.setBounds(670, 40, 70, 25); + p5ContentText = new JTextArea(); + p5ContentText.setLineWrap(true); + p5ContentText.setWrapStyleWord(true); + p5Contentjsp = new JScrollPane(p5ContentText); + p5Contentjsp.setBounds(750, 20, 200, 80); + p5Search = new JButton("搜索"); + p5Search.setBounds(1000, 40, 60, 25); + p5Download = new JButton("日志下载"); + p5Download.setBounds(1080, 40, 100, 25); + + DefaultTableModel p5model = new DefaultTableModel(colDisplayNames2, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p5Table = new JTable(p5model); + p5Table.getColumnModel().getColumn(0).setMinWidth(60); + p5Table.getColumnModel().getColumn(0).setMaxWidth(60); + p5Table.getColumnModel().getColumn(1).setMinWidth(200); + p5Table.getColumnModel().getColumn(2).setMinWidth(200); + p5Table.getColumnModel().getColumn(3).setMinWidth(700); + p5Table.setRowHeight(25); + p5Table.setAutoscrolls(true); + p5Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p5Table.getTableHeader().setReorderingAllowed(false); + RowSorter p5sorter = new TableRowSorter(p5model); + p5Table.setRowSorter(p5sorter); + p5jsp = new JScrollPane(p5Table); + p5jsp.setBounds(20, 130, 1160, 580); + + // 绑定事件 + p5Search.addActionListener(searchLog()); + p5Download.addActionListener(downloadLog(p5Table)); + p5UserText.addKeyListener(logSearchEnter()); + p5TimeStartText.addKeyListener(logSearchEnter()); + p5TimeEndText.addKeyListener(logSearchEnter()); + + p5.add(p5UserLabel); + p5.add(p5UserText); + p5.add(p5TimeLabel); + p5.add(p5TimeStartText); + p5.add(toLabel); + p5.add(p5TimeEndText); + p5.add(p5ContentLabel); + p5.add(p5Contentjsp); + p5.add(p5Search); + p5.add(p5Download); + p5.add(p5jsp); + + root.add("batchReplace", p1); + root.add("batchModify", p2); + root.add("batchAdd", p3); + root.add("batchRemove", p4); + root.add("updateLog", p5); + + rootSwitch.show(root, "batchReplace"); + container.add(root, BorderLayout.CENTER); + this.setVisible(true); + } + + private ActionListener panelSwitch() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String text = ((JButton) e.getSource()).getText(); + for (int i = 0; i < topBtns.length; i++) { + topBtns[i].setSelected(topBtns[i].getText().equals(text)); + } + switch (text) { + case "批量替换": + clearTable(p1Table, p1SelectAll); + p1Right.removeAll(); + JScrollPane panel1 = new JScrollPane(); + panel1.setBounds(p1TreePanel.getX(), p1TreePanel.getY(), p1TreePanel.getWidth(), + p1TreePanel.getHeight()); + p1TreePanel = panel1; + p1Right.add(panel1); + p1Right.revalidate(); + p1Right.repaint(); + rootSwitch.show(root, "batchReplace"); + break; + case "批量更改": + clearTable(p2Table, p2SelectAll); + p2Right.removeAll(); + JScrollPane panel2 = new JScrollPane(); + panel2.setBounds(p2TreePanel.getX(), p2TreePanel.getY(), p2TreePanel.getWidth(), + p2TreePanel.getHeight()); + p2TreePanel = panel2; + p2Right.add(panel2); + p2Right.revalidate(); + p2Right.repaint(); + rootSwitch.show(root, "batchModify"); + break; + case "批量新增": + clearTable(p3Table, p3SelectAll); + p3Right.removeAll(); + JScrollPane panel3 = new JScrollPane(); + panel3.setBounds(p3TreePanel.getX(), p3TreePanel.getY(), p3TreePanel.getWidth(), + p3TreePanel.getHeight()); + p3TreePanel = panel3; + p3Right.add(panel3); + p3Right.revalidate(); + p3Right.repaint(); + rootSwitch.show(root, "batchAdd"); + break; + case "批量删除": + clearTable(p4Table, p4SelectAll); + p4Right.removeAll(); + JScrollPane panel4 = new JScrollPane(); + panel4.setBounds(p4TreePanel.getX(), p4TreePanel.getY(), p4TreePanel.getWidth(), + p4TreePanel.getHeight()); + p4TreePanel = panel4; + p4Right.add(panel4); + p4Right.revalidate(); + p4Right.repaint(); + rootSwitch.show(root, "batchRemove"); + break; + case "更新日志": + createLogDataSourceTable(); + clearTable(p5Table, null); + rootSwitch.show(root, "updateLog"); + break; + default: +// createLogDataSourceTable(); + } + } + }; + } + + private void showWhereUesd(JTable table, JCheckBox selectAll) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + // TODO Auto-generated method stub + clearTable(table, selectAll); + if (table == null || targetRev == null) { + return; + } + long startTime = System.currentTimeMillis(); + List tableDataList = new ArrayList(); + try { + String revString = targetRev.getProperty("object_string"); + TCComponent[] usedComps = targetRev.whereUsed((short) 0); + System.out.println("装配个数======>" + usedComps.length); + + tableDataMap.clear(); +// Map usedMap = usedFilter(usedComps); +// for (Entry entry : usedMap.entrySet()) { + for (TCComponentItemRevision parentRev : usedFilter(usedComps)) { +// TCComponentItemRevision parentRev = entry.getValue(); + String parentString = parentRev.getProperty("object_string"); + TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + TCComponentBOMWindow win = winType.create(null); + TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null); + winMap.put(parentString, win); + AIFComponentContext[] aifs = topLine.getChildren(); + for (AIFComponentContext aif : aifs) { + TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent(); + if (revString.equals(child.getItemRevision().getProperty("object_string"))) { + + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + + Object[] rowData = new Object[] { new JCheckBox(), parentString, revString, unit, num, status }; + rowPrint(rowData); + tableDataList.add(rowData); + tableDataMap.put(parentString, + new BOMManageTableBean(parentString, revString, parentRev, targetRev, topLine, child)); + // TODO 如果bom下有一样的child,可能会异常,操作只会影响第一个 + break; + } + } + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + if (tableDataList == null || tableDataList.size() == 0) { + JOptionPane.showMessageDialog($this, "找到编码对应对象,但该对象没有用于任何装配或者装配该对象的均不是最新版本,请确认编码是否正确", "提示", + JOptionPane.WARNING_MESSAGE); + return; + } + + for (Object[] rowData : tableDataList) { + model.addRow(rowData); + } + table.revalidate(); + table.repaint(); + System.out.println("装配显示完成,用时" + (System.currentTimeMillis() - startTime) + "ms"); + } + + private MouseAdapter showTree(JPanel panelRight) { + return new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + JTable table = (JTable) e.getSource(); + String parentString = table.getValueAt(table.getSelectedRow(), 1).toString(); + System.out.println("select row=====>" + table.getSelectedRow()); + System.out.println("parentName=====>" + parentString); + CustomLovBean lovBean = null; + try { + lovBean = new CustomLovBean(tableDataMap.get(parentString).getChildString()); + CustomLovBean subBean = new CustomLovBean(parentString); + lovBean.addSub(subBean); + getTreeData(tableDataMap.get(parentString).getParentRev(), subBean); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + panelRight.removeAll(); + JTree tree = createTree(lovBean); + JScrollPane treePanel = new JScrollPane(tree); + treePanel.setBounds(20, 130, 360, 500); + panelRight.add(treePanel); + panelRight.revalidate(); + panelRight.repaint(); + } + } + }; + } + + private void getTreeData(TCComponent rev, CustomLovBean lov) throws TCException { + TCComponent[] comps = rev.whereUsed((short) 0); + if (comps == null || comps.length == 0) { + return; + } + for (TCComponent comp : comps) { + CustomLovBean sub = new CustomLovBean(comp.getProperty("object_string")); + System.out.println(sub.displayName); + lov.addSub(sub); + getTreeData(comp, sub); + } + } + + private void clearTable(JTable table, JCheckBox selectAll) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + int cnt = model.getRowCount(); + for (int i = 0; i < cnt; i++) { + model.removeRow(0); + } + table.revalidate(); + table.repaint(); + if (selectAll != null) { + selectAll.setSelected(false); + } + tableDataMap.clear(); + addedBOMLine.clear(); + try { + closeWin(); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private JTree createTree(CustomLovBean lovData) { + if (lovData == null || "".equals(lovData.displayName)) { + return new JTree(); + } + DefaultMutableTreeNode root = new DefaultMutableTreeNode(lovData.displayName); + DefaultMutableTreeNode parent = root; + DefaultTreeModel treeModel = new DefaultTreeModel(root); + + initTree(lovData, parent, treeModel); + + JTree tree = new JTree(treeModel); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); + cellRenderer.setTextNonSelectionColor(Color.black); + cellRenderer.setTextSelectionColor(Color.blue); + return tree; + } + + private void initTree(CustomLovBean lovData, DefaultMutableTreeNode parent, DefaultTreeModel treeModel) { + if (!lovData.hasChild()) { + return; + } + List subList = lovData.getSub(); + for (CustomLovBean sub : subList) { + DefaultMutableTreeNode temp = new DefaultMutableTreeNode(sub.displayName); + treeModel.insertNodeInto(temp, parent, parent.getChildCount()); + initTree(sub, temp, treeModel); + } + } + + private ItemListener selectAll(JTable table) { + return new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + // TODO Auto-generated method stub + boolean select = ((JCheckBox) e.getSource()).isSelected(); + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox checkBox = (JCheckBox) table.getValueAt(i, 0); + checkBox.setSelected(select); + table.revalidate(); + table.repaint(); + } + } + }; + } + + private ActionListener cancel() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + $this.dispose(); + } + }; + } + + private ActionListener batchRevise(JTable table, JCheckBox selectAll) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List selectedRowList = getselectedRow(table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkAccess(selectedRowList).isRes()) { + return; + } + List msgData = new ArrayList(); + for (int i = 0; i < selectedRowList.size(); i++) { + try { + TCComponentItemRevision newRev = selectedRowList.get(i).getParentRev().saveAs(null); + String parentString = newRev.getProperty("object_string"); + selectedRowList.get(i).setParentRev(newRev); + selectedRowList.get(i).setParentString(parentString); + msgData.add(new String[] { msgData.size() + 1 + "", selectedRowList.get(i).getParentString(), + newRev.getProperty("object_string"), "成功" }); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return; + } + } + +// showWhereUesd(table, selectAll); + updateSelectedRow(table, selectedRowList); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "序号", "版本名称(当前)", "版本名称(升版后)", "结果" }, + msgData).panel; + JOptionPane.showMessageDialog($this, jsp, "升版结果", JOptionPane.PLAIN_MESSAGE); + } + }; + } + + private List usedFilter(TCComponent[] comps) throws TCException { +// Map sameParentUsedMap = new HashMap(); + List list = new ArrayList<>(); + for (TCComponent comp : comps) { + if (comp instanceof TCComponentItemRevision) { + TCComponentItemRevision rev = (TCComponentItemRevision) comp; +// String itemId; +// if (sameParentUsedMap.containsKey(itemId = comp.getProperty("item_id"))) { +// if (sameParentUsedMap.get(itemId).getProperty("item_revision_id") +// .compareTo(comp.getProperty("item_revision_id")) < 0) { +// sameParentUsedMap.put(itemId, rev); +// } +// } else { + if (rev.getItem().getLatestItemRevision().getUid().equals(rev.getUid())) { + list.add(rev); + } +// sameParentUsedMap.put(itemId, rev); +// } + } + } + return list; + } + + private void createLogDataSourceTable() { + if (isLogcreated) { + return; + } + String sql1 = "CREATE TABLE JD2_BOMManageLog ( id NUMBER ( 38, 0 ) primary key, modify_user VARCHAR2 ( 200 ), modify_time DATE, modify_content VARCHAR2 ( 500 ), target1 VARCHAR2 ( 100 ), target2 VARCHAR2 ( 100 ), parent VARCHAR2 ( 100 ), operation VARCHAR2 ( 50 ), unit VARCHAR2 ( 100 ), num VARCHAR2 ( 100 ))"; + String sql2 = "CREATE sequence JD2_BOMManageLog_seq minvalue 1 maxvalue 99999999 INCREMENT BY 1 START WITH 1"; + String sql3 = "CREATE OR REPLACE TRIGGER JD2_BOMManageLog_tri before INSERT ON JD2_BOMManageLog FOR each ROW BEGIN SELECT JD2_BOMManageLog_seq.nextval INTO : new.id FROM dual; END;"; + try { + List temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("user_tables", + new Condition("table_name", "JD2_BOMMANAGELOG")); + if (temp == null || temp.size() == 0) { + Db.use(DBUtil.getDataSource(session)).execute(sql1); + System.out.println("JD2_BOMMANAGELOG create success"); + } + temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("user_sequences", + new Condition("sequence_name", "JD2_BOMMANAGELOG_SEQ")); + if (temp == null || temp.size() == 0) { + Db.use(DBUtil.getDataSource(session)).execute(sql2); + System.out.println("JD2_BOMMANAGELOG_SEQ create success"); + } + temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("all_triggers", + new Condition("trigger_name", "JD2_BOMMANAGELOG_TRI")); + if (temp == null || temp.size() == 0) { + DBConnectionUtil.dbConn(session).createStatement().execute(sql3); + System.out.println("JD2_BOMManageLog_tri create success"); + } + isLogcreated = true; + System.out.println("init log success"); + } catch (Exception e) { + // TODO Auto-generated catch block + JOptionPane.showMessageDialog($this, "数据库连接失败,请检查首选项jd2_db_settings", "错误", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + } + } + + private ActionListener searchLog() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String username = p5UserText.getText().trim(); + String content = p5ContentText.getText(); + if (username == null || "".equals(username)) { + return; + } + + String sql = "select * from JD2_BOMMANAGELOG where "; + if (!"*".equals(username)) { + sql += "modify_user like '%" + username + "%' and"; + } + sql += " modify_time between to_date('" + p5TimeStartText.getText() + + " 00:00:00','yyyy-MM-dd hh24:mi:ss') and to_date('" + p5TimeEndText.getText() + + " 23:59:59','yyyy-MM-dd hh24:mi:ss')"; + if (content != null && !"".equals(content)) { + sql += " and modify_content like '%" + content + "%'"; + } + sql += "order by MODIFY_TIME asc"; + System.out.println(sql); + try { + logDataList = Db.use(DBUtil.getDataSource(session)).query(sql); + System.out.println("log size=====>" + logDataList.size()); + DefaultTableModel model = (DefaultTableModel) p5Table.getModel(); + for (Entity entity : logDataList) { + Object[] objArr = new Object[] { entity.get("ID"), entity.get("MODIFY_USER"), + entity.get("MODIFY_TIME"), entity.get("MODIFY_CONTENT") }; + model.addRow(objArr); + } + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return; + } + p5Table.revalidate(); + p5Table.repaint(); + } + }; + } + + private ActionListener downloadLog(JTable table) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + if (table.getRowCount() > 0) { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setMultiSelectionEnabled(false); + chooser.setCurrentDirectory(FileSystemView.getFileSystemView().getHomeDirectory()); + chooser.showOpenDialog($this); + File folder = chooser.getSelectedFile(); + FileWriter fileWriter = null; + String fileName = "批量更新BOM日志-" + new SimpleDateFormat("yyyyMMddHHmm").format(new Date()) + ".txt"; + try { + fileWriter = new FileWriter(folder.getPath() + File.separator + fileName);// 创建文本文件 + String temp; + System.out.println(logDataList.size()); + for (Entity entity : logDataList) { + fileWriter.write((temp = entity.get("ID").toString()) + + StringCreateUtil.createBlank(10 - temp.length()) + + (temp = entity.get("MODIFY_USER").toString()) + + StringCreateUtil.createBlank(20 - temp.length()) + + (temp = entity.get("MODIFY_TIME").toString()) + + StringCreateUtil.createBlank(30 - temp.length()) + + entity.get("MODIFY_CONTENT").toString() + "\r\n"); + } + fileWriter.flush(); + fileWriter.close(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return; + } + + JOptionPane.showMessageDialog($this, "日志导出成功\r\n路径:" + folder + File.separator + fileName, "提示", + JOptionPane.WARNING_MESSAGE); + } + } + }; + + } + + private ActionListener batchReplace() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p1NumText.getText().trim(); + String text = p1UnitCombo.getSelectedText().trim(); + Object value = p1UnitCombo.getSelectedValue(); + System.out.println(numStr); + if ("".equals(numStr) || "".equals(text) || targetRev2 == null) { + JOptionPane.showMessageDialog($this, "存在未填写的信息,请填写", "提示", JOptionPane.WARNING_MESSAGE); + return; + } + List selectedRowList = getselectedRow(p1Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + List logData = new ArrayList(); + L1: for (int i = 0; i < selectedRowList.size(); i++) { + try { + doIndex++; + BOMManageTableBean bean = selectedRowList.get(i); + System.out.println(value.toString()); + if (!addedBOMLine.add(targetRev2)) { + continue L1; + } + AIFComponentContext[] aifs = bean.getParentLine().getChildren(); + for (AIFComponentContext aif : aifs) { + String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision() + .getProperty("object_string"); + if (objStr.equals(targetRev2.getProperty("object_string"))) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), targetRev2.getProperty("object_string"), + value.toString(), numStr, "失败:组件对象下已存在相同子件" }); + continue L1; + } + } + String seq = selectedRowList.get(i).getChildLine().getProperty("bl_sequence_no"); + bean.getParentLine().remove("", bean.getChildLine()); + TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null, + false, ""); + childLine.setReferenceProperty("bl_uom", (TCComponent) value); + childLine.setProperties(new String[] { "bl_quantity", "bl_sequence_no" }, + new String[] { numStr, seq }); + msgData.add( + new String[] { msgData.size() + 1 + "", bean.getParentString(), bean.getChildString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, "成功" }); + BOMLogBean logBean = new BOMLogBean(bean.getChildString(), + targetRev2.getProperty("object_string"), bean.getParentString(), "替换", value.toString(), + "", numStr); + logData.add(logBean); + selectedRowList.get(i).setChildString(targetRev2.getProperty("object_string")); + selectedRowList.get(i).setChildRev(targetRev2); + selectedRowList.get(i).setChildLine(childLine); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("批量替换执行完毕,用时" + (endTime - startTime) + "ms"); + doLog("替换", logData); + JScrollPane jsp = DialogUtil + .createTableMsg(new String[] { "序号", "父级组件", "原子件", "替换子件", "单位", "数量", "结果" }, msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "批量替换结果 成功(" + getResultNum(msgData, true) + ") 失败(" + + getResultNum(msgData, false) + ") 用时:" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); + updateSelectedRow2(p1Table, selectedRowList); + } + }; + } + + private ActionListener batchModify() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p2NumText.getText(); + List selectedRowList = getselectedRow(p2Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + List logData = new ArrayList<>(); + for (BOMManageTableBean bean : selectedRowList) { + String oldNumStr = ""; + try { + doIndex++; + oldNumStr = bean.getChildLine().getProperty("bl_quantity"); + bean.getChildLine().setProperties(new String[] { "bl_quantity" }, new String[] { numStr }); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), oldNumStr, numStr, "成功" }); + BOMLogBean logBean = new BOMLogBean(bean.getChildString(), + targetRev2.getProperty("object_string"), bean.getParentString(), "用量修改", "", oldNumStr, + numStr); + logData.add(logBean); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("批量更改执行完毕,用时" + (endTime - startTime) + "ms"); + doLog("用量修改", logData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "序号", "父级组件", "子件", "原数量", "现数量", "结果" }, + msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "批量更改结果 成功(" + getResultNum(msgData, true) + ") 失败(" + + getResultNum(msgData, false) + ") 用时:" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); + updateSelectedRow(p2Table, selectedRowList); + } + }; + } + + private ActionListener batchAdd() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p3NumText.getText().trim(); + String text = p3UnitCombo.getSelectedText().trim(); + Object value = p3UnitCombo.getSelectedValue(); + System.out.println(numStr); + if ("".equals(numStr) || "".equals(text) || targetRev2 == null) { + JOptionPane.showMessageDialog($this, "存在未填写的信息,请填写", "提示", JOptionPane.WARNING_MESSAGE); + return; + } + List selectedRowList = getselectedRow(p3Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + List logData = new ArrayList<>(); + L1: for (BOMManageTableBean bean : selectedRowList) { + try { + doIndex++; + System.out.println(value.toString()); + if (!addedBOMLine.add(targetRev2)) { + continue L1; + } + AIFComponentContext[] aifs = bean.getParentLine().getChildren(); + for (AIFComponentContext aif : aifs) { + String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision() + .getProperty("object_string"); + if (objStr.equals(targetRev2.getProperty("object_string"))) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, + "失败:组件对象下已存在相同子件" }); + continue L1; + } + } + TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null, + false, ""); + childLine.setReferenceProperty("bl_uom", (TCComponent) value); + childLine.setProperties(new String[] { "bl_quantity" }, new String[] { numStr }); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, "成功" }); + BOMLogBean logBean = new BOMLogBean(bean.getChildString(), + targetRev2.getProperty("object_string"), bean.getParentString(), "新增", value.toString(), + "", numStr); + logData.add(logBean); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("批量新增执行完毕,用时" + (endTime - startTime) + "ms"); + doLog("新增", logData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "序号", "父级组件", "新增子件", "单位", "数量", "结果" }, + msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "批量新增结果 成功(" + getResultNum(msgData, true) + ") 失败(" + + getResultNum(msgData, false) + ") 用时:" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); +// showWhereUesd(p3Table, p3SelectAll); + } + }; + } + + private ActionListener batchRemove() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List selectedRowList = getselectedRow(p4Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + List logData = new ArrayList<>(); + for (BOMManageTableBean bean : selectedRowList) { + try { + doIndex++; + if (bean.getChildLine() == null) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), "bomLine不存在,可能已经成功删除" }); + } else { + bean.getParentLine().remove("", bean.getChildLine()); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), "成功" }); + BOMLogBean logBean = new BOMLogBean(bean.getChildString(), + targetRev2.getProperty("object_string"), bean.getParentString(), "删除", "", "", ""); + logData.add(logBean); + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("批量删除执行完毕,用时" + (endTime - startTime) + "ms"); + doLog("删除", logData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "序号", "父级组件", "删除子件", "结果" }, msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "批量删除结果 成功(" + getResultNum(msgData, true) + ") 失败(" + + getResultNum(msgData, false) + ") 用时:" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); +// removeSelectRow(p4Table); + updateSelectedRow3(p4Table, selectedRowList); + } + }; + } + + private List getselectedRow(JTable table) { + List selectedList = new ArrayList(); + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + System.out.println("select=====>" + table.getValueAt(i, 1)); + selectedList.add(tableDataMap.get(table.getValueAt(i, 1))); + } + } + return selectedList; + } + + private void updateSelectedRow(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + try { + TCComponentItemRevision parentRev = newRowData.get(index).getParentRev(); + String parentString = newRowData.get(index).getParentString(); + TCComponentBOMWindow win = winType.create(null); + TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null); + winMap.get(table.getValueAt(i, 1).toString()).close(); + winMap.remove(table.getValueAt(i, 1)); + winMap.put(parentString, win); + tableDataMap.remove(table.getValueAt(i, 1).toString()); + TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + AIFComponentContext[] aifs = topLine.getChildren(); + for (AIFComponentContext aif : aifs) { + TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent(); + if (newRowData.get(index).getChildString() + .equals(child.getItemRevision().getProperty("object_string"))) { + + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + + JCheckBox selected = new JCheckBox(); + selected.setSelected(true); + Object[] rowData = new Object[] { selected, parentString, + newRowData.get(index).getChildString(), unit, num, status }; + rowPrint(rowData); + for (int ii = 0; ii < rowData.length; ii++) { + table.setValueAt(rowData[ii], i, ii); + } + tableDataMap.put(parentString, new BOMManageTableBean(parentString, + newRowData.get(index).getChildString(), parentRev, targetRev, topLine, child)); + break; + } + } + index++; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + table.revalidate(); + table.repaint(); + } + + private void updateSelectedRow2(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + BOMManageTableBean bean = newRowData.get(index); + try { + TCComponentBOMLine child = bean.getChildLine(); + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + table.setValueAt(bean.getChildString(), i, 2); + table.setValueAt(unit, index, 3); + table.setValueAt(num, index, 4); + tableDataMap.get(bean.getParentString()).setChildRev(bean.getChildRev()); + tableDataMap.get(bean.getParentString()).setChildString(bean.getChildString()); + tableDataMap.get(bean.getParentString()).setChildLine(child); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + index++; + } + } + table.revalidate(); + table.repaint(); + } + + private void updateSelectedRow3(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + BOMManageTableBean bean = newRowData.get(index); + table.setValueAt("", i, 2); + table.setValueAt("", index, 3); + table.setValueAt("", index, 4); + tableDataMap.get(bean.getParentString()).setChildLine(null); + index++; + } + } + table.revalidate(); + table.repaint(); + } + + private void removeSelectRow(JTable table) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + int i = 0; + while (i < table.getRowCount()) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + model.removeRow(i); + continue; + } + i++; + } + table.revalidate(); + table.repaint(); + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + new Thread(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + try { + closeWin(); + System.out.println("closed"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }).start(); + + super.dispose(); + } + + private void saveWin() throws TCException { + for (Entry entry : winMap.entrySet()) { + if (entry.getValue() != null) { + entry.getValue().save(); + } + + } + } + + private void closeWin() throws TCException { + saveWin(); + + for (Entry entry : winMap.entrySet()) { + entry.getValue().close(); + } + winMap.clear(); + } + + private void doLog(String operation, List logData) { + createLogDataSourceTable(); + String username = ""; + try { + username = session.getUser().getUserName() + "(" + session.getUser().getUserId() + ")"; + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + String datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + + List sqls = new ArrayList(); + for (BOMLogBean bean : logData) { + StringBuilder builder = new StringBuilder(); + builder.append( + "insert into JD2_BOMMANAGELOG (MODIFY_USER,MODIFY_TIME,MODIFY_CONTENT,TARGET1,TARGET2,PARENT,OPERATION,UNIT,NUM) VALUES ('"); + builder.append(username); + builder.append("',to_date('"); + builder.append(datetime); + builder.append("','yyyy-MM-dd hh24:mi:ss'),'"); + if ("替换".equals(operation)) { + String temp = String.format("组件%s中子件%s替换为%s;%s;%s", bean.getParent(), bean.getTarget1(), + bean.getTarget2(), bean.getUnit(), bean.getNum()); + builder.append(temp + "','"); + } else if ("用量修改".equals(operation)) { + String temp = String.format("组件%s中子件%s数量由%s改为%s", bean.getParent(), bean.getTarget1(), bean.getOldNum(), + bean.getNum()); + builder.append(temp + "','"); + } else if ("新增".equals(operation)) { + String temp = String.format("组件%s新增子件%s;%s;%s", bean.getParent(), bean.getTarget2(), bean.getUnit(), + bean.getNum()); + builder.append(temp + "','"); + } else if ("删除".equals(operation)) { + String temp = String.format("组件%s删除子件%s", bean.getParent(), bean.getTarget1()); + builder.append(temp + "','"); + } + builder.append(bean.getTarget1() + "','"); + builder.append(bean.getTarget2() + "','"); + builder.append(bean.getParent() + "','"); + builder.append(bean.getUnit() + "','"); + builder.append(operation + "','"); + builder.append(bean.getNum() + "');"); + sqls.add(builder.toString()); + } + + try { + Db.use(DBUtil.getDataSource(session)).executeBatch(sqls.toArray(new String[sqls.size()])); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private ActionListener clickSearch(JTable table, JCheckBox selectAll) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + JDialog content = DialogUtil.createSearchAndSelectRevDialog($this, table, selectAll, + (JButton) e.getSource()); + } + }; + } + + public void okCallback(JTable revTable, JTable table, JCheckBox selectAll, JButton field) { + // TODO Auto-generated method stub + int rowIndex = revTable.getSelectedRow(); + if (rowIndex < 0) { + return; + } + String text = revTable.getValueAt(rowIndex, 0).toString(); + System.out.println(text); + field.setText(text); + if ("".equals(text)) { + return; + } + if (table != null) { + targetRev = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5); + showWhereUesd(table, selectAll); + } else { + targetRev2 = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5); + } + } + + private KeyAdapter logSearchEnter() { + return new KeyAdapter() { + @Override + public void keyTyped(KeyEvent e) { + // TODO Auto-generated method stub + super.keyTyped(e); + if (e.getKeyChar() == KeyEvent.VK_ENTER) { + p5Search.doClick(); + } + } + }; + } + + private void updateTitleShowProgress(List list) { + new Thread(new Runnable() { + + @Override + public void run() { + int num = 1; + String temp; + doIndex = 0; + while (!complate) { + $this.setTitle("正在处理" + (temp = StringCreateUtil.createPoint(num % 3)) + + StringCreateUtil.createBlank(5 - temp.length()) + list.get(doIndex).getParentString() + + " " + (doIndex + 1) + "/" + list.size()); + try { + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + num++; + } + $this.setTitle("BOM管理"); + doIndex = -1; + complate = false; + } + }).start(); + } + + private boolean checkReleaseStatus(TCComponentItemRevision rev) { + try { + System.out.println("item type======>" + rev.getItem().getType()); + if (checkItemType.contains(rev.getItem().getType())) { + return true; + } + TCComponent form = rev.getRelatedComponents("IMAN_master_form_rev")[0]; + TCComponent[] statusArray = form.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + if ("".equals(status) || "JD2_DJJY".equals(status) || "JD2_DJKY".equals(status)) { + return false; + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return true; + } + + private ResultData checkAccess(List data) { + for (BOMManageTableBean bean : data) { + boolean isAccess = true; + try { + isAccess = session.getTCAccessControlService().checkPrivilege(bean.getParentLine(), "WRITE"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (!isAccess) { + try { + return new ResultData(false, "当前用户没有对" + bean.getParentLine().getProperty("object_string") + "的写权限", + bean.getParentLine()); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return new ResultData(true, "", null); + } + + private boolean checkTargetAndSelect(TCComponentItemRevision rev, List data) { + if (!checkReleaseStatus(rev)) { + JOptionPane.showMessageDialog($this, "目标物料未发布或者处于冻结状态,无法保存BOM", "提示", JOptionPane.WARNING_MESSAGE); + return false; + } + ResultData res = checkAccess(data); + if (!res.isRes()) { + JOptionPane.showMessageDialog($this, res.getMessage(), "提示", JOptionPane.WARNING_MESSAGE); + return false; + } + return true; + } + + private ActionListener startWorkFlow(JTable table) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List select = getselectedRow(table); + List parentRev = new ArrayList<>(); + for (BOMManageTableBean bean : select) { + parentRev.add(bean.getParentRev()); + } + $this.setExtendedState(JFrame.ICONIFIED); + NewProcessCommand command = new NewProcessCommand(AIFUtility.getActiveDesktop(), app, + parentRev.toArray(new TCComponentItemRevision[parentRev.size()])); + } + }; + } + + private void rowPrint(Object[] arr) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + for (Object obj : arr) { + if (obj instanceof JCheckBox) { + sb.append(((JCheckBox) obj).isSelected()); + } else { + sb.append(obj.toString()); + } + sb.append(","); + } + if (sb.length() > 1) { + sb.deleteCharAt(sb.length() - 1); + } + sb.append("]"); + System.out.println(sb.toString()); + } + + private void resize() { + double left = 2 * this.widthOffset / 3.0; + double right = this.widthOffset - left; + + int bottom1 = p1BottomBtn2.getX() - p1BottomBtn1.getX() - p1BottomBtn1.getWidth(); + int bottom2 = p1BottomBtn3.getX() - p1BottomBtn2.getX() - p1BottomBtn2.getWidth(); + int botttom3 = p1BottomBtn4.getX() - p1BottomBtn3.getX() - p1BottomBtn3.getWidth(); + + // p1 + int p1x1 = p1TargetBtn.getX() - p1TargetLabel.getX() - p1TargetLabel.getWidth(); + int p1x2 = p1ReplaceBtn.getX() - p1ReplaceLabel.getX() - p1ReplaceLabel.getWidth(); + int p1x3 = p1UnitLabel.getX() - p1ReplaceBtn.getX() - p1ReplaceBtn.getWidth(); + int p1x4 = p1NumLabel.getX() - p1UnitCombo.getX() - p1UnitCombo.getWidth(); + p1TargetLabel.setBounds(p1TargetLabel.getX() + getOffset(left, 20, 800), 20, + p1TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p1TargetBtn.setBounds(p1TargetLabel.getX() + p1TargetLabel.getWidth() + p1x1 + getOffset(left, 10, 800), 20, + p1TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p1ReplaceLabel.setBounds(p1ReplaceLabel.getX() + getOffset(left, 20, 800), 60, + p1ReplaceLabel.getWidth() + getOffset(left, 100, 800), 25); + p1ReplaceBtn.setBounds(p1ReplaceLabel.getX() + p1ReplaceLabel.getWidth() + p1x2 + getOffset(left, 10, 800), 60, + p1ReplaceBtn.getWidth() + getOffset(left, 400, 800), 25); + p1UnitLabel.setBounds(p1ReplaceBtn.getX() + p1ReplaceBtn.getWidth() + p1x3 + getOffset(left, 30, 800), 60, + p1UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p1UnitCombo.setBounds(p1UnitLabel.getX() + p1UnitLabel.getWidth(), 60, + p1UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p1NumLabel.setBounds(p1UnitCombo.getX() + p1UnitCombo.getWidth() + p1x4 + getOffset(left, 20, 800), 60, + p1NumLabel.getWidth() + getOffset(left, 50, 800), 25); + p1NumText.setBounds(p1NumLabel.getX() + p1NumLabel.getWidth(), 60, + p1NumText.getWidth() + getOffset(left, 50, 800), 25); + p1SelectAll.setBounds(p1SelectAll.getX() + getOffset(left, 20, 800), 100, + p1SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p1jsp.setBounds(p1jsp.getX() + getOffset(left, 20, 800), p1jsp.getY(), + p1jsp.getWidth() + getOffset(left, 760, 800), p1jsp.getHeight() + this.heightOffset); + p1BottomBtn1.setBounds(p1BottomBtn1.getX() + getOffset(left, 80, 800), p1BottomBtn1.getY() + this.heightOffset, + p1BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn2.setBounds(p1BottomBtn1.getX() + p1BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p1BottomBtn2.getY() + this.heightOffset, p1BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn3.setBounds(p1BottomBtn2.getX() + p1BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p1BottomBtn3.getY() + this.heightOffset, p1BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn4.setBounds(p1BottomBtn3.getX() + p1BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p1BottomBtn4.getY() + this.heightOffset, p1BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p1Left.setBounds(0, 0, p1Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p1Left.getHeight() + this.heightOffset); + p1TreePanel.setBounds(p1TreePanel.getX() + getOffset(right, 20, 400), 130, + p1TreePanel.getWidth() + getOffset(right, 360, 400), p1TreePanel.getHeight() + this.heightOffset); + p1Right.setBounds(p1Left.getX() + p1Left.getWidth(), 0, + p1Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p1Right.getHeight() + this.heightOffset); + p1.revalidate(); + p1.repaint(); + + // p2 + int p2x1 = p2TargetBtn.getX() - p2TargetLabel.getX() - p2TargetLabel.getWidth(); + int p2x2 = p2NumText.getX() - p2ChangeNumLabel.getX() - p2ChangeNumLabel.getWidth(); + p2TargetLabel.setBounds(p2TargetLabel.getX() + getOffset(left, 20, 800), 20, + p2TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p2TargetBtn.setBounds(p2TargetLabel.getX() + p2TargetLabel.getWidth() + p2x1 + getOffset(left, 10, 800), 20, + p2TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p2ChangeNumLabel.setBounds(p2ChangeNumLabel.getX() + getOffset(left, 20, 800), 60, + p2ChangeNumLabel.getWidth() + getOffset(left, 100, 800), 25); + p2NumText.setBounds(p2ChangeNumLabel.getX() + p2ChangeNumLabel.getWidth() + p2x2 + getOffset(left, 10, 800), 60, + p2NumText.getWidth() + getOffset(left, 50, 800), 25); + p2SelectAll.setBounds(p2SelectAll.getX() + getOffset(left, 20, 800), 100, + p2SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p2jsp.setBounds(p2jsp.getX() + getOffset(left, 20, 800), p2jsp.getY(), + p2jsp.getWidth() + getOffset(left, 760, 800), p2jsp.getHeight() + this.heightOffset); + p2BottomBtn1.setBounds(p2BottomBtn1.getX() + getOffset(left, 80, 800), p2BottomBtn1.getY() + this.heightOffset, + p2BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn2.setBounds(p2BottomBtn1.getX() + p2BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p2BottomBtn2.getY() + this.heightOffset, p2BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn3.setBounds(p2BottomBtn2.getX() + p2BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p2BottomBtn3.getY() + this.heightOffset, p2BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn4.setBounds(p2BottomBtn3.getX() + p2BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p2BottomBtn4.getY() + this.heightOffset, p2BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p2Left.setBounds(0, 0, p2Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p2Left.getHeight() + this.heightOffset); + p2TreePanel.setBounds(p2TreePanel.getX() + getOffset(right, 20, 400), 130, + p2TreePanel.getWidth() + getOffset(right, 360, 400), p2TreePanel.getHeight() + this.heightOffset); + p2Right.setBounds(p2Left.getX() + p2Left.getWidth(), 0, + p2Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p2Right.getHeight() + this.heightOffset); + p2.revalidate(); + p2.repaint(); + + // p3 + int p3x1 = p3TargetBtn.getX() - p3TargetLabel.getX() - p3TargetLabel.getWidth(); + int p3x2 = p3AddBtn.getX() - p3AddLabel.getX() - p3AddLabel.getWidth(); + int p3x3 = p3UnitLabel.getX() - p3AddBtn.getX() - p3AddBtn.getWidth(); + int p3x4 = p3NumLabel.getX() - p3UnitCombo.getX() - p3UnitCombo.getWidth(); + p3TargetLabel.setBounds(p3TargetLabel.getX() + getOffset(left, 20, 800), 20, + p3TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p3TargetBtn.setBounds(p3TargetLabel.getX() + p3TargetLabel.getWidth() + p3x1 + getOffset(left, 10, 800), 20, + p3TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p3AddLabel.setBounds(p3AddLabel.getX() + getOffset(left, 20, 800), 60, + p3AddLabel.getWidth() + getOffset(left, 100, 800), 25); + p3AddBtn.setBounds(p3AddLabel.getX() + p3AddLabel.getWidth() + p3x2 + getOffset(left, 10, 800), 60, + p3AddBtn.getWidth() + getOffset(left, 400, 800), 25); + p3UnitLabel.setBounds(p3AddBtn.getX() + p3AddBtn.getWidth() + p3x3 + getOffset(left, 30, 800), 60, + p3UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p3UnitCombo.setBounds(p3UnitLabel.getX() + p3UnitLabel.getWidth(), 60, + p3UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p3NumLabel.setBounds(p3UnitCombo.getX() + p3UnitCombo.getWidth() + p3x4 + getOffset(left, 20, 800), 60, + p3NumLabel.getWidth() + getOffset(left, 50, 800), 25); + p3NumText.setBounds(p3NumLabel.getX() + p3NumLabel.getWidth(), 60, + p3NumText.getWidth() + getOffset(left, 50, 800), 25); + p3SelectAll.setBounds(p3SelectAll.getX() + getOffset(left, 20, 800), 100, + p3SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p3jsp.setBounds(p3jsp.getX() + getOffset(left, 20, 800), p3jsp.getY(), + p3jsp.getWidth() + getOffset(left, 760, 800), p3jsp.getHeight() + this.heightOffset); + p3BottomBtn1.setBounds(p3BottomBtn1.getX() + getOffset(left, 80, 800), p3BottomBtn1.getY() + this.heightOffset, + p3BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn2.setBounds(p3BottomBtn1.getX() + p3BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p3BottomBtn2.getY() + this.heightOffset, p3BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn3.setBounds(p3BottomBtn2.getX() + p3BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p3BottomBtn3.getY() + this.heightOffset, p3BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn4.setBounds(p3BottomBtn3.getX() + p3BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p3BottomBtn4.getY() + this.heightOffset, p3BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p3Left.setBounds(0, 0, p3Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p3Left.getHeight() + this.heightOffset); + p3TreePanel.setBounds(p3TreePanel.getX() + getOffset(right, 20, 400), 130, + p3TreePanel.getWidth() + getOffset(right, 360, 400), p3TreePanel.getHeight() + this.heightOffset); + p3Right.setBounds(p3Left.getX() + p3Left.getWidth(), 0, + p3Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p3Right.getHeight() + this.heightOffset); + p3.revalidate(); + p3.repaint(); + + // p4 + int p4x1 = p4TargetBtn.getX() - p4TargetLabel.getX() - p4TargetLabel.getWidth(); + p4TargetLabel.setBounds(p4TargetLabel.getX() + getOffset(left, 20, 800), 20, + p4TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p4TargetBtn.setBounds(p4TargetLabel.getX() + p4TargetLabel.getWidth() + p4x1 + getOffset(left, 10, 800), 20, + p4TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p4SelectAll.setBounds(p4SelectAll.getX() + getOffset(left, 20, 800), 100, + p4SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p4jsp.setBounds(p4jsp.getX() + getOffset(left, 20, 800), p4jsp.getY(), + p4jsp.getWidth() + getOffset(left, 760, 800), p4jsp.getHeight() + this.heightOffset); + p4BottomBtn1.setBounds(p4BottomBtn1.getX() + getOffset(left, 80, 800), p4BottomBtn1.getY() + this.heightOffset, + p4BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn2.setBounds(p4BottomBtn1.getX() + p4BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p4BottomBtn2.getY() + this.heightOffset, p4BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn3.setBounds(p4BottomBtn2.getX() + p4BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p4BottomBtn3.getY() + this.heightOffset, p4BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn4.setBounds(p4BottomBtn3.getX() + p4BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p4BottomBtn4.getY() + this.heightOffset, p4BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p4Left.setBounds(0, 0, p4Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p4Left.getHeight() + this.heightOffset); + p4TreePanel.setBounds(p4TreePanel.getX() + getOffset(right, 20, 400), 130, + p4TreePanel.getWidth() + getOffset(right, 360, 400), p4TreePanel.getHeight() + this.heightOffset); + p4Right.setBounds(p4Left.getX() + p4Left.getWidth(), 0, + p4Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p4Right.getHeight() + this.heightOffset); + p4.revalidate(); + p4.repaint(); + + // p5 + int p5x1 = p5UserText.getX() - p5UserLabel.getX() - p5UserLabel.getWidth(); + int p5x2 = p5TimeLabel.getX() - p5UserText.getX() - p5UserText.getWidth(); + int p5x3 = p5TimeStartText.getX() - p5TimeLabel.getX() - p5TimeLabel.getWidth(); + int p5x4 = toLabel.getX() - p5TimeStartText.getX() - p5TimeStartText.getWidth(); + int p5x5 = p5TimeEndText.getX() - toLabel.getX() - toLabel.getWidth(); + int p5x6 = p5ContentLabel.getX() - p5TimeEndText.getX() - p5TimeEndText.getWidth(); + int p5x7 = p5Contentjsp.getX() - p5ContentLabel.getX() - p5ContentLabel.getWidth(); + int p5x8 = p5Search.getX() - p5Contentjsp.getX() - p5Contentjsp.getWidth(); + int p5x9 = p5Download.getX() - p5Search.getX() - p5Search.getWidth(); + p5UserLabel.setBounds(p5UserLabel.getX(), 40, p5UserLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), + 25); + p5UserText.setBounds(p5UserLabel.getX() + p5UserLabel.getWidth() + p5x1 + getOffset(this.widthOffset, 10, 1200), + 40, p5UserText.getWidth() + getOffset(this.widthOffset, 150, 1200), 25); + p5TimeLabel.setBounds(p5UserText.getX() + p5UserText.getWidth() + p5x2 + getOffset(this.widthOffset, 50, 1200), + 40, p5TimeLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25); + p5TimeStartText.setBounds( + p5TimeLabel.getX() + p5TimeLabel.getWidth() + p5x3 + getOffset(this.widthOffset, 10, 1200), 40, + p5TimeStartText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + toLabel.setBounds( + p5TimeStartText.getX() + p5TimeStartText.getWidth() + p5x4 + getOffset(this.widthOffset, 10, 1200), 40, + toLabel.getWidth() + getOffset(this.widthOffset, 20, 1200), 25); + p5TimeEndText.setBounds(toLabel.getX() + toLabel.getWidth() + p5x5 + getOffset(this.widthOffset, 10, 1200), 40, + p5TimeEndText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + p5ContentLabel.setBounds( + p5TimeEndText.getX() + p5TimeEndText.getWidth() + p5x6 + getOffset(this.widthOffset, 50, 1200), 40, + p5ContentLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25); + p5Contentjsp.setBounds( + p5ContentLabel.getX() + p5ContentLabel.getWidth() + p5x7 + getOffset(this.widthOffset, 10, 1200), 20, + p5Contentjsp.getWidth() + getOffset(this.widthOffset, 200, 1200), 80); + p5Search.setBounds(p5Contentjsp.getX() + p5Contentjsp.getWidth() + p5x8 + getOffset(this.widthOffset, 50, 1200), + 40, p5Search.getWidth() + getOffset(this.widthOffset, 60, 1200), 25); + p5Download.setBounds(p5Search.getX() + p5Search.getWidth() + p5x9 + getOffset(this.widthOffset, 20, 1200), 40, + p5Download.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + p5jsp.setBounds(p5jsp.getX() + getOffset(this.widthOffset, 20, 1200), p5jsp.getY(), + p5jsp.getWidth() + getOffset(this.widthOffset, 1160, 1200), p5jsp.getHeight() + this.heightOffset); + p5.revalidate(); + p5.repaint(); + } + + private int getOffset(double num1, int num2, int num3) { + return (int) (num1 * num2 / num3); + } + + private int getResultNum(List msgData, boolean success) { + int num = 0; + String str = success ? "成功" : "失败"; + for (String[] row : msgData) { + if (row[row.length - 1].contains(str)) { + num++; + } + } + return num; + } +} diff --git a/src/com/connor/jd/plm/dialogs/CheckBoxTreeCellRenderer.java b/src/com/connor/jd/plm/dialogs/CheckBoxTreeCellRenderer.java new file mode 100644 index 0000000..bc4a752 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/CheckBoxTreeCellRenderer.java @@ -0,0 +1,107 @@ +package com.connor.jd.plm.dialogs; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.net.URL; + +import javax.swing.ImageIcon; +import javax.swing.JCheckBox; +import javax.swing.JPanel; +import javax.swing.JTree; +import javax.swing.UIManager; +import javax.swing.plaf.ColorUIResource; +import javax.swing.tree.TreeCellRenderer; + +import com.connor.jd.plm.beans.TransformBomBean; +import com.teamcenter.rac.kernel.TCException; + +public class CheckBoxTreeCellRenderer extends JPanel implements TreeCellRenderer { + protected JCheckBox check; + protected CheckBoxTreeLabel label; + + public CheckBoxTreeCellRenderer() { + setLayout(null); + add(check = new JCheckBox()); + add(label = new CheckBoxTreeLabel()); + // 设置不可编辑 + check.setEnabled(false); + check.setBackground(UIManager.getColor("Tree.textBackground")); + label.setForeground(UIManager.getColor("Tree.textForeground")); + } + + /** + * 返回的是一个JPanel对象,该对象中包含一个JCheckBox对象 + * 和一个JLabel对象。并且根据每个结点是否被选中来决定JCheckBox 是否被选中。 + */ + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, + boolean leaf, int row, boolean hasFocus) { + String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); + setEnabled(tree.isEnabled()); + check.setSelected(((CheckBoxTreeNode) value).isSelected()); + label.setFont(tree.getFont()); + label.setText(stringValue); + label.setSelected(selected); + label.setFocus(hasFocus); + + CheckBoxTreeNode node = (CheckBoxTreeNode) value; + TransformBomBean bean = (TransformBomBean) node.getUserObject(); + try { + String type = bean.line.getItemRevision().getType(); + if (type.equals("WX3_ZPTRevision")) { + URL resource = CheckBoxTreeCellRenderer.class.getResource("/com/connor/wxplm/utils/WX3_zptrev.png"); + label.setIcon(new ImageIcon(resource)); + } else if (type.equals("WX3_LJTRevision")) { + URL resource = CheckBoxTreeCellRenderer.class.getResource("/com/connor/wxplm/utils/WX3_ljtrev.png"); + label.setIcon(new ImageIcon(resource)); + } else if (type.equals("WX3_WLRevision")) { + URL resource = CheckBoxTreeCellRenderer.class.getResource("/com/connor/wxplm/utils/WX3_WLRev.png"); + label.setIcon(new ImageIcon(resource)); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + /* + * if(leaf) label.setIcon(UIManager.getIcon("Tree.leafIcon")); else if(expanded) + * label.setIcon(UIManager.getIcon("Tree.expandedIcon")); else + * label.setIcon(UIManager.getIcon("Tree.closedIcon")); + */ + + return this; + } + + @Override + public Dimension getPreferredSize() { + Dimension dCheck = check.getPreferredSize(); + Dimension dLabel = label.getPreferredSize(); + return new Dimension(dCheck.width + dLabel.width, + dCheck.height < dLabel.height ? dLabel.height : dCheck.height); + } + + @Override + public void doLayout() { + Dimension dCheck = check.getPreferredSize(); + Dimension dLabel = label.getPreferredSize(); + int yCheck = 0; + int yLabel = 0; + if (dCheck.height < dLabel.height) + yCheck = (dLabel.height - dCheck.height) / 2; + else + yLabel = (dCheck.height - dLabel.height) / 2; + check.setLocation(0, yCheck); + check.setBounds(0, yCheck, dCheck.width, dCheck.height); + label.setLocation(dCheck.width, yLabel); + label.setBounds(dCheck.width, yLabel, dLabel.width, dLabel.height); + } + + @Override + public void setBackground(Color color) { + if (color instanceof ColorUIResource) + color = null; + super.setBackground(color); + } + +} diff --git a/src/com/connor/jd/plm/dialogs/CheckBoxTreeLabel.java b/src/com/connor/jd/plm/dialogs/CheckBoxTreeLabel.java new file mode 100644 index 0000000..2c8b26c --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/CheckBoxTreeLabel.java @@ -0,0 +1,66 @@ +package com.connor.jd.plm.dialogs; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; + +import javax.swing.Icon; +import javax.swing.JLabel; +import javax.swing.UIManager; +import javax.swing.plaf.ColorUIResource; + +public class CheckBoxTreeLabel extends JLabel { + private boolean isSelected; + private boolean hasFocus; + + public CheckBoxTreeLabel() { + } + + @Override + public void setBackground(Color color) { + if (color instanceof ColorUIResource) + color = null; + super.setBackground(color); + } + + @Override + public void paint(Graphics g) { + String str; + if ((str = getText()) != null) { + if (0 < str.length()) { + if (isSelected) + g.setColor(UIManager.getColor("Tree.selectionBackground")); + else + g.setColor(UIManager.getColor("Tree.textBackground")); + Dimension d = getPreferredSize(); + int imageOffset = 0; + Icon currentIcon = getIcon(); + if (currentIcon != null) + imageOffset = currentIcon.getIconWidth() + Math.max(0, getIconTextGap() - 1); + g.fillRect(imageOffset, 0, d.width - 1 - imageOffset, d.height); + if (hasFocus) { + g.setColor(UIManager.getColor("Tree.selectionBorderColor")); + g.drawRect(imageOffset, 0, d.width - 1 - imageOffset, d.height - 1); + } + } + } + super.paint(g); + } + + @Override + public Dimension getPreferredSize() { + Dimension retDimension = super.getPreferredSize(); + if (retDimension != null) + retDimension = new Dimension(retDimension.width + 3, retDimension.height); + return retDimension; + } + + public void setSelected(boolean isSelected) { + this.isSelected = isSelected; + } + + public void setFocus(boolean hasFocus) { + this.hasFocus = hasFocus; + } + +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/dialogs/CheckBoxTreeNode.java b/src/com/connor/jd/plm/dialogs/CheckBoxTreeNode.java new file mode 100644 index 0000000..65e71b9 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/CheckBoxTreeNode.java @@ -0,0 +1,92 @@ +package com.connor.jd.plm.dialogs; + +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.MutableTreeNode; +import javax.swing.tree.TreeNode; + +public class CheckBoxTreeNode extends DefaultMutableTreeNode { + protected boolean isSelected; + protected boolean isSelectable = true; + public CheckBoxTreeNode() { + this(null); + } + + public CheckBoxTreeNode(Object userObject) { + this(userObject, true, false); + } + + public CheckBoxTreeNode(Object userObject, boolean allowsChildren, boolean isSelected) { + super(userObject, allowsChildren); + this.isSelected = isSelected; + } + + public boolean isSelected() { + return isSelected; + } + + public void setSelected(boolean _isSelected) { + this.isSelected = _isSelected; + + /*if (_isSelected) { + // 如果选中,则将其所有的子结点都选中 + if (children != null) { + for (Object obj : children) { + CheckBoxTreeNode node = (CheckBoxTreeNode) obj; + if (_isSelected != node.isSelected()) + node.setSelected(_isSelected); + } + } + // 向上检查,如果父结点的所有子结点都被选中,那么将父结点也选中 + CheckBoxTreeNode pNode = (CheckBoxTreeNode) parent; + // 开始检查pNode的所有子节点是否都被选中 + if (pNode != null) { + int index = 0; + for (; index < pNode.children.size(); ++index) { + CheckBoxTreeNode pChildNode = (CheckBoxTreeNode) pNode.children.get(index); + if (!pChildNode.isSelected()) + break; + } + + * 表明pNode所有子结点都已经选中,则选中父结点, 该方法是一个递归方法,因此在此不需要进行迭代,因为 + * 当选中父结点后,父结点本身会向上检查的。 + + if (index == pNode.children.size()) { + if (pNode.isSelected() != _isSelected) + pNode.setSelected(_isSelected); + } + } + } else { + + * 如果是取消父结点导致子结点取消,那么此时所有的子结点都应该是选择上的; + * 否则就是子结点取消导致父结点取消,然后父结点取消导致需要取消子结点,但 是这时候是不需要取消子结点的。 + + if (children != null) { + int index = 0; + for (; index < children.size(); ++index) { + CheckBoxTreeNode childNode = (CheckBoxTreeNode) children.get(index); + if (!childNode.isSelected()) + break; + } + // 从上向下取消的时候 + if (index == children.size()) { + for (int i = 0; i < children.size(); ++i) { + CheckBoxTreeNode node = (CheckBoxTreeNode) children.get(i); + if (node.isSelected() != _isSelected) + node.setSelected(_isSelected); + } + } + } + + // 向上取消,只要存在一个子节点不是选上的,那么父节点就不应该被选上。 + CheckBoxTreeNode pNode = (CheckBoxTreeNode) parent; + if (pNode != null && pNode.isSelected() != _isSelected) + pNode.setSelected(_isSelected); + }*/ + } + + // 不可编辑 + public boolean setSelectable(boolean bol) { + + return isSelectable = bol; + } +} diff --git a/src/com/connor/jd/plm/dialogs/CheckBoxTreeNodeSelectionListener.java b/src/com/connor/jd/plm/dialogs/CheckBoxTreeNodeSelectionListener.java new file mode 100644 index 0000000..6631a27 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/CheckBoxTreeNodeSelectionListener.java @@ -0,0 +1,30 @@ +package com.connor.jd.plm.dialogs; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.JTree; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; + + + +public class CheckBoxTreeNodeSelectionListener extends MouseAdapter { + @Override + public void mouseClicked(MouseEvent event) { + + JTree tree = (JTree) event.getSource(); + int x = event.getX(); + int y = event.getY(); + int row = tree.getRowForLocation(x, y); + TreePath path = tree.getPathForRow(row); + if (path != null) { + CheckBoxTreeNode node = (CheckBoxTreeNode) path.getLastPathComponent(); + if (node != null&&node.isSelectable) { + boolean isSelected = !node.isSelected(); + node.setSelected(isSelected); + ((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node); + } + } + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/dialogs/ColorMaterialBean.java b/src/com/connor/jd/plm/dialogs/ColorMaterialBean.java new file mode 100644 index 0000000..318496e --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/ColorMaterialBean.java @@ -0,0 +1,14 @@ +package com.connor.jd.plm.dialogs; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.teamcenter.rac.kernel.TCComponentItemRevision; + +public class ColorMaterialBean { + public List colorMaterial = new ArrayList(); + public Map data = new HashMap(); + +} diff --git a/src/com/connor/jd/plm/dialogs/MyTreeCellRenderer.java b/src/com/connor/jd/plm/dialogs/MyTreeCellRenderer.java new file mode 100644 index 0000000..dcaeb3f --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/MyTreeCellRenderer.java @@ -0,0 +1,40 @@ +package com.connor.jd.plm.dialogs; + +import java.awt.Component; + +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; + +import com.teamcenter.rac.kernel.TCSession; + +public class MyTreeCellRenderer extends DefaultTreeCellRenderer { + private TCSession session; + + public MyTreeCellRenderer(TCSession session) { + this.session = session; + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, + int row, boolean hasFocus) { + + super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + + setText(value.toString()); + + if (sel) { + setForeground(getTextSelectionColor()); + } else { + setForeground(getTextNonSelectionColor()); + } + + DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; + String str = node.toString(); + if (!"".equals(str)) { +// session.search(arg0, arg1, arg2) + } + + return this; + } +} diff --git a/src/com/connor/jd/plm/dialogs/TransformDesignToPartDialog.java b/src/com/connor/jd/plm/dialogs/TransformDesignToPartDialog.java new file mode 100644 index 0000000..c7cb266 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/TransformDesignToPartDialog.java @@ -0,0 +1,887 @@ +package com.connor.jd.plm.dialogs; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.AdjustmentEvent; +import java.awt.event.AdjustmentListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollBar; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.ScrollPaneConstants; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; + +import com.connor.jd.plm.beans.TransformBomBean; +import com.connor.jd.plm.utils.DialogUtil; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMViewRevision; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentICO; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.kernel.ics.ICSProperty; +import com.teamcenter.rac.util.ButtonLayout; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; + +/** + * 设计bom转化为物料bom + * + * @author conner.mcc + * + */ +public class TransformDesignToPartDialog extends AbstractAIFDialog implements ActionListener { + private AbstractAIFApplication app; + private TCSession session; + private TCComponentBOMLine topBomline; + private JButton okButton; + private JButton celButton; + private JTree tree; + private CheckBoxTreeNode topTree; + private List> comboxList; + private JPanel rightJPanel; + private Map> checkBoxTreeNodelMap; + private Map, JButton> boxJButtonMap; + private JPanel leftJPanel; + private int index = 1; + private String[] types; + TCComponentBOMWindow win; + + public TransformDesignToPartDialog(AbstractAIFApplication app, TCComponentBOMLine topBomline, String[] types) { + // TODO Auto-generated constructor stub + System.out.println("step:-3------------------"); + comboxList = new ArrayList<>(); + this.app = app; + this.session = (TCSession) app.getSession(); + this.topBomline = topBomline; + this.types = types; + createWindow(); + + initUI(); + } + + private void createWindow() { + try { + TCTypeService service = session.getTypeService(); + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow"); + win = winType.create(null); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * 界面初始化 + */ + private void initUI() { + this.setTitle("DBOM转EBOM"); + this.setSize(new Dimension(700, 400)); + JPanel rightroot = new JPanel(new BorderLayout()); + rightJPanel = new JPanel(new PropertyLayout()); + rightroot.setBorder(BorderFactory.createTitledBorder("物料")); + leftJPanel = new JPanel(new BorderLayout()); + leftJPanel.setBorder(BorderFactory.createTitledBorder("图纸")); + leftJPanel.setPreferredSize(new Dimension(350, 300)); + rightroot.setPreferredSize(new Dimension(350, 300)); + getBOMTreeAndwl(); + JScrollPane leftpane = new JScrollPane(tree); + leftpane.setBorder(null); + leftJPanel.add(leftpane); + JScrollPane rightpane = new JScrollPane(rightJPanel); + rightroot.add(rightpane); + rightpane.setBorder(null); + final JScrollBar bar2 = rightpane.getVerticalScrollBar(); + final JScrollBar bar1 = leftpane.getVerticalScrollBar(); + rightpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + leftpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + bar2.addAdjustmentListener(new AdjustmentListener() { + + @Override + public void adjustmentValueChanged(AdjustmentEvent e) { + // TODO Auto-generated method stub + if (e.getValueIsAdjusting()) { + bar1.setValue(e.getValue()); + } + } + }); + + bar1.addAdjustmentListener(new AdjustmentListener() { + + @Override + public void adjustmentValueChanged(AdjustmentEvent e) { + // TODO Auto-generated method stub + if (e.getValueIsAdjusting()) { + bar2.setValue(e.getValue()); + } + } + }); + + leftpane.getVerticalScrollBar().setUnitIncrement(10); + leftpane.addMouseWheelListener(new MouseWheelListener() { + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + if (e.getScrollType() == e.WHEEL_UNIT_SCROLL && bar1.getValue() >= 0 + && bar1.getValue() <= bar1.getVisibleAmount()) { + int scroll = e.getUnitsToScroll(); + bar2.setValue(scroll * bar1.getUnitIncrement()); + + } + } + }); + + rightpane.getVerticalScrollBar().setUnitIncrement(10); + rightpane.addMouseWheelListener(new MouseWheelListener() { + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + if (e.getScrollType() == e.WHEEL_UNIT_SCROLL && bar1.getValue() >= 0 + && bar1.getValue() <= bar1.getVisibleAmount()) { + int scroll = e.getUnitsToScroll(); + bar1.setValue(scroll * bar2.getUnitIncrement()); + + } + } + }); + + JPanel botomJPanel = new JPanel(new ButtonLayout()); + okButton = new JButton("转换"); + okButton.addActionListener(this); + celButton = new JButton("退出"); + celButton.addActionListener(this); + + botomJPanel.add("1.1.left.top", okButton); + botomJPanel.add("1.2.left.top", new JLabel(" ")); + botomJPanel.add("1.3.left.top", celButton); + JPanel rootJPanel = new JPanel(new PropertyLayout()); + rootJPanel.add("1.1.left.top", leftJPanel); + rootJPanel.add("1.2.left.top", rightroot); + + this.setLayout(new BorderLayout()); + this.add(rootJPanel, BorderLayout.CENTER); + this.add(botomJPanel, BorderLayout.SOUTH); + this.pack(); + this.centerToScreen(); + this.showDialog(); + this.setResizable(false); + } + + /** + * @param line 所有BOM添加到树结构 + * @param node + * @throws TCException + */ + public void treeModel(TCComponentBOMLine line, CheckBoxTreeNode node) throws TCException { + System.out.println(line.getProperty("object_string") + "-------------------"); + AIFComponentContext[] children = line.getChildren(); + for (AIFComponentContext conetext : children) { + TCComponentBOMLine childLine = (TCComponentBOMLine) conetext.getComponent(); + final CheckBoxTreeNode childNode = new CheckBoxTreeNode(new TransformBomBean(childLine)); + childNode.setSelectable(false); + node.add(childNode); + setCombox(childLine, childNode); + treeModel(childLine, childNode); + } + } + + private void getBOMTreeAndwl() { + try { + checkBoxTreeNodelMap = new HashMap<>(); + boxJButtonMap = new HashMap<>(); + topTree = new CheckBoxTreeNode(new TransformBomBean(topBomline)); + setCombox(topBomline, topTree); + System.out.println("##########" + topTree.toString() + "##########"); + treeModel(topBomline, topTree); + tree = new JTree(); + tree.setEnabled(false); + tree.setRowHeight(30); + DefaultTreeModel model = new DefaultTreeModel(topTree); + tree.addMouseListener(new CheckBoxTreeNodeSelectionListener()); + tree.setModel(model); + tree.setCellRenderer(new CheckBoxTreeCellRenderer()); + tree.putClientProperty("JTree.lineStyle", "Angled"); + topTree.setSelectable(false); + tree.expandPath(new TreePath(topTree.getPath())); + Enumeration enumeration = topTree.preorderEnumeration(); + while (enumeration.hasMoreElements()) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) enumeration.nextElement(); + if (!node.isLeaf()) { + TreePath path = new TreePath(node.getPath()); + tree.expandPath(path); + } + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + if (e.getSource().equals(okButton)) { + try { + System.out.println("进行转换"); + if (win == null) + createWindow(); + ColorMaterialBean bean = new ColorMaterialBean(); + createMaterialBom(topTree, bean); + if (bean.colorMaterial.size() != 0) { + System.out.println( + Arrays.deepToString(bean.colorMaterial.toArray(new String[bean.colorMaterial.size()][]))); + JScrollPane msgPanel = DialogUtil.createTableMsg(new String[] { "ID", "版本", "名称", "颜色" }, + bean.colorMaterial).panel; + int r = JOptionPane.showConfirmDialog((Component) e.getSource(), msgPanel, "颜色件确认", + JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); + if (r == JOptionPane.OK_OPTION) { + createBom1(bean); + } else { + System.out.println("cancel"); + return; + } + } else { + createBom1(bean); + } + MessageBox.post("转换bom成功", "提示", MessageBox.INFORMATION); + this.dispose(); + } catch (TCException e1) { + + // TODO Auto-generated catch block + MessageBox.post(e1.getMessage(), "转换bom失败", MessageBox.INFORMATION); + e1.printStackTrace(); + } finally { + try { + + win.close(); + win = null; + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } else if (e.getSource().equals(celButton)) { + + dispose(); + } + + } + + @SuppressWarnings("unchecked") + private void createBom1(ColorMaterialBean bean) throws TCException { + for (Entry entry : bean.data.entrySet()) { + List arg1 = entry.getValue()[1] == null ? null + : (List) entry.getValue()[1]; + List arg2 = entry.getValue()[2] == null ? null : (List) entry.getValue()[2]; + List arg3 = entry.getValue()[3] == null ? null : (List) entry.getValue()[3]; + createBom(entry.getKey(), arg1, arg2, arg3); + } + } + + /** + * 讲Tree对应的item选中 + * + * @param wl + *//* + * private void checkSelected(String wl) { for (TransformBomBean bean : bomlist) + * { if (bean.map.containsKey(wl)) { bean.selectCount++; if (bean.selectCount > + * 1) { MessageBox.post("只能为当前图纸选择一个物料进行设计BOM的转换!", "警告", MessageBox.WARNING); + * return; } System.out.println(bean.displayName + "选中显示名"); + * System.out.println(checkBoxTreeNodelMap.containsKey(bean.displayName) ); + * checkBoxTreeNodelMap.get(bean.displayName).setSelected(true); + * findInTree(bean.displayName); TransformBomBean bean1 = (TransformBomBean) + * checkBoxTreeNodelMap.get(bean.displayName).getUserObject(); bean1.selectRev = + * (TCComponentItemRevision) bean.map.get(wl); } } } + */ + + /** + * 讲Tree对应的item取消选中 + * + * @param wl + *//* + * private void checkDisSelected(String wl) { for (TransformBomBean bean : + * bomlist) { if (bean.map.containsKey(wl)) { bean.selectCount--; + * checkBoxTreeNodelMap.get(bean.displayName).setSelected(false); } } } + */ + + /** + * 搭建BOM + * + * @param node + * @throws TCException + */ + private void createMaterialBom(CheckBoxTreeNode node, ColorMaterialBean colorMaterialBean) throws TCException { + // System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); + TransformBomBean bean = (TransformBomBean) node.getUserObject(); + TCComponentItemRevision materialRev = bean.selectRev; + // 存在已经发布的物料的bom + /* + * if (WXMethodUtil.isRevBomReleased(materialRev)) { System.out.println("发布"); + * return; } + */ + + if (isLoopBom(node)) { + MessageBox.post("存在循环BOM结构", "警告", MessageBox.WARNING); + return; + } + int childCount = node.getChildCount(); + List childrenList = new ArrayList<>(); + List quantityList = new ArrayList<>(); + for (int i = 0; i < childCount; i++) { + CheckBoxTreeNode childNode = (CheckBoxTreeNode) node.getChildAt(i); + if (childNode.isSelected()) { + TransformBomBean bean1 = (TransformBomBean) childNode.getUserObject(); + childrenList.add(bean1.selectRev); + quantityList.add(bean1.line.getProperty("bl_quantity")); + // 判断是否发布 + if (isRevBomReleased(bean1.selectRev)) { + // 发布就搭建原来的bom + System.out.println("原来搭建》》》》》》》》》》》》》》》"); + if (isLoopBom(childNode)) { + MessageBox.post("存在循环BOM结构", "警告", MessageBox.WARNING); + return; + } + } else { + createMaterialBom(childNode, colorMaterialBean); + } + } + } + + for (TCComponentItemRevision material : childrenList) { + if (material.getClassificationObjects().length > 0) { + String ys = null; + TCComponentICO ico = material.getClassificationObjects()[0]; + ICSProperty[] props = ico.getICSProperties(true); + for (ICSProperty prop : props) { + if (prop.getId() == 1007) { + ys = prop.getValue(); + break; + } + } + if (ys != null && !"".equals(ys)) { + System.out.println("颜色件:" + material.getProperty("object_string")); + colorMaterialBean.colorMaterial.add(new String[] { material.getProperty("item_id"), + material.getProperty("item_revision_id"), material.getProperty("object_name"), ys }); + } + } + } + colorMaterialBean.data.put(materialRev, new Object[] { materialRev, childrenList, null, quantityList }); + } + + private TreePath findInPath(TreePath treePath, String str) { + Object object = treePath.getLastPathComponent(); + if (object == null) { + return null; + } + + String value = object.toString(); + if (str.equals(value)) { + return treePath; + } else { + TreeModel model = tree.getModel(); + int n = model.getChildCount(object); + for (int i = 0; i < n; i++) { + Object child = model.getChild(object, i); + TreePath path = treePath.pathByAddingChild(child); + path = findInPath(path, str); + if (path != null) { + return path; + } + } + return null; + } + } + + private void findInTree(String str) { + Object root = tree.getModel().getRoot(); + TreePath treePath = new TreePath(root); + treePath = findInPath(treePath, str); + if (treePath != null) { + tree.setSelectionPath(treePath); + CheckBoxTreeNode node = (CheckBoxTreeNode) tree.getLastSelectedPathComponent(); + tree.scrollPathToVisible(treePath); + } + } + + /** + * @param line + * @param childNode + * @return 返回关联物料数组 + */ + public String[] getBomRef(TCComponentBOMLine line, CheckBoxTreeNode childNode) { + try { + if (line == null) { + return null; + } + AIFComponentContext[] aifContext = line.getItemRevision().whereReferencedByTypeRelation(types, + new String[] { "TC_Is_Represented_By" }); + if (aifContext == null || aifContext.length == 0) { + return new String[] { "" }; + } else { + AIFComponentContext[] newContext = isNewRev(aifContext); + String[] wl = new String[newContext.length]; + TransformBomBean bean = (TransformBomBean) childNode.getUserObject(); + for (int i = 0; i < wl.length; i++) { + TCComponentItemRevision comp = (TCComponentItemRevision) newContext[i].getComponent(); + wl[i] = comp.getProperty("object_string"); + bean.map.put(wl[i], comp); + } + + return wl; + } + } catch (TCException e) { + e.printStackTrace(); + } + return new String[] { "" }; + } + + /** + * 下拉框选择物料 + * + * @param childLine + * @param childNode + */ + private void setCombox(TCComponentBOMLine childLine, final CheckBoxTreeNode childNode) { + try { + System.out.println(childLine.getItemRevision().getType() + "<<<<<<<<<<"); + final String[] bomRef = getBomRef(childLine, childNode); + final DefaultComboBoxModel model = new DefaultComboBoxModel(); + model.addElement(""); + for (String str : bomRef) { + model.addElement(str); + } + + final JComboBox childbox = new JComboBox(); + + // 模糊搜索按钮 + final JButton search = new JButton("搜索"); + checkBoxTreeNodelMap.put(childNode, childbox); + boxJButtonMap.put(childbox, search); + childbox.setModel(model); + childbox.setSelectedIndex(-1); + childbox.setEditable(true); + + if (childbox.getItemCount() <= 2 && childbox.getItemAt(1) != null && !childbox.getItemAt(1).equals("")) { + childbox.setSelectedIndex(1); + childbox.setEditable(false); + childNode.setSelected(true); + search.setEnabled(false); + childbox.enable(false); + TransformBomBean bean = (TransformBomBean) childNode.getUserObject(); + bean.selectRev = bean.map.get(childbox.getSelectedItem().toString()); + } else if (childbox.getItemCount() <= 2) { + childbox.setEditable(false); + search.setEnabled(false); + childbox.enable(false); + } + if (childLine.getItemRevision().getType().equals("PartRevision")) { + childbox.setEditable(false); + search.setEnabled(false); + childNode.setSelected(true); + childbox.enable(false); + TransformBomBean bean = (TransformBomBean) childNode.getUserObject(); + bean.selectRev = childLine.getItemRevision(); + } + childbox.setPreferredSize(new Dimension(240, 23)); + search.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + if (childbox.isEditable() && search.isEnabled()) { + String str = childbox.getEditor().getItem().toString(); + model.removeAllElements(); + model.addElement(""); + for (int i = 0; i < bomRef.length; i++) { + if (bomRef[i].contains(str)) { + model.addElement(bomRef[i]); + } + } + childbox.setModel(model); + childbox.setPopupVisible(true); + } + } + }); + + childbox.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + // TODO Auto-generated method stub + try { + if (e.getStateChange() == 1) { + if (childbox.getSelectedIndex() > 0) { + TransformBomBean bean = (TransformBomBean) childNode.getUserObject(); + bean.selectRev = bean.map.get(childbox.getSelectedItem().toString()); + childNode.setSelected(true); + System.out.println("-----------" + bean.displayName); + // 判断是否布 发布子类全部不可选择 + boolean released = isReleased(bean.selectRev, childNode); + System.out.println("<<<<<<<<<<是否发布:" + released); + tree.repaint(); + } else { + System.out.println("<<<<<<<<<<选择空:"); + restoreSelect(childNode); + childNode.setSelected(false); + tree.repaint(); + } + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + } + }); + comboxList.add(childbox); + rightJPanel.add((index) + ".1.left.top", childbox); + rightJPanel.add((index++) + ".2.left.top", search); + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * 判断是否发布 + * + * @param rev + * @param childNode + * @return + */ + private boolean isReleased(TCComponentItemRevision rev, CheckBoxTreeNode childNode) { + + try { + System.out.println("执行判断" + rev.getProperty("object_name")); + if (rev != null && isRevBomReleased(rev)) { + setUnable(childNode); + return true; + } else { + restoreSelect(childNode); + return false; + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + private void setUnable(CheckBoxTreeNode childNode) { + int childCount = childNode.getChildCount(); + for (int i = 0; i < childCount; i++) { + CheckBoxTreeNode node = (CheckBoxTreeNode) childNode.getChildAt(i); + JComboBox box = checkBoxTreeNodelMap.get(node); + box.setSelectedIndex(-1); + box.setEditable(false); + box.setEnabled(false); + node.setSelected(false); + boxJButtonMap.get(box).setEnabled(false); + setUnable(node); + } + } + + /** + * 复原 + * + * @param childNode + * @throws TCException + */ + private void restoreSelect(CheckBoxTreeNode childNode) throws TCException { + int childCount = childNode.getChildCount(); + for (int i = 0; i < childCount; i++) { + CheckBoxTreeNode node = (CheckBoxTreeNode) childNode.getChildAt(i); + JComboBox childbox = checkBoxTreeNodelMap.get(node); + TransformBomBean bean = (TransformBomBean) node.getUserObject(); + childbox.setEditable(true); + childbox.setEnabled(true); + childbox.setSelectedIndex(-1); + if (childbox.getItemCount() <= 2 && !childbox.getItemAt(1).equals("")) { + childbox.setSelectedIndex(1); + childbox.setEditable(false); + childbox.setEnabled(false); + node.setSelected(true); + boxJButtonMap.get(childbox).setEnabled(false); + bean.selectRev = bean.map.get(childbox.getSelectedItem().toString()); + } else if (childbox.getItemCount() <= 2) { + childbox.setEditable(false); + childbox.setEnabled(false); + boxJButtonMap.get(childbox).setEnabled(false); + } + if (bean.line.getItemRevision().isTypeOf("PartRevision")) { + childbox.setEditable(false); + boxJButtonMap.get(childbox).setEnabled(false); + node.setSelected(true); + childbox.setEnabled(false); + bean.selectRev = bean.line.getItemRevision(); + } + restoreSelect(node); + } + + } + + /** + * 判断是否为最新版本 剔除旧版本 + * + * @param aifContext + * @return + */ + private AIFComponentContext[] isNewRev(AIFComponentContext[] aifContext) { + try { + List list = new ArrayList<>(); + for (int i = 0; i < aifContext.length; i++) { + TCComponentItemRevision rev = (TCComponentItemRevision) aifContext[i].getComponent(); + if (rev.getItem().getLatestItemRevision().equals(rev)) { + list.add(aifContext[i]); + } + } + AIFComponentContext[] newContext = new AIFComponentContext[list.size()]; + for (int i = 0; i < list.size(); i++) { + newContext[i] = list.get(i); + } + return newContext; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + /** + * 判断循环 + * + * @param node + * @return + */ + private boolean isLoopBom(CheckBoxTreeNode node) { + try { + HashSet loopSet = new HashSet<>(); + boolean checkLoop = checkLoop(node, loopSet); + return checkLoop; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + /** + * 向上找父类,判断是否有相同的物料 + * + * @param node + * @param loopSet + * @return + * @throws TCException + */ + private boolean checkLoop(CheckBoxTreeNode node, HashSet loopSet) throws TCException { + TransformBomBean bean = (TransformBomBean) node.getUserObject(); + TCComponentItemRevision materialRev = bean.selectRev; + boolean add = loopSet.add(materialRev); + if (!add) { + return true; + } else { + CheckBoxTreeNode parent = (CheckBoxTreeNode) node.getParent(); + if (parent == null) { + return false; + } else { + return checkLoop(parent, loopSet); + } + } + } + + public void getAllBomItemByBomline(TCComponentBOMLine line, List itemList) throws TCException { + if (line == null) { + return; + } + itemList.add(line.getItem()); + AIFComponentContext[] contextS = line.getChildren(); + for (AIFComponentContext context : contextS) { + TCComponentBOMLine child = (TCComponentBOMLine) context.getComponent(); + getAllBomItemByBomline(child, itemList); + } + } + + /** + * 搭建bom + * + * @param selectIndex + * @throws TCException + */ + public void createBom(TCComponentItemRevision parentRev, List childRevList, + List queryNoList, List countNoList) throws TCException { + if (childRevList == null || childRevList.size() == 0) { + return; + } + if (parentRev == null) { + return; + } + String[] setProps = { "bl_quantity" }; + TCComponentBOMLine line = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null); + AIFComponentContext[] childrenContext = line.getChildren(); + + win.lock(); + // 移出所有的子bomline + if (childrenContext.length != 0) { + for (AIFComponentContext child : childrenContext) { + line.lock(); + line.remove("", (TCComponent) child.getComponent()); + line.save(); + line.unlock(); + } + // return; + } + for (int i = 0; i < childRevList.size(); i++) { + TCComponentItemRevision rev = childRevList.get(i); + line.lock(); + TCComponentBOMLine childBomLine = line.add(rev.getItem(), rev, null, false, ""); + line.save(); + line.unlock(); + if (countNoList.get(i) != null && !countNoList.get(i).equals("")) { + childBomLine.lock(); + childBomLine.setProperties(setProps, new String[] { countNoList.get(i) }); + childBomLine.save(); + childBomLine.unlock(); + } + + } + try { + win.save(); + win.unlock(); + } catch (Exception e) { + win.unlock(); + win.close(); + win = null; + System.out.println("windows close"); + TCComponent[] comps = parentRev.getTCProperty("structure_revisions").getReferenceValueArray(); + if (comps.length > 0) { + parentRev.remove("structure_revisions", comps[0]); + comps[0].delete(); + ; + } + e.printStackTrace(); + throw e; + } + + } + + /** + * 检查对象是否已经发布 + * + * @param comp + * @return + * @throws TCException + */ + public boolean isCompReleased(TCComponent comp) throws TCException { + TCComponent[] comps = comp.getRelatedComponents("release_status_list"); + if (comps != null && comps.length > 0) { + return true; + } + return false; + } + + /** + * 是否有BOM + * + * @param rev + * @return + */ + public boolean isRevHadBom(TCComponentItemRevision rev) { + boolean isHad = false; + if (rev != null) { + try { + TCComponentBOMLine topLine = win.setWindowTopLine(rev.getItem(), rev, null, null); + if (topLine != null) { + if (topLine.getChildren().length > 0) { + isHad = true; + } + } + } catch (TCException e) { + e.printStackTrace(); + } + } + return isHad; + } + + /** + * 判断已经发布的对象是否有BOM + * + * @param rev + * @return + */ + public boolean isRevBomReleased(TCComponentItemRevision rev) { + boolean isReleased = false; + try { + if (isCompReleased(rev)) { + win.setWindowTopLine(rev.getItem(), rev, null, null); + // TCComponentBOMLine line = window.getTopBOMLine(); + // if(line.getChildren().length!=0){ + // isReleased = true; + // } + if (isRevHadBom(rev)) { + TCComponentBOMViewRevision bvr = win.askBvr(); + if (bvr != null) { + TCComponent[] status = bvr.getReferenceListProperty("release_status_list"); + if (status != null && status.length != 0) { + isReleased = true; + } + } + } + } + } catch (TCException e) { + e.printStackTrace(); + isReleased = true; + } + return isReleased; + + } + + private boolean isYSMaterial(TCComponentItemRevision rev) { + try { + Map map = rev.getClassificationAttributes(); + if (map.get("颜色") != null && !"".equals(map.get("颜色"))) { + return true; + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + +} diff --git a/src/com/connor/jd/plm/form/MyCallBack.java b/src/com/connor/jd/plm/form/MyCallBack.java new file mode 100644 index 0000000..72f83b0 --- /dev/null +++ b/src/com/connor/jd/plm/form/MyCallBack.java @@ -0,0 +1,6 @@ +package com.connor.jd.plm.form; + +public interface MyCallBack { + + public void execute(String itemId); +} diff --git a/src/com/connor/jd/plm/form/PhotoFrame.java b/src/com/connor/jd/plm/form/PhotoFrame.java new file mode 100644 index 0000000..bde2a4c --- /dev/null +++ b/src/com/connor/jd/plm/form/PhotoFrame.java @@ -0,0 +1,79 @@ +package com.connor.jd.plm.form; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Toolkit; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; + +public class PhotoFrame extends JFrame { + + private static final long serialVersionUID = -2216276219179107707L; + private Container con; + + private ZPanel zPanel; + private JScrollPane imgSp; + private static PhotoFrame instance; + + public static PhotoFrame getInstance(String imgPath) { + if (instance == null) { + instance = new PhotoFrame(imgPath); + } else { + instance.zPanel.setImagePath(imgPath); + instance.setVisible(true); + instance.zPanel.setPreferredSize( + new Dimension(instance.zPanel.getImgWidth(), + instance.zPanel.getImgHeight())); + } + return instance; + } + + private PhotoFrame(String imgPath) { + init(imgPath); + finalSetting(); + } + + private void init(String imgPath) { + con = getContentPane(); + + zPanel = new ZPanel(); + zPanel.setImagePath(imgPath); + zPanel.setPreferredSize( + new Dimension(zPanel.getImgWidth(), zPanel.getImgHeight())); + + imgSp = new JScrollPane(); + imgSp.setViewportView(zPanel); + imgSp.setHorizontalScrollBarPolicy( + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + imgSp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + + con.add(imgSp, BorderLayout.CENTER); + } + + private void finalSetting() { + setTitle("预览"); + + Toolkit kit = Toolkit.getDefaultToolkit(); + Dimension screenSize = kit.getScreenSize(); + int screenHeight = screenSize.height; + int screenWidth = screenSize.width; + int frameH = getHeight(); + int frameW = getWidth(); + setLocation((screenWidth - frameW) / 2 - 250, + (screenHeight - frameH) / 2 - 250); + setSize(screenWidth / 2, screenHeight / 2); + setVisible(true); + setResizable(true); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + super.dispose(); + System.out.println("预览关闭"); + zPanel.clear(); + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/form/ZPanel.java b/src/com/connor/jd/plm/form/ZPanel.java new file mode 100644 index 0000000..85988cc --- /dev/null +++ b/src/com/connor/jd/plm/form/ZPanel.java @@ -0,0 +1,79 @@ +package com.connor.jd.plm.form; + +import java.awt.Graphics; +import java.awt.Image; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +import javax.imageio.ImageIO; + +public class ZPanel extends javax.swing.JPanel { + + private static final long serialVersionUID = 1L; + private Image image; + private int imgWidth; + private int imgHeight; + private FileInputStream input; + + public int getImgWidth() { + return imgWidth; + } + + public void setImgWidth(int imgWidth) { + this.imgWidth = imgWidth; + } + + public int getImgHeight() { + return imgHeight; + } + + public void setImgHeight(int imgHeight) { + this.imgHeight = imgHeight; + } + + public ZPanel() { + } + + public void setImagePath(String imgPath) { + // 该方法不推荐使用,该方法是懒加载,图像并不加载到内存,当拿图像的宽和高时会返回-1; + // image = Toolkit.getDefaultToolkit().getImage(imgPath); + try { + // 该方法会将图像加载到内存,从而拿到图像的详细信息。 + input = new FileInputStream(imgPath); + image = ImageIO.read(input); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + setImgWidth(image.getWidth(this)); + setImgHeight(image.getHeight(this)); + } + + @Override + public void paintComponent(Graphics g1) { + int x = 0; + int y = 0; + Graphics g = g1; + if (null == image) { + return; + } + + g.drawImage(image, x, y, image.getWidth(this), image.getHeight(this), + this); + g = null; + } + + public void clear() { + if (input != null) { + try { + image = null; + input.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/handlers/BOMManagementHandler.java b/src/com/connor/jd/plm/handlers/BOMManagementHandler.java new file mode 100644 index 0000000..57e6d71 --- /dev/null +++ b/src/com/connor/jd/plm/handlers/BOMManagementHandler.java @@ -0,0 +1,22 @@ +package com.connor.jd.plm.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.jd.plm.action.BOMManagementAction; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; + +public class BOMManagementHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + BOMManagementAction action = new BOMManagementAction(AIFUtility.getActiveDesktop(), "",app); + new Thread(action).start(); + return null; + } + +} diff --git a/src/com/connor/jd/plm/table/ButtonEditor.java b/src/com/connor/jd/plm/table/ButtonEditor.java new file mode 100644 index 0000000..c1b33cd --- /dev/null +++ b/src/com/connor/jd/plm/table/ButtonEditor.java @@ -0,0 +1,54 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JOptionPane; +import javax.swing.JTable; + +import com.teamcenter.rac.util.DateButton; + +public class ButtonEditor extends DefaultCellEditor { + protected DateButton button; + private String label; + private boolean isPushed; + + public ButtonEditor(JCheckBox checkBox) { + super(checkBox); + button = new DateButton(); + + } + + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, int row, int column) { + if (isSelected) { + button.setForeground(table.getSelectionForeground()); + button.setBackground(table.getSelectionBackground()); + } else { + button.setForeground(table.getForeground()); + button.setBackground(table.getBackground()); + } + + return button; + } + + public Object getCellEditorValue() { + //yyyy年MM月dd日 + SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日"); + SimpleDateFormat format2=new SimpleDateFormat("MM月"); + SimpleDateFormat format3=new SimpleDateFormat("dd日"); + Date data = new Date(); + System.out.println("aaa===>"+format2.format(data)); + System.out.println("bbb===>"+format3.format(data)); + System.out.println("ccc===>"+format.format(data)); + + return format.format(button.getDate()); + } + +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/ButtonEditor2.java b/src/com/connor/jd/plm/table/ButtonEditor2.java new file mode 100644 index 0000000..094ec6c --- /dev/null +++ b/src/com/connor/jd/plm/table/ButtonEditor2.java @@ -0,0 +1,48 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.swing.DefaultCellEditor; +import javax.swing.JCheckBox; +import javax.swing.JTable; + +import com.teamcenter.rac.util.DateButton; + +public class ButtonEditor2 extends DefaultCellEditor { + + protected DateButton button; + private String label; + private boolean isPushed; + + public ButtonEditor2(JCheckBox checkBox) { + super(checkBox); + button = new DateButton(); + + } + + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, int row, int column) { + if (isSelected) { + button.setForeground(table.getSelectionForeground()); + button.setBackground(table.getSelectionBackground()); + } else { + button.setForeground(table.getForeground()); + button.setBackground(table.getBackground()); + } + + return button; + } + + public Object getCellEditorValue() { + //yyyy年MM月dd日 HH:mm + SimpleDateFormat format=new SimpleDateFormat("HH:mm"); + Date data = new Date(); + System.out.println("ccc===>"+format.format(data)); + + return format.format(button.getDate()); + } + + +} diff --git a/src/com/connor/jd/plm/table/CTMap.java b/src/com/connor/jd/plm/table/CTMap.java new file mode 100644 index 0000000..b32d7b0 --- /dev/null +++ b/src/com/connor/jd/plm/table/CTMap.java @@ -0,0 +1,207 @@ +package com.connor.jd.plm.table; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Point; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import javax.swing.event.TableModelEvent; +import javax.swing.table.DefaultTableModel; + +public class CTMap extends DefaultTableModel implements CellSpan { + protected int rowSize; + protected int columnSize; + protected int[][][] span; // CellSpan + + @Override + public int[] getSpan(int row, int column) { + // TODO Auto-generated method stub + if (isOutOfBounds(row, column)) { + int[] ret_code = { 1, 1 }; + return ret_code; + } + return span[row][column]; + } + + @Override + public void setSpan(int[] span, int row, int column) { + // TODO Auto-generated method stub + if (isOutOfBounds(row, column)) + return; + this.span[row][column] = span; + } + + @Override + public boolean isVisible(int row, int column) { + // TODO Auto-generated method stub + if (isOutOfBounds(row, column)) + return false; + if ((span[row][column][CellSpan.COLUMN] < 1) || (span[row][column][CellSpan.ROW] < 1)) + return false; + return true; + } + + @Override + public void combine(int[] rows, int[] columns) { + // TODO Auto-generated method stub + + int rowSpan = rows.length; + int columnSpan = columns.length; + int startRow = rows[0]; + int startColumn = columns[0]; + for (int i = 0; i < rowSpan; i++) { + for (int j = 0; j < columnSpan; j++) { + if ((span[startRow + i][startColumn + j][CellSpan.COLUMN] != 1) + || (span[startRow + i][startColumn + j][CellSpan.ROW] != 1)) { + // System.out.println("can't combine"); + return; + } + } + } + for (int i = 0, ii = 0; i < rowSpan; i++, ii--) { + for (int j = 0, jj = 0; j < columnSpan; j++, jj--) { + span[startRow + i][startColumn + j][CellSpan.COLUMN] = jj; + span[startRow + i][startColumn + j][CellSpan.ROW] = ii; + // System.out.println("r " +ii +" c " +jj); + } + } + span[startRow][startColumn][CellSpan.COLUMN] = columnSpan; + span[startRow][startColumn][CellSpan.ROW] = rowSpan; + } + + public void setSize(Dimension size) { + columnSize = size.width; + rowSize = size.height; + span = new int[rowSize][columnSize][2]; // 2: COLUMN,ROW + initValue(); + } + + protected boolean isOutOfBounds(int row, int column) { + if ((row < 0) || (rowSize <= row) || (column < 0) || (columnSize <= column)) { + return true; + } + return false; + } + + + + public void addRow() { + + Vector newData = new Vector(getColumnCount()); + dataVector.add(newData); + + // + newRowsAdded(new TableModelEvent(this, getRowCount() - 1, getRowCount() - 1, TableModelEvent.ALL_COLUMNS, + TableModelEvent.INSERT)); + int[][][] oldSpan = span; + int numRows = oldSpan.length; + int numColumns = oldSpan[0].length; + span = new int[numRows + 1][numColumns][2]; + System.arraycopy(oldSpan, 0, span, 0, numRows); + for (int i = 0; i < numColumns; i++) { + span[numRows][i][CellSpan.COLUMN] = 1; + span[numRows][i][CellSpan.ROW] = 1; + } + rowSize = span.length; + } + public void addColumn(Object columnName) { + + int[][][] oldSpan = span; + int numRows = oldSpan.length; + int numColumns = oldSpan[0].length; + span = new int[numRows][numColumns + 1][2]; + for (int i = 0; i < span.length; i++) { + for (int j = 0; j < span[0].length; j++) { + span[i][j][CellSpan.COLUMN] = 1; + span[i][j][CellSpan.ROW] = 1; + } + } + + columnSize = span[0].length; + addColumn(columnName, (Vector) null); + } + + + public void insertRow(int row) { + Vector rowData = new Vector(getColumnCount()); + + dataVector.insertElementAt(rowData, row); + System.out.println("size:" + dataVector.size()); + + // + newRowsAdded(new TableModelEvent(this, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); + int[][][] newSpan = new int[span.length + 1][span[0].length][2]; + + int numRows = span.length; + int numColumns = span[0].length; + for (int i = 0; i < newSpan.length; i++) { + if (i < row) { + for (int j = 0; j < numColumns; j++) { + newSpan[i][j][0] = span[i][j][0]; + newSpan[i][j][1] = span[i][j][1]; + } + } else if (i == row) { + for (int j = 0; j < numColumns; j++) { + newSpan[i][j][0] = 1; + newSpan[i][j][1] = 1; + } + } else { + for (int j = 0; j < numColumns; j++) { + newSpan[i][j][0] = span[i - 1][j][0]; + newSpan[i][j][1] = span[i - 1][j][1]; + } + } + } + span = newSpan; + rowSize = span.length; + } + + + public CTMap(int numRows, int numColumns) { + Vector names = new Vector(numColumns); + names.setSize(numColumns); + setColumnIdentifiers(names); + dataVector = new Vector(); + setNumRows(numRows); + setSize(new Dimension(numColumns, numRows)); + } + + protected void initValue() { + System.out.println(span.length); + for (int i = 0; i < span.length; i++) { + for (int j = 0; j < span[i].length; j++) { + span[i][j][CellSpan.COLUMN] = 1; + span[i][j][CellSpan.ROW] = 1; + } + } + } + + public void split(int row, int column) { + if (isOutOfBounds(row, column)) + return; + int columnSpan = span[row][column][CellSpan.COLUMN]; + int rowSpan = span[row][column][CellSpan.ROW]; + for (int i = 0; i < rowSpan; i++) { + for (int j = 0; j < columnSpan; j++) { + span[row + i][column + j][CellSpan.COLUMN] = 1; + span[row + i][column + j][CellSpan.ROW] = 1; + } + } + } + + public void removeCol() { + + columnIdentifiers.removeElementAt(columnIdentifiers.size()-1); + dataVector.setSize(getRowCount()); + + for (int i = 0; i < getRowCount()-1; i++) { + + ((Vector)dataVector.elementAt(i)).setSize(getColumnCount()); + } + fireTableStructureChanged(); + } +} diff --git a/src/com/connor/jd/plm/table/CTUI.java b/src/com/connor/jd/plm/table/CTUI.java new file mode 100644 index 0000000..831439d --- /dev/null +++ b/src/com/connor/jd/plm/table/CTUI.java @@ -0,0 +1,94 @@ +package com.connor.jd.plm.table; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; + +import javax.swing.JComponent; +import javax.swing.plaf.basic.BasicTableUI; +import javax.swing.table.TableCellRenderer; + +public class CTUI extends BasicTableUI { + + public void paint(Graphics g, JComponent c){ + Rectangle oldClipBounds = g.getClipBounds(); + Rectangle clipBounds = new Rectangle(oldClipBounds); + int tableWidth = table.getColumnModel().getTotalColumnWidth(); + clipBounds.width = Math.min(clipBounds.width, tableWidth); + g.setClip(clipBounds); + + int firstIndex = table.rowAtPoint(new Point(0, clipBounds.y)); + int lastIndex = table.getRowCount() - 1; + Rectangle rowRect = new Rectangle(0, 0, tableWidth, table.getRowHeight() + table.getRowMargin()); + rowRect.y = firstIndex * rowRect.height; + for (int index = firstIndex; index <= lastIndex; index++) { + if (rowRect.intersects(clipBounds)) { + // System.out.println(); // debug + // System.out.print("" + index +": "); // row + paintRow(g, index); + } + rowRect.y += rowRect.height; + } + g.setClip(oldClipBounds); + } + + private void paintRow(Graphics g, int row) { + Rectangle rect = g.getClipBounds(); + boolean drawn = false; + CellSpan cellAtt = (CellSpan) table.getModel(); + int numColumns = table.getColumnCount(); + + for (int column = 0; column < numColumns; column++) { + Rectangle cellRect = table.getCellRect(row, column, true); + + int cellRow, cellColumn; + if (cellAtt.isVisible(row, column)) { + cellRow = row; + cellColumn = column; + // System.out.print(" "+column+" "); // debug + } else { + cellRow = row + cellAtt.getSpan(row, column)[CellSpan.ROW]; + cellColumn = column + cellAtt.getSpan(row, column)[CellSpan.COLUMN]; + // System.out.print(" ("+column+")"); // debug + } + if (cellRect.intersects(rect)) { + drawn = true; + paintCell(g, cellRect, cellRow, cellColumn); + } else { + if (drawn) + break; + } + } + + } + + private void paintCell(Graphics g, Rectangle cellRect, int row, int column) { + int spacingHeight = table.getRowMargin(); + int spacingWidth = table.getColumnModel().getColumnMargin(); + + Color c = g.getColor(); + g.setColor(table.getGridColor()); + g.drawRect(cellRect.x, cellRect.y, cellRect.width - 1, cellRect.height - 1); + g.setColor(c); + + cellRect.setBounds(cellRect.x + spacingWidth / 2, cellRect.y + spacingHeight / 2, cellRect.width - spacingWidth, + cellRect.height - spacingHeight); + + if (table.isEditing() && table.getEditingRow() == row && table.getEditingColumn() == column) { + Component component = table.getEditorComponent(); + component.setBounds(cellRect); + component.validate(); + } else { + TableCellRenderer renderer = table.getCellRenderer(row, column); + Component component = table.prepareRenderer(renderer, row, column); + + if (component.getParent() == null) { + rendererPane.add(component); + } + rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y, cellRect.width, cellRect.height, + true); + } + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/CTable.java b/src/com/connor/jd/plm/table/CTable.java new file mode 100644 index 0000000..9e3923b --- /dev/null +++ b/src/com/connor/jd/plm/table/CTable.java @@ -0,0 +1,145 @@ +package com.connor.jd.plm.table; + +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableColumn; +import javax.swing.table.TableModel; + +public class CTable extends JTable { + Map map; + public CTable(TableModel model) { + super(model); + setUI(new CTUI()); + getTableHeader().setReorderingAllowed(false); + setCellSelectionEnabled(true); + setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + map=new HashMap(); + } + 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; + } + public Rectangle getCellRect(int row, int column, boolean includeSpacing) { + Rectangle sRect = super.getCellRect(row, column, includeSpacing); + if ((row < 0) || (column < 0) || (getRowCount() <= row) || (getColumnCount() <= column)) { + return sRect; + } + CellSpan cellAtt = (CellSpan) getModel(); + if (!cellAtt.isVisible(row, column)) { + int temp_row = row; + int temp_column = column; + row += cellAtt.getSpan(temp_row, temp_column)[CellSpan.ROW]; + column += cellAtt.getSpan(temp_row, temp_column)[CellSpan.COLUMN]; + } + int[] n = cellAtt.getSpan(row, column); + + int index = 0; + int columnMargin = getColumnModel().getColumnMargin(); + Rectangle cellFrame = new Rectangle(); + int aCellHeight = rowHeight + rowMargin; + cellFrame.y = row * aCellHeight; + cellFrame.height = n[CellSpan.ROW] * aCellHeight; + + Enumeration eeration = getColumnModel().getColumns(); + while (eeration.hasMoreElements()) { + TableColumn aColumn = (TableColumn) eeration.nextElement(); + cellFrame.width = aColumn.getWidth() + columnMargin; + if (index == column) + break; + cellFrame.x += cellFrame.width; + index++; + } + for (int i = 0; i < n[CellSpan.COLUMN] - 1; i++) { + TableColumn aColumn = (TableColumn) eeration.nextElement(); + cellFrame.width += aColumn.getWidth() + columnMargin; + } + + if (!includeSpacing) { + Dimension spacing = getIntercellSpacing(); + cellFrame.setBounds(cellFrame.x + spacing.width / 2, cellFrame.y + spacing.height / 2, + cellFrame.width - spacing.width, cellFrame.height - spacing.height); + } + return cellFrame; + } + + private int[] rowColumnAtPoint(Point point) { + int[] retValue = { -1, -1 }; + int row = point.y / (rowHeight + rowMargin); + if ((row < 0) || (getRowCount() <= row)) + return retValue; + int column = getColumnModel().getColumnIndexAtX(point.x); + + CellSpan cellAtt = (CellSpan) getModel(); + + if (cellAtt.isVisible(row, column)) { + retValue[CellSpan.COLUMN] = column; + retValue[CellSpan.ROW] = row; + return retValue; + } + retValue[CellSpan.COLUMN] = column + cellAtt.getSpan(row, column)[CellSpan.COLUMN]; + retValue[CellSpan.ROW] = row + cellAtt.getSpan(row, column)[CellSpan.ROW]; + return retValue; + } + + public int rowAtPoint(Point point) { + return rowColumnAtPoint(point)[CellSpan.ROW]; + } + + public int columnAtPoint(Point point) { + return rowColumnAtPoint(point)[CellSpan.COLUMN]; + } + + public void columnSelectionChanged(ListSelectionEvent e) { + repaint(); + } + + public void valueChanged(ListSelectionEvent e) { + int firstIndex = e.getFirstIndex(); + int lastIndex = e.getLastIndex(); + if (firstIndex == -1 && lastIndex == -1) { // Selection cleared. + repaint(); + } + Rectangle dirtyRegion = getCellRect(firstIndex, 0, false); + int numCoumns = getColumnCount(); + int index = firstIndex; + for (int i = 0; i < numCoumns; i++) { + dirtyRegion.add(getCellRect(index, i, false)); + } + index = lastIndex; + for (int i = 0; i < numCoumns; i++) { + dirtyRegion.add(getCellRect(index, i, false)); + } + repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height); + } + public void setCombo(int row,int col,TableCellEditor ce){ + map.put(new Point(row,col), ce); + } + public TableCellEditor getCellEditor(int row, int column){ + Point point = new Point(row,column); + if(map.containsKey(point)){ + return map.get(point); + }else{ + return super.getCellEditor(row, column); + } + } + public void setRowHeight(int row, int rowHeight) { + super.setRowHeight(row, rowHeight); + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/CTest.java b/src/com/connor/jd/plm/table/CTest.java new file mode 100644 index 0000000..465f200 --- /dev/null +++ b/src/com/connor/jd/plm/table/CTest.java @@ -0,0 +1,42 @@ +package com.connor.jd.plm.table; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JScrollPane; + +//import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +public class CTest { + static int[] rows; + static JScrollPane pane; + + public static void main(String args[]) { + final CTMap map = new CTMap(5, 5); + final CTable table = new CTable(map); + table.setDefaultRenderer(Object.class, new TableCellTextAreaRenderer()); + pane = new JScrollPane(table); + JButton button = new JButton("add"); + table.setShowGrid(false); + final JDialog dialog = new JDialog(); + dialog.setLayout(new BorderLayout()); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + table.setRowHeight(2, 50); + table.revalidate(); + table.repaint(); + + } + }); + dialog.add(pane, BorderLayout.CENTER); + dialog.add(button, BorderLayout.SOUTH); + dialog.setPreferredSize(new Dimension(500, 500)); + dialog.show(); + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/CellSpan.java b/src/com/connor/jd/plm/table/CellSpan.java new file mode 100644 index 0000000..a454f89 --- /dev/null +++ b/src/com/connor/jd/plm/table/CellSpan.java @@ -0,0 +1,14 @@ +package com.connor.jd.plm.table; + +interface CellSpan { + public final int ROW = 0; + public final int COLUMN = 1; + + public int[] getSpan(int row, int column); + public void setSpan(int[] span, int row, int column); + + public boolean isVisible(int row, int column); + + public void combine(int[] rows, int[] columns); + +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/DatePickerCellEditor.java b/src/com/connor/jd/plm/table/DatePickerCellEditor.java new file mode 100644 index 0000000..3bbf573 --- /dev/null +++ b/src/com/connor/jd/plm/table/DatePickerCellEditor.java @@ -0,0 +1,34 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.DefaultCellEditor; +import javax.swing.JTable; +import javax.swing.JTextField; + +import com.connor.jd.plm.utils.DatePickerUtil; +import com.eltima.components.ui.DatePicker; + +public class DatePickerCellEditor extends DefaultCellEditor { + + private DatePicker datePicker; + + public DatePickerCellEditor(JTextField arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + // TODO Auto-generated method stub + datePicker = DatePickerUtil.getDatePicker(null); + return datePicker; + } + + @Override + public Object getCellEditorValue() { + // TODO Auto-generated method stub + return datePicker.getText(); + } + +} diff --git a/src/com/connor/jd/plm/table/DefaultModel.java b/src/com/connor/jd/plm/table/DefaultModel.java new file mode 100644 index 0000000..d27ef16 --- /dev/null +++ b/src/com/connor/jd/plm/table/DefaultModel.java @@ -0,0 +1,100 @@ +package com.connor.jd.plm.table; + +import java.awt.Dimension; +import java.util.Vector; + +import javax.swing.table.DefaultTableModel; + +public class DefaultModel extends DefaultTableModel implements CellSpan { + protected int rowSize; + protected int columnSize; + protected int[][][] span; // CellSpan + @Override + public int[] getSpan(int row, int column) { + // TODO Auto-generated method stub + if (isOutOfBounds(row, column)) { + int[] ret_code = { 1, 1 }; + return ret_code; + } + return span[row][column]; + } + + @Override + public void setSpan(int[] span, int row, int column) { + // TODO Auto-generated method stub + if (isOutOfBounds(row, column)) + return; + this.span[row][column] = span; + } + + @Override + public boolean isVisible(int row, int column) { + // TODO Auto-generated method stub + if (isOutOfBounds(row, column)) + return false; + if ((span[row][column][CellSpan.COLUMN] < 1) || (span[row][column][CellSpan.ROW] < 1)) + return false; + return true; + } + + @Override + public void combine(int[] rows, int[] columns) { + // TODO Auto-generated method stub + int rowSpan = rows.length; + int columnSpan = columns.length; + int startRow = rows[0]; + int startColumn = columns[0]; + for (int i = 0; i < rowSpan; i++) { + for (int j = 0; j < columnSpan; j++) { + if ((span[startRow + i][startColumn + j][CellSpan.COLUMN] != 1) + || (span[startRow + i][startColumn + j][CellSpan.ROW] != 1)) { + // System.out.println("can't combine"); + return; + } + } + } + for (int i = 0, ii = 0; i < rowSpan; i++, ii--) { + for (int j = 0, jj = 0; j < columnSpan; j++, jj--) { + span[startRow + i][startColumn + j][CellSpan.COLUMN] = jj; + span[startRow + i][startColumn + j][CellSpan.ROW] = ii; + // System.out.println("r " +ii +" c " +jj); + } + } + span[startRow][startColumn][CellSpan.COLUMN] = columnSpan; + span[startRow][startColumn][CellSpan.ROW] = rowSpan; + } + + public void setSize(Dimension size) { + columnSize = size.width; + rowSize = size.height; + span = new int[rowSize][columnSize][2]; // 2: COLUMN,ROW + initValue(); + } + + protected void initValue() { + System.out.println(span.length); + for (int i = 0; i < span.length; i++) { + for (int j = 0; j < span[i].length; j++) { + span[i][j][CellSpan.COLUMN] = 1; + span[i][j][CellSpan.ROW] = 1; + } + } + } + + protected boolean isOutOfBounds(int row, int column) { + if ((row < 0) || (rowSize <= row) || (column < 0) || (columnSize <= column)) { + return true; + } + return false; + } + + public DefaultModel(int numRows, int numColumns) { + Vector names = new Vector(numColumns); + names.setSize(numColumns); + setColumnIdentifiers(names); + dataVector = new Vector(); + setNumRows(numRows); + setSize(new Dimension(numColumns, numRows)); + } + +} diff --git a/src/com/connor/jd/plm/table/JCheckPanel.java b/src/com/connor/jd/plm/table/JCheckPanel.java new file mode 100644 index 0000000..b61e4ce --- /dev/null +++ b/src/com/connor/jd/plm/table/JCheckPanel.java @@ -0,0 +1,83 @@ +package com.connor.jd.plm.table; + +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.ButtonGroup; +import javax.swing.JCheckBox; +import javax.swing.JPanel; + +public class JCheckPanel extends JPanel { + private JCheckBox[] buttons = null; + private ButtonGroup buttonGroup = new ButtonGroup(); + + public JCheckPanel(String[] text) { + super(); + buttons = new JCheckBox[text.length]; + for (int i = 0; i < text.length; i++) { + buttons[i] = new JCheckBox(text[i]); + buttons[i].setPreferredSize(new Dimension(100, 25)); + buttonGroup.add(buttons[i]); + add(buttons[i]); + } + setLayout(new FlowLayout(FlowLayout.LEFT)); + } + + public JCheckPanel(String[] text, boolean isSingle) { + buttons = new JCheckBox[text.length]; + for (int i = 0; i < text.length; i++) { + buttons[i] = new JCheckBox(text[i]); + buttons[i].setPreferredSize(new Dimension(60, 25)); + if (isSingle) { + buttonGroup.add(buttons[i]); + } + add(buttons[i]); + } + setLayout(new FlowLayout(FlowLayout.LEFT)); + } + + public JCheckBox[] getButtons() { + return buttons; + } + + public List getSelected() { + List list = new ArrayList(); + for (JCheckBox check : buttons) { + if (check.isSelected()) { + list.add(check); + } + } + return list; + } + + public String getSelectedText() { + List list = getSelected(); + if (list.size() == 0) { + return null; + } + String str = ""; + for (JCheckBox jcb : list) { + str += jcb.getText(); + str += ","; + } + return str.substring(0, str.length() - 1); + } + + public void setSelected(int index) { + buttons[index].setSelected(true); + } + + public void setSelected(String value) { + String[] arr = value.split(","); + for (int i = 0; i < arr.length; i++) { + for (int ii = 0; ii < buttons.length; ii++) { + if (buttons[ii].getText().equals(arr[i])) { + buttons[ii].setSelected(true); + break; + } + } + } + } +} diff --git a/src/com/connor/jd/plm/table/JRadioPanel.java b/src/com/connor/jd/plm/table/JRadioPanel.java new file mode 100644 index 0000000..440a761 --- /dev/null +++ b/src/com/connor/jd/plm/table/JRadioPanel.java @@ -0,0 +1,47 @@ +package com.connor.jd.plm.table; + +import java.awt.FlowLayout; + +import javax.swing.ButtonGroup; +import javax.swing.JPanel; +import javax.swing.JRadioButton; + +public class JRadioPanel extends JPanel { + private JRadioButton[] buttons = null; + private ButtonGroup buttonGroup = new ButtonGroup(); + + public JRadioPanel(String[] text) { + super(); + buttons = new JRadioButton[text.length]; + for (int i = 0; i < text.length; i++) { + buttons[i] = new JRadioButton(text[i]); + buttonGroup.add(buttons[i]); + add(buttons[i]); + } + setLayout(new FlowLayout(FlowLayout.LEFT)); + } + + public JRadioButton[] getButtons() { + return buttons; + } + + public JRadioButton getSelected() { + for (JRadioButton jb : buttons) { + if (jb.isSelected()) { + return jb; + } + } + return null; + } + + public void setSelected(int index) { + buttons[index].setSelected(true); + } + + public void setSelected(String value) { + for (int i = 0; i < buttons.length; i++) { + buttons[i].setSelected(buttons[i].getText().equals(value.trim())); + } + } + +} diff --git a/src/com/connor/jd/plm/table/MessageBox2.java b/src/com/connor/jd/plm/table/MessageBox2.java new file mode 100644 index 0000000..c7dc822 --- /dev/null +++ b/src/com/connor/jd/plm/table/MessageBox2.java @@ -0,0 +1,39 @@ +package com.connor.jd.plm.table; + +import javax.swing.JOptionPane; + +public class MessageBox2 { + + private static String Title = "提示"; + public static final int DEFAULT_OPTION = -1; + public static final int YES_NO_OPTION = 10; + public static final int YES_NO_CANCEL_OPTION = 11; + public static final int OK_CANCEL_OPTION = 12; + public static final int YES_OPTION = 0; + public static final int NO_OPTION = 1; + public static final int CANCEL_OPTION = 2; + public static final int OK_OPTION = 0; + public static final int CLOSED_OPTION = -1; + public static final int ERROR_MESSAGE = 0; + public static final int INFORMATION_MESSAGE = 1; + public static final int WARNING_MESSAGE = 2; + public static final int QUESTION_MESSAGE = 3; + public static final int PLAIN_MESSAGE = -1; + + public static int Show(String Msg, int Option) { + switch (Option) { + case YES_NO_OPTION: + case YES_NO_CANCEL_OPTION: + case OK_CANCEL_OPTION: + return JOptionPane.showConfirmDialog(null, Msg, Title, Option - 10); + default: + JOptionPane.showMessageDialog(null, Msg, Title, Option); + } + return 0; + } + + public static int Show(String Msg) { + return Show(Msg, INFORMATION_MESSAGE); + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor.java b/src/com/connor/jd/plm/table/MyCellEditor.java new file mode 100644 index 0000000..e2a6648 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor.java @@ -0,0 +1,122 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.DefaultCellEditor; +import javax.swing.JComboBox; +import javax.swing.JTable; +import javax.swing.JTextField; + +import com.teamcenter.rac.util.MessageBox; + +public class MyCellEditor extends DefaultCellEditor { + private JRadioPanel radio = null; + private JCheckPanel check = null; + private JComboBox comboBox = null; + private int type = -1; + private int row; + private int col; + private int top; + private int end; + private int bottom; + private JTable table; + + public MyCellEditor(JTextField var1) { + super(var1); + // TODO Auto-generated constructor stub + } + + public MyCellEditor(JTextField var1, int top, int end, int bottom) { + super(var1); + // TODO Auto-generated constructor stub + this.top = top; + this.end = end; + this.bottom = bottom; + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (value instanceof JRadioPanel) { + radio = (JRadioPanel) value; + type = 1; + return radio; + } else if (value instanceof JCheckPanel) { + check = (JCheckPanel) value; + type = 2; + return check; + } else if (value instanceof JComboBox) { + comboBox = (JComboBox) value; + type = 3; + return comboBox; + } + this.row = row; + this.col = column; + this.bottom = table.getRowCount() - end; + this.table = table; + type = 0; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + if (type == 1) { + return radio; + } + if (type == 2) { + return check; + } + if (type == 3) { + return comboBox; + } + + Object obj = super.getCellEditorValue(); + if (obj != null && !"".equals(obj.toString().trim()) && row >= top && row <= bottom && col >= 7 + && col < table.getColumnCount() - 3) { + try { + Double.parseDouble(obj.toString().trim()); + } catch (Exception e) { + MessageBox.post("检查数据只能输入数字", "错误", MessageBox.ERROR); + return null; + } + } + return obj; + } + + @Override + public boolean stopCellEditing() { + // TODO Auto-generated method stub + if (row >= top && row <= bottom && col >= 7 && col < table.getColumnCount() - 3) { + double min = Double.MAX_VALUE; + double max = Double.MIN_VALUE; + Object obj; + for (int i = 7; i < col; i++) { + obj = table.getValueAt(row, i); + if (obj != null && !"".equals(obj.toString().trim())) { + min = Math.min(min, Double.parseDouble(obj.toString().trim())); + max = Math.max(max, Double.parseDouble(obj.toString().trim())); + } + } + obj = getCellEditorValue(); + if (obj != null && !"".equals(obj.toString().trim())) { + min = Math.min(min, Double.parseDouble(obj.toString().trim())); + max = Math.max(max, Double.parseDouble(obj.toString().trim())); + } + for (int i = col + 1; i < table.getColumnCount() - 3; i++) { + obj = table.getValueAt(row, i); + if (obj != null && !"".equals(obj.toString().trim())) { + min = Math.min(min, Double.parseDouble(obj.toString().trim())); + max = Math.max(max, Double.parseDouble(obj.toString().trim())); + } + } + if (max > Double.MIN_VALUE) { + table.setValueAt(String.format("%.2f", min), row, table.getColumnCount() - 3); + table.setValueAt(String.format("%.2f", max), row, table.getColumnCount() - 2); + } else { + table.setValueAt("", row, table.getColumnCount() - 3); + table.setValueAt("", row, table.getColumnCount() - 2); + } + } + return super.stopCellEditing(); + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor1.java b/src/com/connor/jd/plm/table/MyCellEditor1.java new file mode 100644 index 0000000..6abc0f1 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor1.java @@ -0,0 +1,300 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.swing.DefaultCellEditor; +import javax.swing.JTable; +import javax.swing.JTextField; + +import com.teamcenter.rac.util.MessageBox; + +public class MyCellEditor1 extends DefaultCellEditor { + private int col; + private int row; + private JTable table; + private int top; + private int end; + private int bottom; + private List data; + private double low = 0.0; + private double up = 0.0; + private int cnt = 0; + private int lowCnt = 0; + private int upCnt = 0; + + public MyCellEditor1(JTextField paramJTextField) { + super(paramJTextField); + // TODO Auto-generated constructor stub + } + + public MyCellEditor1(JTextField paramJTextField, int top, int end, int bottom) { + super(paramJTextField); + // TODO Auto-generated constructor stub + this.top = top; + this.end = end; + this.bottom = bottom; + } + + public double getLow() { + return low; + } + + public void setLow(double low) { + this.low = low; + } + + public double getUp() { + return up; + } + + public void setUp(double up) { + this.up = up; + } + + public int getCnt() { + return cnt; + } + + public void setCnt(int cnt) { + this.cnt = cnt; + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + this.col = column; + this.row = row; + this.table = table; + bottom = table.getRowCount() - end; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + // TODO Auto-generated method stub + Object obj = super.getCellEditorValue(); + if (obj != null && !"".equals(obj.toString().trim()) && row >= top - 3 && row <= bottom) { + try { + Double.parseDouble(obj.toString().trim()); + } catch (Exception e) { + MessageBox.post("计算区域只能输入数字", "错误", MessageBox.ERROR); + return null; + } + } + return obj; + } + + @Override + public boolean stopCellEditing() { + // TODO Auto-generated method stub + System.out.println("top:" + top + ",end:" + end + ",bottom:" + bottom + " 重新计算列:" + col); + data = new ArrayList(); + Object now = getCellEditorValue(); + Object obj = null; + + if (row == 2) { + if (now != null && !"".equals(now.toString().trim())) { + low = Double.parseDouble(now.toString().trim()); + lowCnt = 1; + } else { + low = 0.0; + lowCnt = 0; + } + } + if (row == 3) { + if (now != null && !"".equals(now.toString().trim())) { + up = Double.parseDouble(now.toString().trim()); + upCnt = 1; + } else { + up = 0.0; + upCnt = 0; + } + } + cnt = lowCnt + upCnt; + System.out.println("lowCnt===>" + lowCnt); + System.out.println("upCnt====>" + upCnt); + for (int i = top; i < row && i <= bottom; i++) { + obj = table.getModel().getValueAt(i, col); + if (obj != null && !"".equals(obj.toString().trim())) { + data.add(Double.parseDouble(obj.toString().trim())); + } + } + if (row >= top && row <= bottom && now != null && !"".equals(now.toString().trim())) { + data.add(Double.parseDouble(now.toString().trim())); + } + if (row + 1 >= top) { + for (int i = row + 1; i <= bottom; i++) { + obj = table.getModel().getValueAt(i, col); + if (obj != null && !"".equals(obj.toString().trim())) { + data.add(Double.parseDouble(obj.toString().trim())); + } + } + } else { + for (int i = top; i <= bottom; i++) { + obj = table.getModel().getValueAt(i, col); + if (obj != null && !"".equals(obj.toString().trim())) { + data.add(Double.parseDouble(obj.toString().trim())); + } + } + } + + System.out.println(Arrays.toString(data.toArray())); + + double sum = 0; + double max = Double.MIN_VALUE; + double min = Double.MAX_VALUE; + for (Double d : data) { + sum += d; + max = Math.max(max, d); + min = Math.min(min, d); + } + if (sum != 0) { + double r = max - min; + double avg = sum / data.size(); + table.getModel().setValueAt(String.format("%.2f", min), bottom + 1, col); + table.getModel().setValueAt(String.format("%.2f", max), bottom + 2, col); + table.getModel().setValueAt(String.format("%.2f", r), bottom + 3, col); + table.getModel().setValueAt(String.format("%.2f", avg), bottom + 5, col); + if (data.size() - 1 > 0) { + double stdevSum = 0; + for (Double d : data) { + stdevSum += Math.pow(d - avg, 2); + } + double stdev = Math.sqrt(stdevSum / (data.size() - 1)); + double bar1 = avg - 3 * stdev; + double bar2 = avg + 3 * stdev; + table.getModel().setValueAt(String.format("%.2f", stdev), bottom + 4, col); + table.getModel().setValueAt(String.format("%.2f", bar1), bottom + 6, col); + table.getModel().setValueAt(String.format("%.2f", bar2), bottom + 7, col); + + double cp = 0.0; + if (cnt == 0) { + table.getModel().setValueAt("", bottom + 8, col); + } else if (cnt == 2) { + cp = (up - low) / (6 * stdev); + table.getModel().setValueAt(String.format("%.2f", cp), bottom + 8, col); + } else if (doubleIsEqual(up, 0.0)) { + cp = (avg - low) / (3 * stdev); + table.getModel().setValueAt(String.format("%.2f", cp), bottom + 8, col); + } else { + cp = (up - avg) / (3 * stdev); + table.getModel().setValueAt(String.format("%.2f", cp), bottom + 8, col); + } + double cpu = 0.0; + if (doubleIsEqual(up, 0.0)) { + table.getModel().setValueAt("", bottom + 9, col); + } else { + cpu = (up - avg) / (3 * stdev); + table.getModel().setValueAt(String.format("%.2f", cpu), bottom + 9, col); + } + double cpl = 0.0; + if (doubleIsEqual(low, 0.0)) { + table.getModel().setValueAt("", bottom + 10, col); + } else { + cpl = (avg - low) / (3 * stdev); + table.getModel().setValueAt(String.format("%.2f", cpl), bottom + 10, col); + } + double cpk = 0.0; + if (cnt == 2) { + cpk = (1 - 2 * Math.abs(((low + up) / 2 - avg)) / (up - low)) * cp; + table.getModel().setValueAt(String.format("%.2f", cpk), bottom + 11, col); + } else { + cpk = cp; + table.getModel().setValueAt(doubleIsEqual(cpk, 0.0) ? "" : String.format("%.2f", cpk), bottom + 11, + col); + } + double su = 0.0; + if (doubleIsEqual(cpu, 0.0)) { + table.getModel().setValueAt("", bottom + 12, col); + } else { + su = (1 - normSDist(cpu * 3)) * 1000000; + table.getModel().setValueAt(String.format("%.2f", su), bottom + 12, col); + } + double sl = 0.0; + if (doubleIsEqual(cpl, 0.0)) { + table.getModel().setValueAt("", bottom + 13, col); + } else { + sl = (1 - normSDist(cpl * 3)) * 1000000; + table.getModel().setValueAt(String.format("%.2f", sl), bottom + 13, col); + } + if (cnt == 0) { + table.getModel().setValueAt("", bottom + 14, col); + } else { + table.getModel().setValueAt(String.format("%.2f", su + sl), bottom + 14, col); + } + if (cnt == 0) { + table.getModel().setValueAt("", bottom + 15, col); + } else if (cpk > 1.99) { + table.getModel().setValueAt("非常好", bottom + 15, col); + } else if (cpk > 1.66) { + table.getModel().setValueAt("很好", bottom + 15, col); + } else if (cpk > 1.32) { + table.getModel().setValueAt("好", bottom + 15, col); + } else if (cpk > 0.99) { + table.getModel().setValueAt("有能力", bottom + 15, col); + } else { + table.getModel().setValueAt("能力不足", bottom + 15, col); + } + System.out.println("cp:" + cp + ",cpu:" + cpu + ",cpl:" + cpl + ",cpk:" + cpk + ",su:" + su + ",sl:" + + sl + ",ppm:" + (su + sl)); + } else { + table.getModel().setValueAt("", bottom + 4, col); + table.getModel().setValueAt("", bottom + 6, col); + table.getModel().setValueAt("", bottom + 7, col); + table.getModel().setValueAt("", bottom + 8, col); + table.getModel().setValueAt("", bottom + 9, col); + table.getModel().setValueAt("", bottom + 10, col); + table.getModel().setValueAt("", bottom + 11, col); + table.getModel().setValueAt("", bottom + 12, col); + table.getModel().setValueAt("", bottom + 13, col); + table.getModel().setValueAt("", bottom + 14, col); + table.getModel().setValueAt("", bottom + 15, col); + } + } else { + table.getModel().setValueAt("", bottom + 1, col); + table.getModel().setValueAt("", bottom + 2, col); + table.getModel().setValueAt("", bottom + 3, col); + table.getModel().setValueAt("", bottom + 5, col); + table.getModel().setValueAt("", bottom + 4, col); + table.getModel().setValueAt("", bottom + 6, col); + table.getModel().setValueAt("", bottom + 7, col); + table.getModel().setValueAt("", bottom + 8, col); + table.getModel().setValueAt("", bottom + 9, col); + table.getModel().setValueAt("", bottom + 10, col); + table.getModel().setValueAt("", bottom + 11, col); + table.getModel().setValueAt("", bottom + 12, col); + table.getModel().setValueAt("", bottom + 13, col); + table.getModel().setValueAt("", bottom + 14, col); + table.getModel().setValueAt("", bottom + 15, col); + } + return super.stopCellEditing(); + } + + private boolean doubleIsEqual(double a, double b) { + return Math.abs(a - b) < 0.000001; + } + + private double normSDist(double z) { + // this guards against overflow + if (z > 6) + return 1; + if (z < -6) + return 0; + + double gamma = 0.231641900, a1 = 0.319381530, a2 = -0.356563782, a3 = 1.781477973, a4 = -1.821255978, + a5 = 1.330274429; + + double x = Math.abs(z); + double t = 1 / (1 + gamma * x); + + double n = 1 - (1 / (Math.sqrt(2 * Math.PI)) * Math.exp(-z * z / 2)) + * (a1 * t + a2 * Math.pow(t, 2) + a3 * Math.pow(t, 3) + a4 * Math.pow(t, 4) + a5 * Math.pow(t, 5)); + if (z < 0) + return 1.0 - n; + + return n; + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor2.java b/src/com/connor/jd/plm/table/MyCellEditor2.java new file mode 100644 index 0000000..ccdef61 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor2.java @@ -0,0 +1,48 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.DefaultCellEditor; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.JTextField; + +public class MyCellEditor2 extends DefaultCellEditor { + private JLabel img = null; + private JComboBox jued = null; + private int type = -1; + + public MyCellEditor2(JTextField var1) { + super(var1); + // TODO Auto-generated constructor stub + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (value instanceof JLabel) { + img = (JLabel) value; + type = 1; + return img; + } + if (value instanceof JComboBox) { + jued = (JComboBox) value; + type = 2; + return jued; + } + type = 0; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + if (type == 1) { + return img; + } + if (type == 2) { + return jued; + } + return super.getCellEditorValue(); + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor3.java b/src/com/connor/jd/plm/table/MyCellEditor3.java new file mode 100644 index 0000000..f5b2295 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor3.java @@ -0,0 +1,39 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.DefaultCellEditor; +import javax.swing.JTable; +import javax.swing.JTextField; + +public class MyCellEditor3 extends DefaultCellEditor { + private JCheckPanel check = null; + private int type = -1; + + public MyCellEditor3(JTextField arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + // TODO Auto-generated method stub + if (value instanceof JCheckPanel) { + check = (JCheckPanel) value; + type = 1; + return check; + } + type = 0; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + // TODO Auto-generated method stub + if (type == 1) { + return check; + } + return super.getCellEditorValue(); + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor4.java b/src/com/connor/jd/plm/table/MyCellEditor4.java new file mode 100644 index 0000000..6cd3bb4 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor4.java @@ -0,0 +1,38 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.DefaultCellEditor; +import javax.swing.JCheckBox; +import javax.swing.JTable; +import javax.swing.JTextField; + +public class MyCellEditor4 extends DefaultCellEditor { + private int type = -1; + private JCheckBox check; + + public MyCellEditor4(JTextField arg0) { + super(arg0); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (value instanceof JCheckBox) { + System.out.println("123456789abcdefg"); + check = (JCheckBox) value; + type = 1; + return check; + } + type = 0; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + if (type == 1) { + return check; + } + return super.getCellEditorValue(); + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellRenderer.java b/src/com/connor/jd/plm/table/MyCellRenderer.java new file mode 100644 index 0000000..ed11b04 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellRenderer.java @@ -0,0 +1,19 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.JCheckBox; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +public class MyCellRenderer extends DefaultTableCellRenderer { + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, + int row, int column) { + // TODO Auto-generated method stub + if (value instanceof JCheckBox) { + return (JCheckBox) value; + } + return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + } +} diff --git a/src/com/connor/jd/plm/table/MyComboBoxRenderer.java b/src/com/connor/jd/plm/table/MyComboBoxRenderer.java new file mode 100644 index 0000000..d66441a --- /dev/null +++ b/src/com/connor/jd/plm/table/MyComboBoxRenderer.java @@ -0,0 +1,24 @@ +package com.connor.jd.plm.table; + +import java.awt.Color; +import java.awt.Component; + +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.SwingConstants; + +public class MyComboBoxRenderer extends JLabel implements ListCellRenderer { + public MyComboBoxRenderer() { + setOpaque(true); + } + + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, + boolean cellHasFocus) { + setBackground(isSelected ? new Color(0xff0078D7) : Color.WHITE); + setHorizontalAlignment(SwingConstants.CENTER); + setText(value.toString()); + return this; + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/TableCellTextAreaRenderer.java b/src/com/connor/jd/plm/table/TableCellTextAreaRenderer.java new file mode 100644 index 0000000..e91e9a5 --- /dev/null +++ b/src/com/connor/jd/plm/table/TableCellTextAreaRenderer.java @@ -0,0 +1,72 @@ +package com.connor.jd.plm.table; + +import java.awt.Color; +import java.awt.Component; + +import javax.swing.BorderFactory; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.table.TableCellRenderer; + +public class TableCellTextAreaRenderer extends JTextArea implements TableCellRenderer { + public TableCellTextAreaRenderer() { + setLineWrap(true); + setWrapStyleWord(true); + + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) { + // TODO Auto-generated method stub + int maxPreferredHeight = 0; + for (int i = 0; i < table.getColumnCount(); i++) { + setText("" + table.getValueAt(row, i)); + setSize(table.getColumnModel().getColumn(column).getWidth(), 0); + maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height); + } + setBackground(Color.white); + setForeground(Color.black); + if(isSelected){ + setBackground(new Color(0, 120, 215)); + setForeground(Color.white); + } + if (table.getRowHeight(row) != maxPreferredHeight) // 少了这行则处理器瞎忙 + table.setRowHeight(row, maxPreferredHeight); + + setText(value == null ? "" : value.toString()); + return this; + } + +// @Override +// public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, +// int row, int column) { +// // TODO Auto-generated method stub +// int maxPreferredHeight = 0; +// for (int i = 0; i < table.getColumnCount(); i++) { +// setText("" + table.getValueAt(row, i)); +// setSize(table.getColumnModel().getColumn(column).getWidth(), 0); +// maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height); +// } +// setBorder(BorderFactory.createLineBorder(Color.white)); +// setBackground(Color.white); +// setForeground(Color.black); +// if(isSelected){ +// setBackground(new Color(0, 120, 215)); +// setForeground(Color.white); +// } +// String val=(String) table.getValueAt(row, column); +// int w=0; +// if(val!=null){ +// w=val.length()*6/table.getColumn(table.getColumnName(column)).getWidth(); +// } +// if(w!=0){ +// //System.out.println("height:"+table.getRowHeight()*(w+1)); +// table.setRowHeight(row,table.getRowHeight()*(w+1)); +// } +// +// +// setText(value == null ? "" : value.toString()); +// return this; +// } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/TempTest.java b/src/com/connor/jd/plm/table/TempTest.java new file mode 100644 index 0000000..82c971c --- /dev/null +++ b/src/com/connor/jd/plm/table/TempTest.java @@ -0,0 +1,57 @@ +package com.connor.jd.plm.table; + +import java.awt.BorderLayout; + +import javax.swing.JButton; +import javax.swing.JDialog; + +public class TempTest { + public static void main(String[] args) { + String temp="";; + String[] name=new String[]{"设计潜在失效模式和后果分析","小试过程流程图","初始产品特殊特性清单","控制计划","小试产品验证方案","新原料开发申请表","物料信息调查表","供应商基本资料调查表","原料进料检验评定表","供应商初审评价表","原料转阶段评审表","项目开发技术思路及总结","试验配方单","小试试验操作单","常规性检测单","可靠性项目验证报告","小试配色记录单","小试试验工艺记录单","试验检测数据表","可靠性验证报告","实验性能总结报告","小试试验工艺单","小试试验安排计划表","产品研究汇总表","车间生产申请单","中试产品验证方案","注塑工艺记录表","试验料检测报告","项目发货技术评审记录表","试料前风险预判与行动计划表","客户处试料工艺记录表","客户处试料总结与分析表","小试阶段评审表"}; + String t=""; + String te=""; + String[] name2=new String[]{"原料清单","产品特殊特性清单","BOM表","中试产品验证方案","车间生产申请表","生产过程流程图","过程特殊特性清单","PFMEA","初始过程能力研究计划","生产过程确认计划","生产线平衡分析计划","中试生产工艺卡","新产品上线评审表","生产过程记录总结表","工艺设计目标分析表","中试工艺验证报告","初始过程能力研究报告","生产线平衡分析报告","中试生产过程评审表","试验性能总结报告","可靠性验证报告","技术证明书","检测报告","项目发货技术评审记录表","试料前风险预判与行动计划表","客户处试料工艺记录表","客户处试料总结与分析表","中试阶段评审表"}; + String[] name3=new String[]{"量试控制计划","量试生产工艺卡","PSW","生产过程记录总结表","工艺设计目标分析表","量试PFMEA","量试生产过程流程图","量试工艺优化计划","量试工艺优化方案及总结","客户使用稳定性分析报告","生产原料稳定性分析报告","产品质量稳定性分析报告","生产过程稳定性分析报告","量试阶段评审表"}; + for(int i=0;i props) { + String str = null; + try { + JSONArray json = JSONArray.fromObject(props);// 将java对象转换为json对象 + str = json.toString();// 将json对象转换为字符串 + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("JSON =>" + str); + return str; + } + + public static void grantReadPrivilege(TCSession tcSession, TCComponent tccomponent) { + AbstractAIFApplication app; + app = AIFUtility.getCurrentApplication(); + TCSession session; + session = (TCSession) app.getSession(); + TCPreferenceService preferenceService; + preferenceService = session.getPreferenceService(); + String account = preferenceService.getStringValue("Autocode_PriverUser_ID"); + try { + TCAccessControlService accessControlService = tcSession.getTCAccessControlService(); + TCComponentUserType type = (TCComponentUserType) tcSession.getTypeComponent("User"); + TCComponentUser user = type.find(account); + + if (user == null) { + return; + } + if (tcSession.getUser().equals(user)) { + return; + } + + String[] as2 = new String[] { "READ" }; + + if (tccomponent instanceof TCComponentItemRevision) { + TCComponentItem tempItem = ((TCComponentItemRevision) tccomponent).getItem(); + setByPass(tcSession,true); + accessControlService.grantPrivilege(tempItem, user, as2); + setByPass(tcSession,false); + + setByPass(tcSession,true); + accessControlService.grantPrivilege(tccomponent, user, as2); + setByPass(tcSession,false); + } else { + setByPass(tcSession,true); + accessControlService.grantPrivilege(tccomponent, user, as2); + setByPass(tcSession,false); + } + } catch (TCException e) { + e.printStackTrace(); + } + } + + public static void grantWritePrivilege(TCSession tcSession, TCComponent tccomponent) { + AbstractAIFApplication app; + app = AIFUtility.getCurrentApplication(); + TCSession session; + session = (TCSession) app.getSession(); + TCPreferenceService preferenceService; + preferenceService = session.getPreferenceService(); + String account = preferenceService.getStringValue("Autocode_PriverUser_ID"); + try { + TCAccessControlService accessControlService = tcSession.getTCAccessControlService(); + TCComponentUserType type = (TCComponentUserType) tcSession.getTypeComponent("User"); + + TCComponentUser user = type.find(account); + if (user == null) { + return; + } + if (tcSession.getUser().equals(user)) { + return; + } + + String[] as2 = new String[] { "READ", "WRITE", "DELETE" }; + + if (tccomponent instanceof TCComponentItemRevision) { + TCComponentItem tempItem = ((TCComponentItemRevision) tccomponent).getItem(); + setByPass(tcSession,true); + accessControlService.grantPrivilege(tempItem, user, as2); + setByPass(tcSession,false); + + setByPass(tcSession,true); + accessControlService.grantPrivilege(tccomponent, user, as2); + setByPass(tcSession,false); + } else { + setByPass(tcSession,true); + accessControlService.grantPrivilege(tccomponent, user, as2); + setByPass(tcSession,false); + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * + * @Title: setByPass + * @Description: 开启/关闭旁路 + * @param @param val 参数 + * @return void 返回类型 + * @throws + */ + public static void setByPass(TCSession session, boolean val) { + try { + TCUserService userservice = session.getUserService(); + userservice.call("Connor_open_bypass", new Object[] { val }); + System.out.println(val ? "Open Bypass" : "Close Bypass"); + } catch (Exception e) { + System.out.println("【Connor_open_bypass】命名的方法未注册有用户服务"); + } + } + + +} diff --git a/src/com/connor/jd/plm/util/Util.java b/src/com/connor/jd/plm/util/Util.java new file mode 100644 index 0000000..aab609c --- /dev/null +++ b/src/com/connor/jd/plm/util/Util.java @@ -0,0 +1,849 @@ +/** * @Title: util.java + * @Package com.connor.kwc.createBom + * @Description: TODO(用一句话描述该文件做什么) + * @author admin * @date 2023年12月18日 + * @version V1.0 + */ +package com.connor.jd.plm.util; + +import java.nio.charset.StandardCharsets; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.swing.JTree; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCAccessControlService; +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.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentICO; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentPseudoFolder; +import com.teamcenter.rac.kernel.TCComponentQuery; +import com.teamcenter.rac.kernel.TCComponentQueryType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTextService; +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.util.MessageBox; +import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException; +import com.teamcenter.services.rac.core.DataManagementService; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse; +import com.teamcenter.soa.client.model.ServiceData; + +/** + * @ClassName: util + * @Description: 工具类 + * @author hcj + * @date 2023年12月18日 + * + */ +public class Util { + public static final TCSession session; + public static final TCTextService textService; + + static { + session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + textService = session.getTextService(); + } + + /** + * + * @Title: getText + * @Description: 获取用户条目属性值 + * @param @param session + * @param @param str + * @param @return + * @param @throws Exception 参数 + * @return String 返回类型 + * @throws + */ + public static String getText(TCSession session, String str) throws Exception { + if (isEmpty(str)) { + return str; + } else { + String res = session.getTextService().getTextValue(str); + return !isEmpty(res) ? res : str; + } + } + + /** + * + * @Title: isEmpty + * @Description: 判断是否为空 + * @param @param str + * @param @return 参数 + * @return boolean 返回类型 + * @throws + */ + public static boolean isEmpty(String str) { + return str == null || "".equals(str.trim()); + } + + /** + * + * @Title: getItemById + * @Description: 根据id调用查询返回对象 + * @param @param id + * @param @return 参数 + * @return TCComponent 返回类型 + * @throws + */ + public static TCComponent getItemById(String id) { + + try { + System.out.println("用户条目:" + getText(session, "ItemID")); + // 设置查询的条件 + String[] keys = new String[] { getText(session, "ItemID") }; + // 设置查询的id值 + String[] values = new String[] { id }; + List comps = queryObject("零组件...", keys, values); + if (comps != null || comps.size() > 0) { + return comps.get(0); + } else { + MessageBox.post("根据首选项配置没有查询到对象", "错误", MessageBox.ERROR); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + /** + * + * @Title: expandAll + * @Description: 扩展或折叠指定路径下的所有节点的方法 + * @param @param tree + * @param @param parent + * @param @param expand 参数 + * @return void 返回类型 + * @throws + */ + public static void expandAll(JTree tree, TreePath parent, boolean expand) { + TreeNode node = (TreeNode) parent.getLastPathComponent(); + if (node.getChildCount() >= 0) { + for (Enumeration e = node.children(); e.hasMoreElements();) { + TreeNode n = (TreeNode) e.nextElement(); + TreePath path = parent.pathByAddingChild(n); + tree.expandPath(path); // 展开路径 + expandAll(tree, path, expand); // 递归展开其子节点 + } + } + } + + /** + * + * @Title: getRevisionPseudoFolder + * @Description: 获取伪文件夹 + * @param @param itemRev + * @param @param relation + * @param @return 参数 + * @return TCComponentPseudoFolder 返回类型 + * @throws + */ + public static TCComponentPseudoFolder getRevisionPseudoFolder(TCComponent tcComponent, String relation) { + TCComponentPseudoFolder realtionFolder = null; + try { + AIFComponentContext[] comps = tcComponent.getChildren(); + if (comps != null && comps.length > 0 && comps[0] != null) { + for (int i = 0; i < comps.length; i++) { + TCComponent comp = (TCComponent) comps[i].getComponent(); +// System.out.println("property_name:" + comp.getProperty("property_name")); + if ((comp instanceof TCComponentPseudoFolder)) { + if (comp.isTypeOf("PseudoFolder")) { + if (comp.getProperty("property_name").equalsIgnoreCase(relation)) { + realtionFolder = (TCComponentPseudoFolder) comp; + break; + } + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return realtionFolder; + } + + /** + * + * @Title: queryObject + * @Description: 调用查询方法 + * @param @param queryName + * @param @param keys + * @param @param values + * @param @return 参数 + * @return List 返回类型 + * @throws + */ + public static List queryObject(String queryName, String[] keys, String[] values) { + TCComponent[] components = null; + try { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery query = (TCComponentQuery) queryType.find(queryName); + if (query == null) { + MessageBox.post("没有找到查询:" + queryName, "错误", MessageBox.ERROR); + return null; + } + components = query.execute(keys, values); + } catch (TCException e) { + e.printStackTrace(); + } + if (components != null && components.length > 0) { + List compList = Arrays.asList(components); + return compList; + } else { + MessageBox.post("没有查询到对象", "错误", MessageBox.ERROR); + return null; + } + } + + /** + * + * @Title: getTCPropertyValue + * @Description: 获取属性的真实值 + * @param @param item + * @param @param propertyName + * @param @return 参数 + * @return Object 返回类型 + * @throws + */ + 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; + } + + /** + * 通过SOA创建ITEM对象 + * + * @param session 会话 + * @param itemID 创建对象的ID + * @param itemRev 创建对象的版本 + * @param itemType 创建对象的类型 + * @param itemName 创建对象的名称 + * @param itemDesc 创建对象的描述 + * @param unit 创建对象的单位 + */ + public static TCComponentItem createNewItemSoa1(TCSession session, String itemID, String itemRev, String itemType, + String itemName, String itemDesc, String unit) { + TCComponentItem newComp = null; + try { + DataManagementService datamanagementservice = DataManagementService.getService(session); + com.teamcenter.services.rac.core._2006_03.DataManagement.CreateItemsResponse createitemsresponse = null; + // 设置创建对象的主要属性 + com.teamcenter.services.rac.core._2006_03.DataManagement.ItemProperties aitemproperties[] = new com.teamcenter.services.rac.core._2006_03.DataManagement.ItemProperties[1]; + aitemproperties[0] = new com.teamcenter.services.rac.core._2006_03.DataManagement.ItemProperties(); + aitemproperties[0].clientId = Integer.toString(1); + aitemproperties[0].description = itemDesc; + aitemproperties[0].itemId = itemID; + aitemproperties[0].name = itemName; + aitemproperties[0].revId = itemRev; + aitemproperties[0].type = itemType; + aitemproperties[0].uom = unit; + TCComponent tccomponent1 = null; + String s1 = ""; + createitemsresponse = datamanagementservice.createItems(aitemproperties, tccomponent1, s1); + if (createitemsresponse.serviceData.sizeOfPartialErrors() == 0) { + newComp = createitemsresponse.output[0].item; + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + System.out.println("创建对象[item_id= " + itemID + " / rev =" + itemRev + " / name= " + itemName + "]失败"); + } + return newComp; + } + + /** + * 通过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 TCComponentItem createNewItemSoa2(TCSession session, String itemID, String itemRev, String itemType, + String itemName, String itemDesc, String unit, Map itemPropMap,Map itemMasterMap, + Map itemRevPropMap, Map itemRevMasterPropMap) { + TCComponentItem newComp = null; + try { + DataManagementService datamanagementservice = DataManagementService.getService(session); + com.teamcenter.services.rac.core._2006_03.DataManagement.CreateItemsResponse createitemsresponse = null; + // 设置创建对象的主要属性 + com.teamcenter.services.rac.core._2006_03.DataManagement.ItemProperties aitemproperties[] = new com.teamcenter.services.rac.core._2006_03.DataManagement.ItemProperties[1]; + aitemproperties[0] = new com.teamcenter.services.rac.core._2006_03.DataManagement.ItemProperties(); + aitemproperties[0].clientId = Integer.toString(1); + aitemproperties[0].description = itemDesc; + aitemproperties[0].itemId = itemID; + aitemproperties[0].name = itemName; + aitemproperties[0].revId = itemRev; + aitemproperties[0].type = itemType; + aitemproperties[0].uom = unit; + + ArrayList list = new ArrayList(); + // 设置item对象的扩展属性 + if (itemPropMap != null) { + com.teamcenter.services.rac.core._2006_03.DataManagement.RevisionIds revids = null; + com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes extendedattributesItem = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes(); + extendedattributesItem = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes(); + extendedattributesItem.objectType = itemType; + extendedattributesItem.attributes = itemPropMap; + list.add(extendedattributesItem); + } + // 设置itemMaster对象的扩展属性 + if (itemPropMap != null) { + com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes extendedattributesItemMaster = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes(); + extendedattributesItemMaster = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes(); + extendedattributesItemMaster.objectType = itemType + "Master"; + extendedattributesItemMaster.attributes = itemMasterMap; + list.add(extendedattributesItemMaster); + } + // 设置REV的扩展属性 + if (itemRevPropMap != null) { + com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes extendedattributesRev = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes(); + extendedattributesRev = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes(); + extendedattributesRev.objectType = itemType + "Revision"; + extendedattributesRev.attributes = itemRevPropMap; + list.add(extendedattributesRev); + } + // 设置REVMASTER的扩展属性 + if (itemRevMasterPropMap != null) { + com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes extendedattributesRevMaster = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes(); + extendedattributesRevMaster = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes(); + extendedattributesRevMaster.objectType = itemType + "RevisionMaster"; + extendedattributesRevMaster.attributes = itemRevMasterPropMap; + list.add(extendedattributesRevMaster); + } + // 添加扩展属性 + if (list.size() != 0) { + com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes extendedattributes[] = null; + extendedattributes = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes[list + .size()]; + for (int i = 0; i < list.size(); i++) { + extendedattributes[i] = list.get(i); + } + aitemproperties[0].extendedAttributes = extendedattributes; + } + TCComponent tccomponent1 = null; + String s1 = ""; + createitemsresponse = datamanagementservice.createItems(aitemproperties, tccomponent1, s1); + if (createitemsresponse.serviceData.sizeOfPartialErrors() > 0) { + System.out.println("create item failed"); + for (int i = 0; i < createitemsresponse.serviceData.sizeOfPartialErrors(); i++) { + String[] messages = createitemsresponse.serviceData.getPartialError(0).getMessages(); + for (int j = 0; j < messages.length; j++) { + System.out.println( + createitemsresponse.serviceData.getPartialError(0).getErrorValues()[j].getMessage()); + } + System.out.println(createitemsresponse.serviceData.getPartialError(0).getMessages()); + System.out.println( + createitemsresponse.serviceData.getPartialError(0).getErrorValues()[0].getMessage()); + } + + return null; + } + if (createitemsresponse.serviceData.sizeOfPartialErrors() == 0) { + newComp = createitemsresponse.output[0].item; + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + System.out.println("创建对象[item_id= " + itemID + " / rev =" + itemRev + " / name= " + itemName + "]失败"); + } + return newComp; + } + + + /** + * + * @param uomTags + * @Title: createMaterialBySOA + * @Description: TODO(这里用一句话描述这个方法的作用) + * @param @param session + * @param @param itemID + * @param @param itemRev + * @param @param itemTypeCom + * @param @param itemName + * @param @param itemDesc + * @param @param unit + * @param @param itemPropMap + * @param @param itemRevPropMap + * @param @param itemRevMasterPropMap + * @param @return + * @param @throws TCException + * @param @throws ServiceException + * @param @throws ParseException 参数 + * @return TCComponent 返回类型 + * @throws + */ + public static TCComponent createMaterialBySOA(TCSession session, String itemID, String itemRev, String itemTypeCom, + String itemName, String itemDesc, String unit, Map itemPropMap, + Map itemRevPropMap, Map itemRevMasterPropMap, Map uomTags) + throws TCException, ServiceException, ParseException { + System.out.println(itemTypeCom); + + for (Map.Entry entry : itemPropMap.entrySet()) { + System.out.println("itemPropMaps: key = " + entry.getKey() + ", value = " + entry.getValue()); + } + for (Map.Entry entry : itemRevPropMap.entrySet()) { + System.out.println("revMaps: key = " + entry.getKey() + ", value = " + entry.getValue()); + } + for (Map.Entry entry : itemRevMasterPropMap.entrySet()) { + System.out.println("revMasterMap: key = " + entry.getKey() + ", value = " + entry.getValue()); + } + DataManagementService dmService = DataManagementService.getService(session); + + Map itemPropMapTag = new HashMap<>(); + CreateInput itemInput = new CreateInput(); + if(itemPropMap.containsKey("uom_tag")){ + itemPropMapTag.put("uom_tag", uomTags.get(itemPropMap.get("uom_tag"))); + itemInput.tagProps = itemPropMapTag; + itemPropMap.remove("uom_tag"); + } + + itemInput.boName = itemTypeCom; + itemInput.stringProps = itemPropMap; + + + + CreateInput revInput = new CreateInput(); + revInput.boName = itemTypeCom + "Revision"; + revInput.stringProps = itemRevPropMap; + + CreateInput revMastInput = new CreateInput(); + revMastInput.boName = itemTypeCom + "RevisionMaster"; + revMastInput.stringProps = itemRevMasterPropMap; + + Map revMasterInfoMap = new HashMap<>(); + revMasterInfoMap.put("IMAN_master_form_rev", new CreateInput[] { revMastInput }); + revInput.compoundCreateInput = revMasterInfoMap; + + HashMap revInfoMap = new HashMap(); + revInfoMap.put("revision", new CreateInput[] { revInput }); + itemInput.compoundCreateInput = revInfoMap; + + CreateIn createin = new CreateIn(); + createin.clientId = "CreateItem"; + createin.data = itemInput; + + com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse createresponse; + createresponse = dmService.createObjects(new CreateIn[] { createin }); + if (createresponse.serviceData.sizeOfPartialErrors() > 0) { + System.out.println("create item failed"); + for (int i = 0; i < createresponse.serviceData.sizeOfPartialErrors(); i++) { + String[] messages = createresponse.serviceData.getPartialError(0).getMessages(); + for (int j = 0; j < messages.length; j++) { + System.out.println(createresponse.serviceData.getPartialError(0).getErrorValues()[j].getMessage()); + } + System.out.println(createresponse.serviceData.getPartialError(0).getMessages()); + System.out.println(createresponse.serviceData.getPartialError(0).getErrorValues()[0].getMessage()); + } + + return null; + } + TCComponent comp = null; + CreateOut cOs[] = createresponse.output; + if (cOs.length > 0) { + comp = cOs[0].objects[0]; + System.out.println("创建的对象:" + comp); + return comp; + } + return null; + } + + /** + * 将Map中的String类型的值转换为UTF-8编码 + * + * @param map 需要转换的Map对象 + * @return 转换后的Map对象,其中的String值已转换为UTF-8编码 + */ + public static Map convertValuesToUtf8(Map map) { + Map resultMap = new HashMap<>(); + for (Map.Entry entry : map.entrySet()) { + // 假设值是String类型,尝试将其转换为字节,再从字节转换为UTF-8编码的String + String key = entry.getKey(); + String value = entry.getValue(); + byte[] bytes = value.getBytes(StandardCharsets.UTF_8); // 这里假设原始字符串已经是正确的编码格式,否则解码会失败 + String utf8Value = new String(bytes, StandardCharsets.UTF_8); + resultMap.put(key, utf8Value); + } + return resultMap; + } + + /** + * + * @Title: setTCPropertyValue + * @Description: 根据对象属性类别赋值 + * @param @param item + * @param @param propertyName + * @param @param value 参数 + * @return void 返回类型 + * @throws + */ + 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.setDoubleValue((int) value); + } else { + tcProperty.setDoubleValue(Integer.parseInt(value.toString())); + } + break; + case TCProperty.PROP_string: + tcProperty.setStringValue(value.toString()); + break; + case TCProperty.PROP_long_string: + tcProperty.setStringValueArray((String[]) value); + 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(); + } + } + + /** + * + * @Title: getSXX + * @Description: 获取首选项的值 + * @param @param session + * @param @param name + * @param @return 参数 + * @return String[] 返回类型 + * @throws + */ + public static String[] getSXX(TCSession session, String name) { + String[] value = session.getPreferenceService().getStringValues(name); + if (value != null && value.length > 0) { + return value; + } else { + MessageBox.post("首选项【" + name + "】配置有误", "提示", MessageBox.ERROR); + } + return null; + } + + /** + * + * @Title: userHasPowerForCompont + * @Description: 判断用户是否对某个对象有写的权限 + * @param @param session + * @param @param component + * @param @return 参数 + * @return Boolean 返回类型 + * @throws + */ + public static Boolean userHasPowerForCompont(TCSession session, TCComponent component) { + TCAccessControlService tcAccessControlService = session.getTCAccessControlService(); + TCComponent[] user = new TCComponent[] { session.getUser(), session.getGroup(), session.getRole() }; + try { + return tcAccessControlService.checkAccessorsPrivilege(user, component, "WRITE"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + + } + + /** + * + * @Title: setByPass + * @Description: 开启/关闭旁路 + * @param @param val 参数 + * @return void 返回类型 + * @throws + */ + public static void setByPass(boolean val) { + try { + Object[] obj = new Object[1]; + obj[0] = ""; + TCUserService userservice = session.getUserService(); + if(val) { + userservice.call("Connor_set_bypass", new Object[] { obj }); + }else { + userservice.call("Connor_close_bypass", new Object[] { obj }); + } + } catch (Exception e) { + System.out.println("Connor_set_bypass或者Connor_close_bypass命名的方法未注册有用户服务"); + } + } + + /** + * + * @Title: createFolderBySOA + * @Description: 用SOA创建Folder + * @param @param folderTypeName + * @param @param folderName + * @param @return + * @param @throws Exception 参数 + * @return TCComponentFolder 返回类型 + * @throws + */ + public static TCComponentFolder createFolderBySOA(String folderTypeName, String folderName) throws Exception { + if (folderTypeName == null || "".equals(folderTypeName.trim())) { + return null; + } + CreateInput itemInput = new CreateInput(); + itemInput.boName = folderTypeName; + Map itemPropMap = new HashMap<>(); + itemPropMap.put("object_name", folderName); + itemInput.stringProps = itemPropMap; + // create info + CreateIn cI = new CreateIn(); + cI.clientId = "CreateFolder"; + cI.data = itemInput; + // service + DataManagementService service = DataManagementService.getService(session); + // create + CreateResponse resp = service.createObjects(new CreateIn[] { cI }); + throwServiceDataError(resp.serviceData); + CreateOut[] cOs = resp.output; + if (cOs.length > 0) { + for (TCComponent s : cOs[0].objects) { + if (s instanceof TCComponentFolder) { + return (TCComponentFolder) s; + } + } + } + return null; + } + + public static void throwServiceDataError(ServiceData serviceData) throws Exception { + if (serviceData.sizeOfPartialErrors() > 0) { + StringBuilder errInfo = new StringBuilder(); + for (int i = 0; i < serviceData.sizeOfPartialErrors(); i++) { + for (String msg : serviceData.getPartialError(i).getMessages()) { + errInfo.append(msg + "\n"); + } + } + // System.out.println(errInfo.toString()); + throw new Exception(errInfo.toString()); + } + } + + /** + * 获取分类属性 + * + * @param comp 当前选中的对象 + * @return 获取的订单分类属性 + * @throws TCException + */ + public String getIcoProperty(TCComponent comp, String propertyName) throws Exception { + // 发送到分类 + TCComponentICO[] icos = comp.getClassificationObjects(); + if (icos.length <= 0) { + return ""; + } + // icos[0].delete(); + // 获取分类属性 + ICSProperty[] icsProps = icos[0].getICSProperties(true); + // 获取单个分类属性 + + ICSPropertyDescription[] icsDs = icos[0].getICSPropertyDescriptors(); + + for (ICSPropertyDescription icsD : icsDs) { + // System.out.println(icsD.getName()); + if (icsD.getName().compareTo(propertyName) == 0) { + String value = ""; + for (ICSProperty icsProperty : icsProps) { + if (icsProperty.getId() == icsD.getId()) { + value = icsProperty.getValue(); + if (icsD.isKeyLOV()) { + value = getClassDisplayableValue(value, icsD); + } + return value; + } + } + } + } + return ""; + } + + /** + * 获取分类属性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; + } + + /** + * + * @Title: sendRevToClass + * @Description: 获取originRev分类发送到copyRev + * @param @param originRev + * @param @param copyRev + * @param @throws TCException 参数 + * @return void 返回类型 + * @throws + */ + private static Integer[] keys; + private static String[] vals; + private static String class_id; + private static boolean isSucceed = true; + + public static void sendRevToClass(TCComponentItemRevision originRev, TCComponentItemRevision copyRev) + throws TCException { + TCComponentICO[] icoS = originRev.getClassificationObjects(); + + int count = 0; + int count1 = 0; + for (int i = 0; i < icoS.length; i++) { + ICSProperty[] cPropS = icoS[i].getICSProperties(true); + for (int j = 0; j < cPropS.length; j++) { + count++; + } + keys = new Integer[count]; + vals = new String[count]; + for (int j = 0; j < cPropS.length; j++) { + keys[count1] = cPropS[j].getId(); + vals[count1] = cPropS[j].getValue(); + count1++; + } + break; + } + + try { + sendObjToClassficationByWebService(copyRev, keys, vals); + } catch (Exception e) { + MessageBox.post("分类库操作失败", "错误", MessageBox.ERROR); + e.printStackTrace(); + return; + } + if (isSucceed == false) { + MessageBox.post("分类库操作失败", "错误", MessageBox.ERROR); + return; + } + + } + + /** + * + * @Title: sendObjToClassficationByWebService + * @Description: 发送分类属性 + * @param @param rev + * @param @param keys + * @param @param vals 参数 + * @return void 返回类型 + * @throws + */ + public static void sendObjToClassficationByWebService(TCComponentItemRevision rev, Integer[] keys, String[] vals) { + try { + class_id = rev.getClassificationClass(); + if (!class_id.replace(" ", "").equals("")) { + + List propList = new ArrayList<>(); + for (int i = 0; i < keys.length; i++) { + ClassProperty prop = new ClassProperty(keys[i], vals[i]);// 分类属性 + propList.add(prop); + } + String json = SoaServerUtil.objectToJson(propList);// 将Java对象转换为json对象 + SoaServerUtil.grantWritePrivilege(session, rev);// 赋予写权限 + String url = session.getPreferenceService().getStringValue("Autocode_SendClassServer_URL"); + SoaServerUtil.sendToClass(rev.getUid(), class_id, json, url);// 发送到分类 + SoaServerUtil.grantReadPrivilege(session, rev);// 赋予读权限 + } + + } catch (Exception e) { + isSucceed = false; + e.printStackTrace(); + } + + } +} diff --git a/src/com/connor/jd/plm/util/package-info.java b/src/com/connor/jd/plm/util/package-info.java new file mode 100644 index 0000000..0486a92 --- /dev/null +++ b/src/com/connor/jd/plm/util/package-info.java @@ -0,0 +1 @@ +package com.connor.jd.plm.util; \ No newline at end of file diff --git a/src/com/connor/jd/plm/utils/DBConnectionUtil.java b/src/com/connor/jd/plm/utils/DBConnectionUtil.java new file mode 100644 index 0000000..328c9ef --- /dev/null +++ b/src/com/connor/jd/plm/utils/DBConnectionUtil.java @@ -0,0 +1,50 @@ +package com.connor.jd.plm.utils; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class DBConnectionUtil { + + public static Connection dbConn(TCSession session) { + Connection c = null; + try { + Class.forName("oracle.jdbc.driver.OracleDriver"); + // 要是导入驱动没有成功的话都是会出现classnotfoundException.自己看看是不是哪里错了,例如classpath这些设置 + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + try { + String[] dbSettings = JDMethodUtil.getPrefStrArray("jd2_db_settings", session); + if (dbSettings.length != 3) { + MessageBox.post("jd2_db_settings数据库连接配置错误", "错误", MessageBox.ERROR); + throw new Exception("jd2_db_settings数据库连接配置错误"); + } else { + Map settingMap = new HashMap(); + for (String s : dbSettings) { + settingMap.put(s.substring(0, s.indexOf(":")), s.substring(s.indexOf(":") + 1, s.length())); + } + System.out.println(settingMap.get("url") + settingMap.get("user") + settingMap.get("pass")); + c = DriverManager.getConnection(settingMap.get("url"), settingMap.get("user"), settingMap.get("pass")); + } +// c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:TC", name, pass); + // 连接数据的方法有四种, 这个属于最简单的,一般用网页程序 TC是你的数据库实例名称,在下载的文件test.sql中可以执行语句查看 + // "jdbc:oracle:thin:@计算机名称:监听端口:系统实例名", username, password, + // 计算机名称,要是自己不知道可以在计算机属性查知. + // 监听端口一般默认是1521, 要是改变了就看自己的监听文件listener.ora + // 系统实例名一般是默认orcl, 要是不是的话就用 select name from v$database; + // username,password,就是登陆数据库的用户名和密码. + + } catch (SQLException e) { + e.printStackTrace(); + } catch (Exception e1) { + e1.printStackTrace(); + } + return c; + } +} diff --git a/src/com/connor/jd/plm/utils/DBUtil.java b/src/com/connor/jd/plm/utils/DBUtil.java new file mode 100644 index 0000000..997eda4 --- /dev/null +++ b/src/com/connor/jd/plm/utils/DBUtil.java @@ -0,0 +1,38 @@ +package com.connor.jd.plm.utils; + +import java.util.HashMap; +import java.util.Map; + +import javax.sql.DataSource; +import javax.swing.JOptionPane; + +import com.teamcenter.rac.kernel.TCSession; + +import cn.hutool.db.ds.simple.SimpleDataSource; + +public class DBUtil { + + public static DataSource getDataSource(TCSession session) { + + Map settingMap = getDbSetting(session); + String str = settingMap.get("url") + settingMap.get("user") + settingMap.get("pass"); + DataSource dataSource = new SimpleDataSource(settingMap.get("url"), settingMap.get("user"), + settingMap.get("pass")); + return dataSource; + } + + private static Map getDbSetting(TCSession session) { + Map settingMap = null; + String[] dbSettings = JDMethodUtil.getPrefStrArray("jd2_db_settings", session); + if (dbSettings.length != 3) { + JOptionPane.showMessageDialog(null, "jd2_db_settings数据库连接配置错误", "错误", JOptionPane.ERROR); + } else { + settingMap = new HashMap(); + for (String s : dbSettings) { + settingMap.put(s.substring(0, s.indexOf(":")), s.substring(s.indexOf(":") + 1, s.length())); + } + } + return settingMap; + } + +} diff --git a/src/com/connor/jd/plm/utils/DatePickerUtil.java b/src/com/connor/jd/plm/utils/DatePickerUtil.java new file mode 100644 index 0000000..17ed2a2 --- /dev/null +++ b/src/com/connor/jd/plm/utils/DatePickerUtil.java @@ -0,0 +1,80 @@ +package com.connor.jd.plm.utils; + +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Date; +import java.util.Locale; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JOptionPane; + +import com.eltima.components.ui.DatePicker; + +public class DatePickerUtil { + public static void main(String[] args) { + + final JFrame f = new JFrame("LoL"); + f.setSize(400, 300); + f.setLocation(200, 200); + f.setLayout(null); + + final DatePicker datepick; + datepick = getDatePicker("yyyy-MM-dd hh:mm"); + + f.add(datepick); + + JButton b = new JButton("获取时间"); + b.setBounds(137, 183, 100, 30); + f.add(b); + + b.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + JOptionPane.showMessageDialog(f, "获取控件中的日期:" + datepick.getText()); + System.out.println(datepick.getValue()); + } + }); + + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + f.setVisible(true); + } + + public static DatePicker getDatePicker(String format) { + final DatePicker datepick; + // 格式 如果包含事件会出现时间选择的UI + String DefaultFormat = "yyyy-MM-dd"; + // 当前时间 + Date date = new Date(); + // 字体 + Font font = new Font("Times New Roman", Font.BOLD, 14); + + Dimension dimension = new Dimension(180, 24); + +// int[] hilightDays = { 1, 3, 5, 7 }; + +// int[] disabledDays = { 4, 6, 5, 9 }; + + datepick = new DatePicker(date, format == null ? DefaultFormat : format, font, dimension); + + datepick.setLocation(137, 83); + datepick.setBounds(137, 83, 180, 24); + // 设置一个月份中需要高亮显示的日子 +// datepick.setHightlightdays(hilightDays, Color.red); + // 设置一个月份中不需要的日子,呈灰色显示 +// datepick.setDisableddays(disabledDays); + // 设置国家 + datepick.setLocale(Locale.CHINA); + // 设置时钟面板可见 + if (format != null) { + datepick.setTimePanleVisible(true); + } else { + datepick.setTimePanleVisible(false); + } + return datepick; + } +} diff --git a/src/com/connor/jd/plm/utils/DialogUtil.java b/src/com/connor/jd/plm/utils/DialogUtil.java new file mode 100644 index 0000000..6905915 --- /dev/null +++ b/src/com/connor/jd/plm/utils/DialogUtil.java @@ -0,0 +1,288 @@ +package com.connor.jd.plm.utils; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dialog.ModalityType; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; + +import com.connor.jd.plm.dialogs.BOMManagementFrame; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; + +public class DialogUtil { + + public static TableMsg createTableMsg(String[] header, List msgContent) { + DefaultTableModel msgModel = new DefaultTableModel(header, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + // TODO Auto-generated method stub + return false; + } + }; + JTable msgTable = new JTable(msgModel); + for (int columnIndex = 0; columnIndex < msgTable.getColumnCount(); columnIndex++) { + // msgTable.getColumnModel().getColumn(columnIndex).setMinWidth(100); + msgTable.getColumnModel().getColumn(columnIndex).setPreferredWidth(200); + } + msgTable.setRowHeight(25); + msgTable.setShowGrid(false); + msgTable.setAutoscrolls(true); + msgTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + msgTable.getTableHeader().setReorderingAllowed(false); +// msgTable.getTableHeader().setVisible(false); + + for (String[] row : msgContent) { + msgModel.addRow(row); + } + + msgTable.invalidate(); + msgTable.repaint(); + JScrollPane msgPanel = new JScrollPane(msgTable); + msgPanel.setPreferredSize(new Dimension(header.length * 200, 400)); + msgPanel.setBorder(BorderFactory.createEmptyBorder()); + return new TableMsg(msgPanel, msgTable); + } + + public static JDialog createSearchAndSelectRevDialog(final BOMManagementFrame frame, final JTable paramTable, + final JCheckBox selectAll, final JButton field) { + final JDialog dialog = new JDialog(); + dialog.setTitle("搜索零组件版本"); + dialog.setSize(520, 400); + dialog.setResizable(true); + dialog.setAutoRequestFocus(true); + dialog.setAlwaysOnTop(true); + dialog.setLocationRelativeTo(frame); + dialog.setModalityType(ModalityType.APPLICATION_MODAL); + + final JPanel content = new JPanel(); + content.setLayout(null); + content.setPreferredSize(new Dimension(520, 400)); + JLabel targetLabel = new JLabel("目标"); + targetLabel.setBounds(10, 10, 50, 25); + final JTextField targetText = new JTextField(); + targetText.setText("输入要搜索的零组件ID"); + targetText.setForeground(Color.GRAY); + if (!"".equals(field.getText())) { + targetText.setText(field.getText().substring(0, field.getText().indexOf("/"))); + targetText.setForeground(Color.BLACK); + } + targetText.setBounds(20, 50, 300, 25); + final JButton searchBtn = new JButton("查找"); + searchBtn.setBounds(380, 50, 100, 25); + + String[] colDisplayNames = new String[] { "对象", "描述", "发布状态", "所有者", "组ID", "对象" }; + final DefaultTableModel model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + return false; + } + }; + final JTable table = new JTable(model); + table.getColumnModel().getColumn(0).setMinWidth(100); + table.getColumnModel().getColumn(1).setMinWidth(100); + table.getColumnModel().getColumn(2).setMinWidth(100); + table.getColumnModel().getColumn(3).setMinWidth(100); + table.getColumnModel().getColumn(4).setMinWidth(60); + table.getColumnModel().getColumn(4).setPreferredWidth(60); + TableColumnModel tcm = table.getColumnModel(); + TableColumn tc = tcm.getColumn(5); + tc.setWidth(0); + tc.setPreferredWidth(0); + tc.setMaxWidth(0); + tc.setMinWidth(0); + table.getTableHeader().getColumnModel().getColumn(5).setMaxWidth(0); + table.getTableHeader().getColumnModel().getColumn(5).setMinWidth(0); + table.setRowHeight(25); + table.setAutoscrolls(true); + table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + table.getTableHeader().setReorderingAllowed(false); + JScrollPane jsp = new JScrollPane(table); + jsp.setBounds(20, 100, 460, 200); + + JButton okBtn = new JButton("确定"); + okBtn.setBounds(140, 320, 100, 25); + JButton cancelBtn = new JButton("取消"); + cancelBtn.setBounds(260, 320, 100, 25); + + targetText.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + // TODO Auto-generated method stub + if ("".equals(targetText.getText())) { + targetText.setText("输入要搜索的零组件ID"); + targetText.setForeground(Color.GRAY); + } + } + + @Override + public void focusGained(FocusEvent e) { + // TODO Auto-generated method stub + if ("输入要搜索的零组件ID".equals(targetText.getText())) { + targetText.setText(""); + targetText.setForeground(Color.BLACK); + } + } + }); + + targetText.addKeyListener(new KeyAdapter() { + @Override + public void keyTyped(KeyEvent paramKeyEvent) { + // TODO Auto-generated method stub + super.keyTyped(paramKeyEvent); + if (paramKeyEvent.getKeyChar() == KeyEvent.VK_ENTER) { + searchBtn.doClick(); + } + } + }); + + searchBtn.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int cnt = model.getRowCount(); + for (int i = 0; i < cnt; i++) { + model.removeRow(0); + } + table.revalidate(); + table.repaint(); + String text = targetText.getText(); + System.out.println(text); + if ("输入要搜索的零组件ID".equals(text)) { + return; + } + long startTime = System.currentTimeMillis(); + TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + TCComponentItem[] items = getTarget(content, text, session); + if (items == null) { + return; + } + List tableDataList = new ArrayList(); + for (TCComponentItem item : items) { + try { + item.refresh(); + TCComponent[] comps = item.getRelatedComponents("revision_list"); + for (TCComponent comp : comps) { + String objetcString = comp.getProperty("object_string"); + TCComponent[] forms = comp.getRelatedComponents("IMAN_master_form_rev"); + String desc = ""; + if (forms.length > 0) { + desc = forms[0].getProperty("jd2_wlms"); + } + TCComponent[] statusArray = comp.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + String owningUser = comp.getProperty("owning_user"); + String groupId = comp.getProperty("owning_group"); + tableDataList.add(new Object[] { objetcString, desc, status, owningUser, groupId, comp }); + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + for (Object[] rowData : tableDataList) { + model.addRow(rowData); + } + table.revalidate(); + table.repaint(); + System.out.println("搜索结果已显示,用时" + (System.currentTimeMillis() - startTime) + "ms"); + } + }); + + okBtn.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent paramActionEvent) { + // TODO Auto-generated method stub + frame.okCallback(table, paramTable, selectAll, field); +// dialog.setVisible(false); + dialog.dispose(); + } + }); + + cancelBtn.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent paramActionEvent) { + // TODO Auto-generated method stub +// dialog.setVisible(false); + dialog.dispose(); + } + }); + + content.add(targetLabel); + content.add(targetText); + content.add(searchBtn); + content.add(jsp); + content.add(okBtn); + content.add(cancelBtn); + + dialog.add(content); + dialog.setVisible(true); + + return dialog; + } + + private static TCComponentItem[] getTarget(Component parent, String itemId, TCSession session) { + TCComponent[] comps = null; + try { + comps = session.search("Item ID", new String[] { "零组件 ID" }, new String[] { itemId }); +// TCComponentItemType type = new TCComponentItemType(); +// comps = type.findItems(itemId); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return null; + } + if (comps == null || comps.length == 0) { + JOptionPane.showMessageDialog(parent, "无效的物料编码,请确认编码是否正确", "提示", JOptionPane.WARNING_MESSAGE); + return null; + } + TCComponentItem[] items = new TCComponentItem[comps.length]; + for (int i = 0; i < comps.length; i++) { + items[i] = (TCComponentItem) comps[i]; + } + return items; + } + + public static class TableMsg { + public JScrollPane panel; + public JTable table; + + public TableMsg(JScrollPane panel, JTable table) { + super(); + this.panel = panel; + this.table = table; + } + + } +} diff --git a/src/com/connor/jd/plm/utils/ExcelInfoScanner.java b/src/com/connor/jd/plm/utils/ExcelInfoScanner.java new file mode 100644 index 0000000..11ce297 --- /dev/null +++ b/src/com/connor/jd/plm/utils/ExcelInfoScanner.java @@ -0,0 +1,47 @@ +package com.connor.jd.plm.utils; + +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import com.aspose.cells.Cells; +import com.aspose.cells.License; +import com.aspose.cells.Workbook; +import com.aspose.cells.WorksheetCollection; + +public class ExcelInfoScanner { + + public static Map getClassPropOptions(String path, String nodeName) { + Map res = new HashMap(); + try { + getLicense(); + Workbook excel = new Workbook(path); + WorksheetCollection wc = excel.getWorksheets(); + Cells cells = wc.get(0).getCells(); + for (int i = 0; i <= cells.getMaxDataRow(); i++) { + if (cells.get(i, 0).getStringValue().equals(nodeName)) { + res.put(cells.get(i, 1).getIntValue(), cells.get(i, 2).getStringValue()); + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return res; + } + + public static boolean getLicense() throws Exception { + boolean result = false; + try { + InputStream is = com.aspose.cells.Cell.class.getResourceAsStream("/com/aspose/cells/resources/license.xml"); + License aposeLic = new License(); + aposeLic.setLicense(is); + result = true; + is.close(); + } catch (Exception e) { + e.printStackTrace(System.out); + throw e; + } + return result; + } +} diff --git a/src/com/connor/jd/plm/utils/JDMethodUtil.java b/src/com/connor/jd/plm/utils/JDMethodUtil.java new file mode 100644 index 0000000..bd73a4c --- /dev/null +++ b/src/com/connor/jd/plm/utils/JDMethodUtil.java @@ -0,0 +1,45 @@ +package com.connor.jd.plm.utils; + +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; + +public class JDMethodUtil { + + public static TCPreferenceService service; + public static TCUserService userservice; + + /** + * + * + * @param prefName + * @return + */ + public static String getPrefStr(String prefName, TCSession session) { + if (service == null) { + service = session.getPreferenceService(); + } + String str = service.getString(TCPreferenceService.TC_preference_site, prefName); + if (str == null) { + str = new String(""); + } + return str; + } + + /** + * + * + * @param prefName + * @return + */ + public static String[] getPrefStrArray(String prefName, TCSession session) { + if (service == null) { + service = session.getPreferenceService(); + } + String[] strs = service.getStringArray(TCPreferenceService.TC_preference_site, prefName); + if (strs == null) { + strs = new String[] { "" }; + } + return strs; + } +} diff --git a/src/com/connor/jd/plm/utils/KeyValComboBox.java b/src/com/connor/jd/plm/utils/KeyValComboBox.java new file mode 100644 index 0000000..5659013 --- /dev/null +++ b/src/com/connor/jd/plm/utils/KeyValComboBox.java @@ -0,0 +1,96 @@ +package com.connor.jd.plm.utils; + +import java.awt.Component; +import java.util.Vector; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JComboBox; +import javax.swing.JList; + +import com.connor.jd.plm.beans.CheckBoxPo; + +public class KeyValComboBox extends JComboBox { + + public KeyValComboBox(Vector values) { + super(values); + rendererData(); // 渲染数据 + } + + public void rendererData() { + DefaultListCellRenderer render = new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, + boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof CheckBoxPo) { + CheckBoxPo po = (CheckBoxPo) value; + this.setText(po.text); + } + return this; + } + }; + this.setRenderer(render); + } + + // 修改Combox中的数据 + public void updateData(Vector values) { + setModel(new DefaultComboBoxModel(values)); + rendererData(); + } + + @Override + public void setSelectedItem(Object anObject) { // 选中text与传入的参数相同的项 + if (anObject != null) { + if (anObject instanceof CheckBoxPo) { + super.setSelectedItem(anObject); + } + if (anObject instanceof String) { + for (int index = 0; index < getItemCount(); index++) { + CheckBoxPo po = (CheckBoxPo) getItemAt(index); + if (po.text.equals(anObject.toString())) { + super.setSelectedIndex(index); + } + } + } + } else { + super.setSelectedItem(anObject); + } + } + + public void setSelectedValue(Object anObject) { // 选中value与传入的参数相同的项 + if (anObject != null) { + if (anObject instanceof CheckBoxPo) { + super.setSelectedItem(anObject); + } + if (anObject instanceof String) { + for (int index = 0; index < getItemCount(); index++) { + CheckBoxPo po = (CheckBoxPo) getItemAt(index); + if (po.value.equals(anObject.toString())) { + super.setSelectedIndex(index); + } + } + } + } else { + super.setSelectedItem(anObject); + } + } + + // 获得选中项的键值 + public Object getSelectedValue() { + if (getSelectedItem() instanceof CheckBoxPo) { + CheckBoxPo po = (CheckBoxPo) getSelectedItem(); + return po.value; + } + return (getSelectedItem() != null) ? getSelectedItem().toString() : null; + } + + // 获得选中项的显示文本 + public String getSelectedText() { + if (getSelectedItem() instanceof CheckBoxPo) { + CheckBoxPo po = (CheckBoxPo) getSelectedItem(); + return po.text; + } + return (getSelectedItem() != null) ? getSelectedItem().toString() : null; + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/utils/SimpleExcelUtil.java b/src/com/connor/jd/plm/utils/SimpleExcelUtil.java new file mode 100644 index 0000000..e975127 --- /dev/null +++ b/src/com/connor/jd/plm/utils/SimpleExcelUtil.java @@ -0,0 +1,69 @@ +package com.connor.jd.plm.utils; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import com.aspose.cells.Cells; +import com.aspose.cells.License; +import com.aspose.cells.Workbook; +import com.aspose.cells.WorksheetCollection; + +public class SimpleExcelUtil { + public static void exportExcel(String path, String[] header, List data) { + if (path == null || data == null) { + return; + } + try { + File file = new File(path); + file.createNewFile(); + + getLicense(); + + Workbook excel = new Workbook(path); + WorksheetCollection wc = excel.getWorksheets(); + Cells cells = wc.get(0).getCells(); + int rowIndex = 0; + if (header != null) { + for (int columnIndex = 0; columnIndex < header.length; columnIndex++) { + cells.get(rowIndex, columnIndex).setValue(header[columnIndex]); + } + rowIndex++; + } + for (String[] arr : data) { + for (int columnIndex = 0; columnIndex < arr.length; columnIndex++) { + cells.get(rowIndex, columnIndex).setValue(arr[columnIndex]); + } + rowIndex++; + } + excel.save(path); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static boolean getLicense() throws Exception { + boolean result = false; + try { + InputStream is = com.aspose.cells.Cell.class.getResourceAsStream("/com/aspose/cells/resources/license.xml"); + License aposeLic = new License(); + aposeLic.setLicense(is); + result = true; + is.close(); + } catch (Exception e) { + e.printStackTrace(System.out); + throw e; + } + return result; + } + + public static void main(String[] args) { + List test = new ArrayList(); + test.add(new String[] { "zzz", "xxx" }); + SimpleExcelUtil.exportExcel(System.getenv("temp") + File.separator + "xxxxxxxxxxxxxxxxxxxx.xlsx", + new String[] { "1", "2" }, test); + System.out.println(System.getenv("temp")); + } +} diff --git a/src/com/connor/jd/plm/utils/StringCreateUtil.java b/src/com/connor/jd/plm/utils/StringCreateUtil.java new file mode 100644 index 0000000..57e6a19 --- /dev/null +++ b/src/com/connor/jd/plm/utils/StringCreateUtil.java @@ -0,0 +1,21 @@ +package com.connor.jd.plm.utils; + +public class StringCreateUtil { + public static String createBlank(int num) { + StringBuilder sb = new StringBuilder(); + while (num > 0) { + sb.append(" "); + num--; + } + return sb.toString(); + } + + public static String createPoint(int num) { + StringBuilder sb = new StringBuilder(); + while (num > 0) { + sb.append("."); + num--; + } + return sb.toString(); + } +} diff --git a/src/sapconnect.properties b/src/sapconnect.properties new file mode 100644 index 0000000..e3b241b --- /dev/null +++ b/src/sapconnect.properties @@ -0,0 +1,13 @@ +#\u6D4B\u8BD5\u7CFB\u7EDF +JCO_ASHOST_STR=10.10.22.14 +JCO_SYSNR_STR=00 +JCO_CLIENT_STR=400 +JCO_USER_STR=LDIT001 +JCO_PASSWD_STR=LDIT@2022 +#JCO_ASHOST_STR=10.200.1.192 +#JCO_SYSNR_STR=00 +#JCO_CLIENT_STR=800 +#JCO_USER_STR=SAP_TC +#JCO_PASSWD_STR=Sap_RFC2020 + +