|
|
package com.connor.jd.plm.dialogs;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import com.connor.jd.operations.ExcelOperation;
|
|
|
import com.connor.jd.plm.utils.JDMethodUtil;
|
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
|
import com.teamcenter.rac.kernel.TCComponentDataset;
|
|
|
import com.teamcenter.rac.kernel.TCComponentProjectSmartFolder;
|
|
|
import com.teamcenter.rac.kernel.TCComponentTcFile;
|
|
|
import com.teamcenter.rac.kernel.TCException;
|
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
|
|
|
import javafx.application.Application;
|
|
|
import javafx.scene.Scene;
|
|
|
import javafx.scene.control.Button;
|
|
|
import javafx.scene.control.ComboBox;
|
|
|
import javafx.scene.control.Label;
|
|
|
import javafx.scene.control.TextField;
|
|
|
import javafx.scene.layout.Pane;
|
|
|
import javafx.stage.FileChooser;
|
|
|
import javafx.stage.FileChooser.ExtensionFilter;
|
|
|
import javafx.stage.Stage;
|
|
|
|
|
|
public class QTXJCDialog extends Application {
|
|
|
|
|
|
private TCSession session;
|
|
|
private TextField road = null;
|
|
|
private ComboBox<String> pjsName = null;
|
|
|
private List<String> sfList = new ArrayList<String>();
|
|
|
private TCComponent[] com;
|
|
|
private String type;
|
|
|
private Stage primaryStage = null;
|
|
|
|
|
|
public QTXJCDialog(List<String> sfList, TCComponent[] com, TCSession session, String type) throws TCException {
|
|
|
|
|
|
this.sfList = sfList;
|
|
|
this.com = com;
|
|
|
this.session = session;
|
|
|
this.type = type;
|
|
|
// initUI();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void start(Stage arg0) throws Exception {
|
|
|
primaryStage = new Stage();
|
|
|
Pane root = new Pane();
|
|
|
Label pjStage = new Label("ÏîÄ¿½×¶Î");
|
|
|
pjStage.setLayoutX(37.0);
|
|
|
pjStage.setLayoutY(51.0);
|
|
|
pjsName = new ComboBox<String>();
|
|
|
pjsName.setLayoutX(89.0);
|
|
|
pjsName.setLayoutY(47.0);
|
|
|
pjsName.setPrefSize(161.0, 23.0);
|
|
|
pjsName.setValue("");
|
|
|
pjsName.getItems().add("");
|
|
|
for (int i = 0; i < sfList.size(); i++) {
|
|
|
pjsName.getItems().add(sfList.get(i));
|
|
|
}
|
|
|
Label roadLabel = new Label("·¾¶");
|
|
|
roadLabel.setLayoutX(37.0);
|
|
|
roadLabel.setLayoutY(107.0);
|
|
|
road = new TextField();
|
|
|
road.setLayoutX(89.0);
|
|
|
road.setLayoutY(103.0);
|
|
|
road.setDisable(true);
|
|
|
Button open = new Button("Ñ¡Ôñ");
|
|
|
open.setLayoutX(263.0);
|
|
|
open.setLayoutY(103.0);
|
|
|
open.setOnAction((arg) -> {
|
|
|
openBtn(primaryStage);
|
|
|
});
|
|
|
Button export = new Button("µ¼³ö");
|
|
|
export.setLayoutX(89.0);
|
|
|
export.setLayoutY(158.0);
|
|
|
export.setPrefSize(48.0, 23.0);
|
|
|
export.setOnAction((arg) -> {
|
|
|
exportBtn();
|
|
|
});
|
|
|
Button out = new Button("È¡Ïû");
|
|
|
out.setLayoutX(208.0);
|
|
|
out.setLayoutY(158.0);
|
|
|
out.setPrefSize(48.0, 23.0);
|
|
|
out.setOnAction((arg) -> {
|
|
|
primaryStage.close();
|
|
|
});
|
|
|
root.getChildren().add(pjStage);
|
|
|
root.getChildren().add(pjsName);
|
|
|
root.getChildren().add(roadLabel);
|
|
|
root.getChildren().add(road);
|
|
|
root.getChildren().add(open);
|
|
|
root.getChildren().add(export);
|
|
|
root.getChildren().add(out);
|
|
|
|
|
|
Scene scene = new Scene(root, 338.0, 207);
|
|
|
primaryStage.setScene(scene);
|
|
|
primaryStage.setResizable(false);
|
|
|
primaryStage.show();
|
|
|
}
|
|
|
|
|
|
// private void initUI() {
|
|
|
// this.setAutoRequestFocus(true);
|
|
|
// this.setPreferredSize(new Dimension(360, 150));
|
|
|
// this.setResizable(false);
|
|
|
//
|
|
|
// JLabel pjStage = new JLabel("ÏîÄ¿½×¶Î");
|
|
|
// pjsName.addItem("");
|
|
|
// for (int i = 0; i < sfList.size(); i++) {
|
|
|
// pjsName.addItem(sfList.get(i));
|
|
|
// }
|
|
|
// JLabel roadLabel = new JLabel("·¾¶");
|
|
|
//
|
|
|
// JButton open = new JButton("...");
|
|
|
// open.addActionListener(new ActionListener() {
|
|
|
// @Override
|
|
|
// public void actionPerformed(ActionEvent e) {
|
|
|
// openBtn();
|
|
|
// }
|
|
|
// });
|
|
|
// JButton export = new JButton("µ¼³ö");
|
|
|
// export.addActionListener(new ActionListener() {
|
|
|
// @Override
|
|
|
// public void actionPerformed(ActionEvent e) {
|
|
|
// exportBtn();
|
|
|
// }
|
|
|
// });
|
|
|
// JButton out = new JButton("È¡Ïû");
|
|
|
// out.addActionListener(new ActionListener() {
|
|
|
// @Override
|
|
|
// public void actionPerformed(ActionEvent e) {
|
|
|
// dispose();
|
|
|
// }
|
|
|
// });
|
|
|
// JPanel flow1 = new JPanel();
|
|
|
// Box b1 = Box.createHorizontalBox();
|
|
|
// flow1.add(b1);
|
|
|
// // b1.add(Box.createHorizontalStrut(20));
|
|
|
// b1.add(pjStage);
|
|
|
// b1.add(Box.createHorizontalStrut(50));
|
|
|
// b1.add(pjsName);
|
|
|
// JPanel flow2 = new JPanel();
|
|
|
// Box b2 = Box.createHorizontalBox();
|
|
|
// flow2.add(b2);
|
|
|
// b2.add(Box.createHorizontalStrut(20));
|
|
|
// b2.add(roadLabel);
|
|
|
// b2.add(Box.createHorizontalStrut(20));
|
|
|
// b2.add(road);
|
|
|
// b2.add(Box.createHorizontalStrut(80));
|
|
|
// b2.add(open);
|
|
|
// JPanel btn = new JPanel(new ButtonLayout());
|
|
|
// btn.add(export);
|
|
|
// btn.add(out);
|
|
|
// JPanel center = new JPanel(new BorderLayout());
|
|
|
// center.add(flow1, BorderLayout.NORTH);
|
|
|
// center.add(flow2, BorderLayout.CENTER);
|
|
|
// center.add(btn, BorderLayout.SOUTH);
|
|
|
// this.add(center, "Center");
|
|
|
//
|
|
|
// this.pack();
|
|
|
// this.centerToScreen();
|
|
|
// this.showDialog();
|
|
|
// }
|
|
|
//
|
|
|
String roadName = null;
|
|
|
|
|
|
private void openBtn(Stage primaryStage) {
|
|
|
FileChooser chooser = new FileChooser();
|
|
|
chooser.setTitle("ÇëÑ¡ÔñÒª±£´æµÄÎļþ¼Ð");
|
|
|
chooser.getExtensionFilters().addAll(new ExtensionFilter("Excel¹¤×÷²¾(*.xlsx)", "xlsx"));
|
|
|
File getfile = chooser.showSaveDialog(primaryStage);
|
|
|
try {
|
|
|
if (getfile.getAbsolutePath() != null) {
|
|
|
String filePath = getfile.getAbsolutePath() + ".xlsx";
|
|
|
roadName = filePath;
|
|
|
if (filePath.length() > 25) {
|
|
|
road.setText(filePath.substring(0, 25) + "...");
|
|
|
} else {
|
|
|
road.setText(filePath);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void exportBtn() {
|
|
|
String jdname = "JDJFW";
|
|
|
if (roadName.equals("")) {
|
|
|
MessageBox.post("ûÓÐÑ¡Ôñ±£´æÂ·¾¶", "´íÎó", MessageBox.ERROR);
|
|
|
} else {
|
|
|
System.out.println(road.getText());
|
|
|
String outpath = roadName;
|
|
|
|
|
|
System.out.println(outpath);
|
|
|
// System.out.println("typeÊÇ" + type);
|
|
|
File file = getExcle(jdname, type);
|
|
|
String sel = pjsName.getSelectionModel().getSelectedItem();
|
|
|
Map<String, List<TCComponent>> jfw = new HashMap<String, List<TCComponent>>();
|
|
|
if (sel.equals("")) {
|
|
|
for (int i = 0; i < sfList.size(); i++) {
|
|
|
TCComponentProjectSmartFolder sf = (TCComponentProjectSmartFolder) com[i];
|
|
|
try {
|
|
|
TCComponent[] psf = sf.getTCProperty("project_data").getReferenceValueArray();
|
|
|
|
|
|
List<TCComponent> jfList = new ArrayList<TCComponent>();
|
|
|
for (int j = 0; j < psf.length; j++) {
|
|
|
// TCComponentItem jf = (TCComponentItem) psf[j];
|
|
|
jfList.add(psf[j]);
|
|
|
}
|
|
|
jfw.put(sf.getProperty("object_string"), jfList);
|
|
|
} catch (TCException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
for (int i = 0; i < sfList.size(); i++) {
|
|
|
TCComponentProjectSmartFolder sf = (TCComponentProjectSmartFolder) com[i];
|
|
|
try {
|
|
|
if (sel.equals(sf.getProperty("object_string"))) {
|
|
|
TCComponent[] psf = sf.getTCProperty("project_data").getReferenceValueArray();
|
|
|
List<TCComponent> jfList = new ArrayList<TCComponent>();
|
|
|
for (int j = 0; j < psf.length; j++) {
|
|
|
// TCComponentItem jf = (TCComponentItem) psf[j];
|
|
|
jfList.add(psf[j]);
|
|
|
}
|
|
|
jfw.put(sel, jfList);
|
|
|
}
|
|
|
} catch (TCException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
ExcelOperation.writeExcel(file, outpath, jfw);
|
|
|
System.out.println("µ¼³ö³É¹¦");
|
|
|
primaryStage.close();
|
|
|
MessageBox.post("µ¼³ö³É¹¦", "ÐÅÏ¢", MessageBox.INFORMATION);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private File getExcle(String ssx, String type) {
|
|
|
File fmsFile = null;
|
|
|
String allpuid = JDMethodUtil.getPrefStr(ssx, session);
|
|
|
String[] relpuid = allpuid.split(";");
|
|
|
if (relpuid.length != 3) {
|
|
|
MessageBox.post("ÇëÁªÏµ¹ÜÀíÔ±¼ì²éÊ×Ñ¡Ïî", "´íÎó", MessageBox.ERROR);
|
|
|
return null;
|
|
|
}
|
|
|
String puid = null;
|
|
|
switch (type) {
|
|
|
case "GT":
|
|
|
puid = relpuid[2];
|
|
|
break;
|
|
|
case "BL":
|
|
|
puid = relpuid[1];
|
|
|
break;
|
|
|
case "BX":
|
|
|
puid = relpuid[0];
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
if (puid == null) {
|
|
|
MessageBox.post("ÇëÁªÏµ¹ÜÀíÔ±¼ì²éÊ×Ñ¡Ïî", "´íÎó", MessageBox.ERROR);
|
|
|
return null;
|
|
|
}
|
|
|
TCComponentDataset dateset = null;
|
|
|
try {
|
|
|
dateset = (TCComponentDataset) session.stringToComponent(puid);
|
|
|
} catch (TCException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (dateset == null) {
|
|
|
MessageBox.post("δÕÒµ½Êý¾Ý¼¯£¬ÇëÁªÏµ¹ÜÀíÔ±¼ì²éÊ×Ñ¡Ïî", "´íÎó", MessageBox.ERROR);
|
|
|
return null;
|
|
|
}
|
|
|
try {
|
|
|
TCComponentTcFile[] file = dateset.getTcFiles();
|
|
|
if (file.length == 0 || file.length != 1) {
|
|
|
MessageBox.post("Êý¾Ý¼¯Ã»ÓÐÃüÃûÒýÓõÄÎļþ»òÎļþ¹ý¶à£¬Çë¼ì²é£¡", "¾¯¸æ", MessageBox.WARNING);
|
|
|
return null;
|
|
|
} else {
|
|
|
fmsFile = file[0].getFmsFile();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return fmsFile;
|
|
|
}
|
|
|
|
|
|
}
|