feat(plm): 实现绩效管理插件功能

- 添加多个新功能模块,包括计算材料定额、批量修改任务名称、更新属性到对象等
- 集成 SQL Server 数据库连接和操作
- 增加 Word 和 Excel 模板处理功能
- 优化插件配置,移除不必要的依赖
- 更新插件菜单和弹出菜单结构
main
熊朝柱 1 week ago
parent 1fbdd06a88
commit eae81092c1

@ -3,5 +3,16 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="sqlServerLib/sqljdbc4.jar"/>
<classpathentry kind="lib" path="sqlServerLib/swingx-1.6.1.jar"/>
<classpathentry kind="lib" path="poi_lib/aspose-words-17.4.0-jdk16.jar"/>
<classpathentry kind="lib" path="poi_lib/commons-collections4-4.1.jar"/>
<classpathentry kind="lib" path="poi_lib/poi-3.17.jar"/>
<classpathentry kind="lib" path="poi_lib/poi-examples-3.17.jar"/>
<classpathentry kind="lib" path="poi_lib/poi-excelant-3.17.jar"/>
<classpathentry kind="lib" path="poi_lib/poi-ooxml-3.17.jar"/>
<classpathentry kind="lib" path="poi_lib/poi-ooxml-schemas-3.17.jar"/>
<classpathentry kind="lib" path="poi_lib/poi-scratchpad-3.17.jar"/>
<classpathentry kind="lib" path="poi_lib/xmlbeans-2.6.0.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

@ -3,7 +3,6 @@ Bundle-ManifestVersion: 2
Bundle-Name: Performancemanagement Bundle-Name: Performancemanagement
Bundle-SymbolicName: com.langtech.plm.performancemanagement;singleton:=true Bundle-SymbolicName: com.langtech.plm.performancemanagement;singleton:=true
Bundle-Version: 1.0.0 Bundle-Version: 1.0.0
Bundle-Activator: com.langtech.plm.performancemanagement.Activator
Bundle-Vendor: LANGTECH Bundle-Vendor: LANGTECH
Require-Bundle: org.eclipse.ui, Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime, org.eclipse.core.runtime,
@ -15,7 +14,367 @@ Require-Bundle: org.eclipse.ui,
com.teamcenter.rac.common;bundle-version="13000.1.0", com.teamcenter.rac.common;bundle-version="13000.1.0",
com.teamcenter.rac.kernel;bundle-version="13000.1.0", com.teamcenter.rac.kernel;bundle-version="13000.1.0",
com.teamcenter.rac.external;bundle-version="13000.1.0", com.teamcenter.rac.external;bundle-version="13000.1.0",
org.apache.poi.39;bundle-version="3.9.0" TcSoaCoreRac;bundle-version="13000.1.0",
k.util;bundle-version="1.0.0",
com.teamcenter.rac.aif.registryeditor;bundle-version="13000.1.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: com.langtech.plm.performancemanagement Automatic-Module-Name: com.langtech.plm.performancemanagement
Bundle-ActivationPolicy: lazy Bundle-ClassPath: sqlServerLib/sqljdbc4.jar,
.,
sqlServerLib/swingx-1.6.1.jar,
sqlServerLib/aspose-words-17.4.0-jdk16.jar,
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
Export-Package: asposewobfuscated,
com.aspose.words,
com.aspose.words.net.System,
com.aspose.words.net.System.Data,
com.aspose.words.net.System.Data.Common,
com.langtech.plm.batchRename,
com.langtech.plm.calculateMaterialsAndWork,
com.langtech.plm.createProjectStruct,
com.langtech.plm.mpart,
com.langtech.plm.synchronize,
com.langtech.plm.template,
com.langtech.plm.tqsx,
com.microsoft.schemas.office.excel,
com.microsoft.schemas.office.excel.impl,
com.microsoft.schemas.office.office,
com.microsoft.schemas.office.office.impl,
com.microsoft.schemas.office.visio.x2012.main,
com.microsoft.schemas.office.visio.x2012.main.impl,
com.microsoft.schemas.office.x2006.digsig,
com.microsoft.schemas.office.x2006.digsig.impl,
com.microsoft.schemas.office.x2006.encryption,
com.microsoft.schemas.office.x2006.encryption.impl,
com.microsoft.schemas.office.x2006.keyEncryptor.certificate,
com.microsoft.schemas.office.x2006.keyEncryptor.certificate.impl,
com.microsoft.schemas.office.x2006.keyEncryptor.password,
com.microsoft.schemas.office.x2006.keyEncryptor.password.impl,
com.microsoft.schemas.vml,
com.microsoft.schemas.vml.impl,
com.microsoft.sqlserver.jdbc,
microsoft.sql,
org.apache.commons.collections4,
org.apache.commons.collections4.bag,
org.apache.commons.collections4.bidimap,
org.apache.commons.collections4.collection,
org.apache.commons.collections4.comparators,
org.apache.commons.collections4.functors,
org.apache.commons.collections4.iterators,
org.apache.commons.collections4.keyvalue,
org.apache.commons.collections4.list,
org.apache.commons.collections4.map,
org.apache.commons.collections4.multimap,
org.apache.commons.collections4.multiset,
org.apache.commons.collections4.queue,
org.apache.commons.collections4.sequence,
org.apache.commons.collections4.set,
org.apache.commons.collections4.splitmap,
org.apache.commons.collections4.trie,
org.apache.commons.collections4.trie.analyzer,
org.apache.poi,
org.apache.poi.common.usermodel,
org.apache.poi.common.usermodel.fonts,
org.apache.poi.crypt.examples,
org.apache.poi.ddf,
org.apache.poi.dev,
org.apache.poi.examples.util,
org.apache.poi.extractor,
org.apache.poi.hdgf,
org.apache.poi.hdgf.chunks,
org.apache.poi.hdgf.dev,
org.apache.poi.hdgf.exceptions,
org.apache.poi.hdgf.extractor,
org.apache.poi.hdgf.pointers,
org.apache.poi.hdgf.streams,
org.apache.poi.hemf.extractor,
org.apache.poi.hemf.hemfplus.record,
org.apache.poi.hemf.record,
org.apache.poi.hmef,
org.apache.poi.hmef.attribute,
org.apache.poi.hmef.dev,
org.apache.poi.hmef.extractor,
org.apache.poi.hpbf,
org.apache.poi.hpbf.dev,
org.apache.poi.hpbf.extractor,
org.apache.poi.hpbf.model,
org.apache.poi.hpbf.model.qcbits,
org.apache.poi.hpsf,
org.apache.poi.hpsf.examples,
org.apache.poi.hpsf.extractor,
org.apache.poi.hpsf.wellknown,
org.apache.poi.hslf.blip,
org.apache.poi.hslf.dev,
org.apache.poi.hslf.examples,
org.apache.poi.hslf.exceptions,
org.apache.poi.hslf.extractor,
org.apache.poi.hslf.model,
org.apache.poi.hslf.model.textproperties,
org.apache.poi.hslf.record,
org.apache.poi.hslf.usermodel,
org.apache.poi.hslf.util,
org.apache.poi.hsmf,
org.apache.poi.hsmf.datatypes,
org.apache.poi.hsmf.dev,
org.apache.poi.hsmf.examples,
org.apache.poi.hsmf.exceptions,
org.apache.poi.hsmf.extractor,
org.apache.poi.hsmf.parsers,
org.apache.poi.hssf,
org.apache.poi.hssf.converter,
org.apache.poi.hssf.dev,
org.apache.poi.hssf.eventmodel,
org.apache.poi.hssf.eventusermodel,
org.apache.poi.hssf.eventusermodel.dummyrecord,
org.apache.poi.hssf.eventusermodel.examples,
org.apache.poi.hssf.extractor,
org.apache.poi.hssf.model,
org.apache.poi.hssf.record,
org.apache.poi.hssf.record.aggregates,
org.apache.poi.hssf.record.cf,
org.apache.poi.hssf.record.chart,
org.apache.poi.hssf.record.common,
org.apache.poi.hssf.record.cont,
org.apache.poi.hssf.record.crypto,
org.apache.poi.hssf.record.pivottable,
org.apache.poi.hssf.usermodel,
org.apache.poi.hssf.usermodel.examples,
org.apache.poi.hssf.usermodel.helpers,
org.apache.poi.hssf.util,
org.apache.poi.hssf.view,
org.apache.poi.hssf.view.brush,
org.apache.poi.hwmf.draw,
org.apache.poi.hwmf.record,
org.apache.poi.hwmf.usermodel,
org.apache.poi.hwpf,
org.apache.poi.hwpf.converter,
org.apache.poi.hwpf.dev,
org.apache.poi.hwpf.extractor,
org.apache.poi.hwpf.model,
org.apache.poi.hwpf.model.io,
org.apache.poi.hwpf.model.types,
org.apache.poi.hwpf.sprm,
org.apache.poi.hwpf.usermodel,
org.apache.poi.openxml4j.exceptions,
org.apache.poi.openxml4j.opc,
org.apache.poi.openxml4j.opc.internal,
org.apache.poi.openxml4j.opc.internal.marshallers,
org.apache.poi.openxml4j.opc.internal.unmarshallers,
org.apache.poi.openxml4j.util,
org.apache.poi.poifs.common,
org.apache.poi.poifs.crypt,
org.apache.poi.poifs.crypt.agile,
org.apache.poi.poifs.crypt.binaryrc4,
org.apache.poi.poifs.crypt.cryptoapi,
org.apache.poi.poifs.crypt.dsig,
org.apache.poi.poifs.crypt.dsig.facets,
org.apache.poi.poifs.crypt.dsig.services,
org.apache.poi.poifs.crypt.standard,
org.apache.poi.poifs.crypt.temp,
org.apache.poi.poifs.crypt.xor,
org.apache.poi.poifs.dev,
org.apache.poi.poifs.eventfilesystem,
org.apache.poi.poifs.filesystem,
org.apache.poi.poifs.macros,
org.apache.poi.poifs.nio,
org.apache.poi.poifs.poibrowser,
org.apache.poi.poifs.property,
org.apache.poi.poifs.storage,
org.apache.poi.sl.draw,
org.apache.poi.sl.draw.binding,
org.apache.poi.sl.draw.geom,
org.apache.poi.sl.image,
org.apache.poi.sl.usermodel,
org.apache.poi.ss,
org.apache.poi.ss.examples,
org.apache.poi.ss.examples.formula,
org.apache.poi.ss.examples.html,
org.apache.poi.ss.excelant,
org.apache.poi.ss.excelant.util,
org.apache.poi.ss.extractor,
org.apache.poi.ss.format,
org.apache.poi.ss.formula,
org.apache.poi.ss.formula.atp,
org.apache.poi.ss.formula.constant,
org.apache.poi.ss.formula.eval,
org.apache.poi.ss.formula.eval.forked,
org.apache.poi.ss.formula.function,
org.apache.poi.ss.formula.functions,
org.apache.poi.ss.formula.ptg,
org.apache.poi.ss.formula.udf,
org.apache.poi.ss.usermodel,
org.apache.poi.ss.usermodel.charts,
org.apache.poi.ss.usermodel.helpers,
org.apache.poi.ss.util,
org.apache.poi.ss.util.cellwalk,
org.apache.poi.util,
org.apache.poi.wp.usermodel,
org.apache.poi.xdgf.exceptions,
org.apache.poi.xdgf.extractor,
org.apache.poi.xdgf.geom,
org.apache.poi.xdgf.usermodel,
org.apache.poi.xdgf.usermodel.section,
org.apache.poi.xdgf.usermodel.section.geometry,
org.apache.poi.xdgf.usermodel.shape,
org.apache.poi.xdgf.usermodel.shape.exceptions,
org.apache.poi.xdgf.util,
org.apache.poi.xdgf.xml,
org.apache.poi.xslf.extractor,
org.apache.poi.xslf.model,
org.apache.poi.xslf.usermodel,
org.apache.poi.xslf.usermodel.tutorial,
org.apache.poi.xslf.util,
org.apache.poi.xssf,
org.apache.poi.xssf.binary,
org.apache.poi.xssf.dev,
org.apache.poi.xssf.eventusermodel,
org.apache.poi.xssf.eventusermodel.examples,
org.apache.poi.xssf.extractor,
org.apache.poi.xssf.model,
org.apache.poi.xssf.streaming,
org.apache.poi.xssf.streaming.examples,
org.apache.poi.xssf.usermodel,
org.apache.poi.xssf.usermodel.charts,
org.apache.poi.xssf.usermodel.examples,
org.apache.poi.xssf.usermodel.extensions,
org.apache.poi.xssf.usermodel.helpers,
org.apache.poi.xssf.util,
org.apache.poi.xwpf.extractor,
org.apache.poi.xwpf.model,
org.apache.poi.xwpf.usermodel,
org.apache.poi.xwpf.usermodel.examples,
org.apache.xmlbeans,
org.apache.xmlbeans.impl.common,
org.apache.xmlbeans.impl.config,
org.apache.xmlbeans.impl.inst2xsd,
org.apache.xmlbeans.impl.inst2xsd.util,
org.apache.xmlbeans.impl.jam,
org.apache.xmlbeans.impl.jam.annotation,
org.apache.xmlbeans.impl.jam.internal,
org.apache.xmlbeans.impl.jam.internal.classrefs,
org.apache.xmlbeans.impl.jam.internal.elements,
org.apache.xmlbeans.impl.jam.internal.javadoc,
org.apache.xmlbeans.impl.jam.internal.parser,
org.apache.xmlbeans.impl.jam.internal.reflect,
org.apache.xmlbeans.impl.jam.mutable,
org.apache.xmlbeans.impl.jam.provider,
org.apache.xmlbeans.impl.jam.visitor,
org.apache.xmlbeans.impl.jam.xml,
org.apache.xmlbeans.impl.piccolo.io,
org.apache.xmlbeans.impl.piccolo.util,
org.apache.xmlbeans.impl.piccolo.xml,
org.apache.xmlbeans.impl.regex,
org.apache.xmlbeans.impl.richParser,
org.apache.xmlbeans.impl.schema,
org.apache.xmlbeans.impl.soap,
org.apache.xmlbeans.impl.store,
org.apache.xmlbeans.impl.tool,
org.apache.xmlbeans.impl.util,
org.apache.xmlbeans.impl.validator,
org.apache.xmlbeans.impl.values,
org.apache.xmlbeans.impl.xb.ltgfmt,
org.apache.xmlbeans.impl.xb.ltgfmt.impl,
org.apache.xmlbeans.impl.xb.substwsdl,
org.apache.xmlbeans.impl.xb.substwsdl.impl,
org.apache.xmlbeans.impl.xb.xmlconfig,
org.apache.xmlbeans.impl.xb.xmlconfig.impl,
org.apache.xmlbeans.impl.xb.xmlschema,
org.apache.xmlbeans.impl.xb.xmlschema.impl,
org.apache.xmlbeans.impl.xb.xsdownload,
org.apache.xmlbeans.impl.xb.xsdownload.impl,
org.apache.xmlbeans.impl.xb.xsdschema,
org.apache.xmlbeans.impl.xb.xsdschema.impl,
org.apache.xmlbeans.impl.xpathgen,
org.apache.xmlbeans.impl.xsd2inst,
org.apache.xmlbeans.soap,
org.apache.xmlbeans.xml.stream,
org.apache.xmlbeans.xml.stream.events,
org.apache.xmlbeans.xml.stream.utils,
org.etsi.uri.x01903.v13,
org.etsi.uri.x01903.v13.impl,
org.jdesktop.beans,
org.jdesktop.swingx,
org.jdesktop.swingx.action,
org.jdesktop.swingx.auth,
org.jdesktop.swingx.autocomplete,
org.jdesktop.swingx.autocomplete.workarounds,
org.jdesktop.swingx.border,
org.jdesktop.swingx.calendar,
org.jdesktop.swingx.color,
org.jdesktop.swingx.combobox,
org.jdesktop.swingx.decorator,
org.jdesktop.swingx.error,
org.jdesktop.swingx.event,
org.jdesktop.swingx.geom,
org.jdesktop.swingx.graphics,
org.jdesktop.swingx.hyperlink,
org.jdesktop.swingx.icon,
org.jdesktop.swingx.image,
org.jdesktop.swingx.multislider,
org.jdesktop.swingx.multisplitpane,
org.jdesktop.swingx.painter,
org.jdesktop.swingx.painter.effects,
org.jdesktop.swingx.plaf,
org.jdesktop.swingx.plaf.basic,
org.jdesktop.swingx.plaf.basic.core,
org.jdesktop.swingx.plaf.linux,
org.jdesktop.swingx.plaf.macosx,
org.jdesktop.swingx.plaf.metal,
org.jdesktop.swingx.plaf.misc,
org.jdesktop.swingx.plaf.motif,
org.jdesktop.swingx.plaf.nimbus,
org.jdesktop.swingx.plaf.synth,
org.jdesktop.swingx.plaf.windows,
org.jdesktop.swingx.prompt,
org.jdesktop.swingx.renderer,
org.jdesktop.swingx.rollover,
org.jdesktop.swingx.search,
org.jdesktop.swingx.sort,
org.jdesktop.swingx.table,
org.jdesktop.swingx.tips,
org.jdesktop.swingx.tree,
org.jdesktop.swingx.treetable,
org.jdesktop.swingx.util,
org.openxmlformats.schemas.drawingml.x2006.chart,
org.openxmlformats.schemas.drawingml.x2006.chart.impl,
org.openxmlformats.schemas.drawingml.x2006.main,
org.openxmlformats.schemas.drawingml.x2006.main.impl,
org.openxmlformats.schemas.drawingml.x2006.picture,
org.openxmlformats.schemas.drawingml.x2006.picture.impl,
org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing,
org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.impl,
org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing,
org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.impl,
org.openxmlformats.schemas.officeDocument.x2006.customProperties,
org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl,
org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes,
org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes.impl,
org.openxmlformats.schemas.officeDocument.x2006.extendedProperties,
org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl,
org.openxmlformats.schemas.officeDocument.x2006.relationships,
org.openxmlformats.schemas.officeDocument.x2006.relationships.impl,
org.openxmlformats.schemas.presentationml.x2006.main,
org.openxmlformats.schemas.presentationml.x2006.main.impl,
org.openxmlformats.schemas.spreadsheetml.x2006.main,
org.openxmlformats.schemas.spreadsheetml.x2006.main.impl,
org.openxmlformats.schemas.wordprocessingml.x2006.main,
org.openxmlformats.schemas.wordprocessingml.x2006.main.impl,
org.openxmlformats.schemas.xpackage.x2006.digitalSignature,
org.openxmlformats.schemas.xpackage.x2006.digitalSignature.impl,
org.w3.x2000.x09.xmldsig,
org.w3.x2000.x09.xmldsig.impl,
repackage,
schemaorg_apache_xmlbeans.system.s8C3F193EE11A2F798ACF65489B9E6078,
schemaorg_apache_xmlbeans.system.sF1327CCA741569E70F9CA8C9AF9B44B2,
schemaorg_apache_xmlbeans.system.sXMLCONFIG,
schemaorg_apache_xmlbeans.system.sXMLLANG,
schemaorg_apache_xmlbeans.system.sXMLSCHEMA,
schemaorg_apache_xmlbeans.system.sXMLTOOLS

