commit cfcde4773bd886f133e8aeededdd146d9fd574fe Author: lijh Date: Wed Dec 24 16:58:43 2025 +0800 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..82d2abb --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..3725e71 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + cn.net.connor.std.processedit + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9f6ece8 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8ed1435 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -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 diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..f150088 --- /dev/null +++ b/README.MD @@ -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) +属性位置(工步):如不写默认为文件夹属性(位置包含:bomline,item) +#:属性名称前加#表示改列为手动序号列,用于重排序功能,支持多列 +##:属性名称前加##表示改列为自动序号列,不跟随上下移动,删除行时也会自动调整,支持多列 +属性真实名称:定义的属性名称,如要支持换行,请务必配置“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 + + + + + + + + + + +``` + +修改为 + +```xml + + + + + + + + + + + + + + + +``` + +## 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. 工道编辑,序号特殊配置 + + 更新配置:序号属性名称前加# + + 属性位置(工步):如不写默认为文件夹属性(位置包含:bomline,item) + + ```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 + ``` + diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..eed0977 --- /dev/null +++ b/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + lib/jsqlparser-4.3.jar,\ + lib/jacob.jar diff --git a/icons/T.png b/icons/T.png new file mode 100644 index 0000000..7e07e95 Binary files /dev/null and b/icons/T.png differ diff --git a/icons/add_24px.png b/icons/add_24px.png new file mode 100644 index 0000000..34c2886 Binary files /dev/null and b/icons/add_24px.png differ diff --git a/icons/delete_24px.png b/icons/delete_24px.png new file mode 100644 index 0000000..5e33b13 Binary files /dev/null and b/icons/delete_24px.png differ diff --git a/icons/down_24px.png b/icons/down_24px.png new file mode 100644 index 0000000..5188b82 Binary files /dev/null and b/icons/down_24px.png differ diff --git a/icons/edit16.png b/icons/edit16.png new file mode 100644 index 0000000..a743326 Binary files /dev/null and b/icons/edit16.png differ diff --git a/icons/folder_24.png b/icons/folder_24.png new file mode 100644 index 0000000..8b04344 Binary files /dev/null and b/icons/folder_24.png differ diff --git a/icons/meoperation_16.png b/icons/meoperation_16.png new file mode 100644 index 0000000..d31bd13 Binary files /dev/null and b/icons/meoperation_16.png differ diff --git a/icons/meprocess_16.png b/icons/meprocess_16.png new file mode 100644 index 0000000..125f218 Binary files /dev/null and b/icons/meprocess_16.png differ diff --git a/icons/reorder.png b/icons/reorder.png new file mode 100644 index 0000000..9fe1a82 Binary files /dev/null and b/icons/reorder.png differ diff --git a/icons/sample.png b/icons/sample.png new file mode 100644 index 0000000..02c4b79 Binary files /dev/null and b/icons/sample.png differ diff --git a/icons/sample@2x.png b/icons/sample@2x.png new file mode 100644 index 0000000..c1224d1 Binary files /dev/null and b/icons/sample@2x.png differ diff --git a/icons/search-2.png b/icons/search-2.png new file mode 100644 index 0000000..b925df1 Binary files /dev/null and b/icons/search-2.png differ diff --git a/icons/search.png b/icons/search.png new file mode 100644 index 0000000..b0a0594 Binary files /dev/null and b/icons/search.png differ diff --git a/icons/sort-line-2.png b/icons/sort-line-2.png new file mode 100644 index 0000000..5fe38f5 Binary files /dev/null and b/icons/sort-line-2.png differ diff --git a/icons/sort-line.png b/icons/sort-line.png new file mode 100644 index 0000000..9cb626c Binary files /dev/null and b/icons/sort-line.png differ diff --git a/icons/text.png b/icons/text.png new file mode 100644 index 0000000..24a206b Binary files /dev/null and b/icons/text.png differ diff --git a/icons/up_24px.png b/icons/up_24px.png new file mode 100644 index 0000000..94e9cc8 Binary files /dev/null and b/icons/up_24px.png differ diff --git a/lib/cn.net.connor.std.aifrcp_13000.1.0.jar b/lib/cn.net.connor.std.aifrcp_13000.1.0.jar new file mode 100644 index 0000000..5206255 Binary files /dev/null and b/lib/cn.net.connor.std.aifrcp_13000.1.0.jar differ diff --git a/lib/cn.net.connor.std.fx_13000.1.0.jar b/lib/cn.net.connor.std.fx_13000.1.0.jar new file mode 100644 index 0000000..97aabfd Binary files /dev/null and b/lib/cn.net.connor.std.fx_13000.1.0.jar differ diff --git a/lib/cn.net.connor.std.gdtex_13000.1.0.jar b/lib/cn.net.connor.std.gdtex_13000.1.0.jar new file mode 100644 index 0000000..598fbc7 Binary files /dev/null and b/lib/cn.net.connor.std.gdtex_13000.1.0.jar differ diff --git a/lib/jacob-1.18.zip b/lib/jacob-1.18.zip new file mode 100644 index 0000000..5ff043f Binary files /dev/null and b/lib/jacob-1.18.zip differ diff --git a/lib/jacob.jar b/lib/jacob.jar new file mode 100644 index 0000000..c35ad12 Binary files /dev/null and b/lib/jacob.jar differ diff --git a/lib/jfxswt.jar b/lib/jfxswt.jar new file mode 100644 index 0000000..2c5c7f1 Binary files /dev/null and b/lib/jfxswt.jar differ diff --git a/lib/jsqlparser-4.3.jar b/lib/jsqlparser-4.3.jar new file mode 100644 index 0000000..cff6c65 Binary files /dev/null and b/lib/jsqlparser-4.3.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..8197bf7 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,261 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/cn/net/connor/std/processedit/Activator.java b/src/cn/net/connor/std/processedit/Activator.java new file mode 100644 index 0000000..dfa88fc --- /dev/null +++ b/src/cn/net/connor/std/processedit/Activator.java @@ -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; + } + +} diff --git a/src/cn/net/connor/std/processedit/KStartup.java b/src/cn/net/connor/std/processedit/KStartup.java new file mode 100644 index 0000000..3769677 --- /dev/null +++ b/src/cn/net/connor/std/processedit/KStartup.java @@ -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(); + } + }); + } + +} diff --git a/src/cn/net/connor/std/processedit/choose/ChooseDialog.java b/src/cn/net/connor/std/processedit/choose/ChooseDialog.java new file mode 100644 index 0000000..15632ef --- /dev/null +++ b/src/cn/net/connor/std/processedit/choose/ChooseDialog.java @@ -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; + } + +} diff --git a/src/cn/net/connor/std/processedit/choose/ChooseDialogController.java b/src/cn/net/connor/std/processedit/choose/ChooseDialogController.java new file mode 100644 index 0000000..6c04386 --- /dev/null +++ b/src/cn/net/connor/std/processedit/choose/ChooseDialogController.java @@ -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 prefComponents; + // private Map otherComps; + private ChooseDialog dialog; + protected File excelFile; + protected List configs = new ArrayList(); + protected List searchCols = new ArrayList(); + protected Map searchComps = new HashMap(); + 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 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 searchInfo = new HashMap(); + 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 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(); + } + +} diff --git a/src/cn/net/connor/std/processedit/choose/choose.properties b/src/cn/net/connor/std/processedit/choose/choose.properties new file mode 100644 index 0000000..fd21fb9 --- /dev/null +++ b/src/cn/net/connor/std/processedit/choose/choose.properties @@ -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 diff --git a/src/cn/net/connor/std/processedit/choosefromsql/ChooseFromSqlDialog.java b/src/cn/net/connor/std/processedit/choosefromsql/ChooseFromSqlDialog.java new file mode 100644 index 0000000..bf54938 --- /dev/null +++ b/src/cn/net/connor/std/processedit/choosefromsql/ChooseFromSqlDialog.java @@ -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 prefComponents; + protected Map revChildren; + private static final Registry REG = Registry.getRegistry(ChooseFromSqlDialog.class); + + public ChooseFromSqlDialog(PrefComponent bean, List prefComponents, Map 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; + } + +} diff --git a/src/cn/net/connor/std/processedit/choosefromsql/ChooseFromSqlDialogController.java b/src/cn/net/connor/std/processedit/choosefromsql/ChooseFromSqlDialogController.java new file mode 100644 index 0000000..d904801 --- /dev/null +++ b/src/cn/net/connor/std/processedit/choosefromsql/ChooseFromSqlDialogController.java @@ -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 prefComponents; + // private Map otherComps; + private ChooseFromSqlDialog dialog; + protected List configs = new ArrayList(); + protected Map searchCols_DB_UI = new LinkedHashMap<>(); + protected Map searchComps = new HashMap(); + protected KSqlTable tableBean; + private Map revChildren; + private TCComponentItemType itemType; + private static final Registry REG = Registry.getRegistry(ChooseFromSqlDialogController.class); + + public static void getTableNameBySql(String sql, List headers, List 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 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 headers = new ArrayList<>(); + List 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 searchInfo = new HashMap(); + 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 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(); + } + +} diff --git a/src/cn/net/connor/std/processedit/choosefromsql/choosefromsql.properties b/src/cn/net/connor/std/processedit/choosefromsql/choosefromsql.properties new file mode 100644 index 0000000..2b1aba1 --- /dev/null +++ b/src/cn/net/connor/std/processedit/choosefromsql/choosefromsql.properties @@ -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 \ No newline at end of file diff --git a/src/cn/net/connor/std/processedit/commands/CreateBOMViewHandler.java b/src/cn/net/connor/std/processedit/commands/CreateBOMViewHandler.java new file mode 100644 index 0000000..e4ae138 --- /dev/null +++ b/src/cn/net/connor/std/processedit/commands/CreateBOMViewHandler.java @@ -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; + } +} diff --git a/src/cn/net/connor/std/processedit/commands/G4MDialog.java b/src/cn/net/connor/std/processedit/commands/G4MDialog.java new file mode 100644 index 0000000..c507b13 --- /dev/null +++ b/src/cn/net/connor/std/processedit/commands/G4MDialog.java @@ -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 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(); + 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); + } + + + } + +} diff --git a/src/cn/net/connor/std/processedit/commands/ModifyMeopNoCommand.java b/src/cn/net/connor/std/processedit/commands/ModifyMeopNoCommand.java new file mode 100644 index 0000000..bd42fd6 --- /dev/null +++ b/src/cn/net/connor/std/processedit/commands/ModifyMeopNoCommand.java @@ -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()); + } + +} diff --git a/src/cn/net/connor/std/processedit/commands/NewDatasetFromTemplateCommand.java b/src/cn/net/connor/std/processedit/commands/NewDatasetFromTemplateCommand.java new file mode 100644 index 0000000..1060e88 --- /dev/null +++ b/src/cn/net/connor/std/processedit/commands/NewDatasetFromTemplateCommand.java @@ -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)); + } + +} diff --git a/src/cn/net/connor/std/processedit/commands/NewMeopCommand.java b/src/cn/net/connor/std/processedit/commands/NewMeopCommand.java new file mode 100644 index 0000000..c77df7b --- /dev/null +++ b/src/cn/net/connor/std/processedit/commands/NewMeopCommand.java @@ -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))); + } + +} diff --git a/src/cn/net/connor/std/processedit/commands/NewProcessCommand.java b/src/cn/net/connor/std/processedit/commands/NewProcessCommand.java new file mode 100644 index 0000000..ae8c7ba --- /dev/null +++ b/src/cn/net/connor/std/processedit/commands/NewProcessCommand.java @@ -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))); + } + +} diff --git a/src/cn/net/connor/std/processedit/commands/OpenViewCommand.java b/src/cn/net/connor/std/processedit/commands/OpenViewCommand.java new file mode 100644 index 0000000..dcf22f4 --- /dev/null +++ b/src/cn/net/connor/std/processedit/commands/OpenViewCommand.java @@ -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(); + } + } + } + } +} diff --git a/src/cn/net/connor/std/processedit/ldy/CheckHeaderCellRenderer.java b/src/cn/net/connor/std/processedit/ldy/CheckHeaderCellRenderer.java new file mode 100644 index 0000000..b1cede1 --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/CheckHeaderCellRenderer.java @@ -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 colList; + private ArrayList compList; + private HashMap 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 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 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); + } +} diff --git a/src/cn/net/connor/std/processedit/ldy/GXDivisionHandler.java b/src/cn/net/connor/std/processedit/ldy/GXDivisionHandler.java new file mode 100644 index 0000000..385eec2 --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/GXDivisionHandler.java @@ -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 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; + } + +} diff --git a/src/cn/net/connor/std/processedit/ldy/ProcessBorrowDialog.java b/src/cn/net/connor/std/processedit/ldy/ProcessBorrowDialog.java new file mode 100644 index 0000000..f993ec7 --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/ProcessBorrowDialog.java @@ -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 compMap; + private String queryName; + private Vector showOptions; + private Vector procedureOptions; + private Vector processVec; +// private Vector> proceduresVec; + private Vector options; + private Map> lovMap; + private Map>> tableMap; + private Map, TCComponentBOMLine> proceduresMap; + private Vector updateProps; + private Vector clearProps; + + public ProcessBorrowDialog(TCSession session, TCComponentBOMLine targetLine, Vector options) throws Exception { + super(AIFUtility.getActiveDesktop()); + this.session = session; + this.targetLine = targetLine; + this.options = options; + compMap = new HashMap<>(); + lovMap = new HashMap<>(); + tableMap = new HashMap<>(); + proceduresMap = new HashMap<>(); + this.showOptions = new Vector<>(); + this.procedureOptions = new Vector<>(); + this.processVec = new Vector<>(); + this.updateProps = new Vector<>(); + this.clearProps = new Vector<>(); +// tableMap = new HashMap<>(); + setTitle("ս"); + + String[] propOptions = options.get(3); + for(String s : propOptions) { + updateProps.add(s.split("\\.")); + } + propOptions = options.get(4); + for(String s : propOptions) { + clearProps.add(s.split("\\.")); + } +// JPanel msgPanel = new JPanel(new GridLayout(0,5,2,5)); + JPanel msgPanel = new JPanel(new FlowLayout()); +// String[] searchOptions = options.get(0); + String[] searchOptions = new String[] { "ID=2", "=2" }; + queryName = options.get(0)[0]; + final AbstractAIFDialog dialog = this; + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues"); + for(String s : searchOptions) { + if(!s.contains("=")) + continue; + String[] split = s.split("="); + JLabel label = new JLabel(split[0], SwingConstants.RIGHT); + label.setPreferredSize(new Dimension(80, 23)); +// label.setHorizontalTextPosition(JLabel.RIGHT); +// JPanel propPanel = new JPanel(new BorderLayout()); + JPanel propPanel = new JPanel(new BorderLayout()); + propPanel.add(BorderLayout.WEST, label); + if(split.length==3) { + JComboBox combo = new JComboBox<>(); + combo.setPreferredSize(new Dimension(118, 23)); + if(split[2].indexOf(";")>0) { + String[] value = split[2].split(";"); + combo.addItem(""); + for(String v : value) + combo.addItem(v); + }else { + TCComponentListOfValues[] lovs = lovType.find(split[2]); + if (lovs != null && lovs.length > 0) { + ListOfValuesInfo lovInfo = lovs[0].getListOfValues(); + String[] code = lovInfo.getStringListOfValues(); + String[] name = lovInfo.getLOVDisplayValues(); + Map lovVal = new HashMap<>(); + if (code != null && name != null) { + for (int i = 0; i < code.length; i++) { + lovVal.put(name[i], code[i]); + combo.addItem(name[i]); + } + } + lovMap.put(split[0], lovVal); +// bean.lovList = TCUtil.setAutoComplete(bean, name); + }else + throw new Exception("δҵ"+split[2]+"ѡ"); + } + propPanel.add(BorderLayout.CENTER, combo); + msgPanel.add(propPanel); + compMap.put(split[0], combo); + }else if(split[1].equals("2")) { + JTextField field = new JTextField(); + field.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, field); + msgPanel.add(propPanel); + compMap.put(split[0], field); + }else if(split[1].equals("3")) { + PropertyDateComponent dateBtn = new PropertyDateComponent(); + dateBtn.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, dateBtn); + msgPanel.add(propPanel); + compMap.put(split[0], dateBtn); + }else if(split[1].equals("4")) { + final JTextField field = new JTextField(); + field.setEditable(false); + field.setPreferredSize(new Dimension(60, 23)); + JButton userBtn = new JButton("ѡ"); + userBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + new SelectUserDialog(field, true).showDialog(); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(dialog, ":"+e.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + userBtn.setPreferredSize(new Dimension(56, 23)); + propPanel.add(BorderLayout.CENTER, field); + propPanel.add(BorderLayout.EAST, userBtn); + msgPanel.add(propPanel); + compMap.put(split[0], field); + } + } + searchBtn = new JButton("ѯ"); + exportBtn = new JButton(""); + JPanel btnPanel = new JPanel(new FlowLayout()); + btnPanel.add(searchBtn); + btnPanel.add(exportBtn); + JPanel topPanel = new JPanel(new BorderLayout()); + topPanel.add(BorderLayout.WEST, msgPanel); + topPanel.add(BorderLayout.EAST, btnPanel); + + String[] itemOptions = options.get(0); + String[] tableHeader = new String[itemOptions.length]; + tableHeader[0] = ""; + for(int i=1; i getColumnClass(int column) { + if (column==0) { + return Boolean.class; + } + return super.getColumnClass(column); + } + }; +// processTable.getTableHeader().setReorderingAllowed(false); + processTable.setFillsViewportHeight(true); +// processTable.setEnabled(false); + processTable.setEnabled(true); +// processTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); + processTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + processTable.setModel(processModel); + processTable.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(processTable, true)); + processTable.getTableHeader().setReorderingAllowed(false); + TableColumnModel pColModel = processTable.getColumnModel(); + for(int i=1; i0) { + for(int i=processModel.getRowCount(); i>0; i--) + processModel.removeRow(i-1); + } + if(tableMap.size()==0) + return; + int i = impTable.getSelectedRow(); + for(Vector vo : tableMap.get(i)) { + processModel.addRow(vo); + } + } + }); + searchBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + if(impModel.getRowCount()>0) { + for(int i=impModel.getRowCount(); i>0; i--) + impModel.removeRow(i-1); + } + if(processModel.getRowCount()>0) { + for(int i=processModel.getRowCount(); i>0; i--) + processModel.removeRow(i-1); + } + Vector keyV = new Vector<>(); + Vector valueV = new Vector<>(); + for(Entry e : compMap.entrySet()) { + JComponent c = e.getValue(); + String text = ""; + if(c instanceof JTextField) + text = ((JTextField)c).getText(); + else if(c instanceof PropertyDateComponent) + text = ((PropertyDateComponent)c).getDateViewModel().getDateString(); + else { + text = ((JComboBox)c).getSelectedItem().toString(); + if(lovMap.containsKey(e.getKey())) { + text = lovMap.get(e.getKey()).get(text); + } + } + if(text!=null && !text.isEmpty()) { + if(e.getKey().equals("ID")) + text += "GY"; + keyV.add(e.getKey()); + valueV.add(text); + } + } + TCComponent[] result = TCUtil.query(session, queryName, keyV, valueV); + System.out.println("result:"+result.length); + if(result.length==0) { + MessageBox.post(dialog, "ûзĹգѯ", "ERROR", MessageBox.ERROR); + return; + } + result = TCUtil.TCsort(result, new int[] { 1, -1 }, "item_id", "item_revision_id"); + TCComponentBOPWindowType bomWinType = (TCComponentBOPWindowType) session.getTypeComponent("BOPWindow"); + TCComponentBOPWindow window = (TCComponentBOPWindow) bomWinType.createBOPWindow(null); + for(int i=0; i v = new Vector<>(); + int num = impModel.getRowCount(); + v.add(num+1+""); + TCComponentMEProcessRevision meprocess = (TCComponentMEProcessRevision) result[i]; + TCComponentItem pitem = meprocess.getItem(); + TCComponentForm form = TCUtil.getItemRevisionMasterForm(meprocess); + for(String[] prop : showOptions) { + if(prop[0].equals("item")) + v.add(pitem.getProperty(prop[1])); + else if(prop[0].equals("rev")) + v.add(meprocess.getProperty(prop[1])); + else + v.add(form.getProperty(prop[1])); + } + processVec.add(meprocess); + impModel.addRow(v); + + TCComponentBOMLine ebom = window.setWindowTopLine(pitem, meprocess, null, null); + AIFComponentContext[] p = ebom.getChildren(); + Vector> vvo = new Vector<>(); + for(AIFComponentContext c : p) { + Vector vo = new Vector<>(); + vo.add(true); + TCComponentBOMLine procedure = (TCComponentBOMLine) c.getComponent(); + TCComponentItem pritem = procedure.getItem(); + if(!(pritem instanceof TCComponentMEProcess) && !(pritem instanceof TCComponentMEOP)) + continue; + TCComponentItemRevision prrev = procedure.getItemRevision(); + if(pritem instanceof TCComponentMEOP) + System.out.println(prrev+">>"+prrev.getReferenceProperty("root_activity").getReferenceListProperty("contents").length); + TCComponentForm prform = TCUtil.getItemRevisionMasterForm(prrev); + for(String[] prop : procedureOptions) { + if(prop[0].equals("item")) + vo.add(pritem.getProperty(prop[1])); + else if(prop[0].equals("rev")) + vo.add(prrev.getProperty(prop[1])); + else if(prop[0].equals("bom")) + vo.add(procedure.getProperty(prop[1])); + else + vo.add(prform.getProperty(prop[1])); + } + vvo.add(vo); + proceduresMap.put(vo, procedure); + } + tableMap.put(num, vvo); + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(dialog, ":"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + exportBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + Map borrowMap = new HashMap<>(); + for(String s : options.get(2)) { +// String[] split = s.split("="); + borrowMap.put(s, "true"); + } + if(processTable.getRowCount()==0) + throw new Exception("Ϊգ޷"); + TCComponentItemRevision targetRev = targetLine.getItemRevision(); + TCComponentItemRevision proRev = processVec.get(impTable.getSelectedRow()); + if(!targetRev.getType().equals(proRev.getType())) + throw new Exception("ѡͲͬ޷"); + TCComponentItemType itemType; + TCComponentForm targetForm = TCUtil.getItemRevisionMasterForm(targetRev); +// String revId = targetRev.getProperty("item_revision_id"); +// System.out.println("time1 " + (System.nanoTime() - time0) / 1000000); + int n = 0; + for(AIFComponentContext cs : targetLine.getChildren()) { + int no = Integer.parseInt(((TCComponentBOMLine)cs.getComponent()).getProperty("bl_sequence_no")); + if(no > n) + n = no; + } + if(n%10 != 0) + n = n/10*10 + 10; + else + n = n + 10; + + for(int i=0; i v = tableMap.get(impTable.getSelectedRow()).get(i); + TCComponentBOMLine p = proceduresMap.get(v); + TCComponentItemRevision procedure = p.getItemRevision(); + TCComponentItem pitem = procedure.getItem(); + String type = pitem.getType(); + itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(type); +// TCComponentItem newItem = itemType.create(itemType.getNewID(), revId, type, pitem.getProperty("object_name"), "", null); +// procedure.saveAsItem(arg0, arg1); + TCComponentItem newItem = procedure.saveAsItem(itemType.getNewID(), "A"); + TCComponentBOMLine newLine = targetLine.add(newItem, null); + TCComponentItemRevision newRev = newItem.getLatestItemRevision(); + newLine.setProperty("bl_sequence_no", n+""); + n += 10; +// copyProperty(p, newLine, num); + //TODO + TCComponentForm proForm = TCUtil.getItemRevisionMasterForm(proRev); + for(String[] ss : updateProps) { + if(ss[0].equals("rev")) { + copyProperty(proRev, targetRev, ss[1]); + }else if(ss[0].equals("master")) { + copyProperty(proForm, targetForm, ss[1]); + } + } + TCComponentForm newForm = TCUtil.getItemRevisionMasterForm(newRev); + for(String[] ss : clearProps) { + if(ss[0].equals("rev")) { + newRev.setProperty(ss[1], ""); + }else if(ss[0].equals("master")) { + newForm.setProperty(ss[1], ""); + }else if(ss[0].equals("item")) { + newItem.setProperty(ss[1], ""); + } + } +// num++; + AIFComponentContext[] children = newLine.getChildren(); + for(AIFComponentContext c : children) { +// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000); +// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000); + TCComponentBOMLine child = (TCComponentBOMLine) c.getComponent(); + TCComponentItem subitem = child.getItem(); + String subtype = subitem.getType(); +// System.out.println("child" + child +" "+ (subitem instanceof TCComponentMEOP)); + if(subitem instanceof TCComponentMEOP) { +// TCComponentItem newOpitem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null); +// TCComponentBOMLine newOpline = newLine.add(newSubItem, null); +// copyProperty(child, child, 0); + itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(subtype); + TCComponentItem newSubItem = child.getItemRevision().saveAsItem(itemType.getNewID(), ""); + TCComponentItemRevision newSubRev = newSubItem.getLatestItemRevision(); + child.replace(newSubItem, newSubRev, null); + }else if(borrowMap.containsKey(subtype)) { + if(borrowMap.get(subtype).toLowerCase().equals("false")){ + TCComponentItem newsubItem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null); +// newLine.add(newsubItem, null); + child.replace(newsubItem, newsubItem.getLatestItemRevision(), null); + } + }else { + child.cut(); + } +// else +// newLine.add(subitem, null); + } + } + /*List viewParts = PlatformHelper.getAllViewParts(); + for(Object view : viewParts) { + if(view==null || !(view instanceof CompatibilityView)) + continue; + IViewPart v = ((CompatibilityView)view).getView(); +// System.out.println("ProcessPropertyView "+((CompatibilityPart)view).ENABLE_DEPENDENCY_INJECTION_FOR_E3_PARTS); + if(!(v instanceof ProcessPropertyView)) + continue; + ProcessPropertyView pv = (ProcessPropertyView)v; + Field field = pv.getClass().getDeclaredField("panel"); + field.setAccessible(true); + Object editor = field.get(pv); +// if(editor instanceof ProcessPropertyEditor) +// ((ProcessPropertyEditor) editor).updateSelection(targetLine); + Field pfield = ((ProcessPropertyEditor) editor).getClass().getDeclaredField("propPanel"); + pfield.setAccessible(true); + Object panel = pfield.get(((ProcessPropertyEditor) editor)); + ((PropertyPanel)panel).loadData(); + }*/ + MessageBox.post(dialog, "ɹ", "ʾ", MessageBox.INFORMATION); + dispose(); + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(dialog, ""+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + } + private void copyProperty(TCComponent a, TCComponent b, String prop) throws Exception { + TCProperty property = a.getTCProperty(prop); + if(property==null) { + System.out.println(a+"δҵԣ" + prop); + return; + } + if(b.getTCProperty(prop)==null) { + System.out.println(b+"δҵԣ" + prop); + return; + } + int type = property.getPropertyType(); +// System.out.println(prop+">>" + type); + if(type==TCProperty.PROP_untyped_relation || type==TCProperty.PROP_untyped_reference){ + TCComponentPseudoFolder folder = TCUtil.getPseudoFolder(a, prop); +// System.out.println("folder:" + folder); + TCComponent[] cps; + if(folder == null) { + cps = property.getReferenceValueArray(); + }else { + AIFComponentContext[] cxs = folder.getChildren(); + cps = new TCComponent[cxs.length]; + for(int i=0; i>" + b+"==" + b.getTCProperty(prop)); + } + + /*private void copyProperty(TCComponentBOMLine p, TCComponentBOMLine toLine, int num) throws Exception { + System.out.println("copyProperty:"+p+" copyProperty " + (System.nanoTime() - time0) / 1000000); + if(p.parent()!=null) { + for(String s : propVecs.get(0)) { + toLine.setProperty(s, ""); + } + } + TCComponentItemRevision rev = toLine.getItemRevision(); + for(String s : propVecs.get(1)) { + rev.setProperty(s, ""); + } + + TCComponentItem item = rev.getItem(); + for(String s : propVecs.get(2)) { + item.setProperty(s, ""); + } + + TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev); + for(String s : propVecs.get(3)) { + form.setProperty(s, ""); + } + if(num>0) + form.setProperty("ac5_OperationNumber", num*5+""); + System.out.println("copyProperty " + (System.nanoTime() - time0) / 1000000); + } + private String getProperty(String comp, String prop, TCComponent... comps) throws Exception { + if(comp.equals("rev")) + return comps[0].getProperty(prop); + else if(comp.equals("master")) + return comps[1].getProperty(prop); + else if(comp.equals("item")) + return comps[2].getProperty(prop); + else + return ""; + }*/ +} \ No newline at end of file diff --git a/src/cn/net/connor/std/processedit/ldy/ProcessBorrowHandler.java b/src/cn/net/connor/std/processedit/ldy/ProcessBorrowHandler.java new file mode 100644 index 0000000..f0b23db --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/ProcessBorrowHandler.java @@ -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; + } +} diff --git a/src/cn/net/connor/std/processedit/ldy/ProcessBorrowOperation.java b/src/cn/net/connor/std/processedit/ldy/ProcessBorrowOperation.java new file mode 100644 index 0000000..0050120 --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/ProcessBorrowOperation.java @@ -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 revMap; + + public ProcessBorrowOperation(TCSession session, TCComponentBOMLine target) { + this.session = session; + this.target = target; + } + + @Override + public void executeOperation() throws Exception { + AIFDesktop desktop = AIFUtility.getActiveDesktop(); + try { + revMap = new HashMap<>(); + TCComponentItemType itemType = (TCComponentItemType) session.getTypeService().getTypeComponent("LD6_MEProcessCr"); + TCComponentItem item = target.getItemRevision().saveAsItem(itemType.getNewID(), null); + TCComponentBOMWindow window = TCUtil.getWindow(session); + TCComponentBOMLine bom = TCUtil.getBOMLine(session, window, item.getLatestItemRevision()); + recycle(bom); + window.save(); + window.close(); + TCComponentFolder home = session.getUser().getHomeFolder(); + home.add("contents", item); + + MessageBox.post(desktop, "·ߡ"+item+"ѴHomeļ", "INFO", MessageBox.INFORMATION); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + } + } + + private void recycle(TCComponentBOMLine parent) throws Exception { + for(AIFComponentContext c : parent.getChildren()) { + TCComponentBOMLine bom = (TCComponentBOMLine) c.getComponent(); + TCComponentItem item = bom.getItem(); + if(revMap.containsKey(item)) { + TCComponentItemRevision rev = revMap.get(item); + bom.replace(rev.getItem(), rev, null); + continue; + } + if(!item.isTypeOf(new String[] { "LD6_MEProcess", "LD6_OMEOP", "LD6_MEOP" })) + continue; + TCComponentItemType itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(item.getType()); + TCComponentItem newItem = bom.getItemRevision().saveAsItem(itemType.getNewID(), null); + TCComponentItemRevision newRev = newItem.getLatestItemRevision(); + bom.replace(newItem, newRev, null); + revMap.put(item, newRev); + + recycle(bom); + } + } +} diff --git a/src/cn/net/connor/std/processedit/ldy/ProcessDivisionDialog.java b/src/cn/net/connor/std/processedit/ldy/ProcessDivisionDialog.java new file mode 100644 index 0000000..0c7e1ce --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/ProcessDivisionDialog.java @@ -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 colList; + private ArrayList compList; + private HashMap userMap; + + public ProcessDivisionDialog(TCSession session, TCComponentBOMLine[] target, String[] options) throws Exception{ + super(AIFUtility.getActiveDesktop()); + this.session = session; + accessControlService = session.getTCAccessControlService(); + userMap = new HashMap<>(); + compList = new ArrayList<>(); + + setTitle("շֹ"); + divisionBtn = new JButton("շֹ"); + okBtn = new JButton("ȷ"); + cancelBtn = new JButton("ȡ"); + addActionListener(); + +// String[] tableHeader = new String[] { "", "", "" }; + int size = options.length; + tableHeader = new String[size+1]; + tableHeader[0] = ""; + colList = new ArrayList<>(); + for(int i=0; i v = new Vector<>(); +// v.add(table.getRowCount()+1+""); +// for(String[] s : colList) { +// if(s[0].equals("Item")) { +// v.add(item.getProperty(s[1])); +// }else if(s[0].equals("Rev")) { +// v.add(rev.getProperty(s[1])); +// }else if(s[0].equals("RevMaster")) { +// v.add(form.getProperty(s[1])); +// }else if(s[0].equals("BOMLine")) { +// v.add(line.getProperty(s[1])); +// } +// } +// model.addRow(v); +// AIFComponentContext[] cs = rev.getChildren("bom_view_tags"); +// if(cs.length>0) +// compList.add(new TCComponent[] { item, rev, form, (TCComponent) cs[0].getComponent() }); +// else +// compList.add(new TCComponent[] { item, rev, form }); +// recycleBom(line); +// } +// } + private void 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 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); + } +} diff --git a/src/cn/net/connor/std/processedit/ldy/ProcessDivisionHandler.java b/src/cn/net/connor/std/processedit/ldy/ProcessDivisionHandler.java new file mode 100644 index 0000000..163c6c4 --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/ProcessDivisionHandler.java @@ -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 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; + } + +} diff --git a/src/cn/net/connor/std/processedit/ldy/ProcessMultiplexDialog.java b/src/cn/net/connor/std/processedit/ldy/ProcessMultiplexDialog.java new file mode 100644 index 0000000..8b7b280 --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/ProcessMultiplexDialog.java @@ -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 compMap; + private String queryName; + private Vector showOptions; + private Vector procedureOptions; + private Vector processVec; +// private Vector> proceduresVec; + private Vector options; + private Map> lovMap; + private Map>> tableMap; + private Map, TCComponentBOMLine> proceduresMap; + private Vector updateProps; + private Vector clearProps; + + public ProcessMultiplexDialog(TCSession session, TCComponentBOMLine targetLine, Vector options) throws Exception { + super(AIFUtility.getActiveDesktop()); + this.session = session; + this.targetLine = targetLine; + this.options = options; + compMap = new HashMap<>(); + lovMap = new HashMap<>(); + tableMap = new HashMap<>(); + proceduresMap = new HashMap<>(); + this.showOptions = new Vector<>(); + this.procedureOptions = new Vector<>(); + this.processVec = new Vector<>(); + this.updateProps = new Vector<>(); + this.clearProps = new Vector<>(); +// tableMap = new HashMap<>(); + setTitle("ս"); + + String[] propOptions = options.get(3); + for(String s : propOptions) { + updateProps.add(s.split("\\.")); + } + propOptions = options.get(4); + for(String s : propOptions) { + clearProps.add(s.split("\\.")); + } +// JPanel msgPanel = new JPanel(new GridLayout(0,5,2,5)); + JPanel msgPanel = new JPanel(new FlowLayout()); +// String[] searchOptions = options.get(0); + String[] searchOptions = new String[] { "ID=2", "=2" }; + queryName = options.get(0)[0]; + final AbstractAIFDialog dialog = this; + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType)session.getTypeComponent("ListOfValues"); + for(String s : searchOptions) { + if(!s.contains("=")) + continue; + String[] split = s.split("="); + JLabel label = new JLabel(split[0], SwingConstants.RIGHT); + label.setPreferredSize(new Dimension(80, 23)); +// label.setHorizontalTextPosition(JLabel.RIGHT); +// JPanel propPanel = new JPanel(new BorderLayout()); + JPanel propPanel = new JPanel(new BorderLayout()); + propPanel.add(BorderLayout.WEST, label); + if(split.length==3) { + JComboBox combo = new JComboBox<>(); + combo.setPreferredSize(new Dimension(118, 23)); + if(split[2].indexOf(";")>0) { + String[] value = split[2].split(";"); + combo.addItem(""); + for(String v : value) + combo.addItem(v); + }else { + TCComponentListOfValues[] lovs = lovType.find(split[2]); + if (lovs != null && lovs.length > 0) { + ListOfValuesInfo lovInfo = lovs[0].getListOfValues(); + String[] code = lovInfo.getStringListOfValues(); + String[] name = lovInfo.getLOVDisplayValues(); + Map lovVal = new HashMap<>(); + if (code != null && name != null) { + for (int i = 0; i < code.length; i++) { + lovVal.put(name[i], code[i]); + combo.addItem(name[i]); + } + } + lovMap.put(split[0], lovVal); +// bean.lovList = TCUtil.setAutoComplete(bean, name); + }else + throw new Exception("δҵ"+split[2]+"ѡ"); + } + propPanel.add(BorderLayout.CENTER, combo); + msgPanel.add(propPanel); + compMap.put(split[0], combo); + }else if(split[1].equals("2")) { + JTextField field = new JTextField(); + field.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, field); + msgPanel.add(propPanel); + compMap.put(split[0], field); + }else if(split[1].equals("3")) { + PropertyDateComponent dateBtn = new PropertyDateComponent(); + dateBtn.setPreferredSize(new Dimension(118, 23)); + propPanel.add(BorderLayout.CENTER, dateBtn); + msgPanel.add(propPanel); + compMap.put(split[0], dateBtn); + }else if(split[1].equals("4")) { + final JTextField field = new JTextField(); + field.setEditable(false); + field.setPreferredSize(new Dimension(60, 23)); + JButton userBtn = new JButton("ѡ"); + userBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + new SelectUserDialog(field, true).showDialog(); + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post(dialog, ":"+e.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + userBtn.setPreferredSize(new Dimension(56, 23)); + propPanel.add(BorderLayout.CENTER, field); + propPanel.add(BorderLayout.EAST, userBtn); + msgPanel.add(propPanel); + compMap.put(split[0], field); + } + } + searchBtn = new JButton("ѯ"); + exportBtn = new JButton(""); + JPanel btnPanel = new JPanel(new FlowLayout()); + btnPanel.add(searchBtn); + btnPanel.add(exportBtn); + JPanel topPanel = new JPanel(new BorderLayout()); + topPanel.add(BorderLayout.WEST, msgPanel); + topPanel.add(BorderLayout.EAST, btnPanel); + + String[] itemOptions = options.get(0); + String[] tableHeader = new String[itemOptions.length]; + tableHeader[0] = ""; + for(int i=1; i getColumnClass(int column) { + if (column==0) { + return Boolean.class; + } + return super.getColumnClass(column); + } + }; +// processTable.getTableHeader().setReorderingAllowed(false); + processTable.setFillsViewportHeight(true); +// processTable.setEnabled(false); + processTable.setEnabled(true); +// processTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); + processTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + processTable.setModel(processModel); + processTable.getTableHeader().setDefaultRenderer(new CheckHeaderCellRenderer(processTable, true)); + processTable.getTableHeader().setReorderingAllowed(false); + TableColumnModel pColModel = processTable.getColumnModel(); + for(int i=1; i0) { + for(int i=processModel.getRowCount(); i>0; i--) + processModel.removeRow(i-1); + } + if(tableMap.size()==0) + return; + int i = impTable.getSelectedRow(); + for(Vector vo : tableMap.get(i)) { + processModel.addRow(vo); + } + } + }); + searchBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + if(impModel.getRowCount()>0) { + for(int i=impModel.getRowCount(); i>0; i--) + impModel.removeRow(i-1); + } + if(processModel.getRowCount()>0) { + for(int i=processModel.getRowCount(); i>0; i--) + processModel.removeRow(i-1); + } + Vector keyV = new Vector<>(); + Vector valueV = new Vector<>(); + for(Entry e : compMap.entrySet()) { + JComponent c = e.getValue(); + String text = ""; + if(c instanceof JTextField) + text = ((JTextField)c).getText(); + else if(c instanceof PropertyDateComponent) + text = ((PropertyDateComponent)c).getDateViewModel().getDateString(); + else { + text = ((JComboBox)c).getSelectedItem().toString(); + if(lovMap.containsKey(e.getKey())) { + text = lovMap.get(e.getKey()).get(text); + } + } + if(text!=null && !text.isEmpty()) { +// if(e.getKey().equals("ID")) +// text += "GY"; + keyV.add(e.getKey()); + valueV.add(text); + } + } + TCComponent[] result = TCUtil.query(session, queryName, keyV, valueV); + System.out.println("result:"+result.length); + if(result.length==0) { + MessageBox.post(dialog, "ûзĹգѯ", "ERROR", MessageBox.ERROR); + return; + } + result = TCUtil.TCsort(result, new int[] { 1, -1 }, "item_id", "item_revision_id"); + TCComponentBOPWindowType bomWinType = (TCComponentBOPWindowType) session.getTypeComponent("BOPWindow"); + TCComponentBOPWindow window = (TCComponentBOPWindow) bomWinType.createBOPWindow(null); + for(int i=0; i v = new Vector<>(); + int num = impModel.getRowCount(); + v.add(num+1+""); + TCComponentMEProcessRevision meprocess = (TCComponentMEProcessRevision) result[i]; + TCComponentItem pitem = meprocess.getItem(); + TCComponentForm form = TCUtil.getItemRevisionMasterForm(meprocess); + for(String[] prop : showOptions) { + if(prop[0].equals("item")) + v.add(pitem.getProperty(prop[1])); + else if(prop[0].equals("rev")) + v.add(meprocess.getProperty(prop[1])); + else + v.add(form.getProperty(prop[1])); + } + processVec.add(meprocess); + impModel.addRow(v); + + TCComponentBOMLine ebom = window.setWindowTopLine(pitem, meprocess, null, null); + AIFComponentContext[] p = ebom.getChildren(); + Vector> vvo = new Vector<>(); + for(AIFComponentContext c : p) { + Vector vo = new Vector<>(); + vo.add(true); + TCComponentBOMLine procedure = (TCComponentBOMLine) c.getComponent(); + TCComponentItem pritem = procedure.getItem(); + if(!(pritem instanceof TCComponentMEProcess) && !(pritem instanceof TCComponentMEOP)) + continue; + TCComponentItemRevision prrev = procedure.getItemRevision(); + if(pritem instanceof TCComponentMEOP) + System.out.println(prrev+">>"+prrev.getReferenceProperty("root_activity").getReferenceListProperty("contents").length); + TCComponentForm prform = TCUtil.getItemRevisionMasterForm(prrev); + for(String[] prop : procedureOptions) { + if(prop[0].equals("item")) + vo.add(pritem.getProperty(prop[1])); + else if(prop[0].equals("rev")) + vo.add(prrev.getProperty(prop[1])); + else if(prop[0].equals("bom")) + vo.add(procedure.getProperty(prop[1])); + else + vo.add(prform.getProperty(prop[1])); + } + vvo.add(vo); + proceduresMap.put(vo, procedure); + } + tableMap.put(num, vvo); + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(dialog, ":"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + exportBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + try { + Map borrowMap = new HashMap<>(); + for(String s : options.get(2)) { +// String[] split = s.split("="); + borrowMap.put(s, "true"); + } + if(processTable.getRowCount()==0) + throw new Exception("Ϊգ޷"); + TCComponentItemRevision targetRev = targetLine.getItemRevision(); + TCComponentItemRevision proRev = processVec.get(impTable.getSelectedRow()); + if(!targetRev.getType().equals(proRev.getType())) + throw new Exception("ѡͲͬ޷"); + TCComponentItemType itemType; + TCComponentForm targetForm = TCUtil.getItemRevisionMasterForm(targetRev); +// String revId = targetRev.getProperty("item_revision_id"); +// System.out.println("time1 " + (System.nanoTime() - time0) / 1000000); + int n = 0; + for(AIFComponentContext cs : targetLine.getChildren()) { + int no = Integer.parseInt(((TCComponentBOMLine)cs.getComponent()).getProperty("bl_sequence_no")); + if(no > n) + n = no; + } + if(n%10 != 0) + n = n/10*10 + 10; + else + n = n + 10; + + for(int i=0; i v = tableMap.get(impTable.getSelectedRow()).get(i); + TCComponentBOMLine p = proceduresMap.get(v); + TCComponentItemRevision procedure = p.getItemRevision(); + TCComponentItem pitem = procedure.getItem(); + String type = pitem.getType(); + itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(type); +// TCComponentItem newItem = itemType.create(itemType.getNewID(), revId, type, pitem.getProperty("object_name"), "", null); +// procedure.saveAsItem(arg0, arg1); + TCComponentItem newItem = procedure.getItem().getLatestItemRevision().saveAsItem(itemType.getNewID(), "001"); + newItem.lock(); + TCComponentBOMLine newLine = targetLine.add(newItem, null); + TCComponentItemRevision newRev = newItem.getLatestItemRevision(); + newLine.setProperty("bl_sequence_no", n+""); + n += 10; +// copyProperty(p, newLine, num); + //TODO + TCComponentForm proForm = TCUtil.getItemRevisionMasterForm(proRev); + for(String[] ss : updateProps) { + if(ss[0].equals("rev")) { + copyProperty(proRev, targetRev, ss[1]); + }else if(ss[0].equals("master")) { + copyProperty(proForm, targetForm, ss[1]); + } + } + TCComponentForm newForm = TCUtil.getItemRevisionMasterForm(newRev); + for(String[] ss : clearProps) { + if(ss[0].equals("rev")) { + newRev.setProperty(ss[1], ""); + }else if(ss[0].equals("master")) { + newForm.setProperty(ss[1], ""); + }else if(ss[0].equals("item")) { + newItem.setProperty(ss[1], ""); + } + } + +// num++; + AIFComponentContext[] children = newLine.getChildren(); + for(AIFComponentContext c : children) { +// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000); +// System.out.println("for2 " + (System.nanoTime() - time0) / 1000000); + TCComponentBOMLine child = (TCComponentBOMLine) c.getComponent(); + TCComponentItem subitem = child.getItem(); + String subtype = subitem.getType(); +// System.out.println("child" + child +" "+ (subitem instanceof TCComponentMEOP)); + if(subitem instanceof TCComponentMEOP) { +// TCComponentItem newOpitem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null); +// TCComponentBOMLine newOpline = newLine.add(newSubItem, null); +// copyProperty(child, child, 0); + itemType = (TCComponentItemType) session.getTypeService().getTypeComponent(subtype); + TCComponentItem newSubItem = child.getItemRevision().saveAsItem(itemType.getNewID(), ""); + TCComponentItemRevision newSubRev = newSubItem.getLatestItemRevision(); + child.replace(newSubItem, newSubRev, null); + }else if(borrowMap.containsKey(subtype)) { + if(borrowMap.get(subtype).toLowerCase().equals("false")){ + TCComponentItem newsubItem = itemType.create(itemType.getNewID(), "", subtype, subitem.getProperty("object_name"), "", null); +// newLine.add(newsubItem, null); + child.replace(newsubItem, newsubItem.getLatestItemRevision(), null); + } + }else { + child.cut(); + } +// else +// newLine.add(subitem, null); + } + newItem.save(); + newItem.unlock(); + + } + List viewParts = PlatformHelper.getAllViewParts(); + for(Object view : viewParts) { + if(view==null || !(view instanceof CompatibilityView)) + continue; +// IViewPart v = ((CompatibilityView)view).getView(); +//// System.out.println("ProcessPropertyView "+((CompatibilityPart)view).ENABLE_DEPENDENCY_INJECTION_FOR_E3_PARTS); +// if(!(v instanceof ProcessPropertyView)) +// continue; +// ProcessPropertyView pv = (ProcessPropertyView)v; +// Field field = pv.getClass().getDeclaredField("panel"); +// field.setAccessible(true); +// Object editor = field.get(pv); +//// if(editor instanceof ProcessPropertyEditor) +//// ((ProcessPropertyEditor) editor).updateSelection(targetLine); +// Field pfield = ((ProcessPropertyEditor) editor).getClass().getDeclaredField("propPanel"); +// pfield.setAccessible(true); +// Object panel = pfield.get(((ProcessPropertyEditor) editor)); +// ((PropertyPanel)panel).loadData(); + } + MessageBox.post(dialog, "ɹ", "ʾ", MessageBox.INFORMATION); + dispose(); + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post(dialog, ""+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + } + private void copyProperty(TCComponent a, TCComponent b, String prop) throws Exception { + TCProperty property = a.getTCProperty(prop); + if(property==null) { + System.out.println(a+"δҵԣ" + prop); + return; + } + if(b.getTCProperty(prop)==null) { + System.out.println(b+"δҵԣ" + prop); + return; + } + int type = property.getPropertyType(); +// System.out.println(prop+">>" + type); + if(type==TCProperty.PROP_untyped_relation || type==TCProperty.PROP_untyped_reference){ + TCComponentPseudoFolder folder = TCUtil.getPseudoFolder(a, prop); +// System.out.println("folder:" + folder); + TCComponent[] cps; + if(folder == null) { + cps = property.getReferenceValueArray(); + }else { + AIFComponentContext[] cxs = folder.getChildren(); + cps = new TCComponent[cxs.length]; + for(int i=0; i>" + b+"==" + b.getTCProperty(prop)); + } + + /*private void copyProperty(TCComponentBOMLine p, TCComponentBOMLine toLine, int num) throws Exception { + System.out.println("copyProperty:"+p+" copyProperty " + (System.nanoTime() - time0) / 1000000); + if(p.parent()!=null) { + for(String s : propVecs.get(0)) { + toLine.setProperty(s, ""); + } + } + TCComponentItemRevision rev = toLine.getItemRevision(); + for(String s : propVecs.get(1)) { + rev.setProperty(s, ""); + } + + TCComponentItem item = rev.getItem(); + for(String s : propVecs.get(2)) { + item.setProperty(s, ""); + } + + TCComponentForm form = TCUtil.getItemRevisionMasterForm(rev); + for(String s : propVecs.get(3)) { + form.setProperty(s, ""); + } + if(num>0) + form.setProperty("ac5_OperationNumber", num*5+""); + System.out.println("copyProperty " + (System.nanoTime() - time0) / 1000000); + } + private String getProperty(String comp, String prop, TCComponent... comps) throws Exception { + if(comp.equals("rev")) + return comps[0].getProperty(prop); + else if(comp.equals("master")) + return comps[1].getProperty(prop); + else if(comp.equals("item")) + return comps[2].getProperty(prop); + else + return ""; + }*/ +} \ No newline at end of file diff --git a/src/cn/net/connor/std/processedit/ldy/ProcessMultiplexHandler.java b/src/cn/net/connor/std/processedit/ldy/ProcessMultiplexHandler.java new file mode 100644 index 0000000..af69bb6 --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/ProcessMultiplexHandler.java @@ -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 options = new Vector<>(); + for(String s : prefs) { +// if(s.equals("Connor_AVIC_GYJY_Borrow")) { +// options.add(new String[] {}); +// continue; +// } + String searchOptions[] = session.getPreferenceService().getStringValues(s); + if(searchOptions == null) { +// MessageBox.post(desktop, "ѡ"+s+"òȷ", "ERROR", MessageBox.ERROR); +// return null; + options.add(new String[] {}); + continue; + } + options.add(searchOptions); + } + new ProcessMultiplexDialog(session, (TCComponentBOMLine)target, options); + }catch(Exception e) { + e.printStackTrace(); + MessageBox.post(desktop, ""+e.getMessage(), "ERROR", MessageBox.ERROR); + return null; + } + return null; + } +} diff --git a/src/cn/net/connor/std/processedit/ldy/SelectUserDialog.java b/src/cn/net/connor/std/processedit/ldy/SelectUserDialog.java new file mode 100644 index 0000000..ac830e0 --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/SelectUserDialog.java @@ -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 l_user; + private DefaultListModel lm_user; + private JTextField editPropMap; +// private String group; + private boolean isMulti; + private JTable table; + private int colIndex; + private int[] rowIndex; + private TCComponentProject project; + private HashMap userMap; + + public SelectUserDialog(JTextField editPropMap, boolean isMulti) throws Exception { + super(true); + this.editPropMap = editPropMap; + this.isMulti = isMulti; + initUI(); + } + + private String getValue() { + String val = ""; + if (editPropMap != null) { + val = editPropMap.getText(); + } else if (table != null) { + val = (String) table.getValueAt(rowIndex[0], colIndex); + } + return val; + } + + private void setValue(String text) { + if (editPropMap != null) { + editPropMap.setText(text); + } else if (table != null) { + for(int i : rowIndex) + table.setValueAt(text, i, colIndex); + } + } + + public SelectUserDialog(JTable table, boolean isMulti, int[] rowIndex, int colIndex, TCComponentProject projectID) throws Exception { + super(true); + this.table = table; + this.isMulti = isMulti; + this.colIndex = colIndex; + this.rowIndex = rowIndex; + this.project = projectID; + initUI(); + } + + public SelectUserDialog(JTable table, int[] rowIndex, int colIndex, HashMap userMap) throws Exception { + super(true); + this.table = table; + this.colIndex = colIndex; + this.rowIndex = rowIndex; + this.userMap = userMap; + initUI(); + } + + private void initUI() throws Exception { + this.setTitle("ѡԱ"); + this.setLayout(new BorderLayout()); + int pweight = 440, pheight = 480, mweight = 280, mheight = 320; + if (isMulti) { +// this.setPreferredSize(new Dimension(640, 480)); +// this.setMinimumSize(new Dimension(480, 320)); + pweight = 640; + mweight = 480; + } + if(project != null) { + pheight = 700; + mheight = 700; + } + this.setPreferredSize(new Dimension(pweight, pheight)); + this.setMinimumSize(new Dimension(mweight, mheight)); + OrgTreePanel orgPanel = new OrgTreePanel((TCSession) AIFUtility.getCurrentApplication().getSession()); + this.tree = orgPanel.getOrgTree(); + + if(project != null) { + JPanel panel = new JPanel(new PropertyLayout()); + panel.add("1.1.center.center", orgPanel); + panel.add("2.1.center.center", initProjectPanel(orgPanel)); +// FlowLayout flow = new FlowLayout(); +// flow.setAlignOnBaseline(true); +// JPanel panel = new JPanel(flow); +// panel.add(orgPanel); +// panel.add(initProjectPanel(orgPanel)); + this.add(BorderLayout.WEST, panel); + }else { + this.add(BorderLayout.CENTER, orgPanel); + } + this.add(BorderLayout.SOUTH, initBtnPanel()); + if (isMulti) { + JPanel lp = initListPanel(); + this.add(BorderLayout.EAST, lp); + initData(); + } + addListeners(); + this.setAlwaysOnTop(true); + } + + private void initData() { + String text = getValue(); + if (text.isEmpty()) { + return; + } + String[] split = text.split(","); + for (int i = 0; i < split.length; i++) { + lm_user.addElement(split[i]); + } + } + + private JPanel initListPanel() { + JPanel panel = new JPanel(new BorderLayout()); + FlowLayout flow = new FlowLayout(); + flow.setVgap(100); + JPanel btnPanel = new JPanel(flow); + btnPanel.add(this.add); +// btnPanel.add("2.1.center.center", this.remove); + this.lm_user = new DefaultListModel<>(); + this.l_user = new JList<>(lm_user); + l_user.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + this.l_user.setCellRenderer(new DeleteListRenderer(l_user)); + JScrollPane scroll = new JScrollPane(l_user); + scroll.setPreferredSize(new Dimension(200, 0)); +// this.add.setPreferredSize(new Dimension(50, 30)); + panel.add(BorderLayout.WEST, btnPanel); + panel.add(BorderLayout.CENTER, scroll); + return panel; + } + + private JPanel initBtnPanel() { + JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 5)); + this.b_ok = new JButton("ȷ"); + this.b_cel = new JButton("ȡ"); + this.add = new JButton("+"); + this.remove = new JButton("-"); + panel.add(b_ok); + panel.add(b_cel); + return panel; + } + + private JScrollPane initProjectPanel(OrgTreePanel orgPanel) throws Exception {//TODO + Dimension orgDimension = orgPanel.getPreferredSize(); + orgPanel.setPreferredSize(new Dimension(orgDimension.width*2, orgDimension.height-100)); + DefaultMutableTreeNode root = new DefaultMutableTreeNode(project.getProjectID(), true); + projectTree = new JTree(root); + + List team = project.getTeam(); + TCComponent[] members = (TCComponent[])team.get(0); + for(TCComponent c : members) { + if(c instanceof TCComponentGroupMember) { + TCComponentGroupMember member = (TCComponentGroupMember)c; + DefaultMutableTreeNode childRoot = new DefaultMutableTreeNode(member, true); + root.add(childRoot); + } + } + + projectTree.setPreferredSize(new Dimension(orgDimension.width*2, orgDimension.height/2)); +// projectTree.setMaximumSize(new Dimension(orgDimension.width*2, orgDimension.height/2)); + JScrollPane projectPane = new JScrollPane(projectTree); + return projectPane; + } + + private TCComponentUser getSelectUser() throws Exception { +// Object[] comps = tree.getSelectedOrgObjects(); + AIFTreeNode[] comps = tree.getSelectedNodes(); +// System.out.println("comps:"+(comps==null)); + if (comps == null) { + if(projectTree == null) + return null; + else if(projectTree.getSelectionModel() == null) + return null; + else if(projectTree.getLastSelectedPathComponent() == null) + return null; + DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) projectTree.getLastSelectedPathComponent(); + Object selectObject = selectNode.getUserObject(); + if(selectObject instanceof TCComponentGroupMember) { +// String member = ((TCComponentGroupMember) selectObject).toString(); +// if(member.indexOf(".")>0) +// group = member.substring(0, member.indexOf(".")); +// else +// group = member.substring(0, member.indexOf("/")); + TCComponentUser user = ((TCComponentGroupMember) selectObject).getUser(); + if (user != null) { + return user; + } + }else + return null; + } +// System.out.println("comps:"+comps.length); + for (int i = 0; i < comps.length; i++) { +// OrgObject comp = (OrgObject) comps[i]; + TCComponent gm = (TCComponent) comps[i].getContextComponent().getComponent(); +// System.out.println("gm:"+gm); + if (gm != null && (gm instanceof TCComponentGroupMember)) { + TCComponentUser user = ((TCComponentGroupMember) gm).getUser(); + if (user != null) { +// group = ((DefaultMutableTreeNode)comps[i].getParent().getParent()).getUserObject().toString(); + return user; + } + } + } + return null; + } + + private void addListeners() { + this.b_cel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + disposeDialog(); + } + }); + this.b_ok.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + if (isMulti) { + int size = lm_user.getSize(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < size; i++) { + String text = lm_user.getElementAt(i); + if (text != null) { + sb.append(text).append(";"); + } + } + if (sb.length() > 0) { + sb.setLength(sb.length() - 1); + } + setValue(sb.toString()); + } else { + TCComponentUser user = getSelectUser(); + if (user != null) { + String value = user.getUserId() +"/"+ user.getUserName(); + userMap.put(value, user); + setValue(value); + } else { + setValue(""); + } + } + disposeDialog(); + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + + tree.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + try { + super.mouseClicked(e); + if(projectTree != null) + projectTree.clearSelection(); + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + TCComponentUser user = getSelectUser(); + System.out.println("user:"+user); + if (user != null) { + if (isMulti) { + if (!lm_user.contains(user.toString())) { + lm_user.addElement(user.toString()); + } + } else { + String value = user.getUserId() +"/"+ user.getUserName(); + userMap.put(value, user); + setValue(value); + disposeDialog(); + } + } + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + if(projectTree != null) { + projectTree.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + try { + super.mouseClicked(e); + tree.clearSelection(); + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + TCComponentUser user = getSelectUser(); + if (user != null) { + if (isMulti) { + if (!lm_user.contains(user.toString())) { + lm_user.addElement(user.toString()); + } + } else { + String value = user.getUserId() +"/"+ user.getUserName(); + userMap.put(value, user); + setValue(value); + disposeDialog(); + } + } + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + } + if(l_user!=null) { + this.l_user.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + int ind = l_user.getSelectedIndex(); + if (ind >= 0) { + lm_user.remove(ind); + } + } + + @Override + public void mouseEntered(MouseEvent e) { + super.mouseEntered(e); + } + + @Override + public void mouseExited(MouseEvent e) { + super.mouseExited(e); + } + + }); + } + this.add.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + TCComponentUser user = getSelectUser(); + System.out.println("user:"+user); + if (user != null) { + if (!lm_user.contains(user.toString())) { + lm_user.addElement(user.toString()); + } + } + } catch (Exception e1) { + e1.printStackTrace(); + MessageBox.post("Error:"+e1.getMessage(), "ERROR", MessageBox.ERROR); + } + } + }); + this.remove.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + disposeDialog(); + } + }); + } + private class DeleteListRenderer extends JPanel implements ListCellRenderer { + + /** + * + */ + private static final long serialVersionUID = 1L; + JButton btn; + JLabel label; + + public DeleteListRenderer(final JList list) { + this.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 1)); + this.setBackground(Color.WHITE); + btn = getDeletetBtn(); + label = new JLabel(""); + this.add(btn); + this.add(label); + + btn.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + int ind = list.getSelectedIndex(); + System.out.println(ind); + if (ind >= 0) { + list.remove(ind); + } + } + }); + + } + @Override + public Component getListCellRendererComponent(JList list, String value, int index, + boolean isSelected, boolean cellHasFocus) { + label.setText(value); + return this; + } + private JButton getDeletetBtn() { + ImageIcon icon = new ImageIcon(SelectUserDialog.class.getResource("image/delete.png")); + JButton btn = new JButton(icon); + btn.setPreferredSize(new Dimension(23, 23)); + btn.setContentAreaFilled(false); + btn.setFocusPainted(false); + btn.setBorderPainted(false); + btn.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + return btn; + } + } +} diff --git a/src/cn/net/connor/std/processedit/ldy/TCUtil.java b/src/cn/net/connor/std/processedit/ldy/TCUtil.java new file mode 100644 index 0000000..f086dfa --- /dev/null +++ b/src/cn/net/connor/std/processedit/ldy/TCUtil.java @@ -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||dialogSize.getHeight()>MINHEIGHT)) { abstractAIFDialog.setSize(new + * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20))); + * abstractAIFDialog.setLocation(10, 10); } + */ + } + + public static void fitToScreen(OpenFormDialog openFormDialog) { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + double screenWidth = screenSize.getWidth(); + double screenHeight = screenSize.getHeight(); + Dimension dialogSize = openFormDialog.getSize(); + if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) { + openFormDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight()))); + openFormDialog.setLocation(10, (int) Math.floor(openFormDialog.getLocation().getY())); + } + if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) { + openFormDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20))); + openFormDialog.setLocation((int) Math.floor(openFormDialog.getLocation().getX()), 10); + } + /* + * if((screenWidth + * MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { openFormDialog.setSize(new + * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20))); + * openFormDialog.setLocation(10, 10); } + */ + } + + public static TCComponentBOMWindow getWindow(TCSession session) throws Exception{ + TCComponentBOMWindow window = null; + TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + window = bomWinType.create(null); + return window; + } + + @SuppressWarnings("deprecation") + public static TCComponentBOMLine getBOMLine(TCSession session,TCComponentBOMWindow window, TCComponentItemRevision revision) + throws Exception { + window.lock(); + TCComponentBOMLine bomLine = window.setWindowTopLine(null, revision, null, null); + window.save(); + window.unlock(); + return bomLine; + } + public static TCComponentPseudoFolder getPseudoFolder(TCComponent parent, String relation) + throws Exception { + TCComponentPseudoFolder pseudoFolder = null; + AIFComponentContext[] comps = parent.getChildren(); + if (comps != null && comps.length > 0 && comps[0] != null) { + for (int i = 0; i < comps.length; i++) { + TCComponent comp = (TCComponent) comps[i].getComponent(); + if (comp instanceof TCComponentPseudoFolder) { + if (comp.isTypeOf("PseudoFolder")) { +// System.out.println("PseudoFolder type:" + comp.getDefaultPasteRelation()); + if (comp.getDefaultPasteRelation().equalsIgnoreCase(relation)) { + pseudoFolder = (TCComponentPseudoFolder) comp; + break; + } + } + } + } + } + return pseudoFolder; + } + public static TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws Exception { + if (revision != null) { + AIFComponentContext[] contexts = revision.getChildren("IMAN_master_form_rev"); + if (contexts != null && contexts.length > 0) { + InterfaceAIFComponent component = contexts[0].getComponent(); + if (component instanceof TCComponentForm) { + return (TCComponentForm) component; + } + } + } + return null; + } + public static TCComponentItemRevision getRevisionFromMaster(TCComponentForm form) throws Exception { + if (form != null) { + AIFComponentContext[] contexts = form.whereReferencedByTypeRelation(null, new String[] { "IMAN_master_form_rev" }); + if (contexts != null && contexts.length > 0) { + InterfaceAIFComponent component = contexts[0].getComponent(); + if (component instanceof TCComponentItemRevision) { + return (TCComponentItemRevision) component; + } + } + } + return null; + } + + public static LinkedHashMap getlovValues(TCSession session, String lovName) throws TCException { + LinkedHashMap lovVal = new LinkedHashMap(); + TCComponentListOfValuesType lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues"); + TCComponentListOfValues[] lovs = lovType.find(lovName); + if (lovs != null && lovs.length > 0) { + TCComponentListOfValues lov = lovs[0]; + ListOfValuesInfo lovInfo = lov.getListOfValues(); + String[] code = lovInfo.getStringListOfValues(); + String[] name = lovInfo.getLOVDisplayValues(); + if (code != null && name != null) { + for (int i = 0; i < code.length; i++) { + // System.out.printf("code[%d]=%s name[%d]=%s \n", i, code[i], i, name[i]); + lovVal.put(code[i], name[i]); + } + } + return lovVal; + } + return null; + } + + public static String getTableValue(JTable table, int row, int col){ + Object val = table.getValueAt(row, col); + if(val==null) + return ""; + else + return val.toString(); + } + public static TCComponent[] query(TCSession session, String queryName, String[] aKey, String[] aVal) throws Exception { + TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); + if (imancomponentquery == null) { + throw new Exception("δҵѯ " + queryName + "!"); + } + aKey = session.getTextService().getTextValues(aKey); +// for (int i = 0; i < aKey.length; i++) { +// System.out.println(aKey[i] + "===============" + aVal[i]); +// } + TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(aKey, aVal); + return componentContextList.toTCComponentArray(); + } + public static TCComponent[] query(TCSession session, String queryName, Vector Keys, Vector Vals) throws Exception { + TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); + TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); + if (imancomponentquery == null) { + System.out.println("δҵѯ" + queryName); + throw new Exception("Query:"+queryName+" cannot find"); + } + TCQueryClause[] qc = imancomponentquery.describe(); +// Map clauseMap = new HashMap<>(); + for(TCQueryClause c : qc) { + String key = c.getUserEntryNameDisplay(); + String value = c.getDefaultValue(); +// System.out.println(key + "==>" + c.getAttributeName()); + if(!value.trim().isEmpty() && !Keys.contains(key)) { + if(key.isEmpty()) + Keys.add(c.getAttributeName()); + else + Keys.add(key); + Vals.add(value); + } + } + int size = Keys.size(); + String[] keyA = new String[size]; + String[] valueA = new String[size]; + for(int i=0; i 0) { + Integer maxId = 0; + for (TCComponent comp : comps) { + String pid = comp.getProperty("item_id"); + System.out.println("pid:" + pid); + String pidSuffix = pid.substring(pid.length() - 3); + if (Integer.parseInt(pidSuffix) > maxId) { + maxId = Integer.parseInt(pidSuffix); + } + } + return String.format("%03d", maxId + 1); + } + return "001"; + } + + public static File saveExcelChooser() { + File dir = null; + JFileChooser chooser = new JFileChooser(); + chooser.setAcceptAllFileFilterUsed(false); +// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); + File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); + chooser.setCurrentDirectory(desktopDir); + String saveType[] = { "xlsx" }; + chooser.setFileFilter(new FileNameExtensionFilter("Excel", saveType)); + int returnVal = chooser.showSaveDialog(new Frame()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + dir = chooser.getSelectedFile(); + String path = dir.getPath(); + if(!path.toLowerCase().endsWith(".xlsx")) { + path += ".xlsx"; + dir = new File(path); + } + System.out.println("saveExcelChooser1:" + path); + } + return dir; + } + + public static File saveExcelChooser(String defaultFile) { + File dir = null; + JFileChooser chooser = new JFileChooser(); + chooser.setAcceptAllFileFilterUsed(false); +// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); + File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); + chooser.setCurrentDirectory(desktopDir); + chooser.setSelectedFile(new File(defaultFile)); + String saveType[] = { "xlsx" }; + chooser.setFileFilter(new FileNameExtensionFilter("Excel", saveType)); + int returnVal = chooser.showSaveDialog(new Frame()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + dir = chooser.getSelectedFile(); + String path = dir.getPath(); + if(!path.toLowerCase().endsWith(".xlsx")) { + path += ".xlsx"; + dir = new File(path); + } + if(dir.exists()) + dir.delete(); +// System.out.println("saveExcelChooser1:" + dir.getPath()); + } + return dir; + } + + public static boolean contains(String[] array, String str) { + for(String s : array) { +// System.out.println("contains:"+s+"="+str); + if(s.equals(str)) + return true; + } + return false; + } + + public static Map executeToMap(InputStream in){ + System.out.println("Read properties file"); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); + String line = null; + Map resultMap = new LinkedHashMap<>(16); + if (reader.ready()) { + while (null != (line = reader.readLine())) { + if (line.length() <= 0 || line.contains("#") || !line.contains("=")) { + continue; + } + resultMap.put(line.substring(0, line.indexOf("=")), line.substring(line.indexOf("=") + 1)); + } + } + in.close(); + reader.close(); + return resultMap; + } catch (Exception e) { + e.printStackTrace(); + MessageBox.post("Find properties file failed", "ERROR", MessageBox.ERROR); + } + return null; + } + + public static TCComponentDataset createExcelDataset(TCSession session, File file, String datasetName) throws Exception { + String refType = null, objType = null, fileName = null; + fileName = file.getName().toLowerCase(); + if (fileName.endsWith("xls")) { + refType = "excel"; + objType = "MSExcel"; + } else if (fileName.endsWith("xlsx")) { + refType = "excel"; + objType = "MSExcelX"; + } + TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService().getTypeComponent("Dataset"); + TCComponentDataset dataset = compType.create(datasetName, "description", objType); + dataset.setFiles(new String[] { file.getAbsolutePath() }, new String[] { refType }); + return dataset; + } + + public static Vector getChildren(TCComponent parent, String relation, String name) throws Exception { + Vector result = new Vector<>(); + AIFComponentContext[] children; + if(relation==null || relation.isEmpty()) + children = parent.getChildren(); + else + children = parent.getChildren(relation); + for(AIFComponentContext c : children) { + TCComponent comp = (TCComponent) c.getComponent(); + if(comp.getProperty("object_name").equals(name)) + result.add(comp); + } + return result; + } + + /** + * Ϊѯ + * TCComponentѯ propertyո + */ + public static TCComponent[] TCsort(TCComponent[] TCComponent, String property, int desc) { + HashMap map = new HashMap<>(); + int count = TCComponent.length; + for(TCComponent Component : TCComponent) { + try { + map.put(Component, Component.getProperty(property)); + } catch (Exception e) { + e.printStackTrace(); + } + } + // ͨArrayList캯map.entrySet()תlist + List> list = new ArrayList>(map.entrySet()); + // ͨȽʵֱȽ + Collections.sort(list, new Comparator>() { + public int compare(Map.Entry mapping1, Map.Entry mapping2) { + return mapping1.getValue().compareTo(mapping2.getValue()) * desc; + } + }); + TCComponent = new TCComponent[count]; + int i=0; + for(Map.Entry mapping : list) { + TCComponent[i] = mapping.getKey(); + i++; + } + return TCComponent; + } + public static TCComponent[] TCsort(TCComponent[] TCComponent, int[] desc, String... property) { + HashMap map = new HashMap<>(); + int count = TCComponent.length; + for(TCComponent Component : TCComponent) { + try { + String[] values = new String[property.length]; + for(int i=0; i> list = new ArrayList>(map.entrySet()); + // ͨȽʵֱȽ + Collections.sort(list, new Comparator>() { + public int compare(Map.Entry mapping1, Map.Entry mapping2) { + String[] v1 = mapping1.getValue(), v2 = mapping2.getValue(); + for(int i=0; i mapping : list) { + TCComponent[i] = mapping.getKey(); + i++; + } + return TCComponent; + } + + public static void deleteWarning(File file) throws Exception { + FileInputStream input = null; + FileOutputStream output = null; + try { + input = new FileInputStream(file); + XWPFDocument doc = new XWPFDocument(input); +// XWPFParagraph para = doc.getParagraphs().get(0); +// System.out.println("para.getRuns:"+para.getRuns().size()); +// for(XWPFRun run : para.getRuns()) { +// System.out.println("run:"+run.getText(0)); +// } + doc.removeBodyElement(0); +// para.removeRun(0); +// System.out.println("para.getRuns:"+para.getRuns().size()+" getParagraphs:"+doc.getParagraphs().get(0).getText()); +// para.setPageBreak(false); + output = new FileOutputStream(file.getPath()); + doc.write(output); + }catch (Exception e) { + throw e; + }finally { + if(input!=null) + input.close(); + if(output!=null) + output.close(); + } + } + + public static int findChar(String str, char a, int num) throws Exception { + int n = 1; + for(int i=0; i 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); + } + +} \ No newline at end of file diff --git a/src/cn/net/connor/std/processedit/meopviewfx/bean/KTableRow.java b/src/cn/net/connor/std/processedit/meopviewfx/bean/KTableRow.java new file mode 100644 index 0000000..8d6c9c1 --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/bean/KTableRow.java @@ -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 stringProps = new HashMap(); + protected Map savedValues = new HashMap(); + + 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 bomlinePropMap, Map itemPropMap, Map revPropMap, Map itemMasterPropMap, + Map 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 revPropMap = new HashMap<>(); + Map revMasterPropMap = new HashMap<>(); + Map itemPropMap = new HashMap<>(); + Map itemMasterPropMap = new HashMap<>(); + Map 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() { + // @Override + // public void changed(ObservableValue 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); + } +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/bean/KTableRowBackup20220509.java b/src/cn/net/connor/std/processedit/meopviewfx/bean/KTableRowBackup20220509.java new file mode 100644 index 0000000..0341356 --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/bean/KTableRowBackup20220509.java @@ -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 stringProps = new HashMap(); + protected Map savedValues = new HashMap(); + + 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 bomlinePropMap, Map itemPropMap, Map revPropMap, Map itemMasterPropMap, + Map 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 revPropMap = new HashMap<>(); + Map revMasterPropMap = new HashMap<>(); + Map itemPropMap = new HashMap<>(); + Map itemMasterPropMap = new HashMap<>(); + Map 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; + } + +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/bean/KTableRowMEActivity.java b/src/cn/net/connor/std/processedit/meopviewfx/bean/KTableRowMEActivity.java new file mode 100644 index 0000000..9eaf910 --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/bean/KTableRowMEActivity.java @@ -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 bomlinePropMap , Map 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 itemPropMap = new HashMap<>(); + Map 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); + } + } + +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/bean/PropConfig.java b/src/cn/net/connor/std/processedit/meopviewfx/bean/PropConfig.java new file mode 100644 index 0000000..a2fd32e --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/bean/PropConfig.java @@ -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; + } +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/bean/TextBean.java b/src/cn/net/connor/std/processedit/meopviewfx/bean/TextBean.java new file mode 100644 index 0000000..041577a --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/bean/TextBean.java @@ -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 children = new ArrayList(); + + 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; + } + +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/reorder/ReorderDialog.java b/src/cn/net/connor/std/processedit/meopviewfx/reorder/ReorderDialog.java new file mode 100644 index 0000000..349391a --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/reorder/ReorderDialog.java @@ -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 table; + private Map sequenceConfigMap; + + public ReorderDialog(TableView table, Map 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; + } + +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/reorder/ReorderDialogController.java b/src/cn/net/connor/std/processedit/meopviewfx/reorder/ReorderDialogController.java new file mode 100644 index 0000000..3539e97 --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/reorder/ReorderDialogController.java @@ -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; + } + +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/reorder/reorder.properties b/src/cn/net/connor/std/processedit/meopviewfx/reorder/reorder.properties new file mode 100644 index 0000000..237f9ed --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/reorder/reorder.properties @@ -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 \ No newline at end of file diff --git a/src/cn/net/connor/std/processedit/meopviewfx/ui/KFXEditableStringAreaHtmlTableCell.java b/src/cn/net/connor/std/processedit/meopviewfx/ui/KFXEditableStringAreaHtmlTableCell.java new file mode 100644 index 0000000..645ec70 --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/ui/KFXEditableStringAreaHtmlTableCell.java @@ -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 + * @param + */ + +public class KFXEditableStringAreaHtmlTableCell extends TableCell { + + 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 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 table = getTableView(); + // if (table == null) { + // return; + // } + // TableRow row = getTableRow(); + // int rowNum = row.getIndex(); + // if (rowNum < 0) { + // return; + // } + // TableColumn 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() { + @Override + public void changed(ObservableValue 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("") ? 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("") ? 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() { + @Override + public void changed(ObservableValue arg0, Boolean arg1, Boolean arg2) { + if (arg2) { + SwingTextContextActivator.instance().activateContext(); + } else { + SwingTextContextActivator.instance().deactivateContext(); + } + } + }); + if (textLocator != null) { + textArea.focusedProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue 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() { + @Override + public void changed(ObservableValue 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()); + } + } + +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/ui/KFXEditableStringAreaHtmlTableCellBackup20220409.java b/src/cn/net/connor/std/processedit/meopviewfx/ui/KFXEditableStringAreaHtmlTableCellBackup20220409.java new file mode 100644 index 0000000..b4c8b8b --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/ui/KFXEditableStringAreaHtmlTableCellBackup20220409.java @@ -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 + * @param + */ + +public class KFXEditableStringAreaHtmlTableCellBackup20220409 extends TableCell { + 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 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("") ? 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("") ? 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() { + @Override + public void changed(ObservableValue 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() { + @Override + public void changed(ObservableValue 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() { +// @Override +// public void changed(ObservableValue 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 table = getTableView(); + if (table == null) { + return; + } + TableRow row = getTableRow(); + int rowNum = row.getIndex(); + if (rowNum < 0) { + return; + } + TableColumn 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() { + @Override + public void changed(ObservableValue 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 table = getTableView(); + if (table == null) { + return; + } + TableRow row = getTableRow(); + int rowNum = row.getIndex(); + if (rowNum < 0) { + return; + } + TableColumn 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()); + } + } + +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/ui/KFXEditableStringAreaHtmlTableCellBackup20220509.java b/src/cn/net/connor/std/processedit/meopviewfx/ui/KFXEditableStringAreaHtmlTableCellBackup20220509.java new file mode 100644 index 0000000..5793ffd --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/ui/KFXEditableStringAreaHtmlTableCellBackup20220509.java @@ -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 + * @param + */ + +public class KFXEditableStringAreaHtmlTableCellBackup20220509 extends TableCell { + + 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 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() { + @Override + public void changed(ObservableValue 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 table = getTableView(); + if (table == null) { + return; + } + TableRow row = getTableRow(); + int rowNum = row.getIndex(); + if (rowNum < 0) { + return; + } + TableColumn 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("") ? 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("") ? 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() { + @Override + public void changed(ObservableValue arg0, Boolean arg1, Boolean arg2) { + if(arg2) { + SwingTextContextActivator.instance().activateContext(); + }else { + SwingTextContextActivator.instance().deactivateContext(); + } + } + }); + if (textLocator != null) { + textArea.focusedProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue 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() { + @Override + public void changed(ObservableValue 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() { + @Override + public void changed(ObservableValue 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 table = getTableView(); + if (table == null) { + return; + } + TableRow row = getTableRow(); + int rowNum = row.getIndex(); + if (rowNum < 0) { + return; + } + TableColumn 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()); + } + } + +} diff --git a/src/cn/net/connor/std/processedit/meopviewfx/ui/MEOPPanel.fxml b/src/cn/net/connor/std/processedit/meopviewfx/ui/MEOPPanel.fxml new file mode 100644 index 0000000..27bbf77 --- /dev/null +++ b/src/cn/net/connor/std/processedit/meopviewfx/ui/MEOPPanel.fxml @@ -0,0 +1,94 @@ + + + + + + + + + + + +
+ + + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + + + + + + + + + +