diff --git a/src/com/langtech/plm/bg/QDRWChooseDialog.java b/src/com/langtech/plm/bg/QDRWChooseDialog.java new file mode 100644 index 0000000..4791136 --- /dev/null +++ b/src/com/langtech/plm/bg/QDRWChooseDialog.java @@ -0,0 +1,151 @@ +package com.langtech.plm.bg; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Map.Entry; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.table.DefaultTableModel; + +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; + +public class QDRWChooseDialog extends JFrame implements ActionListener { + + + private JComboBox objectComboBox = new JComboBox(); + private JButton okButton = new JButton("确定"); + private JButton concelButton = new JButton("取消"); + private String[] strings; + private AbstractAIFUIApplication app; + private HashMap> map = new HashMap>(); + public QDRWChooseDialog(String[] strings,AbstractAIFUIApplication app) { + // TODO Auto-generated constructor stub + this.strings = strings; + this.app = app; + initUI(); + } + + + + public void initUI() { + // TODO Auto-generated method stub + try { + this.setTitle("请选择变更模板"); + this.setLayout(new BorderLayout()); + + JPanel topPanel = getTopPanel(); + + JPanel btnPanel = getBtnPanel(); + + this.add(topPanel, BorderLayout.NORTH); + // this.add(pane,BorderLayout.CENTER); + this.add(btnPanel, BorderLayout.SOUTH); + this.setPreferredSize(new Dimension(350, 150)); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸 + int screenWidth = screenSize.width; // 获取屏幕宽度 + int screenHeight = screenSize.height; // 获取屏幕高度 + int x = (screenWidth - 350) / 2; // 计算Frame的左上角x坐标 + int y = (screenHeight - 150) / 2; // 计算Frame的左上角y坐标 + this.setLocation(x, y); // 设置Frame的位置 + + // this.setLocationRelativeTo(null); + this.createActionEvent(); + this.pack(); + + // this.validate(); + this.setVisible(true); + +// this.setAlwaysOnTop(true); + + //设置下拉值 + for (int i = 0; i < strings.length; i++) { + String[] split = strings[i].split("="); + objectComboBox.addItem(split[0]); + ArrayList list = new ArrayList(); + list.add(split[1]); + list.add(split[2]); + map.put(split[0], list); + } + + } catch (Exception e) { + e.printStackTrace(); + return; + } + } + + // 添加监听 + public void createActionEvent() { + + this.okButton.addActionListener(this); + this.concelButton.addActionListener(this); + } + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + + Object source = e.getSource(); + System.out.println("source==>+" + source); + if (this.okButton.equals(source)) { + String selectedItem = (String) objectComboBox.getSelectedItem(); + ArrayList arrayList = map.get(selectedItem); + new QDRWDialog((TCSession)app.getSession(),arrayList.get(0),arrayList.get(1)); + this.dispose(); + } else if (this.concelButton.equals(source)) { + this.dispose(); + } + + } + + private JPanel getBtnPanel() { + JPanel topPanel = new JPanel(); + topPanel.setLayout(new PropertyLayout()); + topPanel.add("1.1.center", new JLabel("")); + topPanel.add("2.1.center", new JLabel(" ")); + topPanel.add("2.2.center", okButton); + topPanel.add("2.3.center", new JLabel("")); + topPanel.add("2.4.center", concelButton); + topPanel.add("3.1.center", new JLabel("")); + topPanel.add("4.1.center", new JLabel("")); + return topPanel; + } + + // 查询部分 + private JPanel getTopPanel() { + // TODO Auto-generated method stub + JPanel topPanel = new JPanel(); + topPanel.setLayout(new PropertyLayout()); + topPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + + topPanel.add("1.1.left.center", new JLabel("")); + topPanel.add("2.1.left.center", new JLabel("")); + topPanel.add("3.1.left.center", new JLabel("")); + topPanel.add("4.1.left.center", new JLabel("")); + + topPanel.add("5.1.left.center", new JLabel(" 变更模板:")); + topPanel.add("5.2.left.center", objectComboBox); + + return topPanel; + } + +} diff --git a/src/com/langtech/plm/bg/QDRWDialog.java b/src/com/langtech/plm/bg/QDRWDialog.java new file mode 100644 index 0000000..c2daa64 --- /dev/null +++ b/src/com/langtech/plm/bg/QDRWDialog.java @@ -0,0 +1,523 @@ +package com.langtech.plm.bg; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +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.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.RowSorter; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumnModel; +import javax.swing.table.TableModel; +import javax.swing.table.TableRowSorter; + +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + + +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +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.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentListOfValuesType; +import com.teamcenter.rac.kernel.TCComponentProject; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.DateButton; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; +import com.teamcenter.soa.client.model.LovValue; + +public class QDRWDialog extends JFrame implements ActionListener { + + private Map textMap = new HashMap<>(); + private TCSession session; + private JTable table; + private String[] header; + private ArrayList gsPrefTopLine; + private ArrayList colorList = new ArrayList(); + private LinkedHashMap gsPrefMap = new LinkedHashMap(); + private LinkedHashMap fieldsMap = new LinkedHashMap(); + private LinkedHashMap cfdjPref = new LinkedHashMap(); + private LinkedHashMap lovPositionMap = new LinkedHashMap(); + private LinkedHashMap positionFieldMap = new LinkedHashMap(); + private LinkedHashMap widtheMap = new LinkedHashMap(); + //public static final int[] HEADERWIDTH = new int[] { 50, 100, 200, 200, 100, 100, 80, 80, 100, 150, 150, 150, 150,150, 150, 150, 150, 150, 150 }; + private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + private DefaultTableModel dtm1; + private JComboBox cfdJComboBox = new JComboBox(); + private DateButton jhksB; + private DateButton jhksS; + private DateButton jhwcB; + private DateButton jhwcS; + private JTextField idField = new JTextField(); + private JButton ssButton = new JButton("搜索"); + private JButton ckButton = new JButton("查看任务分配表"); + private JButton qrqdButton = new JButton("确认启动"); + private JButton gbButton = new JButton("关闭"); + private static ArrayList dateConnList = new ArrayList(); + private String pref; + private String taskName; + private ArrayList canWriteColume = new ArrayList(); + private ArrayList sqlField = new ArrayList(); + public QDRWDialog(TCSession session,String pref,String taskName) { + // TODO Auto-generated constructor stub + this.session = session; + this.pref = pref; + this.taskName = taskName; + initUI(); + } + + public void initUI() { + // TODO Auto-generated method stub + this.setTitle("任务分配表"); + this.setLayout(new BorderLayout()); + + String[] prefs = session.getPreferenceService().getStringValues(pref); + if (prefs == null || prefs.length <= 0) { + MessageBox.post("首选项“"+pref+"”未配置!", "提示 ", MessageBox.INFORMATION); + return; + } + + //获取首选项匹配的类型 + String[] fields = session.getPreferenceService().getStringValues("Connor_ECRECNForm_Datbase_Config"); + if (fields == null || fields.length <= 0) { + MessageBox.post("请配置首选项“Connor_ECRECNForm_Datbase_Config”", "提示 ", MessageBox.INFORMATION); + return; + } + + + String[] split2 = fields[0].split(";"); + for (int j = 0; j < split2.length; j++) { + String[] split3 = split2[j].split("="); + positionFieldMap.put(split3[0],j); + if(split3.length == 3) { + + if(split3[0].contains("#")) { + String[] split = split3[0].split("#"); + fieldsMap.put(split[1],split3[1]); + colorList.add(j); + }else { + fieldsMap.put(split3[0],split3[1]); + } + if(split3[2].contains("%")) { + String[] split4 = split3[2].split("%"); + widtheMap.put(j, Integer.parseInt(split4[0])); + canWriteColume.add(j); + }else { + widtheMap.put(j, Integer.parseInt(split3[2])); + } + + } + + + else if(split3.length == 4) { + fieldsMap.put(split3[0],split3[1]); + System.out.println("split3[2]========"+split3[2]); + if(split3[2].contains("%")) { + String[] split4 = split3[2].split("%"); + widtheMap.put(j, Integer.parseInt(split4[0])); + System.out.println("split4[0]========"+split4[0]); + canWriteColume.add(j); + }else { + widtheMap.put(j, Integer.parseInt(split3[2])); + } + lovPositionMap.put(j,split3[3]); + } + + + + } + + System.out.println("canWriteColume====="+canWriteColume.size()); + System.out.println("fieldsMap====="+fieldsMap); + System.out.println("positionMap====="+lovPositionMap); + System.out.println("widtheMap====="+widtheMap); + Collection valuesCollection = fieldsMap.values(); + + // 将集合转换为数组 + header = valuesCollection.toArray(new String[0]); + + JPanel topPanel = getTopPanel(); + + JScrollPane pane = getTablePanel(); + pane.setBorder(BorderFactory.createTitledBorder("")); +// JPanel btnPanel = getRightPanel(); + + JPanel bottomPane = getBottomPanel(); + this.add(topPanel, BorderLayout.NORTH); + this.add(pane, BorderLayout.CENTER); + this.add(bottomPane, BorderLayout.SOUTH); + this.createActionEvent(); + this.pack(); + this.setPreferredSize(new Dimension(1850, 1000)); + this.validate(); + this.setVisible(true); + // 设置窗口在屏幕中心 +// Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); +// int x = (int) screensize.getWidth() / 2 - window.getWidth() / 2; +// int y = (int) screensize.getHeight() / 2 - window.getHeight() / 2; + this.setLocationRelativeTo(null); + + //设置列宽 + TableColumnModel colModel = table.getColumnModel(); + for (Entry map : widtheMap.entrySet()) { + colModel.getColumn(map.getKey()).setPreferredWidth(map.getValue()); + } + + } + + + public void createActionEvent() { + this.ssButton.addActionListener(this); + this.ckButton.addActionListener(this); + this.gbButton.addActionListener(this); + this.qrqdButton.addActionListener(this); + } + + // 查询部分 + private JPanel getTopPanel() { + // TODO Auto-generated method stub + JPanel topPanel = new JPanel(); + topPanel.setLayout(new PropertyLayout()); + + jhksB = new DateButton(null, "yyyy-MM-dd", false, false, false); + jhksB.setDate("未设置日期"); + jhksS = new DateButton(null, "yyyy-MM-dd", false, false, false); + jhksS.setDate("未设置日期"); + jhwcB = new DateButton(null, "yyyy-MM-dd", false, false, false); + jhwcB.setDate("未设置日期"); + jhwcS = new DateButton(null, "yyyy-MM-dd", false, false, false); + jhwcS.setDate("未设置日期"); + + topPanel.add("1.1.left.center", new JLabel("ID ")); + topPanel.add("1.2.left.center",idField); + topPanel.add("1.3.left.center", new JLabel(" 计划开始早于 ")); + topPanel.add("1.4.left.center",jhksB); + topPanel.add("1.5.left.center", new JLabel(" 计划开始晚于 ")); + topPanel.add("1.6.left.center",jhksS); + topPanel.add("1.7.left.center", new JLabel(" 计划完成早于 ")); + topPanel.add("1.8.left.center",jhwcB); + topPanel.add("1.9.left.center", new JLabel(" 计划完成晚于 ")); + topPanel.add("1.10.left.center",jhwcS); + topPanel.add("2.1.left.center", new JLabel(" ")); + return topPanel; + } + + // 查询部分 + private JPanel getBottomPanel() { + // TODO Auto-generated method stub + JPanel bottomPanel = new JPanel(); + bottomPanel.setLayout(new PropertyLayout()); + bottomPanel.add("1.1.left.center", new JLabel(" ")); + bottomPanel.add("1.2.left.center", ssButton); + bottomPanel.add("1.3.left.center", new JLabel(" ")); + bottomPanel.add("1.4.left.center", ckButton); + bottomPanel.add("1.5.left.center", new JLabel(" ")); + bottomPanel.add("1.6.left.center", qrqdButton); + bottomPanel.add("1.7.left.center", new JLabel(" ")); + bottomPanel.add("1.8.left.center", gbButton); + return bottomPanel; + } + + private JScrollPane getTablePanel() { + // TODO Auto-generated method stub + table = getjTable(null, null, header, null, false); + table.setRowHeight(30); +// table.setPreferredSize(new Dimension(1500,400)); + table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // 设置表格的自动调整模式为关闭自动调整 +// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//设置JTable的列宽随着列表内容的大小进行调整 +// table.setPreferredSize(new Dimension(1200,400)); + JScrollPane pane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + for (Entry map : lovPositionMap.entrySet()) { + JComboBox jComboBox = new JComboBox(); + String value = map.getValue(); + if(value.contains(",")) { + String[] split = value.split(","); + for (int i = 0; i < split.length; i++) { + jComboBox.addItem(split[i]); + } + }else { + jComboBox.addItem(value); + } + table.getColumnModel().getColumn(map.getKey()).setCellEditor(new DefaultCellEditor(jComboBox)); + } + pane.setPreferredSize(new Dimension(1800, 850)); + pane.setViewportView(table);// 为scrollPane指定显示对象为table + return pane; + } + + /*** + * Jtable通用方法 + * + * @param partsTable + * @param dtm + * @param titleNames + * @param values + * @return + */ + public JTable getjTable(JTable partsTable, DefaultTableModel dtm, Object[] titleNames, Object[][] values, + Boolean isTable2) { +// int simpleLen = 100; +// int totleLen = 1000; + if (partsTable == null) { + partsTable = new JTable(this.getTableModel(dtm, titleNames, values)); + partsTable.setRowHeight(20); + partsTable.getTableHeader().setReorderingAllowed(false); + partsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + RowSorter sorter = new TableRowSorter(partsTable.getModel()); + partsTable.setRowSorter(sorter); +// for (int i = 0; i < titleNames.length; i++) { +// if(i==2) { +// partsTable.getColumnModel().getColumn(i).setPreferredWidth(200); +// }else { +// partsTable.getColumnModel().getColumn(i).setPreferredWidth(120); +// } +// +// } + + } + return partsTable; + } + + public DefaultTableModel getTableModel(DefaultTableModel dtm, Object[] titleNames, Object[][] values) { + + dtm1 = null; + if (dtm == null) { + dtm1 = new DefaultTableModel(values, titleNames) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + } + return dtm1; + } + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + Object source = e.getSource(); + System.out.println("source==>+" + source); + + if (source.equals(this.gbButton)) { + dispose(); + } + else if(source.equals(this.ckButton)){ +// + }else if(source.equals(this.qrqdButton)){ + + }else if(source.equals(this.ssButton)){ + + + String condition = ""; + if(condition == null || condition.isEmpty()) { + MessageBox.post("请填写条件。", "提示", 2); + return; + } + String ids = idField.getText(); + if(ids != null && !ids.isEmpty()) { + if(ids.contains(";")) { + String[] split = ids.split(";"); + StringBuilder sqlIn = new StringBuilder(); + sqlIn.append("("); + for (int i = 0; i < split.length; i++) { + sqlIn.append("'"+split[i] +"',"); + } + //去掉最后一个, + sqlIn.setLength(sqlIn.length() - 1); + sqlIn.append(")"); + System.out.println("sqlIn======================"+sqlIn.toString()); + condition += "and ID IN "+sqlIn.toString(); + }else { + condition += "and ID='"+ids+"' "; + } + } + + + String[] value = session.getPreferenceService().getStringValues("LD_dbinfo2"); + + if (value == null || value.length == 0) { + MessageBox.post("首选项LD_dbinfo2配置有误,请检查。", "提示", 2); + return; + } else { + Collections.addAll(dateConnList, value); + } + + Set keySet = fieldsMap.keySet(); + String fieldsSql = ""; + for (String string : keySet) { + String[] split = string.split("\\."); + fieldsSql += split[1] + ","; + sqlField.add(split[1]); + } + fieldsSql = fieldsSql.substring(0, fieldsSql.length() - 1); + System.out.println("fieldsSql=========="+fieldsSql); + System.out.println("condition==================="+condition); + String sqlString = "SELECT " + fieldsSql + " FROM LY_CHANGETASSKFORM_DETAILS where 1=1 "+condition; + System.out.println(sqlString); + Connection conn = getConn(); + PreparedStatement stmt = null; + //存数据的map + LinkedHashMap>>> valueMap = new LinkedHashMap>>>(); + + try{ + stmt = conn.prepareStatement(sqlString); + ResultSet result = stmt.executeQuery(); + while (result.next()) { + String id = result.getString("ID"); + String xh = result.getString("XH"); + LinkedHashMap>> tempMap1 = null; + if(valueMap.containsKey(id)) { + tempMap1 = valueMap.get(id); + }else { + tempMap1 = new LinkedHashMap>>(); + } + + ArrayList> tempList = new ArrayList>(); + for (int i = 0; i < sqlField.size(); i++) { + LinkedHashMap fieldMap = new LinkedHashMap(); + fieldMap.put(sqlField.get(i),result.getString(i+1) == null? result.getString(i+1) : validateAndFormatDate(result.getString(i+1))); + tempList.add(fieldMap); + } + tempMap1.put(xh,tempList); + + } + System.out.println(valueMap.toString()); + + for (Entry>>> map : valueMap.entrySet()) { + ArrayList tableList = new ArrayList(); + for (Entry tempMap : fieldsMap.entrySet()) { + String pref = tempMap.getValue(); + String[] split = pref.split("\\."); + LinkedHashMap>> value2 = map.getValue(); + ArrayList> arrayList = value2.get(split[0]); + for (int i = 0; i < arrayList.size(); i++) { + LinkedHashMap linkedHashMap = arrayList.get(i); + if(linkedHashMap.containsKey(split[1])) { + tableList.add(linkedHashMap.get(split[1])); + System.out.println("linkedHashMap.get(split[1])==============="+linkedHashMap.get(split[1])); + } + } + } + dtm1.addRow(tableList.toArray(new Object[0])); + } + } catch (SQLException e1) { + e1.printStackTrace(); + } + + try { + if(stmt != null) { + stmt.close(); + } + if(conn != null) { + conn.close(); + } + + + } catch (SQLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + + } + + // 获取数据库连接 + public static Connection getConn() { + Connection conn = null; + try { + conn = DbPool.getConnection(dateConnList.get(0), dateConnList.get(1)); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return conn; + } + + public static String calculateDate(String dateString, int daysToAdd) { + // 定义日期格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + // 解析输入的日期字符串 + LocalDate date; + try { + date = LocalDate.parse(dateString, formatter); + } catch (DateTimeParseException e) { + throw new IllegalArgumentException("Invalid date format. Please use yyyy-MM-dd.", e); + } + + // 增加或减少天数 + LocalDate resultDate = date.plusDays(daysToAdd); + + // 格式化结果日期为字符串 + return resultDate.format(formatter); + } + + public String validateAndFormatDate(String input) { + // 定义输入和输出的日期格式 + DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); + DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + try { + // 尝试解析输入的日期时间字符串 + LocalDateTime dateTime = LocalDateTime.parse(input, inputFormatter); + + // 转换为只包含日期的LocalDate对象 + LocalDate date = dateTime.toLocalDate(); + + // 格式化结果日期为字符串 + return date.format(outputFormatter); + } catch (DateTimeParseException e) { + // 如果解析失败,说明输入不符合指定格式,返回原始字符串 + return input; + } + } + +} \ No newline at end of file diff --git a/src/com/langtech/plm/bg/QDRWHandler.java b/src/com/langtech/plm/bg/QDRWHandler.java new file mode 100644 index 0000000..d71c07b --- /dev/null +++ b/src/com/langtech/plm/bg/QDRWHandler.java @@ -0,0 +1,50 @@ +package com.langtech.plm.bg; + +import javax.swing.SwingUtilities; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFUIApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +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 QDRWHandler extends AbstractHandler { + + private AbstractAIFUIApplication app; + private TCSession session; +// private InterfaceAIFComponent target; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + app = AIFUtility.getCurrentApplication(); + session = (TCSession) app.getSession(); + String[] templates = session.getPreferenceService().getStringValues("Connor_TaskFormSummary_Config"); + if(templates != null && templates.length > 0) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + try { + new QDRWChooseDialog(templates,app); + //d.setModal(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + }else { + MessageBox.post("请配置首选项“Connor_TaskFormSummary_Config”!", "提示 ", MessageBox.INFORMATION); + } + + + return null; + } + +} diff --git a/src/com/langtech/plm/project/CalculateDialog.java b/src/com/langtech/plm/project/CalculateDialog.java new file mode 100644 index 0000000..e282d7e --- /dev/null +++ b/src/com/langtech/plm/project/CalculateDialog.java @@ -0,0 +1,690 @@ +package com.langtech.plm.project; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentMEOP; +import com.teamcenter.rac.kernel.TCComponentMEOPRevision; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.rac.util.PropertyLayout; +import com.teamcenter.rac.util.UIUtilities; + +public class CalculateDialog extends JFrame implements ActionListener { + /** + * + */ + private static final long serialVersionUID = 1L; + + private AbstractAIFApplication application; + private TCComponentMEOPRevision meop; + private TCSession session; + + TCComponentItemRevision rawMaterialRevision; + + //打印界面控件 + //图纸零件轮廓直径D + private JLabel zjdLabel; + private JTextField zjdTextField; + //图纸零件轮廓长 + private JLabel lkcLabel; + private JTextField lkcTextField; + //切断用长度 + private JLabel qdycdLabel; + private JTextField qdycdTextField; + //车端面用长度 + private JLabel cdmycdLabel; + private JTextField cdmycdTextField; + //夹头用长度 + private JLabel jtycdLabel; + private JTextField jtycdTextField; + //可制零件数 + private JLabel kzljsLabel; + private JTextField kzljsTextField; + //规格 + private JLabel ggLabel; + private JTextField ggTextField; + //材料牌号 + private JLabel clphLabel; + private JTextField clphTextField; + + //计算结果控件 + //总长 + private JLabel zcLabel; + private JTextField zcTextField; + //单件长度 + private JLabel djcdLabel; + private JTextField djcdTextField; + //单件重量 + private JLabel djzlLabel; + private JTextField djzlTextField; + //标准工时 + private JLabel bzgsLabel; + private JTextField bzgsTextField; + //辅助工时 + private JLabel fzgsLabel; + private JTextField fzgsTextField; + + //计算按钮 + private JButton calculateButton; + //同步按钮 + private JButton syncButton; + //取消按钮 + private JButton celButton; + + //密度 + private String density; + //横截面 + private String crossSection; + //辅助时间 + private String auxiliaryTime; + //固定时间 + private String fixedTime; + //切割时间 + private String cuttingTime; + + + public CalculateDialog(AbstractAIFApplication application,TCComponentMEOPRevision meop) throws TCException { + this.application = application; + this.meop = meop; + this.session = (TCSession) application.getSession(); + initUI(); + getProperties(this.meop); + } + + + private JPanel getTopPanel() { + JPanel centerPanel = new JPanel(new PropertyLayout()); + centerPanel.add("1.1.left.top",this.zjdLabel); + centerPanel.add("1.2.left.top",this.zjdTextField); + centerPanel.add("2.1.left.top",this.lkcLabel); + centerPanel.add("2.2.left.top",this.lkcTextField); + centerPanel.add("3.1.left.top",this.qdycdLabel); + centerPanel.add("3.2.left.top",this.qdycdTextField); + centerPanel.add("4.1.left.top",this.cdmycdLabel); + centerPanel.add("4.2.left.top",this.cdmycdTextField); + centerPanel.add("5.1.left.top",this.jtycdLabel); + centerPanel.add("5.2.left.top",this.jtycdTextField); + centerPanel.add("6.1.left.top",this.kzljsLabel); + centerPanel.add("6.2.left.top",this.kzljsTextField); + centerPanel.add("7.1.left.top",this.ggLabel); + centerPanel.add("7.2.left.top",this.ggTextField); + centerPanel.add("8.1.left.top",this.clphLabel); + centerPanel.add("8.2.left.top",this.clphTextField); + + centerPanel.add("1.3.left.top",this.zcLabel); + centerPanel.add("1.4.left.top",this.zcTextField); + centerPanel.add("2.3.left.top",this.djcdLabel); + centerPanel.add("2.4.left.top",this.djcdTextField); + centerPanel.add("3.3.left.top",this.djzlLabel); + centerPanel.add("3.4.left.top",this.djzlTextField); + centerPanel.add("4.3.left.top",this.bzgsLabel); + centerPanel.add("4.4.left.top",this.bzgsTextField); + centerPanel.add("5.3.left.top",this.fzgsLabel); + centerPanel.add("5.4.left.top",this.fzgsTextField); + centerPanel.add("6.3.left.top",this.calculateButton); + + return centerPanel; + } + + /** + * 设置界面属性条目 + */ + private void setPanelProperties() { + this.zjdLabel = new JLabel("图纸零件轮廓直径D"); + this.lkcLabel = new JLabel("图纸零件轮廓长"); + this.qdycdLabel = new JLabel("切断用长度"); + this.cdmycdLabel = new JLabel("车端面用长度"); + this.jtycdLabel = new JLabel("夹头用长度"); + this.kzljsLabel = new JLabel("可制零件数"); + this.ggLabel = new JLabel("规格"); + this.clphLabel = new JLabel("材料牌号"); + this.zcLabel = new JLabel("总长"); + this.djcdLabel = new JLabel("单件长度"); + this.djzlLabel = new JLabel("单件重量"); + this.bzgsLabel = new JLabel("标准工时"); + this.fzgsLabel = new JLabel("辅助工时"); + + this.zjdTextField = new JTextField(32); + this.lkcTextField = new JTextField(32); + this.qdycdTextField = new JTextField(32); + this.cdmycdTextField = new JTextField(32); + this.jtycdTextField = new JTextField(32); + this.kzljsTextField = new JTextField(32); + this.ggTextField = new JTextField(32); + this.ggTextField.setEditable(false); + this.ggTextField.setBackground(new Color(200, 200, 200)); + this.clphTextField = new JTextField(32); + this.clphTextField.setEditable(false); + this.ggTextField.setBackground(new Color(200, 200, 200)); + this.zcTextField = new JTextField(32); + this.djcdTextField = new JTextField(32); + this.djzlTextField = new JTextField(32); + this.bzgsTextField = new JTextField(32); + this.fzgsTextField = new JTextField(32); + + this.calculateButton = new JButton("计算"); + this.syncButton = new JButton("同步"); + this.celButton = new JButton("取消"); + } + + /** + * 获取底部按钮 + * @return + */ + private JPanel getButtomPanel() { + JPanel bottomPanel = new JPanel(new FlowLayout(1)); +// bottomPanel.add(this.calculateButton); + bottomPanel.add(this.syncButton); + bottomPanel.add(this.celButton); + + return bottomPanel; + } + + /** + * 初始化图形界面 + */ + private void initUI() { + this.setTitle("材料定额及工时计算"); + this.setSize(500, 500); + this.setLayout(new BorderLayout()); + + setPanelProperties(); + + JPanel centerPanel = getTopPanel(); + + JPanel bottomPanel = getButtomPanel(); + + this.add(centerPanel,BorderLayout.CENTER); + this.add(bottomPanel,BorderLayout.SOUTH); + + //添加事件 + this.calculateButton.addActionListener(this); + this.syncButton.addActionListener(this); + this.celButton.addActionListener(this); + + //放到屏幕中央 + UIUtilities.centerToScreen(this); + this.setVisible(true); + + } + + /** + * 获取所选MEOP对象的属性,并赋值给输入框 + * @param meop + * @throws TCException + */ + private void getProperties(TCComponentMEOPRevision meop) throws TCException { + String outlineDiameter = meop.getStringProperty("ly6_outlineDiameter"); + String outlineLength = meop.getStringProperty("ly6_outlineLength"); + String cuttingLength = meop.getStringProperty("ly6_cuttingLength"); + String transverseLength = meop.getStringProperty("ly6_transverseLength"); + String colletLength = meop.getStringProperty("ly6_colletLength"); + String manufacturingQuantity =meop.getStringProperty("ly6_manufacturableQuantity"); + //规格和牌号单独从bomline下的子项中取得: + String specifications = null; + String brandNum = null; +// String specifications = meop.getStringProperty("ly6_specifications"); +// String brandNum = meop.getStringProperty("ly6_material"); + TCComponentItem item = meop.getItem(); + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + // 创建视图:传入参数-版本规则(精确、具有状态···),不给则获取默认规则 + TCComponentBOMWindow view = winType.create(null); + // 发送BOM,即:创建BOM。将item对象发送到BOM,即为创建了一个BOM行 args:item对象 版本对象 ... + TCComponentBOMLine topBomLine = view.setWindowTopLine(item, meop, null, null); + topBomLine.lock(); + if (topBomLine.hasChildren()) { + System.out.println("dialog当前对象存在bom子行!"); + AIFComponentContext[] childrens = topBomLine.getChildren(); + int tag = 0; + for (AIFComponentContext children : childrens) { + TCComponentBOMLine bomLine = (TCComponentBOMLine)children.getComponent(); + TCComponentItemRevision itemRevision = bomLine.getItemRevision(); + String childType = itemRevision.getType(); + System.out.println("当前通过bomline子项获取到子项类型:"+childType); + if (childType.equals("LY6_RawMaterial") || childType.equals("LY6_RawMaterialRevision")) { + System.out.println("成功获取到当前对象关联的“原材料”对象!"); + specifications = itemRevision.getStringProperty("ly6_specifications"); + brandNum = itemRevision.getStringProperty("ly6_material"); + System.out.println("获取到规格:"+specifications); + System.out.println("获取到牌号:"+brandNum); + tag ++; + break; + } + } + if (tag == 0) {//bomline的子项中没有类型为:LY6_RawMaterialRevision的对象 + MessageBox.post("未绑定原材料对象","提示",MessageBox.INFORMATION); + //todo burangjisuan + topBomLine.unlock(); + view.close(); + //关闭 + this.setVisible(false); + //释放 + this.dispose(); + return; + } + }else { + MessageBox.post("未绑定原材料对象","提示",MessageBox.INFORMATION); + //todo burangjisuan + topBomLine.unlock(); + view.close(); + //关闭 + this.setVisible(false); + //释放 + this.dispose(); + return; + } + topBomLine.unlock(); + view.close(); + + + this.zjdTextField.setText(outlineDiameter != null ? outlineDiameter : ""); + this.lkcTextField.setText(outlineLength != null ? outlineLength : ""); + this.qdycdTextField.setText(cuttingLength != null ? cuttingLength : ""); + this.cdmycdTextField.setText(transverseLength != null ? transverseLength : ""); + this.jtycdTextField.setText(colletLength != null ? colletLength : ""); + this.kzljsTextField.setText(manufacturingQuantity != null ? manufacturingQuantity : ""); + this.ggTextField.setText(specifications != null ? specifications : ""); + this.clphTextField.setText(brandNum != null ? brandNum : ""); + } + + + /** + * 计算总长 + * @return + */ + private String calculateTotalLength() { + // 获取各个 TextField 的内容 + String lkcText = this.lkcTextField.getText(); + String qdycdText = this.qdycdTextField.getText(); + String cdmycdText = this.cdmycdTextField.getText(); + String kzljsText = this.kzljsTextField.getText(); + String jtycdText = this.jtycdTextField.getText(); + + // 将字符串转换为数值 + double lkcValue = Double.parseDouble(lkcText); + double qdycdValue = Double.parseDouble(qdycdText); + double cdmycdValue = Double.parseDouble(cdmycdText); + double kzljsValue = Double.parseDouble(kzljsText); + double jtycdValue = Double.parseDouble(jtycdText); + + // 计算结果 + double result = (lkcValue + qdycdValue + cdmycdValue) * kzljsValue + jtycdValue; + System.out.println("图纸轮廓长:"+lkcValue+"切断用长度:"+qdycdValue+"车端面用长度:"+cdmycdValue+"可制零件数:"+kzljsValue+"夹头用长度:"+jtycdValue); + + return String.valueOf(result); + } + + /** + * 计算单件长度 + * @return + */ + private String calculateSingleLength(){ + String zcText = this.zcTextField.getText(); + String kzljsText = this.kzljsTextField.getText(); + + double zcValue = Double.parseDouble(zcText); + double kzljsValue = Double.parseDouble(kzljsText); + if (kzljsValue == 0){ + System.out.println("可制零件数 is 0"); + } + double result = zcValue / kzljsValue; + System.out.println("总长:"+zcValue+"可制零件数:"+kzljsValue); + return String.valueOf(result); + } + + /** + * 根据首选项中的uid获取数据集(EXCEL) + * 根据uid获取item对象,获取该对象下的 + * 根据“直径”读取EXCEL表中参与计算的必要条目:辅助工时和标准工时 + * @throws Exception + */ + private void getDataset(){ + System.out.println("getDataset"); + TCPreferenceService preferenceService = session.getPreferenceService(); + String itemId = preferenceService.getStringValue("LY6_MEOPTypeTime"); + + InterfaceAIFComponent[] resultComponents; + try { + resultComponents = session.search("零组件...", new String[] {"零组件 ID"}, new String[] {itemId}); + + InterfaceAIFComponent component = resultComponents[0]; + if (component instanceof TCComponentItem){ + TCComponentItem item = (TCComponentItem) component; + //读取item下已发布最新版本规范关系下的MSEXCEL数据集 + TCComponentItemRevision[] releasedItemRevisions = item.getReleasedItemRevisions(); + int releaseRevNum = releasedItemRevisions.length; + if (releaseRevNum == 0) { + System.out.println("错误:当前对象下不存在发布版本"); + } + TCComponentItemRevision tcComponentItemRevision = releasedItemRevisions[releaseRevNum - 1]; + + //获取当前版本的规范关系下的数据集 + TCComponent[] referenceListProperty = tcComponentItemRevision.getReferenceListProperty("IMAN_specification"); + if(referenceListProperty.length>0) { + //获取数据集下具体的引用文件 + TCComponentTcFile[] tcFiles = ((TCComponentDataset)referenceListProperty[0]).getTcFiles(); + File file = tcFiles[0].getFmsFile(); + // 根据横截面积获取数据集-excel表中,对应的条目数据:辅助时间、固定时间、切割时间 + FileInputStream fis = new FileInputStream(file); + Workbook workbook = new HSSFWorkbook(fis); + Sheet sheet = workbook.getSheetAt(0); + //从第3条开始逐行数据(前两条是标题和首行栏) + for (int i = 2; i < sheet.getPhysicalNumberOfRows(); i++) { + Row row = sheet.getRow(i); + //获取表中每行的第一个值,即:直径 + double diam = row.getCell(0).getNumericCellValue(); + // 根据规格匹配数据集表中的直径 + if (diam == Double.parseDouble(this.ggTextField.getText())){ + System.out.println("=========》直径匹配成功!开始获取辅助工时和标准工时"+"=========》当前行号:"+(i+1)+",当前行的直径:"+diam); + //获取第11列的值:标准工时 + this.bzgsTextField.setText(row.getCell(10).getStringCellValue()); + //获取第12列的值:辅助工时 + this.fzgsTextField.setText(row.getCell(11).getStringCellValue()); + break; + } + } + } + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } + + /** + * 计算辅助工时 + * @return + */ + private String calculateAssistTime() { + String result = null; + double kzljsNum = Double.parseDouble(this.kzljsTextField.getText()); + if (kzljsNum > 0){ + double auxiliaryTimeNum = Double.parseDouble(this.auxiliaryTime); + double fixedTimeNum = Double.parseDouble(this.fixedTime); + + double resultNum = Math.round((auxiliaryTimeNum + fixedTimeNum) / kzljsNum / 60 * 100.0) / 100.0; + System.out.println("辅助时间:"+auxiliaryTimeNum+",固定时间:"+fixedTimeNum+",可制零件数:"+kzljsNum); + result = String.valueOf(resultNum); + + } + return result; + + } + + /** + * 计算标准工时 + * @return + */ + private String calculateStandardTime() { + String result = null; + double kzljsNum = Double.parseDouble(this.kzljsTextField.getText()); + if (kzljsNum > 0){ + System.out.println("=========>获取到的切割时间:"+this.cuttingTime); + double cuttingTimeNum = Double.parseDouble(this.cuttingTime); + + double resultNum = Math.round((cuttingTimeNum / kzljsNum / 60) * 100.0) / 100.0; + System.out.println("切割时间:"+cuttingTimeNum+",可制零件数:"+kzljsNum); + result = String.valueOf(resultNum); + } + return result; + } + + /** + * 获取密度和截面 + * @throws TCException + */ + private void getDensityAndCrossSection() throws TCException { + System.out.println("=========>开始获取密度和横截面:getDensityAndCrossSection"); + +// 1.获取当前选中MEOP对象的BOM行 + TCComponentMEOP meopItem = (TCComponentMEOP) meop.getItem(); + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) this.session.getTypeComponent("BOMWindow"); + TCComponentBOMWindow view = winType.create(null); + TCComponentBOMLine bomLine = view.setWindowTopLine(meopItem, meop, null, null); +// 2.遍历BOM行,根据“规格”和“材料”检索符合要求的唯一原材料对象 + throughBomline(bomLine); + + view.close(); + } + + /** + * 循环遍历当前bomline下关联的子行,获取符合要求的bom对应的原材料对象,并获取对应的密度和横截面属性 + * @param topBomLine 当前BOM行 + */ + private void throughBomline(TCComponentBOMLine topBomLine) throws TCException{ + // 3.获取原材料对象的密度和横截面 + boolean hasChildren = topBomLine.hasChildren(); + if (hasChildren) { + AIFComponentContext[] childrens = topBomLine.getChildren(); + for (AIFComponentContext children : childrens) { + TCComponentBOMLine bomLine = (TCComponentBOMLine) children.getComponent(); + //获取当前bom的事例类型,若是投料,则到当前bom对应的是原材料对象 + String propertyValue = bomLine.getProperty("bl_occ_type"); + if ("投料".equals(propertyValue)) { + //通过原材料对象获取密度和横截面 + this.rawMaterialRevision = bomLine.getItemRevision(); + String densityString = rawMaterialRevision.getProperty("ly6_density"); + String crossSectionString = rawMaterialRevision.getProperty("ly6_crossSection"); + System.out.println("==========》成功取得当前原材料对象对应的密度:"+densityString+",横截面:"+crossSectionString); + + this.density = densityString != null ? densityString : ""; + this.crossSection = crossSectionString != null ? crossSectionString : ""; + System.out.println("000"); + break; + } + throughBomline(bomLine); + } + } + + } + + + /** + * 计算单件重量 + * @return + * @throws TCException + */ + private String calculateWeight(){ + System.out.println("calculateWeight"); + //通过获取当前选中对象的bom下关联的原材料对象,获取其密度和横截面 + try { + getDensityAndCrossSection(); + } catch (TCException e) { + e.printStackTrace(); + } + //获取横截面和密度、单件长度,计算单件重量 + double crossSectionNum = Double.parseDouble(this.crossSection); + double densityNum = 0; + if (this.density.contentEquals("")) { + densityNum = 0; + }else { + densityNum = Double.parseDouble(this.density); + } + double siglengthNum = Double.parseDouble(this.djcdTextField.getText()); + System.out.println("53456"); + double result = crossSectionNum * densityNum * siglengthNum; + System.out.println("横截面:"+crossSectionNum+",密度:"+densityNum+",单件长度:"+siglengthNum); + return String.valueOf(result); + } + + /** + * 反写属性到对应的对象 + * @throws TCException + */ + private void saveProperty() throws TCException { + try { + meop.setProperty("ly6_specifications", this.ggTextField.getText() == null ? "" : this.ggTextField.getText()); +// rawMaterialRevision.setProperty("ly6_specifications", this.ggTextField.getText() == null ? "" : this.ggTextField.getText()); + meop.setProperty("ly6_totalLenght", this.zcTextField.getText() == null ? "" : this.zcTextField.getText()); + meop.setProperty("ly6_singleLength", this.djcdTextField.getText() == null ? "" : this.djcdTextField.getText()); + meop.setProperty("ly6_weight", this.djzlTextField.getText() == null ? "" : this.djzlTextField.getText()); + meop.setProperty("ly6_standardTime", this.bzgsTextField.getText() == null ? "" : this.bzgsTextField.getText()); + meop.setProperty("ly6_auxiliaryTime", this.fzgsTextField.getText() == null ? "" : this.fzgsTextField.getText()); +// rawMaterialRevision.setProperty("ly6_material", this.clphTextField.getText() == null ? "" : this.clphTextField.getText()); + meop.setProperty("ly6_brandNum", this.clphTextField.getText() == null ? "" : this.clphTextField.getText()); + meop.setProperty("ly6_outlineDiameter", this.zjdTextField.getText() == null ? "" : this.zjdTextField.getText()); + meop.setProperty("ly6_outlineLength", this.lkcTextField.getText() == null ? "" : this.lkcTextField.getText()); + meop.setProperty("ly6_cuttingLength", this.qdycdTextField.getText() == null ? "" : this.qdycdTextField.getText()); + meop.setProperty("ly6_transverseLength", this.cdmycdTextField.getText()== null ? "" : this.cdmycdTextField.getText()); + meop.setProperty("ly6_colletLength", this.jtycdTextField.getText() == null ? "" : this.jtycdTextField.getText()); + meop.setProperty("ly6_manufacturableQuantity", this.kzljsTextField.getText() == null ? "" : this.kzljsTextField.getText()); + }catch (Exception e){ + System.out.println(e.getMessage()); + e.printStackTrace(); + } + } + + /** + * 检查M物料下是否已经挂载原材料 + * @throws TCException + */ + private void checkMaterial() throws TCException { + try { + System.out.println("开始检查M物料下的挂载情况·········"); + boolean isGZ=false; + TCComponent[] whereUsed = meop.whereUsed((short) 0); + for (TCComponent tcComponent : whereUsed) { + //获取到当前工序对象的父级对象-tcComponent + String mepRevisionType = tcComponent.getStringProperty("object_type"); + //获取首选项中的工艺对象类型,进行匹配 + TCSession session = (TCSession) this.application.getSession(); + TCPreferenceService preferenceService = session.getPreferenceService(); + //根据首选项的名称-C8MyPreference,获取首选项值 + String value = preferenceService.getStringValue("LY6_MEPType"); + String[] strings = value.split(","); + for (int i = 0; i < whereUsed.length; i++) { + //工艺对象类型匹配,进行:原材料对象比对 + if (strings[i].equals(mepRevisionType)) { + System.out.println("========>工艺类型匹配成功"); + if (tcComponent instanceof TCComponentItemRevision) { + System.out.println("====>获取到的工艺对象:"+tcComponent.getObjectString()); + TCComponentItemRevision mepRevision = (TCComponentItemRevision) tcComponent; + //获取工艺对象下的物料/制造对象:relatedRevision\\relatedItem + TCComponent relatedComponent = mepRevision.getRelatedComponent("IMAN_METarget"); + TCComponentItemRevision relatedRevision = (TCComponentItemRevision) relatedComponent; + TCComponentItem relatedItem = relatedRevision.getItem(); + + //检查当前物料对象下是否挂在了原材料对象 + TCComponentBOMWindowType winType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + TCComponentBOMWindow view = winType.create(null); + //获取物料对象/制造对象对应的bomline + TCComponentBOMLine bomLine = view.setWindowTopLine(relatedItem, relatedRevision, null, null); + //遍历该物料制造对象的bomline下是否挂在了原材料对象 + if (bomLine.hasChildren()) { + AIFComponentContext[] childrens = bomLine.getChildren(); + for(AIFComponentContext children:childrens) { + TCComponentBOMLine childrenBomLine = (TCComponentBOMLine) children.getComponent(); + TCComponentItemRevision itemRevision = childrenBomLine.getItemRevision(); + String uidTag = itemRevision.getUid(); + String materialRevUid = this.rawMaterialRevision.getUid(); + if (uidTag.equals(materialRevUid)) { + System.out.println("M物料对象下已经挂载原材料对象············"); + //M物料对象下挂载了原材料对象 + isGZ = true; + break; + } + } + } + //M物料对象下没有挂载原材料对象 + if (!isGZ) { + System.out.println("M物料对象下没有挂载原材料对象,开始挂载······"); + view.lock(); + TCComponentItem materialItem = this.rawMaterialRevision.getItem(); + bomLine.add(materialItem,this.rawMaterialRevision,null,false,""); + bomLine.save(); + view.unlock(); + } + // BOMWindow用完后必须关闭! + view.close(); + }else { + System.out.println("非版本对象异常"); + } + break; + } + } + } + }catch (Exception e){ + e.printStackTrace(); + System.out.println(e.getMessage()); + } + } + + /** + * 事件处理:监听按钮的点击事件 + */ + @Override + public void actionPerformed(ActionEvent e) { + Object sourceObject = e.getSource(); + //如果点击“计算”按钮 + if(sourceObject.equals(this.calculateButton)) { + try { + //长度计算 + this.zcTextField.setText(calculateTotalLength()); + this.djcdTextField.setText(calculateSingleLength()); + // 单件重量计算 + this.djzlTextField.setText(calculateWeight()); + // 工时计算 + getDataset(); +// this.bzgsTextField.setText(calculateStandardTime()); +// this.fzgsTextField.setText(calculateAssistTime()); + }catch (Exception e1){ + MessageBox.post("计算失败,请检查属性或手动维护", "提示", MessageBox.ERROR); + e1.printStackTrace(); + } + } else if (sourceObject.equals(this.syncButton)) { + //如果点击“同步”按钮,属性反写 + try { + saveProperty(); + //检查M物料 + checkMaterial(); + MessageBox.post("同步成功", "结果", MessageBox.INFORMATION); + + this.setVisible(false); + this.dispose(); + } catch (TCException e1) { + e1.printStackTrace(); + } + }else { + //如果点击“取消”按钮 + //关闭 + this.setVisible(false); + //释放 + this.dispose(); + } + } +} diff --git a/src/com/langtech/plm/project/CalculateHandler.java b/src/com/langtech/plm/project/CalculateHandler.java new file mode 100644 index 0000000..891d273 --- /dev/null +++ b/src/com/langtech/plm/project/CalculateHandler.java @@ -0,0 +1,121 @@ +package com.langtech.plm.project; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentMEOP; +import com.teamcenter.rac.kernel.TCComponentMEOPRevision; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +import java.sql.SQLOutput; +import java.util.ArrayList; +import java.util.List; + +public class CalculateHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); + TCSession session = (TCSession) app.getSession(); + + try { + new Thread(){ + @Override + public void run() { +// TODO 1.获取选中对象类型和工序名称 + //获取选中对象的拼接字符串 + InterfaceAIFComponent selectComponent = app.getTargetContext().getComponent(); +// 获取选中对象的类型和名称 + String type = selectComponent.getType(); + String name; + boolean existTag = false; + InterfaceAIFComponent[] resultComponents = null; + System.out.println("当前选中对象类型type:"+type); + + try { + //TODO 获取选中对象的type如果是Mfg0BvrOperation则说明是工艺构建器下的对象,可通过真实名称:bl_item_item_id获取选中对象的零组件ID,以此获得该零组件的类型 + if (type.equals("Mfg0BvrOperation")) { + List entryNames = new ArrayList(); + List entryValues = new ArrayList(); + String lzj_id = selectComponent.getProperty("bl_item_item_id"); + String lzj_rev = selectComponent.getProperty("bl_rev_item_revision_id"); + System.out.println("工艺构建器下选中对象的零组件ID="+lzj_id); + entryNames.add("零组件 ID"); + entryNames.add("版本"); + entryValues.add(lzj_id); + entryValues.add(lzj_rev); + resultComponents = session.search( + "零组件版本...", + entryNames.toArray(new String[entryNames.size()]), + entryValues.toArray(new String[entryNames.size()])); + if(resultComponents != null) { + type = resultComponents[0].getType(); + System.out.println("获取到制造工艺规划器下对象的类型="+type); + + }else { + MessageBox.post("没有查询到制造工艺规划器下对象对应的零组件","查询结果",MessageBox.INFORMATION); + } + } + + name = selectComponent.getProperty("object_name"); +// 2.获取首选项字符串数组,并遍历比较(当前选中对象的类型+工序名称拼接字符串) + TCPreferenceService preferenceService = session.getPreferenceService(); + + //根据首选项的名称-C8MyPreference,获取首选项值 + String[] preferenceValues = preferenceService.getStringValues("LY6_MEOPType"); + if (preferenceValues == null) { + MessageBox.post("首选项为空,请先设置首选项!","提示",MessageBox.INFORMATION); + } + for (String string : preferenceValues){ + System.out.println("首选项LY6_MEOPType配置的信息string:"+string); + if (type.equals(string)){ + System.out.println("当前选中对象的类型与首选项配置类型匹配:"+type+"==>"+string); + existTag = true; + break; + } + } + + if (!existTag){ + //3.如果和首选项中的值不匹配,则弹出提示框,提示“对象类型不正确”,并返回 + System.out.println("对象类型不正确,当前选中对象type="+type); + MessageBox.post("对象类型不正确","提示",MessageBox.INFORMATION); + }else { + System.out.println("选中对象类型匹配!"); + TCComponentMEOPRevision rev = null; + if(selectComponent.getType().equals("Mfg0BvrOperation")) { + rev = (TCComponentMEOPRevision)resultComponents[0]; + }else { + //判断选中对象的是item还是版本,item则获取最新版本 + if (selectComponent instanceof TCComponentMEOP) { +// System.out.println("当前选中对象为TCComponentMEOP"); + TCComponentMEOP meopType = (TCComponentMEOP) selectComponent; + rev = (TCComponentMEOPRevision) meopType.getLatestItemRevision(); + }else if (selectComponent instanceof TCComponentMEOPRevision) { +// System.out.println("当前选中对象为TCComponentMEOPRevision"); + rev = (TCComponentMEOPRevision) selectComponent; + } + } +// System.out.println("========》选中的对象类型:"+type); + new CalculateDialog(app,rev); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + }.start(); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + +} diff --git a/src/com/langtech/plm/project/DateChooser.java b/src/com/langtech/plm/project/DateChooser.java deleted file mode 100644 index 6a18a93..0000000 --- a/src/com/langtech/plm/project/DateChooser.java +++ /dev/null @@ -1,700 +0,0 @@ -package com.langtech.plm.project; - -import java.awt.BasicStroke; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.GridLayout; -import java.awt.Point; -import java.awt.Polygon; -import java.awt.Stroke; -import java.awt.Toolkit; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Comparator; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.Popup; -import javax.swing.PopupFactory; -import javax.swing.SwingUtilities; -import javax.swing.event.AncestorEvent; -import javax.swing.event.AncestorListener; - -public class DateChooser extends JPanel { - private static final long serialVersionUID = 4529266044762990227L; - private Date initDate; - private Calendar now; - private Calendar select; - private JPanel monthPanel; - private DateChooser.JP1 jp1; - private DateChooser.JP2 jp2; - private DateChooser.JP3 jp3; - private DateChooser.JP4 jp4; - private Font font; - private final DateChooser.LabelManager lm; - private SimpleDateFormat sdf; - private boolean isShow; - private Popup pop; - private JComponent showDate; - - public static DateChooser getInstance() { - return new DateChooser(); - - - } - - public static DateChooser getInstance(Date date) { - return new DateChooser(date); - } - - public static DateChooser getInstance(String format) { - return new DateChooser(format); - } - - public static DateChooser getInstance(Date date, String format) { - return new DateChooser(date, format); - } - - DateChooser() { - this(new Date()); - } - - private DateChooser(Date date) { - this(date, "yyyy年MM月dd日"); - } - - private DateChooser(String format) { - this(new Date(), format); - } - - private DateChooser(Date date, String format) { - this.now = Calendar.getInstance(); - this.font = new Font("宋体", 0, 12); - this.lm = new DateChooser.LabelManager(); - this.isShow = false; - this.initDate = date; - this.sdf = new SimpleDateFormat(format); - this.select = Calendar.getInstance(); - this.select.setTime(this.initDate); - this.initPanel(); - } - - public void setEnabled(boolean b) { - super.setEnabled(b); - this.showDate.setEnabled(b); - } - - public Date getDate() { - return this.select.getTime(); - } - - public String getStrDate() { - return this.sdf.format(this.select.getTime()); - } - - public String getStrDate(String format) { - this.sdf = new SimpleDateFormat(format); - return this.sdf.format(this.select.getTime()); - } - - private void initPanel() { - this.monthPanel = new JPanel(new BorderLayout()); - this.monthPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE)); - JPanel up = new JPanel(new BorderLayout()); - up.add(this.jp1 = new DateChooser.JP1(), "North"); - up.add(this.jp2 = new DateChooser.JP2(), "Center"); - this.monthPanel.add(this.jp3 = new DateChooser.JP3(), "Center"); - this.monthPanel.add(up, "North"); - this.monthPanel.add(this.jp4 = new DateChooser.JP4(), "South"); - this.addAncestorListener(new AncestorListener() { - public void ancestorAdded(AncestorEvent event) { - } - - public void ancestorRemoved(AncestorEvent event) { - } - - public void ancestorMoved(AncestorEvent event) { - DateChooser.this.hidePanel(); - } - }); - } - - public void register(final JComponent showDate) { - this.showDate = showDate; - showDate.setRequestFocusEnabled(true); - showDate.addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent me) { - showDate.requestFocusInWindow(); - } - }); - this.setBackground(Color.WHITE); - this.add(showDate, "Center"); - this.setPreferredSize(new Dimension(90, 25)); - this.setBorder(BorderFactory.createLineBorder(Color.GRAY)); - showDate.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent me) { - if (showDate.isEnabled()) { - showDate.setCursor(new Cursor(12)); - showDate.setForeground(Color.RED); - } - - } - - public void mouseExited(MouseEvent me) { - if (showDate.isEnabled()) { - showDate.setCursor(new Cursor(0)); - showDate.setForeground(Color.BLACK); - } - - } - - public void mousePressed(MouseEvent me) { - if (showDate.isEnabled()) { - showDate.setForeground(Color.CYAN); - if (DateChooser.this.isShow) { - DateChooser.this.hidePanel(); - } else { - DateChooser.this.showPanel(showDate); - } - } - - } - - public void mouseReleased(MouseEvent me) { - if (showDate.isEnabled()) { - showDate.setForeground(Color.BLACK); - } - - } - }); - showDate.addFocusListener(new FocusListener() { - public void focusLost(FocusEvent e) { - DateChooser.this.hidePanel(); - } - - public void focusGained(FocusEvent e) { - } - }); - } - - private void refresh() { - this.jp1.updateDate(); - this.jp2.updateDate(); - this.jp3.updateDate(); - this.jp4.updateDate(); - SwingUtilities.updateComponentTreeUI(this); - } - - private void commit() { - if (this.showDate instanceof JTextField) { - ((JTextField) this.showDate).setText(this.sdf.format(this.select.getTime())); - } else if (this.showDate instanceof JLabel) { - ((JLabel) this.showDate).setText(this.sdf.format(this.select.getTime())); - } - - this.hidePanel(); - } - - private void hidePanel() { - if (this.pop != null) { - this.isShow = false; - this.pop.hide(); - this.pop = null; - } - - } - - private void showPanel(Component owner) { - if (this.pop != null) { - this.pop.hide(); - } - - Point show = new Point(0, this.showDate.getHeight()); - SwingUtilities.convertPointToScreen(show, this.showDate); - Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); - int x = show.x; - int y = show.y; - if (x < 0) { - x = 0; - } - - if (x > size.width - 295) { - x = size.width - 295; - } - - if (y >= size.height - 170) { - y -= 188; - } - - this.pop = PopupFactory.getSharedInstance().getPopup(owner, this.monthPanel, x, y); - this.pop.show(); - this.isShow = true; - } - - public static void main(String[] args) { - DateChooser dateChooser1 = getInstance("yyyy-MM-dd HH:mm"); - DateChooser dateChooser2 = getInstance("yyyy-MM-dd"); - JTextField showDate1 = new JTextField("单击选择日期"); - JLabel showDate2 = new JLabel("单击选择日期"); - dateChooser1.register(showDate1); - dateChooser2.register(showDate2); - JFrame jf = new JFrame("测试日期选择器"); - jf.add(showDate1, "North"); - jf.add(showDate2, "South"); - jf.pack(); - jf.setLocationRelativeTo((Component) null); - jf.setVisible(true); - jf.setDefaultCloseOperation(3); - } - - private class JP1 extends JPanel { - private static final long serialVersionUID = -5638853772805561174L; - JLabel yearleft; - JLabel yearright; - JLabel monthleft; - JLabel monthright; - JLabel center; - JLabel centercontainer; - - public JP1() { - super(new BorderLayout()); - this.setBackground(new Color(160, 185, 215)); - this.initJP1(); - } - - private void initJP1() { - this.yearleft = new JLabel(" <<", 0); - this.yearleft.setToolTipText("上一年"); - this.yearright = new JLabel(">> ", 0); - this.yearright.setToolTipText("下一年"); - this.yearleft.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); - this.yearright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); - this.monthleft = new JLabel(" <", 4); - this.monthleft.setToolTipText("上一月"); - this.monthright = new JLabel("> ", 2); - this.monthright.setToolTipText("下一月"); - this.monthleft.setBorder(BorderFactory.createEmptyBorder(2, 30, 0, 0)); - this.monthright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 30)); - this.centercontainer = new JLabel("", 0); - this.centercontainer.setLayout(new BorderLayout()); - this.center = new JLabel("", 0); - this.centercontainer.add(this.monthleft, "West"); - this.centercontainer.add(this.center, "Center"); - this.centercontainer.add(this.monthright, "East"); - this.add(this.yearleft, "West"); - this.add(this.centercontainer, "Center"); - this.add(this.yearright, "East"); - this.setPreferredSize(new Dimension(295, 25)); - this.updateDate(); - this.yearleft.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent me) { - JP1.this.yearleft.setCursor(new Cursor(12)); - JP1.this.yearleft.setForeground(Color.RED); - } - - public void mouseExited(MouseEvent me) { - JP1.this.yearleft.setCursor(new Cursor(0)); - JP1.this.yearleft.setForeground(Color.BLACK); - } - - public void mousePressed(MouseEvent me) { - DateChooser.this.select.add(1, -1); - JP1.this.yearleft.setForeground(Color.WHITE); - DateChooser.this.refresh(); - } - - public void mouseReleased(MouseEvent me) { - JP1.this.yearleft.setForeground(Color.BLACK); - } - }); - this.yearright.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent me) { - JP1.this.yearright.setCursor(new Cursor(12)); - JP1.this.yearright.setForeground(Color.RED); - } - - public void mouseExited(MouseEvent me) { - JP1.this.yearright.setCursor(new Cursor(0)); - JP1.this.yearright.setForeground(Color.BLACK); - } - - public void mousePressed(MouseEvent me) { - DateChooser.this.select.add(1, 1); - JP1.this.yearright.setForeground(Color.WHITE); - DateChooser.this.refresh(); - } - - public void mouseReleased(MouseEvent me) { - JP1.this.yearright.setForeground(Color.BLACK); - } - }); - this.monthleft.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent me) { - JP1.this.monthleft.setCursor(new Cursor(12)); - JP1.this.monthleft.setForeground(Color.RED); - } - - public void mouseExited(MouseEvent me) { - JP1.this.monthleft.setCursor(new Cursor(0)); - JP1.this.monthleft.setForeground(Color.BLACK); - } - - public void mousePressed(MouseEvent me) { - DateChooser.this.select.add(2, -1); - JP1.this.monthleft.setForeground(Color.WHITE); - DateChooser.this.refresh(); - } - - public void mouseReleased(MouseEvent me) { - JP1.this.monthleft.setForeground(Color.BLACK); - } - }); - this.monthright.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent me) { - JP1.this.monthright.setCursor(new Cursor(12)); - JP1.this.monthright.setForeground(Color.RED); - } - - public void mouseExited(MouseEvent me) { - JP1.this.monthright.setCursor(new Cursor(0)); - JP1.this.monthright.setForeground(Color.BLACK); - } - - public void mousePressed(MouseEvent me) { - DateChooser.this.select.add(2, 1); - JP1.this.monthright.setForeground(Color.WHITE); - DateChooser.this.refresh(); - } - - public void mouseReleased(MouseEvent me) { - JP1.this.monthright.setForeground(Color.BLACK); - } - }); - } - - private void updateDate() { - this.center.setText(DateChooser.this.select.get(1) + "年" + (DateChooser.this.select.get(2) + 1) + "月"); - } - } - - private class JP2 extends JPanel { - private static final long serialVersionUID = -8176264838786175724L; - - public JP2() { - this.setPreferredSize(new Dimension(295, 20)); - } - - protected void paintComponent(Graphics g) { - g.setFont(DateChooser.this.font); - g.drawString("星期日 星期一 星期二 星期三 星期四 星期五 星期六", 5, 10); - g.drawLine(0, 15, this.getWidth(), 15); - } - - private void updateDate() { - } - } - - private class JP3 extends JPanel { - private static final long serialVersionUID = 43157272447522985L; - - public JP3() { - super(new GridLayout(6, 7)); - this.setPreferredSize(new Dimension(295, 100)); - this.initJP3(); - } - - private void initJP3() { - this.updateDate(); - } - - public void updateDate() { - this.removeAll(); - DateChooser.this.lm.clear(); - Date temp = DateChooser.this.select.getTime(); - Calendar select = Calendar.getInstance(); - select.setTime(temp); - select.set(5, 1); - int index = select.get(7); - int sum = index == 1 ? 8 : index; - select.add(5, 0 - sum); - - for (int i = 0; i < 42; ++i) { - select.add(5, 1); - DateChooser.this.lm.addLabel(DateChooser.this.new MyLabel(select.get(1), select.get(2), select.get(5))); - } - - Iterator var6 = DateChooser.this.lm.getLabels().iterator(); - - while (var6.hasNext()) { - DateChooser.MyLabel my = (DateChooser.MyLabel) var6.next(); - this.add(my); - } - - select.setTime(temp); - } - } - - private class JP4 extends JPanel { - private static final long serialVersionUID = -6391305687575714469L; - - public JP4() { - super(new BorderLayout()); - this.setPreferredSize(new Dimension(295, 20)); - this.setBackground(new Color(160, 185, 215)); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日"); - final JLabel jl = new JLabel("今天: " + sdf.format(new Date())); - jl.setToolTipText("点击选择今天日期"); - this.add(jl, "Center"); - jl.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent me) { - jl.setCursor(new Cursor(12)); - jl.setForeground(Color.RED); - } - - public void mouseExited(MouseEvent me) { - jl.setCursor(new Cursor(0)); - jl.setForeground(Color.BLACK); - } - - public void mousePressed(MouseEvent me) { - jl.setForeground(Color.WHITE); - DateChooser.this.select.setTime(new Date()); - DateChooser.this.refresh(); - DateChooser.this.commit(); - } - - public void mouseReleased(MouseEvent me) { - jl.setForeground(Color.BLACK); - } - }); - } - - private void updateDate() { - } - } - - private class LabelManager { - private List list = new ArrayList(); - - public LabelManager() { - } - - public List getLabels() { - return this.list; - } - - public void addLabel(DateChooser.MyLabel my) { - this.list.add(my); - } - - public void clear() { - this.list.clear(); - } - - public void setSelect(DateChooser.MyLabel my, boolean b) { - Iterator var4 = this.list.iterator(); - - while (var4.hasNext()) { - DateChooser.MyLabel m = (DateChooser.MyLabel) var4.next(); - if (m.equals(my)) { - m.setSelected(true, b); - } else { - m.setSelected(false, b); - } - } - - } - - public void setSelect(Point p, boolean b) { - if (b) { - boolean findPrevious = false; - boolean findNext = false; - Iterator var6 = this.list.iterator(); - - while (var6.hasNext()) { - DateChooser.MyLabel mx = (DateChooser.MyLabel) var6.next(); - if (mx.contains(p)) { - findNext = true; - if (mx.getIsSelected()) { - findPrevious = true; - } else { - mx.setSelected(true, b); - } - } else if (mx.getIsSelected()) { - findPrevious = true; - mx.setSelected(false, b); - } - - if (findPrevious && findNext) { - return; - } - } - } else { - DateChooser.MyLabel temp = null; - Iterator var9 = this.list.iterator(); - - while (var9.hasNext()) { - DateChooser.MyLabel m = (DateChooser.MyLabel) var9.next(); - if (m.contains(p)) { - temp = m; - } else if (m.getIsSelected()) { - m.setSelected(false, b); - } - } - - if (temp != null) { - temp.setSelected(true, b); - } - } - - } - } - - private class MyLabel extends JLabel - implements Comparator, MouseListener, MouseMotionListener { - private static final long serialVersionUID = 3668734399227577214L; - private int year; - private int month; - private int day; - private boolean isSelected; - - public MyLabel(int year, int month, int day) { - super("" + day, 0); - this.year = year; - this.day = day; - this.month = month; - this.addMouseListener(this); - this.addMouseMotionListener(this); - this.setFont(DateChooser.this.font); - if (month == DateChooser.this.select.get(2)) { - this.setForeground(Color.BLACK); - } else { - this.setForeground(Color.LIGHT_GRAY); - } - - if (day == DateChooser.this.select.get(5)) { - this.setBackground(new Color(160, 185, 215)); - } else { - this.setBackground(Color.WHITE); - } - - } - - public boolean getIsSelected() { - return this.isSelected; - } - - public void setSelected(boolean b, boolean isDrag) { - this.isSelected = b; - if (b && !isDrag) { - int temp = DateChooser.this.select.get(2); - DateChooser.this.select.set(this.year, this.month, this.day); - if (temp == this.month) { - SwingUtilities.updateComponentTreeUI(DateChooser.this.jp3); - } else { - DateChooser.this.refresh(); - } - } - - this.repaint(); - } - - protected void paintComponent(Graphics g) { - if (this.day == DateChooser.this.select.get(5) && this.month == DateChooser.this.select.get(2)) { - g.setColor(new Color(160, 185, 215)); - g.fillRect(0, 0, this.getWidth(), this.getHeight()); - } - - if (this.year == DateChooser.this.now.get(1) && this.month == DateChooser.this.now.get(2) - && this.day == DateChooser.this.now.get(5)) { - Graphics2D gdx = (Graphics2D) g; - gdx.setColor(Color.RED); - Polygon p = new Polygon(); - p.addPoint(0, 0); - p.addPoint(this.getWidth() - 1, 0); - p.addPoint(this.getWidth() - 1, this.getHeight() - 1); - p.addPoint(0, this.getHeight() - 1); - gdx.drawPolygon(p); - } - - if (this.isSelected) { - Stroke s = new BasicStroke(1.0F, 2, 2, 1.0F, new float[] { 2.0F, 2.0F }, 1.0F); - Graphics2D gd = (Graphics2D) g; - gd.setStroke(s); - gd.setColor(Color.BLACK); - Polygon px = new Polygon(); - px.addPoint(0, 0); - px.addPoint(this.getWidth() - 1, 0); - px.addPoint(this.getWidth() - 1, this.getHeight() - 1); - px.addPoint(0, this.getHeight() - 1); - gd.drawPolygon(px); - } - - super.paintComponent(g); - } - - public boolean contains(Point p) { - return this.getBounds().contains(p); - } - - private void update() { - this.repaint(); - } - - public void mouseClicked(MouseEvent e) { - } - - public void mousePressed(MouseEvent e) { - this.isSelected = true; - this.update(); - } - - public void mouseReleased(MouseEvent e) { - Point p = SwingUtilities.convertPoint(this, e.getPoint(), DateChooser.this.jp3); - DateChooser.this.lm.setSelect(p, false); - DateChooser.this.commit(); - } - - public void mouseEntered(MouseEvent e) { - } - - public void mouseExited(MouseEvent e) { - } - - public void mouseDragged(MouseEvent e) { - Point p = SwingUtilities.convertPoint(this, e.getPoint(), DateChooser.this.jp3); - DateChooser.this.lm.setSelect(p, true); - } - - public void mouseMoved(MouseEvent e) { - } - - public int compare(DateChooser.MyLabel o1, DateChooser.MyLabel o2) { - Calendar c1 = Calendar.getInstance(); - c1.set(o1.year, o2.month, o1.day); - Calendar c2 = Calendar.getInstance(); - c2.set(o2.year, o2.month, o2.day); - return c1.compareTo(c2); - } - } -} diff --git a/src/com/langtech/plm/project/ProjectECRDialog.java b/src/com/langtech/plm/project/ProjectECRDialog.java deleted file mode 100644 index bcc15c9..0000000 --- a/src/com/langtech/plm/project/ProjectECRDialog.java +++ /dev/null @@ -1,404 +0,0 @@ -package com.langtech.plm.project; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Vector; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.table.DefaultTableModel; - -import org.apache.poi.xssf.usermodel.XSSFCell; -import org.apache.poi.xssf.usermodel.XSSFRow; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.jdesktop.swingx.JXDatePicker; -import com.teamcenter.rac.aif.AbstractAIFDialog; -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.TCComponentTcFile; -import com.teamcenter.rac.kernel.TCSession; -import com.teamcenter.rac.util.MessageBox; - -public class ProjectECRDialog extends AbstractAIFDialog { - private static final long serialVersionUID = 1L; - private TCSession session; - private JTextField field; - private JTextField dateAfterField; - private JTextField dateBeforeField; - private JButton searchBtn; - private JButton exportBtn; - private JTable impTable; - private DefaultTableModel impModel; - private Vector exports; - private Vector excludes; - private String[] tableHeader; - - public ProjectECRDialog(TCSession session, String[] options) throws Exception { - super(AIFUtility.getActiveDesktop()); - this.session = session; - Vector props = new Vector<>(); - this.exports = new Vector<>(); - setTitle("项目变更单查询"); -// 查询条目 - JLabel label = new JLabel("项目&产品名称"); - JLabel appDateLabel0 = new JLabel("申请日期早于"); - JLabel appDateLabel1 = new JLabel("申请日期晚于"); - - // 定义输入框 - field = new JTextField(); - dateAfterField = new JTextField(10); - dateBeforeField = new JTextField(10); - field.setPreferredSize(new Dimension(118, 23)); - - //日期选择器 - DateChooser dateAfterChooser = DateChooser.getInstance("yyyy-M-dd"); - dateAfterChooser.register(this.dateAfterField); - DateChooser dateBeforeChooser = DateChooser.getInstance("yyyy-M-dd"); - dateBeforeChooser.register(this.dateBeforeField); - - JPanel msgPanel = new JPanel(new FlowLayout()); - msgPanel.add(label); - msgPanel.add(field); - msgPanel.add(appDateLabel1);//申请日期晚于 - msgPanel.add(dateBeforeField); - msgPanel.add(appDateLabel0);//申请日期早于 - msgPanel.add(dateAfterField); - - - searchBtn = new JButton("查询"); - exportBtn = new JButton("导出"); - JPanel btnPanel = new JPanel(new FlowLayout()); - btnPanel.add(searchBtn); - btnPanel.add(exportBtn); - - JPanel topPanel = new JPanel(new BorderLayout()); - topPanel.add(BorderLayout.WEST, msgPanel); - topPanel.add(BorderLayout.EAST, btnPanel); -// 根据首选项配置的值获取表头信息 - tableHeader = new String[options.length-1]; - int[] weights = new int[options.length-1]; - for(int i=0; i props) { - - - searchBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent arg0) { - String dateString0 = dateBeforeField.getText(); - String dateString1 = dateAfterField.getText(); - try { - String project = field.getText(); - if(project.isEmpty() && dateString0.isEmpty() && dateString1.isEmpty()) { - MessageBox.post(ProjectECRDialog.this, "至少输入一个查询条件", "ERROR", MessageBox.ERROR); - return; - } - if(impModel.getRowCount()>0) { - for(int i=impModel.getRowCount(); i>0; i--) - impModel.removeRow(i-1); - } - Vector keyV = new Vector<>(); - Vector valueV = new Vector<>(); -// 封装查询条件:项目号、申请日期 - if (!project.isEmpty()) { - keyV.add("projnum"); - valueV.add(project); - }else if (!dateString0.isEmpty()) { - keyV.add("dateafter"); - valueV.add(dateString0+" 00:00"); - }else if (!dateString1.isEmpty()) { - keyV.add("datebefore"); - valueV.add(dateString1+" 23:59"); - } - - //调用查询构建器:条件查询的结果(ecn)-result - TCComponent[] result = TCUtil.query(session, "CONNOR_SearchProjectECN", keyV, valueV); - System.out.println("查询构建器共查询出"+result.length+"条数据"); - for(int i=0; i v = new Vector<>(); - for(String[] prop:props) { - if (prop[0].equals("序号")){ - v.add(impTable.getRowCount()+1+""); - } else if (prop[0].equals("ecn")) { - if (prop[1].equals("rev")){ - //ecn.rev.*:只能通过ecn版本对象取值 - v.add(ecn.getProperty(prop[2])); - } else if (prop[1].equals("master")) { - //ecn.master.*:只能通过ecnform取值 - v.add(ecnform.getProperty(prop[2])); - } - } else if (prop[0].equals("ecr")) { - if (prop[1].equals("rev")) { - v.add(ercBM); - } - }else if (prop[0].equals("状态")) { - // 获取ECN发布状态:发布-关闭,未发布-未关闭 - String releaseStatus = ecn.getProperty("date_released"); -// if (releaseStatus.equals("发布")){ - if (releaseStatus == null || releaseStatus.isEmpty()){ - //未发布状态 - v.add("未关闭"); - }else { - v.add("关闭"); - } - } - } - impModel.addRow(v); - } - } catch (Exception e1) { - e1.printStackTrace(); - MessageBox.post(ProjectECRDialog.this, "错误::"+e1.getMessage(), "ERROR", MessageBox.ERROR); - } - } - }); - exportBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent arg0) { - FileOutputStream output = null; - InputStream input = null; - try { - if(impTable.getRowCount()==0) - throw new Exception("表格内容为空,无法导出"); - TCComponentItem[] item = ((TCComponentItemType) session.getTypeService().getTypeComponent("Item")).findItems(id); - if(item==null || item.length==0) - throw new Exception("未找到模板Item"); - TCComponentDataset dataset = null; - AIFComponentContext[] contexts = item[0].getLatestItemRevision().getChildren(); - for(AIFComponentContext c : contexts) { - TCComponent child = (TCComponent) c.getComponent(); - if(child instanceof TCComponentDataset && child.isTypeOf("MSExcelX")) { - dataset = (TCComponentDataset) child; - break; - } - } - if(dataset == null) - throw new Exception("未找到模板数据集"); - System.out.println("export"); - TCComponentTcFile[] files = dataset.getTcFiles(); - if (files==null || files.length==0) - return; - File directory = TCUtil.saveExcelChooser(); - if(directory == null) - return; - String path = directory.getPath(); - if (!path.endsWith(".xlsx")) { - path = path+".xlsx"; - } - File file = files[0].getFile(directory.getParent()); - input = new FileInputStream(file); - XSSFWorkbook wb = new XSSFWorkbook(input); - XSSFSheet sheet = wb.getSheetAt(0); - XSSFRow row = sheet.getRow(0); - if(row == null) - row = sheet.createRow(0); - int col = 0; - for(int i=0; i boxes = new Vector<>(); - for(int i=0; i(); - for(JCheckBox box : boxes) { - if(!box.isSelected()) { - excludes.add(box.getText()); - } - } - dispose(); - } - }); - JButton cancelBtn = new JButton("取消"); - cancelBtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - excludes = null; - dispose(); - } - }); - JPanel btnPanel = new JPanel(new FlowLayout()); - btnPanel.add(okBtn); - btnPanel.add(cancelBtn); - - setLayout(new BorderLayout()); - add(BorderLayout.CENTER, boxPanel); - add(BorderLayout.SOUTH, btnPanel); - pack(); - setSize(new Dimension(200, 200)); - setDefaultLookAndFeelDecorated(true); - Dimension screen = getToolkit().getScreenSize(); - setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2); -// setAlwaysOnTop(true); - setVisible(true); - } - } -} \ No newline at end of file diff --git a/src/com/langtech/plm/project/ProjectECRHandler.java b/src/com/langtech/plm/project/ProjectECRHandler.java deleted file mode 100644 index 06f8c39..0000000 --- a/src/com/langtech/plm/project/ProjectECRHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.langtech.plm.project; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; - -import com.teamcenter.rac.aif.AIFDesktop; -import com.teamcenter.rac.aifrcp.AIFUtility; -import com.teamcenter.rac.kernel.TCSession; -import com.teamcenter.rac.util.MessageBox; - -//创建常规文件夹结构 -public class ProjectECRHandler extends AbstractHandler implements IHandler { - - public Object execute(ExecutionEvent arg0) throws ExecutionException { - System.out.println("ProjectECRHandler"); - TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession(); - AIFDesktop desktop = AIFUtility.getActiveDesktop(); - try { - //获取首选项中的值:表头=查询数据源=列宽 - String[] option = session.getPreferenceService().getStringValues("CONNOR_ProjectECR");//A3oJ8Bs_J19vPC - if(option==null || option.length<2) { - MessageBox.post(desktop, "首选项CONNOR_ProjectECR配置不正确", "ERROR", MessageBox.ERROR); - return null; - } - new ProjectECRDialog(session, option); - }catch(Exception e) { - e.printStackTrace(); - MessageBox.post(desktop, "错误:"+e.getMessage(), "ERROR", MessageBox.ERROR); - return null; - } - return null; - } -} diff --git a/src/com/langtech/plm/project/TCUtil.java b/src/com/langtech/plm/project/TCUtil.java deleted file mode 100644 index 6353d7f..0000000 --- a/src/com/langtech/plm/project/TCUtil.java +++ /dev/null @@ -1,376 +0,0 @@ -package com.langtech.plm.project; - -import java.awt.Dimension; -import java.awt.Frame; -import java.awt.Toolkit; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Vector; - -import javax.swing.JFileChooser; -import javax.swing.JTable; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.filechooser.FileSystemView; - -import org.apache.poi.xwpf.usermodel.XWPFDocument; -import com.teamcenter.rac.aif.AbstractAIFDialog; -import com.teamcenter.rac.aif.kernel.AIFComponentContext; -import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; -import com.teamcenter.rac.commands.open.OpenFormDialog; -import com.teamcenter.rac.kernel.ListOfValuesInfo; -import com.teamcenter.rac.kernel.TCComponent; -import com.teamcenter.rac.kernel.TCComponentBOMLine; -import com.teamcenter.rac.kernel.TCComponentBOMWindow; -import com.teamcenter.rac.kernel.TCComponentBOMWindowType; -import com.teamcenter.rac.kernel.TCComponentContextList; -import com.teamcenter.rac.kernel.TCComponentDataset; -import com.teamcenter.rac.kernel.TCComponentDatasetType; -import com.teamcenter.rac.kernel.TCComponentForm; -import com.teamcenter.rac.kernel.TCComponentItemRevision; -import com.teamcenter.rac.kernel.TCComponentListOfValues; -import com.teamcenter.rac.kernel.TCComponentListOfValuesType; -import com.teamcenter.rac.kernel.TCComponentPseudoFolder; -import com.teamcenter.rac.kernel.TCComponentQuery; -import com.teamcenter.rac.kernel.TCComponentQueryType; -import com.teamcenter.rac.kernel.TCException; -import com.teamcenter.rac.kernel.TCQueryClause; -import com.teamcenter.rac.kernel.TCSession; -import com.teamcenter.rac.util.MessageBox; - -public class TCUtil { - public static final int MINWIDTH = 1280; - public static final int MINHEIGHT = 768; - - public static void fitToScreen(AbstractAIFDialog abstractAIFDialog) { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - double screenWidth = screenSize.getWidth(); - double screenHeight = screenSize.getHeight(); - Dimension dialogSize = abstractAIFDialog.getSize(); - if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) { - abstractAIFDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight()))); - abstractAIFDialog.setLocation(10, (int) Math.floor(abstractAIFDialog.getLocation().getY())); - } - if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) { - abstractAIFDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20))); - abstractAIFDialog.setLocation((int) Math.floor(abstractAIFDialog.getLocation().getX()), 10); - } - /* - * if((screenWidth - * MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { abstractAIFDialog.setSize(new - * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20))); - * abstractAIFDialog.setLocation(10, 10); } - */ - } - - public static void fitToScreen(OpenFormDialog openFormDialog) { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - double screenWidth = screenSize.getWidth(); - double screenHeight = screenSize.getHeight(); - Dimension dialogSize = openFormDialog.getSize(); - if (screenWidth < MINWIDTH && dialogSize.getWidth() > screenWidth) { - openFormDialog.setSize(new Dimension((int) Math.floor(screenWidth - 20), (int) Math.floor(dialogSize.getHeight()))); - openFormDialog.setLocation(10, (int) Math.floor(openFormDialog.getLocation().getY())); - } - if (screenHeight < MINHEIGHT && dialogSize.getHeight() > screenHeight) { - openFormDialog.setSize(new Dimension((int) Math.floor(dialogSize.getWidth()), (int) Math.floor(screenHeight - 20))); - openFormDialog.setLocation((int) Math.floor(openFormDialog.getLocation().getX()), 10); - } - /* - * if((screenWidth - * MINWIDTH||dialogSize.getHeight()>MINHEIGHT)) { openFormDialog.setSize(new - * Dimension((int)Math.floor(screenWidth-20),(int)Math.floor(screenHeight-20))); - * openFormDialog.setLocation(10, 10); } - */ - } - - public static TCComponentBOMWindow getWindow(TCSession session) throws Exception{ - TCComponentBOMWindow window = null; - TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); - window = bomWinType.create(null); - return window; - } - - @SuppressWarnings("deprecation") - public static TCComponentBOMLine getBOMLine(TCSession session,TCComponentBOMWindow window, TCComponentItemRevision revision) - throws Exception { - window.lock(); - TCComponentBOMLine bomLine = window.setWindowTopLine(null, revision, null, null); - window.save(); - window.unlock(); - return bomLine; - } - public static TCComponentPseudoFolder getPseudoFolder(TCComponent parent, String relation) - throws Exception { - TCComponentPseudoFolder pseudoFolder = null; - AIFComponentContext[] comps = parent.getChildren(); - if (comps != null && comps.length > 0 && comps[0] != null) { - for (int i = 0; i < comps.length; i++) { - TCComponent comp = (TCComponent) comps[i].getComponent(); - if (comp instanceof TCComponentPseudoFolder) { - if (comp.isTypeOf("PseudoFolder")) { -// System.out.println("PseudoFolder type:" + comp.getDefaultPasteRelation()); - if (comp.getDefaultPasteRelation().equalsIgnoreCase(relation)) { - pseudoFolder = (TCComponentPseudoFolder) comp; - break; - } - } - } - } - } - return pseudoFolder; - } - public static TCComponentForm getItemRevisionMasterForm(TCComponentItemRevision revision) throws Exception { - if (revision != null) { - AIFComponentContext[] contexts = revision.getChildren("IMAN_master_form_rev"); - if (contexts != null && contexts.length > 0) { - InterfaceAIFComponent component = contexts[0].getComponent(); - if (component instanceof TCComponentForm) { - return (TCComponentForm) component; - } - } - } - return null; - } - - public static LinkedHashMap getlovValues(TCSession session, String lovName) throws TCException { - LinkedHashMap lovVal = new LinkedHashMap(); - TCComponentListOfValuesType lovType = (TCComponentListOfValuesType) session.getTypeComponent("ListOfValues"); - TCComponentListOfValues[] lovs = lovType.find(lovName); - if (lovs != null && lovs.length > 0) { - TCComponentListOfValues lov = lovs[0]; - ListOfValuesInfo lovInfo = lov.getListOfValues(); - String[] code = lovInfo.getStringListOfValues(); - String[] name = lovInfo.getLOVDisplayValues(); - if (code != null && name != null) { - for (int i = 0; i < code.length; i++) { - // System.out.printf("code[%d]=%s name[%d]=%s \n", i, code[i], i, name[i]); - lovVal.put(code[i], name[i]); - } - } - return lovVal; - } - return null; - } - - public static String getTableValue(JTable table, int row, int col){ - Object val = table.getValueAt(row, col); - if(val==null) - return ""; - else - return val.toString(); - } - public static TCComponent[] query(TCSession session, String queryName, String[] aKey, String[] aVal) throws Exception { - TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); - TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); - if (imancomponentquery == null) { - throw new Exception("未找到查询构建器 " + queryName + "!"); - } - aKey = session.getTextService().getTextValues(aKey); -// for (int i = 0; i < aKey.length; i++) { -// System.out.println(aKey[i] + "===============" + aVal[i]); -// } - TCComponentContextList componentContextList = imancomponentquery.getExecuteResultsList(aKey, aVal); - return componentContextList.toTCComponentArray(); - } - public static TCComponent[] query(TCSession session, String queryName, Vector Keys, Vector Vals) throws Exception { - TCComponentQueryType imanQueryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); - TCComponentQuery imancomponentquery = (TCComponentQuery) imanQueryType.find(queryName); - if (imancomponentquery == null) { - System.out.println("未找到查询构建器" + queryName); - throw new Exception("Query:"+queryName+" cannot find"); - } - TCQueryClause[] qc = imancomponentquery.describe(); -// Map clauseMap = new HashMap<>(); - for(TCQueryClause c : qc) { - String key = c.getUserEntryNameDisplay(); - String value = c.getDefaultValue(); -// System.out.println(key + "==>" + c.getAttributeName()); - if(!value.trim().isEmpty() && !Keys.contains(key)) { - if(key.isEmpty()) - Keys.add(c.getAttributeName()); - else - Keys.add(key); - Vals.add(value); - } - } - int size = Keys.size(); - String[] keyA = new String[size]; - String[] valueA = new String[size]; - for(int i=0; i 0) { - Integer maxId = 0; - for (TCComponent comp : comps) { - String pid = comp.getProperty("item_id"); - System.out.println("pid:" + pid); - String pidSuffix = pid.substring(pid.length() - 3); - if (Integer.parseInt(pidSuffix) > maxId) { - maxId = Integer.parseInt(pidSuffix); - } - } - return String.format("%03d", maxId + 1); - } - return "001"; - } - - public static File saveExcelChooser() { - File dir = null; - JFileChooser chooser = new JFileChooser(); - chooser.setAcceptAllFileFilterUsed(false); -// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); - File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); - chooser.setCurrentDirectory(desktopDir); - String saveType[] = { "xlsx" }; - chooser.setFileFilter(new FileNameExtensionFilter("Excel工作簿", saveType)); - int returnVal = chooser.showSaveDialog(new Frame()); - if (returnVal == JFileChooser.APPROVE_OPTION) { - dir = chooser.getSelectedFile(); - String path = dir.getPath(); - if(!path.toLowerCase().endsWith(".xlsx")) { - path += ".xlsx"; - dir = new File(path); - } - System.out.println("saveExcelChooser1:" + path); - } - return dir; - } - - public static File saveExcelChooser(String defaultFile) { - File dir = null; - JFileChooser chooser = new JFileChooser(); - chooser.setAcceptAllFileFilterUsed(false); -// File currentDir = FileSystemView.getFileSystemView().getDefaultDirectory(); - File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory(); - chooser.setCurrentDirectory(desktopDir); - chooser.setSelectedFile(new File(defaultFile)); - String saveType[] = { "xlsx" }; - chooser.setFileFilter(new FileNameExtensionFilter("Excel工作簿", saveType)); - int returnVal = chooser.showSaveDialog(new Frame()); - if (returnVal == JFileChooser.APPROVE_OPTION) { - dir = chooser.getSelectedFile(); - String path = dir.getPath(); - if(!path.toLowerCase().endsWith(".xlsx")) { - path += ".xlsx"; - dir = new File(path); - } - if(dir.exists()) - dir.delete(); -// System.out.println("saveExcelChooser1:" + dir.getPath()); - } - return dir; - } - - public static boolean contains(String[] array, String str) { - for(String s : array) { -// System.out.println("contains:"+s+"="+str); - if(s.equals(str)) - return true; - } - return false; - } - - public static Map executeToMap(InputStream in){ - System.out.println("Read properties file"); - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); - String line = null; - Map resultMap = new LinkedHashMap<>(16); - if (reader.ready()) { - while (null != (line = reader.readLine())) { - if (line.length() <= 0 || line.contains("#") || !line.contains("=")) { - continue; - } - resultMap.put(line.substring(0, line.indexOf("=")), line.substring(line.indexOf("=") + 1)); - } - } - in.close(); - reader.close(); - return resultMap; - } catch (Exception e) { - e.printStackTrace(); - MessageBox.post("Find properties file failed", "ERROR", MessageBox.ERROR); - } - return null; - } - - public static TCComponentDataset createExcelDataset(TCSession session, File file, String datasetName) throws Exception { - String refType = null, objType = null, fileName = null; - fileName = file.getName().toLowerCase(); - if (fileName.endsWith("xls")) { - refType = "excel"; - objType = "MSExcel"; - } else if (fileName.endsWith("xlsx")) { - refType = "excel"; - objType = "MSExcelX"; - } - TCComponentDatasetType compType = (TCComponentDatasetType) session.getTypeService().getTypeComponent("Dataset"); - TCComponentDataset dataset = compType.create(datasetName, "description", objType); - dataset.setFiles(new String[] { file.getAbsolutePath() }, new String[] { refType }); - return dataset; - } - - public static void deleteWarning(File file) throws IOException { - FileInputStream input = null; - FileOutputStream output = null; - try { - input = new FileInputStream(file); - XWPFDocument doc = new XWPFDocument(input); -// XWPFParagraph para = doc.getParagraphs().get(0); -// System.out.println("para.getRuns:"+para.getRuns().size()); -// for(XWPFRun run : para.getRuns()) { -// System.out.println("run:"+run.getText(0)); -// } - doc.removeBodyElement(0); -// para.removeRun(0); -// System.out.println("para.getRuns:"+para.getRuns().size()+" getParagraphs:"+doc.getParagraphs().get(0).getText()); -// para.setPageBreak(false); - output = new FileOutputStream(file.getPath()); - doc.write(output); - doc.close(); - }catch (Exception e) { - throw e; - }finally { - if(input!=null) - input.close(); - if(output!=null) - output.close(); - } - } - - public static Vector getChildren(TCComponent parent, String relation, String name) throws Exception { - Vector result = new Vector<>(); - AIFComponentContext[] children; - if(relation==null || relation.isEmpty()) - children = parent.getChildren(); - else - children = parent.getChildren(relation); - for(AIFComponentContext c : children) { - TCComponent comp = (TCComponent) c.getComponent(); - if(comp.getProperty("object_name").equals(name)) - result.add(comp); - } - return result; - } - -}