first commit

main
李建辉 4 months ago
commit cfcde4773b

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/jacob.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jsqlparser-4.3.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored

@ -0,0 +1 @@
/bin/

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cn.net.connor.std.processedit</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

@ -0,0 +1,57 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Processedit
Bundle-SymbolicName: cn.net.connor.std.processedit;singleton:=true
Bundle-Version: 13000.1.0
Bundle-Activator: cn.net.connor.std.processedit.Activator
Eclipse-RegisterBuddy: cn.net.connor.std.aifrcp,cn.net.connor.std.fx
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
com.teamcenter.rac.util;bundle-version="13000.1.0",
com.teamcenter.rac.tcapps;bundle-version="13000.1.0",
com.teamcenter.rac.ui.views;bundle-version="13000.1.0",
org.apache.poi.39,
TcSoaCommon,
TcSoaCoreRac,
TcSoaCoreTypes,
com.teamcenter.rac.cme.mpp;bundle-version="13000.1.0",
com.teamcenter.rac.cme.activity;bundle-version="13000.1.0",
com.teamcenter.rac.cme.time;bundle-version="13000.1.0",
com.teamcenter.rac.cme.legacy;bundle-version="13000.1.0",
com.teamcenter.rac.cme.bvr.connect;bundle-version="13000.1.0",
com.teamcenter.rac.cme.framework,
com.teamcenter.rac.classification.icm;bundle-version="13000.1.0",
com.teamcenter.rac.classification.icadmin;bundle-version="13000.1.0",
TcSoaStructureManagementRac;bundle-version="13000.1.0",
TcSoaStructureManagementLoose;bundle-version="13000.1.0",
TcSoaCoreLoose,
com.teamcenter.rac.aifrcp;bundle-version="13000.1.0",
com.teamcenter.rac.kernel;bundle-version="13000.1.0",
com.teamcenter.rac.common;bundle-version="13000.1.0",
cn.net.connor.std.aifrcp;bundle-version="13000.1.0",
cn.net.connor.std.fx;bundle-version="13000.1.0",
cn.net.connor.std.gdtex;bundle-version="13000.1.0",
com.teamcenter.rac.commonclient;bundle-version="13000.1.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: cn.net.connor.std.processedit
Bundle-ActivationPolicy: lazy
Export-Package: cn.net.connor.std.processedit,
cn.net.connor.std.processedit.choose,
cn.net.connor.std.processedit.choosefromsql,
cn.net.connor.std.processedit.commands,
cn.net.connor.std.processedit.meopviewfx,
cn.net.connor.std.processedit.meopviewfx.bean,
cn.net.connor.std.processedit.meopviewfx.reorder,
cn.net.connor.std.processedit.meopviewfx.ui,
cn.net.connor.std.processedit.modifymeopno,
cn.net.connor.std.processedit.newdatasetfromtemplate,
cn.net.connor.std.processedit.newmeop,
cn.net.connor.std.processedit.newmeprocess,
cn.net.connor.std.processedit.processview,
cn.net.connor.std.processedit.processview.safeicon,
cn.net.connor.std.processedit.searchbysql,
cn.net.connor.std.processedit.util,
cn.net.connor.std.processedit.word
Bundle-ClassPath: lib/jsqlparser-4.3.jar,
.,
lib/jacob.jar

@ -0,0 +1,384 @@
# 工艺视图(首选项不完整)
## 1. 工道编辑
相关首选项列表:
1. Connor_AVIC_GXBZ_Bomline: 配置界面上方的表格
2. Connor_AVIC_GXBZ_[对象类型]: 配置界面下方的表格对象类型是选择bom行对应item的真实类型名称
3. Connor_AVIC_GXBZ_Property_[对象类型]:配置界面中间属性表
4. Connor_AVIC_GXBZ_Common_Folder: 配置通用文件夹或Excel的uid
5. Connor_AVIC_GXBZ_Personal_Folder配置个人文件夹或Excel的uid
### 1.1 表格首选项配置
涉及首选项:
1. Connor_AVIC_GXBZ_Bomline
2. Connor_AVIC_GXBZ_[对象类型]
首选项格式说明:
```text
第一行配置:指定的对象类型
指定对象类型后,该表格只加载指定类型的子行,如存在新建功能,则使用该类型新建对象
如不需要指定类型,首行需配置"bomline"此表格仅支持读取和修改bom行属性
第二行开始配置属性映射
格式:[列宽][$每行最大字符数量][属性位置.][#]属性真实名称[=属性值(按该值进行过滤)]
列宽:选配,直接在前面加数字
每行最大字符数量:手动输入时,如果某行超过此数量则自动添加换行符
属性位置如不写即默认bomline属性位置包含bomline, item, rev, itemmaster, revmaster
属性位置工步如不写默认为文件夹属性位置包含bomlineitem
#:属性名称前加#表示改列为手动序号列,用于重排序功能,支持多列
##:属性名称前加##表示改列为自动序号列,不跟随上下移动,删除行时也会自动调整,支持多列
属性真实名称定义的属性名称如要支持换行请务必配置“bl_sequence_no”属性
属性值:配置后,只显示属性匹配的行(如配置指定的事例类型)
20210119更新: 下方表格支持GDT编辑器,属性名称配置到GDT_properties首选项即可
特殊配置:
sequence_step=工步号递增数值配置工步号递增大小不配置默认为10
```
示例:
```text
bomline
bl_indented_title
bl_occ_type=MEAssemble
200bl_item_object_name
```
```text
Item
bomline.##bl_sequence_no
bomline.bl_indented_title
rev.#object_desc
item.#object_desc
150item.object_name
sequence_step=2
```
### 1.2 属性首选项配置
涉及首选项:
1. Connor_AVIC_GXBZ_Property_[对象类型]
格式:
```text
多值,格式:[*]属性真实名称[=下拉值1;下拉值2;下拉值3]
*:表示属性在版本上,不添加*表示属性在版本表单
下拉值配置后若属性上未定义下拉值则变更属性控件为下拉框下拉内容为分号分隔后的配置内容若定义下拉值以bmide中定义的lov为准。
```
示例:
```text
object_name
*object_name=名称1;名称2;名称3
object_type
creation_date
```
### 1.3 特殊文本树
涉及首选项:
1. Connor_AVIC_GXBZ_Common_Folder: 配置通用文件夹或Excel的uid
2. Connor_AVIC_GXBZ_Personal_Folder配置个人文件夹或Excel的uid
Excel 格式说明
> 从左上角开始写入内容,单元格排列保持树形即可,注意不要在内容之间插入空列
真实值说明:真实值有多种配置方式
> 1. 在真实值单元格内容前加“#RV#”
> 2. 在配置的uid后添加“#RealValue#列号”配置后对应文件夹内所有excel或指定uid的excel的对应列作为真实值列
### 1.4 TC兼容性修改
> 由于工序编制界面基于javafx开发TC的文本检测未进行兼容所以在文本框中进行复制粘贴和剪切时存在问题。
>
> 需要修改 com.teamcenter.rac.common.xxxx.jar 中的 plugin.xml
```xml
<definition id="com.teamcenter.rac.common.textActive">
<with variable="activeContexts">
<iterate operator="or" ifEmpty="false">
<or>
<equals value="com.teamcenter.rac.aifrcp.swingtext"/>
<equals value="com.teamcenter.rac.aifrcp.swttext"/>
</or>
</iterate>
</with>
</definition>
```
修改为
```xml
<definition id="com.teamcenter.rac.common.textActive">
<or>
<with variable="activeContexts">
<iterate operator="or" ifEmpty="false">
<or>
<equals value="com.teamcenter.rac.aifrcp.swingtext"/>
<equals value="com.teamcenter.rac.aifrcp.swttext"/>
</or>
</iterate>
</with>
<with variable="activePartId">
<equals value="cn.net.connor.process.meopview.MEOPEditView"/>
</with>
</or>
</definition>
```
## 2. 工艺工序编辑
配置工艺视图中选择对应[对象真实类型]时,要在界面中显示的属性
```text
格式:“[*][#][$]显示名称=属性位置.属性名称[=附加lov的名称[=从工艺提取属性的属性位置.属性名称[=属性是否显示配置]]]”(属性位置包含 item, rev, itemmaster, revmaster
注意:此处增加[$]符号的配置,表示控件是文本域,可多行输入。[*][#]同上,分别表示必填和只读
属性是否显示配置格式:“属性位置.属性名称:配置文本”。当属性真实值等于配置文本时,这条配置为有效配置,控件可见;否则忽略该行配置。
示例:“版本描述=rev.object_desc=BillCodes==rev.object_desc:1”
20210112: 附加lov名称配置可以替换为用英文分号分隔的下拉值列表
20201117 增加额外配置:某个下拉框(控制属性)选择指定的值时,隐藏指定的控件(隐藏属性)
格式“HIDE_LISTENER:控制属性位置.控制属性名称=指定值:隐藏属性位置1.隐藏属性名称1;隐藏属性位置2.隐藏属性名称2”
示例“HIDE_LISTENER:rev.object_desc=Civi:item.object_desc;item.object_name”
```
## 3. 选择原材料配置
**从Excel选择**
Connor_AVIC_MEOPEXCEL_[属性真实名称]
配置**创建工序**和**工艺编辑**视图界面中对应[属性真实名称]的选择按钮逻辑
```text
第一行配置excel数据集的uid可按照创建界面选择的类型区分。首先查找类型对应uid未找到时查找默认uid。
格式“默认uid;真实类型名称1:类型1使用的uid;真实类型名称2:类型2使用的uid;...”
第二行开始:配置表格显示和属性映射信息
格式:“[#]界面列名=excel列名[=属性位置.属性名称[=默认列宽]]”
#:表示添加该列的查询
```
## 3. 修改工序号
1. 首选项Connor_AVIC_SQGXH_GXLX多值配置工序对象类型真实名称
2. 首选项Connor_AVIC_SQGXH_SXBJ多值格式"表头名称=属性位置.属性名称"属性位置包含item,rev,itemmaster,revmaster,bomline
## 4. 安全说明
首选项connor_process_aqtb_zsjm多值
格式:
```text
第一行安全图标文件夹UID
第二行:安全图标和选择版本的关系
第三行:安全说明属性名称(版本属性)
第四行:图标数据集类型,多个类型用英文分号分隔
第五行需要添加安全图标的对象Item类型
```
示例:
```text
BkvJiCugJ5xHGD
IMAN_reference
object_desc
JPEG;Image
SF6_GMEP;Item
```
仅保留安全说明的配置方式
```text
第一行:安全说明属性名称(版本属性)
```
示例:
```text
object_desc
```
## 5. DWG 略图
首选项
```text
Connor_AVIC_BZGXLT配置标准工序略图
Connor_AVIC_XLGXLT配置下料工序略图
```
格式:
```text
select=选择的对象类型名称,多个用英文分号分隔
relation=新数据集和选择对象的关系
name=数据集名称和文件引用名称配置支持拼接和属性路径路径从bom行开始
success=(选配)成功提示,不配置则不提示
exist=(选配)根据名称、类型、关系检查数据集是否存在,已存在则不进行操作,不配置则不检查
dataset=模板数据集uid
```
示例:
```text
select=ItemRevision
relation=IMAN_reference
name=bl_sequence_no+_+bl_revision.IMAN_master_form_rev.object_desc+标准工序略图
success=成功了
exist=已经有了,不准上传
dataset=R0kJyb3IJ5xHGD
```
# 6. 新建工艺
首选项Connor_AVIC_[版本类型]
配置创建工艺界面对齐使用空格对齐shift+space切换中英空格
```text
格式:“[*][#][@]标题名称=写入属性配置[=提取属性配置[+GY][=下拉内容1;下拉内容2;下拉内容3]]”
*:必填
#:不可编辑
@: 不可见
属性配置格式:属性位置.属性名称(属性位置包含 item, rev, itemmaster, revmaster
--------------------------------------------
特殊写入属性配置:
object_type必配指定新建对象的类型如有下拉值配置“真实类型名称[-新对象版本(父)与用户选择版本(子)的关联关系名称[-用户选择版本(父)与新对象(子)的关联关系名称]]”
```
## 7. 更改说明
首选项connor_process_ggjl
配置工艺工序编辑界面中的更改记录,属性定义在版本表单
```text
第一行:表格行对象类型
第二行:版本表单中表格属性名称
第三号开始配置表格行属性,格式“[列宽]标题名称=属性名称”,仅字符串属性
首选项connor_process_ggjl_editable
单值逻辑类型配置更改记录是否可编辑默认不可编辑配置true为可编辑
```
示例:
```text
SF6_TableRow
sf6_tablerow
50第1列=sf6_col1
第2列=sf6_col2
第3列=sf6_col3
第4列=sf6_col4
第5列=sf6_col5
第6列=sf6_col6
```
## 8. 工作中心选择
首选项Connor_AVIC_MEOP_WorkCenter_Class
单值配置工作中心分类ID
# 更新记录
20220224
1. 工道编辑,序号特殊配置
更新配置:序号属性名称前加#
属性位置工步如不写默认为文件夹属性位置包含bomlineitem
```text
[列宽][$每行最大字符数量][属性位置.][#]属性真实名称[=属性值(按该值进行过滤)]
```
示例
```text
首选项名称Connor_AVIC_GXBZ_MEOP
值:
SF6_CheckActivity
object_name
sf6_checkType
#sf6_checkTool
bomline.me_cl_display_string
object_desc
```
2. 工艺工序编辑,选择原材料
**从数据库查询选择**
`Connor_AVIC_MEOPSQL_[对象类型]_[属性真实名称]`
配置**工艺编辑**视图界面中对应[属性真实名称]的选择按钮逻辑
```text
配置sql查询语句配置信息写到自定义表头中注意表头需要加双引号
表头格式:“[#]界面列名[=属性位置.属性名称[=默认列宽]]”
#:表示添加该列的查询
注意存在查询条件时需要在末尾准备好where关键字
添加单个对象到选择版本的关系下:
1. 通过UID添加格式“UID=关系名称=默认列宽”需要查询出需要添加的对象的UID列宽设置为零则不会在界面中显示
2. 通过ID添加格式“ID=关系名称=默认列宽”需要查询出需要添加的对象的ID列宽设置为零则不会在界面中显示添加对象的最新版本
```
示例
```text
首选项名称Connor_AVIC_MEOPSQL_SF6_GMEP_object_name
值:
select
pobject_name "#名称=item.object_name=200",
puid "UID=NHL8_MaterialRlation=0"
from pworkspaceobject
where 1=1
```
3. 工步编辑从数据表选择
**从数据库查询选择**
`Connor_AVIC_GXBZ_SelectSql_[当前视图选择的对象类型]`
```text
配置sql查询语句配置信息写到自定义表头中注意表头需要加双引号
表头格式:“[#]界面列名[=反写属性名称[=默认列宽]]”
#:表示添加该列的查询
注意存在查询条件时需要在末尾准备好where关键字
```
示例
```text
首选项名称Connor_AVIC_GXBZ_SelectSql_MEOP
值:
select
pobject_name "#名称=object_name=200",
puid "UID=object_desc"
from pworkspaceobject
where 1=1
```

@ -0,0 +1,8 @@
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/,\
lib/jsqlparser-4.3.jar,\
lib/jacob.jar

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 942 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 912 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,261 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.ui.startup">
<startup class="cn.net.connor.std.processedit.KStartup"/>
</extension>
<extension point="org.eclipse.ui.views">
<category id="cn.net.connor.std.processedit.view" name="工艺视图"/>
<view
category="cn.net.connor.std.processedit.view"
closable="true"
allowMultiple="false"
icon="icons/meprocess_16.png"
class="cn.net.connor.std.processedit.processview.ProcessPropertyView"
id="cn.net.connor.std.processedit.processview.ProcessPropertyView"
name="工艺工序编辑">
</view>
<view
category="cn.net.connor.std.processedit.view"
closable="true"
allowMultiple="false"
icon="icons/meoperation_16.png"
class="cn.net.connor.std.processedit.meopviewfx.MEOPEditView"
id="cn.net.connor.std.processedit.meopview.MEOPEditView"
name="工步编辑">
</view>
</extension>
<extension point="com.teamcenter.rac.aifrcp.viewDefs">
<view
alwaysUseSetRootInputObject="true"
autoCloseEnabled="true"
folderId="RAC_Folder_UR"
id="cn.net.connor.std.processedit.processview.ProcessPropertyView"
selectionInPrimaryEffectsInvisbleSecondary="false"
selectionInSecondaryEffectsPrimary="false"
type="secondary">
</view>
<view
alwaysUseSetRootInputObject="true"
autoCloseEnabled="true"
folderId="RAC_Folder_UR"
id="cn.net.connor.std.processedit.meopview.MEOPEditView"
selectionInPrimaryEffectsInvisbleSecondary="false"
selectionInSecondaryEffectsPrimary="false"
type="secondary">
</view>
</extension>
<extension point="org.eclipse.ui.commands">
<command name="创建工艺" id="cn.net.connor.std.processedit.commands.NewProcessCommand"/>
<command name="创建工序" id="cn.net.connor.std.processedit.commands.NewMeopCommand"/>
<command name="工艺工序编辑" id="cn.net.connor.std.processedit.commands.OpenViewCommand#cn.net.connor.std.processedit.processview.ProcessPropertyView"/>
<command name="工步编辑" id="cn.net.connor.std.processedit.commands.OpenViewCommand#cn.net.connor.std.processedit.meopview.MEOPEditView"/>
<command name="附件" id="cn.net.connor.std.processedit.commands.OpenViewCommand#com.teamcenter.rac.cme.attachments"/>
<command name="修改工序号" id="cn.net.connor.std.processedit.commands.ModifyMeopNoCommand"/>
<command name="标准工序略图" id="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_BZGXLT"/>
<command name="下料工序略图" id="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_XLGXLT"/>
<command name="创建原材料BOM" id="cn.net.connor.std.processedit.commands.CreateBOMViewHandler"/>
<command name="工艺分工" id="ProcessDivisionHandler"/>
<command name="工序分工" id="GXDivisionHandler"/>
<command name="工艺复用" id="ProcessMultiplexHandler"/>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler commandId="cn.net.connor.std.processedit.commands.NewProcessCommand" class="cn.net.connor.std.aifrcp.KHandler"/>
<handler commandId="cn.net.connor.std.processedit.commands.NewMeopCommand" class="cn.net.connor.std.aifrcp.KHandler">
<activeWhen>
<and>
<reference
definitionId="com.teamcenter.rac.cme.mpp.inMainView">
</reference>
</and>
</activeWhen>
</handler>
<handler commandId="cn.net.connor.std.processedit.commands.OpenViewCommand#cn.net.connor.std.processedit.processview.ProcessPropertyView" class="cn.net.connor.std.aifrcp.KHandler"/>
<handler commandId="cn.net.connor.std.processedit.commands.OpenViewCommand#cn.net.connor.std.processedit.meopview.MEOPEditView" class="cn.net.connor.std.aifrcp.KHandler"/>
<handler commandId="cn.net.connor.std.processedit.commands.OpenViewCommand#com.teamcenter.rac.cme.attachments" class="cn.net.connor.std.aifrcp.KHandler"/>
<handler commandId="cn.net.connor.std.processedit.commands.ModifyMeopNoCommand" class="cn.net.connor.std.aifrcp.KHandler"/>
<handler commandId="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_BZGXLT" class="cn.net.connor.std.aifrcp.KHandler"/>
<handler commandId="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_XLGXLT" class="cn.net.connor.std.aifrcp.KHandler"/>
<handler commandId="ProcessDivisionHandler" class="cn.net.connor.std.processedit.ldy.ProcessDivisionHandler"/>
<handler commandId="GXDivisionHandler" class="cn.net.connor.std.processedit.ldy.GXDivisionHandler"/>
<handler commandId="ProcessMultiplexHandler" class="cn.net.connor.std.processedit.ldy.ProcessMultiplexHandler"/>
<handler commandId="cn.net.connor.std.processedit.commands.CreateBOMViewHandler" class="cn.net.connor.std.processedit.commands.CreateBOMViewHandler"/>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu label="工艺管理" id="cn.net.connor.std.processedit.mainmenu">
<separator name ="sp1" visible="false"/>
<separator name ="sp2" visible="true"/>
<separator name ="sp3" visible="true"/>
<separator name ="sp4" visible="true"/>
<separator name ="sp5" visible="true"/>
<separator name ="sp6" visible="true"/>
<separator name ="sp7" visible="true"/>
<menu label="生成工艺卡" id="cn.net.connor.std.processedit.mainmenu.card"/>
<!--menu label="DWG 工序略图" id="cn.net.connor.std.processedit.mainmenu.dwgdataset"/-->
</menu>
</menuContribution>
<menuContribution locationURI="menu:cn.net.connor.std.processedit.mainmenu.dwgdataset?after=additions">
<command commandId="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_BZGXLT" id="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_BZGXLT">
<visibleWhen>
<with variable="rac_command_suppression">
<not>
<iterate operator="or">
<equals
value="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_BZGXLT">
</equals>
</iterate>
</not>
</with>
</visibleWhen>
</command>
<command commandId="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_XLGXLT" id="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_XLGXLT">
<visibleWhen>
<with variable="rac_command_suppression">
<not>
<iterate operator="or">
<equals
value="cn.net.connor.std.processedit.commands.NewDatasetFromTemplateCommand#Connor_AVIC_XLGXLT">
</equals>
</iterate>
</not>
</with>
</visibleWhen>
</command>
</menuContribution>
<menuContribution locationURI="menu:cn.net.connor.std.processedit.mainmenu?after=sp6">
<command commandId="cn.net.connor.std.processedit.commands.OpenViewCommand#cn.net.connor.std.processedit.processview.ProcessPropertyView" id="cn.net.connor.std.processedit.mainmenu.gygxbj">
<visibleWhen>
<with variable="rac_command_suppression">
<not>
<iterate operator="or">
<equals
value="cn.net.connor.std.processedit.commands.OpenViewCommand#cn.net.connor.std.processedit.processview.ProcessPropertyView">
</equals>
</iterate>
</not>
</with>
</visibleWhen>
</command>
<command commandId="cn.net.connor.std.processedit.commands.OpenViewCommand#cn.net.connor.std.processedit.meopview.MEOPEditView" id="cn.net.connor.std.processedit.mainmenu.gdbj">
<visibleWhen>
<with variable="rac_command_suppression">
<not>
<iterate operator="or">
<equals
value="cn.net.connor.std.processedit.commands.OpenViewCommand#cn.net.connor.std.processedit.meopview.MEOPEditView">
</equals>
</iterate>
</not>
</with>
</visibleWhen>
</command>
<command commandId="ProcessDivisionHandler" id="ProcessDivisionHandler" mnemonic="S"/>
<command commandId="GXDivisionHandler" id="GXDivisionHandler" mnemonic="S"/>
<command commandId="ProcessMultiplexHandler" id="ProcessMultiplexHandler" mnemonic="S"/>
<command commandId="cn.net.connor.std.processedit.commands.CreateBOMViewHandler" id="cn.net.connor.std.processedit.commands.CreateBOMViewHandler" mnemonic="S"/>
</menuContribution>
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command commandId="cn.net.connor.std.processedit.commands.NewProcessCommand" icon="icons/meprocess_16.png" id="popups.newprocess">
<visibleWhen>
<with variable="rac_command_suppression">
<not>
<iterate operator="or">
<equals
value="cn.net.connor.std.processedit.commands.NewProcessCommand">
</equals>
</iterate>
</not>
</with>
</visibleWhen>
</command>
<command commandId="cn.net.connor.std.processedit.commands.NewMeopCommand" icon="icons/meoperation_16.png" id="popups.newmeop">
<visibleWhen>
<with variable="rac_command_suppression">
<not>
<iterate operator="or">
<equals
value="cn.net.connor.std.processedit.commands.NewMeopCommand">
</equals>
</iterate>
</not>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.bindings">
<!--创建工艺-->
<key
commandId="cn.net.connor.std.processedit.commands.NewProcessCommand"
sequence="M3+N"
schemeId="com.teamcenter.rac.scheme">
</key>
<!--创建工序-->
<key
commandId="cn.net.connor.std.processedit.commands.NewMeopCommand"
sequence="M3+C"
schemeId="com.teamcenter.rac.scheme">
</key>
<!--修订工艺>
<!key
commandId="com.connor.nhjs.gy.revise.process.ReviseProcessHandler"
sequence="M3+R"
schemeId="com.teamcenter.rac.scheme">
</key-->
<!--工序简图>
<key
commandId="cn.net.connor.std.word.commands.MeopDatasetCommand"
sequence="M3+J"
schemeId="com.teamcenter.rac.scheme">
</key-->
<!--工艺合本>
<key
commandId="cn.net.connor.std.word.commands.MergePDFCommand"
sequence="M3+H"
schemeId="com.teamcenter.rac.scheme">
</key-->
<!--打开附件-->
<key
commandId="cn.net.connor.std.processedit.commands.OpenViewCommand#com.teamcenter.rac.cme.attachments"
sequence="M3+I"
schemeId="com.teamcenter.rac.scheme">
</key>
<!--工艺借用-->
<key
commandId="ProcessBorrowHandler"
sequence="M3+M"
schemeId="com.teamcenter.rac.scheme">
</key>
<!--工序借用>
<key
commandId="MEOPBorrowHandler"
sequence="M3+O"
schemeId="com.teamcenter.rac.scheme">
</key-->
<!--创建变更>
<key
commandId="cn.com.create.change.CreateChangeHandler"
sequence="M3+L"
schemeId="com.teamcenter.rac.scheme">
</key-->
</extension>
</plugin>

@ -0,0 +1,44 @@
package cn.net.connor.std.processedit;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "cn.net.connor.std.processedit"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}

@ -0,0 +1,27 @@
package cn.net.connor.std.processedit;
import java.lang.reflect.Method;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IStartup;
import javafx.embed.swt.FXCanvas;
public class KStartup implements IStartup {
@Override
public void earlyStartup() {
Display.getDefault().asyncExec(()->{
try {
Class<?> c = FXCanvas.class;
Method m = c.getDeclaredMethod("initFx", new Class[0]);
m.setAccessible(true);
m.invoke(FXCanvas.class, new Object[0]);
System.out.println("FXCanvas inited");
} catch (Exception e) {
e.printStackTrace();
}
});
}
}

@ -0,0 +1,151 @@
package cn.net.connor.std.processedit.choose;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KDialog;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KUtil;
@SuppressWarnings("serial")
public class ChooseDialog extends KDialog {
private ChooseDialogController controller;
private JButton b_ok;
private JButton b_cel;
private JButton b_search;
private static final Registry REG = Registry.getRegistry(ChooseDialog.class);
public ChooseDialog(AbstractAIFDialog newMeopDialog, KDialogController controller) {
super(newMeopDialog,true,controller);
this.controller = (ChooseDialogController) controller;
}
@Override
protected void addListeners() {
this.b_cel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
this.b_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.doSelect();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ChooseDialog.this,e1);
}
}
});
this.b_search.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.doSearch();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ChooseDialog.this,e1);
}
}
});
}
@Override
protected void initUI() {
this.setTitle(REG.getString("select.TITLE"));
this.setPreferredSize(new Dimension(900, 500));
this.setMinimumSize(new Dimension(550, 400));
this.setLayout(new BorderLayout());
this.add(BorderLayout.CENTER, initTablePanel());
this.add(BorderLayout.EAST, initSearchPanel());
}
private Component initBtnPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 0));
panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
this.b_search = new JButton(REG.getString("search"));
this.b_ok = new JButton(REG.getString("ok"));
this.b_cel = new JButton(REG.getString("cancel"));
if (controller.searchCols.size() > 0) {
panel.add(b_search);
}
panel.add(b_ok);
panel.add(b_cel);
return panel;
}
private Component initSearchPanel() {
JPanel panel = new JPanel(new BorderLayout());
if (controller.searchCols.size() == 0) {
this.add(BorderLayout.SOUTH, initBtnPanel());
return panel;
}
JPanel searchPanel = new JPanel(new GridBagLayout());
searchPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
GridBagConstraints s = getGridBagConstraints(0, 0, new Insets(5, 5, 5, 5));
for (String title : controller.searchCols) {
KUtil.newRow(searchPanel, new JLabel(title), s, 1);
JTextField textField = new JTextField(12);
controller.searchComps.put(title, textField);
KUtil.addCol(searchPanel, textField, s, 1, 1);
textField.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
b_search.doClick();
}
}
});
}
s.weighty = 1;
KUtil.newRow(searchPanel, new JLabel(""), s, 1);
JScrollPane scroll = new JScrollPane(searchPanel);
scroll.setBorder(null);
panel.add(BorderLayout.CENTER, scroll);
panel.add(BorderLayout.SOUTH, initBtnPanel());
return panel;
}
private Component initTablePanel() {
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 0));
JScrollPane scroll = new JScrollPane(controller.tableBean.getTable());
panel.add(BorderLayout.CENTER, scroll);
if(!controller.isNHJSChooseSafeDesc) {
controller.tableBean.getTable().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON1 && e.getClickCount()==2) {
b_ok.doClick();
}
}
});
}
return panel;
}
}

@ -0,0 +1,172 @@
package cn.net.connor.std.processedit.choose;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.util.KExcelTable;
import cn.net.connor.std.processedit.util.KExcelTable.Config;
import cn.net.connor.std.processedit.util.PrefComponent;
public class ChooseDialogController extends KDialogController {
private String typeName;
private String[] config;
private List<PrefComponent> prefComponents;
// private Map<String, JTextComponent> otherComps;
private ChooseDialog dialog;
protected File excelFile;
protected List<Config> configs = new ArrayList<Config>();
protected List<String> searchCols = new ArrayList<String>();
protected Map<String, JTextField> searchComps = new HashMap<String, JTextField>();
protected KExcelTable tableBean;
protected boolean isNHJSChooseSafeDesc = false;
private static final String PREFIX_NHJS_CHOOSE_SAFE_DESC = "#NHJS_SAFE_DESC#";
private static final Registry REG = Registry.getRegistry(ChooseDialogController.class);
public ChooseDialogController(AbstractAIFApplication app, String type, PrefComponent bean, List<PrefComponent> prefComponents) {
this.typeName = type;
this.config = bean.getExcelConfig();
this.prefComponents = prefComponents;
}
@Override
public boolean init() throws Exception {
this.dialog = (ChooseDialog) aifDialog;
int len = KUtil.getLen(config);
if (len == 0) {
System.out.println("No Choose Config");
throw new TCException(REG.getString("novalidchooseconfig.ERROR"));
}
String uid = config[0];
this.isNHJSChooseSafeDesc = uid.startsWith(PREFIX_NHJS_CHOOSE_SAFE_DESC);
if(this.isNHJSChooseSafeDesc) {
uid = uid.substring(PREFIX_NHJS_CHOOSE_SAFE_DESC.length());
}
System.out.println(">> Uid: " + uid);
if (!KUtil.isEmpty(typeName)) {
int ind = uid.indexOf("" + typeName + ":");
if (ind > 0) {
uid = uid.substring(ind + typeName.length() + 1);
}
}
int ind = uid.indexOf(';');
if (ind > 0) {
uid = uid.substring(0, ind);
}
System.out.println(">> Uid for type [" + typeName + "] is: " + uid);
if (KUtil.isEmpty(uid)) {
throw new TCException(REG.getString("novalidchooseconfig.ERROR"));
}
TCComponentDataset excelDataset = null;
try {
excelDataset = (TCComponentDataset) session.stringToComponent(uid);
} catch (Exception e) {
e.printStackTrace();
}
if (excelDataset == null || !"MSExcelX".equals(excelDataset.getType())) {
throw new TCException(REG.getString("novalidchooseconfig.ERROR"));
}
// Read Config
for (int i = 1; i < len; i++) {
String pref = config[i];
String[] split = pref.split("=", -1);
int splitCnt = KUtil.getLen(split);
String tableCol = null, excelCol = null, propConfig = null;
int prefW = 100;
if (splitCnt > 0) {
tableCol = split[0];
}
if (splitCnt > 1) {
excelCol = split[1];
}
if (splitCnt > 2) {
propConfig = split[2];
}
if (splitCnt > 3) {
try {
prefW = Integer.parseInt(split[3]);
} catch (Exception e) {
e.printStackTrace();
}
}
if (!KUtil.isEmpty(tableCol) && !KUtil.isEmpty(excelCol)) {
if (tableCol.startsWith("#")) {
tableCol = tableCol.substring(1);
System.out.println(">> Add Search: " + tableCol);
if (!this.searchCols.contains(tableCol)) {
this.searchCols.add(tableCol);
}
}
this.configs.add(new Config(tableCol, excelCol, propConfig, prefW));
} else {
System.out.println("ERROR Config: " + pref);
}
}
this.excelFile = KUtil.getDatasetFile(excelDataset);
if (this.excelFile == null || !this.excelFile.exists()) {
throw new TCException(REG.getString("novalidchooseconfig.ERROR"));
}
this.tableBean = new KExcelTable(configs, excelFile.getAbsolutePath(), this.isNHJSChooseSafeDesc);
return true;
}
public void doSearch() throws Exception {
Map<String, String> searchInfo = new HashMap<String, String>();
System.out.println("Perform Search..");
for (String colName : this.searchComps.keySet()) {
String value = this.searchComps.get(colName).getText();
if (!KUtil.isEmpty(value)) {
System.out.println(">> " + colName + " = " + value);
searchInfo.put(colName, value);
}
}
this.tableBean.performSearch(searchInfo);
}
public void doSelect() throws Exception {
LinkedHashMap<Config, String> data = this.tableBean.getSelectedData();
if (data == null || data.size() <= 0) {
System.out.println("No Select Info");
dialog.disposeDialog();
return;
}
System.out.println("Selected Row: " + Arrays.toString(data.values().toArray()));
for (Config colConfig : data.keySet()) {
String val = data.get(colConfig);
String addition = colConfig.getAdditionalInfo();
if (KUtil.isEmpty(addition)) {
continue;
}
System.out.println(">> Set " + addition + " = " + val);
for (PrefComponent comp : this.prefComponents) {
if (addition.equals(comp.getPropConfig())) {
System.out.println(comp.getValueComp());
if (comp.getValueComp() instanceof JTextArea) {
// 安全说明进行追加
JTextArea textArea = (JTextArea) comp.getValueComp();
textArea.setText(textArea.getText() + val);
} else {
comp.setValue(val);
}
}
}
}
dialog.disposeDialog();
}
}

@ -0,0 +1,5 @@
select.TITLE=\u9009\u62E9
search=\u67E5\u8BE2
ok=\u786E\u5B9A
cancel=\u53D6\u6D88
novalidchooseconfig.ERROR=\u6CA1\u6709\u627E\u5230\u6709\u6548\u914D\u7F6E

@ -0,0 +1,158 @@
package cn.net.connor.std.processedit.choosefromsql;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KDialog;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.util.PrefComponent;
@SuppressWarnings("serial")
public class ChooseFromSqlDialog extends KDialog {
private ChooseFromSqlDialogController controller;
private JButton b_ok;
private JButton b_cel;
private JButton b_search;
protected String[] config;
protected List<PrefComponent> prefComponents;
protected Map<String, TCComponent> revChildren;
private static final Registry REG = Registry.getRegistry(ChooseFromSqlDialog.class);
public ChooseFromSqlDialog(PrefComponent bean, List<PrefComponent> prefComponents, Map<String, TCComponent> revChildren) {
super();
this.config = bean.getSqlConfig();
this.prefComponents = prefComponents;
this.revChildren = revChildren;
}
@Override
protected void addListeners() {
this.b_cel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
this.b_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.doSelect();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ChooseFromSqlDialog.this, e1);
}
}
});
this.b_search.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.doSearch();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ChooseFromSqlDialog.this, e1);
}
}
});
}
@Override
protected void initUI() {
this.controller = (ChooseFromSqlDialogController) aifController;
this.setTitle(REG.getString("select.TITLE"));
this.setPreferredSize(new Dimension(900, 500));
this.setMinimumSize(new Dimension(550, 400));
this.setLayout(new BorderLayout());
this.add(BorderLayout.CENTER, initTablePanel());
this.add(BorderLayout.WEST, initSearchPanel());
}
private Component initBtnPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 0));
panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
this.b_search = new JButton(REG.getString("search"));
this.b_ok = new JButton(REG.getString("ok"));
this.b_cel = new JButton(REG.getString("cancel"));
if (controller.searchCols_DB_UI.size() > 0) {
panel.add(b_search);
}
panel.add(b_ok);
panel.add(b_cel);
return panel;
}
private Component initSearchPanel() {
JPanel panel = new JPanel(new BorderLayout());
if (controller.searchCols_DB_UI.size() == 0) {
this.add(BorderLayout.SOUTH, initBtnPanel());
return panel;
}
JPanel searchPanel = new JPanel(new GridBagLayout());
searchPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 10));
GridBagConstraints s = getGridBagConstraints(0, 0, new Insets(0, 10, 10, 0));
for (String dbColName : controller.searchCols_DB_UI.keySet()) {
String title = controller.searchCols_DB_UI.get(dbColName);
KUtil.newRow(searchPanel, new JLabel(title), s, 1);
JTextField textField = new JTextField(12);
controller.searchComps.put(dbColName, textField);
KUtil.addCol(searchPanel, textField, s, 1, 1);
textField.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
b_search.doClick();
}
}
});
}
s.weighty = 1;
KUtil.newRow(searchPanel, new JLabel(""), s, 1);
JScrollPane scroll = new JScrollPane(searchPanel);
scroll.setBorder(null);
panel.add(BorderLayout.CENTER, scroll);
panel.add(BorderLayout.SOUTH, initBtnPanel());
return panel;
}
private Component initTablePanel() {
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 10));
JScrollPane scroll = new JScrollPane(controller.tableBean.getTable());
panel.add(BorderLayout.CENTER, scroll);
controller.tableBean.getTable().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
b_ok.doClick();
}
}
});
return panel;
}
}

@ -0,0 +1,242 @@
package cn.net.connor.std.processedit.choosefromsql;
import java.io.StringReader;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JTextField;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KSqlUtil;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.util.KSqlTable;
import cn.net.connor.std.processedit.util.KSqlTable.Config;
import cn.net.connor.std.processedit.util.PrefComponent;
import cn.net.connor.std.processedit.util.ProcessUtil;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.Alias;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.select.AllTableColumns;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.select.SelectExpressionItem;
import net.sf.jsqlparser.statement.select.SelectItem;
public class ChooseFromSqlDialogController extends KDialogController {
private String[] config;
private List<PrefComponent> prefComponents;
// private Map<String, JTextComponent> otherComps;
private ChooseFromSqlDialog dialog;
protected List<Config> configs = new ArrayList<Config>();
protected Map<String, String> searchCols_DB_UI = new LinkedHashMap<>();
protected Map<String, JTextField> searchComps = new HashMap<String, JTextField>();
protected KSqlTable tableBean;
private Map<String, TCComponent> revChildren;
private TCComponentItemType itemType;
private static final Registry REG = Registry.getRegistry(ChooseFromSqlDialogController.class);
public static void getTableNameBySql(String sql, List<String> headers, List<String> fields) throws JSQLParserException {
try {
CCJSqlParserManager pm = new CCJSqlParserManager();
Statement statement = pm.parse(new StringReader(sql));
if (statement instanceof Select) {
Select selectStatement = (Select) statement;
PlainSelect selectBody = (PlainSelect) selectStatement.getSelectBody();
List<SelectItem> selectItemlist = selectBody.getSelectItems();
SelectItem selectItem = null;
SelectExpressionItem selectExpressionItem = null;
AllTableColumns allTableColumns = null;
Alias alias = null;
if (selectItemlist != null) {
for (int i = 0; i < selectItemlist.size(); i++) {
selectItem = selectItemlist.get(i);
if (selectItem instanceof SelectExpressionItem) {
selectExpressionItem = (SelectExpressionItem) selectItemlist.get(i);
alias = selectExpressionItem.getAlias();
String columnName = "";
if (alias != null) {
columnName = alias.getName();
} else {
columnName = selectExpressionItem.getExpression().toString();
}
headers.add(columnName);
fields.add(selectExpressionItem.getExpression().toString());
} else if (selectItem instanceof AllTableColumns) {
allTableColumns = (AllTableColumns) selectItemlist.get(i);
headers.add(allTableColumns.toString());
fields.add(allTableColumns.toString());
} else {
headers.add(selectItem.toString());
fields.add(selectItem.toString());
}
}
}
}
} catch (JSQLParserException e) {
e.printStackTrace();
}
}
@Override
public boolean init() throws Exception {
this.dialog = (ChooseFromSqlDialog) aifDialog;
this.config = dialog.config;
this.prefComponents = dialog.prefComponents;
this.revChildren = dialog.revChildren;
int len = KUtil.getLen(config);
if (len == 0) {
System.out.println("No Choose Config");
throw new TCException(REG.getString("novalidchooseconfig.ERROR"));
}
String sql = String.join("\n", config);
System.out.println(">> sql: \n" + sql);
List<String> headers = new ArrayList<>();
List<String> fields = new ArrayList<>();
getTableNameBySql(sql, headers, fields);
System.out.println(">> headers: " + headers);
System.out.println(">> fields: " + fields);
len = headers == null ? 0 : headers.size();
// Read Config
for (int i = 0; i < len; i++) {
String dbColName = headers.get(i);
String dbFieldName = fields.get(i);
String[] split = dbColName.replace("\"", "").split("=", -1);
int splitCnt = KUtil.getLen(split);
String tableCol = null, propConfig = null;
int prefW = 100;
if (splitCnt > 0) {
tableCol = split[0];
}
if (splitCnt > 1) {
propConfig = split[1];
}
if (splitCnt > 2) {
try {
prefW = Integer.parseInt(split[2]);
} catch (Exception e) {
e.printStackTrace();
}
}
if (!KUtil.isEmpty(tableCol)) {
if (tableCol.startsWith("#")) {
tableCol = tableCol.substring(1);
System.out.println(">> Add Search: " + tableCol);
if (!this.searchCols_DB_UI.containsKey(dbFieldName)) {
this.searchCols_DB_UI.put(dbFieldName, tableCol);
}
}
this.configs.add(new Config(tableCol, dbFieldName, propConfig, prefW));
} else {
System.out.println("ERROR Config: " + dbColName);
}
if (dbColName.startsWith("\"")) {
sql = sql.replace(dbColName, "");
}
}
System.out.println("Formated Sql: \n" + sql);
this.tableBean = new KSqlTable(configs, sql);
this.itemType = (TCComponentItemType) session.getTypeComponent("Item");
return true;
}
public void doSearch() throws Exception {
Map<String, String> searchInfo = new HashMap<String, String>();
System.out.println("Perform Search..");
for (String colName : this.searchComps.keySet()) {
String value = this.searchComps.get(colName).getText();
if (!KUtil.isEmpty(value)) {
System.out.println(">> " + colName + " = " + value);
searchInfo.put(colName, value);
}
}
Connection conn = KSqlUtil.getOracleConnection(session, ProcessUtil.PREF_DB_CONN);
try {
this.tableBean.performSearch(searchInfo, conn);
} finally {
KSqlUtil.free(conn);
}
}
public void doSelect() throws Exception {
revChildren.clear();
LinkedHashMap<Config, String> data = this.tableBean.getSelectedData();
if (data == null || data.size() <= 0) {
System.out.println("No Select Info");
dialog.disposeDialog();
return;
}
System.out.println("Selected Row: " + Arrays.toString(data.values().toArray()));
for (Config colConfig : data.keySet()) {
String val = data.get(colConfig);
String addition = colConfig.getAdditionalInfo();
if (KUtil.isEmpty(addition)) {
continue;
}
if ("UID".equalsIgnoreCase(colConfig.getColName())) {
String relationName = addition;
System.out.println(">> Add " + relationName + " = " + val);
if (!KUtil.isEmpty(val)) {
TCComponent comp = null;
try {
comp = session.stringToComponent(val);
} catch (TCException e) {
e.printStackTrace();
}
System.out.println(">> Find component: " + comp);
if (comp == null) {
throw new TCException(REG.getString("loaduid.ERROR"));
}
revChildren.put(relationName, comp);
}
continue;
} else if ("ID".equalsIgnoreCase(colConfig.getColName())) {
String relationName = addition;
System.out.println(">> Add " + relationName + " = " + val);
if (!KUtil.isEmpty(val)) {
TCComponent[] items = null;
try {
items = itemType.findItems(val);
} catch (TCException e) {
e.printStackTrace();
}
System.out.println(">> Find item: " + Arrays.toString(items));
int itemCnt = KUtil.getLen(items);
TCComponentItemRevision rev = null;
for (int i = 0; i < itemCnt; i++) {
TCComponentItem item = (TCComponentItem) items[i];
rev = item.getLatestItemRevision();
}
System.out.println(">> Revision: " + rev);
if (rev == null) {
throw new TCException(String.format(REG.getString("loadid.ERROR1"), val));
}
revChildren.put(relationName, rev);
}
continue;
}
System.out.println(">> Set " + addition + " = " + val);
for (PrefComponent comp : this.prefComponents) {
if (addition.equals(comp.getPropConfig())) {
comp.setValue(val);
}
}
}
dialog.disposeDialog();
}
}

@ -0,0 +1,7 @@
select.TITLE=\u9009\u62E9
search=\u67E5\u8BE2
ok=\u786E\u5B9A
cancel=\u53D6\u6D88
novalidchooseconfig.ERROR=\u6CA1\u6709\u627E\u5230\u6709\u6548\u914D\u7F6E
loaduid.ERROR=\u65E0\u6CD5\u52A0\u8F7D\u5BF9\u8C61\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u6709\u76F8\u5173\u6743\u9650\u3002
loadid.ERROR1=\u672A\u627E\u5230\u5BF9\u8C61\u201C%s\u201D\u7684\u6700\u65B0\u7248\u672C

@ -0,0 +1,94 @@
package cn.net.connor.std.processedit.commands;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import cn.net.connor.std.aifrcp.util.KUtil;
public class CreateBOMViewHandler extends AbstractHandler {
// @Override
// public Object execute(ExecutionEvent arg0) throws ExecutionException {
// // TODO Auto-generated method stub
// AbstractAIFApplication app = AIFUtility.getCurrentApplication();
// TCSession session = (TCSession) app.getSession();
// InterfaceAIFComponent targetComponent = app.getTargetComponent();
// if(targetComponent instanceof TCComponentBOMLine) {
// TCComponentBOMLine bomLine = (TCComponentBOMLine)targetComponent;
// try {
// TCComponentItemRevision revision = (TCComponentItemRevision)bomLine.getRelatedComponent("bl_line_object");
// TCComponent[] reference = revision.getReferenceListProperty("structure_revisions");
// if(reference != null && reference.length > 0) {
// MessageBox.post("该物料已有BOM,不能重复创建!",
// "提示",MessageBox.INFORMATION);
// return null;
// }else {
// KUtil.setByPassItk(session, true);
// TCComponentItemType t = (TCComponentItemType) session.getTypeService().getTypeComponent("Item");
// TCComponentItem item1 = t.findItems("000001")[0];
// TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
// TCComponentBOMWindow window = bomWinType.create(null);
// TCComponentBOMLine newBom = window.setWindowTopLine(null, revision, null, null);
// TCComponentBOMLine newnewLine = newBom.add(item1, item1.getLatestItemRevision(), null, false);
// window.save();
// newnewLine.cut();
// window.save();
// window.close();
// KUtil.setByPassItk(session, false);
// MessageBox.post("创建成功!", "", MessageBox.INFORMATION);
// }
// } catch (TCException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }else {
// MessageBox.post("请选择BOMLine对象!", "提示", MessageBox.INFORMATION);
//
// }
// return null;
// }
@SuppressWarnings("unused")
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
// TODO Auto-generated method stub
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
InterfaceAIFComponent targetComponent = app.getTargetComponent();
if(targetComponent instanceof TCComponentBOMLine) {
TCComponentBOMLine bomLine = (TCComponentBOMLine)targetComponent;
G4MDialog classDialog = new G4MDialog("精雕分类", null, session,bomLine);
new Thread(classDialog).start();
}else {
MessageBox.post("请选择BOMLine对象!", "提示", MessageBox.INFORMATION);
}
return null;
}
}

@ -0,0 +1,252 @@
package cn.net.connor.std.processedit.commands;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JPanel;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.classification.common.AbstractG4MApplication;
import com.teamcenter.rac.classification.common.G4MApplicationPanel;
import com.teamcenter.rac.classification.common.G4MUserAppContext;
import com.teamcenter.rac.classification.common.table.G4MTable;
import com.teamcenter.rac.classification.icm.ICMApplication;
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.TCComponentICO;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import cn.net.connor.std.aifrcp.util.KUtil;
@SuppressWarnings("serial")
public class G4MDialog extends AbstractAIFDialog {
private JButton b_ok;
private JButton b_cel;
private ICMApplication app;
private MyG4MContext m_context;
protected TCComponentICO ico;
private String expandClass;
private List<TCComponentItemRevision> revList;
private TCComponentBOMLine targeTcComponentBOMLine;
InterfaceAIFComponent iaf;
TCComponentForm form;
TCSession session;
// public G4MDialog(String expandClass, InterfaceAIFComponent iaf, QZjsbjdBean jsbjdBean, TCSession session, TCComponentForm form) {
// super(AIFDesktop.getActiveDesktop(), true);
// this.jsbjdBean=jsbjdBean;
// this.expandClass = expandClass;
// this.iaf = iaf;
// this.session=session;
// this.form=form;
// try {
// this.app = new ICMApplication();
// this.m_context = new MyG4MContext(app, "k0");
// } catch (Exception e) {
// e.printStackTrace();
// }
// initUI();
// }
public G4MDialog(String expandClass, InterfaceAIFComponent iaf, TCSession session,TCComponentBOMLine targeTcComponentBOMLine) {
super(AIFDesktop.getActiveDesktop(), true);
this.expandClass = expandClass;
this.iaf = iaf;
this.session=session;
this.targeTcComponentBOMLine = targeTcComponentBOMLine;
try {
this.app = new ICMApplication();
this.m_context = new MyG4MContext(app, "k0");
} catch (Exception e) {
e.printStackTrace();
}
initUI();
}
@Override
public void run() {
showDialog();
}
private void initUI() {
this.setTitle("材料选取");
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(1000, 600));
this.setMinimumSize(new Dimension(640, 480));
MyG4MPanel panel = new MyG4MPanel(null);
try {
m_context.openComponent(iaf);
panel.initialize(m_context);
this.add(BorderLayout.CENTER, panel);
m_context.getTree().expandToClass(expandClass);
// new Thread(m_context.getClassificationDialog()).start();
} catch (Exception e) {
e.printStackTrace();
}
// panel.open(iaf);
this.add(BorderLayout.SOUTH, initBtnPanel());
addListeners();
}
private void addListeners() {
b_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
G4MTable table = m_context.getTablePane().getG4MTable();
List<?> list = null;
if (table != null) {
ISelection sel = table.getSelection();
if (sel != null && sel instanceof StructuredSelection) {
list = ((StructuredSelection) sel).toList();
}
}
if (list == null || list.size() == 0) {
MessageBox.post("请选择要使用的对象", "", MessageBox.INFORMATION);
// KUtil.info(G4MDialog.this, "请选择要使用的对象");
return;
}
if (list.size() > 1) {
MessageBox.post("请选择单行数据", "", MessageBox.INFORMATION);
// KUtil.info(G4MDialog.this, "请选择单行数据");
return;
}
Object target = list.get(0);
revList = new ArrayList<TCComponentItemRevision>();
if (target != null && target instanceof TCComponentICO) {
ico = (TCComponentICO) target;
System.out.println(" ico.getClassId()=====" + ico.getClassId());
TCComponent classifiedObject = ico.getClassifiedObject();
TCComponentItemRevision rev = null;
if(classifiedObject instanceof TCComponentItemRevision) {
rev = (TCComponentItemRevision) classifiedObject;
}else if(classifiedObject instanceof TCComponentItem) {
TCComponentItem item = (TCComponentItem) classifiedObject;
try {
rev = item.getLatestItemRevision();
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
System.out.println("ico.id==="+ico.getId());
System.out.println("rev==="+rev);
revList.add(rev);
if(revList != null && revList.size() > 0) {
try {
TCComponentItemRevision revision = (TCComponentItemRevision)targeTcComponentBOMLine.getRelatedComponent("bl_line_object");
KUtil.setByPassItk(session, true);
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow window = bomWinType.create(null);
TCComponentBOMLine newBom = window.setWindowTopLine(null, revision, null, null);
for (int i = 0; i < revList.size(); i++) {
TCComponentItemRevision tcComponentItemRevision = revList.get(i);
newBom.add(tcComponentItemRevision.getItem(), tcComponentItemRevision, null, false);
}
window.save();
window.close();
KUtil.setByPassItk(session, false);
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else {
MessageBox.post("请选择分类对象!", "提示", MessageBox.INFORMATION);
}
MessageBox.post("图纸引用成功!!!", "成功", MessageBox.INFORMATION);
} else {
MessageBox.post("选择的数据不是ICO对象", "", MessageBox.INFORMATION);
// KUtil.info(G4MDialog.this, "选择的数据不是ICO对象");
return;
}
}
});
b_cel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
}
private JPanel initBtnPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 25, 5));
this.b_ok = new JButton("确定");
this.b_cel = new JButton("取消");
panel.add(b_ok);
panel.add(b_cel);
return panel;
}
public class MyG4MContext extends G4MUserAppContext {
public MyG4MContext(AbstractAIFUIApplication paramAbstractAIFUIApplication, String paramString)
throws Exception {
super(paramAbstractAIFUIApplication, paramString);
}
@Override
public void setBusy(String paramString) {
}
@Override
public void setIdle(String paramString) {
}
}
public class MyG4MPanel extends G4MApplicationPanel {
public MyG4MPanel(AbstractG4MApplication paramAbstractG4MApplication) {
super(paramAbstractG4MApplication);
}
@Override
public void closeSignaled() {
try {
m_context.clear();
} catch (Exception e) {
e.printStackTrace();
}
// m_context.openComponent(iaf);
}
}
}

@ -0,0 +1,15 @@
package cn.net.connor.std.processedit.commands;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import cn.net.connor.std.aifrcp.KCommand;
import cn.net.connor.std.processedit.modifymeopno.ModifyMeopNoDialog;
public class ModifyMeopNoCommand extends KCommand{
public ModifyMeopNoCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
super(app, commandId, actionInfo);
this.setRunnable(new ModifyMeopNoDialog());
}
}

@ -0,0 +1,15 @@
package cn.net.connor.std.processedit.commands;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import cn.net.connor.std.aifrcp.KCommand;
import cn.net.connor.std.processedit.newdatasetfromtemplate.NewDatasetFromTemplateOperation;
public class NewDatasetFromTemplateCommand extends KCommand{
public NewDatasetFromTemplateCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
super(app, commandId, actionInfo);
this.setRunnable(new NewDatasetFromTemplateOperation(app, actionInfo));
}
}

@ -0,0 +1,17 @@
package cn.net.connor.std.processedit.commands;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import cn.net.connor.std.aifrcp.KCommand;
import cn.net.connor.std.processedit.newmeop.NewMeopDialog;
import cn.net.connor.std.processedit.newmeop.NewMeopDialogController;
public class NewMeopCommand extends KCommand {
public NewMeopCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
super(app, commandId, actionInfo);
System.out.println("NewMeopCommand");
this.setRunnable(new NewMeopDialog(new NewMeopDialogController(app)));
}
}

@ -0,0 +1,17 @@
package cn.net.connor.std.processedit.commands;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import cn.net.connor.std.aifrcp.KCommand;
import cn.net.connor.std.processedit.newmeprocess.NewProcessDialog;
import cn.net.connor.std.processedit.newmeprocess.NewProcessDialogController;
public class NewProcessCommand extends KCommand{
public NewProcessCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
super(app, commandId, actionInfo);
System.out.println("NewProcessCommand");
this.setRunnable(new NewProcessDialog(new NewProcessDialogController(app)));
}
}

@ -0,0 +1,75 @@
package cn.net.connor.std.processedit.commands;
import java.util.Arrays;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.cme.time.common.ActivityUtils;
import com.teamcenter.rac.cme.time.common.CommonUtils;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentCfgActivityLine;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PlatformHelper;
import cn.net.connor.std.aifrcp.KCommand;
import cn.net.connor.std.aifrcp.util.KUtil;
public class OpenViewCommand extends KCommand {
public OpenViewCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
super(app, commandId, actionInfo);
}
@Override
protected void executeCommand() throws Exception {
System.out.println("Open View: " + actionInfo);
if (KUtil.isEmpty(actionInfo)) {
return;
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
IWorkbenchWindow var1 = AIFUtility.getActiveDesktop().getDesktopWindow();
IWorkbenchPage var2 = var1.getActivePage();
IViewPart sv = var2.findView(actionInfo);
if (sv == null) {
sv = var2.showView(actionInfo);
}
PlatformHelper.getCurrentPage().activate(sv);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
protected void test() throws Exception{
TCComponentBOMLine targetLine = (TCComponentBOMLine) app.getTargetComponent();
TCComponentCfgActivityLine actLine = (TCComponentCfgActivityLine) targetLine.getReferenceProperty("bl_me_activity_lines");
if (actLine != null) {
TCComponent[] cc = ActivityUtils.getSortedActivityChildren(actLine);
System.out.println(">> " + Arrays.toString(cc));
int len = KUtil.getLen(cc);
if (len > 1) {
CommonUtils.getSession().suspendEvent();
try {
ActivityUtils.moveActivityBefore(cc[1], cc[0]);
} catch (TCException tCException) {
MessageBox.post(tCException);
} finally {
CommonUtils.getSession().resumeEvent();
}
}
}
}
}

@ -0,0 +1,66 @@
package cn.net.connor.std.processedit.ldy;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
public class CheckHeaderCellRenderer implements TableCellRenderer {
DefaultTableModel tableModel;
JTableHeader tableHeader;
final JCheckBox selectBox;
public CheckHeaderCellRenderer(final JTable table, boolean select) {
this.tableModel = (DefaultTableModel) table.getModel();
this.tableHeader = table.getTableHeader();
selectBox = new JCheckBox(tableModel.getColumnName(0));
selectBox.setSelected(select);
tableHeader.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 0) {
// 获得选中列
int selectColumn = tableHeader.columnAtPoint(e.getPoint());
if (selectColumn == 0) {
boolean value = !selectBox.isSelected();
selectBox.setSelected(value);
// tableModel.selectAllOrNull(value);
for(int i=0; i<tableModel.getRowCount(); i++) {
tableModel.setValueAt(value, i, 0);
}
tableHeader.repaint();
}
}
}
});
}
@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);
// selectBox.setSelected(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,56 @@
package cn.net.connor.std.processedit.ldy;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCAccessControlService;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
//创建常规文件夹结构
public class CutterWordTimeHandler extends AbstractHandler implements IHandler{
public Object execute(ExecutionEvent arg0) throws ExecutionException {
System.out.println("CutterWordTimeHandler");
// new Thread() {
// public void run() {
// }
// }.start();
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
InterfaceAIFComponent target = app.getTargetComponent();
AIFDesktop desktop = AIFUtility.getActiveDesktop();
try {
if(!(target instanceof TCComponentBOMLine)) {
MessageBox.post(desktop, "请选择工序BOM进行操作", "ERROR", MessageBox.ERROR);
return null;
}
TCComponentItemRevision rev = ((TCComponentBOMLine)target).getItemRevision();
if(!rev.isTypeOf("LD6_MEOPRevision")) {
MessageBox.post(desktop, "请选择工序BOM进行操作", "ERROR", MessageBox.ERROR);
return null;
}
TCAccessControlService accessControlService = session.getTCAccessControlService();
if(!accessControlService.checkUsersPrivilege(session.getUser(), rev, TCAccessControlService.WRITE)) {
MessageBox.post(desktop, "当前用户对"+rev+"没有写权限,无法执行命令", "ERROR", MessageBox.ERROR);
return null;
}
CutterWordTimeOperation operation = new CutterWordTimeOperation(session, (TCComponentBOMLine)target);
session.queueOperation(operation);
}catch(Exception e) {
e.printStackTrace();
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
return null;
}
return null;
}
}

@ -0,0 +1,72 @@
package cn.net.connor.std.processedit.ldy;
import java.math.BigDecimal;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class CutterWordTimeOperation extends AbstractAIFOperation {
// private TCSession session;
private TCComponentBOMLine target;
public CutterWordTimeOperation(TCSession session, TCComponentBOMLine target) {
// this.session = session;
this.target = target;
}
@Override
public void executeOperation() throws Exception {
AIFDesktop desktop = AIFUtility.getActiveDesktop();
try {
BigDecimal loadingTime = new BigDecimal(0), measureTime = new BigDecimal(0);
StringBuilder message = new StringBuilder("");
for(AIFComponentContext c : target.getChildren()) {
TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent();
TCComponentItemRevision rev = bom.getItemRevision();
if(!rev.isTypeOf("LD6_ComtooldesRevision"))
continue;
String ld6_loadingTime = rev.getProperty("ld6_loadingTime");
if(ld6_loadingTime.isEmpty())
ld6_loadingTime = "0";
String ld6_measureTime = rev.getProperty("ld6_measureTime");
if(ld6_measureTime.isEmpty())
ld6_measureTime = "0";
String bl_quantity = bom.getProperty("bl_quantity");
if(bl_quantity.isEmpty())
bl_quantity = "1";
try {
// loadingTime += Double.parseDouble(ld6_loadingTime) * Double.parseDouble(bl_quantity);
loadingTime = loadingTime.add(new BigDecimal(ld6_loadingTime).multiply(new BigDecimal(bl_quantity)));
}catch(Exception e) {
e.printStackTrace();
message.append("组合刀具【").append(rev).append("】的装刀时间有错误无法计算\n");
}
try {
// measureTime += Double.parseDouble(ld6_measureTime) * Double.parseDouble(bl_quantity);
measureTime = measureTime.add(new BigDecimal(ld6_measureTime).multiply(new BigDecimal(bl_quantity)));
}catch(Exception e) {
e.printStackTrace();
message.append("组合刀具【").append(rev).append("】的量刀时间有错误无法计算\n");
}
}
target.getItemRevision().setProperty("ld6_loadingTime", ""+loadingTime);
target.getItemRevision().setProperty("ld6_measureTime", ""+measureTime);
target.refresh();
if(message.length()==0)
MessageBox.post(desktop, "刀具工时统计完成", "INFO", MessageBox.INFORMATION);
else
MessageBox.post(desktop, message.toString(), "WARN", MessageBox.WARNING);
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
}
}
}

@ -0,0 +1,277 @@
package cn.net.connor.std.processedit.ldy;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCAccessControlService;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentEnvelope;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.services.rac.core.DataManagementService;
import com.teamcenter.services.rac.core.EnvelopeService;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse;
public class GXDivisionDialog extends AbstractAIFDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
private TCSession session;
private JTable table;
private DefaultTableModel model;
private String[] tableHeader;
private JButton divisionBtn;
private JButton okBtn;
private JButton cancelBtn;
private int ld6_resperson = -1;
private TCAccessControlService accessControlService;
private ArrayList<String[]> colList;
private ArrayList<TCComponent[]> compList;
private HashMap<String, TCComponentUser> userMap;
public GXDivisionDialog(TCSession session, TCComponentBOMLine[] target, String[] options) throws Exception{
super(AIFUtility.getActiveDesktop());
this.session = session;
accessControlService = session.getTCAccessControlService();
userMap = new HashMap<>();
compList = new ArrayList<>();
setTitle("工序分工");
divisionBtn = new JButton("工序分工");
okBtn = new JButton("确定");
cancelBtn = new JButton("取消");
addActionListener();
// String[] tableHeader = new String[] { "序号", "名称", "规格" };
int size = options.length;
tableHeader = new String[size+1];
tableHeader[0] = "序号";
colList = new ArrayList<>();
for(int i=0; i<size; i++) {
String[] option = options[i].split("=");
tableHeader[i+1] = option[0];
if(option[1].equals("Rev.j6_resperson")) {//TODO object_desc
ld6_resperson = i+1;
}
String[] prop = option[1].split("\\.");
colList.add(prop);
}
if(ld6_resperson == -1) {
throw new Exception("首选项未配置Rev.j6_resperson无法进行分工");
}
model = new DefaultTableModel(tableHeader, 0);
table = new JTable() {
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int col) {
return false;
}
};
table.setFillsViewportHeight(true);
table.setEnabled(true);
// impTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setModel(model);
table.getColumnModel().getColumn(0).setPreferredWidth(50);
for (int i = 1; i < table.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setPreferredWidth(180);
}
table.getTableHeader().setReorderingAllowed(false);
recycleBom(target);
JScrollPane tablePanel = new JScrollPane();
tablePanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
tablePanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
tablePanel.setViewportView(table);
JPanel btnPanel = new JPanel(new FlowLayout());
btnPanel.add(divisionBtn);
btnPanel.add(okBtn);
btnPanel.add(cancelBtn);
// tablePanel.setBounds(20, 20, 330, 180);
// okBtn.setBounds(70, 220, 100, 25);
// cancelBtn.setBounds(180, 220, 100, 25);
setLayout(new BorderLayout());
add(BorderLayout.CENTER, tablePanel);
add(BorderLayout.SOUTH, btnPanel);
// add(new JLabel(""));
setSize(new Dimension(1000, 600));
Dimension screen = getToolkit().getScreenSize();
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
this.setAlwaysOnTop(true);
setVisible(true);
}
private void addActionListener() {
final AbstractAIFDialog dialog = this;
divisionBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
int[] rows = table.getSelectedRows();
if(rows==null || rows.length==0) {
MessageBox.post(GXDivisionDialog.this, "请选择要分工的行", "ERROR", MessageBox.ERROR);
return;
}
new SelectUserDialog(table, rows, ld6_resperson, userMap).showDialog();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(dialog, "错误:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
return;
}
// dialog.dispose();
}
});
okBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
for(int i=0; i<table.getRowCount(); i++) {
String user = table.getValueAt(i, ld6_resperson).toString();
if(user.isEmpty() || !userMap.containsKey(user))
continue;
for(TCComponent comp : compList.get(i)) {
// if(!accessControlService.checkAccessorsPrivilege(atccomponent, topFolder, "WRITE"))
accessControlService.grantPrivilege(comp, userMap.get(user), new String[]{ "WRITE" });
}
compList.get(i)[1].setProperty("j6_resperson", user);//TODO object_desc
sendMail("工序分工", "您好,此任务已经分配给您请及时完成", userMap.get(user), compList.get(i));
}
MessageBox.post(dialog, "分工完成", "INFO", MessageBox.INFORMATION);
dispose();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(dialog, "错误:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
return;
}
// dialog.dispose();
}
});
cancelBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
}
// private void recycleBom(TCComponentBOMLine parent) throws Exception {
// for(AIFComponentContext c : parent.getChildren()) {
// TCComponentBOMLine line = (TCComponentBOMLine) c.getComponent();
//// String type = line.getItemRevision().getType();
//// if(!type.equals("LD6_MEOPRevision") && !type.equals("LD6_ProDevMEOPRevision")) {
//// if(!type.equals("LD6_MEProcessRevision") && !type.equals("LD6_OMEOPRevision")) {
// /*
// * if(!type.equals("LD6_MEOPRevision")) { recycleBom(line); continue; }
// */
// TCComponentItem item = line.getItem();
// TCComponentItemRevision rev = line.getItemRevision();
// TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev);
// Vector<String> v = new Vector<>();
// v.add(table.getRowCount()+1+"");
// for(String[] s : colList) {
// if(s[0].equals("Item")) {
// v.add(item.getProperty(s[1]));
// }else if(s[0].equals("Rev")) {
// v.add(rev.getProperty(s[1]));
// }else if(s[0].equals("RevMaster")) {
// v.add(form.getProperty(s[1]));
// }else if(s[0].equals("BOMLine")) {
// v.add(line.getProperty(s[1]));
// }
// }
// model.addRow(v);
// AIFComponentContext[] cs = rev.getChildren("bom_view_tags");
// if(cs.length>0)
// compList.add(new TCComponent[] { item, rev, form, (TCComponent) cs[0].getComponent() });
// else
// compList.add(new TCComponent[] { item, rev, form });
// recycleBom(line);
// }
// }
private void recycleBom(TCComponentBOMLine[] parent) throws Exception {
for (int i = 0; i < parent.length; i++) {
TCComponentBOMLine line = parent[i];
TCComponentItem item = line.getItem();
TCComponentItemRevision rev = line.getItemRevision();
TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev);
Vector<String> v = new Vector<>();
v.add(table.getRowCount()+1+"");
for(String[] s : colList) {
if(s[0].equals("Item")) {
v.add(item.getProperty(s[1]));
}else if(s[0].equals("Rev")) {
v.add(rev.getProperty(s[1]));
}else if(s[0].equals("RevMaster")) {
v.add(form.getProperty(s[1]));
}else if(s[0].equals("BOMLine")) {
v.add(line.getProperty(s[1]));
}
}
model.addRow(v);
AIFComponentContext[] cs = rev.getChildren("bom_view_tags");
if(cs.length>0)
compList.add(new TCComponent[] { item, rev, form, (TCComponent) cs[0].getComponent() });
else
compList.add(new TCComponent[] { item, rev, form });
}
}
private void sendMail(String name, String desc, TCComponentUser user, TCComponent[] comps) throws Exception {
DataManagementService dataManagementService = DataManagementService.getService(session);
CreateIn[] arrayOfCreateIn = new CreateIn[] { new CreateIn() };
CreateInput createInput = new CreateInput();
createInput.stringProps.put("object_name", name);
createInput.stringProps.put("object_desc", desc);
createInput.boName = "Envelope";
createInput.tagArrayProps.put("listOfReceivers", new TCComponent[] { user });
createInput.tagArrayProps.put("contents", comps);
// if (paramArrayOfString1 != null && paramArrayOfString1.length > 0)
// createInput.stringArrayProps.put("fnd0ListOfExtRecipients", paramArrayOfString1);
// if (paramArrayOfString2 != null && paramArrayOfString2.length > 0)
// createInput.stringArrayProps.put("fnd0ListOfCcExtRecipients", paramArrayOfString2);
arrayOfCreateIn[0].data = createInput;
CreateResponse createResponse = dataManagementService.createObjects(arrayOfCreateIn);
// String uid2 = e.getUid();
// System.out.println("uid2===================="+uid2);
TCComponentEnvelope[] arrayOfTCComponentEnvelope = new TCComponentEnvelope[] { (TCComponentEnvelope)createResponse.output[0].objects[0] };
EnvelopeService envelopeService = EnvelopeService.getService(session);
envelopeService.sendAndDeleteEnvelopes(arrayOfTCComponentEnvelope);
}
}

@ -0,0 +1,76 @@
package cn.net.connor.std.processedit.ldy;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
//创建常规文件夹结构
public class GXDivisionHandler extends AbstractHandler implements IHandler{
public Object execute(ExecutionEvent arg0) throws ExecutionException {
System.out.println("DivisionHandler");
AIFDesktop desktop = AIFUtility.getActiveDesktop();
try {
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
InterfaceAIFComponent[] targetComponents = app.getTargetComponents();
List<TCComponentBOMLine> tcList = new ArrayList<>();
for (InterfaceAIFComponent comp : targetComponents) {
if (comp instanceof TCComponentBOMLine) {
tcList.add((TCComponentBOMLine) comp);
}
// 可选:记录非 TCComponent 对象用于调试
// else { System.out.println("跳过非TCComponent对象: " + comp); }
}
// 3. 转换为数组
TCComponentBOMLine[] target = tcList.toArray(new TCComponentBOMLine[0]);
if(target.length <= 0) {
MessageBox.post(desktop, "请选择工序路线对象进行工序分工", "ERROR", MessageBox.ERROR);
return null;
}
/*
* String type = ((TCComponentBOMLine)target).getItemRevision().getType();
* if(!type.equals("LD6_MEProcessCrRevision")) { MessageBox.post(desktop,
* "请选择工序路线BOM进行工序分工", "ERROR", MessageBox.ERROR); return null; }
*/
String[] options = session.getPreferenceService().getStringValues("Connor_GXFG");
if(options==null || options.length==0) {
MessageBox.post(desktop, "首选项Connor_GXFG配置不正确", "ERROR", MessageBox.ERROR);
return null;
}
// String optionC[] = session.getPreferenceService().getStringValues("Connor_AVIC_Apply_Create");
// if(optionC==null || optionC.length==0) {
// MessageBox.post(AIFUtility.getActiveDesktop(), "首选项Connor_AVIC_Apply_Create配置不正确", "ERROR", MessageBox.ERROR);
// return null;
// }
// String options[] = new String[] { "名称", "状态" };
new GXDivisionDialog(session, target, options);
}catch(Exception e) {
e.printStackTrace();
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
return null;
}
return null;
}
}

@ -0,0 +1,583 @@
package cn.net.connor.std.processedit.ldy;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import java.util.Map.Entry;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.ListOfValuesInfo;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOPWindow;
import com.teamcenter.rac.kernel.TCComponentBOPWindowType;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
import com.teamcenter.rac.kernel.TCComponentMEOP;
import com.teamcenter.rac.kernel.TCComponentMEProcess;
import com.teamcenter.rac.kernel.TCComponentMEProcessRevision;
import com.teamcenter.rac.kernel.TCComponentPseudoFolder;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.stylesheet.PropertyDateComponent;
import com.teamcenter.rac.util.MessageBox;
public class ProcessBorrowDialog extends AbstractAIFDialog {
private static final long serialVersionUID = 1L;
private TCSession session;
private TCComponentBOMLine targetLine;
private JButton searchBtn;
private JButton exportBtn;
private JTable impTable;
private DefaultTableModel impModel;
private JTable processTable;
private DefaultTableModel processModel;
private Map<String, JComponent> compMap;
private String queryName;
private Vector<String[]> showOptions;
private Vector<String[]> procedureOptions;
private Vector<TCComponentItemRevision> processVec;
// private Vector<Map<String, String>> proceduresVec;
private Vector<String[]> options;
private Map<String, Map<String, String>> lovMap;
private Map<Integer, Vector<Vector<Object>>> tableMap;
private Map<Vector<Object>, TCComponentBOMLine> proceduresMap;
private Vector<String[]> updateProps;
private Vector<String[]> clearProps;
public ProcessBorrowDialog(TCSession session, TCComponentBOMLine targetLine, Vector<String[]> options) throws Exception {
super(AIFUtility.getActiveDesktop());
this.session = session;
this.targetLine = targetLine;
this.options = options;
compMap = new HashMap<>();
lovMap = new HashMap<>();
tableMap = new HashMap<>();
proceduresMap = new HashMap<>();
this.showOptions = new Vector<>();
this.procedureOptions = new Vector<>();
this.processVec = new Vector<>();
this.updateProps = new Vector<>();
this.clearProps = new Vector<>();
// tableMap = new HashMap<>();
setTitle("零组件工艺借用");
String[] propOptions = options.get(3);
for(String s : propOptions) {
updateProps.add(s.split("\\."));
}
propOptions = options.get(4);
for(String s : propOptions) {
clearProps.add(s.split("\\."));
}
// JPanel msgPanel = new JPanel(new GridLayout(0,5,2,5));
JPanel msgPanel = new JPanel(new FlowLayout());
// String[] searchOptions = options.get(0);
String[] searchOptions = new String[] { "零组件号ID=2", "名称=2" };
queryName = options.get(0)[0];
final AbstractAIFDialog dialog = this;
TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues");
for(String s : searchOptions) {
if(!s.contains("="))
continue;
String[] split = s.split("=");
JLabel label = new JLabel(split[0], SwingConstants.RIGHT);
label.setPreferredSize(new Dimension(80, 23));
// label.setHorizontalTextPosition(JLabel.RIGHT);
// JPanel propPanel = new JPanel(new BorderLayout());
JPanel propPanel = new JPanel(new BorderLayout());
propPanel.add(BorderLayout.WEST, label);
if(split.length==3) {
JComboBox<String> combo = new JComboBox<>();
combo.setPreferredSize(new Dimension(118, 23));
if(split[2].indexOf(";")>0) {
String[] value = split[2].split(";");
combo.addItem("");
for(String v : value)
combo.addItem(v);
}else {
TCComponentListOfValues[] lovs = lovType.find(split[2]);
if (lovs != null && lovs.length > 0) {
ListOfValuesInfo lovInfo = lovs[0].getListOfValues();
String[] code = lovInfo.getStringListOfValues();
String[] name = lovInfo.getLOVDisplayValues();
Map<String, String> lovVal = new HashMap<>();
if (code != null && name != null) {
for (int i = 0; i < code.length; i++) {
lovVal.put(name[i], code[i]);
combo.addItem(name[i]);
}
}
lovMap.put(split[0], lovVal);
// bean.lovList = TCUtil.setAutoComplete(bean, name);
}else
throw new Exception("未找到"+split[2]+",请检查首选项配置");
}
propPanel.add(BorderLayout.CENTER, combo);
msgPanel.add(propPanel);
compMap.put(split[0], combo);
}else if(split[1].equals("2")) {
JTextField field = new JTextField();
field.setPreferredSize(new Dimension(118, 23));
propPanel.add(BorderLayout.CENTER, field);
msgPanel.add(propPanel);
compMap.put(split[0], field);
}else if(split[1].equals("3")) {
PropertyDateComponent dateBtn = new PropertyDateComponent();
dateBtn.setPreferredSize(new Dimension(118, 23));
propPanel.add(BorderLayout.CENTER, dateBtn);
msgPanel.add(propPanel);
compMap.put(split[0], dateBtn);
}else if(split[1].equals("4")) {
final JTextField field = new JTextField();
field.setEditable(false);
field.setPreferredSize(new Dimension(60, 23));
JButton userBtn = new JButton("选人");
userBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
new SelectUserDialog(field, true).showDialog();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(dialog, "错误::"+e.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
userBtn.setPreferredSize(new Dimension(56, 23));
propPanel.add(BorderLayout.CENTER, field);
propPanel.add(BorderLayout.EAST, userBtn);
msgPanel.add(propPanel);
compMap.put(split[0], field);
}
}
searchBtn = new JButton("查询");
exportBtn = new JButton("导入");
JPanel btnPanel = new JPanel(new FlowLayout());
btnPanel.add(searchBtn);
btnPanel.add(exportBtn);
JPanel topPanel = new JPanel(new BorderLayout());
topPanel.add(BorderLayout.WEST, msgPanel);
topPanel.add(BorderLayout.EAST, btnPanel);
String[] itemOptions = options.get(0);
String[] tableHeader = new String[itemOptions.length];
tableHeader[0] = "序号";
for(int i=1; i<itemOptions.length; i++) {
String[] split = itemOptions[i].split("=");
tableHeader[i] = split[0];
this.showOptions.add(split[1].split("\\."));
}
impModel = new DefaultTableModel(tableHeader, 0);
impTable = new JTable() {
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int col) {
return false;
}
};
impTable.getTableHeader().setReorderingAllowed(false);
impTable.setFillsViewportHeight(true);
// impTable.setEnabled(false);
impTable.setEnabled(true);
// impTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
impTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
impTable.setModel(impModel);
for(int i=1; i<impModel.getColumnCount(); i++)
impTable.getColumnModel().getColumn(i).setPreferredWidth(150);
JScrollPane itemPanel = new JScrollPane(impTable);
itemPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "零件信息:"));
//TODO processTable
String[] processOption = options.get(1);
tableHeader = new String[processOption.length+1];
tableHeader[0] = "选择";
for(int i=0; i<processOption.length; i++) {
String[] split = processOption[i].split("=");
tableHeader[i+1] = split[0];
this.procedureOptions.add(split[1].split("\\."));
}
processModel = new DefaultTableModel(tableHeader, 0);
processTable = new JTable() {
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int col) {
if (col==0) {
return true;
}
return false;
}
public Class<?> getColumnClass(int column) {
if (column==0) {
return Boolean.class;
}
return super.getColumnClass(column);
}
};
// processTable.getTableHeader().setReorderingAllowed(false);
processTable.setFillsViewportHeight(true);
// processTable.setEnabled(false);
processTable.setEnabled(true);
// processTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
processTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
processTable.setModel(processModel);
processTable.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(processTable, true));
processTable.getTableHeader().setReorderingAllowed(false);
TableColumnModel pColModel = processTable.getColumnModel();
for(int i=1; i<processModel.getColumnCount(); i++)
pColModel.getColumn(i).setPreferredWidth(150);
pColModel.getColumn(0).setCellEditor(new DefaultCellEditor(new JCheckBox()));
JScrollPane processPanel = new JScrollPane(processTable);
processPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "工艺信息:"));
JPanel tablePanel = new JPanel(new GridLayout(0,1,2,5));
tablePanel.add(itemPanel);
tablePanel.add(processPanel);
// processModel.addRow(new Object[] { true, "", "", ""});
addActionListener();
setLayout(new BorderLayout());
add(BorderLayout.NORTH, topPanel);
add(BorderLayout.CENTER, tablePanel);
pack();
setSize(new Dimension(850, 600));
setDefaultLookAndFeelDecorated(true);
Dimension screen = getToolkit().getScreenSize();
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
// setAlwaysOnTop(true);
setVisible(true);
}
private void addActionListener() {
final AbstractAIFDialog dialog = this;
impTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(processModel.getRowCount()>0) {
for(int i=processModel.getRowCount(); i>0; i--)
processModel.removeRow(i-1);
}
if(tableMap.size()==0)
return;
int i = impTable.getSelectedRow();
for(Vector<Object> vo : tableMap.get(i)) {
processModel.addRow(vo);
}
}
});
searchBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
if(impModel.getRowCount()>0) {
for(int i=impModel.getRowCount(); i>0; i--)
impModel.removeRow(i-1);
}
if(processModel.getRowCount()>0) {
for(int i=processModel.getRowCount(); i>0; i--)
processModel.removeRow(i-1);
}
Vector<String> keyV = new Vector<>();
Vector<String> valueV = new Vector<>();
for(Entry<String, JComponent> e : compMap.entrySet()) {
JComponent c = e.getValue();
String text = "";
if(c instanceof JTextField)
text = ((JTextField)c).getText();
else if(c instanceof PropertyDateComponent)
text = ((PropertyDateComponent)c).getDateViewModel().getDateString();
else {
text = ((JComboBox<?>)c).getSelectedItem().toString();
if(lovMap.containsKey(e.getKey())) {
text = lovMap.get(e.getKey()).get(text);
}
}
if(text!=null && !text.isEmpty()) {
if(e.getKey().equals("零组件号ID"))
text += "GY";
keyV.add(e.getKey());
valueV.add(text);
}
}
TCComponent[] result = TCUtil.query(session, queryName, keyV, valueV);
System.out.println("result:"+result.length);
if(result.length==0) {
MessageBox.post(dialog, "没有符合条件的工艺,请检查查询条件", "ERROR", MessageBox.ERROR);
return;
}
result = TCUtil.TCsort(result, new int[] { 1, -1 }, "item_id", "item_revision_id");
TCComponentBOPWindowType bomWinType = (TCComponentBOPWindowType) session.getTypeComponent("BOPWindow");
TCComponentBOPWindow window = (TCComponentBOPWindow) bomWinType.createBOPWindow(null);
for(int i=0; i<result.length; i++) {
Vector<String> v = new Vector<>();
int num = impModel.getRowCount();
v.add(num+1+"");
TCComponentMEProcessRevision meprocess = (TCComponentMEProcessRevision) result[i];
TCComponentItem pitem = meprocess.getItem();
TCComponentForm form = TCUtil.getItemRevisionMasterForm(meprocess);
for(String[] prop : showOptions) {
if(prop[0].equals("item"))
v.add(pitem.getProperty(prop[1]));
else if(prop[0].equals("rev"))
v.add(meprocess.getProperty(prop[1]));
else
v.add(form.getProperty(prop[1]));
}
processVec.add(meprocess);
impModel.addRow(v);
TCComponentBOMLine ebom = window.setWindowTopLine(pitem, meprocess, null, null);
AIFComponentContext[] p = ebom.getChildren();
Vector<Vector<Object>> vvo = new Vector<>();
for(AIFComponentContext c : p) {
Vector<Object> vo = new Vector<>();
vo.add(true);
TCComponentBOMLine procedure = (TCComponentBOMLine) c.getComponent();
TCComponentItem pritem = procedure.getItem();
if(!(pritem instanceof TCComponentMEProcess) && !(pritem instanceof TCComponentMEOP))
continue;
TCComponentItemRevision prrev = procedure.getItemRevision();
if(pritem instanceof TCComponentMEOP)
System.out.println(prrev+">>"+prrev.getReferenceProperty("root_activity").getReferenceListProperty("contents").length);
TCComponentForm prform = TCUtil.getItemRevisionMasterForm(prrev);
for(String[] prop : procedureOptions) {
if(prop[0].equals("item"))
vo.add(pritem.getProperty(prop[1]));
else if(prop[0].equals("rev"))
vo.add(prrev.getProperty(prop[1]));
else if(prop[0].equals("bom"))
vo.add(procedure.getProperty(prop[1]));
else
vo.add(prform.getProperty(prop[1]));
}
vvo.add(vo);
proceduresMap.put(vo, procedure);
}
tableMap.put(num, vvo);
}
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(dialog, "错误::"+e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
exportBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
Map<String, String> borrowMap = new HashMap<>();
for(String s : options.get(2)) {
// String[] split = s.split("=");
borrowMap.put(s, "true");
}
if(processTable.getRowCount()==0)
throw new Exception("工序表格内容为空,无法导入");
TCComponentItemRevision targetRev = targetLine.getItemRevision();
TCComponentItemRevision proRev = processVec.get(impTable.getSelectedRow());
if(!targetRev.getType().equals(proRev.getType()))
throw new Exception("所选工艺类型不同,无法借用");
TCComponentItemType itemType;
TCComponentForm targetForm = TCUtil.getItemRevisionMasterForm(targetRev);
// String revId = targetRev.getProperty("item_revision_id");
// System.out.println("time1 " + (System.nanoTime() - time0) / 1000000);
int n = 0;
for(AIFComponentContext cs : targetLine.getChildren()) {
int no = Integer.parseInt(((TCComponentBOMLine)cs.getComponent()).getProperty("bl_sequence_no"));
if(no > n)
n = no;
}
if(n%10 != 0)
n = n/10*10 + 10;
else
n = n + 10;
for(int i=0; i<processModel.getRowCount(); i++) {
if(!(boolean)processModel.getValueAt(i, 0))
continue;
// System.out.println("for " + (System.nanoTime() - time0) / 1000000);
Vector<Object> v = tableMap.get(impTable.getSelectedRow()).get(i);
TCComponentBOMLine p = proceduresMap.get(v);
TCComponentItemRevision procedure = p.getItemRevision();
TCComponentItem pitem = procedure.getItem();
String type = pitem.getType();
itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(type);
// TCComponentItem newItem = itemType.create(itemType.getNewID(), revId, type, pitem.getProperty("object_name"), "", null);
// procedure.saveAsItem(arg0, arg1);
TCComponentItem newItem = procedure.saveAsItem(itemType.getNewID(), "A");
TCComponentBOMLine newLine = targetLine.add(newItem, null);
TCComponentItemRevision newRev = newItem.getLatestItemRevision();
newLine.setProperty("bl_sequence_no", n+"");
n += 10;
// copyProperty(p, newLine, num);
//TODO
TCComponentForm proForm = TCUtil.getItemRevisionMasterForm(proRev);
for(String[] ss : updateProps) {
if(ss[0].equals("rev")) {
copyProperty(proRev, targetRev, ss[1]);
}else if(ss[0].equals("master")) {
copyProperty(proForm, targetForm, ss[1]);
}
}
TCComponentForm newForm = TCUtil.getItemRevisionMasterForm(newRev);
for(String[] ss : clearProps) {
if(ss[0].equals("rev")) {
newRev.setProperty(ss[1], "");
}else if(ss[0].equals("master")) {
newForm.setProperty(ss[1], "");
}else if(ss[0].equals("item")) {
newItem.setProperty(ss[1], "");
}
}
// num++;
AIFComponentContext[] children = newLine.getChildren();
for(AIFComponentContext c : children) {
// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000);
// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000);
TCComponentBOMLine child = (TCComponentBOMLine) c.getComponent();
TCComponentItem subitem = child.getItem();
String subtype = subitem.getType();
// System.out.println("child" + child +" "+ (subitem instanceof TCComponentMEOP));
if(subitem instanceof TCComponentMEOP) {
// TCComponentItem newOpitem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null);
// TCComponentBOMLine newOpline = newLine.add(newSubItem, null);
// copyProperty(child, child, 0);
itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(subtype);
TCComponentItem newSubItem = child.getItemRevision().saveAsItem(itemType.getNewID(), "");
TCComponentItemRevision newSubRev = newSubItem.getLatestItemRevision();
child.replace(newSubItem, newSubRev, null);
}else if(borrowMap.containsKey(subtype)) {
if(borrowMap.get(subtype).toLowerCase().equals("false")){
TCComponentItem newsubItem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null);
// newLine.add(newsubItem, null);
child.replace(newsubItem, newsubItem.getLatestItemRevision(), null);
}
}else {
child.cut();
}
// else
// newLine.add(subitem, null);
}
}
/*List<Object> viewParts = PlatformHelper.getAllViewParts();
for(Object view : viewParts) {
if(view==null || !(view instanceof CompatibilityView))
continue;
IViewPart v = ((CompatibilityView)view).getView();
// System.out.println("ProcessPropertyView "+((CompatibilityPart)view).ENABLE_DEPENDENCY_INJECTION_FOR_E3_PARTS);
if(!(v instanceof ProcessPropertyView))
continue;
ProcessPropertyView pv = (ProcessPropertyView)v;
Field field = pv.getClass().getDeclaredField("panel");
field.setAccessible(true);
Object editor = field.get(pv);
// if(editor instanceof ProcessPropertyEditor)
// ((ProcessPropertyEditor) editor).updateSelection(targetLine);
Field pfield = ((ProcessPropertyEditor) editor).getClass().getDeclaredField("propPanel");
pfield.setAccessible(true);
Object panel = pfield.get(((ProcessPropertyEditor) editor));
((PropertyPanel)panel).loadData();
}*/
MessageBox.post(dialog, "工序导入成功", "提示", MessageBox.INFORMATION);
dispose();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(dialog, "错误:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
}
private void copyProperty(TCComponent a, TCComponent b, String prop) throws Exception {
TCProperty property = a.getTCProperty(prop);
if(property==null) {
System.out.println(a+"未找到属性:" + prop);
return;
}
if(b.getTCProperty(prop)==null) {
System.out.println(b+"未找到属性:" + prop);
return;
}
int type = property.getPropertyType();
// System.out.println(prop+">>" + type);
if(type==TCProperty.PROP_untyped_relation || type==TCProperty.PROP_untyped_reference){
TCComponentPseudoFolder folder = TCUtil.getPseudoFolder(a, prop);
// System.out.println("folder:" + folder);
TCComponent[] cps;
if(folder == null) {
cps = property.getReferenceValueArray();
}else {
AIFComponentContext[] cxs = folder.getChildren();
cps = new TCComponent[cxs.length];
for(int i=0; i<cxs.length; i++)
cps[i] = (TCComponent) cxs[i].getComponent();
}
b.getTCProperty(prop).setReferenceValueArray(cps);
}else {
b.setProperty(prop, a.getProperty(prop));
}
// System.out.println(a +"=="+ property+">>" + b+"==" + b.getTCProperty(prop));
}
/*private void copyProperty(TCComponentBOMLine p, TCComponentBOMLine toLine, int num) throws Exception {
System.out.println("copyProperty:"+p+" copyProperty " + (System.nanoTime() - time0) / 1000000);
if(p.parent()!=null) {
for(String s : propVecs.get(0)) {
toLine.setProperty(s, "");
}
}
TCComponentItemRevision rev = toLine.getItemRevision();
for(String s : propVecs.get(1)) {
rev.setProperty(s, "");
}
TCComponentItem item = rev.getItem();
for(String s : propVecs.get(2)) {
item.setProperty(s, "");
}
TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev);
for(String s : propVecs.get(3)) {
form.setProperty(s, "");
}
if(num>0)
form.setProperty("ac5_OperationNumber", num*5+"");
System.out.println("copyProperty " + (System.nanoTime() - time0) / 1000000);
}
private String getProperty(String comp, String prop, TCComponent... comps) throws Exception {
if(comp.equals("rev"))
return comps[0].getProperty(prop);
else if(comp.equals("master"))
return comps[1].getProperty(prop);
else if(comp.equals("item"))
return comps[2].getProperty(prop);
else
return "";
}*/
}

@ -0,0 +1,48 @@
package cn.net.connor.std.processedit.ldy;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
//创建常规文件夹结构
public class ProcessBorrowHandler extends AbstractHandler implements IHandler{
public Object execute(ExecutionEvent arg0) throws ExecutionException {
System.out.println("ProcessBorrowHandler");
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
AIFDesktop desktop = AIFUtility.getActiveDesktop();
try {
TCComponent target = (TCComponent)app.getTargetComponent();
if(!(target instanceof TCComponentBOMLine)) {
MessageBox.post(desktop, "请选择工艺BOM进行创建", "ERROR", MessageBox.ERROR);
return null;
}
// if(((TCComponentBOMLine)target).parent() != null) {
// MessageBox.post(desktop, "请选择工艺BOM进行创建", "ERROR", MessageBox.ERROR);
// return null;
// }
TCComponentItem item = ((TCComponentBOMLine)target).getItem();
if(!item.isTypeOf("LD6_MEProcessCr")) {
MessageBox.post(desktop, "请选择工艺BOM进行创建", "ERROR", MessageBox.ERROR);
return null;
}
new ProcessBorrowOperation(session, (TCComponentBOMLine)target).executeOperation();
}catch(Exception e) {
e.printStackTrace();
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
return null;
}
return null;
}
}

@ -0,0 +1,72 @@
package cn.net.connor.std.processedit.ldy;
import java.util.HashMap;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class ProcessBorrowOperation extends AbstractAIFOperation {
private TCSession session;
private TCComponentBOMLine target;
private HashMap<TCComponentItem, TCComponentItemRevision> revMap;
public ProcessBorrowOperation(TCSession session, TCComponentBOMLine target) {
this.session = session;
this.target = target;
}
@Override
public void executeOperation() throws Exception {
AIFDesktop desktop = AIFUtility.getActiveDesktop();
try {
revMap = new HashMap<>();
TCComponentItemType itemType = (TCComponentItemType) session.getTypeService().getTypeComponent("LD6_MEProcessCr");
TCComponentItem item = target.getItemRevision().saveAsItem(itemType.getNewID(), null);
TCComponentBOMWindow window = TCUtil.getWindow(session);
TCComponentBOMLine bom = TCUtil.getBOMLine(session, window, item.getLatestItemRevision());
recycle(bom);
window.save();
window.close();
TCComponentFolder home = session.getUser().getHomeFolder();
home.add("contents", item);
MessageBox.post(desktop, "工艺路线【"+item+"】已存至Home文件夹下", "INFO", MessageBox.INFORMATION);
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
}
}
private void recycle(TCComponentBOMLine parent) throws Exception {
for(AIFComponentContext c : parent.getChildren()) {
TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent();
TCComponentItem item = bom.getItem();
if(revMap.containsKey(item)) {
TCComponentItemRevision rev = revMap.get(item);
bom.replace(rev.getItem(), rev, null);
continue;
}
if(!item.isTypeOf(new String[] { "LD6_MEProcess", "LD6_OMEOP", "LD6_MEOP" }))
continue;
TCComponentItemType itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(item.getType());
TCComponentItem newItem = bom.getItemRevision().saveAsItem(itemType.getNewID(), null);
TCComponentItemRevision newRev = newItem.getLatestItemRevision();
bom.replace(newItem, newRev, null);
revMap.put(item, newRev);
recycle(bom);
}
}
}

@ -0,0 +1,271 @@
package cn.net.connor.std.processedit.ldy;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCAccessControlService;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentEnvelope;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.services.rac.core.DataManagementService;
import com.teamcenter.services.rac.core.EnvelopeService;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse;
public class ProcessDivisionDialog extends AbstractAIFDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
private TCSession session;
private JTable table;
private DefaultTableModel model;
private String[] tableHeader;
private JButton divisionBtn;
private JButton okBtn;
private JButton cancelBtn;
private int ld6_resperson = -1;
private TCAccessControlService accessControlService;
private ArrayList<String[]> colList;
private ArrayList<TCComponent[]> compList;
private HashMap<String, TCComponentUser> userMap;
public ProcessDivisionDialog(TCSession session, TCComponentBOMLine[] target, String[] options) throws Exception{
super(AIFUtility.getActiveDesktop());
this.session = session;
accessControlService = session.getTCAccessControlService();
userMap = new HashMap<>();
compList = new ArrayList<>();
setTitle("工艺分工");
divisionBtn = new JButton("工艺分工");
okBtn = new JButton("确定");
cancelBtn = new JButton("取消");
addActionListener();
// String[] tableHeader = new String[] { "序号", "名称", "规格" };
int size = options.length;
tableHeader = new String[size+1];
tableHeader[0] = "序号";
colList = new ArrayList<>();
for(int i=0; i<size; i++) {
String[] option = options[i].split("=");
tableHeader[i+1] = option[0];
if(option[1].equals("Rev.j6_resperson")) {//TODO object_desc
ld6_resperson = i+1;
}
String[] prop = option[1].split("\\.");
colList.add(prop);
}
if(ld6_resperson == -1) {
throw new Exception("首选项未配置Rev.j6_resperson无法进行分工");
}
model = new DefaultTableModel(tableHeader, 0);
table = new JTable() {
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int col) {
return false;
}
};
table.setFillsViewportHeight(true);
table.setEnabled(true);
// impTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setModel(model);
table.getColumnModel().getColumn(0).setPreferredWidth(50);
for (int i = 1; i < table.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setPreferredWidth(180);
}
table.getTableHeader().setReorderingAllowed(false);
recycleBom(target);
JScrollPane tablePanel = new JScrollPane();
tablePanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
tablePanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
tablePanel.setViewportView(table);
JPanel btnPanel = new JPanel(new FlowLayout());
btnPanel.add(divisionBtn);
btnPanel.add(okBtn);
btnPanel.add(cancelBtn);
// tablePanel.setBounds(20, 20, 330, 180);
// okBtn.setBounds(70, 220, 100, 25);
// cancelBtn.setBounds(180, 220, 100, 25);
setLayout(new BorderLayout());
add(BorderLayout.CENTER, tablePanel);
add(BorderLayout.SOUTH, btnPanel);
// add(new JLabel(""));
setSize(new Dimension(1000, 600));
Dimension screen = getToolkit().getScreenSize();
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
this.setAlwaysOnTop(true);
setVisible(true);
}
private void addActionListener() {
final AbstractAIFDialog dialog = this;
divisionBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
int[] rows = table.getSelectedRows();
if(rows==null || rows.length==0) {
MessageBox.post(ProcessDivisionDialog.this, "请选择要分工的行", "ERROR", MessageBox.ERROR);
return;
}
new SelectUserDialog(table, rows, ld6_resperson, userMap).showDialog();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(dialog, "错误:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
return;
}
// dialog.dispose();
}
});
okBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
for(int i=0; i<table.getRowCount(); i++) {
String user = table.getValueAt(i, ld6_resperson).toString();
if(user.isEmpty() || !userMap.containsKey(user))
continue;
for(TCComponent comp : compList.get(i)) {
// if(!accessControlService.checkAccessorsPrivilege(atccomponent, topFolder, "WRITE"))
accessControlService.grantPrivilege(comp, userMap.get(user), new String[]{ "WRITE" });
}
compList.get(i)[1].setProperty("j6_resperson", user);//TODO object_desc
sendMail("工艺分工", "您好,此任务已经分配给您请及时完成", userMap.get(user), compList.get(i));
}
MessageBox.post(dialog, "分工完成", "INFO", MessageBox.INFORMATION);
dispose();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(dialog, "错误:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
return;
}
// dialog.dispose();
}
});
cancelBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
}
// private void recycleBom(TCComponentBOMLine[] parent) throws Exception {
// for(AIFComponentContext c : parent.getChildren()) {
// TCComponentBOMLine line = (TCComponentBOMLine) c.getComponent();
//// String type = line.getItemRevision().getType();
//// if(!type.equals("LD6_MEOPRevision") && !type.equals("LD6_ProDevMEOPRevision")) {
//// if(!type.equals("LD6_MEProcessRevision") && !type.equals("LD6_OMEOPRevision")) {
// /*
// * if(!type.equals("LD6_MEOPRevision")) { recycleBom(line); continue; }
// */
// TCComponentItem item = line.getItem();
// TCComponentItemRevision rev = line.getItemRevision();
// TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev);
// Vector<String> v = new Vector<>();
// v.add(table.getRowCount()+1+"");
// for(String[] s : colList) {
// if(s[0].equals("Item")) {
// v.add(item.getProperty(s[1]));
// }else if(s[0].equals("Rev")) {
// v.add(rev.getProperty(s[1]));
// }else if(s[0].equals("RevMaster")) {
// v.add(form.getProperty(s[1]));
// }else if(s[0].equals("BOMLine")) {
// v.add(line.getProperty(s[1]));
// }
// }
// model.addRow(v);
// AIFComponentContext[] cs = rev.getChildren("bom_view_tags");
// if(cs.length>0)
// compList.add(new TCComponent[] { item, rev, form, (TCComponent) cs[0].getComponent() });
// else
// compList.add(new TCComponent[] { item, rev, form });
// recycleBom(line);
// }
// }
private void recycleBom(TCComponentBOMLine[] parent) throws Exception {
for (int i = 0; i < parent.length; i++) {
TCComponentBOMLine line = parent[i];
TCComponentItem item = line.getItem();
TCComponentItemRevision rev = line.getItemRevision();
TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev);
Vector<String> v = new Vector<>();
v.add(table.getRowCount()+1+"");
for(String[] s : colList) {
if(s[0].equals("Item")) {
v.add(item.getProperty(s[1]));
}else if(s[0].equals("Rev")) {
v.add(rev.getProperty(s[1]));
}else if(s[0].equals("RevMaster")) {
v.add(form.getProperty(s[1]));
}else if(s[0].equals("BOMLine")) {
v.add(line.getProperty(s[1]));
}
}
model.addRow(v);
AIFComponentContext[] cs = rev.getChildren("bom_view_tags");
if(cs.length>0)
compList.add(new TCComponent[] { item, rev, form, (TCComponent) cs[0].getComponent() });
else
compList.add(new TCComponent[] { item, rev, form });
}
}
private void sendMail(String name, String desc, TCComponentUser user, TCComponent[] comps) throws Exception {
DataManagementService dataManagementService = DataManagementService.getService(session);
CreateIn[] arrayOfCreateIn = new CreateIn[] { new CreateIn() };
CreateInput createInput = new CreateInput();
createInput.stringProps.put("object_name", name);
createInput.stringProps.put("object_desc", desc);
createInput.boName = "Envelope";
createInput.tagArrayProps.put("listOfReceivers", new TCComponent[] { user });
createInput.tagArrayProps.put("contents", comps);
// if (paramArrayOfString1 != null && paramArrayOfString1.length > 0)
// createInput.stringArrayProps.put("fnd0ListOfExtRecipients", paramArrayOfString1);
// if (paramArrayOfString2 != null && paramArrayOfString2.length > 0)
// createInput.stringArrayProps.put("fnd0ListOfCcExtRecipients", paramArrayOfString2);
arrayOfCreateIn[0].data = createInput;
CreateResponse createResponse = dataManagementService.createObjects(arrayOfCreateIn);
// String uid2 = e.getUid();
// System.out.println("uid2===================="+uid2);
TCComponentEnvelope[] arrayOfTCComponentEnvelope = new TCComponentEnvelope[] { (TCComponentEnvelope)createResponse.output[0].objects[0] };
EnvelopeService envelopeService = EnvelopeService.getService(session);
envelopeService.sendAndDeleteEnvelopes(arrayOfTCComponentEnvelope);
}
}

@ -0,0 +1,74 @@
package cn.net.connor.std.processedit.ldy;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
//创建常规文件夹结构
public class ProcessDivisionHandler extends AbstractHandler implements IHandler{
public Object execute(ExecutionEvent arg0) throws ExecutionException {
System.out.println("ProcessDivisionHandler");
AIFDesktop desktop = AIFUtility.getActiveDesktop();
try {
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
InterfaceAIFComponent[] targetComponents = app.getTargetComponents();
List<TCComponentBOMLine> tcList = new ArrayList<>();
for (InterfaceAIFComponent comp : targetComponents) {
if (comp instanceof TCComponentBOMLine) {
tcList.add((TCComponentBOMLine) comp);
}
// 可选:记录非 TCComponent 对象用于调试
// else { System.out.println("跳过非TCComponent对象: " + comp); }
}
// 3. 转换为数组
TCComponentBOMLine[] target = tcList.toArray(new TCComponentBOMLine[0]);
if(target.length <= 0) {
MessageBox.post(desktop, "请选择工艺路线对象进行工艺分工", "ERROR", MessageBox.ERROR);
return null;
}
/*
* String type = ((TCComponentBOMLine)target).getItemRevision().getType();
* if(!type.equals("LD6_MEProcessCrRevision")) { MessageBox.post(desktop,
* "请选择工艺路线BOM进行工艺分工", "ERROR", MessageBox.ERROR); return null; }
*/
String[] options = session.getPreferenceService().getStringValues("Connor_GYFG");
if(options==null || options.length==0) {
MessageBox.post(desktop, "首选项Connor_GYFG配置不正确", "ERROR", MessageBox.ERROR);
return null;
}
// String optionC[] = session.getPreferenceService().getStringValues("Connor_AVIC_Apply_Create");
// if(optionC==null || optionC.length==0) {
// MessageBox.post(AIFUtility.getActiveDesktop(), "首选项Connor_AVIC_Apply_Create配置不正确", "ERROR", MessageBox.ERROR);
// return null;
// }
// String options[] = new String[] { "名称", "状态" };
new ProcessDivisionDialog(session, target, options);
}catch(Exception e) {
e.printStackTrace();
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
return null;
}
return null;
}
}

@ -0,0 +1,597 @@
package cn.net.connor.std.processedit.ldy;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.Map.Entry;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import org.eclipse.ui.internal.e4.compatibility.CompatibilityView;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.ListOfValuesInfo;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOPWindow;
import com.teamcenter.rac.kernel.TCComponentBOPWindowType;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
import com.teamcenter.rac.kernel.TCComponentMEOP;
import com.teamcenter.rac.kernel.TCComponentMEProcess;
import com.teamcenter.rac.kernel.TCComponentMEProcessRevision;
import com.teamcenter.rac.kernel.TCComponentPseudoFolder;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.stylesheet.PropertyDateComponent;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PlatformHelper;
//import cn.net.connor.std.processedit.processview.ProcessPropertyEditor;
//import cn.net.connor.std.processedit.processview.ProcessPropertyView;
//import cn.net.connor.std.processedit.processview.PropertyPanel;
@SuppressWarnings("restriction")
public class ProcessMultiplexDialog extends AbstractAIFDialog {
private static final long serialVersionUID = 1L;
private TCSession session;
private TCComponentBOMLine targetLine;
private JButton searchBtn;
private JButton exportBtn;
private JTable impTable;
private DefaultTableModel impModel;
private JTable processTable;
private DefaultTableModel processModel;
private Map<String, JComponent> compMap;
private String queryName;
private Vector<String[]> showOptions;
private Vector<String[]> procedureOptions;
private Vector<TCComponentItemRevision> processVec;
// private Vector<Map<String, String>> proceduresVec;
private Vector<String[]> options;
private Map<String, Map<String, String>> lovMap;
private Map<Integer, Vector<Vector<Object>>> tableMap;
private Map<Vector<Object>, TCComponentBOMLine> proceduresMap;
private Vector<String[]> updateProps;
private Vector<String[]> clearProps;
public ProcessMultiplexDialog(TCSession session, TCComponentBOMLine targetLine, Vector<String[]> options) throws Exception {
super(AIFUtility.getActiveDesktop());
this.session = session;
this.targetLine = targetLine;
this.options = options;
compMap = new HashMap<>();
lovMap = new HashMap<>();
tableMap = new HashMap<>();
proceduresMap = new HashMap<>();
this.showOptions = new Vector<>();
this.procedureOptions = new Vector<>();
this.processVec = new Vector<>();
this.updateProps = new Vector<>();
this.clearProps = new Vector<>();
// tableMap = new HashMap<>();
setTitle("零组件工艺借用");
String[] propOptions = options.get(3);
for(String s : propOptions) {
updateProps.add(s.split("\\."));
}
propOptions = options.get(4);
for(String s : propOptions) {
clearProps.add(s.split("\\."));
}
// JPanel msgPanel = new JPanel(new GridLayout(0,5,2,5));
JPanel msgPanel = new JPanel(new FlowLayout());
// String[] searchOptions = options.get(0);
String[] searchOptions = new String[] { "零组件号ID=2", "名称=2" };
queryName = options.get(0)[0];
final AbstractAIFDialog dialog = this;
TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues");
for(String s : searchOptions) {
if(!s.contains("="))
continue;
String[] split = s.split("=");
JLabel label = new JLabel(split[0], SwingConstants.RIGHT);
label.setPreferredSize(new Dimension(80, 23));
// label.setHorizontalTextPosition(JLabel.RIGHT);
// JPanel propPanel = new JPanel(new BorderLayout());
JPanel propPanel = new JPanel(new BorderLayout());
propPanel.add(BorderLayout.WEST, label);
if(split.length==3) {
JComboBox<String> combo = new JComboBox<>();
combo.setPreferredSize(new Dimension(118, 23));
if(split[2].indexOf(";")>0) {
String[] value = split[2].split(";");
combo.addItem("");
for(String v : value)
combo.addItem(v);
}else {
TCComponentListOfValues[] lovs = lovType.find(split[2]);
if (lovs != null && lovs.length > 0) {
ListOfValuesInfo lovInfo = lovs[0].getListOfValues();
String[] code = lovInfo.getStringListOfValues();
String[] name = lovInfo.getLOVDisplayValues();
Map<String, String> lovVal = new HashMap<>();
if (code != null && name != null) {
for (int i = 0; i < code.length; i++) {
lovVal.put(name[i], code[i]);
combo.addItem(name[i]);
}
}
lovMap.put(split[0], lovVal);
// bean.lovList = TCUtil.setAutoComplete(bean, name);
}else
throw new Exception("未找到"+split[2]+",请检查首选项配置");
}
propPanel.add(BorderLayout.CENTER, combo);
msgPanel.add(propPanel);
compMap.put(split[0], combo);
}else if(split[1].equals("2")) {
JTextField field = new JTextField();
field.setPreferredSize(new Dimension(118, 23));
propPanel.add(BorderLayout.CENTER, field);
msgPanel.add(propPanel);
compMap.put(split[0], field);
}else if(split[1].equals("3")) {
PropertyDateComponent dateBtn = new PropertyDateComponent();
dateBtn.setPreferredSize(new Dimension(118, 23));
propPanel.add(BorderLayout.CENTER, dateBtn);
msgPanel.add(propPanel);
compMap.put(split[0], dateBtn);
}else if(split[1].equals("4")) {
final JTextField field = new JTextField();
field.setEditable(false);
field.setPreferredSize(new Dimension(60, 23));
JButton userBtn = new JButton("选人");
userBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
new SelectUserDialog(field, true).showDialog();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(dialog, "错误::"+e.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
userBtn.setPreferredSize(new Dimension(56, 23));
propPanel.add(BorderLayout.CENTER, field);
propPanel.add(BorderLayout.EAST, userBtn);
msgPanel.add(propPanel);
compMap.put(split[0], field);
}
}
searchBtn = new JButton("查询");
exportBtn = new JButton("导入");
JPanel btnPanel = new JPanel(new FlowLayout());
btnPanel.add(searchBtn);
btnPanel.add(exportBtn);
JPanel topPanel = new JPanel(new BorderLayout());
topPanel.add(BorderLayout.WEST, msgPanel);
topPanel.add(BorderLayout.EAST, btnPanel);
String[] itemOptions = options.get(0);
String[] tableHeader = new String[itemOptions.length];
tableHeader[0] = "序号";
for(int i=1; i<itemOptions.length; i++) {
String[] split = itemOptions[i].split("=");
tableHeader[i] = split[0];
this.showOptions.add(split[1].split("\\."));
}
impModel = new DefaultTableModel(tableHeader, 0);
impTable = new JTable() {
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int col) {
return false;
}
};
impTable.getTableHeader().setReorderingAllowed(false);
impTable.setFillsViewportHeight(true);
// impTable.setEnabled(false);
impTable.setEnabled(true);
// impTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
impTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
impTable.setModel(impModel);
for(int i=1; i<impModel.getColumnCount(); i++)
impTable.getColumnModel().getColumn(i).setPreferredWidth(150);
JScrollPane itemPanel = new JScrollPane(impTable);
itemPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "零件信息:"));
//TODO processTable
String[] processOption = options.get(1);
tableHeader = new String[processOption.length+1];
tableHeader[0] = "选择";
for(int i=0; i<processOption.length; i++) {
String[] split = processOption[i].split("=");
tableHeader[i+1] = split[0];
this.procedureOptions.add(split[1].split("\\."));
}
processModel = new DefaultTableModel(tableHeader, 0);
processTable = new JTable() {
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int col) {
if (col==0) {
return true;
}
return false;
}
public Class<?> getColumnClass(int column) {
if (column==0) {
return Boolean.class;
}
return super.getColumnClass(column);
}
};
// processTable.getTableHeader().setReorderingAllowed(false);
processTable.setFillsViewportHeight(true);
// processTable.setEnabled(false);
processTable.setEnabled(true);
// processTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
processTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
processTable.setModel(processModel);
processTable.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(processTable, true));
processTable.getTableHeader().setReorderingAllowed(false);
TableColumnModel pColModel = processTable.getColumnModel();
for(int i=1; i<processModel.getColumnCount(); i++)
pColModel.getColumn(i).setPreferredWidth(150);
pColModel.getColumn(0).setCellEditor(new DefaultCellEditor(new JCheckBox()));
JScrollPane processPanel = new JScrollPane(processTable);
processPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "工艺信息:"));
JPanel tablePanel = new JPanel(new GridLayout(0,1,2,5));
tablePanel.add(itemPanel);
tablePanel.add(processPanel);
// processModel.addRow(new Object[] { true, "", "", ""});
addActionListener();
setLayout(new BorderLayout());
add(BorderLayout.NORTH, topPanel);
add(BorderLayout.CENTER, tablePanel);
pack();
setSize(new Dimension(850, 600));
setDefaultLookAndFeelDecorated(true);
Dimension screen = getToolkit().getScreenSize();
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
// setAlwaysOnTop(true);
setVisible(true);
}
private void addActionListener() {
final AbstractAIFDialog dialog = this;
impTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(processModel.getRowCount()>0) {
for(int i=processModel.getRowCount(); i>0; i--)
processModel.removeRow(i-1);
}
if(tableMap.size()==0)
return;
int i = impTable.getSelectedRow();
for(Vector<Object> vo : tableMap.get(i)) {
processModel.addRow(vo);
}
}
});
searchBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
if(impModel.getRowCount()>0) {
for(int i=impModel.getRowCount(); i>0; i--)
impModel.removeRow(i-1);
}
if(processModel.getRowCount()>0) {
for(int i=processModel.getRowCount(); i>0; i--)
processModel.removeRow(i-1);
}
Vector<String> keyV = new Vector<>();
Vector<String> valueV = new Vector<>();
for(Entry<String, JComponent> e : compMap.entrySet()) {
JComponent c = e.getValue();
String text = "";
if(c instanceof JTextField)
text = ((JTextField)c).getText();
else if(c instanceof PropertyDateComponent)
text = ((PropertyDateComponent)c).getDateViewModel().getDateString();
else {
text = ((JComboBox<?>)c).getSelectedItem().toString();
if(lovMap.containsKey(e.getKey())) {
text = lovMap.get(e.getKey()).get(text);
}
}
if(text!=null && !text.isEmpty()) {
// if(e.getKey().equals("零组件号ID"))
// text += "GY";
keyV.add(e.getKey());
valueV.add(text);
}
}
TCComponent[] result = TCUtil.query(session, queryName, keyV, valueV);
System.out.println("result:"+result.length);
if(result.length==0) {
MessageBox.post(dialog, "没有符合条件的工艺,请检查查询条件", "ERROR", MessageBox.ERROR);
return;
}
result = TCUtil.TCsort(result, new int[] { 1, -1 }, "item_id", "item_revision_id");
TCComponentBOPWindowType bomWinType = (TCComponentBOPWindowType) session.getTypeComponent("BOPWindow");
TCComponentBOPWindow window = (TCComponentBOPWindow) bomWinType.createBOPWindow(null);
for(int i=0; i<result.length; i++) {
Vector<String> v = new Vector<>();
int num = impModel.getRowCount();
v.add(num+1+"");
TCComponentMEProcessRevision meprocess = (TCComponentMEProcessRevision) result[i];
TCComponentItem pitem = meprocess.getItem();
TCComponentForm form = TCUtil.getItemRevisionMasterForm(meprocess);
for(String[] prop : showOptions) {
if(prop[0].equals("item"))
v.add(pitem.getProperty(prop[1]));
else if(prop[0].equals("rev"))
v.add(meprocess.getProperty(prop[1]));
else
v.add(form.getProperty(prop[1]));
}
processVec.add(meprocess);
impModel.addRow(v);
TCComponentBOMLine ebom = window.setWindowTopLine(pitem, meprocess, null, null);
AIFComponentContext[] p = ebom.getChildren();
Vector<Vector<Object>> vvo = new Vector<>();
for(AIFComponentContext c : p) {
Vector<Object> vo = new Vector<>();
vo.add(true);
TCComponentBOMLine procedure = (TCComponentBOMLine) c.getComponent();
TCComponentItem pritem = procedure.getItem();
if(!(pritem instanceof TCComponentMEProcess) && !(pritem instanceof TCComponentMEOP))
continue;
TCComponentItemRevision prrev = procedure.getItemRevision();
if(pritem instanceof TCComponentMEOP)
System.out.println(prrev+">>"+prrev.getReferenceProperty("root_activity").getReferenceListProperty("contents").length);
TCComponentForm prform = TCUtil.getItemRevisionMasterForm(prrev);
for(String[] prop : procedureOptions) {
if(prop[0].equals("item"))
vo.add(pritem.getProperty(prop[1]));
else if(prop[0].equals("rev"))
vo.add(prrev.getProperty(prop[1]));
else if(prop[0].equals("bom"))
vo.add(procedure.getProperty(prop[1]));
else
vo.add(prform.getProperty(prop[1]));
}
vvo.add(vo);
proceduresMap.put(vo, procedure);
}
tableMap.put(num, vvo);
}
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(dialog, "错误::"+e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
exportBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
Map<String, String> borrowMap = new HashMap<>();
for(String s : options.get(2)) {
// String[] split = s.split("=");
borrowMap.put(s, "true");
}
if(processTable.getRowCount()==0)
throw new Exception("工序表格内容为空,无法导入");
TCComponentItemRevision targetRev = targetLine.getItemRevision();
TCComponentItemRevision proRev = processVec.get(impTable.getSelectedRow());
if(!targetRev.getType().equals(proRev.getType()))
throw new Exception("所选工艺类型不同,无法借用");
TCComponentItemType itemType;
TCComponentForm targetForm = TCUtil.getItemRevisionMasterForm(targetRev);
// String revId = targetRev.getProperty("item_revision_id");
// System.out.println("time1 " + (System.nanoTime() - time0) / 1000000);
int n = 0;
for(AIFComponentContext cs : targetLine.getChildren()) {
int no = Integer.parseInt(((TCComponentBOMLine)cs.getComponent()).getProperty("bl_sequence_no"));
if(no > n)
n = no;
}
if(n%10 != 0)
n = n/10*10 + 10;
else
n = n + 10;
for(int i=0; i<processModel.getRowCount(); i++) {
if(!(boolean)processModel.getValueAt(i, 0))
continue;
// System.out.println("for " + (System.nanoTime() - time0) / 1000000);
Vector<Object> v = tableMap.get(impTable.getSelectedRow()).get(i);
TCComponentBOMLine p = proceduresMap.get(v);
TCComponentItemRevision procedure = p.getItemRevision();
TCComponentItem pitem = procedure.getItem();
String type = pitem.getType();
itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(type);
// TCComponentItem newItem = itemType.create(itemType.getNewID(), revId, type, pitem.getProperty("object_name"), "", null);
// procedure.saveAsItem(arg0, arg1);
TCComponentItem newItem = procedure.getItem().getLatestItemRevision().saveAsItem(itemType.getNewID(), "001");
newItem.lock();
TCComponentBOMLine newLine = targetLine.add(newItem, null);
TCComponentItemRevision newRev = newItem.getLatestItemRevision();
newLine.setProperty("bl_sequence_no", n+"");
n += 10;
// copyProperty(p, newLine, num);
//TODO
TCComponentForm proForm = TCUtil.getItemRevisionMasterForm(proRev);
for(String[] ss : updateProps) {
if(ss[0].equals("rev")) {
copyProperty(proRev, targetRev, ss[1]);
}else if(ss[0].equals("master")) {
copyProperty(proForm, targetForm, ss[1]);
}
}
TCComponentForm newForm = TCUtil.getItemRevisionMasterForm(newRev);
for(String[] ss : clearProps) {
if(ss[0].equals("rev")) {
newRev.setProperty(ss[1], "");
}else if(ss[0].equals("master")) {
newForm.setProperty(ss[1], "");
}else if(ss[0].equals("item")) {
newItem.setProperty(ss[1], "");
}
}
// num++;
AIFComponentContext[] children = newLine.getChildren();
for(AIFComponentContext c : children) {
// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000);
// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000);
TCComponentBOMLine child = (TCComponentBOMLine) c.getComponent();
TCComponentItem subitem = child.getItem();
String subtype = subitem.getType();
// System.out.println("child" + child +" "+ (subitem instanceof TCComponentMEOP));
if(subitem instanceof TCComponentMEOP) {
// TCComponentItem newOpitem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null);
// TCComponentBOMLine newOpline = newLine.add(newSubItem, null);
// copyProperty(child, child, 0);
itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(subtype);
TCComponentItem newSubItem = child.getItemRevision().saveAsItem(itemType.getNewID(), "");
TCComponentItemRevision newSubRev = newSubItem.getLatestItemRevision();
child.replace(newSubItem, newSubRev, null);
}else if(borrowMap.containsKey(subtype)) {
if(borrowMap.get(subtype).toLowerCase().equals("false")){
TCComponentItem newsubItem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null);
// newLine.add(newsubItem, null);
child.replace(newsubItem, newsubItem.getLatestItemRevision(), null);
}
}else {
child.cut();
}
// else
// newLine.add(subitem, null);
}
newItem.save();
newItem.unlock();
}
List<Object> viewParts = PlatformHelper.getAllViewParts();
for(Object view : viewParts) {
if(view==null || !(view instanceof CompatibilityView))
continue;
// IViewPart v = ((CompatibilityView)view).getView();
//// System.out.println("ProcessPropertyView "+((CompatibilityPart)view).ENABLE_DEPENDENCY_INJECTION_FOR_E3_PARTS);
// if(!(v instanceof ProcessPropertyView))
// continue;
// ProcessPropertyView pv = (ProcessPropertyView)v;
// Field field = pv.getClass().getDeclaredField("panel");
// field.setAccessible(true);
// Object editor = field.get(pv);
//// if(editor instanceof ProcessPropertyEditor)
//// ((ProcessPropertyEditor) editor).updateSelection(targetLine);
// Field pfield = ((ProcessPropertyEditor) editor).getClass().getDeclaredField("propPanel");
// pfield.setAccessible(true);
// Object panel = pfield.get(((ProcessPropertyEditor) editor));
// ((PropertyPanel)panel).loadData();
}
MessageBox.post(dialog, "工序导入成功", "提示", MessageBox.INFORMATION);
dispose();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(dialog, "错误:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
}
private void copyProperty(TCComponent a, TCComponent b, String prop) throws Exception {
TCProperty property = a.getTCProperty(prop);
if(property==null) {
System.out.println(a+"未找到属性:" + prop);
return;
}
if(b.getTCProperty(prop)==null) {
System.out.println(b+"未找到属性:" + prop);
return;
}
int type = property.getPropertyType();
// System.out.println(prop+">>" + type);
if(type==TCProperty.PROP_untyped_relation || type==TCProperty.PROP_untyped_reference){
TCComponentPseudoFolder folder = TCUtil.getPseudoFolder(a, prop);
// System.out.println("folder:" + folder);
TCComponent[] cps;
if(folder == null) {
cps = property.getReferenceValueArray();
}else {
AIFComponentContext[] cxs = folder.getChildren();
cps = new TCComponent[cxs.length];
for(int i=0; i<cxs.length; i++)
cps[i] = (TCComponent) cxs[i].getComponent();
}
b.getTCProperty(prop).setReferenceValueArray(cps);
}else {
b.setProperty(prop, a.getProperty(prop));
}
// System.out.println(a +"=="+ property+">>" + b+"==" + b.getTCProperty(prop));
}
/*private void copyProperty(TCComponentBOMLine p, TCComponentBOMLine toLine, int num) throws Exception {
System.out.println("copyProperty:"+p+" copyProperty " + (System.nanoTime() - time0) / 1000000);
if(p.parent()!=null) {
for(String s : propVecs.get(0)) {
toLine.setProperty(s, "");
}
}
TCComponentItemRevision rev = toLine.getItemRevision();
for(String s : propVecs.get(1)) {
rev.setProperty(s, "");
}
TCComponentItem item = rev.getItem();
for(String s : propVecs.get(2)) {
item.setProperty(s, "");
}
TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev);
for(String s : propVecs.get(3)) {
form.setProperty(s, "");
}
if(num>0)
form.setProperty("ac5_OperationNumber", num*5+"");
System.out.println("copyProperty " + (System.nanoTime() - time0) / 1000000);
}
private String getProperty(String comp, String prop, TCComponent... comps) throws Exception {
if(comp.equals("rev"))
return comps[0].getProperty(prop);
else if(comp.equals("master"))
return comps[1].getProperty(prop);
else if(comp.equals("item"))
return comps[2].getProperty(prop);
else
return "";
}*/
}

@ -0,0 +1,67 @@
package cn.net.connor.std.processedit.ldy;
import java.util.Vector;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentMEProcess;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
//创建常规文件夹结构
public class ProcessMultiplexHandler extends AbstractHandler implements IHandler{
public Object execute(ExecutionEvent arg0) throws ExecutionException {
System.out.println("ProcessBorrowHandler");
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
AIFDesktop desktop = AIFUtility.getActiveDesktop();
try {
TCComponent target = (TCComponent)app.getTargetComponent();
if(!(target instanceof TCComponentBOMLine)) {
MessageBox.post(desktop, "请选择工艺BOM进行创建", "ERROR", MessageBox.ERROR);
return null;
}
if(((TCComponentBOMLine)target).parent() != null) {
MessageBox.post(desktop, "请选择工艺BOM进行创建", "ERROR", MessageBox.ERROR);
return null;
}
TCComponentItem item = ((TCComponentBOMLine)target).getItem();
if(!(item instanceof TCComponentMEProcess)) {
MessageBox.post(desktop, "请选择工艺BOM进行创建", "ERROR", MessageBox.ERROR);
return null;
}
String[] prefs = new String[] { "Connor_LD_GYJY_Item", "Connor_LD_GYJY_Process", "Connor_LD_GYJY_Borrow", "Connor_LD_GYJY_Prop", "Connor_LD_GYJY_Clear" };
Vector<String[]> options = new Vector<>();
for(String s : prefs) {
// if(s.equals("Connor_AVIC_GYJY_Borrow")) {
// options.add(new String[] {});
// continue;
// }
String searchOptions[] = session.getPreferenceService().getStringValues(s);
if(searchOptions == null) {
// MessageBox.post(desktop, "首选项"+s+"配置不正确", "ERROR", MessageBox.ERROR);
// return null;
options.add(new String[] {});
continue;
}
options.add(searchOptions);
}
new ProcessMultiplexDialog(session, (TCComponentBOMLine)target, options);
}catch(Exception e) {
e.printStackTrace();
MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR);
return null;
}
return null;
}
}

@ -0,0 +1,452 @@
package cn.net.connor.std.processedit.ldy;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel;
import javax.swing.tree.DefaultMutableTreeNode;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.common.AIFTreeNode;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.common.organization.OrgTreePanel;
import com.teamcenter.rac.common.organization.OrganizationTree;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentGroupMember;
import com.teamcenter.rac.kernel.TCComponentProject;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
public class SelectUserDialog extends AbstractAIFDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
private JButton b_ok;
private JButton b_cel;
private JButton add;
private JButton remove;
private OrganizationTree tree;
private JTree projectTree;
private JList<String> l_user;
private DefaultListModel<String> lm_user;
private JTextField editPropMap;
// private String group;
private boolean isMulti;
private JTable table;
private int colIndex;
private int[] rowIndex;
private TCComponentProject project;
private HashMap<String, TCComponentUser> userMap;
public SelectUserDialog(JTextField editPropMap, boolean isMulti) throws Exception {
super(true);
this.editPropMap = editPropMap;
this.isMulti = isMulti;
initUI();
}
private String getValue() {
String val = "";
if (editPropMap != null) {
val = editPropMap.getText();
} else if (table != null) {
val = (String) table.getValueAt(rowIndex[0], colIndex);
}
return val;
}
private void setValue(String text) {
if (editPropMap != null) {
editPropMap.setText(text);
} else if (table != null) {
for(int i : rowIndex)
table.setValueAt(text, i, colIndex);
}
}
public SelectUserDialog(JTable table, boolean isMulti, int[] rowIndex, int colIndex, TCComponentProject projectID) throws Exception {
super(true);
this.table = table;
this.isMulti = isMulti;
this.colIndex = colIndex;
this.rowIndex = rowIndex;
this.project = projectID;
initUI();
}
public SelectUserDialog(JTable table, int[] rowIndex, int colIndex, HashMap<String, TCComponentUser> userMap) throws Exception {
super(true);
this.table = table;
this.colIndex = colIndex;
this.rowIndex = rowIndex;
this.userMap = userMap;
initUI();
}
private void initUI() throws Exception {
this.setTitle("Ñ¡ÔñÈËÔ±");
this.setLayout(new BorderLayout());
int pweight = 440, pheight = 480, mweight = 280, mheight = 320;
if (isMulti) {
// this.setPreferredSize(new Dimension(640, 480));
// this.setMinimumSize(new Dimension(480, 320));
pweight = 640;
mweight = 480;
}
if(project != null) {
pheight = 700;
mheight = 700;
}
this.setPreferredSize(new Dimension(pweight, pheight));
this.setMinimumSize(new Dimension(mweight, mheight));
OrgTreePanel orgPanel = new OrgTreePanel((TCSession) AIFUtility.getCurrentApplication().getSession());
this.tree = orgPanel.getOrgTree();
if(project != null) {
JPanel panel = new JPanel(new PropertyLayout());
panel.add("1.1.center.center", orgPanel);
panel.add("2.1.center.center", initProjectPanel(orgPanel));
// FlowLayout flow = new FlowLayout();
// flow.setAlignOnBaseline(true);
// JPanel panel = new JPanel(flow);
// panel.add(orgPanel);
// panel.add(initProjectPanel(orgPanel));
this.add(BorderLayout.WEST, panel);
}else {
this.add(BorderLayout.CENTER, orgPanel);
}
this.add(BorderLayout.SOUTH, initBtnPanel());
if (isMulti) {
JPanel lp = initListPanel();
this.add(BorderLayout.EAST, lp);
initData();
}
addListeners();
this.setAlwaysOnTop(true);
}
private void initData() {
String text = getValue();
if (text.isEmpty()) {
return;
}
String[] split = text.split(",");
for (int i = 0; i < split.length; i++) {
lm_user.addElement(split[i]);
}
}
private JPanel initListPanel() {
JPanel panel = new JPanel(new BorderLayout());
FlowLayout flow = new FlowLayout();
flow.setVgap(100);
JPanel btnPanel = new JPanel(flow);
btnPanel.add(this.add);
// btnPanel.add("2.1.center.center", this.remove);
this.lm_user = new DefaultListModel<>();
this.l_user = new JList<>(lm_user);
l_user.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.l_user.setCellRenderer(new DeleteListRenderer(l_user));
JScrollPane scroll = new JScrollPane(l_user);
scroll.setPreferredSize(new Dimension(200, 0));
// this.add.setPreferredSize(new Dimension(50, 30));
panel.add(BorderLayout.WEST, btnPanel);
panel.add(BorderLayout.CENTER, scroll);
return panel;
}
private JPanel initBtnPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 5));
this.b_ok = new JButton("È·¶¨");
this.b_cel = new JButton("È¡Ïû");
this.add = new JButton("+");
this.remove = new JButton("-");
panel.add(b_ok);
panel.add(b_cel);
return panel;
}
private JScrollPane initProjectPanel(OrgTreePanel orgPanel) throws Exception {//TODO
Dimension orgDimension = orgPanel.getPreferredSize();
orgPanel.setPreferredSize(new Dimension(orgDimension.width*2, orgDimension.height-100));
DefaultMutableTreeNode root = new DefaultMutableTreeNode(project.getProjectID(), true);
projectTree = new JTree(root);
List<Object> team = project.getTeam();
TCComponent[] members = (TCComponent[])team.get(0);
for(TCComponent c : members) {
if(c instanceof TCComponentGroupMember) {
TCComponentGroupMember member = (TCComponentGroupMember)c;
DefaultMutableTreeNode childRoot = new DefaultMutableTreeNode(member, true);
root.add(childRoot);
}
}
projectTree.setPreferredSize(new Dimension(orgDimension.width*2, orgDimension.height/2));
// projectTree.setMaximumSize(new Dimension(orgDimension.width*2, orgDimension.height/2));
JScrollPane projectPane = new JScrollPane(projectTree);
return projectPane;
}
private TCComponentUser getSelectUser() throws Exception {
// Object[] comps = tree.getSelectedOrgObjects();
AIFTreeNode[] comps = tree.getSelectedNodes();
// System.out.println("comps:"+(comps==null));
if (comps == null) {
if(projectTree == null)
return null;
else if(projectTree.getSelectionModel() == null)
return null;
else if(projectTree.getLastSelectedPathComponent() == null)
return null;
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) projectTree.getLastSelectedPathComponent();
Object selectObject = selectNode.getUserObject();
if(selectObject instanceof TCComponentGroupMember) {
// String member = ((TCComponentGroupMember) selectObject).toString();
// if(member.indexOf(".")>0)
// group = member.substring(0, member.indexOf("."));
// else
// group = member.substring(0, member.indexOf("/"));
TCComponentUser user = ((TCComponentGroupMember) selectObject).getUser();
if (user != null) {
return user;
}
}else
return null;
}
// System.out.println("comps:"+comps.length);
for (int i = 0; i < comps.length; i++) {
// OrgObject comp = (OrgObject) comps[i];
TCComponent gm = (TCComponent) comps[i].getContextComponent().getComponent();
// System.out.println("gm:"+gm);
if (gm != null && (gm instanceof TCComponentGroupMember)) {
TCComponentUser user = ((TCComponentGroupMember) gm).getUser();
if (user != null) {
// group = ((DefaultMutableTreeNode)comps[i].getParent().getParent()).getUserObject().toString();
return user;
}
}
}
return null;
}
private void addListeners() {
this.b_cel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
this.b_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
if (isMulti) {
int size = lm_user.getSize();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < size; i++) {
String text = lm_user.getElementAt(i);
if (text != null) {
sb.append(text).append(";");
}
}
if (sb.length() > 0) {
sb.setLength(sb.length() - 1);
}
setValue(sb.toString());
} else {
TCComponentUser user = getSelectUser();
if (user != null) {
String value = user.getUserId() +"/"+ user.getUserName();
userMap.put(value, user);
setValue(value);
} else {
setValue("");
}
}
disposeDialog();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
super.mouseClicked(e);
if(projectTree != null)
projectTree.clearSelection();
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
TCComponentUser user = getSelectUser();
System.out.println("user:"+user);
if (user != null) {
if (isMulti) {
if (!lm_user.contains(user.toString())) {
lm_user.addElement(user.toString());
}
} else {
String value = user.getUserId() +"/"+ user.getUserName();
userMap.put(value, user);
setValue(value);
disposeDialog();
}
}
}
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
if(projectTree != null) {
projectTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
super.mouseClicked(e);
tree.clearSelection();
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
TCComponentUser user = getSelectUser();
if (user != null) {
if (isMulti) {
if (!lm_user.contains(user.toString())) {
lm_user.addElement(user.toString());
}
} else {
String value = user.getUserId() +"/"+ user.getUserName();
userMap.put(value, user);
setValue(value);
disposeDialog();
}
}
}
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
}
if(l_user!=null) {
this.l_user.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
int ind = l_user.getSelectedIndex();
if (ind >= 0) {
lm_user.remove(ind);
}
}
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
}
});
}
this.add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
TCComponentUser user = getSelectUser();
System.out.println("user:"+user);
if (user != null) {
if (!lm_user.contains(user.toString())) {
lm_user.addElement(user.toString());
}
}
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
this.remove.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
}
private class DeleteListRenderer extends JPanel implements ListCellRenderer<String> {
/**
*
*/
private static final long serialVersionUID = 1L;
JButton btn;
JLabel label;
public DeleteListRenderer(final JList<? extends String> list) {
this.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 1));
this.setBackground(Color.WHITE);
btn = getDeletetBtn();
label = new JLabel("");
this.add(btn);
this.add(label);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int ind = list.getSelectedIndex();
System.out.println(ind);
if (ind >= 0) {
list.remove(ind);
}
}
});
}
@Override
public Component getListCellRendererComponent(JList<? extends String> list, String value, int index,
boolean isSelected, boolean cellHasFocus) {
label.setText(value);
return this;
}
private JButton getDeletetBtn() {
ImageIcon icon = new ImageIcon(SelectUserDialog.class.getResource("image/delete.png"));
JButton btn = new JButton(icon);
btn.setPreferredSize(new Dimension(23, 23));
btn.setContentAreaFilled(false);
btn.setFocusPainted(false);
btn.setBorderPainted(false);
btn.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
return btn;
}
}
}

@ -0,0 +1,469 @@
package cn.net.connor.std.processedit.ldy;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JTable;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.filechooser.FileSystemView;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.commands.open.OpenFormDialog;
import com.teamcenter.rac.kernel.ListOfValuesInfo;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
import com.teamcenter.rac.kernel.TCComponentContextList;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentDatasetType;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
import com.teamcenter.rac.kernel.TCComponentPseudoFolder;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCQueryClause;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class TCUtil {
public static final int MINWIDTH = 1280;
public static final int MINHEIGHT = 768;
public static void fitToScreen(AbstractAIFDialog abstractAIFDialog) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double screenWidth = screenSize.getWidth();
double screenHeight = screenSize.getHeight();
Dimension dialogSize = abstractAIFDialog.getSize();
if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) {
abstractAIFDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight())));
abstractAIFDialog.setLocation(10, (int) Math.floor(abstractAIFDialog.getLocation().getY()));
}
if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) {
abstractAIFDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20)));
abstractAIFDialog.setLocation((int) Math.floor(abstractAIFDialog.getLocation().getX()), 10);
}
/*
* if((screenWidth<MINWIDTH||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
* MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { abstractAIFDialog.setSize(new
* Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20)));
* abstractAIFDialog.setLocation(10, 10); }
*/
}
public static void fitToScreen(OpenFormDialog openFormDialog) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double screenWidth = screenSize.getWidth();
double screenHeight = screenSize.getHeight();
Dimension dialogSize = openFormDialog.getSize();
if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) {
openFormDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight())));
openFormDialog.setLocation(10, (int) Math.floor(openFormDialog.getLocation().getY()));
}
if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) {
openFormDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20)));
openFormDialog.setLocation((int) Math.floor(openFormDialog.getLocation().getX()), 10);
}
/*
* if((screenWidth<MINWIDTH||screenHeight<MINHEIGHT)&&(dialogSize.getWidth()>
* MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { openFormDialog.setSize(new
* Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20)));
* openFormDialog.setLocation(10, 10); }
*/
}
public static TCComponentBOMWindow getWindow(TCSession session) throws Exception{
TCComponentBOMWindow window = null;
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
window = bomWinType.create(null);
return window;
}
@SuppressWarnings("deprecation")
public static TCComponentBOMLine getBOMLine(TCSession session,TCComponentBOMWindow window, TCComponentItemRevision revision)
throws Exception {
window.lock();
TCComponentBOMLine bomLine = window.setWindowTopLine(null, revision, null, null);
window.save();
window.unlock();
return bomLine;
}
public static TCComponentPseudoFolder getPseudoFolder(TCComponent parent, String relation)
throws Exception {
TCComponentPseudoFolder pseudoFolder = null;
AIFComponentContext[] comps = parent.getChildren();
if (comps != null && comps.length > 0 && comps[0] != null) {
for (int i = 0; i < comps.length; i++) {
TCComponent comp = (TCComponent) comps[i].getComponent();
if (comp instanceof TCComponentPseudoFolder) {
if (comp.isTypeOf("PseudoFolder")) {
// System.out.println("PseudoFolder type:" + comp.getDefaultPasteRelation());
if (comp.getDefaultPasteRelation().equalsIgnoreCase(relation)) {
pseudoFolder = (TCComponentPseudoFolder) comp;
break;
}
}
}
}
}
return pseudoFolder;
}
public static TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws Exception {
if (revision != null) {
AIFComponentContext[] contexts = revision.getChildren("IMAN_master_form_rev");
if (contexts != null && contexts.length > 0) {
InterfaceAIFComponent component = contexts[0].getComponent();
if (component instanceof TCComponentForm) {
return (TCComponentForm) component;
}
}
}
return null;
}
public static TCComponentItemRevision getRevisionFromMaster(TCComponentForm form) throws Exception {
if (form != null) {
AIFComponentContext[] contexts = form.whereReferencedByTypeRelation(null, new String[] { "IMAN_master_form_rev" });
if (contexts != null && contexts.length > 0) {
InterfaceAIFComponent component = contexts[0].getComponent();
if (component instanceof TCComponentItemRevision) {
return (TCComponentItemRevision) component;
}
}
}
return null;
}
public static LinkedHashMap<String, String> getlovValues(TCSession session, String lovName) throws TCException {
LinkedHashMap<String, String> lovVal = new LinkedHashMap<String, String>();
TCComponentListOfValuesType lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues");
TCComponentListOfValues[] lovs = lovType.find(lovName);
if (lovs != null && lovs.length > 0) {
TCComponentListOfValues lov = lovs[0];
ListOfValuesInfo lovInfo = lov.getListOfValues();
String[] code = lovInfo.getStringListOfValues();
String[] name = lovInfo.getLOVDisplayValues();
if (code != null && name != null) {
for (int i = 0; i < code.length; i++) {
// System.out.printf("code[%d]=%s name[%d]=%s \n", i, code[i], i, name[i]);
lovVal.put(code[i], name[i]);
}
}
return lovVal;
}
return null;
}
public static String getTableValue(JTable table, int row, int col){
Object val = table.getValueAt(row, col);
if(val==null)
return "";
else
return val.toString();
}
public static TCComponent[] query(TCSession session, String queryName, String[] aKey, String[] aVal) throws Exception {
TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName);
if (imancomponentquery == null) {
throw new Exception("未找到查询构建器 " + queryName + "!");
}
aKey = session.getTextService().getTextValues(aKey);
// for (int i = 0; i < aKey.length; i++) {
// System.out.println(aKey[i] + "===============" + aVal[i]);
// }
TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(aKey, aVal);
return componentContextList.toTCComponentArray();
}
public static TCComponent[] query(TCSession session, String queryName, Vector<String> Keys, Vector<String> Vals) throws Exception {
TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery");
TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName);
if (imancomponentquery == null) {
System.out.println("未找到查询构建器" + queryName);
throw new Exception("Query:"+queryName+" cannot find");
}
TCQueryClause[] qc = imancomponentquery.describe();
// Map<String, String> clauseMap = new HashMap<>();
for(TCQueryClause c : qc) {
String key = c.getUserEntryNameDisplay();
String value = c.getDefaultValue();
// System.out.println(key + "==>" + c.getAttributeName());
if(!value.trim().isEmpty() && !Keys.contains(key)) {
if(key.isEmpty())
Keys.add(c.getAttributeName());
else
Keys.add(key);
Vals.add(value);
}
}
int size = Keys.size();
String[] keyA = new String[size];
String[] valueA = new String[size];
for(int i=0; i<size; i++) {
keyA[i] = Keys.get(i);
valueA[i] = Vals.get(i);
System.out.println(keyA[i] + ":" + valueA[i]);
}
TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(keyA, valueA);
return componentContextList.toTCComponentArray();
}
public static String getSerialNo(TCSession session, String itemId, String objectType) throws Exception {
TCComponent[] comps = null;
if (objectType.equals("")) {
comps = query(session, "零组件 ID", new String[] { "ItemID" }, new String[] { itemId + "*" });
} else {
comps = query(session, "零组件...", new String[] { "ItemID", "Type" }, new String[] { itemId + "*", objectType });
}
// System.out.println("getSerialNo comps.len:" + (comps == null ? 0 : comps.length));
if (comps.length > 0) {
Integer maxId = 0;
for (TCComponent comp : comps) {
String pid = comp.getProperty("item_id");
System.out.println("pid:" + pid);
String pidSuffix = pid.substring(pid.length() - 3);
if (Integer.parseInt(pidSuffix) > maxId) {
maxId = Integer.parseInt(pidSuffix);
}
}
return String.format("%03d", maxId + 1);
}
return "001";
}
public static File saveExcelChooser() {
File dir = null;
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory();
File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory();
chooser.setCurrentDirectory(desktopDir);
String saveType[] = { "xlsx" };
chooser.setFileFilter(new FileNameExtensionFilter("Excel工作簿", saveType));
int returnVal = chooser.showSaveDialog(new Frame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
dir = chooser.getSelectedFile();
String path = dir.getPath();
if(!path.toLowerCase().endsWith(".xlsx")) {
path += ".xlsx";
dir = new File(path);
}
System.out.println("saveExcelChooser1:" + path);
}
return dir;
}
public static File saveExcelChooser(String defaultFile) {
File dir = null;
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory();
File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory();
chooser.setCurrentDirectory(desktopDir);
chooser.setSelectedFile(new File(defaultFile));
String saveType[] = { "xlsx" };
chooser.setFileFilter(new FileNameExtensionFilter("Excel工作簿", saveType));
int returnVal = chooser.showSaveDialog(new Frame());
if (returnVal == JFileChooser.APPROVE_OPTION) {
dir = chooser.getSelectedFile();
String path = dir.getPath();
if(!path.toLowerCase().endsWith(".xlsx")) {
path += ".xlsx";
dir = new File(path);
}
if(dir.exists())
dir.delete();
// System.out.println("saveExcelChooser1:" + dir.getPath());
}
return dir;
}
public static boolean contains(String[] array, String str) {
for(String s : array) {
// System.out.println("contains:"+s+"="+str);
if(s.equals(str))
return true;
}
return false;
}
public static Map<String, String> executeToMap(InputStream in){
System.out.println("Read properties file");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
String line = null;
Map<String, String> resultMap = new LinkedHashMap<>(16);
if (reader.ready()) {
while (null != (line = reader.readLine())) {
if (line.length() <= 0 || line.contains("#") || !line.contains("=")) {
continue;
}
resultMap.put(line.substring(0, line.indexOf("=")), line.substring(line.indexOf("=") + 1));
}
}
in.close();
reader.close();
return resultMap;
} catch (Exception e) {
e.printStackTrace();
MessageBox.post("Find properties file failed", "ERROR", MessageBox.ERROR);
}
return null;
}
public static TCComponentDataset createExcelDataset(TCSession session, File file, String datasetName) throws Exception {
String refType = null, objType = null, fileName = null;
fileName = file.getName().toLowerCase();
if (fileName.endsWith("xls")) {
refType = "excel";
objType = "MSExcel";
} else if (fileName.endsWith("xlsx")) {
refType = "excel";
objType = "MSExcelX";
}
TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService().getTypeComponent("Dataset");
TCComponentDataset dataset = compType.create(datasetName, "description", objType);
dataset.setFiles(new String[] { file.getAbsolutePath() }, new String[] { refType });
return dataset;
}
public static Vector<TCComponent> getChildren(TCComponent parent, String relation, String name) throws Exception {
Vector<TCComponent> result = new Vector<>();
AIFComponentContext[] children;
if(relation==null || relation.isEmpty())
children = parent.getChildren();
else
children = parent.getChildren(relation);
for(AIFComponentContext c : children) {
TCComponent comp = (TCComponent) c.getComponent();
if(comp.getProperty("object_name").equals(name))
result.add(comp);
}
return result;
}
/**
*
* TCComponent property
*/
public static TCComponent[] TCsort(TCComponent[] TCComponent, String property, int desc) {
HashMap<TCComponent,String> map = new HashMap<>();
int count = TCComponent.length;
for(TCComponent Component : TCComponent) {
try {
map.put(Component, Component.getProperty(property));
} catch (Exception e) {
e.printStackTrace();
}
}
// 通过ArrayList构造函数把map.entrySet()转换成list
List<Map.Entry<TCComponent, String>> list = new ArrayList<Map.Entry<TCComponent, String>>(map.entrySet());
// 通过比较器实现比较排序
Collections.sort(list, new Comparator<Map.Entry<TCComponent, String>>() {
public int compare(Map.Entry<TCComponent, String> mapping1, Map.Entry<TCComponent, String> mapping2) {
return mapping1.getValue().compareTo(mapping2.getValue()) * desc;
}
});
TCComponent = new TCComponent[count];
int i=0;
for(Map.Entry<TCComponent, String> mapping : list) {
TCComponent[i] = mapping.getKey();
i++;
}
return TCComponent;
}
public static TCComponent[] TCsort(TCComponent[] TCComponent, int[] desc, String... property) {
HashMap<TCComponent, String[]> map = new HashMap<>();
int count = TCComponent.length;
for(TCComponent Component : TCComponent) {
try {
String[] values = new String[property.length];
for(int i=0; i<property.length; i++)
values[i] = Component.getProperty(property[i]);
map.put(Component, values);
} catch (Exception e) {
e.printStackTrace();
}
}
// 通过ArrayList构造函数把map.entrySet()转换成list
List<Map.Entry<TCComponent, String[]>> list = new ArrayList<Map.Entry<TCComponent, String[]>>(map.entrySet());
// 通过比较器实现比较排序
Collections.sort(list, new Comparator<Map.Entry<TCComponent, String[]>>() {
public int compare(Map.Entry<TCComponent, String[]> mapping1, Map.Entry<TCComponent, String[]> mapping2) {
String[] v1 = mapping1.getValue(), v2 = mapping2.getValue();
for(int i=0; i<v1.length; i++) {
if(!v1[i].equals(v2[i]))
return v1[i].compareTo(v2[i]) * desc[i];
}
return 0;
}
});
TCComponent = new TCComponent[count];
int i=0;
for(Map.Entry<TCComponent, String[]> mapping : list) {
TCComponent[i] = mapping.getKey();
i++;
}
return TCComponent;
}
public static void deleteWarning(File file) throws Exception {
FileInputStream input = null;
FileOutputStream output = null;
try {
input = new FileInputStream(file);
XWPFDocument doc = new XWPFDocument(input);
// XWPFParagraph para = doc.getParagraphs().get(0);
// System.out.println("para.getRuns:"+para.getRuns().size());
// for(XWPFRun run : para.getRuns()) {
// System.out.println("run:"+run.getText(0));
// }
doc.removeBodyElement(0);
// para.removeRun(0);
// System.out.println("para.getRuns:"+para.getRuns().size()+" getParagraphs:"+doc.getParagraphs().get(0).getText());
// para.setPageBreak(false);
output = new FileOutputStream(file.getPath());
doc.write(output);
}catch (Exception e) {
throw e;
}finally {
if(input!=null)
input.close();
if(output!=null)
output.close();
}
}
public static int findChar(String str, char a, int num) throws Exception {
int n = 1;
for(int i=0; i<str.length(); i++) {
if(str.charAt(i) == a) {
if(n == num)
return i;
else
n++;
}
}
return str.length();
}
}

@ -0,0 +1,63 @@
package cn.net.connor.std.processedit.meopviewfx;
import java.util.List;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.ui.views.AbstractContentViewPart;
import cn.net.connor.std.processedit.meopviewfx.ui.MEOPPanel;
import javafx.embed.swt.FXCanvas;
import javafx.scene.Scene;
public class MEOPEditView extends AbstractContentViewPart {
public static final String ID = MEOPEditView.class.getName();
private Object currentObj = null;
private MEOPPanel meopPanel;
@Override
protected void processEmptySelection(IWorkbenchPart iWorkbenchPart, List<Object> list) {
if (list == null || list.size() != 1) {
return;
}
final Object target = list.get(0);
if (target != null && !(target.equals(currentObj))) {
System.out.println("Select: " + target);
currentObj = target;
new Thread(new Runnable() {
@Override
public void run() {
if (meopPanel != null)
meopPanel.updateSelection(target);
}
}).start();
}
}
public MEOPEditView() {
this.setProcessNullSelectionsEnabled(true);
this.setUseScrolledForm(false);
this.setShowHeader(true);
this.setMultiSelectionSupported(true);
this.setUISupportsAssociate(false);
this.setUISupportsSetScope(false);
this.setUISupportsViewLocking(true);
this.setUseInitialInputJobEnabled(false);
this.setProcessSelectionFromSiblingViewEnabled(true);
}
@Override
protected void createContent(Composite parent) {
System.out.println("Init UI...");
parent.setLayout(new FillLayout());
FXCanvas fxCanvas = new FXCanvas(parent, 16777216);
this.meopPanel = new MEOPPanel(AIFUtility.getCurrentApplication().getDesktop());
Scene scene = this.meopPanel.getScene();
System.out.println("Init UI Complete");
fxCanvas.setScene(scene);
}
}

@ -0,0 +1,334 @@
package cn.net.connor.std.processedit.meopviewfx.bean;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.SoaUtil;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.services.internal.rac.structuremanagement.StructureService;
import com.teamcenter.services.internal.rac.structuremanagement._2011_06.Structure;
import cn.net.connor.std.aifrcp.util.KUtil;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.layout.Region;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
public class KTableRow {
public static final String BOMLINE = "BOMLINE";
public static final String ITEM = "ITEM";
public static final String ITEMMASTER = "ITEMMASTER";
public static final String REV = "REV";
public static final String REVMASTER = "REVMASTER";
private static double ZOOM = 1;
static {
try {
ZOOM = ((TCSession) AIFUtility.getCurrentApplication().getSession()).getPreferenceService().getDoubleValue("Connor_AVIC_GXBZ_Web_Zoom");
} catch (Exception e) {
}
if (ZOOM < 0) {
ZOOM = 1;
}
System.out.println("GDT ZOOM = " + ZOOM);
}
private TCComponentBOMLine bomline;
private TCComponentItem item;
private TCComponentItemRevision rev;
private TCComponent itemMaster;
private TCComponent revMaster;
private boolean showWebView = true;
private WebView webView;
private String webContent;
public KTableRow(TCComponentBOMLine bomline, TCComponentItem item, TCComponentItemRevision rev, TCComponent itemMaster, TCComponent revMaster) {
this.bomline = bomline;
this.item = item;
this.rev = rev;
this.itemMaster = itemMaster;
this.revMaster = revMaster;
}
public Map<PropConfig, SimpleStringProperty> stringProps = new HashMap<PropConfig, SimpleStringProperty>();
protected Map<PropConfig, String> savedValues = new HashMap<PropConfig, String>();
public TCComponentBOMLine getBomLine() {
return this.bomline;
}
public void setValueByPropName(String config, String value) throws Exception {
if (KUtil.isEmpty(config)) {
return;
}
System.out.println("Set Row Value [" + config + "] = [" + value + "]");
for (PropConfig propConfig : stringProps.keySet()) {
if (config.equalsIgnoreCase(propConfig.propName)) {
stringProps.get(propConfig).setValue(value);
}
}
System.out.println(">> config not found");
}
public boolean parseConfig(PropConfig config) throws Exception {
if (config == null) {
return true;
}
String value = getTCValue(config.propLoc, config.propName);
stringProps.put(config, new SimpleStringProperty(value));
savedValues.put(config, value);
if (!KUtil.isEmpty(config.filterValue)) {
// && !config.filterValue.equals(value)
// 20200722 split filter
String[] filters = config.filterValue.split(";");
boolean checkOK = false;
for (String string : filters) {
if (string.equals(value)) {
checkOK = true;
break;
}
}
return checkOK;
}
return true;
}
public String getTCValue(String proploc, String propName) throws Exception {
TCComponent comp = getTCComponent(proploc);
if (comp == null) {
return "";
}
return comp.getStringProperty(propName);
}
public TCComponent getTCComponent(String proploc) {
if (KUtil.isEmpty(proploc)) {
return bomline;
}
proploc = proploc.toUpperCase();
switch (proploc) {
case BOMLINE:
return bomline;
case ITEM:
return item;
case REV:
return rev;
case ITEMMASTER:
return itemMaster;
case REVMASTER:
return revMaster;
default:
System.out.println(">> Prop location error: " + proploc);
break;
}
return null;
}
private boolean loadTCValues(Map<String, String> bomlinePropMap, Map<String, String> itemPropMap, Map<String, String> revPropMap, Map<String, String> itemMasterPropMap,
Map<String, String> revMasterPropMap) {
boolean modified = false;
for (PropConfig config : stringProps.keySet()) {
if (!config.canEdit) {
continue;
}
String value = stringProps.get(config).getValueSafe();
if (savedValues.containsKey(config)) {
String savedValue = savedValues.get(config);
if (value.equals(savedValue)) {
continue;
}
}
modified = true;
String propName = config.propName;
String proploc = config.propLoc.toUpperCase();
System.out.println(">> " + proploc + "." + propName + " = " + value);
switch (proploc) {
case BOMLINE:
bomlinePropMap.put(propName, value);
break;
case ITEM:
itemPropMap.put(propName, value);
if ("object_name".equals(propName)) {
revPropMap.put(propName, value);
}
break;
case REV:
revPropMap.put(propName, value);
if ("object_name".equals(propName)) {
itemPropMap.put(propName, value);
}
break;
case ITEMMASTER:
itemMasterPropMap.put(propName, value);
break;
case REVMASTER:
revMasterPropMap.put(propName, value);
break;
default:
System.out.println(">> Prop location error: " + proploc);
break;
}
}
return modified;
}
public void saveTCData(TCComponentBOMLine parentLine, TCComponentItemType itemType, int precise, TCComponent viewTypeTag) throws Exception {
if (bomline == null) {
if (itemType != null && parentLine != null) {
System.out.println("Create New Row...");
item = itemType.create(itemType.getNewID(), itemType.getNewRev(null), itemType.getName(), "-", "", null);
System.out.println(">> new item: " + item);
rev = item.getLatestItemRevision();
itemMaster = item.getRelatedComponent("IMAN_master_form");
revMaster = rev.getRelatedComponent("IMAN_master_form_rev");
bomline = parentLine.add(item, rev, null, false, "");
}
}
if (bomline == null) {
return;
}
System.out.println("Update: " + bomline + ", Precise = " + precise);
if (precise != 0) {
TCComponent[] bvrs = rev.getReferenceListProperty("structure_revisions");
System.out.println("BVR: " + Arrays.toString(bvrs));
if (KUtil.getLen(bvrs) == 0) {
TCSession session = rev.getSession();
StructureService structureService = StructureService.getService(session);
Structure.CreateOrSaveAsPSBOMViewRevisionResponse createOrSaveAsPSBOMViewRevisionResponse = null;
Structure.CreateOrSaveAsPSBOMViewRevisionInput[] arrayOfCreateOrSaveAsPSBOMViewRevisionInput = new Structure.CreateOrSaveAsPSBOMViewRevisionInput[1];
arrayOfCreateOrSaveAsPSBOMViewRevisionInput[0] = new Structure.CreateOrSaveAsPSBOMViewRevisionInput();
(arrayOfCreateOrSaveAsPSBOMViewRevisionInput[0]).clientId = (new Integer(0)).toString();
(arrayOfCreateOrSaveAsPSBOMViewRevisionInput[0]).isPrecise = precise > 0;
(arrayOfCreateOrSaveAsPSBOMViewRevisionInput[0]).viewTypeTag = viewTypeTag;
(arrayOfCreateOrSaveAsPSBOMViewRevisionInput[0]).itemObject = rev.getItem();
(arrayOfCreateOrSaveAsPSBOMViewRevisionInput[0]).itemRevObj = rev;
createOrSaveAsPSBOMViewRevisionResponse = structureService.createOrSavePSBOMViewRevision(arrayOfCreateOrSaveAsPSBOMViewRevisionInput);
SoaUtil.checkPartialErrors(createOrSaveAsPSBOMViewRevisionResponse.serviceData);
} else {
bomline.setPrecision(precise > 0);
}
}
Map<String, String> revPropMap = new HashMap<>();
Map<String, String> revMasterPropMap = new HashMap<>();
Map<String, String> itemPropMap = new HashMap<>();
Map<String, String> itemMasterPropMap = new HashMap<>();
Map<String, String> bomlinePropMap = new HashMap<>();
if (!loadTCValues(bomlinePropMap, itemPropMap, revPropMap, itemMasterPropMap, revMasterPropMap)) {
return;
}
if (itemPropMap.size() > 0) {
item.setProperties(itemPropMap);
}
if (revPropMap.size() > 0) {
rev.setProperties(revPropMap);
}
if (itemMasterPropMap.size() > 0) {
itemMaster.setProperties(itemMasterPropMap);
}
if (revMasterPropMap.size() > 0) {
revMaster.setProperties(revMasterPropMap);
}
if (bomlinePropMap.size() > 0) {
bomline.setProperties(bomlinePropMap);
}
bomline.refresh();
}
public void removeLine() throws Exception {
if (bomline != null) {
System.out.println(">> Remove: " + bomline);
bomline.cut();
}
}
public void showWebView(boolean showWebView) {
this.showWebView = showWebView;
}
public boolean showWebView() {
return showWebView;
}
public WebView getWebView() {
return this.webView;
}
public WebView checkWebView() {
if (!showWebView) {
return null;
}
if (webView == null) {
webView = new WebView();
webView.setDisable(true);
webView.setMouseTransparent(true);
webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
webView.setZoom(ZOOM);
// webView.getEngine().documentProperty().addListener((obj, prev, newv) -> {
// if (newv == null) {
// return;
// }
// try {
// // String heightText = webView.getEngine().executeScript(
// // "var body = document.body, html = document.documentElement;Math.max(
// // body.scrollHeight, body.offsetHeight, html.clientHeight,
// html.scrollHeight,
// // html.offsetHeight );")
// // .toString();
//
// // double height = Double.parseDouble(heightText.replace("px", ""));
// // webView.setPrefHeight(height + 12);
// // System.out.println("Set Height [" + getTCComponent(BOMLINE) + "]: " +
// // height);
// new Thread(() -> {
// Platform.runLater(() -> {
// String heightText = webView.getEngine().executeScript("var body =
// document.body, html = document.documentElement;Math.max( body.scrollHeight,
// body.offsetHeight );")
// .toString();
// double height2 = Double.parseDouble(heightText.replace("px", "")) + 12;
// System.out.println("Set Height [" + getTCComponent(BOMLINE) + "][" +
// webView.getWidth() + "]: " + height2);
// webView.setPrefHeight(height2);
// webView.getParent().layout();
// webView.layout();
// });
// }).start();
// } catch (Exception e) {
// e.printStackTrace();
// }
// });
// webView.getEngine().getLoadWorker().stateProperty().addListener(new
// ChangeListener<State>() {
// @Override
// public void changed(ObservableValue<? extends State> observable, State
// oldValue, State newValue) {
// if (newValue == State.SUCCEEDED) {
// // webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
// }
// }
// });
}
return webView;
}
public void loadContent(String html) {
if (html == null) {
html = "";
}
if (html.equals(this.webContent)) {
return;
}
webView.setPrefWidth(Region.USE_COMPUTED_SIZE);
webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
WebEngine engine = webView.getEngine();
this.webContent = html;
engine.loadContent(html);
}
}

@ -0,0 +1,217 @@
package cn.net.connor.std.processedit.meopviewfx.bean;
import java.util.HashMap;
import java.util.Map;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import cn.net.connor.std.aifrcp.util.KUtil;
import javafx.beans.property.SimpleStringProperty;
public class KTableRowBackup20220509 {
public static final String BOMLINE = "BOMLINE";
public static final String ITEM = "ITEM";
public static final String ITEMMASTER = "ITEMMASTER";
public static final String REV = "REV";
public static final String REVMASTER = "REVMASTER";
private TCComponentBOMLine bomline;
private TCComponentItem item;
private TCComponentItemRevision rev;
private TCComponent itemMaster;
private TCComponent revMaster;
private boolean showWebView = true;
public KTableRowBackup20220509(TCComponentBOMLine bomline, TCComponentItem item, TCComponentItemRevision rev, TCComponent itemMaster, TCComponent revMaster) {
this.bomline = bomline;
this.item = item;
this.rev = rev;
this.itemMaster = itemMaster;
this.revMaster = revMaster;
}
public Map<PropConfig, SimpleStringProperty> stringProps = new HashMap<PropConfig, SimpleStringProperty>();
protected Map<PropConfig, String> savedValues = new HashMap<PropConfig, String>();
public TCComponentBOMLine getBomLine() {
return this.bomline;
}
public void setValueByPropName(String config, String value) throws Exception{
if(KUtil.isEmpty(config)) {
return;
}
System.out.println("Set Row Value ["+config+"] = ["+value+"]");
for (PropConfig propConfig : stringProps.keySet()) {
if(config.equalsIgnoreCase(propConfig.propName)) {
stringProps.get(propConfig).setValue(value);
}
}
System.out.println(">> config not found");
}
public boolean parseConfig(PropConfig config) throws Exception {
if (config == null) {
return true;
}
String value = getTCValue(config.propLoc, config.propName);
stringProps.put(config, new SimpleStringProperty(value));
savedValues.put(config, value);
if (!KUtil.isEmpty(config.filterValue)) {
// && !config.filterValue.equals(value)
// 20200722 split filter
String[] filters = config.filterValue.split(";");
boolean checkOK = false;
for (String string : filters) {
if (string.equals(value)) {
checkOK = true;
break;
}
}
return checkOK;
}
return true;
}
public String getTCValue(String proploc, String propName) throws Exception {
TCComponent comp = getTCComponent(proploc);
if (comp == null) {
return "";
}
return comp.getStringProperty(propName);
}
public TCComponent getTCComponent(String proploc) {
if (KUtil.isEmpty(proploc)) {
return bomline;
}
proploc = proploc.toUpperCase();
switch (proploc) {
case BOMLINE:
return bomline;
case ITEM:
return item;
case REV:
return rev;
case ITEMMASTER:
return itemMaster;
case REVMASTER:
return revMaster;
default:
System.out.println(">> Prop location error: " + proploc);
break;
}
return null;
}
private boolean loadTCValues(Map<String, String> bomlinePropMap, Map<String, String> itemPropMap, Map<String, String> revPropMap, Map<String, String> itemMasterPropMap,
Map<String, String> revMasterPropMap) {
boolean modified = false;
for (PropConfig config : stringProps.keySet()) {
if (!config.canEdit) {
continue;
}
String value = stringProps.get(config).getValueSafe();
if (savedValues.containsKey(config)) {
String savedValue = savedValues.get(config);
if (value.equals(savedValue)) {
continue;
}
}
modified = true;
String propName = config.propName;
String proploc = config.propLoc.toUpperCase();
System.out.println(">> " + proploc + "." + propName + " = " + value);
switch (proploc) {
case BOMLINE:
bomlinePropMap.put(propName, value);
break;
case ITEM:
itemPropMap.put(propName, value);
if ("object_name".equals(propName)) {
revPropMap.put(propName, value);
}
break;
case REV:
revPropMap.put(propName, value);
if ("object_name".equals(propName)) {
itemPropMap.put(propName, value);
}
break;
case ITEMMASTER:
itemMasterPropMap.put(propName, value);
break;
case REVMASTER:
revMasterPropMap.put(propName, value);
break;
default:
System.out.println(">> Prop location error: " + proploc);
break;
}
}
return modified;
}
public void saveTCData(TCComponentBOMLine parentLine, TCComponentItemType itemType) throws Exception {
if (bomline == null) {
if (itemType != null && parentLine != null) {
System.out.println("Create New Row...");
item = itemType.create(itemType.getNewID(), itemType.getNewRev(null), itemType.getName(), "-", "", null);
System.out.println(">> new item: " + item);
rev = item.getLatestItemRevision();
itemMaster = item.getRelatedComponent("IMAN_master_form");
revMaster = rev.getRelatedComponent("IMAN_master_form_rev");
bomline = parentLine.add(item, rev, null, false, "");
}
}
if (bomline == null) {
return;
}
System.out.println("Update: " + bomline);
Map<String, String> revPropMap = new HashMap<>();
Map<String, String> revMasterPropMap = new HashMap<>();
Map<String, String> itemPropMap = new HashMap<>();
Map<String, String> itemMasterPropMap = new HashMap<>();
Map<String, String> bomlinePropMap = new HashMap<>();
if (!loadTCValues(bomlinePropMap, itemPropMap, revPropMap, itemMasterPropMap, revMasterPropMap)) {
return;
}
if (itemPropMap.size() > 0) {
item.setProperties(itemPropMap);
}
if (revPropMap.size() > 0) {
rev.setProperties(revPropMap);
}
if (itemMasterPropMap.size() > 0) {
itemMaster.setProperties(itemMasterPropMap);
}
if (revMasterPropMap.size() > 0) {
revMaster.setProperties(revMasterPropMap);
}
if (bomlinePropMap.size() > 0) {
bomline.setProperties(bomlinePropMap);
}
bomline.refresh();
}
public void removeLine() throws Exception {
if (bomline != null) {
System.out.println(">> Remove: " + bomline);
bomline.cut();
}
}
public void showWebView(boolean showWebView) {
this.showWebView = showWebView;
}
public boolean showWebView() {
return showWebView;
}
}

@ -0,0 +1,113 @@
package cn.net.connor.std.processedit.meopviewfx.bean;
import java.util.HashMap;
import java.util.Map;
import com.teamcenter.rac.cme.time.common.ActivityUtils;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentCfgActivityLine;
import com.teamcenter.rac.kernel.TCComponentMEActivity;
import com.teamcenter.rac.kernel.TCComponentMEActivityType;
import com.teamcenter.rac.kernel.TCComponentMECfgLine;
import cn.net.connor.std.aifrcp.util.KUtil;
public class KTableRowMEActivity extends KTableRow {
public TCComponentCfgActivityLine actline;
private TCComponentMEActivity folder;
public KTableRowMEActivity(TCComponentCfgActivityLine bomline,TCComponentMEActivity folder) {
super(null,null,null,null,null);
this.actline = bomline;
this.folder = folder;
}
@Override
public TCComponent getTCComponent(String proploc) {
if(KUtil.isEmpty(proploc)) {
return folder;
}
proploc = proploc.toUpperCase();
switch (proploc) {
case BOMLINE:
return actline;
case ITEM:
return folder;
default:
System.out.println(">> Prop location error: " + proploc);
break;
}
return null;
}
private boolean loadTCValues(Map<String, String> bomlinePropMap , Map<String, String> itemPropMap) {
boolean modified = false;
for (PropConfig config : stringProps.keySet()) {
if(!config.canEdit) {
continue;
}
String value = stringProps.get(config).getValueSafe();
String propName = config.propName;
String proploc = config.propLoc.toUpperCase();
if(savedValues.containsKey(config)) {
String savedValue = savedValues.get(config);
if(value.equals(savedValue)) {
continue;
}
}
modified = true;
System.out.println(">> "+proploc+"."+propName+" = "+value);
switch(proploc) {
case BOMLINE:
bomlinePropMap.put(propName, value);
break;
case ITEM:
itemPropMap.put(propName, value);
break;
default:
System.out.println(">> Prop location error: " + proploc);
break;
}
}
return modified;
}
public void saveTCData(TCComponentCfgActivityLine parentLine, TCComponentMEActivityType itemType) throws Exception{
if(actline==null) {
if(itemType!=null&&parentLine!=null) {
System.out.println("Create New Activity...");
folder= itemType.createActivity("-", itemType.getName(), "", 0.0D);
System.out.println(">> New Activity: "+folder);
this.actline = (TCComponentCfgActivityLine) ActivityUtils.addActivity(parentLine, folder);
System.out.println(">> New Line: "+this.actline);
}
}
if(actline==null) {
return;
}
System.out.println("Update: "+actline);
Map<String, String> itemPropMap = new HashMap<>();
Map<String, String> bomlinePropMap = new HashMap<>();
if(!loadTCValues(bomlinePropMap, itemPropMap)) {
System.out.println(">> No modified property");
return;
}
if(itemPropMap.size()>0) {
folder.setProperties(itemPropMap);
}
if(bomlinePropMap.size()>0) {
actline.setProperties(bomlinePropMap);
}
actline.refresh();
}
@Override
public void removeLine() throws Exception{
if(actline!=null) {
System.out.println(">> Remove Activity: "+actline);
ActivityUtils.removeActivity((TCComponentMECfgLine)actline);
}
}
}

@ -0,0 +1,61 @@
package cn.net.connor.std.processedit.meopviewfx.bean;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCPropertyDescriptor;
import javafx.scene.control.Control;
public class PropConfig {
public String propName;
public String propDisplayName;
public String propLoc;
public TCComponentListOfValues lov;
public String filterValue;
public TCPropertyDescriptor propDesc;
public int width;
public int maxCharacterInRow;
public boolean canEdit;
private Control control;
private Object savedValue;
public int height;
public PropConfig(String propLoc, TCPropertyDescriptor propDesc, String filterValue, int width, int height, int maxCharacterInRow) {
this.propName = propDesc.getName();
this.propDisplayName = propDesc.getDisplayName();
this.propLoc = propLoc;
this.filterValue = filterValue;
this.lov = propDesc.getLOV();
this.propDesc = propDesc;
this.width = width;
this.height = height;
this.maxCharacterInRow = maxCharacterInRow;
// this.canEdit =
// propDesc.isModifiable()&&!"bl_occ_type".equals(propName)&&!"item_id".equals(propName);
this.canEdit = propDesc.isModifiable() && !"item_id".equals(propName);
System.out.println(propName + " >> " + lov + " >> " + canEdit + " >> " + width + "x" + height);
}
public void setSavedValue(Object savedValue) {
this.savedValue = savedValue;
}
public boolean valueChanged(Object newValue) {
if (savedValue != null) {
return !savedValue.equals(newValue);
}
return newValue != null;
}
public void setControl(Control control) {
this.control = control;
}
public Control getControl() {
return control;
}
@Override
public String toString() {
return propName;
}
}

@ -0,0 +1,46 @@
package cn.net.connor.std.processedit.meopviewfx.bean;
import java.util.ArrayList;
import java.util.List;
import cn.net.connor.std.aifrcp.util.KUtil;
public class TextBean {
private String text;
private String realValue;
public List<TextBean> children = new ArrayList<TextBean>();
public TextBean(String text) {
this.text = text;
}
public void setRealValue(String realValue) {
this.realValue = realValue;
}
public String getRealValue() {
return KUtil.isEmpty(realValue)?text:realValue;
}
public String getDisplayValue() {
return text;
}
@Override
public String toString() {
return getDisplayValue();
}
@Override
public boolean equals(Object obj) {
if(obj==null) {
return false;
}
if(obj instanceof TextBean) {
return text.equals(((TextBean) obj).text);
}
return false;
}
}

@ -0,0 +1,134 @@
package cn.net.connor.std.processedit.meopviewfx.reorder;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import com.teamcenter.rac.util.iTextField;
import cn.net.connor.std.aifrcp.KDialog;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.meopviewfx.bean.KTableRow;
import cn.net.connor.std.processedit.meopviewfx.bean.PropConfig;
import javafx.application.Platform;
import javafx.scene.control.TableView;
@SuppressWarnings("serial")
public class ReorderDialog extends KDialog {
public static final Registry REG = Registry.getRegistry(ReorderDialog.class);
private JButton b_Ok;
private JButton b_Cancel;
private iTextField tf_startNum;
private iTextField tf_stepNum;
private int startNum;
private int stepNum;
private TableView<KTableRow> table;
private Map<PropConfig, Integer> sequenceConfigMap;
public ReorderDialog(TableView<KTableRow> table, Map<PropConfig, Integer> sequenceConfigMap) {
super();
this.table = table;
this.sequenceConfigMap = sequenceConfigMap;
}
@Override
protected void addListeners() {
b_Cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
b_Ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
loadNumbers();
disposeDialog();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ReorderDialog.this, e1);
}
}
});
}
protected void loadNumbers() throws Exception {
String startNumStr = tf_startNum.getText().trim();
String stepNumStr = tf_stepNum.getText().trim();
if (KUtil.isEmpty(startNumStr) || KUtil.isEmpty(stepNumStr)) {
throw new TCException(REG.getString("require.error"));
}
this.startNum = -1;
this.stepNum = -1;
try {
startNum = Integer.parseInt(startNumStr);
} catch (NumberFormatException e) {
e.printStackTrace();
throw new TCException(String.format(REG.getString("format.error1"), startNumStr));
}
try {
stepNum = Integer.parseInt(stepNumStr);
} catch (NumberFormatException e) {
e.printStackTrace();
throw new TCException(String.format(REG.getString("format.error1"), stepNumStr));
}
Platform.runLater(() -> {
KTableRow[] rows = table.getItems().toArray(new KTableRow[] {});
int len = KUtil.getLen(rows);
for (int i = 0; i < len; i++) {
KTableRow row = rows[i];
String seq = String.valueOf(startNum + i * stepNum);
for (PropConfig sequenceConfig : this.sequenceConfigMap.keySet()) {
row.stringProps.get(sequenceConfig).setValue(seq);
}
}
int maxSeq = startNum + stepNum * (len - 1);
for (PropConfig sequenceConfig : this.sequenceConfigMap.keySet()) {
sequenceConfigMap.put(sequenceConfig, maxSeq);
}
});
}
@Override
protected void initUI() {
this.setTitle(REG.getString("dialog.title"));
this.setLayout(new BorderLayout());
this.add(BorderLayout.CENTER, initCenterPanel());
this.add(BorderLayout.SOUTH, initBtnPanel());
}
private Component initBtnPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 25, 8));
panel.add(this.b_Ok = new JButton(REG.getString("ok.btn")));
panel.add(this.b_Cancel = new JButton(REG.getString("cancel.btn")));
return panel;
}
private Component initCenterPanel() {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints s = getGridBagConstraints(0, 0, new Insets(8, 8, 0, 0));
panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 8));
KUtil.newRow(panel, new JLabel(REG.getString("startnum.label")), s, 1);
KUtil.addCol(panel, this.tf_startNum = new iTextField(16, true), s, 1, 0);
KUtil.newRow(panel, new JLabel(REG.getString("stepnum.label")), s, 1);
KUtil.addCol(panel, this.tf_stepNum = new iTextField(16, true), s, 1, 0);
return panel;
}
}

@ -0,0 +1,12 @@
package cn.net.connor.std.processedit.meopviewfx.reorder;
import cn.net.connor.std.aifrcp.KDialogController;
public class ReorderDialogController extends KDialogController{
@Override
public boolean init() throws Exception {
return true;
}
}

@ -0,0 +1,7 @@
dialog.title=\u5BF9\u7ED3\u6784\u91CD\u6392\u5E8F
ok.btn=\u786E\u5B9A
cancel.btn=\u53D6\u6D88
startnum.label=\u5F00\u59CB\u6570\u5B57\uFF1A
stepnum.label=\u589E\u91CF\uFF1A
format.error1=\u201C%s\u201D\u4E0D\u662F\u6709\u6548\u7684\u503C
require.error=\u8BF7\u586B\u5199\u5FC5\u586B\u503C

@ -0,0 +1,323 @@
package cn.net.connor.std.processedit.meopviewfx.ui;
import com.teamcenter.rac.treetable.SwingTextContextActivator;
import com.teamcenter.rac.util.Utilities;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.fx.KFXTextLocator;
import cn.net.connor.std.gdtex.KGenerateGDTHTML;
import cn.net.connor.std.processedit.meopviewfx.bean.KTableRow;
import cn.net.connor.std.processedit.meopviewfx.bean.PropConfig;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.geometry.Bounds;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyCode;
import javafx.scene.text.Text;
import javafx.scene.web.WebView;
/**
* select color:
*
* .table-row-cell .ktext { -fx-fill: black; }
*
* .table-row-cell:selected .ktext { -fx-fill: white; }
*
* .table-cell .ktext { -fx-fill: black; }
*
* .table-cell:selected .ktext { -fx-fill: white; }
*
* @author Administrator
*
* @param <T>
* @param <E>
*/
public class KFXEditableStringAreaHtmlTableCell<T, E> extends TableCell<T, String> {
protected PropConfig config;
protected TextArea textArea;
// private static final Registry REG =
// Registry.getRegistry(KFXEditableStringAreaHtmlTableCell.class);
// private static int FONTSIZE = -1;
// static {
// try {
// // String zoomStr = REG.getString("zoom");
// // if (!KUtil.isEmpty(zoomStr)) {
// // double d = Double.parseDouble(zoomStr);
// // System.out.println("Zoom: " + d);
// // ZOOM = d;
// // }
// // FONTSIZE = REG.getInt("fontsize", -1);
// } catch (Exception e) {
// }
// if (ZOOM < 0) {
// ZOOM = 1;
// }
// }
protected ChangeListener<? super Boolean> changeListener = (obs, ov, nv) -> {
if (!nv) {
commitEdit(textArea.getText());
}
};
private Text text;
private KFXTextLocator textLocator;
public KFXEditableStringAreaHtmlTableCell(PropConfig config, KFXTextLocator textLocator) {
super();
this.config = config;
this.textLocator = textLocator;
// this.localToSceneTransformProperty().addListener((obs, oldIndex, newIndex) ->
// {
// if (getGraphic() == null || oldIndex==newIndex) {
// return;
// }
// if(!(getGraphic() instanceof WebView)) {
// return;
// }
// });
}
@Override
public void startEdit() {
if (editableProperty().get()) {
if (!isEmpty()) {
super.startEdit();
createTextField();
setText(null);
setGraphic(textArea);
textArea.requestFocus();
}
}
}
public void startEdit(int temp) {
if (isEditing()) {
System.out.println("=====>" + temp);
textArea.positionCaret(temp);
}
}
public KTableRow showWebView() {
Object obj = null;
try {
obj = super.getTableRow().getItem();
} catch (Exception e1) {
}
if (obj != null && (obj instanceof KTableRow)) {
WebView webView = ((KTableRow) obj).checkWebView();
if (webView != null) {
webView.setOnScroll(e -> {
Event.fireEvent(KFXEditableStringAreaHtmlTableCell.this, e);
});
// webView.setOnMouseClicked(null);
// if (isEditable()) {
// webView.setOnMouseClicked(e -> {
// System.out.println("?????????/");
// TableView<T> table = getTableView();
// if (table == null) {
// return;
// }
// TableRow<?> row = getTableRow();
// int rowNum = row.getIndex();
// if (rowNum < 0) {
// return;
// }
// TableColumn<T, String> col = getTableColumn();
// if (e.getButton() != MouseButton.PRIMARY || e.getClickCount() != 2) {
// table.getSelectionModel().select(rowNum, col);
// return;
// }
// KTableRow bean = (KTableRow) table.getItems().get(rowNum);
// bean.showWebView(false);
// updateItem(getItem(), isEmpty());
// table.layout();
// table.edit(rowNum, col);
// });
// }
return ((KTableRow) obj);
}
}
return null;
}
@Override
public void cancelEdit() {
super.cancelEdit();
// setText((String) getItem());
// setGraphic(null);
KTableRow webView = showWebView();
if (webView != null) {
setGraphic(webView.getWebView());
} else {
setGraphic(text);
}
}
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
// if (webView == null) {
// createWebView();
// }
if (text == null) {
text = new Text();
text.wrappingWidthProperty().bind(getTableColumn().widthProperty().subtract(20));
text.textProperty().bind(itemProperty());
text.getStyleClass().add("ktext");
text.layoutBoundsProperty().addListener(new ChangeListener<Bounds>() {
@Override
public void changed(ObservableValue<? extends Bounds> observable, Bounds oldValue, Bounds newValue) {
KTableRow webView = showWebView();
if (webView == null) {
return;
}
double height = text.getLayoutBounds().getHeight() + 30; // +20 is for paddings
webView.getWebView().setPrefHeight(height);
}
});
}
KTableRow webView = showWebView();
if (empty) {
setText(null);
setGraphic(null);
} else if (webView != null) {
String newValue = item;
String html = KUtil.isEmpty(newValue) || newValue.startsWith("<html>") ? newValue : KGenerateGDTHTML.generatePage(newValue);
// createWebView(html);
webView.loadContent(html);
setGraphic(webView.getWebView());
double height = text.getLayoutBounds().getHeight() + 30; // +20 is for paddings
// System.out.println("Set Height [" + webView.getTCComponent(KTableRow.BOMLINE)
// + "]: " + height);
webView.getWebView().setPrefHeight(height);
// webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
// Platform.runLater(() -> {
// try {
// // System.out.println("Load Html: " + newValue);
// // System.out.println(">> " + html);
// String html = newValue == null || newValue.startsWith("<html>") ? newValue :
// GenerateGDTHTML.generatePage(newValue);
// webView.getEngine().loadContent(html);
// } catch (Exception e) {
// e.printStackTrace();
// }
// });
// setGraphic(webView);
} else {
if (isEditing()) {
if (textArea != null) {
textArea.setText(getString());
// textArea.selectAll();
}
setText(null);
setGraphic(textArea);
} else {
setGraphic(text);
// setText(getString());
// setGraphic(null);
}
}
}
protected void createTextField() {
if (textArea == null) {
textArea = new TextArea();
textArea.setWrapText(true);
// if (FONTSIZE > 0) {
// try {
// textArea.setFont(Font.font(FONTSIZE));
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
textArea.setOnKeyPressed((ke) -> {
if (ke.getCode().equals(KeyCode.ESCAPE)) {
textArea.focusedProperty().removeListener(changeListener);
cancelEdit();
}
if (ke.getCode().equals(KeyCode.TAB)) {
commitEdit(textArea.getText());
}
});
textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2) {
if (arg2) {
SwingTextContextActivator.instance().activateContext();
} else {
SwingTextContextActivator.instance().deactivateContext();
}
}
});
if (textLocator != null) {
textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (newValue) {
System.out.println("focus get:" + getTableColumn().getText() + ":" + getTableRow().getIndex());
textLocator.updateControl(KFXEditableStringAreaHtmlTableCell.this);
} else {
System.out.println("focus lost: " + getTableColumn().getText() + ":" + getTableRow().getIndex());
}
}
});
textArea.caretPositionProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (textArea.isFocused()) {
System.out.println("caret: " + oldValue + " -> " + newValue);
Utilities.setPrivateField(textLocator, "currentCaret", newValue.intValue());
// textLocator.currentCaret = newValue.intValue();
}
}
});
}
}
textArea.setText(getString());
textArea.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
textArea.setPrefHeight(this.getHeight());
textArea.focusedProperty().addListener(changeListener);
// textArea.setOnAction(evt -> commitEdit(textField.getText()));
}
protected String getString() {
return getItem() == null ? "" : getItem().toString();
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void commitEdit(String item) {
if (isEditing()) {
super.commitEdit(item);
} else {
final TableView table = getTableView();
if (table != null) {
TablePosition position = new TablePosition(getTableView(), getTableRow().getIndex(), getTableColumn());
CellEditEvent editEvent = new CellEditEvent(table, position, TableColumn.editCommitEvent(), item);
Event.fireEvent(getTableColumn(), editEvent);
}
updateItem(item, false);
if (table != null) {
table.edit(-1, null);
}
// super.commitEdit(item); // 20201217 bug fix
}
TableRow<?> row = getTableRow();
if (row != null && row.getIndex() >= 0) {
KTableRow bean = (KTableRow) getTableView().getItems().get(row.getIndex());
bean.showWebView(true);
updateItem(item, isEmpty());
}
}
}

@ -0,0 +1,431 @@
package cn.net.connor.std.processedit.meopviewfx.ui;
import com.teamcenter.rac.stylesheet.gdt.GenerateGDTHTML;
import com.teamcenter.rac.util.Registry;
import com.teamcenter.rac.util.Utilities;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.fx.KFXTextLocator;
import cn.net.connor.std.processedit.meopviewfx.bean.KTableRow;
import cn.net.connor.std.processedit.meopviewfx.bean.PropConfig;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker.State;
import javafx.event.Event;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Region;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
/**
* select color:
*
* .table-row-cell .ktext { -fx-fill: black; }
*
* .table-row-cell:selected .ktext { -fx-fill: white; }
*
* .table-cell .ktext { -fx-fill: black; }
*
* .table-cell:selected .ktext { -fx-fill: white; }
*
* @author Administrator
*
* @param <T>
* @param <E>
*/
public class KFXEditableStringAreaHtmlTableCellBackup20220409<T, E> extends TableCell<T, String> {
protected WebView webView;
protected PropConfig config;
protected TextArea textArea;
private static final Registry REG = Registry.getRegistry(KFXEditableStringAreaHtmlTableCellBackup20220409.class);
private static double ZOOM = 1;
private static int FONTSIZE = -1;
static {
try {
String zoomStr = REG.getString("zoom");
if (!KUtil.isEmpty(zoomStr)) {
double d = Double.parseDouble(zoomStr);
System.out.println("Zoom: " + d);
ZOOM = d;
}
FONTSIZE = REG.getInt("fontsize", -1);
} catch (Exception e) {
}
if (ZOOM < 0) {
ZOOM = 1;
}
}
protected ChangeListener<? super Boolean> changeListener = (obs, ov, nv) -> {
if (!nv) {
commitEdit(textArea.getText());
}
};
private Text text;
private KFXTextLocator textLocator;
public KFXEditableStringAreaHtmlTableCellBackup20220409(PropConfig config, KFXTextLocator textLocator) {
super();
this.config = config;
this.textLocator = textLocator;
}
@Override
public void startEdit() {
if (editableProperty().get()) {
if (!isEmpty()) {
super.startEdit();
createTextField();
setText(null);
setGraphic(textArea);
textArea.requestFocus();
}
}
}
public void startEdit(int temp) {
if (isEditing()) {
System.out.println("=====>" + temp);
textArea.positionCaret(temp);
}
}
public boolean showWebView() {
Object obj = super.getTableRow().getItem();
boolean showWebView = true;
if (obj != null && (obj instanceof KTableRow)) {
showWebView = ((KTableRow) obj).showWebView();
}
return showWebView;
}
@Override
public void cancelEdit() {
super.cancelEdit();
// setText((String) getItem());
// setGraphic(null);
if (showWebView()) {
setGraphic(webView);
} else {
setGraphic(text);
}
}
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
// if (webView == null) {
// createWebView();
// }
if (text == null) {
text = new Text();
text.wrappingWidthProperty().bind(getTableColumn().widthProperty().subtract(20));
text.textProperty().bind(itemProperty());
text.getStyleClass().add("ktext");
}
boolean showWebView = showWebView();
if (empty) {
setText(null);
setGraphic(null);
} else if (showWebView) {
String newValue = item;
String html = KUtil.isEmpty(newValue) || newValue.startsWith("<html>") ? newValue : GenerateGDTHTML.generatePage(newValue);
createWebView(html);
// webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
// Platform.runLater(() -> {
// try {
// // System.out.println("Load Html: " + newValue);
// // System.out.println(">> " + html);
// String html = newValue == null || newValue.startsWith("<html>") ? newValue :
// GenerateGDTHTML.generatePage(newValue);
// webView.getEngine().loadContent(html);
// } catch (Exception e) {
// e.printStackTrace();
// }
// });
// setGraphic(webView);
} else {
if (isEditing()) {
if (textArea != null) {
textArea.setText(getString());
// textArea.selectAll();
}
setText(null);
setGraphic(textArea);
} else {
setGraphic(text);
// setText(getString());
// setGraphic(null);
}
}
}
protected void createTextField() {
if (textArea == null) {
textArea = new TextArea();
textArea.setWrapText(true);
if (FONTSIZE > 0) {
try {
textArea.setFont(Font.font(FONTSIZE));
} catch (Exception e) {
e.printStackTrace();
}
}
textArea.setOnKeyPressed((ke) -> {
if (ke.getCode().equals(KeyCode.ESCAPE)) {
textArea.focusedProperty().removeListener(changeListener);
cancelEdit();
}
if (ke.getCode().equals(KeyCode.TAB)) {
commitEdit(textArea.getText());
}
});
if (textLocator != null) {
textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (newValue) {
System.out.println("focus get:" + getTableColumn().getText() + ":" + getTableRow().getIndex());
textLocator.updateControl(KFXEditableStringAreaHtmlTableCellBackup20220409.this);
} else {
System.out.println("focus lost: " + getTableColumn().getText() + ":" + getTableRow().getIndex());
}
}
});
textArea.caretPositionProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (textArea.isFocused()) {
System.out.println("caret: " + oldValue + " -> " + newValue);
Utilities.setPrivateField(textLocator, "currentCaret", newValue.intValue());
// textLocator.currentCaret = newValue.intValue();
}
}
});
}
}
textArea.setText(getString());
textArea.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
textArea.setPrefHeight(this.getHeight());
textArea.focusedProperty().addListener(changeListener);
// textArea.setOnAction(evt -> commitEdit(textField.getText()));
}
protected synchronized void createWebView(String value) {
if(webView==null) {
webView = new WebView();
webView.setCache(false);
if (ZOOM != 1) {
webView.setZoom(ZOOM);
}
webView.setPrefHeight(120 * ZOOM);
// webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
// @Override
// public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
// if (newValue != State.SUCCEEDED) {
// // System.out.println("Load Failed: "+newValue);
// webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
// KFXEditableStringAreaHtmlTableCell.this.setPrefHeight(Region.USE_COMPUTED_SIZE);
// return;
// }
// try {
// Object res = webView.getEngine().executeScript(
// "var body = document.body, html = document.documentElement; Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );");
// double height = Integer.parseInt(res.toString()) * ZOOM + 20;
// webView.setPrefHeight(height);
// KFXEditableStringAreaHtmlTableCell.this.setPrefHeight(height);
// webView.getEngine().reload();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// }
// });
}
WebEngine engine = webView.getEngine();
//webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
// KFXEditableStringAreaHtmlTableCell.this.setPrefHeight(Region.USE_COMPUTED_SIZE);
setGraphic(webView);
engine.loadContent(value);
engine.reload();
// Platform.runLater(()->{
// engine.loadContent(value);
// });
// engine.documentProperty().addListener((obj, prev, newv) -> {
// Double height = 20.0;
// if(!KUtil.isEmpty(value)) {
// String heightText = engine.executeScript("var body = document.body," + "html = document.documentElement;" + "Math.max( body.scrollHeight , body.offsetHeight, "
// + "html.clientHeight, html.scrollHeight , html.offsetHeight );").toString();
// height = Double.parseDouble(heightText.replace("px", "")) * ZOOM + 10;
// }
// webView.setPrefHeight(height);
// this.setPrefHeight(height);
// });
webView.setOnScroll(e -> {
Event.fireEvent(KFXEditableStringAreaHtmlTableCellBackup20220409.this, e);
});
if (isEditable()) {
webView.setOnMouseClicked(e -> {
TableView<T> table = getTableView();
if (table == null) {
return;
}
TableRow<?> row = getTableRow();
int rowNum = row.getIndex();
if (rowNum < 0) {
return;
}
TableColumn<T, String> col = getTableColumn();
if (e.getButton() != MouseButton.PRIMARY || e.getClickCount() != 2) {
table.getSelectionModel().select(rowNum, col);
return;
}
KTableRow bean = (KTableRow) table.getItems().get(rowNum);
bean.showWebView(false);
updateItem(getItem(), isEmpty());
table.layout();
table.edit(rowNum, col);
});
}
}
protected void createWebViewBackup() {
webView = new WebView();
webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
if (ZOOM != 1) {
webView.setZoom(ZOOM);
}
webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
if (newValue != State.SUCCEEDED) {
return;
}
try {
Object res = webView.getEngine().executeScript(
"var body = document.body, html = document.documentElement; Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );");
// System.out.println("Height: " + res);
int height = Integer.parseInt(res.toString());
// int width = Integer.parseInt(webView.getEngine().executeScript("var body =
// document.body, html = document.documentElement; Math.max( body.scrollWidth,
// body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth
// );").toString());
webView.setPrefHeight(height * ZOOM);
KFXEditableStringAreaHtmlTableCellBackup20220409.this.setPrefHeight(height * ZOOM + 20);
} catch (Exception e) {
e.printStackTrace();
}
}
});
if (isEditable()) {
webView.setOnScroll(e -> {
Event.fireEvent(getTableColumn(), e);
});
webView.setOnMouseClicked(e -> {
TableView<T> table = getTableView();
if (table == null) {
return;
}
TableRow<?> row = getTableRow();
int rowNum = row.getIndex();
if (rowNum < 0) {
return;
}
TableColumn<T, String> col = getTableColumn();
if (e.getButton() != MouseButton.PRIMARY || e.getClickCount() != 2) {
table.getSelectionModel().select(rowNum, col);
return;
}
KTableRow bean = (KTableRow) table.getItems().get(rowNum);
bean.showWebView(false);
updateItem(getItem(), isEmpty());
table.layout();
table.edit(rowNum, col);
});
// webView.setOnMouseClicked(e -> {
// if (e.getButton() != MouseButton.PRIMARY || e.getClickCount() != 2) {
// if (e.getButton() == MouseButton.SECONDARY && e.getClickCount() == 1) {
// Object obj = super.getTableRow().getItem();
// if (obj != null && (obj instanceof KTableRow)) {
// Event.fireEvent(getTableColumn(), e);
// }
// }
// return;
// }
// TableRow<?> row = getTableRow();
// KTableRow bean = (KTableRow) getTableView().getItems().get(row.getIndex());
// String oldValue = bean.stringProps.get(config).getValueSafe();
// System.out.println("Modify [" + row + "]: " + oldValue);
// Display localDisplay = Display.getCurrent();
// if (localDisplay == null) {
// localDisplay = Display.getDefault();
// }
// GdtEditor editor = new GdtEditor(new JTextArea(oldValue));
// editor.setValue(oldValue);
// localDisplay.asyncExec(new Runnable() {
// public void run() {
// Shell localShell = UIUtilities.getCurrentModalShell();
// GdtDialog gdtDialog = new GdtDialog(localShell, null, editor, true) {
// public boolean close() {
// try {
// String newValue = editor.getValue();
// System.out.println("New Value: " + newValue);
// bean.stringProps.get(config).setValue(newValue);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// return super.close();
// }
// };
// editor.setGdtDialog(gdtDialog);
// gdtDialog.open();
// }
// });
// });
}
// webView.prefWidthProperty().bind(getTableColumn().widthProperty().subtract(20));
}
protected String getString() {
return getItem() == null ? "" : getItem().toString();
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void commitEdit(String item) {
if (isEditing()) {
super.commitEdit(item);
} else {
final TableView table = getTableView();
if (table != null) {
TablePosition position = new TablePosition(getTableView(), getTableRow().getIndex(), getTableColumn());
CellEditEvent editEvent = new CellEditEvent(table, position, TableColumn.editCommitEvent(), item);
Event.fireEvent(getTableColumn(), editEvent);
}
updateItem(item, false);
if (table != null) {
table.edit(-1, null);
}
// super.commitEdit(item); // 20201217 bug fix
}
TableRow<?> row = getTableRow();
if (row != null && row.getIndex() >= 0) {
KTableRow bean = (KTableRow) getTableView().getItems().get(row.getIndex());
bean.showWebView(true);
updateItem(item, isEmpty());
}
}
}

@ -0,0 +1,448 @@
package cn.net.connor.std.processedit.meopviewfx.ui;
import com.teamcenter.rac.treetable.SwingTextContextActivator;
import com.teamcenter.rac.util.Utilities;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.fx.KFXTextLocator;
import cn.net.connor.std.gdtex.KGenerateGDTHTML;
import cn.net.connor.std.processedit.meopviewfx.bean.KTableRow;
import cn.net.connor.std.processedit.meopviewfx.bean.PropConfig;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker.State;
import javafx.event.Event;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Region;
import javafx.scene.text.Text;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
/**
* select color:
*
* .table-row-cell .ktext { -fx-fill: black; }
*
* .table-row-cell:selected .ktext { -fx-fill: white; }
*
* .table-cell .ktext { -fx-fill: black; }
*
* .table-cell:selected .ktext { -fx-fill: white; }
*
* @author Administrator
*
* @param <T>
* @param <E>
*/
public class KFXEditableStringAreaHtmlTableCellBackup20220509<T, E> extends TableCell<T, String> {
protected WebView webView;
protected PropConfig config;
protected TextArea textArea;
// private static final Registry REG =
// Registry.getRegistry(KFXEditableStringAreaHtmlTableCell.class);
private static double ZOOM = 1;
private int dy = 1;
// private static int FONTSIZE = -1;
// static {
// try {
// // String zoomStr = REG.getString("zoom");
// // if (!KUtil.isEmpty(zoomStr)) {
// // double d = Double.parseDouble(zoomStr);
// // System.out.println("Zoom: " + d);
// // ZOOM = d;
// // }
// // FONTSIZE = REG.getInt("fontsize", -1);
// } catch (Exception e) {
// }
// if (ZOOM < 0) {
// ZOOM = 1;
// }
// }
protected ChangeListener<? super Boolean> changeListener = (obs, ov, nv) -> {
if (!nv) {
commitEdit(textArea.getText());
}
};
private Text text;
private KFXTextLocator textLocator;
public KFXEditableStringAreaHtmlTableCellBackup20220509(PropConfig config, KFXTextLocator textLocator) {
super();
this.config = config;
this.textLocator = textLocator;
webView = new WebView();
webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
webView.getEngine().documentProperty().addListener((obj, prev, newv) -> {
try {
String heightText = webView.getEngine()
.executeScript(
"var body = document.body, html = document.documentElement;Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );")
.toString();
double height = Double.parseDouble(heightText.replace("px", "")) * ZOOM;
webView.setPrefHeight(height);
} catch (Exception e) {
e.printStackTrace();
}
});
webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
if (newValue != State.SUCCEEDED) {
webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
}
}
});
this.localToSceneTransformProperty().addListener((obs, oldIndex, newIndex) -> {
if (getGraphic() == webView) {
try {
webView.getEngine().reload();
webView.setPrefHeight(webView.getPrefHeight() + dy);
dy = -dy;
} catch (Exception e) {
e.printStackTrace();
}
}
});
webView.setOnScroll(e -> {
Event.fireEvent(KFXEditableStringAreaHtmlTableCellBackup20220509.this, e);
});
if (isEditable()) {
webView.setOnMouseClicked(e -> {
TableView<T> table = getTableView();
if (table == null) {
return;
}
TableRow<?> row = getTableRow();
int rowNum = row.getIndex();
if (rowNum < 0) {
return;
}
TableColumn<T, String> col = getTableColumn();
if (e.getButton() != MouseButton.PRIMARY || e.getClickCount() != 2) {
table.getSelectionModel().select(rowNum, col);
return;
}
KTableRow bean = (KTableRow) table.getItems().get(rowNum);
bean.showWebView(false);
updateItem(getItem(), isEmpty());
table.layout();
table.edit(rowNum, col);
});
}
}
@Override
public void startEdit() {
if (editableProperty().get()) {
if (!isEmpty()) {
super.startEdit();
createTextField();
setText(null);
setGraphic(textArea);
textArea.requestFocus();
}
}
}
public void startEdit(int temp) {
if (isEditing()) {
System.out.println("=====>" + temp);
textArea.positionCaret(temp);
}
}
public boolean showWebView() {
Object obj = super.getTableRow().getItem();
boolean showWebView = true;
if (obj != null && (obj instanceof KTableRow)) {
showWebView = ((KTableRow) obj).showWebView();
}
return showWebView;
}
@Override
public void cancelEdit() {
super.cancelEdit();
// setText((String) getItem());
// setGraphic(null);
if (showWebView()) {
setGraphic(webView);
} else {
setGraphic(text);
}
}
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
// if (webView == null) {
// createWebView();
// }
if (text == null) {
text = new Text();
text.wrappingWidthProperty().bind(getTableColumn().widthProperty().subtract(20));
text.textProperty().bind(itemProperty());
text.getStyleClass().add("ktext");
}
boolean showWebView = showWebView();
if (empty) {
setText(null);
setGraphic(null);
} else if (showWebView) {
String newValue = item;
String html = KUtil.isEmpty(newValue) || newValue.startsWith("<html>") ? newValue : KGenerateGDTHTML.generatePage(newValue);
createWebView(html);
// webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
// Platform.runLater(() -> {
// try {
// // System.out.println("Load Html: " + newValue);
// // System.out.println(">> " + html);
// String html = newValue == null || newValue.startsWith("<html>") ? newValue :
// GenerateGDTHTML.generatePage(newValue);
// webView.getEngine().loadContent(html);
// } catch (Exception e) {
// e.printStackTrace();
// }
// });
// setGraphic(webView);
} else {
if (isEditing()) {
if (textArea != null) {
textArea.setText(getString());
// textArea.selectAll();
}
setText(null);
setGraphic(textArea);
} else {
setGraphic(text);
// setText(getString());
// setGraphic(null);
}
}
}
protected void createTextField() {
if (textArea == null) {
textArea = new TextArea();
textArea.setWrapText(true);
// if (FONTSIZE > 0) {
// try {
// textArea.setFont(Font.font(FONTSIZE));
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
textArea.setOnKeyPressed((ke) -> {
if (ke.getCode().equals(KeyCode.ESCAPE)) {
textArea.focusedProperty().removeListener(changeListener);
cancelEdit();
}
if (ke.getCode().equals(KeyCode.TAB)) {
commitEdit(textArea.getText());
}
});
textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2) {
if(arg2) {
SwingTextContextActivator.instance().activateContext();
}else {
SwingTextContextActivator.instance().deactivateContext();
}
}
});
if (textLocator != null) {
textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (newValue) {
System.out.println("focus get:" + getTableColumn().getText() + ":" + getTableRow().getIndex());
textLocator.updateControl(KFXEditableStringAreaHtmlTableCellBackup20220509.this);
} else {
System.out.println("focus lost: " + getTableColumn().getText() + ":" + getTableRow().getIndex());
}
}
});
textArea.caretPositionProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (textArea.isFocused()) {
System.out.println("caret: " + oldValue + " -> " + newValue);
Utilities.setPrivateField(textLocator, "currentCaret", newValue.intValue());
// textLocator.currentCaret = newValue.intValue();
}
}
});
}
}
textArea.setText(getString());
textArea.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
textArea.setPrefHeight(this.getHeight());
textArea.focusedProperty().addListener(changeListener);
// textArea.setOnAction(evt -> commitEdit(textField.getText()));
}
protected synchronized void createWebView(String value) {
// webWrapper.styleProperty().setValue("-fx-border-color: blue");
setGraphic(webView);
WebEngine engine = webView.getEngine();
// webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
// KFXEditableStringAreaHtmlTableCell.this.setPrefHeight(Region.USE_COMPUTED_SIZE);
engine.loadContent(value);
// Platform.runLater(()->{
// engine.loadContent(value);
// });
// engine.documentProperty().addListener((obj, prev, newv) -> {
// Double height = 20.0;
// if(!KUtil.isEmpty(value)) {
// String heightText = engine.executeScript("var body = document.body," + "html
// = document.documentElement;" + "Math.max( body.scrollHeight ,
// body.offsetHeight, "
// + "html.clientHeight, html.scrollHeight , html.offsetHeight );").toString();
// height = Double.parseDouble(heightText.replace("px", "")) * ZOOM + 10;
// }
// webView.setPrefHeight(height);
// this.setPrefHeight(height);
// });
}
protected void createWebViewBackup() {
WebView webView = new WebView();
webView.setPrefHeight(Region.USE_COMPUTED_SIZE);
if (ZOOM != 1) {
webView.setZoom(ZOOM);
}
webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
if (newValue != State.SUCCEEDED) {
return;
}
try {
Object res = webView.getEngine().executeScript(
"var body = document.body, html = document.documentElement; Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );");
// System.out.println("Height: " + res);
int height = Integer.parseInt(res.toString());
// int width = Integer.parseInt(webView.getEngine().executeScript("var body =
// document.body, html = document.documentElement; Math.max( body.scrollWidth,
// body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth
// );").toString());
webView.setPrefHeight(height * ZOOM);
KFXEditableStringAreaHtmlTableCellBackup20220509.this.setPrefHeight(height * ZOOM + 20);
} catch (Exception e) {
e.printStackTrace();
}
}
});
if (isEditable()) {
webView.setOnScroll(e -> {
Event.fireEvent(getTableColumn(), e);
});
webView.setOnMouseClicked(e -> {
TableView<T> table = getTableView();
if (table == null) {
return;
}
TableRow<?> row = getTableRow();
int rowNum = row.getIndex();
if (rowNum < 0) {
return;
}
TableColumn<T, String> col = getTableColumn();
if (e.getButton() != MouseButton.PRIMARY || e.getClickCount() != 2) {
table.getSelectionModel().select(rowNum, col);
return;
}
KTableRow bean = (KTableRow) table.getItems().get(rowNum);
bean.showWebView(false);
updateItem(getItem(), isEmpty());
table.layout();
table.edit(rowNum, col);
});
// webView.setOnMouseClicked(e -> {
// if (e.getButton() != MouseButton.PRIMARY || e.getClickCount() != 2) {
// if (e.getButton() == MouseButton.SECONDARY && e.getClickCount() == 1) {
// Object obj = super.getTableRow().getItem();
// if (obj != null && (obj instanceof KTableRow)) {
// Event.fireEvent(getTableColumn(), e);
// }
// }
// return;
// }
// TableRow<?> row = getTableRow();
// KTableRow bean = (KTableRow) getTableView().getItems().get(row.getIndex());
// String oldValue = bean.stringProps.get(config).getValueSafe();
// System.out.println("Modify [" + row + "]: " + oldValue);
// Display localDisplay = Display.getCurrent();
// if (localDisplay == null) {
// localDisplay = Display.getDefault();
// }
// GdtEditor editor = new GdtEditor(new JTextArea(oldValue));
// editor.setValue(oldValue);
// localDisplay.asyncExec(new Runnable() {
// public void run() {
// Shell localShell = UIUtilities.getCurrentModalShell();
// GdtDialog gdtDialog = new GdtDialog(localShell, null, editor, true) {
// public boolean close() {
// try {
// String newValue = editor.getValue();
// System.out.println("New Value: " + newValue);
// bean.stringProps.get(config).setValue(newValue);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// return super.close();
// }
// };
// editor.setGdtDialog(gdtDialog);
// gdtDialog.open();
// }
// });
// });
}
// webView.prefWidthProperty().bind(getTableColumn().widthProperty().subtract(20));
}
protected String getString() {
return getItem() == null ? "" : getItem().toString();
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void commitEdit(String item) {
if (isEditing()) {
super.commitEdit(item);
} else {
final TableView table = getTableView();
if (table != null) {
TablePosition position = new TablePosition(getTableView(), getTableRow().getIndex(), getTableColumn());
CellEditEvent editEvent = new CellEditEvent(table, position, TableColumn.editCommitEvent(), item);
Event.fireEvent(getTableColumn(), editEvent);
}
updateItem(item, false);
if (table != null) {
table.edit(-1, null);
}
// super.commitEdit(item); // 20201217 bug fix
}
TableRow<?> row = getTableRow();
if (row != null && row.getIndex() >= 0) {
KTableRow bean = (KTableRow) getTableView().getItems().get(row.getIndex());
bean.showWebView(true);
updateItem(item, isEmpty());
}
}
}

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cn.net.connor.std.processedit.meopviewfx.ui.MEOPPanelController">
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<center>
<SplitPane dividerPositions="1.0" prefHeight="160.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<SplitPane dividerPositions="0.4" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0">
<items>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<center>
<TableView fx:id="table1" editable="true" prefHeight="200.0" prefWidth="200.0" style="-fx-faint-focus-color: transparent; -fx-focus-color: rgba(0,0,0,0.2); -fx-background-insets: 0;" styleClass="dark-table" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane minHeight="0.0">
<top>
<ScrollPane fitToWidth="true" style="-fx-background-insets: 0;">
<content>
<FlowPane fx:id="propPane" hgap="8.0" vgap="5.0" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="5.0" />
</BorderPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</FlowPane>
</content>
<BorderPane.margin>
<Insets bottom="5.0" />
</BorderPane.margin>
</ScrollPane>
</top>
<center>
<TableView fx:id="table2" editable="true" minHeight="0.0" prefHeight="200.0" prefWidth="200.0" style="-fx-faint-focus-color: transparent; -fx-focus-color: rgba(0,0,0,0.2);" visible="false" BorderPane.alignment="CENTER" />
</center>
<right>
<VBox fx:id="buttonBox" minHeight="0.0" spacing="5.0" visible="false" BorderPane.alignment="CENTER">
<padding>
<Insets left="5.0" />
</padding>
<children>
<Button fx:id="b_AddRow" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#addRowButtonClicked" prefHeight="25.0" prefWidth="25.0" />
<Button fx:id="b_DelRow" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#delRowButtonClicked" prefHeight="25.0" prefWidth="25.0" />
<Button fx:id="b_MoveUp" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#moveUpButtonClicked" prefHeight="25.0" prefWidth="25.0" />
<Button fx:id="b_MoveDown" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#moveDownButtonClicked" prefHeight="25.0" prefWidth="25.0" />
<!--Button fx:id="b_Symbol" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#symbolButtonClicked" prefHeight="25.0" prefWidth="25.0" />
<Button fx:id="b_Reorder" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#reorderButtonClicked" prefHeight="25.0" prefWidth="25.0" />
<Button fx:id="b_Search" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#searchButtonClicked" prefHeight="25.0" prefWidth="25.0" /-->
</children>
</VBox>
</right>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</BorderPane>
</items>
</SplitPane>
<TabPane fx:id="textTab" prefHeight="200.0" prefWidth="200.0" side="RIGHT" tabClosingPolicy="UNAVAILABLE" />
</items>
</SplitPane>
</center>
<bottom>
<GridPane hgap="20.0" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" minWidth="10.0" />
<ColumnConstraints hgrow="NEVER" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button mnemonicParsing="false" onAction="#reloadDataButtonClick" text=" 更新 " />
<Button mnemonicParsing="false" onAction="#saveButtonClick" text=" 保存 " GridPane.columnIndex="1" />
</children>
<padding>
<Insets bottom="5.0" left="10.0" right="5.0" top="5.0" />
</padding>
</GridPane>
</bottom>
</BorderPane>
<AnchorPane fx:id="cover" prefHeight="200.0" prefWidth="200.0" visible="false">
<children>
<ProgressIndicator prefHeight="30.0" prefWidth="30.0" AnchorPane.bottomAnchor="15.0" AnchorPane.leftAnchor="15.0" />
</children>
</AnchorPane>
</children>
</StackPane>

@ -0,0 +1,46 @@
package cn.net.connor.std.processedit.meopviewfx.ui;
import java.awt.Window;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.pse.common.BOMLineNode;
import com.teamcenter.rac.util.MessageBox;
import cn.net.connor.std.fx.KFXPanel;
public class MEOPPanel extends KFXPanel{
private MEOPPanelController controller;
public MEOPPanel(Window dialog) {
super(dialog, MEOPPanel.class, "style.css");
this.controller = (MEOPPanelController)aifController;
initData();
}
public void refreshUI(TCComponentBOMLine targetLine) throws Exception{
this.controller.refreshUI(targetLine);
}
public synchronized void updateSelection(Object targetObj) {
System.out.println("Update: "+targetObj);
if (targetObj != null && targetObj instanceof AIFComponentContext) {
targetObj = ((AIFComponentContext) targetObj).getComponent();
}
if (targetObj != null && targetObj instanceof BOMLineNode) {
targetObj = ((BOMLineNode) targetObj).getComponent();
}
if (targetObj == null || !(targetObj instanceof TCComponentBOMLine)) {
} else {
TCComponentBOMLine targetLine = (TCComponentBOMLine) targetObj;
try {
refreshUI(targetLine);
} catch (Exception e) {
MessageBox.post(getParentDialog(), e);
e.printStackTrace();
}
}
}
}

@ -0,0 +1,473 @@
package cn.net.connor.std.processedit.meopviewfx.ui;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.internal.e4.compatibility.CompatibilityView;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.cme.application.MFGLegacyApplication;
import com.teamcenter.rac.cme.framework.treetable.CMEBOMTreeTable;
import com.teamcenter.rac.cme.framework.views.primary.BOMPrimaryView;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PlatformHelper;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.fx.KFXPanel;
import cn.net.connor.std.fx.KFXPanelController;
import cn.net.connor.std.processedit.meopviewfx.bean.KTableRow;
import cn.net.connor.std.processedit.meopviewfx.bean.TextBean;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
@SuppressWarnings("restriction")
public class MEOPPanelController extends KFXPanelController {
public static final String PREF_BOM_TABLE = "Connor_AVIC_GXBZ_Bomline";
public static final String PREF_PREFIX_BOM_TABLE_WITH_TYPE = "Connor_AVIC_GXBZ_";
public static final String PREF_PREFIX_PROP_FLOW_WITH_TYPE = "Connor_AVIC_GXBZ_Property_";
public static final String PREF_PREFIX_SEARCH_BY_SQL = "Connor_AVIC_GXBZ_SelectSql_";
@FXML
private TableView<KTableRow> table1;
@FXML
private TableView<KTableRow> table2;
@FXML
private FlowPane propPane;
@FXML
private AnchorPane cover;
@FXML
private Button b_AddRow;
@FXML
private Button b_DelRow;
@FXML
private Button b_MoveUp;
@FXML
private Button b_MoveDown;
@FXML
private Button b_Reorder;
@FXML
private VBox buttonBox;
@FXML
private TabPane textTab;
@FXML
private Button b_Symbol;
@FXML
private Button b_Search;
private boolean busy = false;
private TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession();
private TableLoader table1Loader = new TableLoader(session);
private TableLoader table2Loader;
private PropFlowLoader propLoader = new PropFlowLoader(session);
private static final Registry REG = Registry.getRegistry(MEOPPanelController.class);
// private MEOPPanel panel;
public Image folder = new Image(MEOPPanelController.class.getResourceAsStream("/icons/folder_24.png"), 18, 18, true, false);
public Image text = new Image(MEOPPanelController.class.getResourceAsStream("/icons/text.png"), 18, 18, true, false);
private TCComponentBOMLine targetLine;
private CMEBOMTreeTable bomTreeTable;
private MFGLegacyApplication bomApp;
private BOMPrimaryView bomView;
@Override
public void initData(KFXPanel panel) throws Exception {
// this.panel = (MEOPPanel) panel;
// table1.getSelectionModel().setCellSelectionEnabled(true);
// table2.getSelectionModel().setCellSelectionEnabled(true);
b_AddRow.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/icons/add_24px.png"), 19, 19, true, false)));
b_DelRow.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/icons/delete_24px.png"), 19, 19, true, false)));
b_MoveUp.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/icons/up_24px.png"), 19, 19, true, false)));
b_MoveDown.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/icons/down_24px.png"), 19, 19, true, false)));
if(b_Reorder!=null)
b_Reorder.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/icons/sort-line-2.png"), 19, 19, true, false)));
if(b_Symbol!=null)
b_Symbol.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/icons/T.png"), 19, 19, true, false)));
if(b_Search!=null)
b_Search.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/icons/search-2.png"), 19, 19, true, false)));
table1.setVisible(table1Loader.load(table1, PREF_BOM_TABLE));
if (table1.isVisible()) {
String colName = REG.getString("index.COL");
TableColumn<KTableRow, String> c = new TableColumn<KTableRow, String>(colName);
c.setCellFactory(col -> new TableCell<KTableRow, String>() {
@Override
public void updateIndex(int index) {
super.updateIndex(index);
if (isEmpty() || index < 0) {
setText(null);
} else {
setText(Integer.toString(index + 1));
}
}
});
Platform.runLater(() -> {
c.setEditable(false);
c.setSortable(false);
c.setPrefWidth(70);
table1.getColumns().add(0, c);
});
}
textTab.getTabs().clear();
// load special text
Map<String, TextBean> textMap = new TextTreeLoader(session).loadText();
for (String sheetName : textMap.keySet()) {
TextBean bean = textMap.get(sheetName);
Tab tab = new Tab(sheetName);
textTab.getTabs().add(tab);
TreeView<TextBean> tree = new TreeView<TextBean>();
TreeItem<TextBean> rootNode = new TreeItem<TextBean>(bean, new ImageView(folder));
tree.setRoot(rootNode);
tree.setShowRoot(false);
rootNode.setExpanded(true);
loadTree(rootNode, bean);
tab.setContent(tree);
tree.setOnMouseClicked(e -> {
if (e.getButton() != MouseButton.PRIMARY || e.getClickCount() != 2) {
return;
}
TreeItem<TextBean> treeItem = tree.getSelectionModel().getSelectedItem();
if (treeItem.getChildren().size() > 0) {
return;
}
String text = treeItem.getValue().getRealValue();
System.out.println("Insert: " + text);
long time = Math.max(table1Loader.focuseTime, table2Loader.focuseTime);
time = Math.max(time, propLoader.focuseTime);
if (propLoader.focuseTime == time) {
propLoader.insertText(text);
}
if (table1Loader.focuseTime == time) {
table1Loader.insertText(text);
}
if (table2Loader.focuseTime == time) {
String parentText = treeItem.getParent() == null ? "" : treeItem.getParent().getValue().getRealValue();
table2Loader.insertText(text, parentText);
}
});
}
table2.getSelectionModel().selectedItemProperty().addListener(e -> {
try {
int index = table2.getSelectionModel().getSelectedIndex();
System.out.println("Select Table2: " + index);
KTableRow row = table2.getSelectionModel().getSelectedItem();
TCComponentBOMLine bomLine = row == null ? null : row.getBomLine();
System.out.println(">> bomline: " + bomLine);
if (bomLine == null) {
bomLine = targetLine;
}
if (!bomLine.equals(table1Loader.targetLine)) {
table1Loader.loadTCData(bomLine, true);
}
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(e1);
}
});
}
private void initBomTreeTableInfo() throws Exception {
this.bomTreeTable = null;
this.bomApp = null;
this.bomView = null;
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
TCComponentBOMWindow bomWindow = targetLine.window();
System.out.println(">> BomWindow: " + bomWindow);
System.out.println(">> " + app.getClass());
if (app instanceof MFGLegacyApplication) {
this.bomApp = (MFGLegacyApplication) app;
List<Object> viewParts = PlatformHelper.getAllViewParts();
IWorkbenchWindow var1 = AIFUtility.getActiveDesktop().getDesktopWindow();
IWorkbenchPage page = var1.getActivePage();
for (Object viewPart : viewParts) {
if (viewPart == null || !(viewPart instanceof CompatibilityView)) {
continue;
}
IViewPart view = ((CompatibilityView) viewPart).getView();
if (view == null || !(view instanceof BOMPrimaryView)) {
continue;
}
BOMPrimaryView bomView = (BOMPrimaryView) view;
CMEBOMTreeTable treeTable = bomView.getBOMTreeTable();
if (treeTable == null) {
continue;
}
boolean visible = page.isPartVisible(view);
System.out.println(">> BOMPrimaryView: [" + visible + "]" + bomView);
if (!visible) {
continue;
}
if (treeTable.getBOMWindow() == bomWindow) {
System.out.println(">>>>> find window");
TCComponentBOMLine[] bomlines = treeTable.getSelectedBOMLines();
System.out.println(">> Selected lines: " + Arrays.toString(bomlines));
boolean findLine = false;
int bomLineCnt = KUtil.getLen(bomlines);
for (int i = 0; i < bomLineCnt; i++) {
if (targetLine == bomlines[i]) {
findLine = true;
break;
}
}
if (findLine) {
System.out.println(">>>>> Find targetline");
this.bomTreeTable = treeTable;
this.bomView = bomView;
// Display.getDefault().syncExec(()->{
// view.setFocus();
// });
// treeTable.setRefreshingBOM();
// ((MFGLegacyApplication) app).refreshBOM();
// treeTable.refreshBOMLine(targetLine, true);
return;
}
}
}
}
}
public void reloadDataButtonClick() {
new Thread(() -> {
session.setStatus("Reloading...");
setProgressVisible(true);
try {
reloadData(null);
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(e);
}
setProgressVisible(false);
System.out.println("Reload Complete");
}).start();
}
public void saveButtonClick() {
if (this.bomView != null) {
Display.getDefault().syncExec(() -> {
this.bomView.setFocus();
});
}
new Thread(() -> {
session.setStatus("Saving...");
setProgressVisible(true);
if (this.bomTreeTable != null) {
try {
this.bomTreeTable.setRefreshingBOM();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
saveData();
reloadData(null);
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(e);
}
if (this.bomApp != null) {
try {
this.bomApp.refreshBOM();
} catch (Exception e) {
e.printStackTrace();
}
}
setProgressVisible(false);
System.out.println("Save Complete");
}).start();
}
public synchronized void reloadData(TCComponentBOMLine targetLine) throws Exception {
if (targetLine == null) {
targetLine = this.targetLine;
// AIFComponentContext cc =
// AIFUtility.getCurrentApplication().getTargetContext();
// System.out.println("Select: "+cc);
// if(cc!=null&&cc.getComponent()!=null&&(cc.getComponent() instanceof
// TCComponentBOMLine)){
// targetLine = (TCComponentBOMLine) cc.getComponent();
// }
}
if (targetLine == null) {
return;
}
this.targetLine = targetLine;
System.out.println("Load Line: " + targetLine);
initBomTreeTableInfo();
TCComponentItemType itemType = targetLine == null ? null : targetLine.getItem().getTypeComponent();
String prefName = itemType == null ? null : PREF_PREFIX_BOM_TABLE_WITH_TYPE + itemType.getTypeName();
if (TableLoaderMEActivity.isActivityConfig(session, prefName)) {
table2Loader = new TableLoaderMEActivity(session);
} else {
table2Loader = new TableLoader(session);
}
boolean table2Visible = table2Loader.load(table2, prefName);
String prefName2 = itemType == null ? null : PREF_PREFIX_PROP_FLOW_WITH_TYPE + itemType.getTypeName();
boolean propVisible = propLoader.load(propPane, prefName2, itemType);
if (!Platform.isFxApplicationThread()) {
Platform.runLater(() -> {
table2.setVisible(table2Visible);
buttonBox.setVisible(table2Visible);
propPane.setVisible(propVisible);
try {
propLoader.loadTCData(this.targetLine);
table1Loader.loadTCData(this.targetLine, true);
table2Loader.loadTCData(this.targetLine, false);
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(e);
}
});
} else {
table2.setVisible(table2Visible);
buttonBox.setVisible(table2Visible);
propPane.setVisible(propVisible);
propLoader.loadTCData(targetLine);
table1Loader.loadTCData(targetLine, true);
table2Loader.loadTCData(targetLine, false);
}
}
public void saveData() throws Exception {
if (targetLine == null) {
return;
}
propLoader.saveTCData(targetLine);
table1Loader.saveTCData();
table2Loader.saveTCData();
targetLine.refresh();
// session.refresh();
// AIFUtility.getCurrentApplication().refresh();
}
private void loadTree(TreeItem<TextBean> rootNode, TextBean bean) {
int childCnt = bean.children.size();
for (int i = 0; i < childCnt; i++) {
TextBean childBean = bean.children.get(i);
boolean isFolder = childBean.children.size() > 0;
TreeItem<TextBean> cNode = isFolder ? new TreeItem<TextBean>(childBean, new ImageView(folder)) : new TreeItem<TextBean>(childBean, new ImageView(text));
rootNode.getChildren().add(cNode);
if (isFolder) {
loadTree(cNode, childBean);
}
}
}
public void refreshUI(TCComponentBOMLine targetLine) throws Exception {
if (busy) {
System.out.println("Task Running. Skip load: " + targetLine);
return;
}
setProgressVisible(true);
try {
reloadData(targetLine);
} finally {
setProgressVisible(false);
}
// this.targetLine = targetLine;
// TCComponentItemType itemType = targetLine == null ? null :
// targetLine.getItem().getTypeComponent();
// String prefName = itemType == null ? null : PREF_PREFIX_BOM_TABLE_WITH_TYPE +
// itemType.getTypeName();
// boolean table2Visible = table2Loader.load(table2, prefName);
// String prefName2 = itemType == null ? null : PREF_PREFIX_PROP_FLOW_WITH_TYPE
// + itemType.getTypeName();
// boolean propVisible = propLoader.load(propPane, prefName2, itemType);
// Platform.runLater(() -> {
// table2.setVisible(table2Visible);
// buttonBox.setVisible(table2Visible);
// propPane.setVisible(propVisible);
// });
// reloadData();
}
public void addRowButtonClicked() {
table2Loader.addRow();
}
public void delRowButtonClicked() {
table2Loader.removeRow();
}
public void moveUpButtonClicked() {
table2Loader.moveUp();
}
public void moveDownButtonClicked() {
table2Loader.moveDown();
}
public void reorderButtonClicked() {
try {
table2Loader.reorder();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(e);
}
}
public void symbolButtonClicked() {
try {
table2Loader.editSymbol();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(e);
}
}
public void searchButtonClicked() {
try {
TCComponentItemType itemType = targetLine == null ? null : targetLine.getItem().getTypeComponent();
String prefName = itemType == null ? null : PREF_PREFIX_SEARCH_BY_SQL + itemType.getTypeName();
table2Loader.doSearch(prefName);
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(e);
}
}
public void setProgressVisible(boolean visible) {
this.busy = visible;
if (cover != null) {
if (Platform.isFxApplicationThread()) {
cover.setVisible(visible);
} else {
Platform.runLater(() -> {
cover.setVisible(visible);
});
}
try {
Thread.sleep(10);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,374 @@
package cn.net.connor.std.processedit.meopviewfx.ui;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMLineType;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemRevisionType;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCComponentType;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCPropertyDescriptor;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.treetable.SwingTextContextActivator;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.fx.KFXTextLocator;
import cn.net.connor.std.fx.KLOVComboBox;
import cn.net.connor.std.processedit.meopviewfx.bean.KTableRow;
import cn.net.connor.std.processedit.meopviewfx.bean.PropConfig;
import cn.net.connor.std.processedit.util.ProcessUtil;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Control;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputControl;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Region;
@SuppressWarnings("unchecked")
public class PropFlowLoader extends KFXTextLocator {
protected List<PropConfig> propConfigs = new ArrayList<PropConfig>();
private TCSession session;
private static final Registry REG = Registry.getRegistry(PropFlowLoader.class);
public PropFlowLoader(TCSession session) {
this.session = session;
}
public boolean load(FlowPane flowPane, String prefName, TCComponentItemType itemType) throws Exception {
clearLocatorData();
Platform.runLater(() -> {
flowPane.getChildren().clear();
});
propConfigs.clear();
if (KUtil.isEmpty(prefName) || itemType == null) {
return false;
}
System.out.println("Load FlowPane from pref: " + prefName);
String[] prefVals = KUtil.getPrefVals(session, prefName);
int len = KUtil.getLen(prefVals);
if (len <= 1) {
return false;
}
System.out.println(">> Item Type: " + itemType.getDisplayTypeName());
TCComponentType revMasterType = null;
TCComponentBOMLineType bomlineType = null;
TCComponentItemRevisionType revType = itemType.getItemRevisionType();
revMasterType = session.getTypeComponent(revType.getTypeName() + "Master");
if (revMasterType == null) {
revMasterType = session.getTypeComponent(revType.getTypeName() + " Master");
}
if (revMasterType == null) {
throw new Exception(String.format(REG.getString("typenotfound.ERROR1"), revType.getTypeName() + "Master"));
}
bomlineType = (TCComponentBOMLineType) session.getTypeComponent("BOMLine");
if (bomlineType == null) {
throw new Exception(String.format(REG.getString("typenotfound.ERROR1"), "BOMLine"));
}
for (int i = 0; i < len; i++) {
String propName = prefVals[i];
System.out.println("Load Config: " + propName);
if (KUtil.isEmpty(propName)) {
continue;
}
String propLoc = KTableRow.REVMASTER;
String filterValue = null;
int width = 0;
int height = 0;
while (!KUtil.isEmpty(propName) && Character.isDigit(propName.charAt(0))) {
width = width * 10 + (propName.charAt(0) - '0');
propName = propName.substring(1);
}
if (propName.startsWith("x")) {
propName = propName.substring(1);
while (!KUtil.isEmpty(propName) && Character.isDigit(propName.charAt(0))) {
height = height * 10 + (propName.charAt(0) - '0');
propName = propName.substring(1);
}
}
// while (!KUtil.isEmpty(propName) && Character.isDigit(propName.charAt(0))) {
// width = width * 10 + (propName.charAt(0) - '0');
// propName = propName.substring(1);
// }
// int ind = propName.indexOf('.');
// if (ind > 0) {
// propLoc = propName.substring(0, ind);
// propName = propName.substring(ind + 1);
// }
int ind = propName.indexOf('=');
if (ind > 0) {
filterValue = propName.substring(ind + 1);
propName = propName.substring(0, ind);
}
TCPropertyDescriptor propDesc;
if (propName.startsWith("**")) {
propLoc = KTableRow.BOMLINE;
propName = propName.substring(2);
propDesc = bomlineType.getPropDesc(propName);
if (propDesc == null) {
throw new Exception(String.format(REG.getString("propnotdefinedintype.ERROR2"), propName, bomlineType.getDisplayTypeName()));
}
} else if (propName.startsWith("*")) {
propLoc = KTableRow.REV;
propName = propName.substring(1);
propDesc = revType.getPropDesc(propName);
if (propDesc == null) {
throw new Exception(String.format(REG.getString("propnotdefinedintype.ERROR2"), propName, revType.getDisplayTypeName()));
}
} else {
propDesc = revMasterType.getPropDesc(propName);
if (propDesc == null) {
throw new Exception(String.format(REG.getString("propnotdefinedintype.ERROR2"), propName, revMasterType.getDisplayTypeName()));
}
}
this.propConfigs.add(new PropConfig(propLoc, propDesc, filterValue, width, height, 0));
}
System.out.println("Load complete");
int size = this.propConfigs.size();
if (size == 0) {
return false;
}
for (int i = 0; i < size; i++) {
PropConfig config = propConfigs.get(i);
addPropPane(flowPane, config);
}
return true;
}
public void loadTCData(TCComponentBOMLine targetLine) throws Exception {
if (targetLine == null) {
return;
}
TCComponent revMaster = targetLine == null ? null : targetLine.getItemRevision().getRelatedComponent("IMAN_master_form_rev");
TCComponent rev = targetLine == null ? null : targetLine.getItemRevision();
int size = this.propConfigs.size();
if (size == 0) {
return;
}
for (int j = 0; j < size; j++) {
PropConfig config = propConfigs.get(j);
Control control = config.getControl();
if (control == null) {
continue;
}
TCComponent comp = KTableRow.REV.equals(config.propLoc) ? rev : KTableRow.BOMLINE.equals(config.propLoc) ? targetLine : revMaster;
if (control instanceof TextInputControl) {
TCPropertyDescriptor propDesc = comp.getTypeComponent().getPropDesc(config.propName);
String text;
if (propDesc.getType() == TCPropertyDescriptor.SERVER_PROP_double) {
double num = comp.getDoubleProperty(config.propName);
text = KUtil.isEmpty(comp.getProperty(config.propName)) ? "" : (ProcessUtil.DF.format(num));
} else {
text = comp.getStringProperty(config.propName);
}
((TextInputControl) control).setText(text);
config.setSavedValue(text);
} else if (control instanceof DatePicker) {
Date date = comp.getDateProperty(config.propName);
((DatePicker) control).setValue(KUtil.dateToLocalDate(date));
config.setSavedValue(date);
} else if (control instanceof KLOVComboBox) {
String text = comp.getStringProperty(config.propName);
((KLOVComboBox) control).setValue(text);
config.setSavedValue(text);
} else if (control instanceof ComboBox) {
String text = comp.getStringProperty(config.propName);
((ComboBox<String>) control).setValue(text);
config.setSavedValue(text);
}
}
}
public void saveTCData(TCComponentBOMLine targetLine) throws Exception {
if (targetLine == null) {
return;
}
System.out.println("Update Property: " + targetLine);
TCComponentItemRevision rev = targetLine == null ? null : targetLine.getItemRevision();
TCComponent revMaster = targetLine == null ? null : targetLine.getItemRevision().getRelatedComponent("IMAN_master_form_rev");
int size = this.propConfigs.size();
if (size == 0) {
return;
}
for (int j = 0; j < size; j++) {
PropConfig config = propConfigs.get(j);
Control control = config.getControl();
if (control == null || !config.canEdit) {
continue;
}
TCComponent comp = KTableRow.REV.equals(config.propLoc) ? rev : KTableRow.BOMLINE.equals(config.propLoc) ? targetLine : revMaster;
String propName = config.propName;
if (control instanceof TextInputControl) {
String value = ((TextInputControl) control).getText();
if (config.valueChanged(value)) {
System.out.println(">> " + propName + " = " + value);
comp.setProperty(propName, value);
}
} else if (control instanceof DatePicker) {
Date value = KUtil.localDateToDate(((DatePicker) control).getValue());
if (config.valueChanged(value)) {
System.out.println(">> " + propName + " = " + value);
comp.setDateProperty(propName, value);
}
} else if (control instanceof KLOVComboBox) {
String value = ((KLOVComboBox) control).getSelectionModel().getSelectedItem();
if (config.valueChanged(value)) {
System.out.println(">> " + propName + " = " + value);
comp.setStringProperty(propName, value);
}
} else if (control instanceof ComboBox) {
String value = ((ComboBox<String>) control).getSelectionModel().getSelectedItem();
if (config.valueChanged(value)) {
System.out.println(">> " + propName + " = " + value);
comp.setStringProperty(propName, value);
}
}
}
rev.refresh();
revMaster.refresh();
targetLine.refresh();
}
private void addPropPane(FlowPane flowPane, PropConfig config) throws Exception {
String title = config.propDisplayName;
TCComponentListOfValues lov = config.lov;
// HBox propPane = new HBox();
BorderPane propPane = new BorderPane();
// propPane.setSpacing(5);
// propPane.setAlignment(Pos.CENTER_LEFT);
propPane.setPrefWidth(280);
Label label = new Label(title + " ");
label.setAlignment(Pos.CENTER_RIGHT);
label.setMinWidth(80);
Platform.runLater(() -> {
// propPane.getChildren().add(label);
BorderPane.setAlignment(label, Pos.CENTER_LEFT);
propPane.setLeft(label);
flowPane.getChildren().add(propPane);
});
if (config.propDesc.isType(TCProperty.PROP_date)) {
DatePicker dp = new DatePicker();
config.setControl(dp);
dp.setDisable(!config.canEdit);
} else if (lov == null) {
if (!KUtil.isEmpty(config.filterValue)) {
String[] split = config.filterValue.split(";");
ComboBox<String> cb = new ComboBox<String>();
cb.getItems().add("");
for (String string : split) {
cb.getItems().add(string);
}
cb.setMaxWidth(300);
config.setControl(cb);
cb.setDisable(!config.canEdit);
} else {
// Text
TextInputControl tf;
if (config.width > 0 && config.height > 0) {
tf = new TextArea();
tf.setPrefWidth(config.width);
tf.setPrefHeight(config.height);
((TextArea)tf).setWrapText(true);
propPane.setPrefWidth(Region.USE_COMPUTED_SIZE);
} else {
tf = new TextField();
}
config.setControl(tf);
tf.setEditable(config.canEdit);
tf.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (newValue) {
System.out.println("focus get: " + title);
updateControl(tf);
} else {
System.out.println("focus lost: " + title);
}
}
});
tf.caretPositionProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (tf.isFocused()) {
System.out.println("caret: " + oldValue + " -> " + newValue);
currentCaret = newValue.intValue();
}
}
});
}
} else {
KLOVComboBox cb = new KLOVComboBox(lov);
cb.setMaxWidth(300);
config.setControl(cb);
cb.setDisable(!config.canEdit);
}
if (config.getControl() != null) {
config.getControl().focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2) {
if (arg2) {
SwingTextContextActivator.instance().activateContext();
} else {
SwingTextContextActivator.instance().deactivateContext();
}
}
});
}
Platform.runLater(() -> {
propPane.setCenter(config.getControl());
});
}
@Override
public void insertText(String text) {
if (KUtil.isEmpty(text)) {
return;
}
Control currentControl = getCurrentControl();
if (currentControl == null) {
return;
}
if (currentControl instanceof TextField) {
((TextField) currentControl).insertText(currentCaret, text);
currentCaret += text.length();
int temp = currentCaret;
currentControl.requestFocus();
((TextField) currentControl).positionCaret(temp);
} else if (currentControl instanceof TextArea) {
TextArea textArea = (TextArea) currentControl;
String oldValue = textArea.getText();
String newValue;
System.out.println(currentCaret + ":" + oldValue);
int temp = currentCaret;
if (oldValue == null) {
newValue = text;
} else if (currentCaret >= 0 && currentCaret <= oldValue.length()) {
newValue = oldValue.substring(0, currentCaret) + text + oldValue.substring(currentCaret);
currentCaret += text.length();
temp = currentCaret;
} else {
newValue = oldValue + text;
}
System.out.println("-> " + newValue);
textArea.setText(newValue);
currentControl.requestFocus();
textArea.positionCaret(temp);
}
}
}

@ -0,0 +1,332 @@
package cn.net.connor.std.processedit.meopviewfx.ui;
import java.util.Arrays;
import com.teamcenter.rac.cme.time.common.ActivityUtils;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentCfgActivityLine;
import com.teamcenter.rac.kernel.TCComponentCfgAttachmentLineType;
import com.teamcenter.rac.kernel.TCComponentMEActivity;
import com.teamcenter.rac.kernel.TCComponentMEActivityType;
import com.teamcenter.rac.kernel.TCComponentType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCPropertyDescriptor;
import com.teamcenter.rac.kernel.TCSession;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.meopviewfx.bean.KTableRow;
import cn.net.connor.std.processedit.meopviewfx.bean.KTableRowMEActivity;
import cn.net.connor.std.processedit.meopviewfx.bean.PropConfig;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.TableView;
public class TableLoaderMEActivity extends TableLoader {
protected TCComponentMEActivityType folderType;
public TableLoaderMEActivity(TCSession session) {
super(session);
}
public static boolean isActivityConfig(TCSession session, String prefName) {
if (KUtil.isEmpty(prefName)) {
return false;
}
try {
String[] prefVals = KUtil.getPrefVals(session, prefName);
int len = KUtil.getLen(prefVals);
if (len <= 1) {
return false;
}
String itemTypeName = prefVals[0];
TCComponentType typeComp = session.getTypeComponent(itemTypeName);
if (typeComp == null) {
return false;
}
if (typeComp instanceof TCComponentMEActivityType) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public boolean load(TableView<KTableRow> table, String prefName) throws Exception {
this.table = table;
clearLocatorData();
Platform.runLater(() -> {
table.getColumns().clear();
table.getItems().clear();
});
propConfigs.clear();
sequenceConfigMap.clear();
sequenceConfigMapReorder.clear();
if (KUtil.isEmpty(prefName)) {
return false;
}
System.out.println("Load table from pref: " + prefName);
String[] prefVals = KUtil.getPrefVals(session, prefName);
int len = KUtil.getLen(prefVals);
if (len <= 1) {
return false;
}
String itemTypeName = prefVals[0];
System.out.println(">> Item Type: " + itemTypeName);
TCComponentCfgAttachmentLineType cfglineType = null;
folderType = null;
cfglineType = (TCComponentCfgAttachmentLineType) session.getTypeComponent("CfgActivityLine");
if (cfglineType == null) {
throw new Exception("Type not found: CfgAttachmentLine");
}
folderType = (TCComponentMEActivityType) session.getTypeComponent(itemTypeName);
if (folderType == null) {
throw new Exception(String.format(REG.getString("typenotfound.ERROR1"), itemTypeName));
}
for (int i = 1; i < len; i++) {
String propName = prefVals[i];
System.out.println("Load Config: " + propName);
if (KUtil.isEmpty(propName)) {
continue;
}
if (propName.toLowerCase().startsWith("sequence_step=")) {
String numStr = propName.substring("sequence_step=".length()).trim();
if (!KUtil.isEmpty(numStr)) {
try {
this.defaultSequenceStep = Integer.parseInt(numStr);
System.out.println("Default Sequence Step: " + this.defaultSequenceStep);
} catch (Exception e) {
e.printStackTrace();
}
}
continue;
}
String propLoc = null;
String filterValue = null;
int width = 0;
int height = 0;
int maxCharacter = 0;
if ('-' == propName.charAt(0)) {
width = -1;
propName = propName.substring(1);
} else {
while (!KUtil.isEmpty(propName) && Character.isDigit(propName.charAt(0))) {
width = width * 10 + (propName.charAt(0) - '0');
propName = propName.substring(1);
}
if (propName.startsWith("x")) {
propName = propName.substring(1);
while (!KUtil.isEmpty(propName) && Character.isDigit(propName.charAt(0))) {
height = height * 10 + (propName.charAt(0) - '0');
propName = propName.substring(1);
}
}
if (propName.startsWith("$")) {
propName = propName.substring(1);
while (!KUtil.isEmpty(propName) && Character.isDigit(propName.charAt(0))) {
maxCharacter = maxCharacter * 10 + (propName.charAt(0) - '0');
propName = propName.substring(1);
}
}
}
int ind = propName.indexOf('.');
if (ind > 0) {
propLoc = propName.substring(0, ind);
propName = propName.substring(ind + 1);
}
ind = propName.indexOf('=');
if (ind > 0) {
filterValue = propName.substring(ind + 1);
propName = propName.substring(0, ind);
}
// System.out.println(propName + "|" + filterValue);
TCComponentType type = null;
if (KUtil.isEmpty(propLoc)) {
type = folderType;
propLoc = KTableRow.ITEM;
} else {
switch (propLoc.toUpperCase()) {
case KTableRow.BOMLINE:
type = cfglineType;
break;
case KTableRow.ITEM:
type = folderType;
break;
default:
System.out.println(">> Prop location error: " + propLoc);
break;
}
}
if (type != null) {
boolean isSeq = propName.startsWith("#");
boolean reorder = false;
if (isSeq) {
propName = propName.substring(1);
}
reorder = propName.startsWith("#");
if (reorder) {
propName = propName.substring(1);
}
TCPropertyDescriptor propDesc = type.getPropDesc(propName);
if (propDesc == null) {
throw new Exception(String.format(REG.getString("propnotdefinedintype.ERROR2"), propName, type.getDisplayTypeName()));
}
PropConfig propConfig;
this.propConfigs.add(propConfig = new PropConfig(propLoc, propDesc, filterValue, width, height, maxCharacter));
if (reorder) {
this.sequenceConfigMapReorder.put(propConfig, 0);
} else if (isSeq) {
this.sequenceConfigMap.put(propConfig, 0);
}
}
}
System.out.println("Load complete");
int size = this.propConfigs.size();
if (size == 0) {
return false;
}
this.gdtPropNames = KUtil.getPrefVals(session, PREF_GDT_PROP);
for (int i = 0; i < size; i++) {
PropConfig config = propConfigs.get(i);
addTableCol(table, config);
}
// table.setOnMouseClicked(e->{
// if(e.getButton()!=MouseButton.SECONDARY || e.getClickCount()!=1) {
// return;
// }
// KTableRow row = table.getSelectionModel().getSelectedItem();
// if(row!=null) {
// row.switchWebView();
// table.refresh();
// }
// });
return true;
}
public void loadTCData(TCComponentBOMLine targetLine, boolean useLatestRev) throws Exception {
Platform.runLater(() -> {
table.getItems().clear();
});
if (targetLine == null) {
return;
}
int size = this.propConfigs.size();
if (size == 0) {
return;
}
removeRows.clear();
this.targetLine = targetLine;
this.targetLine.refresh();
TCComponentCfgActivityLine actLine = (TCComponentCfgActivityLine) targetLine.getReferenceProperty("bl_me_activity_lines");
System.out.println("Activity line: " + targetLine + " -> " + actLine);
if (actLine == null) {
return;
}
TCComponent[] cc = ActivityUtils.getSortedActivityChildren(actLine);
System.out.println(">> " + Arrays.toString(cc));
int len = KUtil.getLen(cc);
for (int i = 0; i < len; i++) {
TCComponentCfgActivityLine bomine = (TCComponentCfgActivityLine) cc[i];
bomine.refresh();
TCComponentMEActivity item = (TCComponentMEActivity) bomine.getUnderlyingComponent();
if (this.folderType != null && !this.folderType.getName().equals(item.getType())) {
continue;
}
KTableRowMEActivity row = new KTableRowMEActivity(bomine, item);
boolean checkOK = true;
for (int j = 0; j < size; j++) {
PropConfig config = propConfigs.get(j);
if (!row.parseConfig(config)) {
checkOK = false;
break;
}
}
if (checkOK) {
for (PropConfig sequenceConfig : this.sequenceConfigMap.keySet()) {
int maxSeqNo = this.sequenceConfigMap.get(sequenceConfig);
String seq2 = row.getTCValue(sequenceConfig.propLoc, sequenceConfig.propName);
if (!KUtil.isEmpty(seq2)) {
try {
int seqNum = Integer.parseInt(seq2);
if (seqNum > maxSeqNo) {
maxSeqNo = seqNum;
this.sequenceConfigMap.put(sequenceConfig, maxSeqNo);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
for (PropConfig sequenceConfig : this.sequenceConfigMapReorder.keySet()) {
int maxSeqNo = this.sequenceConfigMapReorder.get(sequenceConfig);
String seq2 = row.getTCValue(sequenceConfig.propLoc, sequenceConfig.propName);
if (!KUtil.isEmpty(seq2)) {
try {
int seqNum = Integer.parseInt(seq2);
if (seqNum > maxSeqNo) {
maxSeqNo = seqNum;
this.sequenceConfigMapReorder.put(sequenceConfig, maxSeqNo);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Platform.runLater(() -> {
table.getItems().add(row);
});
}
}
Platform.runLater(() -> {
table.refresh();
});
System.out.println("Max Sequence: " + sequenceConfigMap);
System.out.println("Max Sequence Reorder: " + sequenceConfigMapReorder);
}
public void saveTCData() throws Exception {
System.out.println("Save: " + targetLine);
if (targetLine == null) {
return;
}
targetLine.refresh();
TCComponentCfgActivityLine actLine = (TCComponentCfgActivityLine) targetLine.getReferenceProperty("bl_me_activity_lines");
if (actLine != null) {
actLine.refresh();
}
TCComponent alObject = actLine == null ? null : actLine.getReferenceProperty("al_object");
System.out.println("Activity line: " + targetLine + " -> " + alObject);
if (actLine == null) {
return;
}
if (alObject == null) {
throw new TCException(REG.getString("alobjectisnull.ERROR"));
}
while (removeRows.size() > 0) {
removeRows.get(0).removeLine();
removeRows.remove(0);
}
KTableRow[] rows = table.getItems().toArray(new KTableRow[] {});
int len = KUtil.getLen(rows);
TCComponentCfgActivityLine pline = null;
for (int i = 0; i < len; i++) {
KTableRowMEActivity row = (KTableRowMEActivity) rows[i];
row.saveTCData(actLine, folderType);
if (pline != null && row.actline != null) {
ActivityUtils.moveActivityAfter(row.actline, pline);
}
pline = row.actline;
}
}
public KTableRow getNewRow() {
KTableRow row = new KTableRowMEActivity(null, null);
for (PropConfig propConfig : propConfigs) {
row.stringProps.put(propConfig, new SimpleStringProperty(""));
}
return row;
}
}

@ -0,0 +1,258 @@
package cn.net.connor.std.processedit.meopviewfx.ui;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.util.KSqlUtil;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.meopviewfx.bean.TextBean;
import cn.net.connor.std.processedit.util.ProcessUtil;
public class TextTreeLoader {
private static final String PREF_COMMON_FOLDER = "Connor_AVIC_GXBZ_Common_Folder";
private static final String PREF_PERSONAL_FOLDER = "Connor_AVIC_GXBZ_Personal_Folder";
private static final String FLAG_REALVALUE = "#RV#";
private static final String PREFFLAG_REALVALUE = "#RealValue#";
private static final Registry REG = Registry.getRegistry(TextTreeLoader.class);
public static class FileBean {
File file;
int realValueCol;
public FileBean(File file, int realValueCol) {
this.file = file;
this.realValueCol = realValueCol;
}
}
private TCSession session;
public TextTreeLoader(TCSession session) {
this.session = session;
}
public Map<String, TextBean> loadText105() throws Exception {
Map<String, TextBean> textMap = new LinkedHashMap<String, TextBean>();
String key = REG.getString("mkhgy");
String sql = "select pac5_JG1, pac5_JG2, pac5_JG3, pac5_JG4, pac5_JG5, pac5_JG6 from pAc5_MKHGYRevMasters";
Connection conn = KSqlUtil.getOracleConnection(session, ProcessUtil.PREF_DB_CONN);
List<String[]> data = null;
int colCnt = 6;
TextBean root = new TextBean(key);
textMap.put(key, root);
try {
data = KSqlUtil.queryStringArray(conn, sql, null, colCnt);
} finally {
KSqlUtil.free(conn);
}
int cnt = data == null?0:data.size();
for(int i=0; i<cnt ;i++) {
String[] rowData = data.get(i);
TextBean parent = root;
for(int c=0; c<colCnt; c++) {
String text = rowData[c];
if(KUtil.isEmpty(text)) {
break;
}
TextBean child = new TextBean(text);
int ind = parent.children.indexOf(child);
if(ind>=0) {
parent = parent.children.get(ind);
}else {
parent.children.add(child);
parent = child;
}
}
}
return textMap;
}
public Map<String, TextBean> loadText() throws Exception {
Map<String, TextBean> textMap = new LinkedHashMap<String, TextBean>();
List<FileBean> docFiles = getConfigFile();
int size = docFiles.size();
if (size == 0) {
System.out.println("Special Text File not found");
return textMap;
}
for (int i = 0; i < size; i++) {
FileBean docFile = docFiles.get(i);
System.out.println("Load File: " + docFile.file.getAbsolutePath());
InputStream in = new FileInputStream(docFile.file);
XSSFWorkbook wb = new XSSFWorkbook(in);
in.close();
int sheetCnt = wb.getNumberOfSheets();
for (int j = 0; j < sheetCnt; j++) {
XSSFSheet sheet = wb.getSheetAt(0);
String sheetName = sheet.getSheetName();
System.out.println(">> Load Sheet: " + sheetName);
if (textMap.containsKey(sheetName)) {
System.out.println("SKIP");
continue;
}
TextBean bean = readSheet(sheet, docFile.realValueCol);
if (bean != null && bean.children.size() > 0) {
textMap.put(sheetName, bean);
} else {
System.out.println("No Data");
}
}
}
return textMap;
}
private TextBean readSheet(XSSFSheet sheet, int realValueCol) throws Exception {
TextBean root = new TextBean(sheet.getSheetName());
int firstRow = sheet.getFirstRowNum();
int lastRow = sheet.getLastRowNum();
Map<Integer, TextBean> parents = new HashMap<Integer, TextBean>();
parents.put(0, root);
for (int i = firstRow; i <= lastRow; i++) {
XSSFRow row = sheet.getRow(i);
if (row == null) {
continue;
}
int firstCol = row.getFirstCellNum();
if (firstCol < 0) {
firstCol = 0;
}
int lastCol = row.getLastCellNum();
for (int j = firstCol; j <= lastCol; j++) {
XSSFCell cell = row.getCell(j);
if (cell == null || cell.getCellType() != XSSFCell.CELL_TYPE_STRING) {
continue;
}
if (!parents.containsKey(j)) {
continue;
}
String text = cell.getStringCellValue();
if (KUtil.isEmpty(text)) {
continue;
}
if (j == realValueCol) {
parents.get(j).setRealValue(text);
continue;
}
if (text.startsWith(FLAG_REALVALUE)) {
parents.get(j).setRealValue(text.substring(FLAG_REALVALUE.length()));
continue;
}
TextBean bean = new TextBean(text);
// for(int k=j+1;k<=lastCol;k++) {
// XSSFCell realValueCell = row.getCell(k);
// if(realValueCell!=null&&realValueCell.getCellType()==XSSFCell.CELL_TYPE_STRING)
// {
// String realValue = realValueCell.getStringCellValue();
// if(!KUtil.isEmpty(realValue)) {
// bean.setRealValue(realValue);
// break;
// }
// }
// }
parents.get(j).children.add(bean);
parents.put(j + 1, bean);
// break;
}
}
return root;
}
protected List<FileBean> getConfigFile() {
List<FileBean> files = new ArrayList<>();
try {
addFileFromPref(files, PREF_COMMON_FOLDER, "");
} catch (Exception e) {
System.out.println("Load Text Tree From <" + PREF_COMMON_FOLDER + "> Error");
e.printStackTrace();
}
try {
addFileFromPref(files, PREF_PERSONAL_FOLDER, session.getUser().getUserId());
} catch (Exception e) {
System.out.println("Load Text Tree From <" + PREF_PERSONAL_FOLDER + "> Error");
e.printStackTrace();
}
return files;
}
private void addFileFromPref(List<FileBean> files, String prefName, String subFolder) throws Exception {
String uid = KUtil.getPrefVal(session, prefName);
if (KUtil.isEmpty(uid)) {
return;
}
int realValueColumn = -1;
int ind = uid.indexOf(PREFFLAG_REALVALUE);
if (ind > 0) {
String numStr = uid.substring(ind + PREFFLAG_REALVALUE.length());
uid = uid.substring(0, ind);
try {
realValueColumn = Integer.parseInt(numStr);
} catch (Exception e) {
e.printStackTrace();
}
}
TCComponent comp = session.stringToComponent(uid);
if (comp == null) {
return;
}
if (comp instanceof TCComponentFolder) {
TCComponentFolder folder = (TCComponentFolder) comp;
AIFComponentContext[] children = folder.getChildren();
if (!KUtil.isEmpty(subFolder)) {
for (AIFComponentContext c : children) {
InterfaceAIFComponent child = c.getComponent();
if (child instanceof TCComponentFolder) {
if (subFolder.equals(((TCComponentFolder) child).getStringProperty("object_name"))) {
children = child.getChildren();
break;
}
}
}
}
for (AIFComponentContext c : children) {
InterfaceAIFComponent child = c.getComponent();
if ("MSExcelX".equals(child.getType())) {
File[] dbFiles = ((TCComponentDataset) child).getFiles("");
if (dbFiles != null) {
for (int i = 0; i < dbFiles.length; i++) {
files.add(new FileBean(dbFiles[i], realValueColumn));
}
}
}
}
} else if (comp instanceof TCComponentDataset) {
TCComponentDataset dataset = (TCComponentDataset) comp;
if ("MSExcelX".equals(dataset.getType())) {
File[] dbFiles = dataset.getFiles("");
if (dbFiles != null) {
for (int i = 0; i < dbFiles.length; i++) {
files.add(new FileBean(dbFiles[i], realValueColumn));
}
}
}
}
}
}

@ -0,0 +1,35 @@
.root {
-fx-font-family: "Microsoft YaHei";
}
.table-row-cell .ktext {
-fx-fill: black;
}
.table-row-cell:selected .ktext {
-fx-fill: white;
}
.table-cell .ktext {
-fx-fill: black;
}
.table-cell:selected .ktext {
-fx-fill: white;
}
.tab-pane .tab-header-area {
-fx-padding: 5 2 0 0;
}
* :disabled {
-fx-opacity: 0.85;
}
.dark-table .table-row-cell:odd {
-fx-control-inner-background: #e6e6e6;
}
.dark-table .table-row-cell:even {
-fx-control-inner-background: #fff;
}

@ -0,0 +1,9 @@
mkhgy=\u6A21\u5757\u5316\u5DE5\u827A
typenotfound.ERROR1=\u672A\u5B9A\u4E49\u7C7B\u578B\u201C%s\u201D
propnotdefinedintype.ERROR2=\u5C5E\u6027\u201C%s\u201D\u672A\u5728\u7C7B\u578B\u201C%s\u201D\u4E2D\u5B9A\u4E49
index.COL=\u5E8F\u53F7
noseqconfig.ERROR=\u8BE5\u7C7B\u578B\u4E0D\u652F\u6301\u6392\u5E8F
OK.NAME=\u786E\u5B9A
GDT_EDITOR_DIALOG.TITLE=\u7279\u6B8A\u7B26\u53F7
zoom=1.5
alobjectisnull.ERROR=\u65E0\u6CD5\u83B7\u53D6\u5DE5\u6B65\u884C\u5BF9\u8C61

@ -0,0 +1,170 @@
package cn.net.connor.std.processedit.modifymeopno;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KDialog;
import cn.net.connor.std.aifrcp.util.KUtil;
@SuppressWarnings("serial")
public class ModifyMeopNoDialog extends KDialog {
public static final Registry REG = Registry.getRegistry(ModifyMeopNoDialog.class);
protected JButton b_ok;
protected DefaultTableModel tableModel;
protected JTable table;
private ModifyMeopNoDialogController controller;
protected JButton b_delete;
protected JButton b_moveup;
protected JButton b_movedown;
@Override
protected void addListeners() {
this.b_delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.delete();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ModifyMeopNoDialog.this, e1);
}
}
});
this.b_moveup.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.moveup();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ModifyMeopNoDialog.this, e1);
}
}
});
this.b_movedown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.movedown();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ModifyMeopNoDialog.this, e1);
}
}
});
this.b_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
}
@Override
protected void initUI() {
this.controller = (ModifyMeopNoDialogController)aifController;
this.setTitle(REG.getString("modifymeopno.TITLE"));
this.setPreferredSize(new Dimension(800, 600));
this.setLayout(new BorderLayout());
this.add(BorderLayout.CENTER, initTablePanel());
this.add(BorderLayout.EAST, initBtnPanel());
try {
controller.readMeop();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(this, e);
}
controller.checkRelease();
}
private Component initBtnPanel() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(BorderFactory.createEmptyBorder(16, 0, 7, 7));
GridBagConstraints s = getGridBagConstraints(0, 0, new Insets(0, 0, 12, 0));
KUtil.newRow(panel, this.b_delete = new JButton(REG.getString("delete")), s, 1);
KUtil.newRow(panel, this.b_moveup = new JButton(REG.getString("moveup")), s, 1);
KUtil.newRow(panel, this.b_movedown = new JButton(REG.getString("movedown")), s, 1);
KUtil.newRow(panel, this.b_ok = new JButton(REG.getString("ok")), s, 1);
s.weighty = 1;
KUtil.newRow(panel, new JLabel(), s, 1);
return panel;
}
private Component initTablePanel() {
this.tableModel = new DefaultTableModel();
this.table = new JTable(tableModel) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
table.setRowHeight(23);
tableModel.setDataVector(null, controller.tableHeaders);
table.getTableHeader().setReorderingAllowed(false);
table.setDefaultRenderer(Object.class, new ColorTableRenderer());
int colCnt = KUtil.getLen(controller.tableHeaders);
TableColumnModel colModel = this.table.getColumnModel();
for (int i = 0; i < colCnt; i++) {
colModel.getColumn(i).setPreferredWidth(controller.tableHeaderWidth[i]);
}
colModel.getColumn(0).setMinWidth(0);
colModel.getColumn(0).setMaxWidth(0);
if (colCnt > 5) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
JScrollPane scroll = new JScrollPane(table);
scroll.setBorder(null);
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, scroll);
panel.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
return panel;
}
public static class ColorTableRenderer extends DefaultTableCellRenderer {
public static final Color DEFBLUE = new Color(51, 153, 255);
public static final Color RED = new Color(255, 59, 48);
public static final Color GREEN = new Color(158, 234, 106);
@Override
public Component getTableCellRendererComponent(JTable t, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (hasFocus) {
setBackground(DEFBLUE);
} else {
Object obj = t.getValueAt(row, 0);
if(obj instanceof ModifyMeopNoRow) {
if(((ModifyMeopNoRow) obj).isReleased()) {
setBackground(RED);
}else {
setBackground(GREEN);
}
}else {
setBackground(Color.WHITE);
}
}
return super.getTableCellRendererComponent(t, value, isSelected, hasFocus, row, column);
}
}
}

@ -0,0 +1,247 @@
package cn.net.connor.std.processedit.modifymeopno;
import java.util.Arrays;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.util.ProcessUtil;
public class ModifyMeopNoDialogController extends KDialogController {
public static final Registry REG = Registry.getRegistry(ModifyMeopNoDialogController.class);
public static final String PREF_MEOP_TYPE = "Connor_AVIC_SQGXH_GXLX";
public static final String PREF_MEOP_TABLE = "Connor_AVIC_SQGXH_SXBJ";
private String[] meopTypes;
protected String[] tableHeaders;
protected int[] tableHeaderWidth;
private String[] tableProps;
private ModifyMeopNoDialog dialog;
private TCComponentBOMLine procLine;
private TCComponentItemRevision targetRev;
@Override
public boolean init() throws Exception {
this.dialog = (ModifyMeopNoDialog) aifDialog;
InterfaceAIFComponent comp = app.getTargetComponent();
System.out.println("Select: " + comp);
if (comp != null) {
if (comp instanceof TCComponentBOMLine) {
this.procLine = (TCComponentBOMLine) comp;
TCComponentItemRevision rev = this.procLine.getItemRevision();
System.out.println(">> " + rev.getType());
if (ProcessUtil.isMEProcess(session, rev.getItem().getType())) {
// if (rev instanceof TCComponentMEProcessRevision) {
this.targetRev = rev;
}
}
}
if (targetRev == null) {
throw new TCException(REG.getString("selectprocessrev.ERROR"));
}
this.meopTypes = KUtil.getPrefVals(session, PREF_MEOP_TYPE);
String[] tableConfigs = KUtil.getPrefVals(session, PREF_MEOP_TABLE);
if (KUtil.getLen(meopTypes) == 0) {
throw new TCException(String.format(REG.getString("prefnotconfiged.ERROR1"), PREF_MEOP_TYPE));
}
if (KUtil.getLen(tableConfigs) == 0) {
throw new TCException(String.format(REG.getString("prefnotconfiged.ERROR1"), PREF_MEOP_TABLE));
}
int colCnt = KUtil.getLen(tableConfigs);
tableHeaders = new String[colCnt + 1];
tableHeaderWidth = new int[colCnt + 1];
tableHeaders[0] = "Hidden";
tableHeaderWidth[0] = 0;
tableProps = new String[colCnt];
for (int i = 0; i < colCnt; i++) {
int colIndex = i + 1;
String config = tableConfigs[i];
int ind = config.lastIndexOf('=');
if (ind > 0) {
tableHeaders[colIndex] = config.substring(0, ind);
tableProps[i] = config.substring(ind + 1);
} else {
tableHeaders[colIndex] = config;
tableProps[i] = config;
}
int width = 0;
while (tableHeaders[colIndex].length() > 0 && Character.isDigit(tableHeaders[colIndex].charAt(0))) {
width = width * 10 + (tableHeaders[colIndex].charAt(0) - '0');
tableHeaders[colIndex] = tableHeaders[colIndex].substring(1);
}
if (width < 1) {
width = 120;
}
tableHeaderWidth[colIndex] = width;
}
return true;
}
protected void readMeop() throws Exception {
System.out.println("Load Meop: " + this.procLine + " | " + Arrays.toString(meopTypes));
if (this.procLine == null) {
return;
}
KUtil.setByPassItk(session, true);
try {
this.procLine.refresh();
AIFComponentContext[] cc = this.procLine.getChildren();
int len = KUtil.getLen(cc);
for (int i = 0; i < len; i++) {
TCComponentBOMLine cLine = (TCComponentBOMLine) cc[i].getComponent();
String cType = cLine.getItem().getType();
System.out.println((i + 1) + ". " + cLine + " -> " + cType);
if (KUtil.inArray(cType, meopTypes) >= 0) {
dialog.tableModel.addRow(new ModifyMeopNoRow(cLine).getRowData(tableProps));
}
}
} finally {
KUtil.setByPassItk(session, false);
}
}
public void delete() throws Exception {
int selectedRow = dialog.table.getSelectedRow();
System.out.println("Delete: " + selectedRow);
if (selectedRow < 0) {
return;
}
ModifyMeopNoRow bean = (ModifyMeopNoRow) dialog.table.getValueAt(selectedRow, 0);
TCComponentBOMLine bomline = bean.getBomline();
System.out.println("Remove Line: " + bomline);
KUtil.setByPassItk(session, true);
try {
// int currentSeq = NewMeopDialogController.getMeopNo(bomline);
// System.out.println("Current Seq: " + currentSeq);
bomline.cut();
dialog.tableModel.removeRow(selectedRow);
// if (checkSeq(currentSeq)) {
// int rowCnt = dialog.table.getRowCount();
// for (int i = selectedRow; i < rowCnt; i++) {
// bean = (ModifyMeopNoRow) dialog.table.getValueAt(i, 0);
// bomline = bean.getBomline();
// bomline.refresh();
// int seq = NewMeopDialogController.getMeopNo(bomline);
// // int seq = Integer.parseInt(bomline.getStringProperty("bl_sequence_no"));
// System.out.println("Change Sequence: " + bomline + " " + seq + " -> " + (seq - 5));
// seq -= 5;
// NewMeopDialogController.setMeopNo(bomline, seq);
// // bomline.setProperty("bl_sequence_no", "" + seq);
// bomline.refresh();
// dialog.tableModel.removeRow(i);
// dialog.tableModel.insertRow(i, bean.getRowData(tableProps));
// }
// } else {
// System.out.println("Skip Change");
// }
procLine.refresh();
} finally {
KUtil.setByPassItk(session, false);
}
checkRelease();
}
public boolean checkSeq(int seq) {
return seq > 0 && seq % 5 == 0;
}
public void checkRelease() {
int rowCnt = dialog.table.getRowCount();
boolean hasRelease = false;
for (int i = 0; i < rowCnt; i++) {
if (((ModifyMeopNoRow) dialog.table.getValueAt(i, 0)).isReleased()) {
hasRelease = true;
break;
}
}
dialog.b_moveup.setEnabled(!hasRelease);
dialog.b_movedown.setEnabled(!hasRelease);
}
public void moveup() throws Exception {
int selectedRow = dialog.table.getSelectedRow();
System.out.println("Move Up: " + selectedRow);
if (selectedRow <= 0) {
return;
}
KUtil.setByPassItk(session, true);
try {
ModifyMeopNoRow bean = (ModifyMeopNoRow) dialog.table.getValueAt(selectedRow, 0);
TCComponentBOMLine bomline = bean.getBomline();
System.out.println("Select Line: " + bomline);
ModifyMeopNoRow otherbean = (ModifyMeopNoRow) dialog.table.getValueAt(selectedRow - 1, 0);
TCComponentBOMLine otherBomline = otherbean.getBomline();
System.out.println("Other Line: " + otherBomline);
int blseq = Integer.parseInt(bomline.getStringProperty("bl_sequence_no"));
int otherblSeq = Integer.parseInt(otherBomline.getStringProperty("bl_sequence_no"));
bomline.setProperty("bl_sequence_no", otherblSeq + "");
otherBomline.setProperty("bl_sequence_no", blseq + "");
// int seq = NewMeopDialogController.getMeopNo(bomline);
// int otherSeq = NewMeopDialogController.getMeopNo(otherBomline);
// if (checkSeq(seq) && checkSeq(otherSeq)) {
// NewMeopDialogController.setMeopNo(bomline, otherSeq);
// NewMeopDialogController.setMeopNo(otherBomline, seq);
// } else {
// System.out.println("Skip Change");
// }
bomline.refresh();
otherBomline.refresh();
procLine.refresh();
dialog.tableModel.removeRow(selectedRow);
dialog.tableModel.removeRow(selectedRow - 1);
dialog.tableModel.insertRow(selectedRow - 1, otherbean.getRowData(tableProps));
dialog.tableModel.insertRow(selectedRow - 1, bean.getRowData(tableProps));
dialog.table.getSelectionModel().setSelectionInterval(selectedRow - 1, selectedRow - 1);
} finally {
KUtil.setByPassItk(session, false);
}
}
public void movedown() throws Exception {
int selectedRow = dialog.table.getSelectedRow();
System.out.println("Move Down: " + selectedRow);
int rowCnt = dialog.table.getRowCount();
if (selectedRow < 0 || selectedRow == rowCnt - 1) {
return;
}
KUtil.setByPassItk(session, true);
try {
ModifyMeopNoRow bean = (ModifyMeopNoRow) dialog.table.getValueAt(selectedRow, 0);
TCComponentBOMLine bomline = bean.getBomline();
System.out.println("Select Line: " + bomline);
ModifyMeopNoRow otherbean = (ModifyMeopNoRow) dialog.table.getValueAt(selectedRow + 1, 0);
TCComponentBOMLine otherBomline = otherbean.getBomline();
System.out.println("Other Line: " + otherBomline);
int blseq = Integer.parseInt(bomline.getStringProperty("bl_sequence_no"));
int otherblSeq = Integer.parseInt(otherBomline.getStringProperty("bl_sequence_no"));
bomline.setProperty("bl_sequence_no", otherblSeq + "");
otherBomline.setProperty("bl_sequence_no", blseq + "");
// int seq = NewMeopDialogController.getMeopNo(bomline);
// int otherSeq = NewMeopDialogController.getMeopNo(otherBomline);
// if (checkSeq(seq) && checkSeq(otherSeq)) {
// NewMeopDialogController.setMeopNo(bomline, otherSeq);
// NewMeopDialogController.setMeopNo(otherBomline, seq);
// } else {
// System.out.println("Skip Change");
// }
bomline.refresh();
otherBomline.refresh();
procLine.refresh();
dialog.tableModel.removeRow(selectedRow + 1);
dialog.tableModel.removeRow(selectedRow);
dialog.tableModel.insertRow(selectedRow, bean.getRowData(tableProps));
dialog.tableModel.insertRow(selectedRow, otherbean.getRowData(tableProps));
dialog.table.getSelectionModel().setSelectionInterval(selectedRow + 1, selectedRow + 1);
} finally {
KUtil.setByPassItk(session, false);
}
}
}

@ -0,0 +1,63 @@
package cn.net.connor.std.processedit.modifymeopno;
import java.util.HashMap;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.aifrcp.util.PropLocation;
public class ModifyMeopNoRow {
private TCComponentBOMLine bomline;
private boolean isReleased;
private HashMap<String, TCComponent> markedComponents;
public ModifyMeopNoRow(TCComponentBOMLine cLine) throws Exception {
this.bomline = cLine;
this.bomline.refresh();
TCComponentItemRevision rev = cLine.getItemRevision();
if(rev==null) {
throw new Exception("revision not found: "+cLine);
}
rev.refresh();
markedComponents = new HashMap<String, TCComponent>();
PropLocation.initLocationMap(markedComponents , getBomline());
this.isReleased=KUtil.isReleased(rev);
}
public boolean isReleased() {
return this.isReleased;
}
public Object[] getRowData(String[] tableProps) throws Exception{
int len = KUtil.getLen(tableProps);
Object[] data = new Object[len+1];
data[0] = this;
for(int i=0; i<len; i++) {
String[] config = tableProps[i].split("\\.");
if(KUtil.getLen(config)!=2) {
data[i+1] = tableProps[i];
continue;
}
String propLoc = config[0].toUpperCase();
if(markedComponents.containsKey(propLoc)) {
data[i+1] = markedComponents.get(propLoc).getProperty(config[1]);
}else {
data[i+1] = tableProps[i];
}
}
return data;
}
@Override
public String toString() {
return getBomline().toString();
}
public TCComponentBOMLine getBomline() {
return bomline;
}
}

@ -0,0 +1,7 @@
modifymeopno.TITLE=\u4FEE\u6539\u5DE5\u5E8F\u53F7
moveup=\u4E0A\u79FB
movedown=\u4E0B\u79FB
delete=\u5220\u9664
ok=\u786E\u5B9A
selectprocessrev.ERROR=\u8BF7\u9009\u62E9\u5DE5\u827A\u8FDB\u884C\u64CD\u4F5C
prefnotconfiged.ERROR1=\u9996\u9009\u9879\u672A\u914D\u7F6E\uFF1A%s

@ -0,0 +1,226 @@
package cn.net.connor.std.processedit.newdatasetfromtemplate;
import java.util.Arrays;
import java.util.List;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.internal.e4.compatibility.CompatibilityView;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.cme.application.MFGLegacyApplication;
import com.teamcenter.rac.cme.framework.treetable.CMEBOMTreeTable;
import com.teamcenter.rac.cme.framework.views.primary.BOMPrimaryView;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentCfgAttachmentLine;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PlatformHelper;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KOperation;
import cn.net.connor.std.aifrcp.util.KUtil;
@SuppressWarnings("restriction")
public class NewDatasetFromTemplateOperation extends KOperation {
public static final Registry REG = Registry.getRegistry(NewDatasetFromTemplateOperation.class);
private String prefName;
private TCComponentDataset template;
private String[] selectTypes;
private String relation;
private String nameConfig;
private String successAlert;
private String existAlert;
private TCComponentItemRevision targetRev;
private TCComponentBOMLine targetBOMLine;
private boolean refreshCfgLines = false;
public NewDatasetFromTemplateOperation(AbstractAIFApplication app, String prefName) {
super(app, REG.getString("op.Name"));
this.prefName = prefName;
}
@Override
public boolean init() throws Exception {
String[] prefValues = KUtil.getPrefVals(session, prefName);
System.out.println("NewDatasetFromTemplateOperation");
System.out.println(prefName + " -> " + Arrays.toString(prefValues));
int prefCnt = KUtil.getLen(prefValues);
/**
* select=select type relation=relation name=dataset name success=success alert
* dataset=uid exist=exist alert
*/
for (int i = 0; i < prefCnt; i++) {
String pref = prefValues[i];
int ind = pref.indexOf('=');
if (ind <= 0) {
continue;
}
String key = pref.substring(0, ind).trim().toLowerCase();
String value = pref.substring(ind + 1);
switch (key) {
case "select":
this.selectTypes = value.split(";");
break;
case "relation":
this.relation = value;
break;
case "name":
this.nameConfig = value;
break;
case "success":
this.successAlert = value;
break;
case "dataset":
String uid = value;
try {
this.template = (TCComponentDataset) session.stringToComponent(uid);
} catch (TCException e) {
e.printStackTrace();
}
break;
case "exist":
this.existAlert = value;
break;
default:
break;
}
}
System.out.println("Template: " + this.template);
if (this.template == null || KUtil.getLen(this.selectTypes) == 0 || KUtil.isEmpty(this.relation) || KUtil.isEmpty(this.nameConfig)) {
throw new TCException(String.format(REG.getString("pref.Error1"), prefName));
}
InterfaceAIFComponent target = app.getTargetComponent();
if (target != null) {
if (target instanceof TCComponentBOMLine) {
this.targetBOMLine = (TCComponentBOMLine) target;
this.targetRev = targetBOMLine.getItemRevision();
} else if (target instanceof TCComponentCfgAttachmentLine) {
TCComponent obj = ((TCComponentCfgAttachmentLine) target).getUnderlyingComponent();
if (obj != null && (obj instanceof TCComponentItemRevision)) {
this.targetRev = (TCComponentItemRevision) obj;
this.refreshCfgLines = true;
}
}
}
if (refreshCfgLines) {
TCComponentBOMWindow bomWindow = ((TCComponentCfgAttachmentLine) target).window().getBomWindow();
System.out.println(">> BomWindow: " + bomWindow);
System.out.println(">> " + app.getClass());
if (app instanceof MFGLegacyApplication) {
List<Object> viewParts = PlatformHelper.getAllViewParts();
IWorkbenchWindow var1 = AIFUtility.getActiveDesktop().getDesktopWindow();
IWorkbenchPage page = var1.getActivePage();
for (Object viewPart : viewParts) {
if (viewPart == null || !(viewPart instanceof CompatibilityView)) {
continue;
}
IViewPart view = ((CompatibilityView) viewPart).getView();
if (view == null || !(view instanceof BOMPrimaryView)) {
continue;
}
BOMPrimaryView bomView = (BOMPrimaryView) view;
CMEBOMTreeTable treeTable = bomView.getBOMTreeTable();
if (treeTable == null) {
continue;
}
boolean visible = page.isPartVisible(view);
System.out.println(">> BOMPrimaryView: [" + visible + "]" + bomView);
if (!visible) {
continue;
}
if (treeTable.getBOMWindow() == bomWindow) {
System.out.println(">>>>> find window");
TCComponentBOMLine[] bomlines = treeTable.getSelectedBOMLines();
System.out.println(">> Selected lines: " + Arrays.toString(bomlines));
int bomLineCnt = KUtil.getLen(bomlines);
if (bomLineCnt == 1 && this.targetRev == bomlines[0].getItemRevision()) {
this.targetBOMLine = bomlines[0];
System.out.println(">>>>> Find targetline");
break;
}
}
}
}
}
String targetType = this.targetRev == null ? "" : this.targetRev.getType();
System.out.println("Select " + target + " [" + targetType + "]");
if (KUtil.isEmpty(targetType) || KUtil.inArray(targetType, selectTypes) < 0) {
String[] typeNames = new String[this.selectTypes.length];
for (int i = 0; i < this.selectTypes.length; i++) {
typeNames[i] = KUtil.getTypeName(session, this.selectTypes[i]);
}
throw new TCException(String.format(REG.getString("select.Error1"), Arrays.toString(typeNames)));
}
if (this.targetBOMLine == null) {
throw new TCException(REG.getString("nobomline.Error"));
}
return true;
}
@SuppressWarnings("deprecation")
@Override
public void execute() throws Exception {
this.targetRev.refresh();
this.targetBOMLine.refresh();
String dsName = KUtil.getPropValueByPath(targetBOMLine, nameConfig, "-");
System.out.println("Dataset Name: " + dsName);
if (!KUtil.isEmpty(this.existAlert)) {
TCComponent existDataset = KUtil.getChildByTypeAndName(targetRev, template.getType(), dsName, relation);
System.out.println("Exist: " + existDataset);
if (existDataset != null) {
MessageBox.post(existAlert, "", MessageBox.WARNING);
return;
}
}
TCComponentDataset newDataset = this.template.saveAs(dsName);
System.out.println("New Dataset: " + newDataset);
if (newDataset == null) {
throw new TCException(REG.getString("saveas.Error"));
}
this.targetRev.add(relation, newDataset);
this.targetRev.refresh();
// rename file ref
TCComponent[] refs = newDataset.getReferenceListProperty("ref_list");
if (KUtil.getLen(refs) > 0) {
TCComponent ref = refs[0];
String fileName = ref.getStringProperty("original_file_name");
System.out.println("Check file name: " + fileName);
int ind = fileName.lastIndexOf('.');
if (ind > 0) {
String ext = fileName.substring(ind);
String newName = dsName;
if (!newName.toLowerCase().endsWith(ext.toLowerCase())) {
newName += ext;
}
ref.lock();
try {
ref.setStringProperty("original_file_name", newName);
ref.save();
} finally {
ref.refresh();
}
}
}
if (!KUtil.isEmpty(this.successAlert)) {
MessageBox.post(successAlert, "", MessageBox.INFORMATION);
}
session.refreshComponentsByType("CfgBlAttachmentLine");
}
@Override
public void clearCache() throws Exception {
}
}

@ -0,0 +1,5 @@
op.Name=\u4ECE\u6A21\u677F\u53E6\u5B58\u6570\u636E\u96C6
pref.Error1=\u9996\u9009\u9879\u201C%s\u201D\u914D\u7F6E\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u3002
select.Error1=\u8BF7\u9009\u62E9%s\u8FDB\u884C\u64CD\u4F5C\u3002
saveas.Error=\u53E6\u5B58\u6A21\u677F\u6570\u636E\u96C6\u5931\u8D25
nobomline.Error=\u672A\u627E\u5230\u5173\u8054BOM\u884C

@ -0,0 +1,260 @@
package cn.net.connor.std.processedit.newmeop;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JPanel;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.classification.common.AbstractG4MApplication;
import com.teamcenter.rac.classification.common.G4MApplicationPanel;
import com.teamcenter.rac.classification.common.G4MUserAppContext;
import com.teamcenter.rac.classification.common.table.G4MTable;
import com.teamcenter.rac.classification.icm.ICMApplication;
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.TCComponentICO;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.util.PrefComponent;
@SuppressWarnings("serial")
public class G4MDialog extends AbstractAIFDialog {
private JButton b_ok;
private JButton b_cel;
private ICMApplication app;
private MyG4MContext m_context;
protected TCComponentICO ico;
private String expandClass;
InterfaceAIFComponent iaf;
TCComponentForm form;
TCSession session;
List<PrefComponent> prefComponents;
// public G4MDialog(String expandClass, InterfaceAIFComponent iaf, QZjsbjdBean jsbjdBean, TCSession session, TCComponentForm form) {
// super(AIFDesktop.getActiveDesktop(), true);
// this.jsbjdBean=jsbjdBean;
// this.expandClass = expandClass;
// this.iaf = iaf;
// this.session=session;
// this.form=form;
// try {
// this.app = new ICMApplication();
// this.m_context = new MyG4MContext(app, "k0");
// } catch (Exception e) {
// e.printStackTrace();
// }
// initUI();
// }
public G4MDialog(String expandClass, InterfaceAIFComponent iaf, TCSession session,List<PrefComponent> prefComponents) {
super(AIFDesktop.getActiveDesktop(), true);
this.expandClass = expandClass;
this.iaf = iaf;
this.session=session;
this.prefComponents = prefComponents;
try {
this.app = new ICMApplication();
this.m_context = new MyG4MContext(app, "k0");
} catch (Exception e) {
e.printStackTrace();
}
initUI();
}
@Override
public void run() {
showDialog();
}
private void initUI() {
this.setTitle("材料选取");
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(1000, 600));
this.setMinimumSize(new Dimension(640, 480));
MyG4MPanel panel = new MyG4MPanel(null);
try {
m_context.openComponent(iaf);
panel.initialize(m_context);
this.add(BorderLayout.CENTER, panel);
m_context.getTree().expandToClass(expandClass);
// new Thread(m_context.getClassificationDialog()).start();
} catch (Exception e) {
e.printStackTrace();
}
// panel.open(iaf);
this.add(BorderLayout.SOUTH, initBtnPanel());
addListeners();
}
private void addListeners() {
b_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
G4MTable table = m_context.getTablePane().getG4MTable();
List<?> list = null;
if (table != null) {
ISelection sel = table.getSelection();
if (sel != null && sel instanceof StructuredSelection) {
list = ((StructuredSelection) sel).toList();
}
}
if (list == null || list.size() == 0) {
MessageBox.post("请选择要使用的对象", "", MessageBox.INFORMATION);
// KUtil.info(G4MDialog.this, "请选择要使用的对象");
return;
}
if (list.size() > 1) {
MessageBox.post("请选择单行数据", "", MessageBox.INFORMATION);
// KUtil.info(G4MDialog.this, "请选择单行数据");
return;
}
Object target = list.get(0);
if (target != null && target instanceof TCComponentICO) {
ico = (TCComponentICO) target;
System.out.println(" ico.getClassId()=====" + ico.getClassId());
TCComponent classifiedObject = ico.getClassifiedObject();
TCComponentItemRevision rev = null;
if(classifiedObject instanceof TCComponentItemRevision) {
rev = (TCComponentItemRevision) classifiedObject;
}else if(classifiedObject instanceof TCComponentItem) {
TCComponentItem item = (TCComponentItem) classifiedObject;
try {
rev = item.getLatestItemRevision();
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
System.out.println("ico.id==="+ico.getId());
System.out.println("rev==="+rev);
if(rev != null) {
try {
for (PrefComponent comp : prefComponents) {
String key = comp.getPropConfig();
if(key.contains(".")) {
String[] split = key.split("\\.");
if(split[0].equalsIgnoreCase("item")) {
String stringProperty = rev.getItem().getStringProperty(split[1]);
System.out.println(String.format("---set [%s]=[%s]", key, stringProperty));
if(stringProperty != null && !stringProperty.isEmpty()) {
comp.setValue(stringProperty);
}
}else if(split[0].equalsIgnoreCase("rev")) {
String stringProperty = rev.getStringProperty(split[1]);
System.out.println(String.format("---set [%s]=[%s]", key, stringProperty));
if(stringProperty != null && !stringProperty.isEmpty()) {
comp.setValue(stringProperty);
}
}
}
}
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else {
MessageBox.post("请选择分类对象!", "提示", MessageBox.INFORMATION);
}
MessageBox.post("工序引用成功!!!", "成功", MessageBox.INFORMATION);
} else {
MessageBox.post("选择的数据不是ICO对象", "", MessageBox.INFORMATION);
// KUtil.info(G4MDialog.this, "选择的数据不是ICO对象");
return;
}
}
});
b_cel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
}
private JPanel initBtnPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 25, 5));
this.b_ok = new JButton("确定");
this.b_cel = new JButton("取消");
panel.add(b_ok);
panel.add(b_cel);
return panel;
}
public class MyG4MContext extends G4MUserAppContext {
public MyG4MContext(AbstractAIFUIApplication paramAbstractAIFUIApplication, String paramString)
throws Exception {
super(paramAbstractAIFUIApplication, paramString);
}
@Override
public void setBusy(String paramString) {
}
@Override
public void setIdle(String paramString) {
}
}
public class MyG4MPanel extends G4MApplicationPanel {
public MyG4MPanel(AbstractG4MApplication paramAbstractG4MApplication) {
super(paramAbstractG4MApplication);
}
@Override
public void closeSignaled() {
try {
m_context.clear();
} catch (Exception e) {
e.printStackTrace();
}
// m_context.openComponent(iaf);
}
}
}

@ -0,0 +1,122 @@
package cn.net.connor.std.processedit.newmeop;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KDialog;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KUtil;
@SuppressWarnings("serial")
public class MeopNoDialog extends KDialog {
private JButton b_insert;
private JButton b_ok;
protected DefaultTableModel tableModel;
protected JTable table;
private MeopNoDialogController controller;
private boolean ok = false;
private static final Registry REG = Registry.getRegistry(MeopNoDialog.class);
public MeopNoDialog(AbstractAIFDialog parent, boolean model, KDialogController controller) {
super(parent, model, controller);
this.controller = (MeopNoDialogController) controller;
}
@Override
protected void addListeners() {
this.b_insert.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.insert();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(MeopNoDialog.this, e1);
}
}
});
this.b_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ok = true;
disposeDialog();
}
});
}
public Map<String, String> getMeopInfo() throws Exception {
if (!initDialog()) {
return null;
}
controller.readMeop();
showDialog();
if (!ok) {
return null;
}
return controller.getInsertedData();
}
@Override
protected void initUI() {
this.setTitle(REG.getString("applymeopno.TITLE"));
this.setPreferredSize(new Dimension(800, 600));
this.setLayout(new BorderLayout());
this.add(BorderLayout.CENTER, initTablePanel());
this.add(BorderLayout.EAST, initBtnPanel());
}
private Component initBtnPanel() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(BorderFactory.createEmptyBorder(16, 0, 7, 7));
GridBagConstraints s = getGridBagConstraints(0, 0, new Insets(0, 0, 12, 0));
KUtil.newRow(panel, this.b_insert = new JButton(REG.getString("insert")), s, 1);
KUtil.newRow(panel, this.b_ok = new JButton(REG.getString("ok")), s, 1);
s.weighty = 1;
KUtil.newRow(panel, new JLabel(), s, 1);
return panel;
}
private Component initTablePanel() {
this.tableModel = new DefaultTableModel();
this.table = new JTable(tableModel);
table.setRowHeight(23);
tableModel.setDataVector(null, controller.tableHeaders);
table.getTableHeader().setReorderingAllowed(false);
int colCnt = KUtil.getLen(controller.tableHeaders);
TableColumnModel colModel = this.table.getColumnModel();
for (int i = 0; i < colCnt; i++) {
colModel.getColumn(i).setPreferredWidth(controller.tableHeaderWidth[i]);
}
if (colCnt > 5) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
JScrollPane scroll = new JScrollPane(table);
scroll.setBorder(null);
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, scroll);
panel.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
return panel;
}
}

@ -0,0 +1,120 @@
package cn.net.connor.std.processedit.newmeop;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KUtil;
public class MeopNoDialogController extends KDialogController {
public static final String PREF_MEOP_TYPE = "Connor_AVIC_SQGXH_GXLX";
public static final String PREF_MEOP_TABLE = "Connor_AVIC_SQGXH_SXBJ";
private String[] meopTypes;
protected String[] tableHeaders;
protected int[] tableHeaderWidth;
private String[] tableProps;
private MeopNoDialog dialog;
private TCComponentBOMLine procLine;
private int newRowNum = -1;
private static final Registry REG = Registry.getRegistry(MeopNoDialogController.class);
public MeopNoDialogController(AbstractAIFApplication app, TCComponentBOMLine procLine) {
super();
this.procLine = procLine;
}
@Override
public boolean init() throws Exception {
this.dialog = (MeopNoDialog) aifDialog;
this.meopTypes = KUtil.getPrefVals(session, PREF_MEOP_TYPE);
String[] tableConfigs = KUtil.getPrefVals(session, PREF_MEOP_TABLE);
if (KUtil.getLen(meopTypes) == 0) {
throw new TCException(String.format(REG.getString("prefnotconfiged.ERROR1"), PREF_MEOP_TYPE));
}
if (KUtil.getLen(tableConfigs) == 0) {
throw new TCException(String.format(REG.getString("prefnotconfiged.ERROR1"), PREF_MEOP_TABLE));
}
int colCnt = KUtil.getLen(tableConfigs);
tableHeaders = new String[colCnt];
tableHeaderWidth = new int[colCnt];
tableProps = new String[colCnt];
for (int i = 0; i < colCnt; i++) {
String config = tableConfigs[i];
int ind = config.lastIndexOf('=');
if (ind > 0) {
tableHeaders[i] = config.substring(0, ind);
tableProps[i] = config.substring(ind + 1);
} else {
tableHeaders[i] = config;
tableProps[i] = config;
}
int width = 0;
while (tableHeaders[i].length() > 0 && Character.isDigit(tableHeaders[i].charAt(0))) {
width = width * 10 + (tableHeaders[i].charAt(0) - '0');
tableHeaders[i] = tableHeaders[i].substring(1);
}
if (width < 1) {
width = 120;
}
tableHeaderWidth[i] = width;
}
return true;
}
protected void readMeop() throws Exception {
System.out.println("Load Meop: " + this.procLine+" | "+Arrays.toString(meopTypes));
if (this.procLine == null) {
return;
}
this.procLine.refresh();
AIFComponentContext[] cc = this.procLine.getChildren();
int len = KUtil.getLen(cc);
for (int i = 0; i < len; i++) {
TCComponentBOMLine cLine = (TCComponentBOMLine) cc[i].getComponent();
String cType = cLine.getItem().getType();
System.out.println((i+1)+". "+cLine+" -> "+cType);
if(KUtil.inArray(cType, meopTypes)>=0) {
dialog.tableModel.addRow(new MeopNoRow(cLine).getRowData(tableProps));
}
}
}
public void insert() throws Exception {
int selectedRow = dialog.table.getSelectedRow();
System.out.println("Insert to: "+selectedRow);
if(selectedRow<0) {
newRowNum = dialog.table.getRowCount();
dialog.tableModel.addRow(new Object[] {});
}else {
newRowNum = selectedRow;
dialog.tableModel.insertRow(newRowNum, new Object[] {});
}
System.out.println("New RowNum: "+this.newRowNum);
}
public Map<String, String> getInsertedData(){
System.out.println("New RowNum: "+this.newRowNum);
if(this.newRowNum<0) {
return null;
}
Map<String, String> res = new HashMap<String, String>();
int colCnt = KUtil.getLen(tableProps);
for(int i=0; i<colCnt; i++) {
String value = (String) dialog.table.getValueAt(this.newRowNum, i);
if(value==null) {
value = "";
}
res.put(tableProps[i], value);
}
return res;
}
}

@ -0,0 +1,41 @@
package cn.net.connor.std.processedit.newmeop;
import java.util.HashMap;
import java.util.Map;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.aifrcp.util.PropLocation;
public class MeopNoRow {
private TCComponentBOMLine bomline;
public MeopNoRow(TCComponentBOMLine cLine) {
this.bomline = cLine;
}
public Object[] getRowData(String[] tableProps) throws Exception{
int len = KUtil.getLen(tableProps);
Object[] data = new Object[len];
Map<String, TCComponent> markedComponents = new HashMap<String, TCComponent>();
PropLocation.initLocationMap(markedComponents , bomline);
for(int i=0; i<len; i++) {
String[] config = tableProps[i].split("\\.");
if(KUtil.getLen(config)!=2) {
data[i] = tableProps[i];
continue;
}
String propLoc = config[0].toUpperCase();
if(markedComponents.containsKey(propLoc)) {
data[i] = markedComponents.get(propLoc).getProperty(config[1]);
}else {
data[i] = tableProps[i];
}
}
return data;
}
}

@ -0,0 +1,311 @@
package cn.net.connor.std.processedit.newmeop;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import com.teamcenter.rac.util.iTextField;
import cn.net.connor.std.aifrcp.KDialog;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.newmeop.NewMeopDialogController.MEOPType;
import cn.net.connor.std.processedit.util.PrefComponent;
@SuppressWarnings("serial")
public class NewMeopDialog extends KDialog {
private JButton b_ok;
private JButton b_cel;
protected DefaultListModel<MEOPType> lm_type;
protected JList<MEOPType> l_type;
private NewMeopDialogController controller;
private JButton b_assignId;
private PrefComponent idComponent;
private Map<PrefComponent,JButton> chooseComponents = new HashMap<PrefComponent, JButton>();
private PrefComponent sequenceComponent;
private JButton b_assignMeopNo;
private JButton b_insertMeopNo;
private JButton b_WorkCenter;
protected iTextField tf_WorkCenter;
private static final Registry REG = Registry.getRegistry(NewMeopDialog.class);
public NewMeopDialog(KDialogController controller) {
super(controller);
this.controller = (NewMeopDialogController)controller;
}
private void setCompEnabled(boolean b) {
b_ok.setEnabled(b);
b_cel.setEnabled(b);
for (JButton btn : chooseComponents.values()) {
btn.setEnabled(b);
}
}
public void setAssignId(String newId) {
if(idComponent!=null&&b_assignId!=null) {
if(KUtil.isEmpty(newId)) {
idComponent.setValue(null);
b_assignId.setEnabled(true);
}else {
idComponent.setValue(newId);
b_assignId.setEnabled(false);
}
}
}
public void setMeopNo(String newId) {
if(sequenceComponent!=null&&b_assignMeopNo!=null&&b_insertMeopNo!=null) {
if(KUtil.isEmpty(newId)) {
sequenceComponent.setValue(null);
// b_assignMeopNo.setEnabled(true);
// b_insertMeopNo.setEnabled(true);
}else {
sequenceComponent.setValue(newId);
// b_assignMeopNo.setEnabled(false);
// b_insertMeopNo.setEnabled(false);
}
}
}
@Override
protected void addListeners() {
if(b_WorkCenter != null)
b_WorkCenter.addActionListener(new ActionListener() {//TODO b_WorkCenter
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.chooseWorkCenter();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(NewMeopDialog.this,e1);
}
}
});
b_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Thread(new Runnable() {
@Override
public void run() {
setCompEnabled(false);
try {
controller.doCreate();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(NewMeopDialog.this,e);
}
setCompEnabled(true);
}
}).start();
}
});
b_cel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
if(b_assignId!=null&&idComponent!=null) {
b_assignId.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.assignId();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(NewMeopDialog.this,e1);
}
}
});
}
if(this.sequenceComponent!=null&&this.b_assignMeopNo!=null&&this.b_insertMeopNo!=null) {
b_assignMeopNo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.assignMeopNo();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(NewMeopDialog.this,e1);
}
}
});
b_insertMeopNo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
controller.insertMeopNo();
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(NewMeopDialog.this,e1);
}
}
});
}
for (PrefComponent bean : chooseComponents.keySet()) {
JButton btn = chooseComponents.get(bean);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MEOPType typeComp = l_type.getSelectedValue();
if (typeComp == null) {
MessageBox.post(NewMeopDialog.this, REG.getString("selectMeopType.INFO"), "", MessageBox.WARNING);
return;
}
//bean.performChoose(NewMeopDialog.this, typeComp.type, controller.getApp(), controller.prefComponents);
G4MDialog classDialog = new G4MDialog("¾«µñ·ÖÀà", null, controller.session,controller.prefComponents);
new Thread(classDialog).start();
}
});
}
this.l_type.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent arg0) {
if(arg0.getValueIsAdjusting()) {
return;
}
System.out.println("Select Type Change > "+l_type.getSelectedValue());
setAssignId(null);
setMeopNo(null);
if(controller.shortDescPrefComp!=null&&l_type.getSelectedValue()!=null) {
controller.shortDescPrefComp.setValue(l_type.getSelectedValue().additional);
}
controller.clearWorkCenter();
}
});
}
@Override
protected void initUI() {
this.setTitle(REG.getString("newmeop.TITLE"));
this.setPreferredSize(new Dimension(850, 780));
this.setMinimumSize(new Dimension(850, 780));
this.setLayout(new BorderLayout());
this.add(BorderLayout.WEST, initTypePanel());
this.add(BorderLayout.CENTER, initPropPanel());
this.add(BorderLayout.SOUTH, initBtnPanel());
}
private Component initBtnPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 5));
this.b_ok = new JButton(REG.getString("ok"));
this.b_cel = new JButton(REG.getString("cancel"));
panel.add(b_ok);
panel.add(b_cel);
return panel;
}
private Component initPropPanel() {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, initMEPropPanel());
panel.add(BorderLayout.SOUTH, initDESCPropPanel());
return panel;
}
private Component initDESCPropPanel() {
JPanel panel = new JPanel(new BorderLayout());
if(controller.shortDescPrefComp!=null) {
//panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(30, 5, 5, 5), ProcessLocale.getString("medesc.TITLE")));
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(30, 5, 5, 5), controller.shortDescPrefComp.getLabel().getText()));
JScrollPane scroll = new JScrollPane(controller.shortDescPrefComp.getValueComp());
panel.add(BorderLayout.CENTER, scroll);
controller.prefComponents.add(controller.shortDescPrefComp);
}
return panel;
}
private Component initMEPropPanel() {
JPanel wrapper = new JPanel(new BorderLayout());
wrapper.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(30, 5, 5, 5), REG.getString("meinfo.TITLE")));
JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(BorderFactory.createEmptyBorder(20,30,20,30));
GridBagConstraints s = getGridBagConstraints(0, 0, new Insets(6, 6, 6, 6));
List<PrefComponent> comps = controller.prefComponents;
int colCnt = 1;
int size = comps.size();
for(int i=0;i<size;i++) {
PrefComponent prefComponent = comps.get(i);
if(i%colCnt==0) {
KUtil.newRow(panel, prefComponent.label, s, 1);
}else {
KUtil.addCol(panel, prefComponent.label, s, 1, 0);
}
KUtil.addCol(panel, prefComponent.getValueComp(), s, 1, 1);
if("item.item_id".equals(prefComponent.propConfig.toLowerCase())) {
KUtil.addCol(panel, this.b_assignId = new JButton(REG.getString("assign")), s, 1, 0);
this.idComponent = prefComponent;
}
//else if(KUtil.getLen(prefComponent.getExcelConfig())>0) {
else if("item.object_name".equals(prefComponent.propConfig.toLowerCase())) {
JButton b_choose = new JButton(REG.getString("select"));
KUtil.addCol(panel, b_choose, s, 1, 0);
chooseComponents.put(prefComponent, b_choose);
// }else if("revmaster.ac5_OperationNumber".equalsIgnoreCase(prefComponent.propConfig)) {
}else if("bomline.bl_sequence_no".equalsIgnoreCase(prefComponent.propConfig)) {
KUtil.addCol(panel,this.b_assignMeopNo = new JButton(REG.getString("shenqing")), s, 1, 0);
KUtil.addCol(panel,this.b_insertMeopNo = new JButton(REG.getString("insert")), s, 1, 0);
this.b_insertMeopNo.setVisible(false);
this.sequenceComponent = prefComponent;
}
}
/*KUtil.newRow(panel, new JLabel(REG.getString("workcenter")), s, 1);
this.tf_WorkCenter = new iTextField(18);
// this.tf_WorkCenter.setRequired(true);
// this.tf_WorkCenter.setEditable(false);//TODO tf_WorkCenter
KUtil.addCol(panel, tf_WorkCenter, s, 1, 1);
KUtil.addCol(panel, this.b_WorkCenter = new JButton(REG.getString("select")), s, 1, 0);*/
s.weighty = 1;
KUtil.newRow(panel, new JLabel(""), s, 1);
JScrollPane scroll = new JScrollPane(panel);
//scroll.setBorder(null);
wrapper.add(BorderLayout.CENTER, scroll);
return wrapper;
}
private Component initTypePanel() {
JPanel panel = new JPanel(new BorderLayout());
panel.setPreferredSize(new Dimension(200,0));
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(30, 5, 5, 0), REG.getString("meoptype.TITLE")));
this.lm_type = new DefaultListModel<MEOPType>();
this.l_type = new JList<MEOPType>(lm_type);
for (MEOPType t : controller.meopTypes) {
this.lm_type.addElement(t);
}
if(controller.meopTypes.size() == 1) {
l_type.setSelectedIndex(0);
}
this.l_type.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane scroll = new JScrollPane(this.l_type);
panel.add(BorderLayout.CENTER, scroll);
return panel;
}
}

@ -0,0 +1,629 @@
package cn.net.connor.std.processedit.newmeop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.SoaUtil;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemRevisionType;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCPropertyDescriptor;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import com.teamcenter.services.rac.core.DataManagementService;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.processview.KAssignResourceCommand;
import cn.net.connor.std.processedit.util.OptionItem;
import cn.net.connor.std.processedit.util.PrefComponent;
import cn.net.connor.std.processedit.util.ProcessUtil;
public class NewMeopDialogController extends KDialogController {
private NewMeopDialog dialog;
private TCComponentBOMLine targetLine;
private TCComponentItemRevision targetRev;
public static final String PREF_PREFIX = "Connor_AVIC_MEOP_";
public static final String PREF_PREFIX_EXCEL = "Connor_AVIC_MEOPEXCEL_";
public static final String PREF_PROPS = "Connor_AVIC_MEOP_Properties";
public static final String PREF_REL_LOV = "Connor_AVIC_MEOP_LOV_";
public static final String PREF_WORKCENTER_CLS_ID = "Connor_AVIC_MEOP_WorkCenter_Class";
public static final Registry REG = Registry.getRegistry(NewMeopDialogController.class);
protected List<MEOPType> meopTypes = new ArrayList<NewMeopDialogController.MEOPType>();
protected List<PrefComponent> prefComponents = new ArrayList<PrefComponent>();
protected int propCols = 1;
protected PrefComponent shortDescPrefComp;
private KAssignResourceCommand workcenterCmd;
public TCSession session;
public class MEOPType {
protected String type;
protected String disType;
protected String additional;
protected TCComponentItemType itemType;
protected boolean isPrecise;
public MEOPType(TCSession session, String type, String disType, String additional, boolean isPrecise) throws Exception {
this.type = type;
this.disType = disType;
this.additional = additional;
this.isPrecise = isPrecise;
this.itemType = (TCComponentItemType) session.getTypeComponent(type);
if (this.itemType == null) {
throw new Exception(String.format(REG.getString("typenotfound.ERROR1"), type));
}
}
@Override
public String toString() {
return " " + disType;
}
}
public NewMeopDialogController(AbstractAIFApplication app) {
super();
session = (TCSession) app.getSession();
}
@Override
public boolean init() throws Exception {
this.dialog = (NewMeopDialog) aifDialog;
InterfaceAIFComponent comp = app.getTargetComponent();
System.out.println("Select: " + comp);
if (comp != null) {
if (comp instanceof TCComponentBOMLine) {
this.targetLine = (TCComponentBOMLine) comp;
TCComponentItemRevision rev = this.targetLine.getItemRevision();
System.out.println(">> " + rev.getType());
if (ProcessUtil.isMEProcess(session, rev.getItem().getType())) {
// if (rev instanceof TCComponentMEProcessRevision) {
this.targetRev = rev;
}
}
}
if (targetRev == null) {
throw new TCException(REG.getString("selectprocessrev.ERROR"));
}
{
String prefName = PREF_PREFIX + this.targetRev.getType();
String[] prefVals = KUtil.getPrefVals(session, prefName);
int len = KUtil.getLen(prefVals);
for (int i = 0; i < len; i++) {
String type = prefVals[i];
boolean isPrecise = type.startsWith("#");
if (isPrecise) {
type = type.substring(1);
}
String addition = "";
int ind = type.indexOf('=');
if (ind > 0) {
addition = type.substring(ind + 1).replace("\\n", "\n");
type = type.substring(0, ind);
}
String disType = KUtil.getTypeName(session, type);
if (KUtil.isEmpty(disType)) {
System.out.println("Error Config: " + prefVals[i]);
continue;
}
this.meopTypes.add(new MEOPType(session, type, disType, addition, isPrecise));
}
if (this.meopTypes.size() == 0) {
throw new TCException(String.format(REG.getString("prefnotconfiged.ERROR1"), prefName));
}
}
{
String[] prefVals = KUtil.getPrefVals(session, PREF_PROPS);
int len = KUtil.getLen(prefVals);
for (int i = 0; i < len; i++) {
String pref = prefVals[i];
if (pref.length() == 1 && Character.isDigit(pref.charAt(0))) {
int col = pref.charAt(0) - '0';
if (col > 0) {
System.out.println("Reset Proc Col: " + col);
this.propCols = col;
}
continue;
}
PrefComponent prefComp = new PrefComponent(pref, "");
if (prefComp.init(session, targetRev, prefComponents)) {
prefComponents.add(prefComp);
} else {
System.out.println("Error Config: " + pref);
}
}
if (prefComponents.size() == 0) {
throw new TCException(String.format(REG.getString("prefnotconfiged.ERROR1"), PREF_PROPS));
}
for (int i = 0; i < prefComponents.size(); i++) {
PrefComponent prefParent = prefComponents.get(i);
if (prefParent.isLovParent) {
for (int j = 0; j < prefComponents.size(); j++) {
PrefComponent prefChild = prefComponents.get(j);
if (prefParent.lovName.equals(prefChild.lovName) && prefChild.isLovChild) {
prefParent.comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedProvince = (String) prefParent.bigJtf.getText();
if (selectedProvince != null) {
List<String> cities = prefParent.listLov.get(selectedProvince);
// 清空子级控件和数据
prefChild.comboBox.removeAllItems();
prefChild.opHashMap.clear();
prefChild.lovDisRealMap.clear();
prefChild.list.clear();
if (cities != null && !cities.isEmpty()) {
for (String city : cities) {
OptionItem optionItem = new OptionItem(city, "");
prefChild.comboBox.addItem(optionItem);
prefChild.opHashMap.put(city, optionItem);
prefChild.lovDisRealMap.put(city, city);
prefChild.list.add(city);
}
// 关键:不自动选中任何项
prefChild.comboBox.setSelectedIndex(-1);
} else {
// 没有子项时也确保无选中
prefChild.comboBox.setSelectedIndex(-1);
}
} else {
prefChild.comboBox.removeAllItems();
prefChild.comboBox.setSelectedIndex(-1); // 确保无选中
}
}
});
}
}
}
}
String descPropName = REG.getString("shortdesc.PROPNAME");
this.shortDescPrefComp = new PrefComponent(descPropName, "");
if (!shortDescPrefComp.init(session, targetRev, prefComponents)) {
this.shortDescPrefComp = null;
}
}
return true;
}
public void assignId() throws Exception {
MEOPType type = dialog.l_type.getSelectedValue();
if (type == null) {
throw new TCException(REG.getString("selectMeopType.INFO"));
}
TCComponentItemType itemType = type.itemType;
String newId = itemType.getNewID();
System.out.println("New ID: " + type.type + " -> " + newId);
dialog.setAssignId(newId);
}
public int getMeopNo(TCComponentBOMLine line) throws Exception {
// TCComponentItemRevision rev = line.getItemRevision();
// if (rev == null) {
// throw new TCException("Get Revision Failed: " + line);
// }
// TCComponent form = rev.getRelatedComponent("IMAN_master_form_rev");
// if (form == null) {
// throw new TCException("Get RevisionMaster Failed: " + rev);
// }
// form.refresh();
// String seqStr = form.getStringProperty("ac5_OperationNumber");
String seqStr = line.getProperty("bl_sequence_no");
System.out.println("Op Number: " + line + " -> " + seqStr);
int seq = 0;
if (!KUtil.isEmpty(seqStr)) {
try {
seq = Integer.parseInt(seqStr);
} catch (Exception e) {
e.printStackTrace();
}
}
return seq;
}
@SuppressWarnings("deprecation")
public void setMeopNo(TCComponentBOMLine line, int meopNo) throws Exception {
System.out.println("Set Op Number: " + line + " -> " + meopNo);
line.lock();
try {
line.setProperty("bl_sequence_no", meopNo + "");
line.save();
} finally {
line.unlock();
}
targetLine.refresh();
// if(meopNo<0) {
// return;
// }
// TCComponentItemRevision rev = line.getItemRevision();
// if (rev == null) {
// throw new TCException("Get Revision Failed: " + line);
// }
// TCComponent form = rev.getRelatedComponent("IMAN_master_form_rev");
// if (form == null) {
// throw new TCException("Get RevisionMaster Failed: " + rev);
// }
// form.refresh();
// form.lock();
// try {
// form.setStringProperty("ac5_OperationNumber", meopNo + "");
// form.save();
// form.refresh();
// } finally {
// form.unlock();
// }
}
public void assignMeopNo() throws Exception {
targetLine.refresh();
AIFComponentContext[] cc = targetLine.getChildren();
int maxSeq = 0;
int len = KUtil.getLen(cc);
for (int i = 0; i < len; i++) {
TCComponentBOMLine cLine = (TCComponentBOMLine) cc[i].getComponent();
int seq = getMeopNo(cLine);
maxSeq = Math.max(seq, maxSeq);
}
maxSeq += 10;
System.out.println("New Sequence: " + maxSeq);
dialog.setMeopNo("" + maxSeq);
}
public void insertMeopNo() throws Exception {
Map<String, String> propData = new MeopNoDialog(dialog, true, new MeopNoDialogController(app, targetLine)).getMeopInfo();
System.out.println("Prop Info: " + propData);
if (propData == null || propData.size() == 0) {
return;
}
for (PrefComponent comp : prefComponents) {
String key = comp.getPropConfig();
if (propData.containsKey(key)) {
String value = propData.get(key);
System.out.println(String.format("set [%s]=[%s]", key, value));
comp.setValue(value);
}
}
}
public void doCreate() throws Exception {
MEOPType typeComp = dialog.l_type.getSelectedValue();
if (typeComp == null) {
throw new TCException(REG.getString("selectMeopType.INFO"));
}
TCComponentItemType itemType = typeComp.itemType;
// Check Require
// if (!checkRequire()) {
// return;
// }
String type = itemType.getName();
System.out.println("Select Type: " + type);
if (KUtil.isEmpty(type)) {
throw new TCException(REG.getString("selectType.INFO"));
}
if (!checkRequire()) {
return;
}
String checkCombox = checkCombox();
System.out.println("checkCombox==="+checkCombox);
if (!checkCombox.equals("")) {
throw new Exception(checkCombox);
}
TCComponentItemRevisionType revType = itemType.getItemRevisionType();
String revTypeName = revType.getName();
String itemMasterTypeName = type + " Master";
String revMasterTypeName = revTypeName + " Master";
if (session.getTypeComponent(itemMasterTypeName) == null) {
itemMasterTypeName = type + "Master";
}
if (session.getTypeComponent(revMasterTypeName) == null) {
revMasterTypeName = revTypeName + "Master";
}
TCComponentType revMasterType = session.getTypeComponent(revMasterTypeName);
TCComponentType itemMasterType = session.getTypeComponent(itemMasterTypeName);
System.out.println("Revision Type: " + type);
System.out.println("Item Master Type: " + itemMasterTypeName);
System.out.println("Revision Master Type: " + revMasterTypeName);
Map<String, String> revPropMap = new HashMap<>();
Map<String, String> revMasterPropMap = new HashMap<>();
Map<String, String> itemPropMap = new HashMap<>();
Map<String, String> itemMasterPropMap = new HashMap<>();
Map<String, Double> revPropMapD = new HashMap<>();
Map<String, Double> revMasterPropMapD = new HashMap<>();
Map<String, Double> itemPropMapD = new HashMap<>();
Map<String, Double> itemMasterPropMapD = new HashMap<>();
Map<String, String> bomLinePropMap = new HashMap<>();
for (PrefComponent prefComponent : this.prefComponents) {
// KUtil.initPropMap(prefComponent.propConfig, prefComponent.getValue(),
// itemPropMap, itemMasterPropMap, revPropMap, revMasterPropMap,
// bomLinePropMap);
String propConfig = prefComponent.propConfig;
String value = prefComponent.getValue();
if (KUtil.isEmpty(propConfig)) {
continue;
}
String propFrom = null, propName = null;
String[] split = propConfig.split("\\.");
if (KUtil.getLen(split) == 2) {
propFrom = split[0].trim().toUpperCase();
propName = split[1].trim();
}
if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) {
continue;
}
TCComponentType targetType = null;
Map<String, String> target;
Map<String, Double> targetD = null;
if ("ITEM".equals(propFrom)) {
target = itemPropMap;
targetD = itemPropMapD;
targetType = itemType;
// System.out.println(">> ITEM PROP: " + propName + " = " + value);
} else if ("REV".equals(propFrom)) {
// System.out.println(">> REV PROP: " + propName + " = " + value);
target = revPropMap;
targetD = revPropMapD;
targetType = revType;
} else if ("ITEMMASTER".equals(propFrom)) {
// System.out.println(">> ITEMMASTER PROP: " + propName + " = " + value);
target = itemMasterPropMap;
targetD = itemMasterPropMapD;
targetType = itemMasterType;
} else if ("REVMASTER".equals(propFrom)) {
// System.out.println(">> REVMASTER PROP: " + propName + " = " + value);
target = revMasterPropMap;
targetD = revMasterPropMapD;
targetType = revMasterType;
} else if ("BOMLINE".equals(propFrom)) {
System.out.println(">> BOMLINE PROP: " + propName + " = " + value);
target = bomLinePropMap;
} else {
throw new TCException(String.format(KUtil.REG.getString("proplocationnotdefined.ERROR1"), propFrom));
}
if (target == null && targetD == null) {
return;
}
if (targetType != null) {
TCPropertyDescriptor desc = targetType.getPropDesc(propName);
// System.out.println(propName+" - "+desc.getType());
if (desc != null && desc.getType() == TCPropertyDescriptor.SERVER_PROP_double) {
if (!KUtil.isEmpty(value)) {
double d = Double.parseDouble(value);
targetD.put(propName, d);
}
continue;
}
}
target.put(propName, value);
}
String bl_sequence_no = bomLinePropMap.get("bl_sequence_no");
int n = 0;
for(AIFComponentContext l : targetLine.getChildren()) {
TCComponentBOMLine line = (TCComponentBOMLine) l.getComponent();
if(line.getProperty("bl_sequence_no").equals(bl_sequence_no))
n++;
}
if(n >= 3) {
throw new TCException(REG.getString("sequence.ERROR"));
}
String propType = "ac5_Type";
// propType = "object_desc"; //
// revMasterPropMap.remove("nhl8_ProShortDescss"); //TODO
if (revMasterPropMap.containsKey(propType)) {
String ac5Type = revMasterPropMap.get(propType);
System.out.println(propType + ": " + ac5Type);
if (!KUtil.isEmpty(ac5Type)) {
revPropMap.put("item_revision_id", ac5Type + "00");
}
}
CreateInput revMasterInput = new CreateInput();
revMasterInput.boName = revMasterTypeName;
revMasterInput.stringProps = revMasterPropMap;
revMasterInput.doubleProps = revMasterPropMapD;
CreateInput itemMasterInput = new CreateInput();
itemMasterInput.boName = itemMasterTypeName;
itemMasterInput.stringProps = itemMasterPropMap;
itemMasterInput.doubleProps = itemMasterPropMapD;
CreateInput revInput = new CreateInput();
revInput.boName = revTypeName;
revInput.stringProps = revPropMap;
revInput.doubleProps = revPropMapD;
Map<String, CreateInput[]> revMasterInfoMap = new HashMap<>();
revMasterInfoMap.put("IMAN_master_form_rev", new CreateInput[] { revMasterInput });
revInput.compoundCreateInput = revMasterInfoMap;
// create rev
CreateInput itemInput = new CreateInput();
itemInput.boName = type;
itemInput.stringProps = itemPropMap;
itemInput.doubleProps = itemPropMapD;
Map<String, CreateInput[]> revInfoMap = new HashMap<>();
revInfoMap.put("revision", new CreateInput[] { revInput });
revInfoMap.put("IMAN_master_form", new CreateInput[] { itemMasterInput });
itemInput.compoundCreateInput = revInfoMap;
// create info
CreateIn cI = new CreateIn();
cI.clientId = "CreateItem";
cI.data = itemInput;
// service
DataManagementService service = DataManagementService.getService(session);
// create
CreateResponse resp = service.createObjects(new CreateIn[] { cI });
SoaUtil.checkPartialErrors(resp.serviceData);
CreateOut[] cOs = resp.output;
TCComponentItem newItem = null;
if (cOs.length > 0) {
for (TCComponent s : cOs[0].objects) {
if (s instanceof TCComponentItem) {
newItem = (TCComponentItem) s;
}
}
}
System.out.println("New Item: " + newItem);
if (newItem == null) {
throw new TCException(REG.getString("createprocess.ERROR"));
}
newItem.refresh();
TCComponentItemRevision newRev = newItem.getLatestItemRevision();
System.out.println("New Rev: " + newRev);
TCComponentBOMLine newLine = this.targetLine.add(newItem, newRev, null, false);
if (bomLinePropMap.size() > 0) {
System.out.println("Set Bom Property: " + bomLinePropMap);
newLine.setProperties(bomLinePropMap);
newLine.refresh();
}
targetLine.setPrecision(true);
TCComponentItemType t = (TCComponentItemType) session.getTypeService().getTypeComponent("Item");
TCComponentItem item1 = t.findItems("000001")[0];
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow window = bomWinType.create(null);
TCComponentBOMLine newBom = window.setWindowTopLine(null, newRev, null, null);
TCComponentBOMLine newnewLine = newBom.add(item1, item1.getLatestItemRevision(), null, false);
window.save();
newnewLine.cut();
window.save();
window.close();
if(workcenterCmd != null) {
System.out.println("Add Workcenter: " + workcenterCmd.getSelected());
workcenterCmd.doAssign(newLine);
}
session.queueOperation(new AbstractAIFOperation() {
@Override
public void executeOperation() throws Exception {
try {
System.out.println("Switch to Precise: " + typeComp.isPrecise);
newLine.setPrecision(typeComp.isPrecise);
} catch (Exception e) {
e.printStackTrace();
}
targetLine.refresh();
}
});
dialog.setAssignId(null);
dialog.setMeopNo(null);
for (PrefComponent c : this.prefComponents) {
c.setValue(null);
}
if (this.shortDescPrefComp != null) {
this.shortDescPrefComp.setValue(null);
}
clearWorkCenter();
}
private boolean checkRequire() {
List<String> requireTitles = new ArrayList<String>();
for (PrefComponent prefComponent : this.prefComponents) {
if (!prefComponent.checkRequire()) {
requireTitles.add(prefComponent.title.replace(" ", "").replace(":", "").replace(REG.getString("CN_SYMBEL4"), "").replace(REG.getString("CN_SYMBEL5"), ""));
}
}
// if (workcenterCmd!=null && this.workcenterCmd.getSelected() == null) {
// requireTitles.add(REG.getString("workcenter"));
// }
if (requireTitles.size() > 0) {
MessageBox.post(dialog, String.format(REG.getString("requireprop.INFO1"), requireTitles.toString()), "", MessageBox.WARNING);
return false;
}
return true;
}
public AbstractAIFApplication getApp() {
return app;
}
public void chooseWorkCenter() throws Exception {
if (this.workcenterCmd == null) {
MEOPType typeComp = dialog.l_type.getSelectedValue();
if (typeComp == null) {
throw new TCException(REG.getString("selectMeopType.INFO"));
}
TCComponentItemType itemType = typeComp.itemType;
TCComponentItem item = new TCComponentItem() {
@Override
public TCComponentItemType getTypeComponent() {
return itemType;
}
@Override
public TCSession getSession() {
return session;
}
@Override
public String[] getClassNameHierarchy() throws TCException {
return itemType.getClassNameHierarchy();
}
};
System.out.println("TypeName: " + itemType);
this.workcenterCmd = new KAssignResourceCommand(KUtil.getPrefVal(session, NewMeopDialogController.PREF_WORKCENTER_CLS_ID), item);
}
this.workcenterCmd.executeModal();
TCComponent comp = workcenterCmd.getSelected();
if(dialog.tf_WorkCenter != null)
dialog.tf_WorkCenter.setText(comp == null ? "" : comp.toString());
}
public void clearWorkCenter() {
workcenterCmd = null;
if(dialog.tf_WorkCenter != null)
dialog.tf_WorkCenter.setText("");
}
private String checkCombox() {
List<String> requireTitles = new ArrayList<String>();
for (PrefComponent prefComponent : prefComponents) {
if (!prefComponent.checkCombox()) {
requireTitles.add(prefComponent.title+"请选择下拉值!");
}
}
if (requireTitles.size() > 0) {
//MessageBox.post(dialog, String.format(REG.getString("requireprop.INFO1"), requireTitles.toString()), "", MessageBox.WARNING);
return requireTitles.toString();
}
return "";
}
}

@ -0,0 +1,21 @@
shortdesc.PROPNAME=$\u5DE5\u827A\u77ED\u63CF\u8FF0=revmaster.object_desc
#shortdesc.PROPNAME=$\u5DE5\u827A\u77ED\u63CF\u8FF0=revmaster.object_desc
selectMeopType.INFO=\u8BF7\u5148\u9009\u62E9\u5DE5\u5E8F\u7C7B\u578B
newmeop.TITLE=\u521B\u5EFA\u5DE5\u5E8F
ok=\u786E\u5B9A
cancel=\u53D6\u6D88
assign=\u6307\u6D3E
select=\u9009\u62E9
shenqing=\u7533\u8BF7
insert=\u63D2\u5165
meoptype.TITLE=\u5DE5\u5E8F\u7C7B\u578B
meinfo.TITLE=\u5DE5\u827A/\u5DE5\u5E8F\u4FE1\u606F
applymeopno.TITLE=\u7533\u8BF7\u5DE5\u5E8F\u53F7
prefnotconfiged.ERROR1=\u9996\u9009\u9879\u672A\u914D\u7F6E\uFF1A%s
typenotfound.ERROR1=\u672A\u5B9A\u4E49\u5BF9\u8C61\u7C7B\u578B\uFF1A%s
selectprocessrev.ERROR=\u8BF7\u9009\u62E9\u5DE5\u827A\u8FDB\u884C\u64CD\u4F5C
selectType.INFO=\u8BF7\u9009\u62E9\u8981\u521B\u5EFA\u7684\u5BF9\u8C61\u7C7B\u578B
createprocess.ERROR=\u521B\u5EFA\u5DE5\u827A\u5F02\u5E38
requireprop.INFO1=\u8BF7\u586B\u5199\u5FC5\u586B\u5C5E\u6027\uFF1A\: %s
workcenter=\u5DE5\u4F5C\u4E2D\u5FC3
sequence.ERROR=\u540C\u4E00\u5DE5\u827A\u8DEF\u7EBF\u4E0B\u4E0D\u5141\u8BB8\u5B58\u57283\u6761\u4EE5\u4E0A\u76F8\u540C\u5DE5\u5E8F\u53F7\u7684\u5DE5\u5E8F

@ -0,0 +1,332 @@
package cn.net.connor.std.processedit.newmeprocess;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.teamcenter.rac.kernel.ListOfValuesInfo;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCPropertyDescriptor;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.soa.client.model.LovValue;
public class LovUtil {
public static void setTCArrProperty(TCProperty property, String[] value) {
try {
if (value == null) {
return;
}
TCPropertyDescriptor descriptor = property.getPropertyDescriptor();
boolean isArray = descriptor.isArray();
if (isArray) {
property.setStringValueArray(value);
}
} catch (Exception e) {
System.out.println("赋值异常:"+e);
}
}
/**
*
* @param property
* @param value
* @throws TCException
*/
public static void setTCProperty(TCProperty property, String value) {
try {
TCPropertyDescriptor descriptor = property.getPropertyDescriptor();
boolean isArray = descriptor.isArray();
if (!isArray) {
switch (descriptor.getType()) {
case TCProperty.PROP_string:
case TCProperty.PROP_long_string:
property.setStringValueData(value);
break;
case TCProperty.PROP_char:
if (value.length() > 0) {
property.setCharValueData(value.charAt(0));
}
break;
case TCProperty.PROP_double:
property.setDoubleValueData(Double.parseDouble(value));
break;
case TCProperty.PROP_float:
property.setFloatValueData(Float.parseFloat(value));
break;
case TCProperty.PROP_int:
case TCProperty.PROP_short:
property.setIntValueData(Integer.parseInt(value));
break;
case TCProperty.PROP_logical:
property.setLogicalValueData(Boolean.parseBoolean(value));
break;
case TCProperty.PROP_date:
try {
if (!value.isEmpty()) {
property.setDateValueData(new SimpleDateFormat("yyyy/MM/dd").parse(value));
}
} catch (ParseException e) {
e.printStackTrace();
}
break;
}
} else {
if (value.indexOf(",") > 0) {
property.setStringValueArray(value.split(","));
} else {
property.setStringValueArray(new String[] { value });
}
// System.out.println("对应的属性为数组类型,不予以处理");
}
} catch (Exception e) {
System.out.println("赋值异常:"+ e);
}
}
public static Map<String, String[]> getLovThree(TCSession session, String lovName) {
Map<String, String[]> notSaveAsMap = new HashMap<String, String[]>();
Map<String, String[]> SaveAsMap = new HashMap<String, String[]>();
notSaveAsMap.clear();
SaveAsMap.clear();
try {
TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(session, lovName);
if (lov != null) {
ListOfValuesInfo lovInfo = lov.getListOfValues();
System.out.println("lovInfo:" + lovInfo);
String[] size = lovInfo.getLOVDisplayValues();
for (int i = 0; i < size.length; i++) {
TCComponentListOfValues Component = lovInfo.getListOfFilters()[i];
ListOfValuesInfo child = Component.getListOfValues();
String[] arr = child.getLOVDisplayValues();
System.out.println("size:" + size[i]);
System.out.println("Component:" + Component);
System.out.println("arr:" + arr.length);
notSaveAsMap.put(size[i], arr);
for (int j = 0; j < arr.length; j++) {
// if(!"H8_ckxd_LOV".equals(child.toString())) {
// continue;
// }
TCComponentListOfValues children = child.getListOfFilters()[j];
ListOfValuesInfo childs = children.getListOfValues();
String[] number = childs.getLOVDisplayValues();
SaveAsMap.put(arr[j], number);
}
}
return SaveAsMap;
}
} catch (TCException e) {
e.printStackTrace();
}
return null;
}
public static Map<String, String> getLovThreeRealValue(TCSession session, String lovName) {
Map<String, String> SaveAsMap = new HashMap<String, String>();
SaveAsMap.clear();
try {
TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(session, lovName);
if (lov != null) {
ListOfValuesInfo lovInfo = lov.getListOfValues();
String[] size = lovInfo.getLOVDisplayValues();
for (int i = 0; i < size.length; i++) {
TCComponentListOfValues Component = lovInfo.getListOfFilters()[i];
ListOfValuesInfo child = Component.getListOfValues();
String[] arr = child.getLOVDisplayValues();
for (int j = 0; j < arr.length; j++) {
TCComponentListOfValues children = child.getListOfFilters()[j];
ListOfValuesInfo childs = children.getListOfValues();
String[] number = childs.getLOVDisplayValues();
List<LovValue> values = childs.getValues();
for (int k = 0; k < number.length; k++) {
SaveAsMap.put(number[k], values.get(k).getStringValue());
}
}
}
return SaveAsMap;
}
} catch (TCException e) {
e.printStackTrace();
}
return null;
}
public static Map<String, String[]> getLovTWO(TCSession session, String lovName) {
Map<String, String[]> notSaveAsMap = new HashMap<String, String[]>();
Map<String, String[]> SaveAsMap = new HashMap<String, String[]>();
notSaveAsMap.clear();
SaveAsMap.clear();
try {
TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(session, lovName);
if (lov != null) {
ListOfValuesInfo lovInfo = lov.getListOfValues();
System.out.println("lovInfo:" + lovInfo);
String[] size = lovInfo.getLOVDisplayValues();
for (int i = 0; i < size.length; i++) {
TCComponentListOfValues Component = lovInfo.getListOfFilters()[i];
ListOfValuesInfo child = Component.getListOfValues();
String[] arr = child.getLOVDisplayValues();
System.out.println("size:" + size[i]);
System.out.println("Component:" + Component);
System.out.println("arr:" + arr.length);
notSaveAsMap.put(size[i], arr);
}
return notSaveAsMap;
}
} catch (TCException e) {
e.printStackTrace();
}
return null;
}
public static Map<String, String> getPropertyone(TCSession session, String lovName) {
Map<String, String> notSaveAsMap = new HashMap<String, String>();
notSaveAsMap.clear();
try {
TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(session, lovName);
if (lov != null) {
ListOfValuesInfo lovInfo = lov.getListOfValues();
System.out.println("lovInfo:" + lovInfo);
String[] size = lovInfo.getStringListOfValues();
String[] arr = lovInfo.getLOVDisplayValues();
for (int i = 0; i < size.length; i++) {
System.out.println("size:" + size[i]);
notSaveAsMap.put(arr[i], size[i]);
}
return notSaveAsMap;
}
} catch (TCException e) {
e.printStackTrace();
}
return null;
}
public static Map<String, String> getLov(TCSession session, String lovName) {
Map<String, String> SaveAsMap = new LinkedHashMap<String, String>();
SaveAsMap.clear();
try {
TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(session, lovName);
if (lov != null) {
ListOfValuesInfo lovInfo = lov.getListOfValues();
System.out.println("lovInfo:" + lovInfo);
String[] size = lovInfo.getLOVDisplayValues();
for (int i = 0; i < size.length; i++) {
TCComponentListOfValues Component = lovInfo.getListOfFilters()[i];
ListOfValuesInfo child = Component.getListOfValues();
System.out.println("size:" + size[i]);
System.out.println("Component:" + Component);
SaveAsMap.put(size[i], Component.toString());
}
return SaveAsMap;
}
} catch (TCException e) {
e.printStackTrace();
}
return null;
}
public static Map<String, String> getPropertytwo(TCSession session, String lovName) {
Map<String, String> SaveAsMap = new HashMap<String, String>();
SaveAsMap.clear();
try {
TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(session, lovName);
if (lov != null) {
ListOfValuesInfo lovInfo = lov.getListOfValues();
System.out.println("lovInfo:" + lovInfo);
String[] size = lovInfo.getLOVDisplayValues();
for (int i = 0; i < size.length; i++) {
TCComponentListOfValues Component = lovInfo.getListOfFilters()[i];
ListOfValuesInfo child = Component.getListOfValues();
String[] arr = child.getStringListOfValues();
String[] arrs = child.getLOVDisplayValues();
System.out.println("size:" + size[i]);
System.out.println("Component:" + Component);
System.out.println("child:" + child);
for (int j = 0; j < arr.length; j++) {
System.out.println("arr:" + arr[j]);
System.out.println("arrs:" + arrs[j]);
SaveAsMap.put(arrs[j], arr[j]);
}
}
System.out.println(SaveAsMap.toString());
return SaveAsMap;
}
} catch (TCException e) {
e.printStackTrace();
}
return null;
}
public static Map<String, String> getPropertythree(TCSession session, String lovName) {
Map<String, String> SaveAsMap = new HashMap<String, String>();
SaveAsMap.clear();
try {
TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(session, lovName);
if (lov != null) {
ListOfValuesInfo lovInfo = lov.getListOfValues();
System.out.println("lovInfo:" + lovInfo);
String[] size = lovInfo.getLOVDisplayValues();
for (int i = 0; i < size.length; i++) {
TCComponentListOfValues Component = lovInfo.getListOfFilters()[i];
ListOfValuesInfo child = Component.getListOfValues();
String[] arr = child.getStringListOfValues();
System.out.println("size:" + size[i]);
System.out.println("Component:" + Component);
System.out.println("arr:" + arr.length);
for (int j = 0; j < arr.length; j++) {
TCComponentListOfValues children = Component.getListOfFilters()[j];
ListOfValuesInfo childs = children.getListOfValues();
String[] number = childs.getStringListOfValues();
String[] numbers = childs.getLOVDisplayValues();
for (int k = 0; k < number.length; k++) {
SaveAsMap.put(numbers[k], number[k]);
}
}
}
return SaveAsMap;
}
} catch (TCException e) {
e.printStackTrace();
}
return null;
}
/**
* LOV
*
* @param session
* @param lovName
* @return
*/
public static String getLovRealValue(TCSession session, String lovName, String displayValue) {
try {
TCComponentListOfValues lov = TCComponentListOfValuesType.findLOVByName(session, lovName);
if (lov != null) {
ListOfValuesInfo lovInfo = lov.getListOfValues();
System.out.println("lovInfo:" + lovInfo);
String realVal = (String) lovInfo.getRealValue(displayValue);
return realVal;
}
} catch (TCException e) {
System.out.println("取lov的真实值warn"+e);
}
return null;
}
}

@ -0,0 +1,161 @@
package cn.net.connor.std.processedit.newmeprocess;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import cn.net.connor.std.aifrcp.KDialog;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KUtil;
@SuppressWarnings("serial")
public class NewProcessDialog extends KDialog {
private JButton b_ok;
private JButton b_cel;
private NewProcessDialogController controller;
private static final Registry REG = Registry.getRegistry(NewProcessDialog.class);
public NewProcessDialog(KDialogController controller) {
super(controller);
this.controller = (NewProcessDialogController) controller;
}
private void setCompEnabled(boolean b) {
b_ok.setEnabled(b);
b_cel.setEnabled(b);
}
@Override
protected void addListeners() {
this.b_cel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
disposeDialog();
}
});
this.b_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Thread(new Runnable() {
@Override
public void run() {
setCompEnabled(false);
try {
controller.doCreate();
disposeDialog();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(NewProcessDialog.this, e);
}
setCompEnabled(true);
}
}).start();
}
});
}
@Override
protected void initUI() {
this.setTitle(REG.getString("newprocess.TITLE"));
this.setPreferredSize(new Dimension(800, 780));
this.setMinimumSize(new Dimension(800, 700));
this.setLayout(new BorderLayout());
JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
pane.setResizeWeight(0.6);
pane.setTopComponent(initProcPanel());
pane.setBottomComponent(initItemPanel());
pane.setBorder(null);
this.add(BorderLayout.CENTER, pane);
this.add(BorderLayout.SOUTH, initBtnPanel());
}
private Component initBtnPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 5));
this.b_ok = new JButton(REG.getString("ok"));
this.b_cel = new JButton(REG.getString("cancel"));
panel.add(b_ok);
panel.add(b_cel);
return panel;
}
private Component initProcPanel() {
String title = REG.getString("procgroup.TITLE");
List<PrefComponent> comps = controller.procComps;
int colCnt = controller.procCols;
JPanel wrapper = new JPanel(new BorderLayout());
wrapper.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(30,5,5,5), title));
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints s = getGridBagConstraints(0, 0, new Insets(4, 0, 4, 25));
int size = comps.size();
int compIndex = 0;
for(int i=0;i<size;i++) {
PrefComponent prefComponent = comps.get(i);
if(prefComponent.isInvisible()) {
continue;
}
// if(compIndex%colCnt==0) {
// KUtil.newRow(panel, prefComponent.getPanel(), s, 1);
// }else {
// KUtil.addCol(panel, prefComponent.getPanel(), s, 1, 0);
// }
KUtil.newRow(panel, prefComponent.getPanel(), s, 1);
compIndex++;
}
s.weighty = 1;
KUtil.newRow(panel, new JLabel(""), s, 1);
JScrollPane scroll = new JScrollPane(panel);
scroll.setBorder(null);
wrapper.add(BorderLayout.CENTER, scroll);
return wrapper;
}
private Component initItemPanel() {
String title = REG.getString("itemgroup.TITLE");
List<PrefComponent> comps = controller.itemComps;
int colCnt = controller.itemCols;
JPanel wrapper = new JPanel(new BorderLayout());
wrapper.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(30,5,5,5), title));
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints s = getGridBagConstraints(0, 0, new Insets(4, 0, 4, 25));
int size = comps.size();
int compIndex = 0;
for(int i=0;i<size;i++) {
PrefComponent prefComponent = comps.get(i);
if(prefComponent.isInvisible()) {
continue;
}
// if(compIndex%colCnt==0) {
// KUtil.newRow(panel, prefComponent.getPanel(), s, 1);
// }else {
// KUtil.addCol(panel, prefComponent.getPanel(), s, 1, 0);
// }
KUtil.newRow(panel, prefComponent.getPanel(), s, 1);
compIndex++;
}
s.weighty = 1;
KUtil.newRow(panel, new JLabel(""), s, 1);
JScrollPane scroll = new JScrollPane(panel);
scroll.setBorder(null);
wrapper.add(BorderLayout.CENTER, scroll);
return wrapper;
}
}

@ -0,0 +1,474 @@
package cn.net.connor.std.processedit.newmeprocess;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.SoaUtil;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemRevisionType;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.Registry;
import com.teamcenter.services.rac.core.DataManagementService;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse;
import cn.net.connor.std.aifrcp.KDialogController;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.util.OptionItem;
import cn.net.connor.std.processedit.util.ProcessUtil;
public class NewProcessDialogController extends KDialogController {
private NewProcessDialog dialog;
private TCComponentItemRevision targetRev;
public static final String PREF_PREFIX = "Connor_AVIC_";
public static final String PREF_GROUP_SPLITTER = "---";
public static final String PROP_OBJECT_TYPE = "object_type";
protected List<PrefComponent> procComps = new ArrayList<PrefComponent>();
protected List<PrefComponent> itemComps = new ArrayList<PrefComponent>();
private PrefComponent objectTypeComp;
protected int procCols = 2;
protected int itemCols = 2;
public static final String PREF_PROCTYPE_SYMBOL = "Connor_AVIC_ProcType_Symbol";
private Map<String, String> procTypeSymbolMap = new HashMap<String, String>();
private Map<PrefComponent, String> symbolCompMap = new HashMap<PrefComponent, String>();
public static final String FLAG_TYPE_SYMBOL = "[PROC_TYPE]";
private static final Registry REG = Registry.getRegistry(NewProcessDialogController.class);
public NewProcessDialogController(AbstractAIFApplication app) {
super();
}
@Override
public boolean init() throws Exception {
this.dialog = (NewProcessDialog) aifDialog;
InterfaceAIFComponent comp = app.getTargetComponent();
if (comp == null || !(comp instanceof TCComponentItemRevision)) {
throw new Exception(REG.getString("selectnewprocesstarget.ERROR"));
}
this.targetRev = (TCComponentItemRevision) comp;
String revType = this.targetRev.getType();
System.out.println("Select Rev: " + this.targetRev + "| " + revType);
String prefName = PREF_PREFIX + revType;
System.out.println("Load Preference: " + prefName);
String[] prefVals = KUtil.getPrefVals(session, prefName);
int len = KUtil.getLen(prefVals);
if (len == 0) {
System.out.println(String.format(REG.getString("prefnotconfiged.ERROR1"), prefName));
throw new TCException(REG.getString("selectnewprocesstarget.ERROR"));
}
/*if (!"NHL8_VirtualPart".equals(this.targetRev.getItem().getType())) {
TCComponent[] statusList = this.targetRev.getReferenceListProperty("release_status_list");
System.out.println("Check Release Status: " + Arrays.toString(statusList));
if (KUtil.getLen(statusList) < 1) {
MessageBox.post(REG.getString("revreleased.ERROR"), "", MessageBox.WARNING);
return false;
}
}*/
List<PrefComponent> compList = procComps;
for (int i = 0; i < len; i++) {
String pref = prefVals[i];
if (pref.length() == 1 && Character.isDigit(pref.charAt(0))) {
if (compList == itemComps) {
int col = pref.charAt(0) - '0';
if (col > 0) {
System.out.println("Reset Item Col: " + col);
itemCols = col;
}
} else if (compList == procComps) {
int col = pref.charAt(0) - '0';
if (col > 0) {
System.out.println("Reset Proc Col: " + col);
procCols = col;
}
}
continue;
}
if (pref.startsWith(PREF_GROUP_SPLITTER)) {
compList = itemComps;
continue;
}
PrefComponent prefComp = new PrefComponent(pref, this.targetRev);
if (prefComp.init(session)) {
if (PROP_OBJECT_TYPE.equals(prefComp.propConfig)) {
this.objectTypeComp = prefComp;
System.out.println("objectTypeComp.lov.length=="+objectTypeComp.lov.length);
if(objectTypeComp.comboBox != null && objectTypeComp.lov.length == 1)
{
objectTypeComp.comboBox.setSelectedIndex(1);
}
}
compList.add(prefComp);
} else {
System.out.println("Error Config: " + pref);
}
}
if (procComps.size() + itemComps.size() == 0) {
throw new Exception(String.format(REG.getString("prefnotconfiged.ERROR1"), prefName));
}
for (PrefComponent c : procComps) {
if (c.textField != null && c.getValue() != null && c.getValue().contains(FLAG_TYPE_SYMBOL)) {
this.symbolCompMap.put(c, c.getValue());
c.textField.setText(c.getValue().replace(FLAG_TYPE_SYMBOL, ""));
}
}
for (PrefComponent c : itemComps) {
if (c.textField != null && c.getValue() != null && c.getValue().contains(FLAG_TYPE_SYMBOL)) {
this.symbolCompMap.put(c, c.getValue());
c.textField.setText(c.getValue().replace(FLAG_TYPE_SYMBOL, ""));
}
}
for (int i = 0; i < itemComps.size(); i++) {
PrefComponent prefParent = itemComps.get(i);
if (prefParent.isLovParent) {
for (int j = 0; j < itemComps.size(); j++) {
PrefComponent prefChild = itemComps.get(j);
if (prefParent.lovName.equals(prefChild.lovName) && prefChild.isLovChild) {
prefParent.comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedProvince = (String) prefParent.bigJtf.getText();
if (selectedProvince != null) {
List<String> cities = prefParent.listLov.get(selectedProvince);
// 清空子级控件和数据
prefChild.comboBox.removeAllItems();
prefChild.opHashMap.clear();
prefChild.lovDisRealMap.clear();
prefChild.list.clear();
if (cities != null && !cities.isEmpty()) {
for (String city : cities) {
OptionItem optionItem = new OptionItem(city, "");
prefChild.comboBox.addItem(optionItem);
prefChild.opHashMap.put(city, optionItem);
prefChild.lovDisRealMap.put(city, city);
prefChild.list.add(city);
}
// 关键:不自动选中任何项
prefChild.comboBox.setSelectedIndex(-1);
} else {
// 没有子项时也确保无选中
prefChild.comboBox.setSelectedIndex(-1);
}
} else {
prefChild.comboBox.removeAllItems();
prefChild.comboBox.setSelectedIndex(-1); // 确保无选中
}
}
});
}
}
}
}
for (int i = 0; i < procComps.size(); i++) {
PrefComponent prefParent = procComps.get(i);
if (prefParent.isLovParent) {
for (int j = 0; j < procComps.size(); j++) {
PrefComponent prefChild = procComps.get(j);
if (prefParent.lovName.equals(prefChild.lovName) && prefChild.isLovChild) {
prefParent.comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedProvince = (String) prefParent.bigJtf.getText();
if (selectedProvince != null) {
List<String> cities = prefParent.listLov.get(selectedProvince);
// 清空子级控件和数据
prefChild.comboBox.removeAllItems();
prefChild.opHashMap.clear();
prefChild.lovDisRealMap.clear();
prefChild.list.clear();
if (cities != null && !cities.isEmpty()) {
for (String city : cities) {
OptionItem optionItem = new OptionItem(city, "");
prefChild.comboBox.addItem(optionItem);
prefChild.opHashMap.put(city, optionItem);
prefChild.lovDisRealMap.put(city, city);
prefChild.list.add(city);
}
// 关键:不自动选中任何项
prefChild.comboBox.setSelectedIndex(-1);
} else {
// 没有子项时也确保无选中
prefChild.comboBox.setSelectedIndex(-1);
}
} else {
prefChild.comboBox.removeAllItems();
prefChild.comboBox.setSelectedIndex(-1); // 确保无选中
}
}
});
}
}
}
}
{
String[] prefVals2 = KUtil.getPrefVals(session, PREF_PROCTYPE_SYMBOL);
int len2 = KUtil.getLen(prefVals2);
for (int i = 0; i < len2; i++) {
String pref = prefVals2[i];
int ind = pref.indexOf('=');
if (ind > 0) {
String type = pref.substring(0, ind);
String symbol = pref.substring(ind + 1);
System.out.println("Type Symbol: " + type + " -> " + symbol);
this.procTypeSymbolMap.put(type, symbol);
}
}
}
if (this.symbolCompMap.size() > 0 && this.objectTypeComp != null && this.objectTypeComp.comboBox != null) {
this.objectTypeComp.comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String type = objectTypeComp.getValue();
String symbol = procTypeSymbolMap.containsKey(type) ? procTypeSymbolMap.get(type) : "";
System.out.println("Select Type: " + type + " -> " + symbol);
for (PrefComponent c : symbolCompMap.keySet()) {
String text = symbolCompMap.get(c);
System.out.println(text);
text = text.replace(FLAG_TYPE_SYMBOL, symbol);
c.textField.setText(text);
}
}
});
}
return true;
}
public void doCreate() throws Exception {
if (this.objectTypeComp == null) {
throw new Exception(REG.getString("typecompnotfound.ERROR"));
}
String type = this.objectTypeComp.getValue();
System.out.println("Select Type: " + type);
if (KUtil.isEmpty(type)) {
throw new Exception(REG.getString("selectType.INFO"));
}
String relName = this.objectTypeComp.getAddtionalValue();
System.out.println("Create Relation: " + relName);
String archiveRelation = "";
if(KUtil.isEmpty(relName)) {
throw new Exception(REG.getString("typecompnotfound.ERROR"));
}
int ind = relName.indexOf('-');
if (ind > 0) {
archiveRelation = relName.substring(ind + 1);
relName = relName.substring(0, ind);
}
if (KUtil.isEmpty(archiveRelation)) {
throw new Exception(REG.getString("typecompnotfound.ERROR"));
}
if(type.equals("LD6_MEProcessCr")) {
AIFComponentContext[] cs = ((TCComponent)targetRev.getChildren(archiveRelation)[0].getComponent()).getChildren();
System.out.println("getChildren: " + cs.length);
int n = 0;
for(AIFComponentContext c : cs) {
if(c.getComponent().getType().equals("LD6_MEProcessCr"))
n++;
}
if(n >= 3) {
throw new Exception(REG.getString("relation.ERROR"));
}
}
TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent(type);
if (itemType == null) {
throw new Exception(String.format(REG.getString("typenotfound.ERROR1"), type));
}
String checkRequire = checkRequire();
if (!checkRequire.equals("")) {
throw new Exception(String.format(REG.getString("requireprop.INFO1"), checkRequire));
}
String checkCombox = checkCombox();
System.out.println("checkCombox==="+checkCombox);
if (!checkCombox.equals("")) {
throw new Exception(checkCombox);
}
boolean addedToNewRev = false;
try {
KUtil.setByPassItk(session, true);
TCComponentItemRevisionType revType = itemType.getItemRevisionType();
String revTypeName = revType.getName();
String itemMasterTypeName = type + " Master";
String revMasterTypeName = revTypeName + " Master";
if (session.getTypeComponent(itemMasterTypeName) == null) {
itemMasterTypeName = type + "Master";
}
if (session.getTypeComponent(revMasterTypeName) == null) {
revMasterTypeName = revTypeName + "Master";
}
System.out.println("Revision Type: " + type);
System.out.println("Item Master Type: " + itemMasterTypeName);
System.out.println("Revision Master Type: " + revMasterTypeName);
Map<String, String> revPropMap = new HashMap<>();
Map<String, String> revMasterPropMap = new HashMap<>();
Map<String, String> itemPropMap = new HashMap<>();
Map<String, String> itemMasterPropMap = new HashMap<>();
for (PrefComponent prefComponent : itemComps) {
KUtil.initPropMap(prefComponent.propConfig, prefComponent.getValue(), itemPropMap, itemMasterPropMap, revPropMap, revMasterPropMap);
}
for (PrefComponent prefComponent : procComps) {
KUtil.initPropMap(prefComponent.propConfig, prefComponent.getValue(), itemPropMap, itemMasterPropMap, revPropMap, revMasterPropMap);
}
CreateInput revMasterInput = new CreateInput();
revMasterInput.boName = revMasterTypeName;
revMasterInput.stringProps = revMasterPropMap;
if ("NHL8_AssemblyPro".equals(type) && "NHL8_VirtualPart".equals(targetRev.getItem().getType())) {
System.out.println(">> set nhl8_isFcheck = true");
System.out.println(">> set nhl8_isfPass = true");
revMasterInput.boolProps = new HashMap<>();
revMasterInput.boolProps.put("nhl8_isFcheck", true);
revMasterInput.boolProps.put("nhl8_isfPass", true);
}
CreateInput itemMasterInput = new CreateInput();
itemMasterInput.boName = itemMasterTypeName;
itemMasterInput.stringProps = itemMasterPropMap;
CreateInput revInput = new CreateInput();
revInput.boName = revTypeName;
revInput.stringProps = revPropMap;
Map<String, CreateInput[]> revMasterInfoMap = new HashMap<>();
revMasterInfoMap.put("IMAN_master_form_rev", new CreateInput[] { revMasterInput });
revInput.compoundCreateInput = revMasterInfoMap;
// create rev
CreateInput itemInput = new CreateInput();
itemInput.boName = type;
itemInput.stringProps = itemPropMap;
Map<String, CreateInput[]> revInfoMap = new HashMap<>();
revInfoMap.put("revision", new CreateInput[] { revInput });
revInfoMap.put("IMAN_master_form", new CreateInput[] { itemMasterInput });
itemInput.compoundCreateInput = revInfoMap;
// create info
CreateIn cI = new CreateIn();
cI.clientId = "CreateItem";
cI.data = itemInput;
// service
DataManagementService service = DataManagementService.getService(session);
// create
CreateResponse resp = service.createObjects(new CreateIn[] { cI });
SoaUtil.checkPartialErrors(resp.serviceData);
CreateOut[] cOs = resp.output;
TCComponentItem newItem = null;
if (cOs.length > 0) {
for (TCComponent s : cOs[0].objects) {
if (s instanceof TCComponentItem) {
newItem = (TCComponentItem) s;
}
}
}
System.out.println("New Item: " + newItem);
if (newItem == null) {
throw new Exception(REG.getString("createprocess.ERROR"));
}
newItem.refresh();
TCComponentItemRevision newRev = newItem.getLatestItemRevision();
System.out.println("New Rev: " + newRev);
ProcessUtil.switchToPrecise(session, newRev);
addedToNewRev = false;
if (newRev != null) {
try {
newRev.add(relName, this.targetRev);
newRev.refresh();
this.targetRev.add(archiveRelation, newItem);
this.targetRev.refresh();
addedToNewRev = true;
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(dialog, e.getMessage(), "错误", MessageBox.ERROR);
}
}
if (!addedToNewRev) {
TCComponentFolder folder = session.getUser().getNewStuffFolder();
folder.add("contents", newItem);
folder.refresh();
}
MessageBox.post(dialog, addedToNewRev ? REG.getString("newprocesscomplete.INFO") : REG.getString("newprocesscomplete.ERROR"), "", MessageBox.INFORMATION);
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(dialog, e.getMessage(), "错误", MessageBox.ERROR);
} finally {
KUtil.setByPassItk(session, false);
}
}
private String checkRequire() {
List<String> requireTitles = new ArrayList<String>();
for (PrefComponent prefComponent : itemComps) {
if (!prefComponent.checkRequire()) {
requireTitles.add(prefComponent.title.replace(" ", "").replace(":", "").replace(REG.getString("CN_SYMBEL4"), "").replace(REG.getString("CN_SYMBEL5"), ""));
}
}
for (PrefComponent prefComponent : procComps) {
if (!prefComponent.checkRequire()) {
requireTitles.add(prefComponent.title.replace(" ", "").replace(":", "").replace(REG.getString("CN_SYMBEL4"), "").replace(REG.getString("CN_SYMBEL5"), ""));
}
}
if (requireTitles.size() > 0) {
//MessageBox.post(dialog, String.format(REG.getString("requireprop.INFO1"), requireTitles.toString()), "", MessageBox.WARNING);
return requireTitles.toString();
}
return "";
}
private String checkCombox() {
List<String> requireTitles = new ArrayList<String>();
for (PrefComponent prefComponent : itemComps) {
if (!prefComponent.checkCombox()) {
requireTitles.add(prefComponent.title+"请选择下拉值!");
}
}
for (PrefComponent prefComponent : procComps) {
if (!prefComponent.checkCombox()) {
requireTitles.add(prefComponent.title+"请选择下拉值!"); }
}
if (requireTitles.size() > 0) {
//MessageBox.post(dialog, String.format(REG.getString("requireprop.INFO1"), requireTitles.toString()), "", MessageBox.WARNING);
return requireTitles.toString();
}
return "";
}
}

@ -0,0 +1,850 @@
package cn.net.connor.std.processedit.newmeprocess;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.ListOfValuesInfo;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.treetable.SwingTextContextActivator;
import com.teamcenter.rac.util.Registry;
import com.teamcenter.rac.util.iTextArea;
import com.teamcenter.rac.util.iTextField;
import com.teamcenter.services.rac.core.LOVService;
import com.teamcenter.services.rac.core._2013_05.LOV.InitialLovData;
import com.teamcenter.services.rac.core._2013_05.LOV.LOVSearchResults;
import com.teamcenter.services.rac.core._2013_05.LOV.LOVValueRow;
import com.teamcenter.services.rac.core._2013_05.LOV.LovFilterData;
import com.teamcenter.soa.client.model.LovValue;
import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.processedit.util.OptionItem;
import cn.net.connor.std.processedit.util.TwoColumnRenderer;
public class PrefComponent {
public boolean isLovParent = false;
public boolean isLovChild = false;
public String lovName;
public JTextField bigJtf;
public static final String REQUIRE = "*";
public static final String READONLY = "#";
public static final String INVISIBLE = "@";
public static final String TEXTAREA = "$";
public static final Registry REG = Registry.getRegistry(PrefComponent.class);
public boolean isTextArea = false;
public JPanel panel;
public String configStr;
public boolean require = false;
public boolean readonly = false;
public boolean invisible = false;
public String title;
public String propConfig;
public String fromPropConfig;
public String[] additional;
public String[] lov;
public String[] displayLov;
public String[] descriptions;
public iTextField textField;
private iTextArea textArea;
public JComboBox comboBox;
public ArrayList<String> list = new ArrayList<String>();
private int textLength = -1;
public TCComponentItemRevision rev;
public HashMap<String,OptionItem> opHashMap = new HashMap<String, OptionItem>();
public HashMap<String,String> lovDisRealMap = new HashMap<String, String>();
public PrefComponent(String pref, TCComponentItemRevision targetRev) {
this.configStr = pref;
this.rev = targetRev;
}
public boolean init(TCSession session) throws Exception{
System.out.println("configStr==="+configStr);
if (KUtil.isEmpty(configStr)) {
return false;
}
if (configStr.startsWith(REQUIRE)) {
configStr = configStr.substring(1);
this.require = true;
}
if (configStr.startsWith(READONLY)) {
configStr = configStr.substring(1);
this.readonly = true;
}
if(configStr.startsWith(INVISIBLE)) {
configStr = configStr.substring(1);
this.invisible = true;
}
if (configStr.startsWith(TEXTAREA)) {
configStr = configStr.substring(1);
this.isTextArea = true;
}
String[] split = configStr.split("=", -1);
int len = KUtil.getLen(split);
if (len > 0) {
this.title = split[0];
}
if (len > 1) {
this.propConfig = split[1];
}
if (len > 2) {
this.fromPropConfig = split[2];
}
if (len > 3 && !KUtil.isEmpty(split[3])) {
this.lov = split[3].split(";");
}
if (len > 4 && !KUtil.isEmpty(split[4])) {
try {
this.textLength = Integer.parseInt(split[4].trim());
} catch (Exception e) {
e.printStackTrace();
}
}
if (KUtil.isEmpty(title)) {
return false;
}
if ("object_type".equals(propConfig)) {
int lovCnt = KUtil.getLen(lov);
displayLov = new String[lovCnt];
descriptions = new String[lovCnt];
additional = new String[lovCnt];
for (int i = 0; i < lovCnt; i++) {
String typeName = lov[i];
String relName = "";
int ind = typeName.indexOf('-');
if(ind>0) {
relName = typeName.substring(ind+1);
typeName = typeName.substring(0,ind);
}
lov[i]=typeName;
displayLov[i] = KUtil.getTypeName(session, typeName);
descriptions[i] = "";
additional[i] = relName;
lovDisRealMap.put(displayLov[i], lov[i]);
}
} else if(lov!=null && lov.length==1) {//TODO
lovName = lov[0];
if(lov[0].contains("^A")) {
lovName = lovName.split("\\^")[0];
isLovParent = true;
// TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues");
// TCComponentListOfValues[] lovs = lovType.find(lov[0]);
// if(lovs==null || lovs.length==0) {
// throw new Exception(String.format(REG.getString("lovnotfound.ERROR1"), lov[0]));
// }
// displayLov = getDynamicLOV(lovs[0]);
//TODO
TCComponentListOfValues lovComp = KUtil.getLov(session, lovName);
if (lovComp == null) {
throw new Exception(String.format(REG.getString("lovnotfound.ERROR1"), lovName));
}
initLovTree(lovComp,session);
System.out.println("lovList==="+listLov.toString());
List<LovValue> vals = lovComp.getListOfValues().getValues();
int lovCnt = vals == null ? 0 : vals.size();
//
// Map<String, String[]> lovTWO = getLovTWO(session,lov[0]);
//
// System.out.println("lovTWO======"+lovTWO.toString());
//
// Map<String, String> lovTh = getLovThreeRealValue(session,lov[0]);
//
// System.out.println("lovTh======"+lovTh.toString());
initLovTree(lovComp,session);
System.out.println("lovList==="+list.toString());
ListOfValuesInfo listOfValues = lovComp.getListOfValues();
System.out.println("lovCnt=="+lovCnt);
if (lovCnt>0) {
descriptions = listOfValues.getDispDescription();//lov描述
System.out.println("getListOfValues:"+lovName+lovCnt);
this.lov = new String[lovCnt];
this.displayLov = new String[lovCnt];
for (int i = 0; i < lovCnt; i++) {
LovValue lovValue = vals.get(i);
String realValue = lovValue.getValue() == null ? "" : lovValue.getValue().toString();
String disValue = lovValue.getDisplayValue();
lov[i] = realValue;
displayLov[i] = disValue;
lovDisRealMap.put(displayLov[i], lov[i]);
}
}else {
System.out.println("getDynamicLOV:"+lovName);
String[] lovValues = getDynamicLOV(lovComp);
lovCnt = KUtil.getLen(lovValues);
this.lov = new String[lovCnt];
this.displayLov = new String[lovCnt];
for (int i = 0; i < lovCnt; i++) {
String realValue = lovValues[i];
String disValue = lovValues[i];
lov[i] = realValue;
displayLov[i] = disValue;
lovDisRealMap.put(displayLov[i], lov[i]);
}
}
}else if(lovName.contains("^B")) {
lovName = lovName.split("\\^")[0];
isLovChild = true;
}else {
// TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues");
// TCComponentListOfValues[] lovs = lovType.find(lov[0]);
// if(lovs==null || lovs.length==0) {
// throw new Exception(String.format(REG.getString("lovnotfound.ERROR1"), lov[0]));
// }
// displayLov = getDynamicLOV(lovs[0]);
lovName = lov[0];
//TODO
TCComponentListOfValues lovComp = KUtil.getLov(session, lovName);
if (lovComp == null) {
throw new Exception(String.format(REG.getString("lovnotfound.ERROR1"), lovName));
}
List<LovValue> vals = lovComp.getListOfValues().getValues();
int lovCnt = vals == null ? 0 : vals.size();
//
// Map<String, String[]> lovTWO = getLovTWO(session,lovName);
//
// System.out.println("lovTWO======"+lovTWO.toString());
//
// Map<String, String> lovTh = getLovThreeRealValue(session,lovName);
//
// System.out.println("lovTh======"+lovTh.toString());
initLovTree(lovComp,session);
System.out.println("lovList==="+list.toString());
ListOfValuesInfo listOfValues = lovComp.getListOfValues();
System.out.println("lovCnt=="+lovCnt);
if (lovCnt>0) {
descriptions = listOfValues.getDispDescription();//lov描述
System.out.println("getListOfValues:"+lovName+lovCnt);
this.lov = new String[lovCnt];
this.displayLov = new String[lovCnt];
for (int i = 0; i < lovCnt; i++) {
LovValue lovValue = vals.get(i);
String realValue = lovValue.getValue() == null ? "" : lovValue.getValue().toString();
String disValue = lovValue.getDisplayValue();
lov[i] = realValue;
displayLov[i] = disValue;
lovDisRealMap.put(displayLov[i], lov[i]);
}
}else {
System.out.println("getDynamicLOV:"+lovName);
String[] lovValues = getDynamicLOV(lovComp);
lovCnt = KUtil.getLen(lovValues);
this.lov = new String[lovCnt];
this.displayLov = new String[lovCnt];
for (int i = 0; i < lovCnt; i++) {
String realValue = lovValues[i];
String disValue = lovValues[i];
lov[i] = realValue;
displayLov[i] = disValue;
lovDisRealMap.put(displayLov[i], lov[i]);
}
}
}
} else {
displayLov = lov;
}
initPanel();
initComponent();
return true;
}
private void initComponent() throws Exception{
if(readonly) {
if(textField!=null) {
textField.setEditable(false);
}
if (textArea != null) {
textArea.setEditable(false);
}
if(comboBox!=null) {
comboBox.setEditable(false);
comboBox.setEnabled(false);
}
}
if(require) {
if(textField!=null) {
textField.setRequired(true);
}
if (textArea != null) {
textArea.setRequired(true);
}
}
if(rev!=null&&!KUtil.isEmpty(fromPropConfig)) {
String value = getConfigPropValue(rev,fromPropConfig);
System.out.println(">> Load Property: "+fromPropConfig+" = "+value);
if(textField!=null) {
textField.setText(value);
}
if(comboBox!=null) {
comboBox.setSelectedItem(value);
}
}
}
public static String getConfigPropValue(TCComponentItemRevision rev, String propConfigStr) throws Exception {
if (rev == null || KUtil.isEmpty(propConfigStr)) {
return "";
}
StringBuilder res = new StringBuilder();
String[] propConfigSplit = propConfigStr.split("\\+");
int len = KUtil.getLen(propConfigSplit);
for (int i = 0; i < len; i++) {
String propConfig = propConfigSplit[i];
String propFrom = null, propName = null;
String[] split = propConfig.split("\\.");
if (KUtil.getLen(split) == 2) {
propFrom = split[0].trim().toUpperCase();
propName = split[1].trim();
}
if (KUtil.isEmpty(propFrom) || KUtil.isEmpty(propName)) {
res.append(propConfig);
continue;
}
TCComponent target = null;
if ("ITEM".equals(propFrom)) {
target = rev.getItem();
} else if ("REV".equals(propFrom)) {
target = rev;
} else if ("IRELA".equals(propFrom)) {
TCComponent[] targets = rev.getRelatedComponents("Ac5_Processroute_Irela");
int targetCnt = KUtil.getLen(targets);
for(int k=0;k<targetCnt;k++) {
if("Ac5_Processroute_FM".equals(targets[k].getType())) {
target = targets[k];
break;
}
}
} else if ("ITEMMASTER".equals(propFrom)) {
target = rev.getItem().getRelatedComponent("IMAN_master_form");
} else if ("REVMASTER".equals(propFrom)) {
target = rev.getRelatedComponent("IMAN_master_form_rev");
} else {
throw new Exception(String.format(REG.getString("proplocationnotdefined.ERROR1"), propFrom));
}
if(target !=null) {
TCProperty prop = target.getTCProperty(propName.trim());
if (prop == null) {
throw new Exception(String.format(REG.getString("propnotdefinedintype.ERROR2"), target.getType(), propName));
}
res.append(prop.getStringValue());
}
}
return res.toString();
}
private void initPanel() {
this.panel = new JPanel(new GridBagLayout());
// 不再硬编码尺寸,让布局自动适应内容
// this.panel.setPreferredSize(new Dimension(260, 40));
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(6, 6, 6, 6); // 与 initMEPropPanel 一致
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
gbc.weighty = 0; // 不抢占垂直空间
if(isLovChild) {
// 构建 label
String labelText = "<html>" + title;
if (require) {
labelText += "<font color='red'>*</font>";
}
labelText += "</html>";
JLabel label = new JLabel(labelText);
// === 开始新行label 是第一个组件 ===
KUtil.newRow(panel, label, gbc, 1);
comboBox = new JComboBox();
comboBox.setRenderer(new TwoColumnRenderer());
comboBox.insertItemAt(null, 0);
comboBox.setSelectedIndex(0);
comboBox.setEditable(true);
this.bigJtf = ((JTextField)this.comboBox.getEditor().getEditorComponent());
this.bigJtf.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e)
{
Object obj = e.getSource();
if ((e.getKeyCode() == 10) &&
(obj == bigJtf))
{
String key = bigJtf.getText();
comboBox.removeAllItems();
// System.out.println("key==="+key);
// System.out.println("opHashMap==="+opHashMap.toString());
for (String item : list) {
System.out.println("item==="+item);
if(item.isEmpty()) {
for (Entry<String, OptionItem> optionItem : opHashMap.entrySet()) {
comboBox.addItem(optionItem);
}
}else {
if (item.contains(key)) {
OptionItem optionItem = opHashMap.get(item);
comboBox.addItem(optionItem);
}
}
}
bigJtf.setText(key);
}
}
public void keyPressed(KeyEvent e) {}
});
//iComboBox iComboBox = new iComboBox();
bigJtf.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent param1FocusEvent) {
SwingTextContextActivator.instance().activateContext();
}
public void focusLost(FocusEvent param1FocusEvent) {
super.focusLost(param1FocusEvent);
SwingTextContextActivator.instance().deactivateContext();
}
});
KUtil.addCol(panel, comboBox, gbc, 1, 1);
}else {
int len = KUtil.getLen(displayLov);
// 构建 label
String labelText = "<html>" + title;
if (len > 0 && require) {
labelText += "<font color='red'>*</font>";
}
labelText += "</html>";
JLabel label = new JLabel(labelText);
// === 开始新行label 是第一个组件 ===
KUtil.newRow(panel, label, gbc, 1);
// === 添加输入控件到同一行 ===
if (len > 0) {
comboBox = new JComboBox();
comboBox.setRenderer(new TwoColumnRenderer());
comboBox.insertItemAt(null, 0);
comboBox.setSelectedIndex(0);
comboBox.setEditable(true);
for (int i = 0; i < len; i++) {
OptionItem optionItem = new OptionItem(displayLov[i], descriptions[i]);
comboBox.addItem(optionItem);
opHashMap.put(displayLov[i], optionItem);
list.add(displayLov[i]);
}
this.bigJtf = ((JTextField)this.comboBox.getEditor().getEditorComponent());
this.bigJtf.addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e)
{
Object obj = e.getSource();
if ((e.getKeyCode() == 10) &&
(obj == bigJtf))
{
String key = bigJtf.getText();
comboBox.removeAllItems();
// System.out.println("key==="+key);
// System.out.println("opHashMap==="+opHashMap.toString());
for (String item : list) {
System.out.println("item==="+item);
if(item.isEmpty()) {
for (Entry<String, OptionItem> optionItem : opHashMap.entrySet()) {
comboBox.addItem(optionItem);
}
}else {
if (item.contains(key)) {
OptionItem optionItem = opHashMap.get(item);
comboBox.addItem(optionItem);
}
}
}
bigJtf.setText(key);
}
}
public void keyPressed(KeyEvent e) {}
});
//iComboBox iComboBox = new iComboBox();
bigJtf.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent param1FocusEvent) {
SwingTextContextActivator.instance().activateContext();
}
public void focusLost(FocusEvent param1FocusEvent) {
super.focusLost(param1FocusEvent);
SwingTextContextActivator.instance().deactivateContext();
}
});
KUtil.addCol(panel, comboBox, gbc, 1, 1);
} else {
if (isTextArea) {
textArea = new iTextArea(8, 18);
textArea.setBorder(BorderFactory.createLineBorder(Color.BLACK));
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
SwingTextContextActivator.instance().activateContext();
}
public void focusLost(FocusEvent e) {
super.focusLost(e);
SwingTextContextActivator.instance().deactivateContext();
}
});
// textArea 占据控件位置第1列不跨行
KUtil.addCol(panel, textArea, gbc, 1, 1);
} else {
textField = new iTextField(textLength > 0 ? textLength : 12);
KUtil.addCol(panel, textField, gbc, 1, 1);
}
// 如果需要额外按钮(类似 initMEPropPanel 中的逻辑),可在此添加
// 例如:
// if ("some_prop".equals(propConfig)) {
// KUtil.addCol(panel, new JButton("..."), gbc, 1, 0);
// }
}
// 可选:如果 textLength > 0 需要占位符(但通常不需要)
// if (textLength > 0 && !isTextArea) {
// KUtil.addCol(panel, new JLabel(""), gbc, 1, 1);
// }
}
}
public Component getPanel() {
return panel;
}
public boolean isInvisible() {
return invisible;
}
public String getValue() {
String value = null;
if(textField!=null) {
value = textField.getText();
} else if (textArea != null) {
value = textArea.getText();
} else if(comboBox!=null) {
String text = bigJtf.getText();
value = lovDisRealMap.get(text);
}
//System.out.println("value==="+value);
return value;
}
public String getAddtionalValue() {
String value = null;
if(textField!=null) {
value = textField.getText();
} else if (textArea != null) {
value = textArea.getText();
} else if(comboBox!=null) {
int ind = comboBox.getSelectedIndex();
ind = ind -1 ;
if(ind>=0&&ind<KUtil.getLen(lov)) {
value = additional[ind];
}
}
return value;
}
public boolean checkRequire() {
if(!require) {
return true;
}
String val = getValue();
return val!=null&&!"".equals(val);
}
public boolean checkCombox() {
if(comboBox!=null) {
String selectedItem = bigJtf.getText();
System.out.println("selectedItem=="+selectedItem);
if(selectedItem.isEmpty()) {
return true;
}
for (Entry<String, OptionItem> optionItem : opHashMap.entrySet()) {
OptionItem value = optionItem.getValue();
if(value.getValue().equals(selectedItem)) {
return true;
}
}
}else {
return true;
}
return false;
}
public String[] getDynamicLOV(TCComponentListOfValues lov) throws Exception {
Vector<String> lovDisplayValueList = new Vector<>();
Vector<String> lovDescValueList = new Vector<>();
// lovDisplayValueList.add("");
// Vector<String> lovValueList = new Vector<>();
LOVService lovService = LOVService.getService((TCSession) AIFUtility.getCurrentApplication().getSession());
InitialLovData input = new InitialLovData();
LovFilterData filter = new LovFilterData();
filter.sortPropertyName = "object_name";
filter.order = 1;
filter.numberToReturn = 100;
filter.maxResults = 100;
input.lov = lov;
input.filterData = filter;
LOVSearchResults result = lovService.getInitialLOVValues(input);
// StringBuffer sb = new StringBuffer();
// sb.append(">>");
for (LOVValueRow row : result.lovValues) {
Map<String, String[]> map = row.propDisplayValues;
// Map<String, String[]> realmap = row.propInternalValues;
for (String key : map.keySet()) {
if(key.equals("object_desc")) {
String[] v = map.get(key);
lovDescValueList.add(v[0]);
}
if(!key.equals("object_name"))
continue;
// sb.append("UID:" + row.uid + ",key:" + key + "value:" + map.get(key)[0]);
// sb.append("\n");
String[] v = map.get(key);
lovDisplayValueList.add(v[0]);
// lovValueList.add(realmap.get(key)[0]);
// System.out.println("key:"+key+"=="+v.length+">>"+v[0]);
}
}
// System.out.println("StringBuffer:"+sb.toString());
descriptions = lovDescValueList.toArray(new String[lovDescValueList.size()]);
return lovDisplayValueList.toArray(new String[lovDisplayValueList.size()]);
}
public LinkedHashMap<String, ArrayList<String>> listLov = new LinkedHashMap<String, ArrayList<String>>();
private void initLovTree(TCComponentListOfValues lov,TCSession session) {
if (lov != null) {
try {
ListOfValuesInfo info = lov.getListOfValues();
String[] valuesList = info.getStringListOfValues();
System.out.println("initLovTree");
if(valuesList != null && valuesList.length != 0) {
System.out.println("valuesList======"+valuesList.length);
for (String v : valuesList) {
String disPlayv = info.getDisplayableValue(v);
ArrayList<String> childLov = new ArrayList<String>();
TCComponentListOfValues cLov = lov
.getListOfFilterOfValue(v);
AIFComponentContext[] children = lov.getChildren();
if(children.length > 0) {
InterfaceAIFComponent component = children[0].getComponent();
String type = component.getType();
}
System.out.println("cLov======"+cLov);
if(cLov != null) {
String lovName = cLov.toString();
TCComponentListOfValues lov111 = TCComponentListOfValuesType.findLOVByName(lovName);
if ("Fnd0ListOfValuesDynamic".equals(lov111.getProperty("lov_type"))) {
System.out.println("动态lovName=" + lovName);
LOVService lovService = LOVService.getService(session);
InitialLovData input = new InitialLovData();
LovFilterData filter = new LovFilterData();
if ("LD6_TecDoc_TypeLOV".equals(lovName)) {
filter.sortPropertyName = "fnd0StringValues"; // lov的后台值
} else {
filter.sortPropertyName = "object_name"; // lov的后台值
}
filter.order = 1;
filter.numberToReturn = 2000;
filter.maxResults = 2000;
input.lov = lov111;
input.filterData = filter;
LOVSearchResults result = lovService.getInitialLOVValues(input);
// System.out.println("111==="+result.toString());
for (LOVValueRow row : result.lovValues) {
Map<String, String[]> map = row.propDisplayValues;
Map<String, String[]> realmap = row.propInternalValues;
// for (String key : map.keySet()) {
// System.out.println("key=" + key + ",value=" + map.get(key)[0]);
// }
// for (String key : realmap.keySet()) {
// System.out.println("key2=" + key + ",value2=" + map.get(key)[0]);
// }
String disval = "";
String val = "";
String key1 = "object_name";// 真实值 显示值第一列
if ("LD6_TecDoc_TypeLOV".equals(lovName)) {
key1 = "fnd0StringValues"; // lov的后台值
}
// String key2 = "object_desc";// 显示值第二列
if (map.containsKey(key1)) {
val = realmap.get(key1)[0];
disval = map.get(key1)[0];
}
if (!val.equals("")) {
childLov.add(disval);
}
}
listLov.put(disPlayv, childLov);
}else {
List<LovValue> vals = lov111.getListOfValues().getValues();
//descriptions = listOfValues.getDispDescription();//lov描述
System.out.println("vals===="+vals.size());
for (int i = 0; i < vals.size(); i++) {
LovValue lovValue = vals.get(i);
String realValue = lovValue.getValue() == null ? "" : lovValue.getValue().toString();
//String disValue = lovValue.getDisplayValue();
childLov.add(realValue);
}
listLov.put(disPlayv, childLov);
}
}
}
}
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}

@ -0,0 +1,22 @@
newprocess.TITLE=\u521B\u5EFA\u5DE5\u827A
ok=\u786E\u5B9A
cancel=\u53D6\u6D88
itemgroup.TITLE=\u96F6\u7EC4\u4EF6\u5C5E\u6027
procgroup.TITLE=\u5DE5\u827A\u64CD\u4F5C
selectnewprocesstarget.ERROR=\u8BF7\u9009\u62E9\u96F6\u4EF6\u6216\u7EC4\u4EF6\u8FDB\u884C\u64CD\u4F5C
prefnotconfiged.ERROR1=\u9996\u9009\u9879\u672A\u914D\u7F6E\uFF1A%s
typecompnotfound.ERROR=\u672A\u5B9A\u4E49\u5BF9\u8C61\u7C7B\u578B\u63A7\u4EF6
selectType.INFO=\u8BF7\u9009\u62E9\u8981\u521B\u5EFA\u7684\u5BF9\u8C61\u7C7B\u578B
createprocess.ERROR=\u521B\u5EFA\u5DE5\u827A\u5F02\u5E38
newprocesscomplete.INFO=\u521B\u5EFA\u6210\u529F
newprocesscomplete.ERROR=\u521B\u5EFA\u5DE5\u827A\u5B8C\u6210\uFF0C\u4FDD\u5B58\u5230NewStuff\u6587\u4EF6\u5939
CN_SYMBEL1=\uFF08
CN_SYMBEL2=\uFF09
CN_SYMBEL3=\uFF01
CN_SYMBEL4=\uFF1A
CN_SYMBEL5=\u3000
requireprop.INFO1=\u8BF7\u586B\u5199\u5FC5\u586B\u5C5E\u6027\uFF1A\: %s
proplocationnotdefined.ERROR1=\u672A\u77E5\u5C5E\u6027\u4F4D\u7F6E\u201C%s\u201D\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E
propnotdefinedintype.ERROR2=\u5C5E\u6027\u201C%s\u201D\u672A\u5728\u7C7B\u578B\u201C%s\u201D\u4E2D\u5B9A\u4E49
revreleased.ERROR=\u672A\u53D1\u5E03\u72B6\u6001\u4E0D\u5141\u8BB8\u521B\u5EFA\u5DE5\u827A
relation.ERROR=\u5DE5\u827A\u8DEF\u7EBF\u6570\u91CF\u8D85\u8FC7\u9650\u5236\uFF0C\u65E0\u6CD5\u5EFA\u7ACB\u5173\u7CFB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save