first commit

main
李建辉 1 month ago
commit f124be2196

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/aspose-cells-18.9.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/commons-codec-1.13.jar"/>
<classpathentry kind="lib" path="lib/commons-collections4-4.4.jar"/>
<classpathentry kind="lib" path="lib/commons-compress-1.19.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.9.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.2.jar"/>
<classpathentry kind="lib" path="lib/commons-math3-3.6.1.jar"/>
<classpathentry kind="lib" path="lib/datepicker.jar"/>
<classpathentry kind="lib" path="lib/fastjson-1.2.9.jar"/>
<classpathentry kind="lib" path="lib/hutool-all-5.0.7.jar" sourcepath="C:/Users/5RKB5B~1/AppData/Local/Temp/.org.sf.feeling.decompiler1604022865349/source/hutool-all-5.0.7-sources-1604023924461.jar"/>
<classpathentry kind="lib" path="lib/jaxb-api-2.3.1.jar"/>
<classpathentry kind="lib" path="lib/jaxb-core-2.3.0.1.jar"/>
<classpathentry kind="lib" path="lib/jaxb-impl-2.3.2.jar"/>
<classpathentry kind="lib" path="lib/jfxrt.jar"/>
<classpathentry kind="lib" path="lib/ojdbc6.jar"/>
<classpathentry kind="lib" path="lib/poi-4.1.1.jar"/>
<classpathentry kind="lib" path="lib/poi-examples-4.1.1.jar"/>
<classpathentry kind="lib" path="lib/poi-excelant-4.1.1.jar"/>
<classpathentry kind="lib" path="lib/poi-ooxml-4.1.1.jar"/>
<classpathentry kind="lib" path="lib/poi-ooxml-schemas-4.1.1.jar"/>
<classpathentry kind="lib" path="lib/poi-scratchpad-4.1.1.jar"/>
<classpathentry kind="lib" path="lib/xmlbeans-3.1.0.jar"/>
<classpathentry kind="lib" path="lib/sqljdbc4.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored

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

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

@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/com/connor/jd/plm/handlers/Wf001ScheduleHandler.java=UTF-8
encoding//src/com/connor/jd/plm/utils/JDMethodUtil.java=UTF-8

@ -0,0 +1,13 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

@ -0,0 +1,68 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JDProject
Bundle-SymbolicName: com.connor.lyBOMManagement;singleton:=true
Bundle-Version: 1.0.0
Require-Bundle: org.eclipse.ui;bundle-version="3.108.0",
com.teamcenter.rac.common;bundle-version="12000.1.0",
com.teamcenter.rac.tcapps;bundle-version="12000.1.0",
com.teamcenter.rac.util;bundle-version="12000.1.0",
com.teamcenter.rac.aifrcp;bundle-version="12000.1.0",
com.teamcenter.rac.ui.commands;bundle-version="12000.1.0",
com.teamcenter.rac.kernel;bundle-version="12000.1.0",
org.eclipse.ui.views;bundle-version="3.8.100",
org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.ui.forms;bundle-version="3.7.0",
com.teamcenter.rac.schedule;bundle-version="12000.1.0",
TcSoaCommon;bundle-version="12000.2.0",
com.teamcenter.rac.workflow.processviewer;bundle-version="12000.2.0",
com.teamcenter.rac.workflow.processdesigner;bundle-version="12000.2.0"
Automatic-Module-Name: JDProject
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: com.connor.jd.operations,
com.connor.jd.plm.action,
com.connor.jd.plm.beans,
com.connor.jd.plm.dialog,
com.connor.jd.plm.dialogs,
com.connor.jd.plm.form,
com.connor.jd.plm.handlers,
com.connor.jd.plm.table,
com.connor.jd.plm.util,
com.connor.jd.plm.utils,
com.teamcenter.rac.stylesheet
Import-Package: com.connor.jd.plm.beans,
com.connor.jd.plm.table,
com.teamcenter.services,
com.teamcenter.services.rac,
com.teamcenter.services.rac.core,
com.teamcenter.services.rac.core._2008_06,
org.apache.http.client,
org.apache.http.client.methods,
org.apache.http.client.params,
org.apache.http.client.protocol,
org.apache.log4j
Bundle-ClassPath: .,
lib/fastjson-1.2.9.jar,
lib/hutool-all-5.0.7.jar,
lib/commons-codec-1.13.jar,
lib/commons-collections4-4.4.jar,
lib/commons-compress-1.19.jar,
lib/commons-logging-1.2.jar,
lib/commons-math3-3.6.1.jar,
lib/jaxb-api-2.3.1.jar,
lib/jaxb-core-2.3.0.1.jar,
lib/jaxb-impl-2.3.2.jar,
lib/jfxrt.jar,
lib/poi-4.1.1.jar,
lib/poi-examples-4.1.1.jar,
lib/poi-excelant-4.1.1.jar,
lib/poi-ooxml-4.1.1.jar,
lib/poi-ooxml-schemas-4.1.1.jar,
lib/poi-scratchpad-4.1.1.jar,
lib/xmlbeans-3.1.0.jar,
lib/commons-lang3-3.9.jar,
lib/ojdbc6.jar,
config/,
lib/datepicker.jar,
lib/aspose-cells-18.9.jar,
lib/sqljdbc4.jar

@ -0,0 +1,31 @@
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/,\
lib/fastjson-1.2.9.jar,\
lib/hutool-all-5.0.7.jar,\
lib/commons-codec-1.13.jar,\
lib/commons-collections4-4.4.jar,\
lib/commons-compress-1.19.jar,\
lib/commons-logging-1.2.jar,\
lib/commons-math3-3.6.1.jar,\
lib/jaxb-api-2.3.1.jar,\
lib/jaxb-core-2.3.0.1.jar,\
lib/jaxb-impl-2.3.2.jar,\
lib/jfxrt.jar,\
lib/poi-4.1.1.jar,\
lib/poi-examples-4.1.1.jar,\
lib/poi-excelant-4.1.1.jar,\
lib/poi-ooxml-4.1.1.jar,\
lib/poi-ooxml-schemas-4.1.1.jar,\
lib/poi-scratchpad-4.1.1.jar,\
lib/xmlbeans-3.1.0.jar,\
lib/ojdbc6.jar,\
lib/commons-lang3-3.9.jar,\
src/config/,\
lib/datepicker.jar,\
lib/aspose-cells-18.9.jar,\
lib/sqljdbc4.jar

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<category
id="JDProject.commands.category"
name="Sample Category">
</category>
<command categoryId="JDProject.commands.category" name="BOM批量管理" id="BOMManagement"></command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler commandId="BOMManagement" class="com.connor.jd.plm.handlers.BOMManagementHandler"></handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="Item"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+6">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
id="BOMManagement"
label="BOM管理"
mnemonic="M">
<command commandId="BOMManagement" id="JDProject.menus.BOMManagement" mnemonic="S"></command>
</menu>
</menuContribution>
</extension>
</plugin>

@ -0,0 +1,52 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
public class Test {
public static void main(String[] args) {
String[] arr = new String[] { "0,1", "1,10", "0,100", "xx", "1,2" };
Arrays.sort(arr, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if (o1.indexOf(",") == -1 || o2.indexOf(",") == -1) {
return 0;
}
String[] temp1 = o1.split(",");
String[] temp2 = o2.split(",");
if (temp1[0].equals(temp2[0])) {
return Integer.parseInt(temp1[1]) - Integer.parseInt(temp2[1]);
} else {
return Integer.parseInt(temp1[0]) - Integer.parseInt(temp2[0]);
}
}
});
System.out.println(Arrays.toString(arr));
List<String> list1 = new ArrayList<String>();
List<String> list2 = new ArrayList<String>();
List<String> list3 = new ArrayList<String>();
for (int i = 0; i < arr.length; i++) {
if (arr[i].indexOf(",") == -1 || "0".equals(arr[i].split(",")[0])) {
list1.add(arr[i]);
} else {
list2.add(arr[i]);
}
}
int maxLength = Math.max(list1.size(), list2.size());
for (int i = 0; i < maxLength; i++) {
if (i > list1.size() - 1) {
list3.add("");
list3.add(list2.get(i));
} else if (i > list2.size() - 1) {
list3.add(list1.get(i));
list3.add("");
} else {
list3.add(list1.get(i));
list3.add(list2.get(i));
}
}
System.out.println(Arrays.toString(list3.toArray()));
}
}

