diff --git a/com.connor.jd.plm/src/com/connor/jd/plm/form/SampleConfirmationForm.java b/com.connor.jd.plm/src/com/connor/jd/plm/form/SampleConfirmationForm.java index 4c60106..bbe15bc 100644 --- a/com.connor.jd.plm/src/com/connor/jd/plm/form/SampleConfirmationForm.java +++ b/com.connor.jd.plm/src/com/connor/jd/plm/form/SampleConfirmationForm.java @@ -79,16 +79,24 @@ public class SampleConfirmationForm extends AbstractRendering { private Map pic; private Map general2; private List disableEdit2; - private JRadioPanel sysl; + private JRadioPanel yssl; private JCheckPanel mqjd; - String[] colNames = { "jd2_no", "jd2_gg", "jd2_gg1", "jd2_gc", "jd2_gc1", "jd2_1", "jd2_2", "jd2_3", "jd2_4", - "jd2_5", "jd2_6", "jd2_7", "jd2_8", "jd2_9", "jd2_10", "jd2_min", "jd2_max", "jd2_jg" }; - String[] colNames1 = { "jd2_ctq1", "jd2_ctq2", "jd2_ctq3", "jd2_ctq4", "jd2_ctq5", "jd2_ctq6", "jd2_ctq7", + private String[] colNames = { "jd2_no", "jd2_gg", "jd2_gg1", "jd2_gc", "jd2_gc1", "jd2_1", "jd2_2", "jd2_3", + "jd2_4", "jd2_5", "jd2_6", "jd2_7", "jd2_8", "jd2_9", "jd2_10", "jd2_min", "jd2_max", "jd2_jg" }; + private String[] colNames1 = { "jd2_ctq1", "jd2_ctq2", "jd2_ctq3", "jd2_ctq4", "jd2_ctq5", "jd2_ctq6", "jd2_ctq7", "jd2_ctq8" }; - String[] colNames2 = { "jd2_no", "jd2_ctq1", "jd2_ctq2", "jd2_ctq3", "jd2_ctq4", "jd2_ctq5", "jd2_ctq6", "jd2_ctq7", - "jd2_ctq8" }; - String[] colNames3 = { "jd2_ctq1", "jd2_ctq2", "jd2_ctq3", "jd2_ctq4", "jd2_ctq5", "jd2_ctq6", "jd2_ctq7", + private String[] colNames2 = { "jd2_no", "jd2_ctq1", "jd2_ctq2", "jd2_ctq3", "jd2_ctq4", "jd2_ctq5", "jd2_ctq6", + "jd2_ctq7", "jd2_ctq8" }; + private String[] colNames3 = { "jd2_ctq1", "jd2_ctq2", "jd2_ctq3", "jd2_ctq4", "jd2_ctq5", "jd2_ctq6", "jd2_ctq7", "jd2_ctq8" }; + private JMenuItem addP; + private JMenuItem delP; + private JMenuItem addR; + private JMenuItem insertR; + private JMenuItem delR; + private JMenuItem addR2; + private JMenuItem insertR2; + private JMenuItem delR2; public SampleConfirmationForm(TCComponent arg0) throws Exception { super(arg0); @@ -175,8 +183,8 @@ public class SampleConfirmationForm extends AbstractRendering { general.put("jd2_wlbm", new int[] { 7, 2 }); model.setValueAt("送样数量", 7, 8); disableEdit.add("7,8"); - sysl = new JRadioPanel(new String[] { "3", "5", "10", "30" }); - model.setValueAt(sysl, 7, 10); + yssl = new JRadioPanel(new String[] { "3", "5", "10", "30" }); + model.setValueAt(yssl, 7, 10); model.setValueAt("状态", 7, 14); disableEdit.add("7,14"); general.put("jd2_zt", new int[] { 7, 17 }); @@ -254,14 +262,14 @@ public class SampleConfirmationForm extends AbstractRendering { disableEdit.add(bottom + 2 + ",15"); model.setValueAt("物料包装及标签", bottom + 2, 18); disableEdit.add(bottom + 2 + ",18"); - general.put("jd2_CTime", new int[] { bottom + 3, 5 }); + general.put("jd2_Ctime", new int[] { bottom + 3, 5 }); general.put("jd2_zs", new int[] { bottom + 3, 6 }); general.put("jd2_lq", new int[] { bottom + 3, 7 }); general.put("jd2_baoz", new int[] { bottom + 3, 8 }); pic.put("jd2_gfzjbg", new int[] { bottom + 3, 9 }); pic.put("jd2_gfzyzds", new int[] { bottom + 3, 12 }); pic.put("jd2_gfqcgct", new int[] { bottom + 3, 15 }); - pic.put("jd2_wlbzjbg", new int[] { bottom + 3, 18 }); + pic.put("jd2_wlbzjbq", new int[] { bottom + 3, 18 }); model.setValueAt("Shot/24Hr", bottom + 4, 5); disableEdit.add(bottom + 4 + ",5"); model.setValueAt("吨", bottom + 4, 6); @@ -270,8 +278,8 @@ public class SampleConfirmationForm extends AbstractRendering { general.put("jd2_d", new int[] { bottom + 5, 6 }); model.setValueAt("3D重量", bottom + 6, 4); disableEdit.add(bottom + 6 + ",4"); - model.setValueAt("jd2_3dzl", bottom + 6, 5); - general.put("jd2_3dzl", new int[] { bottom + 6, 5 }); + model.setValueAt("jd2_3Dzl", bottom + 6, 5); + general.put("jd2_3Dzl", new int[] { bottom + 6, 5 }); model.setValueAt("注塑工艺条件", bottom + 6, 7); disableEdit.add(bottom + 6 + ",7"); model.setValueAt("IQC首检报告", bottom + 6, 9); @@ -282,17 +290,17 @@ public class SampleConfirmationForm extends AbstractRendering { disableEdit.add(bottom + 6 + ",15"); model.setValueAt("模具标识", bottom + 6, 18); disableEdit.add(bottom + 6 + ",18"); - pic.put("jd2_gytj", new int[] { bottom + 7, 7 }); - pic.put("jd2_iqcsjbg", new int[] { bottom + 7, 9 }); + pic.put("jd2_zsgytj", new int[] { bottom + 7, 7 }); + pic.put("jd2_icqsjbg", new int[] { bottom + 7, 9 }); pic.put("jd2_csbg", new int[] { bottom + 7, 12 }); - pic.put("jd2_czbf", new int[] { bottom + 7, 15 }); + pic.put("jd2_czbg", new int[] { bottom + 7, 15 }); pic.put("jd2_mjbs", new int[] { bottom + 7, 18 }); model.setValueAt("实测重量", bottom + 8, 4); disableEdit.add(bottom + 8 + ",4"); general.put("jd2_sczl", new int[] { bottom + 8, 5 }); model.setValueAt("IQC作业指导书", bottom + 10, 4); disableEdit.add(bottom + 10 + ",4"); - pic.put("jd2_icqjyzyzds", new int[] { bottom + 11, 4 }); + pic.put("jd2_icqjyzds", new int[] { bottom + 11, 4 }); model.setValueAt("决定", bottom + 12, 12); disableEdit.add(bottom + 12 + ",12"); general.put("jd2_jued", new int[] { bottom + 12, 15 }); @@ -447,7 +455,7 @@ public class SampleConfirmationForm extends AbstractRendering { tcr1.setHorizontalAlignment(SwingConstants.CENTER); table.setDefaultRenderer(Object.class, tcr1); for (int i = 0; i < model.getColumnCount(); i++) { - table.getColumnModel().getColumn(i).setCellEditor(new MyCellEditor(new JTextField())); + table.getColumnModel().getColumn(i).setCellEditor(new MyCellEditor(new JTextField(), top, end, bottom)); } table.addMouseListener(rightClick()); confirmPanel.add(table, BorderLayout.CENTER); @@ -458,18 +466,21 @@ public class SampleConfirmationForm extends AbstractRendering { if (prop.containsKey(entry.getKey())) { model.setValueAt(prop.get(entry.getKey()), entry.getValue()[0], entry.getValue()[1]); } else { - model.setValueAt(entry.getKey(), entry.getValue()[0], entry.getValue()[1]); + model.setValueAt("", entry.getValue()[0], entry.getValue()[1]); System.out.println("属性‘" + entry.getKey() + "’未找到"); } } - if (prop.containsKey("jd2_sysl")) { - sysl.setSelected(prop.get("jd2_sysl")); + if (prop.containsKey("jd2_yssl")) { + yssl.setSelected(prop.get("jd2_yssl")); + } else { + System.out.println("属性‘jd2_yssl’未找到"); } if (prop.containsKey("jd2_mqjd")) { mqjd.setSelected(prop.get("jd2_mqjd")); + } else { + System.out.println("属性‘jd2_mqjd’未找到"); } - pic.put("user_data_1", new int[] { bottom + 3, 0 }); - pic.put("user_data_2", new int[] { bottom + 3, 9 }); + for (Entry entry : pic.entrySet()) { if (prop.containsKey(entry.getKey())) { TCComponent comp = null; @@ -503,13 +514,17 @@ public class SampleConfirmationForm extends AbstractRendering { label.addMouseListener(showImg(img.getPath())); label.setToolTipText(dataset.getUid()); model.setValueAt(label, row, col); + } else { + model.setValueAt(new JLabel(""), entry.getValue()[0], entry.getValue()[1]); + System.out.println("未找到uid为\"" + prop.get(entry.getKey()) + "\"的数据集"); } } catch (Exception e) { + model.setValueAt(new JLabel(""), entry.getValue()[0], entry.getValue()[1]); e.printStackTrace(System.out); } } else { - model.setValueAt(new JLabel(entry.getKey()), entry.getValue()[0], entry.getValue()[1]); + model.setValueAt(new JLabel(""), entry.getValue()[0], entry.getValue()[1]); System.out.println("属性‘" + entry.getKey() + "’未找到"); } } @@ -528,6 +543,8 @@ public class SampleConfirmationForm extends AbstractRendering { model.setValueAt(tableRows[i][ii], i + top + 2, ii > 2 ? ii + 2 : ii); } } + } else { + System.out.println("属性‘jd2_ypqrdtable’未找到"); } ScrollPane confirmScrollPanel = new ScrollPane(); @@ -682,29 +699,41 @@ public class SampleConfirmationForm extends AbstractRendering { // 确认单右键菜单 menu.setVisible(false); - JMenuItem addP; addP = new JMenuItem("添加图片"); + addP.setEnabled(false); menu.add(addP); addP.addActionListener(addPic()); - JMenuItem addR; + delP = new JMenuItem("删除图片"); + delP.setEnabled(false); + menu.add(delP); + delP.addActionListener(delPic()); addR = new JMenuItem("添加行"); + addR.setEnabled(false); menu.add(addR); addR.addActionListener(addRow()); - JMenuItem insertR; insertR = new JMenuItem("插入行"); + insertR.setEnabled(false); menu.add(insertR); insertR.addActionListener(insertRow()); + delR = new JMenuItem("删除行"); + delR.setEnabled(false); + menu.add(delR); + delR.addActionListener(deleteRow()); // 检验单右键菜单 menu2.setVisible(false); - JMenuItem addR2; addR2 = new JMenuItem("添加行"); + addR2.setEnabled(false); menu2.add(addR2); addR2.addActionListener(addRow2()); - JMenuItem insertR2; insertR2 = new JMenuItem("插入行"); + insertR2.setEnabled(false); menu2.add(insertR2); insertR2.addActionListener(insertRow2()); + delR2 = new JMenuItem("删除行"); + delR2.setEnabled(false); + menu2.add(delR2); + delR2.addActionListener(deleteRow2()); center.add("confirm", confirmScrollPanel); center.add("examine", examineScrollPanel); @@ -741,11 +770,19 @@ public class SampleConfirmationForm extends AbstractRendering { } // 保存选择 try { - if (prop.containsKey("jd2_sysl")) { - form.setProperty("jd2_sysl", sysl.getSelected() == null ? "" : sysl.getSelected().getText()); + if (prop.containsKey("jd2_yssl")) { + String value = yssl.getSelected() == null ? "" : yssl.getSelected().getText(); + if (form.getTCProperty("jd2_yssl").getLOV() != null && !"".equals(value)) { + value = (String) form.getTCProperty("jd2_yssl").getLOV().getListOfValues().getRealValue(value); + } + form.setProperty("jd2_yssl", value); } if (prop.containsKey("jd2_mqjd")) { - form.setProperty("jd2_mqjd", mqjd.getSelectedText() == null ? "" : mqjd.getSelectedText()); + String value = mqjd.getSelectedText() == null ? "" : mqjd.getSelectedText(); + if (form.getTCProperty("jd2_mqjd").getLOV() != null && !"".equals(value)) { + value = (String) form.getTCProperty("jd2_mqjd").getLOV().getListOfValues().getRealValue(value); + } + form.setProperty("jd2_mqjd", value); } } catch (TCException e) { @@ -756,8 +793,12 @@ public class SampleConfirmationForm extends AbstractRendering { for (Entry entry : general.entrySet()) { try { if (prop.containsKey(entry.getKey())) { - form.setProperty(entry.getKey(), - model.getValueAt(entry.getValue()[0], entry.getValue()[1]).toString()); + String value = model.getValueAt(entry.getValue()[0], entry.getValue()[1]).toString(); + if (form.getTCProperty(entry.getKey()).getLOV() != null && !"".equals(value)) { + value = (String) form.getTCProperty(entry.getKey()).getLOV().getListOfValues() + .getRealValue(value); + } + form.setProperty(entry.getKey(), value); } } catch (TCException e) { // TODO Auto-generated catch block @@ -806,7 +847,7 @@ public class SampleConfirmationForm extends AbstractRendering { } String[][] dataArr = data.toArray(new String[data.size()][]); System.out.println(Arrays.deepToString(dataArr)); - TCTableUtil.setTableRows(form, "jd2_ctq1", "JD2_CTQ1", colNames1, dataArr); + TCTableUtil.setTableRows(form, "jd2_ctq1", "JD2_CQT1", colNames1, dataArr); } if (prop.containsKey("jd2_ctq2")) { List data = new ArrayList(); @@ -829,7 +870,7 @@ public class SampleConfirmationForm extends AbstractRendering { } String[][] dataArr = data.toArray(new String[data.size()][]); System.out.println(Arrays.deepToString(dataArr)); - TCTableUtil.setTableRows(form, "jd2_ctq2", "JD2_CTQ2", colNames2, dataArr); + TCTableUtil.setTableRows(form, "jd2_ctq2", "JD2_CQT2", colNames2, dataArr); } if (prop.containsKey("jd2_ctq3")) { List data = new ArrayList(); @@ -852,7 +893,7 @@ public class SampleConfirmationForm extends AbstractRendering { } String[][] dataArr = data.toArray(new String[data.size()][]); System.out.println(Arrays.deepToString(dataArr)); - TCTableUtil.setTableRows(form, "jd2_ctq3", "JD2_CTQ3", colNames3, dataArr); + TCTableUtil.setTableRows(form, "jd2_ctq3", "JD2_CQT3", colNames3, dataArr); } } @@ -887,6 +928,13 @@ public class SampleConfirmationForm extends AbstractRendering { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3 && form.isCheckedOut() && table.getSelectedRow() != -1) { + int row = table.getSelectedRow(); + boolean flag = (row >= top && row <= bottom); + addR.setEnabled(flag); + insertR.setEnabled(flag); + delR.setEnabled(flag); + flag = row > bottom; + addP.setEnabled(flag); menu.show(e.getComponent(), e.getX(), e.getY()); } } @@ -899,6 +947,11 @@ public class SampleConfirmationForm extends AbstractRendering { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3 && form.isCheckedOut() && table2.getSelectedRow() != -1) { + int row = table2.getSelectedRow(); + boolean flag = (row >= top2 && row <= bottom2); + addR2.setEnabled(flag); + insertR2.setEnabled(flag); + delR2.setEnabled(flag); menu2.show(e.getComponent(), e.getX(), e.getY()); } } @@ -972,86 +1025,124 @@ public class SampleConfirmationForm extends AbstractRendering { return actionListener; } + private ActionListener delPic() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int row = table.getSelectedRow(); + int col = table.getSelectedColumn(); + model.setValueAt(new JLabel(""), row, col); + } + + }; + return actionListener; + } + private ActionListener addRow() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int num = Integer.parseInt(model.getValueAt(bottom, 0).toString()); + model.insertRow(++bottom); + model.setValueAt(num + 1, bottom, 0); + model.combine(new int[] { bottom }, new int[] { 2, 3, 4 }); + + } + }; + return actionListener; + } + + private ActionListener addRow2() { + ActionListener actionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + int num = Integer.parseInt(model2.getValueAt(bottom2, 0).toString()); + model2.insertRow(++bottom2); + model2.setValueAt(num + 1, bottom2, 0); + model2.combine(new int[] { bottom2 }, new int[] { 0, 1 }); + } + }; + return actionListener; + } + + private ActionListener insertRow() { ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub int row = table.getSelectedRow(); - if (row >= top && row <= bottom) { - int num = Integer.parseInt(model.getValueAt(bottom, 0).toString()); - model.insertRow(++bottom); - model.setValueAt(num + 1, bottom, 0); - model.combine(new int[] { bottom }, new int[] { 2, 3, 4 }); - } else { - // 提示 + int num = Integer.parseInt(model.getValueAt(row, 0).toString()); + model.insertRow(row); + bottom++; + for (int i = row; i <= bottom; i++) { + model.setValueAt(num + i - row, i, 0); } + model.combine(new int[] { row }, new int[] { 2, 3, 4 }); } }; return actionListener; } - private ActionListener addRow2() { + private ActionListener insertRow2() { ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub int row = table2.getSelectedRow(); - if (row >= top2 && row <= bottom2) { - int num = Integer.parseInt(model2.getValueAt(bottom2, 0).toString()); - model2.insertRow(++bottom2); - model2.setValueAt(num + 1, bottom2, 0); - model2.combine(new int[] { bottom2 }, new int[] { 0, 1 }); - } else { - // 提示 + int num = Integer.parseInt(model2.getValueAt(row, 0).toString()); + model2.insertRow(row); + bottom2++; + for (int i = row; i <= bottom2; i++) { + model2.setValueAt(num + i - row, i, 0); } + model2.combine(new int[] { row }, new int[] { 0, 1 }); } }; return actionListener; } - private ActionListener insertRow() { + private ActionListener deleteRow() { ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub int row = table.getSelectedRow(); - if (row >= top && row <= bottom) { - int num = Integer.parseInt(model.getValueAt(row, 0).toString()); - model.insertRow(row); - bottom++; + int num = Integer.parseInt(model.getValueAt(row, 0).toString()); + model.removeRow(row); + bottom--; + if (row <= bottom) { for (int i = row; i <= bottom; i++) { model.setValueAt(num + i - row, i, 0); } - model.combine(new int[] { row }, new int[] { 2, 3, 4 }); - } else { - // 提示 } } }; return actionListener; } - private ActionListener insertRow2() { + private ActionListener deleteRow2() { ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub int row = table2.getSelectedRow(); - if (row >= top2 && row <= bottom2) { - int num = Integer.parseInt(model2.getValueAt(row, 0).toString()); - model2.insertRow(row); - bottom2++; + int num = Integer.parseInt(model2.getValueAt(row, 0).toString()); + model2.removeRow(row); + bottom2--; + if (row <= bottom2) { for (int i = row; i <= bottom2; i++) { model2.setValueAt(num + i - row, i, 0); } - model2.combine(new int[] { row }, new int[] { 0, 1 }); - } else { - // 提示 } } }; diff --git a/com.connor.jd.plm/src/com/connor/jd/plm/table/JCheckPanel.java b/com.connor.jd.plm/src/com/connor/jd/plm/table/JCheckPanel.java index 946e475..3e31e46 100644 --- a/com.connor.jd.plm/src/com/connor/jd/plm/table/JCheckPanel.java +++ b/com.connor.jd.plm/src/com/connor/jd/plm/table/JCheckPanel.java @@ -5,11 +5,13 @@ import java.awt.FlowLayout; import java.util.ArrayList; import java.util.List; +import javax.swing.ButtonGroup; import javax.swing.JCheckBox; import javax.swing.JPanel; public class JCheckPanel extends JPanel { private JCheckBox[] buttons = null; + private ButtonGroup buttonGroup = new ButtonGroup(); public JCheckPanel(String[] text) { super(); @@ -17,6 +19,7 @@ public class JCheckPanel extends JPanel { for (int i = 0; i < text.length; i++) { buttons[i] = new JCheckBox(text[i]); buttons[i].setPreferredSize(new Dimension(100, 25)); + buttonGroup.add(buttons[i]); add(buttons[i]); } setLayout(new FlowLayout(FlowLayout.LEFT)); diff --git a/com.connor.jd.plm/src/com/connor/jd/plm/table/JRadioPanel.java b/com.connor.jd.plm/src/com/connor/jd/plm/table/JRadioPanel.java index 9ad868a..4d7fbcd 100644 --- a/com.connor.jd.plm/src/com/connor/jd/plm/table/JRadioPanel.java +++ b/com.connor.jd.plm/src/com/connor/jd/plm/table/JRadioPanel.java @@ -26,9 +26,10 @@ public class JRadioPanel extends JPanel { } public JRadioButton getSelected() { - if (buttonGroup.getSelection() != null) { - return (JRadioButton) buttonGroup.getSelection() - .getSelectedObjects()[0]; + for (JRadioButton jb : buttons) { + if (jb.isSelected()) { + return jb; + } } return null; } @@ -39,7 +40,7 @@ public class JRadioPanel extends JPanel { public void setSelected(String value) { for (int i = 0; i < buttons.length; i++) { - buttons[i].setSelected(buttons[i].getText().equals(value)); + buttons[i].setSelected(buttons[i].getText().equals(value.trim())); } } diff --git a/com.connor.jd.plm/src/com/connor/jd/plm/table/MyCellEditor.java b/com.connor.jd.plm/src/com/connor/jd/plm/table/MyCellEditor.java index 8bf1cfe..562f68d 100644 --- a/com.connor.jd.plm/src/com/connor/jd/plm/table/MyCellEditor.java +++ b/com.connor.jd.plm/src/com/connor/jd/plm/table/MyCellEditor.java @@ -7,40 +7,54 @@ import javax.swing.JLabel; import javax.swing.JTable; import javax.swing.JTextField; +import com.teamcenter.rac.util.MessageBox; + public class MyCellEditor extends DefaultCellEditor { private JRadioPanel radio = null; private JCheckPanel check = null; private JLabel img = null; private int type = -1; + private int row; + private int col; + private int top; + private int end; + private int bottom; + private JTable table; public MyCellEditor(JTextField var1) { super(var1); // TODO Auto-generated constructor stub } + public MyCellEditor(JTextField var1, int top, int end, int bottom) { + super(var1); + // TODO Auto-generated constructor stub + this.top = top; + this.end = end; + this.bottom = bottom; + } + @Override - public Component getTableCellEditorComponent(JTable table, Object value, - boolean isSelected, int row, int column) { + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if (value instanceof JRadioPanel) { - System.out.println("radio"); radio = (JRadioPanel) value; type = 1; return radio; } else if (value instanceof JCheckPanel) { - System.out.println("check"); check = (JCheckPanel) value; type = 2; return check; } else if (value instanceof JLabel) { - System.out.println("image"); img = (JLabel) value; type = 3; return img; } + this.row = row; + this.col = column; + this.bottom = table.getRowCount() - end; + this.table = table; type = 0; - System.out.println("default"); - return super.getTableCellEditorComponent(table, value, isSelected, row, - column); + return super.getTableCellEditorComponent(table, value, isSelected, row, column); } @Override @@ -53,13 +67,41 @@ public class MyCellEditor extends DefaultCellEditor { case 3: return img; } - return super.getCellEditorValue(); + Object obj = super.getCellEditorValue(); + if (obj != null && !"".equals(obj.toString().trim()) && row >= top && row <= bottom && col >= 7 + && col < table.getColumnCount() - 3) { + try { + Double.parseDouble(obj.toString().trim()); + } catch (Exception e) { + MessageBox.post("检查数据只能输入数字", "错误", MessageBox.ERROR); + return null; + } + } + return obj; } @Override public boolean stopCellEditing() { // TODO Auto-generated method stub -// System.out.println("stop"); + if (row >= top && row <= bottom && col >= 7 && col < table.getColumnCount() - 3) { + double min = Double.MAX_VALUE; + double max = Double.MIN_VALUE; + Object obj; + for (int i = 7; i < table.getColumnCount() - 3; i++) { + obj = table.getValueAt(row, i); + if (obj != null && !"".equals(obj.toString().trim())) { + min = Math.min(min, Double.parseDouble(obj.toString().trim())); + max = Math.max(max, Double.parseDouble(obj.toString().trim())); + } + } + if (max > Double.MIN_VALUE) { + table.setValueAt(String.format("%.2f", min), row, table.getColumnCount() - 3); + table.setValueAt(String.format("%.2f", max), row, table.getColumnCount() - 2); + } else { + table.setValueAt("", row, table.getColumnCount() - 3); + table.setValueAt("", row, table.getColumnCount() - 2); + } + } return super.stopCellEditing(); } diff --git a/com.connor.jd.plm/src/com/connor/jd/plm/table/MyCellEditor1.java b/com.connor.jd.plm/src/com/connor/jd/plm/table/MyCellEditor1.java index b76211e..c71bdfe 100644 --- a/com.connor.jd.plm/src/com/connor/jd/plm/table/MyCellEditor1.java +++ b/com.connor.jd.plm/src/com/connor/jd/plm/table/MyCellEditor1.java @@ -9,6 +9,8 @@ import javax.swing.DefaultCellEditor; import javax.swing.JTable; import javax.swing.JTextField; +import com.teamcenter.rac.util.MessageBox; + public class MyCellEditor1 extends DefaultCellEditor { private int col; private int row; @@ -67,6 +69,21 @@ public class MyCellEditor1 extends DefaultCellEditor { return super.getTableCellEditorComponent(table, value, isSelected, row, column); } + @Override + public Object getCellEditorValue() { + // TODO Auto-generated method stub + Object obj = super.getCellEditorValue(); + if (obj != null && !"".equals(obj.toString().trim()) && row >= top && row <= bottom) { + try { + Double.parseDouble(obj.toString().trim()); + } catch (Exception e) { + MessageBox.post("计算区域只能输入数字", "错误", MessageBox.ERROR); + return null; + } + } + return obj; + } + @Override public boolean stopCellEditing() { // TODO Auto-generated method stub