@ -2,10 +2,131 @@
# 操作触发 # 操作触发
选中项目文件夹,点击“绩效报表”菜单,输出项目的绩效报表Excel 选中项目文件夹,点击“绩效报表”菜单,输出项目的绩效报表Excel
# 首选项配置 # 首选项配置
## ld_billboards_uid ## ld_billboards_uid
单值报表模板的puid ```text
单值报表模板的puid
```
## ld_postCoefficient
```text
多值,描述岗位组对应的岗位系数,形式:
岗位组=岗位系数
绘图组=1
三维组=1.05
```
## ld_taskNature
```
多值,描述任务性质对应的任务系数,形式:
任务性质=任务系数
全新=10
可复制修改=5
临时=2.5
EC=2.5
```
## ld_taskDifficulty
```
多值,描述任务难度对应的难度系数,形式:
任务难度=难度系数
子项目=0.1
简单=1
一般=1.25
较难=1.5
很难=2
```
## ld_urgency
```
多值,描述紧急度对应的紧急系数,形式:
紧急度=紧急系数
一般=1
紧急=1.25
超紧急=1.5
```
## ld_overtime
```
多值,超时扣分配置,形式:
严重程度:天数区间:扣分比例,其中"()"代表开区间,"[]"代表闭区间
如:
一般:(0,1]:0.2
严重:(1,2]:0.33
超严重:(2,3]:0.5
未定义:(3,1000):0.6
```
## ld_processReview
```
多值,描述流程信息配置,用户获取特定流程节点的分派人和处理人,形式:
新品任务项名称=流程名称:审核节点名称
铸件资料=001铸件资料流程:铸件资料审核
```
## ld_requestTime
```
多值,描述任务要求完成时间对应的公式,形式:
新品任务项名称=公式E和F必须放在运算符前面例如
铸件资料=E-10
PPAP文件=F+1
其中E代表流程发起时间F代表工艺程序结束时间数据库表维护
```
## ld_sqlserver
```
多值描述sqlserver数据库连接信息
第一行:数据库用户名
第二行:数据库密码
第三行登录url
第四行:驱动
第五行:表名
infodba
infodba
jdbc:microsoft:sqlserver://10.10.22.39:1433;DatabaseName=TC13
com.microsoft.jdbc.sqlserver.SQLServerDriver
TASK_REQUIREMENT
```
## Connor_JXFolder
```
多值,描述现有的项目归档文件夹与绩效管理要求的任务包对应,形式:
任务包名称=一级文件夹名称/二级文件夹名称/三级文件夹名称/…….
```

@ -0,0 +1 @@
LD6_NewProdForm.FORMJAVARENDERING=com.langtech.plm.form.LD6_NewProdForm

@ -3,4 +3,16 @@ output.. = bin/
bin.includes = plugin.xml,\ bin.includes = plugin.xml,\
META-INF/,\ META-INF/,\
.,\ .,\
icons/ icons/,\
sqlServerLib/sqljdbc4.jar,\
sqlServerLib/swingx-1.6.1.jar,\
sqlServerLib/aspose-words-17.4.0-jdk16.jar,\
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