@ -0,0 +1,73 @@
package com.connor.jd.operations;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.connor.jd.plm.utils.DBConnectionUtil;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCSession;
public class CreateTableOperation {
private static Connection con = null;
private static Statement ps = null;
private static ResultSet rs = null;
private static TCSession session;
public static void create() {
session = (TCSession) AIFUtility.getCurrentApplication().getSession();
String createTable1 = "CREATE TABLE JD2_Component (test_type VARCHAR(255),test_project VARCHAR(255),test_time VARCHAR(255),test_num NUMBER,test_cost FLOAT, test_id NUMBER primary key)";
String createSeq1 = "CREATE sequence component_id_seq minvalue 1 nomaxvalue INCREMENT BY 1 START WITH 1 nocache";
String createTRG1 = "CREATE or REPLACE TRIGGER component_id_ins_trg before INSERT ON JD2_COMPONENT for each ROW BEGIN SELECT component_id_seq.Nextval into : new.TEST_ID from dual; END;";
String createTable2 = "CREATE TABLE JD2_Machine (test_type VARCHAR(255),test_project VARCHAR(255),test_cost FLOAT, test_id NUMBER primary key)";
String createSeq2 = "CREATE sequence machine_id_seq minvalue 1 nomaxvalue INCREMENT BY 1 START WITH 1 nocache";
String createTRG2 = "CREATE or REPLACE TRIGGER machine_id_ins_trg before INSERT ON JD2_MACHINE for each ROW BEGIN SELECT machine_id_seq.Nextval into : new.TEST_ID from dual; END;";
String[] sqls = { createTable1, createSeq1, createTRG1, createTable2, createSeq2, createTRG2 };
try {
con = DBConnectionUtil.dbConn(session);
String sqlString = "SELECT count(*) from user_tables WHERE table_name='JD2_COMPONENT'";
if (con == null) {
System.out.print("Á¬½Óʧ°Ü");
} else {
ps = con.createStatement();
rs = ps.executeQuery(sqlString);
while (rs.next()) {
System.out.println(rs.getInt(1));
if (rs.getInt(1) == 0) {
for (int i = 0; i < sqls.length; i++) {
ps = con.createStatement();
ps.execute(sqls[i]);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}

@ -0,0 +1,203 @@
package com.connor.jd.operations;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelImportServiceImpl {
public String importExcel(InputStream inputStream, String fileName) throws Exception {
String message = "Import success";
boolean isE2007 = false;
// 判断是否是excel2007格式
if (fileName.endsWith("xlsx")) {
isE2007 = true;
}
int rowIndex = 0;
try {
InputStream input = inputStream; // 建立输入流
Workbook wb;
// 根据文件格式(2003或者2007)来初始化
if (isE2007) {
wb = new XSSFWorkbook(input);
} else {
wb = new HSSFWorkbook(input);
}
Sheet sheet = wb.getSheetAt(0); // 获得第一个表单
int rowCount = sheet.getLastRowNum() + 1;
for (int i = 1; i < rowCount; i++) {
rowIndex = i;
Row row;
for (int j = 0; j < 26; j++) {
if (isMergedRegion(sheet, i, j)) {
System.out.print(getMergedRegionValue(sheet, i, j) + "\t");
} else {
row = sheet.getRow(i);
System.out.print(row.getCell(j) + "\t");
}
}
System.out.print("\n");
}
} catch (Exception ex) {
message = "Import failed, please check the data in " + rowIndex + " rows ";
}
return message;
}
/**
*
*
* @param cell
* @return
*/
public String getCellValue(Cell cell) {
if (cell == null)
return "";
return cell.getStringCellValue();
}
/**
* ,
*
* @param sheet
* @return List<CellRangeAddress>
*/
public List<CellRangeAddress> getCombineCell(Sheet sheet) {
List<CellRangeAddress> list = new ArrayList<>();
// 获得一个 sheet 中合并单元格的数量
int sheetmergerCount = sheet.getNumMergedRegions();
// 遍历所有的合并单元格
for (int i = 0; i < sheetmergerCount; i++) {
// 获得合并单元格保存进list中
CellRangeAddress ca = sheet.getMergedRegion(i);
list.add(ca);
}
return list;
}
private int getRowNum(List<CellRangeAddress> listCombineCell, Cell cell, Sheet sheet) {
int xr = 0;
int firstC = 0;
int lastC = 0;
int firstR = 0;
int lastR = 0;
for (CellRangeAddress ca : listCombineCell) {
// 获得合并单元格的起始行, 结束行, 起始列, 结束列
firstC = ca.getFirstColumn();
lastC = ca.getLastColumn();
firstR = ca.getFirstRow();
lastR = ca.getLastRow();
if (cell.getRowIndex() >= firstR && cell.getRowIndex() <= lastR) {
if (cell.getColumnIndex() >= firstC && cell.getColumnIndex() <= lastC) {
xr = lastR;
}
}
}
return xr;
}
/**
*
*
* @param listCombineCell list
* @param cell
* @param sheet sheet
* @return
*/
public String isCombineCell(List<CellRangeAddress> listCombineCell, Cell cell, Sheet sheet) throws Exception {
int firstC = 0;
int lastC = 0;
int firstR = 0;
int lastR = 0;
String cellValue = null;
for (CellRangeAddress ca : listCombineCell) {
// 获得合并单元格的起始行, 结束行, 起始列, 结束列
firstC = ca.getFirstColumn();
lastC = ca.getLastColumn();
firstR = ca.getFirstRow();
lastR = ca.getLastRow();
if (cell.getRowIndex() >= firstR && cell.getRowIndex() <= lastR) {
if (cell.getColumnIndex() >= firstC && cell.getColumnIndex() <= lastC) {
Row fRow = sheet.getRow(firstR);
Cell fCell = fRow.getCell(firstC);
cellValue = getCellValue(fCell);
break;
}
} else {
cellValue = "";
}
}
return cellValue;
}
/**
*
*
* @param sheet
* @param row
* @param column
* @return
*/
public String getMergedRegionValue(Sheet sheet, int row, int column) {
int sheetMergeCount = sheet.getNumMergedRegions();
for (int i = 0; i < sheetMergeCount; i++) {
CellRangeAddress ca = sheet.getMergedRegion(i);
int firstColumn = ca.getFirstColumn();
int lastColumn = ca.getLastColumn();
int firstRow = ca.getFirstRow();
int lastRow = ca.getLastRow();
if (row >= firstRow && row <= lastRow) {
if (column >= firstColumn && column <= lastColumn) {
Row fRow = sheet.getRow(firstRow);
Cell fCell = fRow.getCell(firstColumn);
return getCellValue(fCell);
}
}
}
return null;
}
/**
*
*
* @param sheet
* @param row
* @param column
* @return
*/
private boolean isMergedRegion(Sheet sheet, int row, int column) {
int sheetMergeCount = sheet.getNumMergedRegions();
for (int i = 0; i < sheetMergeCount; i++) {
CellRangeAddress range = sheet.getMergedRegion(i);
int firstColumn = range.getFirstColumn();
int lastColumn = range.getLastColumn();
int firstRow = range.getFirstRow();
int lastRow = range.getLastRow();
if (row >= firstRow && row <= lastRow) {
if (column >= firstColumn && column <= lastColumn) {
return true;
}
}
}
return false;
}
}

@ -0,0 +1,264 @@
package com.connor.jd.operations;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.teamcenter.rac.kernel.TCComponent;
public class ExcelOperation {
private static final String XLS = "xls";
private static final String XLSX = "xlsx";
public static void writeExcel(File file, String outpath, Map<String, List<TCComponent>> jfw) {
if (jfw.size() == 1) {
writeoneExcel(file, outpath, jfw);
} else {
writeallExcel(file, outpath, jfw);
}
}
public static void writeallExcel(File file, String outpath, Map<String, List<TCComponent>> jfw) {
Workbook workbook;
try {
workbook = getworkbook(file);
System.out.println("已有文件");
Workbook newwb = getWorkbook(outpath);
Sheet newsheet = newwb.createSheet();
Sheet sheet = workbook.getSheetAt(0);
CellStyle style = workbook.createCellStyle();
Row row = sheet.getRow(0);
row.setRowStyle(style);
Row newrow0 = newsheet.createRow(0);
for (int i = 0; i < row.getLastCellNum(); i++) {
Cell newCell = newrow0.createCell(i);
newCell.setCellValue(row.getCell(i).getStringCellValue());
}
List<CellRangeAddress> cellRangeList = getCombineCell(sheet);
for (Entry<String, List<TCComponent>> ever : jfw.entrySet()) {
List<TCComponent> itemList = ever.getValue();
String sfname = ever.getKey();
System.out.println("itemList长度" + itemList.size());
for (int i = 0; i < cellRangeList.size(); i++) {
CellRangeAddress ca = cellRangeList.get(i);
int firstColumn = 0;
int firstRow = ca.getFirstRow();
int lastRow = ca.getLastRow();
Row fRow = sheet.getRow(firstRow);
Cell fCell = fRow.getCell(firstColumn);
String cellVelue = fCell.getStringCellValue();
System.out.println("合并单元格的内容" + cellVelue);
System.out.println("起始行" + firstRow + "最后行" + lastRow);
if (sfname.equals(cellVelue)) {
for (int z = firstRow; z <= lastRow; z++) {
Row newRow = sheet.getRow(z);
String value = newRow.getCell(1).getStringCellValue();
System.out.println("表格内容" + value);
for (int p = 0; p < itemList.size(); p++) {
if (itemList.get(p).getTCProperty("object_type").getDisplayableValue().equals(value)) {
TCComponent[] revlist = itemList.get(p).getTCProperty("revision_list")
.getReferenceValueArray();
TCComponent component = null;
for (int revlength = 0; revlength < revlist.length; revlength++) {
String status = revlist[revlength].getProperty("release_status_list");
if (!status.equals("")) {
component = revlist[revlength];
}
}
String[] info = new String[4];
if (component != null) {
info[0] = component.getProperty("owning_group");
info[1] = component.getProperty("owning_user");
info[2] = component.getProperty("creation_date");
info[3] = component.getProperty("item_id");
} else {
info[0] = "";
info[1] = "";
info[2] = "";
info[3] = "";
}
for (int v = 0; v < info.length; v++) {
Cell cellvalue = newRow.createCell(v + 2);
cellvalue.setCellValue(info[v]);
System.out.println("内容是" + info[v]);
}
}
}
}
}
}
}
FileOutputStream fos = new FileOutputStream(outpath);
workbook.write(fos);
workbook.close();
fos.close();
} catch (Exception e) {
}
}
public static void writeoneExcel(File file, String outpath, Map<String, List<TCComponent>> jfw) {
Workbook workbook;
try {
workbook = getworkbook(file);
System.out.println("已有文件");
Workbook newwb = getWorkbook(outpath);
Sheet newsheet = newwb.createSheet();
Sheet sheet = workbook.getSheetAt(0);
CellStyle style = newwb.createCellStyle();
Row row = sheet.getRow(0);
Row newrow0 = newsheet.createRow(0);
for (int i = 0; i < row.getLastCellNum(); i++) {
Cell oldCell = row.getCell(i);
style.cloneStyleFrom(oldCell.getCellStyle());
Cell newCell = newrow0.createCell(i);
newCell.setCellStyle(style);
newCell.setCellValue(oldCell.getStringCellValue());
}
List<CellRangeAddress> cellRangeList = getCombineCell(sheet);
for (Entry<String, List<TCComponent>> ever : jfw.entrySet()) {
List<TCComponent> itemList = ever.getValue();
String sfname = ever.getKey();
System.out.println("itemList长度" + itemList.size());
for (int i = 0; i < cellRangeList.size(); i++) {
CellRangeAddress ca = cellRangeList.get(i);
int firstColumn = 0;
int firstRow = ca.getFirstRow();
int lastRow = ca.getLastRow();
Row fRow = sheet.getRow(firstRow);
Cell fCell = fRow.getCell(firstColumn);
String cellVelue = fCell.getStringCellValue();
System.out.println("合并单元格的内容" + cellVelue);
System.out.println("起始行" + firstRow + "最后行" + lastRow);
if (sfname.equals(cellVelue)) {
List<String> valueList = new ArrayList<String>();
for (int z = firstRow; z <= lastRow; z++) {
Row oldRow = sheet.getRow(z);
String value = oldRow.getCell(1).getStringCellValue();
valueList.add(value);
}
for (int j = 1; j <= lastRow - firstRow + 1; j++) {
Row newRow = newsheet.createRow(j);
Cell cell = newRow.createCell(0);
cell.setCellValue(cellVelue);
Cell cell2 = newRow.createCell(1);
cell2.setCellValue(valueList.get(j - 1));
System.out.println("特殊表格内容" + valueList.get(j - 1));
for (int p = 0; p < itemList.size(); p++) {
if (itemList.get(p).getTCProperty("object_type").getDisplayableValue()
.equals(valueList.get(j - 1))) {
System.out.println(
"类型:" + itemList.get(p).getTCProperty("object_type").getDisplayableValue());
TCComponent[] revlist = itemList.get(p).getTCProperty("revision_list")
.getReferenceValueArray();
TCComponent component = null;
for (int revlength = 0; revlength < revlist.length; revlength++) {
String status = revlist[revlength].getProperty("release_status_list");
if (!status.equals("")) {
component = revlist[revlength];
}
}
String[] info = new String[4];
if (component != null) {
info[0] = component.getProperty("owning_group");
info[1] = component.getProperty("owning_user");
info[2] = component.getProperty("creation_date");
info[3] = component.getProperty("item_id");
} else {
info[0] = "";
info[1] = "";
info[2] = "";
info[3] = "";
}
for (int v = 0; v < info.length; v++) {
System.out.println("开始创建内容");
Cell cellvalue = newRow.createCell(v + 2);
cellvalue.setCellValue(info[v]);
System.out.println("内容是" + info[v]);
}
}
}
}
CellRangeAddress region = new CellRangeAddress(1, lastRow - firstRow + 1, 0, 0);
newsheet.addMergedRegion(region);
}
}
}
FileOutputStream fos = new FileOutputStream(outpath);
newwb.write(fos);
newwb.close();
fos.close();
} catch (Exception e) {
}
}
/**
* ,
*
* @param sheet
* @return List<CellRangeAddress>
*/
public static List<CellRangeAddress> getCombineCell(Sheet sheet) {
List<CellRangeAddress> list = new ArrayList<>();
// 获得一个 sheet 中合并单元格的数量
int sheetmergerCount = sheet.getNumMergedRegions();
// 遍历所有的合并单元格
for (int i = 0; i < sheetmergerCount; i++) {
// 获得合并单元格保存进list中
CellRangeAddress ca = sheet.getMergedRegion(i);
list.add(ca);
}
return list;
}
public static Workbook getWorkbook(String file) throws IOException {
Workbook workbook = null;
// FileInputStream in = new FileInputStream(file);
if (file.endsWith(XLS)) {
System.out.println("xls");
workbook = new HSSFWorkbook();
} else if (file.endsWith(XLSX)) {
System.out.println("xlsx");
workbook = new XSSFWorkbook();
} else {
System.out.println("格式错误");
}
return workbook;
}
public static Workbook getworkbook(File file) throws IOException {
Workbook workbook = null;
FileInputStream in = new FileInputStream(file);
if (file.getName().endsWith(XLS)) {
System.out.println("xls");
workbook = new HSSFWorkbook(in);
} else if (file.getName().endsWith(XLSX)) {
System.out.println("xlsx");
workbook = new XSSFWorkbook(in);
} else {
System.out.println("格式错误");
}
in.close();
return workbook;
}
}

@ -0,0 +1,96 @@
package com.connor.jd.plm.action;
import java.util.Arrays;
import java.util.Comparator;
import javax.swing.JOptionPane;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
import com.teamcenter.rac.kernel.TCComponent;
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;
public class AddHLBOMAction extends AbstractAIFAction {
private AbstractAIFApplication app;
private TCSession session;
public AddHLBOMAction(AbstractAIFApplication arg0, String arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
this.app = arg0;
this.session = (TCSession) app.getSession();
}
@Override
public void run() {
// TODO Auto-generated method stub
TCComponent target = (TCComponent) app.getTargetComponent();
TCComponentItemRevision rev = null;
if (target instanceof TCComponentItemRevision) {
rev = (TCComponentItemRevision) target;
} else if (target instanceof TCComponentItem) {
try {
rev = ((TCComponentItem) target).getLatestItemRevision();
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
TCComponent[] revs = rev.getRelatedComponents("JD2_HLBOM");
String itemId = rev.getProperty("item_id");
String itemName = rev.getProperty("object_name");
TCComponentItem newItem = null;
session.getUserService().call("bs_bypass", new Object[] { true });
if (revs.length == 0) {
newItem = rev.saveAsItem(itemId + "-1", null);
} else {
Arrays.sort(revs, new Comparator<TCComponent>() {
@Override
public int compare(TCComponent o1, TCComponent o2) {
// TODO Auto-generated method stub
try {
return o1.getProperty("item_id").compareTo(o2.getProperty("item_id"));
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
});
String str = revs[revs.length - 1].getProperty("item_id");
str = str.split("-")[1];
newItem = rev.saveAsItem(itemId + "-" + (Integer.parseInt(str) + 1), null);
}
rev.add("JD2_HLBOM", newItem);
TCComponentItemRevision newRev = newItem.getLatestItemRevision();
TCComponent[] comps = newRev.getRelatedComponents("JD2_HLBOM");
System.out.println(Arrays.toString(comps));
newRev.cutOperation("JD2_HLBOM", comps);
newRev.lock();
newRev.setProperty("jd2_ishl", "1");
newRev.save();
newRev.unlock();
rev.refresh();
MessageBox.post("´´½¨³É¹¦", "Ìáʾ", MessageBox.WARNING);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.getMessage(), "´íÎó", JOptionPane.ERROR_MESSAGE);
} finally {
try {
session.getUserService().call("bs_bypass", new Object[] { false });
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

@ -0,0 +1,23 @@
package com.connor.jd.plm.action;
import com.connor.jd.plm.dialogs.BOMManagementFrame;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
public class BOMManagementAction extends AbstractAIFAction {
private AbstractAIFApplication app;
public BOMManagementAction(AbstractAIFApplication arg0, String arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
this.app = arg0;
}
@Override
public void run() {
// TODO Auto-generated method stub
new BOMManagementFrame(app);
}
}

@ -0,0 +1,94 @@
package com.connor.jd.plm.action;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import com.connor.jd.plm.utils.DialogUtil;
import com.connor.jd.plm.utils.DialogUtil.TableMsg;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCSession;
public class BatchReviseAction extends AbstractAIFAction {
private TCSession session;
private TCComponentFolder folder;
public BatchReviseAction(AbstractAIFApplication arg0, String arg1) {
super(arg0, arg1);
this.session = (TCSession) arg0.getSession();
TCComponent target = (TCComponent) arg0.getTargetComponent();
System.out.println("类型===>" + target.getType());
if (target instanceof TCComponentFolder) {
this.folder = (TCComponentFolder) target;
}
}
@Override
public void run() {
if (folder == null) {
return;
}
try {
TCComponent[] comps = folder.getRelatedComponents("contents");
List<String[]> unpublished = new ArrayList<String[]>();
check(comps, unpublished);
if (unpublished.size() > 0) {
TableMsg msg = DialogUtil.createTableMsg(new String[] { "序号", "名称", "原因" }, unpublished);
JPanel content = new JPanel(new BorderLayout());
content.setSize(new Dimension(msg.panel.getWidth(), msg.panel.getHeight() + 50));
JLabel text = new JLabel("操作已取消,下列目标未满足要求:");
content.add(text, BorderLayout.NORTH);
content.add(msg.panel, BorderLayout.CENTER);
JOptionPane.showMessageDialog(null, content, "信息", JOptionPane.PLAIN_MESSAGE);
return;
}
List<TCComponentItemRevision> newRevs = new ArrayList<>();
for (TCComponent comp : comps) {
if (!(comp instanceof TCComponentItemRevision)) {
continue;
}
TCComponentItemRevision rev = (TCComponentItemRevision) comp;
newRevs.add(rev.saveAs(rev.getItem().getNewRev()));
}
if (comps.length > 0) {
folder.cutOperation("contents", comps);
folder.add("contents", newRevs);
folder.refresh();
JOptionPane.showMessageDialog(null, "升版成功", "信息", JOptionPane.WARNING_MESSAGE);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void check(TCComponent[] comps, List<String[]> unpublished) throws Exception {
for (TCComponent comp : comps) {
if (!(comp instanceof TCComponentItemRevision)) {
unpublished.add(
new String[] { unpublished.size() + 1 + "", comp.getProperty("object_string"), "目标类型错误,请放版本" });
continue;
}
boolean isAccess = session.getTCAccessControlService()
.checkPrivilege(((TCComponentItemRevision) comp).getItem(), "WRITE");
if (!isAccess) {
unpublished.add(new String[] { unpublished.size() + 1 + "", comp.getProperty("object_string"), "无权限" });
continue;
}
TCComponent[] status = comp.getRelatedComponents("release_status_list");
if (status.length == 0) {
unpublished.add(new String[] { unpublished.size() + 1 + "", comp.getProperty("object_string"), "未发布" });
}
}
}
}

@ -0,0 +1,126 @@
package com.connor.jd.plm.action;
import java.util.Arrays;
import java.util.List;
import com.connor.jd.plm.utils.JDMethodUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class DeleteItemRevisionAction extends AbstractAIFAction {
private AbstractAIFApplication app;
public DeleteItemRevisionAction(AbstractAIFApplication arg0, String arg1) {
super(arg0, arg1);
this.app = arg0;
// TODO Auto-generated constructor stub
}
@Override
public void run() {
// TODO Auto-generated method stub
TCSession session = (TCSession) app.getSession();
InterfaceAIFComponent[] targets = app.getTargetComponents();
String[] allow = JDMethodUtil.getPrefStrArray("connor_wl_type", session);
String[] allow2 = JDMethodUtil.getPrefStrArray("connor_tz_type", session);
String[] allow3 = JDMethodUtil.getPrefStrArray("jd2_wltz_Revise_allow", session);
System.out.println("connor_wl_type===>" + Arrays.toString(allow));
System.out.println("connor_tz_type===>" + Arrays.toString(allow2));
System.out.println("jd2_wltz_Revise_allow===>" + Arrays.toString(allow3));
List<String> pref = Arrays.asList(allow);
List<String> pref2 = Arrays.asList(allow2);
List<String> pref3 = Arrays.asList(allow3);
for (InterfaceAIFComponent target : targets) {
System.out.println(target.getType());
if (target instanceof TCComponentItemRevision) {
if (!pref.contains(target.getType()) && !pref2.contains(target.getType())
&& !pref3.contains(target.getType())) {
try {
MessageBox.post(target.getProperty("object_string") + "既不是物料也不是图纸,不执行删除", "提示",
MessageBox.WARNING);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
TCComponentItemRevision rev = (TCComponentItemRevision) target;
try {
String loginUser = session.getUser().getProperty("object_string");
// String owningUser = rev.getProperty("owning_user");
// System.out.println("loginUser===>" + loginUser);
// System.out.println("owningUser===>" + owningUser);
boolean[] isAccess = session.getTCAccessControlService().checkPrivileges(rev.getItem(),
new String[] { "WRITE", "DELETE" });
if (isAccess[0] && isAccess[1]) {
TCComponentItem item = rev.getItem();
TCComponent[] released = item.getReleasedItemRevisions();
for (TCComponent comp : released) {
if (comp.getUid().equals(rev.getUid())) {
MessageBox.post(target.getProperty("object_string") + "无法删除,物料已经发布", "提示",
MessageBox.WARNING);
return;
}
}
session.getUserService().call("bs_bypass", new Object[] { true });
System.out.println("rev uid===>" + rev.getUid());
AIFComponentContext[] aifs = rev.whereReferenced();
for (AIFComponentContext aif : aifs) {
if (aif.getComponent() instanceof TCComponent) {
TCComponent temp = (TCComponent) aif.getComponent();
if (temp.getUid().equals(rev.getItem().getUid())) {
System.out.println("跳过对象");
continue;
}
System.out.println("引用者===>" + temp.getProperty("onject_string"));
TCProperty[] tcProps = temp.getAllTCProperties();
for (TCProperty tcProp : tcProps) {
if (tcProp.isReferenceType()) {
if (tcProp.isNotArray()) {
if (tcProp.getReferenceValue() != null
&& tcProp.getReferenceValue().getUid().equals(rev.getUid())) {
System.out.println("关系===>" + tcProp.getPropertyName());
temp.cutOperation(tcProp.getPropertyName(), new TCComponent[] { rev });
}
} else {
TCComponent[] comps = tcProp.getReferenceValueArray();
for (TCComponent comp : comps) {
if (comp.getUid().equals(rev.getUid())) {
System.out.println("关系===>" + tcProp.getPropertyName());
temp.cutOperation(tcProp.getPropertyName(),
new TCComponent[] { rev });
}
}
}
}
}
}
}
// if (pref.contains(target.getType())) {
// rev.cutOperation("TC_Is_Represented_By", rev.getRelatedComponents("TC_Is_Represented_By"));
// } else {
// rev.cutOperation("representation_for", rev.getRelatedComponents("representation_for"));
// }
rev.delete();
session.getUserService().call("bs_bypass", new Object[] { false });
MessageBox.post("删除成功", "提示", MessageBox.WARNING);
} else {
MessageBox.post(target.getProperty("object_string") + "无修改和删除权限", "提示", MessageBox.WARNING);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}

@ -0,0 +1,29 @@
package com.connor.jd.plm.action;
import com.connor.jd.plm.dialog.EditClassificationDialog;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
import com.teamcenter.rac.kernel.TCException;
public class EditClassificationAction extends AbstractAIFAction {
private final AbstractAIFApplication app;
public EditClassificationAction(AbstractAIFApplication arg0, String arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
this.app = arg0;
}
@Override
public void run() {
// TODO Auto-generated method stub
try {
new EditClassificationDialog(app);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@ -0,0 +1,28 @@
package com.connor.jd.plm.action;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCSession;
public class ExportBOMAction extends AbstractAIFAction {
private AbstractAIFApplication app;
private TCSession session;
public ExportBOMAction(AbstractAIFApplication arg0, String arg1) {
super(arg0, arg1);
this.app = arg0;
this.session = (TCSession) app.getSession();
}
@Override
public void run() {
TCComponent target = (TCComponent) app.getTargetComponent();
TCComponentItemRevision rev;
if (target instanceof TCComponentItemRevision) {
}
}
}

@ -0,0 +1,278 @@
package com.connor.jd.plm.action;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.connor.jd.plm.utils.JDMethodUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.common.Activator;
import com.teamcenter.rac.kernel.TCAccessControlService;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentICO;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.ics.ICSProperty;
import com.teamcenter.rac.util.MessageBox;
public class WLTZReviseAction extends AbstractAIFAction {
private AbstractAIFApplication app;
private TCSession session;
public WLTZReviseAction(AbstractAIFApplication arg0, String arg1) {
super(arg0, arg1);
this.app = arg0;
this.session = (TCSession) app.getSession();
}
@Override
public void run() {
// TODO Auto-generated method stub
String server = JDMethodUtil.getPrefStr("jd2_server_ip", session);
if (server == null || "".equals(server)) {
MessageBox.post("未配置jd2_server_ip首选项", "错误", MessageBox.ERROR);
return;
}
TCComponent target = (TCComponent) AIFUtility.getCurrentApplication().getTargetComponent();
String[] allow = getPrefStrArray("jd2_wltz_Revise_allow");
List<String> list = Arrays.asList(allow);
for (String s : list) {
System.out.println(s);
}
TCAccessControlService aclService = session.getTCAccessControlService();
TCComponentItemRevision rev;
if (target instanceof TCComponentItemRevision) {
rev = (TCComponentItemRevision) target;
} else if (target instanceof TCComponentBOMLine) {
try {
rev = ((TCComponentBOMLine) target).getItemRevision();
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
MessageBox.post(e.getMessage(), "错误", MessageBox.ERROR);
return;
}
} else {
MessageBox.post("当前对象类型不允许修订并发送分类!", "错误", MessageBox.ERROR);
return;
}
try {
String type = rev.getType();
System.out.println("uid===>" + rev.getItem().getUid());
System.out.println("user===>" + session.getUser().getUid());
System.out.println(type);
if (!list.contains(type)) {
MessageBox.post("当前对象类型不允许修订并发送分类!", "错误", MessageBox.ERROR);
return;
}
rev.refresh();
// String url = "http://" + server + ":8880/api/grantPrivilege";
// TCComponentItem item = rev.getItem();
// TCComponent[] comps = rev.getRelatedComponents("fnd0ActuatedInteractiveTsks");
// TCComponent[] bomViews = item.getRelatedComponents("bom_view_tags");
// String uids = "";
// for (TCComponent bomView : bomViews) {
// uids += "," + bomView.getUid();
// }
// AIFComponentContext[] referenced = rev.whereReferenced();
// for (AIFComponentContext aif : referenced) {
// if (aif.getComponent() instanceof TCComponentItem
// || aif.getComponent() instanceof TCComponentItemRevision) {
// uids += aif.getComponent().getUid() + ",";
// }
// }
// uids = uids.substring(0, uids.length() - 1);
// Map<String, Object> privilegeMap = new HashMap<String, Object>();
// privilegeMap.put("uid", uids);
// privilegeMap.put("user", session.getUser().getUid());
// privilegeMap.put("privilege", "WRITE,DELETE");
// privilegeMap.put("pass", true);
// List<String> allow2 = Arrays.asList(JDMethodUtil.getPrefStrArray("jd_wltz_revise_workflow", session));
// System.out.println("allow workflow:" + Arrays.toString(allow2.toArray()));
// TCComponentItemRevision newRev = null;
// boolean getPrivilege = false;
// for (TCComponent comp : comps) {
// if (comp.getProperty("object_name").contains("编制") && allow2.contains(comp.getProperty("parent_name"))
// && comp.getProperty("task_state").equals("已开始")) {
// System.out.println("开始授权");
// privilegeMap.put("pass", true);
// String res = HttpUtil.post(url, privilegeMap);
// System.out.println("res===>" + res);
// if (!res.contains("success")) {
// MessageBox.post("授权异常,失败", "错误", MessageBox.ERROR);
// return;
// }
// item.refresh();
// for (TCComponent bomView : bomViews) {
// bomView.refresh();
// }
// getPrivilege = true;
// System.out.println("已授权读写删除");
// session.getUserService().call("bs_bypass", new Object[] { true });
// newRev = rev.saveAs(item.getNewRev());
// session.getUserService().call("bs_bypass", new Object[] { false });
// break;
// }
// }
// boolean isAccess = session.getTCAccessControlService().checkPrivilege(rev.getItem(), "WRITE");
// if (!isAccess) {
// MessageBox.post("无权限", "提示", MessageBox.WARNING);
// return;
// }
String loginUser = session.getUser().getProperty("object_string");
String owningUser = rev.getProperty("owning_user");
System.out.println("loginUser===>" + loginUser);
System.out.println("owningUser===>" + owningUser);
TCComponentItemRevision newRev = null;
if (!loginUser.equals(owningUser)) {
System.out.println("非所有者请走升版审批流程!");
MessageBox.post("非所有者请走升版审批流程!", "提示", MessageBox.WARNING);
return;
} else {
session.getUserService().call("bs_bypass", new Object[] { true });
newRev = rev.saveAs(rev.getItem().getNewRev());
if (target instanceof TCComponentBOMLine) {
TCComponentBOMLine bomLine = (TCComponentBOMLine) target;
if (bomLine.parent() != null) {
bomLine.window().refresh();
} else {
System.out.println("topLine");
Activator.getDefault().openPerspective("com.teamcenter.rac.pse.PSEPerspective");
Activator.getDefault().openComponents("com.teamcenter.rac.pse.PSEPerspective",
new InterfaceAIFComponent[] { newRev });
}
}
session.getUserService().call("bs_bypass", new Object[] { false });
}
if (rev.getClassificationClass() == null || "".equals(rev.getClassificationClass())) {
MessageBox.post("升版成功", "提示", MessageBox.WARNING);
// if (getPrivilege) {
// privilegeMap.put("pass", false);
// String res = HttpUtil.post(url, privilegeMap);
// System.out.println("res===>" + res);
// if (res.contains("error")) {
// MessageBox.post("撤销权限异常,失败", "错误", MessageBox.ERROR);
// return;
// }
// item.refresh();
// for (TCComponent bomView : bomViews) {
// bomView.refresh();
// }
// System.out.println("已撤销读写删除权限");
// }
System.out.println("success");
return;
}
if (newRev == null) {
MessageBox.post("未知异常", "错误", MessageBox.ERROR);
return;
}
TCComponentICO ico = rev.getClassificationObjects()[0];
ICSProperty[] oldICSProps = ico.getICSProperties(true);
int[] ids = new int[oldICSProps.length];
String[] values = new String[oldICSProps.length];
for (int i = 0; i < oldICSProps.length; i++) {
System.out.println(oldICSProps[i].getId() + "=====>" + oldICSProps[i].getValue());
ids[i] = oldICSProps[i].getId();
values[i] = oldICSProps[i].getValue();
}
JSONObject json = new JSONObject();
json.put("ids", ids);
json.put("values", values);
String prop = json.toString();
// prop = prop.replace("\"", "\\\"");
System.out.println("prop:" + prop);
String uid = newRev.getUid();
System.out.println("uid:" + uid);
String cid = rev.getClassificationClass();
System.out.println("cid:" + cid);
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("uid", uid);
paramMap.put("cid", cid);
paramMap.put("prop", prop);
final String URL = "http://" + server + ":8880/api/sendClassification";
// final String URL2 = url;
final Map<String, Object> PARAMMAP = paramMap;
// final Map<String, Object> PRIVILEGEMAP = privilegeMap;
// final TCComponent[] BOMVIEWS = bomViews;
// final boolean GetPrivilege = getPrivilege;
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
cn.hutool.http.HttpUtil.post(URL, PARAMMAP);
MessageBox.post("升版成功", "提示", MessageBox.WARNING);
// if (GetPrivilege) {
// PRIVILEGEMAP.put("pass", false);
// String res = HttpUtil.post(URL2, PRIVILEGEMAP);
// System.out.println("res===>" + res);
// if (!res.contains("success")) {
// MessageBox.post("撤销权限异常,失败", "错误", MessageBox.ERROR);
// } else {
// try {
// item.refresh();
// for (TCComponent bomView : BOMVIEWS) {
// bomView.refresh();
// }
// } catch (TCException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// System.out.println("已撤销写删除权限");
// }
// }
System.out.println("success");
}
}).start();
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
MessageBox.post(e.getMessage(), "错误", MessageBox.ERROR);
}
}
/**
*
*
* @param prefName
* @return
*/
public String getPrefStr(String prefName) {
TCPreferenceService service = session.getPreferenceService();
String str = service.getString(TCPreferenceService.TC_preference_site, prefName);
if (str == null) {
str = new String("");
}
return str;
}
/**
*
*
* @param prefName
* @return
*/
public String[] getPrefStrArray(String prefName) {
TCPreferenceService service = session.getPreferenceService();
String[] strs = service.getStringArray(TCPreferenceService.TC_preference_site, prefName);
service.getStringValues(prefName);
service.getStringValue(prefName);
if (strs == null) {
strs = new String[] { "" };
}
return strs;
}
}

@ -0,0 +1 @@
package com.connor.jd.plm.action;

@ -0,0 +1,96 @@
package com.connor.jd.plm.beans;
import cn.hutool.core.util.StrUtil;
public class BOMExportBean {
private String pid;// 父id
private String prev;// 父版本
private String cid;// 子id
private String crev;// 子版本
private String childCount;// 子数量
private String childUnit;// 子单位
private String HLCount;// 回料数量
private String SN;// 编号
public BOMExportBean(String pid, String prev, String cid, String crev, String childCount, String childUnit,
String HLCount, String SN) {
super();
this.pid = pid;
this.prev = prev;
this.cid = cid;
this.crev = crev;
this.childCount = childCount;
this.childUnit = childUnit;
this.HLCount = HLCount;
this.SN = SN;
}
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public String getPrev() {
return prev;
}
public void setPrev(String prev) {
this.prev = prev;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getCrev() {
return crev;
}
public void setCrev(String crev) {
this.crev = crev;
}
public String getChildCount() {
return childCount;
}
public void setChildCount(String childCount) {
this.childCount = childCount;
}
public String getChildUnit() {
return childUnit;
}
public void setChildUnit(String childUnit) {
this.childUnit = childUnit;
}
public String getHLCount() {
return HLCount;
}
public void setHLCount(String HLCount) {
this.HLCount = HLCount;
}
public String getSN() {
return SN;
}
public void setSN(String SN) {
this.SN = SN;
}
public int isNegative() {
return StrUtil.isBlank(HLCount) ? 0 : Integer.parseInt(HLCount) < 0 ? 1 : 0;
}
}

@ -0,0 +1,80 @@
package com.connor.jd.plm.beans;
public class BOMLogBean {
private String target1;
private String target2;
private String parent;
private String operation;
private String unit;
private String oldNum;
private String num;
public BOMLogBean(String target1, String target2, String parent, String operation, String unit, String oldNum,
String num) {
super();
this.target1 = target1;
this.target2 = target2;
this.parent = parent;
this.operation = operation;
this.unit = unit;
this.oldNum = oldNum;
this.num = num;
}
public String getTarget1() {
return target1;
}
public void setTarget1(String target1) {
this.target1 = target1;
}
public String getTarget2() {
return target2;
}
public void setTarget2(String target2) {
this.target2 = target2;
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getOldNum() {
return oldNum;
}
public void setOldNum(String oldNum) {
this.oldNum = oldNum;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
}

@ -0,0 +1,74 @@
package com.connor.jd.plm.beans;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
public class BOMManageTableBean {
private String parentString;
private String childString;
private TCComponentItemRevision parentRev;
private TCComponentItemRevision childRev;
private TCComponentBOMLine parentLine;
private TCComponentBOMLine childLine;
public BOMManageTableBean(String parentString, String childString, TCComponentItemRevision parentRev,
TCComponentItemRevision childRev, TCComponentBOMLine parentLine, TCComponentBOMLine childLine) {
super();
this.parentString = parentString;
this.childString = childString;
this.parentRev = parentRev;
this.childRev = childRev;
this.parentLine = parentLine;
this.childLine = childLine;
}
public String getParentString() {
return parentString;
}
public void setParentString(String parentString) {
this.parentString = parentString;
}
public String getChildString() {
return childString;
}
public void setChildString(String childString) {
this.childString = childString;
}
public TCComponentItemRevision getParentRev() {
return parentRev;
}
public void setParentRev(TCComponentItemRevision parentRev) {
this.parentRev = parentRev;
}
public TCComponentItemRevision getChildRev() {
return childRev;
}
public void setChildRev(TCComponentItemRevision childRev) {
this.childRev = childRev;
}
public TCComponentBOMLine getParentLine() {
return parentLine;
}
public void setParentLine(TCComponentBOMLine parentLine) {
this.parentLine = parentLine;
}
public TCComponentBOMLine getChildLine() {
return childLine;
}
public void setChildLine(TCComponentBOMLine childLine) {
this.childLine = childLine;
}
}

@ -0,0 +1,14 @@
package com.connor.jd.plm.beans;
public class CheckBoxPo {
public Object value = null;
public String text = null;
public CheckBoxPo() {
}
public CheckBoxPo(String text, Object value) {
this.value = value;
this.text = text;
}
}

@ -0,0 +1,39 @@
package com.connor.jd.plm.beans;
public class ClassPropBean {
private int id;
private String name;
private String value;
public ClassPropBean(int id, String name, String value) {
super();
this.id = id;
this.name = name;
this.value = value;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

@ -0,0 +1,101 @@
package com.connor.jd.plm.beans;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
public class ComponentBean {
private int compId;
private SimpleStringProperty type;
private SimpleStringProperty project;
private SimpleStringProperty time;
private SimpleStringProperty number;
private SimpleStringProperty cost;
private int addId;// 只用于添加所用
private int stage;// 状态 0为从数据库中取出的1为新增的2为从数据库取出但被修改了的
public int getAddId() {
return addId;
}
public void setAddId(int addId) {
this.addId = addId;
}
public int getStage() {
return stage;
}
public void setStage(int stage) {
this.stage = stage;
}
public ObservableValue<String> typeProperty() {
return type;
}
public ObservableValue<String> projectProperty() {
return project;
}
public ObservableValue<String> timeProperty() {
return time;
}
public ObservableValue<String> numberProperty() {
return number;
}
public ObservableValue<String> costProperty() {
return cost;
}
public int getCompId() {
return compId;
}
public void setCompId(int compId) {
this.compId = compId;
}
public String getType() {
return type.get();
}
public void setType(String type) {
this.type = new SimpleStringProperty(type);
}
public String getProject() {
return project.get();
}
public void setProject(String project) {
this.project = new SimpleStringProperty(project);
}
public String getTime() {
return time.get();
}
public void setTime(String time) {
this.time = new SimpleStringProperty(time);
}
public String getNumber() {
return number.get();
}
public void setNumber(String number) {
this.number = new SimpleStringProperty(number);
}
public String getCost() {
return cost.get();
}
public void setCost(String cost) {
this.cost = new SimpleStringProperty(cost);
}
}

@ -0,0 +1,38 @@
package com.connor.jd.plm.beans;
import java.util.ArrayList;
import java.util.List;
public class CustomLovBean {
private List<CustomLovBean> sub = new ArrayList<CustomLovBean>();
public String displayName = "";
public CustomLovBean(String displayName) {
super();
this.displayName = displayName;
}
public CustomLovBean(String displayName, String[] subArray) {
super();
this.displayName = displayName;
translateArrayToSub(subArray);
}
public void translateArrayToSub(String[] subArray) {
for (int i = 0; i < subArray.length; i++) {
sub.add(new CustomLovBean(subArray[i]));
}
}
public List<CustomLovBean> getSub() {
return sub;
}
public boolean hasChild() {
return sub.size() != 0;
}
public void addSub(CustomLovBean clb) {
sub.add(clb);
}
}

@ -0,0 +1,38 @@
package com.connor.jd.plm.beans;
public class JG {
int row;
int times;
String jg;
public JG(int row, int times, String jg) {
super();
this.row = row;
this.times = times;
this.jg = jg;
}
public int getTimes() {
return times;
}
public void setTimes(int times) {
this.times = times;
}
public String getJg() {
return jg;
}
public void setJg(String jg) {
this.jg = jg;
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
}

@ -0,0 +1,75 @@
package com.connor.jd.plm.beans;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
public class MachineBean {
private int macId;
private SimpleStringProperty type;
private SimpleStringProperty project;
private SimpleStringProperty cost;
private int addId;// 只用于添加所用
private int stage;// 状态 0为从数据库中取出的1为新增的2为从数据库取出但被修改了的
public int getMacId() {
return macId;
}
public void setMacId(int macId) {
this.macId = macId;
}
public int getAddId() {
return addId;
}
public void setAddId(int addId) {
this.addId = addId;
}
public int getStage() {
return stage;
}
public void setStage(int stage) {
this.stage = stage;
}
public ObservableValue<String> typeProperty() {
return type;
}
public ObservableValue<String> projectProperty() {
return project;
}
public ObservableValue<String> costProperty() {
return cost;
}
public String getType() {
return type.get();
}
public void setType(String type) {
this.type = new SimpleStringProperty(type);
}
public String getProject() {
return project.get();
}
public void setProject(String project) {
this.project = new SimpleStringProperty(project);
}
public String getCost() {
return cost.get();
}
public void setCost(String cost) {
this.cost = new SimpleStringProperty(cost);
;
}
}

@ -0,0 +1,39 @@
package com.connor.jd.plm.beans;
public class ResultData {
private boolean res;
private String Message;
private Object data;
public ResultData(boolean res, String message, Object data) {
super();
this.res = res;
Message = message;
this.data = data;
}
public boolean isRes() {
return res;
}
public void setRes(boolean res) {
this.res = res;
}
public String getMessage() {
return Message;
}
public void setMessage(String message) {
Message = message;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}

@ -0,0 +1,36 @@
package com.connor.jd.plm.beans;
import java.util.HashMap;
import java.util.Map;
import javax.swing.Icon;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
public class TransformBomBean {
public String displayName;
public TCComponentBOMLine line;
public TCComponentItemRevision selectRev;
public Map<String, TCComponentItemRevision> map=new HashMap<>();
public TransformBomBean(TCComponentBOMLine line) {
// TODO Auto-generated constructor stub
try {
this.line = line;
this.displayName=line.getProperty("object_string");
} catch (TCException e) {
// TODO Auto-generated catch blocks
e.printStackTrace();
}
}
@Override
public String toString() {
// TODO Auto-generated method stub
return displayName;
}
}

@ -0,0 +1,39 @@
package com.connor.jd.plm.dialog;
public class DocumentTemplate {
private String type;// 模板类型
private String[] relation;// 数据集关系
private String uid;// 模板uid
public DocumentTemplate(String type, String uid, String[] relation) {
super();
this.type = type;
this.relation = relation;
this.uid = uid;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String[] getRelation() {
return relation;
}
public void setRelation(String[] relation) {
this.relation = relation;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
}

@ -0,0 +1,399 @@
package com.connor.jd.plm.dialog;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import com.connor.jd.plm.beans.ClassPropBean;
import com.connor.jd.plm.utils.ExcelInfoScanner;
import com.connor.jd.plm.utils.JDMethodUtil;
import com.connor.jd.plm.utils.StringCreateUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCClassificationService;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentICO;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.ics.ICSAdminClass;
import com.teamcenter.rac.kernel.ics.ICSProperty;
import com.teamcenter.rac.kernel.ics.ICSPropertyDescription;
import com.teamcenter.rac.util.MessageBox;
import cn.hutool.json.JSONObject;
/**
*
*/
public class EditClassificationDialog extends AbstractAIFDialog {
private static final long serialVersionUID = 1L;
private AbstractAIFApplication app;
private TCSession session;
private TCComponent target;
private Map<String, JComponent> propMap;
private TCClassificationService myService;
final EditClassificationDialog DIALOG = this;
private TCComponentItemRevision rev;
private int[] ids;
private String[] values;
private String[] names;
private boolean finished;
public EditClassificationDialog(AbstractAIFApplication app) throws TCException {
this.app = app;
this.session = (TCSession) app.getSession();
this.myService = session.getClassificationService();
this.target = (TCComponent) AIFUtility.getCurrentApplication().getTargetComponent();
System.out.println(target.getType());
System.out.println(target instanceof TCComponentItemRevision ? "是" : "否");
if (target instanceof TCComponentItemRevision) {
try {
rev = (TCComponentItemRevision) target;
boolean isAccess = session.getTCAccessControlService().checkPrivilege(rev, "WRITE");
if (!isAccess) {
JOptionPane.showMessageDialog(this, "没有版本修改权限,请联系系统管理员", "提示", JOptionPane.WARNING_MESSAGE);
return;
}
initUI();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
MessageBox.post("请选择版本", "错误", MessageBox.ERROR);
}
}
private void initUI() {
this.setTitle("修改分类属性");
this.setAutoRequestFocus(true);
this.setResizable(false);
this.setAlwaysOnTop(true);
JPanel rootPanel = new JPanel();
rootPanel.setLayout(null);
rootPanel.setPreferredSize(new Dimension(300, 350));
Map<Integer, ClassPropBean> displayMap = new LinkedHashMap<Integer, ClassPropBean>();
propMap = new HashMap<String, JComponent>();
try {
if (rev.getClassificationClass() != null && !"".equals(rev.getClassificationClass())) {
try {
rev.refresh();
TCComponentICO ico = rev.getClassificationObjects()[0];
ICSProperty[] props = ico.getICSProperties(true);
ICSPropertyDescription[] desc = ico.getICSPropertyDescriptors();
for (int i = 0; i < props.length; i++) {
System.out.println(props[i].getId() + "===>" + props[i].getValue());
displayMap.put(props[i].getId(),
new ClassPropBean(props[i].getId(), desc[i].getName(), props[i].getValue()));
}
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} else {
MessageBox.post("当前版本未被分类", "错误", MessageBox.ERROR);
return;
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (displayMap.size() == 0) {
return;
}
String uid = JDMethodUtil.getPrefStr("jd_class_prop_option", session);
System.out.println("uid======>" + uid);
Map<Integer, String> propOption = null;
try {
TCComponent comp = session.stringToComponent(uid);
if (comp != null) {
TCComponentDataset op = (TCComponentDataset) comp;
String temp = System.getenv("temp");
String[] types = op.getProperty("ref_names").split(",");
File optionFile = op.getFiles(types[0], temp)[0];
optionFile.deleteOnExit();
System.out.println(rev.getItem().getProperty("object_type"));
propOption = ExcelInfoScanner.getClassPropOptions(optionFile.getPath(),
rev.getItem().getProperty("object_type"));
System.out.println("propOption count======>" + propOption.size());
}
} catch (TCException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
JPanel content = new JPanel();
content.setLayout(null);
content.setPreferredSize(new Dimension(300, displayMap.size() * (25 + 10)));
int num = 0;
for (Entry<Integer, ClassPropBean> entry : displayMap.entrySet()) {
JLabel label = new JLabel(entry.getValue().getName() + "");
label.setBounds(10, num * 35 + 10, 100, 25);
if (propOption != null && propOption.containsKey(entry.getKey())) {
String[] items = propOption.get(entry.getKey()).split(",");
JComboBox<String> combo = new JComboBox<String>();
combo.addItem(" ");
for (String s : items) {
combo.addItem(s);
}
String v = entry.getValue().getValue();
combo.setSelectedItem(v);
if (!Arrays.asList(items).contains(v)) {
combo.addItem(v);
combo.setSelectedItem(v);
}
combo.setBounds(130, num * 35 + 10, 150, 25);
propMap.put(entry.getValue().getName(), combo);
content.add(combo);
} else {
JTextField text = new JTextField(entry.getValue().getValue());
text.setBounds(130, num * 35 + 10, 150, 25);
propMap.put(entry.getValue().getName(), text);
content.add(text);
}
content.add(label);
num++;
}
JButton okBtn = new JButton("确认");
okBtn.setBounds(40, 310, 100, 25);
okBtn.setSelected(true);
okBtn.addActionListener(ok());
JButton cancelBtn = new JButton("取消");
cancelBtn.setBounds(160, 310, 100, 25);
cancelBtn.addActionListener(cancel());
JScrollPane jsp = new JScrollPane(content);
jsp.getVerticalScrollBar().setUnitIncrement(16);
jsp.setBounds(0, 0, 300, 300);
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
rootPanel.add(jsp);
rootPanel.add(okBtn);
rootPanel.add(cancelBtn);
this.add(rootPanel);
this.pack();
this.centerToScreen();
this.showDialog();
}
private ActionListener ok() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
((JButton) e.getSource()).setEnabled(false);
rev = (TCComponentItemRevision) target;
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
int i = 1;
while (!DIALOG.finished) {
try {
DIALOG.setTitle("正在修改分类属性 " + StringCreateUtil.createPoint(i++ % 3));
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
saveClassification(rev);
// try {
// System.out.println(rev.getProperty("object_string"));
// if (rev.getType().equals("JD2_GTBJRevision")) {
// TCComponent[] comps = rev.getReferenceListProperty("TC_Is_Represented_By");
// System.out.println(comps.length);
// for (int i = 0; i < comps.length; i++) {
// if (comps[i].getType().equals("JD2_XYJTZRevision")) {
// System.out.println("object_string:" + comps[i].getProperty("object_string"));
// TCComponentItemRevision tzrev = (TCComponentItemRevision) comps[i];
// saveClassification(tzrev);
// }
// }
// }
// } catch (TCException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
}
};
}
private ActionListener cancel() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
DIALOG.disposeDialog();
}
};
}
private boolean saveClassification(TCComponentItemRevision rev) {
try {
TCComponentForm form = (TCComponentForm) rev.getRelatedComponents("IMAN_master_form_rev")[0];
TCComponent[] status = form.getRelatedComponents("release_status_list");
for (TCComponent comp : status) {
if (comp.getProperty("object_name").contains("正式")) {
JOptionPane.showMessageDialog(this, "版本表单已正式发布,不允许修改分类属性", "提示", JOptionPane.WARNING_MESSAGE);
return false;
}
}
TCComponentICO[] icoS = rev.getClassificationObjects();
System.out.println("======>获取的分类对象有:" + icoS.length);
String classID = rev.getClassificationClass();
if (icoS == null || icoS.length == 0) {
return false;
}
for (int i = 0; i < icoS.length; i++) {
TCComponentICO ico = icoS[i];
ICSPropertyDescription[] desc = ico.getICSPropertyDescriptors();
ICSProperty[] oldICSProps = ico.getICSProperties(true);
ids = new int[oldICSProps.length];
values = new String[oldICSProps.length];
names = new String[oldICSProps.length];
for (int j = 0; j < oldICSProps.length; j++) {
ids[j] = oldICSProps[j].getId();
if (propMap.get(desc[j].getName()) instanceof JComboBox) {
String str = ((JComboBox<String>) propMap.get(desc[j].getName())).getSelectedItem().toString();
values[j] = " ".equals(str) ? "" : str;
} else {
values[j] = ((JTextField) propMap.get(desc[j].getName())).getText();
}
names[j] = desc[j].getName();
}
JSONObject obj = new JSONObject();
obj.put("ids", ids);
obj.put("values", values);
String prop = obj.toString();
// prop = prop.replace("\"", "\\\"");
String server = JDMethodUtil.getPrefStr("jd2_server_ip", session);
if (server == null || "".equals(server)) {
MessageBox.post("未配置jd2_server_ip首选项", "错误", MessageBox.ERROR);
return false;
}
String url = "http://" + server + ":8880/api/sendClassification";
Map<String, Object> paramMap = new HashMap<String, Object>();
String uid = rev.getUid();
paramMap.put("uid", uid);
paramMap.put("cid", classID);
paramMap.put("prop", prop);
System.out.println(url);
System.out.println(prop);
final String URL = url;
final Map<String, Object> PARAMMAP = paramMap;
final TCComponentItemRevision REV = rev;
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
String res = cn.hutool.http.HttpUtil.post(URL, PARAMMAP);
System.out.println("uid===>" + uid + " res===>" + res);
finish();
}
}).start();
}
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
JOptionPane.showMessageDialog(null, e1, "错误", JOptionPane.ERROR_MESSAGE);
}
return true;
}
private void finish() {
try {
rev.refresh();
String[] prefArr = JDMethodUtil.getPrefStrArray("jd2_custom_display_name", session);
String classAddress = getClassificationAddress(rev.getClassificationClass());
System.out.println("classAddress=====>" + classAddress);
for (String pref : prefArr) {
String[] className = pref.split(":")[0].split("/");
if (classAddress.contains(className[0]) && classAddress.contains(className[1])) {
String[] prefClassNamesArr = pref.split(":")[1].split(",");
System.out.println("pref class porp names=====>" + Arrays.toString(prefClassNamesArr));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < prefClassNamesArr.length; i++) {
System.out.println(prefClassNamesArr[i]);
for (int ii = 0; ii < names.length; ii++) {
System.out.println(names[ii]);
if (prefClassNamesArr[i].equals(names[ii]) && !"".equals(values[ii].trim())) {
builder.append(values[ii] + ",");
}
}
}
String temp = builder.length() > 0
? builder.toString().substring(0, builder.toString().length() - 1)
: "";
System.out.println("class porp values=====>" + temp);
// session.getUserService().call("bs_bypass", new Object[] { true });
rev.lock();
rev.setProperty("jd2_flfh", temp);
rev.save();
rev.unlock();
rev.refresh();
// session.getUserService().call("bs_bypass", new Object[] { false });
break;
}
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, "首选项jd2_custom_display_name配置有误请检查\r\n" + e.getMessage(), "提示",
JOptionPane.WARNING_MESSAGE);
return;
}
DIALOG.finished = true;
DIALOG.disposeDialog();
JOptionPane.showMessageDialog(null, "修改分类成功", "提示", JOptionPane.WARNING_MESSAGE);
System.out.println("success");
}
private String getClassificationAddress(String classId) throws TCException {
ICSAdminClass clazz = session.getClassificationService().newICSAdminClass();
clazz.load(classId);
if ("ICM".equals(clazz.askClassId())) {
return "根";
}
return clazz.getName() + "=>" + getClassificationAddress(clazz.getParent());
}
}

@ -0,0 +1 @@
package com.connor.jd.plm.dialog;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,107 @@
package com.connor.jd.plm.dialogs;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
import javax.swing.tree.TreeCellRenderer;
import com.connor.jd.plm.beans.TransformBomBean;
import com.teamcenter.rac.kernel.TCException;
public class CheckBoxTreeCellRenderer extends JPanel implements TreeCellRenderer {
protected JCheckBox check;
protected CheckBoxTreeLabel label;
public CheckBoxTreeCellRenderer() {
setLayout(null);
add(check = new JCheckBox());
add(label = new CheckBoxTreeLabel());
// 设置不可编辑
check.setEnabled(false);
check.setBackground(UIManager.getColor("Tree.textBackground"));
label.setForeground(UIManager.getColor("Tree.textForeground"));
}
/**
* <code>JPanel</code><code>JCheckBox</code>
* <code>JLabel</code><code>JCheckBox</code>
*/
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
setEnabled(tree.isEnabled());
check.setSelected(((CheckBoxTreeNode) value).isSelected());
label.setFont(tree.getFont());
label.setText(stringValue);
label.setSelected(selected);
label.setFocus(hasFocus);
CheckBoxTreeNode node = (CheckBoxTreeNode) value;
TransformBomBean bean = (TransformBomBean) node.getUserObject();
try {
String type = bean.line.getItemRevision().getType();
if (type.equals("WX3_ZPTRevision")) {
URL resource = CheckBoxTreeCellRenderer.class.getResource("/com/connor/wxplm/utils/WX3_zptrev.png");
label.setIcon(new ImageIcon(resource));
} else if (type.equals("WX3_LJTRevision")) {
URL resource = CheckBoxTreeCellRenderer.class.getResource("/com/connor/wxplm/utils/WX3_ljtrev.png");
label.setIcon(new ImageIcon(resource));
} else if (type.equals("WX3_WLRevision")) {
URL resource = CheckBoxTreeCellRenderer.class.getResource("/com/connor/wxplm/utils/WX3_WLRev.png");
label.setIcon(new ImageIcon(resource));
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
* if(leaf) label.setIcon(UIManager.getIcon("Tree.leafIcon")); else if(expanded)
* label.setIcon(UIManager.getIcon("Tree.expandedIcon")); else
* label.setIcon(UIManager.getIcon("Tree.closedIcon"));
*/
return this;
}
@Override
public Dimension getPreferredSize() {
Dimension dCheck = check.getPreferredSize();
Dimension dLabel = label.getPreferredSize();
return new Dimension(dCheck.width + dLabel.width,
dCheck.height < dLabel.height ? dLabel.height : dCheck.height);
}
@Override
public void doLayout() {
Dimension dCheck = check.getPreferredSize();
Dimension dLabel = label.getPreferredSize();
int yCheck = 0;
int yLabel = 0;
if (dCheck.height < dLabel.height)
yCheck = (dLabel.height - dCheck.height) / 2;
else
yLabel = (dCheck.height - dLabel.height) / 2;
check.setLocation(0, yCheck);
check.setBounds(0, yCheck, dCheck.width, dCheck.height);
label.setLocation(dCheck.width, yLabel);
label.setBounds(dCheck.width, yLabel, dLabel.width, dLabel.height);
}
@Override
public void setBackground(Color color) {
if (color instanceof ColorUIResource)
color = null;
super.setBackground(color);
}
}

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

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

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

@ -0,0 +1,14 @@
package com.connor.jd.plm.dialogs;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
public class ColorMaterialBean {
public List<String[]> colorMaterial = new ArrayList<String[]>();
public Map<TCComponentItemRevision, Object[]> data = new HashMap<TCComponentItemRevision, Object[]>();
}

@ -0,0 +1,40 @@
package com.connor.jd.plm.dialogs;
import java.awt.Component;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import com.teamcenter.rac.kernel.TCSession;
public class MyTreeCellRenderer extends DefaultTreeCellRenderer {
private TCSession session;
public MyTreeCellRenderer(TCSession session) {
this.session = session;
}
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
setText(value.toString());
if (sel) {
setForeground(getTextSelectionColor());
} else {
setForeground(getTextNonSelectionColor());
}
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
String str = node.toString();
if (!"".equals(str)) {
// session.search(arg0, arg1, arg2)
}
return this;
}
}

@ -0,0 +1,295 @@
package com.connor.jd.plm.dialogs;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.connor.jd.operations.ExcelOperation;
import com.connor.jd.plm.utils.JDMethodUtil;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentProjectSmartFolder;
import com.teamcenter.rac.kernel.TCComponentTcFile;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
public class QTXJCDialog extends Application {
private TCSession session;
private TextField road = null;
private ComboBox<String> pjsName = null;
private List<String> sfList = new ArrayList<String>();
private TCComponent[] com;
private String type;
private Stage primaryStage = null;
public QTXJCDialog(List<String> sfList, TCComponent[] com, TCSession session, String type) throws TCException {
this.sfList = sfList;
this.com = com;
this.session = session;
this.type = type;
// initUI();
}
@Override
public void start(Stage arg0) throws Exception {
primaryStage = new Stage();
Pane root = new Pane();
Label pjStage = new Label("项目阶段");
pjStage.setLayoutX(37.0);
pjStage.setLayoutY(51.0);
pjsName = new ComboBox<String>();
pjsName.setLayoutX(89.0);
pjsName.setLayoutY(47.0);
pjsName.setPrefSize(161.0, 23.0);
pjsName.setValue("");
pjsName.getItems().add("");
for (int i = 0; i < sfList.size(); i++) {
pjsName.getItems().add(sfList.get(i));
}
Label roadLabel = new Label("路径");
roadLabel.setLayoutX(37.0);
roadLabel.setLayoutY(107.0);
road = new TextField();
road.setLayoutX(89.0);
road.setLayoutY(103.0);
road.setDisable(true);
Button open = new Button("选择");
open.setLayoutX(263.0);
open.setLayoutY(103.0);
open.setOnAction((arg) -> {
openBtn(primaryStage);
});
Button export = new Button("导出");
export.setLayoutX(89.0);
export.setLayoutY(158.0);
export.setPrefSize(48.0, 23.0);
export.setOnAction((arg) -> {
exportBtn();
});
Button out = new Button("取消");
out.setLayoutX(208.0);
out.setLayoutY(158.0);
out.setPrefSize(48.0, 23.0);
out.setOnAction((arg) -> {
primaryStage.close();
});
root.getChildren().add(pjStage);
root.getChildren().add(pjsName);
root.getChildren().add(roadLabel);
root.getChildren().add(road);
root.getChildren().add(open);
root.getChildren().add(export);
root.getChildren().add(out);
Scene scene = new Scene(root, 338.0, 207);
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show();
}
// private void initUI() {
// this.setAutoRequestFocus(true);
// this.setPreferredSize(new Dimension(360, 150));
// this.setResizable(false);
//
// JLabel pjStage = new JLabel("项目阶段");
// pjsName.addItem("");
// for (int i = 0; i < sfList.size(); i++) {
// pjsName.addItem(sfList.get(i));
// }
// JLabel roadLabel = new JLabel("路径");
//
// JButton open = new JButton("...");
// open.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// openBtn();
// }
// });
// JButton export = new JButton("导出");
// export.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// exportBtn();
// }
// });
// JButton out = new JButton("取消");
// out.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// dispose();
// }
// });
// JPanel flow1 = new JPanel();
// Box b1 = Box.createHorizontalBox();
// flow1.add(b1);
// // b1.add(Box.createHorizontalStrut(20));
// b1.add(pjStage);
// b1.add(Box.createHorizontalStrut(50));
// b1.add(pjsName);
// JPanel flow2 = new JPanel();
// Box b2 = Box.createHorizontalBox();
// flow2.add(b2);
// b2.add(Box.createHorizontalStrut(20));
// b2.add(roadLabel);
// b2.add(Box.createHorizontalStrut(20));
// b2.add(road);
// b2.add(Box.createHorizontalStrut(80));
// b2.add(open);
// JPanel btn = new JPanel(new ButtonLayout());
// btn.add(export);
// btn.add(out);
// JPanel center = new JPanel(new BorderLayout());
// center.add(flow1, BorderLayout.NORTH);
// center.add(flow2, BorderLayout.CENTER);
// center.add(btn, BorderLayout.SOUTH);
// this.add(center, "Center");
//
// this.pack();
// this.centerToScreen();
// this.showDialog();
// }
//
String roadName = null;
private void openBtn(Stage primaryStage) {
FileChooser chooser = new FileChooser();
chooser.setTitle("请选择要保存的文件夹");
chooser.getExtensionFilters().addAll(new ExtensionFilter("Excel工作簿(*.xlsx)", "xlsx"));
File getfile = chooser.showSaveDialog(primaryStage);
try {
if (getfile.getAbsolutePath() != null) {
String filePath = getfile.getAbsolutePath() + ".xlsx";
roadName = filePath;
if (filePath.length() > 25) {
road.setText(filePath.substring(0, 25) + "...");
} else {
road.setText(filePath);
}
}
} catch (Exception e) {
}
}
private void exportBtn() {
String jdname = "JDJFW";
if (roadName.equals("")) {
MessageBox.post("没有选择保存路径", "错误", MessageBox.ERROR);
} else {
System.out.println(road.getText());
String outpath = roadName;
System.out.println(outpath);
// System.out.println("type是" + type);
File file = getExcle(jdname, type);
String sel = pjsName.getSelectionModel().getSelectedItem();
Map<String, List<TCComponent>> jfw = new HashMap<String, List<TCComponent>>();
if (sel.equals("")) {
for (int i = 0; i < sfList.size(); i++) {
TCComponentProjectSmartFolder sf = (TCComponentProjectSmartFolder) com[i];
try {
TCComponent[] psf = sf.getTCProperty("project_data").getReferenceValueArray();
List<TCComponent> jfList = new ArrayList<TCComponent>();
for (int j = 0; j < psf.length; j++) {
// TCComponentItem jf = (TCComponentItem) psf[j];
jfList.add(psf[j]);
}
jfw.put(sf.getProperty("object_string"), jfList);
} catch (TCException e) {
e.printStackTrace();
}
}
} else {
for (int i = 0; i < sfList.size(); i++) {
TCComponentProjectSmartFolder sf = (TCComponentProjectSmartFolder) com[i];
try {
if (sel.equals(sf.getProperty("object_string"))) {
TCComponent[] psf = sf.getTCProperty("project_data").getReferenceValueArray();
List<TCComponent> jfList = new ArrayList<TCComponent>();
for (int j = 0; j < psf.length; j++) {
// TCComponentItem jf = (TCComponentItem) psf[j];
jfList.add(psf[j]);
}
jfw.put(sel, jfList);
}
} catch (TCException e) {
e.printStackTrace();
}
}
}
ExcelOperation.writeExcel(file, outpath, jfw);
System.out.println("导出成功");
primaryStage.close();
MessageBox.post("导出成功", "信息", MessageBox.INFORMATION);
}
}
private File getExcle(String ssx, String type) {
File fmsFile = null;
String allpuid = JDMethodUtil.getPrefStr(ssx, session);
String[] relpuid = allpuid.split(";");
if (relpuid.length != 3) {
MessageBox.post("请联系管理员检查首选项", "错误", MessageBox.ERROR);
return null;
}
String puid = null;
switch (type) {
case "GT":
puid = relpuid[2];
break;
case "BL":
puid = relpuid[1];
break;
case "BX":
puid = relpuid[0];
break;
default:
break;
}
if (puid == null) {
MessageBox.post("请联系管理员检查首选项", "错误", MessageBox.ERROR);
return null;
}
TCComponentDataset dateset = null;
try {
dateset = (TCComponentDataset) session.stringToComponent(puid);
} catch (TCException e) {
e.printStackTrace();
}
if (dateset == null) {
MessageBox.post("未找到数据集,请联系管理员检查首选项", "错误", MessageBox.ERROR);
return null;
}
try {
TCComponentTcFile[] file = dateset.getTcFiles();
if (file.length == 0 || file.length != 1) {
MessageBox.post("数据集没有命名引用的文件或文件过多,请检查!", "警告", MessageBox.WARNING);
return null;
} else {
fmsFile = file[0].getFmsFile();
}
} catch (Exception e) {
e.printStackTrace();
}
return fmsFile;
}
}

@ -0,0 +1,887 @@
package com.connor.jd.plm.dialogs;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.ScrollPaneConstants;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import com.connor.jd.plm.beans.TransformBomBean;
import com.connor.jd.plm.utils.DialogUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMViewRevision;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
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.kernel.TCTypeService;
import com.teamcenter.rac.kernel.ics.ICSProperty;
import com.teamcenter.rac.util.ButtonLayout;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
/**
* bombom
*
* @author conner.mcc
*
*/
public class TransformDesignToPartDialog extends AbstractAIFDialog implements ActionListener {
private AbstractAIFApplication app;
private TCSession session;
private TCComponentBOMLine topBomline;
private JButton okButton;
private JButton celButton;
private JTree tree;
private CheckBoxTreeNode topTree;
private List<JComboBox<String>> comboxList;
private JPanel rightJPanel;
private Map<CheckBoxTreeNode, JComboBox<String>> checkBoxTreeNodelMap;
private Map<JComboBox<String>, JButton> boxJButtonMap;
private JPanel leftJPanel;
private int index = 1;
private String[] types;
TCComponentBOMWindow win;
public TransformDesignToPartDialog(AbstractAIFApplication app, TCComponentBOMLine topBomline, String[] types) {
// TODO Auto-generated constructor stub
System.out.println("step:-3------------------");
comboxList = new ArrayList<>();
this.app = app;
this.session = (TCSession) app.getSession();
this.topBomline = topBomline;
this.types = types;
createWindow();
initUI();
}
private void createWindow() {
try {
TCTypeService service = session.getTypeService();
TCComponentBOMWindowType winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow");
win = winType.create(null);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
*/
private void initUI() {
this.setTitle("DBOM转EBOM");
this.setSize(new Dimension(700, 400));
JPanel rightroot = new JPanel(new BorderLayout());
rightJPanel = new JPanel(new PropertyLayout());
rightroot.setBorder(BorderFactory.createTitledBorder("物料"));
leftJPanel = new JPanel(new BorderLayout());
leftJPanel.setBorder(BorderFactory.createTitledBorder("图纸"));
leftJPanel.setPreferredSize(new Dimension(350, 300));
rightroot.setPreferredSize(new Dimension(350, 300));
getBOMTreeAndwl();
JScrollPane leftpane = new JScrollPane(tree);
leftpane.setBorder(null);
leftJPanel.add(leftpane);
JScrollPane rightpane = new JScrollPane(rightJPanel);
rightroot.add(rightpane);
rightpane.setBorder(null);
final JScrollBar bar2 = rightpane.getVerticalScrollBar();
final JScrollBar bar1 = leftpane.getVerticalScrollBar();
rightpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
leftpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
bar2.addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
// TODO Auto-generated method stub
if (e.getValueIsAdjusting()) {
bar1.setValue(e.getValue());
}
}
});
bar1.addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
// TODO Auto-generated method stub
if (e.getValueIsAdjusting()) {
bar2.setValue(e.getValue());
}
}
});
leftpane.getVerticalScrollBar().setUnitIncrement(10);
leftpane.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getScrollType() == e.WHEEL_UNIT_SCROLL && bar1.getValue() >= 0
&& bar1.getValue() <= bar1.getVisibleAmount()) {
int scroll = e.getUnitsToScroll();
bar2.setValue(scroll * bar1.getUnitIncrement());
}
}
});
rightpane.getVerticalScrollBar().setUnitIncrement(10);
rightpane.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getScrollType() == e.WHEEL_UNIT_SCROLL && bar1.getValue() >= 0
&& bar1.getValue() <= bar1.getVisibleAmount()) {
int scroll = e.getUnitsToScroll();
bar1.setValue(scroll * bar2.getUnitIncrement());
}
}
});
JPanel botomJPanel = new JPanel(new ButtonLayout());
okButton = new JButton("转换");
okButton.addActionListener(this);
celButton = new JButton("退出");
celButton.addActionListener(this);
botomJPanel.add("1.1.left.top", okButton);
botomJPanel.add("1.2.left.top", new JLabel(" "));
botomJPanel.add("1.3.left.top", celButton);
JPanel rootJPanel = new JPanel(new PropertyLayout());
rootJPanel.add("1.1.left.top", leftJPanel);
rootJPanel.add("1.2.left.top", rightroot);
this.setLayout(new BorderLayout());
this.add(rootJPanel, BorderLayout.CENTER);
this.add(botomJPanel, BorderLayout.SOUTH);
this.pack();
this.centerToScreen();
this.showDialog();
this.setResizable(false);
}
/**
* @param line BOM
* @param node
* @throws TCException
*/
public void treeModel(TCComponentBOMLine line, CheckBoxTreeNode node) throws TCException {
System.out.println(line.getProperty("object_string") + "-------------------");
AIFComponentContext[] children = line.getChildren();
for (AIFComponentContext conetext : children) {
TCComponentBOMLine childLine = (TCComponentBOMLine) conetext.getComponent();
final CheckBoxTreeNode childNode = new CheckBoxTreeNode(new TransformBomBean(childLine));
childNode.setSelectable(false);
node.add(childNode);
setCombox(childLine, childNode);
treeModel(childLine, childNode);
}
}
private void getBOMTreeAndwl() {
try {
checkBoxTreeNodelMap = new HashMap<>();
boxJButtonMap = new HashMap<>();
topTree = new CheckBoxTreeNode(new TransformBomBean(topBomline));
setCombox(topBomline, topTree);
System.out.println("##########" + topTree.toString() + "##########");
treeModel(topBomline, topTree);
tree = new JTree();
tree.setEnabled(false);
tree.setRowHeight(30);
DefaultTreeModel model = new DefaultTreeModel(topTree);
tree.addMouseListener(new CheckBoxTreeNodeSelectionListener());
tree.setModel(model);
tree.setCellRenderer(new CheckBoxTreeCellRenderer());
tree.putClientProperty("JTree.lineStyle", "Angled");
topTree.setSelectable(false);
tree.expandPath(new TreePath(topTree.getPath()));
Enumeration<?> enumeration = topTree.preorderEnumeration();
while (enumeration.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) enumeration.nextElement();
if (!node.isLeaf()) {
TreePath path = new TreePath(node.getPath());
tree.expandPath(path);
}
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource().equals(okButton)) {
try {
System.out.println("进行转换");
if (win == null)
createWindow();
ColorMaterialBean bean = new ColorMaterialBean();
createMaterialBom(topTree, bean);
if (bean.colorMaterial.size() != 0) {
System.out.println(
Arrays.deepToString(bean.colorMaterial.toArray(new String[bean.colorMaterial.size()][])));
JScrollPane msgPanel = DialogUtil.createTableMsg(new String[] { "ID", "版本", "名称", "颜色" },
bean.colorMaterial).panel;
int r = JOptionPane.showConfirmDialog((Component) e.getSource(), msgPanel, "颜色件确认",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (r == JOptionPane.OK_OPTION) {
createBom1(bean);
} else {
System.out.println("cancel");
return;
}
} else {
createBom1(bean);
}
MessageBox.post("转换bom成功", "提示", MessageBox.INFORMATION);
this.dispose();
} catch (TCException e1) {
// TODO Auto-generated catch block
MessageBox.post(e1.getMessage(), "转换bom失败", MessageBox.INFORMATION);
e1.printStackTrace();
} finally {
try {
win.close();
win = null;
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} else if (e.getSource().equals(celButton)) {
dispose();
}
}
@SuppressWarnings("unchecked")
private void createBom1(ColorMaterialBean bean) throws TCException {
for (Entry<TCComponentItemRevision, Object[]> entry : bean.data.entrySet()) {
List<TCComponentItemRevision> arg1 = entry.getValue()[1] == null ? null
: (List<TCComponentItemRevision>) entry.getValue()[1];
List<String> arg2 = entry.getValue()[2] == null ? null : (List<String>) entry.getValue()[2];
List<String> arg3 = entry.getValue()[3] == null ? null : (List<String>) entry.getValue()[3];
createBom(entry.getKey(), arg1, arg2, arg3);
}
}
/**
* Treeitem
*
* @param wl
*//*
* private void checkSelected(String wl) { for (TransformBomBean bean : bomlist)
* { if (bean.map.containsKey(wl)) { bean.selectCount++; if (bean.selectCount >
* 1) { MessageBox.post("只能为当前图纸选择一个物料进行设计BOM的转换", "警告", MessageBox.WARNING);
* return; } System.out.println(bean.displayName + "选中显示名");
* System.out.println(checkBoxTreeNodelMap.containsKey(bean.displayName) );
* checkBoxTreeNodelMap.get(bean.displayName).setSelected(true);
* findInTree(bean.displayName); TransformBomBean bean1 = (TransformBomBean)
* checkBoxTreeNodelMap.get(bean.displayName).getUserObject(); bean1.selectRev =
* (TCComponentItemRevision) bean.map.get(wl); } } }
*/
/**
* Treeitem
*
* @param wl
*//*
* private void checkDisSelected(String wl) { for (TransformBomBean bean :
* bomlist) { if (bean.map.containsKey(wl)) { bean.selectCount--;
* checkBoxTreeNodelMap.get(bean.displayName).setSelected(false); } } }
*/
/**
* BOM
*
* @param node
* @throws TCException
*/
private void createMaterialBom(CheckBoxTreeNode node, ColorMaterialBean colorMaterialBean) throws TCException {
// System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
TransformBomBean bean = (TransformBomBean) node.getUserObject();
TCComponentItemRevision materialRev = bean.selectRev;
// 存在已经发布的物料的bom
/*
* if (WXMethodUtil.isRevBomReleased(materialRev)) { System.out.println("发布");
* return; }
*/
if (isLoopBom(node)) {
MessageBox.post("存在循环BOM结构", "警告", MessageBox.WARNING);
return;
}
int childCount = node.getChildCount();
List<TCComponentItemRevision> childrenList = new ArrayList<>();
List<String> quantityList = new ArrayList<>();
for (int i = 0; i < childCount; i++) {
CheckBoxTreeNode childNode = (CheckBoxTreeNode) node.getChildAt(i);
if (childNode.isSelected()) {
TransformBomBean bean1 = (TransformBomBean) childNode.getUserObject();
childrenList.add(bean1.selectRev);
quantityList.add(bean1.line.getProperty("bl_quantity"));
// 判断是否发布
if (isRevBomReleased(bean1.selectRev)) {
// 发布就搭建原来的bom
System.out.println("原来搭建》》》》》》》》》》》》》》》");
if (isLoopBom(childNode)) {
MessageBox.post("存在循环BOM结构", "警告", MessageBox.WARNING);
return;
}
} else {
createMaterialBom(childNode, colorMaterialBean);
}
}
}
for (TCComponentItemRevision material : childrenList) {
if (material.getClassificationObjects().length > 0) {
String ys = null;
TCComponentICO ico = material.getClassificationObjects()[0];
ICSProperty[] props = ico.getICSProperties(true);
for (ICSProperty prop : props) {
if (prop.getId() == 1007) {
ys = prop.getValue();
break;
}
}
if (ys != null && !"".equals(ys)) {
System.out.println("颜色件:" + material.getProperty("object_string"));
colorMaterialBean.colorMaterial.add(new String[] { material.getProperty("item_id"),
material.getProperty("item_revision_id"), material.getProperty("object_name"), ys });
}
}
}
colorMaterialBean.data.put(materialRev, new Object[] { materialRev, childrenList, null, quantityList });
}
private TreePath findInPath(TreePath treePath, String str) {
Object object = treePath.getLastPathComponent();
if (object == null) {
return null;
}
String value = object.toString();
if (str.equals(value)) {
return treePath;
} else {
TreeModel model = tree.getModel();
int n = model.getChildCount(object);
for (int i = 0; i < n; i++) {
Object child = model.getChild(object, i);
TreePath path = treePath.pathByAddingChild(child);
path = findInPath(path, str);
if (path != null) {
return path;
}
}
return null;
}
}
private void findInTree(String str) {
Object root = tree.getModel().getRoot();
TreePath treePath = new TreePath(root);
treePath = findInPath(treePath, str);
if (treePath != null) {
tree.setSelectionPath(treePath);
CheckBoxTreeNode node = (CheckBoxTreeNode) tree.getLastSelectedPathComponent();
tree.scrollPathToVisible(treePath);
}
}
/**
* @param line
* @param childNode
* @return
*/
public String[] getBomRef(TCComponentBOMLine line, CheckBoxTreeNode childNode) {
try {
if (line == null) {
return null;
}
AIFComponentContext[] aifContext = line.getItemRevision().whereReferencedByTypeRelation(types,
new String[] { "TC_Is_Represented_By" });
if (aifContext == null || aifContext.length == 0) {
return new String[] { "" };
} else {
AIFComponentContext[] newContext = isNewRev(aifContext);
String[] wl = new String[newContext.length];
TransformBomBean bean = (TransformBomBean) childNode.getUserObject();
for (int i = 0; i < wl.length; i++) {
TCComponentItemRevision comp = (TCComponentItemRevision) newContext[i].getComponent();
wl[i] = comp.getProperty("object_string");
bean.map.put(wl[i], comp);
}
return wl;
}
} catch (TCException e) {
e.printStackTrace();
}
return new String[] { "" };
}
/**
*
*
* @param childLine
* @param childNode
*/
private void setCombox(TCComponentBOMLine childLine, final CheckBoxTreeNode childNode) {
try {
System.out.println(childLine.getItemRevision().getType() + "<<<<<<<<<<");
final String[] bomRef = getBomRef(childLine, childNode);
final DefaultComboBoxModel model = new DefaultComboBoxModel();
model.addElement("");
for (String str : bomRef) {
model.addElement(str);
}
final JComboBox<String> childbox = new JComboBox();
// 模糊搜索按钮
final JButton search = new JButton("搜索");
checkBoxTreeNodelMap.put(childNode, childbox);
boxJButtonMap.put(childbox, search);
childbox.setModel(model);
childbox.setSelectedIndex(-1);
childbox.setEditable(true);
if (childbox.getItemCount() <= 2 && childbox.getItemAt(1) != null && !childbox.getItemAt(1).equals("")) {
childbox.setSelectedIndex(1);
childbox.setEditable(false);
childNode.setSelected(true);
search.setEnabled(false);
childbox.enable(false);
TransformBomBean bean = (TransformBomBean) childNode.getUserObject();
bean.selectRev = bean.map.get(childbox.getSelectedItem().toString());
} else if (childbox.getItemCount() <= 2) {
childbox.setEditable(false);
search.setEnabled(false);
childbox.enable(false);
}
if (childLine.getItemRevision().getType().equals("PartRevision")) {
childbox.setEditable(false);
search.setEnabled(false);
childNode.setSelected(true);
childbox.enable(false);
TransformBomBean bean = (TransformBomBean) childNode.getUserObject();
bean.selectRev = childLine.getItemRevision();
}
childbox.setPreferredSize(new Dimension(240, 23));
search.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
if (childbox.isEditable() && search.isEnabled()) {
String str = childbox.getEditor().getItem().toString();
model.removeAllElements();
model.addElement("");
for (int i = 0; i < bomRef.length; i++) {
if (bomRef[i].contains(str)) {
model.addElement(bomRef[i]);
}
}
childbox.setModel(model);
childbox.setPopupVisible(true);
}
}
});
childbox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
try {
if (e.getStateChange() == 1) {
if (childbox.getSelectedIndex() > 0) {
TransformBomBean bean = (TransformBomBean) childNode.getUserObject();
bean.selectRev = bean.map.get(childbox.getSelectedItem().toString());
childNode.setSelected(true);
System.out.println("-----------" + bean.displayName);
// 判断是否布 发布子类全部不可选择
boolean released = isReleased(bean.selectRev, childNode);
System.out.println("<<<<<<<<<<是否发布:" + released);
tree.repaint();
} else {
System.out.println("<<<<<<<<<<选择空:");
restoreSelect(childNode);
childNode.setSelected(false);
tree.repaint();
}
}
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
comboxList.add(childbox);
rightJPanel.add((index) + ".1.left.top", childbox);
rightJPanel.add((index++) + ".2.left.top", search);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
*
* @param rev
* @param childNode
* @return
*/
private boolean isReleased(TCComponentItemRevision rev, CheckBoxTreeNode childNode) {
try {
System.out.println("执行判断" + rev.getProperty("object_name"));
if (rev != null && isRevBomReleased(rev)) {
setUnable(childNode);
return true;
} else {
restoreSelect(childNode);
return false;
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
private void setUnable(CheckBoxTreeNode childNode) {
int childCount = childNode.getChildCount();
for (int i = 0; i < childCount; i++) {
CheckBoxTreeNode node = (CheckBoxTreeNode) childNode.getChildAt(i);
JComboBox<String> box = checkBoxTreeNodelMap.get(node);
box.setSelectedIndex(-1);
box.setEditable(false);
box.setEnabled(false);
node.setSelected(false);
boxJButtonMap.get(box).setEnabled(false);
setUnable(node);
}
}
/**
*
*
* @param childNode
* @throws TCException
*/
private void restoreSelect(CheckBoxTreeNode childNode) throws TCException {
int childCount = childNode.getChildCount();
for (int i = 0; i < childCount; i++) {
CheckBoxTreeNode node = (CheckBoxTreeNode) childNode.getChildAt(i);
JComboBox<String> childbox = checkBoxTreeNodelMap.get(node);
TransformBomBean bean = (TransformBomBean) node.getUserObject();
childbox.setEditable(true);
childbox.setEnabled(true);
childbox.setSelectedIndex(-1);
if (childbox.getItemCount() <= 2 && !childbox.getItemAt(1).equals("")) {
childbox.setSelectedIndex(1);
childbox.setEditable(false);
childbox.setEnabled(false);
node.setSelected(true);
boxJButtonMap.get(childbox).setEnabled(false);
bean.selectRev = bean.map.get(childbox.getSelectedItem().toString());
} else if (childbox.getItemCount() <= 2) {
childbox.setEditable(false);
childbox.setEnabled(false);
boxJButtonMap.get(childbox).setEnabled(false);
}
if (bean.line.getItemRevision().isTypeOf("PartRevision")) {
childbox.setEditable(false);
boxJButtonMap.get(childbox).setEnabled(false);
node.setSelected(true);
childbox.setEnabled(false);
bean.selectRev = bean.line.getItemRevision();
}
restoreSelect(node);
}
}
/**
*
*
* @param aifContext
* @return
*/
private AIFComponentContext[] isNewRev(AIFComponentContext[] aifContext) {
try {
List<AIFComponentContext> list = new ArrayList<>();
for (int i = 0; i < aifContext.length; i++) {
TCComponentItemRevision rev = (TCComponentItemRevision) aifContext[i].getComponent();
if (rev.getItem().getLatestItemRevision().equals(rev)) {
list.add(aifContext[i]);
}
}
AIFComponentContext[] newContext = new AIFComponentContext[list.size()];
for (int i = 0; i < list.size(); i++) {
newContext[i] = list.get(i);
}
return newContext;
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/**
*
*
* @param node
* @return
*/
private boolean isLoopBom(CheckBoxTreeNode node) {
try {
HashSet<TCComponentItemRevision> loopSet = new HashSet<>();
boolean checkLoop = checkLoop(node, loopSet);
return checkLoop;
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
/**
* ,
*
* @param node
* @param loopSet
* @return
* @throws TCException
*/
private boolean checkLoop(CheckBoxTreeNode node, HashSet<TCComponentItemRevision> loopSet) throws TCException {
TransformBomBean bean = (TransformBomBean) node.getUserObject();
TCComponentItemRevision materialRev = bean.selectRev;
boolean add = loopSet.add(materialRev);
if (!add) {
return true;
} else {
CheckBoxTreeNode parent = (CheckBoxTreeNode) node.getParent();
if (parent == null) {
return false;
} else {
return checkLoop(parent, loopSet);
}
}
}
public void getAllBomItemByBomline(TCComponentBOMLine line, List<TCComponentItem> itemList) throws TCException {
if (line == null) {
return;
}
itemList.add(line.getItem());
AIFComponentContext[] contextS = line.getChildren();
for (AIFComponentContext context : contextS) {
TCComponentBOMLine child = (TCComponentBOMLine) context.getComponent();
getAllBomItemByBomline(child, itemList);
}
}
/**
* bom
*
* @param selectIndex
* @throws TCException
*/
public void createBom(TCComponentItemRevision parentRev, List<TCComponentItemRevision> childRevList,
List<String> queryNoList, List<String> countNoList) throws TCException {
if (childRevList == null || childRevList.size() == 0) {
return;
}
if (parentRev == null) {
return;
}
String[] setProps = { "bl_quantity" };
TCComponentBOMLine line = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null);
AIFComponentContext[] childrenContext = line.getChildren();
win.lock();
// 移出所有的子bomline
if (childrenContext.length != 0) {
for (AIFComponentContext child : childrenContext) {
line.lock();
line.remove("", (TCComponent) child.getComponent());
line.save();
line.unlock();
}
// return;
}
for (int i = 0; i < childRevList.size(); i++) {
TCComponentItemRevision rev = childRevList.get(i);
line.lock();
TCComponentBOMLine childBomLine = line.add(rev.getItem(), rev, null, false, "");
line.save();
line.unlock();
if (countNoList.get(i) != null && !countNoList.get(i).equals("")) {
childBomLine.lock();
childBomLine.setProperties(setProps, new String[] { countNoList.get(i) });
childBomLine.save();
childBomLine.unlock();
}
}
try {
win.save();
win.unlock();
} catch (Exception e) {
win.unlock();
win.close();
win = null;
System.out.println("windows close");
TCComponent[] comps = parentRev.getTCProperty("structure_revisions").getReferenceValueArray();
if (comps.length > 0) {
parentRev.remove("structure_revisions", comps[0]);
comps[0].delete();
;
}
e.printStackTrace();
throw e;
}
}
/**
*
*
* @param comp
* @return
* @throws TCException
*/
public boolean isCompReleased(TCComponent comp) throws TCException {
TCComponent[] comps = comp.getRelatedComponents("release_status_list");
if (comps != null && comps.length > 0) {
return true;
}
return false;
}
/**
* BOM
*
* @param rev
* @return
*/
public boolean isRevHadBom(TCComponentItemRevision rev) {
boolean isHad = false;
if (rev != null) {
try {
TCComponentBOMLine topLine = win.setWindowTopLine(rev.getItem(), rev, null, null);
if (topLine != null) {
if (topLine.getChildren().length > 0) {
isHad = true;
}
}
} catch (TCException e) {
e.printStackTrace();
}
}
return isHad;
}
/**
* BOM
*
* @param rev
* @return
*/
public boolean isRevBomReleased(TCComponentItemRevision rev) {
boolean isReleased = false;
try {
if (isCompReleased(rev)) {
win.setWindowTopLine(rev.getItem(), rev, null, null);
// TCComponentBOMLine line = window.getTopBOMLine();
// if(line.getChildren().length!=0){
// isReleased = true;
// }
if (isRevHadBom(rev)) {
TCComponentBOMViewRevision bvr = win.askBvr();
if (bvr != null) {
TCComponent[] status = bvr.getReferenceListProperty("release_status_list");
if (status != null && status.length != 0) {
isReleased = true;
}
}
}
}
} catch (TCException e) {
e.printStackTrace();
isReleased = true;
}
return isReleased;
}
private boolean isYSMaterial(TCComponentItemRevision rev) {
try {
Map<String, String> map = rev.getClassificationAttributes();
if (map.get("颜色") != null && !"".equals(map.get("颜色"))) {
return true;
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
}

@ -0,0 +1,839 @@
package com.connor.jd.plm.form;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import com.connor.jd.plm.beans.ComponentBean;
import com.connor.jd.plm.beans.JG;
import com.connor.jd.plm.table.DatePickerCellEditor;
import com.connor.jd.plm.table.TCTableUtil;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentDatasetType;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.stylesheet.AbstractRendering;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.services.rac.core.DataManagementService;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class CSJHForm extends AbstractRendering {
TCComponent form;
DefaultTableModel model;
TCSession session;
TCComponentItemRevision itemR;
private static Connection con = null;
private static PreparedStatement ps = null;
private static ResultSet rs = null;
private ObservableList<ComponentBean> componentData = FXCollections.observableArrayList();
String[] propNames = new String[] { "jd2_syxh", "jd2_symd", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syzq",
"jd2_syfy", "jd2_jhrc", "jd2_jhrc1", "jd2_sjrc", "jd2_sjrc1", "jd2_syzt", "jd2_syjg", "jd2_sycs",
"jd2_syry", "jd2_csbg", "jd2_bz" };
private JLabel label3;
private List<Integer> editable = new ArrayList<Integer>();
private Map<String, JG> res;
private Map<Integer, String> rowNo;// 真实编号
private JTable table;
private boolean againAllow;
public CSJHForm(TCComponent form) throws Exception {
super();
this.form = form;
session = (TCSession) AIFUtility.getCurrentApplication().getSession();
System.out.println("加载");
loadRendering();
}
int index = 1;
@Override
public void loadRendering() throws TCException {
// try {
// con = DBConnectionUtil.dbConn("infodba", "infodba");
// String sqlString = "select * from JD2_Component";
// if (con == null) {
// Alert alert = new Alert(AlertType.ERROR, "连接失败");
// alert.show();
// } else {
// ps = con.prepareStatement(sqlString);
// rs = ps.executeQuery();
// while (rs.next()) {
// ComponentBean comBean = new ComponentBean();
// // System.out.println("第一列内容:" + rs.getString(1));
// comBean.setType(rs.getString(1));
// comBean.setProject(rs.getString(2));
// comBean.setTime(rs.getString(3));
// comBean.setNumber(String.valueOf(rs.getInt(4)));
// comBean.setCost(String.valueOf(rs.getDouble(5)));
// comBean.setCompId(rs.getInt(6));
// comBean.setAddId(0);
// comBean.setStage(0);// 刚从数据库取出
// componentData.add(comBean);
// }
// }
// } catch (Exception e) {
// e.printStackTrace();
// } finally {
// if (rs != null) {
// try {
// rs.close();
// } catch (SQLException e1) {
// e1.printStackTrace();
// }
// }
// if (ps != null) {
// try {
// ps.close();
// } catch (SQLException e1) {
// e1.printStackTrace();
// }
// }
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e1) {
// e1.printStackTrace();
// }
// }
// }
this.setPreferredSize(new Dimension(1200, 250));
TCComponent[] tables = form.getTCProperty("jd2_csjh").getReferenceValueArray();
AIFComponentContext[] contexts = form.whereReferenced();
for (int i = 0; i < contexts.length; i++) {
if (contexts[i].getComponent() instanceof TCComponentItemRevision) {
try {
itemR = (TCComponentItemRevision) contexts[i].getComponent();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
String[] info = new String[] { "NO", "实验型号", "实验目的", "委托人员", "实验项目", "实验台数", "实验周期", "试验费用", "计划开始日期", "计划完成日期",
"实际开始日期", "实际完成日期", "实验状态", "实验结果", "第_次实验", "实验人员", "测试报告", "备注" };
model = new DefaultTableModel(info, 0);
JComboBox<String> testStage = new JComboBox();
JComboBox<String> testResult = new JComboBox();
String[] stageInfo = { "待测", "进行中", "完成", " " };
for (int i = 0; i < stageInfo.length; i++) {
testStage.addItem(stageInfo[i]);
}
testResult.addItem("不合格");
testResult.addItem("合格");
testResult.addItem(" ");
for (int i = 0; i < tables.length; i++) {
String[] temp = new String[18];
temp[0] = Integer.toString(index++);
String[] props = tables[i].getProperties(propNames);
for (int j = 0; j < props.length; j++) {
temp[j + 1] = props[j];
}
model.addRow(temp);
}
TCComponentItemRevision[] revs = itemR.getItem().getReleasedItemRevisions();
Comparator<TCComponent> leatestRevisionComparator = new Comparator<TCComponent>() {
@Override
public int compare(TCComponent o1, TCComponent o2) {
// TODO Auto-generated method stub
try {
return o1.getProperty("item_revision_id").compareTo(o2.getProperty("item_revision_id"));
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
};
Arrays.parallelSort(revs, leatestRevisionComparator);
if (revs.length > 0) {
List<Map<String, String>> dataMap = TCTableUtil.getTableMapList(
(TCComponentForm) revs[revs.length - 1].getRelatedComponent("IMAN_master_form_rev"), "jd2_csjh",
propNames);
List<String> realNoList = new ArrayList<String>();
for (Map<String, String> tempMap : dataMap) {
realNoList.add(tempMap.get("jd2_syxm") + "," + tempMap.get("jd2_sycs"));
}
for (int i = 0; i < tables.length; i++) {
if (realNoList.contains(tables[i].getProperty("jd2_syxm") + "," + tables[i].getProperty("jd2_sycs"))) {
editable.add(i);
}
}
}
// 目前版本是否为最新发布的下一个版本
List<String> releasedObjectString = new ArrayList<String>();
for (int i = 0; i < revs.length; i++) {
releasedObjectString.add(revs[i].getProperty("object_string"));
}
if (revs.length > 0) {
if (!releasedObjectString.contains(itemR.getProperty("object_string"))) {
TCComponent[] allRev = itemR.getItem().getRelatedComponents("revision_list");
Arrays.parallelSort(allRev, leatestRevisionComparator);
for (int i = 0; i < allRev.length; i++) {
if (allRev[i].getProperty("object_string")
.equals(revs[revs.length - 1].getProperty("object_string")) && i + 1 < allRev.length) {
if (itemR.getProperty("object_string").equals(allRev[i + 1].getProperty("object_string"))) {
againAllow = true;
break;
}
}
}
}
}
// for (int i = 0; i < componentData.size(); i++) {
// // for (int j = 0; j < tables.length; j++) {
// String project = componentData.get(i).getProject();
// String number = componentData.get(i).getNumber();
// String time = componentData.get(i).getTime();
// String cost = componentData.get(i).getCost();
//// if (!project.equals(tables[j].getProperty("jd2_syxm"))
//// && !number.equals(tables[j].getProperty("jd2_syts"))
//// && !time.equals(tables[j].getProperty("jd2_syzq"))
//// && !cost.equals(tables[j].getProperty("jd2_syfy"))) {
// String[] temp = new String[16];
// temp[0] = Integer.toString(index++);
// temp[4] = componentData.get(i).getProject();
// temp[5] = componentData.get(i).getNumber();
// temp[6] = componentData.get(i).getTime();
// temp[7] = componentData.get(i).getCost();
// model.addRow(temp);
//// }
//// }
// }
table = new JTable(model) {
@Override
public boolean isCellEditable(int row, int column) {
if (column == 3 || column == 4 || column == 5 || column == 6 || column == 7 || column == 16
|| column == 14 || editable.contains(row))
return false;
else
return true;
}
};
table.addPropertyChangeListener(e -> {
if (e.getPropertyName().equals("tableCellEditor")) {
// System.out.println("change");
}
});
for (int i = 0; i < 16; i++) {
table.getColumn(table.getColumnName(i)).setMinWidth(100);
}
DefaultCellEditor dce1 = new DefaultCellEditor(testStage) {
int row;
@Override
public Component getTableCellEditorComponent(JTable paramJTable, Object paramObject, boolean paramBoolean,
int paramInt1, int paramInt2) {
// TODO Auto-generated method stub
row = paramInt1;
return super.getTableCellEditorComponent(paramJTable, paramObject, paramBoolean, paramInt1, paramInt2);
}
@Override
public Object getCellEditorValue() {
Object obj = super.getCellEditorValue();
if ("完成".equals(obj.toString())) {
// editable.add(row);
} else {
if (editable.contains(row)) {
editable.remove(row);
}
}
return obj;
}
};
DefaultCellEditor dce2 = new DefaultCellEditor(testResult) {
JTable t;
int row;
int num;
@Override
public Component getTableCellEditorComponent(JTable paramJTable, Object paramObject, boolean paramBoolean,
int paramInt1, int paramInt2) {
// TODO Auto-generated method stub
t = paramJTable;
row = paramInt1;
String str = t.getValueAt(row, 14) == null ? "" : t.getValueAt(row, 14).toString();
num = Objects.equals(str, "") ? 0 : Integer.parseInt(str);
return super.getTableCellEditorComponent(paramJTable, paramObject, paramBoolean, paramInt1, paramInt2);
}
@Override
public Object getCellEditorValue() {
// TODO Auto-generated method stub
Object obj = super.getCellEditorValue();
if (res.containsKey(rowNo.get(row))) {
if (num >= res.get(rowNo.get(row)).getTimes()) {
res.put(rowNo.get(row), new JG(row, num, obj.toString()));
}
} else {
res.put(rowNo.get(row), new JG(row, num, obj.toString()));
}
boolean flag = false;
for (Entry<String, JG> entry : res.entrySet()) {
if ("不合格".equals(entry.getValue().getJg())) {
flag = true;
break;
}
}
if (flag) {
label3.setText("结论:不合格");
} else {
label3.setText("结论:合格");
}
return obj;
}
};
DatePickerCellEditor dpce = new DatePickerCellEditor(new JTextField());
DefaultCellEditor deafult = new DefaultCellEditor(new JTextField());
for (int i = 0; i < table.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setCellEditor(deafult);
}
table.getColumn(table.getColumnName(8)).setCellEditor(dpce);
table.getColumn(table.getColumnName(9)).setCellEditor(dpce);
table.getColumn(table.getColumnName(10)).setCellEditor(dpce);
table.getColumn(table.getColumnName(11)).setCellEditor(dpce);
table.getColumn(table.getColumnName(12)).setCellEditor(dce1);
table.getColumn(table.getColumnName(13)).setCellEditor(dce2);
table.setRowHeight(25);
table.setAutoscrolls(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getTableHeader().setReorderingAllowed(false);
if (form.isCheckedOut()) {
table.setEnabled(true);
} else {
table.setEnabled(false);
}
JPanel panelLable = new JPanel();
JLabel label = new JLabel("试验费用总计:");
JLabel label2 = new JLabel();
Double allcost = 0.0;
for (int i = 0; i < model.getRowCount(); i++) {
String value = (String) model.getValueAt(i, 7);
if (value.equals(""))
value = "0";
allcost += Double.valueOf(value);
}
label2.setText(allcost + "元");
label3 = new JLabel("结论:");
res = new HashMap<String, JG>();
rowNo = new HashMap<Integer, String>();
String no;
String jg;
for (int i = 0; i < tables.length; i++) {
no = tables[i].getProperty("jd2_no");
rowNo.put(i, no);
jg = tables[i].getProperty("jd2_syjg");
int times = Integer.parseInt(
Objects.equals(tables[i].getProperty("jd2_sycs"), "") ? "0" : tables[i].getProperty("jd2_sycs"));
if ("完成".equals(tables[i].getProperty("jd2_syzt"))) {
// editable.add(i);
}
if (res.containsKey(no)) {
if (times >= res.get(no).getTimes()) {
editable.add(res.get(no).getRow());
res.put(no, new JG(i, times, jg));
}
} else {
res.put(no, new JG(i, times, jg));
}
}
boolean notEmpty = false;
boolean qualified = true;
for (Entry<String, JG> entry : res.entrySet()) {
// System.out.println(entry.getKey() + entry.getValue().getRow() + entry.getValue().getJg()
// + entry.getValue().getTimes());
if (!"".equals(entry.getValue().getJg().trim())) {
notEmpty = true;
}
if ("不合格".equals(entry.getValue().getJg())) {
qualified = false;
break;
}
}
if (notEmpty && !qualified) {
label3.setText("结论:不合格");
} else if (notEmpty) {
label3.setText("结论:合格");
}
panelLable.add(label);
panelLable.add(label2);
panelLable.add(label3);
JPanel panel = new JPanel();
JScrollPane pane = new JScrollPane(table);
GridBagLayout gbl = new GridBagLayout();
JPanel bottom = new JPanel(gbl);
GridBagConstraints gbs = new GridBagConstraints();
gbs.anchor = GridBagConstraints.SOUTHEAST;
gbs.fill = GridBagConstraints.HORIZONTAL;
gbs.insets = new Insets(10, 20, 5, 10);
gbs.weighty = 0.2;
gbs.gridheight = 1;
gbs.gridwidth = GridBagConstraints.REMAINDER;
gbs.weightx = 1;
JButton testButton = new JButton("测试报告上传");
gbl.setConstraints(testButton, gbs);
JButton huizongButton = new JButton("汇总结论上传");
gbl.setConstraints(huizongButton, gbs);
JButton againButton = new JButton("再次试验");
gbl.setConstraints(againButton, gbs);
bottom.add(testButton);
bottom.add(huizongButton);
bottom.add(againButton);
setLayout(new BorderLayout());
panel.add(pane, BorderLayout.CENTER);
JPanel root = new JPanel(new BorderLayout());
root.add(bottom, BorderLayout.EAST);
root.add(panelLable, BorderLayout.SOUTH);
root.add(pane, BorderLayout.CENTER);
JScrollPane jsp = new JScrollPane(root);
add(jsp, BorderLayout.CENTER);
testButton.addActionListener(e -> {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("选择上传的测试报告");
FileFilter filter = new FileNameExtensionFilter("Excel工作簿(.xlsx,.xls,.xlsm)", "xlsx", "xls", "xlsm");// 设置文件过滤器只列出JPG或GIF格式的图片
chooser.setFileFilter(filter);
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
if (file != null) {
String filePath = file.getPath();
String fileName = file.getName();
String filename = fileName.substring(0, fileName.lastIndexOf("."));
System.out.println(filePath);
System.out.println(fileName);
int row = table.getSelectedRow();
String value = model.getValueAt(row, 16) == null ? "" : model.getValueAt(row, 16).toString();
if (value.equals("")) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述", null);
itemR.add("JD2_CSBG", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
model.setValueAt(item.getProperty("current_id"), row, 16);
} catch (TCException e1) {
e1.printStackTrace();
}
} else {
// 添加到数据集
boolean exist = false;
try {
TCComponent[] tcc = itemR.getTCProperty("JD2_CSBG").getReferenceValueArray();
for (int i = 0; i < tcc.length; i++) {
if (value.equals(tcc[i].getProperty("current_id"))) {
exist = true;
TCComponentItem item = (TCComponentItem) tcc[i];
TCComponent[] tccitem = item.getLatestItemRevision().getTCProperty("IMAN_specification")
.getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.setFiles(new String[] { file.getPath() }, new String[] { "excel" });
dataset.setProperty("object_name", filename);
item.setProperty("object_name", filename);
item.getLatestItemRevision().setProperty("object_name", filename);
}
}
if (!exist) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session
.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述",
null);
itemR.add("JD2_CSBG", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
model.setValueAt(item.getProperty("current_id"), row, 16);
} catch (TCException e1) {
e1.printStackTrace();
}
}
} catch (TCException e1) {
e1.printStackTrace();
}
}
}
});
huizongButton.addActionListener(e -> {
int row = table.getSelectedRow();
String value = (String) model.getValueAt(row, 16);
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("选择上传的汇总结论");
FileFilter filter = new FileNameExtensionFilter("Excel工作簿(.xlsx,.xls,.xlsm),PPT演示文稿(.ppt,.pptx)", "xlsx",
"xls", "xlsm", "ppt", "pptx");// 设置文件过滤器只列出JPG或GIF格式的图片
chooser.setFileFilter(filter);
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
TCComponentItemRevision parentRev = null;
try {
AIFComponentContext[] aifs = itemR.getItem().whereReferenced();
for (AIFComponentContext aif : aifs) {
if (aif.getComponent().getType().equals("JD2_GTSYWTSRevision")) {
parentRev = (TCComponentItemRevision) aif.getComponent();
System.out.println("JD2_GTSYWTSRevision check");
}
}
} catch (TCException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
if (file != null) {
String filePath = file.getPath();
String fileName = file.getName();
String filename = fileName.substring(0, fileName.lastIndexOf("."));
System.out.println(filePath);
System.out.println(fileName);
if (value.equals("")) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述", null);
parentRev.add("JD2_CSBGHZ", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
String fileType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
fileType = "excel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
fileType = "excel";
} else if (filePath.endsWith(".ppt")) {
msType = "MSPowerPoint";
fileType = "powerpoint";
} else if (filePath.endsWith(".pptx")) {
msType = "MSPowerPointX";
fileType = "powerpoint";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { fileType });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
} catch (TCException e1) {
e1.printStackTrace();
}
} else {
// 添加到数据集
boolean exist = false;
try {
TCComponent[] tcc = itemR.getTCProperty("JD2_CSBGHZ").getReferenceValueArray();
for (int i = 0; i < tcc.length; i++) {
if (value.equals(tcc[i].getProperty("current_id"))) {
exist = true;
TCComponentItem item = (TCComponentItem) tcc[i];
TCComponent[] tccitem = item.getLatestItemRevision().getTCProperty("IMAN_specification")
.getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.setFiles(new String[] { file.getPath() }, new String[] { "excel" });
dataset.setProperty("object_name", filename);
item.setProperty("object_name", filename);
item.getLatestItemRevision().setProperty("object_name", filename);
}
}
if (!exist) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session
.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述",
null);
parentRev.add("JD2_CSBGHZ", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
} catch (TCException e1) {
e1.printStackTrace();
}
}
} catch (TCException e1) {
e1.printStackTrace();
}
}
}
});
againButton.addActionListener(e -> {
String[] temp = new String[16];
int num = Integer.valueOf((String) model.getValueAt(table.getSelectedRow(), 0)) + 1;
// temp[0] = String.valueOf(num);
temp[1] = (String) model.getValueAt(table.getSelectedRow(), 1);
temp[2] = (String) model.getValueAt(table.getSelectedRow(), 2);
temp[3] = (String) model.getValueAt(table.getSelectedRow(), 3);
temp[4] = (String) model.getValueAt(table.getSelectedRow(), 4);
temp[5] = (String) model.getValueAt(table.getSelectedRow(), 5);
temp[6] = (String) model.getValueAt(table.getSelectedRow(), 6);
temp[7] = (String) model.getValueAt(table.getSelectedRow(), 7);
String chishu = (String) model.getValueAt(table.getSelectedRow(), 14);
if ("".equals(chishu)) {
chishu = "0";
System.out.println(chishu);
}
if (chishu == null) {
chishu = "0";
}
int cishuNum = Integer.valueOf(chishu);
boolean isNotLatest = false;
Object obj;
String xm;
int num1;
if (!againAllow) {
MessageBox.post("当前操作的版本不是最新发布版本的下一个未发布版本,不允许再次试验", "提示", MessageBox.WARNING);
return;
}
for (int i = 0; i < table.getRowCount(); i++) {
xm = (obj = table.getValueAt(i, 4)) == null ? "" : obj.toString();
if (temp[4].equals(xm)) {
num1 = Integer.parseInt((obj = table.getValueAt(i, 14)) == null ? "0" : obj.toString());
if (cishuNum < num1) {
isNotLatest = true;
break;
}
}
}
if (isNotLatest) {
MessageBox.post("请选择最新的一次实验", "提示", MessageBox.WARNING);
return;
}
// boolean allowFlag = false;
// if (againAllowFlow == null) {
// try {
// againAllowFlow = JDMethodUtil.getPrefStrArray("jd_csjh_again_allow", session)[1];// 部件
// TCComponent[] comps = form.getRelatedComponents("fnd0AllWorkflows");
// if (comps.length > 0) {
// String flowName;
// for (TCComponent comp : comps) {
// flowName = comps[0].getProperty("object_name");
// System.out.println(flowName);
// if (flowName.equals(againAllowFlow)) {
// allowFlag = true;
// break;
// }
// }
// } else {
// MessageBox.post("无法再次试验,请确认当前目标处于流程中", "提示", MessageBox.WARNING);
// return;
// }
// } catch (ArrayIndexOutOfBoundsException ex) {
// // TODO: handle exception
// ex.printStackTrace();
// MessageBox.post("首选项\"jd_csjh_again_allow\"配置错误", "错误", MessageBox.ERROR);
// return;
// } catch (TCException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
// }
// if (!allowFlag) {
// MessageBox.post("无法再次试验,目标所处流程状态不满足\"jd_csjh_again_allow\"配置", "提示", MessageBox.WARNING);
// return;
// }
temp[14] = String.valueOf(cishuNum + 1);
// temp[16] = (String) model.getValueAt(table.getSelectedRow(), 16);
temp[15] = (String) model.getValueAt(table.getSelectedRow(), 15);
model.insertRow(table.getSelectedRow() + 1, temp);
for (int i = table.getSelectedRow() + 1; i < model.getRowCount(); i++) {
model.setValueAt(String.valueOf(num++), i, 0);
}
for (int i = model.getRowCount(); i > table.getSelectedRow(); i--) {
rowNo.put(i, rowNo.get(i - 1));
}
Double allcost2 = 0.0;
for (int i = 0; i < model.getRowCount(); i++) {
String value = (String) model.getValueAt(i, 7);
if (value.equals(""))
value = "0";
allcost2 += Double.valueOf(value);
}
label2.setText(allcost2 + "元");
editable.add(table.getSelectedRow());
for (int i = 0; i < editable.size(); i++) {
if (editable.get(i) >= (table.getSelectedRow() + 1)) {
editable.set(i, editable.get(i) + 1);
}
}
for (Entry<String, JG> entry : res.entrySet()) {
if (entry.getValue().getRow() >= (table.getSelectedRow() + 1)) {
res.get(entry.getKey()).setRow(entry.getValue().getRow() + 1);
}
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (table.getSelectedColumn() == 16) {
if (e.getClickCount() == 2) {
System.out.println("双击了");
int selectedRow = table.getSelectedRow(); // 获得选中行索引
String value = (String) model.getValueAt(selectedRow, 16);
if (value == null)
value = "";
if (!value.equals("")) {
try {
TCComponent[] result = session.search("零组件 ID", new String[] { "零组件 ID" },
new String[] { value });
TCComponentItem item = (TCComponentItem) result[0];
TCComponent[] tccitem = item.getLatestItemRevision().getTCProperty("IMAN_specification")
.getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.open();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
}
});
}
@Override
public void saveRendering() {
try {
List<TCComponent> c = new ArrayList<TCComponent>();
if (table.getSelectedColumn() >= 0) {
table.getColumnModel().getColumn(table.getSelectedColumn()).getCellEditor().stopCellEditing();
}
// TCComponent[] com = form.getTCProperty("sf6_EplanBOMLineTable").getReferenceValueArray();
// for (int j = 0; j < com.length; j++) {
// c.add(com[j]);
// }
DataManagementService service = DataManagementService
.getService((TCSession) AIFUtility.getCurrentApplication().getSession());
CreateIn[] newIn = new CreateIn[model.getRowCount()];
for (int i = 0; i < model.getRowCount(); i++) {
CreateIn in = new CreateIn();
Map<String, String> propMap = new HashMap<String, String>();
propMap.put("jd2_no", rowNo.get(i));
for (int j = 0; j < propNames.length; j++) {
propMap.put(propNames[j],
model.getValueAt(i, j + 1) == null ? "" : model.getValueAt(i, j + 1).toString());
}
// System.out.println("prop:" + propMap);
in.data.boName = "JD2_CSJHTABLE";
in.data.stringProps = propMap;
newIn[i] = in;
}
try {
CreateResponse response = service.createObjects(newIn);
System.out.println(response.serviceData.sizeOfCreatedObjects());
if (response.serviceData.sizeOfCreatedObjects() > 0) {
// System.out.println("创建CreateResponse");
int length = response.serviceData.sizeOfCreatedObjects();
for (int i = 0; i < length; i++) {
c.add(response.output[i].objects[0]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
form.getTCProperty("jd2_csjh").setReferenceValueArray(c.toArray(new TCComponent[c.size()]));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean isRenderingModified() {
// TODO Auto-generated method stub
return form.isCheckedOut();
}
}

@ -0,0 +1,351 @@
package com.connor.jd.plm.form;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import com.connor.jd.plm.table.CTMap;
import com.connor.jd.plm.table.CTable;
import com.connor.jd.plm.table.MyCellEditor4;
import com.connor.jd.plm.table.TCTableUtil;
import com.connor.jd.plm.utils.DBUtil;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
public class ComponentTestFrame extends JFrame {
private CTMap model;
private CTable table;
private int bottom;
private Container container;
private TCComponentForm form;
private TCSession session;
private MyCallBack callBack;
private String itemId;
private String[] colNames = new String[] { "jd2_no", "jd2_wtry", "jd2_syxm", "jd2_syzq", "jd2_syts", "jd2_syfy",
"jd2_sycs" };
private TCComponentForm testForm;
public ComponentTestFrame(Object itemId, TCComponentForm form, MyCallBack callBack) {
this.itemId = StrUtil.toString(itemId);
this.callBack = callBack;
this.form = form;
this.session = (TCSession) AIFUtility.getCurrentApplication().getSession();
this.init();
}
private void init() {
this.setTitle("部件测试项目");
this.setSize(560, 400);
this.setResizable(true);
this.setAlwaysOnTop(true);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
container = this.getContentPane();
container.setLayout(new BorderLayout());
container.setPreferredSize(new Dimension(600, 400));
model = new CTMap(10, 7);
model.setValueAt("编号", 0, 0);
model.setValueAt("部品类型", 0, 1);
model.setValueAt("试验项目", 0, 2);
model.setValueAt("试验时间", 0, 3);
model.setValueAt("样品数量", 0, 4);
model.setValueAt("试验费用", 0, 5);
model.setValueAt("是否选择", 0, 6);
table = new CTable(model) {
@Override
public boolean isCellEditable(int row, int col) {
if (row == 0 || col == 0) {
return false;
}
return true;
}
};
table.setRowHeight(25);
table.setBorder(BorderFactory.createLineBorder(Color.black));
for (int i = 0; i < model.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setPreferredWidth(80);
}
DefaultTableCellRenderer tcr1 = new DefaultTableCellRenderer() {
// 重写方法
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
// TODO Auto-generated method stub
if (value instanceof JCheckBox) {
return (JCheckBox) value;
}
int maxPreferredHeight = 0;
for (int i = 0; i < table.getColumnCount(); i++) {
setText("" + table.getValueAt(row, i));
setSize(table.getColumnModel().getColumn(column).getWidth(), 0);
maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height);
}
setBackground(Color.white);
// if(points1.contains(new Point(row,column)))
// setForeground(new Color(0,0,255));
// else
setForeground(Color.black);
if (isSelected) {
setBackground(new Color(0, 120, 215));
setForeground(Color.white);
}
if (table.getRowHeight(row) != maxPreferredHeight) // 少了这行则处理器瞎忙
table.setRowHeight(row, maxPreferredHeight);
setText(value == null ? "" : value.toString());
return this;
}
};
tcr1.setHorizontalAlignment(SwingConstants.CENTER);
table.setDefaultRenderer(Object.class, tcr1);
table.getColumnModel().getColumn(6).setCellEditor(new MyCellEditor4(new JTextField()));
// 填写数据
Map<String, String[]> dataMap = new LinkedHashMap<>();
try {
List<Entity> list = Db.use(DBUtil.getDataSource(session)).findAll("JD2_COMPONENT");
for (int i = 0; i < list.size(); i++) {
String[] rowData = new String[6];
rowData[0] = list.get(i).getStr("TEST_ID");
rowData[1] = list.get(i).getStr("TEST_TYPE");
rowData[2] = list.get(i).getStr("TEST_PROJECT");
rowData[3] = list.get(i).getStr("TEST_TIME");
rowData[4] = list.get(i).getInt("TEST_NUM") + "";
rowData[5] = list.get(i).getInt("TEST_COST") == null ? "0" : list.get(i).getInt("TEST_COST") + "";
dataMap.put(rowData[0], rowData);
}
} catch (Exception e) {
// TODO Auto-generated catch block
MessageBox.post("数据库配置错误", "错误", MessageBox.ERROR);
e.printStackTrace();
return;
}
List<String> checkedId = new ArrayList<>();
if (StrUtil.isNotBlank(itemId)) {
try {
TCComponent[] res = session.search("Item ID", new String[] { "零组件 ID" }, new String[] { itemId });
if (ArrayUtil.isNotEmpty(res) && "JD2_GTCSJH".equals(res[0].getType())) {
TCComponentItemRevision resRev = ((TCComponentItem) res[0]).getLatestItemRevision();
TCComponent[] forms = resRev.getRelatedComponents("IMAN_master_form_rev");
testForm = (TCComponentForm) forms[0];
String[][] rowDatas = TCTableUtil.getTableRows(testForm, "jd2_csjh", colNames);
for (int i = 0; i < rowDatas.length; i++) {
checkedId.add(rowDatas[i][0]);
String[] rowData = new String[6];
rowData[0] = rowDatas[i][0];
rowData[1] = "自定义测试项";
rowData[2] = rowDatas[i][2];
rowData[3] = rowDatas[i][3];
rowData[4] = rowDatas[i][4];
rowData[5] = rowDatas[i][5];
dataMap.put(rowDatas[i][0], rowData);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
bottom = dataMap.size();
int row = 1;
for (Entry<String, String[]> entry : dataMap.entrySet()) {
if (row > model.getRowCount() - 1) {
model.addRow();
}
model.setValueAt(entry.getValue()[0], row, 0);
model.setValueAt(entry.getValue()[1], row, 1);
model.setValueAt(entry.getValue()[2], row, 2);
model.setValueAt(entry.getValue()[3], row, 3);
model.setValueAt(entry.getValue()[4], row, 4);
model.setValueAt(entry.getValue()[5], row, 5);
if (checkedId.contains(entry.getValue()[0])) {
JCheckBox tempCheck = new JCheckBox();
tempCheck.setSelected(true);
model.setValueAt(tempCheck, row, 6);
} else {
model.setValueAt(new JCheckBox(), row, 6);
}
row++;
}
// 按钮
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton createTest = new JButton("创建/更新测试计划");
createTest.addActionListener(createTest());
JButton addTestItem = new JButton("新增测试项");
addTestItem.addActionListener(addTestItem());
JButton cancel = new JButton("取消");
cancel.addActionListener(cancel());
buttonPanel.add(createTest);
buttonPanel.add(addTestItem);
buttonPanel.add(cancel);
ScrollPane scrollPane = new ScrollPane();
scrollPane.add(table);
container.add(scrollPane, BorderLayout.CENTER);
container.add(buttonPanel, BorderLayout.SOUTH);
this.setVisible(true);
}
private ActionListener createTest() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
if (testForm != null) {// 更新
String[] propNames = new String[] { "jd2_no", "jd2_syxh", "jd2_symd", "jd2_wtry", "jd2_syxm",
"jd2_syts", "jd2_syzq", "jd2_syfy", "jd2_jhrc", "jd2_jhrc1", "jd2_sjrc", "jd2_sjrc1",
"jd2_syzt", "jd2_syjg", "jd2_sycs", "jd2_syry", "jd2_csbg", "jd2_bz" };
List<Map<String, String>> oldRowData = TCTableUtil.getTableMapList(testForm, "jd2_csjh",
propNames);
List<String> selectedNo = new ArrayList<>();
for (int i = 1; i <= bottom; i++) {
JCheckBox jb = (JCheckBox) model.getValueAt(i, 6);
if (jb.isSelected()) {
String no = model.getValueAt(i, 0).toString();
selectedNo.add(no);
boolean isInclude = false;
for (int ii = 0; ii < oldRowData.size(); ii++) {// 修改
if (no.equals(oldRowData.get(ii).get("jd2_no"))) {
isInclude = true;
oldRowData.get(ii).put("jd2_syxm", model.getValueAt(i, 2).toString());
oldRowData.get(ii).put("jd2_syzq", model.getValueAt(i, 3).toString());
oldRowData.get(ii).put("jd2_syts", model.getValueAt(i, 4).toString());
oldRowData.get(ii).put("jd2_syfy", model.getValueAt(i, 5).toString());
}
}
if (!isInclude) {// 新增
Map<String, String> tempMap = new HashMap<String, String>();
tempMap.put("jd2_no", no);
tempMap.put("jd2_wtry", form.getTCProperty("owning_user").getUIFValue());
tempMap.put("jd2_syxm", model.getValueAt(i, 2).toString());
tempMap.put("jd2_syzq", model.getValueAt(i, 3).toString());
tempMap.put("jd2_syts", model.getValueAt(i, 4).toString());
tempMap.put("jd2_syfy", model.getValueAt(i, 5).toString());
oldRowData.add(tempMap);
}
}
}
for (int i = 0; i < oldRowData.size(); i++) {// 删除
if (!selectedNo.contains(oldRowData.get(i).get("jd2_no"))) {
oldRowData.remove(i);
i--;
}
}
TCTableUtil.setTableMapList(testForm, "jd2_csjh", "JD2_CSJHTABLE", oldRowData);
callBack.execute(itemId);
} else {// 创建
TCComponentItemRevision rev = (TCComponentItemRevision) form.whereReferenced()[0]
.getComponent();
TCComponentItemType type = (TCComponentItemType) session.getTypeComponent("Item");
TCComponentItem item = type.create(null, null, "JD2_GTCSJH", "测试计划", "", null);
rev.add("JD2_CSJH", item);
TCComponentItemRevision rev1 = item.getLatestItemRevision();
TCComponentForm form1 = (TCComponentForm) rev1.getRelatedComponents("IMAN_master_form_rev")[0];
List<String[]> list = new ArrayList<String[]>();
String[] row = new String[7];
for (int i = 1; i <= bottom; i++) {
JCheckBox jb = (JCheckBox) model.getValueAt(i, 6);
if (jb.isSelected()) {
for (int ii = 2; ii < 6; ii++) {
row[ii - 2] = model.getValueAt(i, ii) == null ? ""
: model.getValueAt(i, ii).toString();
}
// TCComponentPerson p = (TCComponentPerson) session.getUser().getUserInformation().get(0);
list.add(new String[] { model.getValueAt(i, 0).toString(),
form.getTCProperty("owning_user").getUIFValue(), row[0], row[1], row[2], row[3],
"1" });
}
}
String[][] data = list.toArray(new String[list.size()][7]);
TCTableUtil.setTableRows(form1, "jd2_csjh", "JD2_CSJHTABLE", colNames, data);
callBack.execute(item.getProperty("item_id"));
}
dispose();
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
};
}
private ActionListener addTestItem() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (bottom > model.getRowCount() - 2) {
model.addRow();
}
int num = Math.max(Integer.parseInt(model.getValueAt(bottom, 0).toString()), 10000);
model.setValueAt(num + 1, ++bottom, 0);
model.setValueAt(new JCheckBox(), bottom, 6);
}
};
}
@Override
public void dispose() {
// TODO Auto-generated method stub
container.removeAll();
super.dispose();
}
private ActionListener cancel() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
dispose();
}
};
}
}

@ -0,0 +1,583 @@
package com.connor.jd.plm.form;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.BorderFactory;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import com.connor.jd.plm.table.CTMap;
import com.connor.jd.plm.table.CTable;
import com.connor.jd.plm.table.JCheckPanel;
import com.connor.jd.plm.table.MyCellEditor3;
import com.connor.jd.plm.table.TCTableUtil;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.stylesheet.AbstractRendering;
public class ExperimentalPowerOfAttorneyForm extends AbstractRendering implements MyCallBack {
private TCComponentForm form;
private CTMap model;
private CTable table;
private int top = 10;
private int end = 1;
private int bottom;
private CTMap model2;
private CTable table2;
private Map<String, String> prop;
private List<String> disableEdit;
private List<String> disableEdit2;
private Map<String, int[]> general;
private Map<String, int[]> general2;
private JCheckPanel bgqf;
private JPopupMenu menu = new JPopupMenu();
private JMenuItem addR;
private JMenuItem delR;
private JMenuItem test;
private String[] colNames = new String[] { "jd2_no", "jd2_name", "jd2_bgq", "jd2_bgh", "jd2_risk", "jd2_csjh",
"jd2_bz" };
private String[][] rows;
private ExperimentalPowerOfAttorneyForm $this;
public ExperimentalPowerOfAttorneyForm(TCComponent arg0) throws Exception {
super(arg0);
if (arg0 instanceof TCComponentForm) {
this.form = (TCComponentForm) arg0;
TCSession session = arg0.getSession();
loadRendering();
}
}
@Override
public void loadRendering() throws TCException {
$this = this;
this.setLayout(new BorderLayout());
JPanel root = new JPanel(new BorderLayout());
root.setPreferredSize(new Dimension(800, 500));
// 内容
prop = form.getProperties();
model = new CTMap(20, 11);
bottom = model.getRowCount() - end;
model2 = new CTMap(3, 11);
initModel();
table = new CTable(model) {
@Override
public boolean isCellEditable(int row, int col) {
if (isEditorDisable(disableEdit, row, col)) {
return false;
}
return true;
}
};
table.setRowHeight(25);
table.setBorder(BorderFactory.createLineBorder(Color.black));
table.getColumnModel().getColumn(0).setPreferredWidth(40);
table.getColumnModel().getColumn(1).setPreferredWidth(100);
table.getColumnModel().getColumn(2).setPreferredWidth(80);
table.getColumnModel().getColumn(3).setPreferredWidth(80);
table.getColumnModel().getColumn(4).setPreferredWidth(80);
table.getColumnModel().getColumn(5).setPreferredWidth(80);
table.getColumnModel().getColumn(6).setPreferredWidth(80);
table.getColumnModel().getColumn(7).setPreferredWidth(80);
table.getColumnModel().getColumn(8).setPreferredWidth(80);
table.getColumnModel().getColumn(9).setPreferredWidth(150);
table.getColumnModel().getColumn(10).setPreferredWidth(60);
table.putClientProperty("terminateEditOnFocusLost", true);
DefaultTableCellRenderer tcr1 = new DefaultTableCellRenderer() {
// 重写方法
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
// TODO Auto-generated method stub
if (value instanceof JPanel) {
return (JPanel) value;
}
int maxPreferredHeight = 0;
for (int i = 0; i < table.getColumnCount(); i++) {
setText("" + table.getValueAt(row, i));
setSize(table.getColumnModel().getColumn(column).getWidth(), 0);
maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height);
}
setBackground(Color.white);
// if(points1.contains(new Point(row,column)))
// setForeground(new Color(0,0,255));
// else
setForeground(Color.black);
if (isSelected) {
setBackground(new Color(0, 120, 215));
setForeground(Color.white);
}
if (table.getRowHeight(row) != maxPreferredHeight) // 少了这行则处理器瞎忙
table.setRowHeight(row, maxPreferredHeight);
setText(value == null ? "" : value.toString());
return this;
}
};
tcr1.setHorizontalAlignment(SwingConstants.CENTER);
table.setAutoResizeMode(CTable.AUTO_RESIZE_NEXT_COLUMN);
table.setDefaultRenderer(Object.class, tcr1);
table.getColumnModel().getColumn(2).setCellEditor(new MyCellEditor3(new JTextField()));
table.addMouseListener(rightClick());
initModel2();
table2 = new CTable(model2) {
@Override
public boolean isCellEditable(int row, int col) {
if (isEditorDisable(disableEdit2, row, col)) {
return false;
}
return true;
}
};
table2.setRowHeight(25);
table2.setBorder(BorderFactory.createLineBorder(Color.black));
table2.getColumnModel().getColumn(0).setPreferredWidth(40);
table2.getColumnModel().getColumn(1).setPreferredWidth(100);
table2.getColumnModel().getColumn(2).setPreferredWidth(80);
table2.getColumnModel().getColumn(3).setPreferredWidth(80);
table2.getColumnModel().getColumn(4).setPreferredWidth(80);
table2.getColumnModel().getColumn(5).setPreferredWidth(80);
table2.getColumnModel().getColumn(6).setPreferredWidth(80);
table2.getColumnModel().getColumn(7).setPreferredWidth(80);
table2.getColumnModel().getColumn(8).setPreferredWidth(80);
table2.getColumnModel().getColumn(9).setPreferredWidth(150);
table2.getColumnModel().getColumn(10).setPreferredWidth(60);
table2.putClientProperty("terminateEditOnFocusLost", true);
DefaultTableCellRenderer tcr2 = new DefaultTableCellRenderer() {
// 重写方法
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
// TODO Auto-generated method stub
if (value instanceof JPanel) {
return (JPanel) value;
}
int maxPreferredHeight = 0;
for (int i = 0; i < table.getColumnCount(); i++) {
setText("" + table.getValueAt(row, i));
setSize(table.getColumnModel().getColumn(column).getWidth(), 0);
maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height);
}
setBackground(Color.white);
// if(points1.contains(new Point(row,column)))
// setForeground(new Color(0,0,255));
// else
setForeground(Color.black);
if (isSelected) {
setBackground(new Color(0, 120, 215));
setForeground(Color.white);
}
if (table.getRowHeight(row) != maxPreferredHeight) // 少了这行则处理器瞎忙
table.setRowHeight(row, maxPreferredHeight);
setText(value == null ? "" : value.toString());
return this;
}
};
tcr2.setHorizontalAlignment(SwingConstants.CENTER);
table2.setAutoResizeMode(CTable.AUTO_RESIZE_NEXT_COLUMN);
table2.setDefaultRenderer(Object.class, tcr2);
// 右键菜单
menu.setVisible(false);
addR = new JMenuItem("新增行");
addR.setEnabled(false);
menu.add(addR);
addR.addActionListener(addRow());
delR = new JMenuItem("删除行");
delR.setEnabled(false);
menu.add(delR);
delR.addActionListener(delRow());
test = new JMenuItem("测试项");
test.setEnabled(false);
menu.add(test);
test.addActionListener(test());
// 填写数据
for (Entry<String, int[]> entry : general.entrySet()) {
if (prop.containsKey(entry.getKey())) {
model.setValueAt(prop.get(entry.getKey()), entry.getValue()[0], entry.getValue()[1]);
} else {
System.out.println("未找到属性 " + entry.getKey());
}
}
for (Entry<String, int[]> entry : general2.entrySet()) {
if (prop.containsKey(entry.getKey())) {
model2.setValueAt(prop.get(entry.getKey()), entry.getValue()[0], entry.getValue()[1]);
} else {
System.out.println("未找到属性 " + entry.getKey());
}
}
if (prop.containsKey("jd2_bgqf")) {
bgqf.setSelected(prop.get("jd2_bgqf"));
} else {
System.out.println("未找到属性 jd2_bgqf");
}
rows = TCTableUtil.getTableRows(form, "jd2_sywts", colNames);
for (int i = 0; i < rows.length; i++) {
if (top + i + 1 > bottom) {
this.addRow();
}
for (int ii = 0; ii < rows[0].length; ii++) {
model.setValueAt(rows[i][ii], top + i + 1, ii > 2 ? ii > 3 ? ii + 4 : ii + 2 : ii);
}
}
// 属性映射
try {
AIFComponentContext[] refs = form.whereReferenced();
for (AIFComponentContext aif : refs) {
if (aif.getComponent().getType().equals("JD2_GTSYWTSRevision")) {
model.setValueAt(aif.getComponent().getProperty("item_id"), 0, 9);
}
}
model.setValueAt(form.getProperty("creation_date"), 1, 9);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JPanel inner = new JPanel(new BorderLayout());
inner.add(table, BorderLayout.CENTER);
inner.add(table2, BorderLayout.SOUTH);
JScrollPane jsp = new JScrollPane(inner);
root.add(jsp, BorderLayout.CENTER);
this.add(menu);
this.add(root);
}
private void initModel() {
disableEdit = new ArrayList<>();// 不允许编辑
general = new HashMap<String, int[]>();// 要填写的一般属性
model.setValueAt("吉德", 0, 0);
disableEdit.add("0,0");
model.setValueAt("试验委托书", 0, 3);
disableEdit.add("0,3");
model.setValueAt("表号", 0, 8);
disableEdit.add("0,8");
model.setValueAt("生效期", 1, 8);
disableEdit.add("1,8");
general.put("jd2_bh", new int[] { 0, 9 });
general.put("jd2_sxr", new int[] { 1, 9 });
model.setValueAt("委托项目:", 3, 0);
disableEdit.add("3,0");
model.setValueAt("委托部门:", 4, 0);
disableEdit.add("4,0");
general.put("jd2_wtxm", new int[] { 3, 3 });
general.put("jd2_wtbm", new int[] { 4, 3 });
model.setValueAt("供货厂家:", 3, 6);
disableEdit.add("3,6");
model.setValueAt("接受部门:", 4, 6);
disableEdit.add("4,6");
general.put("jd2_ghcj", new int[] { 3, 8 });
general.put("jd2_jsbm", new int[] { 4, 8 });
model.setValueAt("变更区分:", 5, 0);
bgqf = new JCheckPanel(new String[] { "复制模", "降本", "二元化", "改善优化", "新规部品" });
model.setValueAt(bgqf, 5, 2);
model.setValueAt("部品型号:", 7, 0);
disableEdit.add("7,0");
general.put("jd2_bpxh", new int[] { 7, 2 });
model.setValueAt("适用型号:", 7, 6);
disableEdit.add("7,6");
general.put("jd2_syxh", new int[] { 7, 7 });
model.setValueAt("变更内容", 8, 0);
disableEdit.add("8,0");
model.setValueAt("NO", top, 0);
disableEdit.add(top + ",0");
model.setValueAt("名称", top, 1);
disableEdit.add(top + ",1");
model.setValueAt("变更前", top, 2);
disableEdit.add(top + ",2");
model.setValueAt("变更后", top, 5);
disableEdit.add(top + ",5");
model.setValueAt("Risk", top, 8);
disableEdit.add(top + ",8");
model.setValueAt("测试计划", top, 9);
disableEdit.add(top + ",9");
model.setValueAt("备注", top, 10);
disableEdit.add(top + ",10");
model.combine(new int[] { 0, 1, 2 }, new int[] { 0, 1, 2 });
model.combine(new int[] { 0, 1, 2 }, new int[] { 3, 4, 5, 6, 7 });
model.combine(new int[] { 0 }, new int[] { 9, 10 });
model.combine(new int[] { 1 }, new int[] { 9, 10 });
model.combine(new int[] { 2 }, new int[] { 8, 9, 10 });
model.combine(new int[] { 3 }, new int[] { 0, 1, 2 });
model.combine(new int[] { 3 }, new int[] { 3, 4, 5 });
model.combine(new int[] { 3 }, new int[] { 6, 7 });
model.combine(new int[] { 3 }, new int[] { 8, 9, 10 });
model.combine(new int[] { 4 }, new int[] { 0, 1, 2 });
model.combine(new int[] { 4 }, new int[] { 3, 4, 5 });
model.combine(new int[] { 4 }, new int[] { 6, 7 });
model.combine(new int[] { 4 }, new int[] { 8, 9, 10 });
model.combine(new int[] { 5 }, new int[] { 0, 1 });
model.combine(new int[] { 5 }, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
model.combine(new int[] { 6 }, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
model.combine(new int[] { 7 }, new int[] { 0, 1 });
model.combine(new int[] { 7 }, new int[] { 2, 3, 4, 5 });
model.combine(new int[] { 7 }, new int[] { 7, 8, 9, 10 });
model.combine(new int[] { 8, 9 }, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
model.combine(new int[] { top }, new int[] { 2, 3, 4 });
model.combine(new int[] { top }, new int[] { 5, 6, 7 });
for (int i = top + 1; i <= bottom; i++) {
model.combine(new int[] { i }, new int[] { 2, 3, 4 });
model.combine(new int[] { i }, new int[] { 5, 6, 7 });
model.setValueAt(i - top, i, 0);
disableEdit.add(i + ",0");
}
}
private void initModel2() {
disableEdit2 = new ArrayList<String>();
general2 = new HashMap<String, int[]>();
model2.setValueAt("预计完成日期:", 0, 0);
disableEdit2.add("0,0");
general2.put("jd2_yjwcrq", new int[] { 0, 2 });
model2.setValueAt("编制签名:", 1, 0);
disableEdit2.add("1,0");
model2.setValueAt("批准签名:", 2, 0);
disableEdit2.add("2,0");
general2.put("jd2_bz", new int[] { 1, 2 });
general2.put("jd2_pz", new int[] { 2, 2 });
model2.setValueAt("编制时间:", 1, 5);
disableEdit2.add("1,5");
model2.setValueAt("批准时间:", 2, 5);
disableEdit2.add("2,5");
general2.put("jd2_bzrq", new int[] { 1, 8 });
general2.put("jd2_pzrq", new int[] { 2, 8 });
model2.combine(new int[] { 0 }, new int[] { 0, 1 });
model2.combine(new int[] { 0 }, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
model2.combine(new int[] { 1 }, new int[] { 0, 1 });
model2.combine(new int[] { 1 }, new int[] { 2, 3, 4 });
model2.combine(new int[] { 1 }, new int[] { 5, 6, 7 });
model2.combine(new int[] { 1 }, new int[] { 8, 9, 10 });
model2.combine(new int[] { 2 }, new int[] { 0, 1 });
model2.combine(new int[] { 2 }, new int[] { 2, 3, 4 });
model2.combine(new int[] { 2 }, new int[] { 5, 6, 7 });
model2.combine(new int[] { 2 }, new int[] { 8, 9, 10 });
}
@Override
public void saveRendering() {
// TODO Auto-generated method stub
for (Entry<String, int[]> entry : general.entrySet()) {
if (prop.containsKey(entry.getKey())) {
String value = model.getValueAt(entry.getValue()[0], entry.getValue()[1]).toString();
try {
if (form.getTCProperty(entry.getKey()).getLOV() != null && !"".equals(value)) {
value = (String) form.getTCProperty(entry.getKey()).getLOV().getListOfValues()
.getRealValue(value);
}
System.out.println(entry.getKey() + ":" + value);
form.setProperty(entry.getKey(), value);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
for (Entry<String, int[]> entry : general2.entrySet()) {
if (prop.containsKey(entry.getKey())) {
String value = model2.getValueAt(entry.getValue()[0], entry.getValue()[1]).toString();
try {
if (form.getTCProperty(entry.getKey()).getLOV() != null && !"".equals(value)) {
value = (String) form.getTCProperty(entry.getKey()).getLOV().getListOfValues()
.getRealValue(value);
}
System.out.println(entry.getKey() + ":" + value);
form.setProperty(entry.getKey(), value);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
if (prop.containsKey("jd2_bgqf")) {
String value = bgqf.getSelectedText() == null ? "" : bgqf.getSelectedText();
try {
if (form.getTCProperty("jd2_bgqf").getLOV() != null && !"".equals(value)) {
value = (String) form.getTCProperty("jd2_bgqf").getLOV().getListOfValues().getRealValue(value);
}
System.out.println("jd2_bgqf:" + value);
form.setProperty("jd2_bgqf", value);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (prop.containsKey("jd2_sywts")) {
List<String[]> data = new ArrayList<String[]>();
int num = 0;
while (true) {
boolean isNotEmpty = false;
String[] row = new String[7];
for (int ii = 0; ii < row.length; ii++) {
Object object = model.getValueAt(top + 1 + num, ii > 2 ? ii > 3 ? ii + 4 : ii + 2 : ii);
row[ii] = object == null ? "" : object.toString();
if (!isNotEmpty && ii > 0 && ii < 4) {
isNotEmpty = !"".equals(row[ii]);
}
}
if (!isNotEmpty) {
break;
}
data.add(row);
num++;
if (top + 1 + num > bottom) {
break;
}
}
String[][] dataArr = data.toArray(new String[data.size()][]);
System.out.println(Arrays.deepToString(dataArr));
TCTableUtil.setTableRows(form, "jd2_sywts", "JD2_SYWTS", colNames, dataArr);
}
try {
form.refresh();
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private boolean isEditorDisable(List<String> list, int row, int col) {
return list.contains(row + "," + col);
}
private MouseAdapter rightClick() {
return new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3 && form.isCheckedOut() && table.getSelectedRow() != -1) {
int row = table.getSelectedRow();
boolean flag = (row > top && row <= bottom);
addR.setEnabled(flag);
delR.setEnabled(flag);
test.setEnabled(flag);
menu.show(e.getComponent(), e.getX(), e.getY());
}
}
};
}
private ActionListener addRow() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int num = Integer.parseInt(model.getValueAt(bottom, 0).toString());
model.insertRow(++bottom);
// model.setValueAt(num + 1, bottom, 0);
// model.combine(new int[] { bottom }, new int[] { 2, 3, 4 });
// model.combine(new int[] { bottom }, new int[] { 5, 6, 7 });
System.out.println(bottom);
initModel();
table.revalidate();
table.repaint();
}
};
}
private ActionListener delRow() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int row = table.getSelectedRow();
int num = Integer.parseInt(model.getValueAt(row, 0).toString());
model.removeRow(row);
bottom--;
// if (row <= bottom) {
// for (int i = row; i <= bottom; i++) {
// model.setValueAt(num + i - row, i, 0);
// }
// }
System.out.println(bottom);
initModel();
table.revalidate();
table.repaint();
}
};
}
private ActionListener test() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
new ComponentTestFrame(model.getValueAt(table.getSelectedRow(), 9), form, $this);
}
}).start();
}
};
}
@Override
public void execute(String itemId) {
// TODO Auto-generated method stub
int row = table.getSelectedRow();
System.out.println(itemId + " " + row);
model.setValueAt(itemId, row, 9);
table.revalidate();
table.repaint();
}
@Override
public boolean isRenderingModified() {
return form.isCheckedOut();
}
}

@ -0,0 +1,810 @@
package com.connor.jd.plm.form;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import com.connor.jd.plm.beans.JG;
import com.connor.jd.plm.table.DatePickerCellEditor;
import com.connor.jd.plm.table.TCTableUtil;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentDatasetType;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.stylesheet.AbstractRendering;
import com.teamcenter.rac.util.MessageBox;
public class GTCSJHForm extends AbstractRendering {
private TCComponentForm form;
private Map<String, String> parentProp;
private String[] labelNames = { "项目信息:", "立项时间:", "基本型号:", "测试型号:", "产品型号:", "项目资料:", "产品经理:", "产品变更点:", "品质经理:",
"开发日程:", "开发等级:", "开发阶段:" };
private String[] labellTexts = { "jd2_xmxx", "jd2_lxsj", "jd2_jbxh", "jd2_csxh", "jd2_cpxh", "jd2_xmzl", "jd2_cpjl",
"jd2_cpbgd", "jd2_pzjl", "jd2_kfrc", "jd2_kfdj", "jd2_kfjd" };
private String[] colNames = { "jd2_no", "jd2_syxh", "jd2_symd", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syzq",
"jd2_syfy", "jd2_jhrc", "jd2_jhrc1", "jd2_sjrc", "jd2_sjrc1", "jd2_syzt", "jd2_syjg", "jd2_sycs",
"jd2_syry", "jd2_csbg", "jd2_bz" };
private String[] colDisplayNames = new String[] { "realNo", "NO", "试验型号", "试验目的", "委托人员", "试验项目", "试验台数", "试验周期",
"试验费用", "计划开始日程", "计划完成日程", "实际开始日程", "实际完成日程", "试验状态", "实验结果", "第_次试验", "实验人员", "测试报告", "备注" };
private List<Integer> disableRows = new ArrayList<Integer>();
private List<Integer> disableColumns = Arrays.asList(4, 5, 6, 8, 15, 17);// 委托人员, 试验项目, 试验台数,第_次试验,测试报告
private Map<String, JG> resultMap = new HashMap<String, JG>();
private JTable table;
private DefaultTableModel model;
private TCComponentItemRevision rev;
private TCSession session;
private JLabel cost;
private JLabel jg;
private boolean againAllow = false;
public GTCSJHForm(TCComponent arg0) throws Exception {
super(arg0);
if (arg0 instanceof TCComponentForm) {
this.form = (TCComponentForm) arg0;
this.session = (TCSession) AIFUtility.getCurrentApplication().getSession();
loadRendering();
}
}
@Override
public void loadRendering() throws TCException {
AIFComponentContext[] contexts = form.whereReferenced();
for (int i = 0; i < contexts.length; i++) {
if (contexts[i].getComponent() instanceof TCComponentItemRevision) {
try {
rev = (TCComponentItemRevision) contexts[i].getComponent();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
// TODO Auto-generated method stub
this.setLayout(new BorderLayout());
JPanel root = new JPanel(new BorderLayout());
JPanel top = new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel inner = new JPanel();
JPanel innerTop = new JPanel();
JPanel innerCenter = new JPanel(new BorderLayout());
root.setPreferredSize(new Dimension(1000, 500));
inner.setLayout(null);
inner.setPreferredSize(new Dimension(1000, 420));
innerTop.setLayout(null);
innerTop.setPreferredSize(new Dimension(1000, 100));
innerTop.setBorder(BorderFactory.createLineBorder(Color.black));
innerTop.setBounds(10, 0, 1000, 100);
innerCenter.setPreferredSize(new Dimension(880, 300));
innerCenter.setBorder(BorderFactory.createLineBorder(Color.black));
innerCenter.setBounds(10, 120, 880, 300);
JLabel title = new JLabel();
AIFComponentContext[] aif = form.whereReferenced();
for (AIFComponentContext a : aif) {
if ("JD2_GTXPXMCSJHRevision".equals(a.getComponent().getType())) {
try {
title.setText(a.getComponent().getProperty("object_name"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
title.setFont(new Font("宋体", Font.PLAIN, 24));
top.add(title);
JLabel[] infoText = new JLabel[13];
JLabel[] infoValue = new JLabel[12];
infoText[0] = new JLabel("基本信息:");
infoText[0].setBounds(10, 0, 80, 25);
for (int i = 1; i < 13; i++) {
infoText[i] = new JLabel(labelNames[i - 1]);
// infoValue[i - 1] = new JLabel(labellTexts[i - 1]);
infoValue[i - 1] = new JLabel();
}
for (int i = 1; i < 7; i++) {
infoText[i].setBounds(25 + 162 * (i - 1), 30, 80, 25);
infoValue[i - 1].setBounds(105 + 162 * (i - 1), 30, 80, 25);
infoText[i + 6].setBounds(25 + 162 * (i - 1), 60, 80, 25);
infoValue[i + 5].setBounds(105 + 162 * (i - 1), 60, 80, 25);
}
innerTop.add(infoText[0]);
for (int i = 0; i < 12; i++) {
innerTop.add(infoText[i + 1]);
innerTop.add(infoValue[i]);
}
model = new DefaultTableModel(colDisplayNames, 0) {
@Override
public boolean isCellEditable(int paramInt1, int paramInt2) {
// TODO Auto-generated method stub
if (disableRows.contains(paramInt1) || disableColumns.contains(paramInt2)) {
return false;
}
return true;
}
};
JComboBox<String> status = new JComboBox<String>();
status.addItem("待测");
status.addItem("进行中");
status.addItem("完成");
status.addItem(" ");
DefaultCellEditor dce1 = new DefaultCellEditor(status) {
int row;
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
int column) {
this.row = row;
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
@Override
public Object getCellEditorValue() {
Object obj = super.getCellEditorValue();
if ("完成".equals(obj == null ? "" : obj.toString())) {
// disableRows.add(row);
}
return obj;
}
};
JComboBox<String> result = new JComboBox<String>();
result.addItem("合格");
result.addItem("不合格");
result.addItem(" ");
DefaultCellEditor dce2 = new DefaultCellEditor(result) {
JTable table;
int row;
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
int column) {
this.table = table;
this.row = row;
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
@Override
public Object getCellEditorValue() {
Object obj = super.getCellEditorValue();
String res = (obj == null ? "" : obj.toString());
String no = table.getValueAt(row, 0).toString();
Object temp;
int times = Integer.parseInt((temp = table.getValueAt(row, 15)) == null ? "0" : temp.toString().trim());
System.out.println("结果:" + res);
addResult(no, row, times, res);
jg.setText(getResult());
return obj;
}
};
DatePickerCellEditor dpce = new DatePickerCellEditor(new JTextField());
table = new JTable(model);
for (int i = 1; i < table.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setMinWidth(100);
}
hiddenColumn(table, 0);
DefaultCellEditor deafult = new DefaultCellEditor(new JTextField());
for (int i = 0; i < table.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setCellEditor(deafult);
}
table.getColumnModel().getColumn(9).setCellEditor(dpce);
table.getColumnModel().getColumn(10).setCellEditor(dpce);
table.getColumnModel().getColumn(11).setCellEditor(dpce);
table.getColumnModel().getColumn(12).setCellEditor(dpce);
table.getColumnModel().getColumn(13).setCellEditor(dce1);
table.getColumnModel().getColumn(14).setCellEditor(dce2);
table.setRowHeight(25);
table.setAutoscrolls(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getTableHeader().setReorderingAllowed(false);
// table.putClientProperty("terminateEditOnFocusLost", true);// 表格失去焦点自动提交(事件控件today会有问题)
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (table.getSelectedColumn() == 17) {
if (e.getClickCount() == 2) {
System.out.println("双击了");
int selectedRow = table.getSelectedRow(); // 获得选中行索引
String value = (String) model.getValueAt(selectedRow, 17);
if (value == null)
value = "";
if (!value.equals("")) {
try {
TCComponent[] result = session.search("零组件 ID", new String[] { "零组件 ID" },
new String[] { value });
TCComponentItem item = (TCComponentItem) result[0];
TCComponent[] tccitem = item.getLatestItemRevision().getTCProperty("IMAN_specification")
.getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.open();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
}
});
JScrollPane jsp = new JScrollPane(table);
innerCenter.add(jsp, BorderLayout.CENTER);
JButton test = new JButton("<html>测试报告<br>上传</html>");
JButton collect = new JButton("<html>汇总结论<br>上传</html>");
JButton again = new JButton("再次试验");
test.setBounds(900, 120, 100, 50);
collect.setBounds(900, 175, 100, 50);
again.setBounds(900, 230, 100, 25);
test.addActionListener(test());
collect.addActionListener(collect());
again.addActionListener(again());
inner.add(test);
inner.add(collect);
inner.add(again);
JLabel label1 = new JLabel("试验费用总计:");
JLabel label2 = new JLabel("结论:");
cost = new JLabel();
jg = new JLabel();
label1.setBounds(300, 470, 120, 25);
cost.setBounds(420, 470, 50, 25);
label2.setBounds(480, 470, 50, 25);
jg.setBounds(530, 470, 60, 25);
root.add(label1);
root.add(label2);
root.add(cost);
root.add(jg);
// 获取信息
AIFComponentContext[] aifs = form.whereReferenced();
String temp;
for (AIFComponentContext a1 : aifs) {
System.out.println("测试结论版本:" + (temp = a1.getComponent().getType()));
if ("JD2_GTXPXMCSJHRevision".equals(temp)) {
TCComponentItemRevision rev = (TCComponentItemRevision) a1.getComponent();
AIFComponentContext[] aifs2 = rev.getItem().whereReferenced();
for (AIFComponentContext a2 : aifs2) {
System.out.println("新品测试项目清单版本:" + (temp = a2.getComponent().getType()));
if ("JD2_GTXPCSXQDRevision".equals(temp)) {
TCComponentItemRevision rev2 = (TCComponentItemRevision) a2.getComponent();
TCComponentForm parent = (TCComponentForm) rev2.getRelatedComponents("IMAN_master_form_rev")[0];
parentProp = parent.getProperties();
}
}
}
}
if (parentProp != null) {
for (int i = 0; i < labellTexts.length; i++) {
if (parentProp.containsKey(labellTexts[i])) {
String str = parentProp.get(labellTexts[i]);
infoValue[i].setText(str);
infoValue[i].setToolTipText(str);
} else {
System.out.println("属性\"" + labellTexts[i] + "\"不存在");
}
}
}
String[][] data = TCTableUtil.getTableRows(form, "jd2_csjhtable", colNames);
System.out.println(data[0].length);
System.out.println(colNames.length);
System.out.println(Arrays.deepToString(data));
System.out.println(data.length);
double sum = 0;
for (int i = 0; i < data.length; i++) {
String[] rowData = new String[19];
rowData[0] = data[i][0];
rowData[1] = i + 1 + "";
for (int ii = 1; ii < colNames.length; ii++) {
rowData[ii + 1] = data[i][ii];
}
model.addRow(rowData);
if ("完成".equals(data[i][12])) {
// disableRows.add(i);
}
sum += Double.parseDouble(data[i][7]);
addResult(data[i][0], i, Integer.parseInt(data[i][14]), data[i][13]);
}
// 最新发布
TCComponentItem item = rev.getItem();
TCComponentItemRevision[] revs = item.getReleasedItemRevisions();
Comparator<TCComponent> leatestRevisionComparator = new Comparator<TCComponent>() {
@Override
public int compare(TCComponent o1, TCComponent o2) {
// TODO Auto-generated method stub
try {
return o1.getProperty("item_revision_id").compareTo(o2.getProperty("item_revision_id"));
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
};
Arrays.parallelSort(revs, leatestRevisionComparator);
if (revs.length > 0) {
List<Map<String, String>> dataMap = TCTableUtil.getTableMapList(
(TCComponentForm) revs[revs.length - 1].getRelatedComponent("IMAN_master_form_rev"),
"jd2_csjhtable", colNames);
List<String> realNoList = new ArrayList<String>();
for (Map<String, String> tempMap : dataMap) {
realNoList.add(tempMap.get("jd2_no") + "," + tempMap.get("jd2_sycs"));
}
for (int i = 0; i < data.length; i++) {
if (realNoList.contains(data[i][0] + "," + data[i][14])) {
disableRows.add(i);
}
}
}
// 目前版本是否为最新发布的下一个版本
List<String> releasedObjectString = new ArrayList<String>();
for (int i = 0; i < revs.length; i++) {
releasedObjectString.add(revs[i].getProperty("object_string"));
}
if (revs.length > 0) {
if (!releasedObjectString.contains(rev.getProperty("object_string"))) {
TCComponent[] allRev = item.getRelatedComponents("revision_list");
Arrays.parallelSort(allRev, leatestRevisionComparator);
for (int i = 0; i < allRev.length; i++) {
if (allRev[i].getProperty("object_string")
.equals(revs[revs.length - 1].getProperty("object_string")) && i + 1 < allRev.length) {
if (rev.getProperty("object_string").equals(allRev[i + 1].getProperty("object_string"))) {
againAllow = true;
break;
}
}
}
}
}
table.revalidate();
table.repaint();
cost.setText(sum + "");
jg.setText(getResult());
inner.add(innerTop);
inner.add(innerCenter);
root.add(top, BorderLayout.NORTH);
root.add(inner, BorderLayout.CENTER);
JScrollPane jsp1 = new JScrollPane(root);
this.add(jsp1, BorderLayout.CENTER);
}
@Override
public void saveRendering() {
// TODO Auto-generated method stub
if (table.getSelectedColumn() >= 0) {
table.getColumnModel().getColumn(table.getSelectedColumn()).getCellEditor().stopCellEditing();
}
String[][] data = new String[0][];
List<String[]> dataList = new ArrayList<String[]>();
Object obj;
for (int i = 0; i < table.getRowCount(); i++) {
String[] rowData = new String[colNames.length];
for (int ii = 0; ii < colNames.length; ii++) {
rowData[ii] = (obj = table.getValueAt(i, ii > 0 ? ii + 1 : ii)) == null ? "" : obj.toString();
}
dataList.add(rowData);
}
data = dataList.toArray(new String[dataList.size()][]);
TCTableUtil.setTableRows(form, "jd2_csjhtable", "JD2_CSJHTABLE", colNames, data);
}
private ActionListener test() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("选择上传的测试报告");
FileFilter filter = new FileNameExtensionFilter("Excel工作簿(.xlsx,.xls,.xlsm)", "xlsx", "xls", "xlsm");
chooser.setFileFilter(filter);
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
if (file != null) {
String filePath = file.getPath();
String fileName = file.getName();
String filename = fileName.substring(0, fileName.lastIndexOf("."));
System.out.println(filePath);
System.out.println(fileName);
int row = table.getSelectedRow();
String value = model.getValueAt(row, 17) == null ? "" : model.getValueAt(row, 17).toString();
if (value.equals("")) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述", null);
rev.add("JD2_CSBG", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
model.setValueAt(item.getProperty("current_id"), row, 17);
} catch (TCException e1) {
e1.printStackTrace();
}
} else {
// 添加到数据集
boolean exist = false;
try {
TCComponent[] tcc = rev.getTCProperty("JD2_CSBG").getReferenceValueArray();
for (int i = 0; i < tcc.length; i++) {
if (value.equals(tcc[i].getProperty("current_id"))) {
exist = true;
TCComponentItem item = (TCComponentItem) tcc[i];
TCComponent[] tccitem = item.getLatestItemRevision()
.getTCProperty("IMAN_specification").getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.setFiles(new String[] { file.getPath() }, new String[] { "excel" });
dataset.setProperty("object_name", filename);
item.setProperty("object_name", filename);
item.getLatestItemRevision().setProperty("object_name", filename);
}
}
if (!exist) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session
.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName,
"描述", null);
rev.add("JD2_CSBG", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
model.setValueAt(item.getProperty("current_id"), row, 17);
} catch (TCException e1) {
e1.printStackTrace();
}
}
} catch (TCException e1) {
e1.printStackTrace();
}
}
}
}
};
}
private ActionListener collect() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
// int row = table.getSelectedRow();
// String value = (String) model.getValueAt(row, 17);
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("选择上传的汇总结论");
FileFilter filter = new FileNameExtensionFilter("Excel工作簿(.xlsx,.xls,.xlsm),PPT演示文稿(.ppt,.pptx)",
"xlsx", "xls", "xlsm", "ppt", "pptx");// 设置文件过滤器只列出JPG或GIF格式的图片
chooser.setFileFilter(filter);
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
TCComponentItemRevision parentRev = null;
try {
AIFComponentContext[] aifs = rev.getItem().whereReferenced();
for (AIFComponentContext aif : aifs) {
if (aif.getComponent().getType().equals("JD2_GTXPCSXQDRevision")) {
parentRev = (TCComponentItemRevision) aif.getComponent();
break;
}
}
} catch (TCException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
if (file != null && parentRev != null) {
String filePath = file.getPath();
String fileName = file.getName();
String filename = fileName.substring(0, fileName.lastIndexOf("."));
System.out.println(filePath);
System.out.println(fileName);
// if (value.equals("")) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述", null);
parentRev.add("JD2_CSBGHZ", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
String fileType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
fileType = "excel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
fileType = "excel";
} else if (filePath.endsWith(".ppt")) {
msType = "MSPowerPoint";
fileType = "powerpoint";
} else if (filePath.endsWith(".pptx")) {
msType = "MSPowerPointX";
fileType = "powerpoint";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { fileType });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
MessageBox.post("上传成功", "提示", MessageBox.WARNING);
} catch (TCException e1) {
e1.printStackTrace();
}
// } else {
// // 添加到数据集
// boolean exist = false;
// try {
// TCComponent[] tcc = rev.getTCProperty("JD2_CSBGHZ").getReferenceValueArray();
// for (int i = 0; i < tcc.length; i++) {
// if (value.equals(tcc[i].getProperty("current_id"))) {
// exist = true;
// TCComponentItem item = (TCComponentItem) tcc[i];
// TCComponent[] tccitem = item.getLatestItemRevision()
// .getTCProperty("IMAN_specification").getReferenceValueArray();
// TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
// dataset.setFiles(new String[] { file.getPath() }, new String[] { "excel" });
// dataset.setProperty("object_name", filename);
// item.setProperty("object_name", filename);
// item.getLatestItemRevision().setProperty("object_name", filename);
// }
// }
// if (!exist) {
// try {
// TCComponentItemType itemtype = (TCComponentItemType) session
// .getTypeComponent("JD2_GTCSBG");
// String itemId = itemtype.getNewID();
// String itemRev = itemtype.getNewRev(null);
// TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName,
// "描述", null);
// parentRev.add("JD2_CSBGHZ", item);
// TCComponentDatasetType datasetType = (TCComponentDatasetType) session
// .getTypeComponent("Dataset");
// String msType = "";
// if (filePath.endsWith(".xls")) {
// msType = "MSExcel";
// } else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
// msType = "MSExcelX";
// }
// TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
// datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
// item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
// } catch (TCException e1) {
// e1.printStackTrace();
// }
// }
// } catch (TCException e1) {
// e1.printStackTrace();
// }
//
// }
}
}
};
}
private ActionListener again() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int row = table.getSelectedRow();
Object obj;
if (row != -1) {
if (!againAllow) {
MessageBox.post("当前操作的版本不是最新发布版本的下一个未发布版本,不允许再次试验", "提示", MessageBox.WARNING);
return;
}
String realNum = (obj = table.getValueAt(row, 0)) == null ? "0" : obj.toString();
int num = Integer.parseInt((obj = table.getValueAt(row, 1)) == null ? "0" : obj.toString());
String[] rowData = new String[table.getColumnCount()];
rowData[0] = realNum;
rowData[1] = num + 1 + "";
num = Integer.parseInt((obj = table.getValueAt(row, 15)) == null ? "0" : obj.toString());
boolean isNotLatest = false;
String realNum1;
int num1;
for (int i = 0; i < table.getRowCount(); i++) {
realNum1 = (obj = table.getValueAt(i, 0)) == null ? "0" : obj.toString();
if (realNum.equals(realNum1)) {
num1 = Integer.parseInt((obj = table.getValueAt(i, 15)) == null ? "0" : obj.toString());
if (num < num1) {
isNotLatest = true;
break;
}
}
}
if (isNotLatest) {
MessageBox.post("请选择最新的一次实验", "提示", MessageBox.WARNING);
return;
}
// boolean allowFlag = false;
// if (againAllowFlow == null) {
// try {
// againAllowFlow = JDMethodUtil.getPrefStrArray("jd_csjh_again_allow", session)[0];// 整机
// TCComponent[] comps = form.getRelatedComponents("fnd0AllWorkflows");
// if (comps.length > 0) {
// String flowName;
// for (TCComponent comp : comps) {
// flowName = comps[0].getProperty("object_name");
// System.out.println(flowName);
// if (flowName.equals(againAllowFlow)) {
// allowFlag = true;
// break;
// }
// }
// } else {
// MessageBox.post("无法再次试验,请确认当前目标处于流程中", "提示", MessageBox.WARNING);
// return;
// }
// } catch (ArrayIndexOutOfBoundsException ex) {
// // TODO: handle exception
// ex.printStackTrace();
// MessageBox.post("首选项\"jd_csjh_again_allow\"配置错误", "错误", MessageBox.ERROR);
// return;
// } catch (TCException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
// }
// if (!allowFlag) {
// MessageBox.post("无法再次试验,目标所处流程状态不满足\"jd_csjh_again_allow\"配置", "提示", MessageBox.WARNING);
// return;
// }
for (int i = 2; i < 9; i++) {
rowData[i] = (obj = table.getValueAt(row, i)) == null ? "" : obj.toString();
}
rowData[15] = num + 1 + "";
rowData[16] = (obj = table.getValueAt(row, 16)) == null ? "" : obj.toString();
disableRows.add(row);
model.insertRow(row + 1, rowData);
for (int i = 0; i < disableRows.size(); i++) {
if (disableRows.get(i) >= (row + 1)) {
disableRows.set(i, disableRows.get(i) + 1);
}
}
for (Entry<String, JG> entry : resultMap.entrySet()) {
if (entry.getValue().getRow() >= (row + 1)) {
resultMap.get(entry.getKey()).setRow(entry.getValue().getRow() + 1);
}
}
table.revalidate();
table.repaint();
cost.setText(getCost() + "");
}
}
};
}
private void hiddenColumn(JTable table, int columnIndex) {
TableColumnModel tcm = table.getColumnModel();
TableColumn tc = tcm.getColumn(columnIndex);
// tc.setResizable(false);
tc.setWidth(0);
tc.setPreferredWidth(0);
tc.setMaxWidth(0);
tc.setMinWidth(0);
table.getTableHeader().getColumnModel().getColumn(columnIndex).setMaxWidth(0);
table.getTableHeader().getColumnModel().getColumn(columnIndex).setMinWidth(0);
}
private double getCost() {
double sum = 0;
Object obj;
for (int i = 0; i < table.getRowCount(); i++) {
double num = Double.parseDouble((obj = table.getValueAt(i, 8)) == null ? "0" : obj.toString());
sum += num;
}
return sum;
}
private void addResult(String realNo, int row, int times, String result) {
if (resultMap.containsKey(realNo)) {
if (times >= resultMap.get(realNo).getTimes()) {
if (table.getSelectedRow() < 0) {
disableRows.add(resultMap.get(realNo).getRow());// 初始化时禁止填写次数小的
}
resultMap.put(realNo, new JG(row, times, result));
}
} else {
resultMap.put(realNo, new JG(row, times, result));
}
}
private String getResult() {
boolean notEmpty = false;
boolean qualified = true;
for (Entry<String, JG> entry : resultMap.entrySet()) {
// System.out.println("realNo:" + entry.getKey() + "row:" + entry.getValue().getRow() + "jg:"
// + entry.getValue().getJg() + "times:" + entry.getValue().getTimes());
if (!"".equals(entry.getValue().getJg().trim())) {
notEmpty = true;
}
if ("不合格".equals(entry.getValue().getJg())) {
qualified = false;
break;
}
}
return notEmpty ? (qualified ? "合格" : "不合格") : "";
}
@Override
public boolean isRenderingModified() {
// TODO Auto-generated method stub
return form.isCheckedOut();
}
}

@ -0,0 +1,6 @@
package com.connor.jd.plm.form;
public interface MyCallBack {
public void execute(String itemId);
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,79 @@
package com.connor.jd.plm.form;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class PhotoFrame extends JFrame {
private static final long serialVersionUID = -2216276219179107707L;
private Container con;
private ZPanel zPanel;
private JScrollPane imgSp;
private static PhotoFrame instance;
public static PhotoFrame getInstance(String imgPath) {
if (instance == null) {
instance = new PhotoFrame(imgPath);
} else {
instance.zPanel.setImagePath(imgPath);
instance.setVisible(true);
instance.zPanel.setPreferredSize(
new Dimension(instance.zPanel.getImgWidth(),
instance.zPanel.getImgHeight()));
}
return instance;
}
private PhotoFrame(String imgPath) {
init(imgPath);
finalSetting();
}
private void init(String imgPath) {
con = getContentPane();
zPanel = new ZPanel();
zPanel.setImagePath(imgPath);
zPanel.setPreferredSize(
new Dimension(zPanel.getImgWidth(), zPanel.getImgHeight()));
imgSp = new JScrollPane();
imgSp.setViewportView(zPanel);
imgSp.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
imgSp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
con.add(imgSp, BorderLayout.CENTER);
}
private void finalSetting() {
setTitle("Ô¤ÀÀ");
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
int frameH = getHeight();
int frameW = getWidth();
setLocation((screenWidth - frameW) / 2 - 250,
(screenHeight - frameH) / 2 - 250);
setSize(screenWidth / 2, screenHeight / 2);
setVisible(true);
setResizable(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
@Override
public void dispose() {
// TODO Auto-generated method stub
super.dispose();
System.out.println("Ô¤ÀÀ¹Ø±Õ");
zPanel.clear();
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,79 @@
package com.connor.jd.plm.form;
import java.awt.Graphics;
import java.awt.Image;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ZPanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
private Image image;
private int imgWidth;
private int imgHeight;
private FileInputStream input;
public int getImgWidth() {
return imgWidth;
}
public void setImgWidth(int imgWidth) {
this.imgWidth = imgWidth;
}
public int getImgHeight() {
return imgHeight;
}
public void setImgHeight(int imgHeight) {
this.imgHeight = imgHeight;
}
public ZPanel() {
}
public void setImagePath(String imgPath) {
// 该方法不推荐使用,该方法是懒加载,图像并不加载到内存,当拿图像的宽和高时会返回-1
// image = Toolkit.getDefaultToolkit().getImage(imgPath);
try {
// 该方法会将图像加载到内存,从而拿到图像的详细信息。
input = new FileInputStream(imgPath);
image = ImageIO.read(input);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
setImgWidth(image.getWidth(this));
setImgHeight(image.getHeight(this));
}
@Override
public void paintComponent(Graphics g1) {
int x = 0;
int y = 0;
Graphics g = g1;
if (null == image) {
return;
}
g.drawImage(image, x, y, image.getWidth(this), image.getHeight(this),
this);
g = null;
}
public void clear() {
if (input != null) {
try {
image = null;
input.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

@ -0,0 +1,22 @@
package com.connor.jd.plm.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.jd.plm.action.AddHLBOMAction;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
public class AddHLBOMHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
// TODO Auto-generated method stub
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
AddHLBOMAction action = new AddHLBOMAction(app, "");
new Thread(action).start();
return null;
}
}

@ -0,0 +1,22 @@
package com.connor.jd.plm.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.jd.plm.action.BOMManagementAction;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
public class BOMManagementHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
// TODO Auto-generated method stub
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
BOMManagementAction action = new BOMManagementAction(app, "");
new Thread(action).start();
return null;
}
}

@ -0,0 +1,21 @@
package com.connor.jd.plm.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.jd.plm.action.BatchReviseAction;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
public class BatchReviseHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
// TODO Auto-generated method stub
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
new Thread(new BatchReviseAction(app, "")).start();
return null;
}
}

@ -0,0 +1,64 @@
package com.connor.jd.plm.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.jd.plm.dialogs.CSXWHDialog;
import com.connor.jd.plm.utils.JDMethodUtil;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.stage.Stage;
public class CSXWHHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
String[] userIdList = JDMethodUtil.getPrefStrArray("JD2_CSXWH", session);
Boolean tag = true;
try {
System.out.println("当前用户id" + session.getUser().getUserId());
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
for (int i = 0; i < userIdList.length; i++) {
try {
if (session.getUser().getUserId().equals(userIdList[i])) {
tag = false;
new Thread(() -> {
new JFXPanel();
Platform.setImplicitExit(false);
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
CSXWHDialog csxwh = new CSXWHDialog();
csxwh.start(new Stage());
} catch (Exception e) {
e.printStackTrace();
}
}
});
}).start();
}
} catch (TCException e) {
e.printStackTrace();
}
}
if (tag) {
MessageBox.post("没有开启权限,请联系管理员", "提示", MessageBox.INFORMATION);
}
return null;
}
}

@ -0,0 +1,316 @@
package com.connor.jd.plm.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
//import com.connor.jk.plm.report.SqlUtil;
import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.aifrcp.SelectionHelper;
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.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.TCTypeService;
import com.teamcenter.rac.services.ISessionService;
import com.teamcenter.rac.ui.commands.Messages;
import com.teamcenter.rac.ui.commands.RACUICommandsActivator;
import com.teamcenter.rac.ui.commands.create.bo.NewBOModel;
import com.teamcenter.rac.ui.commands.create.bo.NewBOWizard;
import com.teamcenter.rac.util.OSGIUtil;
import com.teamcenter.rac.util.SWTUIUtilities;
import com.teamcenter.rac.util.UIUtilities;
import com.teamcenter.rac.util.wizard.extension.BaseExternalWizardDialog;
import com.teamcenter.rac.util.wizard.extension.WizardExtensionHelper;
public class CreateItemHandler extends AbstractHandler implements IExecutableExtension {
private TCSession session;
private String name;
private AbstractAIFApplication app;
private String opType = "";
protected InterfaceAIFComponent selectedCmps[];
protected ISelection m_currentSelection;
protected String wizardId;
protected WizardDialog dialog;
TCComponentBOMWindow window = null;
// private static HashMap<String, String> map;
/**
* @deprecated Field session is deprecated
*/
@Deprecated
protected NewBOModel m_boModel;
@Override
public Object execute(ExecutionEvent executionevent) throws ExecutionException {
System.out.println("开始执行-----------");
app = AIFUtility.getCurrentApplication();
TCComponent comp = (TCComponent) app.getTargetComponent();
session = (TCSession) app.getSession();
// TCComponentUser user=session.getUser();
// try {
// TCComponent person=user.getReferenceProperty("person");
// System.out.println(person.getProperty("PA6"));
// if(person.getProperty("PA6").equals("")) {
// System.out.println("1");
// }else if(person.getProperty("PA6")==null) {
// System.out.println("2");
// }
// } catch (TCException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
//
//
// if(true) {
// return null;
// }
// 必须是folder其他的文件夹类型不能建
// if (comp instanceof TCComponentFolder) {
// System.out.println(comp.getType());
// if (comp.getType().equals("Hxc8XMWJJ")) {
// MessageBox.post("请选中文件夹再新建项目", "", MessageBox.INFORMATION);
// return null;
// }
// } else {
// MessageBox.post("请选中文件夹再新建项目", "", MessageBox.INFORMATION);
// return null;
//
// }
opType = executionevent.getCommand().getId();
if (executionevent == null)
throw new IllegalArgumentException("Event can't be null");
boolean flag = false;
if (executionevent.getParameters() != null && executionevent.getParameters().containsKey("selection")) {
Object obj = executionevent.getParameters().get("selection");
if (obj instanceof InterfaceAIFComponent[]) {
selectedCmps = (InterfaceAIFComponent[]) obj;
m_currentSelection = new StructuredSelection(selectedCmps);
flag = true;
}
}
if (!flag) {
m_currentSelection = HandlerUtil.getCurrentSelection(executionevent);
selectedCmps = SelectionHelper.getTargetComponents(m_currentSelection);
}
m_boModel = getBOModel();
launchWizard(executionevent);
return null;
}
/*
* private void createItem(TCComponent comp) { try {
*
* if (opType .equals("")) { TCComponentItemType itemType =
* (TCComponentItemType) session.getTypeComponent(opType); // create参数:
* ID TCComponentItem item = itemType.create(itemType.getNewID(),
* itemType.getNewRev(null), opType, name + "表", "", null);
*
* comp.add("contents", item); MessageBox.post(name + "表对象创建成功", "成功",
* MessageBox.INFORMATION); } } catch (TCException e) { // TODO Auto-generated
* catch block e.printStackTrace(); } }
*/
private class CreateNewBOSWTDialog implements Runnable {
@Override
public void run() {
NewBOWizard newbowizard = (NewBOWizard) getWizard();
if (newbowizard == null)
newbowizard = new NewBOWizard(wizardId);
newbowizard.setBOModel(m_boModel);
newbowizard.setWindowTitle(getWizardTitle());
newbowizard.setRevisionFlag(m_boModel.getRevisionFlag());
newbowizard.setDefaultType(m_type);
Shell shell = UIUtilities.getCurrentModalShell();
dialog = new BaseExternalWizardDialog(m_shell, newbowizard);
dialog.create();
newbowizard.retrievePersistedDialogSettings(dialog);
newbowizard.setWizardDialog(dialog);
UIUtilities.setCurrentModalShell(dialog.getShell());
dialog.open();
dialog = null;
// InterfaceAIFComponent[] compS = m_boModel.getTargetArray();
//
// if (compS != null && compS.length != 0) {
// System.out.println(" length =" + compS.length);
// if (compS[0] instanceof TCComponentItem) {
//
// System.out.println("ITEM");
// } else if (compS[0] instanceof TCComponentFolder) {
//
// System.out.println("FOLDER");
// }
// TCComponent compT = (TCComponent) compS[0];
// try {
// System.out.println("object_name =>" + compT.getStringProperty("object_name"));
// } catch (TCException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// } else {
// System.out.println(" null ");
// }
//
// System.out.println("=====>");
// List<AIFComponentContext> contextList = m_boModel.getCompContext();
// if (contextList != null) {
// for (AIFComponentContext context : contextList) {
// InterfaceAIFComponent comp = context.getComponent();
// try {
// System.out.println(">" + ((TCComponent) comp).getStringProperty("object_name"));
// } catch (TCException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// }
//
// }
// System.out.println("=====>");
// m_boModel = null;
//
// UIUtilities.setCurrentModalShell(shell);
//
// System.out.println("dialog ==> " + opType + " | " + m_type);
}
private final Shell m_shell;
private final String m_type;
final CreateItemHandler this$0;
private CreateNewBOSWTDialog(Shell shell, String s) {
super();
this$0 = CreateItemHandler.this;
m_shell = shell;
m_type = s;
}
CreateNewBOSWTDialog(Shell shell, String s, CreateNewBOSWTDialog createnewboswtdialog) {
this(shell, s);
}
}
@Override
public void setInitializationData(IConfigurationElement iconfigurationelement, String s, Object obj)
throws CoreException {
}
protected NewBOModel getBOModel() {
if (m_boModel == null)
m_boModel = new NewBOModel(this);
return m_boModel;
}
public Wizard getWizard() {
if (wizardId == null || wizardId.length() == 0)
wizardId = "com.teamcenter.rac.ui.commands.create.bo.NewBOWizard";
return WizardExtensionHelper.getWizard(wizardId);
}
public String getWizardTitle() {
return Messages.getString("wizard.TITLE");
}
public void launchWizard() {
launchWizard(null);
}
public void launchWizard(ExecutionEvent executionevent) {
String s = this.opType;
initWizardModel(executionevent);
// if (executionevent != null)
// s = (String) executionevent.getParameters().get("objectType");
AIFDesktop aifdesktop = AIFUtility.getActiveDesktop();
Shell shell = aifdesktop.getShell();
if (shell != null)
SWTUIUtilities.asyncExec(new CreateNewBOSWTDialog(shell, s, null));
System.out.println("999999999999999");
}
protected void initWizardModel(ExecutionEvent executionevent) {
boolean flag = false;
Object obj = null;
ISessionService isessionservice = (ISessionService) OSGIUtil.getService(RACUICommandsActivator.getDefault(),
com.teamcenter.rac.services.ISessionService.class);
try {
session = (TCSession) isessionservice.getSession(com.teamcenter.rac.kernel.TCSession.class.getName());
} catch (Exception _ex) {
session = (TCSession) AIFUtility.getDefaultSession();
}
m_boModel.setSession(session);
m_boModel.reInitializeTransientData();
m_boModel.setFrame(AIFUtility.getActiveDesktop());
if (executionevent != null) {
if (executionevent.getParameters().containsKey("revisionFlag"))
flag = ((Boolean) executionevent.getParameters().get("revisionFlag")).booleanValue();
if (executionevent.getParameters().containsKey("pasteRelation")) {
String s = (String) executionevent.getParameters().get("pasteRelation");
if (s != null) {
String as[] = null;
as = s.split(",");
m_boModel.setRelType(as[0]);
m_boModel.setPreAssignedRelType(as);
}
}
if (executionevent.getParameters().containsKey("parentComponents")) {
InterfaceAIFComponent ainterfaceaifcomponent[] = (InterfaceAIFComponent[]) executionevent
.getParameters().get("parentComponents");
m_boModel.setTargetArray(ainterfaceaifcomponent);
} else {
m_boModel.setTargetArray(selectedCmps);
}
} else {
m_boModel.setTargetArray(selectedCmps);
}
m_boModel.setRevisionFlag(flag);
AIFDesktop aifdesktop = AIFUtility.getActiveDesktop();
Shell shell = aifdesktop.getShell();
m_boModel.setShell(shell);
m_boModel.setCurrentSelection(m_currentSelection);
}
protected void readDisplayParameters(NewBOWizard newbowizard, WizardDialog wizarddialog) {
newbowizard.retrievePersistedDialogSettings(wizarddialog);
}
public TCComponentBOMLine getTopLineByRev(TCComponentItemRevision rev) {// 获得顶层bomline
TCComponentBOMLine line = null;
try {
TCTypeService service = session.getTypeService();
TCComponentBOMWindowType winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow");
window = winType.create(null);
line = window.setWindowTopLine(rev.getItem(), rev, null, null);
// window.close();//如果不关闭会导致BOM被占用乃至包含BOM的版本不能删除除非重启TC
} catch (TCException e) {
e.printStackTrace();
}
return line;
}
}

@ -0,0 +1,21 @@
package com.connor.jd.plm.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.jd.plm.action.DeleteItemRevisionAction;
import com.teamcenter.rac.aifrcp.AIFUtility;
public class DeleteItemRevisionHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
// TODO Auto-generated method stub
DeleteItemRevisionAction action = new DeleteItemRevisionAction(AIFUtility.getCurrentApplication(), "");
new Thread(action).start();
return null;
}
}

@ -0,0 +1,22 @@
package com.connor.jd.plm.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.jd.plm.action.EditClassificationAction;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
public class EditClassificationHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
// TODO Auto-generated method stub
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
EditClassificationAction action = new EditClassificationAction(app, "");
new Thread(action).start();
return null;
}
}

@ -0,0 +1,21 @@
package com.connor.jd.plm.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.jd.plm.action.ExportBOMAction;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
public class ExportBOMHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
ExportBOMAction action = new ExportBOMAction(app, "");
new Thread(action).start();
return null;
}
}

@ -0,0 +1,84 @@
package com.connor.jd.plm.handlers;
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.connor.jd.plm.dialogs.QTXJCDialog;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentProject;
import com.teamcenter.rac.kernel.TCComponentProjectSmartFolder;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.stage.Stage;
public class QTXJCHandler extends AbstractHandler {
private TCComponent[] com;
private String type = null;
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
List<String> sfList = new ArrayList<String>();
String name = arg0.getCommand().getId();
// System.out.println("name:" + name);
try {
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
if (app.getTargetComponent() != null && app.getTargetComponent() instanceof TCComponentProject) {
TCComponentProject project = (TCComponentProject) app.getTargetComponent();
com = project.getTCProperty("project_data").getReferenceValueArray();
for (int i = 0; i < com.length; i++) {
TCComponentProjectSmartFolder sf = (TCComponentProjectSmartFolder) com[i];
sfList.add(sf.getProperty("object_string"));
}
TCSession session = (TCSession) app.getSession();
switch (name) {
case "JD2_GTQTXJC":
type = "GT";
break;
case "JD2_BLQTXJC":
type = "BL";
break;
case "JD2_BXQTXJC":
type = "BX";
break;
default:
break;
}
new Thread(() -> {
new JFXPanel();
Platform.setImplicitExit(false);
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
// System.out.println("typeÄÚÈÝ" + type);
QTXJCDialog qtxjc = new QTXJCDialog(sfList, com, session, type);
qtxjc.start(new Stage());
} catch (Exception e) {
e.printStackTrace();
}
}
});
}).start();
} else {
MessageBox.post("ÇëÑ¡ÔñÏîÄ¿", "Ìáʾ", MessageBox.INFORMATION);
}
} catch (TCException e1) {
e1.printStackTrace();
}
return null;
}
}

@ -0,0 +1,148 @@
package com.connor.jd.plm.handlers;
import java.awt.BorderLayout;
import java.awt.Label;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.jd.plm.dialogs.TransformDesignToPartDialog;
import com.teamcenter.rac.aif.AbstractAIFApplication;
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.TCComponentBOMWindowType;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.TCTypeService;
import com.teamcenter.rac.util.ButtonLayout;
public class TransformDesignToPartHandler extends AbstractHandler {
private StringBuffer errorMsgSb;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
errorMsgSb=new StringBuffer();
System.out.println("111");
final AbstractAIFApplication app= AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();
final String[] types=session.getPreferenceService().getStringValues("connor_wl_type");
TCComponentItemRevision rev = (TCComponentItemRevision) app.getTargetComponent();
TCTypeService service = session.getTypeService();
TCComponentBOMWindowType bomwindow = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow");
TCComponentBOMWindow window = bomwindow.create(null);
final TCComponentBOMLine topBomline = window.setWindowTopLine(rev.getItem(), rev, null, null);
checkBomRef(topBomline,types);
checkBomLine(topBomline,types);
System.out.println("step:-2------------------");
if (!errorMsgSb.toString().equals("")) {
final JFrame sFrame = new JFrame("确认对话框");
sFrame.setSize(350, 200);
JLabel title = new JLabel(" 警 告 ");
JTextArea area = new JTextArea(4, 30);
area.setText("" + errorMsgSb.append("无关联物料,若不需关联则点确定,若需要关联则点退出!"));
area.setWrapStyleWord(true);
area.setLineWrap(true);
area.setEditable(false);
JButton okButton = new JButton("确定");
okButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
try {
sFrame.dispose();
new TransformDesignToPartDialog(app, topBomline,types);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
JButton celButton = new JButton("退出");
celButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
sFrame.dispose();
return;
}
});
JPanel panel = new JPanel(new BorderLayout());
panel.add(area, BorderLayout.CENTER);
panel.add(title, BorderLayout.NORTH);
JPanel buttonPanel = new JPanel(new ButtonLayout());
buttonPanel.add("1.1.left,top", okButton);
buttonPanel.add("1.2.left,top", new Label(" "));
buttonPanel.add("1.3.left,top", celButton);
JPanel rootPanel = new JPanel(new BorderLayout());
rootPanel.add(buttonPanel, BorderLayout.SOUTH);
rootPanel.add(panel, BorderLayout.CENTER);
sFrame.setLayout(new BorderLayout());
sFrame.add(rootPanel);
sFrame.setLocationRelativeTo(null);
sFrame.setVisible(true);
sFrame.setResizable(false);
} else {
new Thread(new TransformDesignToPartDialog(app, topBomline,types)).start();;
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/**
* bombom
* @param line
* @throws TCException
*/
public void checkBomLine(TCComponentBOMLine line,String[] types) throws TCException {
if (line == null) {
return;
}
AIFComponentContext[] children = line.getChildren();
for (int i = 0; i < children.length; i++) {
TCComponentBOMLine childLine = (TCComponentBOMLine) children[i].getComponent();
checkBomRef(childLine,types);
checkBomLine(childLine,types);
}
}
// 检查有没有关联物料
public void checkBomRef(TCComponentBOMLine line,String[] types) {
try {
if (line == null) {
return;
}
if (line.getItemRevision().isTypeOf("PartRevision")) {
//#物料 不操作
} else {
System.out.println("check");
AIFComponentContext[] aifContext = line.getItemRevision().whereReferencedByTypeRelation(
types, new String[] { "TC_Is_Represented_By" });
if (aifContext == null || aifContext.length == 0) {
this.errorMsgSb.append(line.getProperty("object_string") + ",");
}
}
} catch (
TCException e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,22 @@
package com.connor.jd.plm.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.jd.plm.action.WLTZReviseAction;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
public class WLTZReviseHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
// TODO Auto-generated method stub
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
WLTZReviseAction action = new WLTZReviseAction(app, "");
new Thread(action).start();
return null;
}
}

@ -0,0 +1,101 @@
package com.connor.jd.plm.handlers;
import java.text.MessageFormat;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.schedule.commands.newschedule.NewScheduleHandler;
import com.teamcenter.rac.schedule.plugin.Activator;
import com.teamcenter.rac.schedule.project.sharedUtils.TimeZoneCalUtil;
import com.teamcenter.rac.schedule.wizardpages.SchedulePageModel;
import com.teamcenter.rac.ui.commands.handlers.NewBOHandler;
import com.teamcenter.rac.util.Registry;
public class Wf001ScheduleHandler extends NewBOHandler {
private TCSession session;
public Wf001ScheduleHandler() {
}
public static SchedulePageModel getScheduleModel() {
if (scheduleModel == null)
scheduleModel = new SchedulePageModel();
return scheduleModel;
}
@Override
public Object execute(ExecutionEvent executionevent) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
session = (TCSession) app.getSession();
InterfaceAIFComponent targetComp = app.getTargetComponent();
if (targetComp == null) {
return null;
}
scheduleModel = null;
wizardId = "com.teamcenter.rac.schedule.commands.newschedule.GenericScheduleWizard";
TCSession tcsession = (TCSession) Activator.getDefault().getSessionService().getDefaultSession();
TCPreferenceService tcpreferenceservice = tcsession.getPreferenceService();
String s = tcpreferenceservice.getString(4, "SiteTimeZone", "null");
IWorkbench iworkbench = PlatformUI.getWorkbench();
IWorkbenchWindow iworkbenchwindow = iworkbench.getActiveWorkbenchWindow();
Shell shell = iworkbenchwindow.getShell();
if ("null".equals(s) || s == null) {
MessageDialog.openInformation(shell, textRegistry.getString("tzNotSet.TITLE"),
textRegistry.getString("tzNotSet.MSG"));
return Boolean.valueOf(false);
}
if (!TimeZoneCalUtil.testTimeZoneID(s)) {
String s1 = textRegistry.getString("tzInvalid.MSG");
s1 = MessageFormat.format(s1, new Object[] { s });
MessageDialog.openInformation(shell, textRegistry.getString("tzInvalid.TITLE"), s1);
return Boolean.valueOf(false);
} else {
return super.execute(executionevent);
}
//
// } else
//
// if (targetComp.getType().equals("TC_Project")) {
//
// CreateScheduleOperation operation = new CreateScheduleOperation(targetComp,session);
// session.queueOperation(operation);
//
// return null;
// } else {
// MessageBox.post("ÇëÑ¡ÖÐÏîĿִÐд´½¨!!", "´íÎó", MessageBox.ERROR);
// return null;
}
@Override
public String getWizardTitle() {
Registry registry = Registry.getRegistry(NewScheduleHandler.class);
return registry.getString("dialog.TITLE");
}
private static SchedulePageModel scheduleModel = null;
private final Registry textRegistry = Registry.getRegistry("com.teamcenter.rac.schedule.schedule");
}
/*
* DECOMPILATION REPORT
*
* Decompiled from:
* D:\Teamcenter_4Sh\OTW11\rac\plugins\com.teamcenter.rac.schedule_11000.2.0.jar
* Total time: 1083 ms Jad reported messages/errors: Exit status: 0 Caught
* exceptions:
*/

@ -0,0 +1,54 @@
package com.connor.jd.plm.table;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import com.teamcenter.rac.util.DateButton;
public class ButtonEditor extends DefaultCellEditor {
protected DateButton button;
private String label;
private boolean isPushed;
public ButtonEditor(JCheckBox checkBox) {
super(checkBox);
button = new DateButton();
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
if (isSelected) {
button.setForeground(table.getSelectionForeground());
button.setBackground(table.getSelectionBackground());
} else {
button.setForeground(table.getForeground());
button.setBackground(table.getBackground());
}
return button;
}
public Object getCellEditorValue() {
//yyyyÄêMMÔÂddÈÕ
SimpleDateFormat format=new SimpleDateFormat("yyyyÄêMMÔÂddÈÕ");
SimpleDateFormat format2=new SimpleDateFormat("MMÔÂ");
SimpleDateFormat format3=new SimpleDateFormat("ddÈÕ");
Date data = new Date();
System.out.println("aaa===>"+format2.format(data));
System.out.println("bbb===>"+format3.format(data));
System.out.println("ccc===>"+format.format(data));
return format.format(button.getDate());
}
}

@ -0,0 +1,48 @@
package com.connor.jd.plm.table;
import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import com.teamcenter.rac.util.DateButton;
public class ButtonEditor2 extends DefaultCellEditor {
protected DateButton button;
private String label;
private boolean isPushed;
public ButtonEditor2(JCheckBox checkBox) {
super(checkBox);
button = new DateButton();
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
if (isSelected) {
button.setForeground(table.getSelectionForeground());
button.setBackground(table.getSelectionBackground());
} else {
button.setForeground(table.getForeground());
button.setBackground(table.getBackground());
}
return button;
}
public Object getCellEditorValue() {
//yyyyÄêMMÔÂddÈÕ HH:mm
SimpleDateFormat format=new SimpleDateFormat("HH:mm");
Date data = new Date();
System.out.println("ccc===>"+format.format(data));
return format.format(button.getDate());
}
}

@ -0,0 +1,207 @@
package com.connor.jd.plm.table;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
public class CTMap extends DefaultTableModel implements CellSpan {
protected int rowSize;
protected int columnSize;
protected int[][][] span; // CellSpan
@Override
public int[] getSpan(int row, int column) {
// TODO Auto-generated method stub
if (isOutOfBounds(row, column)) {
int[] ret_code = { 1, 1 };
return ret_code;
}
return span[row][column];
}
@Override
public void setSpan(int[] span, int row, int column) {
// TODO Auto-generated method stub
if (isOutOfBounds(row, column))
return;
this.span[row][column] = span;
}
@Override
public boolean isVisible(int row, int column) {
// TODO Auto-generated method stub
if (isOutOfBounds(row, column))
return false;
if ((span[row][column][CellSpan.COLUMN] < 1) || (span[row][column][CellSpan.ROW] < 1))
return false;
return true;
}
@Override
public void combine(int[] rows, int[] columns) {
// TODO Auto-generated method stub
int rowSpan = rows.length;
int columnSpan = columns.length;
int startRow = rows[0];
int startColumn = columns[0];
for (int i = 0; i < rowSpan; i++) {
for (int j = 0; j < columnSpan; j++) {
if ((span[startRow + i][startColumn + j][CellSpan.COLUMN] != 1)
|| (span[startRow + i][startColumn + j][CellSpan.ROW] != 1)) {
// System.out.println("can't combine");
return;
}
}
}
for (int i = 0, ii = 0; i < rowSpan; i++, ii--) {
for (int j = 0, jj = 0; j < columnSpan; j++, jj--) {
span[startRow + i][startColumn + j][CellSpan.COLUMN] = jj;
span[startRow + i][startColumn + j][CellSpan.ROW] = ii;
// System.out.println("r " +ii +" c " +jj);
}
}
span[startRow][startColumn][CellSpan.COLUMN] = columnSpan;
span[startRow][startColumn][CellSpan.ROW] = rowSpan;
}
public void setSize(Dimension size) {
columnSize = size.width;
rowSize = size.height;
span = new int[rowSize][columnSize][2]; // 2: COLUMN,ROW
initValue();
}
protected boolean isOutOfBounds(int row, int column) {
if ((row < 0) || (rowSize <= row) || (column < 0) || (columnSize <= column)) {
return true;
}
return false;
}
public void addRow() {
Vector newData = new Vector(getColumnCount());
dataVector.add(newData);
//
newRowsAdded(new TableModelEvent(this, getRowCount() - 1, getRowCount() - 1, TableModelEvent.ALL_COLUMNS,
TableModelEvent.INSERT));
int[][][] oldSpan = span;
int numRows = oldSpan.length;
int numColumns = oldSpan[0].length;
span = new int[numRows + 1][numColumns][2];
System.arraycopy(oldSpan, 0, span, 0, numRows);
for (int i = 0; i < numColumns; i++) {
span[numRows][i][CellSpan.COLUMN] = 1;
span[numRows][i][CellSpan.ROW] = 1;
}
rowSize = span.length;
}
public void addColumn(Object columnName) {
int[][][] oldSpan = span;
int numRows = oldSpan.length;
int numColumns = oldSpan[0].length;
span = new int[numRows][numColumns + 1][2];
for (int i = 0; i < span.length; i++) {
for (int j = 0; j < span[0].length; j++) {
span[i][j][CellSpan.COLUMN] = 1;
span[i][j][CellSpan.ROW] = 1;
}
}
columnSize = span[0].length;
addColumn(columnName, (Vector) null);
}
public void insertRow(int row) {
Vector rowData = new Vector(getColumnCount());
dataVector.insertElementAt(rowData, row);
System.out.println("size:" + dataVector.size());
//
newRowsAdded(new TableModelEvent(this, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
int[][][] newSpan = new int[span.length + 1][span[0].length][2];
int numRows = span.length;
int numColumns = span[0].length;
for (int i = 0; i < newSpan.length; i++) {
if (i < row) {
for (int j = 0; j < numColumns; j++) {
newSpan[i][j][0] = span[i][j][0];
newSpan[i][j][1] = span[i][j][1];
}
} else if (i == row) {
for (int j = 0; j < numColumns; j++) {
newSpan[i][j][0] = 1;
newSpan[i][j][1] = 1;
}
} else {
for (int j = 0; j < numColumns; j++) {
newSpan[i][j][0] = span[i - 1][j][0];
newSpan[i][j][1] = span[i - 1][j][1];
}
}
}
span = newSpan;
rowSize = span.length;
}
public CTMap(int numRows, int numColumns) {
Vector names = new Vector(numColumns);
names.setSize(numColumns);
setColumnIdentifiers(names);
dataVector = new Vector();
setNumRows(numRows);
setSize(new Dimension(numColumns, numRows));
}
protected void initValue() {
System.out.println(span.length);
for (int i = 0; i < span.length; i++) {
for (int j = 0; j < span[i].length; j++) {
span[i][j][CellSpan.COLUMN] = 1;
span[i][j][CellSpan.ROW] = 1;
}
}
}
public void split(int row, int column) {
if (isOutOfBounds(row, column))
return;
int columnSpan = span[row][column][CellSpan.COLUMN];
int rowSpan = span[row][column][CellSpan.ROW];
for (int i = 0; i < rowSpan; i++) {
for (int j = 0; j < columnSpan; j++) {
span[row + i][column + j][CellSpan.COLUMN] = 1;
span[row + i][column + j][CellSpan.ROW] = 1;
}
}
}
public void removeCol() {
columnIdentifiers.removeElementAt(columnIdentifiers.size()-1);
dataVector.setSize(getRowCount());
for (int i = 0; i < getRowCount()-1; i++) {
((Vector)dataVector.elementAt(i)).setSize(getColumnCount());
}
fireTableStructureChanged();
}
}

@ -0,0 +1,94 @@
package com.connor.jd.plm.table;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicTableUI;
import javax.swing.table.TableCellRenderer;
public class CTUI extends BasicTableUI {
public void paint(Graphics g, JComponent c){
Rectangle oldClipBounds = g.getClipBounds();
Rectangle clipBounds = new Rectangle(oldClipBounds);
int tableWidth = table.getColumnModel().getTotalColumnWidth();
clipBounds.width = Math.min(clipBounds.width, tableWidth);
g.setClip(clipBounds);
int firstIndex = table.rowAtPoint(new Point(0, clipBounds.y));
int lastIndex = table.getRowCount() - 1;
Rectangle rowRect = new Rectangle(0, 0, tableWidth, table.getRowHeight() + table.getRowMargin());
rowRect.y = firstIndex * rowRect.height;
for (int index = firstIndex; index <= lastIndex; index++) {
if (rowRect.intersects(clipBounds)) {
// System.out.println(); // debug
// System.out.print("" + index +": "); // row
paintRow(g, index);
}
rowRect.y += rowRect.height;
}
g.setClip(oldClipBounds);
}
private void paintRow(Graphics g, int row) {
Rectangle rect = g.getClipBounds();
boolean drawn = false;
CellSpan cellAtt = (CellSpan) table.getModel();
int numColumns = table.getColumnCount();
for (int column = 0; column < numColumns; column++) {
Rectangle cellRect = table.getCellRect(row, column, true);
int cellRow, cellColumn;
if (cellAtt.isVisible(row, column)) {
cellRow = row;
cellColumn = column;
// System.out.print(" "+column+" "); // debug
} else {
cellRow = row + cellAtt.getSpan(row, column)[CellSpan.ROW];
cellColumn = column + cellAtt.getSpan(row, column)[CellSpan.COLUMN];
// System.out.print(" ("+column+")"); // debug
}
if (cellRect.intersects(rect)) {
drawn = true;
paintCell(g, cellRect, cellRow, cellColumn);
} else {
if (drawn)
break;
}
}
}
private void paintCell(Graphics g, Rectangle cellRect, int row, int column) {
int spacingHeight = table.getRowMargin();
int spacingWidth = table.getColumnModel().getColumnMargin();
Color c = g.getColor();
g.setColor(table.getGridColor());
g.drawRect(cellRect.x, cellRect.y, cellRect.width - 1, cellRect.height - 1);
g.setColor(c);
cellRect.setBounds(cellRect.x + spacingWidth / 2, cellRect.y + spacingHeight / 2, cellRect.width - spacingWidth,
cellRect.height - spacingHeight);
if (table.isEditing() && table.getEditingRow() == row && table.getEditingColumn() == column) {
Component component = table.getEditorComponent();
component.setBounds(cellRect);
component.validate();
} else {
TableCellRenderer renderer = table.getCellRenderer(row, column);
Component component = table.prepareRenderer(renderer, row, column);
if (component.getParent() == null) {
rendererPane.add(component);
}
rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y, cellRect.width, cellRect.height,
true);
}
}
}

@ -0,0 +1,145 @@
package com.connor.jd.plm.table;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
public class CTable extends JTable {
Map<Point,TableCellEditor> map;
public CTable(TableModel model) {
super(model);
setUI(new CTUI());
getTableHeader().setReorderingAllowed(false);
setCellSelectionEnabled(true);
setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
map=new HashMap();
}
public String getToolTipText(MouseEvent e) {
int row=this.rowAtPoint(e.getPoint());
int col=this.columnAtPoint(e.getPoint());
String tiptextString=null;
if(row>-1 && col>-1){
Object value=this.getValueAt(row, col);
if(null!=value && !"".equals(value))
tiptextString=value.toString();//Ðü¸¡ÏÔʾµ¥Ôª¸ñÄÚÈÝ
}
return tiptextString;
}
public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
Rectangle sRect = super.getCellRect(row, column, includeSpacing);
if ((row < 0) || (column < 0) || (getRowCount() <= row) || (getColumnCount() <= column)) {
return sRect;
}
CellSpan cellAtt = (CellSpan) getModel();
if (!cellAtt.isVisible(row, column)) {
int temp_row = row;
int temp_column = column;
row += cellAtt.getSpan(temp_row, temp_column)[CellSpan.ROW];
column += cellAtt.getSpan(temp_row, temp_column)[CellSpan.COLUMN];
}
int[] n = cellAtt.getSpan(row, column);
int index = 0;
int columnMargin = getColumnModel().getColumnMargin();
Rectangle cellFrame = new Rectangle();
int aCellHeight = rowHeight + rowMargin;
cellFrame.y = row * aCellHeight;
cellFrame.height = n[CellSpan.ROW] * aCellHeight;
Enumeration eeration = getColumnModel().getColumns();
while (eeration.hasMoreElements()) {
TableColumn aColumn = (TableColumn) eeration.nextElement();
cellFrame.width = aColumn.getWidth() + columnMargin;
if (index == column)
break;
cellFrame.x += cellFrame.width;
index++;
}
for (int i = 0; i < n[CellSpan.COLUMN] - 1; i++) {
TableColumn aColumn = (TableColumn) eeration.nextElement();
cellFrame.width += aColumn.getWidth() + columnMargin;
}
if (!includeSpacing) {
Dimension spacing = getIntercellSpacing();
cellFrame.setBounds(cellFrame.x + spacing.width / 2, cellFrame.y + spacing.height / 2,
cellFrame.width - spacing.width, cellFrame.height - spacing.height);
}
return cellFrame;
}
private int[] rowColumnAtPoint(Point point) {
int[] retValue = { -1, -1 };
int row = point.y / (rowHeight + rowMargin);
if ((row < 0) || (getRowCount() <= row))
return retValue;
int column = getColumnModel().getColumnIndexAtX(point.x);
CellSpan cellAtt = (CellSpan) getModel();
if (cellAtt.isVisible(row, column)) {
retValue[CellSpan.COLUMN] = column;
retValue[CellSpan.ROW] = row;
return retValue;
}
retValue[CellSpan.COLUMN] = column + cellAtt.getSpan(row, column)[CellSpan.COLUMN];
retValue[CellSpan.ROW] = row + cellAtt.getSpan(row, column)[CellSpan.ROW];
return retValue;
}
public int rowAtPoint(Point point) {
return rowColumnAtPoint(point)[CellSpan.ROW];
}
public int columnAtPoint(Point point) {
return rowColumnAtPoint(point)[CellSpan.COLUMN];
}
public void columnSelectionChanged(ListSelectionEvent e) {
repaint();
}
public void valueChanged(ListSelectionEvent e) {
int firstIndex = e.getFirstIndex();
int lastIndex = e.getLastIndex();
if (firstIndex == -1 && lastIndex == -1) { // Selection cleared.
repaint();
}
Rectangle dirtyRegion = getCellRect(firstIndex, 0, false);
int numCoumns = getColumnCount();
int index = firstIndex;
for (int i = 0; i < numCoumns; i++) {
dirtyRegion.add(getCellRect(index, i, false));
}
index = lastIndex;
for (int i = 0; i < numCoumns; i++) {
dirtyRegion.add(getCellRect(index, i, false));
}
repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height);
}
public void setCombo(int row,int col,TableCellEditor ce){
map.put(new Point(row,col), ce);
}
public TableCellEditor getCellEditor(int row, int column){
Point point = new Point(row,column);
if(map.containsKey(point)){
return map.get(point);
}else{
return super.getCellEditor(row, column);
}
}
public void setRowHeight(int row, int rowHeight) {
super.setRowHeight(row, rowHeight);
}
}

@ -0,0 +1,42 @@
package com.connor.jd.plm.table;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class CTest {
static int[] rows;
static JScrollPane pane;
public static void main(String args[]) {
final CTMap map = new CTMap(5, 5);
final CTable table = new CTable(map);
table.setDefaultRenderer(Object.class, new TableCellTextAreaRenderer());
pane = new JScrollPane(table);
JButton button = new JButton("add");
table.setShowGrid(false);
final JDialog dialog = new JDialog();
dialog.setLayout(new BorderLayout());
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
table.setRowHeight(2, 50);
table.revalidate();
table.repaint();
}
});
dialog.add(pane, BorderLayout.CENTER);
dialog.add(button, BorderLayout.SOUTH);
dialog.setPreferredSize(new Dimension(500, 500));
dialog.show();
}
}

@ -0,0 +1,14 @@
package com.connor.jd.plm.table;
interface CellSpan {
public final int ROW = 0;
public final int COLUMN = 1;
public int[] getSpan(int row, int column);
public void setSpan(int[] span, int row, int column);
public boolean isVisible(int row, int column);
public void combine(int[] rows, int[] columns);
}

@ -0,0 +1,34 @@
package com.connor.jd.plm.table;
import java.awt.Component;
import javax.swing.DefaultCellEditor;
import javax.swing.JTable;
import javax.swing.JTextField;
import com.connor.jd.plm.utils.DatePickerUtil;
import com.eltima.components.ui.DatePicker;
public class DatePickerCellEditor extends DefaultCellEditor {
private DatePicker datePicker;
public DatePickerCellEditor(JTextField arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
// TODO Auto-generated method stub
datePicker = DatePickerUtil.getDatePicker(null);
return datePicker;
}
@Override
public Object getCellEditorValue() {
// TODO Auto-generated method stub
return datePicker.getText();
}
}

@ -0,0 +1,100 @@
package com.connor.jd.plm.table;
import java.awt.Dimension;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
public class DefaultModel extends DefaultTableModel implements CellSpan {
protected int rowSize;
protected int columnSize;
protected int[][][] span; // CellSpan
@Override
public int[] getSpan(int row, int column) {
// TODO Auto-generated method stub
if (isOutOfBounds(row, column)) {
int[] ret_code = { 1, 1 };
return ret_code;
}
return span[row][column];
}
@Override
public void setSpan(int[] span, int row, int column) {
// TODO Auto-generated method stub
if (isOutOfBounds(row, column))
return;
this.span[row][column] = span;
}
@Override
public boolean isVisible(int row, int column) {
// TODO Auto-generated method stub
if (isOutOfBounds(row, column))
return false;
if ((span[row][column][CellSpan.COLUMN] < 1) || (span[row][column][CellSpan.ROW] < 1))
return false;
return true;
}
@Override
public void combine(int[] rows, int[] columns) {
// TODO Auto-generated method stub
int rowSpan = rows.length;
int columnSpan = columns.length;
int startRow = rows[0];
int startColumn = columns[0];
for (int i = 0; i < rowSpan; i++) {
for (int j = 0; j < columnSpan; j++) {
if ((span[startRow + i][startColumn + j][CellSpan.COLUMN] != 1)
|| (span[startRow + i][startColumn + j][CellSpan.ROW] != 1)) {
// System.out.println("can't combine");
return;
}
}
}
for (int i = 0, ii = 0; i < rowSpan; i++, ii--) {
for (int j = 0, jj = 0; j < columnSpan; j++, jj--) {
span[startRow + i][startColumn + j][CellSpan.COLUMN] = jj;
span[startRow + i][startColumn + j][CellSpan.ROW] = ii;
// System.out.println("r " +ii +" c " +jj);
}
}
span[startRow][startColumn][CellSpan.COLUMN] = columnSpan;
span[startRow][startColumn][CellSpan.ROW] = rowSpan;
}
public void setSize(Dimension size) {
columnSize = size.width;
rowSize = size.height;
span = new int[rowSize][columnSize][2]; // 2: COLUMN,ROW
initValue();
}
protected void initValue() {
System.out.println(span.length);
for (int i = 0; i < span.length; i++) {
for (int j = 0; j < span[i].length; j++) {
span[i][j][CellSpan.COLUMN] = 1;
span[i][j][CellSpan.ROW] = 1;
}
}
}
protected boolean isOutOfBounds(int row, int column) {
if ((row < 0) || (rowSize <= row) || (column < 0) || (columnSize <= column)) {
return true;
}
return false;
}
public DefaultModel(int numRows, int numColumns) {
Vector names = new Vector(numColumns);
names.setSize(numColumns);
setColumnIdentifiers(names);
dataVector = new Vector();
setNumRows(numRows);
setSize(new Dimension(numColumns, numRows));
}
}

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

Loading…
Cancel
Save