commit f124be2196f6fa90f4b8bc8204ac1badeab6fd29 Author: lijh Date: Tue Mar 10 15:30:41 2026 +0800 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..a7af672 --- /dev/null +++ b/.classpath @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..78066b2 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com.connor.lyBOMManagement + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..0b79718 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -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 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..87b7a7a --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ee502fb --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -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 diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..a84ef7a --- /dev/null +++ b/build.properties @@ -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 + diff --git a/icons/sample.png b/icons/sample.png new file mode 100644 index 0000000..02c4b79 Binary files /dev/null and b/icons/sample.png differ diff --git a/icons/sample@2x.png b/icons/sample@2x.png new file mode 100644 index 0000000..c1224d1 Binary files /dev/null and b/icons/sample@2x.png differ diff --git a/lib/aspose-cells-18.9.jar b/lib/aspose-cells-18.9.jar new file mode 100644 index 0000000..2cefe55 Binary files /dev/null and b/lib/aspose-cells-18.9.jar differ diff --git a/lib/commons-codec-1.13.jar b/lib/commons-codec-1.13.jar new file mode 100644 index 0000000..bf6ccb3 Binary files /dev/null and b/lib/commons-codec-1.13.jar differ diff --git a/lib/commons-collections4-4.4.jar b/lib/commons-collections4-4.4.jar new file mode 100644 index 0000000..da06c3e Binary files /dev/null and b/lib/commons-collections4-4.4.jar differ diff --git a/lib/commons-compress-1.19.jar b/lib/commons-compress-1.19.jar new file mode 100644 index 0000000..5c9f52a Binary files /dev/null and b/lib/commons-compress-1.19.jar differ diff --git a/lib/commons-lang3-3.9.jar b/lib/commons-lang3-3.9.jar new file mode 100644 index 0000000..0d89693 Binary files /dev/null and b/lib/commons-lang3-3.9.jar differ diff --git a/lib/commons-logging-1.2.jar b/lib/commons-logging-1.2.jar new file mode 100644 index 0000000..93a3b9f Binary files /dev/null and b/lib/commons-logging-1.2.jar differ diff --git a/lib/commons-math3-3.6.1.jar b/lib/commons-math3-3.6.1.jar new file mode 100644 index 0000000..0ff582c Binary files /dev/null and b/lib/commons-math3-3.6.1.jar differ diff --git a/lib/datepicker.jar b/lib/datepicker.jar new file mode 100644 index 0000000..8304d36 Binary files /dev/null and b/lib/datepicker.jar differ diff --git a/lib/fastjson-1.2.9.jar b/lib/fastjson-1.2.9.jar new file mode 100644 index 0000000..839cea3 Binary files /dev/null and b/lib/fastjson-1.2.9.jar differ diff --git a/lib/hutool-all-5.0.7.jar b/lib/hutool-all-5.0.7.jar new file mode 100644 index 0000000..0ed0b10 Binary files /dev/null and b/lib/hutool-all-5.0.7.jar differ diff --git a/lib/jaxb-api-2.3.1.jar b/lib/jaxb-api-2.3.1.jar new file mode 100644 index 0000000..4565865 Binary files /dev/null and b/lib/jaxb-api-2.3.1.jar differ diff --git a/lib/jaxb-core-2.3.0.1.jar b/lib/jaxb-core-2.3.0.1.jar new file mode 100644 index 0000000..431e143 Binary files /dev/null and b/lib/jaxb-core-2.3.0.1.jar differ diff --git a/lib/jaxb-impl-2.3.2.jar b/lib/jaxb-impl-2.3.2.jar new file mode 100644 index 0000000..58035e8 Binary files /dev/null and b/lib/jaxb-impl-2.3.2.jar differ diff --git a/lib/jfxrt.jar b/lib/jfxrt.jar new file mode 100644 index 0000000..49b7d90 Binary files /dev/null and b/lib/jfxrt.jar differ diff --git a/lib/ojdbc6.jar b/lib/ojdbc6.jar new file mode 100644 index 0000000..ec3d6f1 Binary files /dev/null and b/lib/ojdbc6.jar differ diff --git a/lib/poi-4.1.1.jar b/lib/poi-4.1.1.jar new file mode 100644 index 0000000..5b12817 Binary files /dev/null and b/lib/poi-4.1.1.jar differ diff --git a/lib/poi-examples-4.1.1.jar b/lib/poi-examples-4.1.1.jar new file mode 100644 index 0000000..334db49 Binary files /dev/null and b/lib/poi-examples-4.1.1.jar differ diff --git a/lib/poi-excelant-4.1.1.jar b/lib/poi-excelant-4.1.1.jar new file mode 100644 index 0000000..f0eb13a Binary files /dev/null and b/lib/poi-excelant-4.1.1.jar differ diff --git a/lib/poi-ooxml-4.1.1.jar b/lib/poi-ooxml-4.1.1.jar new file mode 100644 index 0000000..bf3569d Binary files /dev/null and b/lib/poi-ooxml-4.1.1.jar differ diff --git a/lib/poi-ooxml-schemas-4.1.1.jar b/lib/poi-ooxml-schemas-4.1.1.jar new file mode 100644 index 0000000..d4d0292 Binary files /dev/null and b/lib/poi-ooxml-schemas-4.1.1.jar differ diff --git a/lib/poi-scratchpad-4.1.1.jar b/lib/poi-scratchpad-4.1.1.jar new file mode 100644 index 0000000..1b6a94f Binary files /dev/null and b/lib/poi-scratchpad-4.1.1.jar differ diff --git a/lib/sqljdbc4.jar b/lib/sqljdbc4.jar new file mode 100644 index 0000000..d6b7f6d Binary files /dev/null and b/lib/sqljdbc4.jar differ diff --git a/lib/xmlbeans-3.1.0.jar b/lib/xmlbeans-3.1.0.jar new file mode 100644 index 0000000..18e568f Binary files /dev/null and b/lib/xmlbeans-3.1.0.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..770ba1e --- /dev/null +++ b/plugin.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Test.java b/src/Test.java new file mode 100644 index 0000000..55cd389 --- /dev/null +++ b/src/Test.java @@ -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() { + @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 list1 = new ArrayList(); + List list2 = new ArrayList(); + List list3 = new ArrayList(); + 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())); + } + +} diff --git a/src/com/connor/jd/operations/CreateTableOperation.java b/src/com/connor/jd/operations/CreateTableOperation.java new file mode 100644 index 0000000..b100596 --- /dev/null +++ b/src/com/connor/jd/operations/CreateTableOperation.java @@ -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(); + } + } + } + + } +} diff --git a/src/com/connor/jd/operations/ExcelImportServiceImpl.java b/src/com/connor/jd/operations/ExcelImportServiceImpl.java new file mode 100644 index 0000000..3fb6ec0 --- /dev/null +++ b/src/com/connor/jd/operations/ExcelImportServiceImpl.java @@ -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; + // ļʽ(20032007)ʼ + 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 + */ + public List getCombineCell(Sheet sheet) { + List 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 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 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; + } + +} \ No newline at end of file diff --git a/src/com/connor/jd/operations/ExcelOperation.java b/src/com/connor/jd/operations/ExcelOperation.java new file mode 100644 index 0000000..8252a53 --- /dev/null +++ b/src/com/connor/jd/operations/ExcelOperation.java @@ -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> jfw) { + if (jfw.size() == 1) { + writeoneExcel(file, outpath, jfw); + } else { + writeallExcel(file, outpath, jfw); + } + } + + public static void writeallExcel(File file, String outpath, Map> 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 cellRangeList = getCombineCell(sheet); + for (Entry> ever : jfw.entrySet()) { + List 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> 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 cellRangeList = getCombineCell(sheet); + for (Entry> ever : jfw.entrySet()) { + List 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 valueList = new ArrayList(); + 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 + */ + public static List getCombineCell(Sheet sheet) { + List 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; + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/action/AddHLBOMAction.java b/src/com/connor/jd/plm/action/AddHLBOMAction.java new file mode 100644 index 0000000..ec076ad --- /dev/null +++ b/src/com/connor/jd/plm/action/AddHLBOMAction.java @@ -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() { + @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(); + } + } + } + +} diff --git a/src/com/connor/jd/plm/action/BOMManagementAction.java b/src/com/connor/jd/plm/action/BOMManagementAction.java new file mode 100644 index 0000000..b2bb78a --- /dev/null +++ b/src/com/connor/jd/plm/action/BOMManagementAction.java @@ -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); + } + +} diff --git a/src/com/connor/jd/plm/action/BatchReviseAction.java b/src/com/connor/jd/plm/action/BatchReviseAction.java new file mode 100644 index 0000000..347cc95 --- /dev/null +++ b/src/com/connor/jd/plm/action/BatchReviseAction.java @@ -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 unpublished = new ArrayList(); + 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 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 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"), "δ" }); + } + } + } + +} diff --git a/src/com/connor/jd/plm/action/DeleteItemRevisionAction.java b/src/com/connor/jd/plm/action/DeleteItemRevisionAction.java new file mode 100644 index 0000000..b9cd288 --- /dev/null +++ b/src/com/connor/jd/plm/action/DeleteItemRevisionAction.java @@ -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 pref = Arrays.asList(allow); + List pref2 = Arrays.asList(allow2); + List 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(); + } + } + } + } + +} diff --git a/src/com/connor/jd/plm/action/EditClassificationAction.java b/src/com/connor/jd/plm/action/EditClassificationAction.java new file mode 100644 index 0000000..2fd400e --- /dev/null +++ b/src/com/connor/jd/plm/action/EditClassificationAction.java @@ -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(); + } + + } + +} diff --git a/src/com/connor/jd/plm/action/ExportBOMAction.java b/src/com/connor/jd/plm/action/ExportBOMAction.java new file mode 100644 index 0000000..ddd1909 --- /dev/null +++ b/src/com/connor/jd/plm/action/ExportBOMAction.java @@ -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) { + + } + } + +} diff --git a/src/com/connor/jd/plm/action/WLTZReviseAction.java b/src/com/connor/jd/plm/action/WLTZReviseAction.java new file mode 100644 index 0000000..1efd661 --- /dev/null +++ b/src/com/connor/jd/plm/action/WLTZReviseAction.java @@ -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 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 privilegeMap = new HashMap(); +// privilegeMap.put("uid", uids); +// privilegeMap.put("user", session.getUser().getUid()); +// privilegeMap.put("privilege", "WRITE,DELETE"); +// privilegeMap.put("pass", true); +// List 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 paramMap = new HashMap(); + 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 PARAMMAP = paramMap; +// final Map 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; + } + +} diff --git a/src/com/connor/jd/plm/action/package-info.java b/src/com/connor/jd/plm/action/package-info.java new file mode 100644 index 0000000..8e74581 --- /dev/null +++ b/src/com/connor/jd/plm/action/package-info.java @@ -0,0 +1 @@ +package com.connor.jd.plm.action; \ No newline at end of file diff --git a/src/com/connor/jd/plm/beans/BOMExportBean.java b/src/com/connor/jd/plm/beans/BOMExportBean.java new file mode 100644 index 0000000..3cb287e --- /dev/null +++ b/src/com/connor/jd/plm/beans/BOMExportBean.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/beans/BOMLogBean.java b/src/com/connor/jd/plm/beans/BOMLogBean.java new file mode 100644 index 0000000..56555fc --- /dev/null +++ b/src/com/connor/jd/plm/beans/BOMLogBean.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/beans/BOMManageTableBean.java b/src/com/connor/jd/plm/beans/BOMManageTableBean.java new file mode 100644 index 0000000..0c7600d --- /dev/null +++ b/src/com/connor/jd/plm/beans/BOMManageTableBean.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/beans/CheckBoxPo.java b/src/com/connor/jd/plm/beans/CheckBoxPo.java new file mode 100644 index 0000000..b7c280c --- /dev/null +++ b/src/com/connor/jd/plm/beans/CheckBoxPo.java @@ -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; + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/beans/ClassPropBean.java b/src/com/connor/jd/plm/beans/ClassPropBean.java new file mode 100644 index 0000000..12cf40a --- /dev/null +++ b/src/com/connor/jd/plm/beans/ClassPropBean.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/beans/ComponentBean.java b/src/com/connor/jd/plm/beans/ComponentBean.java new file mode 100644 index 0000000..31c5cd8 --- /dev/null +++ b/src/com/connor/jd/plm/beans/ComponentBean.java @@ -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 typeProperty() { + return type; + } + + public ObservableValue projectProperty() { + return project; + } + + public ObservableValue timeProperty() { + return time; + } + + public ObservableValue numberProperty() { + return number; + } + + public ObservableValue 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); + } + +} diff --git a/src/com/connor/jd/plm/beans/CustomLovBean.java b/src/com/connor/jd/plm/beans/CustomLovBean.java new file mode 100644 index 0000000..75157ec --- /dev/null +++ b/src/com/connor/jd/plm/beans/CustomLovBean.java @@ -0,0 +1,38 @@ +package com.connor.jd.plm.beans; + +import java.util.ArrayList; +import java.util.List; + +public class CustomLovBean { + private List sub = new ArrayList(); + 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 getSub() { + return sub; + } + + public boolean hasChild() { + return sub.size() != 0; + } + + public void addSub(CustomLovBean clb) { + sub.add(clb); + } +} diff --git a/src/com/connor/jd/plm/beans/JG.java b/src/com/connor/jd/plm/beans/JG.java new file mode 100644 index 0000000..cf10668 --- /dev/null +++ b/src/com/connor/jd/plm/beans/JG.java @@ -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; + } +} diff --git a/src/com/connor/jd/plm/beans/MachineBean.java b/src/com/connor/jd/plm/beans/MachineBean.java new file mode 100644 index 0000000..51ebd0f --- /dev/null +++ b/src/com/connor/jd/plm/beans/MachineBean.java @@ -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 typeProperty() { + return type; + } + + public ObservableValue projectProperty() { + return project; + } + + public ObservableValue 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); + ; + } +} diff --git a/src/com/connor/jd/plm/beans/ResultData.java b/src/com/connor/jd/plm/beans/ResultData.java new file mode 100644 index 0000000..ac5430d --- /dev/null +++ b/src/com/connor/jd/plm/beans/ResultData.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/beans/TransformBomBean.java b/src/com/connor/jd/plm/beans/TransformBomBean.java new file mode 100644 index 0000000..20de45b --- /dev/null +++ b/src/com/connor/jd/plm/beans/TransformBomBean.java @@ -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 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; + } + +} diff --git a/src/com/connor/jd/plm/dialog/DocumentTemplate.java b/src/com/connor/jd/plm/dialog/DocumentTemplate.java new file mode 100644 index 0000000..60a256a --- /dev/null +++ b/src/com/connor/jd/plm/dialog/DocumentTemplate.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/dialog/EditClassificationDialog.java b/src/com/connor/jd/plm/dialog/EditClassificationDialog.java new file mode 100644 index 0000000..dc6ea3c --- /dev/null +++ b/src/com/connor/jd/plm/dialog/EditClassificationDialog.java @@ -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 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 displayMap = new LinkedHashMap(); + propMap = new HashMap(); + + 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 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 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 combo = new JComboBox(); + 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) 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 paramMap = new HashMap(); + 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 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()); + } +} diff --git a/src/com/connor/jd/plm/dialog/package-info.java b/src/com/connor/jd/plm/dialog/package-info.java new file mode 100644 index 0000000..803ca64 --- /dev/null +++ b/src/com/connor/jd/plm/dialog/package-info.java @@ -0,0 +1 @@ +package com.connor.jd.plm.dialog; \ No newline at end of file diff --git a/src/com/connor/jd/plm/dialogs/BOMManagementFrame.java b/src/com/connor/jd/plm/dialogs/BOMManagementFrame.java new file mode 100644 index 0000000..4dcab7c --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/BOMManagementFrame.java @@ -0,0 +1,2149 @@ +package com.connor.jd.plm.dialogs; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.Vector; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.RowSorter; +import javax.swing.filechooser.FileSystemView; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableRowSorter; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; + +import com.connor.jd.plm.beans.BOMManageTableBean; +import com.connor.jd.plm.beans.CheckBoxPo; +import com.connor.jd.plm.beans.CustomLovBean; +import com.connor.jd.plm.beans.ResultData; +import com.connor.jd.plm.table.MyCellEditor4; +import com.connor.jd.plm.table.MyCellRenderer; +import com.connor.jd.plm.utils.DBConnectionUtil; +import com.connor.jd.plm.utils.DBUtil; +import com.connor.jd.plm.utils.DatePickerUtil; +import com.connor.jd.plm.utils.DialogUtil; +import com.connor.jd.plm.utils.JDMethodUtil; +import com.connor.jd.plm.utils.KeyValComboBox; +import com.connor.jd.plm.utils.SimpleExcelUtil; +import com.connor.jd.plm.utils.StringCreateUtil; +import com.eltima.components.ui.DatePicker; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.workflow.commands.newprocess.NewProcessCommand; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.db.Db; +import cn.hutool.db.Entity; +import cn.hutool.db.sql.Condition; + +public class BOMManagementFrame extends JFrame { + private AbstractAIFApplication app; + private TCSession session; + private CardLayout rootSwitch = new CardLayout(); + private String[] colDisplayNames = new String[] { "ѡ", "", "Ӽ", "λ", "", "״̬" }; + private String[] colDisplayNames2 = new String[] { "", "޸û", "ʱ", "" }; + private JPanel root; + private Map tableDataMap = new HashMap(); + private BOMManagementFrame $this; + private List logDataList; + private Map winMap = new HashMap(); + private TCComponentItemRevision targetRev; + private TCComponentItemRevision targetRev2; + private boolean isLogcreated = false; + private int doIndex = 0; + private boolean complate = false; + private List checkItemType = new ArrayList(); + private JButton[] topBtns; + private TCComponentBOMWindowType winType; + private int width = 1200; + private int height = 800; + private int widthOffset = 0; + private int heightOffset = 0; + private JLabel p1TargetLabel; + private JButton p1TargetBtn; + private JLabel p1ReplaceLabel; + private JButton p1ReplaceBtn; + private JLabel p1UnitLabel; + private KeyValComboBox p1UnitCombo; + private JLabel p1NumLabel; + private JTextField p1NumText; + private JCheckBox p1SelectAll; + private JTable p1Table; + private JScrollPane p1jsp; + private JButton p1BottomBtn1; + private JButton p1BottomBtn2; + private JButton p1BottomBtn3; + private JButton p1BottomBtn4; + private JPanel p1Left; + private JScrollPane p1TreePanel; + private JPanel p1Right; + private JLabel p2TargetLabel; + private JButton p2TargetBtn; + private JLabel p2ChangeNumLabel; + private JTextField p2NumText; + private JCheckBox p2SelectAll; + private JTable p2Table; + private JScrollPane p2jsp; + private JButton p2BottomBtn1; + private JButton p2BottomBtn2; + private JButton p2BottomBtn3; + private JButton p2BottomBtn4; + private JPanel p2Left; + private JScrollPane p2TreePanel; + private JPanel p2Right; + private JLabel p3TargetLabel; + private JButton p3TargetBtn; + private JLabel p3AddLabel; + private JButton p3AddBtn; + private JLabel p3UnitLabel; + private KeyValComboBox p3UnitCombo; + private JLabel p3NumLabel; + private JTextField p3NumText; + private JCheckBox p3SelectAll; + private JTable p3Table; + private JScrollPane p3jsp; + private JButton p3BottomBtn1; + private JButton p3BottomBtn2; + private JButton p3BottomBtn3; + private JButton p3BottomBtn4; + private JPanel p3Left; + private JScrollPane p3TreePanel; + private JPanel p3Right; + private JLabel p4TargetLabel; + private JButton p4TargetBtn; + private JCheckBox p4SelectAll; + private JTable p4Table; + private JScrollPane p4jsp; + private JButton p4BottomBtn1; + private JButton p4BottomBtn2; + private JButton p4BottomBtn3; + private JButton p4BottomBtn4; + private JPanel p4Left; + private JScrollPane p4TreePanel; + private JPanel p4Right; + private JLabel p5UserLabel; + private JTextField p5UserText; + private JLabel p5TimeLabel; + private DatePicker p5TimeStartText; + private JLabel toLabel; + private DatePicker p5TimeEndText; + private JLabel p5ContentLabel; + private JTextArea p5ContentText; + private JScrollPane p5Contentjsp; + private JButton p5Search; + private JComboBox p5Download; + private JTable p5Table; + private JScrollPane p5jsp; + private Map uiSize = new HashMap<>(); + private JPanel p1; + private JPanel p2; + private JPanel p3; + private JPanel p4; + private JPanel p5; + private Set addedBOMLine = new HashSet<>(); + + public BOMManagementFrame(AbstractAIFApplication app) { + super(); + this.app = app; + this.session = (TCSession) app.getSession(); + $this = this; + String[] prefArray = JDMethodUtil.getPrefStrArray("connor_bom_check_type", session); + if (prefArray != null) { + checkItemType = Arrays.asList(prefArray); + } + TCTypeService service = session.getTypeService(); + try { + this.winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + init(); + } + + private void init() { + this.setTitle("BOM"); + this.setSize(new Dimension(1200, 800)); + this.setLayout(new BorderLayout()); + this.setResizable(true); + this.setAlwaysOnTop(true); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setLocationRelativeTo(null); + this.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + // TODO Auto-generated method stub + super.componentResized(e); + Component comp = e.getComponent(); + $this.widthOffset = comp.getWidth() - $this.width; + $this.heightOffset = comp.getHeight() - $this.height; + if ($this.widthOffset != 0 || $this.heightOffset != 0) { + System.out.println("width===>" + comp.getWidth()); + System.out.println("height===>" + comp.getHeight()); + $this.width = comp.getWidth(); + $this.height = comp.getHeight(); + $this.resize(); + } + } + }); + this.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void focusGained(FocusEvent e) { + // TODO Auto-generated method stub + $this.setAlwaysOnTop(true); + } + }); + + Container container = this.getContentPane(); + container.setLayout(new BorderLayout()); + container.setSize(new Dimension(1200, 800)); + + TCTypeService typeService = session.getTypeService(); + Vector unitVector = new Vector(); + try { + TCComponent[] uomArray = typeService.getTypeComponent("UnitOfMeasure").extent(); + unitVector.add(new CheckBoxPo(" ", " ")); + for (TCComponent comp : uomArray) { + unitVector.add(new CheckBoxPo(comp.toString(), comp)); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // ͷ + JPanel topBtnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + JButton btn = new JButton("滻"); + + btn.setSelected(true); + topBtnPanel.add(btn); + btn.addActionListener(panelSwitch()); + container.add(topBtnPanel, BorderLayout.NORTH); + + // root + root = new JPanel(rootSwitch); + + // 滻 + p1 = new JPanel(); + p1.setLayout(null); + + // 滻 + p1Left = new JPanel(); + p1Left.setLayout(null); + p1Left.setBounds(0, 0, 800, 800); + p1Left.setBorder(BorderFactory.createEtchedBorder()); + + p1TargetLabel = new JLabel("Ŀϱ"); + p1TargetLabel.setBounds(20, 20, 100, 25); + p1TargetBtn = new JButton(); + p1TargetBtn.setBounds(130, 20, 400, 25); + p1ReplaceLabel = new JLabel("滻ϱ"); + p1ReplaceLabel.setBounds(20, 60, 100, 25); + p1ReplaceBtn = new JButton(); + p1ReplaceBtn.setBounds(130, 60, 400, 25); + p1UnitLabel = new JLabel("λ"); + p1UnitLabel.setBounds(560, 60, 50, 25); + p1UnitCombo = new KeyValComboBox(unitVector); + p1UnitCombo.setBounds(610, 60, 50, 25); + p1NumLabel = new JLabel(""); + p1NumLabel.setBounds(680, 60, 50, 25); + p1NumText = new JTextField(); + p1NumText.setBounds(730, 60, 50, 25); + p1SelectAll = new JCheckBox("ȫѡ"); + p1SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p1model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p1Table = new JTable(p1model); + p1Table.getColumnModel().getColumn(0).setMinWidth(60); + p1Table.getColumnModel().getColumn(0).setMaxWidth(60); + p1Table.getColumnModel().getColumn(1).setMinWidth(200); + p1Table.getColumnModel().getColumn(2).setMinWidth(200); + p1Table.getColumnModel().getColumn(3).setMinWidth(100); + p1Table.getColumnModel().getColumn(4).setMinWidth(100); + p1Table.getColumnModel().getColumn(5).setMinWidth(100); + p1Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p1Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p1Table.setRowHeight(25); + p1Table.setAutoscrolls(true); + p1Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p1Table.getTableHeader().setReorderingAllowed(false); + p1Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p1sorter = new TableRowSorter(p1model); + p1Table.setRowSorter(p1sorter); + p1jsp = new JScrollPane(p1Table); + p1jsp.setBounds(20, 130, 760, 500); + + p1BottomBtn1 = new JButton(""); + p1BottomBtn1.setBounds(80, 650, 100, 25); + p1BottomBtn2 = new JButton("滻"); + p1BottomBtn2.setBounds(260, 650, 100, 25); + p1BottomBtn3 = new JButton(""); + p1BottomBtn3.setBounds(440, 650, 100, 25); + p1BottomBtn4 = new JButton("ȡ"); + p1BottomBtn4.setBounds(620, 650, 100, 25); + + p1Left.add(p1TargetLabel); + p1Left.add(p1TargetBtn); + p1Left.add(p1ReplaceLabel); + p1Left.add(p1ReplaceBtn); + //p1Left.add(p1UnitLabel); + //p1Left.add(p1UnitCombo); + p1Left.add(p1NumLabel); + p1Left.add(p1NumText); + p1Left.add(p1SelectAll); + p1Left.add(p1jsp); + p1Left.add(p1BottomBtn1); + p1Left.add(p1BottomBtn2); + //p1Left.add(p1BottomBtn3); + p1Left.add(p1BottomBtn4); + + // 滻ұ + p1Right = new JPanel(); + p1Right.setLayout(null); + p1Right.setBounds(800, 0, 400, 800); + p1Right.setBorder(BorderFactory.createEtchedBorder()); + + p1TreePanel = new JScrollPane(); + p1TreePanel.setBounds(20, 130, 360, 500); + p1Right.add(p1TreePanel); + + // ¼ + p1SelectAll.addItemListener(selectAll(p1Table)); + p1Table.addMouseListener(showTree(p1Right)); + p1BottomBtn4.addActionListener(cancel()); + p1BottomBtn1.addActionListener(batchRevise(p1Table, p1SelectAll)); + p1BottomBtn2.addActionListener(batchReplace()); + p1BottomBtn3.addActionListener(startWorkFlow(p1Table)); + p1TargetBtn.addActionListener(clickSearch(p1Table, p1SelectAll)); + p1ReplaceBtn.addActionListener(clickSearch(null, null)); + + p1.add(p1Left); + p1.add(p1Right); + + // + p2 = new JPanel(); + p2.setLayout(null); + + // + p2Left = new JPanel(); + p2Left.setLayout(null); + p2Left.setBounds(0, 0, 800, 800); + p2Left.setBorder(BorderFactory.createEtchedBorder()); + + p2TargetLabel = new JLabel("Ŀϱ"); + p2TargetLabel.setBounds(20, 20, 100, 25); + p2TargetBtn = new JButton(); + p2TargetBtn.setBounds(130, 20, 400, 25); + p2ChangeNumLabel = new JLabel(""); + p2ChangeNumLabel.setBounds(20, 60, 100, 25); + p2NumText = new JTextField(); + p2NumText.setBounds(130, 60, 50, 25); + + p2SelectAll = new JCheckBox("ȫѡ"); + p2SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p2model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p2Table = new JTable(p2model); + p2Table.getColumnModel().getColumn(0).setMinWidth(60); + p2Table.getColumnModel().getColumn(0).setMaxWidth(60); + p2Table.getColumnModel().getColumn(1).setMinWidth(200); + p2Table.getColumnModel().getColumn(2).setMinWidth(200); + p2Table.getColumnModel().getColumn(3).setMinWidth(100); + p2Table.getColumnModel().getColumn(4).setMinWidth(100); + p2Table.getColumnModel().getColumn(5).setMinWidth(100); + p2Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p2Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p2Table.setRowHeight(25); + p2Table.setAutoscrolls(true); + p2Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p2Table.getTableHeader().setReorderingAllowed(false); + p2Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p2sorter = new TableRowSorter(p2model); + p2Table.setRowSorter(p2sorter); + p2jsp = new JScrollPane(p2Table); + p2jsp.setBounds(20, 130, 760, 500); + + p2BottomBtn1 = new JButton(""); + p2BottomBtn1.setBounds(80, 650, 100, 25); + p2BottomBtn2 = new JButton(""); + p2BottomBtn2.setBounds(260, 650, 100, 25); + p2BottomBtn3 = new JButton(""); + p2BottomBtn3.setBounds(440, 650, 100, 25); + p2BottomBtn4 = new JButton("ȡ"); + p2BottomBtn4.setBounds(620, 650, 100, 25); + + p2Left.add(p2TargetLabel); + p2Left.add(p2TargetBtn); + p2Left.add(p2ChangeNumLabel); + p2Left.add(p2NumText); + p2Left.add(p2SelectAll); + p2Left.add(p2jsp); + p2Left.add(p2BottomBtn1); + p2Left.add(p2BottomBtn2); + p2Left.add(p2BottomBtn3); + p2Left.add(p2BottomBtn4); + + // ұ + p2Right = new JPanel(); + p2Right.setLayout(null); + p2Right.setBounds(800, 0, 400, 800); + p2Right.setBorder(BorderFactory.createEtchedBorder()); + + p2TreePanel = new JScrollPane(); + p2TreePanel.setBounds(20, 130, 360, 500); + p2Right.add(p2TreePanel); + + // ¼ + p2SelectAll.addItemListener(selectAll(p2Table)); + p2Table.addMouseListener(showTree(p2Right)); + p2BottomBtn4.addActionListener(cancel()); + p2BottomBtn1.addActionListener(batchRevise(p2Table, p2SelectAll)); + p2BottomBtn2.addActionListener(batchModify()); + p2BottomBtn3.addActionListener(startWorkFlow(p2Table)); + p2TargetBtn.addActionListener(clickSearch(p2Table, p2SelectAll)); + + p2.add(p2Left); + p2.add(p2Right); + + // + p3 = new JPanel(); + p3.setLayout(null); + + // + p3Left = new JPanel(); + p3Left.setLayout(null); + p3Left.setBounds(0, 0, 800, 800); + p3Left.setBorder(BorderFactory.createEtchedBorder()); + + p3TargetLabel = new JLabel("οϱ"); + p3TargetLabel.setBounds(20, 20, 100, 25); + p3TargetBtn = new JButton(); + p3TargetBtn.setBounds(130, 20, 400, 25); + p3AddLabel = new JLabel("ϱ"); + p3AddLabel.setBounds(20, 60, 100, 25); + p3AddBtn = new JButton(); + p3AddBtn.setBounds(130, 60, 400, 25); + p3UnitLabel = new JLabel("λ"); + p3UnitLabel.setBounds(560, 60, 50, 25); + p3UnitCombo = new KeyValComboBox(unitVector); + p3UnitCombo.setBounds(610, 60, 50, 25); + p3NumLabel = new JLabel(""); + p3NumLabel.setBounds(680, 60, 50, 25); + p3NumText = new JTextField(); + p3NumText.setBounds(730, 60, 50, 25); + + p3SelectAll = new JCheckBox("ȫѡ"); + p3SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p3model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p3Table = new JTable(p3model); + p3Table.getColumnModel().getColumn(0).setMinWidth(60); + p3Table.getColumnModel().getColumn(0).setMaxWidth(60); + p3Table.getColumnModel().getColumn(1).setMinWidth(200); + p3Table.getColumnModel().getColumn(2).setMinWidth(200); + p3Table.getColumnModel().getColumn(3).setMinWidth(100); + p3Table.getColumnModel().getColumn(4).setMinWidth(100); + p3Table.getColumnModel().getColumn(5).setMinWidth(100); + p3Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p3Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p3Table.setRowHeight(25); + p3Table.setAutoscrolls(true); + p3Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p3Table.getTableHeader().setReorderingAllowed(false); + p3Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p3sorter = new TableRowSorter(p3model); + p3Table.setRowSorter(p3sorter); + p3jsp = new JScrollPane(p3Table); + p3jsp.setBounds(20, 130, 760, 500); + + p3BottomBtn1 = new JButton(""); + p3BottomBtn1.setBounds(80, 650, 100, 25); + p3BottomBtn2 = new JButton(""); + p3BottomBtn2.setBounds(260, 650, 100, 25); + p3BottomBtn3 = new JButton(""); + p3BottomBtn3.setBounds(440, 650, 100, 25); + p3BottomBtn4 = new JButton("ȡ"); + p3BottomBtn4.setBounds(620, 650, 100, 25); + + p3Left.add(p3TargetLabel); + p3Left.add(p3TargetBtn); + p3Left.add(p3AddLabel); + p3Left.add(p3AddBtn); + p3Left.add(p3UnitLabel); + p3Left.add(p3UnitCombo); + p3Left.add(p3NumLabel); + p3Left.add(p3NumText); + p3Left.add(p3SelectAll); + p3Left.add(p3jsp); + p3Left.add(p3BottomBtn1); + p3Left.add(p3BottomBtn2); + p3Left.add(p3BottomBtn3); + p3Left.add(p3BottomBtn4); + + // ұ + p3Right = new JPanel(); + p3Right.setLayout(null); + p3Right.setBounds(800, 0, 400, 800); + p3Right.setBorder(BorderFactory.createEtchedBorder()); + + p3TreePanel = new JScrollPane(); + p3TreePanel.setBounds(20, 130, 360, 500); + p3Right.add(p3TreePanel); + + // ¼ + p3SelectAll.addItemListener(selectAll(p3Table)); + p3Table.addMouseListener(showTree(p3Right)); + p3BottomBtn4.addActionListener(cancel()); + p3BottomBtn1.addActionListener(batchRevise(p3Table, p3SelectAll)); + p3BottomBtn2.addActionListener(batchAdd()); + p3BottomBtn3.addActionListener(startWorkFlow(p3Table)); + p3TargetBtn.addActionListener(clickSearch(p3Table, p3SelectAll)); + p3AddBtn.addActionListener(clickSearch(null, null)); + + p3.add(p3Left); + p3.add(p3Right); + + // ɾ + p4 = new JPanel(); + p4.setLayout(null); + + // ɾ + p4Left = new JPanel(); + p4Left.setLayout(null); + p4Left.setBounds(0, 0, 800, 800); + p4Left.setBorder(BorderFactory.createEtchedBorder()); + + p4TargetLabel = new JLabel("Ŀϱ"); + p4TargetLabel.setBounds(20, 20, 100, 25); + p4TargetBtn = new JButton(); + p4TargetBtn.setBounds(130, 20, 400, 25); + + p4SelectAll = new JCheckBox("ȫѡ"); + p4SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p4model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p4Table = new JTable(p4model); + p4Table.getColumnModel().getColumn(0).setMinWidth(60); + p4Table.getColumnModel().getColumn(0).setMaxWidth(60); + p4Table.getColumnModel().getColumn(1).setMinWidth(200); + p4Table.getColumnModel().getColumn(2).setMinWidth(200); + p4Table.getColumnModel().getColumn(3).setMinWidth(100); + p4Table.getColumnModel().getColumn(4).setMinWidth(100); + p4Table.getColumnModel().getColumn(5).setMinWidth(100); + p4Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p4Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p4Table.setRowHeight(25); + p4Table.setAutoscrolls(true); + p4Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p4Table.getTableHeader().setReorderingAllowed(false); + p4Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p4sorter = new TableRowSorter(p4model); + p4Table.setRowSorter(p4sorter); + p4jsp = new JScrollPane(p4Table); + p4jsp.setBounds(20, 130, 760, 500); + + p4BottomBtn1 = new JButton(""); + p4BottomBtn1.setBounds(80, 650, 100, 25); + p4BottomBtn2 = new JButton("ɾ"); + p4BottomBtn2.setBounds(260, 650, 100, 25); + p4BottomBtn3 = new JButton(""); + p4BottomBtn3.setBounds(440, 650, 100, 25); + p4BottomBtn4 = new JButton("ȡ"); + p4BottomBtn4.setBounds(620, 650, 100, 25); + + p4Left.add(p4TargetLabel); + p4Left.add(p4TargetBtn); + p4Left.add(p4SelectAll); + p4Left.add(p4jsp); + p4Left.add(p4BottomBtn1); + p4Left.add(p4BottomBtn2); + p4Left.add(p4BottomBtn3); + p4Left.add(p4BottomBtn4); + + // ұ + p4Right = new JPanel(); + p4Right.setLayout(null); + p4Right.setBounds(800, 0, 400, 800); + p4Right.setBorder(BorderFactory.createEtchedBorder()); + + p4TreePanel = new JScrollPane(); + p4TreePanel.setBounds(20, 130, 360, 500); + p4Right.add(p4TreePanel); + + // ¼ + p4SelectAll.addItemListener(selectAll(p4Table)); + p4Table.addMouseListener(showTree(p4Right)); + p4BottomBtn4.addActionListener(cancel()); + p4BottomBtn1.addActionListener(batchRevise(p4Table, p4SelectAll)); + p4BottomBtn2.addActionListener(batchRemove()); + p4BottomBtn3.addActionListener(startWorkFlow(p4Table)); + p4TargetBtn.addActionListener(clickSearch(p4Table, p4SelectAll)); + + p4.add(p4Left); + p4.add(p4Right); + + // ־ + p5 = new JPanel(); + p5.setLayout(null); + + p5UserLabel = new JLabel("޸û"); + p5UserLabel.setBounds(20, 40, 70, 25); + p5UserText = new JTextField(); + p5UserText.setBounds(100, 40, 150, 25); + p5TimeLabel = new JLabel("޸ʱ"); + p5TimeLabel.setBounds(300, 40, 70, 25); + p5TimeStartText = DatePickerUtil.getDatePicker(null); + p5TimeStartText.setBounds(380, 40, 100, 25); + toLabel = new JLabel(""); + toLabel.setBounds(490, 40, 20, 25); + p5TimeEndText = DatePickerUtil.getDatePicker(null); + p5TimeEndText.setBounds(520, 40, 100, 25); + p5ContentLabel = new JLabel("޸"); + p5ContentLabel.setBounds(670, 40, 70, 25); + p5ContentText = new JTextArea(); + p5ContentText.setLineWrap(true); + p5ContentText.setWrapStyleWord(true); + p5Contentjsp = new JScrollPane(p5ContentText); + p5Contentjsp.setBounds(750, 20, 200, 80); + p5Search = new JButton(""); + p5Search.setBounds(1000, 40, 60, 25); + p5Download = new JComboBox(); + p5Download.addItem("־"); + p5Download.addItem("Ϊtxt"); + p5Download.addItem("Ϊexcel"); + p5Download.setSelectedItem("־"); + p5Download.setBounds(1080, 40, 100, 25); + + DefaultTableModel p5model = new DefaultTableModel(colDisplayNames2, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p5Table = new JTable(p5model); + p5Table.getColumnModel().getColumn(0).setMinWidth(60); + p5Table.getColumnModel().getColumn(0).setMaxWidth(60); + p5Table.getColumnModel().getColumn(1).setMinWidth(200); + p5Table.getColumnModel().getColumn(2).setMinWidth(200); + p5Table.getColumnModel().getColumn(3).setMinWidth(700); + p5Table.setRowHeight(25); + p5Table.setAutoscrolls(true); + p5Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p5Table.getTableHeader().setReorderingAllowed(false); + RowSorter p5sorter = new TableRowSorter(p5model); + p5Table.setRowSorter(p5sorter); + p5jsp = new JScrollPane(p5Table); + p5jsp.setBounds(20, 130, 1160, 580); + + // ¼ + p5Search.addActionListener(searchLog()); + p5Download.addItemListener(downloadLog(p5Table)); + p5UserText.addKeyListener(logSearchEnter()); + p5TimeStartText.addKeyListener(logSearchEnter()); + p5TimeEndText.addKeyListener(logSearchEnter()); + + p5.add(p5UserLabel); + p5.add(p5UserText); + p5.add(p5TimeLabel); + p5.add(p5TimeStartText); + p5.add(toLabel); + p5.add(p5TimeEndText); + p5.add(p5ContentLabel); + p5.add(p5Contentjsp); + p5.add(p5Search); + p5.add(p5Download); + p5.add(p5jsp); + + root.add("batchReplace", p1); + root.add("batchModify", p2); + root.add("batchAdd", p3); + root.add("batchRemove", p4); + root.add("updateLog", p5); + + rootSwitch.show(root, "batchReplace"); + container.add(root, BorderLayout.CENTER); + this.setVisible(true); + } + + private ActionListener panelSwitch() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String text = ((JButton) e.getSource()).getText(); + for (int i = 0; i < topBtns.length; i++) { + topBtns[i].setSelected(topBtns[i].getText().equals(text)); + } + switch (text) { + case "滻": + clearTable(p1Table, p1SelectAll); + p1Right.removeAll(); + JScrollPane panel1 = new JScrollPane(); + panel1.setBounds(p1TreePanel.getX(), p1TreePanel.getY(), p1TreePanel.getWidth(), + p1TreePanel.getHeight()); + p1TreePanel = panel1; + p1Right.add(panel1); + p1Right.revalidate(); + p1Right.repaint(); + rootSwitch.show(root, "batchReplace"); + break; + case "": + clearTable(p2Table, p2SelectAll); + p2Right.removeAll(); + JScrollPane panel2 = new JScrollPane(); + panel2.setBounds(p2TreePanel.getX(), p2TreePanel.getY(), p2TreePanel.getWidth(), + p2TreePanel.getHeight()); + p2TreePanel = panel2; + p2Right.add(panel2); + p2Right.revalidate(); + p2Right.repaint(); + rootSwitch.show(root, "batchModify"); + break; + case "": + clearTable(p3Table, p3SelectAll); + p3Right.removeAll(); + JScrollPane panel3 = new JScrollPane(); + panel3.setBounds(p3TreePanel.getX(), p3TreePanel.getY(), p3TreePanel.getWidth(), + p3TreePanel.getHeight()); + p3TreePanel = panel3; + p3Right.add(panel3); + p3Right.revalidate(); + p3Right.repaint(); + rootSwitch.show(root, "batchAdd"); + break; + case "ɾ": + clearTable(p4Table, p4SelectAll); + p4Right.removeAll(); + JScrollPane panel4 = new JScrollPane(); + panel4.setBounds(p4TreePanel.getX(), p4TreePanel.getY(), p4TreePanel.getWidth(), + p4TreePanel.getHeight()); + p4TreePanel = panel4; + p4Right.add(panel4); + p4Right.revalidate(); + p4Right.repaint(); + rootSwitch.show(root, "batchRemove"); + break; + case "־": + createLogDataSourceTable(); + clearTable(p5Table, null); + rootSwitch.show(root, "updateLog"); + break; + default: +// createLogDataSourceTable(); + } + } + }; + } + + private void showWhereUesd(JTable table, JCheckBox selectAll) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + // TODO Auto-generated method stub + clearTable(table, selectAll); + if (table == null || targetRev == null) { + return; + } + long startTime = System.currentTimeMillis(); + List tableDataList = new ArrayList(); + try { + String revString = targetRev.getProperty("object_string"); + TCComponent[] usedComps = targetRev.whereUsed((short) 0); + System.out.println("װ======>" + usedComps.length); + + tableDataMap.clear(); +// Map usedMap = usedFilter(usedComps); +// for (Entry entry : usedMap.entrySet()) { + for (TCComponentItemRevision parentRev : usedFilter(usedComps)) { +// TCComponentItemRevision parentRev = entry.getValue(); + String parentString = parentRev.getProperty("object_string"); + TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + TCComponentBOMWindow win = winType.create(null); + TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null); + winMap.put(parentString, win); + AIFComponentContext[] aifs = topLine.getChildren(); + for (AIFComponentContext aif : aifs) { + TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent(); + if (revString.equals(child.getItemRevision().getProperty("object_string"))) { + + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + + Object[] rowData = new Object[] { new JCheckBox(), parentString, revString, unit, num, status }; + rowPrint(rowData); + tableDataList.add(rowData); + tableDataMap.put(parentString, + new BOMManageTableBean(parentString, revString, parentRev, targetRev, topLine, child)); + // TODO bomһchildܻ쳣ֻӰһ + break; + } + } + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + if (tableDataList == null || tableDataList.size() == 0) { + JOptionPane.showMessageDialog($this, "ҵӦ󣬵öûκװװöľ°汾ȷϱǷȷ", "ʾ", + JOptionPane.WARNING_MESSAGE); + return; + } + + for (Object[] rowData : tableDataList) { + model.addRow(rowData); + } + table.revalidate(); + table.repaint(); + System.out.println("װʾɣʱ" + (System.currentTimeMillis() - startTime) + "ms"); + } + + private MouseAdapter showTree(JPanel panelRight) { + return new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + JTable table = (JTable) e.getSource(); + String parentString = table.getValueAt(table.getSelectedRow(), 1).toString(); + System.out.println("select row=====>" + table.getSelectedRow()); + System.out.println("parentName=====>" + parentString); + CustomLovBean lovBean = null; + try { + lovBean = new CustomLovBean(tableDataMap.get(parentString).getChildString()); + CustomLovBean subBean = new CustomLovBean(parentString); + lovBean.addSub(subBean); + getTreeData(tableDataMap.get(parentString).getParentRev(), subBean); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + panelRight.removeAll(); + JTree tree = createTree(lovBean); + JScrollPane treePanel = new JScrollPane(tree); + treePanel.setBounds(20, 130, 360, 500); + panelRight.add(treePanel); + panelRight.revalidate(); + panelRight.repaint(); + } + } + }; + } + + private void getTreeData(TCComponent rev, CustomLovBean lov) throws TCException { + TCComponent[] comps = rev.whereUsed((short) 0); + if (comps == null || comps.length == 0) { + return; + } + for (TCComponent comp : comps) { + CustomLovBean sub = new CustomLovBean(comp.getProperty("object_string")); + System.out.println(sub.displayName); + lov.addSub(sub); + getTreeData(comp, sub); + } + } + + private void clearTable(JTable table, JCheckBox selectAll) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + int cnt = model.getRowCount(); + for (int i = 0; i < cnt; i++) { + model.removeRow(0); + } + table.revalidate(); + table.repaint(); + if (selectAll != null) { + selectAll.setSelected(false); + } + tableDataMap.clear(); + addedBOMLine.clear(); + try { + closeWin(); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private JTree createTree(CustomLovBean lovData) { + if (lovData == null || "".equals(lovData.displayName)) { + return new JTree(); + } + DefaultMutableTreeNode root = new DefaultMutableTreeNode(lovData.displayName); + DefaultMutableTreeNode parent = root; + DefaultTreeModel treeModel = new DefaultTreeModel(root); + + initTree(lovData, parent, treeModel); + + JTree tree = new JTree(treeModel); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); + cellRenderer.setTextNonSelectionColor(Color.black); + cellRenderer.setTextSelectionColor(Color.blue); + return tree; + } + + private void initTree(CustomLovBean lovData, DefaultMutableTreeNode parent, DefaultTreeModel treeModel) { + if (!lovData.hasChild()) { + return; + } + List subList = lovData.getSub(); + for (CustomLovBean sub : subList) { + DefaultMutableTreeNode temp = new DefaultMutableTreeNode(sub.displayName); + treeModel.insertNodeInto(temp, parent, parent.getChildCount()); + initTree(sub, temp, treeModel); + } + } + + private ItemListener selectAll(JTable table) { + return new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + // TODO Auto-generated method stub + boolean select = ((JCheckBox) e.getSource()).isSelected(); + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox checkBox = (JCheckBox) table.getValueAt(i, 0); + checkBox.setSelected(select); + table.revalidate(); + table.repaint(); + } + } + }; + } + + private ActionListener cancel() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + $this.dispose(); + } + }; + } + + private ActionListener batchRevise(JTable table, JCheckBox selectAll) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List selectedRowList = getselectedRow(table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkAccess(selectedRowList).isRes()) { + return; + } + List msgData = new ArrayList(); + for (int i = 0; i < selectedRowList.size(); i++) { + try { + TCComponentItemRevision newRev = selectedRowList.get(i).getParentRev().saveAs(null); + String parentString = newRev.getProperty("object_string"); + selectedRowList.get(i).setParentRev(newRev); + selectedRowList.get(i).setParentString(parentString); + msgData.add(new String[] { msgData.size() + 1 + "", selectedRowList.get(i).getParentString(), + newRev.getProperty("object_string"), "ɹ" }); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); +// JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + msgData.add(new String[] { msgData.size() + 1 + "", selectedRowList.get(i).getParentString(), + "", "ʧܣ" + e1.getMessage() }); + } + } + +// showWhereUesd(table, selectAll); + updateSelectedRow(table, selectedRowList); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "汾(ǰ)", "汾()", "" }, + msgData).panel; + JOptionPane.showMessageDialog($this, jsp, "", JOptionPane.PLAIN_MESSAGE); + } + }; + } + + private List usedFilter(TCComponent[] comps) throws TCException { +// Map sameParentUsedMap = new HashMap(); + List list = new ArrayList<>(); + for (TCComponent comp : comps) { + if (comp instanceof TCComponentItemRevision) { + TCComponentItemRevision rev = (TCComponentItemRevision) comp; +// String itemId; +// if (sameParentUsedMap.containsKey(itemId = comp.getProperty("item_id"))) { +// if (sameParentUsedMap.get(itemId).getProperty("item_revision_id") +// .compareTo(comp.getProperty("item_revision_id")) < 0) { +// sameParentUsedMap.put(itemId, rev); +// } +// } else { + if (rev.getItem().getLatestItemRevision().getUid().equals(rev.getUid())) { + list.add(rev); + } +// sameParentUsedMap.put(itemId, rev); +// } + } + } + return list; + } + + private void createLogDataSourceTable() { + if (isLogcreated) { + return; + } + String sql1 = "CREATE TABLE JD2_BOMManageLog ( id NUMBER ( 38, 0 ) primary key, modify_user VARCHAR2 ( 200 ), modify_time DATE, modify_content VARCHAR2 ( 500 ))"; + String sql2 = "CREATE sequence JD2_BOMManageLog_seq minvalue 1 maxvalue 99999999 INCREMENT BY 1 START WITH 1"; + String sql3 = "CREATE OR REPLACE TRIGGER JD2_BOMManageLog_tri before INSERT ON JD2_BOMManageLog FOR each ROW BEGIN SELECT JD2_BOMManageLog_seq.nextval INTO : new.id FROM dual; END;"; + try { + List temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("user_tables", + new Condition("table_name", "JD2_BOMMANAGELOG")); + if (temp == null || temp.size() == 0) { + Db.use(DBUtil.getDataSource(session)).execute(sql1); + System.out.println("JD2_BOMMANAGELOG create success"); + } + temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("user_sequences", + new Condition("sequence_name", "JD2_BOMMANAGELOG_SEQ")); + if (temp == null || temp.size() == 0) { + Db.use(DBUtil.getDataSource(session)).execute(sql2); + System.out.println("JD2_BOMMANAGELOG_SEQ create success"); + } + temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("all_triggers", + new Condition("trigger_name", "JD2_BOMMANAGELOG_TRI")); + if (temp == null || temp.size() == 0) { + DBConnectionUtil.dbConn(session).createStatement().execute(sql3); + System.out.println("JD2_BOMManageLog_tri create success"); + } + isLogcreated = true; + System.out.println("init log success"); + } catch (Exception e) { + // TODO Auto-generated catch block + JOptionPane.showMessageDialog($this, "ݿʧܣѡjd2_db_settings", "", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + } + } + + private ActionListener searchLog() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String username = p5UserText.getText().trim(); + String content = p5ContentText.getText(); + if (username == null || "".equals(username)) { + return; + } + + String sql = "select * from JD2_BOMMANAGELOG where "; + if (!"*".equals(username)) { + sql += "modify_user like '%" + username + "%' and"; + } + sql += " modify_time between to_date('" + p5TimeStartText.getText() + + " 00:00:00','yyyy-MM-dd hh24:mi:ss') and to_date('" + p5TimeEndText.getText() + + " 23:59:59','yyyy-MM-dd hh24:mi:ss')"; + if (content != null && !"".equals(content)) { + sql += " and modify_content like '%" + content + "%'"; + } + sql += "order by MODIFY_TIME asc"; + System.out.println(sql); + try { + logDataList = Db.use(DBUtil.getDataSource(session)).query(sql); + System.out.println("log size=====>" + logDataList.size()); + DefaultTableModel model = (DefaultTableModel) p5Table.getModel(); + for (Entity entity : logDataList) { + Object[] objArr = new Object[] { entity.get("ID"), entity.get("MODIFY_USER"), + entity.get("MODIFY_TIME"), entity.get("MODIFY_CONTENT") }; + model.addRow(objArr); + } + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return; + } + p5Table.revalidate(); + p5Table.repaint(); + } + }; + } + + private ItemListener downloadLog(JTable table) { + return new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent paramItemEvent) { + // TODO Auto-generated method stub + if (paramItemEvent.getStateChange() == ItemEvent.DESELECTED) { + return; + } + String selectItem = ((JComboBox) paramItemEvent.getSource()).getSelectedItem().toString(); + System.out.println(selectItem); + if (!selectItem.contains("txt") && !selectItem.contains("excel")) { + return; + } + if (table.getRowCount() > 0) { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setMultiSelectionEnabled(false); + chooser.setCurrentDirectory(FileSystemView.getFileSystemView().getHomeDirectory()); + chooser.showOpenDialog($this); + File folder = chooser.getSelectedFile(); + if (folder == null) { + p5Download.setSelectedItem("־"); + return; + } + String fileName = ""; + if (selectItem.contains("txt")) { + FileWriter fileWriter = null; + fileName = "BOM־-" + new SimpleDateFormat("yyyyMMddHHmm").format(new Date()) + ".txt"; + try { + fileWriter = new FileWriter(folder.getPath() + File.separator + fileName);// ıļ + String temp; + System.out.println(logDataList.size()); + for (Entity entity : logDataList) { + fileWriter.write((temp = entity.get("ID").toString()) + + StringCreateUtil.createBlank(10 - temp.length()) + + (temp = entity.get("MODIFY_USER").toString()) + + StringCreateUtil.createBlank(20 - temp.length()) + + (temp = entity.get("MODIFY_TIME").toString()) + + StringCreateUtil.createBlank(30 - temp.length()) + + entity.get("MODIFY_CONTENT").toString() + "\r\n"); + } + fileWriter.flush(); + fileWriter.close(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return; + } + } else { + fileName = "BOM־-" + new SimpleDateFormat("yyyyMMddHHmm").format(new Date()) + ".xlsx"; + String[] header = new String[] { "", "޸û", "ʱ", "" }; + List data = new ArrayList<>(); + System.out.println(logDataList.size()); + for (Entity entity : logDataList) { + data.add(new String[] { entity.get("ID").toString(), entity.get("MODIFY_USER").toString(), + entity.get("MODIFY_TIME").toString(), entity.get("MODIFY_CONTENT").toString() }); + } + SimpleExcelUtil.exportExcel(folder.getPath() + File.separator + fileName, header, data); + + } + + JOptionPane.showMessageDialog($this, "־ɹ\r\n·" + folder + File.separator + fileName, "ʾ", + JOptionPane.WARNING_MESSAGE); + p5Download.setSelectedItem("־"); + } + } + }; + + } + + private ActionListener batchReplace() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p1NumText.getText().trim(); + //String text = p1UnitCombo.getSelectedText().trim(); + // Object value = p1UnitCombo.getSelectedValue(); + System.out.println(numStr); +// if ("".equals(numStr) || "".equals(text) || targetRev2 == null) { +// JOptionPane.showMessageDialog($this, "δдϢд", "ʾ", JOptionPane.WARNING_MESSAGE); +// return; +// } + List selectedRowList = getselectedRow(p1Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + L1: for (int i = 0; i < selectedRowList.size(); i++) { + try { + doIndex++; + BOMManageTableBean bean = selectedRowList.get(i); + // System.out.println(value.toString()); + if (!addedBOMLine.add(bean.getParentRev().getUid() + targetRev2.getUid())) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), targetRev2.getProperty("object_string"), + numStr, "ʧܣ滻һΣ滻" }); + continue L1; + } + AIFComponentContext[] aifs = bean.getParentLine().getChildren(); + for (AIFComponentContext aif : aifs) { + String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision() + .getProperty("object_string"); + if (objStr.equals(targetRev2.getProperty("object_string"))) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), targetRev2.getProperty("object_string"), + numStr, "ʧܣѴͬӼ" }); + continue L1; + } + } + String seq = selectedRowList.get(i).getChildLine().getProperty("bl_sequence_no"); + bean.getParentLine().remove("", bean.getChildLine()); + TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null, + false, ""); + // childLine.setReferenceProperty("bl_uom", (TCComponent) value); + childLine.setProperties(new String[] { "bl_quantity", "bl_sequence_no" }, + new String[] { numStr, seq }); + msgData.add( + new String[] { msgData.size() + 1 + "", bean.getParentString(), bean.getChildString(), + targetRev2.getProperty("object_string"), numStr, "ɹ" }); + selectedRowList.get(i).setChildString(targetRev2.getProperty("object_string")); + selectedRowList.get(i).setChildRev(targetRev2); + selectedRowList.get(i).setChildLine(childLine); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("滻ִϣʱ" + (endTime - startTime) + "ms"); + //doLog("滻", msgData); + JScrollPane jsp = DialogUtil + .createTableMsg(new String[] { "", "", "ԭӼ", "滻Ӽ", "λ", "", "" }, msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "滻 ɹ(" + getResultNum(msgData, true) + ") ʧ(" + + getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); + updateSelectedRow2(p1Table, selectedRowList); + } + }; + } + + private ActionListener batchModify() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p2NumText.getText(); + List selectedRowList = getselectedRow(p2Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + for (BOMManageTableBean bean : selectedRowList) { + String oldNumStr = ""; + try { + doIndex++; + oldNumStr = bean.getChildLine().getProperty("bl_quantity"); + bean.getChildLine().setProperties(new String[] { "bl_quantity" }, new String[] { numStr }); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), oldNumStr, numStr, "ɹ" }); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("ִϣʱ" + (endTime - startTime) + "ms"); + //doLog("޸", msgData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "", "Ӽ", "ԭ", "", "" }, + msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "Ľ ɹ(" + getResultNum(msgData, true) + ") ʧ(" + + getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); + updateSelectedRow(p2Table, selectedRowList); + } + }; + } + + private ActionListener batchAdd() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p3NumText.getText().trim(); + String text = p3UnitCombo.getSelectedText().trim(); + Object value = p3UnitCombo.getSelectedValue(); + System.out.println(numStr); + if ("".equals(numStr) || "".equals(text) || targetRev2 == null) { + JOptionPane.showMessageDialog($this, "δдϢд", "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } + List selectedRowList = getselectedRow(p3Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + L1: for (BOMManageTableBean bean : selectedRowList) { + try { + doIndex++; + System.out.println(value.toString()); + if (!addedBOMLine.add(bean.getParentRev().getUid() + targetRev2.getUid())) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, + "ʧܣӹһΣظ" }); + continue L1; + } + AIFComponentContext[] aifs = bean.getParentLine().getChildren(); + for (AIFComponentContext aif : aifs) { + String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision() + .getProperty("object_string"); + if (objStr.equals(targetRev2.getProperty("object_string"))) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, + "ʧܣѴͬӼ" }); + continue L1; + } + } + TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null, + false, ""); + childLine.setReferenceProperty("bl_uom", (TCComponent) value); + childLine.setProperties(new String[] { "bl_quantity" }, new String[] { numStr }); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, "ɹ" }); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("ִϣʱ" + (endTime - startTime) + "ms"); + //doLog("", msgData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "", "Ӽ", "λ", "", "" }, + msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, " ɹ(" + getResultNum(msgData, true) + ") ʧ(" + + getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); +// showWhereUesd(p3Table, p3SelectAll); + } + }; + } + + private ActionListener batchRemove() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List selectedRowList = getselectedRow(p4Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + for (BOMManageTableBean bean : selectedRowList) { + try { + doIndex++; + if (bean.getChildLine() == null) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), "bomLineڣѾɹɾ" }); + } else { + bean.getParentLine().remove("", bean.getChildLine()); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), "ɹ" }); + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("ɾִϣʱ" + (endTime - startTime) + "ms"); + //doLog("ɾ", msgData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "", "ɾӼ", "" }, msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "ɾ ɹ(" + getResultNum(msgData, true) + ") ʧ(" + + getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); +// removeSelectRow(p4Table); + updateSelectedRow3(p4Table, selectedRowList); + } + }; + } + + private List getselectedRow(JTable table) { + List selectedList = new ArrayList(); + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + System.out.println("select=====>" + table.getValueAt(i, 1)); + selectedList.add(tableDataMap.get(table.getValueAt(i, 1))); + } + } + return selectedList; + } + + private void updateSelectedRow(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + try { + TCComponentItemRevision parentRev = newRowData.get(index).getParentRev(); + String parentString = newRowData.get(index).getParentString(); + TCComponentBOMWindow win = winType.create(null); + TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null); + winMap.get(table.getValueAt(i, 1).toString()).close(); + winMap.remove(table.getValueAt(i, 1)); + winMap.put(parentString, win); + tableDataMap.remove(table.getValueAt(i, 1).toString()); + TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + AIFComponentContext[] aifs = topLine.getChildren(); + for (AIFComponentContext aif : aifs) { + TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent(); + if (newRowData.get(index).getChildString() + .equals(child.getItemRevision().getProperty("object_string"))) { + + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + + JCheckBox selected = new JCheckBox(); + selected.setSelected(true); + Object[] rowData = new Object[] { selected, parentString, + newRowData.get(index).getChildString(), unit, num, status }; + rowPrint(rowData); + for (int ii = 0; ii < rowData.length; ii++) { + table.setValueAt(rowData[ii], i, ii); + } + tableDataMap.put(parentString, new BOMManageTableBean(parentString, + newRowData.get(index).getChildString(), parentRev, targetRev, topLine, child)); + break; + } + } + index++; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + table.revalidate(); + table.repaint(); + } + + private void updateSelectedRow2(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + BOMManageTableBean bean = newRowData.get(index); + try { + TCComponentBOMLine child = bean.getChildLine(); + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + table.setValueAt(bean.getChildString(), i, 2); + table.setValueAt(unit, index, 3); + table.setValueAt(num, index, 4); + tableDataMap.get(bean.getParentString()).setChildRev(bean.getChildRev()); + tableDataMap.get(bean.getParentString()).setChildString(bean.getChildString()); + tableDataMap.get(bean.getParentString()).setChildLine(child); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + index++; + } + } + table.revalidate(); + table.repaint(); + } + + private void updateSelectedRow3(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + BOMManageTableBean bean = newRowData.get(index); + table.setValueAt("", i, 2); + table.setValueAt("", index, 3); + table.setValueAt("", index, 4); + tableDataMap.get(bean.getParentString()).setChildLine(null); + index++; + } + } + table.revalidate(); + table.repaint(); + } + + private void removeSelectRow(JTable table) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + int i = 0; + while (i < table.getRowCount()) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + model.removeRow(i); + continue; + } + i++; + } + table.revalidate(); + table.repaint(); + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + new Thread(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + try { + closeWin(); + System.out.println("closed"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }).start(); + + super.dispose(); + } + + private void saveWin() throws TCException { + for (Entry entry : winMap.entrySet()) { + if (entry.getValue() != null) { + entry.getValue().save(); + } + + } + } + + private void closeWin() throws TCException { + saveWin(); + + for (Entry entry : winMap.entrySet()) { + entry.getValue().close(); + } + winMap.clear(); + } + + private void doLog(String operation, List msgData) { + createLogDataSourceTable(); + String content = ""; + if ("滻".equals(operation)) { + content = "%sӼ%s滻Ϊ%s;%s;%s"; + } else if ("޸".equals(operation)) { + content = "%sӼ%s%sΪ%s"; + } else if ("".equals(operation)) { + content = "%sӼ%s;%s;%s"; + } else if ("ɾ".equals(operation)) { + content = "%sɾӼ%s"; + } + String username = ""; + try { + username = session.getUser().getUserName() + "(" + session.getUser().getUserId() + ")"; + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + String datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + + List sqls = new ArrayList(); + int num = StrUtil.count(content, "%s"); + for (String[] arr : msgData) { + String temp; + String[] row = new String[num]; + for (int i = 0; i < num; i++) { + row[i] = arr[i + 1]; + } + temp = String.format(content, row); + String sql = "insert into JD2_BOMMANAGELOG (MODIFY_USER,MODIFY_TIME,MODIFY_CONTENT) VALUES ('" + username + + "',to_date('" + datetime + "','yyyy-MM-dd hh24:mi:ss'),'" + temp + "')"; + sqls.add(sql); + } + + try { + Db.use(DBUtil.getDataSource(session)).executeBatch(sqls.toArray(new String[sqls.size()])); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private ActionListener clickSearch(JTable table, JCheckBox selectAll) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + JDialog content = DialogUtil.createSearchAndSelectRevDialog($this, table, selectAll, + (JButton) e.getSource()); + } + }; + } + + public void okCallback(JTable revTable, JTable table, JCheckBox selectAll, JButton field) { + // TODO Auto-generated method stub + int rowIndex = revTable.getSelectedRow(); + if (rowIndex < 0) { + return; + } + String text = revTable.getValueAt(rowIndex, 0).toString(); + System.out.println(text); + field.setText(text); + if ("".equals(text)) { + return; + } + if (table != null) { + targetRev = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5); + showWhereUesd(table, selectAll); + } else { + targetRev2 = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5); + } + } + + private KeyAdapter logSearchEnter() { + return new KeyAdapter() { + @Override + public void keyTyped(KeyEvent e) { + // TODO Auto-generated method stub + super.keyTyped(e); + if (e.getKeyChar() == KeyEvent.VK_ENTER) { + p5Search.doClick(); + } + } + }; + } + + private void updateTitleShowProgress(List list) { + new Thread(new Runnable() { + + @Override + public void run() { + int num = 1; + String temp; + doIndex = 0; + while (!complate) { + $this.setTitle("ڴ" + (temp = StringCreateUtil.createPoint(num % 3)) + + StringCreateUtil.createBlank(5 - temp.length()) + list.get(doIndex).getParentString() + + " " + (doIndex + 1) + "/" + list.size()); + try { + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + num++; + } + $this.setTitle("BOM"); + doIndex = -1; + complate = false; + } + }).start(); + } + + private boolean checkReleaseStatus(TCComponentItemRevision rev) { + try { + System.out.println("item type======>" + rev.getItem().getType()); + if (checkItemType.contains(rev.getItem().getType())) { + return true; + } + //TCComponent form = rev.getRelatedComponents("IMAN_master_form_rev")[0]; + TCComponent[] statusArray = rev.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + if (status == null || "".equals(status)) { + return false; + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return true; + } + + private ResultData checkAccess(List data) { + for (BOMManageTableBean bean : data) { + boolean isAccess = true; + try { + isAccess = session.getTCAccessControlService().checkPrivilege(bean.getParentLine(), "WRITE"); + } catch (TCException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + } + if (!isAccess) { + try { + return new ResultData(false, "ǰûûж" + bean.getParentLine().getProperty("object_string") + "дȨ", + bean.getParentLine()); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return new ResultData(true, "", null); + } + + private boolean checkTargetAndSelect(TCComponentItemRevision rev, List data) { + if (!checkReleaseStatus(rev)) { + JOptionPane.showMessageDialog($this, "Ŀδߴڶ״̬޷BOM", "ʾ", JOptionPane.WARNING_MESSAGE); + return false; + } + ResultData res = checkAccess(data); + if (!res.isRes()) { + JOptionPane.showMessageDialog($this, res.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return false; + } + return true; + } + + private ActionListener startWorkFlow(JTable table) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List select = getselectedRow(table); + List parentRev = new ArrayList<>(); + for (BOMManageTableBean bean : select) { + parentRev.add(bean.getParentRev()); + } + $this.setExtendedState(JFrame.ICONIFIED); + NewProcessCommand command = new NewProcessCommand(AIFUtility.getActiveDesktop(), app, + parentRev.toArray(new TCComponentItemRevision[parentRev.size()])); + } + }; + } + + private void rowPrint(Object[] arr) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + for (Object obj : arr) { + if (obj instanceof JCheckBox) { + sb.append(((JCheckBox) obj).isSelected()); + } else { + sb.append(obj.toString()); + } + sb.append(","); + } + if (sb.length() > 1) { + sb.deleteCharAt(sb.length() - 1); + } + sb.append("]"); + System.out.println(sb.toString()); + } + + private void resize() { + double left = 2 * this.widthOffset / 3.0; + double right = this.widthOffset - left; + + int bottom1 = p1BottomBtn2.getX() - p1BottomBtn1.getX() - p1BottomBtn1.getWidth(); + int bottom2 = p1BottomBtn3.getX() - p1BottomBtn2.getX() - p1BottomBtn2.getWidth(); + int botttom3 = p1BottomBtn4.getX() - p1BottomBtn3.getX() - p1BottomBtn3.getWidth(); + + // p1 + int p1x1 = p1TargetBtn.getX() - p1TargetLabel.getX() - p1TargetLabel.getWidth(); + int p1x2 = p1ReplaceBtn.getX() - p1ReplaceLabel.getX() - p1ReplaceLabel.getWidth(); + int p1x3 = p1UnitLabel.getX() - p1ReplaceBtn.getX() - p1ReplaceBtn.getWidth(); + int p1x4 = p1NumLabel.getX() - p1UnitCombo.getX() - p1UnitCombo.getWidth(); + p1TargetLabel.setBounds(p1TargetLabel.getX() + getOffset(left, 20, 800), 20, + p1TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p1TargetBtn.setBounds(p1TargetLabel.getX() + p1TargetLabel.getWidth() + p1x1 + getOffset(left, 10, 800), 20, + p1TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p1ReplaceLabel.setBounds(p1ReplaceLabel.getX() + getOffset(left, 20, 800), 60, + p1ReplaceLabel.getWidth() + getOffset(left, 100, 800), 25); + p1ReplaceBtn.setBounds(p1ReplaceLabel.getX() + p1ReplaceLabel.getWidth() + p1x2 + getOffset(left, 10, 800), 60, + p1ReplaceBtn.getWidth() + getOffset(left, 400, 800), 25); + p1UnitLabel.setBounds(p1ReplaceBtn.getX() + p1ReplaceBtn.getWidth() + p1x3 + getOffset(left, 30, 800), 60, + p1UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p1UnitCombo.setBounds(p1UnitLabel.getX() + p1UnitLabel.getWidth(), 60, + p1UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p1NumLabel.setBounds(p1ReplaceBtn.getX() + p1ReplaceBtn.getWidth() + p1x3 + getOffset(left, 30, 800), 60, + p1UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p1NumText.setBounds(p1UnitLabel.getX() + p1UnitLabel.getWidth(), 60, + p1UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p1SelectAll.setBounds(p1SelectAll.getX() + getOffset(left, 20, 800), 100, + p1SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p1jsp.setBounds(p1jsp.getX() + getOffset(left, 20, 800), p1jsp.getY(), + p1jsp.getWidth() + getOffset(left, 760, 800), p1jsp.getHeight() + this.heightOffset); + p1BottomBtn1.setBounds(p1BottomBtn1.getX() + getOffset(left, 80, 800), p1BottomBtn1.getY() + this.heightOffset, + p1BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn2.setBounds(p1BottomBtn1.getX() + p1BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p1BottomBtn2.getY() + this.heightOffset, p1BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); +// p1BottomBtn3.setBounds(p1BottomBtn2.getX() + p1BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), +// p1BottomBtn3.getY() + this.heightOffset, p1BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn4.setBounds(p1BottomBtn2.getX() + p1BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p1BottomBtn3.getY() + this.heightOffset, p1BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p1Left.setBounds(0, 0, p1Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p1Left.getHeight() + this.heightOffset); + p1TreePanel.setBounds(p1TreePanel.getX() + getOffset(right, 20, 400), 130, + p1TreePanel.getWidth() + getOffset(right, 360, 400), p1TreePanel.getHeight() + this.heightOffset); + p1Right.setBounds(p1Left.getX() + p1Left.getWidth(), 0, + p1Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p1Right.getHeight() + this.heightOffset); + p1.revalidate(); + p1.repaint(); + + // p2 + int p2x1 = p2TargetBtn.getX() - p2TargetLabel.getX() - p2TargetLabel.getWidth(); + int p2x2 = p2NumText.getX() - p2ChangeNumLabel.getX() - p2ChangeNumLabel.getWidth(); + p2TargetLabel.setBounds(p2TargetLabel.getX() + getOffset(left, 20, 800), 20, + p2TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p2TargetBtn.setBounds(p2TargetLabel.getX() + p2TargetLabel.getWidth() + p2x1 + getOffset(left, 10, 800), 20, + p2TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p2ChangeNumLabel.setBounds(p2ChangeNumLabel.getX() + getOffset(left, 20, 800), 60, + p2ChangeNumLabel.getWidth() + getOffset(left, 100, 800), 25); + p2NumText.setBounds(p2ChangeNumLabel.getX() + p2ChangeNumLabel.getWidth() + p2x2 + getOffset(left, 10, 800), 60, + p2NumText.getWidth() + getOffset(left, 50, 800), 25); + p2SelectAll.setBounds(p2SelectAll.getX() + getOffset(left, 20, 800), 100, + p2SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p2jsp.setBounds(p2jsp.getX() + getOffset(left, 20, 800), p2jsp.getY(), + p2jsp.getWidth() + getOffset(left, 760, 800), p2jsp.getHeight() + this.heightOffset); + p2BottomBtn1.setBounds(p2BottomBtn1.getX() + getOffset(left, 80, 800), p2BottomBtn1.getY() + this.heightOffset, + p2BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn2.setBounds(p2BottomBtn1.getX() + p2BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p2BottomBtn2.getY() + this.heightOffset, p2BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn3.setBounds(p2BottomBtn2.getX() + p2BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p2BottomBtn3.getY() + this.heightOffset, p2BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn4.setBounds(p2BottomBtn3.getX() + p2BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p2BottomBtn4.getY() + this.heightOffset, p2BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p2Left.setBounds(0, 0, p2Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p2Left.getHeight() + this.heightOffset); + p2TreePanel.setBounds(p2TreePanel.getX() + getOffset(right, 20, 400), 130, + p2TreePanel.getWidth() + getOffset(right, 360, 400), p2TreePanel.getHeight() + this.heightOffset); + p2Right.setBounds(p2Left.getX() + p2Left.getWidth(), 0, + p2Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p2Right.getHeight() + this.heightOffset); + p2.revalidate(); + p2.repaint(); + + // p3 + int p3x1 = p3TargetBtn.getX() - p3TargetLabel.getX() - p3TargetLabel.getWidth(); + int p3x2 = p3AddBtn.getX() - p3AddLabel.getX() - p3AddLabel.getWidth(); + int p3x3 = p3UnitLabel.getX() - p3AddBtn.getX() - p3AddBtn.getWidth(); + int p3x4 = p3NumLabel.getX() - p3UnitCombo.getX() - p3UnitCombo.getWidth(); + p3TargetLabel.setBounds(p3TargetLabel.getX() + getOffset(left, 20, 800), 20, + p3TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p3TargetBtn.setBounds(p3TargetLabel.getX() + p3TargetLabel.getWidth() + p3x1 + getOffset(left, 10, 800), 20, + p3TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p3AddLabel.setBounds(p3AddLabel.getX() + getOffset(left, 20, 800), 60, + p3AddLabel.getWidth() + getOffset(left, 100, 800), 25); + p3AddBtn.setBounds(p3AddLabel.getX() + p3AddLabel.getWidth() + p3x2 + getOffset(left, 10, 800), 60, + p3AddBtn.getWidth() + getOffset(left, 400, 800), 25); + p3UnitLabel.setBounds(p3AddBtn.getX() + p3AddBtn.getWidth() + p3x3 + getOffset(left, 30, 800), 60, + p3UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p3UnitCombo.setBounds(p3UnitLabel.getX() + p3UnitLabel.getWidth(), 60, + p3UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p3NumLabel.setBounds(p3UnitCombo.getX() + p3UnitCombo.getWidth() + p3x4 + getOffset(left, 20, 800), 60, + p3NumLabel.getWidth() + getOffset(left, 50, 800), 25); + p3NumText.setBounds(p3NumLabel.getX() + p3NumLabel.getWidth(), 60, + p3NumText.getWidth() + getOffset(left, 50, 800), 25); + p3SelectAll.setBounds(p3SelectAll.getX() + getOffset(left, 20, 800), 100, + p3SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p3jsp.setBounds(p3jsp.getX() + getOffset(left, 20, 800), p3jsp.getY(), + p3jsp.getWidth() + getOffset(left, 760, 800), p3jsp.getHeight() + this.heightOffset); + p3BottomBtn1.setBounds(p3BottomBtn1.getX() + getOffset(left, 80, 800), p3BottomBtn1.getY() + this.heightOffset, + p3BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn2.setBounds(p3BottomBtn1.getX() + p3BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p3BottomBtn2.getY() + this.heightOffset, p3BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn3.setBounds(p3BottomBtn2.getX() + p3BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p3BottomBtn3.getY() + this.heightOffset, p3BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn4.setBounds(p3BottomBtn3.getX() + p3BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p3BottomBtn4.getY() + this.heightOffset, p3BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p3Left.setBounds(0, 0, p3Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p3Left.getHeight() + this.heightOffset); + p3TreePanel.setBounds(p3TreePanel.getX() + getOffset(right, 20, 400), 130, + p3TreePanel.getWidth() + getOffset(right, 360, 400), p3TreePanel.getHeight() + this.heightOffset); + p3Right.setBounds(p3Left.getX() + p3Left.getWidth(), 0, + p3Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p3Right.getHeight() + this.heightOffset); + p3.revalidate(); + p3.repaint(); + + // p4 + int p4x1 = p4TargetBtn.getX() - p4TargetLabel.getX() - p4TargetLabel.getWidth(); + p4TargetLabel.setBounds(p4TargetLabel.getX() + getOffset(left, 20, 800), 20, + p4TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p4TargetBtn.setBounds(p4TargetLabel.getX() + p4TargetLabel.getWidth() + p4x1 + getOffset(left, 10, 800), 20, + p4TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p4SelectAll.setBounds(p4SelectAll.getX() + getOffset(left, 20, 800), 100, + p4SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p4jsp.setBounds(p4jsp.getX() + getOffset(left, 20, 800), p4jsp.getY(), + p4jsp.getWidth() + getOffset(left, 760, 800), p4jsp.getHeight() + this.heightOffset); + p4BottomBtn1.setBounds(p4BottomBtn1.getX() + getOffset(left, 80, 800), p4BottomBtn1.getY() + this.heightOffset, + p4BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn2.setBounds(p4BottomBtn1.getX() + p4BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p4BottomBtn2.getY() + this.heightOffset, p4BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn3.setBounds(p4BottomBtn2.getX() + p4BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p4BottomBtn3.getY() + this.heightOffset, p4BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn4.setBounds(p4BottomBtn3.getX() + p4BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p4BottomBtn4.getY() + this.heightOffset, p4BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p4Left.setBounds(0, 0, p4Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p4Left.getHeight() + this.heightOffset); + p4TreePanel.setBounds(p4TreePanel.getX() + getOffset(right, 20, 400), 130, + p4TreePanel.getWidth() + getOffset(right, 360, 400), p4TreePanel.getHeight() + this.heightOffset); + p4Right.setBounds(p4Left.getX() + p4Left.getWidth(), 0, + p4Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p4Right.getHeight() + this.heightOffset); + p4.revalidate(); + p4.repaint(); + + // p5 + int p5x1 = p5UserText.getX() - p5UserLabel.getX() - p5UserLabel.getWidth(); + int p5x2 = p5TimeLabel.getX() - p5UserText.getX() - p5UserText.getWidth(); + int p5x3 = p5TimeStartText.getX() - p5TimeLabel.getX() - p5TimeLabel.getWidth(); + int p5x4 = toLabel.getX() - p5TimeStartText.getX() - p5TimeStartText.getWidth(); + int p5x5 = p5TimeEndText.getX() - toLabel.getX() - toLabel.getWidth(); + int p5x6 = p5ContentLabel.getX() - p5TimeEndText.getX() - p5TimeEndText.getWidth(); + int p5x7 = p5Contentjsp.getX() - p5ContentLabel.getX() - p5ContentLabel.getWidth(); + int p5x8 = p5Search.getX() - p5Contentjsp.getX() - p5Contentjsp.getWidth(); + int p5x9 = p5Download.getX() - p5Search.getX() - p5Search.getWidth(); + p5UserLabel.setBounds(p5UserLabel.getX(), 40, p5UserLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), + 25); + p5UserText.setBounds(p5UserLabel.getX() + p5UserLabel.getWidth() + p5x1 + getOffset(this.widthOffset, 10, 1200), + 40, p5UserText.getWidth() + getOffset(this.widthOffset, 150, 1200), 25); + p5TimeLabel.setBounds(p5UserText.getX() + p5UserText.getWidth() + p5x2 + getOffset(this.widthOffset, 50, 1200), + 40, p5TimeLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25); + p5TimeStartText.setBounds( + p5TimeLabel.getX() + p5TimeLabel.getWidth() + p5x3 + getOffset(this.widthOffset, 10, 1200), 40, + p5TimeStartText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + toLabel.setBounds( + p5TimeStartText.getX() + p5TimeStartText.getWidth() + p5x4 + getOffset(this.widthOffset, 10, 1200), 40, + toLabel.getWidth() + getOffset(this.widthOffset, 20, 1200), 25); + p5TimeEndText.setBounds(toLabel.getX() + toLabel.getWidth() + p5x5 + getOffset(this.widthOffset, 10, 1200), 40, + p5TimeEndText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + p5ContentLabel.setBounds( + p5TimeEndText.getX() + p5TimeEndText.getWidth() + p5x6 + getOffset(this.widthOffset, 50, 1200), 40, + p5ContentLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25); + p5Contentjsp.setBounds( + p5ContentLabel.getX() + p5ContentLabel.getWidth() + p5x7 + getOffset(this.widthOffset, 10, 1200), 20, + p5Contentjsp.getWidth() + getOffset(this.widthOffset, 200, 1200), 80); + p5Search.setBounds(p5Contentjsp.getX() + p5Contentjsp.getWidth() + p5x8 + getOffset(this.widthOffset, 50, 1200), + 40, p5Search.getWidth() + getOffset(this.widthOffset, 60, 1200), 25); + p5Download.setBounds(p5Search.getX() + p5Search.getWidth() + p5x9 + getOffset(this.widthOffset, 20, 1200), 40, + p5Download.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + p5jsp.setBounds(p5jsp.getX() + getOffset(this.widthOffset, 20, 1200), p5jsp.getY(), + p5jsp.getWidth() + getOffset(this.widthOffset, 1160, 1200), p5jsp.getHeight() + this.heightOffset); + p5.revalidate(); + p5.repaint(); + } + + private int getOffset(double num1, int num2, int num3) { + return (int) (num1 * num2 / num3); + } + + private int getResultNum(List msgData, boolean success) { + int num = 0; + String str = success ? "ɹ" : "ʧ"; + for (String[] row : msgData) { + if (row[row.length - 1].contains(str)) { + num++; + } + } + return num; + } +} diff --git a/src/com/connor/jd/plm/dialogs/BOMManagementFrame20200826改log格式.txt b/src/com/connor/jd/plm/dialogs/BOMManagementFrame20200826改log格式.txt new file mode 100644 index 0000000..93f6146 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/BOMManagementFrame20200826改log格式.txt @@ -0,0 +1,2145 @@ +package com.connor.jd.plm.dialogs; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.Vector; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.RowSorter; +import javax.swing.filechooser.FileSystemView; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableRowSorter; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; + +import com.connor.jd.plm.beans.BOMLogBean; +import com.connor.jd.plm.beans.BOMManageTableBean; +import com.connor.jd.plm.beans.CheckBoxPo; +import com.connor.jd.plm.beans.CustomLovBean; +import com.connor.jd.plm.beans.ResultData; +import com.connor.jd.plm.table.MyCellEditor4; +import com.connor.jd.plm.table.MyCellRenderer; +import com.connor.jd.plm.utils.DBConnectionUtil; +import com.connor.jd.plm.utils.DBUtil; +import com.connor.jd.plm.utils.DatePickerUtil; +import com.connor.jd.plm.utils.DialogUtil; +import com.connor.jd.plm.utils.JDMethodUtil; +import com.connor.jd.plm.utils.KeyValComboBox; +import com.connor.jd.plm.utils.StringCreateUtil; +import com.eltima.components.ui.DatePicker; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCTypeService; +import com.teamcenter.rac.workflow.commands.newprocess.NewProcessCommand; + +import cn.hutool.db.Db; +import cn.hutool.db.Entity; +import cn.hutool.db.sql.Condition; + +public class BOMManagementFrame extends JFrame { + private AbstractAIFApplication app; + private TCSession session; + private CardLayout rootSwitch = new CardLayout(); + private String[] colDisplayNames = new String[] { "ѡ", "", "Ӽ", "λ", "", "״̬" }; + private String[] colDisplayNames2 = new String[] { "", "޸û", "ʱ", "" }; + private JPanel root; + private Map tableDataMap = new HashMap(); + private BOMManagementFrame $this; + private List logDataList; + private Map winMap = new HashMap(); + private TCComponentItemRevision targetRev; + private TCComponentItemRevision targetRev2; + private boolean isLogcreated = false; + private int doIndex = 0; + private boolean complate = false; + private List checkItemType = new ArrayList(); + private JButton[] topBtns; + private TCComponentBOMWindowType winType; + private int width = 1200; + private int height = 800; + private int widthOffset = 0; + private int heightOffset = 0; + private JLabel p1TargetLabel; + private JButton p1TargetBtn; + private JLabel p1ReplaceLabel; + private JButton p1ReplaceBtn; + private JLabel p1UnitLabel; + private KeyValComboBox p1UnitCombo; + private JLabel p1NumLabel; + private JTextField p1NumText; + private JCheckBox p1SelectAll; + private JTable p1Table; + private JScrollPane p1jsp; + private JButton p1BottomBtn1; + private JButton p1BottomBtn2; + private JButton p1BottomBtn3; + private JButton p1BottomBtn4; + private JPanel p1Left; + private JScrollPane p1TreePanel; + private JPanel p1Right; + private JLabel p2TargetLabel; + private JButton p2TargetBtn; + private JLabel p2ChangeNumLabel; + private JTextField p2NumText; + private JCheckBox p2SelectAll; + private JTable p2Table; + private JScrollPane p2jsp; + private JButton p2BottomBtn1; + private JButton p2BottomBtn2; + private JButton p2BottomBtn3; + private JButton p2BottomBtn4; + private JPanel p2Left; + private JScrollPane p2TreePanel; + private JPanel p2Right; + private JLabel p3TargetLabel; + private JButton p3TargetBtn; + private JLabel p3AddLabel; + private JButton p3AddBtn; + private JLabel p3UnitLabel; + private KeyValComboBox p3UnitCombo; + private JLabel p3NumLabel; + private JTextField p3NumText; + private JCheckBox p3SelectAll; + private JTable p3Table; + private JScrollPane p3jsp; + private JButton p3BottomBtn1; + private JButton p3BottomBtn2; + private JButton p3BottomBtn3; + private JButton p3BottomBtn4; + private JPanel p3Left; + private JScrollPane p3TreePanel; + private JPanel p3Right; + private JLabel p4TargetLabel; + private JButton p4TargetBtn; + private JCheckBox p4SelectAll; + private JTable p4Table; + private JScrollPane p4jsp; + private JButton p4BottomBtn1; + private JButton p4BottomBtn2; + private JButton p4BottomBtn3; + private JButton p4BottomBtn4; + private JPanel p4Left; + private JScrollPane p4TreePanel; + private JPanel p4Right; + private JLabel p5UserLabel; + private JTextField p5UserText; + private JLabel p5TimeLabel; + private DatePicker p5TimeStartText; + private JLabel toLabel; + private DatePicker p5TimeEndText; + private JLabel p5ContentLabel; + private JTextArea p5ContentText; + private JScrollPane p5Contentjsp; + private JButton p5Search; + private JButton p5Download; + private JTable p5Table; + private JScrollPane p5jsp; + private Map uiSize = new HashMap<>(); + private JPanel p1; + private JPanel p2; + private JPanel p3; + private JPanel p4; + private JPanel p5; + private Set addedBOMLine = new HashSet<>(); + + public BOMManagementFrame(AbstractAIFApplication app) { + super(); + this.app = app; + this.session = (TCSession) app.getSession(); + $this = this; + String[] prefArray = JDMethodUtil.getPrefStrArray("connor_bom_check_type", session); + if (prefArray != null) { + checkItemType = Arrays.asList(prefArray); + } + TCTypeService service = session.getTypeService(); + try { + this.winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + init(); + } + + private void init() { + this.setTitle("BOM"); + this.setSize(new Dimension(1200, 800)); + this.setLayout(new BorderLayout()); + this.setResizable(true); + this.setAlwaysOnTop(true); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setLocationRelativeTo(null); + this.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + // TODO Auto-generated method stub + super.componentResized(e); + Component comp = e.getComponent(); + $this.widthOffset = comp.getWidth() - $this.width; + $this.heightOffset = comp.getHeight() - $this.height; + if ($this.widthOffset != 0 || $this.heightOffset != 0) { + System.out.println("width===>" + comp.getWidth()); + System.out.println("height===>" + comp.getHeight()); + $this.width = comp.getWidth(); + $this.height = comp.getHeight(); + $this.resize(); + } + } + }); + this.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void focusGained(FocusEvent e) { + // TODO Auto-generated method stub + $this.setAlwaysOnTop(true); + } + }); + + Container container = this.getContentPane(); + container.setLayout(new BorderLayout()); + container.setSize(new Dimension(1200, 800)); + + TCTypeService typeService = session.getTypeService(); + Vector unitVector = new Vector(); + try { + TCComponent[] uomArray = typeService.getTypeComponent("UnitOfMeasure").extent(); + unitVector.add(new CheckBoxPo(" ", " ")); + for (TCComponent comp : uomArray) { + unitVector.add(new CheckBoxPo(comp.toString(), comp)); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // ͷ + JPanel topBtnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + topBtns = new JButton[5]; + topBtns[0] = new JButton("滻"); + topBtns[1] = new JButton(""); + topBtns[2] = new JButton(""); + topBtns[3] = new JButton("ɾ"); + topBtns[4] = new JButton("־"); +// topBtns[5] = new JButton("԰ť"); + topBtns[0].setSelected(true); + for (JButton btn : topBtns) { + topBtnPanel.add(btn); + btn.addActionListener(panelSwitch()); + } + container.add(topBtnPanel, BorderLayout.NORTH); + + // root + root = new JPanel(rootSwitch); + + // 滻 + p1 = new JPanel(); + p1.setLayout(null); + + // 滻 + p1Left = new JPanel(); + p1Left.setLayout(null); + p1Left.setBounds(0, 0, 800, 800); + p1Left.setBorder(BorderFactory.createEtchedBorder()); + + p1TargetLabel = new JLabel("Ŀϱ"); + p1TargetLabel.setBounds(20, 20, 100, 25); + p1TargetBtn = new JButton(); + p1TargetBtn.setBounds(130, 20, 400, 25); + p1ReplaceLabel = new JLabel("滻ϱ"); + p1ReplaceLabel.setBounds(20, 60, 100, 25); + p1ReplaceBtn = new JButton(); + p1ReplaceBtn.setBounds(130, 60, 400, 25); + p1UnitLabel = new JLabel("λ"); + p1UnitLabel.setBounds(560, 60, 50, 25); + p1UnitCombo = new KeyValComboBox(unitVector); + p1UnitCombo.setBounds(610, 60, 50, 25); + p1NumLabel = new JLabel(""); + p1NumLabel.setBounds(680, 60, 50, 25); + p1NumText = new JTextField(); + p1NumText.setBounds(730, 60, 50, 25); + p1SelectAll = new JCheckBox("ȫѡ"); + p1SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p1model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p1Table = new JTable(p1model); + p1Table.getColumnModel().getColumn(0).setMinWidth(60); + p1Table.getColumnModel().getColumn(0).setMaxWidth(60); + p1Table.getColumnModel().getColumn(1).setMinWidth(200); + p1Table.getColumnModel().getColumn(2).setMinWidth(200); + p1Table.getColumnModel().getColumn(3).setMinWidth(100); + p1Table.getColumnModel().getColumn(4).setMinWidth(100); + p1Table.getColumnModel().getColumn(5).setMinWidth(100); + p1Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p1Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p1Table.setRowHeight(25); + p1Table.setAutoscrolls(true); + p1Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p1Table.getTableHeader().setReorderingAllowed(false); + p1Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p1sorter = new TableRowSorter(p1model); + p1Table.setRowSorter(p1sorter); + p1jsp = new JScrollPane(p1Table); + p1jsp.setBounds(20, 130, 760, 500); + + p1BottomBtn1 = new JButton(""); + p1BottomBtn1.setBounds(80, 650, 100, 25); + p1BottomBtn2 = new JButton("滻"); + p1BottomBtn2.setBounds(260, 650, 100, 25); + p1BottomBtn3 = new JButton(""); + p1BottomBtn3.setBounds(440, 650, 100, 25); + p1BottomBtn4 = new JButton("ȡ"); + p1BottomBtn4.setBounds(620, 650, 100, 25); + + p1Left.add(p1TargetLabel); + p1Left.add(p1TargetBtn); + p1Left.add(p1ReplaceLabel); + p1Left.add(p1ReplaceBtn); + p1Left.add(p1UnitLabel); + p1Left.add(p1UnitCombo); + p1Left.add(p1NumLabel); + p1Left.add(p1NumText); + p1Left.add(p1SelectAll); + p1Left.add(p1jsp); + p1Left.add(p1BottomBtn1); + p1Left.add(p1BottomBtn2); + p1Left.add(p1BottomBtn3); + p1Left.add(p1BottomBtn4); + + // 滻ұ + p1Right = new JPanel(); + p1Right.setLayout(null); + p1Right.setBounds(800, 0, 400, 800); + p1Right.setBorder(BorderFactory.createEtchedBorder()); + + p1TreePanel = new JScrollPane(); + p1TreePanel.setBounds(20, 130, 360, 500); + p1Right.add(p1TreePanel); + + // ¼ + p1SelectAll.addItemListener(selectAll(p1Table)); + p1Table.addMouseListener(showTree(p1Right)); + p1BottomBtn4.addActionListener(cancel()); + p1BottomBtn1.addActionListener(batchRevise(p1Table, p1SelectAll)); + p1BottomBtn2.addActionListener(batchReplace()); + p1BottomBtn3.addActionListener(startWorkFlow(p1Table)); + p1TargetBtn.addActionListener(clickSearch(p1Table, p1SelectAll)); + p1ReplaceBtn.addActionListener(clickSearch(null, null)); + + p1.add(p1Left); + p1.add(p1Right); + + // + p2 = new JPanel(); + p2.setLayout(null); + + // + p2Left = new JPanel(); + p2Left.setLayout(null); + p2Left.setBounds(0, 0, 800, 800); + p2Left.setBorder(BorderFactory.createEtchedBorder()); + + p2TargetLabel = new JLabel("Ŀϱ"); + p2TargetLabel.setBounds(20, 20, 100, 25); + p2TargetBtn = new JButton(); + p2TargetBtn.setBounds(130, 20, 400, 25); + p2ChangeNumLabel = new JLabel(""); + p2ChangeNumLabel.setBounds(20, 60, 100, 25); + p2NumText = new JTextField(); + p2NumText.setBounds(130, 60, 50, 25); + + p2SelectAll = new JCheckBox("ȫѡ"); + p2SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p2model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p2Table = new JTable(p2model); + p2Table.getColumnModel().getColumn(0).setMinWidth(60); + p2Table.getColumnModel().getColumn(0).setMaxWidth(60); + p2Table.getColumnModel().getColumn(1).setMinWidth(200); + p2Table.getColumnModel().getColumn(2).setMinWidth(200); + p2Table.getColumnModel().getColumn(3).setMinWidth(100); + p2Table.getColumnModel().getColumn(4).setMinWidth(100); + p2Table.getColumnModel().getColumn(5).setMinWidth(100); + p2Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p2Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p2Table.setRowHeight(25); + p2Table.setAutoscrolls(true); + p2Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p2Table.getTableHeader().setReorderingAllowed(false); + p2Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p2sorter = new TableRowSorter(p2model); + p2Table.setRowSorter(p2sorter); + p2jsp = new JScrollPane(p2Table); + p2jsp.setBounds(20, 130, 760, 500); + + p2BottomBtn1 = new JButton(""); + p2BottomBtn1.setBounds(80, 650, 100, 25); + p2BottomBtn2 = new JButton(""); + p2BottomBtn2.setBounds(260, 650, 100, 25); + p2BottomBtn3 = new JButton(""); + p2BottomBtn3.setBounds(440, 650, 100, 25); + p2BottomBtn4 = new JButton("ȡ"); + p2BottomBtn4.setBounds(620, 650, 100, 25); + + p2Left.add(p2TargetLabel); + p2Left.add(p2TargetBtn); + p2Left.add(p2ChangeNumLabel); + p2Left.add(p2NumText); + p2Left.add(p2SelectAll); + p2Left.add(p2jsp); + p2Left.add(p2BottomBtn1); + p2Left.add(p2BottomBtn2); + p2Left.add(p2BottomBtn3); + p2Left.add(p2BottomBtn4); + + // ұ + p2Right = new JPanel(); + p2Right.setLayout(null); + p2Right.setBounds(800, 0, 400, 800); + p2Right.setBorder(BorderFactory.createEtchedBorder()); + + p2TreePanel = new JScrollPane(); + p2TreePanel.setBounds(20, 130, 360, 500); + p2Right.add(p2TreePanel); + + // ¼ + p2SelectAll.addItemListener(selectAll(p2Table)); + p2Table.addMouseListener(showTree(p2Right)); + p2BottomBtn4.addActionListener(cancel()); + p2BottomBtn1.addActionListener(batchRevise(p2Table, p2SelectAll)); + p2BottomBtn2.addActionListener(batchModify()); + p2BottomBtn3.addActionListener(startWorkFlow(p2Table)); + p2TargetBtn.addActionListener(clickSearch(p2Table, p2SelectAll)); + + p2.add(p2Left); + p2.add(p2Right); + + // + p3 = new JPanel(); + p3.setLayout(null); + + // + p3Left = new JPanel(); + p3Left.setLayout(null); + p3Left.setBounds(0, 0, 800, 800); + p3Left.setBorder(BorderFactory.createEtchedBorder()); + + p3TargetLabel = new JLabel("οϱ"); + p3TargetLabel.setBounds(20, 20, 100, 25); + p3TargetBtn = new JButton(); + p3TargetBtn.setBounds(130, 20, 400, 25); + p3AddLabel = new JLabel("ϱ"); + p3AddLabel.setBounds(20, 60, 100, 25); + p3AddBtn = new JButton(); + p3AddBtn.setBounds(130, 60, 400, 25); + p3UnitLabel = new JLabel("λ"); + p3UnitLabel.setBounds(560, 60, 50, 25); + p3UnitCombo = new KeyValComboBox(unitVector); + p3UnitCombo.setBounds(610, 60, 50, 25); + p3NumLabel = new JLabel(""); + p3NumLabel.setBounds(680, 60, 50, 25); + p3NumText = new JTextField(); + p3NumText.setBounds(730, 60, 50, 25); + + p3SelectAll = new JCheckBox("ȫѡ"); + p3SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p3model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p3Table = new JTable(p3model); + p3Table.getColumnModel().getColumn(0).setMinWidth(60); + p3Table.getColumnModel().getColumn(0).setMaxWidth(60); + p3Table.getColumnModel().getColumn(1).setMinWidth(200); + p3Table.getColumnModel().getColumn(2).setMinWidth(200); + p3Table.getColumnModel().getColumn(3).setMinWidth(100); + p3Table.getColumnModel().getColumn(4).setMinWidth(100); + p3Table.getColumnModel().getColumn(5).setMinWidth(100); + p3Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p3Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p3Table.setRowHeight(25); + p3Table.setAutoscrolls(true); + p3Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p3Table.getTableHeader().setReorderingAllowed(false); + p3Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p3sorter = new TableRowSorter(p3model); + p3Table.setRowSorter(p3sorter); + p3jsp = new JScrollPane(p3Table); + p3jsp.setBounds(20, 130, 760, 500); + + p3BottomBtn1 = new JButton(""); + p3BottomBtn1.setBounds(80, 650, 100, 25); + p3BottomBtn2 = new JButton(""); + p3BottomBtn2.setBounds(260, 650, 100, 25); + p3BottomBtn3 = new JButton(""); + p3BottomBtn3.setBounds(440, 650, 100, 25); + p3BottomBtn4 = new JButton("ȡ"); + p3BottomBtn4.setBounds(620, 650, 100, 25); + + p3Left.add(p3TargetLabel); + p3Left.add(p3TargetBtn); + p3Left.add(p3AddLabel); + p3Left.add(p3AddBtn); + p3Left.add(p3UnitLabel); + p3Left.add(p3UnitCombo); + p3Left.add(p3NumLabel); + p3Left.add(p3NumText); + p3Left.add(p3SelectAll); + p3Left.add(p3jsp); + p3Left.add(p3BottomBtn1); + p3Left.add(p3BottomBtn2); + p3Left.add(p3BottomBtn3); + p3Left.add(p3BottomBtn4); + + // ұ + p3Right = new JPanel(); + p3Right.setLayout(null); + p3Right.setBounds(800, 0, 400, 800); + p3Right.setBorder(BorderFactory.createEtchedBorder()); + + p3TreePanel = new JScrollPane(); + p3TreePanel.setBounds(20, 130, 360, 500); + p3Right.add(p3TreePanel); + + // ¼ + p3SelectAll.addItemListener(selectAll(p3Table)); + p3Table.addMouseListener(showTree(p3Right)); + p3BottomBtn4.addActionListener(cancel()); + p3BottomBtn1.addActionListener(batchRevise(p3Table, p3SelectAll)); + p3BottomBtn2.addActionListener(batchAdd()); + p3BottomBtn3.addActionListener(startWorkFlow(p3Table)); + p3TargetBtn.addActionListener(clickSearch(p3Table, p3SelectAll)); + p3AddBtn.addActionListener(clickSearch(null, null)); + + p3.add(p3Left); + p3.add(p3Right); + + // ɾ + p4 = new JPanel(); + p4.setLayout(null); + + // ɾ + p4Left = new JPanel(); + p4Left.setLayout(null); + p4Left.setBounds(0, 0, 800, 800); + p4Left.setBorder(BorderFactory.createEtchedBorder()); + + p4TargetLabel = new JLabel("Ŀϱ"); + p4TargetLabel.setBounds(20, 20, 100, 25); + p4TargetBtn = new JButton(); + p4TargetBtn.setBounds(130, 20, 400, 25); + + p4SelectAll = new JCheckBox("ȫѡ"); + p4SelectAll.setBounds(20, 100, 100, 25); + DefaultTableModel p4model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + if (paramInt2 == 0) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p4Table = new JTable(p4model); + p4Table.getColumnModel().getColumn(0).setMinWidth(60); + p4Table.getColumnModel().getColumn(0).setMaxWidth(60); + p4Table.getColumnModel().getColumn(1).setMinWidth(200); + p4Table.getColumnModel().getColumn(2).setMinWidth(200); + p4Table.getColumnModel().getColumn(3).setMinWidth(100); + p4Table.getColumnModel().getColumn(4).setMinWidth(100); + p4Table.getColumnModel().getColumn(5).setMinWidth(100); + p4Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer()); + p4Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField())); + p4Table.setRowHeight(25); + p4Table.setAutoscrolls(true); + p4Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p4Table.getTableHeader().setReorderingAllowed(false); + p4Table.putClientProperty("terminateEditOnFocusLost", true); + RowSorter p4sorter = new TableRowSorter(p4model); + p4Table.setRowSorter(p4sorter); + p4jsp = new JScrollPane(p4Table); + p4jsp.setBounds(20, 130, 760, 500); + + p4BottomBtn1 = new JButton(""); + p4BottomBtn1.setBounds(80, 650, 100, 25); + p4BottomBtn2 = new JButton("ɾ"); + p4BottomBtn2.setBounds(260, 650, 100, 25); + p4BottomBtn3 = new JButton(""); + p4BottomBtn3.setBounds(440, 650, 100, 25); + p4BottomBtn4 = new JButton("ȡ"); + p4BottomBtn4.setBounds(620, 650, 100, 25); + + p4Left.add(p4TargetLabel); + p4Left.add(p4TargetBtn); + p4Left.add(p4SelectAll); + p4Left.add(p4jsp); + p4Left.add(p4BottomBtn1); + p4Left.add(p4BottomBtn2); + p4Left.add(p4BottomBtn3); + p4Left.add(p4BottomBtn4); + + // ұ + p4Right = new JPanel(); + p4Right.setLayout(null); + p4Right.setBounds(800, 0, 400, 800); + p4Right.setBorder(BorderFactory.createEtchedBorder()); + + p4TreePanel = new JScrollPane(); + p4TreePanel.setBounds(20, 130, 360, 500); + p4Right.add(p4TreePanel); + + // ¼ + p4SelectAll.addItemListener(selectAll(p4Table)); + p4Table.addMouseListener(showTree(p4Right)); + p4BottomBtn4.addActionListener(cancel()); + p4BottomBtn1.addActionListener(batchRevise(p4Table, p4SelectAll)); + p4BottomBtn2.addActionListener(batchRemove()); + p4BottomBtn3.addActionListener(startWorkFlow(p4Table)); + p4TargetBtn.addActionListener(clickSearch(p4Table, p4SelectAll)); + + p4.add(p4Left); + p4.add(p4Right); + + // ־ + p5 = new JPanel(); + p5.setLayout(null); + + p5UserLabel = new JLabel("޸û"); + p5UserLabel.setBounds(20, 40, 70, 25); + p5UserText = new JTextField(); + p5UserText.setBounds(100, 40, 150, 25); + p5TimeLabel = new JLabel("޸ʱ"); + p5TimeLabel.setBounds(300, 40, 70, 25); + p5TimeStartText = DatePickerUtil.getDatePicker(null); + p5TimeStartText.setBounds(380, 40, 100, 25); + toLabel = new JLabel(""); + toLabel.setBounds(490, 40, 20, 25); + p5TimeEndText = DatePickerUtil.getDatePicker(null); + p5TimeEndText.setBounds(520, 40, 100, 25); + p5ContentLabel = new JLabel("޸"); + p5ContentLabel.setBounds(670, 40, 70, 25); + p5ContentText = new JTextArea(); + p5ContentText.setLineWrap(true); + p5ContentText.setWrapStyleWord(true); + p5Contentjsp = new JScrollPane(p5ContentText); + p5Contentjsp.setBounds(750, 20, 200, 80); + p5Search = new JButton(""); + p5Search.setBounds(1000, 40, 60, 25); + p5Download = new JButton("־"); + p5Download.setBounds(1080, 40, 100, 25); + + DefaultTableModel p5model = new DefaultTableModel(colDisplayNames2, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + return false; + } + + @Override + public Class getColumnClass(int paramInt) { + // TODO Auto-generated method stub + if (paramInt == 0) { + return Integer.class; + } + return super.getColumnClass(paramInt); + } + }; + p5Table = new JTable(p5model); + p5Table.getColumnModel().getColumn(0).setMinWidth(60); + p5Table.getColumnModel().getColumn(0).setMaxWidth(60); + p5Table.getColumnModel().getColumn(1).setMinWidth(200); + p5Table.getColumnModel().getColumn(2).setMinWidth(200); + p5Table.getColumnModel().getColumn(3).setMinWidth(700); + p5Table.setRowHeight(25); + p5Table.setAutoscrolls(true); + p5Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + p5Table.getTableHeader().setReorderingAllowed(false); + RowSorter p5sorter = new TableRowSorter(p5model); + p5Table.setRowSorter(p5sorter); + p5jsp = new JScrollPane(p5Table); + p5jsp.setBounds(20, 130, 1160, 580); + + // ¼ + p5Search.addActionListener(searchLog()); + p5Download.addActionListener(downloadLog(p5Table)); + p5UserText.addKeyListener(logSearchEnter()); + p5TimeStartText.addKeyListener(logSearchEnter()); + p5TimeEndText.addKeyListener(logSearchEnter()); + + p5.add(p5UserLabel); + p5.add(p5UserText); + p5.add(p5TimeLabel); + p5.add(p5TimeStartText); + p5.add(toLabel); + p5.add(p5TimeEndText); + p5.add(p5ContentLabel); + p5.add(p5Contentjsp); + p5.add(p5Search); + p5.add(p5Download); + p5.add(p5jsp); + + root.add("batchReplace", p1); + root.add("batchModify", p2); + root.add("batchAdd", p3); + root.add("batchRemove", p4); + root.add("updateLog", p5); + + rootSwitch.show(root, "batchReplace"); + container.add(root, BorderLayout.CENTER); + this.setVisible(true); + } + + private ActionListener panelSwitch() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String text = ((JButton) e.getSource()).getText(); + for (int i = 0; i < topBtns.length; i++) { + topBtns[i].setSelected(topBtns[i].getText().equals(text)); + } + switch (text) { + case "滻": + clearTable(p1Table, p1SelectAll); + p1Right.removeAll(); + JScrollPane panel1 = new JScrollPane(); + panel1.setBounds(p1TreePanel.getX(), p1TreePanel.getY(), p1TreePanel.getWidth(), + p1TreePanel.getHeight()); + p1TreePanel = panel1; + p1Right.add(panel1); + p1Right.revalidate(); + p1Right.repaint(); + rootSwitch.show(root, "batchReplace"); + break; + case "": + clearTable(p2Table, p2SelectAll); + p2Right.removeAll(); + JScrollPane panel2 = new JScrollPane(); + panel2.setBounds(p2TreePanel.getX(), p2TreePanel.getY(), p2TreePanel.getWidth(), + p2TreePanel.getHeight()); + p2TreePanel = panel2; + p2Right.add(panel2); + p2Right.revalidate(); + p2Right.repaint(); + rootSwitch.show(root, "batchModify"); + break; + case "": + clearTable(p3Table, p3SelectAll); + p3Right.removeAll(); + JScrollPane panel3 = new JScrollPane(); + panel3.setBounds(p3TreePanel.getX(), p3TreePanel.getY(), p3TreePanel.getWidth(), + p3TreePanel.getHeight()); + p3TreePanel = panel3; + p3Right.add(panel3); + p3Right.revalidate(); + p3Right.repaint(); + rootSwitch.show(root, "batchAdd"); + break; + case "ɾ": + clearTable(p4Table, p4SelectAll); + p4Right.removeAll(); + JScrollPane panel4 = new JScrollPane(); + panel4.setBounds(p4TreePanel.getX(), p4TreePanel.getY(), p4TreePanel.getWidth(), + p4TreePanel.getHeight()); + p4TreePanel = panel4; + p4Right.add(panel4); + p4Right.revalidate(); + p4Right.repaint(); + rootSwitch.show(root, "batchRemove"); + break; + case "־": + createLogDataSourceTable(); + clearTable(p5Table, null); + rootSwitch.show(root, "updateLog"); + break; + default: +// createLogDataSourceTable(); + } + } + }; + } + + private void showWhereUesd(JTable table, JCheckBox selectAll) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + // TODO Auto-generated method stub + clearTable(table, selectAll); + if (table == null || targetRev == null) { + return; + } + long startTime = System.currentTimeMillis(); + List tableDataList = new ArrayList(); + try { + String revString = targetRev.getProperty("object_string"); + TCComponent[] usedComps = targetRev.whereUsed((short) 0); + System.out.println("װ======>" + usedComps.length); + + tableDataMap.clear(); +// Map usedMap = usedFilter(usedComps); +// for (Entry entry : usedMap.entrySet()) { + for (TCComponentItemRevision parentRev : usedFilter(usedComps)) { +// TCComponentItemRevision parentRev = entry.getValue(); + String parentString = parentRev.getProperty("object_string"); + TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + TCComponentBOMWindow win = winType.create(null); + TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null); + winMap.put(parentString, win); + AIFComponentContext[] aifs = topLine.getChildren(); + for (AIFComponentContext aif : aifs) { + TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent(); + if (revString.equals(child.getItemRevision().getProperty("object_string"))) { + + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + + Object[] rowData = new Object[] { new JCheckBox(), parentString, revString, unit, num, status }; + rowPrint(rowData); + tableDataList.add(rowData); + tableDataMap.put(parentString, + new BOMManageTableBean(parentString, revString, parentRev, targetRev, topLine, child)); + // TODO bomһchildܻ쳣ֻӰһ + break; + } + } + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + if (tableDataList == null || tableDataList.size() == 0) { + JOptionPane.showMessageDialog($this, "ҵӦ󣬵öûκװװöľ°汾ȷϱǷȷ", "ʾ", + JOptionPane.WARNING_MESSAGE); + return; + } + + for (Object[] rowData : tableDataList) { + model.addRow(rowData); + } + table.revalidate(); + table.repaint(); + System.out.println("װʾɣʱ" + (System.currentTimeMillis() - startTime) + "ms"); + } + + private MouseAdapter showTree(JPanel panelRight) { + return new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + JTable table = (JTable) e.getSource(); + String parentString = table.getValueAt(table.getSelectedRow(), 1).toString(); + System.out.println("select row=====>" + table.getSelectedRow()); + System.out.println("parentName=====>" + parentString); + CustomLovBean lovBean = null; + try { + lovBean = new CustomLovBean(tableDataMap.get(parentString).getChildString()); + CustomLovBean subBean = new CustomLovBean(parentString); + lovBean.addSub(subBean); + getTreeData(tableDataMap.get(parentString).getParentRev(), subBean); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + panelRight.removeAll(); + JTree tree = createTree(lovBean); + JScrollPane treePanel = new JScrollPane(tree); + treePanel.setBounds(20, 130, 360, 500); + panelRight.add(treePanel); + panelRight.revalidate(); + panelRight.repaint(); + } + } + }; + } + + private void getTreeData(TCComponent rev, CustomLovBean lov) throws TCException { + TCComponent[] comps = rev.whereUsed((short) 0); + if (comps == null || comps.length == 0) { + return; + } + for (TCComponent comp : comps) { + CustomLovBean sub = new CustomLovBean(comp.getProperty("object_string")); + System.out.println(sub.displayName); + lov.addSub(sub); + getTreeData(comp, sub); + } + } + + private void clearTable(JTable table, JCheckBox selectAll) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + int cnt = model.getRowCount(); + for (int i = 0; i < cnt; i++) { + model.removeRow(0); + } + table.revalidate(); + table.repaint(); + if (selectAll != null) { + selectAll.setSelected(false); + } + tableDataMap.clear(); + addedBOMLine.clear(); + try { + closeWin(); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private JTree createTree(CustomLovBean lovData) { + if (lovData == null || "".equals(lovData.displayName)) { + return new JTree(); + } + DefaultMutableTreeNode root = new DefaultMutableTreeNode(lovData.displayName); + DefaultMutableTreeNode parent = root; + DefaultTreeModel treeModel = new DefaultTreeModel(root); + + initTree(lovData, parent, treeModel); + + JTree tree = new JTree(treeModel); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); + cellRenderer.setTextNonSelectionColor(Color.black); + cellRenderer.setTextSelectionColor(Color.blue); + return tree; + } + + private void initTree(CustomLovBean lovData, DefaultMutableTreeNode parent, DefaultTreeModel treeModel) { + if (!lovData.hasChild()) { + return; + } + List subList = lovData.getSub(); + for (CustomLovBean sub : subList) { + DefaultMutableTreeNode temp = new DefaultMutableTreeNode(sub.displayName); + treeModel.insertNodeInto(temp, parent, parent.getChildCount()); + initTree(sub, temp, treeModel); + } + } + + private ItemListener selectAll(JTable table) { + return new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + // TODO Auto-generated method stub + boolean select = ((JCheckBox) e.getSource()).isSelected(); + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox checkBox = (JCheckBox) table.getValueAt(i, 0); + checkBox.setSelected(select); + table.revalidate(); + table.repaint(); + } + } + }; + } + + private ActionListener cancel() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + $this.dispose(); + } + }; + } + + private ActionListener batchRevise(JTable table, JCheckBox selectAll) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List selectedRowList = getselectedRow(table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkAccess(selectedRowList).isRes()) { + return; + } + List msgData = new ArrayList(); + for (int i = 0; i < selectedRowList.size(); i++) { + try { + TCComponentItemRevision newRev = selectedRowList.get(i).getParentRev().saveAs(null); + String parentString = newRev.getProperty("object_string"); + selectedRowList.get(i).setParentRev(newRev); + selectedRowList.get(i).setParentString(parentString); + msgData.add(new String[] { msgData.size() + 1 + "", selectedRowList.get(i).getParentString(), + newRev.getProperty("object_string"), "ɹ" }); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } + } + +// showWhereUesd(table, selectAll); + updateSelectedRow(table, selectedRowList); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "汾(ǰ)", "汾()", "" }, + msgData).panel; + JOptionPane.showMessageDialog($this, jsp, "", JOptionPane.PLAIN_MESSAGE); + } + }; + } + + private List usedFilter(TCComponent[] comps) throws TCException { +// Map sameParentUsedMap = new HashMap(); + List list = new ArrayList<>(); + for (TCComponent comp : comps) { + if (comp instanceof TCComponentItemRevision) { + TCComponentItemRevision rev = (TCComponentItemRevision) comp; +// String itemId; +// if (sameParentUsedMap.containsKey(itemId = comp.getProperty("item_id"))) { +// if (sameParentUsedMap.get(itemId).getProperty("item_revision_id") +// .compareTo(comp.getProperty("item_revision_id")) < 0) { +// sameParentUsedMap.put(itemId, rev); +// } +// } else { + if (rev.getItem().getLatestItemRevision().getUid().equals(rev.getUid())) { + list.add(rev); + } +// sameParentUsedMap.put(itemId, rev); +// } + } + } + return list; + } + + private void createLogDataSourceTable() { + if (isLogcreated) { + return; + } + String sql1 = "CREATE TABLE JD2_BOMManageLog ( id NUMBER ( 38, 0 ) primary key, modify_user VARCHAR2 ( 200 ), modify_time DATE, modify_content VARCHAR2 ( 500 ), target1 VARCHAR2 ( 100 ), target2 VARCHAR2 ( 100 ), parent VARCHAR2 ( 100 ), operation VARCHAR2 ( 50 ), unit VARCHAR2 ( 100 ), num VARCHAR2 ( 100 ))"; + String sql2 = "CREATE sequence JD2_BOMManageLog_seq minvalue 1 maxvalue 99999999 INCREMENT BY 1 START WITH 1"; + String sql3 = "CREATE OR REPLACE TRIGGER JD2_BOMManageLog_tri before INSERT ON JD2_BOMManageLog FOR each ROW BEGIN SELECT JD2_BOMManageLog_seq.nextval INTO : new.id FROM dual; END;"; + try { + List temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("user_tables", + new Condition("table_name", "JD2_BOMMANAGELOG")); + if (temp == null || temp.size() == 0) { + Db.use(DBUtil.getDataSource(session)).execute(sql1); + System.out.println("JD2_BOMMANAGELOG create success"); + } + temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("user_sequences", + new Condition("sequence_name", "JD2_BOMMANAGELOG_SEQ")); + if (temp == null || temp.size() == 0) { + Db.use(DBUtil.getDataSource(session)).execute(sql2); + System.out.println("JD2_BOMMANAGELOG_SEQ create success"); + } + temp = null; + temp = Db.use(DBUtil.getDataSource(session)).findBy("all_triggers", + new Condition("trigger_name", "JD2_BOMMANAGELOG_TRI")); + if (temp == null || temp.size() == 0) { + DBConnectionUtil.dbConn(session).createStatement().execute(sql3); + System.out.println("JD2_BOMManageLog_tri create success"); + } + isLogcreated = true; + System.out.println("init log success"); + } catch (Exception e) { + // TODO Auto-generated catch block + JOptionPane.showMessageDialog($this, "ݿʧܣѡjd2_db_settings", "", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + } + } + + private ActionListener searchLog() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String username = p5UserText.getText().trim(); + String content = p5ContentText.getText(); + if (username == null || "".equals(username)) { + return; + } + + String sql = "select * from JD2_BOMMANAGELOG where "; + if (!"*".equals(username)) { + sql += "modify_user like '%" + username + "%' and"; + } + sql += " modify_time between to_date('" + p5TimeStartText.getText() + + " 00:00:00','yyyy-MM-dd hh24:mi:ss') and to_date('" + p5TimeEndText.getText() + + " 23:59:59','yyyy-MM-dd hh24:mi:ss')"; + if (content != null && !"".equals(content)) { + sql += " and modify_content like '%" + content + "%'"; + } + sql += "order by MODIFY_TIME asc"; + System.out.println(sql); + try { + logDataList = Db.use(DBUtil.getDataSource(session)).query(sql); + System.out.println("log size=====>" + logDataList.size()); + DefaultTableModel model = (DefaultTableModel) p5Table.getModel(); + for (Entity entity : logDataList) { + Object[] objArr = new Object[] { entity.get("ID"), entity.get("MODIFY_USER"), + entity.get("MODIFY_TIME"), entity.get("MODIFY_CONTENT") }; + model.addRow(objArr); + } + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return; + } + p5Table.revalidate(); + p5Table.repaint(); + } + }; + } + + private ActionListener downloadLog(JTable table) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + if (table.getRowCount() > 0) { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setMultiSelectionEnabled(false); + chooser.setCurrentDirectory(FileSystemView.getFileSystemView().getHomeDirectory()); + chooser.showOpenDialog($this); + File folder = chooser.getSelectedFile(); + FileWriter fileWriter = null; + String fileName = "BOM־-" + new SimpleDateFormat("yyyyMMddHHmm").format(new Date()) + ".txt"; + try { + fileWriter = new FileWriter(folder.getPath() + File.separator + fileName);// ıļ + String temp; + System.out.println(logDataList.size()); + for (Entity entity : logDataList) { + fileWriter.write((temp = entity.get("ID").toString()) + + StringCreateUtil.createBlank(10 - temp.length()) + + (temp = entity.get("MODIFY_USER").toString()) + + StringCreateUtil.createBlank(20 - temp.length()) + + (temp = entity.get("MODIFY_TIME").toString()) + + StringCreateUtil.createBlank(30 - temp.length()) + + entity.get("MODIFY_CONTENT").toString() + "\r\n"); + } + fileWriter.flush(); + fileWriter.close(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return; + } + + JOptionPane.showMessageDialog($this, "־ɹ\r\n·" + folder + File.separator + fileName, "ʾ", + JOptionPane.WARNING_MESSAGE); + } + } + }; + + } + + private ActionListener batchReplace() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p1NumText.getText().trim(); + String text = p1UnitCombo.getSelectedText().trim(); + Object value = p1UnitCombo.getSelectedValue(); + System.out.println(numStr); + if ("".equals(numStr) || "".equals(text) || targetRev2 == null) { + JOptionPane.showMessageDialog($this, "δдϢд", "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } + List selectedRowList = getselectedRow(p1Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + List logData = new ArrayList(); + L1: for (int i = 0; i < selectedRowList.size(); i++) { + try { + doIndex++; + BOMManageTableBean bean = selectedRowList.get(i); + System.out.println(value.toString()); + if (!addedBOMLine.add(targetRev2)) { + continue L1; + } + AIFComponentContext[] aifs = bean.getParentLine().getChildren(); + for (AIFComponentContext aif : aifs) { + String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision() + .getProperty("object_string"); + if (objStr.equals(targetRev2.getProperty("object_string"))) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), targetRev2.getProperty("object_string"), + value.toString(), numStr, "ʧܣѴͬӼ" }); + continue L1; + } + } + String seq = selectedRowList.get(i).getChildLine().getProperty("bl_sequence_no"); + bean.getParentLine().remove("", bean.getChildLine()); + TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null, + false, ""); + childLine.setReferenceProperty("bl_uom", (TCComponent) value); + childLine.setProperties(new String[] { "bl_quantity", "bl_sequence_no" }, + new String[] { numStr, seq }); + msgData.add( + new String[] { msgData.size() + 1 + "", bean.getParentString(), bean.getChildString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, "ɹ" }); + BOMLogBean logBean = new BOMLogBean(bean.getChildString(), + targetRev2.getProperty("object_string"), bean.getParentString(), "滻", value.toString(), + "", numStr); + logData.add(logBean); + selectedRowList.get(i).setChildString(targetRev2.getProperty("object_string")); + selectedRowList.get(i).setChildRev(targetRev2); + selectedRowList.get(i).setChildLine(childLine); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("滻ִϣʱ" + (endTime - startTime) + "ms"); + doLog("滻", logData); + JScrollPane jsp = DialogUtil + .createTableMsg(new String[] { "", "", "ԭӼ", "滻Ӽ", "λ", "", "" }, msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "滻 ɹ(" + getResultNum(msgData, true) + ") ʧ(" + + getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); + updateSelectedRow2(p1Table, selectedRowList); + } + }; + } + + private ActionListener batchModify() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p2NumText.getText(); + List selectedRowList = getselectedRow(p2Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + List logData = new ArrayList<>(); + for (BOMManageTableBean bean : selectedRowList) { + String oldNumStr = ""; + try { + doIndex++; + oldNumStr = bean.getChildLine().getProperty("bl_quantity"); + bean.getChildLine().setProperties(new String[] { "bl_quantity" }, new String[] { numStr }); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), oldNumStr, numStr, "ɹ" }); + BOMLogBean logBean = new BOMLogBean(bean.getChildString(), + targetRev2.getProperty("object_string"), bean.getParentString(), "޸", "", oldNumStr, + numStr); + logData.add(logBean); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("ִϣʱ" + (endTime - startTime) + "ms"); + doLog("޸", logData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "", "Ӽ", "ԭ", "", "" }, + msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "Ľ ɹ(" + getResultNum(msgData, true) + ") ʧ(" + + getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); + updateSelectedRow(p2Table, selectedRowList); + } + }; + } + + private ActionListener batchAdd() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String numStr = p3NumText.getText().trim(); + String text = p3UnitCombo.getSelectedText().trim(); + Object value = p3UnitCombo.getSelectedValue(); + System.out.println(numStr); + if ("".equals(numStr) || "".equals(text) || targetRev2 == null) { + JOptionPane.showMessageDialog($this, "δдϢд", "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } + List selectedRowList = getselectedRow(p3Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + List logData = new ArrayList<>(); + L1: for (BOMManageTableBean bean : selectedRowList) { + try { + doIndex++; + System.out.println(value.toString()); + if (!addedBOMLine.add(targetRev2)) { + continue L1; + } + AIFComponentContext[] aifs = bean.getParentLine().getChildren(); + for (AIFComponentContext aif : aifs) { + String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision() + .getProperty("object_string"); + if (objStr.equals(targetRev2.getProperty("object_string"))) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, + "ʧܣѴͬӼ" }); + continue L1; + } + } + TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null, + false, ""); + childLine.setReferenceProperty("bl_uom", (TCComponent) value); + childLine.setProperties(new String[] { "bl_quantity" }, new String[] { numStr }); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + targetRev2.getProperty("object_string"), value.toString(), numStr, "ɹ" }); + BOMLogBean logBean = new BOMLogBean(bean.getChildString(), + targetRev2.getProperty("object_string"), bean.getParentString(), "", value.toString(), + "", numStr); + logData.add(logBean); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("ִϣʱ" + (endTime - startTime) + "ms"); + doLog("", logData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "", "Ӽ", "λ", "", "" }, + msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, " ɹ(" + getResultNum(msgData, true) + ") ʧ(" + + getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); +// showWhereUesd(p3Table, p3SelectAll); + } + }; + } + + private ActionListener batchRemove() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List selectedRowList = getselectedRow(p4Table); + if (selectedRowList.size() == 0) { + return; + } + if (!checkTargetAndSelect(targetRev, selectedRowList)) { + return; + } + long startTime = System.currentTimeMillis(); + updateTitleShowProgress(selectedRowList); + List msgData = new ArrayList(); + List logData = new ArrayList<>(); + for (BOMManageTableBean bean : selectedRowList) { + try { + doIndex++; + if (bean.getChildLine() == null) { + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), "bomLineڣѾɹɾ" }); + } else { + bean.getParentLine().remove("", bean.getChildLine()); + msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(), + bean.getChildString(), "ɹ" }); + BOMLogBean logBean = new BOMLogBean(bean.getChildString(), + targetRev2.getProperty("object_string"), bean.getParentString(), "ɾ", "", "", ""); + logData.add(logBean); + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + complate = true; + return; + } + } + try { + saveWin(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return; + } finally { + complate = true; + } + long endTime = System.currentTimeMillis(); + System.out.println("ɾִϣʱ" + (endTime - startTime) + "ms"); + doLog("ɾ", logData); + JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "", "ɾӼ", "" }, msgData).panel; + JOptionPane + .showMessageDialog( + $this, jsp, "ɾ ɹ(" + getResultNum(msgData, true) + ") ʧ(" + + getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms", + JOptionPane.PLAIN_MESSAGE); +// removeSelectRow(p4Table); + updateSelectedRow3(p4Table, selectedRowList); + } + }; + } + + private List getselectedRow(JTable table) { + List selectedList = new ArrayList(); + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + System.out.println("select=====>" + table.getValueAt(i, 1)); + selectedList.add(tableDataMap.get(table.getValueAt(i, 1))); + } + } + return selectedList; + } + + private void updateSelectedRow(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + try { + TCComponentItemRevision parentRev = newRowData.get(index).getParentRev(); + String parentString = newRowData.get(index).getParentString(); + TCComponentBOMWindow win = winType.create(null); + TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null); + winMap.get(table.getValueAt(i, 1).toString()).close(); + winMap.remove(table.getValueAt(i, 1)); + winMap.put(parentString, win); + tableDataMap.remove(table.getValueAt(i, 1).toString()); + TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + AIFComponentContext[] aifs = topLine.getChildren(); + for (AIFComponentContext aif : aifs) { + TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent(); + if (newRowData.get(index).getChildString() + .equals(child.getItemRevision().getProperty("object_string"))) { + + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + + JCheckBox selected = new JCheckBox(); + selected.setSelected(true); + Object[] rowData = new Object[] { selected, parentString, + newRowData.get(index).getChildString(), unit, num, status }; + rowPrint(rowData); + for (int ii = 0; ii < rowData.length; ii++) { + table.setValueAt(rowData[ii], i, ii); + } + tableDataMap.put(parentString, new BOMManageTableBean(parentString, + newRowData.get(index).getChildString(), parentRev, targetRev, topLine, child)); + break; + } + } + index++; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + table.revalidate(); + table.repaint(); + } + + private void updateSelectedRow2(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + BOMManageTableBean bean = newRowData.get(index); + try { + TCComponentBOMLine child = bean.getChildLine(); + String unit = child.getProperty("bl_uom"); + String num = child.getProperty("bl_quantity"); + table.setValueAt(bean.getChildString(), i, 2); + table.setValueAt(unit, index, 3); + table.setValueAt(num, index, 4); + tableDataMap.get(bean.getParentString()).setChildRev(bean.getChildRev()); + tableDataMap.get(bean.getParentString()).setChildString(bean.getChildString()); + tableDataMap.get(bean.getParentString()).setChildLine(child); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + index++; + } + } + table.revalidate(); + table.repaint(); + } + + private void updateSelectedRow3(JTable table, List newRowData) { + int index = 0; + for (int i = 0; i < table.getRowCount(); i++) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + BOMManageTableBean bean = newRowData.get(index); + table.setValueAt("", i, 2); + table.setValueAt("", index, 3); + table.setValueAt("", index, 4); + tableDataMap.get(bean.getParentString()).setChildLine(null); + index++; + } + } + table.revalidate(); + table.repaint(); + } + + private void removeSelectRow(JTable table) { + DefaultTableModel model = (DefaultTableModel) table.getModel(); + int i = 0; + while (i < table.getRowCount()) { + JCheckBox select = (JCheckBox) table.getValueAt(i, 0); + if (select.isSelected()) { + model.removeRow(i); + continue; + } + i++; + } + table.revalidate(); + table.repaint(); + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + new Thread(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + try { + closeWin(); + System.out.println("closed"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }).start(); + + super.dispose(); + } + + private void saveWin() throws TCException { + for (Entry entry : winMap.entrySet()) { + if (entry.getValue() != null) { + entry.getValue().save(); + } + + } + } + + private void closeWin() throws TCException { + saveWin(); + + for (Entry entry : winMap.entrySet()) { + entry.getValue().close(); + } + winMap.clear(); + } + + private void doLog(String operation, List logData) { + createLogDataSourceTable(); + String username = ""; + try { + username = session.getUser().getUserName() + "(" + session.getUser().getUserId() + ")"; + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + String datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + + List sqls = new ArrayList(); + for (BOMLogBean bean : logData) { + StringBuilder builder = new StringBuilder(); + builder.append( + "insert into JD2_BOMMANAGELOG (MODIFY_USER,MODIFY_TIME,MODIFY_CONTENT,TARGET1,TARGET2,PARENT,OPERATION,UNIT,NUM) VALUES ('"); + builder.append(username); + builder.append("',to_date('"); + builder.append(datetime); + builder.append("','yyyy-MM-dd hh24:mi:ss'),'"); + if ("滻".equals(operation)) { + String temp = String.format("%sӼ%s滻Ϊ%s;%s;%s", bean.getParent(), bean.getTarget1(), + bean.getTarget2(), bean.getUnit(), bean.getNum()); + builder.append(temp + "','"); + } else if ("޸".equals(operation)) { + String temp = String.format("%sӼ%s%sΪ%s", bean.getParent(), bean.getTarget1(), bean.getOldNum(), + bean.getNum()); + builder.append(temp + "','"); + } else if ("".equals(operation)) { + String temp = String.format("%sӼ%s;%s;%s", bean.getParent(), bean.getTarget2(), bean.getUnit(), + bean.getNum()); + builder.append(temp + "','"); + } else if ("ɾ".equals(operation)) { + String temp = String.format("%sɾӼ%s", bean.getParent(), bean.getTarget1()); + builder.append(temp + "','"); + } + builder.append(bean.getTarget1() + "','"); + builder.append(bean.getTarget2() + "','"); + builder.append(bean.getParent() + "','"); + builder.append(bean.getUnit() + "','"); + builder.append(operation + "','"); + builder.append(bean.getNum() + "');"); + sqls.add(builder.toString()); + } + + try { + Db.use(DBUtil.getDataSource(session)).executeBatch(sqls.toArray(new String[sqls.size()])); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private ActionListener clickSearch(JTable table, JCheckBox selectAll) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + JDialog content = DialogUtil.createSearchAndSelectRevDialog($this, table, selectAll, + (JButton) e.getSource()); + } + }; + } + + public void okCallback(JTable revTable, JTable table, JCheckBox selectAll, JButton field) { + // TODO Auto-generated method stub + int rowIndex = revTable.getSelectedRow(); + if (rowIndex < 0) { + return; + } + String text = revTable.getValueAt(rowIndex, 0).toString(); + System.out.println(text); + field.setText(text); + if ("".equals(text)) { + return; + } + if (table != null) { + targetRev = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5); + showWhereUesd(table, selectAll); + } else { + targetRev2 = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5); + } + } + + private KeyAdapter logSearchEnter() { + return new KeyAdapter() { + @Override + public void keyTyped(KeyEvent e) { + // TODO Auto-generated method stub + super.keyTyped(e); + if (e.getKeyChar() == KeyEvent.VK_ENTER) { + p5Search.doClick(); + } + } + }; + } + + private void updateTitleShowProgress(List list) { + new Thread(new Runnable() { + + @Override + public void run() { + int num = 1; + String temp; + doIndex = 0; + while (!complate) { + $this.setTitle("ڴ" + (temp = StringCreateUtil.createPoint(num % 3)) + + StringCreateUtil.createBlank(5 - temp.length()) + list.get(doIndex).getParentString() + + " " + (doIndex + 1) + "/" + list.size()); + try { + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + num++; + } + $this.setTitle("BOM"); + doIndex = -1; + complate = false; + } + }).start(); + } + + private boolean checkReleaseStatus(TCComponentItemRevision rev) { + try { + System.out.println("item type======>" + rev.getItem().getType()); + if (checkItemType.contains(rev.getItem().getType())) { + return true; + } + TCComponent form = rev.getRelatedComponents("IMAN_master_form_rev")[0]; + TCComponent[] statusArray = form.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + if ("".equals(status) || "JD2_DJJY".equals(status) || "JD2_DJKY".equals(status)) { + return false; + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return true; + } + + private ResultData checkAccess(List data) { + for (BOMManageTableBean bean : data) { + boolean isAccess = true; + try { + isAccess = session.getTCAccessControlService().checkPrivilege(bean.getParentLine(), "WRITE"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (!isAccess) { + try { + return new ResultData(false, "ǰûûж" + bean.getParentLine().getProperty("object_string") + "дȨ", + bean.getParentLine()); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return new ResultData(true, "", null); + } + + private boolean checkTargetAndSelect(TCComponentItemRevision rev, List data) { + if (!checkReleaseStatus(rev)) { + JOptionPane.showMessageDialog($this, "Ŀδߴڶ״̬޷BOM", "ʾ", JOptionPane.WARNING_MESSAGE); + return false; + } + ResultData res = checkAccess(data); + if (!res.isRes()) { + JOptionPane.showMessageDialog($this, res.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE); + return false; + } + return true; + } + + private ActionListener startWorkFlow(JTable table) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + List select = getselectedRow(table); + List parentRev = new ArrayList<>(); + for (BOMManageTableBean bean : select) { + parentRev.add(bean.getParentRev()); + } + $this.setExtendedState(JFrame.ICONIFIED); + NewProcessCommand command = new NewProcessCommand(AIFUtility.getActiveDesktop(), app, + parentRev.toArray(new TCComponentItemRevision[parentRev.size()])); + } + }; + } + + private void rowPrint(Object[] arr) { + StringBuilder sb = new StringBuilder(); + sb.append("["); + for (Object obj : arr) { + if (obj instanceof JCheckBox) { + sb.append(((JCheckBox) obj).isSelected()); + } else { + sb.append(obj.toString()); + } + sb.append(","); + } + if (sb.length() > 1) { + sb.deleteCharAt(sb.length() - 1); + } + sb.append("]"); + System.out.println(sb.toString()); + } + + private void resize() { + double left = 2 * this.widthOffset / 3.0; + double right = this.widthOffset - left; + + int bottom1 = p1BottomBtn2.getX() - p1BottomBtn1.getX() - p1BottomBtn1.getWidth(); + int bottom2 = p1BottomBtn3.getX() - p1BottomBtn2.getX() - p1BottomBtn2.getWidth(); + int botttom3 = p1BottomBtn4.getX() - p1BottomBtn3.getX() - p1BottomBtn3.getWidth(); + + // p1 + int p1x1 = p1TargetBtn.getX() - p1TargetLabel.getX() - p1TargetLabel.getWidth(); + int p1x2 = p1ReplaceBtn.getX() - p1ReplaceLabel.getX() - p1ReplaceLabel.getWidth(); + int p1x3 = p1UnitLabel.getX() - p1ReplaceBtn.getX() - p1ReplaceBtn.getWidth(); + int p1x4 = p1NumLabel.getX() - p1UnitCombo.getX() - p1UnitCombo.getWidth(); + p1TargetLabel.setBounds(p1TargetLabel.getX() + getOffset(left, 20, 800), 20, + p1TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p1TargetBtn.setBounds(p1TargetLabel.getX() + p1TargetLabel.getWidth() + p1x1 + getOffset(left, 10, 800), 20, + p1TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p1ReplaceLabel.setBounds(p1ReplaceLabel.getX() + getOffset(left, 20, 800), 60, + p1ReplaceLabel.getWidth() + getOffset(left, 100, 800), 25); + p1ReplaceBtn.setBounds(p1ReplaceLabel.getX() + p1ReplaceLabel.getWidth() + p1x2 + getOffset(left, 10, 800), 60, + p1ReplaceBtn.getWidth() + getOffset(left, 400, 800), 25); + p1UnitLabel.setBounds(p1ReplaceBtn.getX() + p1ReplaceBtn.getWidth() + p1x3 + getOffset(left, 30, 800), 60, + p1UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p1UnitCombo.setBounds(p1UnitLabel.getX() + p1UnitLabel.getWidth(), 60, + p1UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p1NumLabel.setBounds(p1UnitCombo.getX() + p1UnitCombo.getWidth() + p1x4 + getOffset(left, 20, 800), 60, + p1NumLabel.getWidth() + getOffset(left, 50, 800), 25); + p1NumText.setBounds(p1NumLabel.getX() + p1NumLabel.getWidth(), 60, + p1NumText.getWidth() + getOffset(left, 50, 800), 25); + p1SelectAll.setBounds(p1SelectAll.getX() + getOffset(left, 20, 800), 100, + p1SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p1jsp.setBounds(p1jsp.getX() + getOffset(left, 20, 800), p1jsp.getY(), + p1jsp.getWidth() + getOffset(left, 760, 800), p1jsp.getHeight() + this.heightOffset); + p1BottomBtn1.setBounds(p1BottomBtn1.getX() + getOffset(left, 80, 800), p1BottomBtn1.getY() + this.heightOffset, + p1BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn2.setBounds(p1BottomBtn1.getX() + p1BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p1BottomBtn2.getY() + this.heightOffset, p1BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn3.setBounds(p1BottomBtn2.getX() + p1BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p1BottomBtn3.getY() + this.heightOffset, p1BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p1BottomBtn4.setBounds(p1BottomBtn3.getX() + p1BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p1BottomBtn4.getY() + this.heightOffset, p1BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p1Left.setBounds(0, 0, p1Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p1Left.getHeight() + this.heightOffset); + p1TreePanel.setBounds(p1TreePanel.getX() + getOffset(right, 20, 400), 130, + p1TreePanel.getWidth() + getOffset(right, 360, 400), p1TreePanel.getHeight() + this.heightOffset); + p1Right.setBounds(p1Left.getX() + p1Left.getWidth(), 0, + p1Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p1Right.getHeight() + this.heightOffset); + p1.revalidate(); + p1.repaint(); + + // p2 + int p2x1 = p2TargetBtn.getX() - p2TargetLabel.getX() - p2TargetLabel.getWidth(); + int p2x2 = p2NumText.getX() - p2ChangeNumLabel.getX() - p2ChangeNumLabel.getWidth(); + p2TargetLabel.setBounds(p2TargetLabel.getX() + getOffset(left, 20, 800), 20, + p2TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p2TargetBtn.setBounds(p2TargetLabel.getX() + p2TargetLabel.getWidth() + p2x1 + getOffset(left, 10, 800), 20, + p2TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p2ChangeNumLabel.setBounds(p2ChangeNumLabel.getX() + getOffset(left, 20, 800), 60, + p2ChangeNumLabel.getWidth() + getOffset(left, 100, 800), 25); + p2NumText.setBounds(p2ChangeNumLabel.getX() + p2ChangeNumLabel.getWidth() + p2x2 + getOffset(left, 10, 800), 60, + p2NumText.getWidth() + getOffset(left, 50, 800), 25); + p2SelectAll.setBounds(p2SelectAll.getX() + getOffset(left, 20, 800), 100, + p2SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p2jsp.setBounds(p2jsp.getX() + getOffset(left, 20, 800), p2jsp.getY(), + p2jsp.getWidth() + getOffset(left, 760, 800), p2jsp.getHeight() + this.heightOffset); + p2BottomBtn1.setBounds(p2BottomBtn1.getX() + getOffset(left, 80, 800), p2BottomBtn1.getY() + this.heightOffset, + p2BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn2.setBounds(p2BottomBtn1.getX() + p2BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p2BottomBtn2.getY() + this.heightOffset, p2BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn3.setBounds(p2BottomBtn2.getX() + p2BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p2BottomBtn3.getY() + this.heightOffset, p2BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p2BottomBtn4.setBounds(p2BottomBtn3.getX() + p2BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p2BottomBtn4.getY() + this.heightOffset, p2BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p2Left.setBounds(0, 0, p2Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p2Left.getHeight() + this.heightOffset); + p2TreePanel.setBounds(p2TreePanel.getX() + getOffset(right, 20, 400), 130, + p2TreePanel.getWidth() + getOffset(right, 360, 400), p2TreePanel.getHeight() + this.heightOffset); + p2Right.setBounds(p2Left.getX() + p2Left.getWidth(), 0, + p2Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p2Right.getHeight() + this.heightOffset); + p2.revalidate(); + p2.repaint(); + + // p3 + int p3x1 = p3TargetBtn.getX() - p3TargetLabel.getX() - p3TargetLabel.getWidth(); + int p3x2 = p3AddBtn.getX() - p3AddLabel.getX() - p3AddLabel.getWidth(); + int p3x3 = p3UnitLabel.getX() - p3AddBtn.getX() - p3AddBtn.getWidth(); + int p3x4 = p3NumLabel.getX() - p3UnitCombo.getX() - p3UnitCombo.getWidth(); + p3TargetLabel.setBounds(p3TargetLabel.getX() + getOffset(left, 20, 800), 20, + p3TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p3TargetBtn.setBounds(p3TargetLabel.getX() + p3TargetLabel.getWidth() + p3x1 + getOffset(left, 10, 800), 20, + p3TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p3AddLabel.setBounds(p3AddLabel.getX() + getOffset(left, 20, 800), 60, + p3AddLabel.getWidth() + getOffset(left, 100, 800), 25); + p3AddBtn.setBounds(p3AddLabel.getX() + p3AddLabel.getWidth() + p3x2 + getOffset(left, 10, 800), 60, + p3AddBtn.getWidth() + getOffset(left, 400, 800), 25); + p3UnitLabel.setBounds(p3AddBtn.getX() + p3AddBtn.getWidth() + p3x3 + getOffset(left, 30, 800), 60, + p3UnitLabel.getWidth() + getOffset(left, 50, 800), 25); + p3UnitCombo.setBounds(p3UnitLabel.getX() + p3UnitLabel.getWidth(), 60, + p3UnitCombo.getWidth() + getOffset(left, 50, 800), 25); + p3NumLabel.setBounds(p3UnitCombo.getX() + p3UnitCombo.getWidth() + p3x4 + getOffset(left, 20, 800), 60, + p3NumLabel.getWidth() + getOffset(left, 50, 800), 25); + p3NumText.setBounds(p3NumLabel.getX() + p3NumLabel.getWidth(), 60, + p3NumText.getWidth() + getOffset(left, 50, 800), 25); + p3SelectAll.setBounds(p3SelectAll.getX() + getOffset(left, 20, 800), 100, + p3SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p3jsp.setBounds(p3jsp.getX() + getOffset(left, 20, 800), p3jsp.getY(), + p3jsp.getWidth() + getOffset(left, 760, 800), p3jsp.getHeight() + this.heightOffset); + p3BottomBtn1.setBounds(p3BottomBtn1.getX() + getOffset(left, 80, 800), p3BottomBtn1.getY() + this.heightOffset, + p3BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn2.setBounds(p3BottomBtn1.getX() + p3BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p3BottomBtn2.getY() + this.heightOffset, p3BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn3.setBounds(p3BottomBtn2.getX() + p3BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p3BottomBtn3.getY() + this.heightOffset, p3BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p3BottomBtn4.setBounds(p3BottomBtn3.getX() + p3BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p3BottomBtn4.getY() + this.heightOffset, p3BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p3Left.setBounds(0, 0, p3Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p3Left.getHeight() + this.heightOffset); + p3TreePanel.setBounds(p3TreePanel.getX() + getOffset(right, 20, 400), 130, + p3TreePanel.getWidth() + getOffset(right, 360, 400), p3TreePanel.getHeight() + this.heightOffset); + p3Right.setBounds(p3Left.getX() + p3Left.getWidth(), 0, + p3Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p3Right.getHeight() + this.heightOffset); + p3.revalidate(); + p3.repaint(); + + // p4 + int p4x1 = p4TargetBtn.getX() - p4TargetLabel.getX() - p4TargetLabel.getWidth(); + p4TargetLabel.setBounds(p4TargetLabel.getX() + getOffset(left, 20, 800), 20, + p4TargetLabel.getWidth() + getOffset(left, 100, 800), 25); + p4TargetBtn.setBounds(p4TargetLabel.getX() + p4TargetLabel.getWidth() + p4x1 + getOffset(left, 10, 800), 20, + p4TargetBtn.getWidth() + getOffset(left, 400, 800), 25); + p4SelectAll.setBounds(p4SelectAll.getX() + getOffset(left, 20, 800), 100, + p4SelectAll.getWidth() + getOffset(left, 100, 800), 25); + p4jsp.setBounds(p4jsp.getX() + getOffset(left, 20, 800), p4jsp.getY(), + p4jsp.getWidth() + getOffset(left, 760, 800), p4jsp.getHeight() + this.heightOffset); + p4BottomBtn1.setBounds(p4BottomBtn1.getX() + getOffset(left, 80, 800), p4BottomBtn1.getY() + this.heightOffset, + p4BottomBtn1.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn2.setBounds(p4BottomBtn1.getX() + p4BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800), + p4BottomBtn2.getY() + this.heightOffset, p4BottomBtn2.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn3.setBounds(p4BottomBtn2.getX() + p4BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800), + p4BottomBtn3.getY() + this.heightOffset, p4BottomBtn3.getWidth() + getOffset(left, 100, 800), 25); + p4BottomBtn4.setBounds(p4BottomBtn3.getX() + p4BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800), + p4BottomBtn4.getY() + this.heightOffset, p4BottomBtn4.getWidth() + getOffset(left, 100, 800), 25); + p4Left.setBounds(0, 0, p4Left.getWidth() + getOffset(this.widthOffset, 800, 1200), + p4Left.getHeight() + this.heightOffset); + p4TreePanel.setBounds(p4TreePanel.getX() + getOffset(right, 20, 400), 130, + p4TreePanel.getWidth() + getOffset(right, 360, 400), p4TreePanel.getHeight() + this.heightOffset); + p4Right.setBounds(p4Left.getX() + p4Left.getWidth(), 0, + p4Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p4Right.getHeight() + this.heightOffset); + p4.revalidate(); + p4.repaint(); + + // p5 + int p5x1 = p5UserText.getX() - p5UserLabel.getX() - p5UserLabel.getWidth(); + int p5x2 = p5TimeLabel.getX() - p5UserText.getX() - p5UserText.getWidth(); + int p5x3 = p5TimeStartText.getX() - p5TimeLabel.getX() - p5TimeLabel.getWidth(); + int p5x4 = toLabel.getX() - p5TimeStartText.getX() - p5TimeStartText.getWidth(); + int p5x5 = p5TimeEndText.getX() - toLabel.getX() - toLabel.getWidth(); + int p5x6 = p5ContentLabel.getX() - p5TimeEndText.getX() - p5TimeEndText.getWidth(); + int p5x7 = p5Contentjsp.getX() - p5ContentLabel.getX() - p5ContentLabel.getWidth(); + int p5x8 = p5Search.getX() - p5Contentjsp.getX() - p5Contentjsp.getWidth(); + int p5x9 = p5Download.getX() - p5Search.getX() - p5Search.getWidth(); + p5UserLabel.setBounds(p5UserLabel.getX(), 40, p5UserLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), + 25); + p5UserText.setBounds(p5UserLabel.getX() + p5UserLabel.getWidth() + p5x1 + getOffset(this.widthOffset, 10, 1200), + 40, p5UserText.getWidth() + getOffset(this.widthOffset, 150, 1200), 25); + p5TimeLabel.setBounds(p5UserText.getX() + p5UserText.getWidth() + p5x2 + getOffset(this.widthOffset, 50, 1200), + 40, p5TimeLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25); + p5TimeStartText.setBounds( + p5TimeLabel.getX() + p5TimeLabel.getWidth() + p5x3 + getOffset(this.widthOffset, 10, 1200), 40, + p5TimeStartText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + toLabel.setBounds( + p5TimeStartText.getX() + p5TimeStartText.getWidth() + p5x4 + getOffset(this.widthOffset, 10, 1200), 40, + toLabel.getWidth() + getOffset(this.widthOffset, 20, 1200), 25); + p5TimeEndText.setBounds(toLabel.getX() + toLabel.getWidth() + p5x5 + getOffset(this.widthOffset, 10, 1200), 40, + p5TimeEndText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + p5ContentLabel.setBounds( + p5TimeEndText.getX() + p5TimeEndText.getWidth() + p5x6 + getOffset(this.widthOffset, 50, 1200), 40, + p5ContentLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25); + p5Contentjsp.setBounds( + p5ContentLabel.getX() + p5ContentLabel.getWidth() + p5x7 + getOffset(this.widthOffset, 10, 1200), 20, + p5Contentjsp.getWidth() + getOffset(this.widthOffset, 200, 1200), 80); + p5Search.setBounds(p5Contentjsp.getX() + p5Contentjsp.getWidth() + p5x8 + getOffset(this.widthOffset, 50, 1200), + 40, p5Search.getWidth() + getOffset(this.widthOffset, 60, 1200), 25); + p5Download.setBounds(p5Search.getX() + p5Search.getWidth() + p5x9 + getOffset(this.widthOffset, 20, 1200), 40, + p5Download.getWidth() + getOffset(this.widthOffset, 100, 1200), 25); + p5jsp.setBounds(p5jsp.getX() + getOffset(this.widthOffset, 20, 1200), p5jsp.getY(), + p5jsp.getWidth() + getOffset(this.widthOffset, 1160, 1200), p5jsp.getHeight() + this.heightOffset); + p5.revalidate(); + p5.repaint(); + } + + private int getOffset(double num1, int num2, int num3) { + return (int) (num1 * num2 / num3); + } + + private int getResultNum(List msgData, boolean success) { + int num = 0; + String str = success ? "ɹ" : "ʧ"; + for (String[] row : msgData) { + if (row[row.length - 1].contains(str)) { + num++; + } + } + return num; + } +} diff --git a/src/com/connor/jd/plm/dialogs/CSXWHDialog.java b/src/com/connor/jd/plm/dialogs/CSXWHDialog.java new file mode 100644 index 0000000..a3d87b6 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/CSXWHDialog.java @@ -0,0 +1,1020 @@ +package com.connor.jd.plm.dialogs; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.math.NumberUtils; + +import com.connor.jd.operations.CreateTableOperation; +import com.connor.jd.plm.beans.ComponentBean; +import com.connor.jd.plm.beans.MachineBean; +import com.connor.jd.plm.utils.DBConnectionUtil; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; + +import javafx.application.Application; +import javafx.beans.value.ChangeListener; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.Event; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.SelectionMode; +import javafx.scene.control.Tab; +import javafx.scene.control.TabPane; +import javafx.scene.control.TableCell; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableColumn.CellEditEvent; +import javafx.scene.control.TablePosition; +import javafx.scene.control.TableView; +import javafx.scene.control.TextField; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.input.KeyCode; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.Pane; +import javafx.scene.text.Font; +import javafx.stage.Stage; + +public class CSXWHDialog extends Application { + + private static Connection con = null; + private static PreparedStatement ps = null; + private static ResultSet rs = null; + private ObservableList componentData = FXCollections.observableArrayList(); + private ObservableList machineData = FXCollections.observableArrayList(); + private ObservableList findList = FXCollections.observableArrayList(); + private ObservableList findMacList = FXCollections.observableArrayList(); + private TCSession session; + + public CSXWHDialog() throws TCException { + + } + + private TableView tableView0; + private TableView tableView1; + private int index = 10000; + private int macindex = 10000; + + private Stage msgStage; + private Label msgContent; + + @Override + public void start(Stage arg0) throws Exception { + session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + msgStage = new Stage(); + msgContent = new Label(""); + msgContent.setFont(new Font(STYLESHEET_CASPIAN, 16)); + Button ok = new Button("ȷ"); + ok.setPrefSize(60, 25); + ok.setOnAction((arg) -> { + msgStage.close(); + }); + BorderPane msgInner = new BorderPane(); + msgInner.setStyle("-fx-padding:10px;"); + FlowPane btnFlow = new FlowPane(); + btnFlow.setAlignment(Pos.TOP_RIGHT); + btnFlow.getChildren().addAll(ok); + msgInner.setTop(msgContent); + msgInner.setBottom(btnFlow); + Scene msgScene = new Scene(msgInner, 200, 100); + msgStage.setScene(msgScene); + msgStage.setTitle("Ϣ"); + msgStage.setAlwaysOnTop(true); + + CreateTableOperation.create(); + try { + con = DBConnectionUtil.dbConn(session); + String sqlString = "select * from JD2_Component"; + if (con == null) { + msgContent.setText("ʧ"); + msgStage.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) { + rs.close(); + } + if (ps != null) { + ps.close(); + } + if (con != null) { + con.close(); + } + } + for (int i = 0; i < componentData.size(); i++) { + findList.add(componentData.get(i)); + } + Stage primaryStage = new Stage(); + Pane root = new Pane(); + TabPane tabPane = new TabPane(); + Tab tab0 = new Tab("ά"); + Tab tab1 = new Tab("ά"); + // һҳ + AnchorPane ap0 = new AnchorPane(); + tableView0 = new TableView(); + tableView0.setEditable(true); + tableView0.setLayoutY(27.0); + tableView0.setPrefSize(486.0, 270.0); + TableColumn num0 = new TableColumn(""); + num0.setPrefWidth(75); + + TableColumn type0 = new TableColumn("Ʒ"); + type0.setPrefWidth(90); + type0.setCellValueFactory(new PropertyValueFactory<>("type")); + type0.setCellFactory((col) -> { + return new EditableStringTableCell(); + }); + type0.setOnEditCommit((CellEditEvent t) -> { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setType(t.getNewValue()); + // ݱǴݿȡģô״̬Ϊ2->ݿȡ޸˵ + if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setStage(2); + } + }); + TableColumn project0 = new TableColumn("Ŀ"); + project0.setPrefWidth(89); + project0.setCellValueFactory(new PropertyValueFactory<>("project")); + project0.setCellFactory((col) -> { + return new EditableStringTableCell(); + }); + project0.setOnEditCommit((CellEditEvent t) -> { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setProject(t.getNewValue()); + if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setStage(2); + } + }); + TableColumn time = new TableColumn("ʱ"); + time.setPrefWidth(92); + time.setCellValueFactory(new PropertyValueFactory<>("time")); + time.setCellFactory((col) -> { + return new EditableStringTableCell(); + }); + time.setOnEditCommit((CellEditEvent t) -> { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setTime(t.getNewValue()); + if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setStage(2); + } + }); + TableColumn number = new TableColumn("Ʒ"); + number.setPrefWidth(68); + number.setCellValueFactory(new PropertyValueFactory<>("number")); + number.setCellFactory((col) -> { + return new EditableStringTableCell(); + }); + number.setOnEditCommit((CellEditEvent t) -> { + if (NumberUtils.isNumber(t.getNewValue())) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setNumber(t.getNewValue()); + // ݱǴݿȡģô״̬Ϊ2->ݿȡ޸˵ + if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setStage(2); + } + } else { + tableView0.refresh(); + msgContent.setText(""); + msgStage.show(); + } + + }); + TableColumn cost = new TableColumn(""); + cost.setPrefWidth(71); + cost.setCellValueFactory(new PropertyValueFactory<>("cost")); + cost.setCellFactory((col) -> { + return new EditableStringTableCell(); + }); + cost.setOnEditCommit((CellEditEvent t) -> { + t.getNewValue(); + if (NumberUtils.isNumber(t.getNewValue())) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setCost(t.getNewValue()); + if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setStage(2); + } + } else { + tableView0.refresh(); + Alert alert = new Alert(AlertType.ERROR, ""); + alert.show(); + } + + }); + tableView0.getColumns().addAll(num0, type0, project0, time, number, cost); + num0.setCellFactory((col) -> { + TableCell cell = new TableCell() { + @Override + public void updateItem(String item, boolean empty) { + super.updateItem(item, empty); + this.setText(null); + this.setGraphic(null); + if (!empty) { + int rowIndex = this.getIndex() + 1; + this.setText(String.valueOf(rowIndex)); + } + } + }; + return cell; + }); + tableView0.setItems(findList); + tableView0.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + TextField search0 = new TextField(); + search0.setPrefSize(416.0, 23.0); + search0.setLayoutY(3.0); + Button searchBtn0 = new Button("ѯ"); + searchBtn0.setLayoutX(431.0); + searchBtn0.setLayoutY(3.0); + searchBtn0.setPrefSize(55.0, 23.0); + searchBtn0.setOnAction((arg) -> { + findList.clear(); + findList = search(search0.getText(), componentData); + tableView0.setItems(findList); + }); + Button addBtn0 = new Button(""); + addBtn0.setLayoutX(501.0); + addBtn0.setLayoutY(63.0); + addBtn0.setPrefSize(48.0, 23.0); + addBtn0.setOnAction((arg) -> { + + ComponentBean comBean = new ComponentBean(); + comBean.setType(""); + comBean.setProject(""); + comBean.setTime(""); + comBean.setNumber(String.valueOf("")); + comBean.setCost(String.valueOf("")); + comBean.setCompId(0); + comBean.setAddId(index++);// ֻжDz + comBean.setStage(1);// + findList.add(comBean); + componentData.add(comBean); + // tableView0.refresh(); + }); + Button removeBtn0 = new Button("ɾ"); + removeBtn0.setLayoutX(501.0); + removeBtn0.setLayoutY(127.0); + removeBtn0.setPrefSize(48.0, 23.0); + removeBtn0.setOnAction((arg) -> { + ObservableList delList = tableView0.getSelectionModel().getSelectedItems(); + List delAddList = new ArrayList(); + List delCompList = new ArrayList(); + for (int del = 0; del < delList.size(); del++) { + delAddList.add(delList.get(del).getAddId()); + delCompList.add(delList.get(del).getCompId()); + System.out.println("ѡеid" + delList.get(del).getAddId()); + } + for (int i = 0; i < delAddList.size(); i++) { + System.out.println("deListij" + delList.size()); + System.out.println("ѡе" + delAddList.get(i)); + for (int j = 0; j < findList.size(); j++) { + // System.out.println("addId:" + componentData.get(j).getAddId() + "--delId:" + + // delAddList.get(i)); + if (findList.get(j).getCompId() == 0) { + if (delAddList.get(i) == findList.get(j).getAddId()) { + // System.out.println("ֻƳδݿ"); + findList.remove(j); + } + Iterator compIt = componentData.iterator(); + while (compIt.hasNext()) { + int addid = compIt.next().getAddId(); + if (delAddList.get(i) == addid) { + compIt.remove(); + // System.out.println("ʼƳһ"); + } + } + } else { + if (findList.get(j).getCompId() != 0) { + if (delCompList.get(i) == findList.get(j).getCompId()) { + String sql = "delete from JD2_Component where test_id=?"; + update(sql, findList.get(j).getCompId()); + System.out.println("Ƴԭݿе"); + findList.remove(j); + } + Iterator compIt = componentData.iterator(); + while (compIt.hasNext()) { + int compid = compIt.next().getCompId(); + if (delCompList.get(i) == compid) { + compIt.remove(); + System.out.println("ʼƳһ"); + } + } + } + } + } + } + // tableView0.refresh(); + }); + + Button saveBtn0 = new Button(""); + saveBtn0.setLayoutX(161.0); + saveBtn0.setLayoutY(319.0); + saveBtn0.setPrefSize(59.0, 23.0); + saveBtn0.setOnAction((arg) -> { + Boolean flag = true; + for (ComponentBean com : findList) { + if (com.getType().equals("") && com.getProject().equals("") && com.getTime().equals("") + && com.getNumber().equals("") && com.getCost().equals("")) { + flag = false; + } + } + if (flag) { + for (ComponentBean com : findList) { + // System.out.println("״̬" + com.getStage()); + if (com.getStage() == 1) { + insert(com); + com.setStage(0); + selectId(com); + System.out.println("comId" + com.getCompId()); + } + if (com.getStage() == 2) { + update(com); + com.setStage(0); + } + } + tableView0.refresh(); + } else { + msgContent.setText("ijеȫΪգ"); + msgStage.show(); + } + + }); + Button exitBtn0 = new Button("ȡ"); + exitBtn0.setLayoutX(362.0); + exitBtn0.setLayoutY(319.0); + exitBtn0.setPrefSize(59.0, 23.0); + exitBtn0.setOnAction((arg) -> { +// for (int i = 0; i < findList.size(); i++) { +// System.out.println("״̬" + findList.get(i).getStage()); +// } + primaryStage.close(); + }); + ap0.getChildren().addAll(tableView0, search0, searchBtn0, addBtn0, removeBtn0, saveBtn0, exitBtn0); + tab0.setContent(ap0); + tab0.setClosable(false); + // ڶҳ + try { + con = DBConnectionUtil.dbConn(session); + String sqlString = "select * from JD2_Machine"; + if (con == null) { + System.out.print("ʧ"); + // System.exit(0); + } else { + ps = con.prepareStatement(sqlString); + rs = ps.executeQuery(); + while (rs.next()) { + MachineBean macBean = new MachineBean(); + macBean.setType(rs.getString(1)); + macBean.setProject(rs.getString(2)); + macBean.setCost(String.valueOf(rs.getDouble(3))); + macBean.setMacId(rs.getInt(4)); + macBean.setAddId(0); + macBean.setStage(0);// մݿȡ + machineData.add(macBean); + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + rs.close(); + } + if (ps != null) { + ps.close(); + } + if (con != null) { + con.close(); + } + } + for (int i = 0; i < machineData.size(); i++) { + findMacList.add(machineData.get(i)); + } + AnchorPane ap1 = new AnchorPane(); + tableView1 = new TableView(); + tableView1.setEditable(true); + tableView1.setLayoutY(27.0); + tableView1.setPrefSize(486.0, 270.0); + TableColumn num1 = new TableColumn(""); + num1.setPrefWidth(136.0); + TableColumn type1 = new TableColumn(""); + type1.setPrefWidth(110.0); + type1.setCellValueFactory(new PropertyValueFactory<>("type")); + type1.setCellFactory((col) -> { + return new EditableStringTableCell(); + }); + type1.setOnEditCommit((CellEditEvent t) -> { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setType(t.getNewValue()); + if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setStage(2); + } + }); + TableColumn project1 = new TableColumn("Ŀ"); + project1.setPrefWidth(121.0); + project1.setCellValueFactory(new PropertyValueFactory<>("project")); + project1.setCellFactory((col) -> { + return new EditableStringTableCell(); + }); + project1.setOnEditCommit((CellEditEvent t) -> { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setProject(t.getNewValue()); + if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setStage(2); + } + }); + TableColumn cost1 = new TableColumn("Ŀ"); + cost1.setPrefWidth(118.0); + cost1.setCellValueFactory(new PropertyValueFactory<>("cost")); + cost1.setCellFactory((col) -> { + return new EditableStringTableCell(); + }); + cost1.setOnEditCommit((CellEditEvent t) -> { + if (NumberUtils.isNumber(t.getNewValue())) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setCost(t.getNewValue()); + if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) { + t.getTableView().getItems().get(t.getTablePosition().getRow()).setStage(2); + } + } else { + tableView1.refresh(); + msgContent.setText(""); + msgStage.show(); + } + }); + tableView1.getColumns().addAll(num1, type1, project1, cost1); + num1.setCellFactory((col) -> { + TableCell cell = new TableCell() { + @Override + public void updateItem(String item, boolean empty) { + super.updateItem(item, empty); + this.setText(null); + this.setGraphic(null); + if (!empty) { + int rowIndex = this.getIndex() + 1; + this.setText(String.valueOf(rowIndex)); + } + } + }; + return cell; + }); + tableView1.setItems(findMacList); + tableView1.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + TextField search1 = new TextField(); + search1.setPrefSize(416.0, 23.0); + search1.setLayoutY(3.0); + Button searchBtn1 = new Button("ѯ"); + searchBtn1.setLayoutX(431.0); + searchBtn1.setLayoutY(3.0); + searchBtn1.setPrefSize(55.0, 23.0); + searchBtn1.setOnAction((arg) -> { + findMacList.clear(); + findMacList = searchMac(search1.getText(), machineData); + tableView1.setItems(findMacList); + }); + Button addBtn1 = new Button(""); + addBtn1.setLayoutX(501.0); + addBtn1.setLayoutY(63.0); + addBtn1.setPrefSize(48.0, 23.0); + addBtn1.setOnAction((arg) -> { + + MachineBean macBean = new MachineBean(); + macBean.setType(""); + macBean.setProject(""); + macBean.setCost(String.valueOf("")); + macBean.setMacId(0); + macBean.setAddId(macindex++);// ֻжDz + macBean.setStage(1);// + findMacList.add(macBean); + machineData.add(macBean); + }); + Button removeBtn1 = new Button("ɾ"); + removeBtn1.setLayoutX(501.0); + removeBtn1.setLayoutY(127.0); + removeBtn1.setPrefSize(48.0, 23.0); + removeBtn1.setOnAction((arg) -> { + ObservableList delList = tableView1.getSelectionModel().getSelectedItems(); + List delAddList = new ArrayList(); + List delMacList = new ArrayList(); + for (int del = 0; del < delList.size(); del++) { + delAddList.add(delList.get(del).getAddId()); + delMacList.add(delList.get(del).getMacId()); + } + for (int i = 0; i < delAddList.size(); i++) { + System.out.println("deListij" + delList.size()); + System.out.println("ѡе" + delAddList.get(i)); + for (int j = 0; j < findMacList.size(); j++) { + if (findMacList.get(j).getMacId() == 0) { + if (delAddList.get(i) == findMacList.get(j).getAddId()) { + findMacList.remove(j); + } + Iterator compIt = machineData.iterator(); + while (compIt.hasNext()) { + int addid = compIt.next().getAddId(); + if (delAddList.get(i) == addid) { + compIt.remove(); + } + } + } else { + if (findMacList.get(j).getMacId() != 0) { + if (delMacList.get(i) == findMacList.get(j).getMacId()) { + String sql = "delete from JD2_Machine where test_id=?"; + update(sql, findMacList.get(j).getMacId()); + findMacList.remove(j); + } + Iterator compIt = machineData.iterator(); + while (compIt.hasNext()) { + int compid = compIt.next().getMacId(); + if (delMacList.get(i) == compid) { + compIt.remove(); + } + } + } + } + } + } + }); + + Button saveBtn1 = new Button(""); + saveBtn1.setLayoutX(161.0); + saveBtn1.setLayoutY(319.0); + saveBtn1.setPrefSize(59.0, 23.0); + saveBtn1.setOnAction((arg) -> { + Boolean flag = true; + for (MachineBean com : findMacList) { + if (com.getType().equals("") && com.getProject().equals("") && com.getCost().equals("")) { + flag = false; + } + } + if (flag) { + for (MachineBean mac : findMacList) { + if (mac.getStage() == 1) { + insertMac(mac); + mac.setStage(0); + selectMacId(mac); + } + if (mac.getStage() == 2) { + updateMac(mac); + mac.setStage(0); + } + } + tableView1.refresh(); + } else { + msgContent.setText("ijеȫΪգ"); + msgStage.show(); + } + + }); + Button exitBtn1 = new Button("ȡ"); + exitBtn1.setOnAction((arg) -> { + primaryStage.close(); + }); + exitBtn1.setLayoutX(362.0); + exitBtn1.setLayoutY(319.0); + exitBtn1.setPrefSize(59.0, 23.0); + ap1.getChildren().addAll(tableView1, search1, searchBtn1, addBtn1, removeBtn1, saveBtn1, exitBtn1); + tab1.setContent(ap1); + tab1.setClosable(false); + + tabPane.getTabs().addAll(tab0, tab1); + root.getChildren().add(tabPane); + Scene scene = new Scene(root, 600, 400); + primaryStage.setScene(scene); + primaryStage.setTitle("ά"); + primaryStage.show(); + primaryStage.setAlwaysOnTop(true); + } + + public ObservableList search(String name, ObservableList list) { + ObservableList results = FXCollections.observableArrayList(); + Pattern pattern = Pattern.compile(name); + for (int i = 0; i < list.size(); i++) { +// Matcher matcher = pattern.matcher(((ComponentBean) list.get(i)).getType()); +// if (matcher.find()) { +// results.add(list.get(i)); +// } + if (((ComponentBean) list.get(i)).getType().contains(name) + || ((ComponentBean) list.get(i)).getProject().contains(name) + || ((ComponentBean) list.get(i)).getTime().contains(name) + || ((ComponentBean) list.get(i)).getNumber().contains(name) + || ((ComponentBean) list.get(i)).getCost().contains(name)) { + results.add(list.get(i)); + } + } + return results; + } + + public ObservableList searchMac(String name, ObservableList list) { + ObservableList results = FXCollections.observableArrayList(); + Pattern pattern = Pattern.compile(name); + for (int i = 0; i < list.size(); i++) { +// Matcher matcher = pattern.matcher(((MachineBean) list.get(i)).getType()); +// if (matcher.find()) { +// results.add(list.get(i)); +// } + if (((MachineBean) list.get(i)).getType().contains(name) + || ((MachineBean) list.get(i)).getProject().contains(name) + || ((MachineBean) list.get(i)).getCost().contains(name)) { + results.add(list.get(i)); + } + } + return results; + } + + private void selectId(ComponentBean com) { + String sql = "select component_id_seq.nextval from dual"; + con = DBConnectionUtil.dbConn(session); + try { + ps = con.prepareStatement(sql); + rs = ps.executeQuery(); + while (rs.next()) { + int id = rs.getInt(1) - 1; + System.out.println("id" + id); + com.setCompId(id); + } + } catch (Exception e) { + System.out.println("ʧ"); + } finally { + if (ps != null) { + try { + ps.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + private void selectMacId(MachineBean com) { + String sql = "select machine_id_seq.nextval from dual"; + con = DBConnectionUtil.dbConn(session); + try { + ps = con.prepareStatement(sql); + rs = ps.executeQuery(); + while (rs.next()) { + int id = rs.getInt(1); + com.setMacId(id); + } + } catch (Exception e) { + } finally { + if (ps != null) { + try { + ps.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + private void insert(ComponentBean com) { + String sql = "insert into JD2_Component(test_type,test_project,test_time,test_num,test_cost) values(?,?,?,?,?)"; + con = DBConnectionUtil.dbConn(session); + try { + System.out.println(""); + ps = con.prepareStatement(sql); + ps.setString(1, com.getType()); + ps.setString(2, com.getProject()); + ps.setString(3, com.getTime()); + if (com.getNumber().equals("")) { + com.setNumber("0"); + } + ps.setInt(4, Integer.valueOf(com.getNumber())); + if (com.getCost().equals("")) { + com.setCost("0"); + } + ps.setDouble(5, Double.valueOf(com.getCost())); + int rs = ps.executeUpdate(); + if (rs == 1) { + System.out.println("ӳɹ"); + msgContent.setText("ӳɹ"); + msgStage.show(); + } else { + System.out.println("ʧ"); + msgContent.setText("ʧ"); + msgStage.show(); + } + + } catch (Exception e) { + System.out.println("ʧ"); + msgContent.setText("ʧ"); + msgStage.show(); + } finally { + if (ps != null) { + try { + ps.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + } + + private void insertMac(MachineBean mac) { + String sql = "insert into JD2_Machine(test_type,test_project,test_cost) values(?,?,?)"; + con = DBConnectionUtil.dbConn(session); + try { + ps = con.prepareStatement(sql); + ps.setString(1, mac.getType()); + ps.setString(2, mac.getProject()); + if (mac.getCost().equals("")) { + mac.setCost("0"); + } + ps.setDouble(3, Double.valueOf(mac.getCost())); + int rs = ps.executeUpdate(); + System.out.println(rs); + if (rs == 1) { + System.out.println("ӳɹ"); + msgContent.setText("ӳɹ"); + msgStage.show(); + } else { + System.out.println("ʧ"); + msgContent.setText("ʧ"); + msgStage.show(); + } + + } catch (Exception e) { + System.out.println("ʧ"); + } finally { + if (ps != null) { + try { + ps.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + } + + private void update(ComponentBean com) { + String sql = "update JD2_Component set test_type=?,test_project=?,test_time=?,test_num=?,test_cost=? where test_id=?"; + con = DBConnectionUtil.dbConn(session); + try { + ps = con.prepareStatement(sql); + ps.setString(1, com.getType()); + ps.setString(2, com.getProject()); + ps.setString(3, com.getTime()); + if (com.getNumber().equals("")) { + com.setNumber("0"); + } + ps.setInt(4, Integer.valueOf(com.getNumber())); + if (com.getCost().equals("")) { + com.setCost("0"); + } + ps.setDouble(5, Double.valueOf(com.getCost())); + ps.setInt(6, com.getCompId()); + int rs = ps.executeUpdate(); + if (rs == 1) { + System.out.println("³ɹ"); + msgContent.setText("³ɹ"); + msgStage.show(); + } else { + System.out.println("ʧ"); + msgContent.setText("ʧ"); + msgStage.show(); + } + + } catch (Exception e) { + } finally { + if (ps != null) { + try { + ps.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + private void update(String sql, int id) { + con = DBConnectionUtil.dbConn(session); + try { + ps = con.prepareStatement(sql); + ps.setInt(1, id); + int rs = ps.executeUpdate(); + if (rs > 0) { + System.out.println("³ɹ"); + msgContent.setText("³ɹ"); + msgStage.show(); + } else { + System.out.println("³ɹ"); + msgContent.setText("ʧ"); + msgStage.show(); + } + + } catch (Exception e) { + } finally { + if (ps != null) { + try { + ps.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + } + + private void updateMac(MachineBean mac) { + String sql = "update JD2_Machine set test_type=?,test_project=?,test_cost=? where test_id=?"; + con = DBConnectionUtil.dbConn(session); + try { + ps = con.prepareStatement(sql); + ps.setString(1, mac.getType()); + ps.setString(2, mac.getProject()); + if (mac.getCost().equals("")) { + mac.setCost("0"); + } + ps.setDouble(3, Double.valueOf(mac.getCost())); + ps.setInt(4, mac.getMacId()); + int rs = ps.executeUpdate(); + if (rs == 1) { + System.out.println("³ɹ"); + msgContent.setText("³ɹ"); + msgStage.show(); + } else { + System.out.println("ʧ"); + msgContent.setText("ʧ"); + msgStage.show(); + } + + } catch (Exception e) { + } finally { + if (ps != null) { + try { + ps.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } +} + +class EditableStringTableCell extends TableCell { + protected TextField textField; + protected ChangeListener changeListener = (obs, ov, nv) -> { + if (!nv) { + commitEdit(textField.getText()); + } + }; + + public EditableStringTableCell() { + + } + + @Override + public void startEdit() { + if (editableProperty().get()) { + if (!isEmpty()) { + super.startEdit(); + createTextField(); + setText(null); + setGraphic(textField); + textField.requestFocus(); + } + } + } + + @Override + public void cancelEdit() { + super.cancelEdit(); + setText(getItem()); + setGraphic(null); + } + + @Override + public void updateItem(String item, boolean empty) { + super.updateItem(item, empty); + + if (empty) { + setText(null); + setGraphic(null); + } else { + if (isEditing()) { + if (textField != null) { + textField.setText(getString()); + textField.selectAll(); + } + setText(null); + setGraphic(textField); + } else { + setText(getString()); + setGraphic(null); + } + } + } + + protected void createTextField() { + textField = new TextField(getString()); + textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2); + textField.focusedProperty().addListener(changeListener); + textField.setOnAction(evt -> commitEdit(textField.getText())); + + textField.setOnKeyPressed((ke) -> { + if (ke.getCode().equals(KeyCode.ESCAPE)) { + textField.focusedProperty().removeListener(changeListener); + cancelEdit(); + } + if (ke.getCode().equals(KeyCode.TAB)) { + commitEdit(textField.getText()); + } + }); + } + + protected String getString() { + return getItem() == null ? "" : getItem().toString(); + } + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void commitEdit(String item) { + textField.focusedProperty().removeListener(changeListener); + if (isEditing()) { + super.commitEdit(item); + } else { + final TableView table = getTableView(); + if (table != null) { + TablePosition position = new TablePosition(getTableView(), getTableRow().getIndex(), getTableColumn()); + CellEditEvent editEvent = new CellEditEvent(table, position, TableColumn.editCommitEvent(), item); + Event.fireEvent(getTableColumn(), editEvent); + } + updateItem(item, false); + if (table != null) { + table.edit(-1, null); + } + + } + } + +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/dialogs/CheckBoxTreeCellRenderer.java b/src/com/connor/jd/plm/dialogs/CheckBoxTreeCellRenderer.java new file mode 100644 index 0000000..bc4a752 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/CheckBoxTreeCellRenderer.java @@ -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")); + } + + /** + * صһJPanel󣬸öаһJCheckBox + * һJLabel󡣲ҸÿǷѡJCheckBox ǷѡС + */ + @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); + } + +} diff --git a/src/com/connor/jd/plm/dialogs/CheckBoxTreeLabel.java b/src/com/connor/jd/plm/dialogs/CheckBoxTreeLabel.java new file mode 100644 index 0000000..2c8b26c --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/CheckBoxTreeLabel.java @@ -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; + } + +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/dialogs/CheckBoxTreeNode.java b/src/com/connor/jd/plm/dialogs/CheckBoxTreeNode.java new file mode 100644 index 0000000..65e71b9 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/CheckBoxTreeNode.java @@ -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 { + + * ȡ㵼ӽȡôʱеӽ㶼Ӧѡϵģ + * ӽȡ¸ȡȻ󸸽ȡҪȡӽ㣬 ʱDzҪȡӽġ + + 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; + } +} diff --git a/src/com/connor/jd/plm/dialogs/CheckBoxTreeNodeSelectionListener.java b/src/com/connor/jd/plm/dialogs/CheckBoxTreeNodeSelectionListener.java new file mode 100644 index 0000000..6631a27 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/CheckBoxTreeNodeSelectionListener.java @@ -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); + } + } + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/dialogs/ColorMaterialBean.java b/src/com/connor/jd/plm/dialogs/ColorMaterialBean.java new file mode 100644 index 0000000..318496e --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/ColorMaterialBean.java @@ -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 colorMaterial = new ArrayList(); + public Map data = new HashMap(); + +} diff --git a/src/com/connor/jd/plm/dialogs/MyTreeCellRenderer.java b/src/com/connor/jd/plm/dialogs/MyTreeCellRenderer.java new file mode 100644 index 0000000..dcaeb3f --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/MyTreeCellRenderer.java @@ -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; + } +} diff --git a/src/com/connor/jd/plm/dialogs/QTXJCDialog.java b/src/com/connor/jd/plm/dialogs/QTXJCDialog.java new file mode 100644 index 0000000..4b549ca --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/QTXJCDialog.java @@ -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 pjsName = null; + private List sfList = new ArrayList(); + private TCComponent[] com; + private String type; + private Stage primaryStage = null; + + public QTXJCDialog(List 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(); + 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> jfw = new HashMap>(); + 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 jfList = new ArrayList(); + 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 jfList = new ArrayList(); + 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; + } + +} diff --git a/src/com/connor/jd/plm/dialogs/TransformDesignToPartDialog.java b/src/com/connor/jd/plm/dialogs/TransformDesignToPartDialog.java new file mode 100644 index 0000000..c7cb266 --- /dev/null +++ b/src/com/connor/jd/plm/dialogs/TransformDesignToPartDialog.java @@ -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; + +/** + * bomתΪbom + * + * @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> comboxList; + private JPanel rightJPanel; + private Map> checkBoxTreeNodelMap; + private Map, 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 entry : bean.data.entrySet()) { + List arg1 = entry.getValue()[1] == null ? null + : (List) entry.getValue()[1]; + List arg2 = entry.getValue()[2] == null ? null : (List) entry.getValue()[2]; + List arg3 = entry.getValue()[3] == null ? null : (List) entry.getValue()[3]; + createBom(entry.getKey(), arg1, arg2, arg3); + } + } + + /** + * TreeӦitemѡ + * + * @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); } } } + */ + + /** + * TreeӦitemȡѡ + * + * @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 childrenList = new ArrayList<>(); + List 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 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 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 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 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 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 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 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 childRevList, + List queryNoList, List 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 map = rev.getClassificationAttributes(); + if (map.get("ɫ") != null && !"".equals(map.get("ɫ"))) { + return true; + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + +} diff --git a/src/com/connor/jd/plm/form/CSJHForm.java b/src/com/connor/jd/plm/form/CSJHForm.java new file mode 100644 index 0000000..50ff1a9 --- /dev/null +++ b/src/com/connor/jd/plm/form/CSJHForm.java @@ -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 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 editable = new ArrayList(); + private Map res; + private Map 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 testStage = new JComboBox(); + JComboBox 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 leatestRevisionComparator = new Comparator() { + + @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> dataMap = TCTableUtil.getTableMapList( + (TCComponentForm) revs[revs.length - 1].getRelatedComponent("IMAN_master_form_rev"), "jd2_csjh", + propNames); + List realNoList = new ArrayList(); + for (Map 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 releasedObjectString = new ArrayList(); + 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 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(); + rowNo = new HashMap(); + 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 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("ѡϴIJԱ"); + FileFilter filter = new FileNameExtensionFilter("Excel(.xlsx,.xls,.xlsm)", "xlsx", "xls", "xlsm");// ļֻгJPGGIFʽͼƬ + 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");// ļֻгJPGGIFʽͼƬ + 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 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 c = new ArrayList(); + 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 propMap = new HashMap(); + 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(); + } + +} diff --git a/src/com/connor/jd/plm/form/ComponentTestFrame.java b/src/com/connor/jd/plm/form/ComponentTestFrame.java new file mode 100644 index 0000000..0693bd4 --- /dev/null +++ b/src/com/connor/jd/plm/form/ComponentTestFrame.java @@ -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 dataMap = new LinkedHashMap<>(); + try { + List 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 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 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> oldRowData = TCTableUtil.getTableMapList(testForm, "jd2_csjh", + propNames); + List 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 tempMap = new HashMap(); + 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 list = new ArrayList(); + 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(); + } + }; + } + +} diff --git a/src/com/connor/jd/plm/form/ExperimentalPowerOfAttorneyForm.java b/src/com/connor/jd/plm/form/ExperimentalPowerOfAttorneyForm.java new file mode 100644 index 0000000..3736a9b --- /dev/null +++ b/src/com/connor/jd/plm/form/ExperimentalPowerOfAttorneyForm.java @@ -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 prop; + private List disableEdit; + private List disableEdit2; + private Map general; + private Map 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 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 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();// Ҫдһ + 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(); + general2 = new HashMap(); + 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 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 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 data = new ArrayList(); + 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 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(); + } + +} diff --git a/src/com/connor/jd/plm/form/GTCSJHForm.java b/src/com/connor/jd/plm/form/GTCSJHForm.java new file mode 100644 index 0000000..a8417ac --- /dev/null +++ b/src/com/connor/jd/plm/form/GTCSJHForm.java @@ -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 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 disableRows = new ArrayList(); + private List disableColumns = Arrays.asList(4, 5, 6, 8, 15, 17);// ίԱ, Ŀ, ̨,_,Ա + private Map resultMap = new HashMap(); + 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 status = new JComboBox(); + 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 result = new JComboBox(); + 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("Ա
ϴ"); + JButton collect = new JButton("ܽ
ϴ"); + 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 leatestRevisionComparator = new Comparator() { + + @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> dataMap = TCTableUtil.getTableMapList( + (TCComponentForm) revs[revs.length - 1].getRelatedComponent("IMAN_master_form_rev"), + "jd2_csjhtable", colNames); + List realNoList = new ArrayList(); + for (Map 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 releasedObjectString = new ArrayList(); + 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 dataList = new ArrayList(); + 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("ѡϴIJԱ"); + 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");// ļֻгJPGGIFʽͼƬ + 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 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 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(); + } +} diff --git a/src/com/connor/jd/plm/form/MyCallBack.java b/src/com/connor/jd/plm/form/MyCallBack.java new file mode 100644 index 0000000..72f83b0 --- /dev/null +++ b/src/com/connor/jd/plm/form/MyCallBack.java @@ -0,0 +1,6 @@ +package com.connor.jd.plm.form; + +public interface MyCallBack { + + public void execute(String itemId); +} diff --git a/src/com/connor/jd/plm/form/NewProductTestForm.java b/src/com/connor/jd/plm/form/NewProductTestForm.java new file mode 100644 index 0000000..fe0bd7e --- /dev/null +++ b/src/com/connor/jd/plm/form/NewProductTestForm.java @@ -0,0 +1,1037 @@ +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.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +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 javax.swing.table.DefaultTableModel; + +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.ModelList; +import com.connor.jd.plm.table.ModelValue; +import com.connor.jd.plm.table.MyCellEditor3; +import com.connor.jd.plm.table.TCTableUtil; +import com.connor.jd.plm.utils.DBUtil; +import com.connor.jd.plm.utils.DialogUtil; +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.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; +import com.teamcenter.rac.kernel.TCComponentProject; +import com.teamcenter.rac.kernel.TCComponentSchedule; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.stylesheet.AbstractRendering; +import com.teamcenter.rac.util.MessageBox; + +import cn.hutool.db.Db; +import cn.hutool.db.Entity; + +public class NewProductTestForm extends AbstractRendering { + private TCComponentForm form; + private CTMap model1; + private CTMap model2; + private CTable table1; + private CTable table2; + private Map prop; + private ModelList modelList1; + private ModelList modelList2; + private List dbData = new ArrayList(); + private JPopupMenu menu = new JPopupMenu(); + private JMenuItem addR; + private String[][] data = new String[0][]; + private String[] colNames = { "jd2_no", "jd2_lb", "jd2_xm", "jd2_xmfy", "jd2_DV", "jd2_PV", "jd2_PR", "jd2_SR", + "jd2_bz" }; + private String[] colNames2 = { "jd2_no", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syfy", "jd2_sycs" }; + private String[] colNames3 = { "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[] jieduan = { "DV", "PV", "PR", "SR" }; + private TCSession session; + private List compareDataList = new ArrayList(); + private boolean testFlag = false; + private List realIdStr = new ArrayList(); + private TCComponentProject project; + private NewProductTestForm $this; + + public NewProductTestForm(TCComponent arg0) throws Exception { + super(arg0); + if (arg0 instanceof TCComponentForm) { + this.form = (TCComponentForm) arg0; + this.session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + try { + dbData = Db.use(DBUtil.getDataSource(session)) + .query("select * from JD2_Machine ORDER BY TEST_TYPE ASC"); + } catch (Exception e) { + MessageBox.post("ݿô", "", MessageBox.ERROR); + e.printStackTrace(); + return; + } + $this = this; + loadRendering(); + } + } + + @Override + public void loadRendering() throws TCException { + this.setLayout(new BorderLayout()); + JPanel root = new JPanel(new BorderLayout()); + root.setPreferredSize(new Dimension(800, 500)); + JPanel inner = new JPanel(new BorderLayout()); + + JPanel top = new JPanel(new FlowLayout(FlowLayout.CENTER)); + JLabel title = new JLabel("ƷĿԵ"); + title.setFont(new Font("", Font.PLAIN, 24)); + top.add(title); + inner.add(top, BorderLayout.NORTH); + + prop = form.getProperties(); + + // ʼ + model1 = new CTMap(6, 4); + modelList1 = new ModelList(); + String[] textArr1 = { "ĿϢ", "ʱ䣺", "ͺţ", "ͺţ", "Ʒͺţ", "Ŀϣ", "Ʒ", "Ʒ㣺", "Ʒʾ", "ճ̣", + "ȼ", "׶Σ" }; + int[][] textLocation1 = { { 0, 0 }, { 0, 2 }, { 1, 0 }, { 1, 2 }, { 2, 0 }, { 2, 2 }, { 3, 0 }, { 3, 2 }, + { 4, 0 }, { 4, 2 }, { 5, 0 }, { 5, 2 } }; + for (int i = 0; i < textArr1.length; i++) { + modelList1.add(new ModelValue(textArr1[i], false, textLocation1[i][0], textLocation1[i][1], false)); + } + String[] propArr = { "jd2_xmxx", "jd2_lxsj", "jd2_jbxh", "jd2_csxh", "jd2_cpxh", "jd2_xmzl", "jd2_cpjl", + "jd2_cpbgd", "jd2_pzjl", "jd2_kfrc", "jd2_kfdj", "jd2_kfjd" }; + int[][] propLocation1 = { { 0, 1 }, { 0, 3 }, { 1, 1 }, { 1, 3 }, { 2, 1 }, { 2, 3 }, { 3, 1 }, { 3, 3 }, + { 4, 1 }, { 4, 3 }, { 5, 1 }, { 5, 3 } }; + for (int i = 0; i < propArr.length; i++) { + modelList1.add(new ModelValue(propArr[i], true, propLocation1[i][0], propLocation1[i][1], true)); + } + + table1 = new CTable(model1) { + @Override + public boolean isCellEditable(int row, int col) { + return !modelList1.isDisableEdit(row, col); + } + }; + + + initModel(model1, modelList1); + + + table1.setRowHeight(25); + table1.setBorder(BorderFactory.createLineBorder(Color.black)); + table1.getColumnModel().getColumn(0).setPreferredWidth(100); + table1.getColumnModel().getColumn(1).setPreferredWidth(100); + table1.getColumnModel().getColumn(2).setPreferredWidth(100); + table1.getColumnModel().getColumn(3).setPreferredWidth(200); + table1.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 JCheckPanel) { + return (JCheckPanel) 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); + table1.setAutoResizeMode(CTable.AUTO_RESIZE_NEXT_COLUMN); + table1.setDefaultRenderer(Object.class, tcr1); + inner.add(table1, BorderLayout.CENTER); + + modelList2 = new ModelList(); + modelList2.add(new ModelValue("NO", false, 0, 0, false, 0, 1, 0, 0)); + modelList2.add(new ModelValue("", false, 0, 1, false, 0, 1, 1, 1)); + modelList2.add(new ModelValue("Ŀ", false, 0, 2, false, 0, 1, 2, 2)); + modelList2.add(new ModelValue("Ŀ", false, 0, 3, false, 0, 1, 3, 3)); + modelList2.add(new ModelValue("Ŀ׶", false, 0, 4, false, 0, 0, 4, 7)); + modelList2.add(new ModelValue("DV", false, 1, 4, false)); + modelList2.add(new ModelValue("PV", false, 1, 5, false)); + modelList2.add(new ModelValue("PR", false, 1, 6, false)); + modelList2.add(new ModelValue("SR", false, 1, 7, false)); + modelList2.add(new ModelValue("ע", false, 0, 8, false, 0, 1, 8, 8)); + + String type = null; + int typeSpan = 0; + data = TCTableUtil.getTableRows(form, "jd2_xpcsxqd", colNames); + if (data.length == 0) { + + model2 = new CTMap(dbData.size() + 3, 9); + + for (int i = 0; i < dbData.size(); i++) { + realIdStr.add(dbData.get(i).getStr("TEST_ID")); + modelList2.add(new ModelValue(dbData.get(i).getStr("TEST_PROJECT"), false, i + 2, 2, false)); + modelList2.add(new ModelValue(dbData.get(i).getInt("TEST_COST") + "", false, i + 2, 3, false)); + if (i == 0) { + type = dbData.get(i).getStr("TEST_TYPE"); + } + if ((type != null && !type.equals(dbData.get(i).getStr("TEST_TYPE")))) { + System.out.println(type); + modelList2.add( + new ModelValue(type, false, i - typeSpan + 2, 1, false, i - typeSpan + 2, i + 1, 1, 1)); + type = dbData.get(i).getStr("TEST_TYPE"); + typeSpan = 0; + } + System.out.println(dbData.get(i).toString()); + if (i == dbData.size() - 1) { + System.out.println(type); + modelList2.add( + new ModelValue(type, false, i - typeSpan + 2, 1, false, i - typeSpan + 2, i + 2, 1, 1)); + } + model2.setValueAt(i + 1, i + 2, 0); + for (int ii = 4; ii < 8; ii++) { + model2.setValueAt("/", i + 2, ii); + } + typeSpan++; + } + } else { + for (int i = 0; i < data.length; i++) { + compareDataList.add(data[i]); + realIdStr.add(data[i][0]); + } + for (int i = 0; i < dbData.size(); i++) { + String realId = dbData.get(i).getStr("TEST_ID"); + String[] rowData; + if (realIdStr.indexOf(realId) >= 0) { + rowData = compareDataList.get(realIdStr.indexOf(realId)); + rowData[1] = dbData.get(i).getStr("TEST_TYPE"); + rowData[2] = dbData.get(i).getStr("TEST_PROJECT"); + rowData[3] = dbData.get(i).getStr("TEST_COST"); + compareDataList.set(realIdStr.indexOf(realId), rowData); + } else { + rowData = new String[data[0].length]; + rowData[0] = realId; + rowData[1] = dbData.get(i).getStr("TEST_TYPE"); + rowData[2] = dbData.get(i).getStr("TEST_PROJECT"); + rowData[3] = dbData.get(i).getStr("TEST_COST"); + rowData[data[0].length - 1] = ""; + compareDataList.add(rowData); + } + } + Collections.sort(compareDataList, new Comparator() { + + @Override + public int compare(String[] o1, String[] o2) { + // TODO Auto-generated method stub + return o1[1].compareTo(o2[1]); + } + }); + data = compareDataList.toArray(new String[compareDataList.size()][]); + model2 = new CTMap(data.length + 3, 9); + realIdStr.clear(); + for (int i = 0; i < data.length; i++) { + realIdStr.add(data[i][0]); + modelList2.add(new ModelValue(data[i][2] == null ? "" : data[i][2], false, i + 2, 2, false)); + modelList2.add(new ModelValue(data[i][3] == null ? "" : data[i][3], false, i + 2, 3, false)); + if (i == 0) { + type = data[i][1]; + } + if ((type != null && !type.equals(data[i][1]))) { + System.out.println(type); + modelList2.add( + new ModelValue(type, false, i - typeSpan + 2, 1, false, i - typeSpan + 2, i + 1, 1, 1)); + type = data[i][1]; + typeSpan = 0; + } + System.out.println(Arrays.toString(data[i])); + if (i == data.length - 1) { + System.out.println(type); + modelList2.add( + new ModelValue(type, false, i - typeSpan + 2, 1, false, i - typeSpan + 2, i + 2, 1, 1)); + } + + model2.setValueAt(i + 1, i + 2, 0); + for (int ii = 4; ii < 9; ii++) { + model2.setValueAt((data[i][ii] == null) ? "/" : data[i][ii], i + 2, ii); + } + typeSpan++; + } + } + + int buttom = data.length == 0 ? dbData.size() + 2 : data.length + 2; + modelList2.add(new ModelValue("Ŀúϼ", false, buttom, 0, false, buttom, buttom, 0, 2)); + modelList2.add(new ModelValue("jd2_zfy", true, buttom, 3, false)); + modelList2.add(new ModelValue("jd2_dvfy", true, buttom, 4, false)); + modelList2.add(new ModelValue("jd2_pvfy", true, buttom, 5, false)); + modelList2.add(new ModelValue("jd2_prfy", true, buttom, 6, false)); + modelList2.add(new ModelValue("jd2_srfy", true, buttom, 7, false)); + + initModel(model2, modelList2); + + table2 = new CTable(model2) { + @Override + public boolean isCellEditable(int row, int col) { + if (modelList2.isDisableEdit(row, col)) { + return false; + } + return true; + } + }; + + table2.setRowHeight(25); + table2.setBorder(BorderFactory.createLineBorder(Color.black)); + table2.getColumnModel().getColumn(0).setPreferredWidth(100); + table2.getColumnModel().getColumn(1).setPreferredWidth(60); + table2.getColumnModel().getColumn(2).setPreferredWidth(80); + table2.getColumnModel().getColumn(3).setPreferredWidth(60); + table2.getColumnModel().getColumn(4).setPreferredWidth(50); + table2.getColumnModel().getColumn(5).setPreferredWidth(50); + table2.getColumnModel().getColumn(6).setPreferredWidth(50); + table2.getColumnModel().getColumn(7).setPreferredWidth(50); + table2.getColumnModel().getColumn(8).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 + + 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; + } + }; + + DefaultCellEditor dce = new DefaultCellEditor(new JTextField()) { + JTable table; + int row; + int col; + + @Override + public Component getTableCellEditorComponent(JTable paramJTable, Object paramObject, boolean paramBoolean, + int paramInt1, int paramInt2) { + this.table = paramJTable; + this.row = paramInt1; + this.col = paramInt2; + return super.getTableCellEditorComponent(paramJTable, paramObject, paramBoolean, paramInt1, paramInt2); + } + + @Override + public Object getCellEditorValue() { + Object obj = super.getCellEditorValue(); + if (obj != null) { + String objStr = obj.toString().trim(); + try { + if ("/".equals(objStr) || "".equals(objStr)) { + objStr = "0"; + } + int num = Integer.parseInt(objStr); + System.out.println("ֵ" + num); + if (num < 0) { + System.out.println("ֻȻ\"/\""); + MessageBox.post("ֻȻ\"/\"", "", MessageBox.ERROR); + return "/"; + } + int sum = 0; + Object sumObj; + for (int i = 2; i < row; i++) { + sumObj = table.getValueAt(i, col); + if (sumObj != null && !"/".equals(sumObj.toString().trim())) { + sum += Double.parseDouble( + (sumObj = table.getValueAt(i, 3)) == null ? "0" : sumObj.toString().trim()); + } + } + if (!"0".equals(objStr)) { + sum += Double.parseDouble( + (sumObj = table.getValueAt(row, 3)) == null ? "0" : sumObj.toString().trim()); + } + for (int i = row + 1; i < table.getRowCount() - 1; i++) { + sumObj = table.getValueAt(i, col); + if (sumObj != null && !"/".equals(sumObj.toString().trim())) { + sum += Double.parseDouble( + (sumObj = table.getValueAt(i, 3)) == null ? "0" : sumObj.toString().trim()); + } + } + table.setValueAt(sum, table.getRowCount() - 1, col); + double sum1 = Double + .parseDouble(((sumObj = table.getValueAt(table.getRowCount() - 1, 4)) == null + || "".equals(sumObj.toString().trim())) ? "0" : sumObj.toString().trim()); + double sum2 = Double + .parseDouble(((sumObj = table.getValueAt(table.getRowCount() - 1, 5)) == null + || "".equals(sumObj.toString().trim())) ? "0" : sumObj.toString().trim()); + double sum3 = Double + .parseDouble(((sumObj = table.getValueAt(table.getRowCount() - 1, 6)) == null + || "".equals(sumObj.toString().trim())) ? "0" : sumObj.toString().trim()); + double sum4 = Double + .parseDouble(((sumObj = table.getValueAt(table.getRowCount() - 1, 7)) == null + || "".equals(sumObj.toString().trim())) ? "0" : sumObj.toString().trim()); + table.setValueAt(sum1 + sum2 + sum3 + sum4, table.getRowCount() - 1, 3); + table2.revalidate(); + table2.repaint(); + } catch (NumberFormatException e1) { + e1.printStackTrace(); + System.out.println("ֻȻ\"/\""); + MessageBox.post("ֻȻ\"/\"", "", MessageBox.ERROR); + obj = "/"; + } catch (Exception e2) { + e2.printStackTrace(); + obj = "/"; + } + } + if ("0".equals(obj.toString().trim())) { + obj = "/"; + } + return obj; + } + }; + tcr2.setHorizontalAlignment(SwingConstants.CENTER); + table2.getColumnModel().getColumn(4).setCellEditor(dce); + table2.getColumnModel().getColumn(5).setCellEditor(dce); + table2.getColumnModel().getColumn(6).setCellEditor(dce); + table2.getColumnModel().getColumn(7).setCellEditor(dce); + table2.setAutoResizeMode(CTable.AUTO_RESIZE_NEXT_COLUMN); + table2.setDefaultRenderer(Object.class, tcr2); + table2.addMouseListener(rightClick()); + inner.add(table2, BorderLayout.SOUTH); + + JPanel btns = new JPanel(new FlowLayout(FlowLayout.CENTER)); + JButton create = new JButton("Լƻ"); + create.addActionListener(create()); + JButton updateDV = new JButton("DV"); + updateDV.addActionListener(update("DV")); + JButton updatePV = new JButton("PV"); + updatePV.addActionListener(update("PV")); + JButton updatePR = new JButton("PR"); + updatePR.addActionListener(update("PR")); + JButton updateSR = new JButton("SR"); + updateSR.addActionListener(update("SR")); + + JButton testBtn = new JButton("table"); + testBtn.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + String[][] temp = new String[0][]; + TCTableUtil.setTableRows(form, "jd2_xpcsxqd", "JD2_XPCSXQD", colNames, temp); +// try { +// Map testMap = ((TCComponentItemRevision) form.whereReferenced()[0].getComponent()) +// .getClassificationAttributes(); +// for (Entry entry : testMap.entrySet()) { +// System.out.println(entry.getKey() + "====>" + entry.getValue()); +// } +// } catch (TCException e1) { +// // TODO Auto-generated catch block +// e1.printStackTrace(); +// } + testFlag = true; + } + }); + btns.add(create); + btns.add(updateDV); + btns.add(updatePV); + btns.add(updatePR); + btns.add(updateSR); + btns.add(testBtn); + + menu.setVisible(false); + addR = new JMenuItem(""); + addR.setEnabled(false); + addR.addActionListener(addRow()); + menu.add(addR); + + JScrollPane jsp = new JScrollPane(inner); + root.add(jsp, BorderLayout.CENTER); + root.add(btns, BorderLayout.SOUTH); + this.add(root); + } + + @Override + public void saveRendering() { + System.out.println("ǩ"); + if (testFlag) { + return; + } + saveModel(table1, modelList1); + saveModel(table2, modelList2); + + Object obj; + if (data.length == 0) { + if (dbData.size() == 0) { + try { + dbData = Db.use(DBUtil.getDataSource(session)) + .query("select * from JD2_Machine ORDER BY TEST_TYPE ASC"); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + data = new String[table2.getRowCount() - 3][9]; + + for (int i = 0; i < dbData.size(); i++) { + data[i][0] = dbData.get(i).getStr("TEST_ID"); + data[i][1] = dbData.get(i).getStr("TEST_TYPE"); + data[i][2] = dbData.get(i).getStr("TEST_PROJECT"); + data[i][3] = dbData.get(i).getStr("TEST_COST"); + for (int ii = 4; ii < 9; ii++) { + data[i][ii] = (obj = model2.getValueAt(i + 2, ii)) == null ? "" : obj.toString(); + } + } + System.out.println("dbData.size() " + dbData.size()); + System.out.println("table2.getRowCount() " + table2.getRowCount()); + for (int i = dbData.size(); i < table2.getRowCount() - 3; i++) { + data[i][0] = realIdStr.get(i); + for (int ii = 1; ii < 9; ii++) { + data[i][ii] = (obj = model2.getValueAt(i + 2, ii)) == null ? "" : obj.toString(); + } + } + System.out.println(Arrays.deepToString(data)); + TCTableUtil.setTableRows(form, "jd2_xpcsxqd", "JD2_XPCSXQD", colNames, data); + } else { + String[][] newData = new String[table2.getRowCount() - 3][9]; + for (int i = 0; i < data.length; i++) { + System.arraycopy(data[i], 0, newData[i], 0, 4); + for (int ii = 4; ii < 9; ii++) { + newData[i][ii] = (obj = model2.getValueAt(i + 2, ii)) == null ? "" : obj.toString(); + } + } + for (int i = data.length; i < table2.getRowCount() - 3; i++) { + newData[i][0] = realIdStr.get(i); + for (int ii = 1; ii < 9; ii++) { + newData[i][ii] = (obj = model2.getValueAt(i + 2, ii)) == null ? "" : obj.toString(); + } + } + System.out.println(Arrays.deepToString(newData)); + TCTableUtil.setTableRows(form, "jd2_xpcsxqd", "JD2_XPCSXQD", colNames, newData); + } + + } + + private MouseAdapter rightClick() { + return new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON3 && form.isCheckedOut() && table2.getSelectedRow() != -1) { + int row = table2.getSelectedRow(); + boolean flag = (row > 1 && row < table2.getRowCount() - 1); + addR.setEnabled(flag); + menu.show(e.getComponent(), e.getX(), e.getY()); + } + } + }; + } + + private ActionListener addRow() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent paramActionEvent) { + // TODO Auto-generated method stub + int row = model2.getRowCount() - 2; + int num = Integer.parseInt(model2.getValueAt(row, 0).toString()); + modelList2.findAndAddRow(row + 1, table2.getColumnCount(), 1); + model2.insertRow(model2.getRowCount() - 1); + realIdStr.add(System.currentTimeMillis() + ""); + model2.setValueAt(num + 1, row + 1, 0); + for (int i = 4; i < 8; i++) { + model2.setValueAt("/", row + 1, i); + } + table2.revalidate(); + table2.repaint(); + } + }; + } + + private ActionListener create() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent paramActionEvent) { + // TODO Auto-generated method stub + try { + StringBuilder msg = new StringBuilder(); + TCComponentItemRevision rev = (TCComponentItemRevision) form.whereReferenced()[0].getComponent(); + TCComponent[] comps = rev.getRelatedComponents("JD2_CSJH"); + String exist = ""; + for (TCComponent t : comps) { + exist += t.getProperty("object_name"); + } + List colData = new ArrayList(); + String ownner = form.getTCProperty("owning_user").getUIFValue(); + for (int i = 0; i < 4; i++) { + if (exist.contains(jieduan[i])) { + System.out.println("\"" + jieduan[i] + "׶\"ԼƻѴ"); + msg.append("\"" + jieduan[i] + "׶\"ԼƻѴ\n"); + continue; + } + Object obj; + Object temp; + for (int ii = 2; ii < table2.getRowCount() - 1; ii++) { + obj = table2.getValueAt(ii, i + 4); + if (obj != null && !"/".equals(obj.toString().trim())) { + // colNames2 = { "jd2_no", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syfy", + // "jd2_sycs" }; + String[] row = new String[6]; + row[0] = realIdStr.get(ii - 2); + row[1] = ownner; + row[2] = (temp = table2.getValueAt(ii, 2)) == null ? "" : temp.toString(); + row[3] = obj.toString().trim(); + row[4] = (temp = table2.getValueAt(ii, 3)) == null ? "0" : temp.toString().trim(); + row[5] = "1"; + System.out.println(Arrays.toString(row)); + colData.add(row); + } + } + if (colData.size() != 0) { + TCComponentItemType type = (TCComponentItemType) session.getTypeComponent("JD2_GTXPXMCSJH"); + TCComponentItem item = type.create(null, null, "JD2_GTXPXMCSJH", jieduan[i] + "׶βԼƻ", "", + null); + rev.add("JD2_CSJH", item); + TCComponentItemRevision rev1 = item.getLatestItemRevision(); + TCComponentForm form1 = (TCComponentForm) rev1 + .getRelatedComponents("IMAN_master_form_rev")[0]; + String[][] dataArr = colData.toArray(new String[colData.size()][6]); + System.out.println(Arrays.deepToString(dataArr)); + TCTableUtil.setTableRows(form1, "jd2_csjhtable", "JD2_CSJHTABLE", colNames2, dataArr); + msg.append("\"" + jieduan[i] + "׶\"Լƻɹ\n"); + } + colData.clear(); + } + + MessageBox.post(msg.toString(), "ʾ", MessageBox.WARNING); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }; + } + + @Override + public boolean isRenderingModified() { + // TODO Auto-generated method stub + return form.isCheckedOut(); + } + +// String[] textArr1 = { "ĿϢ", "ʱ䣺", "ͺţ", "ͺţ", "Ʒͺţ", "Ŀϣ", "Ʒ", "Ʒ㣺", "Ʒʾ", "ճ̣", +// "ȼ", "׶Σ" }; +// String[] propArr = { "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 void initModel(CTMap model, ModelList modelList) { + try { + //ȡĶ汾 + TCComponentItemRevision rev = (TCComponentItemRevision) form.whereReferenced()[0].getComponent(); + //ȡð汾Ķ + AIFComponentContext[] aifs = rev.whereReferenced(); + for (AIFComponentContext aif : aifs) { + TCProperty tcproperty = ((TCComponent) aif.getComponent()).getTCProperty("project_list"); + //ȡĿбµĿ + TCComponent[] tcComponents = tcproperty.getReferenceValueArray(); + for (TCComponent project1 : tcComponents) { + if (project1 instanceof TCComponentProject) { + project = (TCComponentProject) project1; + } + } + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + for (ModelValue mv : modelList) { + if (mv.isProp()) { + if (prop.containsKey(mv.getValue())) { + if (modelList == modelList1 && project != null) { + // ӳ + try { + switch (mv.getValue()) { + case "jd2_lxsj": + model.setValueAt(project.getProperty("creation_date"), mv.getRow(), mv.getCol()); + break; + case "jd2_xmxx": + model.setValueAt(project.getProjectID(), mv.getRow(), mv.getCol()); + break; + case "jd2_jbxh": + model.setValueAt(project.getProperty("jd2_cpxh"), mv.getRow(), mv.getCol()); + break; + case "jd2_kfdj": + model.setValueAt(project.getProperty("jd2_xmdj"), mv.getRow(), mv.getCol()); + break; + case "jd2_kfjd": + String str = form.getProperty("jd2_kfjd"); + JCheckPanel checkPanel = new JCheckPanel(jieduan, false); + checkPanel.setSelected(str); + model.setValueAt(checkPanel, mv.getRow(), mv.getCol()); + table1.getColumnModel().getColumn(mv.getCol()) + .setCellEditor(new MyCellEditor3(new JTextField())); + break; + case "jd2_cpbgd": + //ȡĿĿб + TCComponent[] cpbg = project.getRelatedComponents("project_data"); + for (TCComponent cpbgTask : cpbg) { + //ҵĿе Ʒ + if ("Ʒ".equals(cpbgTask.toString())) { + //ȡȥƷı + TCComponent[] project_data = cpbgTask.getRelatedComponents("project_data"); + if (project_data.length > 0) { + String displayValue = ""; + for (TCComponent task : project_data) { + displayValue += task.toString() + ";"; + } + if ("".equals(form.getProperty("jd2_cpbgd")) || form.getProperty("jd2_cpbgd") == null) { + model.setValueAt(displayValue, mv.getRow(), mv.getCol()); + } else { + model.setValueAt(form.getProperty("jd2_cpbgd"), mv.getRow(), mv.getCol()); + } + table1.addMouseListener(openCPBGD(project_data, mv, model)); + } else { + form.setProperty("jd2_cpbgd", ""); + } + } + + } +// TCComponent[] cpbgd = project.getRelatedComponents("jd2_cpbgd");// ֪ʲô +// if (cpbgd.length > 0) { +// String displayValue = ""; +// for (TCComponent comp : cpbgd) { +// displayValue += comp.toString() + ";"; +// } +// model.setValueAt(displayValue, mv.getRow(), mv.getCol()); +// table1.addMouseListener(openCPBGD(cpbgd, mv)); +// } + break; + case "jd2_kfrc": + //TCComponent[] kfrc = project.getRelatedComponents("jd2_kfrc"); + //ȡĿĿб + TCComponent[] xmsj = project.getRelatedComponents("project_data"); + for (TCComponent xmjhTask : xmsj) { + //ҵĿе Ŀƻ + if ("Ŀƻ".equals(xmjhTask.toString())) { + //ڻȡĿƻе,Ҳʱ,תΪʱ + TCComponent[] project_data = xmjhTask.getRelatedComponents("project_data"); + if (project_data.length > 0) { + TCComponentSchedule schedule = (TCComponentSchedule) project_data[0]; + TCComponent[] tasks = schedule.getAllTasks(); + String startTime = ""; + String endTime = ""; + for (TCComponent scheduleTask : tasks) { + if ("".equals(scheduleTask.getProperty("object_name"))) { + startTime = scheduleTask.getProperty("start_date"); + } + if ("СPRA".equals(scheduleTask.getProperty("object_name"))) { + endTime = scheduleTask.getProperty("finish_date"); + } + } + if (!"".equals(startTime) || !"".equals(endTime)) { + model.setValueAt(startTime + " - " + endTime, mv.getRow(), mv.getCol()); + } + } + } + } + +// if (kfrc.length > 0) { +// TCComponentSchedule schedule = (TCComponentSchedule) kfrc[0]; +// TCComponent[] tasks = schedule.getAllTasks(); +// String startTime = ""; +// String endTime = ""; +// for (TCComponent task : tasks) { +// if ("".equals(task.getProperty("object_name"))) { +// startTime = task.getProperty(""); +// } +// if ("СPRA".equals(task.getProperty("object_name"))) { +// endTime = task.getProperty(""); +// } +// } +// if (!"".equals(startTime) || !"".equals(endTime)) { +// model.setValueAt(startTime + "-" + endTime, mv.getRow(), mv.getCol()); +// } +// } + break; + default: + if ("".equals(prop.get(mv.getValue()))) { + model.setValueAt("/", mv.getRow(), mv.getCol()); + } else { + model.setValueAt(prop.get(mv.getValue()), mv.getRow(), mv.getCol()); + } + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } else { + model.setValueAt(prop.get(mv.getValue()), mv.getRow(), mv.getCol()); + } + } else { + System.out.println("ԡ" + mv.getValue() + ""); + } + } else { + model.setValueAt(mv.getValue(), mv.getRow(), mv.getCol()); + } + if (mv.isCombine()) { + model.combine(mv.getCombineRows(), mv.getCombineColumns()); + } + } + } + + private MouseAdapter openCPBGD(TCComponent[] cpbgd, ModelValue mv, CTMap model) { + return new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + + if (e.getClickCount() == 1 && table1.getSelectedRow() == mv.getRow() + && table1.getSelectedColumn() == mv.getCol()) { + + try { + if (cpbgd.length > 1) { + List data = new ArrayList(); + for (TCComponent comp : cpbgd) { + data.add(new String[] {data.size() + 1 +"" , comp.toString() }); + } + DialogUtil.TableMsg msg = DialogUtil.createTableMsg(new String[] { "", "" }, data); + int res = JOptionPane.showConfirmDialog($this, msg.panel, "ѡ", JOptionPane.PLAIN_MESSAGE); + if (res == JOptionPane.OK_OPTION) { + String cpbgdValue = ""; + //ȡѡе + int[] selRowIndex = msg.table.getSelectedRows(); + //ȡ + DefaultTableModel tableModel = (DefaultTableModel) msg.table.getModel(); + if (selRowIndex.length > 1) { + for (int i = 0; i < selRowIndex.length; i++) { + //õָԪֵ + cpbgdValue += tableModel.getValueAt(selRowIndex[i], 1) + ";"; + } + model.setValueAt(cpbgdValue, mv.getRow(), mv.getCol()); + form.setProperty("jd2_cpbgd", cpbgdValue); + } + else { + TCComponentItem item = (TCComponentItem) cpbgd[msg.table.getSelectedRow()]; + changeCpbgd(item,mv,model,form); + } + //TCComponentItem item = (TCComponentItem) cpbgd[msg.table.getSelectedRow()]; + //changeCpbgd(item,mv,model,form); + //if (msg.table.getSelectedRow() > 0) { +// TCComponentItem item = (TCComponentItem) cpbgd[msg.table.getSelectedRow()]; +// TCComponent[] tccitem = item.getLatestItemRevision() +// .getTCProperty("IMAN_specification").getReferenceValueArray(); +// TCComponentDataset dataset = (TCComponentDataset) tccitem[0]; +// dataset.open(); +// model.setValueAt(item.getProperty("object_string"), mv.getRow(), mv.getCol()); + //} + } + } else { + TCComponentItem item = (TCComponentItem) cpbgd[0]; + changeCpbgd(item,mv,model,form); + } + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + }; + } + + private void changeCpbgd(TCComponentItem item, ModelValue mv, CTMap model,TCComponentForm form) { + try { + TCComponent[] tccitem = item.getLatestItemRevision() + .getTCProperty("IMAN_specification").getReferenceValueArray(); + String cpbgdValue = item.getProperty("object_string"); + model.setValueAt(cpbgdValue, mv.getRow(), mv.getCol()); + form.setProperty("jd2_cpbgd", cpbgdValue); + if (tccitem.length > 0) { + TCComponentDataset dataset = (TCComponentDataset) tccitem[0]; + dataset.open(); + } + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + } + + private void saveModel(JTable table, ModelList modelList) { + //ǩʱȡѡ + table.getSelectionModel().clearSelection(); + Object obj; + for (ModelValue mv : modelList) { + if (mv.isProp()) { + if (prop.containsKey(mv.getValue())) { + obj = table.getValueAt(mv.getRow(), mv.getCol()); + if (modelList == modelList1 && project != null) { + if ("jd2_kfjd".equals(mv.getValue())) { + obj = table.getValueAt(mv.getRow(), mv.getCol()); + if (obj != null) { + String selectedText = ((JCheckPanel) obj).getSelectedText(); + try { + form.setProperty(mv.getValue(), selectedText); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + try { + if (!"jd2_kfjd".equals(mv.getValue())) { + form.setProperty(mv.getValue(), obj == null ? "" : obj.toString()); + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + System.out.println("\"" + mv.getValue() + "\""); + } + } + } + }; + + private ActionListener update(String jieduanStr) { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent paramActionEvent) { + // TODO Auto-generated method stub + try { + TCComponentItemRevision rev = (TCComponentItemRevision) form.whereReferenced()[0].getComponent(); + TCComponent[] comps = rev.getRelatedComponents("JD2_CSJH"); + TCComponentItem item = null; + for (TCComponent comp : comps) { + System.out.println(comp.getProperty("object_string")); + if (comp.getProperty("object_string").contains(jieduanStr)) { + item = (TCComponentItem) comp; + break; + } + } + if (item == null) { + MessageBox.post("\"" + jieduanStr + "׶\"Լƻδȴ", "ʾ", MessageBox.WARNING); + return; + } + + TCComponentItemRevision rev1 = item.getLatestItemRevision(); + TCComponentForm form1 = (TCComponentForm) rev1.getRelatedComponents("IMAN_master_form_rev")[0]; + List> tableRows = TCTableUtil.getTableMapList(form1, "jd2_csjhtable", + colNames3); + List realNo = new ArrayList(); + for (Map map : tableRows) { + realNo.add(map.get("jd2_no")); + } + + String ownner = form.getTCProperty("owning_user").getUIFValue(); + Object obj, temp; + List jieduanList = Arrays.asList(jieduan); + for (int i = 2; i < table2.getRowCount() - 1; i++) { + obj = table2.getValueAt(i, jieduanList.indexOf(jieduanStr) + 4); + if (obj != null && !"/".equals(obj.toString().trim())) { + // colNames2 = { "jd2_no", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syfy", + // "jd2_sycs" }; + Map tempMap; + if (realNo.contains(realIdStr.get(i - 2))) { + int index = realNo.indexOf(realIdStr.get(i - 2)); + for (int ii = index; ii < realNo.size(); ii++) {// ٴظrealNo + if (realNo.get(ii).equals(realIdStr.get(i - 2))) { + tempMap = tableRows.get(ii); + tempMap.put("jd2_syxm", + (temp = table2.getValueAt(i, 2)) == null ? "" : temp.toString()); + tempMap.put("jd2_syts", obj.toString().trim()); + tempMap.put("jd2_syfy", + (temp = table2.getValueAt(i, 3)) == null ? "" : temp.toString()); + tableRows.set(ii, tempMap); + } + } + } else { + tempMap = new HashMap(); + tempMap.put("jd2_no", realIdStr.get(i - 2)); + tempMap.put("jd2_wtry", ownner); + tempMap.put("jd2_syxm", + (temp = table2.getValueAt(i, 2)) == null ? "" : temp.toString()); + tempMap.put("jd2_syts", obj.toString().trim()); + tempMap.put("jd2_syfy", + (temp = table2.getValueAt(i, 3)) == null ? "0" : temp.toString().trim()); + tempMap.put("jd2_sycs", "1"); + tableRows.add(tempMap); + } + } + } + TCTableUtil.setTableMapList(form1, "jd2_csjhtable", "JD2_CSJHTABLE", tableRows); + MessageBox.post("³ɹ", "ʾ", MessageBox.WARNING); + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }; + } + +} diff --git a/src/com/connor/jd/plm/form/PhotoFrame.java b/src/com/connor/jd/plm/form/PhotoFrame.java new file mode 100644 index 0000000..bde2a4c --- /dev/null +++ b/src/com/connor/jd/plm/form/PhotoFrame.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/form/SampleConfirmationForm.java b/src/com/connor/jd/plm/form/SampleConfirmationForm.java new file mode 100644 index 0000000..e0bdec1 --- /dev/null +++ b/src/com/connor/jd/plm/form/SampleConfirmationForm.java @@ -0,0 +1,1784 @@ +package com.connor.jd.plm.form; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Image; +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.io.IOException; +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.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +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.border.EmptyBorder; +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.JRadioPanel; +import com.connor.jd.plm.table.MyCellEditor; +import com.connor.jd.plm.table.MyCellEditor1; +import com.connor.jd.plm.table.MyCellEditor2; +import com.connor.jd.plm.table.MyComboBoxRenderer; +import com.connor.jd.plm.table.TCTableUtil; +import com.connor.jd.plm.utils.JDMethodUtil; +import com.teamcenter.rac.aif.AbstractAIFApplication; +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.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.ICSProperty; +import com.teamcenter.rac.stylesheet.AbstractRendering; +import com.teamcenter.rac.util.MessageBox; + +public class SampleConfirmationForm extends AbstractRendering { + private AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + private TCComponentForm form; + private TCSession session; + private CardLayout cl = new CardLayout(); + private JPanel center = null; + private JPopupMenu menu = new JPopupMenu(); + private JPopupMenu menu2 = new JPopupMenu(); + private JPopupMenu menu3 = new JPopupMenu(); + private JPanel confirmPanel = new JPanel(); + private JPanel examinePanel = new JPanel(); + private CTMap model; + private CTMap model2; + private CTMap model3; + private CTable table; + private CTable table2; + private CTable table3; + private int top = 13;// ͷ + private int bottom;// м䲿ֽ + private int end = 1;// β+1 + private int top2 = 4; + private int bottom2; + private int end2 = 16; + private Map prop; + private Map general; + private Map general3; + private List disableEdit; + private List disableEdit3; + private Map picMap = new HashMap();// ͼƬ; + private Map fileMap = new HashMap();// ļ; + private List disableEdit2; + private JRadioPanel yssl; + private JCheckPanel mqjd; + private JComboBox bpdj; + private JComboBox fl; + private JComboBox zt; + private JComboBox jued; + private String[] colNames = { "jd2_no", "jd2_gg", "jd2_gg1", "jd2_gc", "jd2_gc1", "jd2_1", "jd2_2", "jd2_3", + "jd2_4", "jd2_5", "jd2_6", "jd2_7", "jd2_8", "jd2_9", "jd2_10", "jd2_min", "jd2_max", "jd2_jg" }; + private String[] colNames1 = { "jd2_ctq1", "jd2_ctq2", "jd2_ctq3", "jd2_ctq4", "jd2_ctq5", "jd2_ctq6", "jd2_ctq7", + "jd2_ctq8" }; + private String[] colNames2 = { "jd2_no", "jd2_ctq1", "jd2_ctq2", "jd2_ctq3", "jd2_ctq4", "jd2_ctq5", "jd2_ctq6", + "jd2_ctq7", "jd2_ctq8" }; + private String[] colNames3 = { "jd2_ctq1", "jd2_ctq2", "jd2_ctq3", "jd2_ctq4", "jd2_ctq5", "jd2_ctq6", "jd2_ctq7", + "jd2_ctq8" }; + private Map jgItems = new HashMap(); + private JMenuItem addP; + private JMenuItem delP; + private JMenuItem addR; + private JMenuItem insertR; + private JMenuItem delR; + private JMenuItem addR2; + private JMenuItem insertR2; + private JMenuItem delR2; + private JMenuItem addF; + private JMenuItem delF; + private TCComponentItemRevision rev; + private String[][] dataStore = new String[8][13]; + + public SampleConfirmationForm(TCComponent arg0) throws Exception { + super(arg0); + + if (arg0 instanceof TCComponentForm) { + this.form = (TCComponentForm) arg0; + this.session = (TCSession) app.getSession(); + loadRendering(); + } + } + + @Override + public void loadRendering() throws TCException { + jgItems.put("ϸ", "0"); + jgItems.put("ܾ", "1"); + jgItems.put("", "2"); + jgItems.put("ͼֽ", "3"); + jgItems.put(" ", null); + AIFComponentContext[] aifs = form.whereReferenced(); + for (AIFComponentContext aif : aifs) { + if ("JD2_GTYPQRDRevision".equals(aif.getComponent().getType())) { + rev = (TCComponentItemRevision) aif.getComponent(); + break; + } + } + + setLayout(new BorderLayout()); + JPanel root = new JPanel(new BorderLayout()); + root.setPreferredSize(new Dimension(800, 600)); + root.setBorder(new EmptyBorder(0, 0, 0, 25)); + // ͷ + JPanel buttons = new JPanel(new FlowLayout(FlowLayout.LEFT)); + JButton confirm = new JButton("Ʒȷϵ"); + JButton examine = new JButton("CTQ"); + + confirm.addActionListener(confirm()); + examine.addActionListener(examine()); + buttons.add(confirm); + buttons.add(examine); + + // + center = new JPanel(cl); + + // ȷϵ + confirmPanel.setBorder(BorderFactory.createLineBorder(Color.black, 1)); + confirmPanel.setLayout(new BorderLayout()); + confirmPanel.setPreferredSize(new Dimension(800, 600)); + + // + model = new CTMap(30, 20); + bottom = model.getRowCount() - end; + 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(60); + table.getColumnModel().getColumn(2).setPreferredWidth(50); + table.getColumnModel().getColumn(3).setPreferredWidth(50); + table.getColumnModel().getColumn(4).setPreferredWidth(50); + table.getColumnModel().getColumn(5).setPreferredWidth(60); + table.getColumnModel().getColumn(6).setPreferredWidth(60); + for (int i = 7; i < model.getColumnCount() - 1; i++) { + table.getColumnModel().getColumn(i).setPreferredWidth(45); + } + table.getColumnModel().getColumn(model.getColumnCount() - 1).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 JPanel) { + return (JPanel) value; + } + if (value instanceof JComboBox) { + return (JComboBox) 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); + for (int i = 0; i < model.getColumnCount(); i++) { + table.getColumnModel().getColumn(i).setCellEditor(new MyCellEditor(new JTextField(), top, end, bottom)); + } + table.addMouseListener(rightClick()); + + model3 = new CTMap(13, 20); + initModel3(); + table3 = new CTable(model3) { + @Override + public boolean isCellEditable(int row, int col) { + if (isEditorDisable(disableEdit3, row, col)) { + return false; + } + return true; + } + }; + table3.setRowHeight(25); + table3.setBorder(BorderFactory.createLineBorder(Color.black)); + table3.getColumnModel().getColumn(0).setPreferredWidth(40); + table3.getColumnModel().getColumn(1).setPreferredWidth(60); + table3.getColumnModel().getColumn(2).setPreferredWidth(50); + table3.getColumnModel().getColumn(3).setPreferredWidth(50); + table3.getColumnModel().getColumn(4).setPreferredWidth(50); + table3.getColumnModel().getColumn(5).setPreferredWidth(60); + table3.getColumnModel().getColumn(6).setPreferredWidth(60); + for (int i = 7; i < model3.getColumnCount() - 1; i++) { + table3.getColumnModel().getColumn(i).setPreferredWidth(45); + } + table3.getColumnModel().getColumn(model3.getColumnCount() - 1).setPreferredWidth(80); + DefaultTableCellRenderer tcr3 = 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 JLabel) { + JLabel label = (JLabel) value; + if (isSelected) { + label.setForeground(Color.WHITE); + label.setBackground(new Color(0xff0078D7)); + label.setOpaque(true); + } else { + label.setForeground(new Color(0xff0078D7)); + label.setBackground(Color.WHITE); + label.setOpaque(true); + } + return label; + } + if (value instanceof JComboBox) { + return (JComboBox) 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; + } + + }; + tcr3.setHorizontalAlignment(SwingConstants.CENTER); + table3.setDefaultRenderer(Object.class, tcr3); + for (int i = 0; i < model3.getColumnCount(); i++) { + table3.getColumnModel().getColumn(i).setCellEditor(new MyCellEditor2(new JTextField())); + } + table3.addMouseListener(rightClick3()); + + // д + prop = form.getProperties(); + for (Entry entry : general.entrySet()) { + if (prop.containsKey(entry.getKey())) { + model.setValueAt(prop.get(entry.getKey()), entry.getValue()[0], entry.getValue()[1]); + } else { + model.setValueAt("", entry.getValue()[0], entry.getValue()[1]); + System.out.println("ԡ" + entry.getKey() + "δҵ"); + } + } + + for (Entry entry : general3.entrySet()) { + if (prop.containsKey(entry.getKey())) { + model3.setValueAt(prop.get(entry.getKey()), entry.getValue()[0], entry.getValue()[1]); + } else { + model3.setValueAt("", entry.getValue()[0], entry.getValue()[1]); + System.out.println("ԡ" + entry.getKey() + "δҵ"); + } + } + if (prop.containsKey("jd2_yssl")) { + yssl.setSelected(prop.get("jd2_yssl")); + } else { + System.out.println("ԡjd2_ysslδҵ"); + } + if (prop.containsKey("jd2_mqjd")) { + mqjd.setSelected(prop.get("jd2_mqjd")); + } else { + System.out.println("ԡjd2_mqjdδҵ"); + } + + for (Entry entry : picMap.entrySet()) { + int row = entry.getValue()[0]; + int col = entry.getValue()[1]; + if (prop.containsKey(entry.getKey())) { + TCComponent comp = null; + try { + if (!"".equals(prop.get(entry.getKey()))) { + comp = session.stringToComponent(prop.get(entry.getKey())); + TCComponentDataset dataset = (TCComponentDataset) comp; + String temp = System.getenv("temp"); + System.out.println(temp); + String[] types = dataset.getProperty("ref_names").split(","); + System.out.println(Arrays.toString(types)); + System.out.println(Arrays.toString(dataset.getFileNames(types[0]))); + File img = dataset.getFiles(types[0], temp)[0]; + System.out.println(img.getPath()); + + ImageIcon icon = new ImageIcon(img.getPath()); + + int[] arr = model3.getSpan(row, col); + System.out.println("row:" + arr[0] + ",col:" + arr[1]); + icon.setImage(icon.getImage().getScaledInstance( + table3.getColumnModel().getColumn(col).getPreferredWidth() * arr[1], + table3.getRowHeight() * arr[0], Image.SCALE_SMOOTH)); + JLabel label = new JLabel(); + label.setLayout(new FlowLayout(FlowLayout.CENTER)); + label.setIcon(icon); + label.setHorizontalAlignment(SwingConstants.CENTER); + label.addMouseListener(showImg(img.getPath())); + label.setToolTipText(dataset.getUid()); + model3.setValueAt(label, row, col); + } else { + model3.setValueAt(new JLabel(""), row, col); + } + } catch (Exception e) { + model3.setValueAt(new JLabel(""), row, col); + e.printStackTrace(); + } + + } else { + model3.setValueAt(new JLabel(""), row, col); + System.out.println("ԡ" + entry.getKey() + "δҵ"); + } + } + + for (Entry entry : fileMap.entrySet()) { + int row = entry.getValue()[0]; + int col = entry.getValue()[1]; + if (prop.containsKey(entry.getKey())) { + TCComponent comp = null; + try { + if (!"".equals(prop.get(entry.getKey()))) { + comp = session.stringToComponent(prop.get(entry.getKey())); + TCComponentDataset dataset = (TCComponentDataset) comp; + String temp = System.getenv("temp"); + System.out.println(temp); + String[] types = dataset.getProperty("ref_names").split(","); + System.out.println(Arrays.toString(types)); + System.out.println(Arrays.toString(dataset.getFileNames(types[0]))); + File img = dataset.getFiles(types[0], temp)[0]; + System.out.println(img.getPath()); + + int[] arr = model3.getSpan(row, col); + System.out.println("row:" + arr[0] + ",col:" + arr[1]); + JLabel label = new JLabel(); + label.setLayout(new FlowLayout(FlowLayout.CENTER)); + label.setForeground(new Color(0xff0078D7)); + label.setText(img.getName()); + label.setHorizontalAlignment(SwingConstants.CENTER); + label.addMouseListener(showFile(dataset)); + label.setToolTipText(dataset.getUid()); + model3.setValueAt(label, row, col); + } else { + model3.setValueAt(new JLabel(""), row, col); + } + } catch (Exception e) { + model3.setValueAt(new JLabel(""), row, col); + e.printStackTrace(); + } + + } else { + model3.setValueAt(new JLabel(""), row, col); + System.out.println("ԡ" + entry.getKey() + "δҵ"); + } + } + + if (prop.containsKey("jd2_ypqrdtable")) { + String[][] tableRows = TCTableUtil.getTableRows(form, "jd2_ypqrdtable", colNames); + System.out.println(Arrays.deepToString(tableRows)); + + for (int i = 0; i < tableRows.length; i++) { + for (int ii = 0; ii < tableRows[0].length; ii++) { + if (i + top + 2 > bottom) { + 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 }); + bottom = model.getRowCount() - end; + } + if (ii == tableRows[0].length - 1) { + JComboBox jgComBox = new JComboBox(); + jgComBox.setRenderer(new MyComboBoxRenderer()); + for (Entry entry : jgItems.entrySet()) { + jgComBox.addItem(entry.getKey()); + } + jgComBox.setSelectedItem(tableRows[i][ii]); + model.setValueAt(jgComBox, i + top + 2, ii + 2); + } else { + model.setValueAt(tableRows[i][ii], i + top + 2, ii > 2 ? ii + 2 : ii); + } + } + } + } else { + System.out.println("ԡjd2_ypqrdtableδҵ"); + } + + // ӳ + prop = form.getProperties(); + AIFComponentContext[] parents = rev.getItem().whereReferenced(); + TCComponentItemRevision parentRev = null; + for (AIFComponentContext aif : parents) { + try { + System.out.println(aif.getComponent().getProperty("object_string")); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (aif.getComponent() instanceof TCComponentItemRevision) { + parentRev = (TCComponentItemRevision) aif.getComponent(); + } + } + if (parentRev != null) { + String partName = parentRev.getProperty("object_name"); + System.out.println(partName); + if (prop.containsKey("jd2_ljm")) { + model.setValueAt(partName, general.get("jd2_ljm")[0], general.get("jd2_ljm")[1]); + } + String materialCode = parentRev.getProperty("item_id"); + System.out.println(materialCode); + if (prop.containsKey("jd2_wlbm")) { + model.setValueAt(materialCode, general.get("jd2_wlbm")[0], general.get("jd2_wlbm")[1]); + } + TCComponent[] drawings = parentRev.getReferenceListProperty("TC_Is_Represented_By"); + if (drawings != null && drawings.length > 0) { + TCComponentItemRevision drawingRev = (TCComponentItemRevision) drawings[0]; + String drawingId = drawingRev.getProperty("item_id"); + System.out.println(drawingId); + if (prop.containsKey("jd2_th")) { + model.setValueAt(drawingId, general.get("jd2_th")[0], general.get("jd2_th")[1]); + } + } + if (parentRev.getClassificationObjects() != null && parentRev.getClassificationObjects().length > 0) { + TCComponentICO ico = parentRev.getClassificationObjects()[0]; + ICSProperty[] parentICSProps = ico.getICSProperties(true); + for (int i = 0; i < parentICSProps.length; i++) { + if (parentICSProps[i].getId() == 1050) { + if (prop.containsKey("jd2_ljywm")) { + model.setValueAt(parentICSProps[i].getValue(), general.get("jd2_ljywm")[0], + general.get("jd2_ljywm")[1]); + } + } + if (parentICSProps[i].getId() == 1058) { + if (prop.containsKey("jd2_gg")) { + model.setValueAt(parentICSProps[i].getValue(), general.get("jd2_gg")[0], + general.get("jd2_gg")[1]); + } + } + } + } + } + + JPanel inner = new JPanel(new BorderLayout()); + inner.add(table, BorderLayout.CENTER); + inner.add(table3, BorderLayout.SOUTH); + +// ScrollPane confirmScrollPanel1 = new ScrollPane(); +// confirmScrollPanel1.add(inner); + JScrollPane confirmScrollPanel1 = new JScrollPane(inner); + confirmPanel.add(confirmScrollPanel1, BorderLayout.CENTER); + + // + examinePanel.setBorder(BorderFactory.createLineBorder(Color.black, 1)); + examinePanel.setLayout(new BorderLayout()); + + model2 = new CTMap(49, 10); + bottom2 = model2.getRowCount() - end2; + disableEdit2 = new ArrayList(); + model2.setValueAt("SPL No", 0, 0); + disableEdit2.add("0,0"); + model2.combine(new int[] { 0, 1, 2, 3 }, new int[] { 0 }); + model2.setValueAt(" SPEC", 0, 1); + disableEdit2.add("0,1"); + model2.combine(new int[] { 0, 1 }, new int[] { 1 }); + for (int i = 0; i < 8; i++) { + model2.setValueAt("CTQ<" + (i + 1) + ">", 0, i + 2); + disableEdit2.add("0," + (i + 2)); + } + model2.setValueAt("LOW", 2, 1); + disableEdit2.add("2,1"); + model2.setValueAt("UP", 3, 1); + disableEdit2.add("3,1"); + + for (int i = top2; i < model2.getRowCount(); i++) { + model2.setValueAt(i - top2 + 1, i, 0); + disableEdit2.add(i + ",0"); + model2.combine(new int[] { i }, new int[] { 0, 1 }); + } + model2.setValueAt("MIN", bottom2 + 1, 0); + model2.setValueAt("MAX", bottom2 + 2, 0); + model2.setValueAt("R", bottom2 + 3, 0); + model2.setValueAt("׼ƫ", bottom2 + 4, 0); + model2.setValueAt("ƽ", bottom2 + 5, 0); + model2.setValueAt("X,BAR-3S", bottom2 + 6, 0); + model2.setValueAt("X,BAR+3S", bottom2 + 7, 0); + model2.setValueAt("CP", bottom2 + 8, 0); + model2.setValueAt("Cpu", bottom2 + 9, 0); + model2.setValueAt("Cpl", bottom2 + 10, 0); + model2.setValueAt("CPK", bottom2 + 11, 0); + model2.setValueAt("SU Ԥⲻ", bottom2 + 12, 0); + model2.setValueAt("SL Ԥⲻ", bottom2 + 13, 0); + model2.setValueAt("Ԥⲻ(PPM)", bottom2 + 14, 0); + model2.setValueAt("", bottom2 + 15, 0); + + table2 = new CTable(model2) { + /** + * + */ + private static final long serialVersionUID = 1L; + + @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)); + for (int i = 0; i < model2.getColumnCount(); i++) { + table2.getColumnModel().getColumn(i).setPreferredWidth(80); + } + 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 + 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); + 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.setDefaultRenderer(Object.class, tcr2); + MyCellEditor1[] editor1 = new MyCellEditor1[model2.getColumnCount()]; + for (int i = 0; i < model2.getColumnCount(); i++) { + editor1[i] = new MyCellEditor1(new JTextField(), top2, end2, bottom2); + table2.getColumnModel().getColumn(i).setCellEditor(editor1[i]); + } + table2.addMouseListener(rightClick2()); + examinePanel.add(table2, BorderLayout.CENTER); + if (prop.containsKey("jd2_ctq1")) { + String[][] tableRows = TCTableUtil.getTableRows(form, "jd2_ctq1", colNames1); + System.out.println(Arrays.deepToString(tableRows)); + for (int i = 0; i < tableRows.length; i++) { + for (int ii = 0; ii < tableRows[0].length; ii++) { + model2.setValueAt(tableRows[i][ii], i + 1, ii + 2); + if (i == 1) { + if (!"".equals(tableRows[i][ii])) { + if (tableRows[i][ii].contains("%")) { + String temp = tableRows[i][ii].replace("%", ""); + editor1[ii + 2].setLow(Double.parseDouble(temp) / 100); + } else { + editor1[ii + 2].setLow(Double.parseDouble(tableRows[i][ii])); + } + + editor1[ii + 2].setCnt(editor1[ii + 2].getCnt() + 1); + } + } + if (i == 2) { + if (!"".equals(tableRows[i][ii])) { + if (tableRows[i][ii].contains("%")) { + String temp = tableRows[i][ii].replace("%", ""); + editor1[ii + 2].setUp(Double.parseDouble(temp) / 100); + } else { + editor1[ii + 2].setUp(Double.parseDouble(tableRows[i][ii])); + } + + editor1[ii + 2].setCnt(editor1[ii + 2].getCnt() + 1); + } + } + } + } + } + if (prop.containsKey("jd2_ctq2")) { + String[][] tableRows = TCTableUtil.getTableRows(form, "jd2_ctq2", colNames2); + System.out.println(Arrays.deepToString(tableRows)); + for (int i = 0; i < tableRows.length; i++) { + for (int ii = 0; ii < tableRows[0].length; ii++) { + if (i + top2 > bottom2) { + int num = Integer.parseInt(model2.getValueAt(bottom2, 0).toString()); + model2.insertRow(++bottom2); + model2.setValueAt(num + 1, bottom2, 0); + model2.combine(new int[] { bottom2 }, new int[] { 0, 1 }); + } + model2.setValueAt(tableRows[i][ii], i + top2, ii > 0 ? ii + 1 : ii); + } + } + } + if (prop.containsKey("jd2_ctq3")) { + String[][] tableRows = TCTableUtil.getTableRows(form, "jd2_ctq3", colNames3); + System.out.println(Arrays.deepToString(tableRows)); + for (int i = 0; i < tableRows.length; i++) { + for (int ii = 0; ii < tableRows[0].length; ii++) { + model2.setValueAt(tableRows[i][ii], i + bottom2 + 1, ii + 2); + } + } + } + +// ScrollPane examineScrollPanel = new ScrollPane(); +// examineScrollPanel.add(examinePanel); + JScrollPane examineScrollPanel = new JScrollPane(examinePanel); + + // ȷϵҼ˵ + menu.setVisible(false); + addR = new JMenuItem(""); + addR.setEnabled(false); + menu.add(addR); + addR.addActionListener(addRow()); + insertR = new JMenuItem(""); + insertR.setEnabled(false); + menu.add(insertR); + insertR.addActionListener(insertRow()); + delR = new JMenuItem("ɾ"); + delR.setEnabled(false); + menu.add(delR); + delR.addActionListener(deleteRow()); + + menu3.setVisible(false); + addP = new JMenuItem("ͼƬ"); + addP.setEnabled(false); + menu3.add(addP); + addP.addActionListener(addPic()); + delP = new JMenuItem("ɾͼƬ"); + delP.setEnabled(false); + menu3.add(delP); + delP.addActionListener(delPic()); + addF = new JMenuItem("ϴļ"); + addF.setEnabled(false); + menu3.add(addF); + addF.addActionListener(addFile()); + delF = new JMenuItem("ɾļ"); + delF.setEnabled(false); + menu3.add(delF); + delF.addActionListener(delFile()); + + // 鵥Ҽ˵ + menu2.setVisible(false); + addR2 = new JMenuItem(""); + addR2.setEnabled(false); + menu2.add(addR2); + addR2.addActionListener(addRow2()); + insertR2 = new JMenuItem(""); + insertR2.setEnabled(false); + menu2.add(insertR2); + insertR2.addActionListener(insertRow2()); + delR2 = new JMenuItem("ɾ"); + delR2.setEnabled(false); + menu2.add(delR2); + delR2.addActionListener(deleteRow2()); + + center.add("confirm", confirmPanel); + center.add("examine", examineScrollPanel); + + root.add(buttons, BorderLayout.NORTH); + root.add(center, BorderLayout.CENTER); + this.add(menu); + this.add(menu2); + this.add(menu3); + this.add(root, BorderLayout.CENTER); + + cl.show(center, "confirm"); + } + + private void initModel() { + disableEdit = new ArrayList<>();// ༭ + general = new HashMap();// Ҫдһ + model.setValueAt("Ʒȷϵ", 0, 0); + disableEdit.add("0,0"); + model.setValueAt("ύ", 0, 14); + disableEdit.add("0,14"); + model.setValueAt("", 0, 16); + disableEdit.add("0,16"); + model.setValueAt("׼", 0, 18); + disableEdit.add("0,18"); + model.setValueAt("", 2, 0); + disableEdit.add("2,0"); + model.setValueAt("Ͳз", 2, 2); + disableEdit.add("2,2"); + general.put("jd2_bz", new int[] { 2, 14 }); +// disableEdit.add("2,14"); + general.put("jd2_sh", new int[] { 2, 16 }); +// disableEdit.add("2,16"); + general.put("jd2_pz", new int[] { 2, 18 }); +// disableEdit.add("2,18"); + model.setValueAt("", 4, 0); + disableEdit.add("4,0"); + general.put("creation_date", new int[] { 4, 2 }); + disableEdit.add("4,2"); + model.setValueAt("", 4, 5); + disableEdit.add("4,5"); + general.put("owning_user", new int[] { 4, 7 }); + disableEdit.add("4,7"); + general.put("jd2_bzrq", new int[] { 4, 14 }); +// disableEdit.add("4,14"); + general.put("jd2_shrq", new int[] { 4, 16 }); +// disableEdit.add("4,16"); + general.put("jd2_pzrq", new int[] { 4, 18 }); +// disableEdit.add("4,18"); + model.setValueAt("", 6, 0); + disableEdit.add("6,0"); + general.put("jd2_ljm", new int[] { 6, 2 }); + general.put("jd2_ljywm", new int[] { 6, 5 }); + model.setValueAt("ͺ", 6, 8); + disableEdit.add("6,8"); + general.put("jd2_xh", new int[] { 6, 10 }); + model.setValueAt("", 6, 14); + disableEdit.add("6,14"); + fl = new JComboBox(); + fl.setRenderer(new MyComboBoxRenderer()); + try { + if (form.getTCProperty("jd2_fl") != null) { + String[] items = form.getTCProperty("jd2_fl").getLOV().getListOfValues().getLOVDisplayValues(); + fl.addItem(" "); + for (String s : items) { + fl.addItem(s); + } + fl.setSelectedItem(form.getProperty("jd2_fl")); + if ("".equals(form.getProperty("jd2_fl"))) { + fl.setSelectedItem(" "); + } + model.setValueAt(fl, 6, 17); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + model.setValueAt("ϱ", 7, 0); + disableEdit.add("7,0"); + general.put("jd2_wlbm", new int[] { 7, 2 }); + model.setValueAt("", 7, 8); + disableEdit.add("7,8"); + yssl = new JRadioPanel(new String[] { "3", "5", "10", "30" }); + model.setValueAt(yssl, 7, 10); + model.setValueAt("״̬", 7, 14); + disableEdit.add("7,14"); + zt = new JComboBox(); + zt.setRenderer(new MyComboBoxRenderer()); + try { + if (form.getTCProperty("jd2_zt") != null) { + String[] items = form.getTCProperty("jd2_zt").getLOV().getListOfValues().getLOVDisplayValues(); + zt.addItem(" "); + for (String s : items) { + zt.addItem(s); + } + zt.setSelectedItem(form.getProperty("jd2_zt")); + if ("".equals(form.getProperty("jd2_zt"))) { + zt.setSelectedItem(" "); + } + model.setValueAt(zt, 7, 17); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + model.setValueAt("Ʒȼ", 8, 0); + disableEdit.add("8,0"); + bpdj = new JComboBox(); + bpdj.setRenderer(new MyComboBoxRenderer()); + try { + if (form.getTCProperty("jd2_bpdj") != null) { + String[] items = form.getTCProperty("jd2_bpdj").getLOV().getListOfValues().getLOVDisplayValues(); + for (String s : items) { + bpdj.addItem(s); + } + bpdj.setSelectedItem(form.getProperty("jd2_bpdj")); + model.setValueAt(bpdj, 8, 2); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + model.setValueAt("ο", 8, 8); + disableEdit.add("8,8"); + model.setValueAt("jd2_ckwl", 8, 10); + general.put("jd2_ckwl", new int[] { 8, 10 }); + model.setValueAt("ͼ", 9, 0); + disableEdit.add("9,0"); + general.put("jd2_th", new int[] { 9, 2 }); + model.setValueAt("", 10, 0); + disableEdit.add("10,0"); + general.put("jd2_gg", new int[] { 10, 2 }); + model.setValueAt("Ӧ", 11, 0); + disableEdit.add("11,0"); + general.put("jd2_gys", new int[] { 11, 2 }); + model.setValueAt("ԭ", 9, 8); + disableEdit.add("9,8"); + general.put("jd2_syyy", new int[] { 9, 10 }); + model.setValueAt("Ŀǰ׶", 12, 0); + disableEdit.add("12,0"); + mqjd = new JCheckPanel(new String[] { "DV", "PV", "PR", "SR", "ֳ", "MP" }); + model.setValueAt(mqjd, 12, 2); + + model.setValueAt("No", top, 0); + disableEdit.add(top + ",0"); + model.setValueAt("ߴ֤", top, 1); + disableEdit.add(top + ",1"); + model.setValueAt("ݣ#Ʒ/ǻţ", top, 7); + disableEdit.add(top + ",7"); + model.setValueAt("", top, 19); + disableEdit.add(top + ",19"); + model.setValueAt("", top + 1, 1); + disableEdit.add(top + 1 + ",1"); + model.setValueAt("Ϲ", top + 1, 5); + model.setValueAt("¹", top + 1, 6); + disableEdit.add(top + 1 + ",5"); + for (int i = 1; i < 11; i++) { + model.setValueAt("#" + i, top + 1, i + 6); + disableEdit.add(top + 1 + "," + (i + 6)); + } + model.setValueAt("Min", top + 1, 17); + disableEdit.add(top + 1 + ",17"); + model.setValueAt("Max", top + 1, 18); + disableEdit.add(top + 1 + ",18"); + + for (int i = top + 2; i <= bottom; i++) { + model.setValueAt(i - 1 - top, i, 0); + disableEdit.add(i + ",0"); + model.combine(new int[] { i }, new int[] { 2, 3, 4 }); + JComboBox jgComBox = new JComboBox(); + jgComBox.setRenderer(new MyComboBoxRenderer()); + for (Entry entry : jgItems.entrySet()) { + jgComBox.addItem(entry.getKey()); + } + model.setValueAt(jgComBox, i, model.getColumnCount() - 1); + } + + model.combine(new int[] { 0, 1 }, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }); + model.combine(new int[] { 0, 1 }, new int[] { 14, 15 }); + model.combine(new int[] { 0, 1 }, new int[] { 16, 17 }); + model.combine(new int[] { 0, 1 }, new int[] { 18, 19 }); + model.combine(new int[] { 2, 3 }, new int[] { 0, 1 }); + model.combine(new int[] { 2, 3 }, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }); + model.combine(new int[] { 2, 3 }, new int[] { 14, 15 }); + model.combine(new int[] { 2, 3 }, new int[] { 16, 17 }); + model.combine(new int[] { 2, 3 }, new int[] { 18, 19 }); + model.combine(new int[] { 4, 5 }, new int[] { 0, 1 }); + model.combine(new int[] { 4, 5 }, new int[] { 2, 3, 4 }); + model.combine(new int[] { 4, 5 }, new int[] { 5, 6 }); + model.combine(new int[] { 4, 5 }, new int[] { 7, 8, 9, 10, 11, 12, 13 }); + model.combine(new int[] { 4, 5 }, new int[] { 14, 15 }); + model.combine(new int[] { 4, 5 }, new int[] { 16, 17 }); + model.combine(new int[] { 4, 5 }, new int[] { 18, 19 }); + model.combine(new int[] { 6 }, new int[] { 0, 1 }); + model.combine(new int[] { 6 }, new int[] { 2, 3, 4 }); + model.combine(new int[] { 6 }, new int[] { 5, 6, 7 }); + model.combine(new int[] { 6 }, new int[] { 8, 9 }); + model.combine(new int[] { 6 }, new int[] { 10, 11, 12, 13 }); + model.combine(new int[] { 6 }, new int[] { 14, 15, 16 }); + model.combine(new int[] { 6 }, new int[] { 17, 18, 19 }); + model.combine(new int[] { 7 }, new int[] { 0, 1 }); + model.combine(new int[] { 7 }, new int[] { 2, 3, 4, 5, 6, 7 }); + model.combine(new int[] { 7 }, new int[] { 8, 9 }); + model.combine(new int[] { 7 }, new int[] { 10, 11, 12, 13 }); + model.combine(new int[] { 7 }, new int[] { 14, 15, 16 }); + model.combine(new int[] { 7 }, new int[] { 17, 18, 19 }); + model.combine(new int[] { 8 }, new int[] { 0, 1 }); + model.combine(new int[] { 8 }, new int[] { 2, 3, 4, 5, 6, 7 }); + model.combine(new int[] { 8 }, new int[] { 8, 9 }); + model.combine(new int[] { 8 }, new int[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }); + model.combine(new int[] { 9 }, new int[] { 0, 1 }); + model.combine(new int[] { 9 }, new int[] { 2, 3, 4, 5, 6, 7 }); + model.combine(new int[] { 9, 10, 11 }, new int[] { 8, 9 }); + model.combine(new int[] { 9, 10, 11 }, new int[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }); + model.combine(new int[] { 10 }, new int[] { 0, 1 }); + model.combine(new int[] { 10 }, new int[] { 2, 3, 4, 5, 6, 7 }); + model.combine(new int[] { 11 }, new int[] { 0, 1 }); + model.combine(new int[] { 11 }, new int[] { 2, 3, 4, 5, 6, 7 }); + model.combine(new int[] { 12 }, new int[] { 0, 1 }); + model.combine(new int[] { 12 }, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }); + model.combine(new int[] { top, 1 }, new int[] { 0 }); + model.combine(new int[] { top }, new int[] { 1, 2, 3, 4, 5, 6 }); + model.combine(new int[] { top }, new int[] { 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }); + model.combine(new int[] { top, top + 1 }, new int[] { 19 }); + model.combine(new int[] { top + 1 }, new int[] { 1, 2, 3, 4 }); + } + + private void initModel3() { + disableEdit3 = new ArrayList<>();// ༭ + general3 = new HashMap();// Ҫдһ + model3.setValueAt("ΪCTQijߴdzҪ", 0, 0);// ӡײʼ + disableEdit3.add(0 + ",0"); + model3.setValueAt("SPL Picture", 1, 0); +// picMap.put("jd2_ypzp", new int[] { 2, 0 }); + picMap.put("user_data_1", new int[] { 2, 0 }); + disableEdit3.add(1 + ",0"); + model3.setValueAt("ע", 1, 4); + disableEdit3.add(1 + ",4"); + model3.setValueAt("C/Time", 1, 5); + disableEdit3.add(1 + ",5"); + model3.setValueAt("ע", 1, 6); + disableEdit3.add(1 + ",6"); + model3.setValueAt("ȴ", 1, 7); + disableEdit3.add(1 + ",7"); + model3.setValueAt("װ", 1, 8); + disableEdit3.add(1 + ",8"); + model3.setValueAt("Լ챨", 1, 9); + disableEdit3.add(1 + ",9"); + model3.setValueAt("ҵָ", 1, 12); + disableEdit3.add(1 + ",12"); + model3.setValueAt("QCͼ", 1, 15); + disableEdit3.add(1 + ",15"); + model3.setValueAt("ϰװǩ", 1, 18); + disableEdit3.add(1 + ",18"); + general3.put("jd2_Ctime", new int[] { 2, 5 }); + general3.put("jd2_zs", new int[] { 2, 6 }); + general3.put("jd2_lq", new int[] { 2, 7 }); + general3.put("jd2_baoz", new int[] { 2, 8 }); +// fileMap.put("jd2_gfzjbg", new int[] { 2, 9 }); + fileMap.put("user_data_2", new int[] { 2, 9 }); + fileMap.put("jd2_gfzyzds", new int[] { 2, 12 }); + fileMap.put("jd2_gfqcgct", new int[] { 2, 15 }); + fileMap.put("jd2_wlbzjbq", new int[] { 2, 18 }); + model3.setValueAt("Shot/24Hr", 3, 5); + disableEdit3.add(3 + ",5"); + model3.setValueAt("", 3, 6); + disableEdit3.add(3 + ",6"); + general3.put("jd2_Shot24Hr", new int[] { 4, 5 }); + general3.put("jd2_d", new int[] { 4, 6 }); + model3.setValueAt("3D", 5, 4); + disableEdit3.add(5 + ",4"); + model3.setValueAt("jd2_3Dzl", 5, 5); + general3.put("jd2_3Dzl", new int[] { 5, 5 }); + model3.setValueAt("עܹ", 5, 7); + disableEdit3.add(5 + ",7"); + model3.setValueAt("IQC׼챨", 5, 9); + disableEdit3.add(5 + ",9"); + model3.setValueAt("Ա", 5, 12); + disableEdit3.add(5 + ",12"); + model3.setValueAt("ʱ", 5, 15); + disableEdit3.add(5 + ",15"); + model3.setValueAt("ģ߱ʶ", 5, 18); + disableEdit3.add(5 + ",18"); + fileMap.put("jd2_zsgytj", new int[] { 6, 7 }); + fileMap.put("jd2_icqsjbg", new int[] { 6, 9 }); + fileMap.put("jd2_csbg", new int[] { 6, 12 }); + fileMap.put("jd2_czbg", new int[] { 6, 15 }); + fileMap.put("jd2_mjbs", new int[] { 6, 18 }); + model3.setValueAt("ʵ", 7, 4); + disableEdit3.add(7 + ",4"); + general3.put("jd2_sczl", new int[] { 7, 5 }); + model3.setValueAt("IQCҵָ", 9, 4); + disableEdit3.add(9 + ",4"); + fileMap.put("jd2_icqjyzds", new int[] { 10, 4 }); + model3.setValueAt("", 11, 12); + disableEdit3.add(11 + ",12"); + jued = new JComboBox(); + jued.setRenderer(new MyComboBoxRenderer()); + try { + if (form.getTCProperty("jd2_jued") != null) { + String[] items = form.getTCProperty("jd2_jued").getLOV().getListOfValues().getLOVDisplayValues(); + jued.addItem(" "); + for (String s : items) { + jued.addItem(s); + } + jued.setSelectedItem(form.getProperty("jd2_jued")); + if ("".equals(form.getProperty("jd2_jued"))) { + jued.setSelectedItem(" "); + } + model3.setValueAt(jued, 11, 15); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + fileMap.put("jd2_qtbg", new int[] { 9, 7 }); + + model3.combine(new int[] { 0 }, new int[] { 0, 1, 2, 3, 4, 5 }); + model3.combine(new int[] { 1 }, new int[] { 0, 1 }); + model3.combine(new int[] { 1 }, new int[] { 2, 3 }); + model3.combine(new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, new int[] { 0, 1, 2, 3 }); + model3.combine(new int[] { 1, 2, 3, 4 }, new int[] { 4 }); + model3.combine(new int[] { 1 }, new int[] { 9, 10, 11 }); + model3.combine(new int[] { 1 }, new int[] { 12, 13, 14 }); + model3.combine(new int[] { 1 }, new int[] { 15, 16, 17 }); + model3.combine(new int[] { 1 }, new int[] { 18, 19 }); + model3.combine(new int[] { 3, 4 }, new int[] { 7, 8 }); + model3.combine(new int[] { 2, 3, 4 }, new int[] { 9, 10, 11 }); + model3.combine(new int[] { 2, 3, 4 }, new int[] { 12, 13, 14 }); + model3.combine(new int[] { 2, 3, 4 }, new int[] { 15, 16, 17 }); + model3.combine(new int[] { 2, 3, 4 }, new int[] { 18, 19 }); + model3.combine(new int[] { 5, 6 }, new int[] { 4 }); + model3.combine(new int[] { 7, 8 }, new int[] { 4 }); + model3.combine(new int[] { 5, 6 }, new int[] { 5 }); + model3.combine(new int[] { 7, 8 }, new int[] { 5 }); + model3.combine(new int[] { 5, 6, 7, 8 }, new int[] { 6 }); + model3.combine(new int[] { 5 }, new int[] { 7, 8 }); + model3.combine(new int[] { 5 }, new int[] { 9, 10, 11 }); + model3.combine(new int[] { 5 }, new int[] { 12, 13, 14 }); + model3.combine(new int[] { 5 }, new int[] { 15, 16, 17 }); + model3.combine(new int[] { 5 }, new int[] { 18, 19 }); + model3.combine(new int[] { 6, 7, 8 }, new int[] { 7, 8 }); + model3.combine(new int[] { 6, 7, 8 }, new int[] { 9, 10, 11 }); + model3.combine(new int[] { 6, 7, 8 }, new int[] { 12, 13, 14 }); + model3.combine(new int[] { 6, 7, 8 }, new int[] { 15, 16, 17 }); + model3.combine(new int[] { 6, 7, 8 }, new int[] { 18, 19 }); + model3.combine(new int[] { 9 }, new int[] { 4, 5, 6 }); + model3.combine(new int[] { 10, 11, 12 }, new int[] { 4, 5, 6 }); + model3.combine(new int[] { 9, 10, 11, 12 }, new int[] { 7, 8, 9, 10, 11 }); + model3.combine(new int[] { 9, 10 }, new int[] { 12, 13, 14, 15, 16, 17, 18, 19 }); + model3.combine(new int[] { 11, 12 }, new int[] { 12, 13, 14 }); + model3.combine(new int[] { 11, 12 }, new int[] { 15, 16, 17, 18, 19 }); + } + + @Override + public void saveRendering() { + // ͼƬ + JLabel label = null; + for (Entry entry : picMap.entrySet()) { + if (prop.containsKey(entry.getKey())) { + System.out.println(entry.getKey()); + label = (JLabel) model3.getValueAt(entry.getValue()[0], entry.getValue()[1]); + try { + form.setProperty(entry.getKey(), label.getToolTipText() == null ? "" : label.getToolTipText()); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } + + // ļ + for (Entry entry : fileMap.entrySet()) { + if (prop.containsKey(entry.getKey())) { + System.out.println(entry.getKey()); + label = (JLabel) model3.getValueAt(entry.getValue()[0], entry.getValue()[1]); + try { + form.setProperty(entry.getKey(), label.getToolTipText() == null ? "" : label.getToolTipText()); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } + + // ѡ + try { + if (prop.containsKey("jd2_yssl")) { + String value = yssl.getSelected() == null ? "" : yssl.getSelected().getText(); + if (form.getTCProperty("jd2_yssl").getLOV() != null && !"".equals(value)) { + value = (String) form.getTCProperty("jd2_yssl").getLOV().getListOfValues().getRealValue(value); + } + form.setProperty("jd2_yssl", value); + } + if (prop.containsKey("jd2_mqjd")) { + String value = mqjd.getSelectedText() == null ? "" : mqjd.getSelectedText(); + if (form.getTCProperty("jd2_mqjd").getLOV() != null && !"".equals(value)) { + value = (String) form.getTCProperty("jd2_mqjd").getLOV().getListOfValues().getRealValue(value); + } + form.setProperty("jd2_mqjd", value); + } + if (prop.containsKey("jd2_bpdj")) { + String value = bpdj.getSelectedItem() == null ? " " : bpdj.getSelectedItem().toString(); + if (form.getTCProperty("jd2_bpdj").getLOV() != null && !" ".equals(value)) { + value = (String) form.getTCProperty("jd2_bpdj").getLOV().getListOfValues().getRealValue(value); + } + form.setProperty("jd2_bpdj", " ".equals(value) ? null : value); + } + if (prop.containsKey("jd2_fl")) { + String value = fl.getSelectedItem() == null ? " " : fl.getSelectedItem().toString(); + if (form.getTCProperty("jd2_fl").getLOV() != null && !" ".equals(value)) { + value = (String) form.getTCProperty("jd2_fl").getLOV().getListOfValues().getRealValue(value); + } + form.setProperty("jd2_fl", " ".equals(value) ? null : value); + } + if (prop.containsKey("jd2_zt")) { + String value = zt.getSelectedItem() == null ? " " : zt.getSelectedItem().toString(); + if (form.getTCProperty("jd2_zt").getLOV() != null && !" ".equals(value)) { + value = (String) form.getTCProperty("jd2_zt").getLOV().getListOfValues().getRealValue(value); + } + form.setProperty("jd2_zt", " ".equals(value) ? null : value); + } + if (prop.containsKey("jd2_jued")) { + String value = jued.getSelectedItem() == null ? " " : jued.getSelectedItem().toString(); + if (form.getTCProperty("jd2_jued").getLOV() != null && !" ".equals(value)) { + value = (String) form.getTCProperty("jd2_jued").getLOV().getListOfValues().getRealValue(value); + } + form.setProperty("jd2_jued", " ".equals(value) ? null : value); + } + + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // ͨ + for (Entry entry : general.entrySet()) { + try { + if (prop.containsKey(entry.getKey())) { + String value = model.getValueAt(entry.getValue()[0], entry.getValue()[1]).toString(); + 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 entry : general3.entrySet()) { + try { + if (prop.containsKey(entry.getKey())) { + String value = model3.getValueAt(entry.getValue()[0], entry.getValue()[1]).toString(); + 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_ypqrdtable")) { + List data = new ArrayList(); + int num = 0; + while (model.getValueAt(top + 2 + num, 1) != null && !"".equals(model.getValueAt(top + 2 + num, 1))) { + String[] row = new String[18]; + for (int ii = 0; ii < row.length; ii++) { + Object object = model.getValueAt(top + 2 + num, ii > 2 ? ii + 2 : ii); + if (ii == row.length - 1) { + object = ((JComboBox) object).getSelectedItem(); + row[ii] = object == null ? "" : jgItems.get(object.toString()); + } else { + row[ii] = object == null ? "" : object.toString(); + } + } + data.add(row); + num++; + if (top + 2 + num > bottom) { + break; + } + } + String[][] dataArr = data.toArray(new String[data.size()][]); + System.out.println(Arrays.deepToString(dataArr)); + TCTableUtil.setTableRows(form, "jd2_ypqrdtable", "JD2_YPQRDTABLE", colNames, dataArr); + } + if (prop.containsKey("jd2_ctq1")) { + List data = new ArrayList(); + int num = 0; + while (num < 3) { + String[] row = new String[8]; + for (int ii = 0; ii < row.length; ii++) { + Object object = model2.getValueAt(num + 1, ii + 2); + if (object == null) { + row[ii] = ""; + } else { + row[ii] = object.toString(); + } + } + data.add(row); + num++; + } + String[][] dataArr = data.toArray(new String[data.size()][]); + System.out.println(Arrays.deepToString(dataArr)); + TCTableUtil.setTableRows(form, "jd2_ctq1", "JD2_CQT1", colNames1, dataArr); + } + if (prop.containsKey("jd2_ctq2")) { + List data = new ArrayList(); + int num = 0; + while (model2.getValueAt(top2 + num, 2) != null && !"".equals(model2.getValueAt(top2 + num, 2))) { + String[] row = new String[9]; + for (int ii = 0; ii < row.length; ii++) { + Object object = model2.getValueAt(top2 + num, ii > 0 ? ii + 1 : ii); + if (object == null) { + row[ii] = ""; + } else { + row[ii] = object.toString(); + } + } + data.add(row); + num++; + if (top2 + num > bottom2) { + break; + } + } + String[][] dataArr = data.toArray(new String[data.size()][]); + System.out.println(Arrays.deepToString(dataArr)); + TCTableUtil.setTableRows(form, "jd2_ctq2", "JD2_CQT2", colNames2, dataArr); + } + if (prop.containsKey("jd2_ctq3")) { + List data = new ArrayList(); + int num = 0; + while (num < end2 - 1) { + String[] row = new String[8]; + for (int ii = 0; ii < row.length; ii++) { + Object object = model2.getValueAt(bottom2 + 1 + num, ii + 2); + if (object == null) { + row[ii] = ""; + } else { + row[ii] = object.toString(); + } + } + data.add(row); + num++; + if (bottom2 + 1 + num > model2.getRowCount()) { + break; + } + } + String[][] dataArr = data.toArray(new String[data.size()][]); + System.out.println(Arrays.deepToString(dataArr)); + TCTableUtil.setTableRows(form, "jd2_ctq3", "JD2_CQT3", colNames3, dataArr); + } + + } + + private ActionListener confirm() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + System.out.println("confirm"); + for (int i = 2; i < 10; i++) { + for (int ii = 1; ii < 14; ii++) { + String temp = table2.getValueAt(ii, i) == null ? "" : table2.getValueAt(ii, i).toString(); + table.setValueAt(temp, top + i, ii + 1 > 2 ? ii + 3 : ii + 1); + } + } + for (int i = 2; i < 10; i++) { + table.getColumnModel().getColumn(10).getCellEditor().getTableCellEditorComponent(table, + table.getValueAt(top + i, 10), true, top + i, 10); + table.getColumnModel().getColumn(10).getCellEditor().stopCellEditing(); + } + table.revalidate(); + table.repaint(); + cl.show(center, "confirm"); + } + }; + return actionListener; + } + + private ActionListener examine() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + System.out.println("examine"); + for (int i = 1; i < 9; i++) { + for (int ii = 2; ii < 15; ii++) { + String temp = table.getValueAt(top + 1 + i, ii > 2 ? ii + 2 : ii) == null ? "" + : table.getValueAt(top + 1 + i, ii > 2 ? ii + 2 : ii).toString(); + table2.setValueAt(temp, ii - 1, i + 1); + } + } + for (int i = 2; i < 10; i++) { + table2.getColumnModel().getColumn(i).getCellEditor().getTableCellEditorComponent(table2, + table2.getValueAt(2, i), true, 2, i); + table2.getColumnModel().getColumn(i).getCellEditor().stopCellEditing(); + table2.getColumnModel().getColumn(i).getCellEditor().getTableCellEditorComponent(table2, + table2.getValueAt(3, i), true, 3, i); + table2.getColumnModel().getColumn(i).getCellEditor().stopCellEditing(); + table2.getColumnModel().getColumn(i).getCellEditor().getTableCellEditorComponent(table2, + table2.getValueAt(4, i), true, 4, i); + table2.getColumnModel().getColumn(i).getCellEditor().stopCellEditing(); + } + table2.revalidate(); + table2.repaint(); + cl.show(center, "examine"); + } + }; + return actionListener; + } + + private MouseAdapter rightClick() { + MouseAdapter mouseAdapter = 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 + 2 && row <= bottom); + addR.setEnabled(flag); + insertR.setEnabled(flag); + delR.setEnabled(flag); + menu.show(e.getComponent(), e.getX(), e.getY()); + } + } + }; + return mouseAdapter; + } + + private MouseAdapter rightClick2() { + MouseAdapter mouseAdapter = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON3 && form.isCheckedOut() && table2.getSelectedRow() != -1) { + int row = table2.getSelectedRow(); + boolean flag = (row >= top2 && row <= bottom2); + addR2.setEnabled(flag); + insertR2.setEnabled(flag); + delR2.setEnabled(flag); + menu2.show(e.getComponent(), e.getX(), e.getY()); + } + } + }; + return mouseAdapter; + } + + private MouseAdapter rightClick3() { + MouseAdapter mouseAdapter = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON3 && form.isCheckedOut() && table3.getSelectedRow() != -1) { + int row = table3.getSelectedRow(); + int col = table3.getSelectedColumn(); + boolean flag = false; + for (Entry entry : picMap.entrySet()) { + if (entry.getValue()[0] == row && entry.getValue()[1] == col) { + flag = true; + break; + } + } + addP.setEnabled(flag); + delP.setEnabled(flag); + flag = false; + for (Entry entry : fileMap.entrySet()) { + if (entry.getValue()[0] == row && entry.getValue()[1] == col) { + flag = true; + break; + } + } + addF.setEnabled(flag); + delF.setEnabled(flag); + menu3.show(e.getComponent(), e.getX(), e.getY()); + + } + } + }; + return mouseAdapter; + } + + private ActionListener addPic() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileChooser.setMultiSelectionEnabled(false); + fileChooser.showOpenDialog(menu);// ʾλ + File file = fileChooser.getSelectedFile(); + + if (file != null) { + System.out.println("fileName:" + file.getName()); + String as1[] = { file.getPath() };// ļ· + String as2[] = new String[1]; + String type = null; + String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1); + String[] datasets = JDMethodUtil.getPrefStrArray("connor_default_dataset", session); + for (String str : datasets) { + String prefSuffix = str.substring(0, str.indexOf("=")); + if (suffix.equals(prefSuffix)) { + String temp = str.substring(str.indexOf("=") + 1); + String[] temps = temp.split(","); + type = temps[0]; + as2[0] = temps[1]; + } + } + if (type == null) { + MessageBox.post("ϴļͲ֧֣", "ʾ", MessageBox.WARNING); + return; + } + TCComponentDatasetType datasetType; + try { + datasetType = (TCComponentDatasetType) session.getTypeComponent("Dataset"); + TCComponentDataset dataset = datasetType.create(file.getName(), "", type); + dataset.setFiles(as1, as2); + rev.add("IMAN_specification", dataset); + String uid = dataset.getUid(); + System.out.println("uid:" + uid); + ImageIcon icon = new ImageIcon(file.getPath()); + int row = table3.getSelectedRow(); + int col = table3.getSelectedColumn(); + String str = ((JLabel) model3.getValueAt(row, col)).getToolTipText(); + if (str != null && !"".equals(str)) { + try { + TCComponentDataset oldDataset = (TCComponentDataset) session.stringToComponent(str); + rev.cutOperation("IMAN_specification", new TCComponent[] { oldDataset }); + oldDataset.delete(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + int[] arr = model3.getSpan(row, col); + System.out.println("row:" + arr[0] + ",col:" + arr[1]); + icon.setImage(icon.getImage().getScaledInstance( + table3.getColumnModel().getColumn(col).getPreferredWidth() * arr[1], + table3.getRowHeight() * arr[0], Image.SCALE_SMOOTH)); + JLabel label = new JLabel(); + label.setLayout(new FlowLayout(FlowLayout.CENTER)); + label.setIcon(icon); + label.addMouseListener(showImg(file.getPath())); + label.setToolTipText(uid); + model3.setValueAt(label, table3.getSelectedRow(), table3.getSelectedColumn()); + table3.revalidate(); + table3.repaint(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + }; + + return actionListener; + } + + private ActionListener delPic() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int row = table3.getSelectedRow(); + int col = table3.getSelectedColumn(); + String uid = ((JLabel) model3.getValueAt(row, col)).getToolTipText(); + if (uid != null && !"".equals(uid)) { + try { + TCComponentDataset dataset = (TCComponentDataset) session.stringToComponent(uid); + rev.cutOperation("IMAN_specification", new TCComponent[] { dataset }); + dataset.delete(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + ((JLabel) model3.getValueAt(row, col)).setText(""); + table3.revalidate(); + table3.repaint(); + } + + }; + return actionListener; + } + + private ActionListener addRow() { + ActionListener actionListener = 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 }); + + table.revalidate(); + table.repaint(); + } + }; + return actionListener; + } + + private ActionListener addRow2() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int num = Integer.parseInt(model2.getValueAt(bottom2, 0).toString()); + model2.insertRow(++bottom2); + model2.setValueAt(num + 1, bottom2, 0); + model2.combine(new int[] { bottom2 }, new int[] { 0, 1 }); + table2.revalidate(); + table2.repaint(); + } + }; + return actionListener; + } + + private ActionListener insertRow() { + ActionListener actionListener = 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.insertRow(row); + bottom++; + for (int i = row; i <= bottom; i++) { + model.setValueAt(num + i - row, i, 0); + } + model.combine(new int[] { row }, new int[] { 2, 3, 4 }); + + table.revalidate(); + table.repaint(); + } + }; + return actionListener; + } + + private ActionListener insertRow2() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int row = table2.getSelectedRow(); + int num = Integer.parseInt(model2.getValueAt(row, 0).toString()); + model2.insertRow(row); + bottom2++; + for (int i = row; i <= bottom2; i++) { + model2.setValueAt(num + i - row, i, 0); + } + model2.combine(new int[] { row }, new int[] { 0, 1 }); + table2.revalidate(); + table2.repaint(); + } + }; + return actionListener; + } + + private ActionListener deleteRow() { + ActionListener actionListener = 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); + } + } + + table.revalidate(); + table.repaint(); + } + }; + return actionListener; + } + + private ActionListener deleteRow2() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int row = table2.getSelectedRow(); + int num = Integer.parseInt(model2.getValueAt(row, 0).toString()); + model2.removeRow(row); + bottom2--; + if (row <= bottom2) { + for (int i = row; i <= bottom2; i++) { + model2.setValueAt(num + i - row, i, 0); + } + } + table2.revalidate(); + table2.repaint(); + } + }; + return actionListener; + } + + private boolean isEditorDisable(List list, int row, int col) { + return list.contains(row + "," + col); + } + + private MouseAdapter showImg(String path) { + final String imagePath = path; + MouseAdapter adapter = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + PhotoFrame.getInstance(imagePath); + } + } + }; + return adapter; + } + + private MouseAdapter showFile(TCComponentDataset dataset) { + MouseAdapter adapter = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + try { + dataset.open(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + }; + return adapter; + } + + private ActionListener addFile() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileChooser.setMultiSelectionEnabled(false); + fileChooser.showOpenDialog(menu3);// ʾλ + File file = fileChooser.getSelectedFile(); + if (file != null) { + System.out.println("fileName:" + file.getName()); + String as1[] = { file.getPath() };// ļ· + String as2[] = new String[1]; + String type = null; + String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1); + String[] datasets = JDMethodUtil.getPrefStrArray("connor_default_dataset", session); + for (String str : datasets) { + String prefSuffix = str.substring(0, str.indexOf("=")); + if (suffix.equals(prefSuffix)) { + String temp = str.substring(str.indexOf("=") + 1); + String[] temps = temp.split(","); + type = temps[0]; + as2[0] = temps[1]; + } + } + if (type == null) { + MessageBox.post("ϴļͲ֧֣", "ʾ", MessageBox.WARNING); + return; + } +// if (file.getName().endsWith(".doc")) { +// as2[0] = "word"; +// type = "MSWord"; +// } else if (file.getName().endsWith(".docx")) { +// as2[0] = "word"; +// type = "MSWordX"; +// } else if (file.getName().endsWith(".xls")) { +// as2[0] = "excel"; +// type = "MSExcel"; +// } else if (file.getName().endsWith(".xlsx")) { +// as2[0] = "excel"; +// type = "MSExcelX"; +// } else { +// as2[0] = "Image"; +// type = "Image"; +// } + TCComponentDatasetType datasetType; + try { + datasetType = (TCComponentDatasetType) session.getTypeComponent("Dataset"); + TCComponentDataset dataset = datasetType.create(file.getName(), "", type); + dataset.setFiles(as1, as2); + rev.add("IMAN_specification", dataset); + String uid = dataset.getUid(); + System.out.println("uid:" + uid); + int row = table3.getSelectedRow(); + int col = table3.getSelectedColumn(); + String str = ((JLabel) model3.getValueAt(row, col)).getToolTipText(); + if (str != null && !"".equals(str)) { + try { + TCComponentDataset oldDataset = (TCComponentDataset) session.stringToComponent(str); + rev.cutOperation("IMAN_specification", new TCComponent[] { oldDataset }); + oldDataset.delete(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + int[] arr = model3.getSpan(row, col); + System.out.println("row:" + arr[0] + ",col:" + arr[1]); + JLabel label = new JLabel(); + label.setLayout(new FlowLayout(FlowLayout.CENTER)); + label.setText(file.getName()); + label.setHorizontalAlignment(SwingConstants.CENTER); + label.setForeground(new Color(0xff0078D7)); + label.addMouseListener(showFile(dataset)); + label.setToolTipText(uid); + model3.setValueAt(label, table3.getSelectedRow(), table3.getSelectedColumn()); + table3.revalidate(); + table3.repaint(); + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + }; + } + + private ActionListener delFile() { + return delPic(); + } +} diff --git a/src/com/connor/jd/plm/form/ZPanel.java b/src/com/connor/jd/plm/form/ZPanel.java new file mode 100644 index 0000000..85988cc --- /dev/null +++ b/src/com/connor/jd/plm/form/ZPanel.java @@ -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(); + } + } + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/handlers/AddHLBOMHandler.java b/src/com/connor/jd/plm/handlers/AddHLBOMHandler.java new file mode 100644 index 0000000..f62fd68 --- /dev/null +++ b/src/com/connor/jd/plm/handlers/AddHLBOMHandler.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/handlers/BOMManagementHandler.java b/src/com/connor/jd/plm/handlers/BOMManagementHandler.java new file mode 100644 index 0000000..344d47d --- /dev/null +++ b/src/com/connor/jd/plm/handlers/BOMManagementHandler.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/handlers/BatchReviseHandler.java b/src/com/connor/jd/plm/handlers/BatchReviseHandler.java new file mode 100644 index 0000000..271f0e7 --- /dev/null +++ b/src/com/connor/jd/plm/handlers/BatchReviseHandler.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/handlers/CSXWHHandler.java b/src/com/connor/jd/plm/handlers/CSXWHHandler.java new file mode 100644 index 0000000..138a1e4 --- /dev/null +++ b/src/com/connor/jd/plm/handlers/CSXWHHandler.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/handlers/CreateItemHandler.java b/src/com/connor/jd/plm/handlers/CreateItemHandler.java new file mode 100644 index 0000000..43a878d --- /dev/null +++ b/src/com/connor/jd/plm/handlers/CreateItemHandler.java @@ -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 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 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; + } +} diff --git a/src/com/connor/jd/plm/handlers/DeleteItemRevisionHandler.java b/src/com/connor/jd/plm/handlers/DeleteItemRevisionHandler.java new file mode 100644 index 0000000..fc238dd --- /dev/null +++ b/src/com/connor/jd/plm/handlers/DeleteItemRevisionHandler.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/handlers/EditClassificationHandler.java b/src/com/connor/jd/plm/handlers/EditClassificationHandler.java new file mode 100644 index 0000000..772372b --- /dev/null +++ b/src/com/connor/jd/plm/handlers/EditClassificationHandler.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/handlers/ExportBOMHandler.java b/src/com/connor/jd/plm/handlers/ExportBOMHandler.java new file mode 100644 index 0000000..3420d03 --- /dev/null +++ b/src/com/connor/jd/plm/handlers/ExportBOMHandler.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/handlers/QTXJCHandler.java b/src/com/connor/jd/plm/handlers/QTXJCHandler.java new file mode 100644 index 0000000..8fe54a9 --- /dev/null +++ b/src/com/connor/jd/plm/handlers/QTXJCHandler.java @@ -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 sfList = new ArrayList(); + 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; + } + +} diff --git a/src/com/connor/jd/plm/handlers/TransformDesignToPartHandler.java b/src/com/connor/jd/plm/handlers/TransformDesignToPartHandler.java new file mode 100644 index 0000000..85adc37 --- /dev/null +++ b/src/com/connor/jd/plm/handlers/TransformDesignToPartHandler.java @@ -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(); + } + } + +} diff --git a/src/com/connor/jd/plm/handlers/WLTZReviseHandler.java b/src/com/connor/jd/plm/handlers/WLTZReviseHandler.java new file mode 100644 index 0000000..2b41687 --- /dev/null +++ b/src/com/connor/jd/plm/handlers/WLTZReviseHandler.java @@ -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; + } + +} diff --git a/src/com/connor/jd/plm/handlers/Wf001ScheduleHandler.java b/src/com/connor/jd/plm/handlers/Wf001ScheduleHandler.java new file mode 100644 index 0000000..66dd04b --- /dev/null +++ b/src/com/connor/jd/plm/handlers/Wf001ScheduleHandler.java @@ -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: + */ \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/ButtonEditor.java b/src/com/connor/jd/plm/table/ButtonEditor.java new file mode 100644 index 0000000..c1b33cd --- /dev/null +++ b/src/com/connor/jd/plm/table/ButtonEditor.java @@ -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() { + //yyyyMMdd + SimpleDateFormat format=new SimpleDateFormat("yyyyMMdd"); + 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()); + } + +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/ButtonEditor2.java b/src/com/connor/jd/plm/table/ButtonEditor2.java new file mode 100644 index 0000000..094ec6c --- /dev/null +++ b/src/com/connor/jd/plm/table/ButtonEditor2.java @@ -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() { + //yyyyMMdd HH:mm + SimpleDateFormat format=new SimpleDateFormat("HH:mm"); + Date data = new Date(); + System.out.println("ccc===>"+format.format(data)); + + return format.format(button.getDate()); + } + + +} diff --git a/src/com/connor/jd/plm/table/CTMap.java b/src/com/connor/jd/plm/table/CTMap.java new file mode 100644 index 0000000..b32d7b0 --- /dev/null +++ b/src/com/connor/jd/plm/table/CTMap.java @@ -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(); + } +} diff --git a/src/com/connor/jd/plm/table/CTUI.java b/src/com/connor/jd/plm/table/CTUI.java new file mode 100644 index 0000000..831439d --- /dev/null +++ b/src/com/connor/jd/plm/table/CTUI.java @@ -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); + } + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/CTable.java b/src/com/connor/jd/plm/table/CTable.java new file mode 100644 index 0000000..9e3923b --- /dev/null +++ b/src/com/connor/jd/plm/table/CTable.java @@ -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 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); + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/CTest.java b/src/com/connor/jd/plm/table/CTest.java new file mode 100644 index 0000000..465f200 --- /dev/null +++ b/src/com/connor/jd/plm/table/CTest.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/CellSpan.java b/src/com/connor/jd/plm/table/CellSpan.java new file mode 100644 index 0000000..a454f89 --- /dev/null +++ b/src/com/connor/jd/plm/table/CellSpan.java @@ -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); + +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/DatePickerCellEditor.java b/src/com/connor/jd/plm/table/DatePickerCellEditor.java new file mode 100644 index 0000000..3bbf573 --- /dev/null +++ b/src/com/connor/jd/plm/table/DatePickerCellEditor.java @@ -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(); + } + +} diff --git a/src/com/connor/jd/plm/table/DefaultModel.java b/src/com/connor/jd/plm/table/DefaultModel.java new file mode 100644 index 0000000..d27ef16 --- /dev/null +++ b/src/com/connor/jd/plm/table/DefaultModel.java @@ -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)); + } + +} diff --git a/src/com/connor/jd/plm/table/JCheckPanel.java b/src/com/connor/jd/plm/table/JCheckPanel.java new file mode 100644 index 0000000..b61e4ce --- /dev/null +++ b/src/com/connor/jd/plm/table/JCheckPanel.java @@ -0,0 +1,83 @@ +package com.connor.jd.plm.table; + +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.ButtonGroup; +import javax.swing.JCheckBox; +import javax.swing.JPanel; + +public class JCheckPanel extends JPanel { + private JCheckBox[] buttons = null; + private ButtonGroup buttonGroup = new ButtonGroup(); + + public JCheckPanel(String[] text) { + super(); + buttons = new JCheckBox[text.length]; + for (int i = 0; i < text.length; i++) { + buttons[i] = new JCheckBox(text[i]); + buttons[i].setPreferredSize(new Dimension(100, 25)); + buttonGroup.add(buttons[i]); + add(buttons[i]); + } + setLayout(new FlowLayout(FlowLayout.LEFT)); + } + + public JCheckPanel(String[] text, boolean isSingle) { + buttons = new JCheckBox[text.length]; + for (int i = 0; i < text.length; i++) { + buttons[i] = new JCheckBox(text[i]); + buttons[i].setPreferredSize(new Dimension(60, 25)); + if (isSingle) { + buttonGroup.add(buttons[i]); + } + add(buttons[i]); + } + setLayout(new FlowLayout(FlowLayout.LEFT)); + } + + public JCheckBox[] getButtons() { + return buttons; + } + + public List getSelected() { + List list = new ArrayList(); + for (JCheckBox check : buttons) { + if (check.isSelected()) { + list.add(check); + } + } + return list; + } + + public String getSelectedText() { + List list = getSelected(); + if (list.size() == 0) { + return null; + } + String str = ""; + for (JCheckBox jcb : list) { + str += jcb.getText(); + str += ","; + } + return str.substring(0, str.length() - 1); + } + + public void setSelected(int index) { + buttons[index].setSelected(true); + } + + public void setSelected(String value) { + String[] arr = value.split(","); + for (int i = 0; i < arr.length; i++) { + for (int ii = 0; ii < buttons.length; ii++) { + if (buttons[ii].getText().equals(arr[i])) { + buttons[ii].setSelected(true); + break; + } + } + } + } +} diff --git a/src/com/connor/jd/plm/table/JRadioPanel.java b/src/com/connor/jd/plm/table/JRadioPanel.java new file mode 100644 index 0000000..440a761 --- /dev/null +++ b/src/com/connor/jd/plm/table/JRadioPanel.java @@ -0,0 +1,47 @@ +package com.connor.jd.plm.table; + +import java.awt.FlowLayout; + +import javax.swing.ButtonGroup; +import javax.swing.JPanel; +import javax.swing.JRadioButton; + +public class JRadioPanel extends JPanel { + private JRadioButton[] buttons = null; + private ButtonGroup buttonGroup = new ButtonGroup(); + + public JRadioPanel(String[] text) { + super(); + buttons = new JRadioButton[text.length]; + for (int i = 0; i < text.length; i++) { + buttons[i] = new JRadioButton(text[i]); + buttonGroup.add(buttons[i]); + add(buttons[i]); + } + setLayout(new FlowLayout(FlowLayout.LEFT)); + } + + public JRadioButton[] getButtons() { + return buttons; + } + + public JRadioButton getSelected() { + for (JRadioButton jb : buttons) { + if (jb.isSelected()) { + return jb; + } + } + return null; + } + + public void setSelected(int index) { + buttons[index].setSelected(true); + } + + public void setSelected(String value) { + for (int i = 0; i < buttons.length; i++) { + buttons[i].setSelected(buttons[i].getText().equals(value.trim())); + } + } + +} diff --git a/src/com/connor/jd/plm/table/MessageBox2.java b/src/com/connor/jd/plm/table/MessageBox2.java new file mode 100644 index 0000000..c7dc822 --- /dev/null +++ b/src/com/connor/jd/plm/table/MessageBox2.java @@ -0,0 +1,39 @@ +package com.connor.jd.plm.table; + +import javax.swing.JOptionPane; + +public class MessageBox2 { + + private static String Title = "ʾ"; + public static final int DEFAULT_OPTION = -1; + public static final int YES_NO_OPTION = 10; + public static final int YES_NO_CANCEL_OPTION = 11; + public static final int OK_CANCEL_OPTION = 12; + public static final int YES_OPTION = 0; + public static final int NO_OPTION = 1; + public static final int CANCEL_OPTION = 2; + public static final int OK_OPTION = 0; + public static final int CLOSED_OPTION = -1; + public static final int ERROR_MESSAGE = 0; + public static final int INFORMATION_MESSAGE = 1; + public static final int WARNING_MESSAGE = 2; + public static final int QUESTION_MESSAGE = 3; + public static final int PLAIN_MESSAGE = -1; + + public static int Show(String Msg, int Option) { + switch (Option) { + case YES_NO_OPTION: + case YES_NO_CANCEL_OPTION: + case OK_CANCEL_OPTION: + return JOptionPane.showConfirmDialog(null, Msg, Title, Option - 10); + default: + JOptionPane.showMessageDialog(null, Msg, Title, Option); + } + return 0; + } + + public static int Show(String Msg) { + return Show(Msg, INFORMATION_MESSAGE); + } + +} diff --git a/src/com/connor/jd/plm/table/ModelList.java b/src/com/connor/jd/plm/table/ModelList.java new file mode 100644 index 0000000..cd14d7e --- /dev/null +++ b/src/com/connor/jd/plm/table/ModelList.java @@ -0,0 +1,87 @@ +package com.connor.jd.plm.table; + +import java.util.ArrayList; +import java.util.List; + +public class ModelList extends ArrayList { + + private List disableEdit = new ArrayList(); + + @Override + public boolean add(ModelValue e) { + // TODO Auto-generated method stub + if (!e.isEditable()) { + disableEdit.add(e.getRow() + "," + e.getCol()); + } + return super.add(e); + } + + public ModelValue getModelValue(int row, int col) { + for (ModelValue mv : this) { + if (mv.getRow() == row && mv.getCol() == col) { + return mv; + } + } + return null; + } + + public ModelValue getModelValueInRange(int row, int col) { + int rowStart; + int colStart; + int rowEnd; + int colEnd; + for (ModelValue mv : this) { + if (mv.isCombine()) { + rowStart = mv.getCombineRows()[0]; + rowEnd = rowStart + mv.getRowSpan() - 1; + colStart = mv.getCombineColumns()[0]; + colEnd = colStart + mv.getColSpan() - 1; + if (row >= rowStart && row <= rowEnd && col >= colStart && col <= colEnd) { + return mv; + } + } + } + return null; + } + + public boolean addDisableEdit(int row, int col) { + String str = row + "," + col; + if (disableEdit.contains(str)) { + disableEdit.add(disableEdit.indexOf(str), str); + return true; + } + disableEdit.add(str); + return false; + } + + public boolean removeDisableEdit(int row, int col) { + String str = row + "," + col; + if (disableEdit.contains(str)) { + disableEdit.remove(disableEdit.indexOf(str)); + return true; + } + return false; + } + + public boolean isDisableEdit(int row, int col) { + return disableEdit.contains(row + "," + col); + } + + public void findAndAddRow(int row, int tableColumsCount, int offset) { + if (offset <= 0) { + return; + } + if (this.size() == 0) { + return; + } + for (int i = 0; i < tableColumsCount; i++) { + if (this.getModelValue(row, i) != null) { + System.out.println(this.getModelValue(row, i).getValue()); + this.getModelValue(row, i).setRow(row + offset); + this.removeDisableEdit(row, i); + this.addDisableEdit(row + offset, i); + } + } + } + +} diff --git a/src/com/connor/jd/plm/table/ModelValue.java b/src/com/connor/jd/plm/table/ModelValue.java new file mode 100644 index 0000000..3f05b8b --- /dev/null +++ b/src/com/connor/jd/plm/table/ModelValue.java @@ -0,0 +1,163 @@ +package com.connor.jd.plm.table; + +import java.util.Objects; + +public class ModelValue { + + private String value; + private boolean isProp; + private int row; + private int col; + private boolean editable; + private int[] combineRows; + private int rowSpan; + private int[] combineColumns; + private int colSpan; + + public ModelValue(String value, boolean isProp, int row, int col, boolean editable, int[] combineRows, + int[] combineColumns, String type) { + super(); + this.value = value; + this.isProp = isProp; + this.row = row; + this.col = col; + this.editable = editable; + this.combineRows = combineRows; + this.combineColumns = combineColumns; + } + + public ModelValue(boolean editable, int[] combineRows, int[] combineColumns) { + super(); + this.editable = editable; + this.combineRows = combineRows; + this.combineColumns = combineColumns; + } + + public ModelValue(String value, boolean isProp, int row, int col, boolean editable) { + super(); + this.value = value; + this.isProp = isProp; + this.row = row; + this.col = col; + this.editable = editable; + } + + public ModelValue(String value, boolean isProp, int row, int col, boolean editable, int[] combineRows, + int[] combineColumns) { + super(); + this.value = value; + this.isProp = isProp; + this.row = row; + this.col = col; + this.editable = editable; + this.combineRows = combineRows; + this.combineColumns = combineColumns; + } + + public ModelValue(String value, boolean isProp, int row, int col, boolean editable, int rowStart, int rowEnd, + int colStart, int colEnd) { + super(); + this.value = value; + this.isProp = isProp; + this.row = row; + this.col = col; + this.editable = editable; + setCombineRows(rowStart, rowEnd); + setCombineColumns(colStart, colEnd); + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public int getRow() { + return row; + } + + public void setRow(int row) { + this.row = row; + } + + public int getCol() { + return col; + } + + public void setCol(int col) { + this.col = col; + } + + public boolean isEditable() { + return editable; + } + + public void setEditable(boolean editable) { + this.editable = editable; + } + + public int[] getCombineRows() { + return combineRows; + } + + public void setCombineRows(int[] combineRows) { + this.rowSpan = combineRows.length; + this.combineRows = combineRows; + } + + public void setCombineRows(int start, int end) { + if (start <= end) { + this.rowSpan = end - start + 1; + this.combineRows = new int[rowSpan]; + for (int i = 0; i < rowSpan; i++) { + combineRows[i] = start + i; + } + } + } + + public int[] getCombineColumns() { + return combineColumns; + } + + public void setCombineColumns(int[] combineColumns) { + this.colSpan = combineColumns.length; + this.combineColumns = combineColumns; + } + + public void setCombineColumns(int start, int end) { + if (start <= end) { + this.colSpan = end - start + 1; + this.combineColumns = new int[colSpan]; + for (int i = 0; i < colSpan; i++) { + combineColumns[i] = start + i; + } + } + } + + public int getRowSpan() { + return rowSpan; + } + + public int getColSpan() { + return colSpan; + } + + public boolean isProp() { + return isProp; + } + + public void setProp(boolean isProp) { + this.isProp = isProp; + } + + public boolean hasValue() { + return Objects.nonNull(value); + } + + public boolean isCombine() { + return rowSpan != 0 && colSpan != 0; + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor.java b/src/com/connor/jd/plm/table/MyCellEditor.java new file mode 100644 index 0000000..e2a6648 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor.java @@ -0,0 +1,122 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.DefaultCellEditor; +import javax.swing.JComboBox; +import javax.swing.JTable; +import javax.swing.JTextField; + +import com.teamcenter.rac.util.MessageBox; + +public class MyCellEditor extends DefaultCellEditor { + private JRadioPanel radio = null; + private JCheckPanel check = null; + private JComboBox comboBox = null; + private int type = -1; + private int row; + private int col; + private int top; + private int end; + private int bottom; + private JTable table; + + public MyCellEditor(JTextField var1) { + super(var1); + // TODO Auto-generated constructor stub + } + + public MyCellEditor(JTextField var1, int top, int end, int bottom) { + super(var1); + // TODO Auto-generated constructor stub + this.top = top; + this.end = end; + this.bottom = bottom; + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (value instanceof JRadioPanel) { + radio = (JRadioPanel) value; + type = 1; + return radio; + } else if (value instanceof JCheckPanel) { + check = (JCheckPanel) value; + type = 2; + return check; + } else if (value instanceof JComboBox) { + comboBox = (JComboBox) value; + type = 3; + return comboBox; + } + this.row = row; + this.col = column; + this.bottom = table.getRowCount() - end; + this.table = table; + type = 0; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + if (type == 1) { + return radio; + } + if (type == 2) { + return check; + } + if (type == 3) { + return comboBox; + } + + Object obj = super.getCellEditorValue(); + if (obj != null && !"".equals(obj.toString().trim()) && row >= top && row <= bottom && col >= 7 + && col < table.getColumnCount() - 3) { + try { + Double.parseDouble(obj.toString().trim()); + } catch (Exception e) { + MessageBox.post("ֻ", "", MessageBox.ERROR); + return null; + } + } + return obj; + } + + @Override + public boolean stopCellEditing() { + // TODO Auto-generated method stub + if (row >= top && row <= bottom && col >= 7 && col < table.getColumnCount() - 3) { + double min = Double.MAX_VALUE; + double max = Double.MIN_VALUE; + Object obj; + for (int i = 7; i < col; i++) { + obj = table.getValueAt(row, i); + if (obj != null && !"".equals(obj.toString().trim())) { + min = Math.min(min, Double.parseDouble(obj.toString().trim())); + max = Math.max(max, Double.parseDouble(obj.toString().trim())); + } + } + obj = getCellEditorValue(); + if (obj != null && !"".equals(obj.toString().trim())) { + min = Math.min(min, Double.parseDouble(obj.toString().trim())); + max = Math.max(max, Double.parseDouble(obj.toString().trim())); + } + for (int i = col + 1; i < table.getColumnCount() - 3; i++) { + obj = table.getValueAt(row, i); + if (obj != null && !"".equals(obj.toString().trim())) { + min = Math.min(min, Double.parseDouble(obj.toString().trim())); + max = Math.max(max, Double.parseDouble(obj.toString().trim())); + } + } + if (max > Double.MIN_VALUE) { + table.setValueAt(String.format("%.2f", min), row, table.getColumnCount() - 3); + table.setValueAt(String.format("%.2f", max), row, table.getColumnCount() - 2); + } else { + table.setValueAt("", row, table.getColumnCount() - 3); + table.setValueAt("", row, table.getColumnCount() - 2); + } + } + return super.stopCellEditing(); + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor1.java b/src/com/connor/jd/plm/table/MyCellEditor1.java new file mode 100644 index 0000000..6abc0f1 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor1.java @@ -0,0 +1,300 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.swing.DefaultCellEditor; +import javax.swing.JTable; +import javax.swing.JTextField; + +import com.teamcenter.rac.util.MessageBox; + +public class MyCellEditor1 extends DefaultCellEditor { + private int col; + private int row; + private JTable table; + private int top; + private int end; + private int bottom; + private List data; + private double low = 0.0; + private double up = 0.0; + private int cnt = 0; + private int lowCnt = 0; + private int upCnt = 0; + + public MyCellEditor1(JTextField paramJTextField) { + super(paramJTextField); + // TODO Auto-generated constructor stub + } + + public MyCellEditor1(JTextField paramJTextField, int top, int end, int bottom) { + super(paramJTextField); + // TODO Auto-generated constructor stub + this.top = top; + this.end = end; + this.bottom = bottom; + } + + public double getLow() { + return low; + } + + public void setLow(double low) { + this.low = low; + } + + public double getUp() { + return up; + } + + public void setUp(double up) { + this.up = up; + } + + public int getCnt() { + return cnt; + } + + public void setCnt(int cnt) { + this.cnt = cnt; + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + this.col = column; + this.row = row; + this.table = table; + bottom = table.getRowCount() - end; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + // TODO Auto-generated method stub + Object obj = super.getCellEditorValue(); + if (obj != null && !"".equals(obj.toString().trim()) && row >= top - 3 && row <= bottom) { + try { + Double.parseDouble(obj.toString().trim()); + } catch (Exception e) { + MessageBox.post("ֻ", "", MessageBox.ERROR); + return null; + } + } + return obj; + } + + @Override + public boolean stopCellEditing() { + // TODO Auto-generated method stub + System.out.println("top:" + top + ",end:" + end + ",bottom:" + bottom + " ¼У" + col); + data = new ArrayList(); + Object now = getCellEditorValue(); + Object obj = null; + + if (row == 2) { + if (now != null && !"".equals(now.toString().trim())) { + low = Double.parseDouble(now.toString().trim()); + lowCnt = 1; + } else { + low = 0.0; + lowCnt = 0; + } + } + if (row == 3) { + if (now != null && !"".equals(now.toString().trim())) { + up = Double.parseDouble(now.toString().trim()); + upCnt = 1; + } else { + up = 0.0; + upCnt = 0; + } + } + cnt = lowCnt + upCnt; + System.out.println("lowCnt===>" + lowCnt); + System.out.println("upCnt====>" + upCnt); + for (int i = top; i < row && i <= bottom; i++) { + obj = table.getModel().getValueAt(i, col); + if (obj != null && !"".equals(obj.toString().trim())) { + data.add(Double.parseDouble(obj.toString().trim())); + } + } + if (row >= top && row <= bottom && now != null && !"".equals(now.toString().trim())) { + data.add(Double.parseDouble(now.toString().trim())); + } + if (row + 1 >= top) { + for (int i = row + 1; i <= bottom; i++) { + obj = table.getModel().getValueAt(i, col); + if (obj != null && !"".equals(obj.toString().trim())) { + data.add(Double.parseDouble(obj.toString().trim())); + } + } + } else { + for (int i = top; i <= bottom; i++) { + obj = table.getModel().getValueAt(i, col); + if (obj != null && !"".equals(obj.toString().trim())) { + data.add(Double.parseDouble(obj.toString().trim())); + } + } + } + + System.out.println(Arrays.toString(data.toArray())); + + double sum = 0; + double max = Double.MIN_VALUE; + double min = Double.MAX_VALUE; + for (Double d : data) { + sum += d; + max = Math.max(max, d); + min = Math.min(min, d); + } + if (sum != 0) { + double r = max - min; + double avg = sum / data.size(); + table.getModel().setValueAt(String.format("%.2f", min), bottom + 1, col); + table.getModel().setValueAt(String.format("%.2f", max), bottom + 2, col); + table.getModel().setValueAt(String.format("%.2f", r), bottom + 3, col); + table.getModel().setValueAt(String.format("%.2f", avg), bottom + 5, col); + if (data.size() - 1 > 0) { + double stdevSum = 0; + for (Double d : data) { + stdevSum += Math.pow(d - avg, 2); + } + double stdev = Math.sqrt(stdevSum / (data.size() - 1)); + double bar1 = avg - 3 * stdev; + double bar2 = avg + 3 * stdev; + table.getModel().setValueAt(String.format("%.2f", stdev), bottom + 4, col); + table.getModel().setValueAt(String.format("%.2f", bar1), bottom + 6, col); + table.getModel().setValueAt(String.format("%.2f", bar2), bottom + 7, col); + + double cp = 0.0; + if (cnt == 0) { + table.getModel().setValueAt("", bottom + 8, col); + } else if (cnt == 2) { + cp = (up - low) / (6 * stdev); + table.getModel().setValueAt(String.format("%.2f", cp), bottom + 8, col); + } else if (doubleIsEqual(up, 0.0)) { + cp = (avg - low) / (3 * stdev); + table.getModel().setValueAt(String.format("%.2f", cp), bottom + 8, col); + } else { + cp = (up - avg) / (3 * stdev); + table.getModel().setValueAt(String.format("%.2f", cp), bottom + 8, col); + } + double cpu = 0.0; + if (doubleIsEqual(up, 0.0)) { + table.getModel().setValueAt("", bottom + 9, col); + } else { + cpu = (up - avg) / (3 * stdev); + table.getModel().setValueAt(String.format("%.2f", cpu), bottom + 9, col); + } + double cpl = 0.0; + if (doubleIsEqual(low, 0.0)) { + table.getModel().setValueAt("", bottom + 10, col); + } else { + cpl = (avg - low) / (3 * stdev); + table.getModel().setValueAt(String.format("%.2f", cpl), bottom + 10, col); + } + double cpk = 0.0; + if (cnt == 2) { + cpk = (1 - 2 * Math.abs(((low + up) / 2 - avg)) / (up - low)) * cp; + table.getModel().setValueAt(String.format("%.2f", cpk), bottom + 11, col); + } else { + cpk = cp; + table.getModel().setValueAt(doubleIsEqual(cpk, 0.0) ? "" : String.format("%.2f", cpk), bottom + 11, + col); + } + double su = 0.0; + if (doubleIsEqual(cpu, 0.0)) { + table.getModel().setValueAt("", bottom + 12, col); + } else { + su = (1 - normSDist(cpu * 3)) * 1000000; + table.getModel().setValueAt(String.format("%.2f", su), bottom + 12, col); + } + double sl = 0.0; + if (doubleIsEqual(cpl, 0.0)) { + table.getModel().setValueAt("", bottom + 13, col); + } else { + sl = (1 - normSDist(cpl * 3)) * 1000000; + table.getModel().setValueAt(String.format("%.2f", sl), bottom + 13, col); + } + if (cnt == 0) { + table.getModel().setValueAt("", bottom + 14, col); + } else { + table.getModel().setValueAt(String.format("%.2f", su + sl), bottom + 14, col); + } + if (cnt == 0) { + table.getModel().setValueAt("", bottom + 15, col); + } else if (cpk > 1.99) { + table.getModel().setValueAt("dz", bottom + 15, col); + } else if (cpk > 1.66) { + table.getModel().setValueAt("ܺ", bottom + 15, col); + } else if (cpk > 1.32) { + table.getModel().setValueAt("", bottom + 15, col); + } else if (cpk > 0.99) { + table.getModel().setValueAt("", bottom + 15, col); + } else { + table.getModel().setValueAt("", bottom + 15, col); + } + System.out.println("cp:" + cp + ",cpu:" + cpu + ",cpl:" + cpl + ",cpk:" + cpk + ",su:" + su + ",sl:" + + sl + ",ppm:" + (su + sl)); + } else { + table.getModel().setValueAt("", bottom + 4, col); + table.getModel().setValueAt("", bottom + 6, col); + table.getModel().setValueAt("", bottom + 7, col); + table.getModel().setValueAt("", bottom + 8, col); + table.getModel().setValueAt("", bottom + 9, col); + table.getModel().setValueAt("", bottom + 10, col); + table.getModel().setValueAt("", bottom + 11, col); + table.getModel().setValueAt("", bottom + 12, col); + table.getModel().setValueAt("", bottom + 13, col); + table.getModel().setValueAt("", bottom + 14, col); + table.getModel().setValueAt("", bottom + 15, col); + } + } else { + table.getModel().setValueAt("", bottom + 1, col); + table.getModel().setValueAt("", bottom + 2, col); + table.getModel().setValueAt("", bottom + 3, col); + table.getModel().setValueAt("", bottom + 5, col); + table.getModel().setValueAt("", bottom + 4, col); + table.getModel().setValueAt("", bottom + 6, col); + table.getModel().setValueAt("", bottom + 7, col); + table.getModel().setValueAt("", bottom + 8, col); + table.getModel().setValueAt("", bottom + 9, col); + table.getModel().setValueAt("", bottom + 10, col); + table.getModel().setValueAt("", bottom + 11, col); + table.getModel().setValueAt("", bottom + 12, col); + table.getModel().setValueAt("", bottom + 13, col); + table.getModel().setValueAt("", bottom + 14, col); + table.getModel().setValueAt("", bottom + 15, col); + } + return super.stopCellEditing(); + } + + private boolean doubleIsEqual(double a, double b) { + return Math.abs(a - b) < 0.000001; + } + + private double normSDist(double z) { + // this guards against overflow + if (z > 6) + return 1; + if (z < -6) + return 0; + + double gamma = 0.231641900, a1 = 0.319381530, a2 = -0.356563782, a3 = 1.781477973, a4 = -1.821255978, + a5 = 1.330274429; + + double x = Math.abs(z); + double t = 1 / (1 + gamma * x); + + double n = 1 - (1 / (Math.sqrt(2 * Math.PI)) * Math.exp(-z * z / 2)) + * (a1 * t + a2 * Math.pow(t, 2) + a3 * Math.pow(t, 3) + a4 * Math.pow(t, 4) + a5 * Math.pow(t, 5)); + if (z < 0) + return 1.0 - n; + + return n; + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor2.java b/src/com/connor/jd/plm/table/MyCellEditor2.java new file mode 100644 index 0000000..ccdef61 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor2.java @@ -0,0 +1,48 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.DefaultCellEditor; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.JTextField; + +public class MyCellEditor2 extends DefaultCellEditor { + private JLabel img = null; + private JComboBox jued = null; + private int type = -1; + + public MyCellEditor2(JTextField var1) { + super(var1); + // TODO Auto-generated constructor stub + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (value instanceof JLabel) { + img = (JLabel) value; + type = 1; + return img; + } + if (value instanceof JComboBox) { + jued = (JComboBox) value; + type = 2; + return jued; + } + type = 0; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + if (type == 1) { + return img; + } + if (type == 2) { + return jued; + } + return super.getCellEditorValue(); + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor3.java b/src/com/connor/jd/plm/table/MyCellEditor3.java new file mode 100644 index 0000000..f5b2295 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor3.java @@ -0,0 +1,39 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.DefaultCellEditor; +import javax.swing.JTable; +import javax.swing.JTextField; + +public class MyCellEditor3 extends DefaultCellEditor { + private JCheckPanel check = null; + private int type = -1; + + public MyCellEditor3(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 + if (value instanceof JCheckPanel) { + check = (JCheckPanel) value; + type = 1; + return check; + } + type = 0; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + // TODO Auto-generated method stub + if (type == 1) { + return check; + } + return super.getCellEditorValue(); + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellEditor4.java b/src/com/connor/jd/plm/table/MyCellEditor4.java new file mode 100644 index 0000000..6cd3bb4 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellEditor4.java @@ -0,0 +1,38 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.DefaultCellEditor; +import javax.swing.JCheckBox; +import javax.swing.JTable; +import javax.swing.JTextField; + +public class MyCellEditor4 extends DefaultCellEditor { + private int type = -1; + private JCheckBox check; + + public MyCellEditor4(JTextField arg0) { + super(arg0); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (value instanceof JCheckBox) { + System.out.println("123456789abcdefg"); + check = (JCheckBox) value; + type = 1; + return check; + } + type = 0; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + if (type == 1) { + return check; + } + return super.getCellEditorValue(); + } + +} diff --git a/src/com/connor/jd/plm/table/MyCellRenderer.java b/src/com/connor/jd/plm/table/MyCellRenderer.java new file mode 100644 index 0000000..ed11b04 --- /dev/null +++ b/src/com/connor/jd/plm/table/MyCellRenderer.java @@ -0,0 +1,19 @@ +package com.connor.jd.plm.table; + +import java.awt.Component; + +import javax.swing.JCheckBox; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +public class MyCellRenderer extends 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; + } + return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + } +} diff --git a/src/com/connor/jd/plm/table/MyComboBoxRenderer.java b/src/com/connor/jd/plm/table/MyComboBoxRenderer.java new file mode 100644 index 0000000..d66441a --- /dev/null +++ b/src/com/connor/jd/plm/table/MyComboBoxRenderer.java @@ -0,0 +1,24 @@ +package com.connor.jd.plm.table; + +import java.awt.Color; +import java.awt.Component; + +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.SwingConstants; + +public class MyComboBoxRenderer extends JLabel implements ListCellRenderer { + public MyComboBoxRenderer() { + setOpaque(true); + } + + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, + boolean cellHasFocus) { + setBackground(isSelected ? new Color(0xff0078D7) : Color.WHITE); + setHorizontalAlignment(SwingConstants.CENTER); + setText(value.toString()); + return this; + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/TCTableUtil.java b/src/com/connor/jd/plm/table/TCTableUtil.java new file mode 100644 index 0000000..9141026 --- /dev/null +++ b/src/com/connor/jd/plm/table/TCTableUtil.java @@ -0,0 +1,141 @@ +package com.connor.jd.plm.table; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException; +import com.teamcenter.services.rac.core.DataManagementService; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn; +import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse; + +public class TCTableUtil { + public static String[][] getTableRows(TCComponentForm form, String prop, String[] colNames) { + try { + TCProperty tcProperty = form.getTCProperty(prop); + TCComponent[] components = tcProperty.getReferenceValueArray(); + String[][] res = new String[components.length][colNames.length]; + for (int i = 0; i < components.length; i++) { + for (int ii = 0; ii < colNames.length; ii++) { + res[i][ii] = components[i].getPropertyDisplayableValue(colNames[ii]); + } + } + return res; + } catch (NullPointerException e) { + System.out.println("\"" + prop + "\""); + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + + e.printStackTrace(); + } + + return null; + } + + public static List> getTableMapList(TCComponentForm form, String prop, String[] colNames) { + try { + TCProperty tcProperty = form.getTCProperty(prop); + TCComponent[] components = tcProperty.getReferenceValueArray(); + List> res = new ArrayList>(); + for (int i = 0; i < components.length; i++) { + Map temp = new HashMap(); + for (int ii = 0; ii < colNames.length; ii++) { + temp.put(colNames[ii], components[i].getPropertyDisplayableValue(colNames[ii])); + } + res.add(temp); + } + return res; + } catch (NullPointerException e) { + System.out.println("\"" + prop + "\""); + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + + e.printStackTrace(); + } + + return null; + } + + public static boolean setTableRows(TCComponentForm form, String prop, String refName, String[] colNames, + String[][] rows) { + List list = new ArrayList(); + DataManagementService service = DataManagementService + .getService((TCSession) AIFUtility.getCurrentApplication().getSession()); + CreateIn ci = new CreateIn(); + ci.data.boName = refName; + Map map = new HashMap(); + for (int i = 0; i < rows.length; i++) { + for (int ii = 0; ii < colNames.length; ii++) { + map.put(colNames[ii], rows[i][ii]); + } + System.out.println(map.size()); + ci.data.stringProps = map; + try { + CreateResponse response = service.createObjects(new CreateIn[] { ci }); + System.out.println("CreateResponse size:" + response.serviceData.sizeOfCreatedObjects()); + if (response.serviceData.sizeOfCreatedObjects() > 0) { + list.add(response.output[0].objects[0]); + } else { + String str = String.join(",", response.serviceData.getPartialError(0).getMessages()); + System.out.println(str); + } + } catch (ServiceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + try { + form.getTCProperty(prop).setReferenceValueArray(list.toArray(new TCComponent[list.size()])); + System.out.println("tableɹ"); + return true; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + public static boolean setTableMapList(TCComponentForm form, String prop, String refName, + List> dataList) { + List list = new ArrayList(); + DataManagementService service = DataManagementService + .getService((TCSession) AIFUtility.getCurrentApplication().getSession()); + CreateIn ci = new CreateIn(); + ci.data.boName = refName; + for (int i = 0; i < dataList.size(); i++) { + System.out.println(dataList.get(i).size()); + ci.data.stringProps = dataList.get(i); + try { + CreateResponse response = service.createObjects(new CreateIn[] { ci }); + System.out.println("CreateResponse size:" + response.serviceData.sizeOfCreatedObjects()); + if (response.serviceData.sizeOfCreatedObjects() > 0) { + list.add(response.output[0].objects[0]); + } else { + String str = String.join(",", response.serviceData.getPartialError(0).getMessages()); + System.out.println(str); + } + } catch (ServiceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + try { + form.getTCProperty(prop).setReferenceValueArray(list.toArray(new TCComponent[list.size()])); + System.out.println("tableɹ"); + return true; + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } +} diff --git a/src/com/connor/jd/plm/table/TableCellTextAreaRenderer.java b/src/com/connor/jd/plm/table/TableCellTextAreaRenderer.java new file mode 100644 index 0000000..e91e9a5 --- /dev/null +++ b/src/com/connor/jd/plm/table/TableCellTextAreaRenderer.java @@ -0,0 +1,72 @@ +package com.connor.jd.plm.table; + +import java.awt.Color; +import java.awt.Component; + +import javax.swing.BorderFactory; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.table.TableCellRenderer; + +public class TableCellTextAreaRenderer extends JTextArea implements TableCellRenderer { + public TableCellTextAreaRenderer() { + setLineWrap(true); + setWrapStyleWord(true); + + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) { + // TODO Auto-generated method stub + 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); + 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; + } + +// @Override +// public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, +// int row, int column) { +// // TODO Auto-generated method stub +// 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); +// } +// setBorder(BorderFactory.createLineBorder(Color.white)); +// setBackground(Color.white); +// setForeground(Color.black); +// if(isSelected){ +// setBackground(new Color(0, 120, 215)); +// setForeground(Color.white); +// } +// String val=(String) table.getValueAt(row, column); +// int w=0; +// if(val!=null){ +// w=val.length()*6/table.getColumn(table.getColumnName(column)).getWidth(); +// } +// if(w!=0){ +// //System.out.println("height:"+table.getRowHeight()*(w+1)); +// table.setRowHeight(row,table.getRowHeight()*(w+1)); +// } +// +// +// setText(value == null ? "" : value.toString()); +// return this; +// } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/table/TempTest.java b/src/com/connor/jd/plm/table/TempTest.java new file mode 100644 index 0000000..82c971c --- /dev/null +++ b/src/com/connor/jd/plm/table/TempTest.java @@ -0,0 +1,57 @@ +package com.connor.jd.plm.table; + +import java.awt.BorderLayout; + +import javax.swing.JButton; +import javax.swing.JDialog; + +public class TempTest { + public static void main(String[] args) { + String temp="";; + String[] name=new String[]{"DZʧЧģʽͺ","СԹͼ","ʼƷ嵥","Ƽƻ","СԲƷ֤","ԭϿ","Ϣ","Ӧ̻ϵ","ԭϽϼ","Ӧ̳۱","ԭת׶","Ŀ˼·ܽ","䷽","С","Լⵥ","ɿĿ֤","Сɫ¼","С鹤ռ¼","ݱ","ɿ֤","ʵܽᱨ","С鹤յ","С鰲żƻ","Ʒоܱ","뵥","ԲƷ֤","עܹռ¼","ϼⱨ","Ŀ¼","ǰԤжƻ","ͻϹռ¼","ͻܽ","СԽ׶"}; + String t=""; + String te=""; + String[] name2=new String[]{"ԭ嵥","Ʒ嵥","BOM","ԲƷ֤","","ͼ","嵥","PFMEA","ʼоƻ","ȷϼƻ","ƽƻ","տ","²Ʒ","̼¼ܽ","Ŀ","Թ֤","ʼо","ƽ","","ܽᱨ","ɿ֤","֤","ⱨ","Ŀ¼","ǰԤжƻ","ͻϹռ¼","ͻܽ","Խ׶"}; + String[] name3=new String[]{"ԿƼƻ","տ","PSW","̼¼ܽ","Ŀ","PFMEA","ͼ","ԹŻƻ","ԹŻܽ","ͻʹȶԷ","ԭȶԷ","ƷȶԷ","ȶԷ","Խ׶"}; + for(int i=0;i settingMap = new HashMap(); + for (String s : dbSettings) { + settingMap.put(s.substring(0, s.indexOf(":")), s.substring(s.indexOf(":") + 1, s.length())); + } + System.out.println(settingMap.get("url") + settingMap.get("user") + settingMap.get("pass")); + c = DriverManager.getConnection(settingMap.get("url"), settingMap.get("user"), settingMap.get("pass")); + } +// c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:TC", name, pass); + // ݵķ, 򵥵,һҳ TCݿʵƣصļtest.sqlпִ鿴 + // "jdbc:oracle:thin:@:˿:ϵͳʵ", username, password, + // ,ҪԼ֪ڼԲ֪. + // ˿һĬ1521, ҪǸı˾ͿԼļļlistener.ora + // ϵͳʵһĬorcl, ҪDzǵĻ select name from v$database; + // username,password,ǵ½ݿû. + + } catch (SQLException e) { + e.printStackTrace(); + } catch (Exception e1) { + e1.printStackTrace(); + } + return c; + } +} diff --git a/src/com/connor/jd/plm/utils/DBUtil.java b/src/com/connor/jd/plm/utils/DBUtil.java new file mode 100644 index 0000000..ba1337a --- /dev/null +++ b/src/com/connor/jd/plm/utils/DBUtil.java @@ -0,0 +1,49 @@ +package com.connor.jd.plm.utils; + +import java.util.HashMap; +import java.util.Map; + +import javax.sql.DataSource; +import javax.swing.JOptionPane; + +import com.teamcenter.rac.kernel.TCSession; + +import cn.hutool.db.ds.simple.SimpleDataSource; + +public class DBUtil { + + public static DataSource getDataSource(TCSession session) { + Map settingMap = getDbSetting(session); + if (settingMap == null) { + return null; + } + + String url = settingMap.get("url"); + String user = settingMap.get("user"); + String pass = settingMap.get("pass"); + String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // ָ SQL Server + + DataSource dataSource = new SimpleDataSource(url, user, pass,driverClass); + return dataSource; + } + + private static Map getDbSetting(TCSession session) { + Map settingMap = null; + String[] dbSettings = JDMethodUtil.getPrefStrArray("jd2_db_settings", session); + if (dbSettings.length != 3) { + JOptionPane.showMessageDialog(null, "jd2_db_settingsݿô", "", JOptionPane.ERROR_MESSAGE); + } else { + settingMap = new HashMap<>(); + for (String s : dbSettings) { + int colonIndex = s.indexOf(":"); + if (colonIndex != -1) { + settingMap.put(s.substring(0, colonIndex), s.substring(colonIndex + 1)); + } + } + } + return settingMap; + } +} + + + diff --git a/src/com/connor/jd/plm/utils/DatePickerUtil.java b/src/com/connor/jd/plm/utils/DatePickerUtil.java new file mode 100644 index 0000000..c5eb47e --- /dev/null +++ b/src/com/connor/jd/plm/utils/DatePickerUtil.java @@ -0,0 +1,80 @@ +package com.connor.jd.plm.utils; + +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Date; +import java.util.Locale; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JOptionPane; + +import com.eltima.components.ui.DatePicker; + +public class DatePickerUtil { + public static void main(String[] args) { + + JFrame f = new JFrame("LoL"); + f.setSize(400, 300); + f.setLocation(200, 200); + f.setLayout(null); + + final DatePicker datepick; + datepick = getDatePicker("yyyy-MM-dd hh:mm"); + + f.add(datepick); + + JButton b = new JButton("ȡʱ"); + b.setBounds(137, 183, 100, 30); + f.add(b); + + b.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + JOptionPane.showMessageDialog(f, "ȡؼеڣ" + datepick.getText()); + System.out.println(datepick.getValue()); + } + }); + + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + f.setVisible(true); + } + + public static DatePicker getDatePicker(String format) { + final DatePicker datepick; + // ʽ ¼ʱѡUI + String DefaultFormat = "yyyy-MM-dd"; + // ǰʱ + Date date = new Date(); + // + Font font = new Font("Times New Roman", Font.BOLD, 14); + + Dimension dimension = new Dimension(180, 24); + +// int[] hilightDays = { 1, 3, 5, 7 }; + +// int[] disabledDays = { 4, 6, 5, 9 }; + + datepick = new DatePicker(date, format == null ? DefaultFormat : format, font, dimension); + + datepick.setLocation(137, 83); + datepick.setBounds(137, 83, 180, 24); + // һ·Ҫʾ +// datepick.setHightlightdays(hilightDays, Color.red); + // һ·вҪӣʻɫʾ +// datepick.setDisableddays(disabledDays); + // ù + datepick.setLocale(Locale.CHINA); + // ʱɼ + if (format != null) { + datepick.setTimePanleVisible(true); + } else { + datepick.setTimePanleVisible(false); + } + return datepick; + } +} diff --git a/src/com/connor/jd/plm/utils/DialogUtil.java b/src/com/connor/jd/plm/utils/DialogUtil.java new file mode 100644 index 0000000..31781d4 --- /dev/null +++ b/src/com/connor/jd/plm/utils/DialogUtil.java @@ -0,0 +1,288 @@ +package com.connor.jd.plm.utils; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dialog.ModalityType; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; + +import com.connor.jd.plm.dialogs.BOMManagementFrame; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; + +public class DialogUtil { + + public static TableMsg createTableMsg(String[] header, List msgContent) { + DefaultTableModel msgModel = new DefaultTableModel(header, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + // TODO Auto-generated method stub + return false; + } + }; + JTable msgTable = new JTable(msgModel); + for (int columnIndex = 0; columnIndex < msgTable.getColumnCount(); columnIndex++) { + // msgTable.getColumnModel().getColumn(columnIndex).setMinWidth(100); + msgTable.getColumnModel().getColumn(columnIndex).setPreferredWidth(200); + } + msgTable.setRowHeight(25); + msgTable.setShowGrid(false); + msgTable.setAutoscrolls(true); + msgTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + msgTable.getTableHeader().setReorderingAllowed(false); +// msgTable.getTableHeader().setVisible(false); + + for (String[] row : msgContent) { + msgModel.addRow(row); + } + + msgTable.invalidate(); + msgTable.repaint(); + JScrollPane msgPanel = new JScrollPane(msgTable); + msgPanel.setPreferredSize(new Dimension(header.length * 200, 400)); + msgPanel.setBorder(BorderFactory.createEmptyBorder()); + return new TableMsg(msgPanel, msgTable); + } + + public static JDialog createSearchAndSelectRevDialog(BOMManagementFrame frame, JTable paramTable, + JCheckBox selectAll, JButton field) { + JDialog dialog = new JDialog(); + dialog.setTitle("汾"); + dialog.setSize(520, 400); + dialog.setResizable(true); + dialog.setAutoRequestFocus(true); + dialog.setAlwaysOnTop(true); + dialog.setLocationRelativeTo(frame); + dialog.setModalityType(ModalityType.APPLICATION_MODAL); + + JPanel content = new JPanel(); + content.setLayout(null); + content.setPreferredSize(new Dimension(520, 400)); + JLabel targetLabel = new JLabel("Ŀ"); + targetLabel.setBounds(10, 10, 50, 25); + JTextField targetText = new JTextField(); + targetText.setText("ҪID"); + targetText.setForeground(Color.GRAY); + if (!"".equals(field.getText())) { + targetText.setText(field.getText().substring(0, field.getText().indexOf("/"))); + targetText.setForeground(Color.BLACK); + } + targetText.setBounds(20, 50, 300, 25); + JButton searchBtn = new JButton(""); + searchBtn.setBounds(380, 50, 100, 25); + + String[] colDisplayNames = new String[] { "", "", "״̬", "", "ID", "" }; + DefaultTableModel model = new DefaultTableModel(colDisplayNames, 0) { + @Override + public boolean isCellEditable(int paramInt1, int paramInt2) { + return false; + } + }; + JTable table = new JTable(model); + table.getColumnModel().getColumn(0).setMinWidth(100); + table.getColumnModel().getColumn(1).setMinWidth(100); + table.getColumnModel().getColumn(2).setMinWidth(100); + table.getColumnModel().getColumn(3).setMinWidth(100); + table.getColumnModel().getColumn(4).setMinWidth(60); + table.getColumnModel().getColumn(4).setPreferredWidth(60); + TableColumnModel tcm = table.getColumnModel(); + TableColumn tc = tcm.getColumn(5); + tc.setWidth(0); + tc.setPreferredWidth(0); + tc.setMaxWidth(0); + tc.setMinWidth(0); + table.getTableHeader().getColumnModel().getColumn(5).setMaxWidth(0); + table.getTableHeader().getColumnModel().getColumn(5).setMinWidth(0); + table.setRowHeight(25); + table.setAutoscrolls(true); + table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + table.getTableHeader().setReorderingAllowed(false); + JScrollPane jsp = new JScrollPane(table); + jsp.setBounds(20, 100, 460, 200); + + JButton okBtn = new JButton("ȷ"); + okBtn.setBounds(140, 320, 100, 25); + JButton cancelBtn = new JButton("ȡ"); + cancelBtn.setBounds(260, 320, 100, 25); + + targetText.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + // TODO Auto-generated method stub + if ("".equals(targetText.getText())) { + targetText.setText("ҪID"); + targetText.setForeground(Color.GRAY); + } + } + + @Override + public void focusGained(FocusEvent e) { + // TODO Auto-generated method stub + if ("ҪID".equals(targetText.getText())) { + targetText.setText(""); + targetText.setForeground(Color.BLACK); + } + } + }); + + targetText.addKeyListener(new KeyAdapter() { + @Override + public void keyTyped(KeyEvent paramKeyEvent) { + // TODO Auto-generated method stub + super.keyTyped(paramKeyEvent); + if (paramKeyEvent.getKeyChar() == KeyEvent.VK_ENTER) { + searchBtn.doClick(); + } + } + }); + + searchBtn.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int cnt = model.getRowCount(); + for (int i = 0; i < cnt; i++) { + model.removeRow(0); + } + table.revalidate(); + table.repaint(); + String text = targetText.getText(); + System.out.println(text); + if ("ҪID".equals(text)) { + return; + } + long startTime = System.currentTimeMillis(); + TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession(); + TCComponentItem[] items = getTarget(content, text, session); + if (items == null) { + return; + } + List tableDataList = new ArrayList(); + for (TCComponentItem item : items) { + try { + item.refresh(); + TCComponent[] comps = item.getRelatedComponents("revision_list"); + for (TCComponent comp : comps) { + String objetcString = comp.getProperty("object_string"); + TCComponent[] forms = comp.getRelatedComponents("IMAN_master_form_rev"); + String desc = ""; + if (forms.length > 0) { + desc = forms[0].getProperty("jd2_wlms"); + } + TCComponent[] statusArray = comp.getRelatedComponents("release_status_list"); + String status = ""; + if (statusArray != null && statusArray.length > 0) { + status = statusArray[statusArray.length - 1].getProperty("object_name"); + } + String owningUser = comp.getProperty("owning_user"); + String groupId = comp.getProperty("owning_group"); + tableDataList.add(new Object[] { objetcString, desc, status, owningUser, groupId, comp }); + } + } catch (TCException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + for (Object[] rowData : tableDataList) { + model.addRow(rowData); + } + table.revalidate(); + table.repaint(); + System.out.println("ʾʱ" + (System.currentTimeMillis() - startTime) + "ms"); + } + }); + + okBtn.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent paramActionEvent) { + // TODO Auto-generated method stub + frame.okCallback(table, paramTable, selectAll, field); +// dialog.setVisible(false); + dialog.dispose(); + } + }); + + cancelBtn.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent paramActionEvent) { + // TODO Auto-generated method stub +// dialog.setVisible(false); + dialog.dispose(); + } + }); + + content.add(targetLabel); + content.add(targetText); + content.add(searchBtn); + content.add(jsp); + content.add(okBtn); + content.add(cancelBtn); + + dialog.add(content); + dialog.setVisible(true); + + return dialog; + } + + private static TCComponentItem[] getTarget(Component parent, String itemId, TCSession session) { + TCComponent[] comps = null; + try { + comps = session.search("Item ID", new String[] { " ID" }, new String[] { itemId }); +// TCComponentItemType type = new TCComponentItemType(); +// comps = type.findItems(itemId); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return null; + } + if (comps == null || comps.length == 0) { + JOptionPane.showMessageDialog(parent, "Чϱ룬ȷϱǷȷ", "ʾ", JOptionPane.WARNING_MESSAGE); + return null; + } + TCComponentItem[] items = new TCComponentItem[comps.length]; + for (int i = 0; i < comps.length; i++) { + items[i] = (TCComponentItem) comps[i]; + } + return items; + } + + public static class TableMsg { + public JScrollPane panel; + public JTable table; + + public TableMsg(JScrollPane panel, JTable table) { + super(); + this.panel = panel; + this.table = table; + } + + } +} diff --git a/src/com/connor/jd/plm/utils/ExcelInfoScanner.java b/src/com/connor/jd/plm/utils/ExcelInfoScanner.java new file mode 100644 index 0000000..11ce297 --- /dev/null +++ b/src/com/connor/jd/plm/utils/ExcelInfoScanner.java @@ -0,0 +1,47 @@ +package com.connor.jd.plm.utils; + +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import com.aspose.cells.Cells; +import com.aspose.cells.License; +import com.aspose.cells.Workbook; +import com.aspose.cells.WorksheetCollection; + +public class ExcelInfoScanner { + + public static Map getClassPropOptions(String path, String nodeName) { + Map res = new HashMap(); + try { + getLicense(); + Workbook excel = new Workbook(path); + WorksheetCollection wc = excel.getWorksheets(); + Cells cells = wc.get(0).getCells(); + for (int i = 0; i <= cells.getMaxDataRow(); i++) { + if (cells.get(i, 0).getStringValue().equals(nodeName)) { + res.put(cells.get(i, 1).getIntValue(), cells.get(i, 2).getStringValue()); + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return res; + } + + public static boolean getLicense() throws Exception { + boolean result = false; + try { + InputStream is = com.aspose.cells.Cell.class.getResourceAsStream("/com/aspose/cells/resources/license.xml"); + License aposeLic = new License(); + aposeLic.setLicense(is); + result = true; + is.close(); + } catch (Exception e) { + e.printStackTrace(System.out); + throw e; + } + return result; + } +} diff --git a/src/com/connor/jd/plm/utils/JDMethodUtil.java b/src/com/connor/jd/plm/utils/JDMethodUtil.java new file mode 100644 index 0000000..f7b63ad --- /dev/null +++ b/src/com/connor/jd/plm/utils/JDMethodUtil.java @@ -0,0 +1,47 @@ +package com.connor.jd.plm.utils; + +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.TCUserService; + +public class JDMethodUtil { + + public static TCPreferenceService service; + public static TCUserService userservice; + + /** + * + * + * @param prefName + * @return + */ + public static String getPrefStr(String prefName, TCSession session) { + if (service == null) { + service = session.getPreferenceService(); + } + String str = service.getString(TCPreferenceService.TC_preference_site, prefName); + if (str == null) { + str = new String(""); + } + return str; + } + + /** + * + * + * @param prefName + * @return + */ + public static String[] getPrefStrArray(String prefName, TCSession session) { + if (service == null) { + 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; + } +} diff --git a/src/com/connor/jd/plm/utils/KeyValComboBox.java b/src/com/connor/jd/plm/utils/KeyValComboBox.java new file mode 100644 index 0000000..5659013 --- /dev/null +++ b/src/com/connor/jd/plm/utils/KeyValComboBox.java @@ -0,0 +1,96 @@ +package com.connor.jd.plm.utils; + +import java.awt.Component; +import java.util.Vector; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JComboBox; +import javax.swing.JList; + +import com.connor.jd.plm.beans.CheckBoxPo; + +public class KeyValComboBox extends JComboBox { + + public KeyValComboBox(Vector values) { + super(values); + rendererData(); // Ⱦ + } + + public void rendererData() { + DefaultListCellRenderer render = new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, + boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof CheckBoxPo) { + CheckBoxPo po = (CheckBoxPo) value; + this.setText(po.text); + } + return this; + } + }; + this.setRenderer(render); + } + + // ޸Comboxе + public void updateData(Vector values) { + setModel(new DefaultComboBoxModel(values)); + rendererData(); + } + + @Override + public void setSelectedItem(Object anObject) { // ѡtext봫IJͬ + if (anObject != null) { + if (anObject instanceof CheckBoxPo) { + super.setSelectedItem(anObject); + } + if (anObject instanceof String) { + for (int index = 0; index < getItemCount(); index++) { + CheckBoxPo po = (CheckBoxPo) getItemAt(index); + if (po.text.equals(anObject.toString())) { + super.setSelectedIndex(index); + } + } + } + } else { + super.setSelectedItem(anObject); + } + } + + public void setSelectedValue(Object anObject) { // ѡvalue봫IJͬ + if (anObject != null) { + if (anObject instanceof CheckBoxPo) { + super.setSelectedItem(anObject); + } + if (anObject instanceof String) { + for (int index = 0; index < getItemCount(); index++) { + CheckBoxPo po = (CheckBoxPo) getItemAt(index); + if (po.value.equals(anObject.toString())) { + super.setSelectedIndex(index); + } + } + } + } else { + super.setSelectedItem(anObject); + } + } + + // ѡļֵ + public Object getSelectedValue() { + if (getSelectedItem() instanceof CheckBoxPo) { + CheckBoxPo po = (CheckBoxPo) getSelectedItem(); + return po.value; + } + return (getSelectedItem() != null) ? getSelectedItem().toString() : null; + } + + // ѡʾı + public String getSelectedText() { + if (getSelectedItem() instanceof CheckBoxPo) { + CheckBoxPo po = (CheckBoxPo) getSelectedItem(); + return po.text; + } + return (getSelectedItem() != null) ? getSelectedItem().toString() : null; + } +} \ No newline at end of file diff --git a/src/com/connor/jd/plm/utils/SimpleExcelUtil.java b/src/com/connor/jd/plm/utils/SimpleExcelUtil.java new file mode 100644 index 0000000..e975127 --- /dev/null +++ b/src/com/connor/jd/plm/utils/SimpleExcelUtil.java @@ -0,0 +1,69 @@ +package com.connor.jd.plm.utils; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import com.aspose.cells.Cells; +import com.aspose.cells.License; +import com.aspose.cells.Workbook; +import com.aspose.cells.WorksheetCollection; + +public class SimpleExcelUtil { + public static void exportExcel(String path, String[] header, List data) { + if (path == null || data == null) { + return; + } + try { + File file = new File(path); + file.createNewFile(); + + getLicense(); + + Workbook excel = new Workbook(path); + WorksheetCollection wc = excel.getWorksheets(); + Cells cells = wc.get(0).getCells(); + int rowIndex = 0; + if (header != null) { + for (int columnIndex = 0; columnIndex < header.length; columnIndex++) { + cells.get(rowIndex, columnIndex).setValue(header[columnIndex]); + } + rowIndex++; + } + for (String[] arr : data) { + for (int columnIndex = 0; columnIndex < arr.length; columnIndex++) { + cells.get(rowIndex, columnIndex).setValue(arr[columnIndex]); + } + rowIndex++; + } + excel.save(path); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static boolean getLicense() throws Exception { + boolean result = false; + try { + InputStream is = com.aspose.cells.Cell.class.getResourceAsStream("/com/aspose/cells/resources/license.xml"); + License aposeLic = new License(); + aposeLic.setLicense(is); + result = true; + is.close(); + } catch (Exception e) { + e.printStackTrace(System.out); + throw e; + } + return result; + } + + public static void main(String[] args) { + List test = new ArrayList(); + test.add(new String[] { "zzz", "xxx" }); + SimpleExcelUtil.exportExcel(System.getenv("temp") + File.separator + "xxxxxxxxxxxxxxxxxxxx.xlsx", + new String[] { "1", "2" }, test); + System.out.println(System.getenv("temp")); + } +} diff --git a/src/com/connor/jd/plm/utils/StringCreateUtil.java b/src/com/connor/jd/plm/utils/StringCreateUtil.java new file mode 100644 index 0000000..57e6a19 --- /dev/null +++ b/src/com/connor/jd/plm/utils/StringCreateUtil.java @@ -0,0 +1,21 @@ +package com.connor.jd.plm.utils; + +public class StringCreateUtil { + public static String createBlank(int num) { + StringBuilder sb = new StringBuilder(); + while (num > 0) { + sb.append(" "); + num--; + } + return sb.toString(); + } + + public static String createPoint(int num) { + StringBuilder sb = new StringBuilder(); + while (num > 0) { + sb.append("."); + num--; + } + return sb.toString(); + } +} diff --git a/src/com/teamcenter/rac/commands/namedreferences/NamedReferencesDialog.java b/src/com/teamcenter/rac/commands/namedreferences/NamedReferencesDialog.java new file mode 100644 index 0000000..d026ef6 --- /dev/null +++ b/src/com/teamcenter/rac/commands/namedreferences/NamedReferencesDialog.java @@ -0,0 +1,1501 @@ +package com.teamcenter.rac.commands.namedreferences; + +import java.awt.Component; +import java.awt.Cursor; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Insets; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; + +import org.apache.log4j.Logger; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +import com.teamcenter.rac.aif.AIFClipboard; +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AIFPortal; +import com.teamcenter.rac.aif.AbstractAIFCommand; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.InterfaceAIFOperationListener; +import com.teamcenter.rac.aif.common.AIFIdentifier; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.AIFComponentEvent; +import com.teamcenter.rac.aif.kernel.AbstractAIFSession; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponentEventListener; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.commands.newdataset.DatasetUtil; +import com.teamcenter.rac.commands.newdataset.IFilesSelector; +import com.teamcenter.rac.commands.newdataset.TCFileDescriptor; +import com.teamcenter.rac.commands.newdataset.TCFileSelectorService; +import com.teamcenter.rac.common.Activator; +import com.teamcenter.rac.common.viewedit.ViewEditHelper; +import com.teamcenter.rac.kernel.NamedReferenceContext; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetDefinition; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.services.IPropertyPolicyService; +import com.teamcenter.rac.util.ButtonLayout; +import com.teamcenter.rac.util.ConfirmDialog; +import com.teamcenter.rac.util.ConfirmationDialog; +import com.teamcenter.rac.util.Cookie; +import com.teamcenter.rac.util.HorizontalLayout; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.OSGIUtil; +import com.teamcenter.rac.util.Registry; +import com.teamcenter.rac.util.Separator; +import com.teamcenter.rac.util.Utilities; +import com.teamcenter.rac.util.VerticalLayout; +import com.teamcenter.rac.util.log.Debug; +import com.teamcenter.soa.common.ObjectPropertyPolicy; +import com.teamcenter.soa.common.PolicyType; + +public class NamedReferencesDialog extends AbstractAIFDialog implements InterfaceAIFComponentEventListener { + private static final Logger logger = Logger.getLogger(NamedReferencesDialog.class); + + private JTable table; + + private JScrollPane tableScrollPane; + + private NamedReferencesTableModel model; + + private JButton openButton; + + private JButton importButton; + + private JButton exportButton; + + private JButton cutButton; + + private JButton copyButton; + + private JButton pasteButton; + + private JButton deleteButton; + + private Window parent; + + private AbstractAIFSession session; + + private Registry appReg; + + private TCComponentDataset datasetComponent = null; + + private String truncateFileName = "FALSE"; + + private static String[] sourceClassificationString; + + private static String[] destClassificationString; + + String[] prop = { "ip_classification", "gov_classification" }; + + public static final String OBJECT_NAME_COLUMN_ID = "object_name"; + + public static final String TCFILE_NAME_COLUMN_ID = "original_file_name"; + + public static final String SIZE_COLUMN_ID = "file_size"; + + public static final String REMOTE_COLUMN_ID = "owning_site"; + + public static final String TYPE_COLUMN_ID = "object_type"; + + public static final String LASTMODIFIED_COLUMN_ID = "last_mod_date"; + + public static final String VOLUME_COLUMN_ID = "volume_tag"; + + public static final String REF_LIST = "ref_list"; + + public static final String REF_NAMES = "ref_names"; + + public static final String ADDITIONAL_COLUMN = "com.teamcenter.rac.commands.namedreferences.AdditionalColumnShown"; + + public static final String TC_TRUNCATE_FILE_NAME = "TC_truncate_file_name"; + + protected JFileChooser exportFc; + + private TCComponent[] toolComponents; + + private TCComponent selectedToolComponent; + + private static String fileNamePolicy; + + public NamedReferencesDialog(TCComponentDataset paramTCComponentDataset, Frame paramFrame) { + super(paramFrame, true); + this.parent = paramFrame; + this.session = paramTCComponentDataset.getSession(); + this.datasetComponent = paramTCComponentDataset; + initializeDialog(); + } + + public NamedReferencesDialog(TCComponentDataset paramTCComponentDataset, Dialog paramDialog) { + super(paramDialog, true); + this.parent = paramDialog; + this.session = paramTCComponentDataset.getSession(); + this.datasetComponent = paramTCComponentDataset; + initializeDialog(); + } + + public NamedReferencesDialog(TCComponentDataset paramTCComponentDataset) { + super(true); + this.session = paramTCComponentDataset.getSession(); + this.datasetComponent = paramTCComponentDataset; + initializeDialog(); + } + + private void initializeDialog() { + this.appReg = Registry.getRegistry(this); + setTitle(this.appReg.getString("command.TITLE")); + setModal(false); + JPanel jPanel1 = new JPanel(new VerticalLayout(5, 2, 2, 2, 2)); + getContentPane().add(jPanel1); + JPanel jPanel2 = new JPanel(new HorizontalLayout(2, 2, 2, 2, 2)); + JPanel jPanel3 = new JPanel(new ButtonLayout()); + TCPreferenceService tCPreferenceService = ((TCSession) this.session).getPreferenceService(); + String[] arrayOfString = tCPreferenceService.getStringArray(0, + "com.teamcenter.rac.commands.namedreferences.AdditionalColumnShown"); + this.truncateFileName = tCPreferenceService.getString(0, "TC_truncate_file_name"); + this.model = new NamedReferencesTableModel(arrayOfString); + this.table = new JTable(this.model); + this.table.setPreferredScrollableViewportSize(new Dimension(550, 100)); + RightTextRenderer rightTextRenderer = new RightTextRenderer(); + TableColumn tableColumn1 = getTableColumnByName("file_size"); + tableColumn1.setCellRenderer(rightTextRenderer); + this.table.setAutoResizeMode(0); + this.tableScrollPane = new JScrollPane(this.table); + DefaultTableCellRenderer defaultTableCellRenderer = new DefaultTableCellRenderer(); + defaultTableCellRenderer.setToolTipText(this.appReg.getString("changeFileName.TIP")); + TableColumn tableColumn2 = getTableColumnByName("original_file_name"); + tableColumn2.setCellRenderer(defaultTableCellRenderer); + AIFIdentifier[] arrayOfAIFIdentifier1 = this.model.getColumnIdentifiers(); + AIFIdentifier[] arrayOfAIFIdentifier2; + arrayOfAIFIdentifier2 = arrayOfAIFIdentifier1; + int i = arrayOfAIFIdentifier1.length; + for (byte b = 0; b < i; b++) { + AIFIdentifier aIFIdentifier = arrayOfAIFIdentifier2[b]; + TableColumn tableColumn = getTableColumnByName((String) aIFIdentifier.getColumnId()); + if (aIFIdentifier.getClientData() != null) { + Integer integer = (Integer) aIFIdentifier.getClientData(); + tableColumn.setPreferredWidth(integer.intValue()); + } + } + JPanel jPanel4 = new JPanel(new ButtonLayout()); + this.openButton = new JButton(this.appReg.getString("open")); + this.openButton.setMnemonic(this.appReg.getString("open.MNEMONIC").charAt(0)); + this.openButton.setToolTipText(this.appReg.getString("open.TOOLTIP")); + this.importButton = new JButton(this.appReg.getString("importbutton")); + this.importButton.setMnemonic(this.appReg.getString("import.MNEMONIC").charAt(0)); + this.importButton.setToolTipText(this.appReg.getString("import.TOOLTIP")); + this.exportButton = new JButton(this.appReg.getString("exportbutton")); + this.exportButton.setMnemonic(this.appReg.getString("export.MNEMONIC").charAt(0)); + this.exportButton.setToolTipText(this.appReg.getString("export.TOOLTIP")); + jPanel4.add(this.openButton); + jPanel4.add(this.importButton); + jPanel4.add(this.exportButton); + JPanel jPanel5 = new JPanel(new HorizontalLayout()); + this.cutButton = new JButton(this.appReg.getImageIcon("cut.ICON")); + this.cutButton.setFocusPainted(false); + this.cutButton.setMargin(new Insets(0, 0, 0, 0)); + this.cutButton.setToolTipText(this.appReg.getString("cut.TOOLTIP")); + this.copyButton = new JButton(this.appReg.getImageIcon("copy.ICON")); + this.copyButton.setFocusPainted(false); + this.copyButton.setMargin(new Insets(0, 0, 0, 0)); + this.copyButton.setToolTipText(this.appReg.getString("copy.TOOLTIP")); + this.pasteButton = new JButton(this.appReg.getImageIcon("paste.ICON")); + this.pasteButton.setFocusPainted(false); + this.pasteButton.setMargin(new Insets(0, 0, 0, 0)); + this.pasteButton.setToolTipText(this.appReg.getString("paste.TOOLTIP")); + this.deleteButton = new JButton(this.appReg.getImageIcon("delete.ICON")); + this.deleteButton.setFocusPainted(false); + this.deleteButton.setMargin(new Insets(0, 0, 0, 0)); + this.deleteButton.setToolTipText(this.appReg.getString("remove.TOOLTIP")); + jPanel5.add("right.nobind.center.center", this.deleteButton); + jPanel5.add("right.nobind.center.center", this.pasteButton); + jPanel5.add("right.nobind.center.center", this.copyButton); + jPanel5.add("right.nobind.center.center", this.cutButton); + jPanel2.add("left.nobind.left.center", jPanel4); + jPanel2.add("right.nobind.right.center", jPanel5); + JButton jButton = new JButton(this.appReg.getString("close")); + jButton.setMnemonic(this.appReg.getString("close.MNEMONIC").charAt(0)); + jPanel3.add(jButton); + JLabel jLabel1 = new JLabel(this.appReg.getImageIcon("namedreferences.ICON"), 0); + JLabel jLabel2 = new JLabel(this.appReg.getImageIcon("modeless.ICON")); + jLabel2.setToolTipText(this.appReg.getString("modeless.TOOLTIP")); + String str = allowedNameReferenceModification() ? "" : this.appReg.getString("CheckoutNamedRef.INFOMESSAGE"); + JLabel jLabel3 = new JLabel(str, 0); + JPanel jPanel6 = new JPanel(new HorizontalLayout(2, 0, 0, 0, 0)); + jPanel6.add("left", jLabel1); + jPanel6.add("left", jLabel3); + jPanel6.add("right", jLabel2); + jPanel1.add("top", jPanel6); + jPanel1.add("top.bind", new Separator()); + jPanel1.add("bottom.bind.center.top", jPanel3); + jPanel1.add("bottom.bind", new Separator()); + jPanel1.add("bottom.bind", jPanel2); + jPanel1.add("unbound.bind.center.top", this.tableScrollPane); + this.importButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent param1ActionEvent) { + NamedReferencesDialog.this.startImportFilesOperation(); + } + }); + this.exportButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent param1ActionEvent) { + NamedReferencesDialog.this.startExportFilesOperation(); + } + }); + this.openButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent param1ActionEvent) { + NamedReferencesDialog.this.startOpenFileOperation(); + } + }); + this.copyButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent param1ActionEvent) { + NamedReferencesDialog.this.startCopyOperation(); + } + }); + this.cutButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent param1ActionEvent) { + NamedReferencesDialog.this.startCutNamedRefOperation(); + } + }); + this.pasteButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent param1ActionEvent) { + NamedReferencesDialog.this.startPasteOperation(); + } + }); + this.deleteButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent param1ActionEvent) { + NamedReferencesDialog.this.startDeleteNamedRefOperation(); + } + }); + jButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent param1ActionEvent) { + NamedReferencesDialog.this.closePressed(); + } + }); + pack(); + centerToScreen(1.5D, 1.0D); + jButton.requestFocusInWindow(); + AbstractAIFOperation abstractAIFOperation = new AbstractAIFOperation() { + @Override + public void executeOperation() { + ArrayList arrayList = new ArrayList(); + arrayList.add(NamedReferencesDialog.this.datasetComponent); + TCComponentType.refresh(arrayList); + } + }; + abstractAIFOperation.addOperationListener(new InterfaceAIFOperationListener() { + @Override + public void startOperation(String param1String) { + } + + @Override + public void endOperation() { + NamedReferencesDialog.this.loadNamedReferences(); + } + }); + this.session.queueOperation(abstractAIFOperation); + this.session.addAIFComponentEventListener(this); + validateButtons(); + this.table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent param1ListSelectionEvent) { + NamedReferencesDialog.this.validateButtons(); + } + }); + this.table.addKeyListener(new KeyListener() { + @Override + public void keyTyped(KeyEvent param1KeyEvent) { + } + + @Override + public void keyReleased(KeyEvent param1KeyEvent) { + } + + @Override + public void keyPressed(KeyEvent param1KeyEvent) { + if (param1KeyEvent.isControlDown() && param1KeyEvent.getKeyCode() == 67) { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringBuilder stringBuilder = new StringBuilder(); + int[] arrayOfInt1 = NamedReferencesDialog.this.table.getSelectedRows(); + int i = NamedReferencesDialog.this.table.getColumnCount(); + int[] arrayOfInt2; + arrayOfInt2 = arrayOfInt1; + int j = arrayOfInt1.length; + for (byte b = 0; b < j; b++) { + int k = arrayOfInt2[b]; + for (byte b1 = 0; b1 < i; b1++) { + String str = String.valueOf(NamedReferencesDialog.this.table.getModel().getValueAt(k, b1)); + stringBuilder.append(str).append("\t"); + } + stringBuilder.append("\n"); + } + StringSelection stringSelection = new StringSelection(stringBuilder.toString()); + clipboard.setContents(stringSelection, null); + } + } + }); + } + + @Override + public void run() { + setVisible(true); + } + + public void closePressed() { + this.session.removeAIFComponentEventListener(this); + TableColumnModel tableColumnModel = this.table.getColumnModel(); + int i = tableColumnModel.getColumnCount(); + String[] arrayOfString1 = new String[i]; + String[] arrayOfString2 = new String[i]; + AIFIdentifier[] arrayOfAIFIdentifier = this.model.getColumnIdentifiers(); + for (byte b = 0; b < i; b++) { + TableColumn tableColumn = tableColumnModel.getColumn(b); + Integer integer = new Integer(tableColumn.getWidth()); + arrayOfString2[b] = integer.toString(); + arrayOfString1[b] = getPropertyName(this.table.getColumnName(b), arrayOfAIFIdentifier); + } + try { + Cookie cookie = Cookie.getCookie("namedreference", true); + cookie.setStringArray("columnname", arrayOfString1); + cookie.setStringArray("columnwidth", arrayOfString2); + cookie.close(); + } catch (Exception exception) { + } + disposeDialog(); + } + + private String getPropertyName(String paramString, AIFIdentifier[] paramArrayOfAIFIdentifier) { + String str = ""; + if (paramArrayOfAIFIdentifier != null) { + AIFIdentifier[] arrayOfAIFIdentifier; + arrayOfAIFIdentifier = paramArrayOfAIFIdentifier; + int i = paramArrayOfAIFIdentifier.length; + for (byte b = 0; b < i; b++) { + AIFIdentifier aIFIdentifier = arrayOfAIFIdentifier[b]; + if (aIFIdentifier.getColumnName().equals(paramString)) { + str = (String) aIFIdentifier.getColumnId(); + break; + } + } + } + return str; + } + + private TableColumn getTableColumnByName(String paramString) { + byte b1 = 0; + AIFIdentifier[] arrayOfAIFIdentifier = this.model.getColumnIdentifiers(); + for (byte b2 = 0; b2 < arrayOfAIFIdentifier.length; b2++) { + if (paramString.equals(arrayOfAIFIdentifier[b2].getColumnId())) { + b1 = b2; + break; + } + } + return this.table.getColumnModel().getColumn(b1); + } + + private int[] checkTableSelection(boolean paramBoolean1, boolean paramBoolean2) { + int[] arrayOfInt = this.table.getSelectedRows(); + if (arrayOfInt == null || arrayOfInt.length == 0) { + if (paramBoolean2) + MessageBox.post(this.parent, this.appReg.getString("noSelection"), + this.appReg.getString("warning.TITLE"), 4); + return null; + } + if (!paramBoolean1 && arrayOfInt.length > 1) { + if (paramBoolean2) + MessageBox.post(this.parent, this.appReg.getString("noMultipleSelection"), + this.appReg.getString("warning.TITLE"), 4); + return null; + } + return arrayOfInt; + } + + private void startExportFilesOperation() { + if (Debug.isOn("dataset,export")) + Debug.println("==> startExportFilesOperation"); + int[] arrayOfInt = checkTableSelection(true, true); + if (arrayOfInt == null) + return; + int i = arrayOfInt.length; + Vector vector = new Vector(); + TCComponent tCComponent = null; + for (byte b = 0; b < i; b++) { + tCComponent = this.model.getComponentAt(arrayOfInt[b]); + if (tCComponent instanceof TCComponentTcFile) { + vector.addElement(tCComponent); + final TCComponentTcFile tcFile = (TCComponentTcFile) tCComponent; + + // jd + boolean flag = true; + try { + TCSession tcSession = (TCSession) this.session; + TCPreferenceService service = tcSession.getPreferenceService(); + String[] pref = service.getStringValues("jd_dataset_download"); + String[] pref2 = service.getStringValues("jd_wl_type_classify"); + Map> typeClassify = new HashMap>(); + List list = new ArrayList(); + if (pref != null && pref.length > 0) { + System.out.println("ѡ===>" + Arrays.toString(pref)); + list = Arrays.asList(pref); + } + if (pref2 != null && pref2.length > 0) { + System.out.println("ѡ2===>" + Arrays.toString(pref2)); + for (String str : pref2) { + String[] row = str.split(":"); + typeClassify.put(row[0], Arrays.asList(row[1].split(","))); + } + } + AIFComponentContext[] parents = tcFile.whereReferenced(); + L1: for (AIFComponentContext aif : parents) { + TCComponentDataset dataset = (TCComponentDataset) aif.getComponent(); + System.out.println(dataset.getProperty("object_string")); + System.out.println(dataset.getType()); + if (list.contains(dataset.getType())) { + flag = false; + String currentUser = tcSession.getUser().getProperty("object_string"); + String owningUser = dataset.getProperty("owning_user"); + System.out.println("currentUser===>" + currentUser + ",owningUser===>" + owningUser); + if (currentUser.equals(owningUser)) { + System.out.println(""); + flag = true; + break; + } + String loginGroup = tcSession.getUser().getProperty("login_group"); + System.out.println("loginGroup===>" + loginGroup); + if (loginGroup.contains("dba")) { + System.out.println("dba"); + flag = true; + break; + } + AIFComponentContext[] revs = dataset.whereReferenced(); + for (AIFComponentContext aif1 : revs) { + if (aif1.getComponent() != null + && (aif1.getComponent() instanceof TCComponentItemRevision)) { + String type = aif1.getComponent().getType(); + System.out.println("===>" + type); + if ((loginGroup.contains("зһ") && typeClassify.get("GT") != null + && typeClassify.get("GT").contains(type)) + || (loginGroup.contains("з") && typeClassify.get("BL") != null + && typeClassify.get("BL").contains(type)) + || (loginGroup.contains("з岿") && typeClassify.get("BX") != null + && typeClassify.get("BX").contains(type))) { + System.out.println(""); + flag = true; + break L1; + } + } + } + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + logger.error(e.getLocalizedMessage(), e); + e.printStackTrace(); + } + if (!flag) { + MessageBox.post(this.parent, "", "ʾ", MessageBox.WARNING); + return; + } + + if (this.exportFc == null) { + this.exportFc = new JFileChooser(getDefaultExportDirectory()); + this.exportFc.setFileSelectionMode(0); + this.exportFc.setApproveButtonText(this.appReg.getString("export")); + } + this.exportFc.rescanCurrentDirectory(); + String str1 = null; + try { + str1 = tcFile.getProperty("original_file_name"); + } catch (TCException tCException) { + logger.error(tCException.getLocalizedMessage(), tCException); + return; + } + this.exportFc.setDialogTitle( + String.valueOf(this.appReg.getString("exportFile.TITLE")) + " " + str1 + " ... "); + File file1 = this.exportFc.getCurrentDirectory(); + String str2 = String.valueOf(file1.getAbsolutePath()) + File.separator + str1; + File file2 = new File(str2); + int j = str1.lastIndexOf('.'); + String str3 = null; + if (j == -1) { + str3 = str1; + } else { + str3 = str1.substring(0, j); + } + if (Debug.isOn("dataset,export")) + Debug.println("Processing TCComponentTcFile [" + tcFile + "] defaultFileLocation [" + str2 + + "], file name [" + str1 + "] absFileName [" + str3 + "]"); + try { + TCPreferenceService tCPreferenceService = ((TCSession) this.session).getPreferenceService(); + String str = tCPreferenceService.getString(0, "Dataset_File_Export_Option"); + if (Debug.isOn("dataset,export")) + Debug.println("Pref [Dataset_File_Export_Option] value [" + str + "]"); + if (str != null && str.length() > 0) + if (str.equalsIgnoreCase("LOWERCASE")) { + file2 = new File(String.valueOf(file1.getAbsolutePath()) + File.separator + + str3.toLowerCase() + str1.substring(j)); + } else if (str.equalsIgnoreCase("UPPERCASE")) { + file2 = new File(String.valueOf(file1.getAbsolutePath()) + File.separator + + str3.toUpperCase() + str1.substring(j)); + } + } catch (Exception exception) { + if (Debug.isOn("dataset,export")) + Debug.printStackTrace(exception); + } + this.exportFc.setSelectedFile(file2); + if (Debug.isOn("dataset,export")) + Debug.println("setSelectedFile [" + file2.getName() + "]"); + File file3 = null; + Frame frame = Utilities.getCurrentFrame(); + if (this.exportFc.showOpenDialog(frame) == 0) + for (file3 = this.exportFc.getSelectedFile(); file3 != null && file3.exists(); file3 = null) { + if (ConfirmationDialog.post(frame, this.appReg.getString("fileExist.TITLE"), + this.appReg.getString("fileExists")) == 2) { + if (Debug.isOn("dataset,export")) + Debug.println("Deleting [" + file3.getName() + "]"); + if (!file3.delete()) { + MessageBox.post(this.appReg.getString("exportFailure.MESSAGE"), + this.appReg.getString("exportFailure.TITLE"), 4); + file3 = null; + } + continue; + } + if (this.exportFc.showOpenDialog(frame) == 0) { + file3 = this.exportFc.getSelectedFile(); + continue; + } + } + if (Debug.isOn("dataset,export")) + Debug.println("getSelectedFile [" + file3.getName() + "]"); + if (file3 != null) { + final File realDirFile = file3; + Utilities.setCookie("filechooser", true, "DatasetExport.DIR", realDirFile.getParent()); + this.session.queueOperation(new AbstractAIFOperation( + String.valueOf(this.appReg.getString("exportingFiles")) + tcFile + " ... ") { + @Override + public void executeOperation() { + NamedReferencesDialog.this.executeExportOperation(tcFile, realDirFile); + } + }); + } + } + } + if (vector.isEmpty()) { + MessageBox.post(this.parent, this.appReg.getString("noValidExportSelection"), + this.appReg.getString("warning.TITLE"), 4); + return; + } + } + + protected void executeExportOperation(TCComponentTcFile paramTCComponentTcFile, File paramFile) { + try { + if (Debug.isOn("dataset,export")) + Debug.println("getSelectedFile [" + paramFile.getName() + "] parent [[" + paramFile.getParent() + "]"); + paramTCComponentTcFile.getFile(this.datasetComponent, paramFile.getParent(), paramFile.getName()); + } catch (Exception exception) { + if (Debug.isOn("dataset,export")) + Debug.printStackTrace(exception); + MessageBox.post(this.parent, exception); + } + } + + private void startImportFilesOperation() { + TCComponentDatasetDefinition tCComponentDatasetDefinition = null; + NamedReferenceContext[] arrayOfNamedReferenceContext = null; + try { + tCComponentDatasetDefinition = this.datasetComponent.getDatasetDefinitionComponent(); + arrayOfNamedReferenceContext = tCComponentDatasetDefinition.getNamedReferenceContexts(); + } catch (Exception exception) { + MessageBox.post(this.parent, exception); + } + if (arrayOfNamedReferenceContext == null || arrayOfNamedReferenceContext.length == 0) { + MessageBox.post(this.parent, this.appReg.getString("noRefTypeFound"), + this.appReg.getString("warning.TITLE"), 4); + return; + } + Frame frame = Utilities.getCurrentFrame(); + TCFileSelectorService tCFileSelectorService = TCFileSelectorService.getInstance(); + IFilesSelector iFilesSelector = tCFileSelectorService.getFileSelector(); + if (iFilesSelector == null) { + ImportFilesFileChooser importFilesFileChooser = new ImportFilesFileChooser(tCComponentDatasetDefinition, + frame); + int i = importFilesFileChooser.showDialog(frame, null); + if (i == 0) { + final File f = importFilesFileChooser.getSelectedFile(); + if (f != null) { + String str1 = f.getAbsolutePath(); + final String type = importFilesFileChooser.getType(); + final String ref = importFilesFileChooser.getReferenceType(); + Registry registry = Registry.getRegistry(this); + if (!DatasetUtil.isValidFileForUpload(tCComponentDatasetDefinition, str1)) { + MessageBox.post(this.parent, registry.getString("invalidFile.MSG"), + registry.getString("warning.TITLE"), 4); + return; + } + Utilities.setCookie("filechooser", true, "DatasetImport.DIR", f.getParent()); + if (this.truncateFileName.equalsIgnoreCase("TRUE")) { + byte b = 30; + if (f.getName().length() > b) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + String str = NamedReferencesDialog.this.appReg.getString("fileNameTruncated"); + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + int i = ConfirmDialog.prompt(shell, + NamedReferencesDialog.this.appReg.getString("warning.TITLE"), str); + if (i == 2) + NamedReferencesDialog.this.executeImportOperation(f, type, ref); + } + }); + } else { + executeImportOperation(f, type, ref); + } + } else { + char c = '„'; + if (f.getName().length() > c) { + StringBuffer stringBuffer = (new StringBuffer( + this.appReg.getString("fileNameLengthTooLong"))).append(" (").append(c) + .append(")."); + MessageBox.post(this.parent, stringBuffer.toString(), + this.appReg.getString("warning.TITLE"), 4); + } else { + executeImportOperation(f, type, ref); + } + } + } else { + MessageBox.post(this.parent, this.appReg.getString("noImportFileSelection"), + this.appReg.getString("warning.TITLE"), 4); + } + } + } else { + try { + logger.debug("Delegating file selection to extensionPointImplementation class: " + + iFilesSelector.getClass()); + iFilesSelector.initialize(tCComponentDatasetDefinition, null, null); + List list = iFilesSelector.getSelectedFiles(); + if (list != null && !list.isEmpty()) { + logger.debug("File descriptor information for files selected by custom code"); + for (TCFileDescriptor tCFileDescriptor1 : list) + logger.debug(tCFileDescriptor1); + TCFileDescriptor tCFileDescriptor = list.get(0); + if (tCFileDescriptor != null) { + final File f = tCFileDescriptor.getFile(); + if (f != null) { + Utilities.setCookie("filechooser", true, "DatasetImport.DIR", f.getParent()); + } else { + logger.error("File object in TCFileDescriptor return by custom code is null"); + } + } else { + logger.error( + "TCFileDescriptor object in List returned by custom code is null"); + } + } else { + logger.debug( + "Custom code did not return any information about selected files. Looks like user has not selected any files"); + if (list == null) { + logger.debug("getSelectedFiles returned null"); + } else { + logger.debug("getSelectedFiles returned empty list"); + } + } + ImportFilesOperation importFilesOperation = new ImportFilesOperation(this.datasetComponent, + iFilesSelector, null, Utilities.getCurrentFrame()); + this.session.queueOperation(importFilesOperation); + } catch (Exception exception) { + MessageBox messageBox = new MessageBox(this.parent, exception); + messageBox.setModal(true); + messageBox.setVisible(true); + return; + } + } + } + + protected void executeImportOperation(File paramFile, String paramString1, String paramString2) { + ImportFilesOperation importFilesOperation = new ImportFilesOperation(this.datasetComponent, paramFile, + paramString1, null, paramString2, Utilities.getCurrentFrame()); + this.session.queueOperation(importFilesOperation); + } + + private void startOpenFileOperation() { + int[] arrayOfInt = checkTableSelection(false, true); + if (arrayOfInt == null) + return; + Registry registry = Registry.getRegistry("com.teamcenter.rac.common.actions.actions"); + TCComponent tCComponent = this.model.getComponentAt(arrayOfInt[0]); + if (tCComponent instanceof TCComponentTcFile) { + String str1 = (String) this.model.getValueAt(arrayOfInt[0], "object_name"); + if (this.selectedToolComponent == null) + return; + String str2 = (String) this.model.getValueAt(arrayOfInt[0], "original_file_name"); + AbstractAIFCommand abstractAIFCommand = (AbstractAIFCommand) registry.newInstanceFor("openAsCommand", + new Object[] { this.datasetComponent, this.selectedToolComponent, str2, + Utilities.getParentFrame(this) }); + abstractAIFCommand.executeModeless(); + } else if (tCComponent != null) { + AIFDesktop aIFDesktop = AIFUtility.getActiveDesktop(); + AbstractAIFCommand abstractAIFCommand = (AbstractAIFCommand) registry.newInstanceFor("openCommand", + new Object[] { aIFDesktop, tCComponent }); + abstractAIFCommand.executeModeless(); + } + } + + private void startCutNamedRefOperation() { + int[] arrayOfInt1 = checkTableSelection(true, true); + if (arrayOfInt1 == null) + return; + ArrayList arrayList1 = new ArrayList(); + ArrayList arrayList2 = new ArrayList(); + ArrayList arrayList3 = new ArrayList(); + ArrayList arrayList4 = new ArrayList(); + int[] arrayOfInt2; + arrayOfInt2 = arrayOfInt1; + int i = arrayOfInt1.length; + for (byte b = 0; b < i; b++) { + int j = arrayOfInt2[b]; + TCComponent tCComponent = this.model.getComponentAt(j); + if (tCComponent instanceof TCComponentTcFile) { + arrayList1.add(tCComponent); + String str1 = (String) this.model.getValueAt(j, "object_name"); + String str2 = (String) this.model.getValueAt(j, "original_file_name"); + arrayList2.add(str1); + arrayList3.add(str2); + } else { + String str = this.model.getNamedRefType(tCComponent); + if (str == null) { + MessageBox.post(this.parent, + String.valueOf(this.appReg.getString("cannotCut")) + " " + tCComponent.toString(), + this.appReg.getString("warning.TITLE"), 4); + } else { + arrayList1.add(tCComponent); + arrayList4.add(str); + } + } + } + if (!arrayList1.isEmpty()) { + int j = arrayList1.size(); + InterfaceAIFComponent[] arrayOfInterfaceAIFComponent = (InterfaceAIFComponent[]) arrayList1 + .toArray(new InterfaceAIFComponent[j]); + Registry registry = Registry.getRegistry("com.teamcenter.rac.common.actions.actions"); + AbstractAIFCommand abstractAIFCommand = (AbstractAIFCommand) registry.newInstanceFor("copyCommand", + new Object[] { arrayOfInterfaceAIFComponent }); + abstractAIFCommand.executeModeless(); + } + try { + sourceClassificationString = this.datasetComponent.getProperties(this.prop); + } catch (TCException tCException) { + MessageBox.post(this.parent, tCException); + } + if (!arrayList2.isEmpty()) { + int j = arrayList2.size(); + String[] arrayOfString1 = (String[]) arrayList2.toArray(new String[j]); + String[] arrayOfString2 = (String[]) arrayList3.toArray(new String[j]); + RemoveNamedRefOperation removeNamedRefOperation = new RemoveNamedRefOperation(this.datasetComponent, + arrayOfString1, arrayOfString2, Utilities.getCurrentFrame()); + this.session.queueOperation(removeNamedRefOperation); + } + if (!arrayList4.isEmpty()) { + int j = arrayList4.size(); + String[] arrayOfString = (String[]) arrayList4.toArray(new String[j]); + RemoveNamedRefOperation removeNamedRefOperation = new RemoveNamedRefOperation(this.datasetComponent, + arrayOfString, Utilities.getCurrentFrame()); + this.session.queueOperation(removeNamedRefOperation); + } + } + + private void startDeleteNamedRefOperation() { + int[] arrayOfInt1 = checkTableSelection(true, true); + if (arrayOfInt1 == null) + return; + if (ConfirmationDialog.post((Frame) this.parent, this.appReg.getString("delete.TITLE"), + this.appReg.getString("delete")) != 2) + return; + ArrayList arrayList1 = new ArrayList(); + ArrayList arrayList2 = new ArrayList(); + ArrayList arrayList3 = new ArrayList(); + ArrayList arrayList4 = new ArrayList(); + int[] arrayOfInt2; + arrayOfInt2 = arrayOfInt1; + int i = arrayOfInt1.length; + for (byte b = 0; b < i; b++) { + int j = arrayOfInt2[b]; + TCComponent tCComponent = this.model.getComponentAt(j); + if (tCComponent instanceof TCComponentTcFile) { + arrayList1.add(tCComponent); + String str1 = (String) this.model.getValueAt(j, "object_name"); + String str2 = (String) this.model.getValueAt(j, "original_file_name"); + arrayList2.add(str1); + arrayList3.add(str2); + } else { + String str = this.model.getNamedRefType(tCComponent); + if (str == null) { + MessageBox.post(this.parent, + String.valueOf(this.appReg.getString("cannotDelete")) + " " + tCComponent.toString(), + this.appReg.getString("warning.TITLE"), 4); + } else { + arrayList1.add(tCComponent); + arrayList4.add(str); + } + } + } + if (!arrayList2.isEmpty()) { + arrayList3.add(":::::::::://////////\\\\\\\\\\"); + arrayList2.add(":::::::::://////////\\\\\\\\\\"); + int j = arrayList2.size(); + String[] arrayOfString1 = (String[]) arrayList2.toArray(new String[j]); + String[] arrayOfString2 = (String[]) arrayList3.toArray(new String[j]); + RemoveNamedRefOperation removeNamedRefOperation = new RemoveNamedRefOperation(this.datasetComponent, + arrayOfString1, arrayOfString2, Utilities.getCurrentFrame()); + this.session.queueOperation(removeNamedRefOperation); + } + if (!arrayList4.isEmpty()) { + int j = arrayList4.size(); + String[] arrayOfString = (String[]) arrayList4.toArray(new String[j]); + RemoveNamedRefOperation removeNamedRefOperation = new RemoveNamedRefOperation(this.datasetComponent, + arrayOfString, Utilities.getCurrentFrame()); + this.session.queueOperation(removeNamedRefOperation); + } + } + + private void startCopyOperation() { + int[] arrayOfInt = checkTableSelection(true, true); + if (arrayOfInt == null) + return; + int i = arrayOfInt.length; + TCComponent[] arrayOfTCComponent = new TCComponent[i]; + for (byte b = 0; b < i; b++) { + arrayOfTCComponent[b] = this.model.getComponentAt(arrayOfInt[b]); + arrayOfTCComponent[b].setClientObject(this.model.getValueAt(arrayOfInt[b], "object_name")); + } + try { + sourceClassificationString = this.datasetComponent.getProperties(this.prop); + } catch (TCException b) { + TCException tCException; + MessageBox.post(this.parent, b); + } + Registry registry = Registry.getRegistry("com.teamcenter.rac.common.actions.actions"); + AbstractAIFCommand abstractAIFCommand = (AbstractAIFCommand) registry.newInstanceFor("copyCommand", + new Object[] { arrayOfTCComponent }); + abstractAIFCommand.executeModeless(); + } + + private void startPasteOperation() { + AIFClipboard aIFClipboard = AIFPortal.getClipboard(); + Transferable transferable = aIFClipboard.getContents(this); + if (transferable == null) { + MessageBox.post(this.parent, this.appReg.getString("clipboardEmpty"), + this.appReg.getString("warning.TITLE"), 4); + return; + } + Vector vector1 = new Vector(); + try { + vector1 = (Vector) transferable.getTransferData(new DataFlavor(Vector.class, "AIF Vector")); + } catch (Exception exception) { + MessageBox.post(this.parent, exception); + return; + } + if (vector1 == null || vector1.isEmpty()) { + MessageBox.post(this.parent, this.appReg.getString("clipboardEmpty"), + this.appReg.getString("warning.TITLE"), 4); + return; + } + Vector vector2 = new Vector(); + for (byte b = 0; b < vector1.size(); b++) { + if (vector1.elementAt(b) instanceof TCComponent) + vector2.addElement(vector1.elementAt(b)); + } + try { + destClassificationString = this.datasetComponent.getProperties(this.prop); + } catch (TCException b) { + TCException tCException; + MessageBox.post(this.parent, b); + } + if (sourceClassificationString != null && destClassificationString != null + && (!sourceClassificationString[0].equals(destClassificationString[0]) + || !sourceClassificationString[1].equals(destClassificationString[1]))) { + MessageBox.post(this.parent, this.appReg.getString("incorrectClassification"), + this.appReg.getString("error.TITLE"), 1); + return; + } + if (vector2.isEmpty()) { + MessageBox.post(this.parent, this.appReg.getString("cannotPaste"), this.appReg.getString("warning.TITLE"), + 4); + return; + } + TCComponent[] arrayOfTCComponent = (TCComponent[]) vector2.toArray(new TCComponent[vector2.size()]); + PasteNamedReferencesDialog pasteNamedReferencesDialog = new PasteNamedReferencesDialog(this.datasetComponent, + arrayOfTCComponent, Utilities.getCurrentFrame()); + pasteNamedReferencesDialog.setVisible(true); + } + + private void startModifyFileName(TCComponent paramTCComponent, String paramString) { + if (paramTCComponent == null || paramString == null || paramString.length() == 0) + return; + try { + String str = paramTCComponent.getProperty("original_file_name"); + if (str.equals(paramString)) + return; + if (paramTCComponent instanceof TCComponentTcFile) { + TCComponentTcFile tCComponentTcFile = (TCComponentTcFile) paramTCComponent; + tCComponentTcFile.setOriginalFileName(this.datasetComponent, paramString); + } else { + paramTCComponent.setProperty("object_name", paramString); + paramTCComponent.firePropertyChangeEvent("object_name"); + } + } catch (TCException tCException) { + MessageBox.post(this.parent, tCException); + } + } + + private void loadNamedReferences() { + String str = String.valueOf(this.appReg.getString("loadingNamedRef")) + this.datasetComponent.toString(); + this.session.queueOperation(new AbstractAIFOperation(str) { + @Override + public void executeOperation() { + TCComponent[] arrayOfTCComponent1; + NamedReferencesDialog.this.tableScrollPane.setCursor(Cursor.getPredefinedCursor(3)); + try { + arrayOfTCComponent1 = NamedReferencesDialog.this.datasetComponent.getNamedReferences(); + for (byte b = 0; b < arrayOfTCComponent1.length; b++) + arrayOfTCComponent1[b].clearCache(); + } catch (TCException tCException) { + MessageBox.post(NamedReferencesDialog.this.parent, tCException); + NamedReferencesDialog.this.tableScrollPane.setCursor(Cursor.getPredefinedCursor(0)); + return; + } + if (arrayOfTCComponent1.length == 0) { + NamedReferencesDialog.this.tableScrollPane.setCursor(Cursor.getPredefinedCursor(0)); + return; + } + final TCComponent[] namedRefsArray = arrayOfTCComponent1; + Utilities.invokeLater(new Runnable() { + @Override + public void run() { + try { + NamedReferencesDialog.this.model.removeAllRows(); + TCComponent[] arrayOfTCComponent; + arrayOfTCComponent = namedRefsArray; + int i = namedRefsArray.length; + for (byte b = 0; b < i; b++) { + TCComponent tCComponent = arrayOfTCComponent[b]; + NamedReferencesDialog.this.model.addRow(tCComponent); + } + } catch (Exception exception) { + MessageBox.post(NamedReferencesDialog.this.parent, exception); + } + NamedReferencesDialog.this.tableScrollPane.setCursor(Cursor.getPredefinedCursor(0)); + NamedReferencesDialog.this.tableScrollPane.validate(); + NamedReferencesDialog.this.tableScrollPane.repaint(); + NamedReferencesDialog.this.table.validate(); + NamedReferencesDialog.this.table.repaint(); + } + }); + } + }); + } + + @Override + public void processComponentEvents(AIFComponentEvent[] paramArrayOfAIFComponentEvent) { + AIFComponentEvent[] arrayOfAIFComponentEvent; + arrayOfAIFComponentEvent = paramArrayOfAIFComponentEvent; + int i = paramArrayOfAIFComponentEvent.length; + for (byte b = 0; b < i; b++) { + AIFComponentEvent aIFComponentEvent = arrayOfAIFComponentEvent[b]; + if (aIFComponentEvent instanceof com.teamcenter.rac.aif.kernel.AIFComponentChangeEvent) { + TCComponent tCComponent = (TCComponent) aIFComponentEvent.getComponent(); + if (tCComponent instanceof TCComponentDataset) { + TCComponentDataset tCComponentDataset = (TCComponentDataset) tCComponent; + if (tCComponentDataset == this.datasetComponent) { + Utilities.invokeLater(new Runnable() { + @Override + public void run() { + NamedReferencesDialog.this.model.removeAllRows(); + } + }); + loadNamedReferences(); + break; + } + } + } + } + } + + protected String getDefaultExportDirectory() { + String str = Utilities.getCookie("filechooser", "DatasetExport.DIR", true); + if (str == null || str.length() == 0) { + TCPreferenceService tCPreferenceService = ((TCSession) this.session).getPreferenceService(); + str = tCPreferenceService.getString(0, "defaultExportDirectory"); + } + if (str != null) { + str = str.trim(); + if (str.length() == 0) + str = null; + } + return str; + } + + private void validateButtons() { + boolean bool = !this.table.getSelectionModel().isSelectionEmpty(); + AIFClipboard aIFClipboard = AIFPortal.getClipboard(); + Transferable transferable = aIFClipboard.getContents(this); + this.copyButton.setEnabled(bool); + this.exportButton.setEnabled(bool); + this.openButton.setEnabled(bool); + this.cutButton.setEnabled((allowedNameReferenceModification() && bool)); + this.deleteButton.setEnabled((allowedNameReferenceModification() && bool)); + this.pasteButton.setEnabled((allowedNameReferenceModification() && transferable != null)); + this.importButton.setEnabled(allowedNameReferenceModification()); + try { + if (this.datasetComponent.isTypeOf("FullText")) { + this.deleteButton.setEnabled(false); + this.cutButton.setEnabled(false); + this.importButton.setEnabled(false); + this.pasteButton.setEnabled(false); + } + } catch (Exception exception) { + MessageBox.post(this.parent, exception); + } + } + + private boolean allowedNameReferenceModification() { + ViewEditHelper viewEditHelper = new ViewEditHelper(this.datasetComponent.getSession()); + return !(!viewEditHelper.isImplicitlyCheckoutable() && !this.datasetComponent.isCheckedOut()); + } + + private class NamedReferencesTableModel extends DefaultTableModel { + private Vector compVector = new Vector(); + + private AIFIdentifier[] identifiers = null; + + private Hashtable osLastModifiedDateTable = new Hashtable(); + + public NamedReferencesTableModel(String[] param1ArrayOfString) { + Registry registry = Registry.getRegistry(this); + String[] arrayOfString1 = null; + String[] arrayOfString2 = null; + try { + Cookie cookie = Cookie.getCookie("namedreference", true); + arrayOfString1 = cookie.getStringArray("columnname"); + arrayOfString2 = cookie.getStringArray("columnwidth"); + cookie.close(); + } catch (Exception exception) { + } + if (arrayOfString1 == null || arrayOfString1.length == 0) { + int j = 7; + if (param1ArrayOfString != null && param1ArrayOfString.length > 0) + j = 7 + param1ArrayOfString.length; + arrayOfString1 = new String[j]; + arrayOfString1[0] = "object_name"; + arrayOfString1[1] = "original_file_name"; + arrayOfString1[2] = "file_size"; + arrayOfString1[3] = "owning_site"; + arrayOfString1[4] = "object_type"; + arrayOfString1[5] = "last_mod_date"; + arrayOfString1[6] = "volume_tag"; + if (param1ArrayOfString != null && param1ArrayOfString.length > 0) + for (byte b1 = 0; b1 < param1ArrayOfString.length; b1++) + arrayOfString1[b1 + 7] = param1ArrayOfString[b1]; + } else if (param1ArrayOfString != null && param1ArrayOfString.length > 0) { + Vector vector = Utilities.convertArrayToVector(arrayOfString1); + String[] arrayOfString; + arrayOfString = param1ArrayOfString; + int j = param1ArrayOfString.length; + for (byte b1 = 0; b1 < j; b1++) { + String str = arrayOfString[b1]; + if (!vector.contains(str)) + vector.add(str); + } + arrayOfString1 = (String[]) vector.toArray(new String[vector.size()]); + } + int i = arrayOfString1.length; + Integer[] arrayOfInteger = new Integer[i]; + if (arrayOfString2 == null || arrayOfString2.length == 0) { + for (byte b1 = 0; b1 < i; b1++) + arrayOfInteger[b1] = null; + } else { + for (byte b1 = 0; b1 < i; b1++) { + if (b1 < arrayOfString2.length) { + arrayOfInteger[b1] = new Integer(arrayOfString2[b1]); + } else { + arrayOfInteger[b1] = null; + } + } + } + this.identifiers = new AIFIdentifier[i]; + for (byte b = 0; b < i; b++) { + String str = String.valueOf(arrayOfString1[b]) + ".NAME"; + this.identifiers[b] = new AIFIdentifier(registry.getString(str, arrayOfString1[b]), arrayOfString1[b]); + if (b < arrayOfInteger.length) + this.identifiers[b].setClientData(arrayOfInteger[b]); + } + setColumnIdentifiers(this.identifiers); + } + + public AIFIdentifier[] getColumnIdentifiers() { + return this.identifiers; + } + + @Override + public int getColumnCount() { + return this.identifiers.length; + } + + @Override + public int getRowCount() { + return (this.compVector == null) ? 0 : this.compVector.size(); + } + + @Override + public String getColumnName(int param1Int) { + return (String) this.identifiers[param1Int].getColumnName(); + } + + public Object getValueAt(int param1Int, String param1String) { + String str = ""; + TCComponent tCComponent = getComponentAt(param1Int); + try { + if (param1String.equals("object_name")) { + str = getNamedRefType(tCComponent); + } else if (param1String.equals("original_file_name")) { + if (tCComponent instanceof TCComponentTcFile) { + str = tCComponent.getProperty(param1String); + if (str.isEmpty()) + str = tCComponent.getProperty("object_string"); + } else { + str = tCComponent.getProperty("object_name"); + } + } else if (tCComponent instanceof TCComponentTcFile && param1String.equals("last_mod_date")) { + TCPreferenceService tCPreferenceService = ((TCSession) NamedReferencesDialog.this.session) + .getPreferenceService(); + boolean bool = tCPreferenceService.isTrue(4, "Display_OSFile_LMD_for_TCFile"); + if (Debug.isOn("dataset")) { + Debug.println("Preference [Display_OSFile_LMD_for_TCFile] value [" + bool + "]"); + if (bool) { + Debug.println("Use OSFile LMD for LMD of TCFile [" + tCComponent.toString() + "]"); + } else { + Debug.println("Use LMD of TCFile [" + tCComponent.toString() + "]"); + } + } + if (this.osLastModifiedDateTable.containsKey(tCComponent)) { + str = this.osLastModifiedDateTable.get(tCComponent); + } else { + if (bool) { + str = ((TCComponentTcFile) tCComponent).getOSLastModifiedDate(); + } else { + str = tCComponent.getProperty(param1String); + } + this.osLastModifiedDateTable.put(tCComponent, str); + } + } else { + str = tCComponent.getProperty(param1String); + } + } catch (TCException tCException) { + System.out.println(tCException.toString()); + } + return str; + } + + @Override + public Object getValueAt(int param1Int1, int param1Int2) { + String str = (String) this.identifiers[param1Int2].getColumnId(); + return getValueAt(param1Int1, str); + } + + public TCComponent getComponentAt(int param1Int) { + return this.compVector.elementAt(param1Int); + } + + @Override + public Class getColumnClass(int param1Int) { + return getValueAt(0, param1Int).getClass(); + } + + @Override + public boolean isCellEditable(int param1Int1, int param1Int2) { + boolean bool = false; + String str = (String) this.identifiers[param1Int2].getColumnId(); + TCComponent tCComponent = getComponentAt(param1Int1); + if (str.equals("original_file_name") && tCComponent instanceof TCComponentTcFile) { + IPropertyPolicyService iPropertyPolicyService = (IPropertyPolicyService) OSGIUtil + .getService(Activator.getDefault(), IPropertyPolicyService.class); + try { + if (fileNamePolicy == null) { + ObjectPropertyPolicy objectPropertyPolicy = new ObjectPropertyPolicy(); + objectPropertyPolicy.addType(new PolicyType("ImanFile", new String[] { "original_file_name" }, + new String[] { "includeIsModifiable" })); + fileNamePolicy = iPropertyPolicyService.createPropertyPolicy(objectPropertyPolicy); + } + iPropertyPolicyService.setPropertyPolicy(fileNamePolicy); + TCComponentType.getTCPropertiesViaSOA(tCComponent.getSession(), tCComponent, + new String[] { "original_file_name" }, false); + TCProperty tCProperty = tCComponent.getTCProperty("original_file_name"); + if (tCProperty.isModifiable()) + bool = true; + } catch (TCException tCException) { + logger.error(tCException.getLocalizedMessage(), tCException); + } finally { + iPropertyPolicyService.restorePropertyPolicy(); + } + } + return bool; + } + + @Override + public void setValueAt(Object param1Object, int param1Int1, int param1Int2) { + TCComponent tCComponent = getComponentAt(param1Int1); + NamedReferencesDialog.this.startModifyFileName(tCComponent, (String) param1Object); + fireTableCellUpdated(param1Int1, param1Int2); + } + + @Override + public void removeRow(int param1Int) { + TCComponent tCComponent = getComponentAt(param1Int); + if (this.osLastModifiedDateTable.containsKey(tCComponent)) + this.osLastModifiedDateTable.remove(tCComponent); + this.compVector.removeElementAt(param1Int); + fireTableRowsDeleted(param1Int, param1Int); + } + + public void removeAllRows() { + int i = getRowCount(); + for (byte b = 0; b < i; b++) + removeRow(0); + } + + public void addRow(TCComponent param1TCComponent) { + if (param1TCComponent == null) + return; + int i = this.compVector.size(); + this.compVector.addElement(param1TCComponent); + String[] arrayOfString = { "last_mod_date", "object_name", "owning_site", "object_type", "volume_tag", + "file_size" }; + arrayOfString = param1TCComponent.getValidPropertyNames(arrayOfString); + try { + param1TCComponent.getTCProperties(arrayOfString); + } catch (TCException tCException) { + Logger.getLogger(NamedReferencesTableModel.class).error(tCException.getLocalizedMessage(), tCException); + } + fireTableRowsInserted(i, i); + } + + private String getNamedRefType(TCComponent param1TCComponent) { + String str = ""; + try { + String[] arrayOfString1 = { "ref_list", "ref_names" }; + TCProperty[] arrayOfTCProperty = NamedReferencesDialog.this.datasetComponent + .getTCProperties(arrayOfString1); + TCProperty tCProperty1 = arrayOfTCProperty[0]; + TCProperty tCProperty2 = arrayOfTCProperty[1]; + if (tCProperty1 == null || tCProperty2 == null) + return str; + TCComponent[] arrayOfTCComponent = tCProperty1.getReferenceValueArray(); + String[] arrayOfString2 = tCProperty2.getStringValueArray(); + if (arrayOfTCComponent == null || arrayOfString2 == null) + return str; + int i = arrayOfTCComponent.length; + if (i != arrayOfString2.length) + return str; + byte b1 = -1; + for (byte b2 = 0; b2 < i; b2++) { + if (param1TCComponent == arrayOfTCComponent[b2]) { + b1 = b2; + break; + } + } + if (b1 != -1) + str = arrayOfString2[b1]; + } catch (TCException tCException) { + return ""; + } + return str; + } + } + + private static class RightTextRenderer extends DefaultTableCellRenderer { + public RightTextRenderer() { + setHorizontalAlignment(4); + } + + @Override + public Component getTableCellRendererComponent(JTable param1JTable, Object param1Object, boolean param1Boolean1, + boolean param1Boolean2, int param1Int1, int param1Int2) { + super.getTableCellRendererComponent(param1JTable, param1Object, param1Boolean1, param1Boolean2, param1Int1, + param1Int2); + if (param1Object != null) { + setText(param1Object.toString()); + } else { + setText(""); + } + return this; + } + } + + private class ToolSelectedDialog extends AbstractAIFDialog { + private JButton nextButton; + + private JList toolList; + + private DefaultListModel toolListModel; + + private String namedRef; + + public ToolSelectedDialog(Frame param1Frame, String param1String) { + super(param1Frame, true); + this.namedRef = param1String; + initializeDialog(); + } + + private void initializeDialog() { + setTitle(NamedReferencesDialog.this.appReg.getString("selectTool.TITLE")); + JPanel jPanel1 = new JPanel(new VerticalLayout(5, 2, 2, 2, 2)); + getContentPane().add(jPanel1); + this.toolListModel = new DefaultListModel(); + this.toolList = new JList(this.toolListModel); + this.toolList.setSelectionMode(0); + JScrollPane jScrollPane = new JScrollPane(this.toolList); + JPanel jPanel2 = new JPanel(new VerticalLayout(5, 2, 2, 2, 2)); + JLabel jLabel = new JLabel(NamedReferencesDialog.this.appReg.getString("userWizard")); + Font font = jLabel.getFont(); + font = new Font(font.getName(), 1, font.getSize()); + jLabel.setFont(font); + jPanel2.add("top.nobind.left.top", jLabel); + jPanel2.add("unbound.bind.center.center", jScrollPane); + JPanel jPanel3 = new JPanel(new HorizontalLayout(15, 2, 2, 2, 2)); + jPanel3.add("left.bind.left.center", new JLabel( + NamedReferencesDialog.this.appReg.getOverlayImageIcon("stepBackground.ICON", "newForm32.ICON", 1))); + jPanel3.add("unbound.bind.center.center", jPanel2); + JPanel jPanel4 = new JPanel(); + jPanel4.setLayout(new ButtonLayout(1, 3, 20)); + this.nextButton = new JButton(NamedReferencesDialog.this.appReg.getString("nextButton"), + NamedReferencesDialog.this.appReg.getImageIcon("next.ICON")); + this.nextButton.setHorizontalTextPosition(2); + this.nextButton.setMnemonic(NamedReferencesDialog.this.appReg.getString("next.MNEMONIC").charAt(0)); + this.nextButton.setEnabled(false); + this.nextButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent param2ActionEvent) { + NamedReferencesDialog.ToolSelectedDialog.this.doNextOperation(); + NamedReferencesDialog.ToolSelectedDialog.this.disposeDialog(); + } + }); + this.toolList.addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent param2ListSelectionEvent) { + NamedReferencesDialog.ToolSelectedDialog.this.nextButton.requestFocusInWindow(); + } + }); + jPanel4.add(this.nextButton); + jPanel1.add("top.nobind.left.top", + new JLabel(NamedReferencesDialog.this.appReg.getImageIcon("Tool.ICON"), 0)); + jPanel1.add("top.bind.center.center", new Separator()); + jPanel1.add("unbound.bind.left.center", jPanel3); + jPanel1.add("bottom.bind.center.center", jPanel4); + jPanel1.add("bottom.bind.center.center", new Separator()); + loadTools(); + if (NamedReferencesDialog.this.toolComponents == null) + return; + if (NamedReferencesDialog.this.toolComponents.length == 1) { + NamedReferencesDialog.this.selectedToolComponent = NamedReferencesDialog.this.toolComponents[0]; + return; + } + this.toolList.setSelectedIndex(0); + this.nextButton.setEnabled(true); + setDefaultCloseOperation(0); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent param2WindowEvent) { + NamedReferencesDialog.this.selectedToolComponent = null; + NamedReferencesDialog.ToolSelectedDialog.this.disposeDialog(); + } + }); + pack(); + centerToScreen(1.5D, 1.0D, 0.6D, 0.4D); + setVisible(true); + } + + private void loadTools() { + try { + NamedReferencesDialog.this.toolComponents = NamedReferencesDialog.this.datasetComponent + .getDatasetDefinitionComponent().getToolsForNamedRef(this.namedRef, 4); + } catch (TCException tCException) { + MessageBox.post(NamedReferencesDialog.this.parent, tCException); + return; + } + if (NamedReferencesDialog.this.toolComponents == null) + return; + TCComponent[] arrayOfTCComponent; + arrayOfTCComponent = NamedReferencesDialog.this.toolComponents; + int i = NamedReferencesDialog.this.toolComponents.length; + for (byte b = 0; b < i; b++) { + TCComponent tCComponent = arrayOfTCComponent[b]; + this.toolListModel.addElement(tCComponent); + } + this.toolList.revalidate(); + this.toolList.doLayout(); + this.toolList.repaint(); + } + + private void doNextOperation() { + NamedReferencesDialog.this.selectedToolComponent = (TCComponent) this.toolList.getSelectedValue(); + } + } +} + +/* + * Location: + * E:\work\plugins12_1\com.teamcenter.rac.common_12000.1.0.jar!/com/teamcenter/ + * rac/commands/namedreferences/NamedReferencesDialog.class Java compiler + * version: 8 (52.0) JD-Core Version: 1.0.7 + */ \ No newline at end of file diff --git a/src/com/teamcenter/rac/commands/open/OpenCommand.java b/src/com/teamcenter/rac/commands/open/OpenCommand.java new file mode 100644 index 0000000..1b46832 --- /dev/null +++ b/src/com/teamcenter/rac/commands/open/OpenCommand.java @@ -0,0 +1,873 @@ +package com.teamcenter.rac.commands.open; + +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.Window; +import java.lang.reflect.InvocationTargetException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import javax.swing.SwingUtilities; + +import org.apache.log4j.Logger; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IPerspectiveDescriptor; + +import com.teamcenter.rac.aif.AIFDesktop; +import com.teamcenter.rac.aif.AIFPortal; +import com.teamcenter.rac.aif.AbstractAIFCommand; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.AbstractAIFOperation; +import com.teamcenter.rac.aif.ICommandListener; +import com.teamcenter.rac.aif.ICommandListenerEvent; +import com.teamcenter.rac.aif.IPerspectiveDef; +import com.teamcenter.rac.aif.IPerspectiveDefService; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.AbstractAIFSession; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AifrcpPlugin; +import com.teamcenter.rac.commands.newobjectlink.NewObjectLinkCommand; +import com.teamcenter.rac.commands.properties.PropertiesCommand; +import com.teamcenter.rac.common.Activator; +import com.teamcenter.rac.common.services.IOpenConfigurationService; +import com.teamcenter.rac.common.viewedit.IViewEditOperationListener; +import com.teamcenter.rac.common.viewedit.ViewEditHelper; +import com.teamcenter.rac.kernel.NamedReferenceContext; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMView; +import com.teamcenter.rac.kernel.TCComponentBOMViewRevision; +import com.teamcenter.rac.kernel.TCComponentCfgAttachmentLine; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentDatasetDefinition; +import com.teamcenter.rac.kernel.TCComponentFnd0AbstractMarkupSpace; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentReleaseStatus; +import com.teamcenter.rac.kernel.TCComponentStructureContext; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCComponentType; +import com.teamcenter.rac.kernel.TCComponentWolfObject; +import com.teamcenter.rac.kernel.TCComponentWorkContext; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.services.IOpenService; +import com.teamcenter.rac.util.ConfirmationDialog; +import com.teamcenter.rac.util.Instancer; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.OSGIUtil; +import com.teamcenter.rac.util.PlatformHelper; +import com.teamcenter.rac.util.Registry; +import com.teamcenter.rac.util.SWTUIUtilities; +import com.teamcenter.rac.util.Utilities; +import com.teamcenter.rac.util.event.ClientEventDispatcher; +import com.teamcenter.rac.util.log.Debug; + +public class OpenCommand extends com.teamcenter.rac.aif.commands.open.OpenCommand { + private static final String[] SPECIAL_TYPES = new String[] { "Specification", "SpecElement", + "Specification Revision", "SpecElementRevision" }; + + private static final int TC_not_a_valid_operation_Tool = 9130; + + private static final int TC_asynchronous_upload_error = 0; + + protected AIFDesktop frame; + + private static final String[] MSOFILES = new String[] { ".doc", ".dot", ".xls", ".xlt", ".ppt", ".pot", ".docx", + ".dotx", ".xlsx", ".xltx", ".pptx", ".potx", ".docm", ".dotm", ".xlsm", ".xltm", ".pptm", ".potm", ".msg" }; + + public OpenCommand(AIFPortal paramAIFPortal, InterfaceAIFComponent paramInterfaceAIFComponent) { + super(paramAIFPortal, paramInterfaceAIFComponent); + } + + public OpenCommand(AIFPortal paramAIFPortal, InterfaceAIFComponent[] paramArrayOfInterfaceAIFComponent) { + super(paramAIFPortal, paramArrayOfInterfaceAIFComponent); + } + + public OpenCommand(AIFDesktop paramAIFDesktop, InterfaceAIFComponent paramInterfaceAIFComponent) { + super(paramAIFDesktop, paramInterfaceAIFComponent); + this.frame = paramAIFDesktop; + } + + public OpenCommand(AIFDesktop paramAIFDesktop, InterfaceAIFComponent[] paramArrayOfInterfaceAIFComponent) { + super(paramAIFDesktop, paramArrayOfInterfaceAIFComponent); + this.frame = paramAIFDesktop; + InterfaceAIFComponent interfaceAIFComponent = paramArrayOfInterfaceAIFComponent[0]; + if (interfaceAIFComponent instanceof TCComponentStructureContext) { + TCComponentStructureContext tCComponentStructureContext = (TCComponentStructureContext) interfaceAIFComponent; + TCComponentWorkContext tCComponentWorkContext = null; + TCSession tCSession = (TCSession) interfaceAIFComponent.getSession(); + try { + tCComponentWorkContext = (TCComponentWorkContext) tCComponentStructureContext + .getReferenceProperty("default_workcontext"); + if (tCComponentWorkContext != null && tCSession != null + && tCComponentWorkContext != tCSession.getCurrentWorkContext()) + tCSession.setCurrentWorkContext(tCComponentWorkContext); + } catch (Exception exception) { + } + } + } + + public OpenCommand(AIFDesktop paramAIFDesktop, Dialog paramDialog, + InterfaceAIFComponent paramInterfaceAIFComponent) { + super(paramAIFDesktop, paramDialog, paramInterfaceAIFComponent); + this.frame = paramAIFDesktop; + } + + public OpenCommand(AIFDesktop paramAIFDesktop, Dialog paramDialog, + InterfaceAIFComponent[] paramArrayOfInterfaceAIFComponent) { + super(paramAIFDesktop, paramDialog, paramArrayOfInterfaceAIFComponent); + this.frame = paramAIFDesktop; + } + + protected boolean checkReadOnly() { + return true; + } + + @Override + public int postReadOnlyConfirmation(String paramString) { + Registry registry = Registry.getRegistry(this); + return ConfirmationDialog.post(this.desktop, + String.valueOf(registry.getString("readOnly.TITLE")) + " " + paramString, + registry.getStringWithSubstitution("readOnly.MSG", new String[] { paramString }), + "FormReadOnlyConfirmation"); + } + + @Override + protected String resolveType(String[] paramArrayOfString, InterfaceAIFComponent paramInterfaceAIFComponent) + throws Exception { + String str1 = null; + TCComponent tCComponent = (TCComponent) paramInterfaceAIFComponent; + if (tCComponent.isTypeOf(SPECIAL_TYPES)) + return "Specification"; + if (tCComponent instanceof TCComponentBOMViewRevision) { + TCComponentBOMViewRevision tCComponentBOMViewRevision = (TCComponentBOMViewRevision) tCComponent; + TCComponent tCComponent1 = tCComponentBOMViewRevision.getRelatedComponent("bom_view"); + TCComponent tCComponent2 = tCComponent1.getRelatedComponent("parent_item"); + if (tCComponent2.isTypeOf(SPECIAL_TYPES)) + return "Specification"; + } + if (tCComponent instanceof TCComponentBOMView) { + TCComponentBOMView tCComponentBOMView = (TCComponentBOMView) tCComponent; + TCComponent tCComponent1 = tCComponentBOMView.getRelatedComponent("parent_item"); + if (tCComponent1.isTypeOf(SPECIAL_TYPES)) + return "Specification"; + } + List list = Arrays.asList(paramArrayOfString); + String str2 = tCComponent.getType(); + if (!(tCComponent instanceof com.teamcenter.rac.kernel.TCComponentPseudoFolder) && list.contains(str2)) { + str1 = str2; + } else { + (new String[1])[0] = "POM_object"; + String[] arrayOfString = (tCComponent instanceof com.teamcenter.rac.kernel.TCComponentPseudoFolder) + ? new String[1] + : tCComponent.getClassNameHierarchy(); + if (arrayOfString != null) { + String[] arrayOfString1; + int i = (arrayOfString1 = arrayOfString).length; + for (byte b = 0; b < i; b++) { + String str = arrayOfString1[b]; + if (list.contains(str)) { + str1 = str; + break; + } + } + } + } + return str1; + } + + @Override + protected String getRegisteredClass(InterfaceAIFComponent paramInterfaceAIFComponent, String paramString) + throws Exception { + if (paramString.equals("APPLICATION")) { + IOpenConfigurationService iOpenConfigurationService = (IOpenConfigurationService) OSGIUtil + .getService(Activator.getDefault(), IOpenConfigurationService.class); + String str = iOpenConfigurationService.getPerspectiveIdToOpenWith(paramInterfaceAIFComponent); + return (str != null && !str.isEmpty()) ? str : null; + } + return super.getRegisteredClass(paramInterfaceAIFComponent, paramString); + } + + @Override + protected boolean isReadOnly(InterfaceAIFComponent paramInterfaceAIFComponent) { + boolean bool = false; + if (paramInterfaceAIFComponent == null) + return bool; + if (this.session == null) + this.session = paramInterfaceAIFComponent.getSession(); + if (this.session == null || !(this.session instanceof TCSession) + || !(paramInterfaceAIFComponent instanceof TCComponent)) + return bool; + if (paramInterfaceAIFComponent instanceof TCComponentDataset + || paramInterfaceAIFComponent instanceof TCComponentForm) { + TCComponent tCComponent = (TCComponent) paramInterfaceAIFComponent; + try { + ArrayList arrayList = new ArrayList(); + arrayList.add(tCComponent); + TCComponentType.refresh(arrayList); + if (paramInterfaceAIFComponent instanceof TCComponentDataset) { + bool = ((TCComponentDataset) paramInterfaceAIFComponent).isEditable() ? false : true; + } else { + bool = tCComponent.okToModify() ? false : true; + } + } catch (Exception exception) { + Logger.getLogger(OpenCommand.class).error(exception.getLocalizedMessage(), exception); + } + } + return bool; + } + + @Override + protected boolean isUploading(InterfaceAIFComponent paramInterfaceAIFComponent) { + if (paramInterfaceAIFComponent == null || !(paramInterfaceAIFComponent instanceof TCComponentDataset)) + return false; + TCComponentDataset tCComponentDataset = (TCComponentDataset) paramInterfaceAIFComponent; + return tCComponentDataset.askUploadingFlag(); + } + + @Override + protected boolean openComponent(InterfaceAIFComponent paramInterfaceAIFComponent) throws Exception { + boolean bool1 = isSupportedComponent(paramInterfaceAIFComponent); + boolean bool2 = false; + if (bool1) + if (paramInterfaceAIFComponent.getType().equals("SimulationProcessStudio")) { + bool2 = openApplication(paramInterfaceAIFComponent); + } else if (((TCComponent) paramInterfaceAIFComponent).isTypeOf("Fnd0AbstractMarkupSpace")) { + bool2 = openMarkupSpaceInApplication((TCComponentFnd0AbstractMarkupSpace) paramInterfaceAIFComponent); + } else { + bool2 = super.openComponent(paramInterfaceAIFComponent); + } + return bool2; + } + + protected boolean isSupportedComponent(InterfaceAIFComponent paramInterfaceAIFComponent) throws TCException { + return true; + } + + @Override + protected boolean openByWindow(InterfaceAIFComponent paramInterfaceAIFComponent) throws Exception { + if (paramInterfaceAIFComponent instanceof TCComponentForm) { + if (((TCComponentForm) paramInterfaceAIFComponent).isTypeOf("Web Link")) { + TCComponentForm tCComponentForm = (TCComponentForm) paramInterfaceAIFComponent; + TCProperty[] arrayOfTCProperty = tCComponentForm.getFormTCProperties(); + TCProperty tCProperty = null; + if (arrayOfTCProperty != null) { + TCProperty[] arrayOfTCProperty1; + int i = (arrayOfTCProperty1 = arrayOfTCProperty).length; + for (byte b = 0; b < i; b++) { + TCProperty tCProperty1 = arrayOfTCProperty1[b]; + if (tCProperty1.getPropertyName().equals("url")) { + tCProperty = tCProperty1; + break; + } + } + } + if (tCProperty != null) + openWebLink(paramInterfaceAIFComponent.toString(), tCProperty.getStringValue()); + return true; + } + TCPreferenceService tCPreferenceService = ((TCComponent) paramInterfaceAIFComponent).getSession() + .getPreferenceService(); + String str = tCPreferenceService.getStringValue("Form_double_click"); + if (str != null && str.equalsIgnoreCase("edit")) { + openFormBasedOnPrefValue((TCComponentForm) paramInterfaceAIFComponent); + return true; + } + openFormByOpenWindowMethod((TCComponentForm) paramInterfaceAIFComponent); + return true; + } + if (paramInterfaceAIFComponent instanceof TCComponent + && ((TCComponent) paramInterfaceAIFComponent).isTypeOf("WolfObject")) { + String str = NewObjectLinkCommand.getObjCurrentUrl((TCComponentWolfObject) paramInterfaceAIFComponent, + (Frame) this.frame, (TCSession) this.session); + if (str != null) { + if (Debug.isOn("proxylink")) + Debug.println("Object URL: " + str); + openWebLink((String) null, str); + } else if (Debug.isOn("proxylink")) { + Debug.println("Object URL is NULL"); + } + return true; + } + return (paramInterfaceAIFComponent instanceof com.teamcenter.rac.kernel.TCComponentPseudoFolder) ? false + : super.openByWindow(paramInterfaceAIFComponent); + } + + private void openFormBasedOnPrefValue(final TCComponentForm formComp) { + final ViewEditHelper veHelper = new ViewEditHelper(formComp.getSession()); + Job job = new Job("") { + @Override + protected IStatus run(IProgressMonitor param1IProgressMonitor) { + param1IProgressMonitor.beginTask("Form Dialog..", -1); + try { + ViewEditHelper.CKO cKO = veHelper.getObjectState(formComp); + if (veHelper.isSWTPerspective()) { + OpenCommand.IC_PostReserveSWTListener iC_PostReserveSWTListener = new OpenCommand.IC_PostReserveSWTListener( + formComp); + if (ViewEditHelper.CKO.IMPLICITLY_CHECKOUTABLE.equals(cKO)) { + iC_PostReserveSWTListener.operationComplete(0); + } else { + veHelper.reserveSWTOperation(formComp, formComp.getSession(), iC_PostReserveSWTListener); + } + } else { + OpenCommand.IC_PostReserveCommandListener iC_PostReserveCommandListener = new OpenCommand.IC_PostReserveCommandListener( + formComp); + if (ViewEditHelper.CKO.IMPLICITLY_CHECKOUTABLE.equals(cKO)) { + iC_PostReserveCommandListener.commandDone(null); + } else { + veHelper.reserveOperation(formComp, iC_PostReserveCommandListener); + } + } + } catch (TCException tCException) { + Logger.getLogger(OpenCommand.class).error(tCException.getLocalizedMessage(), tCException); + } finally { + param1IProgressMonitor.done(); + } + return Status.OK_STATUS; + } + }; + job.setPriority(10); + job.schedule(); + } + + protected void openFormByOpenWindowMethod(TCComponentForm paramTCComponentForm) throws Exception { + IOpenService iOpenService = (IOpenService) OSGIUtil.getService(Activator.getDefault(), IOpenService.class, + "(objectType=" + paramTCComponentForm.getType() + ")"); + if (iOpenService != null) { + Logger.getLogger(OpenCommand.class).debug("Open service is found, use it to open the form."); + boolean bool1 = iOpenService.open(paramTCComponentForm); + if (bool1) { + Logger.getLogger(OpenCommand.class).debug("Form is opened by open service."); + return; + } + } else { + Logger.getLogger(OpenCommand.class).debug("No Open Service is found. Continue."); + } + String str = null; + TCPreferenceService tCPreferenceService = paramTCComponentForm.getSession().getPreferenceService(); + String[] arrayOfString = tCPreferenceService.getStringValues("defaultViewerConfig.VIEWERCONFIG"); + Boolean bool = tCPreferenceService.getLogicalValue("UsePropertyStylesheetPlatformRenderer"); + if (bool.booleanValue()) { + str = this.registry.getString("openFormDialog"); + } else if (arrayOfString != null && arrayOfString.length != 0) { + String str1 = String.valueOf(paramTCComponentForm.getType()) + ".FormViewer"; + if (Utilities.contains(str1, arrayOfString) || Utilities.contains("Form.FormViewer", arrayOfString)) + str = this.registry.getString("openFormDialog"); + } + openByWindow(paramTCComponentForm, str); + } + + @Override + protected boolean openByOpenMethod(InterfaceAIFComponent paramInterfaceAIFComponent) throws Exception { + if (paramInterfaceAIFComponent instanceof TCComponentDataset) { + if (paramInterfaceAIFComponent.getType().equals("FullText")) { + openFullText((TCComponentDataset) paramInterfaceAIFComponent); + } else if (paramInterfaceAIFComponent.getType().equals("ProgramView")) { + openProgramView((TCComponentDataset) paramInterfaceAIFComponent); + } else if (paramInterfaceAIFComponent.getType().equals("SnapShotViewData")) { + openProgramView((TCComponentDataset) paramInterfaceAIFComponent); + } else { + TCComponentDataset tCComponentDataset = (TCComponentDataset) paramInterfaceAIFComponent; + boolean bool = false; + TCComponentTcFile[] arrayOfTCComponentTcFile = tCComponentDataset.getTcFiles(); + if (arrayOfTCComponentTcFile != null && arrayOfTCComponentTcFile.length > 0) { + bool = validFileForMSOIntegration(arrayOfTCComponentTcFile[0]); + } else { + String[] arrayOfString = null; + TCComponentDatasetDefinition tCComponentDatasetDefinition = tCComponentDataset + .getDatasetDefinitionComponent(); + NamedReferenceContext[] arrayOfNamedReferenceContext = tCComponentDatasetDefinition + .getNamedReferenceContexts(); + if (arrayOfNamedReferenceContext != null) { + arrayOfString = new String[arrayOfNamedReferenceContext.length]; + for (byte b = 0; b < arrayOfNamedReferenceContext.length; b++) { + arrayOfString[b] = arrayOfNamedReferenceContext[b].getFileTemplate(); + if (arrayOfString[b] != null && arrayOfString[b].indexOf('.') > 0) { + String str = arrayOfString[b].substring(arrayOfString[b].lastIndexOf('.')); + String[] arrayOfString1; + int i = (arrayOfString1 = MSOFILES).length; + for (byte b1 = 0; b1 < i; b1++) { + String str1 = arrayOfString1[b1]; + if (str.equalsIgnoreCase(str1)) { + bool = true; + break; + } + } + } + if (bool) + break; + } + } + } + if (bool) + tCComponentDataset.setOfficeType(bool); + openDataset(tCComponentDataset); + } + return true; + } + return super.openByOpenMethod(paramInterfaceAIFComponent); + } + + private boolean openMarkupSpaceInApplication( + TCComponentFnd0AbstractMarkupSpace paramTCComponentFnd0AbstractMarkupSpace) throws Exception { + boolean bool = false; + TCComponent[] arrayOfTCComponent = paramTCComponentFnd0AbstractMarkupSpace + .getReferenceListProperty("fnd0ReferenceObjects"); + if (arrayOfTCComponent != null && arrayOfTCComponent.length == 1) { + TCComponent tCComponent = arrayOfTCComponent[0]; + String str = getRegisteredClass(tCComponent, "APPLICATION"); + if (str != null) { + IPerspectiveDescriptor iPerspectiveDescriptor = PlatformHelper.getCurrentPerspective(); + IPerspectiveDefService iPerspectiveDefService = (IPerspectiveDefService) OSGIUtil + .getService(AifrcpPlugin.getDefault(), IPerspectiveDefService.class); + IPerspectiveDef iPerspectiveDef = iPerspectiveDefService.findByLegacyAppId(str); + if (iPerspectiveDef != null) { + IPerspectiveDef iPerspectiveDef1 = iPerspectiveDefService.findByPerspective(iPerspectiveDescriptor); + if (iPerspectiveDef1 != null) { + String str1 = iPerspectiveDef1.getLegacyAppId(); + final InterfaceAIFComponent[] arrayOfInterfaceAIFComponent = new InterfaceAIFComponent[2]; + arrayOfInterfaceAIFComponent[0] = tCComponent; + arrayOfInterfaceAIFComponent[1] = paramTCComponentFnd0AbstractMarkupSpace; + if (!iPerspectiveDefService.isTypeOfLegacyApp(str, str1)) { + final String perspectiveId = iPerspectiveDef.getId(); + SWTUIUtilities.asyncExec(new Runnable() { + @Override + public void run() { + AifrcpPlugin.getDefault().openPerspective(perspectiveId); + AifrcpPlugin.getDefault().openComponents(perspectiveId, + arrayOfInterfaceAIFComponent); + } + }); + bool = true; + } else { + final IOpenService openService = iPerspectiveDef1.getOpenService(); + if (openService != null) { + Job job = new Job(Registry.getRegistry(this).getString("openComponent.MESSAGE")) { + @Override + protected IStatus run(IProgressMonitor param1IProgressMonitor) { + boolean bool = openService.open(arrayOfInterfaceAIFComponent); + return bool ? Status.OK_STATUS : Status.CANCEL_STATUS; + } + }; + job.schedule(); + bool = true; + } + } + } + } + } + } else { + bool = openApplication(paramTCComponentFnd0AbstractMarkupSpace); + } + return bool; + } + + public void openDataset(TCComponentDataset paramTCComponentDataset) throws Exception { + boolean bool = true; + boolean bool1 = isReadOnly(paramTCComponentDataset); + if (!bool1) + try { + paramTCComponentDataset.openForEdit(); + } catch (TCException | java.io.IOException tCException) { + if (tCException instanceof TCException) { + if (((TCException) tCException).getErrorCode() == 9130) { + MessageBox.post(tCException); + return; + } + if (((TCException) tCException).getErrorCode() == 0) + throw tCException; + } + int i = postReadOnlyConfirmation(paramTCComponentDataset.toString()); + if (i != 2) + return; + bool = false; + } catch (Exception exception) { + throw exception; + } + if (bool1 || !bool) + try { + paramTCComponentDataset.openForView(); + } catch (Exception exception) { + throw exception; + } + } + + public void openFullText(TCComponentDataset paramTCComponentDataset) { + boolean bool = isReadOnly(paramTCComponentDataset) ? false : true; + try { + AbstractAIFOperation abstractAIFOperation = (AbstractAIFOperation) Instancer.newInstanceEx( + "com.teamcenter.rac.requirementsmanager.commands.viewedit.ViewEditOperation", + new Object[] { paramTCComponentDataset, Boolean.valueOf(bool) }); + abstractAIFOperation.executeModeless(); + } catch (Exception exception) { + Logger.getLogger(OpenCommand.class).error(exception.getLocalizedMessage(), exception); + } + } + + public void openProgramView(TCComponentDataset paramTCComponentDataset) { + try { + openApplication(paramTCComponentDataset); + } catch (Exception exception) { + Logger.getLogger(OpenCommand.class).error(exception.getLocalizedMessage(), exception); + } + } + + @Override + protected boolean isReleased(List paramList) { + final AbstractAIFDialog effDia; + try { + if (!((TCSession) this.session).isInV7Mode()) + return true; + } catch (Exception exception) { + MessageBox.post(exception); + } + TCComponentReleaseStatus[] arrayOfTCComponentReleaseStatus = new TCComponentReleaseStatus[paramList.size()]; + for (byte b = 0; b < arrayOfTCComponentReleaseStatus.length; b++) + arrayOfTCComponentReleaseStatus[b] = (TCComponentReleaseStatus) paramList.get(b); + try { + effDia = (AbstractAIFDialog) Instancer.newInstance( + "com.teamcenter.rac.effectivity.ReleaseStatusEffectivityDialog", + new Object[] { arrayOfTCComponentReleaseStatus, this.frame }); + } catch (Exception exception) { + MessageBox.post(exception, true); + return true; + } + Runnable runnable = new Runnable() { + @Override + public void run() { + effDia.run(); + } + }; + SwingUtilities.invokeLater(runnable); + return true; + } + + @Override + protected boolean isArchived(InterfaceAIFComponent paramInterfaceAIFComponent) { + boolean bool = false; + if (paramInterfaceAIFComponent == null) + return bool; + if (this.session == null) + this.session = paramInterfaceAIFComponent.getSession(); + if (this.session == null || !(this.session instanceof TCSession) + || !(paramInterfaceAIFComponent instanceof TCComponent)) + return bool; + if (paramInterfaceAIFComponent instanceof TCComponentDataset + || paramInterfaceAIFComponent instanceof TCComponentForm) { + TCComponent tCComponent = (TCComponent) paramInterfaceAIFComponent; + try { + String str = tCComponent.getProperty("archive_date"); + if (str != null && str.length() > 0) + bool = true; + } catch (Exception exception) { + Logger.getLogger(OpenCommand.class).error(exception.getLocalizedMessage(), exception); + } + } + return bool; + } + + @Override + protected void executeCommand() throws Exception { + final Registry commandRegistry = Registry.getRegistry(this); + TCPreferenceService tCPreferenceService = (TCPreferenceService) OSGIUtil.getService(Activator.getDefault(), + TCPreferenceService.class); + final Integer prefValue = tCPreferenceService.getIntegerValue("TCMaxOpenViewsLimit"); + InterfaceAIFComponent[] arrayOfInterfaceAIFComponent = new InterfaceAIFComponent[prefValue.intValue()]; + if (this.components.length > prefValue.intValue()) { + for (byte b = 0; b < prefValue.intValue(); b++) + arrayOfInterfaceAIFComponent[b] = this.components[b]; + this.components = arrayOfInterfaceAIFComponent; + final Display display = PlatformHelper.getCurrentDisplay(); + display.asyncExec(new Runnable() { + @Override + public void run() { + MessageDialog messageDialog = new MessageDialog(display.getActiveShell(), + commandRegistry.getString("tooManyViews.TITLE"), null, + MessageFormat.format(commandRegistry.getString("tooManyViewsError.MSG"), + new Object[] { prefValue }), + 4, new String[] { commandRegistry.getString("openViewDialog_buttonOK"), + commandRegistry.getString("openViewDialog_buttonCancel") }, + 0); + if (messageDialog.open() != 0) + return; + OpenCommand.this.openComponents(); + } + }); + } else { + openComponents(); + } + } + + private void openComponents() { + this.session.queueOperation(new AbstractAIFOperation(Registry.getRegistry(this).getString("opening")) { + @Override + public final void executeOperation() throws Exception { + Registry registry = Registry.getRegistry(this); + Vector vector = new Vector(); + InterfaceAIFComponent[] arrayOfInterfaceAIFComponent; + int i = (arrayOfInterfaceAIFComponent = OpenCommand.this.components).length; + for (byte b = 0; b < i; b++) { + InterfaceAIFComponent interfaceAIFComponent1 = arrayOfInterfaceAIFComponent[b]; + InterfaceAIFComponent interfaceAIFComponent2 = interfaceAIFComponent1; + System.out.println(interfaceAIFComponent2); + // jd + if (interfaceAIFComponent2 instanceof TCComponentDataset) { + + try { + TCSession tcSession = (TCSession) interfaceAIFComponent2.getSession(); + TCPreferenceService service = tcSession.getPreferenceService(); + String[] pref = service.getStringValues("jd_dataset_download"); + String[] pref2 = service.getStringValues("jd_wl_type_classify"); + Map> typeClassify = new HashMap>(); + List list = new ArrayList(); + if (pref != null && pref.length > 0) { + System.out.println("ѡ===>" + Arrays.toString(pref)); + list = Arrays.asList(pref); + } + if (pref2 != null && pref2.length > 0) { + System.out.println("ѡ2===>" + Arrays.toString(pref2)); + for (String str : pref2) { + String[] row = str.split(":"); + typeClassify.put(row[0], Arrays.asList(row[1].split(","))); + } + } + TCComponentDataset dataset = (TCComponentDataset) interfaceAIFComponent2; + System.out.println(dataset.getProperty("object_string")); + System.out.println(dataset.getType()); + if (list.contains(dataset.getType())) { + boolean flag = false; + String currentUser = tcSession.getUser().getProperty("object_string"); + String owningUser = dataset.getProperty("owning_user"); + System.out.println("currentUser===>" + currentUser + ",owningUser===>" + owningUser); + if (currentUser.equals(owningUser)) { + System.out.println(""); + flag = true; + } + String loginGroup = tcSession.getUser().getProperty("login_group"); + System.out.println("loginGroup===>" + loginGroup); + System.out.println("pre===>" + flag); + if (loginGroup.contains("dba")) { + System.out.println("dba"); + flag = true; + } + System.out.println("behind===>" + flag); + if (!flag) { + AIFComponentContext[] revs = dataset.whereReferenced(); + for (AIFComponentContext aif1 : revs) { + if (aif1.getComponent() != null + && (aif1.getComponent() instanceof TCComponentItemRevision)) { + String type = aif1.getComponent().getType(); + System.out.println("===>" + type); + if ((loginGroup.contains("зһ") && typeClassify.get("GT") != null + && typeClassify.get("GT").contains(type)) + || (loginGroup.contains("з") && typeClassify.get("BL") != null + && typeClassify.get("BL").contains(type)) + || (loginGroup.contains("з岿") && typeClassify.get("BX") != null + && typeClassify.get("BX").contains(type))) { + System.out.println(""); + flag = true; + break; + } + } + } + } + if (!flag) { + MessageBox.post("", "ʾ", MessageBox.WARNING); + return; + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + interfaceAIFComponent2 = OpenCommand.this.getOpeningComponent(interfaceAIFComponent2); + if (interfaceAIFComponent2 instanceof TCComponentReleaseStatus) { + vector.addElement(interfaceAIFComponent2); + continue; + } + if (OpenCommand.this.isArchived(interfaceAIFComponent2)) { + MessageBox.post(OpenCommand.this.desktop, + String.valueOf(interfaceAIFComponent2.toString()) + " " + + registry.getString("archivedObject.MSG"), + registry.getString("archivedObject.TITLE"), 4); + continue; + } + if (OpenCommand.this.checkReadOnly() && OpenCommand.this.isReadOnly(interfaceAIFComponent2)) { + TCComponent tCComponent = null; + if (interfaceAIFComponent2 instanceof TCComponent) { + tCComponent = (TCComponent) interfaceAIFComponent2; + tCComponent.clearCache("checked_out_user"); + } + String str2 = ""; + int j = 0; + String str1 = interfaceAIFComponent2.getProperty("checked_out_user").trim(); + if (!str1.equals("")) { + Registry registry1 = Registry.getRegistry(this); + str2 = MessageFormat.format(registry1.getString("checkedOut.MSG"), new Object[] { str1 }); + j = ConfirmationDialog.post(OpenCommand.this.desktop, + String.valueOf(registry1.getString("checkedOut.TITLE")) + " " + + interfaceAIFComponent2.toString(), + String.valueOf(interfaceAIFComponent2.toString()) + " " + str2, + "FormReadOnlyConfirmation"); + } else { + j = OpenCommand.this.postReadOnlyConfirmation(interfaceAIFComponent2.toString()); + } + if (j != 2) + continue; + } + if (OpenCommand.this.isUploading(interfaceAIFComponent2)) { + int j = OpenCommand.this.postUploadingConfirmation(interfaceAIFComponent2.toString()); + if (j != 2) + continue; + } + AbstractAIFSession abstractAIFSession = interfaceAIFComponent2.getSession(); + try { + setStatus(interfaceAIFComponent2.toString()); + OpenCommand.this.processOpen(interfaceAIFComponent2); + } catch (InvocationTargetException invocationTargetException) { + MessageBox messageBox = new MessageBox(OpenCommand.this.desktop, + invocationTargetException.getTargetException().getCause().toString(), + registry.getString("unableToOpen"), 1); + messageBox.setModal(true); + messageBox.setVisible(true); + } catch (Exception exception) { + Logger.getLogger(OpenCommand.class).error(exception.getLocalizedMessage(), exception); + String str = String.valueOf(registry.getString("unableToOpen", "Unable to open ")) + " " + + interfaceAIFComponent2.toString(); + abstractAIFSession.setStatus(str); + MessageBox messageBox = new MessageBox(OpenCommand.this.desktop, str, + exception.getLocalizedMessage(), registry.getString("unableToOpen"), 1); + messageBox.setModal(true); + messageBox.setVisible(true); + } + continue; + } + if (!vector.isEmpty()) + OpenCommand.this.isReleased(vector); + } + }); + } + + @Override + protected InterfaceAIFComponent getOpeningComponent(InterfaceAIFComponent paramInterfaceAIFComponent) + throws Exception { + TCComponent tCComponent = (TCComponent) paramInterfaceAIFComponent; + InterfaceAIFComponent interfaceAIFComponent = paramInterfaceAIFComponent; + if (paramInterfaceAIFComponent instanceof TCComponentCfgAttachmentLine) + tCComponent = ((TCComponentCfgAttachmentLine) paramInterfaceAIFComponent).getUnderlyingComponent(); + return tCComponent; + } + + public static void openWebLink(String paramString1, String paramString2) { + ClientEventDispatcher.fireEventNow(OpenCommand.class, "com/teamcenter/rac/aifrcp/browser/launchRequest", + new Object[] { "com/teamcenter/rac/aifrcp/browser/urlToOpen", paramString2, + "com/teamcenter/rac/aifrcp/browser/title", paramString1 }); + } + + @Override + protected boolean openProperties(InterfaceAIFComponent paramInterfaceAIFComponent) throws Exception { + if (paramInterfaceAIFComponent instanceof TCComponent) { + TCComponent[] arrayOfTCComponent = { (TCComponent) paramInterfaceAIFComponent }; + Window window = (this.parentWindow != null) ? this.parentWindow : this.desktop; + PropertiesCommand propertiesCommand = new PropertiesCommand(arrayOfTCComponent, window); + propertiesCommand.executeModeless(); + return true; + } + return false; + } + + private boolean validFileForMSOIntegration(TCComponentTcFile paramTCComponentTcFile) throws Exception { + boolean bool = false; + if (paramTCComponentTcFile != null) { + String str = paramTCComponentTcFile.getProperty("original_file_name"); + if (str != null && str.indexOf('.') > 0) { + String str1 = str.substring(str.lastIndexOf('.')); + String[] arrayOfString; + int i = (arrayOfString = MSOFILES).length; + for (byte b = 0; b < i; b++) { + String str2 = arrayOfString[b]; + if (str1.equalsIgnoreCase(str2)) { + bool = true; + break; + } + } + } + } + return bool; + } + + private void openForm(final TCComponent component) { + Runnable runnable = new Runnable() { + @Override + public void run() { + try { + OpenCommand.this.openFormByOpenWindowMethod((TCComponentForm) component); + } catch (Exception exception) { + Logger.getLogger(OpenCommand.class).error(exception.getLocalizedMessage(), exception); + } + } + }; + SwingUtilities.invokeLater(runnable); + } + + private class IC_PostReserveCommandListener implements ICommandListener { + private final TCComponent m_component; + + public IC_PostReserveCommandListener(TCComponent param1TCComponent) { + this.m_component = param1TCComponent; + } + + @Override + public void commandDone(ICommandListenerEvent param1ICommandListenerEvent) { + AbstractAIFCommand abstractAIFCommand = (param1ICommandListenerEvent != null) + ? param1ICommandListenerEvent.getCommand() + : null; + OpenCommand.this.openForm(this.m_component); + if (abstractAIFCommand != null) + param1ICommandListenerEvent.getCommand().removeCommandListener(this); + } + + @Override + public void commandStarting(ICommandListenerEvent param1ICommandListenerEvent) { + } + } + + private class IC_PostReserveSWTListener implements IViewEditOperationListener { + private final TCComponent m_component; + + public IC_PostReserveSWTListener(TCComponentForm param1TCComponentForm) { + this.m_component = param1TCComponentForm; + } + + @Override + public void operationComplete(int param1Int) { + OpenCommand.this.openForm(this.m_component); + } + + @Override + public void operationError(TCException param1TCException) { + Logger.getLogger(OpenCommand.class).error(param1TCException.getLocalizedMessage(), param1TCException); + } + } +} + +/* + * Location: + * C:\Users\5rKB5bPlusD\Desktop\com.teamcenter.rac.common_12000.2.0.jar!\com\ + * teamcenter\rac\commands\open\OpenCommand.class Java compiler version: 8 + * (52.0) JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/src/com/teamcenter/rac/stylesheet/stylesheet_user.properties b/src/com/teamcenter/rac/stylesheet/stylesheet_user.properties new file mode 100644 index 0000000..c80cffc --- /dev/null +++ b/src/com/teamcenter/rac/stylesheet/stylesheet_user.properties @@ -0,0 +1,6 @@ +JD2_GTYPQRDRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.SampleConfirmationForm +JD2_GTSYWTSRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.ExperimentalPowerOfAttorneyForm +SF6_ElecElementRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.CSJHForm +JD2_GTCSJHRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.CSJHForm +JD2_GTXPCSXQDRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.NewProductTestForm +JD2_GTXPXMCSJHRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.GTCSJHForm \ No newline at end of file diff --git a/src/config/db.setting b/src/config/db.setting new file mode 100644 index 0000000..c668ca1 --- /dev/null +++ b/src/config/db.setting @@ -0,0 +1,14 @@ +## db.settingļ + +url = jdbc:oracle:thin:@localhost:1521:TC +#url = jdbc:oracle:thin:@10.20.4.75:1521:TC12 +user = infodba +pass = infodba + +## ѡ +# Ƿ־ʾִеSQL +showSql = true +# ǷʽʾSQL +formatSql = false +# ǷʾSQL +showParams = true \ No newline at end of file