@ -8,27 +8,78 @@
id="com.langtech.plm.performancemanagement.commands.category" id="com.langtech.plm.performancemanagement.commands.category"
name="Sample Category"> name="Sample Category">
</category> </category>
<!-- 自定义的获取属性工具-->
<command <command
categoryId="com.langtech.plm.performancemanagement.commands.category" categoryId="com.langtech.plm.calculateMaterialsAndWork.CalculateHandler"
name="Sample Command" name="计算材料定额"
id="com.langtech.plm.performancemanagement.commands.taskFolderMatching"> id="com.langtech.plm.calculateMaterialsAndWork.CalculateHandler">
</command>
<command
categoryId="com.langtech.plm.batchRename.BatchRenameHandler"
name="批量修改时间表任务名称"
id="com.langtech.plm.batchRename.BatchRenameHandler">
</command>
<command
categoryId="com.langtech.plm.synchronize.SynchronizeHandler"
name="更新属性到对象"
id="com.langtech.plm.synchronize.SynchronizeHandler">
</command>
<command
categoryId="com.langtech.plm.createProjectStruct.CreateProjectStructHandler"
name="文件夹批量创建"
id="com.langtech.plm.createProjectStruct.CreateProjectStructHandler">
</command>
<command
categoryId="com.langtech.plm.mpart.MpartHandler"
name="Mpart派生"
id="com.langtech.plm.mpart.MpartHandler">
</command>
<command
categoryId="com.langtech.plm.template.TemplateHandler"
name="插入模板"
id="com.langtech.plm.template.TemplateHandler">
</command>
<command
categoryId="com.langtech.plm.tqsx.PropertyToWordOrExcelCommand"
name="提取属性到Word、Excel"
id="com.langtech.plm.tqsx.PropertyToWordOrExcelCommand">
</command> </command>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.handlers"> point="org.eclipse.ui.handlers">
<!-- 自定义获取属性工具-->
<handler <handler
class="com.langtech.plm.performancemanagement.handlers.TaskFolderMatchingHandler" class="com.langtech.plm.calculateMaterialsAndWork.CalculateHandler"
commandId="com.langtech.plm.performancemanagement.commands.taskFolderMatching"> commandId="com.langtech.plm.calculateMaterialsAndWork.CalculateHandler">
</handler>
<handler
class="com.langtech.plm.batchRename.BatchRenameHandler"
commandId="com.langtech.plm.batchRename.BatchRenameHandler">
</handler>
<handler
class="com.langtech.plm.synchronize.SynchronizeHandler"
commandId="com.langtech.plm.synchronize.SynchronizeHandler">
</handler>
<handler
class="com.langtech.plm.createProjectStruct.CreateProjectStructHandler"
commandId="com.langtech.plm.createProjectStruct.CreateProjectStructHandler">
</handler>
<handler
class="com.langtech.plm.mpart.MpartHandler"
commandId="com.langtech.plm.mpart.MpartHandler">
</handler>
<handler
class="com.langtech.plm.template.TemplateHandler"
commandId="com.langtech.plm.template.TemplateHandler">
</handler>
<handler
class="com.langtech.plm.tqsx.KHandler"
commandId="com.langtech.plm.tqsx.PropertyToWordOrExcelCommand">
</handler> </handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="com.langtech.plm.performancemanagement.commands.sampleCommand"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+6">
</key>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.menus"> point="org.eclipse.ui.menus">
@ -36,15 +87,60 @@
locationURI="menu:org.eclipse.ui.main.menu?after=additions"> locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu <menu
id="com.langtech.plm.performancemanagement.menus.sampleMenu" id="com.langtech.plm.performancemanagement.menus.sampleMenu"
label="Sample Menu" label="二开菜单"
mnemonic="M">
<command
commandId="com.langtech.plm.synchronize.SynchronizeHandler"
id="com.langtech.plm.synchronize.SynchronizeHandler"
mnemonic="S">
</command>
<command
commandId="com.langtech.plm.template.TemplateHandler"
id="com.langtech.plm.template.TemplateHandler"
mnemonic="S">
</command>
<!-- com.langtech.plm.calculateMaterialsAndWork.CalculateHandler-->
<command
commandId="com.langtech.plm.calculateMaterialsAndWork.CalculateHandler"
id="com.langtech.plm.calculateMaterialsAndWork.CalculateHandler"
mnemonic="S">
</command>
</menu>
<menu
id="com.langtech.plm.performancemanagement.menus.sampleMenu1"
label="项目管理"
mnemonic="M"> mnemonic="M">
<command <command
commandId="com.langtech.plm.performancemanagement.commands.taskFolderMatching" commandId="com.langtech.plm.batchRename.BatchRenameHandler"
id="com.langtech.plm.performancemanagement.menus.taskFolderMatchingCommand" id="com.langtech.plm.batchRename.BatchRenameHandler"
mnemonic="S">
</command>
<command
commandId="com.langtech.plm.createProjectStruct.CreateProjectStructHandler"
id="com.langtech.plm.createProjectStruct.CreateProjectStructHandler"
mnemonic="S">
</command>
<command
commandId="com.langtech.plm.mpart.MpartHandler"
id="com.langtech.plm.mpart.MpartHandler"
mnemonic="S"> mnemonic="S">
</command> </command>
</menu> </menu>
</menuContribution> </menuContribution>
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="com.langtech.plm.tqsx.PropertyToWordOrExcelCommand"
id="com.langtech.plm.tqsx.PropertyToWordOrExcelCommand">
</command>
</menuContribution>
</extension> </extension>
</plugin> </plugin>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,215 @@
package com.langtech.plm.batchRename;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map.Entry;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
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.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
public class BatchRenameDialog extends JFrame implements ActionListener {
private TCSession session;
protected DefaultTableModel tm_part;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private TCComponentScheduleTask task;
private JTextField find = new JTextField();
private JTextField replace = new JTextField();
private JButton okButton = new JButton("确定");
private JButton concelButton = new JButton("取消");
HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
public BatchRenameDialog(TCSession session, TCComponentScheduleTask task) throws TCException {
// TODO Auto-generated constructor stub
this.session = session;
this.task = task;
initUI();
}
private void initUI() {
// TODO Auto-generated method stub
try {
find.setPreferredSize(new Dimension(200,30));
replace.setPreferredSize(new Dimension(200,30));
this.setTitle("批量修改时间表任务名称");
this.setLayout(new BorderLayout());
JPanel topPanel = getTopPanel();
JPanel btnPanel = getBtnPanel();
this.add(topPanel, BorderLayout.NORTH);
// this.add(pane,BorderLayout.CENTER);
this.add(btnPanel, BorderLayout.SOUTH);
this.setPreferredSize(new Dimension(450, 200));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
int screenWidth = screenSize.width; // 获取屏幕宽度
int screenHeight = screenSize.height; // 获取屏幕高度
int x = (screenWidth - 450) / 2; // 计算Frame的左上角x坐标
int y = (screenHeight - 200) / 2; // 计算Frame的左上角y坐标
this.setLocation(x, y); // 设置Frame的位置
// this.setLocationRelativeTo(null);
this.createActionEvent();
this.pack();
// this.validate();
this.setVisible(true);
// this.setAlwaysOnTop(true);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
// 添加监听
public void createActionEvent() {
this.okButton.addActionListener(this);
this.concelButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
System.out.println("source==>+" + source);
if (this.okButton.equals(source)) {
String fString = find.getText();
String rString = replace.getText();
if(fString.isEmpty()) {
MessageBox.post("请填写查找内容!", "提示 ", MessageBox.INFORMATION);
return;
}
if(rString.isEmpty()) {
MessageBox.post("请填写替换内容!", "提示 ", MessageBox.INFORMATION);
return;
}
//获取含有查找内容的个数
int childrenCount = 0;
try {
childrenCount = task.getChildrenCount();
System.out.println("childrenCount=============="+childrenCount);
//子个数为0
if(childrenCount == 0) {
MessageBox.post("该时间表对象下没有子对象!", "提示 ", MessageBox.INFORMATION);
return;
}
//获取对象名称
AIFComponentContext[] children = task.getChildren();
HashMap<TCComponentScheduleTask, String> map = new HashMap<TCComponentScheduleTask, String>();
for (int i = 0; i < children.length; i++) {
InterfaceAIFComponent component = children[i].getComponent();
if(component instanceof TCComponentScheduleTask) {
TCComponentScheduleTask scheduleTask = (TCComponentScheduleTask)component;
String objectName = scheduleTask.getStringProperty("object_name");
if(objectName.contains(fString)) {
map.put(scheduleTask, objectName.replace(fString, rString));
}
}
}
if(map.size() == 0) {
MessageBox.post("未匹配到含有查找内容的对象!", "提示 ", MessageBox.INFORMATION);
return;
}
//修改
for (Entry<TCComponentScheduleTask, String> tempMap : map.entrySet()) {
TCComponentScheduleTask key = tempMap.getKey();
String value = tempMap.getValue();
key.setProperty("object_name", value);
}
//返回修改信息
MessageBox.post("成功修改"+map.size()+"个对象!", "提示 ", MessageBox.INFORMATION);
this.dispose();
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} else if (this.concelButton.equals(source)) {
this.dispose();
}
}
private JPanel getBtnPanel() {
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.add("1.1.center", new JLabel(""));
topPanel.add("2.1.center", new JLabel(" "));
topPanel.add("2.2.center", okButton);
topPanel.add("2.3.center", new JLabel(""));
topPanel.add("2.4.center", concelButton);
return topPanel;
}
// 查询部分
private JPanel getTopPanel() {
// TODO Auto-generated method stub
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
topPanel.add("1.1.left.center", new JLabel(""));
topPanel.add("2.1.left.center", new JLabel(""));
topPanel.add("3.1.left.center", new JLabel(""));
topPanel.add("4.1.left.center", new JLabel(" 查找内容:"));
topPanel.add("4.2.left.center", find);
topPanel.add("5.1.left.center", new JLabel(""));
topPanel.add("6.1.left.center", new JLabel(""));
topPanel.add("7.1.left.center", new JLabel(""));
topPanel.add("8.1.left.center", new JLabel(" 替换内容:"));
topPanel.add("8.2.left.center", replace);
return topPanel;
}
}

@ -0,0 +1,57 @@
package com.langtech.plm.batchRename;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentSchedule;
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class BatchRenameHandler extends AbstractHandler{
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
try {
new Thread() {
@Override
public void run() {
InterfaceAIFComponent targetComponent = app.getTargetComponent();
if(targetComponent instanceof TCComponentScheduleTask) {
try {
TCComponentScheduleTask task = (TCComponentScheduleTask)targetComponent;
new BatchRenameDialog(session,task);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
MessageBox.post("Çëʱ¼ä±í¶ÔÏó£¡","Ìáʾ",2);
return;
}
}
}.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,623 @@
package com.langtech.plm.calculateMaterialsAndWork;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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.xssf.usermodel.XSSFWorkbook;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentMEOP;
import com.teamcenter.rac.kernel.TCComponentMEOPRevision;
import com.teamcenter.rac.kernel.TCComponentTcFile;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
import com.teamcenter.rac.util.UIUtilities;
public class CalculateDialog extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private AbstractAIFApplication application;
private TCComponentMEOPRevision meop;
private TCSession session;
TCComponentItemRevision rawMaterialRevision;
//打印界面控件
//图纸零件轮廓直径D
private JLabel zjdLabel;
private JTextField zjdTextField;
//图纸零件轮廓长
private JLabel lkcLabel;
private JTextField lkcTextField;
//切断用长度
private JLabel qdycdLabel;
private JTextField qdycdTextField;
//车端面用长度
private JLabel cdmycdLabel;
private JTextField cdmycdTextField;
//夹头用长度
private JLabel jtycdLabel;
private JTextField jtycdTextField;
//可制零件数
private JLabel kzljsLabel;
private JTextField kzljsTextField;
//规格
private JLabel ggLabel;
private JTextField ggTextField;
//材料牌号
private JLabel clphLabel;
private JTextField clphTextField;
//计算结果控件
//总长
private JLabel zcLabel;
private JTextField zcTextField;
//单件长度
private JLabel djcdLabel;
private JTextField djcdTextField;
//单件重量
private JLabel djzlLabel;
private JTextField djzlTextField;
//标准工时
private JLabel bzgsLabel;
private JTextField bzgsTextField;
//辅助工时
private JLabel fzgsLabel;
private JTextField fzgsTextField;
//计算按钮
private JButton calculateButton;
//同步按钮
private JButton syncButton;
//取消按钮
private JButton celButton;
//密度
private String density;
//横截面
private String crossSection;
//辅助时间
private String auxiliaryTime;
//固定时间
private String fixedTime;
//切割时间
private String cuttingTime;
public CalculateDialog(AbstractAIFApplication application,TCComponentMEOPRevision meop) throws TCException {
this.application = application;
this.meop = meop;
this.session = (TCSession) application.getSession();
initUI();
getProperties(this.meop);
}
private JPanel getTopPanel() {
JPanel centerPanel = new JPanel(new PropertyLayout());
centerPanel.add("1.1.left.top",this.zjdLabel);
centerPanel.add("1.2.left.top",this.zjdTextField);
centerPanel.add("2.1.left.top",this.lkcLabel);
centerPanel.add("2.2.left.top",this.lkcTextField);
centerPanel.add("3.1.left.top",this.qdycdLabel);
centerPanel.add("3.2.left.top",this.qdycdTextField);
centerPanel.add("4.1.left.top",this.cdmycdLabel);
centerPanel.add("4.2.left.top",this.cdmycdTextField);
centerPanel.add("5.1.left.top",this.jtycdLabel);
centerPanel.add("5.2.left.top",this.jtycdTextField);
centerPanel.add("6.1.left.top",this.kzljsLabel);
centerPanel.add("6.2.left.top",this.kzljsTextField);
centerPanel.add("7.1.left.top",this.ggLabel);
centerPanel.add("7.2.left.top",this.ggTextField);
centerPanel.add("8.1.left.top",this.clphLabel);
centerPanel.add("8.2.left.top",this.clphTextField);
centerPanel.add("1.3.left.top",this.zcLabel);
centerPanel.add("1.4.left.top",this.zcTextField);
centerPanel.add("2.3.left.top",this.djcdLabel);
centerPanel.add("2.4.left.top",this.djcdTextField);
centerPanel.add("3.3.left.top",this.djzlLabel);
centerPanel.add("3.4.left.top",this.djzlTextField);
centerPanel.add("4.3.left.top",this.bzgsLabel);
centerPanel.add("4.4.left.top",this.bzgsTextField);
centerPanel.add("5.3.left.top",this.fzgsLabel);
centerPanel.add("5.4.left.top",this.fzgsTextField);
centerPanel.add("6.3.left.top",this.calculateButton);
return centerPanel;
}
/**
*
*/
private void setPanelProperties() {
this.zjdLabel = new JLabel("图纸零件轮廓直径D");
this.lkcLabel = new JLabel("图纸零件轮廓长");
this.qdycdLabel = new JLabel("切断用长度");
this.cdmycdLabel = new JLabel("车端面用长度");
this.jtycdLabel = new JLabel("夹头用长度");
this.kzljsLabel = new JLabel("可制零件数");
this.ggLabel = new JLabel("规格");
this.clphLabel = new JLabel("材料牌号");
this.zcLabel = new JLabel("总长");
this.djcdLabel = new JLabel("单件长度");
this.djzlLabel = new JLabel("单件重量");
this.bzgsLabel = new JLabel("标准工时");
this.fzgsLabel = new JLabel("辅助工时");
this.zjdTextField = new JTextField(32);
this.lkcTextField = new JTextField(32);
this.qdycdTextField = new JTextField(32);
this.cdmycdTextField = new JTextField(32);
this.jtycdTextField = new JTextField(32);
this.kzljsTextField = new JTextField(32);
this.ggTextField = new JTextField(32);
this.clphTextField = new JTextField(32);
this.zcTextField = new JTextField(32);
this.djcdTextField = new JTextField(32);
this.djzlTextField = new JTextField(32);
this.bzgsTextField = new JTextField(32);
this.fzgsTextField = new JTextField(32);
this.calculateButton = new JButton("计算");
this.syncButton = new JButton("同步");
this.celButton = new JButton("取消");
}
/**
*
* @return
*/
private JPanel getButtomPanel() {
JPanel bottomPanel = new JPanel(new FlowLayout());
// bottomPanel.add(this.calculateButton);
bottomPanel.add(this.syncButton);
bottomPanel.add(this.celButton);
return bottomPanel;
}
/**
*
*/
private void initUI() {
this.setTitle("材料定额及工时计算");
this.setSize(500, 500);
this.setLayout(new BorderLayout());
setPanelProperties();
JPanel centerPanel = getTopPanel();
JPanel bottomPanel = getButtomPanel();
this.add(centerPanel,BorderLayout.CENTER);
this.add(bottomPanel,BorderLayout.SOUTH);
//添加事件
this.calculateButton.addActionListener(this);
this.syncButton.addActionListener(this);
this.celButton.addActionListener(this);
//放到屏幕中央
UIUtilities.centerToScreen(this);
this.setVisible(true);
}
/**
* MEOP
* @param meop
* @throws TCException
*/
private void getProperties(TCComponentMEOPRevision meop) throws TCException {
String outlineDiameter = meop.getStringProperty("ly6_outlineDiameter");
String outlineLength = meop.getStringProperty("ly6_outlineLength");
String cuttingLength = meop.getStringProperty("ly6_cuttingLength");
String transverseLength = meop.getStringProperty("ly6_transverseLength");
String colletLength = meop.getStringProperty("ly6_colletLength");
String manufacturingQuantity =meop.getStringProperty("ly6_manufacturableQuantity");
String specifications = meop.getStringProperty("ly6_specifications");
String brandNum = meop.getStringProperty("ly6_brandNum");
this.zjdTextField.setText(outlineDiameter != null ? outlineDiameter : "");
this.lkcTextField.setText(outlineLength != null ? outlineLength : "");
this.qdycdTextField.setText(cuttingLength != null ? cuttingLength : "");
this.cdmycdTextField.setText(transverseLength != null ? transverseLength : "");
this.jtycdTextField.setText(colletLength != null ? colletLength : "");
this.kzljsTextField.setText(manufacturingQuantity != null ? manufacturingQuantity : "");
this.ggTextField.setText(specifications != null ? specifications : "");
this.clphTextField.setText(brandNum != null ? brandNum : "");
}
/**
*
* @return
*/
private String calculateTotalLength() {
// 获取各个 TextField 的内容
String lkcText = this.lkcTextField.getText();
String qdycdText = this.qdycdTextField.getText();
String cdmycdText = this.cdmycdTextField.getText();
String kzljsText = this.kzljsTextField.getText();
String jtycdText = this.jtycdTextField.getText();
// 将字符串转换为数值
double lkcValue = Double.parseDouble(lkcText);
double qdycdValue = Double.parseDouble(qdycdText);
double cdmycdValue = Double.parseDouble(cdmycdText);
double kzljsValue = Double.parseDouble(kzljsText);
double jtycdValue = Double.parseDouble(jtycdText);
// 计算结果
double result = (lkcValue + qdycdValue + cdmycdValue) * kzljsValue + jtycdValue;
System.out.println("图纸轮廓长:"+lkcValue+"切断用长度:"+qdycdValue+"车端面用长度:"+cdmycdValue+"可制零件数:"+kzljsValue+"夹头用长度:"+jtycdValue);
return String.valueOf(result);
}
/**
*
* @return
*/
private String calculateSingleLength(){
String zcText = this.zcTextField.getText();
String kzljsText = this.kzljsTextField.getText();
double zcValue = Double.parseDouble(zcText);
double kzljsValue = Double.parseDouble(kzljsText);
if (kzljsValue == 0){
System.out.println("可制零件数 is 0");
}
double result = zcValue / kzljsValue;
System.out.println("总长:"+zcValue+"可制零件数:"+kzljsValue);
return String.valueOf(result);
}
/**
* uidEXCEL
* uiditem
* EXCEL
* @throws Exception
*/
private void getDataset(){
TCPreferenceService preferenceService = session.getPreferenceService();
String itemId = preferenceService.getStringValue("LY6_MEOPTypeTime");
InterfaceAIFComponent[] resultComponents;
try {
resultComponents = session.search("零组件...", new String[] {"零组件 ID"}, new String[] {itemId});
InterfaceAIFComponent component = resultComponents[0];
if (component instanceof TCComponentItem){
TCComponentItem item = (TCComponentItem) component;
//读取item下已发布最新版本规范关系下的MSEXCEL数据集
TCComponentItemRevision[] releasedItemRevisions = item.getReleasedItemRevisions();
int releaseRevNum = releasedItemRevisions.length;
if (releaseRevNum == 0) {
System.out.println("错误:当前对象下不存在发布版本");
}
TCComponentItemRevision tcComponentItemRevision = releasedItemRevisions[releaseRevNum - 1];
//获取当前版本的规范关系下的数据集
TCComponent[] referenceListProperty = tcComponentItemRevision.getReferenceListProperty("IMAN_specification");
if(referenceListProperty.length>0) {
//获取数据集下具体的引用文件
TCComponentTcFile[] tcFiles = ((TCComponentDataset)referenceListProperty[0]).getTcFiles();
File file = tcFiles[0].getFmsFile();
// 根据横截面积获取数据集-excel表中对应的条目数据辅助时间、固定时间、切割时间
FileInputStream fis = new FileInputStream(file);
Workbook workbook = new HSSFWorkbook(fis);
Sheet sheet = workbook.getSheetAt(0);
//从第3条开始逐行数据(前两条是标题和首行栏)
for (int i = 2; i < sheet.getPhysicalNumberOfRows(); i++) {
Row row = sheet.getRow(i);
//获取表中每行的第一个值,即:直径
double diam = row.getCell(0).getNumericCellValue();
// 根据规格匹配数据集表中的直径
if (diam == Double.parseDouble(this.ggTextField.getText())){
System.out.println("=========》直径匹配成功!开始获取辅助工时和标准工时"+"=========》当前行号:"+(i+1)+",当前行的直径:"+diam);
//获取第11列的值标准工时
this.bzgsTextField.setText(row.getCell(10).getStringCellValue());
//获取第12列的值辅助工时
this.fzgsTextField.setText(row.getCell(11).getStringCellValue());
break;
}
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @return
*/
private String calculateAssistTime() {
String result = null;
double kzljsNum = Double.parseDouble(this.kzljsTextField.getText());
if (kzljsNum > 0){
double auxiliaryTimeNum = Double.parseDouble(this.auxiliaryTime);
double fixedTimeNum = Double.parseDouble(this.fixedTime);
double resultNum = Math.round((auxiliaryTimeNum + fixedTimeNum) / kzljsNum / 60 * 100.0) / 100.0;
System.out.println("辅助时间:"+auxiliaryTimeNum+",固定时间:"+fixedTimeNum+",可制零件数:"+kzljsNum);
result = String.valueOf(resultNum);
}
return result;
}
/**
*
* @return
*/
private String calculateStandardTime() {
String result = null;
double kzljsNum = Double.parseDouble(this.kzljsTextField.getText());
if (kzljsNum > 0){
System.out.println("=========>获取到的切割时间:"+this.cuttingTime);
double cuttingTimeNum = Double.parseDouble(this.cuttingTime);
double resultNum = Math.round((cuttingTimeNum / kzljsNum / 60) * 100.0) / 100.0;
System.out.println("切割时间:"+cuttingTimeNum+",可制零件数:"+kzljsNum);
result = String.valueOf(resultNum);
}
return result;
}
/**
*
* @throws TCException
*/
private void getDensityAndCrossSection() throws TCException {
System.out.println("=========>开始获取密度和横截面getDensityAndCrossSection");
// 1.获取当前选中MEOP对象的BOM行
TCComponentMEOP meopItem = (TCComponentMEOP) meop.getItem();
TCComponentBOMWindowType winType = (TCComponentBOMWindowType) this.session.getTypeComponent("BOMWindow");
TCComponentBOMWindow view = winType.create(null);
TCComponentBOMLine bomLine = view.setWindowTopLine(meopItem, meop, null, null);
// 2.遍历BOM行根据“规格”和“材料”检索符合要求的唯一原材料对象
throughBomline(bomLine);
view.close();
}
/**
* bomlinebom
* @param topBomLine BOM
*/
private void throughBomline(TCComponentBOMLine topBomLine) throws TCException{
// 3.获取原材料对象的密度和横截面
boolean hasChildren = topBomLine.hasChildren();
if (hasChildren) {
AIFComponentContext[] childrens = topBomLine.getChildren();
for (AIFComponentContext children : childrens) {
TCComponentBOMLine bomLine = (TCComponentBOMLine) children.getComponent();
//获取当前bom的事例类型若是投料则到当前bom对应的是原材料对象
String propertyValue = bomLine.getProperty("bl_occ_type");
if ("投料".equals(propertyValue)) {
//通过原材料对象获取密度和横截面
this.rawMaterialRevision = bomLine.getItemRevision();
String densityString = rawMaterialRevision.getProperty("ly6_density");
String crossSectionString = rawMaterialRevision.getProperty("ly6_crossSection");
System.out.println("==========》成功取得当前原材料对象对应的密度:"+densityString+",横截面:"+crossSectionString);
this.density = densityString != null ? densityString : "";
this.crossSection = crossSectionString != null ? crossSectionString : "";
break;
}
throughBomline(bomLine);
}
}
}
/**
*
* @return
* @throws TCException
*/
private String calculateWeight(){
//通过获取当前选中对象的bom下关联的原材料对象获取其密度和横截面
try {
getDensityAndCrossSection();
} catch (TCException e) {
e.printStackTrace();
}
//获取横截面和密度、单件长度,计算单件重量
double crossSectionNum = Double.parseDouble(this.crossSection);
double densityNum = Double.parseDouble(this.density);
double siglengthNum = Double.parseDouble(this.djcdTextField.getText());
double result = crossSectionNum * densityNum * siglengthNum;
System.out.println("横截面:"+crossSectionNum+",密度:"+densityNum+",单件长度:"+siglengthNum);
return String.valueOf(result);
}
/**
*
* @throws TCException
*/
private void saveProperty() throws TCException {
try {
meop.setProperty("ly6_specifications", this.ggTextField.getText() == null ? "" : this.ggTextField.getText());
rawMaterialRevision.setProperty("ly6_specifications", this.ggTextField.getText() == null ? "" : this.ggTextField.getText());
meop.setProperty("ly6_totalLenght", this.zcTextField.getText() == null ? "" : this.zcTextField.getText());
meop.setProperty("ly6_singleLength", this.djcdTextField.getText() == null ? "" : this.djcdTextField.getText());
meop.setProperty("ly6_weight", this.djzlTextField.getText() == null ? "" : this.djzlTextField.getText());
meop.setProperty("ly6_standardTime", this.bzgsTextField.getText() == null ? "" : this.bzgsTextField.getText());
meop.setProperty("ly6_auxiliaryTime", this.fzgsTextField.getText() == null ? "" : this.fzgsTextField.getText());
rawMaterialRevision.setProperty("ly6_material", this.clphTextField.getText() == null ? "" : this.clphTextField.getText());
meop.setProperty("ly6_brandNum", this.clphTextField.getText() == null ? "" : this.clphTextField.getText());
meop.setProperty("ly6_outlineDiameter", this.zjdTextField.getText() == null ? "" : this.zjdTextField.getText());
meop.setProperty("ly6_outlineLength", this.lkcTextField.getText() == null ? "" : this.lkcTextField.getText());
meop.setProperty("ly6_cuttingLength", this.qdycdTextField.getText() == null ? "" : this.qdycdTextField.getText());
meop.setProperty("ly6_transverseLength", this.cdmycdTextField.getText()== null ? "" : this.cdmycdTextField.getText());
meop.setProperty("ly6_colletLength", this.jtycdTextField.getText() == null ? "" : this.jtycdTextField.getText());
meop.setProperty("ly6_manufacturableQuantity", this.kzljsTextField.getText() == null ? "" : this.kzljsTextField.getText());
}catch (Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
/**
* M
* @throws TCException
*/
private void checkMaterial() throws TCException {
try {
System.out.println("开始检查M物料下的挂载情况·········");
boolean isGZ=false;
TCComponent[] whereUsed = meop.whereUsed((short) 0);
for (TCComponent tcComponent : whereUsed) {
//获取到当前工序对象的父级对象-tcComponent
String mepRevisionType = tcComponent.getStringProperty("object_type");
//获取首选项中的工艺对象类型,进行匹配
TCSession session = (TCSession) this.application.getSession();
TCPreferenceService preferenceService = session.getPreferenceService();
//根据首选项的名称-C8MyPreference,获取首选项值
String value = preferenceService.getStringValue("LY6_MEPType");
String[] strings = value.split(",");
for (int i = 0; i < whereUsed.length; i++) {
//工艺对象类型匹配,进行:原材料对象比对
if (strings[i].equals(mepRevisionType)) {
System.out.println("========>工艺类型匹配成功");
if (tcComponent instanceof TCComponentItemRevision) {
System.out.println("====>获取到的工艺对象:"+tcComponent.getObjectString());
TCComponentItemRevision mepRevision = (TCComponentItemRevision) tcComponent;
//获取工艺对象下的物料/制造对象:relatedRevision\\relatedItem
TCComponent relatedComponent = mepRevision.getRelatedComponent("IMAN_METarget");
TCComponentItemRevision relatedRevision = (TCComponentItemRevision) relatedComponent;
TCComponentItem relatedItem = relatedRevision.getItem();
//检查当前物料对象下是否挂在了原材料对象
TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow view = winType.create(null);
//获取物料对象/制造对象对应的bomline
TCComponentBOMLine bomLine = view.setWindowTopLine(relatedItem, relatedRevision, null, null);
//遍历该物料制造对象的bomline下是否挂在了原材料对象
if (bomLine.hasChildren()) {
AIFComponentContext[] childrens = bomLine.getChildren();
for(AIFComponentContext children:childrens) {
TCComponentBOMLine childrenBomLine = (TCComponentBOMLine) children.getComponent();
TCComponentItemRevision itemRevision = childrenBomLine.getItemRevision();
String uidTag = itemRevision.getUid();
String materialRevUid = this.rawMaterialRevision.getUid();
if (uidTag.equals(materialRevUid)) {
System.out.println("M物料对象下已经挂载原材料对象············");
//M物料对象下挂载了原材料对象
isGZ = true;
break;
}
}
}
//M物料对象下没有挂载原材料对象
if (!isGZ) {
System.out.println("M物料对象下没有挂载原材料对象开始挂载······");
view.lock();
TCComponentItem materialItem = this.rawMaterialRevision.getItem();
bomLine.add(materialItem,this.rawMaterialRevision,null,false,"");
bomLine.save();
view.unlock();
}
// BOMWindow用完后必须关闭
view.close();
}else {
System.out.println("非版本对象异常");
}
break;
}
}
}
}catch (Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
}
}
/**
*
*/
@Override
public void actionPerformed(ActionEvent e) {
Object sourceObject = e.getSource();
//如果点击“计算”按钮
if(sourceObject.equals(this.calculateButton)) {
try {
//长度计算
this.zcTextField.setText(calculateTotalLength());
this.djcdTextField.setText(calculateSingleLength());
// 单件重量计算
this.djzlTextField.setText(calculateWeight());
// 工时计算
getDataset();
// this.bzgsTextField.setText(calculateStandardTime());
// this.fzgsTextField.setText(calculateAssistTime());
}catch (Exception e1){
MessageBox.post("计算失败,请检查属性或手动维护", "提示", MessageBox.ERROR);
}
} else if (sourceObject.equals(this.syncButton)) {
//如果点击“同步”按钮,属性反写
try {
saveProperty();
//检查M物料
checkMaterial();
MessageBox.post("同步成功", "结果", MessageBox.INFORMATION);
this.setVisible(false);
this.dispose();
} catch (TCException e1) {
e1.printStackTrace();
}
}else {
//如果点击“取消”按钮
//关闭
this.setVisible(false);
//释放
this.dispose();
}
}
}

@ -0,0 +1,84 @@
package com.langtech.plm.calculateMaterialsAndWork;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentMEOP;
import com.teamcenter.rac.kernel.TCComponentMEOPRevision;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import java.sql.SQLOutput;
public class CalculateHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
try {
new Thread(){
@Override
public void run() {
// TODO 1.获取选中对象类型和工序名称
//获取选中对象的拼接字符串
InterfaceAIFComponent selectComponent = app.getTargetContext().getComponent();
// 获取选中对象的类型和名称
String type = selectComponent.getType();
String name;
boolean existTag = false;
try {
name = selectComponent.getProperty("object_name");
// 2.获取首选项字符串数组,并遍历比较(当前选中对象的类型+工序名称拼接字符串)
TCPreferenceService preferenceService = session.getPreferenceService();
//根据首选项的名称-C8MyPreference,获取首选项值
String[] preferenceValues = preferenceService.getStringValues("LY6_MEOPType");
if (preferenceValues == null) {
MessageBox.post("首选项为空,请先设置首选项!","提示",MessageBox.INFORMATION);
}
for (String string : preferenceValues){
if (type.equals(string)){
existTag = true;
}
}
if (!existTag){
//3.如果和首选项中的值不匹配,则弹出提示框,提示“对象类型不正确”,并返回
MessageBox.post("对象类型不正确","提示",MessageBox.INFORMATION);
}else {
TCComponentMEOPRevision rev = null;
//判断选中对象的是item还是版本item则获取最新版本
if (selectComponent instanceof TCComponentMEOP) {
// System.out.println("当前选中对象为TCComponentMEOP");
TCComponentMEOP meopType = (TCComponentMEOP) selectComponent;
rev = (TCComponentMEOPRevision) meopType.getLatestItemRevision();
}else if (selectComponent instanceof TCComponentMEOPRevision) {
// System.out.println("当前选中对象为TCComponentMEOPRevision");
rev = (TCComponentMEOPRevision) selectComponent;
}
// System.out.println("========》选中的对象类型:"+type);
new CalculateDialog(app,rev);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,41 @@
package com.langtech.plm.calculateMaterialsAndWork;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AbstractAIFSession;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentMEOPType;
import com.teamcenter.rac.kernel.TCSession;
public class TestHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
// TODO Auto-generated method stub
AbstractAIFApplication application = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) application.getSession();
//获取选中对象
InterfaceAIFComponent selectComponent = application.getTargetContext().getComponent();
String type = selectComponent.getType();
try {
String propertyName = selectComponent.getProperty("object_name");
System.out.println("选中对象类型:"+type);
System.out.println("选中对象名称1"+propertyName);
System.out.println("选中对象名称2"+selectComponent.getObjectString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//TCComponentMEOPType
return null;
}
}

@ -0,0 +1,84 @@
package com.langtech.plm.createProjectStruct;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
import javax.swing.tree.TreeCellRenderer;
public class CheckBoxTreeCellRenderer extends JPanel implements TreeCellRenderer
{
protected JCheckBox check;
protected CheckBoxTreeLabel label;
public CheckBoxTreeCellRenderer()
{
setLayout(null);
add(check = new JCheckBox());
add(label = new CheckBoxTreeLabel());
check.setBackground(UIManager.getColor("Tree.textBackground"));
label.setForeground(UIManager.getColor("Tree.textForeground"));
}
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,
boolean hasFocus)
{
String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
setEnabled(tree.isEnabled());
check.setSelected(((CheckBoxTreeNode)value).isSelected());
label.setFont(tree.getFont());
label.setText(stringValue);
label.setSelected(selected);
label.setFocus(hasFocus);
if(leaf)
//label.setIcon(UIManager.getIcon("Tree.leafIcon"));
label.setIcon(UIManager.getIcon("Tree.openIcon"));
else if(expanded)
label.setIcon(UIManager.getIcon("Tree.openIcon"));
else
label.setIcon(UIManager.getIcon("Tree.closedIcon"));
return this;
}
@Override
public Dimension getPreferredSize()
{
Dimension dCheck = check.getPreferredSize();
Dimension dLabel = label.getPreferredSize();
return new Dimension(dCheck.width + dLabel.width, dCheck.height < dLabel.height ? dLabel.height: dCheck.height);
}
@Override
public void doLayout()
{
Dimension dCheck = check.getPreferredSize();
Dimension dLabel = label.getPreferredSize();
int yCheck = 0;
int yLabel = 0;
if(dCheck.height < dLabel.height)
yCheck = (dLabel.height - dCheck.height) / 2;
else
yLabel = (dCheck.height - dLabel.height) / 2;
check.setLocation(0, yCheck);
check.setBounds(0, yCheck, dCheck.width, dCheck.height);
label.setLocation(dCheck.width, yLabel);
label.setBounds(dCheck.width, yLabel, dLabel.width, dLabel.height);
}
@Override
public void setBackground(Color color)
{
if(color instanceof ColorUIResource)
color = null;
super.setBackground(color);
}
}

@ -0,0 +1,75 @@
package com.langtech.plm.createProjectStruct;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
public class CheckBoxTreeLabel extends JLabel
{
private boolean isSelected;
private boolean hasFocus;
public CheckBoxTreeLabel()
{
}
@Override
public void setBackground(Color color)
{
if(color instanceof ColorUIResource)
color = null;
super.setBackground(color);
}
@Override
public void paint(Graphics g)
{
String str;
if((str = getText()) != null)
{
if(0 < str.length())
{
if(isSelected)
g.setColor(UIManager.getColor("Tree.selectionBackground"));
else
g.setColor(UIManager.getColor("Tree.textBackground"));
Dimension d = getPreferredSize();
int imageOffset = 0;
Icon currentIcon = getIcon();
if(currentIcon != null)
imageOffset = currentIcon.getIconWidth() + Math.max(0, getIconTextGap() - 1);
g.fillRect(imageOffset, 0, d.width - 1 - imageOffset, d.height);
if(hasFocus)
{
g.setColor(UIManager.getColor("Tree.selectionBorderColor"));
g.drawRect(imageOffset, 0, d.width - 1 - imageOffset, d.height - 1);
}
}
}
super.paint(g);
}
@Override
public Dimension getPreferredSize()
{
Dimension retDimension = super.getPreferredSize();
if(retDimension != null)
retDimension = new Dimension(retDimension.width + 3, retDimension.height);
return retDimension;
}
public void setSelected(boolean isSelected)
{
this.isSelected = isSelected;
}
public void setFocus(boolean hasFocus)
{
this.hasFocus = hasFocus;
}
}

@ -0,0 +1,85 @@
package com.langtech.plm.createProjectStruct;
import javax.swing.tree.DefaultMutableTreeNode;
public class CheckBoxTreeNode extends DefaultMutableTreeNode {
protected boolean isSelected;
public CheckBoxTreeNode() {
this(null);
}
public CheckBoxTreeNode(Object userObject) {
this(userObject, true, false);
}
public CheckBoxTreeNode(Object userObject, boolean allowsChildren, boolean isSelected) {
super(userObject, allowsChildren);
this.isSelected = isSelected;
}
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean _isSelected) {
this.isSelected = _isSelected;
if (_isSelected) {
// 如果选中,则将其所有的子结点都选中
if (children != null) {
for (Object obj : children) {
CheckBoxTreeNode node = (CheckBoxTreeNode) obj;
if (_isSelected != node.isSelected())
node.setSelected(_isSelected);
}
}
// 向上检查,如果父结点的所有子结点都被选中,那么将父结点也选中
CheckBoxTreeNode pNode = (CheckBoxTreeNode) parent;
// 开始检查pNode的所有子节点是否都被选中
if (pNode != null) {
int index = 0;
for (; index < pNode.children.size(); ++index) {
CheckBoxTreeNode pChildNode = (CheckBoxTreeNode) pNode.children.get(index);
if (!pChildNode.isSelected())
break;
}
/*
* pNode
*/
if (index == pNode.children.size()) {
if (pNode.isSelected() != _isSelected)
pNode.setSelected(_isSelected);
}
}
} else {
/*
*
*
*/
if (children != null) {
int index = 0;
for (; index < children.size(); ++index) {
CheckBoxTreeNode childNode = (CheckBoxTreeNode) children.get(index);
if (!childNode.isSelected())
break;
}
// 从上向下取消的时候
if (index == children.size()) {
for (int i = 0; i < children.size(); ++i) {
CheckBoxTreeNode node = (CheckBoxTreeNode) children.get(i);
if (node.isSelected() != _isSelected)
node.setSelected(_isSelected);
}
}
}
// 向上取消,只要存在一个子节点不是选上的,那么父节点就不应该被选上。
CheckBoxTreeNode pNode = (CheckBoxTreeNode) parent;
/*
* if (pNode != null && pNode.isSelected() != _isSelected)
* pNode.setSelected(_isSelected);
*/
}
}
}

@ -0,0 +1,31 @@
package com.langtech.plm.createProjectStruct;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTree;
import javax.swing.tree.TreePath;
import javax.swing.tree.DefaultTreeModel;
public class CheckBoxTreeNodeSelectionListener extends MouseAdapter
{
@Override
public void mouseClicked(MouseEvent event)
{
JTree tree = (JTree)event.getSource();
int x = event.getX();
int y = event.getY();
int row = tree.getRowForLocation(x, y);
TreePath path = tree.getPathForRow(row);
if(path != null)
{
CheckBoxTreeNode node = (CheckBoxTreeNode)path.getLastPathComponent();
if(node != null)
{
boolean isSelected = !node.isSelected();
node.setSelected(isSelected);
((DefaultTreeModel)tree.getModel()).nodeStructureChanged(node);
}
}
}
}

@ -0,0 +1,250 @@
package com.langtech.plm.createProjectStruct;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashMap;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.tree.DefaultTreeModel;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentFolderType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.services.rac.core.ReservationService;
@SuppressWarnings("serial")
public class CreateProjectStructDialog extends AbstractAIFDialog{
protected TCSession session;
private TCComponent target;
private JLabel modelLabel;
private JComboBox<String> modelBox;
private JTextField nameField;
private JLabel nameLabel;
private JTree jtree;
private JButton okButton;
private JButton celButton;
private HashMap<String, String> preMap = new HashMap<String, String>();
public static final String preName = "connor_LY6_FolderTemp";
public CreateProjectStructDialog(AbstractAIFApplication app) {
super(false);
this.session = (TCSession) app.getSession();
this.target = (TCComponent) app.getTargetComponent();
try {
initUI();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void run() {
try {
initUI();
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
}
private void initUI() throws Exception {
this.setTitle("根据模板创建文件夹");
Dimension dim = new Dimension(950, 600);
this.setPreferredSize(new Dimension(1000, 600));
this.setMinimumSize(dim);
this.setLayout(new BorderLayout());
modelLabel = new JLabel("模板:");
modelBox = new JComboBox<String>();
modelBox.setPreferredSize(new Dimension(200,30));
String[] prefVals = KUtil.getPrefVals(session, preName);
if(prefVals == null) {
MessageBox.post("首选项 " + preName + " 不存在或值为空", "提示 ", MessageBox.INFORMATION);
return;
}
else {
for(String prefVal : prefVals) {
if(prefVal.contains("=")) {
String[] split = prefVal.split("=");
modelBox.addItem(split[0]);
preMap.put(split[0], split[1]);
}
}
}
nameLabel = new JLabel("成品图号:");
nameField = new JTextField();
nameField.setPreferredSize(new Dimension(200,30));
JPanel topPanel = new JPanel();
topPanel.add(modelLabel);
topPanel.add(modelBox);
topPanel.add(nameLabel);
topPanel.add(nameField);
//String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
//String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
String lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
jtree = new JTree();
initTree(jtree);
JScrollPane centerPane = new JScrollPane(jtree);
JPanel buttonPanel = new JPanel();
okButton = new JButton("创建");
celButton = new JButton("取消");
buttonPanel.add(okButton);
buttonPanel.add(celButton);
this.add(BorderLayout.NORTH,topPanel);
this.add(BorderLayout.CENTER,centerPane);
this.add(BorderLayout.SOUTH,buttonPanel);
addListeners();
showDialog();
}
/**
*
* @param tree
*/
private void initTree(JTree tree){
String puid = preMap.get(modelBox.getSelectedItem());
TCComponent component;
try {
component = session.stringToComponent(puid);
if(component == null || !(component instanceof TCComponentFolder)) {
MessageBox.post(puid + " 该puid在TC中不存在对象或者该puid对应的不是文件夹对象", "异常", MessageBox.ERROR);
return;
}
else {
CheckBoxTreeNode rootNode = new CheckBoxTreeNode(component.getStringProperty("object_name"));
buildTree(component,rootNode);
DefaultTreeModel model = new DefaultTreeModel(rootNode);
tree.addMouseListener(new CheckBoxTreeNodeSelectionListener());
tree.setModel(model);
tree.setCellRenderer(new CheckBoxTreeCellRenderer());
//展开所有节点并选中
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
rootNode.setSelected(true);
}
} catch (TCException e) {
e.printStackTrace();
}
}
/**
*
* @param component
* @param rootNode
* @throws TCException
*/
private void buildTree(TCComponent component, CheckBoxTreeNode rootNode) throws TCException {
TCComponent[] relatedComponent = component.getRelatedComponents("contents");
if(relatedComponent != null) {
for (TCComponent child : relatedComponent) {
CheckBoxTreeNode childNode = new CheckBoxTreeNode(child.getStringProperty("object_name"));
rootNode.add(childNode);
buildTree(child,childNode);
}
}
}
/**
*
* @param root
* @param folder
* @param folderType
* @throws Exception
*/
private void createFolderStruct(CheckBoxTreeNode root, TCComponentFolder parentFolder,
TCComponentFolderType folderType,boolean ifTop) throws Exception {
if(root.isSelected()) {
if(ifTop) {
for (int i = 0; i < root.getChildCount(); i++) {
CheckBoxTreeNode child = (CheckBoxTreeNode) root.getChildAt(i);
createFolderStruct(child,parentFolder,folderType,false);
}
}
else {
TCComponentFolder folder = KUtil.createFolderBySOA(folderType.getTypeName(), root.toString());
parentFolder.add("contents", folder);
for (int i = 0; i < root.getChildCount(); i++) {
CheckBoxTreeNode child = (CheckBoxTreeNode) root.getChildAt(i);
createFolderStruct(child,folder,folderType,false);
}
}
}
}
private void addListeners() {
this.celButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
this.okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
if (name.isEmpty()) {
MessageBox.post("请填写成品图号!", "提示 ", MessageBox.INFORMATION);
} else {
TCComponentFolderType folderType;
try {
KUtil.setByPass(true);
folderType = (TCComponentFolderType) session.getTypeComponent("LD6_CusProdFolder");
TCComponentFolder folder = KUtil.createFolderBySOA(folderType.getTypeName(), name);
//TCComponentFolder folder = folderType.create(name, "", "LD6_CusProdFolder");
target.add("contents", folder);
CheckBoxTreeNode root = (CheckBoxTreeNode) jtree.getModel().getRoot();
createFolderStruct(root,folder,(TCComponentFolderType) session.getTypeComponent("LD6_ProjMaFolder"),true);
KUtil.setByPass(false);
disposeDialog();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
});
this.modelBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent event) {
if(event.getStateChange() == ItemEvent.SELECTED) {
//重新刷新树
jtree.setModel(null);
initTree(jtree);
}else if(event.getStateChange() == ItemEvent.DESELECTED){
}
}
});
}
}

@ -0,0 +1,51 @@
package com.langtech.plm.createProjectStruct;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class CreateProjectStructHandler extends AbstractHandler{
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
try {
new Thread() {
@Override
public void run() {
InterfaceAIFComponent targetComponent = app.getTargetComponent();
if(targetComponent instanceof TCComponentFolder) {
new CreateProjectStructDialog(app);
}
else {
MessageBox.post("请选中一个客户文件夹!", "提示 ", MessageBox.INFORMATION);
}
}
}.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,72 @@
package com.langtech.plm.mpart;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
public class CheckHeaderCellRenderer implements TableCellRenderer {
DefaultTableModel tableModel;
JTableHeader tableHeader;
final JCheckBox selectBox;
public CheckHeaderCellRenderer(final JTable table) {
this.tableModel = (DefaultTableModel) table.getModel();
this.tableHeader = table.getTableHeader();
selectBox = new JCheckBox(tableModel.getColumnName(0));
selectBox.setSelected(false);
tableHeader.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 0) {
// 获得选中列
int selectColumn = tableHeader.columnAtPoint(e.getPoint());
if (selectColumn == 0) {
boolean value = !selectBox.isSelected();
selectBox.setSelected(value);
// tableModel.selectAllOrNull(value);
tableHeader.repaint();
if(value) {
for(int i=0;i<table.getRowCount();i++) {
table.setValueAt("1", i, 0);
}
}else {
for(int i=0;i<table.getRowCount();i++) {
table.setValueAt("0", i, 0);
}
}
}
}
}
});
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
// TODO Auto-generated method stub
String valueStr = (String) value;
JLabel label = new JLabel(valueStr);
label.setHorizontalAlignment(SwingConstants.CENTER); // 表头标签剧中
selectBox.setHorizontalAlignment(SwingConstants.CENTER);// 表头标签剧中
selectBox.setBorderPainted(true);
JComponent component = (column == 0) ? selectBox : label;
component.setForeground(tableHeader.getForeground());
component.setBackground(tableHeader.getBackground());
component.setFont(tableHeader.getFont());
component.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return component;
}
}

@ -0,0 +1,139 @@
package com.langtech.plm.mpart;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map.Entry;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
public class ChoosePartDialog extends JFrame implements ActionListener {
private JComboBox<String> objectComboBox;
private JButton okButton = new JButton("确定");
private JButton concelButton = new JButton("取消");
private HashMap<String, String> fieldMap = new HashMap<String, String>();
private String revType = "";
HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
public ChoosePartDialog(JComboBox<String> objectComboBox,AIFDesktop aifDesktop) {
// TODO Auto-generated constructor stub
this.objectComboBox = objectComboBox;
initUI();
}
private void initUI() {
// TODO Auto-generated method stub
try {
this.setTitle("选择BOM");
this.setLayout(new BorderLayout());
JPanel topPanel = getTopPanel();
JPanel btnPanel = getBtnPanel();
this.add(topPanel, BorderLayout.NORTH);
// this.add(pane,BorderLayout.CENTER);
this.add(btnPanel, BorderLayout.SOUTH);
this.setPreferredSize(new Dimension(550, 200));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
int screenWidth = screenSize.width; // 获取屏幕宽度
int screenHeight = screenSize.height; // 获取屏幕高度
int x = (screenWidth - 550) / 2; // 计算Frame的左上角x坐标
int y = (screenHeight - 300) / 2; // 计算Frame的左上角y坐标
this.setLocation(x, y); // 设置Frame的位置
// this.setLocationRelativeTo(null);
this.createActionEvent();
this.pack();
// this.validate();
this.setVisible(true);
// this.setAlwaysOnTop(true);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
// 添加监听
public void createActionEvent() {
this.okButton.addActionListener(this);
this.concelButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
System.out.println("source==>+" + source);
if (this.okButton.equals(source)) {
this.dispose();
} else if (this.concelButton.equals(source)) {
this.dispose();
}
}
private JPanel getBtnPanel() {
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.add("1.1.center", new JLabel(""));
topPanel.add("2.1.center", new JLabel(" "));
topPanel.add("2.2.center", okButton);
topPanel.add("2.3.center", new JLabel(""));
topPanel.add("2.4.center", concelButton);
return topPanel;
}
// 查询部分
private JPanel getTopPanel() {
// TODO Auto-generated method stub
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
topPanel.add("1.1.left.center", new JLabel(""));
topPanel.add("2.1.left.center", new JLabel(""));
topPanel.add("3.1.left.center", new JLabel(""));
topPanel.add("4.1.left.center", new JLabel(""));
topPanel.add("5.1.left.center", new JLabel(""));
topPanel.add("6.1.left.center", new JLabel(""));
topPanel.add("7.1.left.center", new JLabel("选择属性来源对象:"));
topPanel.add("7.2.left.center", objectComboBox);
return topPanel;
}
}

@ -0,0 +1,50 @@
package com.langtech.plm.mpart;
import javax.swing.*;
import com.sun.scenario.effect.impl.hw.d3d.D3DShaderSource;
import com.teamcenter.rac.util.MessageBox;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedHashMap;
public class DialogFrame extends JDialog {
private JComboBox<String> comboBox;
private Object syncObject;
public DialogFrame(JFrame owner,JComboBox<String> comboBox,ArrayList<String> list) {
super(owner, "Dialog Window", true); // 模态对话框
this.comboBox = comboBox;
this.syncObject = syncObject;
JButton button = new JButton("确定");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedItem =(String) comboBox.getSelectedItem();
if(selectedItem == null || selectedItem.isEmpty()) {
MessageBox.post("请选择数据!", "提示 ", MessageBox.INFORMATION);
}else {
System.out.println("Selected Item: " + selectedItem);
list.add(selectedItem);
dispose(); // 关闭对话框
}
}
});
this.setPreferredSize(new Dimension(300,100));
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(new JLabel("请选择:"));
panel.add(comboBox);
panel.add(button);
this.add(panel);
this.pack();
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(owner); // 居中显示
}
}

@ -0,0 +1,95 @@
package com.langtech.plm.mpart;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class MainFrame extends JFrame {
private JTextField textField;
private Object syncObject = new Object();
public MainFrame() {
super("Main Window");
textField = new JTextField(20);
JButton button = new JButton("Open Dialog");
ArrayList<String> childrenList = new ArrayList<String>();
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// 创建并显示模态对话框
JComboBox<String> a = new JComboBox<String>();
a.addItem("1");
System.out.println("0");
System.out.println(syncObject);
for (int i = 0; i < 5; i++) {
DialogFrame dialog = new DialogFrame(MainFrame.this,a,childrenList);
dialog.setVisible(true);
// 等待对话框关闭后执行的操作
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosed(java.awt.event.WindowEvent e) {
System.out.println("21121212");
}
});
}
System.out.println("2");
System.out.println(childrenList.size());
// DialogFrame dialog = new DialogFrame(MainFrame.this,a,syncObject);
// dialog.setVisible(true);
// // 等待对话框关闭后执行的操作
// dialog.addWindowListener(new java.awt.event.WindowAdapter() {
// @Override
// public void windowClosed(java.awt.event.WindowEvent e) {
//
// System.out.println("1");
// }
// });
// System.out.println("2");
// synchronized (syncObject) {
//
// try {
// // Wait until notified
// System.out.println("4");
// syncObject.wait();
//
// } catch (InterruptedException ex) {
// Thread.currentThread().interrupt(); // Restore interrupted status
// System.err.println("Thread was interrupted.");
// }
// System.out.println("2");
//
// }
System.out.println("3");
}
});
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(textField);
panel.add(button);
this.add(panel);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null); // 居中显示
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
MainFrame frame = new MainFrame();
frame.setVisible(true);
});
}
}

@ -0,0 +1,931 @@
package com.langtech.plm.mpart;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentGroup;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
import k.util.KOrgDialog;
public class MpartDialog extends JFrame implements ActionListener {
private TCSession session;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private ArrayList<TCComponentItemRevision> list;
private JTextField find = new JTextField();
private JTextField replace = new JTextField();
private JButton xrButton = new JButton("选人");
private JButton createButton = new JButton("Mpart创建任务分工");
private JButton viewlButton = new JButton("查看已有M");
private JTable t_part;
private JComboBox<String> gsdwComboBox = new JComboBox<String>();
protected DefaultTableModel tm_part;
public static final String[] HEADER = new String[] { "","序号", "ID", "名称", "件号", "是否自制", "是否存在M", "归属单位", "工艺小组", "责任人"};
public static final int[] HEADERWIDTH = new int[] { 30,40, 60, 120, 100, 60, 60, 60, 60, 100};
private JTable t_part2;
protected DefaultTableModel tm_part2;
public static final String[] HEADER2 = new String[] {"序号", "对象"};
public static final int[] HEADERWIDTH2 = new int[] {10, 60};
private ArrayList<ArrayList<Object>> valueList = new ArrayList<ArrayList<Object>>();
private HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
private ArrayList<TCComponentItemRevision> table2RevList = new ArrayList<TCComponentItemRevision>();
TCComponentBOMWindowType viewType;
TCComponentBOMWindow view;
TCComponentItemType type;
private String[] groupSplit;
public MpartDialog(TCSession session, ArrayList<TCComponentItemRevision> list) throws TCException {
// TODO Auto-generated constructor stub
this.session = session;
this.list = list;
viewType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
view = viewType.create(null);
type = (TCComponentItemType) session.getTypeComponent("LY6_ProductM");
initUI();
}
private void initUI() {
// TODO Auto-generated method stub
try {
gsdwComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
String selectedItem = (String) gsdwComboBox.getSelectedItem();
System.out.println("Selected Item: " + selectedItem);
// 在这里可以执行其他操作
int count = 0;
for(int i=0;i<tm_part.getRowCount();i++) {
if(tm_part.getValueAt(i, 0).toString().equals("1")) {
tm_part.setValueAt(selectedItem, i, 7);
count++;
}
if(count == 0) {
MessageBox.post("请勾选数据!", "提示 ", MessageBox.INFORMATION);
return;
}
}
}
}
});
find.setPreferredSize(new Dimension(200,30));
replace.setPreferredSize(new Dimension(200,30));
this.setTitle("Mpart界面");
this.setLayout(new BorderLayout());
JPanel topPanel = getTopPanel();
JPanel btnPanel = getBtnPanel();
this.add(topPanel, BorderLayout.NORTH);
// this.add(pane,BorderLayout.CENTER);
this.add(btnPanel, BorderLayout.SOUTH);
this.setPreferredSize(new Dimension(1400, 730));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
int screenWidth = screenSize.width; // 获取屏幕宽度
int screenHeight = screenSize.height; // 获取屏幕高度
int x = (screenWidth - 1400) / 2; // 计算Frame的左上角x坐标
int y = (screenHeight - 800) / 2; // 计算Frame的左上角y坐标
this.setLocation(x, y); // 设置Frame的位置
// this.setLocationRelativeTo(null);
this.createActionEvent();
this.pack();
// this.validate();
this.setVisible(true);
String groupID = getGroupID();
System.out.println("groupID=========="+groupID);
String factory = "";
//gsdwComboBox.addItem("请选择...");
String[] userCompany = session.getPreferenceService().getStringValues("LY6_UserCompany");
for (int i = 0; i < userCompany.length; i++) {
String[] split = userCompany[i].split("=");
if(split[0].equals(groupID)) {
factory = split[1];
}
}
gsdwComboBox.addItem("");
if(factory != null && !factory.isEmpty()) {
groupSplit = factory.split(";");
for (int j = 0; j < groupSplit.length; j++) {
gsdwComboBox.addItem(groupSplit[j]);
}
}
// this.setAlwaysOnTop(true);
//塞值
//获取当前组
for (int i = 0; i < list.size(); i++) {
ArrayList<Object> tempList = new ArrayList<Object>();
tempList.add(0);
tempList.add(i+1);
TCComponentItemRevision tcComponentItemRevision = list.get(i);
String revId = tcComponentItemRevision.getStringProperty("item_id");
String object_name = tcComponentItemRevision.getStringProperty("object_name");
String ly6_partNum = tcComponentItemRevision.getStringProperty("ly6_partNum");
String ly6_homemadeStatus = tcComponentItemRevision.getStringProperty("ly6_homemadeStatus");
tempList.add(revId);
tempList.add(object_name);
tempList.add(ly6_partNum);
tempList.add(ly6_homemadeStatus);
if(factory != null && !factory.isEmpty()) {
ArrayList<TCComponentItemRevision> mrevList = new ArrayList<TCComponentItemRevision>();
String[] split = factory.split(";");
for (int j = 0; j < split.length; j++) {
TCComponent[] search = session.search("_SearchMFKProperties", new String[] { "ID","工厂" }, new String[] { revId,split[j] });
if(search.length > 0) {
for (int k = 0; k < search.length; k++) {
TCComponentItem item = (TCComponentItem)search[k];
mrevList.add(item.getLatestItemRevision());
}
}
}
if(mrevList.size() <= 0) {
tempList.add("");
tempList.add("");
tempList.add(null);
tempList.add(tcComponentItemRevision);
}else {
tempList.add("存在");
tempList.add("");
tempList.add(mrevList);
tempList.add(tcComponentItemRevision);
}
}else {
tempList.add("");
tempList.add("");
tempList.add(null);
tempList.add(tcComponentItemRevision);
}
System.out.println("tempList.size============"+tempList.size());
valueList.add(tempList);
}
System.out.println("valueList================"+valueList.size());
for (int j = 0; j < valueList.size(); j++) {
ArrayList<Object> arrayList = valueList.get(j);
tm_part.addRow(new Object[] {arrayList.get(0),arrayList.get(1),arrayList.get(2),
arrayList.get(3),arrayList.get(4),arrayList.get(5),arrayList.get(6),
arrayList.get(7),"",""});
}
} catch (Exception e) {
e.printStackTrace();
return;
}
}
// 添加监听
public void createActionEvent() {
this.createButton.addActionListener(this);
this.viewlButton.addActionListener(this);
this.xrButton.addActionListener(this);
this.gsdwComboBox.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
System.out.println("source==>+" + source);
if (this.createButton.equals(source)) {
//判断是否含有子 //循环
int count = 0;
//先循环一遍判断 归属单位 和 责任人
for(int i=0;i<tm_part.getRowCount();i++) {
if(tm_part.getValueAt(i, 0).toString().equals("1")) {
if(tm_part.getValueAt(i, 7) == null || tm_part.getValueAt(i, 7).toString().isEmpty()) {
MessageBox.post("请填写第"+(i+1)+"行归属单位!", "提示 ", MessageBox.INFORMATION);
return;
}
if(tm_part.getValueAt(i, 9) == null || tm_part.getValueAt(i, 9).toString().isEmpty()) {
MessageBox.post("请填写第"+(i+1)+"行责任人!", "提示 ", MessageBox.INFORMATION);
return;
}
count++;
}
}
if(count == 0) {
MessageBox.post("请勾选数据!", "提示 ", MessageBox.INFORMATION);
return;
}
for(int i=0;i<tm_part.getRowCount();i++) {
if(tm_part.getValueAt(i, 0).toString().equals("1")) {
try {
ArrayList<Object> arrayList = valueList.get(i);
TCComponentItemRevision rev = (TCComponentItemRevision)arrayList.get(9);
TCComponentBOMLine topLine = view.setWindowTopLine(rev.getItem(), rev, null, null);
int childrenCount = topLine.getChildrenCount();
System.out.println("childrenCount========"+childrenCount);
TCComponent[] searchLs = session.search("_SearchMFKProperties", new String[] { "ID","工厂" }, new String[] { (String) arrayList.get(2),(String) tm_part.getValueAt(i, 7) });
String ly6_sequenceNum = "";
//去调用查询查看该工厂最大流水
if(searchLs != null && searchLs.length > 0) {
TCComponentItem mItem = (TCComponentItem)searchLs[0];
ly6_sequenceNum = mItem.getStringProperty("ly6_sequenceNum");
System.out.println("ly6_sequenceNum==="+ly6_sequenceNum);
}
if(childrenCount == 0) {
//直接创建对象
String newID = (String) arrayList.get(2);
String newRev = type.getNewRev(null);
TCComponentItem item = type.create(newID, newRev, "LY6_ProductM", "", "", null);
item.setProperty("ly6_company", tm_part.getValueAt(i, 7).toString());
if(ly6_sequenceNum.isEmpty()) {
item.setProperty("ly6_sequenceNum", "01");
}else {
item.setProperty("ly6_sequenceNum", incrementNumber(ly6_sequenceNum));
}
//把对象放到管理文件夹下
rev.add("LY6_relatedMPart",item);
}else {
AIFComponentContext[] children = topLine.getChildren();
//直接创建对象
String newID = (String) arrayList.get(2);
String newRev = type.getNewRev(null);
TCComponentItem item = type.create(newID, newRev, "LY6_ProductM", "", "", null);
item.setProperty("ly6_company", tm_part.getValueAt(i, 7).toString());
if(ly6_sequenceNum.isEmpty()) {
item.setProperty("ly6_sequenceNum", "01");
}else {
item.setProperty("ly6_sequenceNum", incrementNumber(ly6_sequenceNum));
}
//把对象放到管理文件夹下
rev.add("LY6_relatedMPart",item);
//搭建mBOM
TCComponentBOMWindowType viewType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow view = viewType.create(null);
TCComponentBOMLine mTopLine = view.setWindowTopLine(item, item.getLatestItemRevision(), null, null);
ArrayList<TCComponentItemRevision> addList = new ArrayList<TCComponentItemRevision>();//mbom的子
ArrayList<String> childrenList = new ArrayList<String>();//下拉框选中的值
HashMap<String, TCComponentItemRevision> revMap = new HashMap<String, TCComponentItemRevision>();//object_String 和对应版本
for (int j = 0; j < children.length; j++) {
TCComponentBOMLine eLine = (TCComponentBOMLine) children[j].getComponent();
//判断是否自制
TCComponentItemRevision eRev = eLine.getItemRevision();
String tcProperty = eRev.getTCProperty("ly6_homemadeStatus").toString();
System.out.println("ly6_homemadeStatus======="+tcProperty);
String eId = eRev.getStringProperty("item_id");
if(tcProperty.equals("自制")) {
//判断e下面的m是否唯一
ArrayList<TCComponentItemRevision> tempMrevList = new ArrayList<TCComponentItemRevision>();
for (int k = 0; k < groupSplit.length; k++) {
TCComponent[] search = session.search("_SearchMFKProperties", new String[] { "ID","工厂" }, new String[] { eId,groupSplit[k] });
for (int l = 0; l < search.length; l++) {
TCComponentItem tempItem = (TCComponentItem)search[l];
tempMrevList.add(tempItem.getLatestItemRevision());
}
}
if(tempMrevList.size() == 0) {
MessageBox.post(eId+"对象未创建MPart", "提示 ", MessageBox.INFORMATION);
return;
}else if(tempMrevList.size() == 1) {
//把M放bom下
addList.add(tempMrevList.get(0));
}else if(tempMrevList.size() > 1) {
//让用户选一个M放bom下
JComboBox<String> jComboBox = new JComboBox<String>();
for (int k = 0; k < tempMrevList.size(); k++) {
String stringProperty = tempMrevList.get(k).getStringProperty("object_string");
revMap.put(stringProperty, tempMrevList.get(k));
jComboBox.addItem(stringProperty);
}
// 创建并显示模态对话框
DialogFrame dialog = new DialogFrame(MpartDialog.this,jComboBox,childrenList);
dialog.setVisible(true);
// 等待对话框关闭后执行的操作
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosed(java.awt.event.WindowEvent e) {
}
});
}
}else {
//不为自制则直接将EPart搭建进入MBOM中
addList.add(eRev);
}
}
System.out.println("childrenList.size()======="+childrenList.size());
for (int j = 0; j < childrenList.size(); j++) {
addList.add(revMap.get(childrenList.get(j)));
}
System.out.println("addList.size()============"+addList.size());
for (int j = 0; j < addList.size(); j++) {
mTopLine.add(addList.get(j).getItem(), addList.get(j), null, false, "");
}
mTopLine.save();
view.save();
view.close();
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
MessageBox.post("创建成功!", "提示 ", MessageBox.INFORMATION);
} else if (this.viewlButton.equals(source)) {
//打开对象到结构管理器
System.out.println("选中的行==="+t_part2.getSelectedRow());
if(t_part2.getSelectedRow() == -1) {
MessageBox.post("请在右表选择想要打开的对象行!", "提示 ", MessageBox.INFORMATION);
return;
}else {
if(table2RevList != null && table2RevList.size() > 0) {
ArrayList<Object> arrayList = valueList.get(t_part.getSelectedRow());
Object object = arrayList.get(8);
com.teamcenter.rac.common.Activator.getDefault()
.openPerspective("com.teamcenter.rac.pse.PSEPerspective");
try {
com.teamcenter.rac.common.Activator.getDefault().openComponents(
"com.teamcenter.rac.pse.PSEPerspective",
new InterfaceAIFComponent[] {table2RevList.get(t_part2.getSelectedRow()).getItem() });
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}else if(this.xrButton.equals(source)) {
TCComponentUser user = new KOrgDialog("").getUser();
System.out.println("Select User: " + user);
String userName = "";
try {
userName = user.getUserName();
} catch (TCException e1) {
// TODO Auto-generated catch block
MessageBox.post("请选择用户!", "提示 ", MessageBox.INFORMATION);
return;
}
int count = 0;
for(int i=0;i<tm_part.getRowCount();i++) {
if(tm_part.getValueAt(i, 0).toString().equals("1")) {
tm_part.setValueAt(userName, i, 9);
count++;
}
if(count == 0) {
MessageBox.post("请勾选数据!", "提示 ", MessageBox.INFORMATION);
return;
}
}
}
}
private JPanel getBtnPanel() {
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.add("1.1.center", new JLabel(" "));
topPanel.add("2.1.center", xrButton);
topPanel.add("2.2.center", new JLabel(" "));
topPanel.add("2.3.center", new JLabel("归属单位:"));
topPanel.add("2.4.center", new JLabel(" "));
topPanel.add("2.5.center", gsdwComboBox);
topPanel.add("2.6.center", new JLabel(" "));
topPanel.add("2.7.center", createButton);
topPanel.add("2.8.center", new JLabel(" "));
topPanel.add("2.9.center", viewlButton);
topPanel.add("3.1.center", new JLabel(" "));
return topPanel;
}
// 查询部分
private JPanel getTopPanel() {
// TODO Auto-generated method stub
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
topPanel.add(getTablePanel(),BorderLayout.WEST);
topPanel.add(getTablePanel2(),BorderLayout.CENTER);
return topPanel;
}
private JPanel getTablePanel() {
JPanel panel = new JPanel(new BorderLayout());
panel.setPreferredSize(new Dimension(1100, 600));
tm_part = new DefaultTableModel();
t_part = new JTable(tm_part) {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int column) {
//非自制不可编辑
String value = (String) getValueAt(row, 5);
System.out.println("value=========="+value);
if(value.equals("自制")) {
if (column == 0 || column == 5) {// 可编辑的列
return true;
}
else {
return false;
}
}else {
return false;
}
}
};
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// 添加鼠标监听器
t_part.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("2222222222222222222222222222222222222222222222222222222");
if (e.getClickCount() == 2 || e.getClickCount() == 1) {
// TODO Auto-generated method stub
int selectColumn = t_part.getTableHeader().columnAtPoint(e.getPoint());
int selectedRow = t_part.rowAtPoint(e.getPoint());
if(selectColumn != 0)
{
t_part2.removeAll();
tm_part2.setRowCount(0);
table2RevList.clear();
ArrayList<Object> arrayList = valueList.get(selectedRow);
Object object = arrayList.get(8);
System.out.println("11111111111111111111111111111111");
if(object != null) {
ArrayList<TCComponentItemRevision> tempList = (ArrayList<TCComponentItemRevision>)object;
for (int i = 0; i < tempList.size(); i++) {
table2RevList.add(tempList.get(i));
}
System.out.println("tempList======"+tempList.size());
for (int i = 0; i < tempList.size(); i++) {
TCComponentItemRevision tcComponentItemRevision = tempList.get(i);
try {
String id = tcComponentItemRevision.getStringProperty("item_id");
System.out.println("item_id======"+id);
String objectName = tcComponentItemRevision.getStringProperty("object_string");
tm_part2.addRow(new Object[] {i+1,objectName});
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}else {
Object valueAt = t_part.getValueAt(selectedRow, selectColumn);
if(valueAt.toString().equals("1")) {
t_part.setValueAt("0", selectedRow, selectColumn);
}else {
t_part.setValueAt("1", selectedRow, selectColumn);
}
}
}
}
});
}
});
// t_part.addMouseListener(new MouseListener() {
//
// @Override
// public void mouseReleased(MouseEvent e) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void mousePressed(MouseEvent e) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void mouseExited(MouseEvent e) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void mouseEntered(MouseEvent e) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void mouseClicked(MouseEvent e) {
// // TODO Auto-generated method stub
// int selectColumn = t_part.getTableHeader().columnAtPoint(e.getPoint());
// int selectedRow = t_part.rowAtPoint(e.getPoint());
//
// if(selectColumn != 0)
// {
// t_part2.removeAll();
// tm_part2.setRowCount(0);
// table2RevList.clear();
// ArrayList<Object> arrayList = valueList.get(selectedRow);
// Object object = arrayList.get(8);
// System.out.println("11111111111111111111111111111111");
// if(object != null) {
//
// ArrayList<TCComponentItemRevision> tempList = (ArrayList<TCComponentItemRevision>)object;
// for (int i = 0; i < tempList.size(); i++) {
// table2RevList.add(tempList.get(i));
// }
// System.out.println("tempList======"+tempList.size());
// for (int i = 0; i < tempList.size(); i++) {
// TCComponentItemRevision tcComponentItemRevision = tempList.get(i);
// try {
// String id = tcComponentItemRevision.getStringProperty("item_id");
// System.out.println("item_id======"+id);
// String objectName = tcComponentItemRevision.getStringProperty("object_name");
// tm_part2.addRow(new Object[] {i+1,id+"_"+objectName});
// } catch (TCException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
// }
// }
// }else {
// Object valueAt = t_part.getValueAt(selectedRow, selectColumn);
// if(valueAt.toString().equals("1")) {
// t_part.setValueAt("0", selectedRow, selectColumn);
// }else {
// t_part.setValueAt("1", selectedRow, selectColumn);
// }
// }
// }
// });
tm_part.setDataVector(null, HEADER);
t_part.getTableHeader().setReorderingAllowed(false); // 设置列不可移动,否则会发生类型转换错误(第三列)
this.t_part.setRowHeight(30);
TableColumnModel colModel = this.t_part.getColumnModel();
int colCnt = HEADERWIDTH.length;
for (int i = 0; i < colCnt; i++) {
colModel.getColumn(i).setPreferredWidth(HEADERWIDTH[i]);
}
t_part.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(t_part));
t_part.getColumnModel().getColumn(0).setCellRenderer(new TableCellCheckboxRenderer(t_part));
// 获取首选项值
// String[] ld_taskNature = session.getPreferenceService().getStringValues("ld_taskNature");// 任务性质
// String[] ld_taskDifficulty = session.getPreferenceService().getStringValues("ld_taskDifficulty");// 难易程度
// String[] ld_urgency = session.getPreferenceService().getStringValues("ld_urgency");// 紧急程度
//
// Map<String, Double> ld_taskNatureMap = new HashMap<String, Double>();
// Map<String, Double> ld_taskDifficultyMap = new HashMap<String, Double>();
// Map<String, Double> ld_urgencyMap = new HashMap<String, Double>();
// 塞下拉框值
// for (int i = 0; i < ld_taskNature.length; i++) {
// String[] split = ld_taskNature[i].split("=");
// ld_taskNatureMap.put(split[0], Double.parseDouble(split[1]));
// jComboBox1.addItem(split[0]);
// }
//
// for (int i = 0; i < ld_taskDifficulty.length; i++) {
// String[] split = ld_taskDifficulty[i].split("=");
// ld_taskDifficultyMap.put(split[0], Double.parseDouble(split[1]));
// jComboBox2.addItem(split[0]);
// }
//
// for (int i = 0; i < ld_urgency.length; i++) {
// String[] split = ld_urgency[i].split("=");
// ld_urgencyMap.put(split[0], Double.parseDouble(split[1]));
// jComboBox3.addItem(split[0]);
// }
//
// // 添加鼠标监听器
// t_part.addMouseListener(new MouseAdapter() {
// @Override
// public void mouseClicked(MouseEvent e) {
// if (e.getClickCount() == 2 && t_part.columnAtPoint(e.getPoint()) == 2) { // 判断是否双击并且是在第二列
// int row = t_part.rowAtPoint(e.getPoint());
// int column = t_part.columnAtPoint(e.getPoint());
// if (column == 2) {
// // 获取被双击的单元格的数据
// String value = (String) t_part.getModel().getValueAt(row, column);
// // 在这里处理双击事件
// System.out.println("Double-clicked on cell: Row=" + row + ", Column=" + column + ", Value=" + value);
// // 这里可以添加更多的逻辑来处理双击事件
//
// }
//
// }
// }
// });
//this.t_part.getTableHeader().setBackground(Color.blue);
JScrollPane scroll = new JScrollPane(t_part);
panel.add(BorderLayout.CENTER, scroll);
panel.setBorder(BorderFactory.createLoweredBevelBorder());
return panel;
}
private JPanel getTablePanel2() {
JPanel panel = new JPanel(new BorderLayout());
panel.setPreferredSize(new Dimension(200, 600));
tm_part2 = new DefaultTableModel();
t_part2 = new JTable(tm_part2) {
/**
*
*/
@Override
public boolean isCellEditable(int row, int column) {
if (column == 0) {// 可编辑的列
return true;
}
else {
return false;
}
}
};
tm_part2.setDataVector(null, HEADER2);
t_part2.getTableHeader().setReorderingAllowed(false); // 设置列不可移动,否则会发生类型转换错误(第三列)
this.t_part2.setRowHeight(23);
TableColumnModel colModel = this.t_part2.getColumnModel();
int colCnt = HEADERWIDTH2.length;
for (int i = 0; i < colCnt; i++) {
colModel.getColumn(i).setPreferredWidth(HEADERWIDTH2[i]);
}
//t_part2.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(t_part2));
//t_part2.getColumnModel().getColumn(0).setCellRenderer(new TableCellCheckboxRenderer(t_part2));
// t_part2.addMouseListener(new MouseListener() {
//
// @Override
// public void mouseReleased(MouseEvent e) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void mousePressed(MouseEvent e) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void mouseExited(MouseEvent e) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void mouseEntered(MouseEvent e) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void mouseClicked(MouseEvent e) {
// // TODO Auto-generated method stub
// int selectColumn = t_part2.getTableHeader().columnAtPoint(e.getPoint());
// int selectedRow = t_part2.rowAtPoint(e.getPoint());
//// System.out.println("selectColumn==>"+selectColumn);
// if(selectColumn != 0)
// {
// return;
// }else {
// Object valueAt = t_part2.getValueAt(selectedRow, selectColumn);
// if(valueAt.toString().equals("1")) {
// t_part2.setValueAt("0", selectedRow, selectColumn);
// }else {
// t_part2.setValueAt("1", selectedRow, selectColumn);
// }
// }
// }
// });
// 设置第一列的单元格渲染器和编辑器
//
// // 添加鼠标监听器
// t_part.addMouseListener(new MouseAdapter() {
// @Override
// public void mouseClicked(MouseEvent e) {
// if (e.getClickCount() == 2 && t_part.columnAtPoint(e.getPoint()) == 2) { // 判断是否双击并且是在第二列
// int row = t_part.rowAtPoint(e.getPoint());
// int column = t_part.columnAtPoint(e.getPoint());
// if (column == 2) {
// // 获取被双击的单元格的数据
// String value = (String) t_part.getModel().getValueAt(row, column);
// // 在这里处理双击事件
// System.out.println("Double-clicked on cell: Row=" + row + ", Column=" + column + ", Value=" + value);
// // 这里可以添加更多的逻辑来处理双击事件
//
// }
//
// }
// }
// });
// this.t_part2.getTableHeader().setBackground(Color.blue);
JScrollPane scroll = new JScrollPane(t_part2);
panel.add(BorderLayout.CENTER, scroll);
panel.setBorder(BorderFactory.createLoweredBevelBorder());
return panel;
}
public String getGroupID() throws TCException {
TCComponentGroup group = session.getCurrentGroup();
String name = group.getTCProperty("name").getStringValue();
return name;
}
/**
* 1011
*
* @param numberStr "01", "02", ..., "10"
* @return 1
*/
public String incrementNumber(String numberStr) {
// 验证输入字符串是否符合预期格式
if (!numberStr.matches("^0[1-9]|10$")) {
throw new IllegalArgumentException("Input must be a string representing a number between 01 and 10.");
}
// 将字符串转换为整数
int number = Integer.parseInt(numberStr);
// 对整数加1
number++;
// 格式化输出
String formattedNumber = String.format("%02d", number);
return formattedNumber;
}
}

