commit 7435655f6781d82820c539205edd2ccbe7b210be Author: xiongcz Date: Wed May 21 14:36:10 2025 +0800 项目来源:20250521WC 项目备份 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..4fbb42b --- /dev/null +++ b/.classpath @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..c4f4a55 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com.connor.plm + + + + + + 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..dec50fb --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,38 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Plm +Bundle-SymbolicName: com.connor.plm;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Vendor: CONNOR +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + com.teamcenter.rac.aifrcp, + com.teamcenter.rac.kernel, + com.teamcenter.rac.util, + com.teamcenter.rac.common, + com.teamcenter.rac.tcapps, + TcSoaCoreRac;bundle-version="12000.3.0", + com.teamcenter.rac.ui;bundle-version="12000.3.0", + org.eclipse.osgi.services;bundle-version="3.7.100", + org.eclipse.osgi.util;bundle-version="3.5.100", + com.teamcenter.rac.pca.kernel;bundle-version="12000.3.0", + com.teamcenter.rac.workflow.processdesigner;bundle-version="12000.3.0", + TcSoaWorkflowRac;bundle-version="12000.3.0", + com.teamcenter.rac.workflow;bundle-version="12000.3.0", + com.teamcenter.rac.workflow.processviewer;bundle-version="12000.3.0", + TcSoaWorkflowLoose;bundle-version="12000.3.0" +Automatic-Module-Name: com.connor.plm +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: poi_lib/aspose-words-17.4.0-jdk16.jar, + poi_lib/commons-collections4-4.1.jar, + poi_lib/poi-3.17.jar, + poi_lib/poi-examples-3.17.jar, + poi_lib/poi-excelant-3.17.jar, + poi_lib/poi-ooxml-3.17.jar, + poi_lib/poi-ooxml-schemas-3.17.jar, + poi_lib/poi-scratchpad-3.17.jar, + poi_lib/xmlbeans-2.6.0.jar, + ., + poi_lib/axis2-ant-plugin-1.6.2.jar, + poi_lib/antlr-2.7.7.jar, + poi_lib/commons-io-1.4.jar diff --git a/bin/com/connor/plm/Activator.class b/bin/com/connor/plm/Activator.class new file mode 100644 index 0000000..187c2bc Binary files /dev/null and b/bin/com/connor/plm/Activator.class differ diff --git a/bin/com/connor/plm/DateUtil$FormatEnum.class b/bin/com/connor/plm/DateUtil$FormatEnum.class new file mode 100644 index 0000000..25f1e10 Binary files /dev/null and b/bin/com/connor/plm/DateUtil$FormatEnum.class differ diff --git a/bin/com/connor/plm/DateUtil.class b/bin/com/connor/plm/DateUtil.class new file mode 100644 index 0000000..ca7ce65 Binary files /dev/null and b/bin/com/connor/plm/DateUtil.class differ diff --git a/bin/com/connor/plm/KAction.class b/bin/com/connor/plm/KAction.class new file mode 100644 index 0000000..2480566 Binary files /dev/null and b/bin/com/connor/plm/KAction.class differ diff --git a/bin/com/connor/plm/KCommand.class b/bin/com/connor/plm/KCommand.class new file mode 100644 index 0000000..1e0f546 Binary files /dev/null and b/bin/com/connor/plm/KCommand.class differ diff --git a/bin/com/connor/plm/KHandler.class b/bin/com/connor/plm/KHandler.class new file mode 100644 index 0000000..52aabac Binary files /dev/null and b/bin/com/connor/plm/KHandler.class differ diff --git a/bin/com/connor/plm/KLocale.class b/bin/com/connor/plm/KLocale.class new file mode 100644 index 0000000..55c42d7 Binary files /dev/null and b/bin/com/connor/plm/KLocale.class differ diff --git a/bin/com/connor/plm/KOperation.class b/bin/com/connor/plm/KOperation.class new file mode 100644 index 0000000..03eca2e Binary files /dev/null and b/bin/com/connor/plm/KOperation.class differ diff --git a/bin/com/connor/plm/KOperation2.class b/bin/com/connor/plm/KOperation2.class new file mode 100644 index 0000000..6bc6882 Binary files /dev/null and b/bin/com/connor/plm/KOperation2.class differ diff --git a/bin/com/connor/plm/KUtil.class b/bin/com/connor/plm/KUtil.class new file mode 100644 index 0000000..ca2e675 Binary files /dev/null and b/bin/com/connor/plm/KUtil.class differ diff --git a/bin/com/connor/plm/ProgressBar$1.class b/bin/com/connor/plm/ProgressBar$1.class new file mode 100644 index 0000000..5a844ba Binary files /dev/null and b/bin/com/connor/plm/ProgressBar$1.class differ diff --git a/bin/com/connor/plm/ProgressBar$2.class b/bin/com/connor/plm/ProgressBar$2.class new file mode 100644 index 0000000..219a9f4 Binary files /dev/null and b/bin/com/connor/plm/ProgressBar$2.class differ diff --git a/bin/com/connor/plm/ProgressBar.class b/bin/com/connor/plm/ProgressBar.class new file mode 100644 index 0000000..c79289d Binary files /dev/null and b/bin/com/connor/plm/ProgressBar.class differ diff --git a/bin/com/connor/plm/k_locale.properties b/bin/com/connor/plm/k_locale.properties new file mode 100644 index 0000000..ac8931f --- /dev/null +++ b/bin/com/connor/plm/k_locale.properties @@ -0,0 +1,58 @@ +# +#Thu Jan 21 10:28:16 CST 2021 +createscheduledeliverable.ERROR2=\u4E3A [%s] \u521B\u5EFA\u65F6\u95F4\u8868\u4EA4\u4ED8\u7269 [%s] \u5931\u8D25 +project=Project +dsuidinpref.ERROR1=Error dataset uid set in preference\: %s +valuenotinlov.ERROR2=LOV "%s" does not contain value\: %s +writedata=Write Data +querynotexist.ERROR1=Query not exist\: %s +dialoginit.ERROR=Init Error +preferror.ERROR1=Preference error\: %s +norefindataset.ERROR1=Download file from dataset "%s" failed. No ref file. +cancel=Cancel +exeop.STATUS=Execute... +initop.STATUS=Checking Data... +noflowkey.ERROR=Missing key for flow number. +wordfield_pagecount.NAME=\u9875\u6570 +nopropintype.ERROR2=Property is not defined in type "%s"\: %s. +getflowno.ERROR1=Error getting new flow number for key\: %s +formsave.ERRORTITLE=Error Saving Data +wordfield_pageno.NAME=\u9875\u7801 +wordfield_totalpagenominus1.NAME=\u603B\u9875\u7801\u51CF\u4E00 +wordfield_totalpagecount.NAME=\u603B\u9875\u6570 +exceltitlenorelateinfo.ERROR=Title row in sheet does not have any relation info. +selectProject=Select Project +proplocationnotdefined.ERROR1=\u672A\u77E5\u5C5E\u6027\u4F4D\u7F6E\u201C%s\u201D\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E +excelnotitle.ERROR=Can't find title row in excel sheet. +loadCompFromUid.Error2=Error loading component "%s", UID \= "%s". +uploadfilewhencheckout.ERROR1=Dataset "%s" is checked out. Upload file failed. +wordfield_totalactualpagecountminus1.NAME=\u603B\u5B9E\u9645\u9875\u6570\u51CF\u4E00 +nodatainfile.ERROR1=No Data in File\: %s +noexportdata.ERROR=\u6CA1\u6709\u6570\u636E\u53EF\u4EE5\u5BFC\u51FA +notscheduleadmin.INFO=\u53EA\u6709\u534F\u8C03\u8005\u624D\u80FD\u64CD\u4F5C +error=Error +mergefile=Merge File... +index=Index +forminit.ERRORTITLE=Error Loading Rendering +ok=OK +wordfield_totalactualpagecount.NAME=\u603B\u5B9E\u9645\u9875\u6570 +requireprop.INFO1=\u8BF7\u586B\u5199\u5C5E\u6027\uFF1A%s +functionnotavailable.INFO=\u6B64\u5BF9\u8C61\u4E0D\u53EF\u4F7F\u7528\u6B64\u529F\u80FD +multiuserbyid.ERROR1=Find multiple users by id\: %s +preparedata=Prepare Data +dbconn.ERROR=Connect to database failed. +typenotfound.ERROR1=Type not found\: %s +filenotexist.ERROR1=File not exist\: %s +wordfield_totalpagecountminus1.NAME=\u603B\u9875\u6570\u51CF\u4E00 +readdata=Read Data +clearcache=Clear Cache +exportsuccess.INFO=Export Complete. +uploadfile=Upload File +propnotdefinedintype.ERROR2=\u5BF9\u8C61\u7C7B\u578B\u201C%s\u201D\u672A\u5B9A\u4E49\u5C5E\u6027\uFF1A%s +foldernotexist.ERROR1=Folder not exist\: %s +info=Info +wordfield_totalpageno.NAME=\u603B\u9875\u7801 +multiuserbyname.ERROR1=Find multiple users by name\: %s +exportopenfile.INFO=Export complete. Open file? +prefnotconfiged.ERROR1=Prefernce not found\: %s +export=Export diff --git a/bin/com/connor/plm/k_locale_zh_CN.properties b/bin/com/connor/plm/k_locale_zh_CN.properties new file mode 100644 index 0000000..902d489 --- /dev/null +++ b/bin/com/connor/plm/k_locale_zh_CN.properties @@ -0,0 +1,58 @@ +# +#Thu Jan 21 10:28:16 CST 2021 +createscheduledeliverable.ERROR2=\u4E3A [%s] \u521B\u5EFA\u65F6\u95F4\u8868\u4EA4\u4ED8\u7269 [%s] \u5931\u8D25 +project=\u9879\u76EE +dsuidinpref.ERROR1=\u8BF7\u68C0\u67E5\u9996\u9009\u9879<%s>\uFF0C\u901A\u8FC7\u914D\u7F6EUID\u672A\u627E\u5230\u6570\u636E\u96C6 +valuenotinlov.ERROR2=LOV "%s" \u4E2D\u672A\u5B9A\u4E49\u6570\u503C\uFF1A%s +writedata=\u5199\u5165\u6570\u636E +querynotexist.ERROR1=\u67E5\u8BE2\u4E0D\u5B58\u5728\uFF1A%s +dialoginit.ERROR=\u521D\u59CB\u5316\u5F02\u5E38 +preferror.ERROR1=\u9996\u9009\u9879\u914D\u7F6E\u9519\u8BEF\uFF1A%s +norefindataset.ERROR1=\u4ECE\u6570\u636E\u96C6\u201C%s\u201D\u4E0B\u8F7D\u6587\u4EF6\u5931\u8D25\uFF0C\u6CA1\u6709\u627E\u5230\u5F15\u7528\u6587\u4EF6\u3002 +cancel=\u53D6\u6D88 +exeop.STATUS=\u6B63\u5728\u6267\u884C... +initop.STATUS=\u68C0\u67E5\u6570\u636E... +noflowkey.ERROR=\u6D41\u6C34\u7801\u952E\u503C\u4E0D\u53EF\u4E3A\u7A7A +wordfield_pagecount.NAME=\u9875\u6570 +nopropintype.ERROR2=\u5BF9\u8C61\u7C7B\u578B\u201C%s\u201D\u4E0D\u5B58\u5728\u5C5E\u6027\uFF1A%s +getflowno.ERROR1=\u83B7\u53D6\u6D41\u6C34\u7801\u5931\u8D25\uFF1A%s +formsave.ERRORTITLE=\u4FDD\u5B58\u6570\u636E\u51FA\u9519 +wordfield_pageno.NAME=\u9875\u7801 +wordfield_totalpagenominus1.NAME=\u603B\u9875\u7801\u51CF\u4E00 +wordfield_totalpagecount.NAME=\u603B\u9875\u6570 +exceltitlenorelateinfo.ERROR=\u6807\u9898\u884C\u6CA1\u6709\u89E3\u6790\u5230\u6620\u5C04\u5185\u5BB9 +selectProject=\u9009\u62E9\u9879\u76EE +proplocationnotdefined.ERROR1=\u672A\u77E5\u5C5E\u6027\u4F4D\u7F6E\u201C%s\u201D\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E +excelnotitle.ERROR=\u672A\u627E\u5230\u5DE5\u4F5C\u8868\u4E2D\u7684\u6807\u9898\u884C +loadCompFromUid.Error2=\u52A0\u8F7D\u5BF9\u8C61\u201C%s\u201D\u5931\u8D25\uFF0CUID\=\u201C%s\u201D\u3002 +uploadfilewhencheckout.ERROR1=\u6570\u636E\u96C6\u201C%s\u201D\u5DF2\u7B7E\u51FA\uFF0C\u4E0A\u4F20\u6587\u4EF6\u5931\u8D25\u3002\u8BF7\u7B7E\u5165\u540E\u518D\u8FDB\u884C\u64CD\u4F5C\u3002 +wordfield_totalactualpagecountminus1.NAME=\u603B\u5B9E\u9645\u9875\u6570\u51CF\u4E00 +nodatainfile.ERROR1=\u6587\u4EF6\u4E2D\u6CA1\u6709\u6570\u636E\uFF1A%s +noexportdata.ERROR=\u6CA1\u6709\u6570\u636E\u53EF\u4EE5\u5BFC\u51FA +notscheduleadmin.INFO=\u53EA\u6709\u534F\u8C03\u8005\u624D\u80FD\u64CD\u4F5C +error=\u9519\u8BEF +mergefile=\u5408\u5E76\u6587\u4EF6 +index=\u5E8F\u53F7 +forminit.ERRORTITLE=\u521D\u59CB\u5316\u754C\u9762\u5F02\u5E38 +ok=\u786E\u5B9A +wordfield_totalactualpagecount.NAME=\u603B\u5B9E\u9645\u9875\u6570 +requireprop.INFO1=\u8BF7\u586B\u5199\u5C5E\u6027\uFF1A%s +functionnotavailable.INFO=\u6B64\u5BF9\u8C61\u4E0D\u53EF\u4F7F\u7528\u6B64\u529F\u80FD +multiuserbyid.ERROR1=\u901A\u8FC7id\u67E5\u8BE2\u5230\u591A\u4E2A\u7528\u6237\uFF1A%s +preparedata=\u51C6\u5907\u6570\u636E +dbconn.ERROR=\u8FDE\u63A5\u6570\u636E\u5E93\u5931\u8D25\u3002 +typenotfound.ERROR1=\u672A\u627E\u5230\u7C7B\u578B\uFF1A%s +filenotexist.ERROR1=\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A%s +wordfield_totalpagecountminus1.NAME=\u603B\u9875\u6570\u51CF\u4E00 +readdata=\u8BFB\u53D6\u6570\u636E +clearcache=\u6E05\u7406\u7F13\u5B58 +exportsuccess.INFO=\u5BFC\u51FA\u5B8C\u6210 +uploadfile=\u4E0A\u4F20\u6587\u4EF6 +propnotdefinedintype.ERROR2=\u5BF9\u8C61\u7C7B\u578B\u201C%s\u201D\u672A\u5B9A\u4E49\u5C5E\u6027\uFF1A%s +foldernotexist.ERROR1=\u6587\u4EF6\u5939\u4E0D\u5B58\u5728\uFF1A%s +info=\u63D0\u793A +wordfield_totalpageno.NAME=\u603B\u9875\u7801 +multiuserbyname.ERROR1=\u901A\u8FC7\u59D3\u540D\u67E5\u8BE2\u5230\u591A\u4E2A\u7528\u6237\uFF1A%s +exportopenfile.INFO=\u5BFC\u51FA\u5B8C\u6210\uFF0C\u6253\u5F00\u6587\u4EF6\uFF1F +prefnotconfiged.ERROR1=\u672A\u914D\u7F6E\u9996\u9009\u9879\uFF1A%s +export=\u5BFC\u51FA diff --git a/bin/com/connor/plm/sample/DatasetSaveAsHandler.class b/bin/com/connor/plm/sample/DatasetSaveAsHandler.class new file mode 100644 index 0000000..3b937e2 Binary files /dev/null and b/bin/com/connor/plm/sample/DatasetSaveAsHandler.class differ diff --git a/bin/com/connor/plm/sample/DatasetSaveAsOperation.class b/bin/com/connor/plm/sample/DatasetSaveAsOperation.class new file mode 100644 index 0000000..67bc26c Binary files /dev/null and b/bin/com/connor/plm/sample/DatasetSaveAsOperation.class differ diff --git a/bin/com/connor/plm/sample/PlmLocale.class b/bin/com/connor/plm/sample/PlmLocale.class new file mode 100644 index 0000000..c809539 Binary files /dev/null and b/bin/com/connor/plm/sample/PlmLocale.class differ diff --git a/bin/com/connor/plm/sample/sample_locale.properties b/bin/com/connor/plm/sample/sample_locale.properties new file mode 100644 index 0000000..6dd4d27 --- /dev/null +++ b/bin/com/connor/plm/sample/sample_locale.properties @@ -0,0 +1,7 @@ +selectDataset=Please select a dataset +warn=warn +ok=ok +err=err +revisedSuccessful=save successfully +revisionFailed=save failed +cel=cancel \ No newline at end of file diff --git a/bin/com/connor/plm/sample/sample_locale_zh_CN.properties b/bin/com/connor/plm/sample/sample_locale_zh_CN.properties new file mode 100644 index 0000000..d9f2615 --- /dev/null +++ b/bin/com/connor/plm/sample/sample_locale_zh_CN.properties @@ -0,0 +1,7 @@ +selectDataset=\u8BF7\u9009\u4E2D\u6570\u636E\u96C6 +warn=\u63D0\u9192 +ok=\u786E\u8BA4 +err=\u9519\u8BEF +revisedSuccessful=\u5907\u4EFD\u5B8C\u6210 +revisionFailed=\u5907\u4EFD\u5931\u8D25 +cel=\u53D6\u6D88 diff --git a/bin/com/connor/plm/sb01/PropertyToWordOrExcelCommand.class b/bin/com/connor/plm/sb01/PropertyToWordOrExcelCommand.class new file mode 100644 index 0000000..d244435 Binary files /dev/null and b/bin/com/connor/plm/sb01/PropertyToWordOrExcelCommand.class differ diff --git a/bin/com/connor/plm/sb01/PropertyToWordOrExcelOperation.class b/bin/com/connor/plm/sb01/PropertyToWordOrExcelOperation.class new file mode 100644 index 0000000..5e3ab7a Binary files /dev/null and b/bin/com/connor/plm/sb01/PropertyToWordOrExcelOperation.class differ diff --git a/bin/com/connor/plm/sb01/Test.class b/bin/com/connor/plm/sb01/Test.class new file mode 100644 index 0000000..e98fcd4 Binary files /dev/null and b/bin/com/connor/plm/sb01/Test.class differ diff --git a/bin/com/connor/plm/sb01/WordUtils.class b/bin/com/connor/plm/sb01/WordUtils.class new file mode 100644 index 0000000..cf5df0a Binary files /dev/null and b/bin/com/connor/plm/sb01/WordUtils.class differ diff --git a/bin/com/connor/plm/sb02/ArrowIcon.class b/bin/com/connor/plm/sb02/ArrowIcon.class new file mode 100644 index 0000000..2670948 Binary files /dev/null and b/bin/com/connor/plm/sb02/ArrowIcon.class differ diff --git a/bin/com/connor/plm/sb02/ColumnSorter.class b/bin/com/connor/plm/sb02/ColumnSorter.class new file mode 100644 index 0000000..36e59ab Binary files /dev/null and b/bin/com/connor/plm/sb02/ColumnSorter.class differ diff --git a/bin/com/connor/plm/sb02/ControlBean.class b/bin/com/connor/plm/sb02/ControlBean.class new file mode 100644 index 0000000..74b622d Binary files /dev/null and b/bin/com/connor/plm/sb02/ControlBean.class differ diff --git a/bin/com/connor/plm/sb02/DateTest.class b/bin/com/connor/plm/sb02/DateTest.class new file mode 100644 index 0000000..66eee00 Binary files /dev/null and b/bin/com/connor/plm/sb02/DateTest.class differ diff --git a/bin/com/connor/plm/sb02/DerivedChangeNoticeCommand.class b/bin/com/connor/plm/sb02/DerivedChangeNoticeCommand.class new file mode 100644 index 0000000..1d0c878 Binary files /dev/null and b/bin/com/connor/plm/sb02/DerivedChangeNoticeCommand.class differ diff --git a/bin/com/connor/plm/sb02/DerivedChangeRequestCommand.class b/bin/com/connor/plm/sb02/DerivedChangeRequestCommand.class new file mode 100644 index 0000000..add5578 Binary files /dev/null and b/bin/com/connor/plm/sb02/DerivedChangeRequestCommand.class differ diff --git a/bin/com/connor/plm/sb02/DerivedChangeRequestDialog$1.class b/bin/com/connor/plm/sb02/DerivedChangeRequestDialog$1.class new file mode 100644 index 0000000..84a8c8a Binary files /dev/null and b/bin/com/connor/plm/sb02/DerivedChangeRequestDialog$1.class differ diff --git a/bin/com/connor/plm/sb02/DerivedChangeRequestDialog.class b/bin/com/connor/plm/sb02/DerivedChangeRequestDialog.class new file mode 100644 index 0000000..062fc19 Binary files /dev/null and b/bin/com/connor/plm/sb02/DerivedChangeRequestDialog.class differ diff --git a/bin/com/connor/plm/sb02/TableDemo$1.class b/bin/com/connor/plm/sb02/TableDemo$1.class new file mode 100644 index 0000000..a27eeda Binary files /dev/null and b/bin/com/connor/plm/sb02/TableDemo$1.class differ diff --git a/bin/com/connor/plm/sb02/TableDemo.class b/bin/com/connor/plm/sb02/TableDemo.class new file mode 100644 index 0000000..f3d25f1 Binary files /dev/null and b/bin/com/connor/plm/sb02/TableDemo.class differ diff --git a/bin/com/connor/plm/sb02/old.txt b/bin/com/connor/plm/sb02/old.txt new file mode 100644 index 0000000..23d018a --- /dev/null +++ b/bin/com/connor/plm/sb02/old.txt @@ -0,0 +1,86 @@ +package com.net.connor.ld.plm.ld06; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Polygon; +import java.util.Comparator; + +import javax.swing.Icon; +import javax.swing.RowSorter; +import javax.swing.RowSorter.SortKey; +import javax.swing.SortOrder; +import javax.swing.table.TableRowSorter; + +import antlr.collections.List; + +public class ArrowIcon implements Icon { + private final SortOrder sortOrder; + private final int size; + private final boolean ascending; + public ArrowIcon(TableRowSorter sorter, int column, boolean ascending) { + this.ascending = ascending; + this.size = 12; + java.util.List sortKeys = sorter.getSortKeys(); + if (sortKeys.size() > 0 && ((RowSorter.SortKey) sortKeys.get(0)).getColumn() == column) { + this.sortOrder = ((RowSorter.SortKey) sortKeys.get(0)).getSortOrder(); + } else { + this.sortOrder = SortOrder.ASCENDING; + } + } + public void paintIcon(Component c, Graphics g, int x, int y) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.translate(x, y); + if (ascending) { + g2.rotate(Math.PI, size / 2.0, size / 2.0); + } + if (sortOrder == SortOrder.ASCENDING) { + g2.draw(createUpTriangle(size)); + } else { + g2.draw(createDownTriangle(size)); + } + g2.dispose(); + } + public int getIconWidth() { + return size; + } + public int getIconHeight() { + return size; + } + private Polygon createUpTriangle(int size) { + Polygon triangle = new Polygon(); + triangle.addPoint(0, size); + triangle.addPoint(size / 2, 0); + triangle.addPoint(size, size); + return triangle; + } + private Polygon createDownTriangle(int size) { + Polygon triangle = new Polygon(); + triangle.addPoint(0, 0); + triangle.addPoint(size, 0); + triangle.addPoint(size / 2, size); + return triangle; + } +} +//表格列排序类 +class ColumnSorter implements Comparator { + private final int col; + private final boolean ascending; + public ColumnSorter(int col, boolean ascending) { + this.col = col; + this.ascending = ascending; + } + @Override + public int compare(Object a, Object b) { + if (a instanceof Comparable && b instanceof Comparable) { + if (ascending) { + return ((Comparable) a).compareTo((Comparable) b); + } else { + return ((Comparable) b).compareTo((Comparable) a); + } + } else { + return 0; + } + } +} + diff --git a/bin/com/connor/plm/test.class b/bin/com/connor/plm/test.class new file mode 100644 index 0000000..153b6cd Binary files /dev/null and b/bin/com/connor/plm/test.class differ diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..dffe1d4 --- /dev/null +++ b/build.properties @@ -0,0 +1,18 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + poi_lib/aspose-words-17.4.0-jdk16.jar,\ + poi_lib/commons-collections4-4.1.jar,\ + poi_lib/poi-3.17.jar,\ + poi_lib/poi-examples-3.17.jar,\ + poi_lib/poi-excelant-3.17.jar,\ + poi_lib/poi-ooxml-3.17.jar,\ + poi_lib/poi-ooxml-schemas-3.17.jar,\ + poi_lib/poi-scratchpad-3.17.jar,\ + poi_lib/xmlbeans-2.6.0.jar,\ + poi_lib/axis2-ant-plugin-1.6.2.jar,\ + poi_lib/antlr-2.7.7.jar,\ + poi_lib/commons-io-1.4.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/plugin.xml b/plugin.xml new file mode 100644 index 0000000..ae07695 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/poi_lib/antlr-2.7.7.jar b/poi_lib/antlr-2.7.7.jar new file mode 100644 index 0000000..5e5f14b Binary files /dev/null and b/poi_lib/antlr-2.7.7.jar differ diff --git a/poi_lib/aspose-words-17.4.0-jdk16.jar b/poi_lib/aspose-words-17.4.0-jdk16.jar new file mode 100644 index 0000000..e8bd66c Binary files /dev/null and b/poi_lib/aspose-words-17.4.0-jdk16.jar differ diff --git a/poi_lib/axis2-ant-plugin-1.6.2.jar b/poi_lib/axis2-ant-plugin-1.6.2.jar new file mode 100644 index 0000000..771b222 Binary files /dev/null and b/poi_lib/axis2-ant-plugin-1.6.2.jar differ diff --git a/poi_lib/commons-collections4-4.1.jar b/poi_lib/commons-collections4-4.1.jar new file mode 100644 index 0000000..43a9413 Binary files /dev/null and b/poi_lib/commons-collections4-4.1.jar differ diff --git a/poi_lib/commons-io-1.4.jar b/poi_lib/commons-io-1.4.jar new file mode 100644 index 0000000..133dc6c Binary files /dev/null and b/poi_lib/commons-io-1.4.jar differ diff --git a/poi_lib/poi-3.17.jar b/poi_lib/poi-3.17.jar new file mode 100644 index 0000000..353ce76 Binary files /dev/null and b/poi_lib/poi-3.17.jar differ diff --git a/poi_lib/poi-examples-3.17.jar b/poi_lib/poi-examples-3.17.jar new file mode 100644 index 0000000..a923b04 Binary files /dev/null and b/poi_lib/poi-examples-3.17.jar differ diff --git a/poi_lib/poi-excelant-3.17.jar b/poi_lib/poi-excelant-3.17.jar new file mode 100644 index 0000000..da9f5ed Binary files /dev/null and b/poi_lib/poi-excelant-3.17.jar differ diff --git a/poi_lib/poi-ooxml-3.17.jar b/poi_lib/poi-ooxml-3.17.jar new file mode 100644 index 0000000..68086e8 Binary files /dev/null and b/poi_lib/poi-ooxml-3.17.jar differ diff --git a/poi_lib/poi-ooxml-schemas-3.17.jar b/poi_lib/poi-ooxml-schemas-3.17.jar new file mode 100644 index 0000000..2e9b3e7 Binary files /dev/null and b/poi_lib/poi-ooxml-schemas-3.17.jar differ diff --git a/poi_lib/poi-scratchpad-3.17.jar b/poi_lib/poi-scratchpad-3.17.jar new file mode 100644 index 0000000..12ba1f1 Binary files /dev/null and b/poi_lib/poi-scratchpad-3.17.jar differ diff --git a/poi_lib/xmlbeans-2.6.0.jar b/poi_lib/xmlbeans-2.6.0.jar new file mode 100644 index 0000000..d1b6627 Binary files /dev/null and b/poi_lib/xmlbeans-2.6.0.jar differ diff --git a/src/com/connor/plm/Activator.java b/src/com/connor/plm/Activator.java new file mode 100644 index 0000000..fdc2a09 --- /dev/null +++ b/src/com/connor/plm/Activator.java @@ -0,0 +1,44 @@ +package com.connor.plm; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "cn.net.connor.ml.plm"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/src/com/connor/plm/DateUtil.java b/src/com/connor/plm/DateUtil.java new file mode 100644 index 0000000..9c8fdd0 --- /dev/null +++ b/src/com/connor/plm/DateUtil.java @@ -0,0 +1,603 @@ +package com.connor.plm; + +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.util.Date; + +public class DateUtil { + private static final String HYPHEN = "-"; + private static final String COLON = ":"; + + /* ʱʽ DateTimeFormatter (Java8) */ + enum FormatEnum { + /** + * DateTimeFormatter "yyyy-MM-dd HH:mm:ss" ʱʽ + */ + FORMAT_DATA_TIME(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)), + + /** + * DateTimeFormatter "yyyyMMddHHmmss"ʱʽ + */ + FORMAT_DATA_TIME_NO_SYMBOL(DateTimeFormatter.ofPattern(DATETIME_FORMAT)), + + /** + * DateTimeFormatter "yyyy-MM-dd"ʱʽ + */ + FORMAT_DATE(DateTimeFormatter.ofPattern(DATE_FORMAT)), + + /** + * DateTimeFormatter "HH:mm:ss"ʱʽ + */ + FORMAT_TIME(DateTimeFormatter.ofPattern(TIME_FORMAT)); + + private DateTimeFormatter value; + + FormatEnum(DateTimeFormatter format) { + this.value = format; + } + } + /* ʱʽ DateTimeFormatter (Java8) */ + + /* ʱʽ ַ */ + + /** + * ʱʽ + *
+ * "yyyy" ַ + */ + public static final String YEAR_FORMAT = "yyyy"; + + /** + * µʱʽ + *
+ * "MM" ַ + */ + public static final String MONTH_FORMAT = "MM"; + + /** + * յʱʽ + *
+ * "dd" ַ + */ + public static final String DAY_FORMAT = "dd"; + + /** + * ʱʱʽ + *
+ * "HH" ַ + */ + public static final String HOUR_FORMAT = "HH"; + + /** + * ֵʱʽ + *
+ * "mm" ַ + */ + public static final String MINUTE_FORMAT = "mm"; + + /** + * ʱʽ + *
+ * "ss" ַ + */ + public static final String SECOND_FORMAT = "ss"; + + /** + * --ʱʽ + *
+ * "yyyy-MM-dd" ַ + */ + public static final String DATE_FORMAT = YEAR_FORMAT + HYPHEN + MONTH_FORMAT + HYPHEN + DAY_FORMAT; + + /** + * ʱ::ʱʽ + *
+ * "HH:mm:ss" ַ + */ + public static final String TIME_FORMAT = HOUR_FORMAT + COLON + MINUTE_FORMAT + COLON + SECOND_FORMAT; + + /** + * -- ʱ::ʱʽ + *
+ * "yyyy-MM-dd HH:mm:ss" ַ + */ + public static final String DATE_TIME_FORMAT = DATE_FORMAT + " " + TIME_FORMAT; + + /** + * ʱʱʽ޷ţ + *
+ * "yyyyMMddHHmmss" ַ + */ + public static final String DATETIME_FORMAT = YEAR_FORMAT + MONTH_FORMAT + DAY_FORMAT + HOUR_FORMAT + MINUTE_FORMAT + SECOND_FORMAT; + + /* ʱʽ ַ */ + + + + /* ʱ */ + + /** + * ȡ뼶ʱ + */ + public static Long epochSecond() { + return localDateTime().toEpochSecond(ZoneOffset.of("+8")); + } + + /** + * ȡ뼶ʱ + */ + public static Long epochMilli() { + return localDateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli(); + } + + /* ʱ */ + + + /* ǰʱ */ + + /** + * ȡǰϸʱ䣬like 2018-08-27 17:20:06 + */ + public static String dateTime() { + return localDateTime().format(FormatEnum.FORMAT_DATA_TIME.value); + } + + /** + * ȡǰϸʱ䣬like 20180827172006 + */ + public static String dateTimeNoSymbol() { + return localDateTime().format(FormatEnum.FORMAT_DATA_TIME_NO_SYMBOL.value); + } + + /** + * ȡǰڣlike 2018-08-27 + */ + public static String date() { + return localDate() + ""; + } + + /** + * ȡǰʱ䣬like 17:20:06 + */ + public static String time() { + return localTime().format(FormatEnum.FORMAT_TIME.value); + } + + /** + * ȡǰ + */ + public static Integer year() { + return localDate().getYear(); + } + + /** + * ȡǰ + */ + public static int month() { + return localDate().getMonthValue(); + } + + /** + * ȡǰе + */ + public static Integer dayOfYear() { + return localDate().getDayOfYear(); + } + + /** + * ȡǰе + */ + public static Integer dayOfMonth() { + return localDate().getDayOfMonth(); + } + + /** + * ȡǰе + */ + public static Integer dayOfWeek() { + return localDate().getDayOfWeek().getValue(); + } + + /** + * ȡǰСʱ + */ + public static Integer hour() { + return localTime().getHour(); + } + + /** + * ȡǰ + */ + public static Integer minute() { + return localTime().getMinute(); + } + + /** + * ȡǰ + */ + public static Integer second() { + return localTime().getSecond(); + } + + /* ǰʱ */ + + + + /* δʷʱ */ + + /** + * ȡǰ ǰ + *

+ * + * @param years ǰ + * @param formatEnum ʽ + * @return ǰ ǰ Ӧ ʽ + */ + public static String minusYears(Long years, FormatEnum formatEnum) { + return minusOrPlusYears(-years, formatEnum); + } + + /** + * ȡǰ + *

+ * + * @param years + * @param formatEnum ʽ + * @return ǰ Ӧ ʽ + */ + public static String plusYears(Long years, FormatEnum formatEnum) { + return minusOrPlusYears(years, formatEnum); + } + + /** + * ȡǰµ ǰ + * + * @param months ǰ + * @param formatEnum ʽ + * @return ǰµ ǰ Ӧ ʽ + */ + public static String minusMonths(Long months, FormatEnum formatEnum) { + return minusOrPlusMonths(-months, formatEnum); + } + + /** + * ȡǰµ + * + * @param months + * @param formatEnum ʽ + * @return ǰµ Ӧ ʽ + */ + public static String plusMonths(Long months, FormatEnum formatEnum) { + return minusOrPlusMonths(months, formatEnum); + } + + /** + * ȡǰյ ǰ + * + * @param days ǰ + * @param formatEnum ʽ + * @return ǰյ ǰ Ӧ ʽ + */ + public static String minusDays(Long days, FormatEnum formatEnum) { + return minusOrPlusDays(-days, formatEnum); + } + + /** + * ȡǰյ + * + * @param days + * @param formatEnum ʽ + * @return ǰյ Ӧ ʽ + */ + public static String plusDays(Long days, FormatEnum formatEnum) { + return minusOrPlusDays(days, formatEnum); + } + + /** + * ȡǰڵ ǰ + * + * @param weeks ǰ + * @param formatEnum ʽ + * @return ǰڵ ǰ Ӧ ʽ + */ + public static String minusWeeks(Long weeks, FormatEnum formatEnum) { + return minusOrPlusWeeks(-weeks, formatEnum); + } + + /** + * ȡǰڵ + * + * @param weeks + * @param formatEnum ʽ + * @return ǰڵ Ӧ ʽ + */ + public static String plusWeeks(Long weeks, FormatEnum formatEnum) { + return minusOrPlusWeeks(weeks, formatEnum); + } + + /** + * ȡǰСʱ ǰСʱ + * + * @param hours ǰСʱ + * @param formatEnum ʽ + * @return ǰСʱ ǰСʱ Ӧ ʽ + */ + public static String minusHours(Long hours, FormatEnum formatEnum) { + return minusOrPlusHours(-hours, formatEnum); + } + + /** + * ȡǰСʱ Сʱ + * + * @param hours Сʱ + * @param formatEnum ʽ + * @return ǰСʱ Сʱ Ӧ ʽ + */ + public static String plusHours(Long hours, FormatEnum formatEnum) { + return minusOrPlusHours(hours, formatEnum); + } + + /** + * ȡǰӵ ǰ + * + * @param minutes ǰ + * @param formatEnum ʽ + * @return ǰӵ ǰ Ӧ ʽ + */ + public static String minusMinutes(Long minutes, FormatEnum formatEnum) { + return minusOrPlusMinutes(-minutes, formatEnum); + } + + /** + * ȡǰӵ 󼸷 + * + * @param minutes 󼸷 + * @param formatEnum ʽ + * @return ǰӵ 󼸷 Ӧ ʽ + */ + public static String plusMinutes(Long minutes, FormatEnum formatEnum) { + return minusOrPlusMinutes(minutes, formatEnum); + } + + /** + * ȡǰ ǰ + * + * @param seconds ǰ + * @param formatEnum ʽ + * @return ǰ ǰ Ӧ ʽ + */ + public static String minusSeconds(Long seconds, FormatEnum formatEnum) { + return minusOrPlusSeconds(-seconds, formatEnum); + } + + /** + * ȡǰ ǰ/ + * + * @param seconds + * @param formatEnum ʽ + * @return ǰ Ӧ ʽ + */ + public static String plusSeconds(Long seconds, FormatEnum formatEnum) { + return minusOrPlusSeconds(seconds, formatEnum); + } + + /* δʷʱ */ + + + /* ʱת */ + + /** + * DateתLocalDateTime + *

+ * + * @param date dateʱ + * @return LocalDateTime + */ + public static LocalDateTime toLocalDateTime(Date date) { + return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); + } + + /** + * DateתLocalDate + *

+ * + * @param date dateʱ + * @return LocalDate + */ + public static LocalDate toLocalDate(Date date) { + return toLocalDateTime(date).toLocalDate(); + } + + /** + * DateתLocalTime + *

+ * + * @param date dateʱ + * @return LocalTime + */ + public static LocalTime toLocalTime(Date date) { + return toLocalDateTime(date).toLocalTime(); + } + + /** + * LocalDateTime ת Date + * + * @param localDateTime localDateTime + * @return תDate + */ + public static Date toDate(LocalDateTime localDateTime) { + return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + } + + /** + * LocalDateתDate + * + * @param localDate localDate + * @return תDate + */ + public static Date toDate(LocalDate localDate) { + return toDate(localDate.atStartOfDay()); + } + + /** + * LocalTimeתDate + * + * @param localTime localTime + * @return תDate + */ + public static Date toDate(LocalTime localTime) { + return toDate(LocalDateTime.of(localDate(), localTime)); + } + + /* ʱת */ + + + /* ʱ */ + + /** + * ȡ endDate-startDate ʱ + *
ˣ leigq + *
ʱ䣺 2018-11-07 09:55 + *
+ * + * @param startDate ʼʱ + * @param endDate ʱ + * @return ʱ + */ + public static Long daysInterval(LocalDate startDate, LocalDate endDate) { + return endDate.toEpochDay() - startDate.toEpochDay(); + } + + /** + * ȡ endDate-startDate ʱ + *
ˣ leigq + *
ʱ䣺 2018-11-07 09:55 + *
+ * + * @param startDate ʼʱ + * @param endDate ʱ + * @return ʱ + */ + public static Long daysInterval(String startDate, String endDate) { + return daysInterval(LocalDateTime.parse(endDate, FormatEnum.FORMAT_DATA_TIME.value).toLocalDate(), + LocalDateTime.parse(startDate, FormatEnum.FORMAT_DATA_TIME.value).toLocalDate()); + } + + /** + * ȡ endDate-startDate ʱ + *
ˣ leigq + *
ʱ䣺 2018-11-07 09:55 + *
+ * + * @param startDate ʼʱ + * @param endDate ʱ + * @return ʱ + */ + public static Long daysInterval(LocalDateTime startDate, LocalDateTime endDate) { + return daysInterval(startDate.toLocalDate(), endDate.toLocalDate()); + } + + /* ʱ */ + + /*ֻá*/ + + /** + * ȡ ǰ ǰ/ + *

+ * + * @param yearsToAddOrSubtract 괫ǰ괫 + * @param formatEnum ʽ + * @return ǰǰ/ĶӦ ʽ + */ + private static String minusOrPlusYears(Long yearsToAddOrSubtract, FormatEnum formatEnum) { + return localDateTime().plusYears(yearsToAddOrSubtract).format(formatEnum.value); + } + + /** + * ȡ ǰ ǰ/µ + * + * @param monthsToAddOrSubtract ´ǰ´ + * @param formatEnum ʽ + * @return ǰµǰ/µĶӦ ʽ + */ + private static String minusOrPlusMonths(Long monthsToAddOrSubtract, FormatEnum formatEnum) { + return localDateTime().plusMonths(monthsToAddOrSubtract).format(formatEnum.value); + } + + /** + * ȡ ǰ ǰ/յ + * + * @param daysToAddOrSubtract մǰմ + * @param formatEnum ʽ + * @return ǰյǰ/յ Ӧ ʽ + */ + private static String minusOrPlusDays(Long daysToAddOrSubtract, FormatEnum formatEnum) { + return localDateTime().plusDays(daysToAddOrSubtract).format(formatEnum.value); + } + + /** + * ȡǰڵǰ/ڵ + * + * @param weeksToAddOrSubtract ڴǰڴ + * @param formatEnum ʽ + * @return ǰڵǰ/ڵ Ӧ ʽ + */ + private static String minusOrPlusWeeks(Long weeksToAddOrSubtract, FormatEnum formatEnum) { + return localDateTime().plusWeeks(weeksToAddOrSubtract).format(formatEnum.value); + } + + /** + * ȡǰСʱǰСʱ/Сʱ + * + * @param hoursToAddOrSubtract СʱǰСʱ + * @param formatEnum ʽ + * @return ǰСʱǰСʱ/Сʱ Ӧ ʽ + */ + private static String minusOrPlusHours(Long hoursToAddOrSubtract, FormatEnum formatEnum) { + return localDateTime().plusHours(hoursToAddOrSubtract).format(formatEnum.value); + } + + /** + * ȡǰӵǰ/󼸷ӵ + * + * @param minutesToAddOrSubtract 󼸷ӴǰӴ + * @param formatEnum ʽ + * @return ǰӵǰ/󼸷ӵ Ӧ ʽ + */ + private static String minusOrPlusMinutes(Long minutesToAddOrSubtract, FormatEnum formatEnum) { + return localDateTime().plusMinutes(minutesToAddOrSubtract).format(formatEnum.value); + } + + /** + * ȡǰǰ/ + * + * @param secondsToAddOrSubtract 봫ǰ봫 + * @param formatEnum ʽ + * @return ǰǰ/ Ӧ ʽ + */ + private static String minusOrPlusSeconds(Long secondsToAddOrSubtract, FormatEnum formatEnum) { + return localDateTime().plusSeconds(secondsToAddOrSubtract).format(formatEnum.value); + } + + /** + * ȡ LocalDate + */ + private static LocalDate localDate() { + return localDateTime().toLocalDate(); + } + + /** + * ȡ LocalTime + */ + private static LocalTime localTime() { + return localDateTime().toLocalTime(); + } + + /** + * ȡ LocalDateTime + */ + private static LocalDateTime localDateTime() { + return LocalDateTime.now(); + } + +} diff --git a/src/com/connor/plm/KAction.java b/src/com/connor/plm/KAction.java new file mode 100644 index 0000000..8b7c3c2 --- /dev/null +++ b/src/com/connor/plm/KAction.java @@ -0,0 +1,37 @@ +package com.connor.plm; + +import java.lang.reflect.Constructor; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.common.actions.AbstractAIFAction; +import com.teamcenter.rac.util.MessageBox; + + +public class KAction extends AbstractAIFAction { + + + KAction(AbstractAIFUIApplication app, String string) { + super(app,string); + } + + @Override + public void run() { + try { + int ind = actionName.indexOf('#'); + String action=actionName; + String actionData=""; + if(ind>0) { + action=actionName.substring(0,ind); + actionData=actionName.substring(ind+1); + } + Class c = Class.forName(action); + Constructor constructor = c.getConstructor(AbstractAIFApplication.class, String.class,String.class); + KCommand command = (KCommand) constructor.newInstance(this.application, action, actionData); + command.executeModal(); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(e.toString(),KLocale.getString("error"),MessageBox.ERROR); + } + } +} diff --git a/src/com/connor/plm/KCommand.java b/src/com/connor/plm/KCommand.java new file mode 100644 index 0000000..e228d17 --- /dev/null +++ b/src/com/connor/plm/KCommand.java @@ -0,0 +1,16 @@ +package com.connor.plm; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFCommand; + +public abstract class KCommand extends AbstractAIFCommand { + + protected AbstractAIFApplication app; + protected String actionInfo; + + public KCommand(AbstractAIFApplication app, String commandId, String actionInfo) { + this.app = app; + this.actionInfo = actionInfo; + } + +} diff --git a/src/com/connor/plm/KHandler.java b/src/com/connor/plm/KHandler.java new file mode 100644 index 0000000..7c10840 --- /dev/null +++ b/src/com/connor/plm/KHandler.java @@ -0,0 +1,24 @@ +package com.connor.plm; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; + +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aifrcp.AIFUtility; + +/** + * Add following config to MANIFEST.MF + * Eclipse-RegisterBuddy: k.util + * @author Administrator + * + */ +public class KHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) { + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + new Thread(new KAction(app,arg0.getCommand().getId())).start(); + return null; + } + +} diff --git a/src/com/connor/plm/KLocale.java b/src/com/connor/plm/KLocale.java new file mode 100644 index 0000000..a658f8b --- /dev/null +++ b/src/com/connor/plm/KLocale.java @@ -0,0 +1,22 @@ +package com.connor.plm; + +import com.teamcenter.rac.util.Registry; + + +public class KLocale { + + public static final Registry reg = Registry.getRegistry(KLocale.class); + + public static String getString(String title) { + if (isEmpty(title)) { + return ""; + } else { + String res = reg.getString(title); + return isEmpty(res) ? title : res; + } + } + + private static boolean isEmpty(String title) { + return title == null || "".equals(title.trim()); + } +} diff --git a/src/com/connor/plm/KOperation.java b/src/com/connor/plm/KOperation.java new file mode 100644 index 0000000..14fcef3 --- /dev/null +++ b/src/com/connor/plm/KOperation.java @@ -0,0 +1,52 @@ +package com.connor.plm; + +import java.awt.Dimension; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.kernel.TCSession; + +/* + * do not call executeOperation yourself + * use session.performOperation + */ +public abstract class KOperation extends AbstractAIFOperation { + + protected AbstractAIFApplication app; + protected TCSession session; + public String messageLabel; + + public KOperation(AbstractAIFApplication app, String opName, String messageLabel) { + super(opName, true); + this.app = app; + this.session = (TCSession) app.getSession(); + this.messageLabel = messageLabel;// Ϣ + setSession(session); + } + + public abstract boolean init() throws Exception; + + public abstract void execute() throws Exception; + + @Override + public void executeOperation() { + ProgressBar pb = new ProgressBar(getCurrentDesktop(), new Dimension(250, 50), true); + try { + pb.showDialog(); + pb.setText(messageLabel); + setStatus("Checking Data..."); + if (!init()) { + pb.disposeDialog(); + return; + } + setStatus("Execute..."); + pb.setText(messageLabel); + execute(); + pb.disposeDialog(); + } catch (Exception e) { + pb.disposeDialog(); + KUtil.error(getCurrentDesktop(), "쳣\n" + e.getMessage()); + e.printStackTrace(); + } + } +} diff --git a/src/com/connor/plm/KOperation2.java b/src/com/connor/plm/KOperation2.java new file mode 100644 index 0000000..0cbdcb4 --- /dev/null +++ b/src/com/connor/plm/KOperation2.java @@ -0,0 +1,51 @@ +package com.connor.plm; + +import java.awt.Dimension; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.kernel.TCSession; + +/* + * do not call executeOperation yourself + * use session.performOperation + */ +public abstract class KOperation2 extends AbstractAIFOperation { + + protected AbstractAIFApplication app; + protected TCSession session; + protected ProgressBar pb; + + public KOperation2(AbstractAIFApplication app, String opName) { + super(opName, true); + this.app = app; + this.session = (TCSession) app.getSession(); + setSession(session); + } + + public abstract boolean init() throws Exception; + + public abstract void execute() throws Exception; + + @Override + public void executeOperation() { + pb = new ProgressBar(getCurrentDesktop(), new Dimension(250, 50), true); + try { + pb.showDialog(); + setStatus(KLocale.getString("initop.STATUS")); + if (!init()) { + pb.disposeDialog(); + return; + } + setStatus(KLocale.getString("exeop.STATUS")); + execute(); + KUtil.setByPass(false); + pb.disposeDialog(); + } catch (Exception e) { + pb.disposeDialog(); + KUtil.setByPass(false); + KUtil.error(getCurrentDesktop(), "쳣\n" + e); + e.printStackTrace(); + } + } +} diff --git a/src/com/connor/plm/KUtil.java b/src/com/connor/plm/KUtil.java new file mode 100644 index 0000000..855a1a6 --- /dev/null +++ b/src/com/connor/plm/KUtil.java @@ -0,0 +1,2395 @@ +package com.connor.plm; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.Window; +import java.io.BufferedWriter; +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.filechooser.FileSystemView; + +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.WorkbookFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; + +import com.connor.plm.sb02.ControlBean; +import com.teamcenter.rac.aif.commands.open.OpenCommand; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.common.lov.view.components.LOVDisplayer; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentContextList; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentGroup; +import com.teamcenter.rac.kernel.TCComponentGroupMember; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemRevisionType; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCComponentManager; +import com.teamcenter.rac.kernel.TCComponentQuery; +import com.teamcenter.rac.kernel.TCComponentQueryType; +import com.teamcenter.rac.kernel.TCComponentRole; +import com.teamcenter.rac.kernel.TCComponentSchedule; +import com.teamcenter.rac.kernel.TCComponentScheduleDeliverable; +import com.teamcenter.rac.kernel.TCComponentTCCalendar; +import com.teamcenter.rac.kernel.TCComponentTaskDeliverable; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCComponentUser; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCPropertyDescriptor; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTextService; +import com.teamcenter.rac.kernel.TCUserService; +import com.teamcenter.rac.schedule.calendar.TCCalendar; +import com.teamcenter.rac.schedule.componentutils.CalendarHelper; +import com.teamcenter.rac.ui.common.RACUIUtil; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.Registry; +import com.teamcenter.rac.util.UIUtilities; +import com.teamcenter.services.rac.core.DataManagementService; +import com.teamcenter.services.rac.core.LOVService; +import com.teamcenter.services.rac.core._2006_03.DataManagement.Relationship; +import com.teamcenter.services.rac.core._2007_01.DataManagement.WhereReferencedInfo; +import com.teamcenter.services.rac.core._2007_01.DataManagement.WhereReferencedOutput; +import com.teamcenter.services.rac.core._2007_01.DataManagement.WhereReferencedResponse; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse; +import com.teamcenter.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; +import com.teamcenter.soa.client.model.LovValue; +import com.teamcenter.soa.client.model.ServiceData; + +@SuppressWarnings("deprecation") +public class KUtil { + + public static final TCSession session; + public static final TCTextService textService; + // public static final Registry REG = Registry.getRegistry(KUtil.class); + public static final ZoneId zoneId = ZoneId.systemDefault(); + // public static final Registry reg = Registry.getRegistry(KUtil.class); + + // public static String getRegString(String title) { + // String res = reg.getString(title); + // if (KUtil.isEmpty(res)) { + // return title; + // } + // return res; + // } + + static { + session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + textService = session.getTextService(); + } + + public static void setTCPropertyValue(TCComponent item, String propertyName, Object value) { + try { + TCProperty tcProperty = item.getTCProperty(propertyName); + switch (tcProperty.getPropertyType()) { + case TCProperty.PROP_double: + if (value instanceof Double) { + tcProperty.setDoubleValue((double) value); + } else { + tcProperty.setDoubleValue(Double.parseDouble(value.toString())); + } + break; + case TCProperty.PROP_int: + if (value instanceof Integer) { + tcProperty.setDoubleValue((int) value); + } else { + tcProperty.setDoubleValue(Integer.parseInt(value.toString())); + } + break; + case TCProperty.PROP_string: + tcProperty.setStringValue(value.toString()); + break; + case TCProperty.PROP_date: + if (value instanceof Date) { + tcProperty.setDateValue((Date) value); + } else { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd HH:mm"); + tcProperty.setDateValue(sdf.parse(value.toString())); + } + break; + default: + break; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static Object getTCPropertyValue(TCComponent item, String propertyName) { + Object result = ""; + try { + TCProperty tcProperty = item.getTCProperty(propertyName); + if (tcProperty == null) { + System.out.println("δȡԣ" + propertyName); + return result; + } + switch (tcProperty.getPropertyType()) { + case TCProperty.PROP_double: + result = tcProperty.getDoubleValue(); + break; + case TCProperty.PROP_int: + result = tcProperty.getIntValue(); + break; + case TCProperty.PROP_string: + result = tcProperty.getStringValue(); + break; + case TCProperty.PROP_date: + result = tcProperty.getDateValue(); + break; + case TCProperty.PROP_logical: + result = tcProperty.getLogicalValue(); + break; + default: + break; + } + } catch (TCException e) { + e.printStackTrace(); + } + return result; + } + + public static String getCellValue(Cell c) { + if (c == null) { + return ""; + } + String value = ""; + if (c.getCellType() == CellType.NUMERIC.getCode()) { + DecimalFormat df = new DecimalFormat("0"); + String whatYourWant = df.format(c.getNumericCellValue()); + return whatYourWant; + } + switch (c.getCellType()) { + case HSSFCell.CELL_TYPE_NUMERIC:// + value = (c.getNumericCellValue() + "").split("\\.")[0]; + break; + case HSSFCell.CELL_TYPE_STRING:// ַ + value = c.getStringCellValue(); + break; + case HSSFCell.CELL_TYPE_BOOLEAN:// boolean + value = c.getBooleanCellValue() + ""; + break; + case HSSFCell.CELL_TYPE_FORMULA:// ʽ + value = c.getCellFormula() + ""; + break; + case HSSFCell.CELL_TYPE_BLANK:// ֵ + value = ""; + break; + case HSSFCell.CELL_TYPE_ERROR: + value = "Ƿַ"; + break; + default: + value = "δ֪"; + break; + } + return value; + } + + /** + * õʵ + * + * @param sheet + * @param flag ҪдݿExcelԪöŸ Excel5еԪ4 + * Ҫ⣬2вҪ⣬flagʹ [0,2,3,4] + * @return + * @throws Exception + * + */ + public static int findRealRows(Sheet sheet, int... flag) throws Exception { + int row_real = 0; + int rows = sheet.getPhysicalNumberOfRows();// ˴ͳд, + try { + + for (int i = 1; i < rows; i++) { + Row row = sheet.getRow(i); + int total = 0; + ArrayList blank = new ArrayList(); + int type = -1; + String s = null; + for (int j : flag) { + if (!(row.getCell(j) == null) && row.getCell(j).getCellType() < 2) { + type = row.getCell(j).getCellType(); + row.getCell(j).setCellType(1); + } + + if (row.getCell(j) == null || row.getCell(j).getStringCellValue().matches("^\\s+$") + || row.getCell(j).getCellType() > 2) { + total++; + + if (!(row.getCell(j) == null) && row.getCell(j).getCellType() < 2) { + row.getCell(j).setCellType(type); + } + blank.add(j); + + } + } + System.out.println(s + ""); + // 4жǿ˵͸÷ + if (total == flag.length) { + + return row_real; + } else if (total == 0) { + row_real++; + + } else { + String h = ""; + for (Integer b : blank) { + + h = h + "" + (b + 1) + "" + " "; + } + throw new Exception("" + (i + 1) + "" + h + "Ϊ"); + } + + } + } catch (NullPointerException e) { + throw new Exception("excelʽ쳣,excelʽȱʧ,Ч!"); + } + return row_real; + } + + public static Workbook getWorkbook(File file) throws Exception { + Workbook workbook = null; + FileInputStream in = new FileInputStream(file); + if (file.getName().endsWith("xlsx")) { + System.out.println("ȡģ:" + file.getName()); + try { + workbook = WorkbookFactory.create(in); + } catch (EOFException e) { + e.printStackTrace(); + } + // workbook = new XSSFWorkbook(in); + } else { + System.out.println("ʽ"); + } + in.close(); + return workbook; + } + + public static void removeEnd(StringBuilder sb, int len) { + if (sb == null || len <= 0) { + return; + } + if (sb.length() >= len) { + sb.setLength(sb.length() - len); + } + } + + public static TCComponent[] getComponentsByItemType(TCComponent comp, String type, String relation) + throws TCException { + TCComponent[] comps1 = comp.getRelatedComponents(relation); + if (comps1 == null || comps1.length < 1) { + return null; + } + ArrayList list = new ArrayList(); + for (TCComponent comp1 : comps1) { + if (comp1.getType().equals(type)) { + list.add(comp1); + } + } + return list.toArray(new TCComponent[] {}); + } + + public static TCComponentContextList objectsInProject(String type, String projId) throws Exception { + if (KUtil.isEmpty(type) || KUtil.isEmpty(projId)) { + return null; + } + String queryName = "Objects in Projects"; + String[] keys = new String[] { KUtil.getText("Type"), KUtil.getText("ProjectID") }; + String[] vals = new String[] { type, projId }; + return KUtil.query(KUtil.session, queryName, keys, vals); + } + + public static TCComponentContextList objectsInProject(String type, String projId, String name) throws Exception { + if (KUtil.isEmpty(type) || KUtil.isEmpty(projId) || KUtil.isEmpty(name)) { + return null; + } + String queryName = "Objects in Projects"; + String[] keys = new String[] { KUtil.getText("Name"), KUtil.getText("Type"), KUtil.getText("ProjectID") }; + String[] vals = new String[] { name, type, projId }; + return KUtil.query(KUtil.session, queryName, keys, vals); + } + + public static boolean checkGMPrivilegeFromPref(String prefName) throws Exception { + boolean validityCanEdit = false; + String validRoles = KUtil.getPrefVal(KUtil.session, prefName); + System.out.println(">> Check GroupMember Priv: " + validRoles); + if (!KUtil.isEmpty(validRoles)) { + List groups = new ArrayList(); + List roles = new ArrayList(); + String[] split = validRoles.split(":"); + for (String string : split) { + if (string.startsWith("G.")) { + groups.add(string.substring(2)); + } else if (string.startsWith("R.")) { + roles.add(string.substring(2)); + } + } + TCComponentUser currentUser = KUtil.session.getUser(); + System.out.println(">> Current User: " + currentUser); + TCComponentGroupMember[] gms = currentUser.getGroupMembers(); + System.out.println(">> Current GroupMembers: " + Arrays.toString(gms)); + int len = KUtil.getLen(gms); + for (int i = 0; i < len; i++) { + TCComponentGroupMember gm = gms[i]; + TCComponentGroup g = gm.getGroup(); + TCComponentRole r = gm.getRole(); + String gName = g.getGroupName(); + String rName = r.getRoleName(); + System.out.println((i + 1) + ". " + gName + " - " + rName); + if (groups.contains(gName) && roles.contains(rName)) { + validityCanEdit = true; + // break; + } + } + } + return validityCanEdit; + } + + public static boolean compare(String str1, String str2) { + if (str1 == null) { + str1 = ""; + } + if (str2 == null) { + str2 = ""; + } + return str1.equals(str2); + } + + public static boolean compare(Object str1, Object str2) { + if (str1 == null) { + return str2 == null; + } + return str1.equals(str2); + } + + public static TCComponentItem createItem(TCComponentItemType itemType, String itemName) throws Exception { + if (itemType == null) { + return null; + } + String id = itemType.getNewID(); + String rev = itemType.getNewRev(null); + return itemType.create(id, rev, itemType.getName(), itemName, "", null); + } + + public static void setByPass(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 TCComponentItem createItemBySOA(String itemTypeName, String revTypeName, String revMasterTypeName, + String itemId, String revId, String name, Map stringProps, Map dateProps) + throws Exception { + if (KUtil.isEmpty(itemTypeName) || KUtil.isEmpty(revTypeName) || KUtil.isEmpty(revMasterTypeName)) { + return null; + } + CreateInput revMasterInput = new CreateInput(); + revMasterInput.boName = revMasterTypeName; + if (stringProps != null) { + revMasterInput.stringProps = stringProps; + } + if (dateProps != null) { + revMasterInput.dateProps = dateProps; + } + CreateInput revInput = new CreateInput(); + revInput.boName = revTypeName; + Map revPropMap = new HashMap<>(); + if (!KUtil.isEmpty(revId)) { + revPropMap.put("item_revision_id", revId); + } + revInput.stringProps = revPropMap; + Map revMasterInfoMap = new HashMap<>(); + revMasterInfoMap.put("IMAN_master_form_rev", new CreateInput[] { revMasterInput }); + revInput.compoundCreateInput = revMasterInfoMap; + // create rev + CreateInput itemInput = new CreateInput(); + itemInput.boName = itemTypeName; + Map itemPropMap = new HashMap<>(); + if (!KUtil.isEmpty(itemId)) { + itemPropMap.put("item_id", itemId); + } + if (!KUtil.isEmpty(name)) { + itemPropMap.put("object_name", name); + } + itemInput.stringProps = itemPropMap; + Map revInfoMap = new HashMap<>(); + revInfoMap.put("revision", new CreateInput[] { revInput }); + itemInput.compoundCreateInput = revInfoMap; + // create info + CreateIn cI = new CreateIn(); + cI.clientId = "CreateItem"; + cI.data = itemInput; + // service + DataManagementService service = DataManagementService.getService(session); + // create + CreateResponse resp = service.createObjects(new CreateIn[] { cI }); + throwServiceDataError(resp.serviceData); + CreateOut[] cOs = resp.output; + if (cOs.length > 0) { + for (TCComponent s : cOs[0].objects) { + if (s instanceof TCComponentItem) { + return (TCComponentItem) s; + } + } + } + return null; + } + + public static TCComponentFolder createFolderBySOA(String folderTypeName, String folderName) throws Exception { + if (KUtil.isEmpty(folderTypeName)) { + return null; + } + CreateInput itemInput = new CreateInput(); + itemInput.boName = folderTypeName; + Map itemPropMap = new HashMap<>(); + itemPropMap.put("object_name", folderName); + itemInput.stringProps = itemPropMap; + // create info + CreateIn cI = new CreateIn(); + cI.clientId = "CreateFolder"; + cI.data = itemInput; + // service + DataManagementService service = DataManagementService.getService(session); + // create + CreateResponse resp = service.createObjects(new CreateIn[] { cI }); + throwServiceDataError(resp.serviceData); + CreateOut[] cOs = resp.output; + if (cOs.length > 0) { + for (TCComponent s : cOs[0].objects) { + if (s instanceof TCComponentFolder) { + return (TCComponentFolder) s; + } + } + } + return null; + } + + public static void throwServiceDataError(ServiceData serviceData) throws Exception { + if (serviceData.sizeOfPartialErrors() > 0) { + StringBuilder errInfo = new StringBuilder(); + for (int i = 0; i < serviceData.sizeOfPartialErrors(); i++) { + for (String msg : serviceData.getPartialError(i).getMessages()) { + errInfo.append(msg + "\n"); + } + } + // System.out.println(errInfo.toString()); + throw new Exception(errInfo.toString()); + } + } + + public static void throwServiceDataError(ServiceData serviceData, String defaultErrorMsg) throws Exception { + if (serviceData.sizeOfPartialErrors() > 0) { + StringBuilder errInfo = new StringBuilder(); + for (int i = 0; i < serviceData.sizeOfPartialErrors(); i++) { + for (String msg : serviceData.getPartialError(i).getMessages()) { + errInfo.append(msg + "\n"); + } + } + // System.out.println(errInfo.toString()); + if (KUtil.isEmpty(errInfo.toString())) { + throw new Exception(defaultErrorMsg); + } + throw new Exception(errInfo.toString()); + } + } + + public static Date localDateToDate(LocalDate localDate) { + if (localDate == null) { + return null; + } + ZonedDateTime zdt = localDate.atStartOfDay(zoneId); + Date date = Date.from(zdt.toInstant()); + return date; + } + + public static LocalDate dateToLocalDate(Date date) { + if (date == null) { + return null; + } + Instant instant = date.toInstant(); + LocalDate localDate = instant.atZone(zoneId).toLocalDate(); + return localDate; + } + + public static TCComponent stringToComponent(String uid) throws Exception { + if (KUtil.isEmpty(uid)) { + return null; + } + return session.stringToComponent(uid); + } + + public static String getText(String str) throws Exception { + if (KUtil.isEmpty(str)) { + return str; + } + String res = textService.getTextValue(str); + if (!KUtil.isEmpty(res)) { + return res; + } + return str; + } + + public static void sendTo(TCComponent comp, String perspectiveId) { + if (comp == null) { + return; + } + if (KUtil.isEmpty(perspectiveId)) { + perspectiveId = "com.teamcenter.rac.ui.perspectives.navigatorPerspective"; + } + com.teamcenter.rac.common.Activator.getDefault().openPerspective(perspectiveId); + com.teamcenter.rac.common.Activator.getDefault().openComponents(perspectiveId, new TCComponent[] { comp }); + } + + public static void open(TCComponent comp) { + if (comp == null) { + return; + } + if (comp instanceof TCComponentScheduleDeliverable) { + System.out.println(">> Open Schedule Deliverable: " + comp); + try { + comp = comp.getReferenceProperty("deliverable_inst"); + System.out.println(">> Open Schedule Deliverable Inst: " + comp); + if (comp == null) { + return; + } + } catch (Exception e) { + e.printStackTrace(); + } + } else if (comp instanceof TCComponentTaskDeliverable) { + System.out.println(">> Open Task Deliverable: " + comp); + try { + comp = comp.getReferenceProperty("fnd0DeliverableInstance"); + System.out.println(">> Open Task Deliverable Inst: " + comp); + if (comp == null) { + return; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + try { + Registry localRegistry = Registry.getRegistry("com.teamcenter.rac.commands.open.open"); + OpenCommand localOpenCommand = (OpenCommand) localRegistry.newInstanceForEx("openCommand", + new Object[] { AIFUtility.getActiveDesktop(), comp }); + localOpenCommand.executeModeless(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static JButton getImageBtn(String iconName) { + ImageIcon icon = new ImageIcon(KUtil.class.getResource("/icons/" + iconName)); + JButton btn = new JButton(icon); + btn.setPreferredSize(new Dimension(26, 26)); + btn.setContentAreaFilled(true); + btn.setFocusPainted(false); + btn.setBorderPainted(true); + // btn.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + return btn; + } + + public static void info(Window dialog, String msg) { + MessageBox.post(dialog, msg, "", MessageBox.INFORMATION); + } + + public static void warn(Window dialog, String msg) { + MessageBox.post(dialog, msg, "", MessageBox.WARNING); + } + + public static void error(Window dialog, String msg) { + MessageBox.post(dialog, msg, "", MessageBox.ERROR); + } + + public static void error(Window dialog, String msg, String title) { + MessageBox.post(dialog, msg, title, MessageBox.ERROR); + } + + public static void showScrollDialog(Window dialog, String text, String title) { + if (dialog == null) { + dialog = UIUtilities.getCurrentModalDialog(); + } + JTextArea textArea = new JTextArea(text); + textArea.setEditable(false); + JScrollPane scrollPane = new JScrollPane(textArea); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + scrollPane.setPreferredSize(new Dimension(500, 300)); + JOptionPane.showMessageDialog(dialog, scrollPane, title, JOptionPane.INFORMATION_MESSAGE); + } + + public static void showScrollDialogWithExport(Window dialog, String text, String title, String exportFileName) { + if (dialog == null) { + dialog = UIUtilities.getCurrentModalDialog(); + } + JTextArea textArea = new JTextArea(text); + textArea.setEditable(false); + JScrollPane scrollPane = new JScrollPane(textArea); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + scrollPane.setPreferredSize(new Dimension(500, 300)); + String yesOption = KLocale.getString("ok"); + String exportOption = KLocale.getString("export"); + int op = JOptionPane.showOptionDialog(dialog, scrollPane, title, JOptionPane.YES_NO_OPTION, + JOptionPane.INFORMATION_MESSAGE, null, new String[] { yesOption, exportOption }, yesOption); + if (op == 1) { + System.out.println("Export"); + File saveFile = KUtil.chooseSaveFile(dialog, exportFileName, "txt"); + if (saveFile != null) { + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(saveFile, false)); + writer.write(text); + writer.flush(); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(dialog, e); + } + } + } + } + + public static void errorSWT(Shell shell, String message, String title) { + showDialog(shell, message, title, SWT.ICON_ERROR); + } + + public static void showDialog(Shell shell, String message, String title, int type) { + org.eclipse.swt.widgets.MessageBox dialog = new org.eclipse.swt.widgets.MessageBox(shell, SWT.OK | type); + dialog.setText(title); + dialog.setMessage(message); + dialog.open(); + } + + public static String[] getPrefVals(TCSession session, String prefName) throws Exception { + if (KUtil.isEmpty(prefName)) { + return null; + } + return session.getPreferenceService().getStringValues(prefName); + } + + public static String getPrefVal(TCSession session, String prefName) throws Exception { + if (KUtil.isEmpty(prefName)) { + return null; + } + return session.getPreferenceService().getStringValue(prefName); + } + + public static String getReg(Registry reg, String name) { + String val = reg.getString(name); + // System.out.println("Read REG: " + name + " = " + val); + return val; + } + + // public static String getReg(String name) { + // return getReg(REG, name); + // } + + public static void newRow(JPanel panel, Component comp, GridBagConstraints s, int width) { + newRow(panel, comp, s, width, 0); + } + + public static void newRow(JPanel panel, Component comp, GridBagConstraints s, int width, double weightx) { + s.weightx = weightx; + s.gridwidth = width; + s.gridx = 0; + s.gridy++; + panel.add(comp, s); + } + + public static void newRow(JDialog panel, Component comp, GridBagConstraints s, int width) { + s.weightx = 0; + s.gridwidth = width; + s.gridx = 0; + s.gridy++; + panel.add(comp, s); + } + + public static void addCol(JPanel panel, Component comp, GridBagConstraints s, int width, double weightx) { + s.gridx++; + s.gridwidth = width; + s.weightx = weightx; + panel.add(comp, s); + } + + public static TCComponentDataset getDataset(TCComponent rev, String dsType, String dsName, String rel) + throws Exception { + if (rev == null || KUtil.isEmpty(dsName)) { + return null; + } + rev.refresh(); + TCComponent[] kids = rev.getRelatedComponents(rel); + for (TCComponent c : kids) { + if (c.getType().equals(dsType) && c.toString().equals(dsName)) { + return (TCComponentDataset) c; + } + } + return null; + } + + public static List getDatasets(TCComponent rev, String dsType, String rel) throws Exception { + if (rev == null) { + return null; + } + rev.refresh(); + List res = new ArrayList(); + TCComponent[] kids = rev.getRelatedComponents(rel); + for (TCComponent c : kids) { + if (c.getType().equals(dsType)) { + res.add((TCComponentDataset) c); + } + } + return res; + } + + public static List getChildComponents(TCComponent rev, String dsType, String rel, String dsNamePrefix) + throws Exception { + if (rev == null) { + return null; + } + rev.refresh(); + List res = new ArrayList(); + TCComponent[] kids = rev.getRelatedComponents(rel); + for (TCComponent c : kids) { + if (c.getType().equals(dsType) && c.getProperty("object_name").startsWith(dsNamePrefix)) { + res.add(c); + } + } + return res; + } + + public static List getChildComponentsContainsStr(TCComponent rev, String dsType, String rel, + String dsNameSubStr) throws Exception { + if (rev == null) { + return null; + } + if (dsNameSubStr == null) { + dsNameSubStr = ""; + } + rev.refresh(); + List res = new ArrayList(); + TCComponent[] kids = rev.getRelatedComponents(rel); + for (TCComponent c : kids) { + if (c.getType().equals(dsType) && c.getProperty("object_name").contains(dsNameSubStr)) { + res.add(c); + } + } + return res; + } + + public static List getChildComponents(TCComponent rev, String dsType, String rel) throws Exception { + if (rev == null) { + return null; + } + rev.refresh(); + List res = new ArrayList(); + TCComponent[] kids = rev.getRelatedComponents(rel); + for (TCComponent c : kids) { + if (c.getType().equals(dsType)) { + res.add(c); + } + } + return res; + } + + public static TCComponentFolder getChildFolder(TCComponentFolder folder, String cFolderName) throws Exception { + if (folder == null || cFolderName == null) { + return null; + } + AIFComponentContext[] cc = folder.getChildren(); + int len = KUtil.getLen(cc); + for (int i = 0; i < len; i++) { + InterfaceAIFComponent c = cc[i].getComponent(); + if ((c instanceof TCComponentFolder) && cFolderName.equals(c.getProperty("object_name"))) { + return (TCComponentFolder) c; + } + } + return null; + } + + public static TCComponentDataset uploadFile(TCSession session, TCComponent rev, File newFile, String dsName, + String dsTypeName, String refName, String rel) throws Exception { + TCComponentDataset ds = getDataset(rev, dsTypeName, dsName, rel); + if (ds == null) { + TCComponentDatasetType dsType = (TCComponentDatasetType) session.getTypeComponent(dsTypeName); + ds = dsType.create(dsName, "", dsTypeName); + if (rev != null) { + rev.add(rel, ds); + rev.refresh(); + } + } + setDsFile(ds, refName, newFile); + return ds; + } + + public static void setDsFile(TCComponentDataset ds, String refName, File newFile) throws Exception { + if (ds.isCheckedOut()) { + throw new Exception(String.format(KLocale.getString("uploadfilewhencheckout.ERROR1"), ds.toString())); + } + String[] refs = new String[] { refName }; + String[] files = new String[] { newFile.getAbsolutePath() }; + ds.setFiles(files, refs); + // ds.save(); + ds.refresh(); + } + + public static void setDsFile2(TCComponentDataset ds, String refName, File newFile) throws Exception { + String[] refs = new String[] { refName }; + String[] files = new String[] { newFile.getAbsolutePath() }; + ds.setFiles(files, refs); + // ds.save(); + ds.refresh(); + } + + public static boolean isEmpty(String str) { + return str == null || "".equals(str.trim()); + } + + public static int inArray(int target, int[] arr) { + int len = arr == null ? 0 : arr.length; + for (int i = 0; i < len; i++) { + if (target == arr[i]) { + return i; + } + } + return -1; + } + + public static boolean inArray(String str, String arr, String splitter) { + if (KUtil.isEmpty(arr) || KUtil.isEmpty(splitter)) { + return false; + } + if (KUtil.isEmpty(str)) { + return true; + } + return inArray(str, arr.split(splitter)) >= 0; + } + + public static int inArray(String target, String[] arr) { + int len = arr == null ? 0 : arr.length; + for (int i = 0; i < len; i++) { + if (target.equals(arr[i])) { + return i; + } + } + return -1; + } + + public static int getNextColNumber(int currentIndex, int[] skipColIndex, int cols) { + int res = currentIndex; + for (int i = 0; i < cols; i++) { + res++; + if (inArray(res, skipColIndex) >= 0) { + i--; + } + } + return res; + } + + public static List> groupList(List originList, int maxCount, int gap, E gapFiller) { + List> res = new ArrayList>(); + int cnt = originList == null ? 0 : originList.size(); + List list = new ArrayList(); + for (int i = 0; i < cnt; i++) { + list.add(originList.get(i)); + if (i != cnt - 1) {// add gap + for (int j = 0; j < gap; j++) { + list.add(gapFiller); + } + } + } + cnt = list == null ? 0 : list.size(); + if (maxCount <= 0) { + maxCount = cnt; + } + int pageCounter = 0; + List cList = new ArrayList(); + res.add(cList); + for (int i = 0; i < cnt; i++) { + if (pageCounter == maxCount) { + cList = new ArrayList<>(); + res.add(cList); + pageCounter = 0; + } + if (cList != null) { + E item = list.get(i); + if (cList.size() == 0 && item == gapFiller) { + continue; + } + cList.add(list.get(i)); + pageCounter++; + } + } + list.clear(); + list = null; + return res; + } + + public static List> groupListWithGapAdded(List list, int maxCount, E gapFiller) { + List> res = new ArrayList>(); + int cnt = list == null ? 0 : list.size(); + if (maxCount <= 0) { + maxCount = cnt; + } + int pageCounter = 0; + List cList = new ArrayList(); + res.add(cList); + for (int i = 0; i < cnt; i++) { + if (pageCounter == maxCount) { + cList = new ArrayList<>(); + res.add(cList); + pageCounter = 0; + } + if (cList != null) { + E item = list.get(i); + if (cList.size() == 0 && item == gapFiller) { + continue; + } + cList.add(list.get(i)); + pageCounter++; + } + } + list.clear(); + list = null; + return res; + } + + public static List>> groupList(List> originList, int maxCount, int gap, + Map gapFiller, String gapKey) { + List>> res = new ArrayList>>(); + int cnt = originList == null ? 0 : originList.size(); + List> list = new ArrayList>(); + boolean addGap = false; + for (int i = 0; i < cnt; i++) { + Map item = originList.get(i); + list.add(item); + if (i != cnt - 1) {// add gap + Map nextItem = originList.get(i + 1); + addGap = KUtil.isEmpty(gapKey) || (nextItem != null && nextItem.containsKey(gapKey)); + for (int j = 0; j < gap; j++) { + if (addGap) { + list.add(gapFiller); + } + } + } + } + cnt = list == null ? 0 : list.size(); + if (maxCount <= 0) { + maxCount = cnt; + } + int pageCounter = 0; + List> cList = new ArrayList>(); + res.add(cList); + for (int i = 0; i < cnt; i++) { + if (pageCounter == maxCount) { + cList = new ArrayList<>(); + res.add(cList); + pageCounter = 0; + } + if (cList != null) { + Map item = list.get(i); + if (cList.size() == 0 && item == gapFiller) { + continue; + } + cList.add(list.get(i)); + pageCounter++; + } + } + list.clear(); + list = null; + return res; + } + + public static File getFileFromDataset(TCSession session, String dsType, String uid, String prefName) + throws Exception { + TCComponent comp = null; + try { + comp = session.stringToComponent(uid); + } catch (Exception e) { + e.printStackTrace(); + } + if (comp == null) { + throw new Exception(String.format(KLocale.getString("dsuidinpref.ERROR1"), prefName)); + } + String type = comp.getType(); + System.out.println("Dataset: " + comp + "|Type: " + type); + if (!dsType.equals(type)) { + throw new Exception(String.format(KLocale.getString("dsuidinpref.ERROR1"), prefName)); + } + TCComponentDataset tDataset = (TCComponentDataset) comp; + return getDatasetFile(tDataset); + } + + public static File getDatasetFile(TCComponentDataset dataset) throws Exception { + File[] files = dataset.getFiles("", System.getenv("TEMP")); + if (files == null || files.length == 0) { + throw new Exception(String.format(KLocale.getString("norefindataset.ERROR1"), dataset.toString())); + } + System.out.println(">> Download file (" + files.length + "): " + files[0].getAbsolutePath()); + return files[0]; + } + + public static File getDatasetFile(File dir, TCComponentDataset dataset) throws Exception { + if (dir == null || !dir.isDirectory()) { + throw new Exception("Directory not found."); + } + File[] files = dataset.getFiles("", dir.getAbsolutePath()); + if (files == null || files.length == 0) { + throw new Exception(String.format(KLocale.getString("norefindataset.ERROR1"), dataset.toString())); + } + System.out.println(">> Download file (" + files.length + "): " + files[0].getAbsolutePath()); + return files[0]; + } + + public static String[] getStringArrayProp(TCComponentForm form, String propName) throws Exception { + if (form == null) { + return null; + } + TCProperty prop = form.getFormTCProperty(propName); + if (prop == null) { + throw new java.lang.Exception( + String.format(KLocale.getString("nopropintype.ERROR2"), form.getDisplayType(), propName)); + } + return prop.getStringArrayValue(); + } + + public static File chooseDirectory(Component parent) { + FileSystemView fsv = FileSystemView.getFileSystemView(); + String deskPath = fsv.getHomeDirectory().getPath(); + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setCurrentDirectory(new File(deskPath)); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int state = fileChooser.showOpenDialog(parent); + if (state == 1) { + return null; + } + return fileChooser.getSelectedFile(); + } + + public static boolean addReleaseStatus(TCSession session, String uid, String status) throws Exception { + TCUserService userservice = session.getUserService(); + Object[] obj = new Object[2]; + obj[0] = uid; + obj[1] = status; + Object res = userservice.call("K_add_release_status", obj); + if (res != null && res.toString().equalsIgnoreCase("true")) { + return true; + } + return false; + } + + /** + * ֻԵֵ + * + * @param session + * @param propName + * @param propValue + * @param comp + * @return + * @throws Exception + */ + public static boolean setPropValue(TCSession session, String propName, String propValue, TCComponent comp) + throws Exception { + TCUserService userservice = session.getUserService(); + Object[] obj = new Object[3]; + obj[0] = propName; + obj[1] = propValue; + obj[2] = comp; + Object res = userservice.call("Connor_Set_Prop_Value", obj); + if (res != null && res.toString().equalsIgnoreCase("true")) { + return true; + } + return false; + } + + public static File chooseFile(Component parent) { + FileSystemView fsv = FileSystemView.getFileSystemView(); + String deskPath = fsv.getHomeDirectory().getPath(); + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setCurrentDirectory(new File(deskPath)); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + FileNameExtensionFilter filter = new FileNameExtensionFilter("*.xlsx", "xlsx"); + fileChooser.setFileFilter(filter); + int state = fileChooser.showOpenDialog(parent); + if (state == 1) { + return null; + } + return fileChooser.getSelectedFile(); + } + + public static File chooseSaveFile(Component parent, String defaultFile) { + FileSystemView fsv = FileSystemView.getFileSystemView(); + String deskPath = fsv.getHomeDirectory().getPath(); + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setCurrentDirectory(new File(deskPath)); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + FileNameExtensionFilter filter = new FileNameExtensionFilter("*.xlsx", "xlsx"); + fileChooser.setFileFilter(filter); + fileChooser.setSelectedFile(new File(defaultFile)); + int state = fileChooser.showSaveDialog(parent); + if (state == 1) { + return null; + } + return fileChooser.getSelectedFile(); + } + + public static File chooseSaveFile(Component parent, String defaultFile, String ext) { + FileSystemView fsv = FileSystemView.getFileSystemView(); + String deskPath = fsv.getHomeDirectory().getPath(); + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setCurrentDirectory(new File(deskPath)); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + if (!KUtil.isEmpty(ext)) { + FileNameExtensionFilter filter = new FileNameExtensionFilter("*." + ext, ext); + fileChooser.setFileFilter(filter); + } + fileChooser.setSelectedFile(new File(defaultFile)); + int state = fileChooser.showSaveDialog(parent); + if (state == 1) { + return null; + } + return fileChooser.getSelectedFile(); + } + + public static File getNewFile(File folder, String fileName, String ext) { + File file = new File(folder.getAbsolutePath() + "\\" + fileName + "." + ext); + int index = 1; + while (file.exists()) { + file = new File(folder.getAbsolutePath() + "\\" + fileName + "(" + (index++) + ")." + ext); + } + return file; + } + + public static String getDateStr(Date date, String format) { + String res = ""; + try { + SimpleDateFormat sdf = new SimpleDateFormat(format); + res = sdf.format(date); + } catch (Exception e) { + e.printStackTrace(); + } + return res; + } + + public static TCComponentContextList query(TCSession session, String queryName, Map fields) + throws Exception { + String[] keys = fields.keySet().toArray(new String[] {}); + String[] vals = fields.values().toArray(new String[] {}); + return query(session, queryName, keys, vals); + } + + public static TCComponentContextList query(TCSession session, String queryName, String[] keys, String[] vals) + throws Exception { + System.out.println("Query: " + queryName); + System.out.println("keys = " + Arrays.toString(keys)); + System.out.println("vals = " + Arrays.toString(vals)); + TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery query = (TCComponentQuery) queryType.find(queryName); + if (query == null) { + throw new Exception(String.format(KLocale.getString("querynotexist.ERROR1"), queryName)); + } + queryType.clearCache(); + query.clearCache(); + query.refresh(); + return query.getExecuteResultsList(keys, vals); + } + + public static TCComponent[] query2(TCSession session, String queryName, String[] keys, String[] vals) + throws Exception { + System.out.println("Query: " + queryName); + System.out.println("keys = " + Arrays.toString(keys)); + System.out.println("vals = " + Arrays.toString(vals)); + TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery query = (TCComponentQuery) queryType.find(queryName); + if (query == null) { + throw new Exception(String.format(KLocale.getString("querynotexist.ERROR1"), queryName)); + } + queryType.clearCache(); + query.clearCache(); + query.refresh(); + return query.execute(keys, vals); + } + + public static TCComponentContextList combineContext(TCSession session, TCComponentQuery query, + TCComponentContextList... contexts) throws Exception { + Class c = TCComponentContextList.class; + Field f1 = c.getDeclaredField("m_compUids"); + f1.setAccessible(true); + List compUids = new ArrayList<>(); + for (TCComponentContextList cc : contexts) { + String[] u1 = (String[]) f1.get(cc); + System.out.println(Arrays.toString(u1)); + compUids.addAll(Arrays.asList(u1)); + } + Constructor constructor = c.getDeclaredConstructor(TCComponentManager.class, TCComponent.class, + String[].class, String[].class, String.class); + constructor.setAccessible(true); + TCComponentContextList res = (TCComponentContextList) constructor.newInstance(new TCComponentManager(session), + query, compUids.toArray(new String[] {}), null, ""); + return res; + } + + public static int getLen(Object[] arr) { + return arr == null ? 0 : arr.length; + } + + public static String getValueInArray(String[] arr, int index) { + int len = arr == null ? 0 : arr.length; + if (index >= len) { + return ""; + } + return arr[index]; + } + + public static String getValueInArray(String arrStr, int index, String splitter) { + if (KUtil.isEmpty(arrStr)) { + return ""; + } + String[] split = arrStr.split(splitter, -1); + int len = getLen(split); + if (len > index && index >= 0) { + return split[index]; + } + return ""; + } + + public static String getTypeNames(TCSession session, Object[] types) { + int len = types == null ? 0 : types.length; + if (len == 0) { + return ""; + } + String[] names = new String[len]; + for (int i = 0; i < len; i++) { + try { + if ("TC_Project".equals(types[i].toString())) { + names[i] = KLocale.getString("project"); + } else { + names[i] = session.getTypeComponent(types[i].toString()).getDisplayTypeName(); + } + } catch (Exception e) { + e.printStackTrace(); + } + if (names[i] == null) { + names[i] = types[i].toString(); + } + } + return Arrays.toString(names); + } + + public static String getTypeName(TCSession session, String type) { + if (KUtil.isEmpty(type)) { + return ""; + } + try { + if ("TC_Project".equals(type)) { + return KLocale.getString("project"); + } else { + return session.getTypeComponent(type).getDisplayTypeName(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return type; + } + + public static boolean isReleased(TCComponent comp) throws Exception { + TCComponent[] status = comp.getReferenceListProperty("release_status_list"); + if (status == null || status.length == 0) { + return false; + } + return true; + } + + public static TCComponentUser getUserFromStr(String str) throws Exception { + System.out.println("Search User: " + str); + if (KUtil.isEmpty(str)) { + return null; + } + int ind1 = str.lastIndexOf('('); + int ind2 = str.lastIndexOf(')'); + TCComponentUser user = null; + if (ind1 > 0 && ind2 > ind1) { + String userId = str.substring(ind1 + 1, ind2); + if (KUtil.isEmpty(userId)) { + System.out.println("No Id between '(' and ')'"); + user = null; + } else { + user = queryUserById(userId); + } + } else { + user = queryUserById(str); + if (user == null) { + user = queryUserByName(str); + } + } + return user; + } + + public static TCComponentUser queryUserById(String userId) throws Exception { + System.out.println("Search User By Id: " + userId); + if (KUtil.isEmpty(userId)) { + return null; + } + String queryName = "Admin - Employee Information"; + String[] keys = new String[] { KUtil.getText("UserId") }; + String[] vals = new String[] { userId }; + TCComponentContextList res = KUtil.query(KUtil.session, queryName, keys, vals); + if (res.getListCount() == 0) { + return null; + } + if (res.getListCount() > 1) { + throw new Exception(String.format(KLocale.getString("multiuserbyid.ERROR1"), userId)); + } + return (TCComponentUser) res.get(0).getComponent(); + } + + public static TCComponentUser queryUserByName(String userName) throws Exception { + System.out.println("Search User By Name: " + userName); + if (KUtil.isEmpty(userName)) { + return null; + } + String queryName = "Admin - Employee Information"; + String[] keys = new String[] { KUtil.getText("PersonName") }; + String[] vals = new String[] { userName }; + TCComponentContextList res = KUtil.query(KUtil.session, queryName, keys, vals); + if (res.getListCount() == 0) { + return null; + } + if (res.getListCount() > 1) { + throw new Exception(String.format(KLocale.getString("multiuserbyname.ERROR1"), userName)); + } + return (TCComponentUser) res.get(0).getComponent(); + } + + public static TCComponent[] getGroupMember(List privMembers) throws Exception { + if (privMembers == null) { + return null; + } + List res = new ArrayList<>(); + for (TCComponentUser user : privMembers) { + TCComponentGroupMember[] gms = user.getGroupMembers(); + int len = KUtil.getLen(gms); + for (int i = 0; i < len; i++) { + TCComponentGroupMember gm = gms[i]; + if (KUtil.isEmpty(gm.toString())) { + continue; + } + /* + * if(!gm.isActive()) { System.out.println("���Ա�ǻ�?"+gm); continue; } + */ + if (!res.contains(gm)) { + System.out.println("Add Group Member: " + gm); + res.add(gm); + } else { + System.out.println("Added: " + gm); + } + } + } + return res.toArray(new TCComponent[] {}); + } + + public static int compareWBS(String wbsCode, String wbsCode2) { + if (KUtil.isEmpty(wbsCode) && KUtil.isEmpty(wbsCode2)) { + return 0; + } + if (KUtil.isEmpty(wbsCode)) { + return -1; + } + if (KUtil.isEmpty(wbsCode2)) { + return 1; + } + String[] a = wbsCode.split("\\."); + String[] b = wbsCode2.split("\\."); + int lenA = a.length; + int lenB = b.length; + for (int i = 0; i < lenA && i < lenB; i++) { + String aa = a[i]; + String bb = b[i]; + int ai = 0; + int bi = 0; + try { + ai = Integer.parseInt(aa); + bi = Integer.parseInt(bb); + } catch (Exception e) { + e.printStackTrace(); + } + if (ai != bi) { + return ai - bi; + } + } + return lenA - lenB; + } + + public static TCComponentListOfValues getLov(String lovName) { + TCComponentListOfValuesType lovType; + try { + lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues"); + TCComponentListOfValues[] lov = lovType.find(lovName); + if (lov.length > 0) + return lov[0]; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static String[] getDynamicLOV(String s) { + TCComponentListOfValues lov = null; + List lovDisplayValueList = new ArrayList<>(); + lovDisplayValueList.add(""); + List lovValueList = new ArrayList<>(); + lov = TCComponentListOfValuesType.findLOVByName(s); + try { + if ("Fnd0ListOfValuesDynamic".equals(lov.getProperty("lov_type"))) { + LOVService lovService = LOVService.getService(RACUIUtil.getTCSession()); + 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()) { + sb.append("UID:" + row.uid + ",key:" + key + "value:" + map.get(key)[0]); + sb.append("\n"); + + lovDisplayValueList.add(map.get(key)[0]); + lovValueList.add(realmap.get(key)[0]); + } + } + } + } catch (TCException e) { + e.printStackTrace(); + } + return lovDisplayValueList.toArray(new String[lovDisplayValueList.size()]); + } + + public static String getLovValue(TCComponentListOfValues lov, String str) throws Exception { + return getLovValue(lov, str, true); + } + + public static String getLovValue(TCComponentListOfValues lov, String str, boolean translate) throws Exception { + if (lov == null || KUtil.isEmpty(str)) { + return str; + } + if (translate) { + String prefName = "LOV_TRANS_" + lov.getStringProperty(TCComponentListOfValues.PROP_LOV_NAME); + String[] prefVals = KUtil.getPrefVals(KUtil.session, prefName); + int len = KUtil.getLen(prefVals); + for (int i = 0; i < len; i++) { + String pref = prefVals[i]; + int ind = pref.indexOf('='); + if (ind > 0) { + String realVal = pref.substring(0, ind); + String disVal = pref.substring(ind + 1); + if (str.equals(realVal) || str.equals(disVal)) { + return realVal; + } + } + } + } + ListOfValuesInfo info = lov.getListOfValues(); + if (info == null) { + return str; + } + List v = info.getValues(); + int size = v == null ? 0 : v.size(); + for (int i = 0; i < size; i++) { + LovValue vv = v.get(i); + String realValue = vv.getValue() == null ? "" : vv.getValue().toString(); + if (str.equals(realValue)) { + return str; + } + String disValue = vv.getDisplayValue(); + if (str.equals(disValue)) { + return realValue; + } + } + throw new Exception(String.format(KLocale.getString("valuenotinlov.ERROR2"), lov.toString(), str)); + } + + public static String getLovDisplayableValue(TCComponentListOfValues lov, String str) throws Exception { + if (lov == null || KUtil.isEmpty(str)) { + return str; + } + ListOfValuesInfo info = lov.getListOfValues(); + if (info == null) { + return str; + } + List v = info.getValues(); + int size = v == null ? 0 : v.size(); + for (int i = 0; i < size; i++) { + LovValue vv = v.get(i); + String realValue = vv.getValue() == null ? "" : vv.getValue().toString(); + if (str.equals(realValue)) { + return vv.getDisplayValue(); + } + String disValue = vv.getDisplayValue(); + if (str.equals(disValue)) { + return str; + } + } + throw new Exception(String.format(KLocale.getString("valuenotinlov.ERROR2"), lov.toString(), str)); + } + + public static void openFile(File file) { + try { + if (file != null && file.exists()) { + Runtime.getRuntime().exec("cmd /c start /b call \"" + file.getAbsolutePath() + "\""); + } + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(e); + } + } + + public static void importDataset(TCComponent parent, String rel, File f, String dsType, String refName) + throws Exception { + if (f == null || !f.exists() || KUtil.isEmpty(dsType) || KUtil.isEmpty(refName)) { + return; + } + TCComponentDatasetType datasetType = (TCComponentDatasetType) session.getTypeComponent(dsType); + TCComponentDataset dataset = datasetType.create(f.getName(), "", dsType); + String paths[] = { f.getAbsolutePath() }; + String refs[] = { refName }; + dataset.setFiles(paths, refs); + if (parent != null && !KUtil.isEmpty(rel)) { + parent.add(rel, dataset); + } + } + + public static void initPropMap(String propConfig, String value, Map itemPropMap, + Map itemMasterPropMap, Map revPropMap, Map revMasterPropMap) + throws Exception { + initPropMap(propConfig, value, itemPropMap, itemMasterPropMap, revPropMap, revMasterPropMap, null); + } + + public static void initPropMap(String propConfig, String value, Map itemPropMap, + Map itemMasterPropMap, Map revPropMap, Map revMasterPropMap, + Map bomlinePropMap) throws Exception { + if (KUtil.isEmpty(propConfig)) { + return; + } + String propFrom = null, propName = null; + String[] split = propConfig.split("\\."); + if (KUtil.getLen(split) == 2) { + propFrom = split[0].trim().toUpperCase(); + propName = split[1].trim(); + } + if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) { + return; + } + Map target; + if ("ITEM".equals(propFrom)) { + target = itemPropMap; + System.out.println(">> ITEM PROP: " + propName + " = " + value); + } else if ("REV".equals(propFrom)) { + System.out.println(">> REV PROP: " + propName + " = " + value); + target = revPropMap; + } else if ("ITEMMASTER".equals(propFrom)) { + System.out.println(">> ITEMMASTER PROP: " + propName + " = " + value); + target = itemMasterPropMap; + } else if ("REVMASTER".equals(propFrom)) { + System.out.println(">> REVMASTER PROP: " + propName + " = " + value); + target = revMasterPropMap; + } else if ("BOMLINE".equals(propFrom)) { + System.out.println(">> BOMLINE PROP: " + propName + " = " + value); + target = bomlinePropMap; + } else { + throw new Exception(String.format(KLocale.getString("proplocationnotdefined.ERROR1"), propFrom)); + } + if (target == null) { + return; + } + target.put(propName, value); + } + + public static String getMarkedPropValue(String config, Map markedComponents) throws Exception { + return getMarkedPropValue(config, markedComponents, null); + } + + public static String getMarkedPropValue(String config, Map markedComponents, + Map> relatedComponents) throws Exception { + if (markedComponents == null || KUtil.isEmpty(config)) { + return ""; + } + StringBuilder res = new StringBuilder(); + String[] propConfigSplit = config.split("\\+"); + int len = KUtil.getLen(propConfigSplit); + for (int i = 0; i < len; i++) { + String propConfig = propConfigSplit[i]; + String propFrom = null, propName = null; + String defaultValue = ""; + String[] split = propConfig.split("\\."); + if (KUtil.getLen(split) >= 2) { + propFrom = split[0].trim().toUpperCase(); + propName = split[1].trim(); + } + if (KUtil.getLen(split) >= 3) { + defaultValue = split[2].trim(); + } + if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) { + if (propConfig.contains("\\n")) { + propConfig = propConfig.replace("\\n", "\n"); + } + res.append(propConfig); + continue; + } + if (!markedComponents.containsKey(propFrom)) { + if (propFrom.startsWith("T")) { + return ""; + } + continue; + } + TCComponent comp = markedComponents.get(propFrom); + // λ.-[-ӷ] + int ind = propName.indexOf('-'); + if (ind > 0) { + String tableProp = propName.substring(0, ind).trim(); + String tableRowProp = propName.substring(ind + 1).trim(); + if (!KUtil.isEmpty(tableProp) && !KUtil.isEmpty(tableRowProp)) { + TCProperty prop = comp.getTCProperty(tableProp.trim()); + if (prop == null) { + throw new Exception(String.format(KLocale.getString("propnotdefinedintype.ERROR2"), + comp.getType(), propName)); + } + String rowSplitter = "#ROW#"; + ind = tableRowProp.indexOf('-'); + if (ind > 0) { + rowSplitter = tableRowProp.substring(ind + 1); + tableRowProp = tableRowProp.substring(0, ind); + } + TCComponent[] tableRows = prop.getReferenceValueArray(); + int rowCnt = KUtil.getLen(tableRows); + String[] value = new String[rowCnt]; + for (int j = 0; j < rowCnt; j++) { + value[j] = tableRows[j].getPropertyDisplayableValue(tableRowProp); + } + res.append(String.join(rowSplitter, value)); + } + continue; + } + TCProperty prop = comp.getTCProperty(propName.trim()); + if (prop == null) { + throw new Exception( + String.format(KLocale.getString("propnotdefinedintype.ERROR2"), comp.getType(), propName)); + } + String value = prop.getDisplayableValue(); + if ("NAME".equalsIgnoreCase(defaultValue)) { + value = prop.getPropertyDisplayName(); + } else if (value == null || "".equals(value)) { + value = defaultValue; + } + res.append(value); + } + return res.toString(); + } + + public static TCComponent getLatestComponent(List comps) { + int size = comps == null ? 0 : comps.size(); + if (size == 0) { + return null; + } + if (size == 1) { + return comps.get(0); + } + TCComponent res = comps.get(0); + try { + Date maxDate = res.getDateProperty("creation_date"); + for (int i = 1; i < size; i++) { + TCComponent temp = comps.get(i); + Date tempDate = temp.getDateProperty("creation_date"); + if (tempDate.after(maxDate)) { + maxDate = tempDate; + res = temp; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return res; + } + + public static TCComponentType[] getComponentTypes(String itemTypeName) throws Exception { + TCComponentItemType itemType = null; + try { + itemType = (TCComponentItemType) session.getTypeComponent(itemTypeName); + } catch (Exception e) { + e.printStackTrace(); + } + if (itemType == null) { + throw new Exception(String.format(KLocale.getString("typenotfound.ERROR1"), itemTypeName)); + } + TCComponentItemRevisionType revType = itemType.getItemRevisionType(); + if (revType == null) { + throw new Exception(String.format(KLocale.getString("typenotfound.ERROR1"), itemTypeName + "Revision")); + } + TCComponentType itemMasterType = null; + try { + itemMasterType = session.getTypeComponent(itemTypeName + "Master"); + } catch (Exception e) { + e.printStackTrace(); + } + if (itemMasterType == null) { + try { + itemMasterType = session.getTypeComponent(itemTypeName + " Master"); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (itemMasterType == null) { + throw new Exception(String.format(KLocale.getString("typenotfound.ERROR1"), itemTypeName + "Master")); + } + TCComponentType revMasterType = null; + try { + revMasterType = session.getTypeComponent(revType.getTypeName() + "Master"); + } catch (Exception e) { + e.printStackTrace(); + } + if (revMasterType == null) { + try { + revMasterType = session.getTypeComponent(revType.getTypeName() + " Master"); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (revMasterType == null) { + throw new Exception( + String.format(KLocale.getString("typenotfound.ERROR1"), revType.getTypeName() + "Master")); + } + return new TCComponentType[] { itemType, revType, itemMasterType, revMasterType }; + } + + public static String getPropertyDisplayName(TCComponentType type, String propName) throws Exception { + if (type == null || KUtil.isEmpty(propName)) { + return propName; + } + TCPropertyDescriptor desc = type.getPropDesc(propName); + if (desc == null) { + throw new Exception(String.format(KLocale.getString("propnotdefinedintype.ERROR2"), + type.getDisplayTypeName(), propName)); + } + return desc.getDisplayName(); + } + + public static String getConfigPropValue(TCComponentItemRevision rev, String propConfigStr) throws Exception { + if (rev == null || KUtil.isEmpty(propConfigStr)) { + return ""; + } + StringBuilder res = new StringBuilder(); + String[] propConfigSplit = propConfigStr.split("\\+"); + int len = KUtil.getLen(propConfigSplit); + for (int i = 0; i < len; i++) { + String propConfig = propConfigSplit[i]; + String propFrom = null, propName = null; + String[] split = propConfig.split("\\."); + if (KUtil.getLen(split) == 2) { + propFrom = split[0].trim().toUpperCase(); + propName = split[1].trim(); + } + if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) { + res.append(propConfig); + continue; + } + TCComponent target; + if ("ITEM".equals(propFrom)) { + target = rev.getItem(); + } else if ("REV".equals(propFrom)) { + target = rev; + } else if ("ITEMMASTER".equals(propFrom)) { + target = rev.getItem().getRelatedComponent("IMAN_master_form"); + } else if ("REVMASTER".equals(propFrom)) { + target = rev.getRelatedComponent("IMAN_master_form_rev"); + } else { + throw new Exception(String.format(KLocale.getString("proplocationnotdefined.ERROR1"), propFrom)); + } + TCProperty prop = target.getTCProperty(propName.trim()); + if (prop == null) { + throw new Exception( + String.format(KLocale.getString("propnotdefinedintype.ERROR2"), target.getType(), propName)); + } + res.append(prop.getStringValue()); + } + return res.toString(); + } + + public static String getConfigPropDisplayableValue(TCComponentItemRevision rev, String propConfigStr) + throws Exception { + if (rev == null || KUtil.isEmpty(propConfigStr)) { + return ""; + } + StringBuilder res = new StringBuilder(); + String[] propConfigSplit = propConfigStr.split("\\+"); + int len = KUtil.getLen(propConfigSplit); + for (int i = 0; i < len; i++) { + String propConfig = propConfigSplit[i]; + String propFrom = null, propName = null; + String[] split = propConfig.split("\\."); + if (KUtil.getLen(split) == 2) { + propFrom = split[0].trim().toUpperCase(); + propName = split[1].trim(); + } + if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) { + res.append(propConfig); + continue; + } + TCComponent target; + if ("ITEM".equals(propFrom)) { + target = rev.getItem(); + } else if ("REV".equals(propFrom)) { + target = rev; + } else if ("ITEMMASTER".equals(propFrom)) { + target = rev.getItem().getRelatedComponent("IMAN_master_form"); + } else if ("REVMASTER".equals(propFrom)) { + target = rev.getRelatedComponent("IMAN_master_form_rev"); + } else { + throw new Exception(String.format(KLocale.getString("proplocationnotdefined.ERROR1"), propFrom)); + } + TCProperty prop = target.getTCProperty(propName.trim()); + if (prop == null) { + throw new Exception( + String.format(KLocale.getString("propnotdefinedintype.ERROR2"), target.getType(), propName)); + } + res.append(prop.getDisplayableValue()); + } + return res.toString(); + } + + public static void removeAllParents(DataManagementService dm, TCComponent comp) throws Exception { + comp.refresh(); + System.out.println("Remove from parent: " + comp); + WhereReferencedResponse refResp = dm.whereReferenced(new TCComponent[] { comp }, 1); + KUtil.throwServiceDataError(refResp.serviceData); + int len = KUtil.getLen(refResp.output); + List datas = new ArrayList(); + for (int i = 0; i < len; i++) { + WhereReferencedOutput ref = refResp.output[i]; + int cnt = KUtil.getLen(ref.info); + for (int j = 0; j < cnt; j++) { + WhereReferencedInfo info = ref.info[j]; + Relationship data = new Relationship(); + data.primaryObject = info.referencer; + data.secondaryObject = comp; + data.relationType = info.relation; + System.out.println(">> " + info.relation + " | " + info.referencer); + datas.add(data); + } + } + ServiceData resp = dm.deleteRelations(datas.toArray(new Relationship[] {})); + KUtil.throwServiceDataError(resp); + } + + public static TCComponent newTableRow(DataManagementService dmService, String type, + Map rowStringProps, Map rowDateProps) throws Exception { + CreateIn rowIn = new CreateIn(); + CreateInput rowInput = new CreateInput(); + rowInput.boName = type; + if (rowStringProps != null) { + rowInput.stringProps = rowStringProps; + } + if (rowDateProps != null) { + rowInput.dateProps = rowDateProps; + } + rowIn.data = rowInput; + CreateResponse res = dmService.createObjects(new CreateIn[] { rowIn }); + KUtil.throwServiceDataError(res.serviceData); + if (res.serviceData.sizeOfCreatedObjects() > 0) { + return res.serviceData.getCreatedObject(0); + } + return null; + } + + public static Date addDay(Date day, int cnt) { + if (day == null) { + return null; + } + Calendar c = Calendar.getInstance(); + c.setTime(day); + c.add(Calendar.DATE, cnt); + return c.getTime(); + } + + public static Date calTime(TCCalendar calendar, Date date, int minutes) { + if (calendar == null || date == null) { + return null; + } + int diff = minutes > 0 ? 1 : -1; + if (minutes < 0) { + minutes = -minutes; + } + Calendar c = Calendar.getInstance(); + c.setTime(date); + int counter = 0; + while (counter < minutes) { + counter += calendar.getMinutesOnDay(c); + c.add(Calendar.DATE, diff); + } + return c.getTime(); + } + + public static int getMinutesBetween(TCCalendar calendar, Date start, Date end) { + if (calendar == null || start == null || end == null) { + return 0; + } + Calendar c = Calendar.getInstance(); + c.setTime(start); + int res = 0; + while (c.getTime().before(end)) { + res += calendar.getMinutesOnDay(c); + // System.out.println(calendar.getMinutesOnDay(c)+" > "+c.getTime()); + c.add(Calendar.DATE, 1); + } + return res; + } + + public static TCComponentTCCalendar getScheduleCalendar(TCComponentSchedule schedule) throws Exception { + if (schedule == null) { + return null; + } + return CalendarHelper.getScheduleCalendar(schedule, session); + } + + public static void dealSpecialModelValue(ArrayList specialList, String prefName, String prop, int ind) { + int index = 0; + + try { + String[] prefVals = KUtil.getPrefVals(session, prefName); + String puid = prefVals[ind]; + TCComponent component = session.stringToComponent(puid); + if (component instanceof TCComponentForm) { + + TCComponentForm form = (TCComponentForm) component; + + TCComponent[] tables = form.getReferenceListProperty("ld6_ChangeTable"); + for (int j = 0; j < tables.length; j++) { + + String change = tables[j].getStringProperty(prop); + if (change.equals("")) { + specialList.add(j); + } + } + + } + + // + // Set>> entrySet = map.entrySet(); + // for (Entry> entry : entrySet) { + // ArrayList list = entry.getValue(); + // String value = list.get(2); + // System.out.println("ǰֵΪ" + value); + // if(value != null && value.equals("")) { + // specialList.add(index); + // } + // index++; + // } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + /** + * õģֵ + * + * @param map + * @throws Exception + */ + // public static void getModelVale(LinkedHashMap> map,String prefName,int index) throws Exception { + // AbstractAIFApplication application = AIFUtility.getCurrentApplication(); + // TCSession session = (TCSession) application.getSession(); + // String[] prefVals = KUtil.getPrefVals(session, prefName); + // String puid = prefVals[index]; + // TCComponentDataset component = (TCComponentDataset) session.stringToComponent(puid); + // TCComponentTcFile[] tcFiles = component.getTcFiles(); + // File datasetFile = null; + // String name = ""; + // if (tcFiles != null && tcFiles.length != 0) { + // TCComponentTcFile tcComponentTcFile = tcFiles[0]; + // File fmsFile = tcComponentTcFile.getFmsFile(); + // name = tcComponentTcFile.getStringProperty("original_file_name"); + // datasetFile = new File(System.getenv("TEMP")+"\\"+name); + // FileUtility.copyFile(fmsFile, datasetFile); + // + // } + // XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(datasetFile)); + // XSSFSheet sheet = wb.getSheetAt(0); + // for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) { + // XSSFRow row = sheet.getRow(i); + // for (int j = 0; j < 5; j++) { + // XSSFCell cell = row.getCell(j); + // if(cell != null) { + // String cellValue = KUtil.getCellValue(cell); + // if(j == 0 && cellValue.isEmpty()) { + // break; + // } + // if(j == 0 ) { + // if(map.containsKey(cellValue)) { + // break; + // }else { + // map.put(cellValue, null); + // } + // }else { + // String key = KUtil.getCellValue(row.getCell(0)); + // ArrayList arrayList = map.get(key); + // if(arrayList != null) { + // arrayList.add(cellValue); + // }else { + // ArrayList list = new ArrayList(); + // list.add(cellValue); + // map.put(key, list); + // } + // } + // + // } + // } + // } + // wb.close(); + // datasetFile.delete(); + // } + /** + * õģֵ + * + * @param map + * @throws Exception + */ + public static void getModelVale(LinkedHashMap> map, TCComponent forms, + ArrayList specialList, String[] propNames) throws Exception { + // AbstractAIFApplication application = AIFUtility.getCurrentApplication(); + // TCSession session = (TCSession) application.getSession(); + // String[] prefVals = KUtil.getPrefVals(session, prefName); + // String puid = prefVals[index]; + // TCComponent component = session.stringToComponent(puid); + int t = 1; + if (forms instanceof TCComponentForm) { + + TCComponentForm form = (TCComponentForm) forms; + TCComponent[] tables = form.getReferenceListProperty("ld6_ChangeTable"); + for (int j = 0; j < tables.length; j++) { + ArrayList tableValue = new ArrayList(); + + for (String propName : propNames) { + System.out.println("ǰΪ" + propName); + String prop = tables[j].getTCProperty(propName).getDisplayableValue(); + if (propName.equals("ld6_YNChange") && prop.equals("")) { + // specialList.add(j); + } + tableValue.add(prop == null ? "" : prop.trim()); + } + + map.put(String.valueOf(t), tableValue); + // tableValue + + t = t + 1; + } + + } + + } + + /** + * õlovʵֵʾֵ + * + * @param lovMap + * @param comboBox + * @throws TCException + */ + public static void getLov(HashMap lovMap, String lovName, JComboBox comboBox) + throws TCException { +// if (comboBox != null) { +// comboBox.addItem(""); +// } + // for (LovValue lovV : lovValueList) { + // map.put(lovV.getDisplayValue(), lovV.getStringValue()); + // comboBox.addItem(lovV.getDisplayValue()); + // System.out.println(lovV.getDisplayValue() + "===" + lovV.getStringValue()); + // } + + TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(lovName); + if ("Fnd0ListOfValuesDynamic".equals(lov.getProperty("lov_type"))) { + System.out.println("̬lovName=" + lovName); + LOVService lovService = LOVService.getService(RACUIUtil.getTCSession()); + InitialLovData input = new InitialLovData(); + LovFilterData filter = new LovFilterData(); + if ("LD6_TecDoc_TypeLOV".equals(lovName)) { + filter.sortPropertyName = "fnd0StringValues"; // lovĺֵ̨ + } else { + filter.sortPropertyName = "object_name"; // lovĺֵ̨ + } + + filter.order = 1; + filter.numberToReturn = 2000; + filter.maxResults = 2000; + + input.lov = lov; + input.filterData = filter; + LOVSearchResults result = lovService.getInitialLOVValues(input); + // System.out.println("111==="+result.toString()); + + for (LOVValueRow row : result.lovValues) { + Map map = row.propDisplayValues; + Map realmap = row.propInternalValues; + // for (String key : map.keySet()) { + // System.out.println("key=" + key + ",value=" + map.get(key)[0]); + // } + // for (String key : realmap.keySet()) { + // System.out.println("key2=" + key + ",value2=" + map.get(key)[0]); + // } + String disval = ""; + String val = ""; + String key1 = "object_name";// ʵֵ ʾֵһ + if ("LD6_TecDoc_TypeLOV".equals(lovName)) { + key1 = "fnd0StringValues"; // lovĺֵ̨ + } + // String key2 = "object_desc";// ʾֵڶ + if (map.containsKey(key1)) { + val = realmap.get(key1)[0]; + disval = map.get(key1)[0]; + } + if (!val.equals("")) { + lovMap.put(disval, val); + if (comboBox != null) { + comboBox.addItem(disval); + } + } + + } + + } else { + ListOfValuesInfo info = lov.getListOfValues(); + info.getLOVDisplayValues(); + List lovValueList = info.getValues(); + for (LovValue lovV : lovValueList) { + lovMap.put(lovV.getDisplayValue(), lovV.getStringValue()); + if (comboBox != null) { + comboBox.addItem(lovV.getDisplayValue()); + } + } + } + + } + + public static void dealPref(String[] prefVals, InterfaceAIFComponent targetComponent, + ArrayList beanList, StringBuffer newTypeBuffer) throws Exception { + /** + * LD6_PRRevision/LD6_CR|*[string]Item.item_id=; + * *[string]Item.object_name=;*[string]Rev.ld6_processNum=;*[string]Rev.ld6_productNum=Rev.ld6_proNum + */ + String type = targetComponent.getType(); + TCComponentItemRevision rev = (TCComponentItemRevision) targetComponent; + for (String string : prefVals) { + String[] split = string.split("\\|"); + if (split.length == 2) { + String[] split2 = split[0].split("/"); + if (split2.length == 2 && type.equals(split2[0])) { + // õ + newTypeBuffer.append(split2[1]); + // õĿؼ + String[] split3 = split[1].split(";"); + for (int i = 0; i < split3.length; i++) { + ControlBean bean = new ControlBean(); + if (split3[i].contains("*[")) { + bean.setIfMust(true); + } + String[] split4 = split3[i].split("="); + // жʲô͵ + if (split4[0].contains("boolean")) { + bean.setPropType("boolean"); + } else if (split4[0].contains("date")) { + bean.setPropType("date"); + } else if (split4[0].contains("string:")) { + bean.setPropType("lov"); + } else if (split4[0].contains("string") && !split4[0].contains("string:")) { + bean.setPropType("string"); + } + if (split4.length == 2) { + bean.setDefaultValue(getTCPropertyValue(rev, split4[1], bean)); + } + String[] split5 = split4[0].split("]"); + if (split5.length == 2) { + String[] split6 = split5[1].split("\\."); + bean.setPropTo(split6[0]); + bean.setPropRelName(split6[1]); + bean.setPropName(split6[2]); + if ("lov".equals(bean.getPropType())) { + // õlovlovMap + String[] split7 = split5[0].split(":"); + String lovName = split7[1]; + HashMap lovMap = new LinkedHashMap(); + JComboBox combox = new JComboBox(); + if (split4.length == 2) { + combox.addItem(getTCPropertyDisplayValue(rev, split4[1], bean)); + }else { + combox.addItem(""); + } + try { + String desType = newTypeBuffer.toString(); + if ("Rev".equals(bean.getPropTo())) { + desType = desType + "Revision"; + } else if ("Form".equals(bean.getPropTo())) { + desType = desType + "Revision Master"; + } + System.out.println("desType======"+desType); + System.out.println("bean.getPropRelName()======"+bean.getPropRelName()); + TCComponentType localTCComponentType = session.getTypeComponent(desType); + System.out.println("localTCComponentType======"+localTCComponentType); + TCPropertyDescriptor descriptor = localTCComponentType + .getPropertyDescriptor(bean.getPropRelName()); + // LOVDisplayer combo = new LOVDisplayer(descriptor); + getLov(lovMap, lovName, combox); + // bean.setCombox(combo); + } catch (TCException e) { + e.printStackTrace(); + } + bean.setLovMap(lovMap); + bean.setCombox(combox); + } + } + beanList.add(bean); + } + break; + } + } + } + } + + public static String getTCPropertyValue(TCComponentItemRevision rev, String specialValue, ControlBean bean) { + try { + String[] split = specialValue.split("\\."); + TCComponent center = null; + if (split.length == 2 || split.length == 3) { + switch (split[0]) { + case "Rev": + center = rev; + break; + case "Item": + center = rev.getItem(); + break; + case "Form": + center = rev.getRelatedComponent("IMAN_master_form_rev"); + break; + default: + break; + } + String value = ""; + if ("date".equals(bean.getPropType())) { + System.out.println("ǰʵΪ" + split[1]); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd HH:mm"); + if (center.getDateProperty(split[1]) != null) { + value = sdf.format(center.getDateProperty(split[1])); + } + } else { + value = center.getStringProperty(split[1]); + } + if (split.length == 3) { + bean.setPropName(split[2]); + } + return value; + } + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + public static String getTCPropertyDisplayValue(TCComponentItemRevision rev, String specialValue, ControlBean bean) { + try { + String[] split = specialValue.split("\\."); + TCComponent center = null; + if (split.length == 2 || split.length == 3) { + switch (split[0]) { + case "Rev": + center = rev; + break; + case "Item": + center = rev.getItem(); + break; + case "Form": + center = rev.getRelatedComponent("IMAN_master_form_rev"); + break; + default: + break; + } + String value = ""; + if ("date".equals(bean.getPropType())) { + System.out.println("ǰʵΪ" + split[1]); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd HH:mm"); + if (center.getDateProperty(split[1]) != null) { + value = sdf.format(center.getDateProperty(split[1])); + } + } else { + value = center.getProperty(split[1]); + } + if (split.length == 3) { + bean.setPropName(split[2]); + } + return value; + } + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } +} diff --git a/src/com/connor/plm/ProgressBar.java b/src/com/connor/plm/ProgressBar.java new file mode 100644 index 0000000..1827f94 --- /dev/null +++ b/src/com/connor/plm/ProgressBar.java @@ -0,0 +1,130 @@ +package com.connor.plm; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.KeyStroke; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AbstractAIFDialog; + +@SuppressWarnings("serial") +public class ProgressBar extends AbstractAIFDialog { + + private JLabel messageLabel; + + private JProgressBar progressBar; + + private boolean showBar = false; + + public ProgressBar(AIFDesktop aifDesktop, Dimension dim, boolean showBar) { + super(aifDesktop, false); + this.showBar = showBar; + initUI(dim); + } + + public ProgressBar(AbstractAIFDialog pd, Dimension dimension) { + super(pd, false); + initUI(dimension); + } + + public ProgressBar(Dimension dim, boolean showBar) { + super(false); + this.showBar = showBar; + initUI(dim); + } + + public ProgressBar(AbstractAIFDialog pd, Dimension dimension, boolean showBar) { + super(pd, false); + this.showBar = showBar; + initUI(dimension); + } + + private void initUI(Dimension dim) { + this.setLayout(new BorderLayout(0, 0)); + this.setUndecorated(true); + JPanel main = new JPanel(new GridBagLayout()); + GridBagConstraints s = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2, 5, 2, 5), 0, 0); + main.setBackground(new Color(53, 53, 53)); + if (dim != null) { + this.setPreferredSize(dim); + } else { + this.setPreferredSize(new Dimension(200, 40)); + } + messageLabel = new JLabel(" "); + messageLabel.setForeground(Color.white); + progressBar = new JProgressBar(); + progressBar.setForeground(Color.black); + main.add(messageLabel, s); + s.gridy++; + s.insets = new Insets(0, 5, 2, 5); + if (showBar) { + main.add(progressBar, s); + } + this.add(BorderLayout.CENTER, main); + KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + this.getRootPane().registerKeyboardAction(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + disposeDialog(); + } + }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); + MouseAdapter ma = new MouseAdapter() { + private Point pressPoint = new Point(); + + @Override + public void mousePressed(MouseEvent e) { + pressPoint = e.getPoint(); + } + + @Override + public void mouseReleased(MouseEvent e) { + pressPoint = new Point(); + } + + @Override + public void mouseDragged(MouseEvent e) { + Rectangle r = ProgressBar.this.getBounds(); + setLocation(r.x + (e.getX() - pressPoint.x), r.y + (e.getY() - pressPoint.y)); + } + }; + this.addMouseListener(ma); + this.addMouseMotionListener(ma); + } + + public void setText(String message) { + // System.out.println(message); + messageLabel.setText(message); + } + + public void setText(String txt, int percent) { + setText(txt); + if (percent > progressBar.getMaximum()) { + percent = progressBar.getMaximum(); + } + progressBar.setValue(percent); + } + + public void cancel() { + disposeDialog(); + } + + public void startProgress() { + showDialog(); + } +} \ No newline at end of file diff --git a/src/com/connor/plm/k_locale.properties b/src/com/connor/plm/k_locale.properties new file mode 100644 index 0000000..ac8931f --- /dev/null +++ b/src/com/connor/plm/k_locale.properties @@ -0,0 +1,58 @@ +# +#Thu Jan 21 10:28:16 CST 2021 +createscheduledeliverable.ERROR2=\u4E3A [%s] \u521B\u5EFA\u65F6\u95F4\u8868\u4EA4\u4ED8\u7269 [%s] \u5931\u8D25 +project=Project +dsuidinpref.ERROR1=Error dataset uid set in preference\: %s +valuenotinlov.ERROR2=LOV "%s" does not contain value\: %s +writedata=Write Data +querynotexist.ERROR1=Query not exist\: %s +dialoginit.ERROR=Init Error +preferror.ERROR1=Preference error\: %s +norefindataset.ERROR1=Download file from dataset "%s" failed. No ref file. +cancel=Cancel +exeop.STATUS=Execute... +initop.STATUS=Checking Data... +noflowkey.ERROR=Missing key for flow number. +wordfield_pagecount.NAME=\u9875\u6570 +nopropintype.ERROR2=Property is not defined in type "%s"\: %s. +getflowno.ERROR1=Error getting new flow number for key\: %s +formsave.ERRORTITLE=Error Saving Data +wordfield_pageno.NAME=\u9875\u7801 +wordfield_totalpagenominus1.NAME=\u603B\u9875\u7801\u51CF\u4E00 +wordfield_totalpagecount.NAME=\u603B\u9875\u6570 +exceltitlenorelateinfo.ERROR=Title row in sheet does not have any relation info. +selectProject=Select Project +proplocationnotdefined.ERROR1=\u672A\u77E5\u5C5E\u6027\u4F4D\u7F6E\u201C%s\u201D\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E +excelnotitle.ERROR=Can't find title row in excel sheet. +loadCompFromUid.Error2=Error loading component "%s", UID \= "%s". +uploadfilewhencheckout.ERROR1=Dataset "%s" is checked out. Upload file failed. +wordfield_totalactualpagecountminus1.NAME=\u603B\u5B9E\u9645\u9875\u6570\u51CF\u4E00 +nodatainfile.ERROR1=No Data in File\: %s +noexportdata.ERROR=\u6CA1\u6709\u6570\u636E\u53EF\u4EE5\u5BFC\u51FA +notscheduleadmin.INFO=\u53EA\u6709\u534F\u8C03\u8005\u624D\u80FD\u64CD\u4F5C +error=Error +mergefile=Merge File... +index=Index +forminit.ERRORTITLE=Error Loading Rendering +ok=OK +wordfield_totalactualpagecount.NAME=\u603B\u5B9E\u9645\u9875\u6570 +requireprop.INFO1=\u8BF7\u586B\u5199\u5C5E\u6027\uFF1A%s +functionnotavailable.INFO=\u6B64\u5BF9\u8C61\u4E0D\u53EF\u4F7F\u7528\u6B64\u529F\u80FD +multiuserbyid.ERROR1=Find multiple users by id\: %s +preparedata=Prepare Data +dbconn.ERROR=Connect to database failed. +typenotfound.ERROR1=Type not found\: %s +filenotexist.ERROR1=File not exist\: %s +wordfield_totalpagecountminus1.NAME=\u603B\u9875\u6570\u51CF\u4E00 +readdata=Read Data +clearcache=Clear Cache +exportsuccess.INFO=Export Complete. +uploadfile=Upload File +propnotdefinedintype.ERROR2=\u5BF9\u8C61\u7C7B\u578B\u201C%s\u201D\u672A\u5B9A\u4E49\u5C5E\u6027\uFF1A%s +foldernotexist.ERROR1=Folder not exist\: %s +info=Info +wordfield_totalpageno.NAME=\u603B\u9875\u7801 +multiuserbyname.ERROR1=Find multiple users by name\: %s +exportopenfile.INFO=Export complete. Open file? +prefnotconfiged.ERROR1=Prefernce not found\: %s +export=Export diff --git a/src/com/connor/plm/k_locale_zh_CN.properties b/src/com/connor/plm/k_locale_zh_CN.properties new file mode 100644 index 0000000..902d489 --- /dev/null +++ b/src/com/connor/plm/k_locale_zh_CN.properties @@ -0,0 +1,58 @@ +# +#Thu Jan 21 10:28:16 CST 2021 +createscheduledeliverable.ERROR2=\u4E3A [%s] \u521B\u5EFA\u65F6\u95F4\u8868\u4EA4\u4ED8\u7269 [%s] \u5931\u8D25 +project=\u9879\u76EE +dsuidinpref.ERROR1=\u8BF7\u68C0\u67E5\u9996\u9009\u9879<%s>\uFF0C\u901A\u8FC7\u914D\u7F6EUID\u672A\u627E\u5230\u6570\u636E\u96C6 +valuenotinlov.ERROR2=LOV "%s" \u4E2D\u672A\u5B9A\u4E49\u6570\u503C\uFF1A%s +writedata=\u5199\u5165\u6570\u636E +querynotexist.ERROR1=\u67E5\u8BE2\u4E0D\u5B58\u5728\uFF1A%s +dialoginit.ERROR=\u521D\u59CB\u5316\u5F02\u5E38 +preferror.ERROR1=\u9996\u9009\u9879\u914D\u7F6E\u9519\u8BEF\uFF1A%s +norefindataset.ERROR1=\u4ECE\u6570\u636E\u96C6\u201C%s\u201D\u4E0B\u8F7D\u6587\u4EF6\u5931\u8D25\uFF0C\u6CA1\u6709\u627E\u5230\u5F15\u7528\u6587\u4EF6\u3002 +cancel=\u53D6\u6D88 +exeop.STATUS=\u6B63\u5728\u6267\u884C... +initop.STATUS=\u68C0\u67E5\u6570\u636E... +noflowkey.ERROR=\u6D41\u6C34\u7801\u952E\u503C\u4E0D\u53EF\u4E3A\u7A7A +wordfield_pagecount.NAME=\u9875\u6570 +nopropintype.ERROR2=\u5BF9\u8C61\u7C7B\u578B\u201C%s\u201D\u4E0D\u5B58\u5728\u5C5E\u6027\uFF1A%s +getflowno.ERROR1=\u83B7\u53D6\u6D41\u6C34\u7801\u5931\u8D25\uFF1A%s +formsave.ERRORTITLE=\u4FDD\u5B58\u6570\u636E\u51FA\u9519 +wordfield_pageno.NAME=\u9875\u7801 +wordfield_totalpagenominus1.NAME=\u603B\u9875\u7801\u51CF\u4E00 +wordfield_totalpagecount.NAME=\u603B\u9875\u6570 +exceltitlenorelateinfo.ERROR=\u6807\u9898\u884C\u6CA1\u6709\u89E3\u6790\u5230\u6620\u5C04\u5185\u5BB9 +selectProject=\u9009\u62E9\u9879\u76EE +proplocationnotdefined.ERROR1=\u672A\u77E5\u5C5E\u6027\u4F4D\u7F6E\u201C%s\u201D\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E +excelnotitle.ERROR=\u672A\u627E\u5230\u5DE5\u4F5C\u8868\u4E2D\u7684\u6807\u9898\u884C +loadCompFromUid.Error2=\u52A0\u8F7D\u5BF9\u8C61\u201C%s\u201D\u5931\u8D25\uFF0CUID\=\u201C%s\u201D\u3002 +uploadfilewhencheckout.ERROR1=\u6570\u636E\u96C6\u201C%s\u201D\u5DF2\u7B7E\u51FA\uFF0C\u4E0A\u4F20\u6587\u4EF6\u5931\u8D25\u3002\u8BF7\u7B7E\u5165\u540E\u518D\u8FDB\u884C\u64CD\u4F5C\u3002 +wordfield_totalactualpagecountminus1.NAME=\u603B\u5B9E\u9645\u9875\u6570\u51CF\u4E00 +nodatainfile.ERROR1=\u6587\u4EF6\u4E2D\u6CA1\u6709\u6570\u636E\uFF1A%s +noexportdata.ERROR=\u6CA1\u6709\u6570\u636E\u53EF\u4EE5\u5BFC\u51FA +notscheduleadmin.INFO=\u53EA\u6709\u534F\u8C03\u8005\u624D\u80FD\u64CD\u4F5C +error=\u9519\u8BEF +mergefile=\u5408\u5E76\u6587\u4EF6 +index=\u5E8F\u53F7 +forminit.ERRORTITLE=\u521D\u59CB\u5316\u754C\u9762\u5F02\u5E38 +ok=\u786E\u5B9A +wordfield_totalactualpagecount.NAME=\u603B\u5B9E\u9645\u9875\u6570 +requireprop.INFO1=\u8BF7\u586B\u5199\u5C5E\u6027\uFF1A%s +functionnotavailable.INFO=\u6B64\u5BF9\u8C61\u4E0D\u53EF\u4F7F\u7528\u6B64\u529F\u80FD +multiuserbyid.ERROR1=\u901A\u8FC7id\u67E5\u8BE2\u5230\u591A\u4E2A\u7528\u6237\uFF1A%s +preparedata=\u51C6\u5907\u6570\u636E +dbconn.ERROR=\u8FDE\u63A5\u6570\u636E\u5E93\u5931\u8D25\u3002 +typenotfound.ERROR1=\u672A\u627E\u5230\u7C7B\u578B\uFF1A%s +filenotexist.ERROR1=\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A%s +wordfield_totalpagecountminus1.NAME=\u603B\u9875\u6570\u51CF\u4E00 +readdata=\u8BFB\u53D6\u6570\u636E +clearcache=\u6E05\u7406\u7F13\u5B58 +exportsuccess.INFO=\u5BFC\u51FA\u5B8C\u6210 +uploadfile=\u4E0A\u4F20\u6587\u4EF6 +propnotdefinedintype.ERROR2=\u5BF9\u8C61\u7C7B\u578B\u201C%s\u201D\u672A\u5B9A\u4E49\u5C5E\u6027\uFF1A%s +foldernotexist.ERROR1=\u6587\u4EF6\u5939\u4E0D\u5B58\u5728\uFF1A%s +info=\u63D0\u793A +wordfield_totalpageno.NAME=\u603B\u9875\u7801 +multiuserbyname.ERROR1=\u901A\u8FC7\u59D3\u540D\u67E5\u8BE2\u5230\u591A\u4E2A\u7528\u6237\uFF1A%s +exportopenfile.INFO=\u5BFC\u51FA\u5B8C\u6210\uFF0C\u6253\u5F00\u6587\u4EF6\uFF1F +prefnotconfiged.ERROR1=\u672A\u914D\u7F6E\u9996\u9009\u9879\uFF1A%s +export=\u5BFC\u51FA diff --git a/src/com/connor/plm/sample/DatasetSaveAsHandler.java b/src/com/connor/plm/sample/DatasetSaveAsHandler.java new file mode 100644 index 0000000..eb83f98 --- /dev/null +++ b/src/com/connor/plm/sample/DatasetSaveAsHandler.java @@ -0,0 +1,47 @@ +package com.connor.plm.sample; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +/** + * : ʵʩƻ + * :2024-08-04 + * @author + * + * ޸ ޸ ޸ + * + */ +public class DatasetSaveAsHandler extends AbstractHandler{ + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + AbstractAIFUIApplication app = AIFUtility.getCurrentApplication(); + InterfaceAIFComponent targetComp = app.getTargetComponent(); + TCSession session = (TCSession) app.getSession(); + if(targetComp != null){ + if(targetComp instanceof TCComponentDataset){ + TCComponentDataset targetDataset = (TCComponentDataset)targetComp; + DatasetSaveAsOperation operation = new DatasetSaveAsOperation(app,targetDataset); + session.queueOperation(operation); + return null; + }else{ + MessageBox.post(PlmLocale.getString("selectDataset"), + PlmLocale.getString("warn"), + MessageBox.INFORMATION); + return null; + } + }else{ + MessageBox.post(PlmLocale.getString("selectDataset"), + PlmLocale.getString("warn"), + MessageBox.INFORMATION); + } + return null; + } +} diff --git a/src/com/connor/plm/sample/DatasetSaveAsOperation.java b/src/com/connor/plm/sample/DatasetSaveAsOperation.java new file mode 100644 index 0000000..0912955 --- /dev/null +++ b/src/com/connor/plm/sample/DatasetSaveAsOperation.java @@ -0,0 +1,170 @@ +package com.connor.plm.sample; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.io.FileUtils; + +import com.connor.plm.KUtil; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +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.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetType; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.services.rac.workflow.WorkflowService; +import com.teamcenter.services.rac.workflow._2008_06.Workflow.ContextData; +import com.teamcenter.services.rac.workflow._2008_06.Workflow.InstanceInfo; +/** + * : Ʒͼ޶ + * :2019-02-26 + * @author + * + * ޸ ޸ ޸ + * 2019-01-24 XXXX + */ +public class DatasetSaveAsOperation extends AbstractAIFOperation{ + + private AbstractAIFUIApplication app; + private TCComponentDataset targetComp; + private static final String SPEC_RELATION_TYPE = "IMAN_specification"; + private static final String preName = "Connor_dataset_ref"; + private TCSession session; + + public DatasetSaveAsOperation(AbstractAIFUIApplication app, + TCComponentDataset targetComp) { + this.app = app; + this.targetComp = targetComp; + session = (TCSession) app.getSession(); + } + /** + * + * Դݼµݼ + * @return ´ݼ + */ + private TCComponentDataset createDataset() { + TCComponentDataset newDataset = null; + String[] path = new String[1]; + String[] refType = new String[1]; + try { + String type = targetComp.getType(); + Map refMap = new HashMap(); + String[] prefVals = KUtil.getPrefVals(session, preName); + for (int i = 0; i < prefVals.length; i++) { + if(prefVals[i].contains("=")) { + String[] split = prefVals[i].split("="); + refMap.put(split[0], split[1]); + } + } + if(refMap.containsKey(type)) { + refType[0] = refMap.get(type); + }else { + MessageBox.post("δҵӦݼ"+type+"ãϵԱ", + PlmLocale.getString("err"), + MessageBox.INFORMATION); + return null; + } + String datasetName = targetComp.getStringProperty("object_name"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String timestamp = sdf.format(new Date()); + String objectName = ""; + if(datasetName.contains(".")) { + String[] split = datasetName.split("\\."); + objectName = split[0] + timestamp + "." + split[1]; + }else { + objectName = datasetName + timestamp; + } + + File[] files = targetComp.getFiles(""); + TCComponentDatasetType datasetType = (TCComponentDatasetType) session.getTypeComponent("Dataset"); + //ݼ + newDataset = datasetType.create(objectName, "", type); + //ϴļ + if(newDataset != null) { + String oldPath = files[0].getAbsolutePath(); + if(oldPath.contains(".")) { + String[] split = oldPath.split("\\."); + String newPath = split[0] + timestamp + "." + split[1]; + FileUtils.copyFile(new File(oldPath), new File(newPath)); + path[0] = newPath; + newDataset.setFiles(path, refType); + } + }else { + return newDataset; + } + + } catch (Exception e) { + e.printStackTrace(); + } + return newDataset; + } + + @Override + public void executeOperation() throws Exception { + try { + //ȡĿݼİ汾 + AIFComponentContext[] whereReferenced = targetComp.whereReferenced(); + InterfaceAIFComponent comp = whereReferenced[0].getComponent(); + if(comp instanceof TCComponentItemRevision) { + TCComponentItemRevision rev = (TCComponentItemRevision) comp; + TCComponentDataset tempDataset = createDataset(); + if(tempDataset != null) { + //ݼϷ״̬ + workflow(new String[] {tempDataset.getUid()},"ٷ","TCM Release Process"); + //ӹϵ + rev.add(SPEC_RELATION_TYPE,tempDataset); + MessageBox.post(PlmLocale.getString("revisedSuccessful"), + PlmLocale.getString("ok"), + MessageBox.INFORMATION); + }else { + MessageBox.post(PlmLocale.getString("revisionFailed"), + PlmLocale.getString("err"), + MessageBox.ERROR); + } + + } + } catch (TCException e) { + e.printStackTrace(); + MessageBox.post(PlmLocale.getString("revisionFailed"), + PlmLocale.getString("err"), + MessageBox.ERROR); + } + + } + /** + * + * ½ݼϷ״̬ + */ + public void workflow(String[] uid,String workFlowName,String templateName) { + // String uid = rev.getUid(); + // + WorkflowService wfService = WorkflowService.getService(session); + ContextData contextData = new ContextData(); + String observerKey = ""; + String name = workFlowName; + String subject = ""; + String description = ""; + contextData.processTemplate = templateName; // update with your own ProcessTemplate. + contextData.subscribeToEvents = false; + contextData.subscriptionEventCount = 0; + contextData.attachmentCount = uid.length; + contextData.attachments = uid ; + int [] types = new int[uid.length]; + for(int i = 0;i nameMap = new HashMap();//ݼƺͶ(item,rev,revMaster) + if(prefVals.length >= 2) { + for (int i = 1; i < prefVals.length; i++) { + //Item.object_name=object_name + String[] split = prefVals[i].split("\\|"); + if(!split[0].equals(revType)) { + continue; + } + String[] split1 = split[1].split("="); + nameMap.put(split1[1],split1[0]); + } + } + for (TCComponent tcComponent : relatedComponents) { + if (tcComponent instanceof TCComponentDataset) { + TCComponentDataset dataset = (TCComponentDataset) tcComponent; + TCComponent[] comps = dataset.getRelatedComponents("release_status_list"); + if(comps != null && comps.length > 0) { + continue; + } + File datasetFile = KUtil.getDatasetFile(dataset); + String type = tcComponent.getType(); + String datasetType = ""; + String newPath = ""; + if("MSExcel".equals(type) || "MSExcelX".equals(type) || "MSWord".equals(type) || "MSWordX".equals(type)) { + switch (type) { + case "MSExcel": + datasetType = "excel"; + newPath = dealExcel(datasetFile,revision,nameMap); + break; + case "MSExcelX": + datasetType = "excel"; + newPath = dealExcelX(datasetFile,revision,nameMap); + break; + case "MSWord": + datasetType = "word"; + newPath = dealWord2(datasetFile,revision,nameMap,"doc"); + break; + case "MSWordX": + datasetType = "word"; + newPath = dealWord2(datasetFile,revision,nameMap,"docx"); + break; + } + //ݼµ + dataset.setFiles(new String[] {newPath}, new String[] {datasetType}); + } + } + } + KUtil.info(AIFDesktop.getActiveDesktop(), "ȡ汾ԵWord Excelִ"); + return true; + } + + @Override + public void execute() throws Exception { + + } + + private String dealExcel(File datasetFile, TCComponentItemRevision revision, HashMap nameMap) throws IOException, TCException { + FileInputStream is = new FileInputStream(datasetFile); + HSSFWorkbook workbook = new HSSFWorkbook(is); + List allNames = workbook.getAllNames(); + for (HSSFName hssfName : allNames) { + String name = hssfName.getNameName(); + //ƹѡ + if (nameMap.containsKey(name)) { + CellReference cellReference = new CellReference(hssfName.getRefersToFormula()); + HSSFSheet sheet = workbook.getSheet(cellReference.getSheetName()); + HSSFRow row = sheet.getRow(cellReference.getRow()); + HSSFCell cell = row.getCell(cellReference.getCol()); + String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(name)); + if(preConfigValue.endsWith("00:00")) { + System.out.println("ʱʽ⴦"); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date date = dateFormat.parse(preConfigValue); + preConfigValue = dateFormat2.format(date); + } catch (ParseException e) { + e.printStackTrace(); + } + } + System.out.println("Ϊ" + cellReference.getRow() + "====" + "Ϊ" + cellReference.getCol() + "====" + + "ֵΪ " + preConfigValue); + if(cell == null) { + cell = row.createCell(cellReference.getCol()); + } + cell.setCellValue(preConfigValue); + + } + } + is.close(); + FileOutputStream os = new FileOutputStream(datasetFile); + workbook.write(os); + workbook.close(); + return datasetFile.getAbsolutePath(); + } + + private String dealExcelX(File datasetFile, TCComponentItemRevision revision, HashMap nameMap) throws IOException, TCException { + FileInputStream is = new FileInputStream(datasetFile); + XSSFWorkbook workbook = new XSSFWorkbook(is); + List allNames = workbook.getAllNames(); + for (XSSFName xssfName : allNames) { + String name = xssfName.getNameName(); + //ƹѡ + if (nameMap.containsKey(name)) { + CellReference cellReference = new CellReference(xssfName.getRefersToFormula()); + XSSFSheet sheet = workbook.getSheet(cellReference.getSheetName()); + XSSFRow row = sheet.getRow(cellReference.getRow()); + XSSFCell cell = row.getCell(cellReference.getCol()); + String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(name)); + if(preConfigValue.endsWith("00:00")) { + System.out.println("ʱʽ⴦"); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date date = dateFormat.parse(preConfigValue); + preConfigValue = dateFormat2.format(date); + } catch (ParseException e) { + e.printStackTrace(); + } + } + System.out.println("Ϊ" + cellReference.getRow() + "====" + "Ϊ" + cellReference.getCol() + "====" + + "ֵΪ " + preConfigValue); + if(cell == null) { + cell = row.createCell(cellReference.getCol()); + cell.setCellValue(preConfigValue); + } + else { + cell.setCellValue(preConfigValue); + } + } + } + is.close(); + FileOutputStream os = new FileOutputStream(datasetFile); + workbook.write(os); + workbook.close(); + return datasetFile.getAbsolutePath(); + } + + private String dealWord(File datasetFile, TCComponentItemRevision revision, HashMap nameMap,String type) throws IOException, TCException { + String path = datasetFile.getAbsolutePath(); + InputStream inputStream = Files.newInputStream(Paths.get(path)); + Map dataMap = new HashMap<>(); + for(String key : nameMap.keySet()) { + String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(key)); + if(preConfigValue.endsWith("00:00")) { + System.out.println("ʱʽ⴦"); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date date = dateFormat.parse(preConfigValue); + preConfigValue = dateFormat2.format(date); + } catch (ParseException e) { + e.printStackTrace(); + } + } + dataMap.put(key, preConfigValue); + } + String newPath = ""; + if(type.equals("doc")) { + newPath = path.replace(".doc", "temp.doc"); + WordUtils.replaceBookmarksByDoc(inputStream, Files.newOutputStream(Paths.get(newPath)), dataMap); + } + else if(type.equals("docx")) { + newPath = path.replace(".docx", "temp.docx"); + WordUtils.replaceBookmarksByDocx(inputStream, Files.newOutputStream(Paths.get(newPath)), dataMap); + } + return newPath; + } + + private String dealWord2(File datasetFile, TCComponentItemRevision revision, HashMap nameMap,String type) throws FileNotFoundException, Exception { + String path = datasetFile.getAbsolutePath(); + Document document2 = new Document(new FileInputStream(path)); + OutputStream outputStream = null; + String newPath = path.replace(".doc", "temp.doc"); + outputStream = new FileOutputStream(newPath); + Map dataMap = new HashMap<>(); + for(String key : nameMap.keySet()) { + String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(key)); + if(preConfigValue.endsWith("00:00")) { + System.out.println("ʱʽ⴦"); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date date = dateFormat.parse(preConfigValue); + preConfigValue = dateFormat2.format(date); + } catch (ParseException e) { + e.printStackTrace(); + } + } + dataMap.put(key, preConfigValue); + } + for (Bookmark bookmark : document2.getRange().getBookmarks()) { + String bookmarkName = bookmark.getName(); + System.out.println("ǩ"+bookmarkName); + if(dataMap.containsKey(bookmarkName)) + { + System.out.println(""); + bookmark.setText(dataMap.get(bookmarkName)); + } + } + if(type.equals("doc")) { + document2.save(outputStream, SaveFormat.DOC); + }else if(type.equals("docx")) { + document2.save(outputStream, SaveFormat.DOCX); + } + return newPath; + } + + /** + * õѡС=߶Ӧֵ + * @param revision + * @param nameMap + * @param value + * @return + * @throws TCException + */ + private String getPreConfigValue(TCComponentItemRevision revision, HashMap nameMap,String value) throws TCException { + String[] split = value.split("\\."); + String cellValue = ""; + TCProperty property = null; + if(split.length == 2) { + switch (split[0]) { + case "Item": + property = revision.getItem().getTCProperty(split[1]); + break; + case "Rev": + property = revision.getTCProperty(split[1]); + break; + case "RevMaster": + property = revision.getRelatedComponent("IMAN_master_form_rev").getTCProperty(split[1]); + break; + default: + break; + } + } + //ȡϵļµ + else if(split.length == 3) { + String relation = split[0]; + TCComponent relatedComponent = revision.getRelatedComponent(relation); + TCComponentItemRevision centerRev = null; + if(relatedComponent instanceof TCComponentItemRevision) { + centerRev = (TCComponentItemRevision) relatedComponent; + }else if(relatedComponent instanceof TCComponentItem) { + centerRev = ((TCComponentItem) relatedComponent).getLatestItemRevision(); + } + if(centerRev != null) { + switch (split[1]) { + case "Item": + property = centerRev.getItem().getTCProperty(split[2]); + break; + case "Rev": + property = centerRev.getTCProperty(split[2]); + break; + case "RevMaster": + property = centerRev.getRelatedComponent("IMAN_master_form_rev").getTCProperty(split[2]); + break; + default: + break; + } + } + } + if(property == null) { + return ""; + } + else { + cellValue = property.getDisplayValue(); + return cellValue; + } + } +} diff --git a/src/com/connor/plm/sb01/Test.java b/src/com/connor/plm/sb01/Test.java new file mode 100644 index 0000000..eaa4bdc --- /dev/null +++ b/src/com/connor/plm/sb01/Test.java @@ -0,0 +1,68 @@ +package com.connor.plm.sb01; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.poi.hssf.usermodel.HSSFName; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.util.CellReference; +import org.apache.poi.xssf.usermodel.XSSFName; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.aspose.words.Bookmark; +import com.aspose.words.Document; +import com.aspose.words.SaveFormat; + +public class Test { + public static void main(String[] args) { + try { +// FileInputStream is = new FileInputStream("C:\\Users\\Administrator\\Desktop\\ļ\\2.xls"); +// // ȡļ +// HSSFWorkbook workbook = new HSSFWorkbook(is); +// List allNames = workbook.getAllNames(); +// System.out.println("allNames = " + allNames); +// String cellReference = allNames.get(0).getRefersToFormula(); +// workbook.close(); +// is.close(); + +// FileInputStream is2 = new FileInputStream("C:\\Users\\Administrator\\Desktop\\ļ\\1.xlsx"); +// // ȡļ +// XSSFWorkbook workbook2 = new XSSFWorkbook(is2); +// List allNames2 = workbook2.getAllNames(); +// +// workbook2.close(); +// is2.close(); + + FileInputStream is = new FileInputStream("C:\\Users\\Administrator\\Desktop\\workexcel\\1.docx"); + // ȡļ + XSSFWorkbook workbook = new XSSFWorkbook(is); + File datasetFile = new File("C:\\Users\\Administrator\\Desktop\\workexcel\\1.docx"); + String path = datasetFile.getAbsolutePath(); + Document document2 = new Document(new FileInputStream(path)); + OutputStream outputStream = null; + String newPath = path.replace(".doc", "temp.doc"); + outputStream = new FileOutputStream(newPath); + Map dataMap = new HashMap<>(); + dataMap.put("one", "one"); + dataMap.put("two", "two"); + for (Bookmark bookmark : document2.getRange().getBookmarks()) { + String bookmarkName = bookmark.getName(); + System.out.println("ǩ"+bookmarkName); + if(dataMap.containsKey(bookmarkName)) + { + System.out.println(""); + bookmark.setText(dataMap.get(bookmarkName)); + } + } + document2.save(outputStream, SaveFormat.DOC); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/com/connor/plm/sb01/WordUtils.java b/src/com/connor/plm/sb01/WordUtils.java new file mode 100644 index 0000000..3c426e1 --- /dev/null +++ b/src/com/connor/plm/sb01/WordUtils.java @@ -0,0 +1,168 @@ +package com.connor.plm.sb01; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.usermodel.Bookmark; +import org.apache.poi.hwpf.usermodel.Bookmarks; +import org.apache.poi.hwpf.usermodel.Range; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.apache.poi.xwpf.usermodel.XWPFRun; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; +import org.w3c.dom.Node; + +public class WordUtils { + + public static final String RUN_NODE_NAME = "w:r"; + public static final String TEXT_NODE_NAME = "w:t"; + public static final String BOOKMARK_START_TAG = "w:bookmarkStart"; + public static final String BOOKMARK_END_TAG = "w:bookmarkEnd"; + public static final String BOOKMARK_ID_ATTR_NAME = "w:id"; + public static final String STYLE_NODE_NAME = "w:rPr"; + + public static void main(String[] args) throws IOException { + // 滻ļе bookmark + InputStream inputStream3 = Files.newInputStream(Paths.get("C:\\Users\\Administrator\\Desktop\\ļ\\22.doc")); + Map dataMap = new HashMap<>(); + dataMap.put("one", "oneoneoneoneone"); + dataMap.put("two", "twotwotwotwo"); + dataMap.put("three", "ceshi"); + replaceBookmarksByDoc(inputStream3, Files.newOutputStream(Paths.get("C:\\Users\\Administrator\\Desktop\\ļ\\33.doc")), dataMap); + } + + /** + * ȡ doc ļеǩ + * + * @param inputStream + * @throws IOException + */ + public static void getBookmarksByDoc(InputStream inputStream) throws IOException { + HWPFDocument wordDoc = new HWPFDocument(inputStream); + + Bookmarks bookmarks = wordDoc.getBookmarks(); + + for (int b = 0; b < bookmarks.getBookmarksCount(); b++) { + Bookmark bookmark = bookmarks.getBookmark(b); + String bookMarkText = new Range(bookmark.getStart(), bookmark.getEnd(), wordDoc).text(); + + System.out.println("[" + bookmark.getStart() + "; " + + bookmark.getEnd() + "]: " + bookmark.getName() + " = " + bookMarkText); + } + + } + + /** + * ȡ docx ļеǩ + * + * @param inputStream + * @throws IOException + */ + public static void getBookmarksByDocx(InputStream inputStream) throws IOException { + XWPFDocument docx = new XWPFDocument(inputStream); + + List paragraphList = docx.getParagraphs(); + for (XWPFParagraph xwpfParagraph : paragraphList) { + CTP ctp = xwpfParagraph.getCTP(); + + for (int dwI = 0; dwI < ctp.sizeOfBookmarkStartArray(); dwI++) { + CTBookmark bookmark = ctp.getBookmarkStartArray(dwI); + String bookmarkName = bookmark.getName(); + + // Ϊ docx Ľṹxmlʽ doc ĵоstartendֵλһbookmarkֵΧ + // Ҫȡ docx ĵbookmarkݣҪ bookmarkStart ڵ㿪ʼνxml + // nodeValue ֵƴӣֱȡһΪ bookmarkEnd ĽڵΪֹ + // getBookmarkTextContent() һûʵֵķҪʵ + // String bookmarkTextContent = getBookmarkTextContent(bookmark); + + System.out.println(bookmarkName); + } + } + } + + + /** + * docx ļǩ滻 + * + * @param inputStream + * @param outputStream + * @param dataMap + * @throws IOException + */ + public static void replaceBookmarksByDocx(InputStream inputStream, OutputStream outputStream, Map dataMap) throws IOException { + XWPFDocument document = new XWPFDocument(inputStream).getXWPFDocument(); + List paragraphList = document.getParagraphs(); + for (XWPFParagraph xwpfParagraph : paragraphList) { + CTP ctp = xwpfParagraph.getCTP(); + + for (int dwI = 0; dwI < ctp.sizeOfBookmarkStartArray(); dwI++) { + CTBookmark bookmark = ctp.getBookmarkStartArray(dwI); + if (dataMap.containsKey(bookmark.getName())) { + + XWPFRun run = xwpfParagraph.createRun(); + run.setText(dataMap.get(bookmark.getName())); + + Node firstNode = bookmark.getDomNode(); + Node nextNode = firstNode.getNextSibling(); + while (nextNode != null) { + // ѭҽ + String nodeName = nextNode.getNodeName(); + if (nodeName.equals(BOOKMARK_END_TAG)) { + break; + } + + // ɾмķǽڵ㣬ɾԭǩ + Node delNode = nextNode; + nextNode = nextNode.getNextSibling(); + + ctp.getDomNode().removeChild(delNode); + } + + if (nextNode == null) { + // ʼҲʶģǩǰ + ctp.getDomNode().insertBefore(run.getCTR().getDomNode(), firstNode); + } else { + // ҵӵ֮ǰдbookmarkм + ctp.getDomNode().insertBefore(run.getCTR().getDomNode(), nextNode); + } + } + } + } + + document.write(outputStream); + document.close(); + } + + + /** + * doc ļǩ滻 + * + * @param inputStream + * @param outputStream + * @param dataMap + * @throws IOException + */ + public static void replaceBookmarksByDoc(InputStream inputStream, OutputStream outputStream, + Map dataMap) throws IOException { + HWPFDocument document = new HWPFDocument(inputStream); + Bookmarks bookmarks = document.getBookmarks(); + for (int dwI = 0; dwI < bookmarks.getBookmarksCount(); dwI++) { + Bookmark bookmark = bookmarks.getBookmark(dwI); + if (dataMap.containsKey(bookmark.getName())) { + Range range = new Range(bookmark.getStart(), bookmark.getEnd(), document); + range.replaceText(dataMap.get(bookmark.getName()), false); + } + } + document.write(outputStream); + } +} + + diff --git a/src/com/connor/plm/sb02/ArrowIcon.java b/src/com/connor/plm/sb02/ArrowIcon.java new file mode 100644 index 0000000..5451d76 --- /dev/null +++ b/src/com/connor/plm/sb02/ArrowIcon.java @@ -0,0 +1,86 @@ +package com.connor.plm.sb02; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Polygon; +import java.util.Comparator; + +import javax.swing.Icon; +import javax.swing.RowSorter; +import javax.swing.RowSorter.SortKey; +import javax.swing.SortOrder; +import javax.swing.table.TableRowSorter; + +import antlr.collections.List; + +public class ArrowIcon implements Icon { + private final SortOrder sortOrder; + private final int size; + private final boolean ascending; + public ArrowIcon(TableRowSorter sorter, int column, boolean ascending) { + this.ascending = ascending; + this.size = 12; + java.util.List sortKeys = sorter.getSortKeys(); + if (sortKeys.size() > 0 && ((RowSorter.SortKey) sortKeys.get(0)).getColumn() == column) { + this.sortOrder = ((RowSorter.SortKey) sortKeys.get(0)).getSortOrder(); + } else { + this.sortOrder = SortOrder.ASCENDING; + } + } + public void paintIcon(Component c, Graphics g, int x, int y) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.translate(x, y); + if (ascending) { + g2.rotate(Math.PI, size / 2.0, size / 2.0); + } + if (sortOrder == SortOrder.ASCENDING) { + g2.draw(createUpTriangle(size)); + } else { + g2.draw(createDownTriangle(size)); + } + g2.dispose(); + } + public int getIconWidth() { + return size; + } + public int getIconHeight() { + return size; + } + private Polygon createUpTriangle(int size) { + Polygon triangle = new Polygon(); + triangle.addPoint(0, size); + triangle.addPoint(size / 2, 0); + triangle.addPoint(size, size); + return triangle; + } + private Polygon createDownTriangle(int size) { + Polygon triangle = new Polygon(); + triangle.addPoint(0, 0); + triangle.addPoint(size, 0); + triangle.addPoint(size / 2, size); + return triangle; + } +} +// +class ColumnSorter implements Comparator { + private final int col; + private final boolean ascending; + public ColumnSorter(int col, boolean ascending) { + this.col = col; + this.ascending = ascending; + } + @Override + public int compare(Object a, Object b) { + if (a instanceof Comparable && b instanceof Comparable) { + if (ascending) { + return ((Comparable) a).compareTo((Comparable) b); + } else { + return ((Comparable) b).compareTo((Comparable) a); + } + } else { + return 0; + } + } +} + diff --git a/src/com/connor/plm/sb02/ControlBean.java b/src/com/connor/plm/sb02/ControlBean.java new file mode 100644 index 0000000..cb4078e --- /dev/null +++ b/src/com/connor/plm/sb02/ControlBean.java @@ -0,0 +1,97 @@ +package com.connor.plm.sb02; + +import java.util.HashMap; + +import javax.swing.JComboBox; + +import com.teamcenter.rac.common.lov.view.components.LOVDisplayer; + +public class ControlBean { + private String propName; + private String propRelName; + private String defaultValue = ""; + private String propType; + private HashMap lovMap; + private String propTo; // дItem/Rev/Form + private JComboBox combox; + private boolean ifMust = false; + // private LOVDisplayer combox; + + // public LOVDisplayer getCombox() { + // return combox; + // } + // + // public void setCombox(LOVDisplayer combox) { + // this.combox = combox; + // } + + public boolean isIfMust() { + return ifMust; + } + + public void setIfMust(boolean ifMust) { + this.ifMust = ifMust; + } + + public JComboBox getCombox() { + return combox; + } + public void setCombox(JComboBox combox) { + this.combox = combox; + } + public String getPropTo() { + return propTo; + } + + public void setPropTo(String propTo) { + this.propTo = propTo; + } + + public HashMap getLovMap() { + return lovMap; + } + + public void setLovMap(HashMap lovMap) { + this.lovMap = lovMap; + } + + public String getPropName() { + return propName; + } + + public void setPropName(String propName) { + this.propName = propName; + } + + public String getPropRelName() { + return propRelName; + } + + public void setPropRelName(String propRelName) { + this.propRelName = propRelName; + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + public String getPropType() { + return propType; + } + + public void setPropType(String propType) { + this.propType = propType; + } + + @Override + public String toString() { + return "ControlBean [propName=" + propName + ", propRelName=" + propRelName + ", defaultValue=" + defaultValue + + ", propType=" + propType + ", lovMap=" + lovMap + ", propTo=" + propTo + ", ifMust=" + ifMust + + ", combox=" + combox + "]"; + } + +} diff --git a/src/com/connor/plm/sb02/DateTest.java b/src/com/connor/plm/sb02/DateTest.java new file mode 100644 index 0000000..5d5bdad --- /dev/null +++ b/src/com/connor/plm/sb02/DateTest.java @@ -0,0 +1,18 @@ +package com.connor.plm.sb02; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class DateTest { + public static void main(String[] args) { + String ssString = "sss.sss"; + String[] split = ssString.split("\\."); + System.out.println(split.length); + String takeeffect = ""; + DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-M-dd HH:mm"); + //LocalDateTime createDate = LocalDateTime.parse(create, fmt); + LocalDateTime takeeffectDate = LocalDateTime.parse(takeeffect, fmt); + + } + +} diff --git a/src/com/connor/plm/sb02/DerivedChangeNoticeCommand.java b/src/com/connor/plm/sb02/DerivedChangeNoticeCommand.java new file mode 100644 index 0000000..6231138 --- /dev/null +++ b/src/com/connor/plm/sb02/DerivedChangeNoticeCommand.java @@ -0,0 +1,54 @@ +package com.connor.plm.sb02; + +import java.util.ArrayList; + +import com.connor.plm.KCommand; +import com.connor.plm.KUtil; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + + +public class DerivedChangeNoticeCommand extends KCommand { + + public DerivedChangeNoticeCommand(AbstractAIFApplication app, String commandId, String actionInfo) { + super(app, commandId, actionInfo); + TCSession session = (TCSession) app.getSession(); + String preName = "Connor_Derive_CN"; + try { + String[] prefVals = KUtil.getPrefVals(session, preName); + InterfaceAIFComponent targetComponent = app.getTargetComponent(); + StringBuffer newType = new StringBuffer(); + if (prefVals == null) { + MessageBox.post(preName + "ѡδ", "ʾ", MessageBox.INFORMATION); + return; + } + ArrayList beanList = new ArrayList(); + KUtil.dealPref(prefVals, targetComponent, beanList, newType); + for (ControlBean bean : beanList) { + System.out.println("beanList" + bean.toString()); + } + if (newType.toString().isEmpty()) { + MessageBox.post(preName + "ѡ󣬲½Ķ", "ʾ", MessageBox.INFORMATION); + return; + } + if (beanList.size() == 0) { + MessageBox.post(preName + "ѡ󣬲ѡж͵", "ʾ", MessageBox.INFORMATION); + return; + } + // ⱨ +// if (targetComponent.getType().equals("ProblemReportRevision")) { + this.setRunnable(new DerivedChangeRequestDialog(app, beanList, newType, + (TCComponentItemRevision) targetComponent)); +// } + // new + // DerivedChangeRequestDialog(app,beanList,newType,(TCComponentItemRevision)targetComponent); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/com/connor/plm/sb02/DerivedChangeRequestCommand.java b/src/com/connor/plm/sb02/DerivedChangeRequestCommand.java new file mode 100644 index 0000000..6a79581 --- /dev/null +++ b/src/com/connor/plm/sb02/DerivedChangeRequestCommand.java @@ -0,0 +1,46 @@ +package com.connor.plm.sb02; + +import java.util.ArrayList; + +import com.connor.plm.KCommand; +import com.connor.plm.KUtil; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + + +public class DerivedChangeRequestCommand extends KCommand { + + public DerivedChangeRequestCommand(AbstractAIFApplication app, String commandId, String actionInfo) { + super(app, commandId, actionInfo); + TCSession session = (TCSession) app.getSession(); + String preName = "Connor_Derive_CR"; + try { + String[] prefVals = KUtil.getPrefVals(session, preName); + InterfaceAIFComponent targetComponent = app.getTargetComponent(); + StringBuffer newType = new StringBuffer(); + if (prefVals == null) { + MessageBox.post(preName + "ѡδ", "ʾ", MessageBox.INFORMATION); + return; + } + ArrayList beanList = new ArrayList(); + KUtil.dealPref(prefVals, targetComponent, beanList, newType); + System.out.println("newType:" + newType); + if (newType.toString().isEmpty()) { + MessageBox.post(preName + "ѡ󣬲½Ķ", "ʾ", MessageBox.INFORMATION); + return; + } + if (beanList.size() == 0) { + MessageBox.post(preName + "ѡ󣬲ѡж͵", "ʾ", MessageBox.INFORMATION); + return; + } + this.setRunnable( + new DerivedChangeRequestDialog(app, beanList, newType, (TCComponentItemRevision) targetComponent)); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/com/connor/plm/sb02/DerivedChangeRequestDialog.java b/src/com/connor/plm/sb02/DerivedChangeRequestDialog.java new file mode 100644 index 0000000..9e65d96 --- /dev/null +++ b/src/com/connor/plm/sb02/DerivedChangeRequestDialog.java @@ -0,0 +1,623 @@ +package com.connor.plm.sb02; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.regex.Pattern; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.border.LineBorder; + +import com.aspose.words.FieldAutoNumLgl; +import com.aspose.words.Revision; +import com.connor.plm.KUtil; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.common.lov.view.components.LOVDisplayer; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentFolder; +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.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.DateButton; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; +import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException; +import com.teamcenter.services.rac.core.DataManagementService; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse; +import com.teamcenter.services.rac.workflow.WorkflowService; +import com.teamcenter.services.rac.workflow._2008_06.Workflow.ContextData; +import com.teamcenter.services.rac.workflow._2008_06.Workflow.InstanceInfo; + + +@SuppressWarnings("serial") +public class DerivedChangeRequestDialog extends AbstractAIFDialog implements ActionListener { + protected TCSession session; + private ArrayList beanList; + private String newType; + private JPanel centerPanel; + private JButton okButton; + private JButton celButton; + private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd HH:mm"); + private TCComponentItemRevision tarRev; + private JTextField idField = null; + private static final Pattern ECN_PATTERN = Pattern.compile("ECN-[0-9]{8}"); + private static final Pattern ECR_PATTERN = Pattern.compile("ECR-[0-9]{8}"); + // ʵֵ + private HashMap beanMap = new HashMap(); + // ѡеϼ + private ArrayList partList = new ArrayList(); + + public DerivedChangeRequestDialog(AbstractAIFApplication app, ArrayList beanList, StringBuffer newType, + TCComponentItemRevision tarRev) { + super(false); + this.session = (TCSession) app.getSession(); + this.beanList = beanList; + this.newType = newType.toString(); + this.tarRev = tarRev; + } + + public DerivedChangeRequestDialog(AbstractAIFApplication app, ArrayList beanList, StringBuffer newType, + TCComponentItemRevision tarRev, ArrayList partList) { + super(false); + this.session = (TCSession) app.getSession(); + this.beanList = beanList; + this.newType = newType.toString(); + this.tarRev = tarRev; + this.partList = partList; + run(); + } + + @Override + public void run() { + initUI(); + + } + + private void initUI() { + this.setPreferredSize(new Dimension(555, 888)); + centerPanel = new JPanel(new PropertyLayout()); + JLabel label1 = new JLabel(" "); + centerPanel.add("1.1.center", label1); + for (int i = 0; i < beanList.size(); i++) { + int row = i + 2; + ControlBean bean = beanList.get(i); + beanMap.put(bean.getPropRelName(), bean); + String labelValue = bean.getPropName(); + if (bean.isIfMust()) { + labelValue = bean.getPropName() + "()"; + } + JLabel oneLabel = new JLabel(" "); + centerPanel.add(row + ".1.center", oneLabel); + JLabel label = new JLabel(labelValue); + label.setPreferredSize(new Dimension(120, 40)); + centerPanel.add(row + ".2.center", label); + + if (bean.getPropType().equals("lov")) { + JComboBox combox = bean.getCombox(); + combox.setName(bean.getPropRelName()); + combox.setPreferredSize(new Dimension(350, 25)); + System.out.println("ĬֵΪ" + bean.getDefaultValue()); + combox.setSelectedItem(bean.getDefaultValue()); + System.out.println("bean==>" + bean.toString()); + centerPanel.add(row + ".3.center", combox); + } else if (bean.getPropType().equals("string")) { + if ("object_name".equals(bean.getPropRelName()) || "object_desc".equals(bean.getPropRelName())) { + JTextArea area = new JTextArea(bean.getDefaultValue()); + area.setName(bean.getPropRelName()); + area.setPreferredSize(new Dimension(350, 50)); + area.setBorder(new LineBorder(new java.awt.Color(127, 157, 185), 1, false)); + centerPanel.add(row + ".3.center", area); + } else { + if("item_id".equals(bean.getPropRelName())) { + idField = new JTextField(bean.getDefaultValue()); + idField.setName(bean.getPropRelName()); + idField.setPreferredSize(new Dimension(350, 25)); + centerPanel.add(row + ".3.center", idField); + }else { + JTextField field = new JTextField(bean.getDefaultValue()); + field.setName(bean.getPropRelName()); + field.setPreferredSize(new Dimension(350, 25)); + centerPanel.add(row + ".3.center", field); + } + + } + } else if (bean.getPropType().equals("boolean")) { + JComboBox combox = new JComboBox(); + combox.addItem(""); + combox.addItem(""); + combox.setPreferredSize(new Dimension(350, 25)); + centerPanel.add(row + ".3.center", combox); + } else if (bean.getPropType().equals("date")) { + DateButton dateButton = new DateButton(sdf); + dateButton.setName(bean.getPropRelName()); + dateButton.setText(bean.getDefaultValue()); + dateButton.setPreferredSize(new Dimension(350, 25)); + centerPanel.add(row + ".3.center", dateButton); + } + } + // LOVDisplayer year_categoryCombo = null; + // TCProperty prop; + // try { + // prop = tarRev.getTCProperty("ld6_emergencyLevel"); + // TCPropertyDescriptor descriptor = prop.getPropertyDescriptor(); + // year_categoryCombo = new LOVDisplayer(descriptor); + // //String projectYear = Utilities.getStringForArray(Utilities.getArray(year_categoryCombo.getSelectedValue()),""); + // } catch (TCException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // JLabel oneLabel = new JLabel(" "); + // centerPanel.add(beanList.size() + 2 + ".1.center",oneLabel); + // JLabel label = new JLabel("ݣ"); + // label.setPreferredSize(new Dimension(120,40)); + // centerPanel.add(beanList.size() + 2 + ".2.center",label); + // centerPanel.add(beanList.size() + 2 + ".3.center",year_categoryCombo); + + JScrollPane jsp = new JScrollPane(centerPanel); + + okButton = new JButton(""); + okButton.addActionListener(this); + celButton = new JButton("ȡ"); + celButton.addActionListener(this); + JPanel buttonPanel = new JPanel(); + buttonPanel.add(okButton); + buttonPanel.add(celButton); + this.setLayout(new BorderLayout()); + this.add(BorderLayout.CENTER, jsp); + this.add(BorderLayout.SOUTH, buttonPanel); + showDialog(); + } + + @Override + public void actionPerformed(ActionEvent arg0) { + if (arg0.getSource() == this.celButton) { + this.dispose(); + } else if (arg0.getSource() == this.okButton) { + new Thread() { + @Override + public void run() { + try { + long time1 = System.nanoTime(); + // KUtil.setByPass(true); + if(idField != null) { + String itemId = idField.getText(); + String type = tarRev.getType(); + if("ProblemReportRevision".equals(type)) { + if(!ECR_PATTERN.matcher(itemId).matches()) { + MessageBox.post("ֵΪ" + itemId + "ϵͳECR-'nnnnnnnn'ȷϺд", + "ʾ", MessageBox.INFORMATION); + return; + } + }else { + if(!ECN_PATTERN.matcher(itemId).matches()) { + MessageBox.post("ֵΪ" + itemId + "ϵͳECN-'nnnnnnnn'ȷϺд", + "ʾ", MessageBox.INFORMATION); + return; + } + } + TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent(newType); + TCComponentItem findItem = itemType.find(itemId); + if(findItem != null) { + MessageBox.post("ϵͳѾidΪ" + itemId + "Ķ,дID", + "ʾ", MessageBox.INFORMATION); + return; + } + } + TCComponentItemRevision rev = createItem(""); + // KUtil.setByPass(false); + long time2 = System.nanoTime(); + System.out.println("ʱ(ms) " + (time2 - time1) / 1000000); + if(rev != null) { + MessageBox.post("ɹ,¶newstuffļ", "ʾ", MessageBox.INFORMATION); + } + disposeDialog(); + } catch (Exception e) { + MessageBox.post(e.getMessage(), "ʾ", MessageBox.INFORMATION); + e.printStackTrace(); + } + } + }.start(); + } + } + + /** + * жϱǷд + * + * @param errorBuffer + * @param valueMap + * @param objectDesc + * @param itemId + */ + private void judgeMust(StringBuffer errorBuffer, HashMap valueMap) { + for (Entry entry : beanMap.entrySet()) { + String name = entry.getKey(); + ControlBean bean = entry.getValue(); + System.out.println("ǰֶΪ" + name + "======ǰǷΪ" + bean.isIfMust()); + + if (bean.isIfMust()) { + String propValue = valueMap.get(name); + System.out.println("ǰֶΪ" + name + "======ǰֶεֵΪ" + propValue); + if (propValue == null || propValue.isEmpty() || "δڡ".equals(propValue)) { + errorBuffer.append(bean.getPropName() + ","); + } + } + } + valueMap.remove("item_id"); + valueMap.remove("object_desc"); + } + + /** + * + * + * @throws TCException + * @throws ServiceException + * @throws ParseException + * @throws NotLoadedException + */ + private TCComponentItemRevision createItem(String partNum) + throws TCException, ServiceException, ParseException { + TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent(newType); + HashMap valueMap = new HashMap(); + int componentCount = centerPanel.getComponentCount(); + // String itemId = null; + String objectDesc = ""; + String objectName = ""; + for (int i = 0; i < componentCount; i++) { + Component component = centerPanel.getComponent(i); + if (component instanceof JTextField) { + JTextField filed = (JTextField) component; + valueMap.put(filed.getName(), filed.getText()); + + } else if (component instanceof JComboBox) { + JComboBox combox = (JComboBox) component; + String select = (String)combox.getSelectedItem(); + valueMap.put(combox.getName(), select); + } else if (component instanceof DateButton) { + DateButton date = (DateButton) component; + valueMap.put(date.getName(), date.getText()); + } else if (component instanceof JTextArea) { + JTextArea area = (JTextArea) component; + if (area.getName().equals("object_desc")) { + objectDesc = area.getText(); + } else { + objectName = area.getText(); + valueMap.put(area.getName(), area.getText()); + } + } + } + StringBuffer errorBuffer = new StringBuffer(); + if(idField != null && idField.getText() != null && !"".equals(idField.getText().trim())) { + valueMap.put("item_id", idField.getText()); + }else { + String itemId = itemType.getNewID(); + valueMap.put("item_id", itemId); + } + valueMap.put("object_desc", objectDesc); + judgeMust(errorBuffer, valueMap); + if (!errorBuffer.toString().isEmpty()) { + MessageBox.post(errorBuffer.toString() + " Щδ", "ʾ", MessageBox.INFORMATION); + return null; + } + Map itemMaps = new HashMap(); + Map revMaps = new HashMap(); + if(idField != null && idField.getText() != null && !"".equals(idField.getText().trim())) { + itemMaps.put("item_id", idField.getText()); + }else { + itemMaps.put("item_id", valueMap.get("item_id")); + } + + itemMaps.put("object_desc", objectDesc); + // revMaps.put("object_name", partNum + objectName); + // ޸3.7 + revMaps.put("object_name", objectName); + + //object_name ld6_partName + System.out.println("newType:" + newType); + TCComponent createMaterialBySOA = createMaterialBySOA(newType, itemMaps, revMaps,valueMap); + if (createMaterialBySOA == null) { + MessageBox.post("ʧ", "ʾ", MessageBox.INFORMATION); + return null; + } + TCComponentItem newItem = (TCComponentItem) createMaterialBySOA; + + TCComponentItemRevision latestItemRevision = newItem.getLatestItemRevision(); + // ŵnewstuff + TCComponentFolder newStuffFolder = session.getUser().getNewStuffFolder(); + newStuffFolder.add("contents", newItem); + try { + KUtil.setByPass(true); + tarRev.add("CMImplementedBy", latestItemRevision); + KUtil.setByPass(false); + } catch (TCException e) { + // TODO Auto-generated catch blocke + e.printStackTrace(); + }finally { + KUtil.setByPass(false); + } + + // id汾ͣƣ + // TCComponentItem newItem = itemType.create(itemId,"",newType ,"", "niuma", + // null); + // TCComponentItemRevision latestItemRevision = newItem.getLatestItemRevision(); + // tarRev.add("CMImplementedBy", latestItemRevision); + // + for (Entry entry : valueMap.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + ControlBean controlBean = beanMap.get(key); + TCComponent center = null; + if ("Item".equals(controlBean.getPropTo())) { + center = newItem; + } else if ("Rev".equals(controlBean.getPropTo())) { + center = latestItemRevision; + } else if ("Form".equals(controlBean.getPropTo())) { + center = latestItemRevision.getRelatedComponent("IMAN_master_form_rev"); + } + if ("boolean".equals(controlBean.getPropType())) { + if ("".equals(value)) { + center.setLogicalProperty(key, true); + } else if ("".equals(value)) { + center.setLogicalProperty(key, false); + } + } else if ("date".equals(controlBean.getPropType())) { + if (!value.isEmpty() && !"δڡ".equals(value)) { + center.setDateProperty(key, sdf.parse(value)); + } + } else if ("string".equals(controlBean.getPropType())) { + if (!value.isEmpty()) { + center.setStringProperty(key, value); + } + } else if ("lov".equals(controlBean.getPropType())) { + center.setStringProperty(key, controlBean.getLovMap().get(value)); + } + } + System.out.println("ʼתƹϵļµĶ"); + TCComponent[] re1 = tarRev.getRelatedComponents("CMHasProblemItem"); + if (re1 != null && re1.length > 0) { + latestItemRevision.add("CMHasProblemItem", re1); + } + TCComponent[] re2 = tarRev.getRelatedComponents("CMReferences"); + if (re2 != null && re2.length > 0) { + latestItemRevision.add("CMReferences", re2); + } + String type = tarRev.getType(); + if (!"ProblemReportRevision".equals(type)) { + TCComponent[] re4 = tarRev.getRelatedComponents("CMHasImpactedItem"); + if (re4 != null && re4.length > 0) { + latestItemRevision.add("CMHasImpactedItem", re4); + } + } + if("ChangeRequestRevision".equals(type)) { + TCComponent[] re5 = tarRev.getRelatedComponents("IMAN_specification"); + if(re5 != null && re5.length > 0) { + for (int i = 0; i < re5.length; i++) { + TCComponent dataset = re5[i]; + if(dataset instanceof TCComponentDataset) { + TCComponentDataset newDataset = ((TCComponentDataset) dataset).saveAs(dataset.getStringProperty("object_name")); + if(newDataset != null) { + workflow(new String[] {newDataset.getUid()},"ٷ","TCM Release Process"); + latestItemRevision.add("IMAN_specification", newDataset); + } + } + } + } + } + return latestItemRevision; + } + + /** + * + * @param itemTypeCom + * @param itemPropMaps + * @param revMaps 汾 + * @return ¶ + * @throws TCException + * @throws ServiceException + * @throws ParseException + */ + private TCComponent createMaterialBySOA(String itemTypeCom, Map itemPropMaps, + Map revMaps,HashMap valueMap) throws TCException, ServiceException, ParseException { + System.out.println(itemTypeCom); + Map itemboole = new HashMap(); + Map itemdate = new HashMap(); + Map revboole = new HashMap(); + Map revdate = new HashMap(); + Map formMaps = new HashMap(); + Map formboole = new HashMap(); + Map formdate = new HashMap(); + for (Entry entry : valueMap.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + ControlBean controlBean = beanMap.get(key); + + if ("Item".equals(controlBean.getPropTo())) { + if ("boolean".equals(controlBean.getPropType())) { + if ("".equals(value)) { + itemboole.put(key, true); + } else if ("".equals(value)) { + itemboole.put(key, false); + } + } else if ("date".equals(controlBean.getPropType())) { + if (!value.isEmpty() && !"δڡ".equals(value)) { + Date parse = sdf.parse(value); + Calendar cal = Calendar.getInstance(); + cal.setTime(parse); + itemdate.put(key, cal); + } + } else if ("string".equals(controlBean.getPropType())) { + if (!value.isEmpty()) { + itemPropMaps.put(key, value); + } + } else if ("lov".equals(controlBean.getPropType())) { + String string = controlBean.getLovMap().get(value); + if(!"".equals(string.trim())) { + itemPropMaps.put(key, string); + } + } + } else if ("Rev".equals(controlBean.getPropTo())) { + if ("boolean".equals(controlBean.getPropType())) { + if ("".equals(value)) { + revboole.put(key, true); + } else if ("".equals(value)) { + revboole.put(key, false); + } + } else if ("date".equals(controlBean.getPropType())) { + if (!value.isEmpty() && !"δڡ".equals(value)) { + Date parse = sdf.parse(value); + Calendar cal = Calendar.getInstance(); + cal.setTime(parse); + revdate.put(key, cal); + } + } else if ("string".equals(controlBean.getPropType())) { + if (!value.isEmpty()) { + revMaps.put(key, value); + } + } else if ("lov".equals(controlBean.getPropType())) { + String string = controlBean.getLovMap().get(value); + if(!"".equals(string.trim())) { + revMaps.put(key, string); + } + } + }else if("Form".equals(controlBean.getPropTo())) { + if ("boolean".equals(controlBean.getPropType())) { + if ("".equals(value)) { + formboole.put(key, true); + } else if ("".equals(value)) { + formboole.put(key, false); + } + } else if ("date".equals(controlBean.getPropType())) { + if (!value.isEmpty() && !"δڡ".equals(value)) { + Date parse = sdf.parse(value); + Calendar cal = Calendar.getInstance(); + cal.setTime(parse); + formdate.put(key, cal); + } + } else if ("string".equals(controlBean.getPropType())) { + if (!value.isEmpty()) { + formMaps.put(key, value); + } + } else if ("lov".equals(controlBean.getPropType())) { + String string = controlBean.getLovMap().get(value); + if(!"".equals(string.trim())) { + formMaps.put(key, string); + } + } + } + + } + for (Map.Entry entry : itemPropMaps.entrySet()) { + System.out.println("itemPropMaps: key = " + entry.getKey() + ", value = " + entry.getValue()); + } + for (Map.Entry entry : revMaps.entrySet()) { + System.out.println("revMaps: key = " + entry.getKey() + ", value = " + entry.getValue()); + } + DataManagementService dmService = DataManagementService.getService(session); + CreateInput revInput = new CreateInput(); + revInput.boName = itemTypeCom + "Revision"; + revInput.stringProps = revMaps; + revInput.dateProps = revdate; + revInput.boolProps = revboole; + + + CreateInput[] formCompInputS = new CreateInput[1]; + formCompInputS[0] = new CreateInput(); + formCompInputS[0].boName = itemTypeCom + "Revision Master"; + formCompInputS[0].stringProps = formMaps; + formCompInputS[0].dateProps = formdate; + formCompInputS[0].boolProps = formboole; + + Map formCompMap = new HashMap(); + formCompMap.put("IMAN_master_form_rev", formCompInputS); + revInput.compoundCreateInput = formCompMap; + CreateInput itemInput = new CreateInput(); + itemInput.boName = itemTypeCom; + itemInput.stringProps = itemPropMaps; + itemInput.dateProps = itemdate; + itemInput.boolProps = itemboole; + HashMap revInfoMap = new HashMap(); + revInfoMap.put("revision", new CreateInput[] { revInput }); + itemInput.compoundCreateInput = revInfoMap; + CreateIn createin = new CreateIn(); + createin.clientId = "CreateItem"; + createin.data = itemInput; + com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse createresponse; + createresponse = dmService.createObjects(new CreateIn[] { createin }); + if (createresponse.serviceData.sizeOfPartialErrors() > 0) { + System.out.println("create item failed"); + for (int i = 0; i < createresponse.serviceData.sizeOfPartialErrors(); i++) { + String[] messages = createresponse.serviceData.getPartialError(0).getMessages(); + for(int j=0;j 0) { + comp = cOs[0].objects[0]; + System.out.println("Ķ:" + comp); + return comp; + } + return null; + } + /** + * + * ½ݼϷ״̬ + */ + public void workflow(String[] uid,String workFlowName,String templateName) { + // String uid = rev.getUid(); + // + WorkflowService wfService = WorkflowService.getService(session); + ContextData contextData = new ContextData(); + String observerKey = ""; + String name = workFlowName; + String subject = ""; + String description = ""; + contextData.processTemplate = templateName; // update with your own ProcessTemplate. + contextData.subscribeToEvents = false; + contextData.subscriptionEventCount = 0; + contextData.attachmentCount = uid.length; + contextData.attachments = uid ; + int [] types = new int[uid.length]; + for(int i = 0;i ()); + model.addColumn("", new Vector()); + model.addColumn("", new Vector()); + model.addColumn("Ƿѡ", new Vector()); + + table = new JTable(model); + JScrollPane jp = new JScrollPane(table); + for(int i = 0;i < 20 ;i ++) { + model.addRow(new Vector()); + } + + + JTableHeader head = table.getTableHeader(); + //ñͷĴС + head.setPreferredSize(new Dimension(head.getWidth(),30)); + //ñͷС + head.setFont(new Font("",Font.BOLD,16)); + //ñп + table.setRowHeight(30); + //ñС + table.setFont(new Font("",Font.ROMAN_BASELINE,13)); + /*ñеݾ*/ + DefaultTableCellRenderer renderer=new DefaultTableCellRenderer(); + renderer.setHorizontalAlignment(DefaultTableCellRenderer.CENTER); + table.setDefaultRenderer(Object.class, renderer); + + /*帴ѡ*/ + JCheckBox box = new JCheckBox(); + + /*getColumn()ӦĵڼӸѡ*/ + table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRenderer() { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus,int row, int column) { + + + /*õѡѡбȾ*/ + box.setSelected(isSelected); + + /*øѡڵԪо*/ + box.setHorizontalAlignment((int) 0.5f); + + return box; + } + + }); + + this.add(jp); + setVisible(true); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + } + public static void main(String[] args) { + TableDemo t = new TableDemo(); + } +} \ No newline at end of file diff --git a/src/com/connor/plm/sb02/old.txt b/src/com/connor/plm/sb02/old.txt new file mode 100644 index 0000000..23d018a --- /dev/null +++ b/src/com/connor/plm/sb02/old.txt @@ -0,0 +1,86 @@ +package com.net.connor.ld.plm.ld06; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Polygon; +import java.util.Comparator; + +import javax.swing.Icon; +import javax.swing.RowSorter; +import javax.swing.RowSorter.SortKey; +import javax.swing.SortOrder; +import javax.swing.table.TableRowSorter; + +import antlr.collections.List; + +public class ArrowIcon implements Icon { + private final SortOrder sortOrder; + private final int size; + private final boolean ascending; + public ArrowIcon(TableRowSorter sorter, int column, boolean ascending) { + this.ascending = ascending; + this.size = 12; + java.util.List sortKeys = sorter.getSortKeys(); + if (sortKeys.size() > 0 && ((RowSorter.SortKey) sortKeys.get(0)).getColumn() == column) { + this.sortOrder = ((RowSorter.SortKey) sortKeys.get(0)).getSortOrder(); + } else { + this.sortOrder = SortOrder.ASCENDING; + } + } + public void paintIcon(Component c, Graphics g, int x, int y) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.translate(x, y); + if (ascending) { + g2.rotate(Math.PI, size / 2.0, size / 2.0); + } + if (sortOrder == SortOrder.ASCENDING) { + g2.draw(createUpTriangle(size)); + } else { + g2.draw(createDownTriangle(size)); + } + g2.dispose(); + } + public int getIconWidth() { + return size; + } + public int getIconHeight() { + return size; + } + private Polygon createUpTriangle(int size) { + Polygon triangle = new Polygon(); + triangle.addPoint(0, size); + triangle.addPoint(size / 2, 0); + triangle.addPoint(size, size); + return triangle; + } + private Polygon createDownTriangle(int size) { + Polygon triangle = new Polygon(); + triangle.addPoint(0, 0); + triangle.addPoint(size, 0); + triangle.addPoint(size / 2, size); + return triangle; + } +} +//表格列排序类 +class ColumnSorter implements Comparator { + private final int col; + private final boolean ascending; + public ColumnSorter(int col, boolean ascending) { + this.col = col; + this.ascending = ascending; + } + @Override + public int compare(Object a, Object b) { + if (a instanceof Comparable && b instanceof Comparable) { + if (ascending) { + return ((Comparable) a).compareTo((Comparable) b); + } else { + return ((Comparable) b).compareTo((Comparable) a); + } + } else { + return 0; + } + } +} + diff --git a/src/com/connor/plm/test.java b/src/com/connor/plm/test.java new file mode 100644 index 0000000..a15bbec --- /dev/null +++ b/src/com/connor/plm/test.java @@ -0,0 +1,15 @@ +package com.connor.plm; + +import java.text.SimpleDateFormat; + +public class test { + + public static void main(String[] args) { + // TODO Auto-generated method stub + String value = null; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd HH:mm"); + value = sdf.format(""); + System.out.println(value); + } + +}