Merge pull request 'zouxk' (#2) from zouxk into master

main
邹旭科 5 years ago
commit ff23109716

1
.gitignore vendored

@ -23,3 +23,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/

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

File diff suppressed because it is too large Load Diff

@ -10,9 +10,10 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.108.0",
com.teamcenter.rac.aifrcp;bundle-version="12000.1.0",
com.teamcenter.rac.ui.commands;bundle-version="12000.1.0",
com.teamcenter.rac.kernel;bundle-version="12000.1.0",
com.teamcenter.rac.ui.views;bundle-version="12000.1.0",
org.eclipse.ui.views;bundle-version="3.8.100",
org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.ui.forms;bundle-version="3.7.0"
org.eclipse.ui.forms;bundle-version="3.7.0",
com.teamcenter.rac.schedule;bundle-version="12000.1.0"
Automatic-Module-Name: JDProject
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: com.connor.jd.operations,
@ -29,7 +30,11 @@ Export-Package: com.connor.jd.operations,
Import-Package: com.teamcenter.services,
com.teamcenter.services.rac,
com.teamcenter.services.rac.core,
com.teamcenter.services.rac.core._2008_06
com.teamcenter.services.rac.core._2008_06,
org.apache.http.client,
org.apache.http.client.methods,
org.apache.http.client.params,
org.apache.http.client.protocol
Bundle-ClassPath: .,
lib/fastjson-1.2.9.jar,
lib/hutool-all-5.0.7.jar,
@ -49,5 +54,6 @@ Bundle-ClassPath: .,
lib/poi-ooxml-schemas-4.1.1.jar,
lib/poi-scratchpad-4.1.1.jar,
lib/xmlbeans-3.1.0.jar,
lib/commons-lang3-3.9.jar,
lib/ojdbc6.jar,
lib/commons-lang3-3.9.jar
config/

@ -23,4 +23,6 @@ bin.includes = plugin.xml,\
lib/poi-scratchpad-4.1.1.jar,\
lib/xmlbeans-3.1.0.jar,\
lib/ojdbc6.jar,\
lib/commons-lang3-3.9.jar
lib/commons-lang3-3.9.jar,\
config/

@ -0,0 +1,14 @@
## db.setting文件
#url = jdbc:oracle:thin:@localhost:1521:TC
url = jdbc:oracle:thin:@10.20.4.75:1521:TC12
user = infodba
pass = infodba
## 可选配置
# 是否在日志中显示执行的SQL
showSql = true
# 是否格式化显示的SQL
formatSql = false
# 是否显示SQL参数
showParams = true

@ -55,6 +55,7 @@
<command categoryId="JDProject.commands.category" name="问题点" id="JD2_PROBLEM"></command>
<command categoryId="JDProject.commands.category" name="变更通知单" id="JD2_GTECN"></command>
<command categoryId="JDProject.commands.category" name="齐套性检查" id="JD2_GTQTXJC"></command>
<command categoryId="JDProject.commands.category" name="滚筒新品测试项清单" id="JD2_GTXPCSXQD"></command>
<!--波轮PLM菜单-->
<command categoryId="JDProject.commands.category" name="年度规划大纲" id="JD2_BLNDGHDG"></command>
<command categoryId="JDProject.commands.category" name="产品立项申请表" id="JD2_BLCPLXSQB"></command>
@ -242,8 +243,6 @@
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BLXCJYWPXZL"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BLSHZL"></handler>
<handler class="com.connor.jd.plm.handlers.QTXJCHandler" commandId="JD2_BLQTXJC"></handler>
<handler class="com.connor.jd.plm.handlers.Wf001ScheduleHandler" commandId="Schedule"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_PROBLEM"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BLECN"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BXNDGHDG"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BXCPLXSQB"></handler>
@ -286,14 +285,13 @@
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BXSHZL"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BXCPSHB"></handler>
<handler class="com.connor.jd.plm.handlers.QTXJCHandler" commandId="JD2_BXQTXJC"></handler>
<handler class="com.connor.jd.plm.handlers.Wf001ScheduleHandler" commandId="Schedule"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_PROBLEM"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BXECN"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BXSJPSBG"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BLSJPSBG"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_GTSJPSBG"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BXSJJHS"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_BXSJRWS"></handler>
<handler class="com.connor.jd.plm.handlers.CreateItemHandler" commandId="JD2_GTXPCSXQD"></handler>
<handler class="com.connor.jd.plm.handlers.CSXWHHandler" commandId="JD2_CSXWH"></handler>
<handler commandId="editClassification" class="com.connor.jd.plm.handlers.EditClassificationHandler"></handler>
@ -348,6 +346,7 @@
<command commandId="JD2_GTCPRZQRB" id="JDProject.menus.JD2_GTCPRZQRB" mnemonic="S"></command>
<command commandId="JD2_GTYPQRD" id="JDProject.menus.JD2_GTYPQRD" mnemonic="S"></command>
<command commandId="JD2_GTKFYJPSD" id="JDProject.menus.JD2_GTKFYJPSD" mnemonic="S"></command>
<command commandId="JD2_GTXPCSXQD" id="JDProject.menus.JD2_GTXPCSXQD" mnemonic="S"></command>
</menu>
<menu id="JDProject.menus.JD2_GTGYYJ" label="工艺样机" mnemonic="M">
<command commandId="JD2_GTRZZL" id="JDProject.menus.JD2_GTRZZL" mnemonic="S"></command>

@ -0,0 +1,10 @@
public class Test {
public static void main(String[] args) {
String fileName = "111.xlsx";
String[] filename = fileName.split("\\.");
System.out.println(fileName.lastIndexOf("."));
}
}

@ -19,8 +19,6 @@ import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.ics.ICSProperty;
import com.teamcenter.rac.util.MessageBox;
import cn.hutool.http.HttpUtil;
public class WLTZReviseAction extends AbstractAIFAction {
private AbstractAIFApplication app;
private TCSession session;
@ -51,7 +49,9 @@ public class WLTZReviseAction extends AbstractAIFAction {
return;
}
TCComponentItem item = rev.getItem();
session.getUserService().call("bs_bypass", new Object[] { true });
TCComponentItemRevision newRev = rev.saveAs(item.getNewRev());
session.getUserService().call("bs_bypass", new Object[] { false });
TCComponentICO ico = rev.getClassificationObjects()[0];
ICSProperty[] oldICSProps = ico.getICSProperties(true);
int[] ids = new int[oldICSProps.length];
@ -88,7 +88,7 @@ public class WLTZReviseAction extends AbstractAIFAction {
@Override
public void run() {
// TODO Auto-generated method stub
HttpUtil.post(URL, PARAMMAP);
cn.hutool.http.HttpUtil.post(URL, PARAMMAP);
System.out.println("success");
}
}).start();

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

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

@ -28,7 +28,6 @@ import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentICO;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.ics.ICSApplicationObject;
import com.teamcenter.rac.kernel.ics.ICSProperty;
@ -53,6 +52,9 @@ public class EditClassificationDialog extends AbstractAIFDialog {
this.session = (TCSession) app.getSession();
this.myService = session.getClassificationService();
this.target = (TCComponent) AIFUtility.getCurrentApplication().getTargetComponent();
System.out.println(target.getType());
System.out.println(target instanceof TCComponentItemRevision ? "ÊÇ" : "·ñ");
if (target instanceof TCComponentItemRevision) {
try {
initUI();
@ -69,6 +71,7 @@ public class EditClassificationDialog extends AbstractAIFDialog {
this.setTitle("Ð޸ķÖÀàÊôÐÔ");
this.setAutoRequestFocus(true);
this.setResizable(true);
this.setAlwaysOnTop(true);
JPanel rootPanel = new JPanel(new BorderLayout());
rootPanel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
@ -152,20 +155,25 @@ public class EditClassificationDialog extends AbstractAIFDialog {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
TCComponentItemRevision rev = (TCComponentItemRevision) target;
saveClassification(rev);
try {
if (rev.getProperty("object_type").equals("JD2_GTBJRevision")) {
TCProperty property = rev.getTCProperty("TC_Is_Represented_By");
TCComponent[] comp = property.getReferenceValueArray();
if (comp.length > 0) {
TCComponentItemRevision tzrev = (TCComponentItemRevision) comp[0];
saveClassification(tzrev);
}
}
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// try {
// System.out.println(rev.getProperty("object_string"));
// if (rev.getType().equals("JD2_GTBJRevision")) {
// TCComponent[] comps = rev.getReferenceListProperty("TC_Is_Represented_By");
// System.out.println(comps.length);
// for (int i = 0; i < comps.length; i++) {
// if (comps[i].getType().equals("JD2_XYJTZRevision")) {
// System.out.println("object_string:" + comps[i].getProperty("object_string"));
// TCComponentItemRevision tzrev = (TCComponentItemRevision) comps[i];
// saveClassification(tzrev);
// }
// }
// }
// } catch (TCException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
DIALOG.disposeDialog();
}
};

@ -0,0 +1,7 @@
package com.connor.jd.plm.dialog;
import javafx.scene.control.Dialog;
public class MsgDialog extends Dialog<String> {
}

@ -7,7 +7,6 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.math.NumberUtils;
@ -20,24 +19,32 @@ import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.kernel.TCException;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class CSXWHDialog extends Application {
@ -60,15 +67,38 @@ public class CSXWHDialog extends Application {
private int index = 10000;
private int macindex = 10000;
private Stage msgStage;
private Label msgContent;
@Override
public void start(Stage arg0) throws Exception {
msgStage = new Stage();
msgContent = new Label("");
msgContent.setFont(new Font(STYLESHEET_CASPIAN, 16));
Button ok = new Button("确定");
ok.setPrefSize(60, 25);
ok.setOnAction((arg) -> {
msgStage.close();
});
BorderPane msgInner = new BorderPane();
msgInner.setStyle("-fx-padding:10px;");
FlowPane btnFlow = new FlowPane();
btnFlow.setAlignment(Pos.TOP_RIGHT);
btnFlow.getChildren().addAll(ok);
msgInner.setTop(msgContent);
msgInner.setBottom(btnFlow);
Scene msgScene = new Scene(msgInner, 200, 100);
msgStage.setScene(msgScene);
msgStage.setTitle("信息");
msgStage.setAlwaysOnTop(true);
CreateTableOperation.create();
try {
con = DBConnectionUtil.dbConn("infodba", "infodba");
String sqlString = "select * from JD2_Component";
if (con == null) {
Alert alert = new Alert(AlertType.ERROR, "连接失败");
alert.show();
msgContent.setText("连接失败");
msgStage.show();
} else {
ps = con.prepareStatement(sqlString);
rs = ps.executeQuery();
@ -119,7 +149,9 @@ public class CSXWHDialog extends Application {
TableColumn<ComponentBean, String> type0 = new TableColumn<ComponentBean, String>("部品类型");
type0.setPrefWidth(90);
type0.setCellValueFactory(new PropertyValueFactory<>("type"));
type0.setCellFactory(TextFieldTableCell.<ComponentBean>forTableColumn());
type0.setCellFactory((col) -> {
return new EditableStringTableCell<ComponentBean, String>();
});
type0.setOnEditCommit((CellEditEvent<ComponentBean, String> t) -> {
t.getTableView().getItems().get(t.getTablePosition().getRow()).setType(t.getNewValue());
// 如果数据本身是从数据库中取出的那么将数据状态改为2->从数据库取出但被修改了的
@ -130,7 +162,9 @@ public class CSXWHDialog extends Application {
TableColumn<ComponentBean, String> project0 = new TableColumn<ComponentBean, String>("试验项目");
project0.setPrefWidth(89);
project0.setCellValueFactory(new PropertyValueFactory<>("project"));
project0.setCellFactory(TextFieldTableCell.<ComponentBean>forTableColumn());
project0.setCellFactory((col) -> {
return new EditableStringTableCell<ComponentBean, String>();
});
project0.setOnEditCommit((CellEditEvent<ComponentBean, String> t) -> {
t.getTableView().getItems().get(t.getTablePosition().getRow()).setProject(t.getNewValue());
if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) {
@ -140,7 +174,9 @@ public class CSXWHDialog extends Application {
TableColumn<ComponentBean, String> time = new TableColumn<ComponentBean, String>("试验时间");
time.setPrefWidth(92);
time.setCellValueFactory(new PropertyValueFactory<>("time"));
time.setCellFactory(TextFieldTableCell.<ComponentBean>forTableColumn());
time.setCellFactory((col) -> {
return new EditableStringTableCell<ComponentBean, String>();
});
time.setOnEditCommit((CellEditEvent<ComponentBean, String> t) -> {
t.getTableView().getItems().get(t.getTablePosition().getRow()).setTime(t.getNewValue());
if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) {
@ -150,7 +186,9 @@ public class CSXWHDialog extends Application {
TableColumn<ComponentBean, String> number = new TableColumn<ComponentBean, String>("样品数量");
number.setPrefWidth(68);
number.setCellValueFactory(new PropertyValueFactory<>("number"));
number.setCellFactory(TextFieldTableCell.<ComponentBean>forTableColumn());
number.setCellFactory((col) -> {
return new EditableStringTableCell<ComponentBean, String>();
});
number.setOnEditCommit((CellEditEvent<ComponentBean, String> t) -> {
if (NumberUtils.isNumber(t.getNewValue())) {
t.getTableView().getItems().get(t.getTablePosition().getRow()).setNumber(t.getNewValue());
@ -160,15 +198,17 @@ public class CSXWHDialog extends Application {
}
} else {
tableView0.refresh();
Alert alert = new Alert(AlertType.ERROR, "请输入数字");
alert.show();
msgContent.setText("请输入数字");
msgStage.show();
}
});
TableColumn<ComponentBean, String> cost = new TableColumn<ComponentBean, String>("试验费用");
cost.setPrefWidth(71);
cost.setCellValueFactory(new PropertyValueFactory<>("cost"));
cost.setCellFactory(TextFieldTableCell.<ComponentBean>forTableColumn());
cost.setCellFactory((col) -> {
return new EditableStringTableCell<ComponentBean, String>();
});
cost.setOnEditCommit((CellEditEvent<ComponentBean, String> t) -> {
t.getNewValue();
if (NumberUtils.isNumber(t.getNewValue())) {
@ -286,6 +326,7 @@ public class CSXWHDialog extends Application {
}
// tableView0.refresh();
});
Button saveBtn0 = new Button("保存");
saveBtn0.setLayoutX(161.0);
saveBtn0.setLayoutY(319.0);
@ -310,13 +351,12 @@ public class CSXWHDialog extends Application {
if (com.getStage() == 2) {
update(com);
com.setStage(0);
}
}
tableView0.refresh();
} else {
Alert alert = new Alert(AlertType.ERROR, "存在某行的内容全为空,请检查");
alert.show();
msgContent.setText("存在某行的内容全为空,请检查");
msgStage.show();
}
});
@ -380,7 +420,9 @@ public class CSXWHDialog extends Application {
TableColumn<MachineBean, String> type1 = new TableColumn<MachineBean, String>("类别");
type1.setPrefWidth(110.0);
type1.setCellValueFactory(new PropertyValueFactory<>("type"));
type1.setCellFactory(TextFieldTableCell.<MachineBean>forTableColumn());
type1.setCellFactory((col) -> {
return new EditableStringTableCell<MachineBean, String>();
});
type1.setOnEditCommit((CellEditEvent<MachineBean, String> t) -> {
t.getTableView().getItems().get(t.getTablePosition().getRow()).setType(t.getNewValue());
if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) {
@ -390,7 +432,9 @@ public class CSXWHDialog extends Application {
TableColumn<MachineBean, String> project1 = new TableColumn<MachineBean, String>("项目");
project1.setPrefWidth(121.0);
project1.setCellValueFactory(new PropertyValueFactory<>("project"));
project1.setCellFactory(TextFieldTableCell.<MachineBean>forTableColumn());
project1.setCellFactory((col) -> {
return new EditableStringTableCell<MachineBean, String>();
});
project1.setOnEditCommit((CellEditEvent<MachineBean, String> t) -> {
t.getTableView().getItems().get(t.getTablePosition().getRow()).setProject(t.getNewValue());
if (t.getTableView().getItems().get(t.getTablePosition().getRow()).getStage() == 0) {
@ -400,7 +444,9 @@ public class CSXWHDialog extends Application {
TableColumn<MachineBean, String> cost1 = new TableColumn<MachineBean, String>("项目费用");
cost1.setPrefWidth(118.0);
cost1.setCellValueFactory(new PropertyValueFactory<>("cost"));
cost1.setCellFactory(TextFieldTableCell.<MachineBean>forTableColumn());
cost1.setCellFactory((col) -> {
return new EditableStringTableCell<MachineBean, String>();
});
cost1.setOnEditCommit((CellEditEvent<MachineBean, String> t) -> {
if (NumberUtils.isNumber(t.getNewValue())) {
t.getTableView().getItems().get(t.getTablePosition().getRow()).setCost(t.getNewValue());
@ -408,9 +454,9 @@ public class CSXWHDialog extends Application {
t.getTableView().getItems().get(t.getTablePosition().getRow()).setStage(2);
}
} else {
tableView0.refresh();
Alert alert = new Alert(AlertType.ERROR, "请输入数字");
alert.show();
tableView1.refresh();
msgContent.setText("请输入数字");
msgStage.show();
}
});
tableView1.getColumns().addAll(num1, type1, project1, cost1);
@ -531,8 +577,8 @@ public class CSXWHDialog extends Application {
}
tableView1.refresh();
} else {
Alert alert = new Alert(AlertType.ERROR, "存在某行的内容全为空,请检查");
alert.show();
msgContent.setText("存在某行的内容全为空,请检查");
msgStage.show();
}
});
@ -553,15 +599,22 @@ public class CSXWHDialog extends Application {
primaryStage.setScene(scene);
primaryStage.setTitle("测试项维护");
primaryStage.show();
primaryStage.setAlwaysOnTop(true);
}
public ObservableList search(String name, ObservableList list) {
ObservableList results = FXCollections.observableArrayList();
Pattern pattern = Pattern.compile(name);
for (int i = 0; i < list.size(); i++) {
Matcher matcher = pattern.matcher(((ComponentBean) list.get(i)).getType());
if (matcher.find()) {
// Matcher matcher = pattern.matcher(((ComponentBean) list.get(i)).getType());
// if (matcher.find()) {
// results.add(list.get(i));
// }
if (((ComponentBean) list.get(i)).getType().contains(name)
|| ((ComponentBean) list.get(i)).getProject().contains(name)
|| ((ComponentBean) list.get(i)).getTime().contains(name)
|| ((ComponentBean) list.get(i)).getNumber().contains(name)
|| ((ComponentBean) list.get(i)).getCost().contains(name)) {
results.add(list.get(i));
}
}
@ -572,8 +625,13 @@ public class CSXWHDialog extends Application {
ObservableList results = FXCollections.observableArrayList();
Pattern pattern = Pattern.compile(name);
for (int i = 0; i < list.size(); i++) {
Matcher matcher = pattern.matcher(((MachineBean) list.get(i)).getType());
if (matcher.find()) {
// Matcher matcher = pattern.matcher(((MachineBean) list.get(i)).getType());
// if (matcher.find()) {
// results.add(list.get(i));
// }
if (((MachineBean) list.get(i)).getType().contains(name)
|| ((MachineBean) list.get(i)).getProject().contains(name)
|| ((MachineBean) list.get(i)).getCost().contains(name)) {
results.add(list.get(i));
}
}
@ -658,13 +716,20 @@ public class CSXWHDialog extends Application {
}
ps.setDouble(5, Double.valueOf(com.getCost()));
int rs = ps.executeUpdate();
if (rs == 1)
if (rs == 1) {
System.out.println("添加成功");
else
msgContent.setText("添加成功");
msgStage.show();
} else {
System.out.println("添加失败");
msgContent.setText("添加失败");
msgStage.show();
}
} catch (Exception e) {
System.out.println("添加失败");
msgContent.setText("添加失败");
msgStage.show();
} finally {
if (ps != null) {
try {
@ -697,10 +762,15 @@ public class CSXWHDialog extends Application {
ps.setDouble(3, Double.valueOf(mac.getCost()));
int rs = ps.executeUpdate();
System.out.println(rs);
if (rs == 1)
if (rs == 1) {
System.out.println("添加成功");
else
msgContent.setText("添加成功");
msgStage.show();
} else {
System.out.println("添加失败");
msgContent.setText("添加失败");
msgStage.show();
}
} catch (Exception e) {
System.out.println("添加失败");
@ -741,10 +811,15 @@ public class CSXWHDialog extends Application {
ps.setDouble(5, Double.valueOf(com.getCost()));
ps.setInt(6, com.getCompId());
int rs = ps.executeUpdate();
if (rs == 1)
if (rs == 1) {
System.out.println("更新成功");
else
msgContent.setText("更新成功");
msgStage.show();
} else {
System.out.println("更新失败");
msgContent.setText("更新失败");
msgStage.show();
}
} catch (Exception e) {
} finally {
@ -771,10 +846,16 @@ public class CSXWHDialog extends Application {
ps = con.prepareStatement(sql);
ps.setInt(1, id);
int rs = ps.executeUpdate();
if (rs > 0)
System.out.println("成功");
else
System.out.println("失败");
if (rs > 0) {
System.out.println("更新成功");
msgContent.setText("更新成功");
msgStage.show();
} else {
System.out.println("更新成功");
msgContent.setText("更新失败");
msgStage.show();
}
} catch (Exception e) {
} finally {
if (ps != null) {
@ -808,10 +889,15 @@ public class CSXWHDialog extends Application {
ps.setDouble(3, Double.valueOf(mac.getCost()));
ps.setInt(4, mac.getMacId());
int rs = ps.executeUpdate();
if (rs == 1)
if (rs == 1) {
System.out.println("更新成功");
else
msgContent.setText("更新成功");
msgStage.show();
} else {
System.out.println("更新失败");
msgContent.setText("更新失败");
msgStage.show();
}
} catch (Exception e) {
} finally {
@ -832,3 +918,101 @@ public class CSXWHDialog extends Application {
}
}
}
class EditableStringTableCell<T, E> extends TableCell<T, String> {
protected TextField textField;
protected ChangeListener<? super Boolean> changeListener = (obs, ov, nv) -> {
if (!nv) {
commitEdit(textField.getText());
}
};
public EditableStringTableCell() {
}
@Override
public void startEdit() {
if (editableProperty().get()) {
if (!isEmpty()) {
super.startEdit();
createTextField();
setText(null);
setGraphic(textField);
textField.requestFocus();
}
}
}
@Override
public void cancelEdit() {
super.cancelEdit();
setText(getItem());
setGraphic(null);
}
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
if (isEditing()) {
if (textField != null) {
textField.setText(getString());
textField.selectAll();
}
setText(null);
setGraphic(textField);
} else {
setText(getString());
setGraphic(null);
}
}
}
protected void createTextField() {
textField = new TextField(getString());
textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
textField.focusedProperty().addListener(changeListener);
textField.setOnAction(evt -> commitEdit(textField.getText()));
textField.setOnKeyPressed((ke) -> {
if (ke.getCode().equals(KeyCode.ESCAPE)) {
textField.focusedProperty().removeListener(changeListener);
cancelEdit();
}
if (ke.getCode().equals(KeyCode.TAB)) {
commitEdit(textField.getText());
}
});
}
protected String getString() {
return getItem() == null ? "" : getItem().toString();
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void commitEdit(String item) {
textField.focusedProperty().removeListener(changeListener);
if (isEditing()) {
super.commitEdit(item);
} else {
final TableView table = getTableView();
if (table != null) {
TablePosition position = new TablePosition(getTableView(), getTableRow().getIndex(), getTableColumn());
CellEditEvent editEvent = new CellEditEvent(table, position, TableColumn.editCommitEvent(), item);
Event.fireEvent(getTableColumn(), editEvent);
}
updateItem(item, false);
if (table != null) {
table.edit(-1, null);
}
}
}
}

@ -1,6 +1,7 @@
package com.connor.jd.plm.form;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@ -15,6 +16,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
@ -29,6 +32,7 @@ import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import com.connor.jd.plm.beans.ComponentBean;
import com.connor.jd.plm.beans.JG;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
@ -59,6 +63,10 @@ public class CSJHForm extends AbstractRendering {
private ObservableList<ComponentBean> componentData = FXCollections.observableArrayList();
String[] propNames = new String[] { "jd2_syxh", "jd2_symd", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syzq",
"jd2_syfy", "jd2_jhrc", "jd2_sjrc", "jd2_syzt", "jd2_syjg", "jd2_sycs", "jd2_syry", "jd2_csbg", "jd2_bz" };
private JLabel label3;
private List<Integer> editable = new ArrayList<Integer>();
private Map<String, JG> res;
private Map<Integer, String> rowNo;
public CSJHForm(TCComponent form) throws Exception {
super();
@ -176,7 +184,8 @@ public class CSJHForm extends AbstractRendering {
final JTable table = new JTable(model) {
@Override
public boolean isCellEditable(int row, int column) {
if (column == 3 || column == 4 || column == 5 || column == 6 || column == 7 || column == 14)
if (column == 3 || column == 4 || column == 5 || column == 6 || column == 7 || column == 14
|| column == 12 || editable.contains(row))
return false;
else
return true;
@ -191,8 +200,88 @@ public class CSJHForm extends AbstractRendering {
for (int i = 0; i < 16; i++) {
table.getColumn(table.getColumnName(i)).setMinWidth(60);
}
table.getColumn(table.getColumnName(10)).setCellEditor(new DefaultCellEditor(testStage));
table.getColumn(table.getColumnName(11)).setCellEditor(new DefaultCellEditor(testResult));
DefaultCellEditor dce1 = new DefaultCellEditor(testStage) {
int row;
@Override
public Component getTableCellEditorComponent(JTable paramJTable, Object paramObject, boolean paramBoolean,
int paramInt1, int paramInt2) {
// TODO Auto-generated method stub
row = paramInt1;
return super.getTableCellEditorComponent(paramJTable, paramObject, paramBoolean, paramInt1, paramInt2);
}
@Override
public Object getCellEditorValue() {
Object obj = super.getCellEditorValue();
if ("完成".equals(obj.toString())) {
editable.add(row);
} else {
if (editable.contains(row)) {
editable.remove(row);
}
}
return obj;
}
};
DefaultCellEditor dce2 = new DefaultCellEditor(testResult) {
JTable t;
int row;
int num;
@Override
public Component getTableCellEditorComponent(JTable paramJTable, Object paramObject, boolean paramBoolean,
int paramInt1, int paramInt2) {
// TODO Auto-generated method stub
t = paramJTable;
row = paramInt1;
String str = t.getValueAt(row, 12) == null ? "" : t.getValueAt(row, 12).toString();
num = Objects.equals(str, "") ? 0 : Integer.parseInt(str);
return super.getTableCellEditorComponent(paramJTable, paramObject, paramBoolean, paramInt1, paramInt2);
}
@Override
public Object getCellEditorValue() {
// TODO Auto-generated method stub
Object obj = super.getCellEditorValue();
if (res.containsKey(rowNo.get(row))) {
if (num >= res.get(rowNo.get(row)).getTimes()) {
res.put(rowNo.get(row), new JG(row, num, obj.toString()));
}
} else {
res.put(rowNo.get(row), new JG(row, num, obj.toString()));
}
boolean flag = false;
for (Entry<String, JG> entry : res.entrySet()) {
if ("不合格".equals(entry.getValue().getJg())) {
flag = true;
break;
}
}
if (flag) {
label3.setText("结论:不合格");
} else {
label3.setText("结论:合格");
}
return obj;
}
};
table.getColumn(table.getColumnName(10)).setCellEditor(dce1);
table.getColumn(table.getColumnName(11)).setCellEditor(dce2);
if (form.isCheckedOut()) {
table.setEnabled(true);
} else {
table.setEnabled(false);
}
JPanel panelLable = new JPanel();
JLabel label = new JLabel("试验费用总计:");
JLabel label2 = new JLabel();
@ -204,8 +293,43 @@ public class CSJHForm extends AbstractRendering {
allcost += Double.valueOf(value);
}
label2.setText(allcost + "元");
label3 = new JLabel("结论:合格");
res = new HashMap<String, JG>();
rowNo = new HashMap<Integer, String>();
String no;
String jg;
for (int i = 0; i < tables.length; i++) {
no = tables[i].getProperty("jd2_no");
rowNo.put(i, no);
jg = tables[i].getProperty("jd2_syjg");
int times = Integer.parseInt(
Objects.equals(tables[i].getProperty("jd2_sycs"), "") ? "0" : tables[i].getProperty("jd2_sycs"));
if ("完成".equals(tables[i].getProperty("jd2_syzt"))) {
editable.add(i);
}
if (res.containsKey(no)) {
if (times >= res.get(no).getTimes()) {
editable.add(res.get(no).getRow());
res.put(no, new JG(i, times, jg));
}
} else {
res.put(no, new JG(i, times, jg));
}
}
for (Entry<String, JG> entry : res.entrySet()) {
System.out.println(entry.getKey() + entry.getValue().getRow() + entry.getValue().getJg()
+ entry.getValue().getTimes());
if ("不合格".equals(entry.getValue().getJg())) {
label3.setText("结论:不合格");
}
}
panelLable.add(label);
panelLable.add(label2);
panelLable.add(label3);
JPanel panel = new JPanel();
JScrollPane pane = new JScrollPane(table);
GridBagLayout gbl = new GridBagLayout();
@ -243,11 +367,11 @@ public class CSJHForm extends AbstractRendering {
if (file != null) {
String filePath = file.getPath();
String fileName = file.getName();
String[] filename = fileName.split(".");
String filename = fileName.substring(0, fileName.lastIndexOf("."));
System.out.println(filePath);
System.out.println(fileName);
int row = table.getSelectedRow();
String value = (String) model.getValueAt(row, 14);
String value = model.getValueAt(row, 14) == null ? "" : model.getValueAt(row, 14).toString();
if (value.equals("")) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session.getTypeComponent("JD2_GTCSBG");
@ -263,7 +387,7 @@ public class CSJHForm extends AbstractRendering {
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename[0], "", msType);
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
model.setValueAt(item.getProperty("current_id"), row, 14);
@ -272,15 +396,45 @@ public class CSJHForm extends AbstractRendering {
}
} else {
// 添加到数据集
boolean exist = false;
try {
TCComponent[] tcc = itemR.getTCProperty("JD2_CSBG").getReferenceValueArray();
for (int i = 0; i < tcc.length; i++) {
if (value.equals(tcc[i].getProperty("current_id"))) {
exist = true;
TCComponentItem item = (TCComponentItem) tcc[i];
TCComponent[] tccitem = item.getLatestItemRevision().getTCProperty("IMAN_specification")
.getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.setFiles(new String[] { file.getPath() }, new String[] { "excel" });
dataset.setProperty("object_name", filename);
item.setProperty("object_name", filename);
item.getLatestItemRevision().setProperty("object_name", filename);
}
}
if (!exist) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session
.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述",
null);
itemR.add("JD2_CSBG", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
model.setValueAt(item.getProperty("current_id"), row, 14);
} catch (TCException e1) {
e1.printStackTrace();
}
}
} catch (TCException e1) {
@ -303,7 +457,7 @@ public class CSJHForm extends AbstractRendering {
if (file != null) {
String filePath = file.getPath();
String fileName = file.getName();
String[] filename = fileName.split(".");
String filename = fileName.substring(0, fileName.lastIndexOf("."));
System.out.println(filePath);
System.out.println(fileName);
if (value.equals("")) {
@ -321,25 +475,52 @@ public class CSJHForm extends AbstractRendering {
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename[0], "", msType);
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
model.setValueAt(item.getProperty("current_id"), row, 14);
} catch (TCException e1) {
e1.printStackTrace();
}
} else {
// 添加到数据集
boolean exist = false;
try {
TCComponent[] tcc = itemR.getTCProperty("JD2_CSBGHZ").getReferenceValueArray();
for (int i = 0; i < tcc.length; i++) {
if (value.equals(tcc[i].getProperty("current_id"))) {
exist = true;
TCComponentItem item = (TCComponentItem) tcc[i];
TCComponent[] tccitem = item.getLatestItemRevision().getTCProperty("IMAN_specification")
.getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.setFiles(new String[] { file.getPath() }, new String[] { "excel" });
dataset.setProperty("object_name", filename);
item.setProperty("object_name", filename);
item.getLatestItemRevision().setProperty("object_name", filename);
}
}
if (!exist) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session
.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述",
null);
itemR.add("JD2_CSBGHZ", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
} catch (TCException e1) {
e1.printStackTrace();
}
}
} catch (TCException e1) {
@ -370,7 +551,7 @@ public class CSJHForm extends AbstractRendering {
chishu = "0";
}
temp[12] = String.valueOf(Integer.valueOf(chishu) + 1);
temp[14] = (String) model.getValueAt(table.getSelectedRow(), 14);
// temp[14] = (String) model.getValueAt(table.getSelectedRow(), 14);
temp[15] = (String) model.getValueAt(table.getSelectedRow(), 15);
model.insertRow(table.getSelectedRow() + 1, temp);
for (int i = table.getSelectedRow() + 1; i < model.getRowCount(); i++) {
@ -385,6 +566,8 @@ public class CSJHForm extends AbstractRendering {
allcost2 += Double.valueOf(value);
}
label2.setText(allcost2 + "元");
editable.add(table.getSelectedRow());
rowNo.put(table.getSelectedRow() + 1, rowNo.get(table.getSelectedRow()));
});
table.addMouseListener(new MouseAdapter() {
@ -433,6 +616,7 @@ public class CSJHForm extends AbstractRendering {
for (int i = 0; i < model.getRowCount(); i++) {
CreateIn in = new CreateIn();
Map<String, String> propMap = new HashMap<String, String>();
propMap.put("jd2_no", rowNo.get(i));
for (int j = 0; j < propNames.length; j++) {
propMap.put(propNames[j],
model.getValueAt(i, j + 1) == null ? "" : model.getValueAt(i, j + 1).toString());
@ -464,4 +648,10 @@ public class CSJHForm extends AbstractRendering {
}
}
@Override
public boolean isRenderingModified() {
// TODO Auto-generated method stub
return form.isCheckedOut();
}
}

@ -0,0 +1,266 @@
package com.connor.jd.plm.form;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import com.connor.jd.plm.table.CTMap;
import com.connor.jd.plm.table.CTable;
import com.connor.jd.plm.table.MyCellEditor4;
import com.connor.jd.plm.table.TCTableUtil;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
public class ComponentTestFrame extends JFrame {
private CTMap model;
private CTable table;
private List<Entity> list;
private int bottom;
private Container container;
private TCComponentForm form;
private TCSession session;
private MyCallBack callBack;
private static ComponentTestFrame instance;
public static ComponentTestFrame getInstance(TCComponentForm form, MyCallBack callBack) {
if (instance == null) {
instance = new ComponentTestFrame(form);
instance.callBack = callBack;
} else {
instance.bottom = 0;
instance.form = form;
instance.callBack = callBack;
instance.init();
}
return instance;
}
private ComponentTestFrame(TCComponentForm form) {
this.form = form;
this.session = (TCSession) AIFUtility.getCurrentApplication().getSession();
this.init();
}
private void init() {
this.setTitle("部件测试项目");
this.setSize(560, 400);
this.setResizable(true);
this.setAlwaysOnTop(true);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
container = this.getContentPane();
container.setLayout(new BorderLayout());
container.setPreferredSize(new Dimension(600, 400));
model = new CTMap(10, 7);
model.setValueAt("序号", 0, 0);
model.setValueAt("部品类型", 0, 1);
model.setValueAt("试验项目", 0, 2);
model.setValueAt("试验时间", 0, 3);
model.setValueAt("样品数量", 0, 4);
model.setValueAt("试验费用", 0, 5);
model.setValueAt("是否选择", 0, 6);
table = new CTable(model) {
@Override
public boolean isCellEditable(int row, int col) {
if (row == 0 || col == 0) {
return false;
}
return true;
}
};
table.setRowHeight(25);
table.setBorder(BorderFactory.createLineBorder(Color.black));
for (int i = 0; i < model.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setPreferredWidth(80);
}
DefaultTableCellRenderer tcr1 = new DefaultTableCellRenderer() {
// 重写方法
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
// TODO Auto-generated method stub
if (value instanceof JCheckBox) {
return (JCheckBox) value;
}
int maxPreferredHeight = 0;
for (int i = 0; i < table.getColumnCount(); i++) {
setText("" + table.getValueAt(row, i));
setSize(table.getColumnModel().getColumn(column).getWidth(), 0);
maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height);
}
setBackground(Color.white);
// if(points1.contains(new Point(row,column)))
// setForeground(new Color(0,0,255));
// else
setForeground(Color.black);
if (isSelected) {
setBackground(new Color(0, 120, 215));
setForeground(Color.white);
}
if (table.getRowHeight(row) != maxPreferredHeight) // 少了这行则处理器瞎忙
table.setRowHeight(row, maxPreferredHeight);
setText(value == null ? "" : value.toString());
return this;
}
};
tcr1.setHorizontalAlignment(SwingConstants.CENTER);
table.setDefaultRenderer(Object.class, tcr1);
table.getColumnModel().getColumn(6).setCellEditor(new MyCellEditor4(new JTextField()));
// 填写数据
try {
list = Db.use().findAll("JD2_COMPONENT");
bottom = list.size();
for (int i = 0; i < bottom; i++) {
if (i > model.getRowCount() - 2) {
model.addRow();
}
int row = i + 1;
model.setValueAt(row, row, 0);
model.setValueAt(list.get(i).getStr("TEST_TYPE"), row, 1);
model.setValueAt(list.get(i).getStr("TEST_PROJECT"), row, 2);
model.setValueAt(list.get(i).getStr("TEST_TIME"), row, 3);
model.setValueAt(list.get(i).getInt("TEST_NUM"), row, 4);
model.setValueAt(list.get(i).getInt("TEST_COST"), row, 5);
model.setValueAt(new JCheckBox(), row, 6);
System.out.println(list.get(i).toString());
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 按钮
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton createTest = new JButton("创建测试计划");
createTest.addActionListener(createTest());
JButton addTestItem = new JButton("新增测试项");
addTestItem.addActionListener(addTestItem());
JButton cancel = new JButton("取消");
cancel.addActionListener(cancel());
buttonPanel.add(createTest);
buttonPanel.add(addTestItem);
buttonPanel.add(cancel);
ScrollPane scrollPane = new ScrollPane();
scrollPane.add(table);
container.add(scrollPane, BorderLayout.CENTER);
container.add(buttonPanel, BorderLayout.SOUTH);
this.setVisible(true);
}
private ActionListener createTest() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
TCComponentItemRevision rev = (TCComponentItemRevision) form.whereReferenced()[0].getComponent();
TCComponentItemType type = (TCComponentItemType) session.getTypeComponent("Item");
TCComponentItem item = type.create(null, null, "JD2_GTCSJH", "测试计划", "", null);
rev.add("JD2_CSJH", item);
TCComponentItemRevision rev1 = item.getLatestItemRevision();
TCComponentForm form1 = (TCComponentForm) rev1.getRelatedComponents("IMAN_master_form_rev")[0];
String[] colNames = new String[] { "jd2_no", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syzq",
"jd2_syfy", "jd2_sycs" };
List<String[]> list = new ArrayList<String[]>();
String[] row = new String[7];
for (int i = 1; i <= bottom; i++) {
JCheckBox jb = (JCheckBox) model.getValueAt(i, 6);
if (jb.isSelected()) {
for (int ii = 2; ii < 6; ii++) {
row[ii - 2] = model.getValueAt(i, ii) == null ? "" : model.getValueAt(i, ii).toString();
}
// TCComponentPerson p = (TCComponentPerson) session.getUser().getUserInformation().get(0);
list.add(new String[] { i + "", form.getTCProperty("owning_user").getUIFValue(), row[0],
row[2], row[1], row[3], "1" });
}
}
String[][] data = list.toArray(new String[list.size()][7]);
TCTableUtil.setTableRows(form1, "jd2_csjh", "JD2_CSJHTABLE", colNames, data);
callBack.execute(item.getProperty("item_id"));
dispose();
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
};
}
private ActionListener addTestItem() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (bottom > model.getRowCount() - 2) {
model.addRow();
}
int num = 1;
if (bottom > 0) {
num = Integer.parseInt(model.getValueAt(bottom, 0).toString());
}
model.setValueAt(num + 1, ++bottom, 0);
model.setValueAt(new JCheckBox(), bottom, 6);
}
};
}
@Override
public void dispose() {
// TODO Auto-generated method stub
container.removeAll();
super.dispose();
}
private ActionListener cancel() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
dispose();
}
};
}
}

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

@ -0,0 +1,639 @@
package com.connor.jd.plm.form;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import com.connor.jd.plm.beans.JG;
import com.connor.jd.plm.table.TCTableUtil;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentDatasetType;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.stylesheet.AbstractRendering;
public class GTCSJHForm extends AbstractRendering {
private TCComponentForm form;
private Map<String, String> parentProp;
private String[] labelNames = { "项目信息:", "立项时间:", "基本型号:", "测试型号:", "产品型号:", "项目资料:", "产品经理:", "产品变更点:", "品质经理:",
"开发日程:", "开发等级:", "开发阶段:" };
private String[] labellTexts = { "jd2_xmxx", "jd2_lxsj", "jd2_jbxh", "jd2_csxh", "jd2_cpxh", "jd2_xmzl", "jd2_cpjl",
"jd2_cpbgd", "jd2_pzjl", "jd2_kfrc", "jd2_kfdj", "jd2_kfjd" };
private String[] colNames = { "jd2_no", "jd2_syxh", "jd2_symd", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syzq",
"jd2_syfy", "jd2_jhrc", "jd2_sjrc", "jd2_syzt", "jd2_syjg", "jd2_sycs", "jd2_syry", "jd2_csbg", "jd2_bz" };
private String[] colDisplayNames = new String[] { "realNo", "NO", "试验型号", "试验目的", "委托人员", "试验项目", "试验台数", "试验周期",
"试验费用", "计划日程", "实际日程", "试验状态", "实验结果", "第_次试验", "实验人员", "测试报告", "备注" };
private List<Integer> disableRows = new ArrayList<Integer>();
private List<Integer> disableColumns = Arrays.asList(4, 5, 6, 7, 8, 13, 15);
private Map<String, JG> resultMap = new HashMap<String, JG>();
private JTable table;
private DefaultTableModel model;
private TCComponentItemRevision rev;
private TCSession session;
private JLabel cost;
private JLabel jg;
public GTCSJHForm(TCComponent arg0) throws Exception {
super(arg0);
if (arg0 instanceof TCComponentForm) {
this.form = (TCComponentForm) arg0;
this.session = (TCSession) AIFUtility.getCurrentApplication().getSession();
loadRendering();
}
}
@Override
public void loadRendering() throws TCException {
AIFComponentContext[] contexts = form.whereReferenced();
for (int i = 0; i < contexts.length; i++) {
if (contexts[i].getComponent() instanceof TCComponentItemRevision) {
try {
rev = (TCComponentItemRevision) contexts[i].getComponent();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
// TODO Auto-generated method stub
this.setLayout(new BorderLayout());
JPanel root = new JPanel(new BorderLayout());
JPanel top = new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel inner = new JPanel();
JPanel innerTop = new JPanel();
JPanel innerCenter = new JPanel(new BorderLayout());
root.setPreferredSize(new Dimension(1000, 500));
inner.setLayout(null);
inner.setPreferredSize(new Dimension(1000, 420));
innerTop.setLayout(null);
innerTop.setPreferredSize(new Dimension(880, 100));
innerTop.setBorder(BorderFactory.createLineBorder(Color.black));
innerTop.setBounds(10, 0, 880, 100);
innerCenter.setPreferredSize(new Dimension(880, 300));
innerCenter.setBorder(BorderFactory.createLineBorder(Color.black));
innerCenter.setBounds(10, 120, 880, 300);
JLabel title = new JLabel();
AIFComponentContext[] aif = form.whereReferenced();
for (AIFComponentContext a : aif) {
if ("JD2_GTXPXMCSJHRevision".equals(a.getComponent().getType())) {
try {
title.setText(a.getComponent().getProperty("object_name"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
title.setFont(new Font("宋体", Font.PLAIN, 24));
top.add(title);
JLabel[] infoText = new JLabel[13];
JLabel[] infoValue = new JLabel[12];
infoText[0] = new JLabel("基本信息:");
infoText[0].setBounds(10, 0, 80, 25);
for (int i = 1; i < 13; i++) {
infoText[i] = new JLabel(labelNames[i - 1]);
// infoValue[i - 1] = new JLabel(labellTexts[i - 1]);
infoValue[i - 1] = new JLabel();
}
for (int i = 1; i < 7; i++) {
infoText[i].setBounds(25 * i + 120 * (i - 1), 30, 60, 25);
infoValue[i - 1].setBounds(85 * i + 60 * (i - 1), 30, 60, 25);
infoText[i + 6].setBounds(25 * i + 120 * (i - 1), 60, 60, 25);
infoValue[i + 5].setBounds(85 * i + 60 * (i - 1), 60, 60, 25);
}
innerTop.add(infoText[0]);
for (int i = 0; i < 12; i++) {
innerTop.add(infoText[i + 1]);
innerTop.add(infoValue[i]);
}
model = new DefaultTableModel(colDisplayNames, 0) {
@Override
public boolean isCellEditable(int paramInt1, int paramInt2) {
// TODO Auto-generated method stub
if (disableRows.contains(paramInt1) || disableColumns.contains(paramInt2)) {
return false;
}
return true;
}
};
JComboBox<String> status = new JComboBox<String>();
status.addItem("待测");
status.addItem("进行中");
status.addItem("完成");
DefaultCellEditor dce1 = new DefaultCellEditor(status) {
int row;
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
int column) {
this.row = row;
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
@Override
public Object getCellEditorValue() {
Object obj = super.getCellEditorValue();
if ("完成".equals(obj == null ? "" : obj.toString())) {
disableRows.add(row);
}
return obj;
}
};
JComboBox<String> result = new JComboBox<String>();
result.addItem("合格");
result.addItem("不合格");
DefaultCellEditor dce2 = new DefaultCellEditor(result) {
JTable table;
int row;
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
int column) {
this.table = table;
this.row = row;
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
@Override
public Object getCellEditorValue() {
Object obj = super.getCellEditorValue();
String res = (obj == null ? "" : obj.toString());
String no = table.getValueAt(row, 0).toString();
Object temp;
int times = Integer.parseInt((temp = table.getValueAt(row, 13)) == null ? "0" : temp.toString().trim());
addResult(no, row, times, res);
jg.setText(getResult());
return obj;
}
};
table = new JTable(model);
TableColumn tc = table.getColumnModel().getColumn(0);
for (int i = 1; i < table.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setMinWidth(100);
}
hiddenColumn(table, 0);
table.getColumnModel().getColumn(11).setCellEditor(dce1);
table.getColumnModel().getColumn(12).setCellEditor(dce2);
table.setRowHeight(25);
table.setAutoscrolls(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (table.getSelectedColumn() == 15) {
if (e.getClickCount() == 2) {
System.out.println("双击了");
int selectedRow = table.getSelectedRow(); // 获得选中行索引
String value = (String) model.getValueAt(selectedRow, 15);
if (value == null)
value = "";
if (!value.equals("")) {
try {
TCComponent[] result = session.search("零组件 ID", new String[] { "零组件 ID" },
new String[] { value });
TCComponentItem item = (TCComponentItem) result[0];
TCComponent[] tccitem = item.getLatestItemRevision().getTCProperty("IMAN_specification")
.getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.open();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
}
});
JScrollPane jsp = new JScrollPane(table);
jsp.setAutoscrolls(true);
innerCenter.add(jsp, BorderLayout.CENTER);
JButton test = new JButton("<html>测试报告<br>上传</html>");
JButton collect = new JButton("<html>汇总结论<br>上传</html>");
JButton again = new JButton("再次试验");
test.setBounds(900, 120, 100, 50);
collect.setBounds(900, 175, 100, 50);
again.setBounds(900, 230, 100, 25);
test.addActionListener(test());
collect.addActionListener(collect());
again.addActionListener(again());
inner.add(test);
inner.add(collect);
inner.add(again);
JLabel label1 = new JLabel("试验费用总计:");
JLabel label2 = new JLabel("结论:");
cost = new JLabel();
jg = new JLabel();
label1.setBounds(300, 470, 120, 25);
cost.setBounds(420, 470, 50, 25);
label2.setBounds(480, 470, 50, 25);
jg.setBounds(530, 470, 60, 25);
root.add(label1);
root.add(label2);
root.add(cost);
root.add(jg);
// 获取信息
AIFComponentContext[] aifs = form.whereReferenced();
String temp;
for (AIFComponentContext a1 : aifs) {
System.out.println("测试计划版本:" + (temp = a1.getComponent().getType()));
if ("JD2_GTXPXMCSJHRevision".equals(temp)) {
TCComponentItemRevision rev = (TCComponentItemRevision) a1.getComponent();
AIFComponentContext[] aifs2 = rev.getItem().whereReferenced();
for (AIFComponentContext a2 : aifs2) {
System.out.println("新品测试项目清单版本:" + (temp = a2.getComponent().getType()));
if ("JD2_GTXPCSXQDRevision".equals(temp)) {
TCComponentItemRevision rev2 = (TCComponentItemRevision) a2.getComponent();
TCComponentForm parent = (TCComponentForm) rev2.getRelatedComponents("IMAN_master_form_rev")[0];
parentProp = parent.getProperties();
}
}
}
}
if (parentProp != null) {
for (int i = 0; i < labellTexts.length; i++) {
if (parentProp.containsKey(labellTexts[i])) {
String str = parentProp.get(labellTexts[i]);
infoValue[i].setText(str);
} else {
System.out.println("属性\"" + labellTexts[i] + "\"不存在");
}
}
}
String[][] data = TCTableUtil.getTableRows(form, "jd2_csjhtable", colNames);
// colNames = { "jd2_no", "jd2_syxh", "jd2_symd", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syzq",
// "jd2_syfy", "jd2_jhrc", "jd2_sjrc", "jd2_syzt", "jd2_syjg", "jd2_sycs", "jd2_syry", "jd2_csbg", "jd2_bz" };
// colDisplayNames = new String[] { "realNo", "NO", "试验型号", "试验目的", "委托人员", "试验项目", "试验台数", "试验周期",
// "试验费用", "计划日程", "实际日程", "试验状态", "实验结果", "第_次试验", "实验人员", "测试报告", "备注" };
System.out.println(Arrays.deepToString(data));
System.out.println(data.length);
double sum = 0;
for (int i = 0; i < data.length; i++) {
String[] rowData = new String[17];
rowData[0] = data[i][0];
rowData[1] = i + 1 + "";
for (int ii = 1; ii < colNames.length; ii++) {
rowData[ii + 1] = data[i][ii];
}
Arrays.toString(rowData);
model.addRow(rowData);
if ("完成".equals(data[i][10])) {
disableRows.add(i);
}
sum += Double.parseDouble(data[i][7]);
addResult(data[i][0], i, Integer.parseInt(data[i][12]), data[i][11]);
}
table.revalidate();
table.repaint();
cost.setText(sum + "");
jg.setText(getResult());
inner.add(innerTop);
inner.add(innerCenter);
root.add(top, BorderLayout.NORTH);
root.add(inner, BorderLayout.CENTER);
ScrollPane sc = new ScrollPane();
sc.add(root);
this.add(sc, BorderLayout.CENTER);
}
@Override
public void saveRendering() {
// TODO Auto-generated method stub
String[][] data = new String[0][];
List<String[]> dataList = new ArrayList<String[]>();
Object obj;
for (int i = 0; i < table.getRowCount(); i++) {
String[] rowData = new String[colNames.length];
for (int ii = 0; ii < colNames.length; ii++) {
rowData[ii] = (obj = table.getValueAt(i, ii > 0 ? ii + 1 : ii)) == null ? "" : obj.toString();
}
dataList.add(rowData);
}
data = dataList.toArray(new String[dataList.size()][]);
TCTableUtil.setTableRows(form, "jd2_csjhtable", "JD2_CSJHTABLE", colNames, data);
}
private ActionListener test() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("选择上传的测试报告");
FileFilter filter = new FileNameExtensionFilter("Excel工作簿(.xlsx)", "xlsx");
chooser.setFileFilter(filter);
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
if (file != null) {
String filePath = file.getPath();
String fileName = file.getName();
String filename = fileName.substring(0, fileName.lastIndexOf("."));
System.out.println(filePath);
System.out.println(fileName);
int row = table.getSelectedRow();
String value = model.getValueAt(row, 15) == null ? "" : model.getValueAt(row, 15).toString();
if (value.equals("")) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述", null);
rev.add("JD2_CSBG", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
model.setValueAt(item.getProperty("current_id"), row, 15);
} catch (TCException e1) {
e1.printStackTrace();
}
} else {
// 添加到数据集
boolean exist = false;
try {
TCComponent[] tcc = rev.getTCProperty("JD2_CSBG").getReferenceValueArray();
for (int i = 0; i < tcc.length; i++) {
if (value.equals(tcc[i].getProperty("current_id"))) {
exist = true;
TCComponentItem item = (TCComponentItem) tcc[i];
TCComponent[] tccitem = item.getLatestItemRevision()
.getTCProperty("IMAN_specification").getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.setFiles(new String[] { file.getPath() }, new String[] { "excel" });
dataset.setProperty("object_name", filename);
item.setProperty("object_name", filename);
item.getLatestItemRevision().setProperty("object_name", filename);
}
}
if (!exist) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session
.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName,
"描述", null);
rev.add("JD2_CSBG", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
model.setValueAt(item.getProperty("current_id"), row, 15);
} catch (TCException e1) {
e1.printStackTrace();
}
}
} catch (TCException e1) {
e1.printStackTrace();
}
}
}
}
};
}
private ActionListener collect() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int row = table.getSelectedRow();
String value = (String) model.getValueAt(row, 15);
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("选择上传的汇总结论");
FileFilter filter = new FileNameExtensionFilter("Excel工作簿(.xlsx)", "xlsx");// 设置文件过滤器只列出JPG或GIF格式的图片
chooser.setFileFilter(filter);
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
if (file != null) {
String filePath = file.getPath();
String fileName = file.getName();
String filename = fileName.substring(0, fileName.lastIndexOf("."));
System.out.println(filePath);
System.out.println(fileName);
if (value.equals("")) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName, "描述", null);
rev.add("JD2_CSBGHZ", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
} catch (TCException e1) {
e1.printStackTrace();
}
} else {
// 添加到数据集
boolean exist = false;
try {
TCComponent[] tcc = rev.getTCProperty("JD2_CSBGHZ").getReferenceValueArray();
for (int i = 0; i < tcc.length; i++) {
if (value.equals(tcc[i].getProperty("current_id"))) {
exist = true;
TCComponentItem item = (TCComponentItem) tcc[i];
TCComponent[] tccitem = item.getLatestItemRevision()
.getTCProperty("IMAN_specification").getReferenceValueArray();
TCComponentDataset dataset = (TCComponentDataset) tccitem[0];
dataset.setFiles(new String[] { file.getPath() }, new String[] { "excel" });
dataset.setProperty("object_name", filename);
item.setProperty("object_name", filename);
item.getLatestItemRevision().setProperty("object_name", filename);
}
}
if (!exist) {
try {
TCComponentItemType itemtype = (TCComponentItemType) session
.getTypeComponent("JD2_GTCSBG");
String itemId = itemtype.getNewID();
String itemRev = itemtype.getNewRev(null);
TCComponentItem item = itemtype.create(itemId, itemRev, "JD2_GTCSBG", fileName,
"描述", null);
rev.add("JD2_CSBGHZ", item);
TCComponentDatasetType datasetType = (TCComponentDatasetType) session
.getTypeComponent("Dataset");
String msType = "";
if (filePath.endsWith(".xls")) {
msType = "MSExcel";
} else if (filePath.endsWith(".xlsx") || filePath.endsWith(".xlsm")) {
msType = "MSExcelX";
}
TCComponentDataset datasetMSExcelX = datasetType.create(filename, "", msType);
datasetMSExcelX.setFiles(new String[] { filePath }, new String[] { "excel" });// 两参文件路径命名应用text
item.getLatestItemRevision().add("IMAN_specification", datasetMSExcelX);
} catch (TCException e1) {
e1.printStackTrace();
}
}
} catch (TCException e1) {
e1.printStackTrace();
}
}
}
}
};
}
private ActionListener again() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int row = table.getSelectedRow();
Object obj;
// "realNo", "NO", "试验型号", "试验目的", "委托人员", "试验项目", "试验台数", "试验周期",
// "试验费用", "计划日程", "实际日程", "试验状态", "实验结果", "第_次试验", "实验人员", "测试报告", "备注"
if (row != -1) {
String realNum = (obj = table.getValueAt(row, 0)) == null ? "0" : obj.toString();
int num = Integer.parseInt((obj = table.getValueAt(row, 1)) == null ? "0" : obj.toString());
String[] rowData = new String[table.getColumnCount()];
rowData[0] = realNum;
rowData[1] = num + 1 + "";
for (int i = 2; i < 9; i++) {
rowData[i] = (obj = table.getValueAt(row, i)) == null ? "" : obj.toString();
}
num = Integer.parseInt((obj = table.getValueAt(row, 13)) == null ? "0" : obj.toString());
rowData[13] = num + 1 + "";
rowData[16] = (obj = table.getValueAt(row, 16)) == null ? "" : obj.toString();
disableRows.add(row);
model.insertRow(row + 1, rowData);
table.revalidate();
table.repaint();
cost.setText(getCost() + "");
}
}
};
}
private void hiddenColumn(JTable table, int columnIndex) {
TableColumnModel tcm = table.getColumnModel();
TableColumn tc = tcm.getColumn(columnIndex);
// tc.setResizable(false);
tc.setWidth(0);
tc.setPreferredWidth(0);
tc.setMaxWidth(0);
tc.setMinWidth(0);
table.getTableHeader().getColumnModel().getColumn(columnIndex).setMaxWidth(0);
table.getTableHeader().getColumnModel().getColumn(columnIndex).setMinWidth(0);
}
private double getCost() {
double sum = 0;
Object obj;
for (int i = 0; i < table.getRowCount(); i++) {
double num = Double.parseDouble((obj = table.getValueAt(i, 8)) == null ? "0" : obj.toString());
sum += num;
}
return sum;
}
private void addResult(String realNo, int row, int times, String result) {
if (resultMap.containsKey(realNo)) {
if (times > resultMap.get(realNo).getTimes()) {
disableRows.add(resultMap.get(realNo).getRow());
resultMap.put(realNo, new JG(row, times, result));
}
} else {
resultMap.put(realNo, new JG(row, times, result));
}
}
private String getResult() {
for (Entry<String, JG> entry : resultMap.entrySet()) {
System.out.println("realNo:" + entry.getKey() + "row:" + entry.getValue().getRow() + "jg:"
+ entry.getValue().getJg() + "times:" + entry.getValue().getTimes());
if ("不合格".equals(entry.getValue().getJg())) {
return "不合格";
}
}
return "合格";
}
@Override
public boolean isRenderingModified() {
// TODO Auto-generated method stub
return form.isCheckedOut();
}
}

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

@ -0,0 +1,631 @@
package com.connor.jd.plm.form;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import com.connor.jd.plm.table.CTMap;
import com.connor.jd.plm.table.CTable;
import com.connor.jd.plm.table.ModelList;
import com.connor.jd.plm.table.ModelValue;
import com.connor.jd.plm.table.TCTableUtil;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.stylesheet.AbstractRendering;
import com.teamcenter.rac.util.MessageBox;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
public class NewProductTestForm extends AbstractRendering {
private TCComponentForm form;
private CTMap model1;
private CTMap model2;
private CTable table1;
private CTable table2;
private Map<String, String> prop;
private ModelList modelList1;
private ModelList modelList2;
private List<Entity> dbData = new ArrayList<Entity>();
private JPopupMenu menu = new JPopupMenu();
private JMenuItem addR;
private String[][] data = new String[0][];
private String[] colNames = { "jd2_no", "jd2_lb", "jd2_xm", "jd2_xmfy", "jd2_DV", "jd2_PV", "jd2_PR", "jd2_SR",
"jd2_bz" };
private String[] colNames2 = { "jd2_no", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syfy", "jd2_sycs" };
private String[] jieduan = { "DV", "PV", "PR", "SR" };
private TCSession session;
public NewProductTestForm(TCComponent arg0) throws Exception {
super(arg0);
if (arg0 instanceof TCComponentForm) {
this.form = (TCComponentForm) arg0;
this.session = (TCSession) AIFUtility.getCurrentApplication().getSession();
loadRendering();
}
}
@Override
public void loadRendering() throws TCException {
this.setLayout(new BorderLayout());
JPanel root = new JPanel(new BorderLayout());
root.setPreferredSize(new Dimension(800, 500));
JPanel inner = new JPanel(new BorderLayout());
JPanel top = new JPanel(new FlowLayout(FlowLayout.CENTER));
JLabel title = new JLabel("新品项目测试单");
title.setFont(new Font("宋体", Font.PLAIN, 24));
top.add(title);
inner.add(top, BorderLayout.NORTH);
prop = form.getProperties();
// 初始化表格
model1 = new CTMap(6, 4);
modelList1 = new ModelList();
String[] textArr1 = { "项目信息:", "立项时间:", "基本型号:", "测试型号:", "产品型号:", "项目资料:", "产品经理:", "产品变更点:", "品质经理:", "开发日程:",
"开发等级:", "开发阶段:" };
int[][] textLocation1 = { { 0, 0 }, { 0, 2 }, { 1, 0 }, { 1, 2 }, { 2, 0 }, { 2, 2 }, { 3, 0 }, { 3, 2 },
{ 4, 0 }, { 4, 2 }, { 5, 0 }, { 5, 2 } };
for (int i = 0; i < textArr1.length; i++) {
modelList1.add(new ModelValue(textArr1[i], false, textLocation1[i][0], textLocation1[i][1], false));
}
String[] propArr = { "jd2_xmxx", "jd2_lxsj", "jd2_jbxh", "jd2_csxh", "jd2_cpxh", "jd2_xmzl", "jd2_cpjl",
"jd2_cpbgd", "jd2_pzjl", "jd2_kfrc", "jd2_kfdj", "jd2_kfjd" };
int[][] propLocation1 = { { 0, 1 }, { 0, 3 }, { 1, 1 }, { 1, 3 }, { 2, 1 }, { 2, 3 }, { 3, 1 }, { 3, 3 },
{ 4, 1 }, { 4, 3 }, { 5, 1 }, { 5, 3 } };
for (int i = 0; i < propArr.length; i++) {
modelList1.add(new ModelValue(propArr[i], true, propLocation1[i][0], propLocation1[i][1], true));
}
initModel(model1, modelList1);
table1 = new CTable(model1) {
@Override
public boolean isCellEditable(int row, int col) {
return !modelList1.isDisableEdit(row, col);
}
};
table1.setRowHeight(25);
table1.setBorder(BorderFactory.createLineBorder(Color.black));
table1.getColumnModel().getColumn(0).setPreferredWidth(100);
table1.getColumnModel().getColumn(1).setPreferredWidth(100);
table1.getColumnModel().getColumn(2).setPreferredWidth(100);
table1.getColumnModel().getColumn(3).setPreferredWidth(200);
DefaultTableCellRenderer tcr1 = new DefaultTableCellRenderer() {
// 重写方法
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
// TODO Auto-generated method stub
int maxPreferredHeight = 0;
for (int i = 0; i < table.getColumnCount(); i++) {
setText("" + table.getValueAt(row, i));
setSize(table.getColumnModel().getColumn(column).getWidth(), 0);
maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height);
}
setBackground(Color.white);
// if(points1.contains(new Point(row,column)))
// setForeground(new Color(0,0,255));
// else
setForeground(Color.black);
if (isSelected) {
setBackground(new Color(0, 120, 215));
setForeground(Color.white);
}
if (table.getRowHeight(row) != maxPreferredHeight) // 少了这行则处理器瞎忙
table.setRowHeight(row, maxPreferredHeight);
setText(value == null ? "" : value.toString());
return this;
}
};
tcr1.setHorizontalAlignment(SwingConstants.CENTER);
table1.setAutoResizeMode(CTable.AUTO_RESIZE_NEXT_COLUMN);
table1.setDefaultRenderer(Object.class, tcr1);
inner.add(table1, BorderLayout.CENTER);
modelList2 = new ModelList();
modelList2.add(new ModelValue("NO", false, 0, 0, false, 0, 1, 0, 0));
modelList2.add(new ModelValue("类别", false, 0, 1, false, 0, 1, 1, 1));
modelList2.add(new ModelValue("项目", false, 0, 2, false, 0, 1, 2, 2));
modelList2.add(new ModelValue("项目费用", false, 0, 3, false, 0, 1, 3, 3));
modelList2.add(new ModelValue("项目阶段", false, 0, 4, false, 0, 0, 4, 7));
modelList2.add(new ModelValue("DV", false, 1, 4, false));
modelList2.add(new ModelValue("PV", false, 1, 5, false));
modelList2.add(new ModelValue("PR", false, 1, 6, false));
modelList2.add(new ModelValue("SR", false, 1, 7, false));
modelList2.add(new ModelValue("备注", false, 0, 8, false, 0, 1, 8, 8));
String type = null;
int typeSpan = 0;
data = TCTableUtil.getTableRows(form, "jd2_xpcsxqd", colNames);
if (data.length == 0) {
try {
dbData = Db.use().query("select * from JD2_Machine ORDER BY TEST_TYPE ASC");
model2 = new CTMap(dbData.size() + 3, 9);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i = 0; i < dbData.size(); i++) {
System.out.println(dbData.get(i).toString());
modelList2.add(new ModelValue(dbData.get(i).getStr("TEST_PROJECT"), false, i + 2, 2, false));
modelList2.add(new ModelValue(dbData.get(i).getInt("TEST_COST") + "", false, i + 2, 3, false));
if (i == 0) {
type = dbData.get(i).getStr("TEST_TYPE");
}
if ((type != null && !type.equals(dbData.get(i).getStr("TEST_TYPE")))) {
System.out.println(type);
modelList2.add(
new ModelValue(type, false, i - typeSpan + 2, 1, false, i - typeSpan + 2, i + 1, 1, 1));
type = dbData.get(i).getStr("TEST_TYPE");
typeSpan = 0;
}
if ((i == dbData.size() - 1)) {
System.out.println(type);
modelList2.add(
new ModelValue(type, false, i - typeSpan + 2, 1, false, i - typeSpan + 2, i + 2, 1, 1));
}
model2.setValueAt(i + 1, i + 2, 0);
for (int ii = 4; ii < 8; ii++) {
model2.setValueAt("/", i + 2, ii);
}
typeSpan++;
}
} else {
model2 = new CTMap(data.length + 3, 9);
for (int i = 0; i < data.length; i++) {
System.out.println(Arrays.toString(data[i]));
modelList2.add(new ModelValue(data[i][2], false, i + 2, 2, false));
modelList2.add(new ModelValue(data[i][3], false, i + 2, 3, false));
if (i == 0) {
type = data[i][1];
}
if ((type != null && !type.equals(data[i][1]))) {
System.out.println(type);
modelList2.add(
new ModelValue(type, false, i - typeSpan + 2, 1, false, i - typeSpan + 2, i + 1, 1, 1));
type = data[i][1];
typeSpan = 0;
}
if ((i == data.length - 1)) {
System.out.println(type);
modelList2.add(
new ModelValue(type, false, i - typeSpan + 2, 1, false, i - typeSpan + 2, i + 2, 1, 1));
}
model2.setValueAt(i + 1, i + 2, 0);
for (int ii = 4; ii < 9; ii++) {
model2.setValueAt(data[i][ii], i + 2, ii);
}
typeSpan++;
}
}
int buttom = data.length == 0 ? dbData.size() + 2 : data.length + 2;
modelList2.add(new ModelValue("项目费用合计", false, buttom, 0, false, buttom, buttom, 0, 2));
modelList2.add(new ModelValue("jd2_zfy", true, buttom, 3, false));
modelList2.add(new ModelValue("jd2_dvfy", true, buttom, 4, false));
modelList2.add(new ModelValue("jd2_pvfy", true, buttom, 5, false));
modelList2.add(new ModelValue("jd2_prfy", true, buttom, 6, false));
modelList2.add(new ModelValue("jd2_srfy", true, buttom, 7, false));
initModel(model2, modelList2);
table2 = new CTable(model2) {
@Override
public boolean isCellEditable(int row, int col) {
if (modelList2.isDisableEdit(row, col) || col == 0 || row == table2.getRowCount() - 1) {
return false;
}
return true;
}
};
table2.setRowHeight(25);
table2.setBorder(BorderFactory.createLineBorder(Color.black));
table2.getColumnModel().getColumn(0).setPreferredWidth(100);
table2.getColumnModel().getColumn(1).setPreferredWidth(60);
table2.getColumnModel().getColumn(2).setPreferredWidth(80);
table2.getColumnModel().getColumn(3).setPreferredWidth(60);
table2.getColumnModel().getColumn(4).setPreferredWidth(50);
table2.getColumnModel().getColumn(5).setPreferredWidth(50);
table2.getColumnModel().getColumn(6).setPreferredWidth(50);
table2.getColumnModel().getColumn(7).setPreferredWidth(50);
table2.getColumnModel().getColumn(8).setPreferredWidth(60);
DefaultTableCellRenderer tcr2 = new DefaultTableCellRenderer() {
// 重写方法
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
// TODO Auto-generated method stub
int maxPreferredHeight = 0;
for (int i = 0; i < table.getColumnCount(); i++) {
setText("" + table.getValueAt(row, i));
setSize(table.getColumnModel().getColumn(column).getWidth(), 0);
maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height);
}
setBackground(Color.white);
// if(points1.contains(new Point(row,column)))
// setForeground(new Color(0,0,255));
// else
setForeground(Color.black);
if (isSelected) {
setBackground(new Color(0, 120, 215));
setForeground(Color.white);
}
if (table.getRowHeight(row) != maxPreferredHeight) // 少了这行则处理器瞎忙
table.setRowHeight(row, maxPreferredHeight);
setText(value == null ? "" : value.toString());
return this;
}
};
DefaultCellEditor dce = new DefaultCellEditor(new JTextField()) {
JTable table;
int row;
int col;
@Override
public Component getTableCellEditorComponent(JTable paramJTable, Object paramObject, boolean paramBoolean,
int paramInt1, int paramInt2) {
this.table = paramJTable;
this.row = paramInt1;
this.col = paramInt2;
return super.getTableCellEditorComponent(paramJTable, paramObject, paramBoolean, paramInt1, paramInt2);
}
@Override
public Object getCellEditorValue() {
Object obj = super.getCellEditorValue();
if (obj != null) {
String objStr = obj.toString().trim();
try {
if ("/".equals(objStr)) {
objStr = "0";
}
int num = Integer.parseInt(objStr);
System.out.println("值:" + num);
if (num < 0) {
System.out.println("计算区域只能输入自然数或\"/\"");
MessageBox.post("计算区域只能输入自然数或\"/\"", "错误", MessageBox.ERROR);
return "/";
}
int sum = 0;
Object sumObj;
for (int i = 2; i < row; i++) {
sumObj = table.getValueAt(i, col);
if (sumObj != null && !"/".equals(sumObj.toString().trim())) {
sum += Double.parseDouble(
(sumObj = table.getValueAt(i, 3)) == null ? "0" : sumObj.toString().trim());
}
}
if (!"0".equals(objStr)) {
sum += Double.parseDouble(
(sumObj = table.getValueAt(row, 3)) == null ? "0" : sumObj.toString().trim());
}
for (int i = row + 1; i < table.getRowCount() - 1; i++) {
sumObj = table.getValueAt(i, col);
if (sumObj != null && !"/".equals(sumObj.toString().trim())) {
sum += Double.parseDouble(
(sumObj = table.getValueAt(i, 3)) == null ? "0" : sumObj.toString().trim());
}
}
table.setValueAt(sum, table.getRowCount() - 1, col);
double sum1 = Double
.parseDouble(((sumObj = table.getValueAt(table.getRowCount() - 1, 4)) == null
|| "".equals(sumObj.toString().trim())) ? "0" : sumObj.toString().trim());
double sum2 = Double
.parseDouble(((sumObj = table.getValueAt(table.getRowCount() - 1, 5)) == null
|| "".equals(sumObj.toString().trim())) ? "0" : sumObj.toString().trim());
double sum3 = Double
.parseDouble(((sumObj = table.getValueAt(table.getRowCount() - 1, 6)) == null
|| "".equals(sumObj.toString().trim())) ? "0" : sumObj.toString().trim());
double sum4 = Double
.parseDouble(((sumObj = table.getValueAt(table.getRowCount() - 1, 7)) == null
|| "".equals(sumObj.toString().trim())) ? "0" : sumObj.toString().trim());
table.setValueAt(sum1 + sum2 + sum3 + sum4, table.getRowCount() - 1, 3);
table2.revalidate();
table2.repaint();
} catch (NumberFormatException e1) {
e1.printStackTrace();
System.out.println("计算区域只能输入自然数或\"/\"");
MessageBox.post("计算区域只能输入自然数或\"/\"", "错误", MessageBox.ERROR);
obj = "/";
} catch (Exception e2) {
e2.printStackTrace();
obj = "/";
}
}
if ("0".equals(obj.toString().trim())) {
obj = "/";
}
return obj;
}
};
tcr2.setHorizontalAlignment(SwingConstants.CENTER);
table2.getColumnModel().getColumn(4).setCellEditor(dce);
table2.getColumnModel().getColumn(5).setCellEditor(dce);
table2.getColumnModel().getColumn(6).setCellEditor(dce);
table2.getColumnModel().getColumn(7).setCellEditor(dce);
table2.setAutoResizeMode(CTable.AUTO_RESIZE_NEXT_COLUMN);
table2.setDefaultRenderer(Object.class, tcr2);
table2.addMouseListener(rightClick());
inner.add(table2, BorderLayout.SOUTH);
JPanel btns = new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton create = new JButton("创建测试计划");
create.addActionListener(create());
btns.add(create);
menu.setVisible(false);
addR = new JMenuItem("新增测试项");
addR.setEnabled(false);
addR.addActionListener(addRow());
menu.add(addR);
ScrollPane sc = new ScrollPane();
sc.add(inner);
root.add(sc, BorderLayout.CENTER);
root.add(btns, BorderLayout.SOUTH);
this.add(root);
}
@Override
public void saveRendering() {
savePropValue(table1, modelList1);
savePropValue(table2, modelList2);
Object obj;
if (data.length == 0) {
if (dbData.size() == 0) {
try {
dbData = Db.use().query("select * from JD2_Machine ORDER BY TEST_TYPE ASC");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
data = new String[table2.getRowCount() - 3][9];
for (int i = 0; i < dbData.size(); i++) {
data[i][0] = (obj = model2.getValueAt(i + 2, 0)) == null ? "" : obj.toString();
data[i][1] = dbData.get(i).getStr("TEST_TYPE");
data[i][2] = dbData.get(i).getStr("TEST_PROJECT");
data[i][3] = dbData.get(i).getStr("TEST_COST");
for (int ii = 4; ii < 9; ii++) {
data[i][ii] = (obj = model2.getValueAt(i + 2, ii)) == null ? "" : obj.toString();
}
}
System.out.println("dbData.size() " + dbData.size());
System.out.println("table2.getRowCount() " + table2.getRowCount());
for (int i = dbData.size() + 2; i < table2.getRowCount() - 1; i++) {
for (int ii = 0; ii < 9; ii++) {
data[i][ii] = (obj = model2.getValueAt(i + 2, ii)) == null ? "" : obj.toString();
}
}
System.out.println(Arrays.deepToString(data));
TCTableUtil.setTableRows(form, "jd2_xpcsxqd", "JD2_XPCSXQD", colNames, data);
} else {
String[][] newData = new String[table2.getRowCount() - 3][9];
for (int i = 0; i < data.length; i++) {
System.arraycopy(data[i], 0, newData[i], 0, 4);
for (int ii = 4; ii < 9; ii++) {
newData[i][ii] = (obj = model2.getValueAt(i + 2, ii)) == null ? "" : obj.toString();
}
}
for (int i = data.length + 2; i < table2.getRowCount() - 1; i++) {
for (int ii = 0; ii < 9; ii++) {
newData[i][ii] = (obj = model2.getValueAt(i + 2, ii)) == null ? "" : obj.toString();
}
}
System.out.println(Arrays.deepToString(newData));
TCTableUtil.setTableRows(form, "jd2_xpcsxqd", "JD2_XPCSXQD", colNames, newData);
}
}
private void savePropValue(CTable table, ModelList ml) {
for (ModelValue mv : ml) {
if (mv.isProp()) {
Object obj = table.getValueAt(mv.getRow(), mv.getCol());
try {
if (prop.containsKey(mv.getValue())) {
form.setProperty(mv.getValue(), obj == null ? "" : obj.toString());
}
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
private MouseAdapter rightClick() {
return new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3 && form.isCheckedOut() && table2.getSelectedRow() != -1) {
int row = table2.getSelectedRow();
boolean flag = (row > 1 && row < table2.getRowCount() - 1);
addR.setEnabled(flag);
menu.show(e.getComponent(), e.getX(), e.getY());
}
}
};
}
private ActionListener addRow() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent paramActionEvent) {
// TODO Auto-generated method stub
int row = model2.getRowCount() - 2;
int num = Integer.parseInt(model2.getValueAt(row, 0).toString());
model2.insertRow(model2.getRowCount() - 1);
model2.setValueAt(num + 1, row + 1, 0);
table2.revalidate();
table2.repaint();
}
};
}
private ActionListener create() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent paramActionEvent) {
// TODO Auto-generated method stub
try {
AIFComponentContext[] comps = form.whereReferenced();
StringBuilder msg = new StringBuilder();
for (AIFComponentContext aif : comps) {
System.out.println("ref type:" + aif.getComponent().getType());
if ("JD2_GTXPCSXQDRevision".equals(aif.getComponent().getType())) {
TCComponentItemRevision rev = (TCComponentItemRevision) aif.getComponent();
TCComponent[] compArr = rev.getTCProperty("JD2_CSJH").getReferenceValueArray();
String exist = "";
for (TCComponent t : compArr) {
exist += t.getProperty("object_name");
}
List<String[]> colData = new ArrayList<String[]>();
String ownner = form.getTCProperty("owning_user").getUIFValue();
for (int i = 0; i < 4; i++) {
if (exist.contains(jieduan[i])) {
System.out.println("\"" + jieduan[i] + "阶段\"测试计划已创建");
msg.append("\"" + jieduan[i] + "阶段\"测试计划已创建\n");
continue;
}
Object obj;
Object temp;
int rowNum = 0;
for (int ii = 2; ii < table2.getRowCount() - 1; ii++) {
obj = table2.getValueAt(ii, i + 4);
if (obj != null && !"/".equals(obj.toString().trim())) {
// colNames2 = { "jd2_no", "jd2_wtry", "jd2_syxm", "jd2_syts", "jd2_syfy",
// "jd2_sycs" };
String[] row = new String[6];
row[0] = rowNum + "";
row[1] = ownner;
row[2] = (temp = table2.getValueAt(ii, 2)) == null ? "" : temp.toString();
row[3] = obj.toString().trim();
row[4] = (temp = table2.getValueAt(ii, 3)) == null ? "0"
: temp.toString().trim();
row[5] = "1";
System.out.println(Arrays.toString(row));
colData.add(row);
rowNum++;
}
}
if (colData.size() != 0) {
TCComponentItemType type = (TCComponentItemType) session
.getTypeComponent("JD2_GTXPXMCSJH");
TCComponentItem item = type.create(null, null, "JD2_GTXPXMCSJH",
jieduan[i] + "阶段测试计划", "", null);
rev.add("JD2_CSJH", item);
TCComponentItemRevision rev1 = item.getLatestItemRevision();
TCComponentForm form1 = (TCComponentForm) rev1
.getRelatedComponents("IMAN_master_form_rev")[0];
String[][] dataArr = colData.toArray(new String[colData.size()][6]);
System.out.println(Arrays.deepToString(dataArr));
TCTableUtil.setTableRows(form1, "jd2_csjhtable", "JD2_CSJHTABLE", colNames2,
dataArr);
msg.append("\"" + jieduan[i] + "阶段\"测试计划创建成功\n");
}
colData.clear();
}
}
}
MessageBox.post(msg.toString(), "提示", MessageBox.WARNING);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
}
@Override
public boolean isRenderingModified() {
// TODO Auto-generated method stub
return form.isCheckedOut();
}
private void initModel(CTMap model, ModelList modelList) {
for (ModelValue mv : modelList) {
if (mv.isProp()) {
if (prop.containsKey(mv.getValue())) {
model.setValueAt(prop.get(mv.getValue()), mv.getRow(), mv.getCol());
} else {
System.out.println("属性‘" + mv.getValue() + "’不存在");
}
} else {
model.setValueAt(mv.getValue(), mv.getRow(), mv.getCol());
}
if (mv.isCombine()) {
model.combine(mv.getCombineRows(), mv.getCombineColumns());
}
}
}
private void saveModel(ModelList modelList) {
Object obj;
for (ModelValue mv : modelList) {
if (mv.isProp()) {
if (prop.containsKey(mv.getValue())) {
obj = table2.getValueAt(mv.getRow(), mv.getCol());
try {
form.setProperty(mv.getValue(), obj == null ? "" : obj.toString());
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
System.out.println("属性\"" + mv.getValue() + "\"不存在");
}
}
}
};
}

@ -24,6 +24,12 @@ public class CSXWHHandler extends AbstractHandler {
TCSession session = (TCSession) app.getSession();
String[] userIdList = JDMethodUtil.getPrefStrArray("JD2_CSXWH", session);
Boolean tag = true;
try {
System.out.println("当前用户id" + session.getUser().getUserId());
} catch (TCException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
for (int i = 0; i < userIdList.length; i++) {
try {
if (session.getUser().getUserId().equals(userIdList[i])) {

@ -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));

@ -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()));
}
}

@ -0,0 +1,70 @@
package com.connor.jd.plm.table;
import java.util.ArrayList;
import java.util.List;
public class ModelList extends ArrayList<ModelValue> {
private List<String> disableEdit = new ArrayList<String>();
@Override
public boolean add(ModelValue e) {
// TODO Auto-generated method stub
if (!e.isEditable()) {
disableEdit.add(e.getRow() + "," + e.getCol());
}
return super.add(e);
}
public ModelValue getModelValue(int row, int col) {
for (ModelValue mv : this) {
if (mv.getRow() == row && mv.getCol() == col) {
return mv;
}
}
return null;
}
public ModelValue getModelValueInRange(int row, int col) {
int rowStart;
int colStart;
int rowEnd;
int colEnd;
for (ModelValue mv : this) {
if (mv.isCombine()) {
rowStart = mv.getCombineRows()[0];
rowEnd = rowStart + mv.getRowSpan() - 1;
colStart = mv.getCombineColumns()[0];
colEnd = colStart + mv.getColSpan() - 1;
if (row >= rowStart && row <= rowEnd && col >= colStart && col <= colEnd) {
return mv;
}
}
}
return null;
}
public boolean addDisableEdit(int row, int col) {
String str = row + "," + col;
if (disableEdit.contains(str)) {
disableEdit.add(disableEdit.indexOf(str), str);
return true;
}
disableEdit.add(str);
return false;
}
public boolean removeDisableEdit(int row, int col) {
String str = row + "," + col;
if (disableEdit.contains(str)) {
disableEdit.remove(disableEdit.indexOf(str));
return true;
}
return false;
}
public boolean isDisableEdit(int row, int col) {
return disableEdit.contains(row + "," + col);
}
}

@ -0,0 +1,163 @@
package com.connor.jd.plm.table;
import java.util.Objects;
public class ModelValue {
private String value;
private boolean isProp;
private int row;
private int col;
private boolean editable;
private int[] combineRows;
private int rowSpan;
private int[] combineColumns;
private int colSpan;
public ModelValue(String value, boolean isProp, int row, int col, boolean editable, int[] combineRows,
int[] combineColumns, String type) {
super();
this.value = value;
this.isProp = isProp;
this.row = row;
this.col = col;
this.editable = editable;
this.combineRows = combineRows;
this.combineColumns = combineColumns;
}
public ModelValue(boolean editable, int[] combineRows, int[] combineColumns) {
super();
this.editable = editable;
this.combineRows = combineRows;
this.combineColumns = combineColumns;
}
public ModelValue(String value, boolean isProp, int row, int col, boolean editable) {
super();
this.value = value;
this.isProp = isProp;
this.row = row;
this.col = col;
this.editable = editable;
}
public ModelValue(String value, boolean isProp, int row, int col, boolean editable, int[] combineRows,
int[] combineColumns) {
super();
this.value = value;
this.isProp = isProp;
this.row = row;
this.col = col;
this.editable = editable;
this.combineRows = combineRows;
this.combineColumns = combineColumns;
}
public ModelValue(String value, boolean isProp, int row, int col, boolean editable, int rowStart, int rowEnd,
int colStart, int colEnd) {
super();
this.value = value;
this.isProp = isProp;
this.row = row;
this.col = col;
this.editable = editable;
setCombineRows(rowStart, rowEnd);
setCombineColumns(colStart, colEnd);
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
public int getCol() {
return col;
}
public void setCol(int col) {
this.col = col;
}
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
public int[] getCombineRows() {
return combineRows;
}
public void setCombineRows(int[] combineRows) {
this.rowSpan = combineRows.length;
this.combineRows = combineRows;
}
public void setCombineRows(int start, int end) {
if (start <= end) {
this.rowSpan = end - start + 1;
this.combineRows = new int[rowSpan];
for (int i = 0; i < rowSpan; i++) {
combineRows[i] = start + i;
}
}
}
public int[] getCombineColumns() {
return combineColumns;
}
public void setCombineColumns(int[] combineColumns) {
this.colSpan = combineColumns.length;
this.combineColumns = combineColumns;
}
public void setCombineColumns(int start, int end) {
if (start <= end) {
this.colSpan = end - start + 1;
this.combineColumns = new int[colSpan];
for (int i = 0; i < colSpan; i++) {
combineColumns[i] = start + i;
}
}
}
public int getRowSpan() {
return rowSpan;
}
public int getColSpan() {
return colSpan;
}
public boolean isProp() {
return isProp;
}
public void setProp(boolean isProp) {
this.isProp = isProp;
}
public boolean hasValue() {
return Objects.nonNull(value);
}
public boolean isCombine() {
return rowSpan != 0 && colSpan != 0;
}
}

@ -3,63 +3,119 @@ package com.connor.jd.plm.table;
import java.awt.Component;
import javax.swing.DefaultCellEditor;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.JTextField;
import com.teamcenter.rac.util.MessageBox;
public class MyCellEditor extends DefaultCellEditor {
private JRadioPanel radio = null;
private JCheckPanel check = null;
private JLabel img = null;
private JComboBox<String> comboBox = null;
private int type = -1;
private int row;
private int col;
private int top;
private int end;
private int bottom;
private JTable table;
public MyCellEditor(JTextField var1) {
super(var1);
// TODO Auto-generated constructor stub
}
public MyCellEditor(JTextField var1, int top, int end, int bottom) {
super(var1);
// TODO Auto-generated constructor stub
this.top = top;
this.end = end;
this.bottom = bottom;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
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;
} else if (value instanceof JComboBox) {
comboBox = (JComboBox<String>) value;
type = 3;
return img;
return comboBox;
}
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
public Object getCellEditorValue() {
switch (type) {
case 1:
if (type == 1) {
return radio;
case 2:
}
if (type == 2) {
return check;
case 3:
return img;
}
return super.getCellEditorValue();
if (type == 3) {
return comboBox;
}
Object obj = super.getCellEditorValue();
if (obj != null && !"".equals(obj.toString().trim()) && row >= top && row <= bottom && col >= 7
&& col < table.getColumnCount() - 3) {
try {
Double.parseDouble(obj.toString().trim());
} catch (Exception e) {
MessageBox.post("检查数据只能输入数字", "错误", MessageBox.ERROR);
return null;
}
}
return obj;
}
@Override
public boolean stopCellEditing() {
// TODO Auto-generated method stub
// 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 < col; i++) {
obj = table.getValueAt(row, i);
if (obj != null && !"".equals(obj.toString().trim())) {
min = Math.min(min, Double.parseDouble(obj.toString().trim()));
max = Math.max(max, Double.parseDouble(obj.toString().trim()));
}
}
obj = getCellEditorValue();
if (obj != null && !"".equals(obj.toString().trim())) {
min = Math.min(min, Double.parseDouble(obj.toString().trim()));
max = Math.max(max, Double.parseDouble(obj.toString().trim()));
}
for (int i = col + 1; i < table.getColumnCount() - 3; i++) {
obj = table.getValueAt(row, i);
if (obj != null && !"".equals(obj.toString().trim())) {
min = Math.min(min, Double.parseDouble(obj.toString().trim()));
max = Math.max(max, Double.parseDouble(obj.toString().trim()));
}
}
if (max > Double.MIN_VALUE) {
table.setValueAt(String.format("%.2f", min), row, table.getColumnCount() - 3);
table.setValueAt(String.format("%.2f", max), row, table.getColumnCount() - 2);
} else {
table.setValueAt("", row, table.getColumnCount() - 3);
table.setValueAt("", row, table.getColumnCount() - 2);
}
}
return super.stopCellEditing();
}

@ -0,0 +1,285 @@
package com.connor.jd.plm.table;
import java.awt.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.DefaultCellEditor;
import javax.swing.JTable;
import javax.swing.JTextField;
import com.teamcenter.rac.util.MessageBox;
public class MyCellEditor1 extends DefaultCellEditor {
private int col;
private int row;
private JTable table;
private int top;
private int end;
private int bottom;
private List<Double> data;
private double low = 0.0;
private double up = 0.0;
private int cnt = 0;
public MyCellEditor1(JTextField paramJTextField) {
super(paramJTextField);
// TODO Auto-generated constructor stub
}
public MyCellEditor1(JTextField paramJTextField, int top, int end, int bottom) {
super(paramJTextField);
// TODO Auto-generated constructor stub
this.top = top;
this.end = end;
this.bottom = bottom;
}
public double getLow() {
return low;
}
public void setLow(double low) {
this.low = low;
}
public double getUp() {
return up;
}
public void setUp(double up) {
this.up = up;
}
public int getCnt() {
return cnt;
}
public void setCnt(int cnt) {
this.cnt = cnt;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
this.col = column;
this.row = row;
this.table = table;
bottom = table.getRowCount() - end;
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
@Override
public Object getCellEditorValue() {
// TODO Auto-generated method stub
Object obj = super.getCellEditorValue();
if (obj != null && !"".equals(obj.toString().trim()) && row >= top && row <= bottom) {
try {
Double.parseDouble(obj.toString().trim());
} catch (Exception e) {
MessageBox.post("计算区域只能输入数字", "错误", MessageBox.ERROR);
return null;
}
}
return obj;
}
@Override
public boolean stopCellEditing() {
// TODO Auto-generated method stub
System.out.println("top:" + top + ",end:" + end + ",bottom:" + bottom + " 重新计算列:" + col);
data = new ArrayList<Double>();
Object now = getCellEditorValue();
Object obj = null;
if (row == 2) {
if (now != null && !"".equals(now.toString().trim())) {
low = Double.parseDouble(now.toString().trim());
cnt++;
} else {
low = 0.0;
cnt--;
}
}
if (row == 3) {
if (now != null && !"".equals(now.toString().trim())) {
up = Double.parseDouble(now.toString().trim());
cnt++;
} else {
up = 0.0;
cnt--;
}
}
for (int i = top; i < row && i <= bottom; i++) {
obj = table.getModel().getValueAt(i, col);
if (obj != null && !"".equals(obj.toString().trim())) {
data.add(Double.parseDouble(obj.toString().trim()));
}
}
if (row >= top && row <= bottom && now != null && !"".equals(now.toString().trim())) {
data.add(Double.parseDouble(now.toString().trim()));
}
for (int i = row + 1; i <= bottom; i++) {
obj = table.getModel().getValueAt(i, col);
if (obj != null && !"".equals(obj.toString().trim())) {
data.add(Double.parseDouble(obj.toString().trim()));
}
}
System.out.println(Arrays.toString(data.toArray()));
double sum = 0;
double max = Double.MIN_VALUE;
double min = Double.MAX_VALUE;
for (Double d : data) {
sum += d;
max = Math.max(max, d);
min = Math.min(min, d);
}
if (sum != 0) {
double r = max - min;
double avg = sum / data.size();
table.getModel().setValueAt(String.format("%.2f", min), bottom + 1, col);
table.getModel().setValueAt(String.format("%.2f", max), bottom + 2, col);
table.getModel().setValueAt(String.format("%.2f", r), bottom + 3, col);
table.getModel().setValueAt(String.format("%.2f", avg), bottom + 5, col);
if (data.size() - 1 > 0) {
double stdevSum = 0;
for (Double d : data) {
stdevSum += Math.pow(d - avg, 2);
}
double stdev = Math.sqrt(stdevSum / (data.size() - 1));
double bar1 = avg - 3 * stdev;
double bar2 = avg + 3 * stdev;
table.getModel().setValueAt(String.format("%.2f", stdev), bottom + 4, col);
table.getModel().setValueAt(String.format("%.2f", bar1), bottom + 6, col);
table.getModel().setValueAt(String.format("%.2f", bar2), bottom + 7, col);
double cp = 0.0;
if (cnt == 0) {
table.getModel().setValueAt("", bottom + 8, col);
} else if (cnt == 2) {
cp = (up - low) / (6 * stdev);
table.getModel().setValueAt(String.format("%.2f", cp), bottom + 8, col);
} else if (doubleIsEqual(up, 0.0)) {
cp = (avg - low) / (3 * stdev);
table.getModel().setValueAt(String.format("%.2f", cp), bottom + 8, col);
} else {
cp = (up - avg) / (3 * stdev);
table.getModel().setValueAt(String.format("%.2f", cp), bottom + 8, col);
}
double cpu = 0.0;
if (doubleIsEqual(up, 0.0)) {
table.getModel().setValueAt("", bottom + 9, col);
} else {
cpu = (up - avg) / (3 * stdev);
table.getModel().setValueAt(String.format("%.2f", cpu), bottom + 9, col);
}
double cpl = 0.0;
if (doubleIsEqual(low, 0.0)) {
table.getModel().setValueAt("", bottom + 10, col);
} else {
cpl = (avg - low) / (3 * stdev);
table.getModel().setValueAt(String.format("%.2f", cpl), bottom + 10, col);
}
double cpk = 0.0;
if (cnt == 2) {
cpk = (1 - 2 * Math.abs(((low + up) / 2 - avg)) / (up - low)) * cp;
table.getModel().setValueAt(String.format("%.2f", cpk), bottom + 11, col);
} else {
cpk = cp;
table.getModel().setValueAt(doubleIsEqual(cpk, 0.0) ? "" : String.format("%.2f", cpk), bottom + 11,
col);
}
double su = 0.0;
if (doubleIsEqual(cpu, 0.0)) {
table.getModel().setValueAt("", bottom + 12, col);
} else {
su = (1 - normSDist(cpu * 3)) * 1000000;
table.getModel().setValueAt(String.format("%.2f", su), bottom + 12, col);
}
double sl = 0.0;
if (doubleIsEqual(cpl, 0.0)) {
table.getModel().setValueAt("", bottom + 13, col);
} else {
sl = (1 - normSDist(cpl * 3)) * 1000000;
table.getModel().setValueAt(String.format("%.2f", sl), bottom + 13, col);
}
if (cnt == 0) {
table.getModel().setValueAt("", bottom + 14, col);
} else {
table.getModel().setValueAt(String.format("%.2f", su + sl), bottom + 14, col);
}
if (cnt == 0) {
table.getModel().setValueAt("", bottom + 15, col);
} else if (cpk > 1.99) {
table.getModel().setValueAt("非常好", bottom + 15, col);
} else if (cpk > 1.66) {
table.getModel().setValueAt("很好", bottom + 15, col);
} else if (cpk > 1.32) {
table.getModel().setValueAt("好", bottom + 15, col);
} else if (cpk > 0.99) {
table.getModel().setValueAt("有能力", bottom + 15, col);
} else {
table.getModel().setValueAt("能力不足", bottom + 15, col);
}
System.out.println("cp:" + cp + ",cpu:" + cpu + ",cpl:" + cpl + ",cpk:" + cpk + ",su:" + su + ",sl:"
+ sl + ",ppm:" + (su + sl));
} else {
table.getModel().setValueAt("", bottom + 4, col);
table.getModel().setValueAt("", bottom + 6, col);
table.getModel().setValueAt("", bottom + 7, col);
table.getModel().setValueAt("", bottom + 8, col);
table.getModel().setValueAt("", bottom + 9, col);
table.getModel().setValueAt("", bottom + 10, col);
table.getModel().setValueAt("", bottom + 11, col);
table.getModel().setValueAt("", bottom + 12, col);
table.getModel().setValueAt("", bottom + 13, col);
table.getModel().setValueAt("", bottom + 14, col);
table.getModel().setValueAt("", bottom + 15, col);
}
} else {
table.getModel().setValueAt("", bottom + 1, col);
table.getModel().setValueAt("", bottom + 2, col);
table.getModel().setValueAt("", bottom + 3, col);
table.getModel().setValueAt("", bottom + 5, col);
table.getModel().setValueAt("", bottom + 4, col);
table.getModel().setValueAt("", bottom + 6, col);
table.getModel().setValueAt("", bottom + 7, col);
table.getModel().setValueAt("", bottom + 8, col);
table.getModel().setValueAt("", bottom + 9, col);
table.getModel().setValueAt("", bottom + 10, col);
table.getModel().setValueAt("", bottom + 11, col);
table.getModel().setValueAt("", bottom + 12, col);
table.getModel().setValueAt("", bottom + 13, col);
table.getModel().setValueAt("", bottom + 14, col);
table.getModel().setValueAt("", bottom + 15, col);
}
return super.stopCellEditing();
}
private boolean doubleIsEqual(double a, double b) {
return Math.abs(a - b) < 0.000001;
}
private double normSDist(double z) {
// this guards against overflow
if (z > 6)
return 1;
if (z < -6)
return 0;
double gamma = 0.231641900, a1 = 0.319381530, a2 = -0.356563782, a3 = 1.781477973, a4 = -1.821255978,
a5 = 1.330274429;
double x = Math.abs(z);
double t = 1 / (1 + gamma * x);
double n = 1 - (1 / (Math.sqrt(2 * Math.PI)) * Math.exp(-z * z / 2))
* (a1 * t + a2 * Math.pow(t, 2) + a3 * Math.pow(t, 3) + a4 * Math.pow(t, 4) + a5 * Math.pow(t, 5));
if (z < 0)
return 1.0 - n;
return n;
}
}

@ -0,0 +1,48 @@
package com.connor.jd.plm.table;
import java.awt.Component;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextField;
public class MyCellEditor2 extends DefaultCellEditor {
private JLabel img = null;
private JComboBox<String> jued = null;
private int type = -1;
public MyCellEditor2(JTextField var1) {
super(var1);
// TODO Auto-generated constructor stub
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
if (value instanceof JLabel) {
img = (JLabel) value;
type = 1;
return img;
}
if (value instanceof JComboBox) {
jued = (JComboBox<String>) value;
type = 2;
return jued;
}
type = 0;
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
@Override
public Object getCellEditorValue() {
if (type == 1) {
return img;
}
if (type == 2) {
return jued;
}
return super.getCellEditorValue();
}
}

@ -0,0 +1,39 @@
package com.connor.jd.plm.table;
import java.awt.Component;
import javax.swing.DefaultCellEditor;
import javax.swing.JTable;
import javax.swing.JTextField;
public class MyCellEditor3 extends DefaultCellEditor {
private JCheckPanel check = null;
private int type = -1;
public MyCellEditor3(JTextField arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
// TODO Auto-generated method stub
if (value instanceof JCheckPanel) {
check = (JCheckPanel) value;
type = 1;
return check;
}
type = 0;
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
@Override
public Object getCellEditorValue() {
// TODO Auto-generated method stub
if (type == 1) {
return check;
}
return super.getCellEditorValue();
}
}

@ -0,0 +1,37 @@
package com.connor.jd.plm.table;
import java.awt.Component;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.JTextField;
public class MyCellEditor4 extends DefaultCellEditor {
private int type = -1;
private JCheckBox check;
public MyCellEditor4(JTextField arg0) {
super(arg0);
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
if (value instanceof JCheckBox) {
check = (JCheckBox) value;
type = 1;
return check;
}
type = 0;
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
@Override
public Object getCellEditorValue() {
if (type == 1) {
return check;
}
return super.getCellEditorValue();
}
}

@ -17,34 +17,36 @@ import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse;
public class TCTableUtil {
public static String[][] getTableRows(TCComponentForm form, String prop,
String[] colNames) {
public static String[][] getTableRows(TCComponentForm form, String prop, String[] colNames) {
try {
TCProperty tcProperty = form.getTCProperty(prop);
TCComponent[] components = tcProperty.getReferenceValueArray();
String[][] res = new String[components.length][colNames.length];
for (int i = 0; i < components.length; i++) {
for (int ii = 0; ii < colNames.length; ii++) {
res[i][ii] = components[i]
.getPropertyDisplayableValue(colNames[ii]);
res[i][ii] = components[i].getPropertyDisplayableValue(colNames[ii]);
}
}
return res;
} catch (NullPointerException e) {
System.out.println("ÊôÐÔ\"" + prop + "\"²»´æÔÚ");
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static boolean setTableRows(TCComponentForm form, String prop,
String[] colNames, String[][] rows) {
public static boolean setTableRows(TCComponentForm form, String prop, String refName, String[] colNames,
String[][] rows) {
List<TCComponent> list = new ArrayList<TCComponent>();
DataManagementService service = DataManagementService.getService(
(TCSession) AIFUtility.getCurrentApplication().getSession());
DataManagementService service = DataManagementService
.getService((TCSession) AIFUtility.getCurrentApplication().getSession());
CreateIn ci = new CreateIn();
ci.data.boName = "JD2_table";
ci.data.boName = refName;
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < rows.length; i++) {
for (int ii = 0; ii < colNames.length; ii++) {
@ -53,12 +55,13 @@ public class TCTableUtil {
System.out.println(map.size());
ci.data.stringProps = map;
try {
CreateResponse response = service
.createObjects(new CreateIn[] { ci });
System.out.println("CreateResponse size:"
+ response.serviceData.sizeOfCreatedObjects());
CreateResponse response = service.createObjects(new CreateIn[] { ci });
System.out.println("CreateResponse size:" + response.serviceData.sizeOfCreatedObjects());
if (response.serviceData.sizeOfCreatedObjects() > 0) {
list.add(response.output[0].objects[0]);
} else {
String str = String.join(",", response.serviceData.getPartialError(0).getMessages());
System.out.println(str);
}
} catch (ServiceException e) {
// TODO Auto-generated catch block
@ -66,8 +69,7 @@ public class TCTableUtil {
}
}
try {
form.getTCProperty(prop).setReferenceValueArray(
list.toArray(new TCComponent[list.size()]));
form.getTCProperty(prop).setReferenceValueArray(list.toArray(new TCComponent[list.size()]));
System.out.println("±£´ætable³É¹¦");
return true;
} catch (TCException e) {

@ -16,6 +16,7 @@ public class DBConnectionUtil {
}
try {
c = DriverManager.getConnection("jdbc:oracle:thin:@10.20.4.75:1521:TC12", name, pass);
// c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:TC", name, pass);
// 连接数据的方法有四种, 这个属于最简单的,一般用网页程序 TC是你的数据库实例名称在下载的文件test.sql中可以执行语句查看
// "jdbc:oracle:thin:@计算机名称:监听端口:系统实例名", username, password,
// 计算机名称,要是自己不知道可以在计算机属性查知.

@ -1,3 +1,6 @@
JD2_GTYPQRDRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.SampleConfirmationForm
JD2_GTSYWTSRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.ExperimentalPowerOfAttorneyForm
SF6_ElecElementRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.CSJHForm
JD2_GTCSJHRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.CSJHForm
JD2_GTXPCSXQDRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.NewProductTestForm
JD2_GTXPXMCSJHRevisionMaster.FORMJAVARENDERING=com.connor.jd.plm.form.GTCSJHForm
Loading…
Cancel
Save