@ -0,0 +1,67 @@
package com.langtech.plm.mpart;
import java.util.ArrayList;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentSchedule;
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class MpartHandler extends AbstractHandler{
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
try {
new Thread() {
@Override
public void run() {
InterfaceAIFComponent[] targetComponent = app.getTargetComponents();
ArrayList<TCComponentItemRevision> arrayList = new ArrayList<TCComponentItemRevision>();
for (int i = 0; i < targetComponent.length; i++) {
InterfaceAIFComponent component = targetComponent[i];
if(component instanceof TCComponentItemRevision) {
arrayList.add((TCComponentItemRevision)component);
}
}
System.out.println("arrayList.size()==========="+arrayList.size());
if(arrayList.size() > 0) {
try {
new MpartDialog(session,arrayList);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,54 @@
package com.langtech.plm.mpart;
import java.awt.Component;
import java.util.List;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.EventListenerList;
import javax.swing.table.TableCellRenderer;
import com.teamcenter.rac.treetable.JTreeTable;
public class TableCellCheckboxRenderer extends JCheckBox implements
TableCellRenderer {
private List<Integer> processRows;
protected EventListenerList listenerList = new EventListenerList();
protected ChangeEvent changeEvent = new ChangeEvent(this);
//private TestTreeTableModel tableModel;
public List<Integer> getProcessRows() {
return processRows;
}
public void setProcessRows(List<Integer> processRows) {
this.processRows = processRows;
}
public TableCellCheckboxRenderer(final JTable table) {
}
public TableCellCheckboxRenderer(final JTreeTable table) {
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
// TODO Auto-generated method stub
this.setHorizontalAlignment(SwingConstants.CENTER);// ±íÍ·±êÇ©¾çÖÐ
// this.setBorderPainted(true);
if(value != null)
{
this.setSelected(value.toString().equals("1"));
}
else
{
this.setSelected(false);
}
return this;
}
}

@ -1,426 +0,0 @@
package com.langtech.plm.performancemanagement.handlers;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentTcFile;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.FileUtility;
import com.teamcenter.rac.util.MessageBox;
/**
*
*
*
*/
public class TaskFolderMatchingHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
TCComponent target = null;
target = (TCComponent) app.getTargetComponent();
// 选中项目类型,否则报错
String type = target.getType();
if (type.equals("LD6_CusProdFolder") || type.equals("客户成品文件夹")) {
// TODO 换成数据库方式维护
// TCComponent[] workRequest = null;
// try {
// workRequest = session.search("常规...", new String[] { "名称", "类型" }, new String[] { "任务要求表", "xxxx" });
// } catch (Exception e) {
// e.printStackTrace();
// MessageBox.post("查询异常", "", MessageBox.INFORMATION);
// }
// if (workRequest.length == 0) {
// MessageBox.post("系统中没有任务要求表,请导入后重试", "", MessageBox.INFORMATION);
// } else if (workRequest.length > 1) {
//
// MessageBox.post("系统中存在多个任务要求表", "", MessageBox.INFORMATION);
// }
// 检查报表模板是否存在首选项ld_billboards_uid
String ldBillboardsUid = session.getPreferenceService().getStringValue("ld_billboards_uid");
if (!getMessageboxInfo(ldBillboardsUid, "ld_billboards_uid")) {
return null;
}
TCComponent billboard = null;
try {
billboard = session.stringToComponent(ldBillboardsUid);
} catch (TCException e) {
e.printStackTrace();
MessageBox.post("请通知管理员检查首选项ld_billboards_uid是否配置", "", MessageBox.INFORMATION);
return null;
}
if (billboard == null) {
MessageBox.post("请通知管理员检查首选项ld_billboards_uid是否配置", "", MessageBox.INFORMATION);
return null;
}
// 获取岗位系数 难度系数 紧张度系数 要求完成时间公式的首选项
String[] ldPostCoefficient = session.getPreferenceService().getStringValues("ld_postCoefficient");
String[] ldTaskNature = session.getPreferenceService().getStringValues("ld_taskNature");// 难度系数对应的难度系数?
String[] ldUrgency = session.getPreferenceService().getStringValues("ld_urgency");
// 超时配置
String[] ldOvertime = session.getPreferenceService().getStringValues("ld_overtime");// 严重等级:天数区间(整数)[0,0]:扣分系数;一般:(0,1]:1/5;严重:(1,2]:1/3;超严重:(2,3]:1/2;未定义:[3,1000):0.6
// 流程信息配置成 任务包名称=流程名称:审核节点名称
String[] ldProcessReview = session.getPreferenceService().getStringValues("ld_processReview");
if (!getMessageInfo(ldPostCoefficient, "ld_processReview")) {
return false;
}
if (!getMessageInfo(ldTaskNature, "ld_taskNature")) {
return false;
}
if (!getMessageInfo(ldUrgency, "ld_urgency")) {
return false;
}
if (!getMessageInfo(ldProcessReview, "ld_processReview")) {
return false;
}
if (!getMessageInfo(ldOvertime, "ld_overtime")) {
return false;
}
Map<String, String> postCoefficientMap = new HashMap<String, String>();// 岗位,岗位系数
Map<String, String> taskNatureMap = new HashMap<String, String>();// 任务性质,任务系数
Map<String, String> urgencyMap = new HashMap<String, String>();// 紧急程度,紧急程度系数
Map<String, String> processReviewMap = new HashMap<String, String>();// 流程名称,指派的节点名称
Map<String, String> severityIntervalMap = new HashMap<String, String>();// 键:天数区间;值:扣分系数
for (int i = 0; i < ldPostCoefficient.length; i++) {
String value = ldPostCoefficient[i];
postCoefficientMap.put(value.split("=")[0], value.split("=")[0]);
}
for (int i = 0; i < ldTaskNature.length; i++) {
String value = ldTaskNature[i];
taskNatureMap.put(value.split("=")[0], value.split("=")[0]);
}
for (int i = 0; i < ldUrgency.length; i++) {
String value = ldUrgency[i];
urgencyMap.put(value.split("=")[0], value.split("=")[0]);
}
for (int i = 0; i < ldProcessReview.length; i++) {
String value = ldProcessReview[i];
processReviewMap.put(value.split("=")[0], value.split("=")[0]);
}
for (int i = 0; i < ldOvertime.length; i++) {
String dayInterval = ldOvertime[i].split(":")[1];
String severity = ldOvertime[i].split(":")[0];
String point = ldOvertime[i].split(":")[2];
severityIntervalMap.put(dayInterval, point);
}
// 下载报表命名引用和任务要求表的命名引用
String billboardAddress = downLoadFile(billboard);
// TODO 获取工艺结束时间
String targetName = "";
try {
targetName = target.getProperty("object_name");
} catch (TCException e) {
e.printStackTrace();
}
Date processEndTime = getEndTime(targetName);
if (processEndTime == null) {
MessageBox.post("请检查是否设置或者导入相关客户成品文件夹名称和工艺程序结束时间", "", MessageBox.INFORMATION);
return null;
}
// 获取任务包的流程 组织
// 先遍历底层结构
String path = "";
path = targetName;
String link = "/";
List<String> taskPathList = new ArrayList<String>();
Map<String, TCComponent> folderMap = new HashMap<String, TCComponent>();// 键:文件夹层级结构 值:文件夹对象
getAllFolderPath(target, path, link, taskPathList, folderMap);
// 获取首选项Connor_JXFolder
Map<String, List<String>> packageMap = new HashMap<String, List<String>>();
String connorJXFolderPreference = "Connor_JXFolder";
String[] ConnorJXFolders = session.getPreferenceService().getStringValues(connorJXFolderPreference);
if (getMessageInfo(ConnorJXFolders, connorJXFolderPreference)) {
return false;
}
for (int i = 0; i < ConnorJXFolders.length; i++) {
String[] values = ConnorJXFolders[i].split("=");
String[] folders = values[1].split(";");
List<String> folderList = Arrays.asList(folders);
packageMap.put(values[0], folderList);
}
// 读取报表信息
File file = new File(billboardAddress);
XSSFWorkbook workbook = null;
try {
FileInputStream fis = new FileInputStream(file);
workbook = new XSSFWorkbook(fis);
} catch (IOException e) {
e.printStackTrace();
}
XSSFSheet sheet = workbook.getSheet("新品任务分配表");
int rowNum = sheet.getLastRowNum();
for (int i = 1; i < rowNum; i++) {
XSSFRow row = sheet.getRow(i);
String cellBValue = row.getCell(1).getStringCellValue().trim();// 任务包名
List<String> folderList = packageMap.get(cellBValue);
if (folderList != null && folderList.size() > 0) {
String folderPath = folderList.get(0);
TCComponent folder = folderMap.get(folderPath);
String[] properties = new String[] { "object_desc", "任务性质", "难易程度", "紧急程度", "额定业务工时(小时)",
"fnd0AllWorkflows" };
TCProperty[] tcproperties = null;
try {
tcproperties = folder.getTCProperties(properties);
} catch (TCException e) {
e.printStackTrace();
}
// 新品任务要求描述
String objectDesc = tcproperties[0].getStringValue();
String taskNature = tcproperties[1].getDisplayValue();
String difficulty = tcproperties[2].getDisplayValue();
String urgency = tcproperties[3].getDisplayValue();
String ratedBusinessHours = tcproperties[4].getStringValue();
String taskNatureCoefficient = taskNatureMap.get(difficulty);
String urgencyCoefficient = urgencyMap.get(urgency);
String postCoefficient = "";// 待定
// 获取流程信息
String processReview = processReviewMap.get(cellBValue);
String processName = processReview.split(":")[0];
String reviewName = processReview.split(":")[1];
String assignee = "";// 被指派者fnd0Assignee如果流程任务没有经过转发被指派者即流程接受者等同于责任方
String assigner = "";// 指派者fnd0Assigner如果流程任务没有经过转发这个属性没有值可以取被指派者
String assigneeGroup = "";// 被指派者的组
String status = "";// 流程状态
String startData = "";// 流程开始时间
String endDateValue = "";// 流程结束时间
String actualHours = "";// 实际业务工时
String deductPoints = "";// 超时扣分
TCComponent[] workflows = tcproperties[5].getReferenceValueArray();
for (int j = 0; j < workflows.length; j++) {
TCComponent workflow = workflows[j];
try {
String[] workflowProperties = new String[] { "object_name", "fnd0ActuatedInteractiveTsks",
"fnd0EndDate", "fnd0StartDate", "fnd0Status" };
TCProperty[] workflowTcProperties = workflow.getTCProperties(workflowProperties);
String workflowName = workflowTcProperties[0].getDisplayValue();
TCComponent[] reviews = workflowTcProperties[1].getReferenceValueArray();
if (workflowName.equals(processName)) {
for (int k = 0; k < reviews.length; k++) {
TCComponent review = reviews[k];
String typeName = review.getType();
if (typeName.equals("签发")) {// 任务fnd0AliasTaskName;执行者fnd0Performer
// fnd0AssigneeGroupRole owning_group
String[] reviewProperties = new String[] { "fnd0AliasTaskName", "fnd0Performer",
"owning_group", "fnd0Assigner", "fnd0Assignee" };
TCProperty[] reviewTcProperties = review.getTCProperties(reviewProperties);
String aliasTaskName = reviewTcProperties[0].getDisplayValue();
if (aliasTaskName.contains(":")) {
String reviewNodeName = aliasTaskName.split(":")[0];
if (reviewNodeName.equals(reviewName)) {
assignee = reviewTcProperties[4].getDisplayValue();
assigneeGroup = reviewTcProperties[2].getDisplayableValue();
TCProperty assigneeProperty = reviewTcProperties[3];
if (assigneeProperty.getDisplayValue().length() > 0) {
assigner = assigneeProperty.getDisplayValue();
} else {
assigner = assignee;
}
}
}
status = workflowTcProperties[4].getDisplayValue().equals("已完成") ? "已完成"
: "未完成";
endDateValue = workflowTcProperties[2].getDisplayValue();
Date startDate = workflowTcProperties[2].getDateValue();
Date endDate = workflowTcProperties[3].getDateValue();
actualHours = "" + (endDate.getTime() - startDate.getTime()) / 1000 / 3600;
float point = (float) 0.0;
if (status.equals("已完成")) {
ZoneId zoneId = ZoneId.systemDefault();
Instant instantEnd = endDate.toInstant();
Instant instantProcessEnd = processEndTime.toInstant();
LocalDate localEndDate = instantEnd.atZone(zoneId).toLocalDate();
LocalDate localProcessEndDate = instantProcessEnd.atZone(zoneId)
.toLocalDate();
long diff = localEndDate.toEpochDay() - localProcessEndDate.toEpochDay();
String overtimeCoefficient = "";// 扣分系数
postCoefficient = postCoefficientMap.get(assigneeGroup);
for (Map.Entry<String, String> me : severityIntervalMap.entrySet()) {
String interval = me.getKey();
String startDay = interval.split(",")[0];
String endDay = interval.split(",")[1];
boolean condition1 = false;
boolean condition2 = false;
if (startDay.startsWith("[")) {
condition1 = diff >= (Integer
.valueOf(startDay.substring(1, startDay.length() - 1)))
? true
: false;
} else if (startDay.startsWith("(")) {
condition1 = diff > (Integer
.valueOf(startDay.substring(1, startDay.length() - 1)))
? true
: false;
}
if (endDay.endsWith("]")) {
condition2 = diff <= (Integer
.valueOf(endDay.substring(0, endDay.length() - 2))) ? true
: false;
} else if (startDay.startsWith(")")) {
condition2 = diff < (Integer
.valueOf(endDay.substring(0, endDay.length() - 2))) ? true
: false;
}
if (condition1 == true && condition2 == true) {
overtimeCoefficient = me.getValue();
} else {
continue;
}
}
if (!overtimeCoefficient.equals("")) {
point = 1 * Float.valueOf(overtimeCoefficient)
* Float.valueOf(taskNatureCoefficient)
* Float.valueOf(urgencyCoefficient);// TODO 公式待定,尤其时任务性质和难度系数
}
}
}
}
}
} catch (TCException e) {
e.printStackTrace();
}
}
} else {
continue;
}
}
} else {
MessageBox.post("请选择客户成品文件夹", "", MessageBox.INFORMATION);
}
return null;
}
/**
*
*/
private Date getEndTime(String targetName) {
// TODO
return null;
}
/**
*
*
* @param preferenceValue
* @param preferenceName
* @return false
*/
private boolean getMessageInfo(String[] preferenceValue, String preferenceName) {
if (preferenceValue == null || preferenceValue.length == 0) {
MessageBox.post("请通知管理员检查首选项" + preferenceName + "是否配置", "", MessageBox.INFORMATION);
return false;
}
return true;
}
/**
*
*
* @param preferenceValue
* @param preferenceName
* @return false
*/
private boolean getMessageboxInfo(String preferenceValue, String preferenceName) {
if (preferenceValue == null || preferenceValue.length() == 0) {
MessageBox.post("请通知管理员检查首选项" + preferenceName + "是否配置", "", MessageBox.INFORMATION);
return false;
}
return true;
}
/**
* 便map
*
* @param target
* @param path
* @param link
* @param taskPathList
* @param folderMap
* @return
*/
private void getAllFolderPath(TCComponent target, String path, String link, List<String> taskPathList,
Map<String, TCComponent> folderMap) {
try {
TCComponent[] contents = target.getRelatedComponents("contents");
for (int i = 0; i < contents.length; i++) {
TCComponent content = contents[i];
TCComponent[] childContents = content.getRelatedComponents("contents");
path = path + link + content.getProperty("object_name");
if (childContents.length > 0) {
getAllFolderPath(content, path, link, taskPathList, folderMap);
} else {
taskPathList.add(path);
folderMap.put(path, content);
}
}
} catch (TCException e) {
e.printStackTrace();
}
}
/**
*
*
* @param
* @return
*/
public String downLoadFile(TCComponent comp) {
if (comp == null) {
return "";
}
String value = "";
String tempPath = System.getenv("TEMP");
if (tempPath == null) {
tempPath = "";
} else if (!tempPath.endsWith("\\")) {
tempPath = tempPath + "\\";
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
try {
if (comp instanceof TCComponentDataset) {
TCComponentTcFile[] tcFiles = ((TCComponentDataset) comp).getTcFiles();
File file = null;
System.out.println("tcFiles:" + tcFiles.length);
if (tcFiles != null && tcFiles.length != 0) {
file = tcFiles[0].getFmsFile();
String fileName = file.getName();
System.out.println("fileName:" + fileName);
String fileDix = fileName.substring(fileName.lastIndexOf("."), fileName.length());
fileName = tempPath + sdf.format(new Date()) + fileDix;
File dirFile = new File(fileName);
FileUtility.copyFile(file, dirFile);
return fileName;
}
}
} catch (TCException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return value;
}
}

@ -0,0 +1,720 @@
package com.langtech.plm.synchronize;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map.Entry;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
public class SynchronizeDialog extends JFrame implements ActionListener {
private TCSession session;
protected DefaultTableModel tm_part;
private static ArrayList<String> dateConnList = new ArrayList<String>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private TCComponentItemRevision rev;
private JComboBox<String> objectComboBox = new JComboBox<String>();
private JButton okButton = new JButton("确定");
private JButton concelButton = new JButton("取消");
private HashMap<String, String> fieldMap = new HashMap<String, String>();
private String revType = "";
HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
public SynchronizeDialog(TCSession session, TCComponentItemRevision rev) {
// TODO Auto-generated constructor stub
this.session = session;
this.rev = rev;
initUI();
}
private void initUI() {
// TODO Auto-generated method stub
try {
this.setTitle("同步属性");
this.setLayout(new BorderLayout());
JPanel topPanel = getTopPanel();
JPanel btnPanel = getBtnPanel();
this.add(topPanel, BorderLayout.NORTH);
// this.add(pane,BorderLayout.CENTER);
this.add(btnPanel, BorderLayout.SOUTH);
this.setPreferredSize(new Dimension(550, 200));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
int screenWidth = screenSize.width; // 获取屏幕宽度
int screenHeight = screenSize.height; // 获取屏幕高度
int x = (screenWidth - 550) / 2; // 计算Frame的左上角x坐标
int y = (screenHeight - 300) / 2; // 计算Frame的左上角y坐标
this.setLocation(x, y); // 设置Frame的位置
// this.setLocationRelativeTo(null);
this.createActionEvent();
this.pack();
// this.validate();
this.setVisible(true);
// this.setAlwaysOnTop(true);
// 获取首选项 设置下拉框
String[] relations = session.getPreferenceService().getStringValues("LY6_CopyAttributeRelation");
String[] fields = session.getPreferenceService().getStringValues("LY6_CopyAttribute");
if (relations == null || relations.length <= 0) {
MessageBox.post("请配置LY6_CopyAttributeRelation", "提示", 2);
return;
}
if (fields == null || fields.length <= 0) {
MessageBox.post("请配置LY6_CopyAttribute", "提示", 2);
return;
}
for (int i = 0; i < fields.length; i++) {
String[] split = fields[i].split("=");
fieldMap.put(split[0], split[1]);
}
HashMap<String, String> relationsMap = new HashMap<String, String>();
for (int i = 0; i < relations.length; i++) {
String[] split = relations[i].split("=");
relationsMap.put(split[0], split[1]);
}
// 获取版本类型
revType = rev.getStringProperty("object_type");
String relation = relationsMap.get(revType);
if (relation == null || relation.isEmpty()) {
MessageBox.post("首选项未匹配到关系!", "提示", 2);
return;
}
// 获取关系下的对象
if (relation.contains(",")) {
String[] split = relation.split(",");
for (int i = 0; i < split.length; i++) {
TCComponent[] components = rev.getRelatedComponents(split[i]);
for (int j = 0; j < components.length; j++) {
if (components[j] instanceof TCComponentItemRevision) {
TCComponentItemRevision relationRev = (TCComponentItemRevision) components[j];
String object_string = relationRev.getStringProperty("object_string");
String object_type = relationRev.getStringProperty("object_type");
objectMap.put(object_string + "-" + object_type, relationRev);
}
}
}
} else {
TCComponent[] components = rev.getRelatedComponents(relation);
for (int j = 0; j < components.length; j++) {
if (components[j] instanceof TCComponentItemRevision) {
TCComponentItemRevision relationRev = (TCComponentItemRevision) components[j];
String object_string = relationRev.getStringProperty("object_string");
String object_type = relationRev.getStringProperty("object_type");
objectMap.put(object_string + "-" + object_type, relationRev);
}
}
}
// 设置下拉框的值
for (Entry<String, TCComponentItemRevision> map : objectMap.entrySet()) {
objectComboBox.addItem(map.getKey());
}
} catch (Exception e) {
e.printStackTrace();
return;
}
}
// 添加监听
public void createActionEvent() {
this.okButton.addActionListener(this);
this.concelButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
System.out.println("source==>+" + source);
if (this.okButton.equals(source)) {
// 获取选择的对象
try {
String selectedItem = (String) objectComboBox.getSelectedItem();
TCComponentItemRevision selectRev = objectMap.get(selectedItem);
String selectRevType = selectRev.getStringProperty("object_type");
String field = fieldMap.get(revType + ":" + selectRevType);
// 获取两个对象的 item 和 form
TCComponentItem revItem = rev.getItem();
TCComponentForm revForm = (TCComponentForm) rev.getReferenceListProperty("IMAN_master_form_rev")[0];
TCComponentItem selectRevItem = selectRev.getItem();
TCComponentForm selectRevForm = (TCComponentForm) selectRev
.getReferenceListProperty("IMAN_master_form_rev")[0];
if (field == null || field.isEmpty()) {
field = fieldMap.get("通用");
// 解析属性
System.out.println("field==="+field);
if (field.contains(",")) {// 判断是否多个
String[] split = field.split(",");
for (int i = 0; i < split.length; i++) {
String[] split2 = split[i].split(":");
String[] selectSplit = split2[1].split("\\.");
System.out.println("selectSplit[0]==="+selectSplit[0]);
if (selectSplit[0].equals("item")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRevItem.getStringProperty(selectSplit[1]);
System.out.println("value===="+value);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRevItem.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
} else if (selectSplit[0].equals("rev")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRev.getStringProperty(selectSplit[1]);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRev.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
} else if (selectSplit[0].equals("rm")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRevForm.getStringProperty(selectSplit[1]);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRevForm.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
}
}
} else {
String[] split2 = field.split(":");
String[] selectSplit = split2[1].split("\\.");
System.out.println("selectSplit[0]==="+selectSplit[0]);
if (selectSplit[0].equals("item")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRevItem.getStringProperty(selectSplit[1]);
System.out.println("value===="+value);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRevItem.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
} else if (selectSplit[0].equals("rev")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRev.getStringProperty(selectSplit[1]);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRev.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
} else if (selectSplit[0].equals("rm")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRevForm.getStringProperty(selectSplit[1]);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRevForm.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
}
}
} else {
// 解析属性
System.out.println("field==="+field);
if (field.contains(",")) {// 判断是否多个
String[] split = field.split(",");
for (int i = 0; i < split.length; i++) {
String[] split2 = split[i].split(":");
String[] selectSplit = split2[1].split("\\.");
System.out.println("selectSplit[0]==="+selectSplit[0]);
if (selectSplit[0].equals("item")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRevItem.getStringProperty(selectSplit[1]);
System.out.println("value===="+value);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRevItem.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
} else if (selectSplit[0].equals("rev")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRev.getStringProperty(selectSplit[1]);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRev.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
} else if (selectSplit[0].equals("rm")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRevForm.getStringProperty(selectSplit[1]);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRevForm.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
}
}
} else {
String[] split2 = field.split(":");
String[] selectSplit = split2[1].split("\\.");
System.out.println("selectSplit[0]==="+selectSplit[0]);
if (selectSplit[0].equals("item")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRevItem.getStringProperty(selectSplit[1]);
System.out.println("value===="+value);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRevItem.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
} else if (selectSplit[0].equals("rev")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRev.getStringProperty(selectSplit[1]);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRev.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
} else if (selectSplit[0].equals("rm")) {
String value = "";
Date dateValue = null;
if(dateValue != null && value.isEmpty()) {
value = sdf.format(dateValue);
}
if (selectSplit[2].equals("string") || selectSplit[2].equals("lov")) {
value = selectRevForm.getStringProperty(selectSplit[1]);
} else if (selectSplit[2].equals("date")) {
dateValue = selectRevForm.getDateProperty(selectSplit[1]);
}
// 获取目标对象要更新哪个属性
String[] targetSplit = split2[0].split("\\.");
if (targetSplit[0].equals("item")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revItem.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revItem.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rev")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
rev.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
rev.setDateProperty(targetSplit[1], dateValue);
}
} else if (targetSplit[0].equals("rm")) {
if (targetSplit[2].equals("string") || targetSplit[2].equals("lov")) {
revForm.setProperty(targetSplit[1], value);
} else if (targetSplit[2].equals("date")) {
revForm.setDateProperty(targetSplit[1], dateValue);
}
}
}
}
}
MessageBox.post("修改成功!", "提示", 2);
this.dispose();
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} else if (this.concelButton.equals(source)) {
this.dispose();
}
}
private JPanel getBtnPanel() {
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.add("1.1.center", new JLabel(""));
topPanel.add("2.1.center", new JLabel(" "));
topPanel.add("2.2.center", okButton);
topPanel.add("2.3.center", new JLabel(""));
topPanel.add("2.4.center", concelButton);
return topPanel;
}
// 查询部分
private JPanel getTopPanel() {
// TODO Auto-generated method stub
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
topPanel.add("1.1.left.center", new JLabel(""));
topPanel.add("2.1.left.center", new JLabel(""));
topPanel.add("3.1.left.center", new JLabel(""));
topPanel.add("4.1.left.center", new JLabel(""));
topPanel.add("5.1.left.center", new JLabel(""));
topPanel.add("6.1.left.center", new JLabel(""));
topPanel.add("7.1.left.center", new JLabel("选择属性来源对象:"));
topPanel.add("7.2.left.center", objectComboBox);
return topPanel;
}
}

@ -0,0 +1,53 @@
package com.langtech.plm.synchronize;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class SynchronizeHandler extends AbstractHandler{
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
try {
new Thread() {
@Override
public void run() {
InterfaceAIFComponent targetComponent = app.getTargetComponent();
if(targetComponent instanceof TCComponentItemRevision) {
try {
TCComponentItemRevision rev = (TCComponentItemRevision)targetComponent;
new SynchronizeDialog(session,rev);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
MessageBox.post("ÇëÑ¡Ôñ°æ±¾¶ÔÏó£¡","Ìáʾ",2);
return;
}
}
}.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,222 @@
package com.langtech.plm.template;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map.Entry;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
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.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
public class TemplateDialog extends JFrame implements ActionListener {
private TCSession session;
protected DefaultTableModel tm_part;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private TCComponentItemRevision rev;
private JComboBox<String> company = new JComboBox<String>();
private JComboBox<String> template = new JComboBox<String>();
private JButton okButton = new JButton("确定");
private JButton concelButton = new JButton("取消");
private HashMap<String, String> map = new HashMap<String, String>();
HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
public TemplateDialog(TCSession session, TCComponentItemRevision rev) throws TCException {
// TODO Auto-generated constructor stub
this.session = session;
this.rev = rev;
initUI();
}
private void initUI() {
// TODO Auto-generated method stub
try {
company.setPreferredSize(new Dimension(200,30));
template.setPreferredSize(new Dimension(200,30));
this.setTitle("工序模版");
this.setLayout(new BorderLayout());
JPanel topPanel = getTopPanel();
JPanel btnPanel = getBtnPanel();
this.add(topPanel, BorderLayout.NORTH);
// this.add(pane,BorderLayout.CENTER);
this.add(btnPanel, BorderLayout.SOUTH);
this.setPreferredSize(new Dimension(450, 200));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
int screenWidth = screenSize.width; // 获取屏幕宽度
int screenHeight = screenSize.height; // 获取屏幕高度
int x = (screenWidth - 450) / 2; // 计算Frame的左上角x坐标
int y = (screenHeight - 200) / 2; // 计算Frame的左上角y坐标
this.setLocation(x, y); // 设置Frame的位置
// this.setLocationRelativeTo(null);
this.createActionEvent();
this.pack();
// this.validate();
this.setVisible(true);
// this.setAlwaysOnTop(true);
String[] pref = session.getPreferenceService().getStringValues("LY6_MEOP_TemplateType");
for (int i = 0; i < pref.length; i++) {
String[] split = pref[i].split(":");
company.addItem(split[0]);
map.put(split[0], split[1]);
}
String mrselectitem = (String)company.getSelectedItem();
String mrValue = map.get(mrselectitem);
String[] split = mrValue.split(",");
for (int i = 0; i < split.length; i++) {
template.addItem(split[i]);
}
//下拉值联动
company.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
template.removeAllItems();
String selectedItem = (String) company.getSelectedItem();
System.out.println("Selected Item: " + selectedItem);
// 在这里可以执行其他操作
String value = map.get(selectedItem);
String[] split = value.split(",");
for (int i = 0; i < split.length; i++) {
template.addItem(split[i]);
}
}
}
});
} catch (Exception e) {
e.printStackTrace();
return;
}
}
// 添加监听
public void createActionEvent() {
this.okButton.addActionListener(this);
this.concelButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
System.out.println("source==>+" + source);
if (this.okButton.equals(source)) {
String templateString = (String)template.getSelectedItem();
String companyString = (String)company.getSelectedItem();
System.out.println("templateString==="+templateString);
System.out.println("companyString==="+companyString);
if(companyString.isEmpty()) {
MessageBox.post("请选择公司!", "提示 ", MessageBox.INFORMATION);
return;
}
if(templateString.isEmpty()) {
MessageBox.post("请选择模板!", "提示 ", MessageBox.INFORMATION);
return;
}
//调用查询获取模板的dwg数据集
try {
TCComponent[] items = session.search("零组件...", new String[] { "零组件 ID" }, new String[] {templateString});
System.out.println("items.length===="+items.length);
TCComponentItem item = null;
if(items.length > 0) {
item = (TCComponentItem)items[0];
}
TCComponentItemRevision latestItemRevision = item.getLatestItemRevision();
TCComponent[] relatedComponent = latestItemRevision.getRelatedComponents("IMAN_specification");
System.out.println("relatedComponent========"+relatedComponent.length);
for (int i = 0; i < relatedComponent.length; i++) {
rev.add("IMAN_specification",relatedComponent[i]);
}
MessageBox.post("模板插入成功!", "提示 ", MessageBox.INFORMATION);
this.dispose();
return;
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//挂在数据集
} else if (this.concelButton.equals(source)) {
this.dispose();
}
}
private JPanel getBtnPanel() {
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.add("1.1.center", new JLabel(""));
topPanel.add("2.1.center", new JLabel(" "));
topPanel.add("2.2.center", okButton);
topPanel.add("2.3.center", new JLabel(""));
topPanel.add("2.4.center", concelButton);
return topPanel;
}
// 查询部分
private JPanel getTopPanel() {
// TODO Auto-generated method stub
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
topPanel.add("1.1.left.center", new JLabel(""));
topPanel.add("2.1.left.center", new JLabel(""));
topPanel.add("3.1.left.center", new JLabel(""));
topPanel.add("4.1.left.center", new JLabel(" 公司:"));
topPanel.add("4.2.left.center", company);
topPanel.add("5.1.left.center", new JLabel(""));
topPanel.add("6.1.left.center", new JLabel(""));
topPanel.add("7.1.left.center", new JLabel(""));
topPanel.add("8.1.left.center", new JLabel(" 模板:"));
topPanel.add("8.2.left.center", template);
return topPanel;
}
}

@ -0,0 +1,77 @@
package com.langtech.plm.template;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentSchedule;
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class TemplateHandler extends AbstractHandler{
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
try {
new Thread() {
@Override
public void run() {
InterfaceAIFComponent targetComponent = app.getTargetComponent();
if(targetComponent instanceof TCComponentItemRevision) {
try {
String[] pref = session.getPreferenceService().getStringValues("LY6_MEOP_TemplateObject");
String types = "";
if(pref.length > 0) {
types = pref[0];
}else {
MessageBox.post("请配置首选项LY6_MEOP_TemplateObject","提示",2);
return;
}
TCComponentItemRevision rev = (TCComponentItemRevision)targetComponent;
String object_type = rev.getStringProperty("object_type");
if(types.contains(object_type)) {
new TemplateDialog(session,rev);
}else {
MessageBox.post("请选择首选项LY6_MEOP_TemplateObject中匹配的对象","提示",2);
return;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
MessageBox.post("请选择版本对象!","提示",2);
return;
}
}
}.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}

@ -1,4 +1,4 @@
package com.langtech.plm.performancemanagement; package com.langtech.plm.tqsx;
import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
@ -9,7 +9,7 @@ import org.osgi.framework.BundleContext;
public class Activator extends AbstractUIPlugin { public class Activator extends AbstractUIPlugin {
// The plug-in ID // The plug-in ID
public static final String PLUGIN_ID = "com.langtech.plm.performancemanagement"; //$NON-NLS-1$ public static final String PLUGIN_ID = "cn.net.connor.ml.plm"; //$NON-NLS-1$
// The shared instance // The shared instance
private static Activator plugin; private static Activator plugin;

@ -0,0 +1,603 @@
package com.langtech.plm.tqsx;
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) ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 时间格式 字符串 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/**
*
* <br/>
* "yyyy"
*/
public static final String YEAR_FORMAT = "yyyy";
/**
*
* <br/>
* "MM"
*/
public static final String MONTH_FORMAT = "MM";
/**
*
* <br/>
* "dd"
*/
public static final String DAY_FORMAT = "dd";
/**
*
* <br/>
* "HH"
*/
public static final String HOUR_FORMAT = "HH";
/**
*
* <br/>
* "mm"
*/
public static final String MINUTE_FORMAT = "mm";
/**
*
* <br/>
* "ss"
*/
public static final String SECOND_FORMAT = "ss";
/**
* <span color='red'>--</span>
* <br/>
* "yyyy-MM-dd"
*/
public static final String DATE_FORMAT = YEAR_FORMAT + HYPHEN + MONTH_FORMAT + HYPHEN + DAY_FORMAT;
/**
* <span color='red'>::</span>
* <br/>
* "HH:mm:ss"
*/
public static final String TIME_FORMAT = HOUR_FORMAT + COLON + MINUTE_FORMAT + COLON + SECOND_FORMAT;
/**
* <span color='red'>-- ::</span>
* <br/>
* "yyyy-MM-dd HH:mm:ss"
*/
public static final String DATE_TIME_FORMAT = DATE_FORMAT + " " + TIME_FORMAT;
/**
* <span color='red'></span>
* <br/>
* "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();
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 当前时间相关 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 未来、历史时间相关 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/**
*
* <p>
*
* @param years
* @param formatEnum
* @return
*/
public static String minusYears(Long years, FormatEnum formatEnum) {
return minusOrPlusYears(-years, formatEnum);
}
/**
*
* <p>
*
* @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);
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 未来、历史时间相关 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 时间转换相关 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/**
* DateLocalDateTime
* <p>
*
* @param date date
* @return LocalDateTime
*/
public static LocalDateTime toLocalDateTime(Date date) {
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
}
/**
* DateLocalDate
* <p>
*
* @param date date
* @return LocalDate
*/
public static LocalDate toLocalDate(Date date) {
return toLocalDateTime(date).toLocalDate();
}
/**
* DateLocalTime
* <p>
*
* @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());
}
/**
* LocalDateDate
*
* @param localDate localDate
* @return Date
*/
public static Date toDate(LocalDate localDate) {
return toDate(localDate.atStartOfDay());
}
/**
* LocalTimeDate
*
* @param localTime localTime
* @return Date
*/
public static Date toDate(LocalTime localTime) {
return toDate(LocalDateTime.of(localDate(), localTime));
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 时间转换相关 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 时间间隔相关 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/**
* endDate-startDate
* <br> leigq
* <br> 2018-11-07 09:55
* <br>
*
* @param startDate
* @param endDate
* @return
*/
public static Long daysInterval(LocalDate startDate, LocalDate endDate) {
return endDate.toEpochDay() - startDate.toEpochDay();
}
/**
* endDate-startDate
* <br> leigq
* <br> 2018-11-07 09:55
* <br>
*
* @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
* <br> leigq
* <br> 2018-11-07 09:55
* <br>
*
* @param startDate
* @param endDate
* @return
*/
public static Long daysInterval(LocalDateTime startDate, LocalDateTime endDate) {
return daysInterval(startDate.toLocalDate(), endDate.toLocalDate());
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 时间间隔相关 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓只允许此类调用↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/**
* /
* <p>
*
* @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();
}
}

@ -0,0 +1,37 @@
package com.langtech.plm.tqsx;
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);
}
}
}

@ -0,0 +1,16 @@
package com.langtech.plm.tqsx;
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;
}
}

@ -0,0 +1,24 @@
package com.langtech.plm.tqsx;
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;
}
}

@ -0,0 +1,22 @@
package com.langtech.plm.tqsx;
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());
}
}

@ -0,0 +1,54 @@
package com.langtech.plm.tqsx;
import java.awt.Dimension;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.kernel.TCSession;
import k.util.ProgressBar;
/*
* 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(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();
}
}
}

@ -0,0 +1,53 @@
package com.langtech.plm.tqsx;
import java.awt.Dimension;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.kernel.TCSession;
import k.util.ProgressBar;
/*
* 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(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();
}
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,66 @@
package com.langtech.plm.tqsx;
import java.io.File;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCSession;
public class PropertyToWordOrExcelCommand extends KCommand{
final String preName = "Connor_LY6_WordExcel_Report_ItemType";
public PropertyToWordOrExcelCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
super(app, commandId, actionInfo);
TCSession session = (TCSession) app.getSession();
this.setRunnable(new PropertyToWordOrExcelOperation(app, "提取对象版本属性到Word Excel"));
// InterfaceAIFComponent targetComponent = app.getTargetComponent();
// TCComponentItemRevision revision = (TCComponentItemRevision) targetComponent;
// try {
// String[] prefVals = KUtil.getPrefVals(session, preName);
// if(prefVals == null || prefVals.length == 0) {
// KUtil.info(AIFDesktop.getActiveDesktop(), preName + "该首选项未配置,请联系管理员!");
// return ;
// }
// String relatioin = prefVals[0];
// TCComponent[] relatedComponents = revision.getRelatedComponents(relatioin);
// if(relatedComponents == null || relatedComponents.length == 0) {
// KUtil.info(AIFDesktop.getActiveDesktop(), "选中对象的 " + relatioin + " 关系下没有数据集");
// return ;
// }
// for (TCComponent tcComponent : relatedComponents) {
// if (tcComponent instanceof TCComponentDataset) {
// TCComponentDataset dataset = (TCComponentDataset) tcComponent;
// File datasetFile = KUtil.getDatasetFile(dataset);
// System.out.println();
// String type = tcComponent.getType();
// switch (type) {
// case "MSExcel":
//
// break;
// case "MSExcelX":
//
// break;
// case "MSWord":
//
// break;
// case "MSWordX":
//
// break;
// }
// }
// }
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
}

@ -0,0 +1,288 @@
package com.langtech.plm.tqsx;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
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.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFName;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFName;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.aspose.words.Bookmark;
import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AbstractAIFSession;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentTcFile;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.util.FileUtility;
public class PropertyToWordOrExcelOperation extends KOperation {
public PropertyToWordOrExcelOperation(AbstractAIFApplication app, String opName) {
super(app, opName, "正在执行。。。");
}
final String preName = "Connor_LY6_WordExcel_Report_ItemType";
@Override
public boolean init() throws Exception {
new Thread().sleep(1000);
InterfaceAIFComponent targetComponent = app.getTargetComponent();
TCComponentItemRevision revision = (TCComponentItemRevision) targetComponent;
String[] prefVals = KUtil.getPrefVals(session, preName);
if(prefVals == null || prefVals.length == 0) {
KUtil.info(AIFDesktop.getActiveDesktop(), preName + "该首选项未配置,请联系管理员!");
return false;
}
String relatioin = prefVals[0];
TCComponent[] relatedComponents = revision.getRelatedComponents(relatioin);
if(relatedComponents == null || relatedComponents.length == 0) {
KUtil.info(AIFDesktop.getActiveDesktop(), "选中对象的 " + relatioin + " 关系下没有数据集");
return false;
}
//处理首选项
HashMap<String, String> nameMap = new HashMap<String, String>();//数据集里面的名称和对象(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("=");
nameMap.put(split[1],split[0]);
}
}
for (TCComponent tcComponent : relatedComponents) {
if (tcComponent instanceof TCComponentDataset) {
TCComponentDataset dataset = (TCComponentDataset) tcComponent;
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<String, String> nameMap) throws IOException, TCException {
FileInputStream is = new FileInputStream(datasetFile);
HSSFWorkbook workbook = new HSSFWorkbook(is);
List<HSSFName> 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));
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<String, String> nameMap) throws IOException, TCException {
FileInputStream is = new FileInputStream(datasetFile);
XSSFWorkbook workbook = new XSSFWorkbook(is);
List<XSSFName> 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));
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<String, String> nameMap,String type) throws IOException, TCException {
String path = datasetFile.getAbsolutePath();
InputStream inputStream = Files.newInputStream(Paths.get(path));
Map<String, String> dataMap = new HashMap<>();
for(String key : nameMap.keySet()) {
String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(key));
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<String, String> 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<String, String> dataMap = new HashMap<>();
for(String key : nameMap.keySet()) {
String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(key));
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<String, String> 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;
}
}
}

@ -0,0 +1,167 @@
package com.langtech.plm.tqsx;
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<String, String> 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<XWPFParagraph> 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 文档那样有具体的start和end值来定位一个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<String, String> dataMap) throws IOException {
XWPFDocument document = new XWPFDocument(inputStream).getXWPFDocument();
List<XWPFParagraph> 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<String, String> 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);
}
}

@ -0,0 +1 @@
LD6_NewProdForm.FORMJAVARENDERING=com.langtech.plm.form.LD6_NewProdForm
Loading…
Cancel
Save