commit 0bc1e4471a8537db2ad674dd1f652fc7a84ed7c4 Author: xiongcz Date: Fri Jun 6 12:00:25 2025 +0800 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..a086418 --- /dev/null +++ b/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..1858750 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/git_toolbox_blame.xml b/.idea/git_toolbox_blame.xml new file mode 100644 index 0000000..7dc1249 --- /dev/null +++ b/.idea/git_toolbox_blame.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7da3b0e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..1d64a8f --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com.connor.ldy + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..bcdc0ef --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,51 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ldy +Bundle-SymbolicName: com.connor.ldy;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Vendor: CONNOR +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime;bundle-version="3.15.100", + com.teamcenter.rac.aifrcp;bundle-version="13000.1.0", + com.teamcenter.rac.kernel;bundle-version="13000.1.0", + com.teamcenter.rac.util;bundle-version="13000.1.0", + com.teamcenter.rac.common;bundle-version="13000.1.0", + com.teamcenter.rac.ui.views;bundle-version="13000.1.0", + TcSoaCoreRac;bundle-version="13000.1.0", + TcSoaCoreLoose;bundle-version="13000.1.0", + com.teamcenter.rac.commonclient;bundle-version="13000.1.0", + org.eclipse.core.jobs;bundle-version="3.10.200", + org.apache.poi.39;bundle-version="3.9.0" +Automatic-Module-Name: com.connor.ldy +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: ., + lib/swingx-1.6.1.jar, + lib/spire.doc-3.2.3.jar, + lib/sqljdbc4.jar, + lib/commons-net-3.5.jar, + lib/axiom-api-1.2.20.jar, + lib/axis2-kernel-1.7.8.jar, + lib/commons-logging-1.1.jar, + lib/axiom-impl-1.2.20.jar, + lib/neethi-3.0.3.jar, + lib/axis2-adb-1.7.8.jar, + lib/axis2-transport-local-1.7.8.jar, + lib/axis2-transport-http-1.7.8.jar, + lib/axis2-transport-base-1.7.8.jar, + lib/commons-beanutils-1.7.0.jar, + lib/commons-codec-1.2.jar, + lib/commons-collections-3.2.jar, + lib/commons-httpclient-3.1.jar, + lib/commons-io-2.1.jar, + lib/commons-lang-2.4.jar, + lib/commons-logging-1.1.1.jar, + lib/ezmorph-1.0.4.jar, + lib/httpcore-4.4.6.jar, + lib/woden-core-1.0M10.jar, + lib/wsdl4j-1.6.2.jar, + lib/xmlbeans-2.5.0.jar, + lib/xmlschema-core-2.2.1.jar, + lib/cn.net.connor.std.gdtex_13000.1.0.jar, + lib/json.jar, + lib/okhttp-2.7.4.jar, + lib/okio-1.13.0.jar diff --git a/SubstMacros-MSWord.wsf b/SubstMacros-MSWord.wsf new file mode 100644 index 0000000..e1d7809 --- /dev/null +++ b/SubstMacros-MSWord.wsf @@ -0,0 +1,235 @@ + + + + diff --git a/bin/com/connor/ld/processRevision/KUtil.class b/bin/com/connor/ld/processRevision/KUtil.class new file mode 100644 index 0000000..20e7608 Binary files /dev/null and b/bin/com/connor/ld/processRevision/KUtil.class differ diff --git a/bin/com/connor/ld/processRevision/ProcessRevisionCommand.class b/bin/com/connor/ld/processRevision/ProcessRevisionCommand.class new file mode 100644 index 0000000..7bbff18 Binary files /dev/null and b/bin/com/connor/ld/processRevision/ProcessRevisionCommand.class differ diff --git a/bin/com/connor/ldy/bom/DbomTransitionToEbomCommand.class b/bin/com/connor/ldy/bom/DbomTransitionToEbomCommand.class new file mode 100644 index 0000000..a32f058 Binary files /dev/null and b/bin/com/connor/ldy/bom/DbomTransitionToEbomCommand.class differ diff --git a/bin/com/connor/ldy/bom/DbomTransitionToEbomDialog.class b/bin/com/connor/ldy/bom/DbomTransitionToEbomDialog.class new file mode 100644 index 0000000..01be342 Binary files /dev/null and b/bin/com/connor/ldy/bom/DbomTransitionToEbomDialog.class differ diff --git a/bin/com/connor/ldy/bom/DbomTransitionToEbomHandler.class b/bin/com/connor/ldy/bom/DbomTransitionToEbomHandler.class new file mode 100644 index 0000000..54418a8 Binary files /dev/null and b/bin/com/connor/ldy/bom/DbomTransitionToEbomHandler.class differ diff --git a/bin/com/connor/ldy/bom/JTreeTable.class b/bin/com/connor/ldy/bom/JTreeTable.class new file mode 100644 index 0000000..ccf6811 Binary files /dev/null and b/bin/com/connor/ldy/bom/JTreeTable.class differ diff --git a/bin/com/connor/ldy/bom/JTreeTableModel.class b/bin/com/connor/ldy/bom/JTreeTableModel.class new file mode 100644 index 0000000..2eecff9 Binary files /dev/null and b/bin/com/connor/ldy/bom/JTreeTableModel.class differ diff --git a/bin/com/connor/ldy/bom/NodeBean.class b/bin/com/connor/ldy/bom/NodeBean.class new file mode 100644 index 0000000..ad1e685 Binary files /dev/null and b/bin/com/connor/ldy/bom/NodeBean.class differ diff --git a/bin/com/connor/ldy/bom/TableCellCheckboxRenderer.class b/bin/com/connor/ldy/bom/TableCellCheckboxRenderer.class new file mode 100644 index 0000000..261adb5 Binary files /dev/null and b/bin/com/connor/ldy/bom/TableCellCheckboxRenderer.class differ diff --git a/bin/com/connor/ldy/oa/OAPurchaseProcessDialog.class b/bin/com/connor/ldy/oa/OAPurchaseProcessDialog.class new file mode 100644 index 0000000..65003c2 Binary files /dev/null and b/bin/com/connor/ldy/oa/OAPurchaseProcessDialog.class differ diff --git a/bin/com/connor/ldy/oa/OAPurchaseProcessHandler.class b/bin/com/connor/ldy/oa/OAPurchaseProcessHandler.class new file mode 100644 index 0000000..c990d80 Binary files /dev/null and b/bin/com/connor/ldy/oa/OAPurchaseProcessHandler.class differ diff --git a/bin/com/connor/ldy/oa/OAPurchaseProcessOperation.class b/bin/com/connor/ldy/oa/OAPurchaseProcessOperation.class new file mode 100644 index 0000000..09971c5 Binary files /dev/null and b/bin/com/connor/ldy/oa/OAPurchaseProcessOperation.class differ diff --git a/bin/com/connor/ldy/oa/SendDocumentToMESHandler.class b/bin/com/connor/ldy/oa/SendDocumentToMESHandler.class new file mode 100644 index 0000000..ff37088 Binary files /dev/null and b/bin/com/connor/ldy/oa/SendDocumentToMESHandler.class differ diff --git a/bin/com/connor/ldy/oa/SendDocumentToMESOperation.class b/bin/com/connor/ldy/oa/SendDocumentToMESOperation.class new file mode 100644 index 0000000..8a61c8e Binary files /dev/null and b/bin/com/connor/ldy/oa/SendDocumentToMESOperation.class differ diff --git a/bin/com/connor/ldy/oa/SendECRtoOAHandler.class b/bin/com/connor/ldy/oa/SendECRtoOAHandler.class new file mode 100644 index 0000000..557e0cf Binary files /dev/null and b/bin/com/connor/ldy/oa/SendECRtoOAHandler.class differ diff --git a/bin/com/connor/ldy/oa/SendECRtoOAOperation.class b/bin/com/connor/ldy/oa/SendECRtoOAOperation.class new file mode 100644 index 0000000..618b657 Binary files /dev/null and b/bin/com/connor/ldy/oa/SendECRtoOAOperation.class differ diff --git a/bin/com/connor/ldy/process/CheckHeaderCellRenderer$1.class b/bin/com/connor/ldy/process/CheckHeaderCellRenderer$1.class new file mode 100644 index 0000000..e5687ef Binary files /dev/null and b/bin/com/connor/ldy/process/CheckHeaderCellRenderer$1.class differ diff --git a/bin/com/connor/ldy/process/CheckHeaderCellRenderer.class b/bin/com/connor/ldy/process/CheckHeaderCellRenderer.class new file mode 100644 index 0000000..f9f672a Binary files /dev/null and b/bin/com/connor/ldy/process/CheckHeaderCellRenderer.class differ diff --git a/bin/com/connor/ldy/process/CutterWordTimeHandler.class b/bin/com/connor/ldy/process/CutterWordTimeHandler.class new file mode 100644 index 0000000..321d3af Binary files /dev/null and b/bin/com/connor/ldy/process/CutterWordTimeHandler.class differ diff --git a/bin/com/connor/ldy/process/CutterWordTimeOperation.class b/bin/com/connor/ldy/process/CutterWordTimeOperation.class new file mode 100644 index 0000000..66b104c Binary files /dev/null and b/bin/com/connor/ldy/process/CutterWordTimeOperation.class differ diff --git a/bin/com/connor/ldy/process/MEOPBorrowDialog.class b/bin/com/connor/ldy/process/MEOPBorrowDialog.class new file mode 100644 index 0000000..d3acbd2 Binary files /dev/null and b/bin/com/connor/ldy/process/MEOPBorrowDialog.class differ diff --git a/bin/com/connor/ldy/process/MEOPBorrowHandler.class b/bin/com/connor/ldy/process/MEOPBorrowHandler.class new file mode 100644 index 0000000..a960e4a Binary files /dev/null and b/bin/com/connor/ldy/process/MEOPBorrowHandler.class differ diff --git a/bin/com/connor/ldy/process/MEOPReviseHandler.class b/bin/com/connor/ldy/process/MEOPReviseHandler.class new file mode 100644 index 0000000..ccbe881 Binary files /dev/null and b/bin/com/connor/ldy/process/MEOPReviseHandler.class differ diff --git a/bin/com/connor/ldy/process/MEOPReviseOperation.class b/bin/com/connor/ldy/process/MEOPReviseOperation.class new file mode 100644 index 0000000..1e72d2f Binary files /dev/null and b/bin/com/connor/ldy/process/MEOPReviseOperation.class differ diff --git a/bin/com/connor/ldy/process/ProcessBorrowDialog.class b/bin/com/connor/ldy/process/ProcessBorrowDialog.class new file mode 100644 index 0000000..8692a72 Binary files /dev/null and b/bin/com/connor/ldy/process/ProcessBorrowDialog.class differ diff --git a/bin/com/connor/ldy/process/ProcessBorrowHandler.class b/bin/com/connor/ldy/process/ProcessBorrowHandler.class new file mode 100644 index 0000000..eee8edf Binary files /dev/null and b/bin/com/connor/ldy/process/ProcessBorrowHandler.class differ diff --git a/bin/com/connor/ldy/process/ProcessBorrowOperation.class b/bin/com/connor/ldy/process/ProcessBorrowOperation.class new file mode 100644 index 0000000..092af8c Binary files /dev/null and b/bin/com/connor/ldy/process/ProcessBorrowOperation.class differ diff --git a/bin/com/connor/ldy/process/ProcessDivisionDialog.class b/bin/com/connor/ldy/process/ProcessDivisionDialog.class new file mode 100644 index 0000000..63e5d07 Binary files /dev/null and b/bin/com/connor/ldy/process/ProcessDivisionDialog.class differ diff --git a/bin/com/connor/ldy/process/ProcessDivisionHandler.class b/bin/com/connor/ldy/process/ProcessDivisionHandler.class new file mode 100644 index 0000000..be69fdc Binary files /dev/null and b/bin/com/connor/ldy/process/ProcessDivisionHandler.class differ diff --git a/bin/com/connor/ldy/process/ProcessMultiplexDialog.class b/bin/com/connor/ldy/process/ProcessMultiplexDialog.class new file mode 100644 index 0000000..a249deb Binary files /dev/null and b/bin/com/connor/ldy/process/ProcessMultiplexDialog.class differ diff --git a/bin/com/connor/ldy/process/ProcessMultiplexHandler.class b/bin/com/connor/ldy/process/ProcessMultiplexHandler.class new file mode 100644 index 0000000..389c1bd Binary files /dev/null and b/bin/com/connor/ldy/process/ProcessMultiplexHandler.class differ diff --git a/bin/com/connor/ldy/process/ProcessWordExportHandler.class b/bin/com/connor/ldy/process/ProcessWordExportHandler.class new file mode 100644 index 0000000..1e5325f Binary files /dev/null and b/bin/com/connor/ldy/process/ProcessWordExportHandler.class differ diff --git a/bin/com/connor/ldy/process/ProcessWordExportOperation.class b/bin/com/connor/ldy/process/ProcessWordExportOperation.class new file mode 100644 index 0000000..7d11a7c Binary files /dev/null and b/bin/com/connor/ldy/process/ProcessWordExportOperation.class differ diff --git a/bin/com/connor/ldy/process/test.class b/bin/com/connor/ldy/process/test.class new file mode 100644 index 0000000..b5f0ec1 Binary files /dev/null and b/bin/com/connor/ldy/process/test.class differ diff --git a/bin/com/connor/ldy/util/FTPTools.class b/bin/com/connor/ldy/util/FTPTools.class new file mode 100644 index 0000000..641ff64 Binary files /dev/null and b/bin/com/connor/ldy/util/FTPTools.class differ diff --git a/bin/com/connor/ldy/util/SelectUserDialog$DeleteListRenderer.class b/bin/com/connor/ldy/util/SelectUserDialog$DeleteListRenderer.class new file mode 100644 index 0000000..e7d063b Binary files /dev/null and b/bin/com/connor/ldy/util/SelectUserDialog$DeleteListRenderer.class differ diff --git a/bin/com/connor/ldy/util/SelectUserDialog.class b/bin/com/connor/ldy/util/SelectUserDialog.class new file mode 100644 index 0000000..6037ba1 Binary files /dev/null and b/bin/com/connor/ldy/util/SelectUserDialog.class differ diff --git a/bin/com/connor/ldy/util/SqlUtil.class b/bin/com/connor/ldy/util/SqlUtil.class new file mode 100644 index 0000000..d0f73f2 Binary files /dev/null and b/bin/com/connor/ldy/util/SqlUtil.class differ diff --git a/bin/com/connor/ldy/util/TCUtil.class b/bin/com/connor/ldy/util/TCUtil.class new file mode 100644 index 0000000..e89bc37 Binary files /dev/null and b/bin/com/connor/ldy/util/TCUtil.class differ diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..45602ef --- /dev/null +++ b/build.properties @@ -0,0 +1,36 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + lib/swingx-1.6.1.jar,\ + lib/spire.doc-3.2.3.jar,\ + lib/sqljdbc4.jar,\ + lib/commons-net-3.5.jar,\ + lib/axiom-api-1.2.20.jar,\ + lib/axis2-kernel-1.7.8.jar,\ + lib/commons-logging-1.1.jar,\ + lib/axiom-impl-1.2.20.jar,\ + lib/neethi-3.0.3.jar,\ + lib/axis2-adb-1.7.8.jar,\ + lib/axis2-transport-local-1.7.8.jar,\ + lib/axis2-transport-http-1.7.8.jar,\ + lib/axis2-transport-base-1.7.8.jar,\ + lib/commons-beanutils-1.7.0.jar,\ + lib/commons-codec-1.2.jar,\ + lib/commons-collections-3.2.jar,\ + lib/commons-httpclient-3.1.jar,\ + lib/commons-io-2.1.jar,\ + lib/commons-lang-2.4.jar,\ + lib/commons-logging-1.1.1.jar,\ + lib/ezmorph-1.0.4.jar,\ + lib/httpcore-4.4.6.jar,\ + lib/woden-core-1.0M10.jar,\ + lib/wsdl4j-1.6.2.jar,\ + lib/xmlbeans-2.5.0.jar,\ + lib/xmlschema-core-2.2.1.jar,\ + lib/cn.net.connor.std.gdtex_13000.1.0.jar,\ + lib/json.jar,\ + lib/okhttp-2.7.4.jar,\ + lib/okio-1.13.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/SPIDERIntegration.jar b/lib/SPIDERIntegration.jar new file mode 100644 index 0000000..73d7025 Binary files /dev/null and b/lib/SPIDERIntegration.jar differ diff --git a/lib/axiom-api-1.2.20.jar b/lib/axiom-api-1.2.20.jar new file mode 100644 index 0000000..c7fca6c Binary files /dev/null and b/lib/axiom-api-1.2.20.jar differ diff --git a/lib/axiom-impl-1.2.20.jar b/lib/axiom-impl-1.2.20.jar new file mode 100644 index 0000000..2fd9d43 Binary files /dev/null and b/lib/axiom-impl-1.2.20.jar differ diff --git a/lib/axis2-adb-1.7.8.jar b/lib/axis2-adb-1.7.8.jar new file mode 100644 index 0000000..39459cd Binary files /dev/null and b/lib/axis2-adb-1.7.8.jar differ diff --git a/lib/axis2-kernel-1.7.8.jar b/lib/axis2-kernel-1.7.8.jar new file mode 100644 index 0000000..13eeb69 Binary files /dev/null and b/lib/axis2-kernel-1.7.8.jar differ diff --git a/lib/axis2-transport-base-1.7.8.jar b/lib/axis2-transport-base-1.7.8.jar new file mode 100644 index 0000000..f109cd3 Binary files /dev/null and b/lib/axis2-transport-base-1.7.8.jar differ diff --git a/lib/axis2-transport-http-1.7.8.jar b/lib/axis2-transport-http-1.7.8.jar new file mode 100644 index 0000000..d34c116 Binary files /dev/null and b/lib/axis2-transport-http-1.7.8.jar differ diff --git a/lib/axis2-transport-local-1.7.8.jar b/lib/axis2-transport-local-1.7.8.jar new file mode 100644 index 0000000..817280c Binary files /dev/null and b/lib/axis2-transport-local-1.7.8.jar differ diff --git a/lib/classes12.jar b/lib/classes12.jar new file mode 100644 index 0000000..9eaf0b4 Binary files /dev/null and b/lib/classes12.jar differ diff --git a/lib/cn.net.connor.std.gdtex_13000.1.0.jar b/lib/cn.net.connor.std.gdtex_13000.1.0.jar new file mode 100644 index 0000000..26b8448 Binary files /dev/null and b/lib/cn.net.connor.std.gdtex_13000.1.0.jar differ diff --git a/lib/com.kostech.DesignChickList_1.0.0.0.jar b/lib/com.kostech.DesignChickList_1.0.0.0.jar new file mode 100644 index 0000000..bd9294f Binary files /dev/null and b/lib/com.kostech.DesignChickList_1.0.0.0.jar differ diff --git a/lib/commons-beanutils-1.7.0.jar b/lib/commons-beanutils-1.7.0.jar new file mode 100644 index 0000000..b1b89c9 Binary files /dev/null and b/lib/commons-beanutils-1.7.0.jar differ diff --git a/lib/commons-codec-1.2.jar b/lib/commons-codec-1.2.jar new file mode 100644 index 0000000..67cb720 Binary files /dev/null and b/lib/commons-codec-1.2.jar differ diff --git a/lib/commons-collections-3.2.jar b/lib/commons-collections-3.2.jar new file mode 100644 index 0000000..75580be Binary files /dev/null and b/lib/commons-collections-3.2.jar differ diff --git a/lib/commons-httpclient-3.1.jar b/lib/commons-httpclient-3.1.jar new file mode 100644 index 0000000..7c59774 Binary files /dev/null and b/lib/commons-httpclient-3.1.jar differ diff --git a/lib/commons-io-2.1.jar b/lib/commons-io-2.1.jar new file mode 100644 index 0000000..b5c7d69 Binary files /dev/null and b/lib/commons-io-2.1.jar differ diff --git a/lib/commons-lang-2.4.jar b/lib/commons-lang-2.4.jar new file mode 100644 index 0000000..532939e Binary files /dev/null and b/lib/commons-lang-2.4.jar differ diff --git a/lib/commons-logging-1.1.1.jar b/lib/commons-logging-1.1.1.jar new file mode 100644 index 0000000..1deef14 Binary files /dev/null and b/lib/commons-logging-1.1.1.jar differ diff --git a/lib/commons-logging-1.1.jar b/lib/commons-logging-1.1.jar new file mode 100644 index 0000000..2ff9bbd Binary files /dev/null and b/lib/commons-logging-1.1.jar differ diff --git a/lib/commons-net-3.5.jar b/lib/commons-net-3.5.jar new file mode 100644 index 0000000..d50e36f Binary files /dev/null and b/lib/commons-net-3.5.jar differ diff --git a/lib/dom4j-1.6.1.jar b/lib/dom4j-1.6.1.jar new file mode 100644 index 0000000..c8c4dbb Binary files /dev/null and b/lib/dom4j-1.6.1.jar differ diff --git a/lib/ezmorph-1.0.4.jar b/lib/ezmorph-1.0.4.jar new file mode 100644 index 0000000..7625af6 Binary files /dev/null and b/lib/ezmorph-1.0.4.jar differ diff --git a/lib/httpcore-4.4.6.jar b/lib/httpcore-4.4.6.jar new file mode 100644 index 0000000..16ed0d1 Binary files /dev/null and b/lib/httpcore-4.4.6.jar differ diff --git a/lib/jdom.jar b/lib/jdom.jar new file mode 100644 index 0000000..65a1b3f Binary files /dev/null and b/lib/jdom.jar differ diff --git a/lib/jfxrt.jar b/lib/jfxrt.jar new file mode 100644 index 0000000..cfe922d Binary files /dev/null and b/lib/jfxrt.jar differ diff --git a/lib/jfxswt.jar b/lib/jfxswt.jar new file mode 100644 index 0000000..2c5c7f1 Binary files /dev/null and b/lib/jfxswt.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/json-lib-2.2.3-jdk13.jar b/lib/json-lib-2.2.3-jdk13.jar new file mode 100644 index 0000000..a6513db Binary files /dev/null and b/lib/json-lib-2.2.3-jdk13.jar differ diff --git a/lib/json.jar b/lib/json.jar new file mode 100644 index 0000000..592f08c Binary files /dev/null and b/lib/json.jar differ diff --git a/lib/log4j-1.2.15.jar b/lib/log4j-1.2.15.jar new file mode 100644 index 0000000..c930a6a Binary files /dev/null and b/lib/log4j-1.2.15.jar differ diff --git a/lib/neethi-3.0.3.jar b/lib/neethi-3.0.3.jar new file mode 100644 index 0000000..38b77ff Binary files /dev/null and b/lib/neethi-3.0.3.jar differ diff --git a/lib/ojdbc6.jar b/lib/ojdbc6.jar new file mode 100644 index 0000000..c14cac4 Binary files /dev/null and b/lib/ojdbc6.jar differ diff --git a/lib/okhttp-2.7.4.jar b/lib/okhttp-2.7.4.jar new file mode 100644 index 0000000..be7249f Binary files /dev/null and b/lib/okhttp-2.7.4.jar differ diff --git a/lib/okio-1.13.0.jar b/lib/okio-1.13.0.jar new file mode 100644 index 0000000..02c302f Binary files /dev/null and b/lib/okio-1.13.0.jar differ diff --git a/lib/soap-2.1.jar b/lib/soap-2.1.jar new file mode 100644 index 0000000..744ec3c Binary files /dev/null and b/lib/soap-2.1.jar differ diff --git a/lib/spire.doc-3.2.3.jar b/lib/spire.doc-3.2.3.jar new file mode 100644 index 0000000..749d809 Binary files /dev/null and b/lib/spire.doc-3.2.3.jar differ diff --git a/lib/sqljdbc4.jar b/lib/sqljdbc4.jar new file mode 100644 index 0000000..d6b7f6d Binary files /dev/null and b/lib/sqljdbc4.jar differ diff --git a/lib/swingx-1.6.1.jar b/lib/swingx-1.6.1.jar new file mode 100644 index 0000000..b0bcc87 Binary files /dev/null and b/lib/swingx-1.6.1.jar differ diff --git a/lib/woden-core-1.0M10.jar b/lib/woden-core-1.0M10.jar new file mode 100644 index 0000000..9777ad9 Binary files /dev/null and b/lib/woden-core-1.0M10.jar differ diff --git a/lib/wsdl4j-1.6.2.jar b/lib/wsdl4j-1.6.2.jar new file mode 100644 index 0000000..b9ffc36 Binary files /dev/null and b/lib/wsdl4j-1.6.2.jar differ diff --git a/lib/xmlbeans-2.5.0.jar b/lib/xmlbeans-2.5.0.jar new file mode 100644 index 0000000..c368fb2 Binary files /dev/null and b/lib/xmlbeans-2.5.0.jar differ diff --git a/lib/xmlschema-core-2.2.1.jar b/lib/xmlschema-core-2.2.1.jar new file mode 100644 index 0000000..cab69fd Binary files /dev/null and b/lib/xmlschema-core-2.2.1.jar differ diff --git a/plugin - 副本.xml b/plugin - 副本.xml new file mode 100644 index 0000000..cca8b83 --- /dev/null +++ b/plugin - 副本.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..8d33ec4 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/connor/ld/processRevision/KUtil.java b/src/com/connor/ld/processRevision/KUtil.java new file mode 100644 index 0000000..bf603f6 --- /dev/null +++ b/src/com/connor/ld/processRevision/KUtil.java @@ -0,0 +1,54 @@ +/** * @Title: KUtil.java + * @Package com.connor.ld.sendMesJc + * @Description: TODO(һ仰ļʲô) + * @author admin * @date 20231219 + * @version V1.0 + */ +package com.connor.ld.processRevision; + +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; + +/** + * @ClassName: KUtil + * @Description: TODO + * @author hcj + * @date 20231219 + * + */ +public class KUtil { + /** + * + * @Title: setByPass + * @Description: · + * @param @param session + * @param @param val + * @return void + * @throws + */ + public static void setByPass(TCSession session, boolean val) { + try { + TCUserService userservice = session.getUserService(); + userservice.call(val ? "CONNOR_open_bypass" : "CONNOR_close_bypass", new Object[] { "" }); + System.out.println(val ? "Open Bypass" : "Close Bypass"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static boolean isTCM(TCComponent comp) throws TCException { + if (comp == null) { + return false; + } + // System.out.println("comp:"+comp); + TCComponent tcms[] = comp.getRelatedComponents("release_status_list"); + + if (tcms.length > 0) { + return true; + } + return false; + } + +} diff --git a/src/com/connor/ld/processRevision/ProcessRevisionCommand.java b/src/com/connor/ld/processRevision/ProcessRevisionCommand.java new file mode 100644 index 0000000..b459d5f --- /dev/null +++ b/src/com/connor/ld/processRevision/ProcessRevisionCommand.java @@ -0,0 +1,164 @@ +/** * @Title: ProcessRevisionCommand.java + * @Package com.connor.ld.processRevision + * @Description: TODO(һ仰ļʲô) + * @author admin * @date 2024531 + * @version V1.0 + */ +package com.connor.ld.processRevision; + +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.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +/** + * @ClassName: ProcessRevisionCommand + * @Description: ޶ + * @author hcj + * @date 2024531 + * + */ +public class ProcessRevisionCommand extends AbstractHandler { + private TCSession session; + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + new Thread() { + @Override + public void run() { + // ȡtcǰѡIJ + InterfaceAIFComponent target = app.getTargetComponent(); + TCComponentItemRevision revision = null; + if (target instanceof TCComponentItemRevision) { + revision = (TCComponentItemRevision) target; + } else if (target instanceof TCComponentBOMLine) { + try { + revision = ((TCComponentBOMLine) target).getItemRevision(); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + MessageBox.post("ѡ汾", "ʾ", MessageBox.INFORMATION); + return; + } + String type = revision.getType(); + System.out.println("type:" + type); + if ("LD6_MEOPRevision".equals(type)) { + // жǷΪӹ + try { + String property = revision.getProperty("ld6_MEprocessType"); + if ("ӹ".equals(property)) { + // жϹĹǷȫ + String processIsRelease = processIsRelease(revision); + if (processIsRelease!=null) { + MessageBox.post("޶¹·ߣ"+processIsRelease, "ʾ", MessageBox.INFORMATION); + return; + } + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // ʼ + try { + revise(revision); + MessageBox.post("޶ɹ", "ʾ", MessageBox.INFORMATION); + return; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + MessageBox.post("޶ʧܣ"+e.getMessage(), "ʾ", MessageBox.INFORMATION); + return; + } + + } else { + MessageBox.post("ѡ汾", "ʾ", MessageBox.INFORMATION); + return; + } + + }; + }.start(); + return null; + } + + /** + * @Title: revise + * @Description: TODO(һ仰) + * @param @param revision + * @return void + * @throws TCException + * @throws + */ + protected void revise(TCComponentItemRevision revision) throws TCException { + // TODO Auto-generated method stub + //· + KUtil.setByPass(session, true); + revision.saveAs(null); + //· + KUtil.setByPass(session, false); + } + + /** + * @Title: revise + * @Description: жϹĹǷȫ + * @param @param revision + * @return void + * @throws TCException + * @throws + */ + protected String processIsRelease(TCComponentItemRevision revision) throws TCException { + // TODO Auto-generated method stub + TCComponent[] whereUsed = revision.whereUsed((short) 0); + String err = ""; + List idList = new ArrayList(); + for(TCComponent component : whereUsed) { + if(component instanceof TCComponentItemRevision) { + TCComponentItemRevision rev = (TCComponentItemRevision)component; + String type = rev.getStringProperty("object_type"); + if("LD6_MEProcessCrRevision".equals(type) || "LD6_LSMEProcessRevision".equals(type)) { + TCComponentItemRevision latestItemRevision = rev.getItem().getLatestItemRevision(); + if(idList.size()>0 && idList.contains(latestItemRevision.getStringProperty("item_id"))) { + continue; + } + idList.add(latestItemRevision.getStringProperty("item_id")); + //жǷ񷢲 + if(isTCM(latestItemRevision)) { + err += latestItemRevision.getStringProperty("item_id")+";"; + } + } + } + } + if(!err.isEmpty()) { + return err; + } + return null; + } + + public boolean isTCM(TCComponent comp) throws TCException { + if (comp == null) { + return false; + } + // System.out.println("comp:"+comp); + TCComponent tcms[] = comp.getRelatedComponents("release_status_list"); + + if (tcms.length > 0) { + return true; + } + return false; + } + +} diff --git a/src/com/connor/ldy/bom/DbomTransitionToEbomCommand.java b/src/com/connor/ldy/bom/DbomTransitionToEbomCommand.java new file mode 100644 index 0000000..225946a --- /dev/null +++ b/src/com/connor/ldy/bom/DbomTransitionToEbomCommand.java @@ -0,0 +1,271 @@ +package com.connor.ldy.bom; + +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; + +import com.teamcenter.rac.aif.AbstractAIFCommand; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItem; +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; + +public class DbomTransitionToEbomCommand extends AbstractAIFCommand { + + private InterfaceAIFComponent comp; + private TCSession session; + private TCComponentBOMLine bomLine = null; + private boolean flag=true; + private String topRelease ="";//bomϵµĶǷȫڹУлѷ + + public DbomTransitionToEbomCommand(InterfaceAIFComponent comp, TCSession session) { + // Auto-generated constructor stub + System.out.println("DbomTransitionToEbomCommand"); + this.comp = comp; + this.session = session; + } + + @Override + public void executeModal() throws Exception { + // Auto-generated method stub +// TCComponentType compType = session.getTypeComponent("ML8_Washing"); +// String[] allProperties=compType.getPropertyNames();//ȡ + //TCProperty[] allProperties=compType.getPropertyNames();//ȡ + //System.out.println(tCComponents.length); + //ȡѡеĶ + if(!(comp instanceof TCComponentBOMLine)) + { + MessageBox.post("ڽṹѡBOMLine", "", MessageBox.ERROR); + return; + } + //System.out.println("11111111111"); + bomLine = (TCComponentBOMLine) comp; + if(bomLine.getChildrenCount() <= 0) + { + MessageBox.post("ӼDBOMEBOM", "", MessageBox.ERROR); + return; + } + //ж϶ + TCComponentItem item = bomLine.getItem(); + System.out.println(item.getType()); +// if(!item.getType().equals("ML8_Design")) +// { +// MessageBox.post("ѡƶ", "", MessageBox.ERROR); +// return; +// } + //final List> bomPropertyList = this.getBomPropertys(session, bomLine); + + + final DefaultMutableTreeTableNode node = this.getBomPropertyToNode(session, bomLine); + //flag=true;//̬ҪΪtrue +// if(!topRelease.equals("")) { +// MessageBox.post(topRelease+"ڹ", "", MessageBox.ERROR); +// return; +// } + + new Thread() { + @Override + public void run() { + new DbomTransitionToEbomDialog(comp, session,node,topRelease); + } + }.start(); + super.executeModal(); + } + + /** + * ȡBOM + * @throws TCException + */ + public DefaultMutableTreeTableNode getBomPropertyToNode(TCSession session, TCComponentBOMLine topBomLine) throws TCException { + // Auto-generated method stub + + NodeBean nodeBean = new NodeBean(); + + //String ss = subline.getStringProperty("bl_indented_title"); + //ID + nodeBean.setDbom(""); + nodeBean.setEbom(""); + nodeBean.setEbomId(""); + nodeBean.setNum(""); + nodeBean.setLabel(""); + nodeBean.setRefreshStatus(""); + nodeBean.setParentString(""); + + DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode(nodeBean); + //ȡBOM + try { + //getRepresentationPropertysToNode(topBomLine, rootNode, ""); + getBomPropertysToNode(topBomLine, rootNode, ""); + return rootNode; + } catch (Exception e) { + // : handle exception + e.printStackTrace(); + } + return null; + } + /*** + * ȡʾµĶ + * @param bomLine + * @param rootNode + * @param parentID + * @throws TCException + */ + public void getRepresentationPropertysToNode(TCComponentBOMLine bomLine, DefaultMutableTreeTableNode rootNode,String parentID,String quantity) throws TCException + { + TCComponentItemRevision itemRevision = bomLine.getItemRevision(); + + //ȡʾϵµĶ + TCComponent[] tcComponents = itemRevision.getReferenceListProperty("representation_for"); + if(flag && tcComponents.length<=0) { + topRelease += "bomϵ޶"; + } + for (TCComponent tcComponent : tcComponents) { + + TCProperty refreshStatusProperty = tcComponent.getTCProperty("release_status_list"); + TCComponent[] refreshStatus = refreshStatusProperty.getReferenceValueArray(); + TCProperty processProperty = tcComponent.getTCProperty("process_stage_list"); + TCComponent[] processStage = processProperty.getReferenceValueArray(); + + NodeBean nodeBean = new NodeBean(); + + nodeBean.setDbom(""); + nodeBean.setEbom(tcComponent.getStringProperty("object_string")); + nodeBean.setEbomId(tcComponent.getStringProperty("item_id")); + nodeBean.setEbomDesc(tcComponent.getStringProperty("ml8_StdDesc")); + nodeBean.setNum(quantity); + nodeBean.setLabel("0"); + if(processStage.length > 0) { + nodeBean.setRefreshStatus(""); + if(flag) { + System.out.println("topRelease += \"\""); + topRelease += ""; + } + } + if(refreshStatus.length > 0) { + StringBuffer stringBuffer = new StringBuffer(); + //ӷ״̬ + for (int i = 0; i < refreshStatus.length; i++) { + stringBuffer.append(refreshStatus[i].toString()); + if(i < refreshStatus.length - 1) + { + stringBuffer.append(","); + } + } + nodeBean.setRefreshStatus(stringBuffer.toString()); + } else { + nodeBean.setRefreshStatus(""); + } + //+++ֻж϶bomµĶǷлѷ + if(flag) { + String status = nodeBean.getRefreshStatus(); + if(!status.isEmpty() && !status.contains("Է")) { + topRelease+=nodeBean.getEbomId();//ID + topRelease+="-";//ID + topRelease+=tcComponent.getStringProperty("current_revision_id");//汾 + topRelease+="-";//ID + topRelease+=tcComponent.getStringProperty("object_name");// + topRelease+=";"; + } + } + //+++ + nodeBean.setParentString(itemRevision.getStringProperty("object_string")); + + DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(nodeBean); + rootNode.add(node); + + if(tcComponents.length == 1) { +// if(getTopRefresh(node)) +// { +// nodeBean.setLabel("0"); +// } +// else +// { +// nodeBean.setLabel("1"); +// } + nodeBean.setLabel("1"); + } + } + } + /*** + * жϼǷѡѷ + * @param node + * @return + + private boolean getTopRefresh(DefaultMutableTreeTableNode node) + { + boolean result = false; + + //жϲǷѡѷĶ + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) + { + for (int i = 0; i < rootNode.getChildCount();) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && childBean.getRefreshStatus().indexOf("") >= 0) + { + //MessageBox.post("ϲ["+childBean.getEbom()+"]ѹѡͲ㲻ѡ", "", MessageBox.ERROR); + return true; + } + else + { + return getTopRefresh(childNode); + } + } + } + } + + return result; + } + */ + + /** + * ȡBOMϢ + * @param bomLine + * @param bomPropertyList + * @param parentID + */ + public void getBomPropertysToNode(TCComponentBOMLine bomLine, DefaultMutableTreeTableNode rootNode,String parentID) + { + try { + + NodeBean nodeBean = new NodeBean(); + + nodeBean.setDbom(bomLine.getStringProperty("bl_item_object_string")); + nodeBean.setNum(bomLine.getStringProperty("bl_quantity")); + nodeBean.setEbom(""); + nodeBean.setEbomId(""); + nodeBean.setLabel(""); + nodeBean.setRefreshStatus(""); + nodeBean.setParentString(""); + + DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(nodeBean); + rootNode.add(node); + + System.out.println("ID:"+bomLine.getStringProperty("bl_item_item_id")); + getRepresentationPropertysToNode(bomLine, node, bomLine.getStringProperty("bl_item_item_id"), bomLine.getStringProperty("bl_quantity")); + + if(bomLine.getChildren().length > 0 && flag) { + flag = false;//ֻbomµbom + AIFComponentContext aif[] = bomLine.getChildren(); + for (int i = 0; i < aif.length; i++) { + + TCComponentBOMLine subline = (TCComponentBOMLine) aif[i].getComponent(); + + getBomPropertysToNode(subline, node,bomLine.getStringProperty("bl_item_item_id")); + } + + } + } catch (Exception e) { + // Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/src/com/connor/ldy/bom/DbomTransitionToEbomDialog.java b/src/com/connor/ldy/bom/DbomTransitionToEbomDialog.java new file mode 100644 index 0000000..d7e1d83 --- /dev/null +++ b/src/com/connor/ldy/bom/DbomTransitionToEbomDialog.java @@ -0,0 +1,703 @@ +package com.connor.ldy.bom; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.table.DefaultTableModel; +import javax.swing.tree.TreePath; + +import org.jdesktop.swingx.decorator.HighlighterFactory; +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; + +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.common.Activator; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentUser; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +@SuppressWarnings("deprecation") +public class DbomTransitionToEbomDialog extends AbstractAIFDialog implements ActionListener, MouseListener { + + /** + * + */ + private static final long serialVersionUID = 1L; + private TCSession session; + private InterfaceAIFComponent comp; + //private InterfaceAIFComponent comp;//ȡѡеĶ + + private List isNotEditableRow = new ArrayList(); + //private TCComponentBOMLine bomLine; + private DefaultMutableTreeTableNode node; + + private String[] header = new String[] { "DBOM", "EBOM","ѡ", "EBOMID", "","","״̬","Ӧڵ"}; + + private JPanel titlePanel; + private JLabel titleLabel; + private JTreeTable table; + private JTreeTableModel map; + + private JPanel rootPanel; + private JButton okButton; + private JButton celButton; + private JButton refreshButton; + + //Ҽ˵ +// private static JPopupMenu menu; + //Ҽ˵ + private JMenuItem sendItem; + private String topRelease; + + public DbomTransitionToEbomDialog(InterfaceAIFComponent comp,TCSession session, + DefaultMutableTreeTableNode node,String topRelease) { + // Auto-generated constructor stub + super(false); + this.session = session; + this.comp = comp; + this.node = node; + this.topRelease=topRelease; + init(); + } + + private void init() { + // Auto-generated method stub + this.setTitle("DBOMתEBOM"); + this.setPreferredSize(new Dimension(800,600)); + // ʼⲿֿؼ + this.titlePanel = new JPanel(); + this.titleLabel = new JLabel("DBOMתEBOM"); + this.titleLabel.setFont(new Font("", 1, 18)); + this.titlePanel.add(titleLabel); + + JPanel panel = new JPanel(); + panel.add(this.titlePanel,BorderLayout.NORTH); + + this.table = getJTreeTable(null, null, header, null); + + this.table.addMouseListener(this); +// Adapter adapter = new Adapter(table); + + this.rootPanel = new JPanel(new FlowLayout()); + this.okButton = new JButton("ȷ"); + this.celButton = new JButton("ȡ"); + this.refreshButton = new JButton("ˢ"); + + this.rootPanel.add(okButton); + this.rootPanel.add(celButton); + this.rootPanel.add(refreshButton); + //this.rootPanel.add(celValueButton); + //Ҽ˵ +// menu = new JPopupMenu(); + // + sendItem = new JMenuItem("͵ҵTeamcenter"); + + // + this.createActionEvent(); + this.setLayout(new BorderLayout()); + // this.add(centerPanel, BorderLayout.NORTH); + this.add(panel, BorderLayout.NORTH); + this.add(new JScrollPane(this.table), BorderLayout.CENTER); + // dialog.add(tablePanel, BorderLayout.CENTER); + this.add(rootPanel, BorderLayout.SOUTH); + //this.setAlwaysOnTop(true); + this.pack(); + this.setLocationRelativeTo(null); + this.show(); + } + + //Ӽ + public void createActionEvent() { + this.okButton.addActionListener(this); + this.celButton.addActionListener(this); + this.refreshButton.addActionListener(this); + this.sendItem.addActionListener(this); + //this.celValueButton.addActionListener(this); + } + + //Jtableͨ÷ + public JTreeTable getJTreeTable(JTreeTable partsTable, DefaultTableModel dtm, + Object[] titleNames, Object[][] values) { + int simpleLen = 100; + int totleLen = 1500; + if (partsTable == null) { + this.map = new JTreeTableModel(this.node); + this.map.setIsNotEditableRow(this.isNotEditableRow); + //map.setColumnIdentifiers(titleNames); + + partsTable = new JTreeTable(map); + partsTable.setIsNotEditableRow(this.isNotEditableRow); + partsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + // partsTable.setRowHeight(1, 50); + // partsTable.setRowHeight(2, 100); + partsTable.setRowHeight(30); + partsTable.expandAll(); // չȫڵ + // +// partsTable.HiddenCell(0); + + partsTable.getColumnModel().getColumn(0).setPreferredWidth(188); // õһп + partsTable.getColumnModel().getColumn(1).setPreferredWidth(150); // õڶп + partsTable.getColumnModel().getColumn(2).setPreferredWidth(55); // õп + + partsTable.setHighlighters(HighlighterFactory.createSimpleStriping()); + + if (simpleLen * titleNames.length >= totleLen) { + for (int i = 0; i < titleNames.length; i++) { + partsTable.getColumnModel().getColumn(i) + .setPreferredWidth(simpleLen); + } + partsTable.setAutoResizeMode(0); + } else { + partsTable.setAutoResizeMode(1); + } + } + return partsTable; + } + + @Override + public void mouseClicked(MouseEvent e) { + // Auto-generated method stub + if(e.getClickCount() == 2) { + TreePath treePath = table.getPathForLocation(e.getX(),e.getY()); + if (treePath != null) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) treePath.getLastPathComponent(); + NodeBean nodeBean = (NodeBean) node.getUserObject(); + String itemId = nodeBean.getDbom(); + if(itemId == null || itemId.isEmpty()) { + itemId = nodeBean.getEbomId(); + } + if(itemId != null && !itemId.isEmpty()) { + try { + //ȡ + TCComponentItemType itemType = (TCComponentItemType) this.session.getTypeComponent("Item"); + TCComponentItem item = itemType.find(itemId.split("-")[0]); + + Activator.getDefault().openPerspective("com.teamcenter.rac.ui.perspectives.navigatorPerspective"); + Activator.getDefault().openComponents("com.teamcenter.rac.ui.perspectives.navigatorPerspective",new InterfaceAIFComponent[] { item }); + } catch (Exception e2) { + // : handle exception + e2.printStackTrace(); + } + } + } + } else if (e.getClickCount() > 0) { +// +// if(e.getButton() == MouseEvent.BUTTON3) +// { +// menu.show(table, e.getX(), e.getY()); +// } + + // ѡ + int selectColumn = table.getTableHeader().columnAtPoint(e.getPoint()); + + if(selectColumn != 2){ + return; + } + + TreePath treePath = table.getPathForLocation(e.getX(),e.getY()); + if (treePath != null) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) treePath.getLastPathComponent(); + NodeBean nodeBean = (NodeBean) node.getUserObject(); + +// if(getTopRefresh(node)) +// { +// MessageBox.post("ϲѹѡͲ㲻ѡ", "", MessageBox.ERROR); +// return; +// } + + if(getTopProcessRefresh(node)) + { + MessageBox.post("ϲѹѡеͲ㲻ѡ", "", MessageBox.ERROR); + return; + } + + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + NodeBean rootNodeBean = (NodeBean) rootNode.getUserObject(); + + + if(!rootNodeBean.getDbom().equals("") && !getTop(node) && nodeBean.getLabel().equals("0")) + { + MessageBox.post("ϲδѡ²㲻ѡ", "", MessageBox.ERROR); + return; + } + } + + + try { + TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent("Item"); + + if(nodeBean.getLabel().equals("0")) + { + //жͬһǷѹѡ + if(parentNode != null) + { + for (int i = 0; i < parentNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) parentNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1")) + { + MessageBox.post("ͬһ㼶ֻѡһ", "", MessageBox.ERROR); + return; + } + } + + } + + nodeBean.setLabel("1"); + isHaveBom(node, nodeBean.getEbomId(), "1", itemType); + } else if(nodeBean.getLabel().equals("1")) { + nodeBean.setLabel("0"); + isHaveBom(node, nodeBean.getEbomId(), "0", itemType); + } + Robot robot = new Robot(); + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + } catch (Exception e2) { + // : handle exception + e2.printStackTrace(); + } + } + } + } + + /*** + * жϼǷѡ + * @param node + * @return + * @throws TCException + */ + private void isHaveBom(DefaultMutableTreeTableNode node,String parentID,String status,TCComponentItemType itemType) throws TCException + { + TCComponentItem item = itemType.find(parentID); + TCComponentItemRevision itemRevision = item.getLatestItemRevision(); + + TCComponent[] tcComponents = itemRevision.getReferenceListProperty("view"); + if(tcComponents.length > 0) + { + for (int ii = 0; ii < node.getParent().getChildCount(); ii++) { + DefaultMutableTreeTableNode tableNode = (DefaultMutableTreeTableNode)node.getParent().getChildAt(ii); + + if(tableNode.getChildCount() > 0) + { + for (int i = 0; i < tcComponents.length; i++) { + TCComponent childBomLine = tcComponents[i]; + List haveItemID = new ArrayList(); + for (int j = 0; j < tableNode.getChildCount(); j++) { + String childItemId = childBomLine.getStringProperty("item_id"); + NodeBean childNodeBean = (NodeBean) tableNode.getChildAt(j).getUserObject(); + if(childItemId.equals(childNodeBean.getEbomId()) && !haveItemID.contains(childNodeBean.getEbomId())) + { + haveItemID.add(childNodeBean.getEbomId()); + childNodeBean.setLabel(status); + isHaveBom((DefaultMutableTreeTableNode)(tableNode.getChildAt(j)), childNodeBean.getEbomId(), status, itemType); + } + } + } + } + } + } + } + + /*** + * жϼǷѡ + * @param node + * @return + */ + private boolean getTop(DefaultMutableTreeTableNode node) + { + boolean result = false; + + //жϲǷѡѷĶ + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) + { + for (int i = 0; i < rootNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1")) + { + //MessageBox.post("ϲ["+childBean.getEbom()+"]ѹѡͲ㲻ѡ", "", MessageBox.ERROR); + return true; + } + } + } + } + + return result; + } + + /*** + * жϼǷѡѷ + * @param node + * @return + + private boolean getTopRefresh(DefaultMutableTreeTableNode node) + { + boolean result = false; + + //жϲǷѡѷĶ + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) + { + for (int i = 0; i < rootNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && !childBean.getRefreshStatus().equals("Է") && !childBean.getRefreshStatus().isEmpty()) + { + result = true; + break; + } + else + { + if(getTopRefresh(childNode)) + { + result = true; + break; + } + } + } + } + } + + return result; + }*/ + + /*** + * жϼǷѡж + * @param node + * @return + */ + private boolean getTopProcessRefresh(DefaultMutableTreeTableNode node) + { + boolean result = false; + + //жϲǷѡѷĶ + DefaultMutableTreeTableNode parentNode = (DefaultMutableTreeTableNode) node.getParent(); + if(parentNode != null) + { + DefaultMutableTreeTableNode rootNode = (DefaultMutableTreeTableNode) parentNode.getParent(); + if(rootNode != null) + { + for (int i = 0; i < rootNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) rootNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && childBean.getRefreshStatus().equals("")) + { + result = true; + break; + } + else + { + if(getTopProcessRefresh(childNode)) + { + result = true; + break; + } + } + } + } + } + + return result; + } + + @Override + public void mousePressed(MouseEvent e) { + // Auto-generated method stub + + } + + @Override + public void mouseReleased(MouseEvent e) { + // Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) { + // Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // Auto-generated method stub + + } + + @Override + public void actionPerformed(ActionEvent e) { + // Auto-generated method stub + Object source = e.getSource(); + if (source.equals(this.okButton)) + { + System.out.println("topRelease:"+topRelease); + if(!topRelease.equals("")) { + if(topRelease.indexOf("-")>=0) {//bomϵ޶ + MessageBox.post(topRelease+"ڹ", "", MessageBox.ERROR); + return; + }else if(topRelease.contains("")){ + MessageBox.post("", "", MessageBox.ERROR); + return; + }else { + MessageBox.post("bomϵ޶", "", MessageBox.ERROR); + return; + } + + } + //ȡѡеEBOM + try { + TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent("Item"); + DefaultMutableTreeTableNode tableNode = (DefaultMutableTreeTableNode)this.node.getChildAt(0); + TCComponentUser user = session.getUser(); + for (int i = 0; i < tableNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) tableNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && (childBean.getRefreshStatus().equals("Է") || childBean.getRefreshStatus().equals(""))) { + TCComponentItem topItem = itemType.findItems(childBean.getEbomId())[0]; + System.out.println("topItem:"+topItem+"=="+topItem.getReferenceProperty("owning_user")); + if(!topItem.getReferenceProperty("owning_user").equals(user) && !childBean.getRefreshStatus().equals("Է")) { + MessageBox.post(DbomTransitionToEbomDialog.this, "ǰû"+topItem+"ߣת", "", MessageBox.ERROR); + return; + } + } + } +// MethodUtil.openByPass(session);//TODO + this.adaptiveVariants(tableNode, itemType); +// MethodUtil.closeByPass(session); + MessageBox.post("תɹ", "ɹ", MessageBox.INFORMATION); + } catch (Exception e1) { + // Auto-generated catch block + e1.printStackTrace(); + } + } + else if(source.equals(this.refreshButton)) + { + this.dispose(); + try { + DbomTransitionToEbomCommand command = new DbomTransitionToEbomCommand(comp,session); + command.executeModal(); + } catch (Exception e1) { + // Auto-generated catch block + e1.printStackTrace(); + } + } + else if(source.equals(this.sendItem)) + { + String itemId = table.getValueAt(table.getSelectedRow(), 3) == null? "" : table.getValueAt(table.getSelectedRow(), 3).toString(); + if(itemId.isEmpty()) + { + String itemString = table.getValueAt(table.getSelectedRow(), 0) == null? "" : table.getValueAt(table.getSelectedRow(), 0).toString(); + if(itemString.indexOf("-") > 0) + { + itemId = itemString.split("-")[0]; + } + } + if(itemId != null && !itemId.isEmpty()) + { + try { + //ȡ + TCComponentItemType itemType = (TCComponentItemType) this.session.getTypeComponent("Item"); + TCComponentItem item = itemType.find(itemId.split("-")[0]); + + Activator.getDefault().openPerspective("com.teamcenter.rac.ui.perspectives.navigatorPerspective"); + Activator.getDefault().openComponents("com.teamcenter.rac.ui.perspectives.navigatorPerspective", new InterfaceAIFComponent[] { item }); + } catch (Exception e2) { + // : handle exception + e2.printStackTrace(); + } + } + } + else + { + this.dispose(); + } + } + + TCComponentBOMLine resultTopline = null; + /** + * ´BOM + * + * @param topItem + * @throws TCException + */ + private void adaptiveVariants(DefaultMutableTreeTableNode tableNode,TCComponentItemType itemType) throws TCException { + TCComponentItem topItem = null; + ArrayList itemList = new ArrayList(); + Map itemNumMap = new HashMap(); + for (int i = 0; i < tableNode.getChildCount(); i++) { + DefaultMutableTreeTableNode childNode = (DefaultMutableTreeTableNode) tableNode.getChildAt(i); + NodeBean childBean = (NodeBean) childNode.getUserObject(); + if(childBean.getLabel().equals("1") && (childBean.getRefreshStatus().equals("Է") || childBean.getRefreshStatus().equals(""))) { + topItem = itemType.find(childBean.getEbomId()); + for (int j = 0; j < tableNode.getChildCount(); j++) { + DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) tableNode.getChildAt(j); + for (int k = 0; k < node.getChildCount(); k++) { + DefaultMutableTreeTableNode childTableNode = (DefaultMutableTreeTableNode) node.getChildAt(k); + NodeBean childNodeBean = (NodeBean) childTableNode.getUserObject(); + if(childNodeBean.getLabel().equals("1")) { + TCComponentItem item = itemType.find(childNodeBean.getEbomId()); + itemList.add(item.getLatestItemRevision()); + itemNumMap.put(item.getStringProperty("item_id"), childNodeBean.getNum()); + if(childNodeBean.getRefreshStatus().equals("Է") || childNodeBean.getRefreshStatus().equals("")) { + adaptiveVariants((DefaultMutableTreeTableNode)(childTableNode.getParent()), itemType); + } + } + } + } + } + } + if(topItem != null) { + resultTopline = null; + this.recreateBom(topItem.getLatestItemRevision(), itemList, true); + if(resultTopline != null) { + resultTopline.lock(); + //BOM + for (int j = 0; j < resultTopline.getChildren().length; j++) { + TCComponentBOMLine bomLine = (TCComponentBOMLine) resultTopline.getChildren()[j].getComponent(); + if(itemNumMap.keySet().contains((bomLine.getStringProperty("bl_item_item_id")))) + { + String quantity = itemNumMap.get(bomLine.getStringProperty("bl_item_item_id")); + if(quantity == null || quantity.isEmpty() || quantity.equals("0")) + { + String uom = ""; + try { + uom = bomLine.getPropertyDisplayableValue("bl_uom"); + } catch (Exception e) { + // Auto-generated catch block + e.printStackTrace(); + } + System.out.println("λ++++++++++++++++"+uom); + if(uom.equals("ÿ")) + { + continue; + } + quantity = "1.00"; + } + System.out.println("++++++++++++++++"+quantity); + if(quantity.indexOf(".") > 0) + { + Double bomNum = Double.parseDouble(quantity); + bomLine.setStringProperty("bl_quantity", bomNum.toString()); + } + else + { + Integer bomNum = Integer.parseInt(quantity); + bomLine.setStringProperty("bl_quantity", bomNum.toString()); + } + //bomLine.setStringProperty("bl_quantity", itemNumMap.get(bomLine.getStringProperty("bl_item_item_id"))); + } + } + resultTopline.save(); + resultTopline.unlock(); + resultTopline.refresh(); + if(resultTopline.getBOMView() != null) + { + resultTopline.getBOMView().save(); + resultTopline.getBOMView().refresh(); + } + } + } + } + + /** + * ´BOM + * + * @param item + * @param itemlists + * @throws TCException + */ + public void recreateBom(TCComponentItemRevision topItemRev, + ArrayList itemRevisionlists, boolean isDelete) + throws TCException { + TCComponentBOMWindow bomWindow = null; + try { + TCComponentBOMWindowType bomWindowType = (TCComponentBOMWindowType) session + .getTypeComponent("BOMWindow"); + bomWindow = bomWindowType.create(null); + TCComponentBOMLine topline = bomWindow.setWindowTopLine(topItemRev.getItem(), + topItemRev, null, null); + resultTopline = topline; + bomWindow.lock(); + topline.lock(); + if (isDelete) { + if (topline.hasChildren()) { + AIFComponentContext[] childrens = topline.getChildren(); + for (AIFComponentContext children : childrens) { + ((TCComponentBOMLine) children.getComponent()).cut(); + } + } + } + for (TCComponentItemRevision n_itemRevision : itemRevisionlists) { + if(n_itemRevision != null) + { + boolean isHave = false; + if(!isDelete) + { + for (AIFComponentContext children : topline.getChildren()) { + if(n_itemRevision.getStringProperty("item_id").compareTo(children.getComponent().getProperty("bl_child_id")) == 0) + { + isHave = true; + } + } + } + if(!isHave) + { + topline.add(n_itemRevision.getItem(), n_itemRevision, null, false, ""); + } + } + } + topline.save(); + topline.unlock(); + topline.refresh(); + if(topline.getBOMView() != null) + { + topline.getBOMView().save(); + topline.getBOMView().refresh(); + } + } catch (Exception e) { + // : handle exception + e.printStackTrace(); + } + bomWindow.save(); + bomWindow.unlock(); + bomWindow.refresh(); + } + +} diff --git a/src/com/connor/ldy/bom/DbomTransitionToEbomHandler.java b/src/com/connor/ldy/bom/DbomTransitionToEbomHandler.java new file mode 100644 index 0000000..638d5ac --- /dev/null +++ b/src/com/connor/ldy/bom/DbomTransitionToEbomHandler.java @@ -0,0 +1,32 @@ +package com.connor.ldy.bom; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + + +public class DbomTransitionToEbomHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + try { + //MessageBox.post("ml8_FilingRequirements:", "", MessageBox.ERROR); + DbomTransitionToEbomCommand command = new DbomTransitionToEbomCommand(app.getTargetComponent(),session); + command.executeModal(); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(""+e.getMessage(), "ERROR", MessageBox.ERROR); + } + return null; + } + + +} diff --git a/src/com/connor/ldy/bom/JTreeTable.java b/src/com/connor/ldy/bom/JTreeTable.java new file mode 100644 index 0000000..912af58 --- /dev/null +++ b/src/com/connor/ldy/bom/JTreeTable.java @@ -0,0 +1,89 @@ +package com.connor.ldy.bom; + +import java.awt.event.MouseEvent; +import java.util.List; + +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; + +import org.jdesktop.swingx.JXTreeTable; + +public class JTreeTable extends JXTreeTable { + + + /** + * + */ + private static final long serialVersionUID = 1L; + private List isNotEditableRow; + //CheckBoxCellEditor checkBoxCellEditor = new CheckBoxCellEditor(this); + TableCellCheckboxRenderer checkboxRenderer = new TableCellCheckboxRenderer(this); + + public List getIsNotEditableRow() { + return isNotEditableRow; + } + + public void setIsNotEditableRow(List isNotEditableRow) { + this.isNotEditableRow = isNotEditableRow; + } + + public JTreeTable(JTreeTableModel testTreeTableModel) { + // Auto-generated constructor stub + super(testTreeTableModel); + } + + @Override + public boolean isCellEditable(int arg0, int arg1) { + // Auto-generated method stub + return true;//super.isCellEditable(arg0, arg1); + } + + @Override + public TableCellEditor getCellEditor(int row, int column) { + // Auto-generated method stub + //if(isNotEditableRow.contains(row) && column == 2) + + + return cellEditor; + //return super.getCellEditor(row, column); + } + + public String getToolTipText(MouseEvent e) { + int row = this.rowAtPoint(e.getPoint()); + int col = this.columnAtPoint(e.getPoint()); + String tiptextString = null; + if (row > -1 && col > -1) { + Object value = this.getValueAt(row, col); + if (null != value && !"".equals(value)) + tiptextString = value.toString();// ʾԪ + } + return tiptextString; + } + + @Override + public TableCellRenderer getCellRenderer(int row, int column) { + // Auto-generated method stub + if(this.getValueAt(row, 2) != null && (this.getValueAt(row, 2).toString().equals("0") || this.getValueAt(row, 2).toString().equals("1")) && column == 2) + { + return checkboxRenderer; + } + else + { + return super.getCellRenderer(row, column); + } + } + + // + public void HiddenCell(int column) { + TableColumn tc = this.getTableHeader().getColumnModel() + .getColumn(column); + tc.setMaxWidth(0); + tc.setPreferredWidth(0); + tc.setWidth(0); + tc.setMinWidth(0); + this.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(0); + this.getTableHeader().getColumnModel().getColumn(column).setMinWidth(0); + } + +} diff --git a/src/com/connor/ldy/bom/JTreeTableModel.java b/src/com/connor/ldy/bom/JTreeTableModel.java new file mode 100644 index 0000000..8b58f6f --- /dev/null +++ b/src/com/connor/ldy/bom/JTreeTableModel.java @@ -0,0 +1,117 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.connor.ldy.bom; + +import java.util.List; + +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; +import org.jdesktop.swingx.treetable.DefaultTreeTableModel; +import org.jdesktop.swingx.treetable.TreeTableNode; + +/** + * + * @author vearn + */ +public class JTreeTableModel extends DefaultTreeTableModel { + + private String[] _names = { "DBOM", "EBOM","ѡ", "EBOMID", "","","״̬","Ӧڵ"}; + + + private List isNotEditableRow; + + + + public JTreeTableModel(TreeTableNode node) { + super(node); + } + + + public List getIsNotEditableRow() { + return isNotEditableRow; + } + + public void setIsNotEditableRow(List isNotEditableRow) { + this.isNotEditableRow = isNotEditableRow; + } + + /** + * е + */ + @Override + public int getColumnCount() { + return _names.length; + } + + /** + * ͷʾ + */ + @Override + public String getColumnName(int column) { + return _names[column]; + } + + /** + * ڵԪʾObject + */ + @Override + public Object getValueAt(Object node, int column) { + Object value = null; + if (node instanceof DefaultMutableTreeTableNode) { + DefaultMutableTreeTableNode mutableNode = (DefaultMutableTreeTableNode) node; + Object o = mutableNode.getUserObject(); + if (o != null && o instanceof NodeBean) { + NodeBean bean = (NodeBean) o; + switch (column) { + case 0: + value = bean.getDbom(); + break; + case 1: + value = bean.getEbom(); + break; + case 2: + value = bean.getLabel(); + break; + case 3: + value = bean.getEbomId(); + break; + case 4: + value = bean.getEbomDesc(); + break; + case 5: + value = bean.getNum(); + break; + case 6: + value = bean.getRefreshStatus(); + break; + case 7: + value = bean.getParentString(); + break; + } + } + } + return value; + } + + /** + * еԪ񶼲ܱ༭ + * + * @param the node (i.e. row) for which editing is to be determined + * @param the column for which editing is to be determined + * @return false + */ + @Override + public boolean isCellEditable(Object node, int column) { + //if(column == 5) + //{ + return true; + //} + //else + //{ + // return false; + //} + } + + +} diff --git a/src/com/connor/ldy/bom/NodeBean.java b/src/com/connor/ldy/bom/NodeBean.java new file mode 100644 index 0000000..3b311ad --- /dev/null +++ b/src/com/connor/ldy/bom/NodeBean.java @@ -0,0 +1,71 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.connor.ldy.bom; + +/** + * + * @author vearn + */ +public class NodeBean { + + private String dbom;//ID + private String ebom;// + private String ebomId;// + private String ebomDesc;// + private String num;// + private String label;// + private String refreshStatus;//״̬ + private String parentString;//Ӧڵ + + public String getDbom() { + return dbom; + } + public void setDbom(String dbom) { + this.dbom = dbom; + } + public String getEbom() { + return ebom; + } + public void setEbom(String ebom) { + this.ebom = ebom; + } + public String getEbomId() { + return ebomId; + } + public void setEbomId(String ebomId) { + this.ebomId = ebomId; + } + public String getLabel() { + return label; + } + public void setLabel(String label) { + this.label = label; + } + public String getRefreshStatus() { + return refreshStatus; + } + public void setRefreshStatus(String refreshStatus) { + this.refreshStatus = refreshStatus; + } + public String getParentString() { + return parentString; + } + public void setParentString(String parentString) { + this.parentString = parentString; + } + public String getNum() { + return num; + } + public void setNum(String num) { + this.num = num; + } + public String getEbomDesc() { + return ebomDesc; + } + public void setEbomDesc(String ebomDesc) { + this.ebomDesc = ebomDesc; + } + +} \ No newline at end of file diff --git a/src/com/connor/ldy/bom/TableCellCheckboxRenderer.java b/src/com/connor/ldy/bom/TableCellCheckboxRenderer.java new file mode 100644 index 0000000..c008a4c --- /dev/null +++ b/src/com/connor/ldy/bom/TableCellCheckboxRenderer.java @@ -0,0 +1,74 @@ +package com.connor.ldy.bom; + +import java.awt.Component; +import java.util.List; + +import javax.swing.JCheckBox; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.EventListenerList; +import javax.swing.table.TableCellRenderer; + + +public class TableCellCheckboxRenderer extends JCheckBox implements TableCellRenderer { + /** + * + */ + private static final long serialVersionUID = 1L; + private List processRows; + protected EventListenerList listenerList = new EventListenerList(); + protected ChangeEvent changeEvent = new ChangeEvent(this); + //private TestTreeTableModel tableModel; + + public List getProcessRows() { + return processRows; + } + + public void setProcessRows(List processRows) { + this.processRows = processRows; + + } + + public TableCellCheckboxRenderer(final JTreeTable table) { + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) { + // TODO Auto-generated method stub + this.setHorizontalAlignment(SwingConstants.CENTER);// ͷǩ + this.setBorderPainted(true); + + if(value != null) + { +// if(value.toString().equals("1")) +// { +// if(table.getColumnName(column).equals("") && hasFocus) +// { +// if(table.getValueAt(row, column + 1).toString().equals("1")) +// { +// table.setValueAt(0, row, column + 1); +// } +// } +// else if(table.getColumnName(column).equals("ɾ") && hasFocus) +// { +// if(table.getValueAt(row, column - 1).toString().equals("1")) +// { +// table.setValueAt(0, row, column - 1); +// } +// } +// } +// if(value.toString().equals("1")) +// { +// System.out.println(value.toString().equals("1") + "===="); +// } + this.setSelected(value.toString().equals("1")); + } + else + { + this.setSelected(false); + } + return this; + } +} \ No newline at end of file diff --git a/src/com/connor/ldy/oa/OAPurchaseProcessDialog.java b/src/com/connor/ldy/oa/OAPurchaseProcessDialog.java new file mode 100644 index 0000000..452646b --- /dev/null +++ b/src/com/connor/ldy/oa/OAPurchaseProcessDialog.java @@ -0,0 +1,212 @@ +package com.connor.ldy.oa; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Map; +import java.util.Vector; +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumnModel; + +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.services.rac.core.LOVService; +import com.teamcenter.services.rac.core._2013_05.LOV.InitialLovData; +import com.teamcenter.services.rac.core._2013_05.LOV.LOVSearchResults; +import com.teamcenter.services.rac.core._2013_05.LOV.LOVValueRow; +import com.teamcenter.services.rac.core._2013_05.LOV.LovFilterData; + +public class OAPurchaseProcessDialog extends AbstractAIFDialog { + private static final long serialVersionUID = 1L; + private TCSession session; + protected JComboBox combo; + private JButton exportBtn; + private JButton cancelBtn; + protected JTable processTable; + private DefaultTableModel processModel; + + public OAPurchaseProcessDialog(TCSession session, ArrayList revs, String[] options, String[] dbinfo) throws Exception { + super(AIFUtility.getActiveDesktop()); + this.session = session; + setTitle("OA깺"); + + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues"); + TCComponentListOfValues[] loves = lovType.find("LD6_CompanyNum_DLOV"); + if(loves.length<1) + throw new Exception("δҵLOVLD6_CompanyNum_DLOV"); + String[] lovs = getDynamicLOV(loves[0]);//LD6_CompanyNum_DLOV + JLabel label = new JLabel("", SwingConstants.RIGHT); + label.setPreferredSize(new Dimension(80, 23)); +// label.setHorizontalTextPosition(JLabel.RIGHT); + FlowLayout flow = new FlowLayout(); + flow.setAlignment(FlowLayout.LEFT); + JPanel propPanel = new JPanel(flow); + propPanel.add(label); + combo = new JComboBox<>(); + combo.setPreferredSize(new Dimension(118, 23)); + combo.addItem(""); + for(String s : lovs) { + combo.addItem(s); + } + propPanel.add(combo); + + exportBtn = new JButton(""); + cancelBtn = new JButton("ȡ"); + JPanel btnPanel = new JPanel(new FlowLayout()); + btnPanel.add(exportBtn); + btnPanel.add(cancelBtn); +// JPanel topPanel = new JPanel(new BorderLayout()); +// topPanel.add(BorderLayout.WEST, propPanel); +// topPanel.add(BorderLayout.EAST, btnPanel); + + String[] tableHeader = new String[] { "", "Ϻ", "", "ɹ", "ע" }; + processModel = new DefaultTableModel(tableHeader, 0); + processTable = new JTable() { + private static final long serialVersionUID = 1L; + @Override + public boolean isCellEditable(int row, int col) { + if (col > 2) { + return true; + } + return false; + } + public Class getColumnClass(int column) { + if (column==0) { +// return Boolean.class; + } + return super.getColumnClass(column); + } + }; +// processTable.getTableHeader().setReorderingAllowed(false); + processTable.setFillsViewportHeight(true); +// processTable.setEnabled(false); + processTable.setEnabled(true); +// processTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); + processTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + processTable.setModel(processModel); +// processTable.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(processTable, true)); + processTable.getTableHeader().setReorderingAllowed(false); + TableColumnModel pColModel = processTable.getColumnModel(); + for(int i=1; i revs, String[] options, String[] dbinfo) { + final AbstractAIFDialog dialog = this; + exportBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + String center = combo.getSelectedItem().toString(); + if(center.isEmpty()) { + MessageBox.post(dialog, "IJΪ", "ʾ", MessageBox.ERROR); + return; + } + for(int i=0; i lovDisplayValueList = new Vector<>(); +// lovDisplayValueList.add(""); +// Vector lovValueList = new Vector<>(); + LOVService lovService = LOVService.getService((TCSession) AIFUtility.getCurrentApplication().getSession()); + InitialLovData input = new InitialLovData(); + LovFilterData filter = new LovFilterData(); + filter.sortPropertyName = "object_name"; + filter.order = 1; + filter.numberToReturn = 100; + filter.maxResults = 100; + + input.lov = lov; + input.filterData = filter; + LOVSearchResults result = lovService.getInitialLOVValues(input); +// StringBuffer sb = new StringBuffer(); +// sb.append(">>"); + for (LOVValueRow row : result.lovValues) { + Map map = row.propDisplayValues; +// Map realmap = row.propInternalValues; + for (String key : map.keySet()) { + if(!key.equals("object_name")) + continue; +// sb.append("UID:" + row.uid + ",key:" + key + "value:" + map.get(key)[0]); +// sb.append("\n"); + String[] v = map.get(key); + lovDisplayValueList.add(v[0]); +// lovValueList.add(realmap.get(key)[0]); +// System.out.println("key:"+key+"=="+v.length+">>"+v[0]); + } + } +// System.out.println("StringBuffer:"+sb.toString()); + if(lovDisplayValueList.size()<1) + throw new Exception("δҵLOV"+lov.getProperty("lov_name")); + return lovDisplayValueList.toArray(new String[lovDisplayValueList.size()]); + } +} \ No newline at end of file diff --git a/src/com/connor/ldy/oa/OAPurchaseProcessHandler.java b/src/com/connor/ldy/oa/OAPurchaseProcessHandler.java new file mode 100644 index 0000000..259f171 --- /dev/null +++ b/src/com/connor/ldy/oa/OAPurchaseProcessHandler.java @@ -0,0 +1,80 @@ +package com.connor.ldy.oa; + +import java.util.ArrayList; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.connor.ldy.util.TCUtil; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class OAPurchaseProcessHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("OAPurchaseProcessHandler"); + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + String[] dbinfo = session.getPreferenceService().getStringValues("LD_dbinfo"); + if(dbinfo==null || dbinfo.length<2) { + MessageBox.post(desktop, "ѡLD_dbinfoòȷ", "ERROR", MessageBox.ERROR); + return null; + } + String[] options = session.getPreferenceService().getStringValues("Connor_OAPurchaseProcess"); + if(options==null || options.length<2) { + MessageBox.post(desktop, "ѡConnor_OAPurchaseProcessòȷ", "ERROR", MessageBox.ERROR); + return null; + } + String[] types = options[0].split("\\|"); + int max = Integer.parseInt(options[1]); + InterfaceAIFComponent[] targets = app.getTargetComponents(); + if(targets==null || targets.length==0) { + MessageBox.post(desktop, "ѡ񵶾", "ERROR", MessageBox.ERROR); + return null; + }else if(max>0 && targets.length>max) { + MessageBox.post(desktop, "ѡĶޣѡ", "ERROR", MessageBox.ERROR); + return null; + } + ArrayList revs = new ArrayList<>(); + for(InterfaceAIFComponent target : targets) { + TCComponentItemRevision rev = null; + String type = ""; + if(target instanceof TCComponentItemRevision) { + rev = (TCComponentItemRevision) target; + type = rev.getItem().getType(); + }else if(target instanceof TCComponentItem) { + rev = ((TCComponentItem) target).getLatestItemRevision(); + type = target.getType(); + }else { + MessageBox.post(desktop, "ѡ񵶾", "ERROR", MessageBox.ERROR); + return null; + } + if(revs.contains(rev)) + continue; + if(!TCUtil.contains(types, type)) { + MessageBox.post(desktop, "ѡ񵶾", "ERROR", MessageBox.ERROR); + return null; + } + revs.add(rev); + } + new OAPurchaseProcessDialog(session, revs, options, dbinfo); +// new CutterPurchaseProcessOperation(session, (TCComponentBOMLine)target).executeOperation(); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ldy/oa/OAPurchaseProcessOperation.java b/src/com/connor/ldy/oa/OAPurchaseProcessOperation.java new file mode 100644 index 0000000..cd866ef --- /dev/null +++ b/src/com/connor/ldy/oa/OAPurchaseProcessOperation.java @@ -0,0 +1,186 @@ +package com.connor.ldy.oa; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Date; + +import javax.swing.JTable; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.InputStreamRequestEntity; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.RequestEntity; +import org.dom4j.Document; +import org.dom4j.DocumentHelper; + +import com.connor.ldy.util.SqlUtil; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.util.MessageBox; + +public class OAPurchaseProcessOperation extends AbstractAIFOperation { + + private OAPurchaseProcessDialog parent; +// private ArrayList revs; + private String[] options; + private String[] dbinfo; + private String[] logs; + + public OAPurchaseProcessOperation(OAPurchaseProcessDialog parent, ArrayList revs, String[] options, String[] dbinfo) { + this.parent = parent; + this.options = options; + this.dbinfo = dbinfo; + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + this.logs = new String[] { "OA_004", "߲ɹ", "OA", "PLM", "", "", "", + String.format("%tF", new Date())+" "+String.format("%tT", new Date()) }; + String center = parent.combo.getSelectedItem().toString(); + JTable table = parent.processTable; + + ServiceClient sc = new ServiceClient(); + Options opts = new Options(); + EndpointReference end = new EndpointReference(options[2]);//"http://10.10.22.18:9089/services/PlmXgxxService" + opts.setTo(end); + String methodName = "plm:creatCgsqspWorkFlow"; + opts.setAction("http://localhost/services/PlmXgxxService/" + methodName); + opts.setTimeOutInMilliSeconds(5000); + sc.setOptions(opts); + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMNamespace omNs = fac.createOMNamespace("http://localhost/services/PlmXgxxService", ""); // ռ + OMElement method = fac.createOMElement(methodName, omNs); // õķ + OMElement in0 = fac.createOMElement("plm:in0", omNs); // xml ǰû + + OMElement bak1 = fac.createOMElement("bean:bak1", omNs); + bak1.setText(center); + in0.addChild(bak1); + for(int i=2; i<6; i++) { + OMElement bak = fac.createOMElement("bean:bak" + i, omNs); + bak.setText(""); + in0.addChild(bak); + } + OMElement createrCode = fac.createOMElement("bean:createrCode", omNs); + createrCode.setText("A2207"); + in0.addChild(createrCode); + + OMElement item = fac.createOMElement("bean:item", omNs); + for(int i=0; i" + + xml + + ""; + System.out.println("address:"+address); + PostMethod postMethod = new PostMethod(address); + byte[] b = soapRequestData.getBytes("utf-8"); + InputStream is = new ByteArrayInputStream(b, 0, b.length); + RequestEntity re = new InputStreamRequestEntity(is, b.length, "text/xml; charset=utf-8"); + postMethod.setRequestEntity(re); + + HttpClient httpClient = new HttpClient(); + int statusCode = httpClient.executeMethod(postMethod); + soapRequestData = postMethod.getResponseBodyAsString(); + System.out.println("soapRequestData:"+soapRequestData); + + //TODO + // 200˵ + + soapRequestData = soapRequestData.replaceAll("<", "<").replaceAll(">", ">"); + soapRequestData = soapRequestData.substring(soapRequestData.indexOf(""), soapRequestData.indexOf("")+10).replaceAll("ns1:", ""); + return statusCode+"&&"+soapRequestData; + } + + private void log() { + SqlUtil.getSqlserverConnection("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://"+dbinfo[3]+":1433;DatabaseName="+dbinfo[2], + dbinfo[0], dbinfo[1]); + StringBuilder sql = new StringBuilder("insert into OA_LOG values('").append(logs[0]).append("','").append(logs[1]).append("','").append(logs[2]) + .append("','").append(logs[3]).append("','").append(logs[4]).append("','").append(logs[5]).append("','").append(logs[6]).append("','").append(logs[7]) + .append("')"); + System.out.println("sql:"+sql); + SqlUtil.update(sql.toString()); + SqlUtil.freeAll(); + } + +} diff --git a/src/com/connor/ldy/oa/SendDocumentToMESHandler.java b/src/com/connor/ldy/oa/SendDocumentToMESHandler.java new file mode 100644 index 0000000..a0b1b5e --- /dev/null +++ b/src/com/connor/ldy/oa/SendDocumentToMESHandler.java @@ -0,0 +1,70 @@ +package com.connor.ldy.oa; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +//import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class SendDocumentToMESHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("SendDocumentToMESHandler"); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + Date start = new Date(); + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent[] targets = app.getTargetComponents(); + ArrayList opts = new ArrayList<>(); + for(String n : new String[] { "LD_PLM2MES_DocDesign_URL", "LD_dbinfo", "Connor_DatasetTypeName" }) {//LD6_ProductRevision + String[] option = session.getPreferenceService().getStringValues(n); + if(option==null || option.length==0) { + MessageBox.post(desktop, "ѡ"+n+"òȷ", "ERROR", MessageBox.ERROR); + return null; + } + opts.add(option); + } + if(opts.get(1).length<2) { + MessageBox.post(desktop, "ѡLD_dbinfoòȷ", "ERROR", MessageBox.ERROR);//TC_Is_Represented_By + return null; + } + String[] options = session.getPreferenceService().getStringValues("LD_PLM2MES_DocDesign_Config"); + if(options==null || options.length==0) { + MessageBox.post(desktop, "ѡLD_PLM2MES_DocDesign_Configòȷ", "ERROR", MessageBox.ERROR); + return null; + } + HashMap omap = new HashMap<>(); + for(String s : options) { + String[] ss = s.split(":"); + omap.put(ss[0], ss[1].split(";")); + } + for(InterfaceAIFComponent target : targets) { + if(!omap.containsKey(target.getType())) { + MessageBox.post(desktop, "ѡ "+target+" ÷ΧڣѡִзĵݵMES!", "ERROR", MessageBox.ERROR); + return null; + } + } + + SendDocumentToMESOperation operation = new SendDocumentToMESOperation(session, opts, omap, targets, start); + session.queueOperation(operation); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ldy/oa/SendDocumentToMESOperation.java b/src/com/connor/ldy/oa/SendDocumentToMESOperation.java new file mode 100644 index 0000000..d6eab5c --- /dev/null +++ b/src/com/connor/ldy/oa/SendDocumentToMESOperation.java @@ -0,0 +1,305 @@ +package com.connor.ldy.oa; + +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; + +import org.json.JSONArray; +import org.json.JSONObject; + +import com.connor.ldy.util.SqlUtil; +import com.connor.ldy.util.TCUtil; +import com.squareup.okhttp.MediaType; +import com.squareup.okhttp.OkHttpClient; +import com.squareup.okhttp.Request; +import com.squareup.okhttp.RequestBody; +import com.squareup.okhttp.Response; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFOperation; +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.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.util.MessageBox; + +@SuppressWarnings("deprecation") +public class SendDocumentToMESOperation extends AbstractAIFOperation { + + private TCSession session; + private InterfaceAIFComponent[] targets; + private HashMap omap; + private ArrayList opts; + private String[] dbinfo; + private String[] logs; + private Date start; + + public SendDocumentToMESOperation(TCSession session, ArrayList opts, HashMap omap, InterfaceAIFComponent[] targets, Date start) { + this.session = session; + this.opts = opts; + this.omap = omap; + this.targets = targets; + this.start = start; + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + this.dbinfo = opts.get(1); + String[] urlos = opts.get(0); + this.logs = new String[] { "MES_006", "ĵݴ", "MES", "PLM", "", "", "", + String.format("%tF", start)+" "+String.format("%tT", start) }; + TCUserService userservice = session.getUserService(); + JSONArray json = new JSONArray(); + StringBuilder ids = new StringBuilder(""); + HashMap revs = new HashMap<>(); + for(InterfaceAIFComponent c : targets) { + TCComponentItemRevision rev = (TCComponentItemRevision) c; + ids.append(",").append(rev.getProperty("item_id")); +// HashMap files = new HashMap<>(); + JSONArray files = new JSONArray(); +// StringBuilder url = new StringBuilder(""); + for(AIFComponentContext dc : rev.getChildren("IMAN_specification")) { + if(!(dc.getComponent() instanceof TCComponentDataset)) + continue; + TCComponentDataset dataset = (TCComponentDataset) dc.getComponent(); + String type = dataset.getType(); + for(String s : opts.get(2)) { + String[] ss = s.split("="); + if(!type.equals(ss[0])) + continue; + File file = dataset.getTcFiles()[0].getFile(System.getProperty("java.io.tmpdir")); + String id = rev.getProperty("item_id"); + String name = file.getName(); + String saveName = dataset.getProperty("object_name"); + if(name.indexOf(".")>0) { + String last = name.substring(name.lastIndexOf(".")); + if(!saveName.endsWith(last)) + saveName += last; + } + saveName = userservice.call("DownloadDataset", new Object[] { dataset.getUid(), ss[1], ss[2], + urlos[1]+"\\"+id+"\\"+saveName }).toString(); + System.out.println("saveName:" + saveName); + if(saveName.startsWith("@@")) { + saveName = saveName.substring(saveName.indexOf("@@")+2); + JSONObject fj = new JSONObject(); + fj.put("FILEURL", urlos[2] + id+"\\"+ saveName); + fj.put("FILENAME", saveName); + files.put(fj); + }else { + throw new Exception(dataset+" ļس"+saveName); + } + break; + } + } + String ld6_docdesignSyncMES = rev.getProperty("ld6_docdesignSyncMES"); + TCComponentItem item = rev.getItem(); + TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev); + String[] options = omap.get(rev.getType()); + String relation = ""; + for(String option : options) { + String[] ops = option.split("=")[1].split("\\."); + if(ops.length > 2) { + relation = ops[0]; + break; + } + } + if(relation.isEmpty()) { + JSONObject js = new JSONObject(new LinkedHashMap<>()); + if(ld6_docdesignSyncMES.isEmpty() || ld6_docdesignSyncMES.equals("ʧ")) { + js.put("STATS", "I"); + revs.put(rev, "I"); + }else if(ld6_docdesignSyncMES.equals("ɹ") || ld6_docdesignSyncMES.equals("ʧ")) { + js.put("STATS", "U"); + revs.put(rev, "U"); + } + for(String option : options) { + String[] ops = option.split("="); + String[] opss = ops[1].split("\\."); + if(opss[0].equals("item")) { + js.put(ops[0], item.getProperty(opss[1])); + }else if(opss[0].equals("rev")) { + js.put(ops[0], rev.getProperty(opss[1])); + }else if(opss[0].equals("form")) { + js.put(ops[0], form.getProperty(opss[1])); + } + } + js.put("FILE", files); + json.put(js); + continue; + } + //TODO ================================================================================================ + TCComponentItemRevision crev = null; + TCComponentItem citem = null; + TCComponentForm cform = null; + AIFComponentContext[] cs = TCUtil.getPseudoFolder(rev, relation).getChildren(); + boolean down = true; + for(AIFComponentContext ch : cs) { + if(!(ch.getComponent() instanceof TCComponentItemRevision)) + continue; + crev = (TCComponentItemRevision) ch.getComponent(); + citem = crev.getItem(); + cform = TCUtil.getItemRevisionMasterForm(crev); + LinkedHashMap map = new LinkedHashMap<>(); + if(ld6_docdesignSyncMES.isEmpty() || ld6_docdesignSyncMES.equals("ʧ")) { + map.put("STATS", "I"); + revs.put(rev, "I"); + }else if(ld6_docdesignSyncMES.equals("ɹ") || ld6_docdesignSyncMES.equals("ʧ")) { + map.put("STATS", "U"); + revs.put(rev, "U"); + } +// map.put("aa", 1); + for(String option : options) { + String[] ops = option.split("="); + String[] opss = ops[1].split("\\."); +// System.out.println("opss:"+Arrays.toString(opss)); + if(opss.length > 2) { + if(opss[1].equals("item")) { + map.put(ops[0], citem.getProperty(opss[2])); + }else if(opss[1].equals("rev")) { + map.put(ops[0], crev.getProperty(opss[2])); + }else if(opss[1].equals("form")) { + map.put(ops[0], cform.getProperty(opss[2])); + } + }else { + if(opss[0].equals("item")) { + map.put(ops[0], item.getProperty(opss[1])); + }else if(opss[0].equals("rev")) { + map.put(ops[0], rev.getProperty(opss[1])); + }else if(opss[0].equals("form")) { + map.put(ops[0], form.getProperty(opss[1])); + } + } + } + map.put("FILE", files); +// for(String s : map.keySet()) +// System.out.println("map:"+s); + JSONObject js = new JSONObject(map); +// System.out.println("js:"+js.toString()); + json.put(js); + down = false; + } + if(down) { + LinkedHashMap map = new LinkedHashMap<>(); + if(ld6_docdesignSyncMES.isEmpty() || ld6_docdesignSyncMES.equals("ʧ")) { + map.put("STATS", "I"); + revs.put(rev, "I"); + }else if(ld6_docdesignSyncMES.equals("ɹ") || ld6_docdesignSyncMES.equals("ʧ")) { + map.put("STATS", "U"); + revs.put(rev, "U"); + } +// map.put("aa", 1); + for(String option : options) { + String[] ops = option.split("="); + String[] opss = ops[1].split("\\."); +// System.out.println("opss:"+Arrays.toString(opss)); + if(opss.length > 2) { + map.put(ops[0], ""); + }else { + if(opss[0].equals("item")) { + map.put(ops[0], item.getProperty(opss[1])); + }else if(opss[0].equals("rev")) { + map.put(ops[0], rev.getProperty(opss[1])); + }else if(opss[0].equals("form")) { + map.put(ops[0], form.getProperty(opss[1])); + } + } + } + map.put("FILE", files); +// for(String s : map.keySet()) +// System.out.println("map:"+s); + JSONObject js = new JSONObject(map); +// System.out.println("js:"+js.toString()); + json.put(js); + } + } + logs[4] = ids.substring(1); + logs[5] = json.toString(); + System.out.println("json:"+logs[5]); + + String re = send(json.toString(), urlos[0]); + logs[6] = re; + System.out.println("re"+ re); + //TODO + JSONObject parseObject = new JSONObject(re); +// int code = (int) parseObject.get("code"); + int status = (int) parseObject.get("status"); + + if(status == 0) { + boolean success = (boolean) parseObject.get("success"); + String message = (String) parseObject.get("msg"); + if(!success) { + log(); + for(TCComponentItemRevision rev : revs.keySet()) { + if(revs.get(rev).equals("U")) + rev.setProperty("ld6_docdesignSyncMES", "ʧ"); + else + rev.setProperty("ld6_docdesignSyncMES", "ʧ"); + } + MessageBox.post(AIFUtility.getActiveDesktop(), "쳣ؽ"+message, "ʾ", MessageBox.ERROR); + return; + } + }else { + log(); + for(TCComponentItemRevision rev : revs.keySet()) { + if(revs.get(rev).equals("U")) + rev.setProperty("ld6_docdesignSyncMES", "ʧ"); + else + rev.setProperty("ld6_docdesignSyncMES", "ʧ"); + } + MessageBox.post(AIFUtility.getActiveDesktop(), "쳣ţ"+status+"رģ"+re, "ʾ", MessageBox.ERROR); + return; + } + for(TCComponentItemRevision rev : revs.keySet()) { + rev.setProperty("ld6_docdesignSyncMES", "ɹ"); + } + log(); + MessageBox.post(desktop, "ĵݴMESɣ", "INFO", MessageBox.INFORMATION); + } catch (Exception e) { + e.printStackTrace(); + logs[6] = logs[6] + e.getMessage(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + log(); + } + } + + private String send(String json, String url) throws Exception {//TODO + /**/ + OkHttpClient client = new OkHttpClient(); +// MediaType mediaType = MediaType.parse("application/ison"); + MediaType mediaType = MediaType.parse("application/json;charset=UTF-8"); + RequestBody body = RequestBody.create(mediaType,json); +// System.out.printIn("token==>"+token); + Request request = new Request.Builder().url(url) + .method("POST", body) +// addHeader("Authorization""Bearer"+token)addHeader("send""PLM")addHeader("ET AUTH TYPE""JWT") +// addHeader("ET AUTH TOKEN"token) +// addHeader("transID"getDate1()) + .addHeader("Content-Type", "application/json") + .build(); + Response response = client.newCall(request).execute(); +// System.outprintIn(response.body().string()); +// JSONObject parseObject = JSONObject.parseObject(response.body().string()); + return response.body().string(); +// return "{\"code\":300,\"success\":true,\"data\":\"\",\"msg\":\"ɹ\",\"status\":0}"; + } + + private void log() { + SqlUtil.getSqlserverConnection("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://"+dbinfo[3]+":1433;DatabaseName="+dbinfo[2], + dbinfo[0], dbinfo[1]); + long time = (System.nanoTime()/1000000 - start.getTime())/1000; + StringBuilder sql = new StringBuilder("insert into OA_LOG values('").append(logs[0]).append("','").append(logs[1]).append("','").append(logs[2]) + .append("','").append(logs[3]).append("','").append(logs[4]).append("','").append(logs[5]).append("','").append(logs[6]) + .append("','").append(logs[7]).append("',").append(time).append(")"); + System.out.println("sql:"+sql); + SqlUtil.update(sql.toString()); + SqlUtil.freeAll(); + } +} diff --git a/src/com/connor/ldy/oa/SendECRtoOAHandler.java b/src/com/connor/ldy/oa/SendECRtoOAHandler.java new file mode 100644 index 0000000..5afb523 --- /dev/null +++ b/src/com/connor/ldy/oa/SendECRtoOAHandler.java @@ -0,0 +1,83 @@ +package com.connor.ldy.oa; + +import java.util.Arrays; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentPseudoFolder; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class SendECRtoOAHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("SendECRtoOAHandler"); +// new Thread() { +// public void run() { +// } +// }.start(); + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent target = app.getTargetComponent(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + if(target instanceof TCComponentPseudoFolder) { + System.out.println("type:"+((TCComponentPseudoFolder)target).getDefaultPasteRelation()); + System.out.println("parent:"+((TCComponentPseudoFolder)target).getReferenceProperty("owning_object")); + } + if(target instanceof TCComponentBOMLine) { +// TCComponentBOMLine line = (TCComponentBOMLine) target; +// TCComponentBOMLine parent = line.parent(); +// System.out.println("parent:"+parent.getChildrenCount()); +// TCComponentItemRevision rev = line.getItemRevision(); +// line.cut(); +// parent.add(rev.getItem(), rev, null, false); +// return null; + } + if(!(target instanceof TCComponentItemRevision)) { + MessageBox.post(desktop, "ѡ뵥汾д", "ERROR", MessageBox.ERROR); + return null; + } + String[] dbinfo = session.getPreferenceService().getStringValues("LD_dbinfo"); + if(dbinfo==null || dbinfo.length<2) { + MessageBox.post(desktop, "ѡLD_dbinfoòȷ", "ERROR", MessageBox.ERROR); + return null; + } + String[] datasets = session.getPreferenceService().getStringValues("Connor_DatasetTypeName"); + if(datasets==null || datasets.length==0) { + MessageBox.post(desktop, "ѡConnor_DatasetTypeNameòȷ", "ERROR", MessageBox.ERROR); + return null; + } + String[] options = session.getPreferenceService().getStringValues("Connor_SendECRtoOA"); + if(options==null || options.length<2) { + MessageBox.post(desktop, "ѡConnor_SendECRtoOAòȷ", "ERROR", MessageBox.ERROR); + return null; + } + String[] types = options[0].split("\\|"); + TCComponentItemRevision rev = (TCComponentItemRevision)target; + System.out.println("rev:"+rev.getType()+"=="+Arrays.toString(types)); + if(!rev.isTypeOf(types)) { + MessageBox.post(desktop, "ѡ뵥汾д", "ERROR", MessageBox.ERROR); + return null; + } + + SendECRtoOAOperation operation = new SendECRtoOAOperation(session, dbinfo, options, datasets, rev); + session.queueOperation(operation); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ldy/oa/SendECRtoOAOperation.java b/src/com/connor/ldy/oa/SendECRtoOAOperation.java new file mode 100644 index 0000000..fb392d6 --- /dev/null +++ b/src/com/connor/ldy/oa/SendECRtoOAOperation.java @@ -0,0 +1,266 @@ +package com.connor.ldy.oa; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.util.Date; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.InputStreamRequestEntity; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.RequestEntity; +import org.dom4j.Document; +import org.dom4j.DocumentHelper; + +import com.connor.ldy.util.SqlUtil; +import com.connor.ldy.util.TCUtil; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.util.MessageBox; + +@SuppressWarnings("deprecation") +public class SendECRtoOAOperation extends AbstractAIFOperation { + + private TCSession session; + private TCComponentItemRevision target; + private String[] options; + private String[] datasets; + private String[] dbinfo; + private String[] logs; + private long start; + + public SendECRtoOAOperation(TCSession session, String[] dbinfo, String[] options, String[] datasets, TCComponentItemRevision target) { + this.session = session; + this.dbinfo = dbinfo; + this.options = options; + this.datasets = datasets; + this.target = target; + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + start = new Date().getTime()/1000; + this.logs = new String[] { "OA_003", "洦", "OA", "PLM", target.getProperty("item_id"), "", "", + String.format("%tF", new Date())+" "+String.format("%tT", new Date()) }; +// StringBuilder json = new StringBuilder("{"); + TCComponentItem item = target.getItem(); + TCComponentForm form = TCUtil.getItemRevisionMasterForm(target); + /*for(int i=1; i files = new ArrayList<>(); + StringBuilder url = new StringBuilder(""); + for(AIFComponentContext c : target.getChildren("IMAN_specification")) { + if(!(c.getComponent() instanceof TCComponentDataset)) + continue; + TCComponentDataset dataset = (TCComponentDataset) c.getComponent(); + String type = dataset.getType(); + for(String s : datasets) { + String[] ss = s.split("="); + if(type.equals(ss[0])) { + File file = dataset.getTcFiles()[0].getFile(System.getProperty("java.io.tmpdir")); + String id = item.getProperty("item_id"); + String name = file.getName(); + String last = name.substring(name.lastIndexOf(".")); + String saveName = dataset.getProperty("object_name"); + if(!saveName.endsWith(last)) + saveName += last; + saveName = userservice.call("DownloadDataset", new Object[] { dataset.getUid(), ss[1], ss[2], + options[2]+"\\"+id+"\\"+saveName }).toString(); + System.out.println("saveName:" + saveName); + if(saveName.contains("@@")) { + saveName = saveName.substring(saveName.indexOf("@@")+2); + } + url.append("|").append(options[3] + id+"\\"+ saveName); + break; + } + } + /*InputStream fileInputStream = null; + try { + fileInputStream = new FileInputStream(file); +// boolean result = FTPTools.upload( "192.168.1.182", 21, "administrator", "1", "/", fileInputStream, saveName); +// System.out.println("result:"+result); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return; + }finally { + if(fileInputStream != null) + fileInputStream.close(); + }*/ + } + + ServiceClient sc = new ServiceClient(); + Options opts = new Options(); + EndpointReference end = new EndpointReference(options[1]);//"http://10.10.22.18:9089/services/PlmXgxxService" + opts.setTo(end); + String methodName = "plm:creatPlmGzpspWorkFlow"; + opts.setAction("http://localhost/services/PlmXgxxService/" + methodName); + opts.setTimeOutInMilliSeconds(5000); + sc.setOptions(opts); + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMNamespace omNs = fac.createOMNamespace("http://localhost/services/PlmXgxxService", ""); // ռ + OMElement method = fac.createOMElement(methodName, omNs); // õķ + OMElement in0 = fac.createOMElement("plm:in0", omNs); // xml ǰû +// in0.setText(target.toString()); + for(int i=4; i" + + xml + + ""; + System.out.println("address:"+address); + PostMethod postMethod = new PostMethod(address); + byte[] b = soapRequestData.getBytes("utf-8"); + InputStream is = new ByteArrayInputStream(b, 0, b.length); + RequestEntity re = new InputStreamRequestEntity(is, b.length, "text/xml; charset=utf-8"); + postMethod.setRequestEntity(re); + + HttpClient httpClient = new HttpClient(); + int statusCode = httpClient.executeMethod(postMethod); + soapRequestData = postMethod.getResponseBodyAsString(); + System.out.println("soapRequestData:"+soapRequestData); + + //TODO + // 200˵ + + soapRequestData = soapRequestData.replaceAll("<", "<").replaceAll(">", ">"); + soapRequestData = soapRequestData.substring(soapRequestData.indexOf(""), soapRequestData.indexOf("")+10) + .replaceAll("ns1:", ""); + return statusCode+"&&"+soapRequestData; + } + + private String getDateProp(TCComponent comp, String prop) throws Exception { + Date date = comp.getDateProperty(prop); + if(date==null) + return ""; + return String.format("%tF", date); + } + + private void log() { + SqlUtil.getSqlserverConnection("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://"+dbinfo[3]+":1433;DatabaseName="+dbinfo[2], + dbinfo[0], dbinfo[1]); + long end = new Date().getTime()/1000; + StringBuilder sql = new StringBuilder("insert into OA_LOG values('").append(logs[0]).append("','").append(logs[1]).append("','").append(logs[2]) + .append("','").append(logs[3]).append("','").append(logs[4]).append("','").append(logs[5]).append("','").append(logs[6]) + .append("','").append(logs[7]).append("',").append(end-start).append(")"); + System.out.println("sql:"+sql); + SqlUtil.update(sql.toString()); + SqlUtil.freeAll(); + } +} diff --git a/src/com/connor/ldy/process/CheckHeaderCellRenderer.java b/src/com/connor/ldy/process/CheckHeaderCellRenderer.java new file mode 100644 index 0000000..1635ae5 --- /dev/null +++ b/src/com/connor/ldy/process/CheckHeaderCellRenderer.java @@ -0,0 +1,66 @@ +package com.connor.ldy.process; + +import java.awt.Component; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.UIManager; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.JTableHeader; +import javax.swing.table.TableCellRenderer; + +public class CheckHeaderCellRenderer implements TableCellRenderer { + DefaultTableModel tableModel; + JTableHeader tableHeader; + final JCheckBox selectBox; + + public CheckHeaderCellRenderer(final JTable table, boolean select) { + this.tableModel = (DefaultTableModel) table.getModel(); + this.tableHeader = table.getTableHeader(); + selectBox = new JCheckBox(tableModel.getColumnName(0)); + selectBox.setSelected(select); + tableHeader.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() > 0) { + // ѡ + int selectColumn = tableHeader.columnAtPoint(e.getPoint()); + if (selectColumn == 0) { + boolean value = !selectBox.isSelected(); + selectBox.setSelected(value); +// tableModel.selectAllOrNull(value); + for(int i=0; i compMap; + private String queryName; + private Vector procedureOptions; +// private Vector procedures; +// private Vector> proceduresVec; + private Vector options; + private Map> lovMap; +// private Map>> tableMap; + private Map proceduresMap; + private Vector clearProps; + + public MEOPBorrowDialog(TCSession session, TCComponentBOMLine targetLine, Vector options) throws Exception { + super(AIFUtility.getActiveDesktop()); + this.session = session; + this.targetLine = targetLine; + this.options = options; + compMap = new HashMap<>(); + lovMap = new HashMap<>(); +// tableMap = new HashMap<>(); + proceduresMap = new HashMap<>(); + this.procedureOptions = new Vector<>(); + this.clearProps = new Vector<>(); +// tableMap = new HashMap<>(); + setTitle(""); + + String[] propOptions = options.get(2); + Map typeMap = new HashMap<>(); + for(String s : propOptions) { + String[] ss = s.split("="); + typeMap.put(ss[0], ss[1]); + } + propOptions = options.get(3); + for(String s : propOptions) { + clearProps.add(s.split("\\.")); + } +// JPanel msgPanel = new JPanel(new GridLayout(0,5,2,5)); + JPanel msgPanel = new JPanel(new FlowLayout()); +// String[] searchOptions = options.get(0); + String[] searchOptions = new String[] { "=1", "=2", "=2" }; + queryName = options.get(0)[0]; + final AbstractAIFDialog dialog = this; + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues"); + for(String s : searchOptions) { + if(!s.contains("=")) + continue; + String[] split = s.split("="); + JLabel label = new JLabel(split[0], SwingConstants.RIGHT); + label.setPreferredSize(new Dimension(80, 23)); +// label.setHorizontalTextPosition(JLabel.RIGHT); +// JPanel propPanel = new JPanel(new BorderLayout()); + JPanel propPanel = new JPanel(new BorderLayout()); + propPanel.add(BorderLayout.WEST, label); + if(split[1].equals("1")) { + JComboBox combo = new JComboBox<>(); + combo.setPreferredSize(new Dimension(118, 23)); + if(split.length==2) { + combo.addItem(""); + for (String v : typeMap.keySet()) { + combo.addItem(v); + } + lovMap.put(split[0], typeMap); + }else if(split[2].indexOf(";")>0) { + String[] value = split[2].split(";"); + combo.addItem(""); + for(String v : value) + combo.addItem(v); + }else { + TCComponentListOfValues[] lovs = lovType.find(split[2]); + if (lovs != null && lovs.length > 0) { + ListOfValuesInfo lovInfo = lovs[0].getListOfValues(); + String[] code = lovInfo.getStringListOfValues(); + String[] name = lovInfo.getLOVDisplayValues(); + Map lovVal = new HashMap<>(); + if (code != null && name != null) { + for (int i = 0; i < code.length; i++) { + lovVal.put(name[i], code[i]); + combo.addItem(name[i]); + } + } + lovMap.put(split[0], lovVal); +// bean.lovList = TCUtil.setAutoComplete(bean, name); + }else + throw new Exception("δҵ"+split[2]+"ѡ"); + } + propPanel.add(BorderLayout.CENTER, combo); + msgPanel.add(propPanel); + compMap.put(split[0], combo); + }else if(split[1].equals("2")) { + JTextField field = new JTextField(); + field.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, field); + msgPanel.add(propPanel); + compMap.put(split[0], field); + }else if(split[1].equals("3")) { + PropertyDateComponent dateBtn = new PropertyDateComponent(); + dateBtn.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, dateBtn); + msgPanel.add(propPanel); + compMap.put(split[0], dateBtn); + }else if(split[1].equals("4")) { + final JTextField field = new JTextField(); + field.setEditable(false); + field.setPreferredSize(new Dimension(60, 23)); + JButton userBtn = new JButton("ѡ"); + userBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + new SelectUserDialog(field, true).showDialog(); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(dialog, ":"+e.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + userBtn.setPreferredSize(new Dimension(56, 23)); + propPanel.add(BorderLayout.CENTER, field); + propPanel.add(BorderLayout.EAST, userBtn); + msgPanel.add(propPanel); + compMap.put(split[0], field); + } + } + searchBtn = new JButton("ѯ"); + exportBtn = new JButton(""); + JPanel btnPanel = new JPanel(new FlowLayout()); + btnPanel.add(searchBtn); + btnPanel.add(exportBtn); + JPanel topPanel = new JPanel(new BorderLayout()); + topPanel.add(BorderLayout.WEST, msgPanel); + topPanel.add(BorderLayout.EAST, btnPanel); + + //TODO processTable + String[] processOption = options.get(0); + String[] tableHeader = new String[processOption.length]; + tableHeader[0] = "ѡ"; + for(int i=1; i getColumnClass(int column) { + if (column==0) { + return Boolean.class; + } + return super.getColumnClass(column); + } + }; +// processTable.getTableHeader().setReorderingAllowed(false); + processTable.setFillsViewportHeight(true); +// processTable.setEnabled(false); + processTable.setEnabled(true); +// processTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); + processTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + processTable.setModel(processModel); + processTable.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(processTable, false)); + processTable.getTableHeader().setReorderingAllowed(false); + TableColumnModel pColModel = processTable.getColumnModel(); + for(int i=1; i0) { + for(int i=processModel.getRowCount(); i>0; i--) + processModel.removeRow(i-1); + } + Vector keyV = new Vector<>(); + Vector valueV = new Vector<>(); + for(Entry e : compMap.entrySet()) { + JComponent c = e.getValue(); + String text = ""; + if(c instanceof JTextField) + text = ((JTextField)c).getText(); + else if(c instanceof PropertyDateComponent) + text = ((PropertyDateComponent)c).getDateViewModel().getDateString(); + else { + text = ((JComboBox)c).getSelectedItem().toString(); + if(!text.isEmpty() && lovMap.containsKey(e.getKey())) { + text = lovMap.get(e.getKey()).get(text); + } + } + if(text!=null && !text.isEmpty()) { +// if(e.getKey().equals("ID")) +// text += "GY"; + keyV.add(e.getKey()); + valueV.add(text); + } + } + TCComponent[] result = TCUtil.query(session, queryName, keyV, valueV); + System.out.println("result:"+result.length); + if(result.length==0) { + MessageBox.post(dialog, "ûзĹѯ", "ERROR", MessageBox.ERROR); + return; + } + result = TCUtil.TCsort(result, new int[] { 1, -1 }, "item_id", "item_revision_id"); +// TCComponentBOPWindowType bomWinType = (TCComponentBOPWindowType) session.getTypeComponent("BOPWindow"); +// TCComponentBOPWindow window = (TCComponentBOPWindow) bomWinType.createBOPWindow(null); + + for(int i=0; i v = new Vector<>(); + v.add(false); + TCComponentItemRevision meprocess = (TCComponentItemRevision) result[i]; + TCComponentItem item = meprocess.getItem(); + if(!(item instanceof TCComponentMEProcess) && !(item instanceof TCComponentMEOP)) + continue; + TCComponentForm form = TCUtil.getItemRevisionMasterForm(meprocess); + for(String[] prop : procedureOptions) { + if(prop[0].equals("item")) + v.add(item.getProperty(prop[1])); + else if(prop[0].equals("rev")) + v.add(meprocess.getProperty(prop[1])); + else + v.add(form.getProperty(prop[1])); + } + processModel.addRow(v); + proceduresMap.put(i, meprocess); + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(dialog, ""+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + exportBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + Map borrowMap = new HashMap<>(); + for(String s : options.get(1)) { +// String[] split = s.split("="); + borrowMap.put(s, "true"); + } + if(processTable.getRowCount()==0) + throw new Exception("Ϊգ޷"); + TCComponentItemType itemType; +// TCComponentItemRevision targetRev = targetLine.getItemRevision(); +// TCComponentForm targetForm = TCUtil.getItemRevisionMasterForm(targetRev); +// String revId = targetRev.getProperty("item_revision_id"); +// System.out.println("time1 " + (System.nanoTime() - time0) / 1000000); + int n = 0; + for(AIFComponentContext cs : targetLine.getChildren()) { + int no = Integer.parseInt(((TCComponentBOMLine)cs.getComponent()).getProperty("bl_sequence_no")); + if(no > n) + n = no; + } + if(n%10 != 0) + n = n/10*10 + 10; + else + n = n + 10; + for(int i=0; i0) + form.setProperty("ac5_OperationNumber", num*5+""); + System.out.println("copyProperty " + (System.nanoTime() - time0) / 1000000); + } + private String getProperty(String comp, String prop, TCComponent... comps) throws Exception { + if(comp.equals("rev")) + return comps[0].getProperty(prop); + else if(comp.equals("master")) + return comps[1].getProperty(prop); + else if(comp.equals("item")) + return comps[2].getProperty(prop); + else + return ""; + }*/ +} \ No newline at end of file diff --git a/src/com/connor/ldy/process/MEOPBorrowHandler.java b/src/com/connor/ldy/process/MEOPBorrowHandler.java new file mode 100644 index 0000000..20f729a --- /dev/null +++ b/src/com/connor/ldy/process/MEOPBorrowHandler.java @@ -0,0 +1,63 @@ +package com.connor.ldy.process; + +import java.util.Vector; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentMEProcess; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class MEOPBorrowHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("MEOPBorrowHandler"); + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + TCComponent target = (TCComponent)app.getTargetComponent(); + if(!(target instanceof TCComponentBOMLine)) { + MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); + return null; + } + if(((TCComponentBOMLine)target).parent() != null) { + MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); + return null; + } + TCComponentItem item = ((TCComponentBOMLine)target).getItem(); + if(!(item instanceof TCComponentMEProcess)) { + MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); + return null; + } + String[] prefs = new String[] { "Connor_NHL_GXJY_Process", "Connor_NHL_GYJY_Borrow", "Connor_NHL_GXJY_Type", "Connor_NHL_GXJY_Clear" }; + Vector options = new Vector<>(); + for(String s : prefs) { + String searchOptions[] = session.getPreferenceService().getStringValues(s); + if(searchOptions == null) { +// MessageBox.post(desktop, "ѡ"+s+"òȷ", "ERROR", MessageBox.ERROR); +// return null; + options.add(new String[] {}); + continue; + } + options.add(searchOptions); + } + new MEOPBorrowDialog(session, (TCComponentBOMLine)target, options); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ldy/process/MEOPReviseHandler.java b/src/com/connor/ldy/process/MEOPReviseHandler.java new file mode 100644 index 0000000..975b872 --- /dev/null +++ b/src/com/connor/ldy/process/MEOPReviseHandler.java @@ -0,0 +1,84 @@ +package com.connor.ldy.process; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.connor.ldy.util.TCUtil; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class MEOPReviseHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("MEOPReviseHandler"); + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + TCComponent target = (TCComponent)app.getTargetComponent(); + if(!(target instanceof TCComponentBOMLine)) { + MessageBox.post(desktop, "ڹBOMѡBOM޶", "ERROR", MessageBox.ERROR); + return null; + } + TCComponentBOMLine parent = ((TCComponentBOMLine)target).parent(); + if(parent==null) { + MessageBox.post(desktop, "ڹBOMѡBOM޶", "ERROR", MessageBox.ERROR); + return null; + } + String[] types = session.getPreferenceService().getStringValues("Connor_NHL_GXXD_GYType"); + if(types==null || types.length==0) { + MessageBox.post(desktop, "ѡConnor_NHL_GXXD_GYTypeòȷ", "ERROR", MessageBox.ERROR); + return null; + } + while(parent.parent()!=null) { + parent = parent.parent(); + } + String type = parent.getItem().getType(); + if(!TCUtil.contains(types, type)) { + MessageBox.post(desktop, "ڹBOMѡBOM޶", "ERROR", MessageBox.ERROR); + return null; + } + type = ((TCComponentBOMLine)target).getItem().getType(); +// if(!(item instanceof TCComponentMEOP)) { +// MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); +// return null; +// } + types = session.getPreferenceService().getStringValues("Connor_NHL_GXXD_GXType"); + if(types==null || types.length==0) { + MessageBox.post(desktop, "ѡConnor_NHL_GXXD_GXTypeòȷ", "ERROR", MessageBox.ERROR); + return null; + } + boolean no = true; + for(String s : types) { + if(s.equals(type)) { + no = false; + break; + } + } + if(no) { + MessageBox.post(desktop, "ѡIJǹͣ޶", "ERROR", MessageBox.ERROR); + return null; + } + types = session.getPreferenceService().getStringValues("Connor_NHL_GXXD_GBType"); + if(types==null || types.length==0) { + MessageBox.post(desktop, "ѡConnor_NHL_GXXD_GBTypeòȷ", "ERROR", MessageBox.ERROR); + return null; + } + MEOPReviseOperation operation = new MEOPReviseOperation(session, types, (TCComponentBOMLine) target); + session.queueOperation(operation); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ldy/process/MEOPReviseOperation.java b/src/com/connor/ldy/process/MEOPReviseOperation.java new file mode 100644 index 0000000..31ac150 --- /dev/null +++ b/src/com/connor/ldy/process/MEOPReviseOperation.java @@ -0,0 +1,59 @@ +package com.connor.ldy.process; + +import com.connor.ldy.util.TCUtil; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class MEOPReviseOperation extends AbstractAIFOperation { + + private TCSession session; + private TCComponentBOMLine target; + private String[] options; + + public MEOPReviseOperation(TCSession session, String[] options, TCComponentBOMLine target) { + this.session = session; + this.target = target; + this.options = options; + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + TCComponentBOMWindow window = target.window(); + TCComponentBOMWindow newwin = TCUtil.getWindow(session); + TCComponentItemRevision rev = target.getItemRevision(); + TCComponentItem item = target.getItem(); + TCComponentItemRevision newrev = rev.saveAs(null); + TCComponentBOMLine newline = newwin.setWindowTopLine(item, newrev, null, null); + for(AIFComponentContext child : newline.getChildren()) { + TCComponentBOMLine line = (TCComponentBOMLine) child.getComponent(); + TCComponentItem citem = line.getItem(); + String type = citem.getType(); + if(!TCUtil.contains(options, type)) + continue; + TCComponentItemRevision crev = line.getItemRevision(); + TCComponentItemRevision newac = crev.saveAs(null); + line.replace(citem, newac, null); + } + newwin.save(); + newwin.close(); + target.replace(item, newrev, null); + window.refresh(); + window.save(); + + MessageBox.post(desktop, "޶", "INFO", MessageBox.INFORMATION); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + } + } +} diff --git a/src/com/connor/ldy/process/ProcessBorrowDialog.java b/src/com/connor/ldy/process/ProcessBorrowDialog.java new file mode 100644 index 0000000..83aef3f --- /dev/null +++ b/src/com/connor/ldy/process/ProcessBorrowDialog.java @@ -0,0 +1,585 @@ +package com.connor.ldy.process; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.border.TitledBorder; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumnModel; + +import com.connor.ldy.util.SelectUserDialog; +import com.connor.ldy.util.TCUtil; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOPWindow; +import com.teamcenter.rac.kernel.TCComponentBOPWindowType; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCComponentMEOP; +import com.teamcenter.rac.kernel.TCComponentMEProcess; +import com.teamcenter.rac.kernel.TCComponentMEProcessRevision; +import com.teamcenter.rac.kernel.TCComponentPseudoFolder; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.stylesheet.PropertyDateComponent; +import com.teamcenter.rac.util.MessageBox; + +public class ProcessBorrowDialog extends AbstractAIFDialog { + private static final long serialVersionUID = 1L; + private TCSession session; + private TCComponentBOMLine targetLine; + private JButton searchBtn; + private JButton exportBtn; + private JTable impTable; + private DefaultTableModel impModel; + private JTable processTable; + private DefaultTableModel processModel; + private Map compMap; + private String queryName; + private Vector showOptions; + private Vector procedureOptions; + private Vector processVec; +// private Vector> proceduresVec; + private Vector options; + private Map> lovMap; + private Map>> tableMap; + private Map, TCComponentBOMLine> proceduresMap; + private Vector updateProps; + private Vector clearProps; + + public ProcessBorrowDialog(TCSession session, TCComponentBOMLine targetLine, Vector options) throws Exception { + super(AIFUtility.getActiveDesktop()); + this.session = session; + this.targetLine = targetLine; + this.options = options; + compMap = new HashMap<>(); + lovMap = new HashMap<>(); + tableMap = new HashMap<>(); + proceduresMap = new HashMap<>(); + this.showOptions = new Vector<>(); + this.procedureOptions = new Vector<>(); + this.processVec = new Vector<>(); + this.updateProps = new Vector<>(); + this.clearProps = new Vector<>(); +// tableMap = new HashMap<>(); + setTitle("ս"); + + String[] propOptions = options.get(3); + for(String s : propOptions) { + updateProps.add(s.split("\\.")); + } + propOptions = options.get(4); + for(String s : propOptions) { + clearProps.add(s.split("\\.")); + } +// JPanel msgPanel = new JPanel(new GridLayout(0,5,2,5)); + JPanel msgPanel = new JPanel(new FlowLayout()); +// String[] searchOptions = options.get(0); + String[] searchOptions = new String[] { "ID=2", "=2" }; + queryName = options.get(0)[0]; + final AbstractAIFDialog dialog = this; + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues"); + for(String s : searchOptions) { + if(!s.contains("=")) + continue; + String[] split = s.split("="); + JLabel label = new JLabel(split[0], SwingConstants.RIGHT); + label.setPreferredSize(new Dimension(80, 23)); +// label.setHorizontalTextPosition(JLabel.RIGHT); +// JPanel propPanel = new JPanel(new BorderLayout()); + JPanel propPanel = new JPanel(new BorderLayout()); + propPanel.add(BorderLayout.WEST, label); + if(split.length==3) { + JComboBox combo = new JComboBox<>(); + combo.setPreferredSize(new Dimension(118, 23)); + if(split[2].indexOf(";")>0) { + String[] value = split[2].split(";"); + combo.addItem(""); + for(String v : value) + combo.addItem(v); + }else { + TCComponentListOfValues[] lovs = lovType.find(split[2]); + if (lovs != null && lovs.length > 0) { + ListOfValuesInfo lovInfo = lovs[0].getListOfValues(); + String[] code = lovInfo.getStringListOfValues(); + String[] name = lovInfo.getLOVDisplayValues(); + Map lovVal = new HashMap<>(); + if (code != null && name != null) { + for (int i = 0; i < code.length; i++) { + lovVal.put(name[i], code[i]); + combo.addItem(name[i]); + } + } + lovMap.put(split[0], lovVal); +// bean.lovList = TCUtil.setAutoComplete(bean, name); + }else + throw new Exception("δҵ"+split[2]+"ѡ"); + } + propPanel.add(BorderLayout.CENTER, combo); + msgPanel.add(propPanel); + compMap.put(split[0], combo); + }else if(split[1].equals("2")) { + JTextField field = new JTextField(); + field.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, field); + msgPanel.add(propPanel); + compMap.put(split[0], field); + }else if(split[1].equals("3")) { + PropertyDateComponent dateBtn = new PropertyDateComponent(); + dateBtn.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, dateBtn); + msgPanel.add(propPanel); + compMap.put(split[0], dateBtn); + }else if(split[1].equals("4")) { + final JTextField field = new JTextField(); + field.setEditable(false); + field.setPreferredSize(new Dimension(60, 23)); + JButton userBtn = new JButton("ѡ"); + userBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + new SelectUserDialog(field, true).showDialog(); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(dialog, ":"+e.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + userBtn.setPreferredSize(new Dimension(56, 23)); + propPanel.add(BorderLayout.CENTER, field); + propPanel.add(BorderLayout.EAST, userBtn); + msgPanel.add(propPanel); + compMap.put(split[0], field); + } + } + searchBtn = new JButton("ѯ"); + exportBtn = new JButton(""); + JPanel btnPanel = new JPanel(new FlowLayout()); + btnPanel.add(searchBtn); + btnPanel.add(exportBtn); + JPanel topPanel = new JPanel(new BorderLayout()); + topPanel.add(BorderLayout.WEST, msgPanel); + topPanel.add(BorderLayout.EAST, btnPanel); + + String[] itemOptions = options.get(0); + String[] tableHeader = new String[itemOptions.length]; + tableHeader[0] = ""; + for(int i=1; i getColumnClass(int column) { + if (column==0) { + return Boolean.class; + } + return super.getColumnClass(column); + } + }; +// processTable.getTableHeader().setReorderingAllowed(false); + processTable.setFillsViewportHeight(true); +// processTable.setEnabled(false); + processTable.setEnabled(true); +// processTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); + processTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + processTable.setModel(processModel); + processTable.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(processTable, true)); + processTable.getTableHeader().setReorderingAllowed(false); + TableColumnModel pColModel = processTable.getColumnModel(); + for(int i=1; i0) { + for(int i=processModel.getRowCount(); i>0; i--) + processModel.removeRow(i-1); + } + if(tableMap.size()==0) + return; + int i = impTable.getSelectedRow(); + for(Vector vo : tableMap.get(i)) { + processModel.addRow(vo); + } + } + }); + searchBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + if(impModel.getRowCount()>0) { + for(int i=impModel.getRowCount(); i>0; i--) + impModel.removeRow(i-1); + } + if(processModel.getRowCount()>0) { + for(int i=processModel.getRowCount(); i>0; i--) + processModel.removeRow(i-1); + } + Vector keyV = new Vector<>(); + Vector valueV = new Vector<>(); + for(Entry e : compMap.entrySet()) { + JComponent c = e.getValue(); + String text = ""; + if(c instanceof JTextField) + text = ((JTextField)c).getText(); + else if(c instanceof PropertyDateComponent) + text = ((PropertyDateComponent)c).getDateViewModel().getDateString(); + else { + text = ((JComboBox)c).getSelectedItem().toString(); + if(lovMap.containsKey(e.getKey())) { + text = lovMap.get(e.getKey()).get(text); + } + } + if(text!=null && !text.isEmpty()) { + if(e.getKey().equals("ID")) + text += "GY"; + keyV.add(e.getKey()); + valueV.add(text); + } + } + TCComponent[] result = TCUtil.query(session, queryName, keyV, valueV); + System.out.println("result:"+result.length); + if(result.length==0) { + MessageBox.post(dialog, "ûзĹգѯ", "ERROR", MessageBox.ERROR); + return; + } + result = TCUtil.TCsort(result, new int[] { 1, -1 }, "item_id", "item_revision_id"); + TCComponentBOPWindowType bomWinType = (TCComponentBOPWindowType) session.getTypeComponent("BOPWindow"); + TCComponentBOPWindow window = (TCComponentBOPWindow) bomWinType.createBOPWindow(null); + for(int i=0; i v = new Vector<>(); + int num = impModel.getRowCount(); + v.add(num+1+""); + TCComponentMEProcessRevision meprocess = (TCComponentMEProcessRevision) result[i]; + TCComponentItem pitem = meprocess.getItem(); + TCComponentForm form = TCUtil.getItemRevisionMasterForm(meprocess); + for(String[] prop : showOptions) { + if(prop[0].equals("item")) + v.add(pitem.getProperty(prop[1])); + else if(prop[0].equals("rev")) + v.add(meprocess.getProperty(prop[1])); + else + v.add(form.getProperty(prop[1])); + } + processVec.add(meprocess); + impModel.addRow(v); + + TCComponentBOMLine ebom = window.setWindowTopLine(pitem, meprocess, null, null); + AIFComponentContext[] p = ebom.getChildren(); + Vector> vvo = new Vector<>(); + for(AIFComponentContext c : p) { + Vector vo = new Vector<>(); + vo.add(true); + TCComponentBOMLine procedure = (TCComponentBOMLine) c.getComponent(); + TCComponentItem pritem = procedure.getItem(); + if(!(pritem instanceof TCComponentMEProcess) && !(pritem instanceof TCComponentMEOP)) + continue; + TCComponentItemRevision prrev = procedure.getItemRevision(); + if(pritem instanceof TCComponentMEOP) + System.out.println(prrev+">>"+prrev.getReferenceProperty("root_activity").getReferenceListProperty("contents").length); + TCComponentForm prform = TCUtil.getItemRevisionMasterForm(prrev); + for(String[] prop : procedureOptions) { + if(prop[0].equals("item")) + vo.add(pritem.getProperty(prop[1])); + else if(prop[0].equals("rev")) + vo.add(prrev.getProperty(prop[1])); + else if(prop[0].equals("bom")) + vo.add(procedure.getProperty(prop[1])); + else + vo.add(prform.getProperty(prop[1])); + } + vvo.add(vo); + proceduresMap.put(vo, procedure); + } + tableMap.put(num, vvo); + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(dialog, ":"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + exportBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + Map borrowMap = new HashMap<>(); + for(String s : options.get(2)) { +// String[] split = s.split("="); + borrowMap.put(s, "true"); + } + if(processTable.getRowCount()==0) + throw new Exception("Ϊգ޷"); + TCComponentItemRevision targetRev = targetLine.getItemRevision(); + TCComponentItemRevision proRev = processVec.get(impTable.getSelectedRow()); + if(!targetRev.getType().equals(proRev.getType())) + throw new Exception("ѡͲͬ޷"); + TCComponentItemType itemType; + TCComponentForm targetForm = TCUtil.getItemRevisionMasterForm(targetRev); +// String revId = targetRev.getProperty("item_revision_id"); +// System.out.println("time1 " + (System.nanoTime() - time0) / 1000000); + int n = 0; + for(AIFComponentContext cs : targetLine.getChildren()) { + int no = Integer.parseInt(((TCComponentBOMLine)cs.getComponent()).getProperty("bl_sequence_no")); + if(no > n) + n = no; + } + if(n%10 != 0) + n = n/10*10 + 10; + else + n = n + 10; + + for(int i=0; i v = tableMap.get(impTable.getSelectedRow()).get(i); + TCComponentBOMLine p = proceduresMap.get(v); + TCComponentItemRevision procedure = p.getItemRevision(); + TCComponentItem pitem = procedure.getItem(); + String type = pitem.getType(); + itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(type); +// TCComponentItem newItem = itemType.create(itemType.getNewID(), revId, type, pitem.getProperty("object_name"), "", null); +// procedure.saveAsItem(arg0, arg1); + TCComponentItem newItem = procedure.saveAsItem(itemType.getNewID(), "A"); + TCComponentBOMLine newLine = targetLine.add(newItem, null); + TCComponentItemRevision newRev = newItem.getLatestItemRevision(); + newLine.setProperty("bl_sequence_no", n+""); + n += 10; +// copyProperty(p, newLine, num); + //TODO + TCComponentForm proForm = TCUtil.getItemRevisionMasterForm(proRev); + for(String[] ss : updateProps) { + if(ss[0].equals("rev")) { + copyProperty(proRev, targetRev, ss[1]); + }else if(ss[0].equals("master")) { + copyProperty(proForm, targetForm, ss[1]); + } + } + TCComponentForm newForm = TCUtil.getItemRevisionMasterForm(newRev); + for(String[] ss : clearProps) { + if(ss[0].equals("rev")) { + newRev.setProperty(ss[1], ""); + }else if(ss[0].equals("master")) { + newForm.setProperty(ss[1], ""); + }else if(ss[0].equals("item")) { + newItem.setProperty(ss[1], ""); + } + } +// num++; + AIFComponentContext[] children = newLine.getChildren(); + for(AIFComponentContext c : children) { +// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000); +// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000); + TCComponentBOMLine child = (TCComponentBOMLine) c.getComponent(); + TCComponentItem subitem = child.getItem(); + String subtype = subitem.getType(); +// System.out.println("child" + child +" "+ (subitem instanceof TCComponentMEOP)); + if(subitem instanceof TCComponentMEOP) { +// TCComponentItem newOpitem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null); +// TCComponentBOMLine newOpline = newLine.add(newSubItem, null); +// copyProperty(child, child, 0); + itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(subtype); + TCComponentItem newSubItem = child.getItemRevision().saveAsItem(itemType.getNewID(), ""); + TCComponentItemRevision newSubRev = newSubItem.getLatestItemRevision(); + child.replace(newSubItem, newSubRev, null); + }else if(borrowMap.containsKey(subtype)) { + if(borrowMap.get(subtype).toLowerCase().equals("false")){ + TCComponentItem newsubItem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null); +// newLine.add(newsubItem, null); + child.replace(newsubItem, newsubItem.getLatestItemRevision(), null); + } + }else { + child.cut(); + } +// else +// newLine.add(subitem, null); + } + } + /*List viewParts = PlatformHelper.getAllViewParts(); + for(Object view : viewParts) { + if(view==null || !(view instanceof CompatibilityView)) + continue; + IViewPart v = ((CompatibilityView)view).getView(); +// System.out.println("ProcessPropertyView "+((CompatibilityPart)view).ENABLE_DEPENDENCY_INJECTION_FOR_E3_PARTS); + if(!(v instanceof ProcessPropertyView)) + continue; + ProcessPropertyView pv = (ProcessPropertyView)v; + Field field = pv.getClass().getDeclaredField("panel"); + field.setAccessible(true); + Object editor = field.get(pv); +// if(editor instanceof ProcessPropertyEditor) +// ((ProcessPropertyEditor) editor).updateSelection(targetLine); + Field pfield = ((ProcessPropertyEditor) editor).getClass().getDeclaredField("propPanel"); + pfield.setAccessible(true); + Object panel = pfield.get(((ProcessPropertyEditor) editor)); + ((PropertyPanel)panel).loadData(); + }*/ + MessageBox.post(dialog, "ɹ", "ʾ", MessageBox.INFORMATION); + dispose(); + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(dialog, ""+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + } + private void copyProperty(TCComponent a, TCComponent b, String prop) throws Exception { + TCProperty property = a.getTCProperty(prop); + if(property==null) { + System.out.println(a+"δҵԣ" + prop); + return; + } + if(b.getTCProperty(prop)==null) { + System.out.println(b+"δҵԣ" + prop); + return; + } + int type = property.getPropertyType(); +// System.out.println(prop+">>" + type); + if(type==TCProperty.PROP_untyped_relation || type==TCProperty.PROP_untyped_reference){ + TCComponentPseudoFolder folder = TCUtil.getPseudoFolder(a, prop); +// System.out.println("folder:" + folder); + TCComponent[] cps; + if(folder == null) { + cps = property.getReferenceValueArray(); + }else { + AIFComponentContext[] cxs = folder.getChildren(); + cps = new TCComponent[cxs.length]; + for(int i=0; i>" + b+"==" + b.getTCProperty(prop)); + } + + /*private void copyProperty(TCComponentBOMLine p, TCComponentBOMLine toLine, int num) throws Exception { + System.out.println("copyProperty:"+p+" copyProperty " + (System.nanoTime() - time0) / 1000000); + if(p.parent()!=null) { + for(String s : propVecs.get(0)) { + toLine.setProperty(s, ""); + } + } + TCComponentItemRevision rev = toLine.getItemRevision(); + for(String s : propVecs.get(1)) { + rev.setProperty(s, ""); + } + + TCComponentItem item = rev.getItem(); + for(String s : propVecs.get(2)) { + item.setProperty(s, ""); + } + + TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev); + for(String s : propVecs.get(3)) { + form.setProperty(s, ""); + } + if(num>0) + form.setProperty("ac5_OperationNumber", num*5+""); + System.out.println("copyProperty " + (System.nanoTime() - time0) / 1000000); + } + private String getProperty(String comp, String prop, TCComponent... comps) throws Exception { + if(comp.equals("rev")) + return comps[0].getProperty(prop); + else if(comp.equals("master")) + return comps[1].getProperty(prop); + else if(comp.equals("item")) + return comps[2].getProperty(prop); + else + return ""; + }*/ +} \ No newline at end of file diff --git a/src/com/connor/ldy/process/ProcessBorrowHandler.java b/src/com/connor/ldy/process/ProcessBorrowHandler.java new file mode 100644 index 0000000..68026b0 --- /dev/null +++ b/src/com/connor/ldy/process/ProcessBorrowHandler.java @@ -0,0 +1,48 @@ +package com.connor.ldy.process; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class ProcessBorrowHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("ProcessBorrowHandler"); + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + TCComponent target = (TCComponent)app.getTargetComponent(); + if(!(target instanceof TCComponentBOMLine)) { + MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); + return null; + } +// if(((TCComponentBOMLine)target).parent() != null) { +// MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); +// return null; +// } + TCComponentItem item = ((TCComponentBOMLine)target).getItem(); + if(!item.isTypeOf("LD6_MEProcessCr")) { + MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); + return null; + } + new ProcessBorrowOperation(session, (TCComponentBOMLine)target).executeOperation(); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ldy/process/ProcessBorrowOperation.java b/src/com/connor/ldy/process/ProcessBorrowOperation.java new file mode 100644 index 0000000..4042b4d --- /dev/null +++ b/src/com/connor/ldy/process/ProcessBorrowOperation.java @@ -0,0 +1,72 @@ +package com.connor.ldy.process; + +import java.util.HashMap; + +import com.connor.ldy.util.TCUtil; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class ProcessBorrowOperation extends AbstractAIFOperation { + + private TCSession session; + private TCComponentBOMLine target; + private HashMap revMap; + + public ProcessBorrowOperation(TCSession session, TCComponentBOMLine target) { + this.session = session; + this.target = target; + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + revMap = new HashMap<>(); + TCComponentItemType itemType = (TCComponentItemType) session.getTypeService().getTypeComponent("LD6_MEProcessCr"); + TCComponentItem item = target.getItemRevision().saveAsItem(itemType.getNewID(), null); + TCComponentBOMWindow window = TCUtil.getWindow(session); + TCComponentBOMLine bom = TCUtil.getBOMLine(session, window, item.getLatestItemRevision()); + recycle(bom); + window.save(); + window.close(); + TCComponentFolder home = session.getUser().getHomeFolder(); + home.add("contents", item); + + MessageBox.post(desktop, "·ߡ"+item+"ѴHomeļ", "INFO", MessageBox.INFORMATION); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + } + } + + private void recycle(TCComponentBOMLine parent) throws Exception { + for(AIFComponentContext c : parent.getChildren()) { + TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent(); + TCComponentItem item = bom.getItem(); + if(revMap.containsKey(item)) { + TCComponentItemRevision rev = revMap.get(item); + bom.replace(rev.getItem(), rev, null); + continue; + } + if(!item.isTypeOf(new String[] { "LD6_MEProcess", "LD6_OMEOP", "LD6_MEOP" })) + continue; + TCComponentItemType itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(item.getType()); + TCComponentItem newItem = bom.getItemRevision().saveAsItem(itemType.getNewID(), null); + TCComponentItemRevision newRev = newItem.getLatestItemRevision(); + bom.replace(newItem, newRev, null); + revMap.put(item, newRev); + + recycle(bom); + } + } +} diff --git a/src/com/connor/ldy/process/ProcessDivisionDialog.java b/src/com/connor/ldy/process/ProcessDivisionDialog.java new file mode 100644 index 0000000..ab589ee --- /dev/null +++ b/src/com/connor/ldy/process/ProcessDivisionDialog.java @@ -0,0 +1,246 @@ +package com.connor.ldy.process; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +import com.connor.ldy.util.SelectUserDialog; +import com.connor.ldy.util.TCUtil; +import com.teamcenter.rac.aif.AbstractAIFDialog; +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.TCComponentEnvelope; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentUser; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.services.rac.core.DataManagementService; +import com.teamcenter.services.rac.core.EnvelopeService; +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.CreateResponse; + +public class ProcessDivisionDialog extends AbstractAIFDialog { + + /** + * + */ + private static final long serialVersionUID = 1L; + private TCSession session; + private JTable table; + private DefaultTableModel model; + private String[] tableHeader; + private JButton divisionBtn; + private JButton okBtn; + private JButton cancelBtn; + private int ld6_resperson = -1; + private TCAccessControlService accessControlService; + private ArrayList colList; + private ArrayList compList; + private HashMap userMap; + + public ProcessDivisionDialog(TCSession session, TCComponentBOMLine target, String[] options) throws Exception{ + super(AIFUtility.getActiveDesktop()); + this.session = session; + accessControlService = session.getTCAccessControlService(); + userMap = new HashMap<>(); + compList = new ArrayList<>(); + + setTitle("շֹ"); + divisionBtn = new JButton("շֹ"); + okBtn = new JButton("ȷ"); + cancelBtn = new JButton("ȡ"); + addActionListener(target.getItemRevision()); + +// String[] tableHeader = new String[] { "", "", "" }; + int size = options.length; + tableHeader = new String[size+1]; + tableHeader[0] = ""; + colList = new ArrayList<>(); + for(int i=0; i v = new Vector<>(); + v.add(table.getRowCount()+1+""); + for(String[] s : colList) { + if(s[0].equals("Item")) { + v.add(item.getProperty(s[1])); + }else if(s[0].equals("Rev")) { + v.add(rev.getProperty(s[1])); + }else if(s[0].equals("RevMaster")) { + v.add(form.getProperty(s[1])); + }else if(s[0].equals("BOMLine")) { + v.add(line.getProperty(s[1])); + } + } + model.addRow(v); + AIFComponentContext[] cs = rev.getChildren("bom_view_tags"); + if(cs.length>0) + compList.add(new TCComponent[] { item, rev, form, (TCComponent) cs[0].getComponent() }); + else + compList.add(new TCComponent[] { item, rev, form }); + recycleBom(line); + } + } + + private void sendMail(String name, String desc, TCComponentUser user, TCComponent[] comps) throws Exception { + DataManagementService dataManagementService = DataManagementService.getService(session); + CreateIn[] arrayOfCreateIn = new CreateIn[] { new CreateIn() }; + CreateInput createInput = new CreateInput(); + createInput.stringProps.put("object_name", name); + createInput.stringProps.put("object_desc", desc); + createInput.boName = "Envelope"; + createInput.tagArrayProps.put("listOfReceivers", new TCComponent[] { user }); + createInput.tagArrayProps.put("contents", comps); + +// if (paramArrayOfString1 != null && paramArrayOfString1.length > 0) +// createInput.stringArrayProps.put("fnd0ListOfExtRecipients", paramArrayOfString1); +// if (paramArrayOfString2 != null && paramArrayOfString2.length > 0) +// createInput.stringArrayProps.put("fnd0ListOfCcExtRecipients", paramArrayOfString2); + arrayOfCreateIn[0].data = createInput; + + CreateResponse createResponse = dataManagementService.createObjects(arrayOfCreateIn); + +// String uid2 = e.getUid(); +// System.out.println("uid2===================="+uid2); + TCComponentEnvelope[] arrayOfTCComponentEnvelope = new TCComponentEnvelope[] { (TCComponentEnvelope)createResponse.output[0].objects[0] }; + EnvelopeService envelopeService = EnvelopeService.getService(session); + envelopeService.sendAndDeleteEnvelopes(arrayOfTCComponentEnvelope); + } +} diff --git a/src/com/connor/ldy/process/ProcessDivisionHandler.java b/src/com/connor/ldy/process/ProcessDivisionHandler.java new file mode 100644 index 0000000..520ed58 --- /dev/null +++ b/src/com/connor/ldy/process/ProcessDivisionHandler.java @@ -0,0 +1,58 @@ +package com.connor.ldy.process; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class ProcessDivisionHandler extends AbstractHandler implements IHandler{ + + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("ProcessDivisionHandler"); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + TCComponent target = (TCComponent) app.getTargetComponent(); + + if(!(target instanceof TCComponentBOMLine)) { + MessageBox.post(desktop, "ѡ·BOMйշֹ", "ERROR", MessageBox.ERROR); + return null; + } + String type = ((TCComponentBOMLine)target).getItemRevision().getType(); + if(!type.equals("LD6_MEProcessCrRevision")) { + MessageBox.post(desktop, "ѡ·BOMйշֹ", "ERROR", MessageBox.ERROR); + return null; + } + + String[] options = session.getPreferenceService().getStringValues("Connor_GYFG"); + if(options==null || options.length==0) { + MessageBox.post(desktop, "ѡConnor_GYFGòȷ", "ERROR", MessageBox.ERROR); + return null; + } +// String optionC[] = session.getPreferenceService().getStringValues("Connor_AVIC_Apply_Create"); +// if(optionC==null || optionC.length==0) { +// MessageBox.post(AIFUtility.getActiveDesktop(), "ѡConnor_AVIC_Apply_Createòȷ", "ERROR", MessageBox.ERROR); +// return null; +// } +// String options[] = new String[] { "", "״̬" }; + new ProcessDivisionDialog(session, (TCComponentBOMLine)target, options); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } + +} diff --git a/src/com/connor/ldy/process/ProcessMultiplexDialog.java b/src/com/connor/ldy/process/ProcessMultiplexDialog.java new file mode 100644 index 0000000..3dd436b --- /dev/null +++ b/src/com/connor/ldy/process/ProcessMultiplexDialog.java @@ -0,0 +1,597 @@ +package com.connor.ldy.process; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.border.TitledBorder; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumnModel; + +import org.eclipse.ui.internal.e4.compatibility.CompatibilityView; + +import com.connor.ldy.util.SelectUserDialog; +import com.connor.ldy.util.TCUtil; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOPWindow; +import com.teamcenter.rac.kernel.TCComponentBOPWindowType; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCComponentMEOP; +import com.teamcenter.rac.kernel.TCComponentMEProcess; +import com.teamcenter.rac.kernel.TCComponentMEProcessRevision; +import com.teamcenter.rac.kernel.TCComponentPseudoFolder; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.stylesheet.PropertyDateComponent; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PlatformHelper; + +@SuppressWarnings("restriction") +public class ProcessMultiplexDialog extends AbstractAIFDialog { + private static final long serialVersionUID = 1L; + private TCSession session; + private TCComponentBOMLine targetLine; + private JButton searchBtn; + private JButton exportBtn; + private JTable impTable; + private DefaultTableModel impModel; + private JTable processTable; + private DefaultTableModel processModel; + private Map compMap; + private String queryName; + private Vector showOptions; + private Vector procedureOptions; + private Vector processVec; +// private Vector> proceduresVec; + private Vector options;//ȡѡֵ + private Map> lovMap; + private Map>> tableMap; + private Map, TCComponentBOMLine> proceduresMap; + private Vector updateProps; + private Vector clearProps; + + public ProcessMultiplexDialog(TCSession session, TCComponentBOMLine targetLine, Vector options) throws Exception { + super(AIFUtility.getActiveDesktop()); + this.session = session; + this.targetLine = targetLine; + this.options = options; + compMap = new HashMap<>(); + lovMap = new HashMap<>(); + tableMap = new HashMap<>(); + proceduresMap = new HashMap<>(); + this.showOptions = new Vector<>(); + this.procedureOptions = new Vector<>(); + this.processVec = new Vector<>(); + this.updateProps = new Vector<>(); + this.clearProps = new Vector<>(); +// tableMap = new HashMap<>(); + setTitle("ս"); + + String[] propOptions = options.get(3); + for(String s : propOptions) { + updateProps.add(s.split("\\.")); + } + propOptions = options.get(4); + for(String s : propOptions) { + clearProps.add(s.split("\\.")); + } +// JPanel msgPanel = new JPanel(new GridLayout(0,5,2,5)); + JPanel msgPanel = new JPanel(new FlowLayout()); +// String[] searchOptions = options.get(0); + String[] searchOptions = new String[] { "ID=2", "=2" }; + queryName = options.get(0)[0]; + final AbstractAIFDialog dialog = this; + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues"); + for(String s : searchOptions) { + if(!s.contains("=")) + continue; + String[] split = s.split("="); + JLabel label = new JLabel(split[0], SwingConstants.RIGHT); + label.setPreferredSize(new Dimension(80, 23)); +// label.setHorizontalTextPosition(JLabel.RIGHT); +// JPanel propPanel = new JPanel(new BorderLayout()); + JPanel propPanel = new JPanel(new BorderLayout()); + propPanel.add(BorderLayout.WEST, label); + if(split.length==3) { + JComboBox combo = new JComboBox<>(); + combo.setPreferredSize(new Dimension(118, 23)); + if(split[2].indexOf(";")>0) { + String[] value = split[2].split(";"); + combo.addItem(""); + for(String v : value) + combo.addItem(v); + }else { + TCComponentListOfValues[] lovs = lovType.find(split[2]); + if (lovs != null && lovs.length > 0) { + ListOfValuesInfo lovInfo = lovs[0].getListOfValues(); + String[] code = lovInfo.getStringListOfValues(); + String[] name = lovInfo.getLOVDisplayValues(); + Map lovVal = new HashMap<>(); + if (code != null && name != null) { + for (int i = 0; i < code.length; i++) { + lovVal.put(name[i], code[i]); + combo.addItem(name[i]); + } + } + lovMap.put(split[0], lovVal); +// bean.lovList = TCUtil.setAutoComplete(bean, name); + }else + throw new Exception("δҵ"+split[2]+"ѡ"); + } + propPanel.add(BorderLayout.CENTER, combo); + msgPanel.add(propPanel); + compMap.put(split[0], combo); + }else if(split[1].equals("2")) { + JTextField field = new JTextField(); + field.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, field); + msgPanel.add(propPanel); + compMap.put(split[0], field); + }else if(split[1].equals("3")) { + PropertyDateComponent dateBtn = new PropertyDateComponent(); + dateBtn.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, dateBtn); + msgPanel.add(propPanel); + compMap.put(split[0], dateBtn); + }else if(split[1].equals("4")) { + final JTextField field = new JTextField(); + field.setEditable(false); + field.setPreferredSize(new Dimension(60, 23)); + JButton userBtn = new JButton("ѡ"); + userBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + new SelectUserDialog(field, true).showDialog(); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(dialog, ":"+e.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + userBtn.setPreferredSize(new Dimension(56, 23)); + propPanel.add(BorderLayout.CENTER, field); + propPanel.add(BorderLayout.EAST, userBtn); + msgPanel.add(propPanel); + compMap.put(split[0], field); + } + } + searchBtn = new JButton("ѯ"); + exportBtn = new JButton(""); + JPanel btnPanel = new JPanel(new FlowLayout()); + btnPanel.add(searchBtn); + btnPanel.add(exportBtn); + JPanel topPanel = new JPanel(new BorderLayout()); + topPanel.add(BorderLayout.WEST, msgPanel); + topPanel.add(BorderLayout.EAST, btnPanel); + + String[] itemOptions = options.get(0); + String[] tableHeader = new String[itemOptions.length]; + tableHeader[0] = ""; + for(int i=1; i getColumnClass(int column) { + if (column==0) { + return Boolean.class; + } + return super.getColumnClass(column); + } + }; +// processTable.getTableHeader().setReorderingAllowed(false); + processTable.setFillsViewportHeight(true); +// processTable.setEnabled(false); + processTable.setEnabled(true); +// processTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); + processTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + processTable.setModel(processModel); + processTable.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(processTable, true)); + processTable.getTableHeader().setReorderingAllowed(false); + TableColumnModel pColModel = processTable.getColumnModel(); + for(int i=1; i0) { + for(int i=processModel.getRowCount(); i>0; i--) + processModel.removeRow(i-1); + } + if(tableMap.size()==0) + return; + int i = impTable.getSelectedRow(); + for(Vector vo : tableMap.get(i)) { + processModel.addRow(vo); + } + } + }); + searchBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + if(impModel.getRowCount()>0) { + for(int i=impModel.getRowCount(); i>0; i--) + impModel.removeRow(i-1); + } + if(processModel.getRowCount()>0) { + for(int i=processModel.getRowCount(); i>0; i--) + processModel.removeRow(i-1); + } + Vector keyV = new Vector<>(); + Vector valueV = new Vector<>(); + for(Entry e : compMap.entrySet()) { + JComponent c = e.getValue(); + String text = ""; + if(c instanceof JTextField) + text = ((JTextField)c).getText(); + else if(c instanceof PropertyDateComponent) + text = ((PropertyDateComponent)c).getDateViewModel().getDateString(); + else { + text = ((JComboBox)c).getSelectedItem().toString(); + if(lovMap.containsKey(e.getKey())) { + text = lovMap.get(e.getKey()).get(text); + } + } + if(text!=null && !text.isEmpty()) { +// if(e.getKey().equals("ID")) +// text += "GY"; + keyV.add(e.getKey()); + valueV.add(text); + } + } + TCComponent[] result = TCUtil.query(session, queryName, keyV, valueV); + System.out.println("result:"+result.length); + if(result.length==0) { + MessageBox.post(dialog, "ûзĹգѯ", "ERROR", MessageBox.ERROR); + return; + } + result = TCUtil.TCsort(result, new int[] { 1, -1 }, "item_id", "item_revision_id"); + TCComponentBOPWindowType bomWinType = (TCComponentBOPWindowType) session.getTypeComponent("BOPWindow"); + TCComponentBOPWindow window = (TCComponentBOPWindow) bomWinType.createBOPWindow(null); + for(int i=0; i v = new Vector<>(); + int num = impModel.getRowCount(); + v.add(num+1+""); + TCComponentMEProcessRevision meprocess = (TCComponentMEProcessRevision) result[i]; + TCComponentItem pitem = meprocess.getItem(); + TCComponentForm form = TCUtil.getItemRevisionMasterForm(meprocess); + for(String[] prop : showOptions) { + if(prop[0].equals("item")) + v.add(pitem.getProperty(prop[1])); + else if(prop[0].equals("rev")) + v.add(meprocess.getProperty(prop[1])); + else + v.add(form.getProperty(prop[1])); + } + processVec.add(meprocess); + impModel.addRow(v); + + TCComponentBOMLine ebom = window.setWindowTopLine(pitem, meprocess, null, null); + AIFComponentContext[] p = ebom.getChildren(); + Vector> vvo = new Vector<>(); + for(AIFComponentContext c : p) { + Vector vo = new Vector<>(); + vo.add(true); + TCComponentBOMLine procedure = (TCComponentBOMLine) c.getComponent(); + TCComponentItem pritem = procedure.getItem(); + if(!(pritem instanceof TCComponentMEProcess) && !(pritem instanceof TCComponentMEOP)) + continue; + TCComponentItemRevision prrev = procedure.getItemRevision(); + if(pritem instanceof TCComponentMEOP) + System.out.println(prrev+">>"+prrev.getReferenceProperty("root_activity").getReferenceListProperty("contents").length); + TCComponentForm prform = TCUtil.getItemRevisionMasterForm(prrev); + for(String[] prop : procedureOptions) { + if(prop[0].equals("item")) + vo.add(pritem.getProperty(prop[1])); + else if(prop[0].equals("rev")) + vo.add(prrev.getProperty(prop[1])); + else if(prop[0].equals("bom")) + vo.add(procedure.getProperty(prop[1])); + else + vo.add(prform.getProperty(prop[1])); + } + vvo.add(vo); + proceduresMap.put(vo, procedure); + } + tableMap.put(num, vvo); + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(dialog, ":"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + exportBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + Map borrowMap = new HashMap<>(); + for(String s : options.get(2)) { +// String[] split = s.split("="); + borrowMap.put(s, "true"); + } + if(processTable.getRowCount()==0) + throw new Exception("Ϊգ޷"); + TCComponentItemRevision targetRev = targetLine.getItemRevision(); + TCComponentItemRevision proRev = processVec.get(impTable.getSelectedRow()); + if(!targetRev.getType().equals(proRev.getType())) + throw new Exception("ѡͲͬ޷"); + TCComponentItemType itemType; + TCComponentForm targetForm = TCUtil.getItemRevisionMasterForm(targetRev); +// String revId = targetRev.getProperty("item_revision_id"); +// System.out.println("time1 " + (System.nanoTime() - time0) / 1000000); + int n = 0; + for(AIFComponentContext cs : targetLine.getChildren()) { + int no = Integer.parseInt(((TCComponentBOMLine)cs.getComponent()).getProperty("bl_sequence_no")); + if(no > n) + n = no; + } + if(n%10 != 0) + n = n/10*10 + 10; + else + n = n + 10; + + for(int i=0; i v = tableMap.get(impTable.getSelectedRow()).get(i); + TCComponentBOMLine p = proceduresMap.get(v); + TCComponentItemRevision procedure = p.getItemRevision(); + TCComponentItem pitem = procedure.getItem(); + String type = pitem.getType(); + itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(type); +// TCComponentItem newItem = itemType.create(itemType.getNewID(), revId, type, pitem.getProperty("object_name"), "", null); +// procedure.saveAsItem(arg0, arg1); + TCComponentItem newItem = procedure.getItem().getLatestItemRevision().saveAsItem(itemType.getNewID(), "001"); + newItem.lock(); + TCComponentBOMLine newLine = targetLine.add(newItem, null); + TCComponentItemRevision newRev = newItem.getLatestItemRevision(); + newLine.setProperty("bl_sequence_no", n+""); + n += 10; +// copyProperty(p, newLine, num); + //TODO + TCComponentForm proForm = TCUtil.getItemRevisionMasterForm(proRev); + for(String[] ss : updateProps) { + if(ss[0].equals("rev")) { + copyProperty(proRev, targetRev, ss[1]); + }else if(ss[0].equals("master")) { + copyProperty(proForm, targetForm, ss[1]); + } + } + TCComponentForm newForm = TCUtil.getItemRevisionMasterForm(newRev); + for(String[] ss : clearProps) { + if(ss[0].equals("rev")) { + newRev.setProperty(ss[1], ""); + }else if(ss[0].equals("master")) { + newForm.setProperty(ss[1], ""); + }else if(ss[0].equals("item")) { + newItem.setProperty(ss[1], ""); + } + } + +// num++; + AIFComponentContext[] children = newLine.getChildren(); + for(AIFComponentContext c : children) { +// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000); +// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000); + TCComponentBOMLine child = (TCComponentBOMLine) c.getComponent(); + TCComponentItem subitem = child.getItem(); + String subtype = subitem.getType(); +// System.out.println("child" + child +" "+ (subitem instanceof TCComponentMEOP)); + if(subitem instanceof TCComponentMEOP) { +// TCComponentItem newOpitem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null); +// TCComponentBOMLine newOpline = newLine.add(newSubItem, null); +// copyProperty(child, child, 0); + itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(subtype); + TCComponentItem newSubItem = child.getItemRevision().saveAsItem(itemType.getNewID(), ""); + TCComponentItemRevision newSubRev = newSubItem.getLatestItemRevision(); + child.replace(newSubItem, newSubRev, null); + }else if(borrowMap.containsKey(subtype)) { + if(borrowMap.get(subtype).toLowerCase().equals("false")){ + TCComponentItem newsubItem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null); +// newLine.add(newsubItem, null); + child.replace(newsubItem, newsubItem.getLatestItemRevision(), null); + } + }else { + child.cut(); + } +// else +// newLine.add(subitem, null); + } + newItem.save(); + newItem.unlock(); + + } + List viewParts = PlatformHelper.getAllViewParts(); + for(Object view : viewParts) { + if(view==null || !(view instanceof CompatibilityView)) + continue; + +// IViewPart v = ((CompatibilityView)view).getView(); +//// System.out.println("ProcessPropertyView "+((CompatibilityPart)view).ENABLE_DEPENDENCY_INJECTION_FOR_E3_PARTS); +// if(!(v instanceof ProcessPropertyView)) +// continue; +// ProcessPropertyView pv = (ProcessPropertyView)v; +// Field field = pv.getClass().getDeclaredField("panel"); +// field.setAccessible(true); +// Object editor = field.get(pv); +//// if(editor instanceof ProcessPropertyEditor) +//// ((ProcessPropertyEditor) editor).updateSelection(targetLine); +// Field pfield = ((ProcessPropertyEditor) editor).getClass().getDeclaredField("propPanel"); +// pfield.setAccessible(true); +// Object panel = pfield.get(((ProcessPropertyEditor) editor)); +// ((PropertyPanel)panel).loadData(); + } + MessageBox.post(dialog, "ɹ", "ʾ", MessageBox.INFORMATION); + dispose(); + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(dialog, ""+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + } + private void copyProperty(TCComponent a, TCComponent b, String prop) throws Exception { + System.out.println(">>>copyProperty bagin!prop = "+prop); + TCProperty property = a.getTCProperty(prop); + if(property==null) { + System.out.println(a+"δҵԣ" + prop); + return; + } + if(b.getTCProperty(prop)==null) { + System.out.println(b+"δҵԣ" + prop); + return; + } + int type = property.getPropertyType(); +// System.out.println(prop+">>" + type); + if(type==TCProperty.PROP_untyped_relation || type==TCProperty.PROP_untyped_reference){ + TCComponentPseudoFolder folder = TCUtil.getPseudoFolder(a, prop); +// System.out.println("folder:" + folder); + TCComponent[] cps; + if(folder == null) { + cps = property.getReferenceValueArray(); + }else { + AIFComponentContext[] cxs = folder.getChildren(); + cps = new TCComponent[cxs.length]; + for(int i=0; i>" + b+"==" + b.getTCProperty(prop)); + } + + /*private void copyProperty(TCComponentBOMLine p, TCComponentBOMLine toLine, int num) throws Exception { + System.out.println("copyProperty:"+p+" copyProperty " + (System.nanoTime() - time0) / 1000000); + if(p.parent()!=null) { + for(String s : propVecs.get(0)) { + toLine.setProperty(s, ""); + } + } + TCComponentItemRevision rev = toLine.getItemRevision(); + for(String s : propVecs.get(1)) { + rev.setProperty(s, ""); + } + + TCComponentItem item = rev.getItem(); + for(String s : propVecs.get(2)) { + item.setProperty(s, ""); + } + + TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev); + for(String s : propVecs.get(3)) { + form.setProperty(s, ""); + } + if(num>0) + form.setProperty("ac5_OperationNumber", num*5+""); + System.out.println("copyProperty " + (System.nanoTime() - time0) / 1000000); + } + private String getProperty(String comp, String prop, TCComponent... comps) throws Exception { + if(comp.equals("rev")) + return comps[0].getProperty(prop); + else if(comp.equals("master")) + return comps[1].getProperty(prop); + else if(comp.equals("item")) + return comps[2].getProperty(prop); + else + return ""; + }*/ +} \ No newline at end of file diff --git a/src/com/connor/ldy/process/ProcessMultiplexHandler.java b/src/com/connor/ldy/process/ProcessMultiplexHandler.java new file mode 100644 index 0000000..d6ccbfe --- /dev/null +++ b/src/com/connor/ldy/process/ProcessMultiplexHandler.java @@ -0,0 +1,67 @@ +package com.connor.ldy.process; + +import java.util.Vector; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentMEProcess; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class ProcessMultiplexHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("ProcessBorrowHandler"); + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + TCComponent target = (TCComponent)app.getTargetComponent(); + if(!(target instanceof TCComponentBOMLine)) { + MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); + return null; + } + if(((TCComponentBOMLine)target).parent() != null) { + MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); + return null; + } + TCComponentItem item = ((TCComponentBOMLine)target).getItem(); + if(!(item instanceof TCComponentMEProcess)) { + MessageBox.post(desktop, "ѡBOMд", "ERROR", MessageBox.ERROR); + return null; + } + String[] prefs = new String[] { "Connor_LD_GYJY_Item", "Connor_LD_GYJY_Process", "Connor_LD_GYJY_Borrow", "Connor_LD_GYJY_Prop", "Connor_LD_GYJY_Clear" }; + Vector options = new Vector<>(); + for(String s : prefs) { +// if(s.equals("Connor_AVIC_GYJY_Borrow")) { +// options.add(new String[] {}); +// continue; +// } + String searchOptions[] = session.getPreferenceService().getStringValues(s);//ȡѡ + if(searchOptions == null) { +// MessageBox.post(desktop, "ѡ"+s+"òȷ", "ERROR", MessageBox.ERROR); +// return null; + options.add(new String[] {}); + continue; + } + options.add(searchOptions); + } + new ProcessMultiplexDialog(session, (TCComponentBOMLine)target, options); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ldy/process/ProcessWordExportHandler.java b/src/com/connor/ldy/process/ProcessWordExportHandler.java new file mode 100644 index 0000000..a684ab8 --- /dev/null +++ b/src/com/connor/ldy/process/ProcessWordExportHandler.java @@ -0,0 +1,162 @@ +package com.connor.ldy.process; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +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.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +//ļнṹ +public class ProcessWordExportHandler extends AbstractHandler implements IHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + System.out.println("ProcessWordExportHandler"); +// new Thread() { +// public void run() { +// } +// }.start(); + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + InterfaceAIFComponent target = app.getTargetComponent(); + TCComponentBOMLine bomLine = null; + if(target instanceof TCComponentBOMLine) { + bomLine = (TCComponentBOMLine)target; + }else if(target instanceof TCComponentItemRevision) { + //bom + TCComponentItemRevision revision = (TCComponentItemRevision)target; + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + TCComponentBOMWindow view = winType.create(null); + bomLine = view.setWindowTopLine(revision.getItem(), revision, null, null); + }else { + MessageBox.post(desktop, "ѡ·߰汾BOMе", "ERROR", MessageBox.ERROR); + return null; + } + String option = ""; + String name = ""; + String id = arg0.getCommand().getId(); + int type = Integer.parseInt(id.substring(id.length()-8, id.length()-7)); + if(id.equals("ProcessWordExport1Handler")){//000590 + option = "ӹտƬ"; + name = "ӹտƬ"; + }else if(id.equals("ProcessWordExport2Handler")) { + option = "տƬ"; + name = "տƬ"; + }else if(id.equals("ProcessWordExport3Handler")) { + option = "װտƬ"; + name = "װտƬ"; + }else if(id.equals("ProcessWordExport4Handler")) { + option = "ʱӹտƬ"; + name = "ӹʱտƬ"; + }else { + option = "ʱտƬ"; + name = "ʱտƬ"; + } + TCComponentItemRevision rev = bomLine.getItemRevision(); + if(type > 3 && !rev.isTypeOf("LD6_LSMEProcessRevision")) { + MessageBox.post(desktop, "ѡʱ·BOMе", "ERROR", MessageBox.ERROR); + return null; + } + TCComponent[] mets = rev.getReferenceListProperty("IMAN_METarget"); + if(mets==null || mets.length==0) { + MessageBox.post(desktop, "ѡδĿ꣬!", "ERROR", MessageBox.ERROR); + return null; + } + if(type==3) { + if(!mets[0].getProperty("ld6_drawNum").equals(rev.getProperty("ld6_clientPartNum"))) { + MessageBox.post(desktop, "·߰汾ĿϵĹװͼŲһ£!", "ERROR", MessageBox.ERROR); + return null; + } + }else { + if(!mets[0].getProperty("ld6_clientPartNum").equals(rev.getProperty("ld6_clientPartNum")) + || !mets[0].getProperty("ld6_clientPartRev").equals(rev.getProperty("ld6_clientPartRev"))) { + MessageBox.post(desktop, "·߰汾ź汾Ŀϵš汾һ£!", "ERROR", MessageBox.ERROR); + return null; + } + } + + //2024 6 3 hcj ǵڶεտƬʱ򣬲ٴģлȡݼֱʹõǰϵµݼļ + TCComponentDataset model = null; + Boolean create = true; + for(AIFComponentContext c : bomLine.getItemRevision().getChildren("IMAN_specification")) { + TCComponent comp = (TCComponent)c.getComponent(); + System.out.println("ݼƣ"+comp.getProperty("object_name")); + System.out.println("ɸѡƣ"+name); + System.out.println("Ƿ"+comp.getProperty("object_name").contains(name)); + if(comp.isTypeOf("MSWordX") && comp.getProperty("object_name").contains(name)) { + create = false; + model = (TCComponentDataset)comp; + break; + } + } + if(create) { + //һεտƬ ʹģļ + String[] ids = session.getPreferenceService().getStringValues("Connor_ExportMenu_Template_Mapping"); + if(ids==null || ids.length<1) { + MessageBox.post(desktop, "ѡConnor_ExportMenu_Template_Mappingòȷ", "ERROR", MessageBox.ERROR); + return null; + } + for(String s : ids) { + String[] ss = s.split("="); + if(ss[0].equals(option)) { + id = ss[1]; + break; + } + } + TCComponentItemType itemType = (TCComponentItemType) session.getTypeService().getTypeComponent("Item"); + TCComponentItem[] item = itemType.findItems(id); + if(item==null || item.length==0) { + MessageBox.post(desktop, "ѡConnor_ExportMenu_Template_Mappingòȷ", "ERROR", MessageBox.ERROR); + return null; + } + AIFComponentContext[] comps = item[0].getLatestItemRevision().getChildren("IMAN_specification"); + if(comps.length==0) { + MessageBox.post(desktop, ""+id+"°汾δҵWordģ", "ERROR", MessageBox.ERROR); + return null; + } + + for(AIFComponentContext c : comps) { + TCComponent comp = (TCComponent) c.getComponent(); + if(comp.isTypeOf("MSWordX")) { + model = (TCComponentDataset) comp; + break; + } + } + if(model==null) { + MessageBox.post(desktop, ""+id+"°汾δҵWordģ", "ERROR", MessageBox.ERROR); + return null; + } + } + + String[] options = session.getPreferenceService().getStringValues("Connor_GYKP_types"); + if(options==null || options.length<4) { + MessageBox.post(desktop, "ѡConnor_GYKP_typesòȷ", "ERROR", MessageBox.ERROR); + return null; + } + + ProcessWordExportOperation operation = new ProcessWordExportOperation(session, bomLine, model, type, options,name,create); + session.queueOperation(operation); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/com/connor/ldy/process/ProcessWordExportOperation.java b/src/com/connor/ldy/process/ProcessWordExportOperation.java new file mode 100644 index 0000000..c70e260 --- /dev/null +++ b/src/com/connor/ldy/process/ProcessWordExportOperation.java @@ -0,0 +1,1188 @@ +package com.connor.ldy.process; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ThreadLocalRandom; + +import com.spire.doc.Document; +import com.spire.doc.FileFormat; +import com.spire.doc.Section; +import com.spire.doc.Table; +import com.spire.doc.TableCell; +import com.spire.doc.collections.ParagraphCollection; +import com.spire.doc.collections.RowCollection; +import com.spire.doc.collections.TableCollection; +import com.spire.doc.documents.Paragraph; +import com.spire.doc.documents.SubSuperScript; +import com.spire.doc.fields.omath.OfficeMath; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFOperation; +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.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentTcFile; +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 cn.net.connor.std.gdtex.KGenerateGDTHTML; + +import com.connor.ld.processRevision.KUtil; +import com.connor.ldy.util.TCUtil; + +public class ProcessWordExportOperation extends AbstractAIFOperation { + + private TCSession session; + private TCComponentDataset model; + private TCComponentBOMLine target; + private ArrayList nums; + private int choice; + private String[] options; + private TableCollection tables; + private int totalRow; + private int first; + private ArrayList symbols; + private Document doc; + private String oldName; + private Map queryName = new HashMap(); + private Boolean create; +// private static final int ROW = 12; + + public ProcessWordExportOperation(TCSession session, TCComponentBOMLine target, TCComponentDataset model, int type, + String[] options, String name, Boolean create) { + this.session = session; + this.model = model; + this.target = target; + this.choice = type; + this.options = options; + this.oldName = name; + this.create = create; + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + FileInputStream input = null; + FileOutputStream output = null; + BufferedWriter buffered = null; + try { + String[] equips = options[0].split(";"); + String[] docs = options[1].split(";"); + String[] split = options[2].split(";"); + HashMap types = new HashMap<>(); + for (String s : split) { + String[] ss = s.split("="); + types.put(ss[1], ss[0]); + } + symbols = new ArrayList<>(); + symbols.add('.'); + symbols.add('+'); + symbols.add('-'); + symbols.add('*'); + symbols.add('/'); + symbols.add('='); + symbols.add('('); + symbols.add(')'); + symbols.add(''); + + nums = new ArrayList<>(); + nums.add(""); + nums.add("һ"); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + nums.add(""); + ArrayList blist = new ArrayList<>(); + + //ȡѡ + String[] dl = session.getPreferenceService().getStringValues("ld6_deviceGroup"); + if(dl == null || dl.length == 0) { + MessageBox.post("ѡld6_deviceGroup", "ʾ", MessageBox.ERROR); + return; + } + for (String str : dl) { + try { + String[] split1 = str.split("="); + queryName.put(split1[0], split1[1].split(";")); + } catch (Exception e) { + // TODO Auto-generated catch block + MessageBox.post("ѡld6_deviceGroup" + str + "", "ʾ", MessageBox.ERROR); + return; + } + } + +// TCComponentForm form = TCUtil.getItemRevisionMasterForm(target.getItemRevision()); + boolean find = false; + int last = 0; + String idString = ""; + + for (AIFComponentContext c : target.getChildren()) { + TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent(); + TCComponentItemRevision rev = bom.getItemRevision(); + String dg = property(rev, "ld6_deviceGroup"); + // 豸ϢҵѡĴ + int count1 = 0; + for (Entry entry : queryName.entrySet()) { + if(!Arrays.asList(entry.getValue()).contains(dg)) { + count1++; + } + } + if(count1 == queryName.size()) { + //ʾû + idString += dg+"("+property(rev, "item_id")+")"; + idString += ","; + continue; + } + } + if(idString.length()>0) { + String newString = idString.substring(0, idString.length() - 1); + MessageBox.post("" + newString + "δҵ࣬ϵԱάϢִеտƬ", "ʾ", MessageBox.ERROR); + return; + } + + for (AIFComponentContext c : target.getChildren()) { + TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent(); + TCComponentItemRevision rev = bom.getItemRevision(); +// if(!rev.isTypeOf("LD6_MEProcessRevision")) + if (!rev.isTypeOf("LD6_MEOPRevision")) + continue; + String ld6_MEprocessType = rev.getProperty("ld6_MEprocessType"); + if (choice == 1 || choice == 4) { + if (ld6_MEprocessType.equals("ϵ¹")) { + blist.add(bom); + continue; + } + boolean type = ld6_MEprocessType.equals("ӹ"); + if (!find && !type) + continue; + find = true; + blist.add(bom); + if (type) + last = blist.size(); + } else if (choice == 2 || choice == 5) { + if (ld6_MEprocessType.equals("")) { + blist.add(bom); + find = true; + last = blist.size(); + } else if (find && ld6_MEprocessType.equals("ӹ")) { +// list.add(bom); +// list.get(sequence).removeAll(list.get(sequence)); + blist.removeAll(blist); + find = false; + } + } else { + blist.add(bom); + } + } + if (choice != 3 && last < blist.size()) { + for (int i = blist.size(); i > last; i--) { + blist.remove(i - 1); + } + } + ArrayList slist = new ArrayList<>(); + HashMap> meopMap = new HashMap<>(); + HashMap sequences = new HashMap<>(); + for (int i = 0; i < blist.size(); i++) { + TCComponentBOMLine bom = blist.get(i); + TCComponentItemRevision rev = bom.getItemRevision(); + String name = rev.getProperty("object_name"), sequence = bom.getProperty("bl_sequence_no"); + if (sequences.containsKey(sequence)) { + if (!name.equals(sequences.get(sequence))) { + MessageBox.post(desktop, "ͬŲͬƵĹ", "ERROR", MessageBox.ERROR); + return; + } + } else { + meopMap.put(sequence, new ArrayList()); + slist.add(sequence); + sequences.put(sequence, name); + } + meopMap.get(sequence).add(bom); + } + if (slist.size() > 20) { + MessageBox.post(desktop, "ʮ޷е", "ERROR", MessageBox.ERROR); + return; + } + TCComponentItemRevision proRev = target.getItemRevision(); + TCComponentItemRevision tarRev = (TCComponentItemRevision) proRev.getChildren("IMAN_METarget")[0] + .getComponent(); +// TCComponent[] components = form.getReferenceListProperty(tableProp); + + TCComponentTcFile[] files = model.getTcFiles(); + File file = files[0].getFile(System.getProperty("java.io.tmpdir")); + // ȡjava.io.tmpdirĿ¼ΪļĿ¼ + String tempDir = System.getProperty("java.io.tmpdir"); + + // ļǰʱȷΨһ + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String timestamp = dateFormat.format(new Date()); // ǰʱȷ + int randomNum = ThreadLocalRandom.current().nextInt(1000, 9999); // һλ + String newFileName = "file_" + timestamp + "_" + randomNum + ".txt"; // ļʽ + + // µļ· + File newFile = new File(tempDir, newFileName); + + try { + // ļλò + Files.copy(file.toPath(), newFile.toPath()); + System.out.println("File renamed and moved to: " + newFile.getAbsolutePath()); + + // Ҫɾԭļ + // originalFile.delete(); + } catch (IOException e) { + System.err.println("Error occurred while renaming the file: " + e.getMessage()); + } + input = new FileInputStream(newFile); + doc = new Document(input); + + ArrayList datas = new ArrayList<>(); + ArrayList words = new ArrayList<>(); + for (int i = 0; i < slist.size(); i++) { + String[] data = new String[5]; +// Table table = tables.get(i/2); +// int row = i>1 ? (3 + i%2) : (5 + i%2);//TODO +// if(i<2 && choice>3) +// row += 2; + String sequence = slist.get(i); + String name = sequences.get(sequence); +// table.get(row, 0).getParagraphs().get(0).setText(getChineseNum(i+1)); +// table.get(row, 1).getParagraphs().get(0).setText(name); + data[0] = getChineseNum(i + 1); + data[1] = name; + + ArrayList boms = meopMap.get(sequence); + StringBuilder contents = new StringBuilder(""), machine = new StringBuilder(""), + equip = new StringBuilder(""), remark = new StringBuilder(""); + TCComponent[] mecs = boms.get(0).getItemRevision().getReferenceProperty("root_activity") + .getReferenceListProperty("contents"); + mecs = TCsort(mecs, "ld6_activityno"); + for (TCComponent mec : mecs) { + contents.append(mec.getProperty("ld6_activityno")).append("") + .append(mec.getProperty("ld6_activitydesc")).append("\n"); + remark.append(mec.getProperty("ld6_controlpoint")).append("\n"); + } + ArrayList idSet = new ArrayList<>(); + Boolean isExit = false; + for (TCComponentBOMLine bom : boms) { +// TCComponentBOMLine bom = boms.get(0); + TCComponentItemRevision rev = bom.getItemRevision(); + + String dg = property(rev, "ld6_deviceGroup"); + if (!dg.isEmpty()) { + // 豸ϢҵѡĴ + for (Entry entry : queryName.entrySet()) { + if(Arrays.asList(entry.getValue()).contains(dg)) { + if(isExit) { + break; + } + machine.append(entry.getKey()); + isExit = true; +// machine.append("(ͼϵͳ)"); + machine.append(";"); + break; + } + } + + } + + for (AIFComponentContext c : bom.getChildren()) { + TCComponentBOMLine line = (TCComponentBOMLine) c.getComponent(); + TCComponentItemRevision r = line.getItemRevision(); + String id = r.getProperty("item_id"); + if (idSet.contains(id)) + continue; + idSet.add(id); + String occ = line.getProperty("bl_occ_type"); + if (occ.equals("ָ") && r.isTypeOf("LD6_TecDOCRevision")) { + String t = property(r, "ld6_type"); + if (TCUtil.contains(docs, t)) + equip.append(options[3]).append(t).append("").append(id).append("\\") + .append(property(r, "ld6_docNum")).append("\n"); + } else if (occ.equals("Դ")) { + String type = r.getType(); + if (r.isTypeOf("LD6_EquipmentRevision")) { + String t = property(r, "ld6_equType"); + if (TCUtil.contains(equips, t)) + equip.append(options[3]).append(t).append("").append(id).append("\\") + .append(property(r, "ld6_drawNum")).append("\n"); + } else if (types.containsKey(type)) { + String q = property(line, "bl_quantity"); + equip.append(options[3]).append(types.get(type)).append("").append(id).append("\\") + .append(q.isEmpty() ? "1" : q).append("\\") + .append(property(r, "ld6_materialDesc")).append("\n"); + } + } + } + + TCComponentDataset word = null; + AIFComponentContext[] cs = rev.getChildren("IMAN_specification"); + for (AIFComponentContext c : cs) { + TCComponent comp = (TCComponent) c.getComponent(); + if (comp.isTypeOf("MSWordX") && comp.getProperty("object_name").contains("ռͼ")) { + word = (TCComponentDataset) comp; + break; + } + } + if (word == null) { + continue; + } + words.add(word); + } + + if (contents.length() > 0) + contents.deleteCharAt(contents.length() - 1); + if (machine.length() > 0) + machine.deleteCharAt(machine.length() - 1).append("\n").insert(0, options[3] + ""); + if (equip.length() > 0) + equip.deleteCharAt(equip.length() - 1); + if (remark.length() > 0) + remark.deleteCharAt(remark.length() - 1); +// table.get(row, 2).getParagraphs().get(0).setText(contents.toString()); +// table.get(row, 3).getParagraphs().get(0).setText(machine.append(equip).toString()); +// table.get(row, 4).getParagraphs().get(0).setText(remark.toString()); + data[2] = shiftRow(contents.toString(), 74).toString(); + data[3] = shiftRow(machine.append(equip).toString(), 32).toString();// TODO shiftRow + data[4] = shiftRow(remark.toString(), 24).toString(); + datas.add(data); +// System.out.println("data"+data[2]+""+contents.toString()); + } + Section section = doc.getSections().get(0); + tables = section.getTables(); + System.out.println("tables:" + tables.getCount()); + totalRow = 0; + first = choice > 3 ? 11 : 12; + ArrayList hights = new ArrayList<>(); + for (String[] data : datas) { + int a = rowCount(data[2], 75, first, totalRow); + int b = rowCount(data[3], 31, first, totalRow); + int c = rowCount(data[4], 24, first, totalRow); + System.out.println("rowCount" + a + "==" + b + "==" + c); + if (a >= b && a >= c) { + totalRow += a; + hights.add(a); + } else if (b >= a && b >= c) { + totalRow += b; + hights.add(b); + } else { + totalRow += c; + hights.add(c); + } + System.out.println("data" + hights.size() + "" + hights.get(hights.size() - 1)); + } + //¼һͼֽ + int tznum = 0; + if(!create) { + int sum = tables.getCount(); + int txtsum = totalRow / 2 + totalRow % 2; + tznum = sum - txtsum; + System.out.println("tznum:"+tznum); + } + + //һεʱ򴴽ҳ ظʱ ֱ滻 ҳ + if(create) { + + System.out.println("ʼҳ"); + int count = totalRow / 2 + totalRow % 2; + if (count > 2) { + for (int i = 0; i < count - 2; i++) { + tables.add(tables.get(1).deepClone()); + // doc.getLastParagraph().setText("last\n\n"); + section.addParagraph(); + section.addParagraph(); +// System.out.println("Last:"+doc.pa); + } + } + } + + + + totalRow = 0; + for (int i = 0; i < datas.size(); i++) { + String[] strings = datas.get(i); + + System.out.println("totalRow" + totalRow); + + write(datas.get(i), hights.get(i));// TODO wright + } + //ظʱ Ѿڵͼֽɾ µ + if(!create) { + System.out.println("ʼɾͼֽ"); + System.out.println("count:"+tables.getCount()); + int tznum2 = tznum; + for(int a = tables.getCount()-1;tznum2>0;a--,tznum2--) { + tables.removeAt(a); + } + // Ϊɾ񣬻пвԸɾն + ParagraphCollection paragraphs = section.getParagraphs(); + // һ俪ʼ + for (int n = paragraphs.getCount() - 1; n >= 0; n--) { + if(tznum < 0) { + break; + } + Paragraph paragraph = paragraphs.get(n); + tznum--; + // ǷΪ + if (paragraph.getText().trim().isEmpty()) { + // ɾն + paragraphs.remove(paragraph); + + } else { + // ǿնʱ˳ѭ + break; + } + } + } + + + + for (TCComponentDataset word : words) { + FileInputStream input2 = null; + try { + File file2 = word.getTcFiles()[0].getFile(System.getProperty("java.io.tmpdir")); + input2 = new FileInputStream(file2); + Document doc2 = new Document(input2); + TableCollection tables2 = doc2.getSections().get(0).getTables(); + for (int j = 0; j < tables2.getCount(); j++) { + + tables.add(tables2.get(j).deepClone()); + section.addParagraph(); + section.addParagraph(); + } + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, "" + e.getMessage(), "ERROR", MessageBox.ERROR); + } finally { + if (input2 != null) + input2.close(); + } + } + tables = doc.getSections().get(0).getTables(); + for (int i = 0; i < tables.getCount(); i++) { + Table table = tables.get(i); + RowCollection rows = table.getRows(); + int rowc = rows.getCount(); +// System.out.println("tables:"+table.get(rowc-1, rows.get(rowc-1).getCells().getCount()-1).getParagraphs().get(0).getText()); +// System.out.println("tables:"+table.get(rowc-2, rows.get(rowc-2).getCells().getCount()-1).getParagraphs().get(0).getText()); + table.get(rowc - 2, rows.get(rowc - 2).getCells().getCount() - 1).getParagraphs().get(0) + .setText(" " + (i + 1) + " ҳ"); + table.get(rowc - 3, rows.get(rowc - 3).getCells().getCount() - 1).getParagraphs().get(0) + .setText(" " + tables.getCount() + " ҳ"); + } + + output = new FileOutputStream(newFile.getPath()); + doc.saveToFile(output, FileFormat.Docx_2010); + doc.dispose(); + TCUtil.deleteWarning(newFile); + input.close(); + output.close(); + + String t = (choice == 2 || choice == 5) ? "-T04-" : "-T02-"; + if (choice > 3) + t += "L"; + StringBuilder builder = new StringBuilder(""); + String no = new StringBuilder("LD.Y-") + .append(tarRev.getType().equals("LD6_EquipmentRevision") ? property(tarRev, "ld6_drawNum") + : property(tarRev, "ld6_clientPartNum")) + .append(t).append(property(proRev.getItem(), "ld6_SeqNum")).toString(); + builder.append("ͻ=").append(value(property(tarRev, "ld6_clientName"), 10)).append("|ͺ=") + .append(value(property(tarRev, "ld6_specsModel"), 10)).append("|ͼ=") + .append(value(property(tarRev, "ld6_clientPartNum"), 24)).append("|=") + .append(value(property(tarRev, "object_name"), 24)).append("|ļ=").append(value(no, 28)) + .append("|汾=").append(value(property(tarRev, "ld6_clientPartRev"), 28)).append("|ļ=") + .append(property(tarRev, "item_revision_id")) + + .append("|ƺ=").append(property(tarRev, "ld6_partMaterialQ")).append("|ëߴ=") + .append(property(proRev, "ld6_blankSize")).append("|=") + .append(property(tarRev, "ld6_netWeight")).append("|ע=").append(property(proRev, "ld6_notes")) + .append("|ë=").append(property(proRev, "ld6_blanktype")).append("|Ƴ=") + .append(property(proRev, "ld6_madePartNum")).append("|ë=") + .append(property(tarRev, "ld6_grossWeight")).append("|ÿ̨=") + .append(property(proRev, "ld6_eachNum")) + + .append("|װ=").append(value(property(tarRev, "ld6_equType"), 28)).append("|װͼ=") + .append(value(property(tarRev, "ld6_drawNum"), 46)).append("|װͼŰ汾=") + .append(value(property(proRev, "ld6_clientPartRev"), 24)).append("|װ=") + .append(property(tarRev, "object_name")).append("|ԭ=").append(property(proRev, "ld6_reason")) + .append("|ǷҪò=").append(property(proRev, "ld6_ifConcession")).append("|λ=") + .append(property(proRev, "ld6_workpieceStation")).append("|÷Χ=") + .append(property(proRev, "ld6_scope")).append("|ģ״̬=") + .append(property(proRev, "ld6_progsimstat")).append("|=").append(property(proRev, "ld6_type")); + // жǷҪӹߡߡԼӦʱӵ + if (choice == 1 || choice == 4) { + String property = property(proRev, "ld6_creatordate1"); + if(property.contains("00:00")) { + property = property.replace("00:00", ""); + } + builder.append("|=").append(property(proRev, "ld6_creator")).append("|=") + .append(property); + } else if (choice == 2 || choice == 5) { + String property = property(proRev, "ld6_creatordate1"); + if(property.contains("00:00")) { + property = property.replace("00:00", ""); + } + builder.append("|=").append(property(proRev, "ld6_creator2")).append("|=") + .append(property); + } + for (int j = 0; j < meopMap.size(); j++) { + builder.append("|").append(j + 1).append("=").append(sequences.get(slist.get(j)));// .getItemRevision().getProperty("object_name") + } + File saveFile = new File(System.getProperty("java.io.tmpdir") + "\\word.txt"); + if (saveFile.exists()) { + saveFile.delete(); + } + saveFile.createNewFile(); + buffered = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(saveFile, true))); + buffered.write(builder.toString()); + buffered.close(); + String pluginsDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); + pluginsDir = pluginsDir.substring(1, pluginsDir.lastIndexOf("/")); + runWsf(pluginsDir + "\\SubstMacros-MSWord.wsf", new String[] { newFile.getPath(), saveFile.getPath() }); + +// String name = file.getName().replace(".docx", "");//TODO name +// String name = model.getProperty("object_name"); + + // 鿴·Ƿijδı֪ͨECNĸĺϵ + String changeID = ""; + AIFComponentContext[] whereReferenced = proRev.whereReferenced(); + for (AIFComponentContext componentContext : whereReferenced) { + TCComponent component = (TCComponent) componentContext.getComponent(); + System.out.println("component.getType():" + component.getType()); + if ("LD6_CNRevision".equals(component.getType())) { + // δ + if (!KUtil.isTCM(component)) { + // ȡϵµĶ + TCComponent[] referenceListProperty = component.getReferenceListProperty("CMHasSolutionItem"); + for (TCComponent component2 : referenceListProperty) { + if (proRev.getStringProperty("item_id").equals(component2.getStringProperty("item_id"))) { + changeID = component.getStringProperty("item_id"); + break; + } + } + if (!changeID.isEmpty()) { + break; + } + } + } + } + +// StringBuilder names = new StringBuilder(""); +// if (choice == 1) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("ӹտƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } else if (choice == 2) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("տƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } else if (choice == 3) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("װտƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } else if (choice == 4) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("ӹʱտƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } else if (choice == 5) { +// names.append(proRev.getProperty("ld6_partName")).append("_") +// .append(proRev.getProperty("ld6_clientPartNum")).append("_") +// .append(proRev.getProperty("ld6_clientPartRev")).append("_") +// .append(proRev.getProperty("item_revision_id")).append("_") +// .append(proRev.getProperty("ld6_keyMT")).append("ʱտƬ") +// .append(proRev.getProperty("ld6_SeqNum_Comp")).append(changeID); +// } +// String name = names.toString(); + String name = ""; + if (choice == 1) { + name = getDatasetName(proRev, "Connor_Exportname1_Mapping", changeID); + } else if (choice == 2) { + name = getDatasetName(proRev, "Connor_Exportname2_Mapping", changeID); + } else if (choice == 3) { + name = getDatasetName(proRev, "Connor_Exportname3_Mapping", changeID); + } else if (choice == 4) { + name = getDatasetName(proRev, "Connor_Exportname4_Mapping", changeID); + } else if (choice == 5) { + name = getDatasetName(proRev, "Connor_Exportname5_Mapping", changeID); + } + System.out.println("name:"+name); + + boolean create = true; + for (AIFComponentContext c : proRev.getChildren("IMAN_specification")) { + TCComponent comp = (TCComponent) c.getComponent(); + if (comp.isTypeOf("MSWordX") && comp.getProperty("object_name").contains(oldName)) { + KUtil.setByPass(session, true); + proRev.remove("IMAN_specification", comp); +// comp.delete(); + KUtil.setByPass(session, false); + break; + } + } + if (create) { + File namedref = new File(newFile.getParent() + "\\" + name + ".docx"); + if (namedref.exists()) + namedref.delete(); +// if(!file.getName().equals(name+".docx")) + newFile.renameTo(namedref); + System.out.println("newFile:" + namedref.getPath()); + TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService() + .getTypeComponent("Dataset"); + TCComponentDataset dataset = compType.create(name, "", "MSWordX"); + dataset.setFiles(new String[] { namedref.getAbsolutePath() }, new String[] { "word" }); + proRev.add("IMAN_specification", dataset); + } + + MessageBox.post(desktop, "", "INFO", MessageBox.INFORMATION); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, "" + e.getMessage(), "ERROR", MessageBox.ERROR); + } finally { + if (input != null) + input.close(); + if (output != null) + output.close(); + if (buffered != null) + buffered.close(); + } + } + + private String getDatasetName(TCComponentItemRevision revision, String name, String id) throws TCException { + String[] stringValues = session.getPreferenceService().getStringValues(name); + if (stringValues == null || stringValues.length == 0) { + MessageBox.post("ѡ" + name + "òȷ", "ERROR", MessageBox.ERROR); + return null; + } + if (!stringValues[0].contains("ӹտƬ") && !stringValues[0].contains("տƬ") + && !stringValues[0].contains("װտƬ") && !stringValues[0].contains("ӹʱտƬ") + && !stringValues[0].contains("ʱտƬ")) { + MessageBox.post("ѡ" + name + "òȷ,ȱٹؼʡ*տƬ", "ERROR", MessageBox.ERROR); + return null; + } + System.out.println(stringValues[0]); + String[] split = stringValues[0].split("\\|"); + StringBuilder names = new StringBuilder(""); + for (String str : split) { + String[] split2 = str.split("\\."); + String value = ""; + if (split2.length == 1) { + if (split2[0].contains("ECNID")) { + if(!id.isEmpty()) { + value = split2[0].replaceAll("ECNID", id); + }else { + value = ""; + } + + } else { + value = split2[0]; + } + } else if (split2.length == 2) { + if ("item".equals(split2[0])) { + value = property(revision.getItem(), split2[1]); + } else if ("rev".equals(split2[0])) { + value = property(revision, split2[1]); + } + + } else if (split2.length == 4) { + // ȡϵ + TCComponent[] referenceListProperty = revision.getReferenceListProperty(split2[0]); + for (TCComponent component : referenceListProperty) { + if (split2[1].equals(component.getType())) { + if ("item".equals(split2[2])) { + value = property(((TCComponentItemRevision) component).getItem(), split2[3]); + } else if ("rev".equals(split2[2])) { + value = property((TCComponentItemRevision) component, split2[3]); + } + } + } + } else { + MessageBox.post("ѡ" + name + "", "ERROR", MessageBox.ERROR); + return null; + } + names.append(value); + } + return names.toString(); + } + + private String getChineseNum(int num) throws Exception { + String value = ""; + int ten = num / 10, n = num % 10; + if (ten > 1) + value += nums.get(ten) + "ʮ"; + else if (ten == 1) + value += "ʮ"; + value += nums.get(n); + return value; + } + + private String property(TCComponent comp, String prop) { + try { + TCProperty tcprop = comp.getTCProperty(prop); + if (tcprop == null) + return ""; + return comp.getProperty(prop); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + private String value(String str, int max) { + int len = str.length(); + if (len < 1 || len >= max) + return str; + int count = 0; + for (int i = 0; i < len; i++) { + char c = str.charAt(i); + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) + count += 1; + else + count += 2; + } + if (count >= max) + return str; + StringBuilder sb = new StringBuilder(str); + for (int i = 0; i < (max - count) / 2; i++) { + sb.insert(0, " ").append(" "); + } + return sb.toString(); + } + + private int rowCount(String str) { + if (str == null) + return 0; + return str.replaceAll("\n", "\n0").length() - str.length(); + } + + /* + * private int rowCount(String str, int max) { String[] ss = str.split("\n"); + * int r = ss.length; for(String s : ss) { int w = s.length(); for(int i=0; + * i='0' && c<=9) && !(c>='a' + * && c<='z')) w += 1; } r += w/max; } return r; } + */ + + private int rowCount(String str, int max, int first, int row) { + System.out.println("str:"+str); + System.out.println("max:"+max); + System.out.println("first:"+first); + System.out.println("row:"+row); +// int r = str.replaceAll("\n", "\n0").length() - str.length(); + int r = rowCount(str); + System.out.println("r:"+r); + int f2 = first * 2 + 1; + System.out.println("f2:"+f2); + if (row == 0) { + if (r > f2) + return 2 + rowCount(r - f2, true); + else if (r > first) + return 2; + else + return 1; + } else if (row == 1) { + if (r > first) + return 1 + rowCount(r - first, true); + else + return 1; + } else { + return rowCount(r, row % 2 == 0); + } + } + + private int rowCount(int row, boolean up) { + if (row <= 13) + return 1; + else { + if (up) { + if (row <= 27) + return 2; + else + return 2 + rowCount(row - 27, true); + } else { + return 1 + rowCount(row - 13, true); + } + } + } + + private StringBuilder shiftRow(String str, int max) { + str = str.replaceAll("\n\n", "\n"); + int len = str.replaceAll("\n", "").length(); +// System.out.println("shiftRow"+len+""+max/2+""+str.indexOf("\n")); + if (len < max / 2) + return new StringBuilder(str); + + if (str.indexOf("\n") < 0) { + StringBuilder sb = new StringBuilder(str); + int count = 1; + for (int i = 0; i < len; i++) { + char c = str.charAt(i); + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || symbols.contains(c)) + count += 1; + else + count += 2; + if (count >= max) {// && count= '0' && c <= '9') || (c >= 'a' && c <= 'z') || symbols.contains(c)) + count += 1; + else + count += 2; +// if(s.startsWith("־")) +// System.out.println("count"+sbd+""+count+""+l); + if (count >= max) {// && count 0 && sb.substring(sb.length() - 1).equals("\n")) + sb.deleteCharAt(sb.length() - 1); + return sb; + } + } + + private void write(String[] data, int h) throws Exception { + Table table = tables.get(totalRow / 2); + int uod = totalRow % 2; + int row = totalRow > 1 ? (3 + uod) : (5 + uod);// TODO + if (totalRow < 2 && choice > 3) + row += 2; +// String[] data = datas.get(i); +// if(i<2 && h<=first || h<=13) { +// System.out.println("data3"+data[2]+""+data[0]); +// if(h>0) { +// for(int a= 0;a 1 ? 13 : first); + each = each * 2; + System.out.println("3.1:"+data[0]); + setText(table.get(row, 0).getParagraphs().get(0), data[0]); + table.applyVerticalMerge(0, row, row + 1); + System.out.println("3.2:"+data[1]); + setText(table.get(row, 1).getParagraphs().get(0), data[1]); + table.applyVerticalMerge(1, row, row + 1); + for (int j = 2; j < 5; j++) { + TableCell tableCell = table.get(row, j); + ParagraphCollection paragraphs = tableCell.getParagraphs(); + for(int n=0;n 1 ? 13 : first); + System.out.println("5.1:"+data[0]); + table.get(row, 0).getParagraphs().get(0).setText(""); + setText(table.get(row, 0).getParagraphs().get(0), data[0]); + + System.out.println("5.2:"+data[1]); + table.get(row, 1).getParagraphs().get(0).setText(""); + setText(table.get(row, 1).getParagraphs().get(0), data[1]); + for (int j = 2; j < 5; j++) { + TableCell tableCell = table.get(row, j); + ParagraphCollection paragraphs = tableCell.getParagraphs(); + for(int n=0;n", t)); + String s5 = data.substring(data.indexOf(">", t) + 1); + setText(parag, s1); + StringBuilder sb = new StringBuilder("$"); + sb.append(s2).append("_{").append(s3).append("}^{").append(s4).append("}$"); + + OfficeMath officeMath2 = new OfficeMath(doc); + parag.getItems().add(officeMath2); + officeMath2.fromLatexMathCode(sb.toString()); + + setText(parag, s5); + } else if (data.contains("")) { + String[] split = data.split(""); + for (int j = 0; j < split.length; j += 2) { +// parag.appendText(split[j]); + setText(parag, split[j]); + if (j + 1 < split.length) + parag.appendText(split[j + 1]).getCharacterFormat().setSubSuperScript(SubSuperScript.Super_Script);// TODO + } + } else if (data.contains("<#G>")) { + String[] split = data.split("<#G>"); + for (int i = 0; i < split.length; i++) { +// parag.appendText(split[j]); + setText(parag, split[i]); + if (i + 1 < split.length) { +// ShapeObject triangle = parag.appendShape(10, 5, ShapeType.Triangle); +// +// triangle.setStrokeColor(Color.BLACK); +// triangle.setFillColor(Color.WHITE); +//// triangle.setVerticalPosition(50); +//// triangle.setHorizontalPosition(170);S +// triangle.setRotation(225); +// +// triangle.setTextWrappingStyle(TextWrappingStyle.Through); + getHTML(parag, "<#G>"); + } + } + } else { + String[] options = session.getPreferenceService().getStringValues("connor_gdt_custom_symbols"); + boolean hast = false; + for (String s : options) { + String[] ss = s.split("="); + String sy = ""; + if (ss.length == 2 && data.contains(ss[0])) { + sy = ss[0]; + hast = true; + } else if (ss.length == 3 && data.contains(ss[1])) { + sy = ss[1]; + hast = true; + } + if (sy.isEmpty()) + continue; + String[] split = data.split(sy); + for (int i = 0; i < split.length; i++) { + setText(parag, split[i]); + if (i + 1 < split.length) { + getHTML(parag, sy); + } + } + + } + if (!hast) + parag.appendText(data); + } + } + + private void getHTML(Paragraph parag, String txt) { + String htmlstring = KGenerateGDTHTML.generatePage(txt); + System.out.println(txt + " == " + htmlstring); + parag.appendHTML(htmlstring); +// String out = System.getProperty("java.io.tmpdir") + "\\out.html"; +// File htmlfile = new File(out); +// if(htmlfile.exists()) +// htmlfile.delete(); +// htmlfile.createNewFile(); +// FileWriter fos = new FileWriter(htmlfile); +// fos.write(htmlstring); +// fos.close(); + +// Document doc = new Document(); +// doc.loadFromFile(out, FileFormat.Html, XHTMLValidationType.None); +// Paragraph d = doc.getSections().get(0).getParagraphs().get(0); + +// parag. + } + + private TCComponent[] TCsort(TCComponent[] TCComponent, String property) { + HashMap map = new HashMap<>(); + int count = TCComponent.length; + for (TCComponent comp : TCComponent) { + try { + map.put(comp, comp.getProperty(property)); + } catch (Exception e) { + e.printStackTrace(); + } + } + // ͨArrayList캯map.entrySet()תlist + List> list = new ArrayList>(map.entrySet()); + // ͨȽʵֱȽ + Collections.sort(list, new Comparator>() { + public int compare(Map.Entry mapping1, Map.Entry mapping2) { +// return mapping1.getValue().compareTo(mapping2.getValue()); + int v1 = Integer.parseInt(mapping1.getValue()); + int v2 = Integer.parseInt(mapping2.getValue()); + return v1 - v2; + } + }); + TCComponent = new TCComponent[count]; + int i = 0; + for (Map.Entry mapping : list) { + TCComponent[i] = mapping.getKey(); + i++; + } + return TCComponent; + } + + public static void runWsf(String wsfPath, String[] paras) throws Exception { + ArrayList cmdVector = new ArrayList<>(); + cmdVector.add("wscript"); + cmdVector.add(wsfPath); + for (String para : paras) { + cmdVector.add(para); + } + StringBuilder builder = new StringBuilder("wscript ").append(wsfPath).append(" ").append(paras[0]).append(" ") + .append(paras[1]); + System.out.println(builder.toString()); + String[] cmd = (String[]) cmdVector.toArray(new String[cmdVector.size()]); +// for (int i = 0; i < cmd.length; i++) { +// System.out.println(cmd[i]); +// } + Process process = Runtime.getRuntime().exec(cmd); + process.waitFor(); +// MessageBox.post("Success!","INFORMATION",MessageBox.INFORMATION); +// Runtime.getRuntime().exec(paras[0]); + } +} diff --git a/src/com/connor/ldy/process/test.java b/src/com/connor/ldy/process/test.java new file mode 100644 index 0000000..7422591 --- /dev/null +++ b/src/com/connor/ldy/process/test.java @@ -0,0 +1,64 @@ +/** * @Title: test.java + * @Package com.connor.ldy.process + * @Description: TODO(һ仰ļʲô) + * @author admin * @date 202464 + * @version V1.0 + */ +package com.connor.ldy.process; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import com.teamcenter.services.loose.core._2008_06.DataManagement.RelatedObjectInfo; + +/** + * @ClassName: test + * @Description: TODO(һ仰) + * @author admin + * @date 202464 + * + */ +public class test { + public static void main(String[] args) { + Map map = new HashMap(); + Map map2 = new HashMap(); + String str = "汾1:1 = ֵ1 |{ ݼ1 :( 1 , 2 ); ݼ2 :( 1 ,2)};2 = ֵ2 |{ ݼ1 :( 1 , 2 ); ݼ2 :( 1 ,2 )}"; + if(str.endsWith(")}")) { + String replaceAll = str.replaceAll("\\)}", ""); + System.out.println(replaceAll); + String[] split = replaceAll.split(":"); + System.out.println(split[1]); + String[] split2 = split[1].split(";"); + + for (String string : split2) { + System.out.println(string); + String[] split3 = string.split("\\|\\{"); + System.out.println(split3[1]); + String[] split4 = split3[1].split("\\);"); + String[] split4sStrings = new String[split4.length]; + + for (int i=0;i l_user; + private DefaultListModel lm_user; + private JTextField editPropMap; +// private String group; + private boolean isMulti; + private JTable table; + private int colIndex; + private int[] rowIndex; + private TCComponentProject project; + private HashMap userMap; + + public SelectUserDialog(JTextField editPropMap, boolean isMulti) throws Exception { + super(true); + this.editPropMap = editPropMap; + this.isMulti = isMulti; + initUI(); + } + + private String getValue() { + String val = ""; + if (editPropMap != null) { + val = editPropMap.getText(); + } else if (table != null) { + val = (String) table.getValueAt(rowIndex[0], colIndex); + } + return val; + } + + private void setValue(String text) { + if (editPropMap != null) { + editPropMap.setText(text); + } else if (table != null) { + for(int i : rowIndex) + table.setValueAt(text, i, colIndex); + } + } + + public SelectUserDialog(JTable table, boolean isMulti, int[] rowIndex, int colIndex, TCComponentProject projectID) throws Exception { + super(true); + this.table = table; + this.isMulti = isMulti; + this.colIndex = colIndex; + this.rowIndex = rowIndex; + this.project = projectID; + initUI(); + } + + public SelectUserDialog(JTable table, int[] rowIndex, int colIndex, HashMap userMap) throws Exception { + super(true); + this.table = table; + this.colIndex = colIndex; + this.rowIndex = rowIndex; + this.userMap = userMap; + initUI(); + } + + private void initUI() throws Exception { + this.setTitle("ѡԱ"); + this.setLayout(new BorderLayout()); + int pweight = 440, pheight = 480, mweight = 280, mheight = 320; + if (isMulti) { +// this.setPreferredSize(new Dimension(640, 480)); +// this.setMinimumSize(new Dimension(480, 320)); + pweight = 640; + mweight = 480; + } + if(project != null) { + pheight = 700; + mheight = 700; + } + this.setPreferredSize(new Dimension(pweight, pheight)); + this.setMinimumSize(new Dimension(mweight, mheight)); + OrgTreePanel orgPanel = new OrgTreePanel((TCSession) AIFUtility.getCurrentApplication().getSession()); + this.tree = orgPanel.getOrgTree(); + + if(project != null) { + JPanel panel = new JPanel(new PropertyLayout()); + panel.add("1.1.center.center", orgPanel); + panel.add("2.1.center.center", initProjectPanel(orgPanel)); +// FlowLayout flow = new FlowLayout(); +// flow.setAlignOnBaseline(true); +// JPanel panel = new JPanel(flow); +// panel.add(orgPanel); +// panel.add(initProjectPanel(orgPanel)); + this.add(BorderLayout.WEST, panel); + }else { + this.add(BorderLayout.CENTER, orgPanel); + } + this.add(BorderLayout.SOUTH, initBtnPanel()); + if (isMulti) { + JPanel lp = initListPanel(); + this.add(BorderLayout.EAST, lp); + initData(); + } + addListeners(); + this.setAlwaysOnTop(true); + } + + private void initData() { + String text = getValue(); + if (text.isEmpty()) { + return; + } + String[] split = text.split(","); + for (int i = 0; i < split.length; i++) { + lm_user.addElement(split[i]); + } + } + + private JPanel initListPanel() { + JPanel panel = new JPanel(new BorderLayout()); + FlowLayout flow = new FlowLayout(); + flow.setVgap(100); + JPanel btnPanel = new JPanel(flow); + btnPanel.add(this.add); +// btnPanel.add("2.1.center.center", this.remove); + this.lm_user = new DefaultListModel<>(); + this.l_user = new JList<>(lm_user); + l_user.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + this.l_user.setCellRenderer(new DeleteListRenderer(l_user)); + JScrollPane scroll = new JScrollPane(l_user); + scroll.setPreferredSize(new Dimension(200, 0)); +// this.add.setPreferredSize(new Dimension(50, 30)); + panel.add(BorderLayout.WEST, btnPanel); + panel.add(BorderLayout.CENTER, scroll); + return panel; + } + + private JPanel initBtnPanel() { + JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 5)); + this.b_ok = new JButton("ȷ"); + this.b_cel = new JButton("ȡ"); + this.add = new JButton("+"); + this.remove = new JButton("-"); + panel.add(b_ok); + panel.add(b_cel); + return panel; + } + + private JScrollPane initProjectPanel(OrgTreePanel orgPanel) throws Exception {//TODO + Dimension orgDimension = orgPanel.getPreferredSize(); + orgPanel.setPreferredSize(new Dimension(orgDimension.width*2, orgDimension.height-100)); + DefaultMutableTreeNode root = new DefaultMutableTreeNode(project.getProjectID(), true); + projectTree = new JTree(root); + + List team = project.getTeam(); + TCComponent[] members = (TCComponent[])team.get(0); + for(TCComponent c : members) { + if(c instanceof TCComponentGroupMember) { + TCComponentGroupMember member = (TCComponentGroupMember)c; + DefaultMutableTreeNode childRoot = new DefaultMutableTreeNode(member, true); + root.add(childRoot); + } + } + + projectTree.setPreferredSize(new Dimension(orgDimension.width*2, orgDimension.height/2)); +// projectTree.setMaximumSize(new Dimension(orgDimension.width*2, orgDimension.height/2)); + JScrollPane projectPane = new JScrollPane(projectTree); + return projectPane; + } + + private TCComponentUser getSelectUser() throws Exception { +// Object[] comps = tree.getSelectedOrgObjects(); + AIFTreeNode[] comps = tree.getSelectedNodes(); +// System.out.println("comps:"+(comps==null)); + if (comps == null) { + if(projectTree == null) + return null; + else if(projectTree.getSelectionModel() == null) + return null; + else if(projectTree.getLastSelectedPathComponent() == null) + return null; + DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) projectTree.getLastSelectedPathComponent(); + Object selectObject = selectNode.getUserObject(); + if(selectObject instanceof TCComponentGroupMember) { +// String member = ((TCComponentGroupMember) selectObject).toString(); +// if(member.indexOf(".")>0) +// group = member.substring(0, member.indexOf(".")); +// else +// group = member.substring(0, member.indexOf("/")); + TCComponentUser user = ((TCComponentGroupMember) selectObject).getUser(); + if (user != null) { + return user; + } + }else + return null; + } +// System.out.println("comps:"+comps.length); + for (int i = 0; i < comps.length; i++) { +// OrgObject comp = (OrgObject) comps[i]; + TCComponent gm = (TCComponent) comps[i].getContextComponent().getComponent(); +// System.out.println("gm:"+gm); + if (gm != null && (gm instanceof TCComponentGroupMember)) { + TCComponentUser user = ((TCComponentGroupMember) gm).getUser(); + if (user != null) { +// group = ((DefaultMutableTreeNode)comps[i].getParent().getParent()).getUserObject().toString(); + return user; + } + } + } + return null; + } + + private void addListeners() { + this.b_cel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + disposeDialog(); + } + }); + this.b_ok.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + if (isMulti) { + int size = lm_user.getSize(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < size; i++) { + String text = lm_user.getElementAt(i); + if (text != null) { + sb.append(text).append(";"); + } + } + if (sb.length() > 0) { + sb.setLength(sb.length() - 1); + } + setValue(sb.toString()); + } else { + TCComponentUser user = getSelectUser(); + if (user != null) { + String value = user.getUserId() +"/"+ user.getUserName(); + userMap.put(value, user); + setValue(value); + } else { + setValue(""); + } + } + disposeDialog(); + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + + tree.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + try { + super.mouseClicked(e); + if(projectTree != null) + projectTree.clearSelection(); + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + TCComponentUser user = getSelectUser(); + System.out.println("user:"+user); + if (user != null) { + if (isMulti) { + if (!lm_user.contains(user.toString())) { + lm_user.addElement(user.toString()); + } + } else { + String value = user.getUserId() +"/"+ user.getUserName(); + userMap.put(value, user); + setValue(value); + disposeDialog(); + } + } + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + if(projectTree != null) { + projectTree.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + try { + super.mouseClicked(e); + tree.clearSelection(); + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + TCComponentUser user = getSelectUser(); + if (user != null) { + if (isMulti) { + if (!lm_user.contains(user.toString())) { + lm_user.addElement(user.toString()); + } + } else { + String value = user.getUserId() +"/"+ user.getUserName(); + userMap.put(value, user); + setValue(value); + disposeDialog(); + } + } + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + } + if(l_user!=null) { + this.l_user.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + int ind = l_user.getSelectedIndex(); + if (ind >= 0) { + lm_user.remove(ind); + } + } + + @Override + public void mouseEntered(MouseEvent e) { + super.mouseEntered(e); + } + + @Override + public void mouseExited(MouseEvent e) { + super.mouseExited(e); + } + + }); + } + this.add.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + TCComponentUser user = getSelectUser(); + System.out.println("user:"+user); + if (user != null) { + if (!lm_user.contains(user.toString())) { + lm_user.addElement(user.toString()); + } + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + this.remove.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + disposeDialog(); + } + }); + } + private class DeleteListRenderer extends JPanel implements ListCellRenderer { + + /** + * + */ + private static final long serialVersionUID = 1L; + JButton btn; + JLabel label; + + public DeleteListRenderer(final JList list) { + this.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 1)); + this.setBackground(Color.WHITE); + btn = getDeletetBtn(); + label = new JLabel(""); + this.add(btn); + this.add(label); + + btn.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + int ind = list.getSelectedIndex(); + System.out.println(ind); + if (ind >= 0) { + list.remove(ind); + } + } + }); + + } + @Override + public Component getListCellRendererComponent(JList list, String value, int index, + boolean isSelected, boolean cellHasFocus) { + label.setText(value); + return this; + } + private JButton getDeletetBtn() { + ImageIcon icon = new ImageIcon(SelectUserDialog.class.getResource("image/delete.png")); + JButton btn = new JButton(icon); + btn.setPreferredSize(new Dimension(23, 23)); + btn.setContentAreaFilled(false); + btn.setFocusPainted(false); + btn.setBorderPainted(false); + btn.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + return btn; + } + } +} diff --git a/src/com/connor/ldy/util/SqlUtil.java b/src/com/connor/ldy/util/SqlUtil.java new file mode 100644 index 0000000..efa02f1 --- /dev/null +++ b/src/com/connor/ldy/util/SqlUtil.java @@ -0,0 +1,685 @@ +package com.connor.ldy.util; + +import java.io.Reader; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.Statement; +import java.sql.Timestamp; +import java.sql.Types; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +public class SqlUtil { + + public static Connection connection = null; + public static PreparedStatement ps = null; + public static ResultSet rs = null; +// public static Registry reg = Registry.getRegistry(SqlUtil.class); + public static int ORACLE = 1; + public static int SQLSERVER = 2; + +// public static Connection getConnection(int dbType) { +// if (dbType == ORACLE) { +// return getOracleConnection(); +// } else if (dbType == SQLSERVER) { +// return getSqlserverConnection(); +// } +// return null; +// } + + public static Date getDate(java.sql.Date date) { + if (date == null) { + return null; + } + return new Date(date.getTime()); + } + + /** + * ݿ + + public static Connection getSqlserverConnection() { + String driver = reg.getString("SQL.SQLSERVER.DRIVER"); + String url = reg.getString("SQL.SQLSERVER.URL"); + String user = reg.getString("SQL.SQLSERVER.USER"); + String password = reg.getString("SQL.SQLSERVER.PASSWORD"); + System.out.println("ݿϢ"); + System.out.println("DRIVER: " + driver); + System.out.println("URL: " + url); + System.out.println("USER: " + user); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + try { + // + Class.forName(driver); + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + }*/ + + public static Connection getSqlserverConnection(String driver, String url, String user, String password) { +// String driver = reg.getString("SQL.SQLSERVER.DRIVER"); +// String url = reg.getString("SQL.SQLSERVER.URL"); +// String user = reg.getString("SQL.SQLSERVER.USER"); +// String password = reg.getString("SQL.SQLSERVER.PASSWORD"); + System.out.println("ݿϢ"); +// System.out.println("DRIVER: " + driver); +// System.out.println("URL: " + url); +// System.out.println("USER: " + user); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + try { + // + Class.forName(driver); + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + } + + public static Connection getOracleConnection(String url, String user, String password) { + String driver = "oracle.jdbc.driver.OracleDriver"; + System.out.println("ݿϢ"); + System.out.println("DRIVER: " + driver); + System.out.println("URL: " + url); + System.out.println("USER: " + user); + if (connection != null) { + try { + connection.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + connection = null; + } + try { + // + Class.forName(driver); + // 1.getConnection()MySQLݿ⣡ + connection = DriverManager.getConnection(url, user, password); + connection.setAutoCommit(false); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + } + + /* + public static Connection getOracleConnection() { + // String driver = reg.getString("SQL.ORACLE.DRIVER"); + String url = reg.getString("SQL.ORACLE.URL"); + String user = reg.getString("SQL.ORACLE.USER"); + String password = reg.getString("SQL.ORACLE.PASSWORD"); +// if(prefs!=null&&prefs.length==5) { +// url = "jdbc:oracle:thin:@"+prefs[0]+":"+prefs[1]+":"+prefs[2]; +// user = prefs[3]; +// password = prefs[4]; +// } + return getOracleConnection(url, user, password); + }*/ + + /** + * ˽йnew󣬷ֹö + */ + private SqlUtil() { + } + + /** + * ƴSELECT + * + * @param tableName + * @param selectElement + * @param args + * @return + */ + public static String getSelectSql(String tableName, String[] selectElement, String... args) { + StringBuffer valuesSB = new StringBuffer("SELECT "); + if (selectElement != null) { + for (String element : selectElement) { + valuesSB.append(element).append(","); + } + valuesSB.delete(valuesSB.length() - 1, valuesSB.length()); + } + valuesSB.append(" FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE"); + for (int i = 0; i < args.length; i++) { + valuesSB.append(" "); + valuesSB.append(args[i]); + valuesSB.append("=? "); + valuesSB.append("AND"); + } + + valuesSB.delete(valuesSB.length() - 3, valuesSB.length()); + return valuesSB.toString(); + } + + /** + * ƴSELECT + * + * @param tableName + * @param args + * @return + */ + public static String getSelectSql(String tableName, String... args) { + StringBuffer valuesSB = new StringBuffer("SELECT * FROM "); + valuesSB.append(tableName); + valuesSB.append(" WHERE"); + for (int i = 0; i < args.length; i++) { + valuesSB.append(" "); + valuesSB.append(args[i]); + valuesSB.append("=? "); + valuesSB.append("AND"); + } + + valuesSB.delete(valuesSB.length() - 3, valuesSB.length()); + return valuesSB.toString(); + } + + /** + * ƴӸ + * + * @param tableName + * @param args + * @param args2 + * @return + */ + public static String getUpdataSQL(String tableName, String[] args, String[] args2) { + StringBuffer updateSB = new StringBuffer("UPDATE "); + updateSB.append(tableName); + updateSB.append(" SET "); + // ƴӸ + for (int i = 0; i < args.length; i++) { + if (args[i].toUpperCase().equals("CREATED_DATE") || args[i].toUpperCase().equals("LAST_UPDATE_DATE")) { + updateSB.append(args[i]).append("=to_date(?,'yyyy-MM-dd HH24:mi:ss') ,"); + } else { + updateSB.append(args[i]).append("=? ,"); + } + } + updateSB.delete(updateSB.length() - 2, updateSB.length()); + ; + updateSB.append(" WHERE "); + for (int i = 0; i < args2.length; i++) { + updateSB.append(args2[i]).append("=? AND "); + } + updateSB.delete(updateSB.length() - 4, updateSB.length()); + return updateSB.toString(); + } + + /** + * ƴSQLinsert + * + * @param tableName + * @param args + * @return + */ + public static String getInsertSql(String tableName, String... args) { + StringBuffer insertSql = new StringBuffer("insert into "); + StringBuffer values = new StringBuffer("values("); + + if (tableName != null && args != null && args.length > 0) { + insertSql.append(tableName); + insertSql.append("("); + for (int i = 0; i < args.length; i++) { + insertSql.append(args[i]); + insertSql.append(", "); + if (args[i].toUpperCase().equals("LAST_UPDATE_DATE") || args[i].toUpperCase().equals("CREATED_DATE")) { + values.append("to_date(?,'yyyy-MM-dd HH24:mi:ss'), "); + } else { + values.append("?, "); + } + + } + } else { + return null; + } + insertSql.delete(insertSql.length() - 2, insertSql.length()); + values.delete(values.length() - 2, values.length()); + insertSql.append(") ").append(values).append(")"); + return insertSql.toString(); + } + + /** + * õݿ + * + * @param tableName + * @param args + * + * @param args2 + * + * @return ƴӺĴݿ + */ + public final static String GetCreateTableSQL(String tableName, String[] args, String[] args2) { + + if (args == null || args2 == null || args.length != args2.length) { + System.out.println("THE INPUT PRAGREMS IS ERROR"); + return null; + } + StringBuffer createSQL = new StringBuffer("create table "); + createSQL.append(tableName); + createSQL.append("("); + for (int i = 0; i < args.length; i++) { + createSQL.append(args[i] + " "); + createSQL.append(args2[i] + ", "); + } + createSQL.delete(createSQL.length() - 2, createSQL.length()); + createSQL.append(")"); + return createSQL.toString(); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql) throws Exception { + return getPs(sql, null); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(Object[] argments, String sql) throws Exception { + return getPs(sql, argments); + } + + /** + * õStatement + */ + public final static PreparedStatement getPs(String sql, Object[] argments) throws Exception { + SqlUtil.ps = SqlUtil.connection.prepareStatement(sql); + if (argments != null) { + for (int i = 0; i < argments.length; i++) { + SqlUtil.ps.setObject(i + 1, argments[i]); + } + } + return SqlUtil.ps; + } + + /** + * + */ + public final static int write(String sql) { + return write(sql, null); + } + + /** + * + */ + public final static int write(Object[] argments, String sql) { + return write(sql, argments); + } + + /** + * + */ + public final static int write(String sql, Object[] argments) { + + return update(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql) { + return delete(sql, null); + } + + /** + * ɾ + */ + public final static int delete(Object[] argments, String sql) { + return delete(sql, argments); + } + + /** + * ɾ + */ + public final static int delete(String sql, Object[] argments) { + return update(sql, argments); + } + + /** + * ޸ + */ + public final static int update(String sql) { + return update(sql, null); + } + + /** + * ޸ + */ + public final static int update(String[] argments, String sql) { + return update(sql, argments); + } + + /** + * ޸(ɾնҪô˷˴쳣رճConnectionΪĶ) + */ + public final static int update(String sql, Object[] argments) { + int i = -1; + try { + i = SqlUtil.getPs(argments, sql).executeUpdate(); + SqlUtil.connection.commit(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + return i; + } + + /** + * ѯ + */ + public final static ResultSet read(String sql) throws Exception { + return read(sql, null); + } + + /** + * ѯ + */ + public final static ResultSet read(Object[] argments, String sql) throws Exception { + return read(sql, argments); + } + + /** + * ѯ(вѯնҪô˷治쳣׳ɵߴfinallyͷԴ) + * + * @throws SQLException + */ + public final static ResultSet read(String sql, Object[] argments) throws Exception { + System.out.println("argments=" + argments.length); + return SqlUtil.rs = SqlUtil.getPs(argments, sql).executeQuery(); + } + + /** + * + */ + public final static boolean createTable(String sql) { + return go(sql, null); + } + + /** + * ɾ + */ + public final static boolean dropTable(String sql) { + return go(sql, null); + } + + /** + * ޸ı + */ + public final static boolean alterTable(String sql) { + return go(sql, null); + } + + /** + * ˷ִDDL(,޸ı,ɾ) + */ + private final static boolean go(String sql, Object[] argments) { + boolean flag = false; + try { + flag = SqlUtil.getPs(sql, argments).execute(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + free(SqlUtil.rs, SqlUtil.ps); + } + if (flag) { + try { + SqlUtil.connection.commit(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return flag; + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet) { + free(resultSet, null, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement) { + free(null, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Connection connection) { + free(null, null, connection); + } + + /** + * ͷԴ + */ + public final static void free(ResultSet resultSet, Statement statement) { + free(resultSet, statement, null); + } + + /** + * ͷԴ + */ + public final static void free(Statement statement, Connection connection) { + free(null, statement, connection); + } + + /** + * ͷԴ(Ĭϲ) + */ + public final static void free() { + free(SqlUtil.rs, SqlUtil.ps); + } + + /** + * ͷԴ(ȫͷ) + */ + public final static void freeAll() { + free(SqlUtil.rs, SqlUtil.ps, SqlUtil.connection); + } + + /** + * ͷԴ(ҲҪȫͷ) + */ + public final static void free(ResultSet resultSet, Statement statement, Connection connection) { + try { + if (resultSet != null) { + try { + resultSet.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } finally { + try { + if (statement != null) { + try { + statement.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } finally { + if (connection != null) { + try { + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + } + public static List> getDBInfo(Connection connection, String sql) throws Exception { + if (connection == null) { + throw new Exception("޷ȡݿϢ"); + } + + List> vecData = new ArrayList>(); + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(sql); + + ResultSetMetaData meta = rs.getMetaData(); + String[] columnNames = new String[meta.getColumnCount()]; + int[] columnTypes = new int[meta.getColumnCount()]; + + for (int i = 0; i < columnNames.length; i++) { + columnNames[i] = meta.getColumnName(i + 1); + columnTypes[i] = meta.getColumnType(i + 1); + } + + while (rs.next()) { + HashMap dataTable = new HashMap(); + + for (int i = 0; i < columnNames.length; i++) { + Object value = null; + switch (columnTypes[i]) { + case Types.VARCHAR: + value = rs.getString(columnNames[i]); + if (value == null) { + value = ""; + } + break; + case Types.INTEGER: + case Types.NUMERIC: + value = rs.getInt(columnNames[i]); + break; + case Types.DATE: + Timestamp timestamp = rs.getTimestamp(columnNames[i]); + if (timestamp != null) { + value = new Date(timestamp.getTime()); + } + break; + case Types.TIMESTAMP: + value = rs.getTimestamp(columnNames[i]); + break; + case Types.CLOB: + Clob clob = rs.getClob(columnNames[i]); + if (clob != null) { + Reader inStream = clob.getCharacterStream(); + char[] c = new char[(int) clob.length()]; + inStream.read(c); + value = new String(c); + inStream.close(); + } + if (value == null) { + value = ""; + } + break; + default: + value = ""; + break; + } +// if (value == null) { +// value = ""; +// } + dataTable.put(columnNames[i], value); +// System.out.println("data"+columnNames[i]+"=="+columnTypes[i]); + } + vecData.add(dataTable); + } + rs.close(); + statement.close(); + return vecData; + } + public static List getArrayDBInfo(Connection connection, String sql) throws Exception { + if (connection == null) { + throw new Exception("޷ȡݿϢ"); + } + + List vecData = new LinkedList<>(); + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(sql); + + ResultSetMetaData meta = rs.getMetaData(); + String[] columnNames = new String[meta.getColumnCount()]; + int[] columnTypes = new int[meta.getColumnCount()]; + + for (int i = 0; i < columnNames.length; i++) { + columnNames[i] = meta.getColumnName(i + 1); + columnTypes[i] = meta.getColumnType(i + 1); + } + + while (rs.next()) { + Object[] result = new Object[columnNames.length]; + + for (int i = 0; i < columnNames.length; i++) { + Object value = null; + switch (columnTypes[i]) { + case Types.VARCHAR: + value = rs.getString(columnNames[i]); + if (value == null) { + value = ""; + } + break; + case Types.INTEGER: + case Types.NUMERIC: + value = rs.getInt(columnNames[i]); + break; + case Types.DATE: + Timestamp timestamp = rs.getTimestamp(columnNames[i]); + if (timestamp != null) { + value = new Date(timestamp.getTime()); + } + break; + case Types.TIMESTAMP: + value = rs.getTimestamp(columnNames[i]); + break; + case Types.CLOB: + Clob clob = rs.getClob(columnNames[i]); + if (clob != null) { + Reader inStream = clob.getCharacterStream(); + char[] c = new char[(int) clob.length()]; + inStream.read(c); + value = new String(c); + inStream.close(); + } + if (value == null) { + value = ""; + } + break; + default: + value = ""; + break; + } +// if (value == null) { +// value = ""; +// } +// dataTable.put(columnNames[i], value); +// System.out.println("data"+columnNames[i]+"=="+columnTypes[i]); + result[i] = value; + } + vecData.add(result); + } + rs.close(); + statement.close(); + return vecData; + } +} diff --git a/src/com/connor/ldy/util/TCUtil.java b/src/com/connor/ldy/util/TCUtil.java new file mode 100644 index 0000000..701f48a --- /dev/null +++ b/src/com/connor/ldy/util/TCUtil.java @@ -0,0 +1,469 @@ +package com.connor.ldy.util; + +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Toolkit; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import javax.swing.JFileChooser; +import javax.swing.JTable; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.filechooser.FileSystemView; + +import org.apache.poi.xwpf.usermodel.XWPFDocument; + +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.commands.open.OpenFormDialog; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +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.TCComponentContextList; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +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.TCQueryClause; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class TCUtil { + public static final int MINWIDTH = 1280; + public static final int MINHEIGHT = 768; + + public static void fitToScreen(AbstractAIFDialog abstractAIFDialog) { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + double screenWidth = screenSize.getWidth(); + double screenHeight = screenSize.getHeight(); + Dimension dialogSize = abstractAIFDialog.getSize(); + if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) { + abstractAIFDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight()))); + abstractAIFDialog.setLocation(10, (int) Math.floor(abstractAIFDialog.getLocation().getY())); + } + if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) { + abstractAIFDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20))); + abstractAIFDialog.setLocation((int) Math.floor(abstractAIFDialog.getLocation().getX()), 10); + } + /* + * if((screenWidth + * MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { abstractAIFDialog.setSize(new + * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20))); + * abstractAIFDialog.setLocation(10, 10); } + */ + } + + public static void fitToScreen(OpenFormDialog openFormDialog) { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + double screenWidth = screenSize.getWidth(); + double screenHeight = screenSize.getHeight(); + Dimension dialogSize = openFormDialog.getSize(); + if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) { + openFormDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight()))); + openFormDialog.setLocation(10, (int) Math.floor(openFormDialog.getLocation().getY())); + } + if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) { + openFormDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20))); + openFormDialog.setLocation((int) Math.floor(openFormDialog.getLocation().getX()), 10); + } + /* + * if((screenWidth + * MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { openFormDialog.setSize(new + * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20))); + * openFormDialog.setLocation(10, 10); } + */ + } + + public static TCComponentBOMWindow getWindow(TCSession session) throws Exception{ + TCComponentBOMWindow window = null; + TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + window = bomWinType.create(null); + return window; + } + + @SuppressWarnings("deprecation") + public static TCComponentBOMLine getBOMLine(TCSession session,TCComponentBOMWindow window, TCComponentItemRevision revision) + throws Exception { + window.lock(); + TCComponentBOMLine bomLine = window.setWindowTopLine(null, revision, null, null); + window.save(); + window.unlock(); + return bomLine; + } + public static TCComponentPseudoFolder getPseudoFolder(TCComponent parent, String relation) + throws Exception { + TCComponentPseudoFolder pseudoFolder = null; + AIFComponentContext[] comps = parent.getChildren(); + if (comps != null && comps.length > 0 && comps[0] != null) { + for (int i = 0; i < comps.length; i++) { + TCComponent comp = (TCComponent) comps[i].getComponent(); + if (comp instanceof TCComponentPseudoFolder) { + if (comp.isTypeOf("PseudoFolder")) { +// System.out.println("PseudoFolder type:" + comp.getDefaultPasteRelation()); + if (comp.getDefaultPasteRelation().equalsIgnoreCase(relation)) { + pseudoFolder = (TCComponentPseudoFolder) comp; + break; + } + } + } + } + } + return pseudoFolder; + } + public static TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws Exception { + if (revision != null) { + AIFComponentContext[] contexts = revision.getChildren("IMAN_master_form_rev"); + if (contexts != null && contexts.length > 0) { + InterfaceAIFComponent component = contexts[0].getComponent(); + if (component instanceof TCComponentForm) { + return (TCComponentForm) component; + } + } + } + return null; + } + public static TCComponentItemRevision getRevisionFromMaster(TCComponentForm form) throws Exception { + if (form != null) { + AIFComponentContext[] contexts = form.whereReferencedByTypeRelation(null, new String[] { "IMAN_master_form_rev" }); + if (contexts != null && contexts.length > 0) { + InterfaceAIFComponent component = contexts[0].getComponent(); + if (component instanceof TCComponentItemRevision) { + return (TCComponentItemRevision) component; + } + } + } + return null; + } + + public static LinkedHashMap getlovValues(TCSession session, String lovName) throws TCException { + LinkedHashMap lovVal = new LinkedHashMap(); + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues"); + TCComponentListOfValues[] lovs = lovType.find(lovName); + if (lovs != null && lovs.length > 0) { + TCComponentListOfValues lov = lovs[0]; + ListOfValuesInfo lovInfo = lov.getListOfValues(); + String[] code = lovInfo.getStringListOfValues(); + String[] name = lovInfo.getLOVDisplayValues(); + if (code != null && name != null) { + for (int i = 0; i < code.length; i++) { + // System.out.printf("code[%d]=%s name[%d]=%s \n", i, code[i], i, name[i]); + lovVal.put(code[i], name[i]); + } + } + return lovVal; + } + return null; + } + + public static String getTableValue(JTable table, int row, int col){ + Object val = table.getValueAt(row, col); + if(val==null) + return ""; + else + return val.toString(); + } + public static TCComponent[] query(TCSession session, String queryName, String[] aKey, String[] aVal) throws Exception { + TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); + if (imancomponentquery == null) { + throw new Exception("δҵѯ " + queryName + "!"); + } + aKey = session.getTextService().getTextValues(aKey); +// for (int i = 0; i < aKey.length; i++) { +// System.out.println(aKey[i] + "===============" + aVal[i]); +// } + TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(aKey, aVal); + return componentContextList.toTCComponentArray(); + } + public static TCComponent[] query(TCSession session, String queryName, Vector Keys, Vector Vals) throws Exception { + TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); + if (imancomponentquery == null) { + System.out.println("δҵѯ" + queryName); + throw new Exception("Query:"+queryName+" cannot find"); + } + TCQueryClause[] qc = imancomponentquery.describe(); +// Map clauseMap = new HashMap<>(); + for(TCQueryClause c : qc) { + String key = c.getUserEntryNameDisplay(); + String value = c.getDefaultValue(); +// System.out.println(key + "==>" + c.getAttributeName()); + if(!value.trim().isEmpty() && !Keys.contains(key)) { + if(key.isEmpty()) + Keys.add(c.getAttributeName()); + else + Keys.add(key); + Vals.add(value); + } + } + int size = Keys.size(); + String[] keyA = new String[size]; + String[] valueA = new String[size]; + for(int i=0; i 0) { + Integer maxId = 0; + for (TCComponent comp : comps) { + String pid = comp.getProperty("item_id"); + System.out.println("pid:" + pid); + String pidSuffix = pid.substring(pid.length() - 3); + if (Integer.parseInt(pidSuffix) > maxId) { + maxId = Integer.parseInt(pidSuffix); + } + } + return String.format("%03d", maxId + 1); + } + return "001"; + } + + public static File saveExcelChooser() { + File dir = null; + JFileChooser chooser = new JFileChooser(); + chooser.setAcceptAllFileFilterUsed(false); +// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); + File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); + chooser.setCurrentDirectory(desktopDir); + String saveType[] = { "xlsx" }; + chooser.setFileFilter(new FileNameExtensionFilter("Excel", saveType)); + int returnVal = chooser.showSaveDialog(new Frame()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + dir = chooser.getSelectedFile(); + String path = dir.getPath(); + if(!path.toLowerCase().endsWith(".xlsx")) { + path += ".xlsx"; + dir = new File(path); + } + System.out.println("saveExcelChooser1:" + path); + } + return dir; + } + + public static File saveExcelChooser(String defaultFile) { + File dir = null; + JFileChooser chooser = new JFileChooser(); + chooser.setAcceptAllFileFilterUsed(false); +// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); + File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); + chooser.setCurrentDirectory(desktopDir); + chooser.setSelectedFile(new File(defaultFile)); + String saveType[] = { "xlsx" }; + chooser.setFileFilter(new FileNameExtensionFilter("Excel", saveType)); + int returnVal = chooser.showSaveDialog(new Frame()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + dir = chooser.getSelectedFile(); + String path = dir.getPath(); + if(!path.toLowerCase().endsWith(".xlsx")) { + path += ".xlsx"; + dir = new File(path); + } + if(dir.exists()) + dir.delete(); +// System.out.println("saveExcelChooser1:" + dir.getPath()); + } + return dir; + } + + public static boolean contains(String[] array, String str) { + for(String s : array) { +// System.out.println("contains:"+s+"="+str); + if(s.equals(str)) + return true; + } + return false; + } + + public static Map executeToMap(InputStream in){ + System.out.println("Read properties file"); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); + String line = null; + Map resultMap = new LinkedHashMap<>(16); + if (reader.ready()) { + while (null != (line = reader.readLine())) { + if (line.length() <= 0 || line.contains("#") || !line.contains("=")) { + continue; + } + resultMap.put(line.substring(0, line.indexOf("=")), line.substring(line.indexOf("=") + 1)); + } + } + in.close(); + reader.close(); + return resultMap; + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post("Find properties file failed", "ERROR", MessageBox.ERROR); + } + return null; + } + + public static TCComponentDataset createExcelDataset(TCSession session, File file, String datasetName) throws Exception { + String refType = null, objType = null, fileName = null; + fileName = file.getName().toLowerCase(); + if (fileName.endsWith("xls")) { + refType = "excel"; + objType = "MSExcel"; + } else if (fileName.endsWith("xlsx")) { + refType = "excel"; + objType = "MSExcelX"; + } + TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService().getTypeComponent("Dataset"); + TCComponentDataset dataset = compType.create(datasetName, "description", objType); + dataset.setFiles(new String[] { file.getAbsolutePath() }, new String[] { refType }); + return dataset; + } + + public static Vector getChildren(TCComponent parent, String relation, String name) throws Exception { + Vector result = new Vector<>(); + AIFComponentContext[] children; + if(relation==null || relation.isEmpty()) + children = parent.getChildren(); + else + children = parent.getChildren(relation); + for(AIFComponentContext c : children) { + TCComponent comp = (TCComponent) c.getComponent(); + if(comp.getProperty("object_name").equals(name)) + result.add(comp); + } + return result; + } + + /** + * Ϊѯ + * TCComponentѯ propertyո + */ + public static TCComponent[] TCsort(TCComponent[] TCComponent, String property, int desc) { + HashMap map = new HashMap<>(); + int count = TCComponent.length; + for(TCComponent Component : TCComponent) { + try { + map.put(Component, Component.getProperty(property)); + } catch (Exception e) { + e.printStackTrace(); + } + } + // ͨArrayList캯map.entrySet()תlist + List> list = new ArrayList>(map.entrySet()); + // ͨȽʵֱȽ + Collections.sort(list, new Comparator>() { + public int compare(Map.Entry mapping1, Map.Entry mapping2) { + return mapping1.getValue().compareTo(mapping2.getValue()) * desc; + } + }); + TCComponent = new TCComponent[count]; + int i=0; + for(Map.Entry mapping : list) { + TCComponent[i] = mapping.getKey(); + i++; + } + return TCComponent; + } + public static TCComponent[] TCsort(TCComponent[] TCComponent, int[] desc, String... property) { + HashMap map = new HashMap<>(); + int count = TCComponent.length; + for(TCComponent Component : TCComponent) { + try { + String[] values = new String[property.length]; + for(int i=0; i> list = new ArrayList>(map.entrySet()); + // ͨȽʵֱȽ + Collections.sort(list, new Comparator>() { + public int compare(Map.Entry mapping1, Map.Entry mapping2) { + String[] v1 = mapping1.getValue(), v2 = mapping2.getValue(); + for(int i=0; i mapping : list) { + TCComponent[i] = mapping.getKey(); + i++; + } + return TCComponent; + } + + public static void deleteWarning(File file) throws Exception { + FileInputStream input = null; + FileOutputStream output = null; + try { + input = new FileInputStream(file); + XWPFDocument doc = new XWPFDocument(input); +// XWPFParagraph para = doc.getParagraphs().get(0); +// System.out.println("para.getRuns:"+para.getRuns().size()); +// for(XWPFRun run : para.getRuns()) { +// System.out.println("run:"+run.getText(0)); +// } + doc.removeBodyElement(0); +// para.removeRun(0); +// System.out.println("para.getRuns:"+para.getRuns().size()+" getParagraphs:"+doc.getParagraphs().get(0).getText()); +// para.setPageBreak(false); + output = new FileOutputStream(file.getPath()); + doc.write(output); + }catch (Exception e) { + throw e; + }finally { + if(input!=null) + input.close(); + if(output!=null) + output.close(); + } + } + + public static int findChar(String str, char a, int num) throws Exception { + int n = 1; + for(int i=0; i