SagaFileMoveApp.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. package com.persagy.filemove.app;
  2. import com.persagy.filemove.dialog.FileMoveHelpDialog;
  3. import com.persagy.filemove.dialog.MessageDialog;
  4. import com.persagy.filemove.dto.SagaFileMoveDTO;
  5. import com.persagy.filemove.dto.WorkerFactory;
  6. import com.persagy.filemove.service.SagaFileMoveService;
  7. import javafx.application.Application;
  8. import javafx.collections.FXCollections;
  9. import javafx.concurrent.Task;
  10. import javafx.geometry.Insets;
  11. import javafx.geometry.Pos;
  12. import javafx.scene.Node;
  13. import javafx.scene.Scene;
  14. import javafx.scene.control.*;
  15. import javafx.scene.layout.BorderPane;
  16. import javafx.scene.layout.HBox;
  17. import javafx.scene.layout.Pane;
  18. import javafx.scene.layout.VBox;
  19. import javafx.scene.paint.Color;
  20. import javafx.stage.Stage;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import java.lang.reflect.Field;
  24. import java.util.LinkedHashMap;
  25. public class SagaFileMoveApp extends Application {
  26. private static final Logger log = LoggerFactory.getLogger(SagaFileMoveApp.class);
  27. private static final String aboutInfo = "Version:1.0\nJDK:1.8\nAuthor:cuixubin@persagy.com";
  28. private static int appWidth = 640;
  29. private static int appHeight = 560;
  30. public static SagaFileMoveDTO dto = new SagaFileMoveDTO();
  31. /** 数据平台默认systemId */
  32. private static String sysId_dpf = "dataPlatform";
  33. /** 数据平台默认密码 */
  34. private static String secret_dpf = "9e0891a7a8c8e885";
  35. /** revit默认systemId */
  36. private static String sysId_rvt = "revit";
  37. /** revit默认密码 */
  38. private static String secret_rvt = "63afbef6906c342b";
  39. /** key值校正 */
  40. private static String keyValueTip = "key值校正";
  41. private SagaFileMoveService service = new SagaFileMoveService();
  42. /** 文件服务上传下载接口类型 */
  43. private static final String[] apiTypes = {"default", "file", "image"};
  44. /** 对象类型 */
  45. private static String[] objTypes;
  46. /** 对象类型对应信息点 */
  47. private static final LinkedHashMap<String, String[]> objToInfoCode = new LinkedHashMap<>();
  48. static {
  49. objToInfoCode.put("Fl", new String[]{"FloorMap"});
  50. objToInfoCode.put("Eq", new String[]{"EquipQRCode"});
  51. objToInfoCode.put("Sp", new String[]{"RoomQRCode"});
  52. objToInfoCode.put("Sy", new String[]{"EquipQRCode"});
  53. objToInfoCode.put("Ec", new String[]{"EquipQRCode"});
  54. objTypes = objToInfoCode.keySet().stream().toArray(n -> new String[n]);
  55. }
  56. /** 数据平台地址 */
  57. private TextField tfDPF = new TextField("http://api.sagacloud.cn/data-platform-3");
  58. /** 项目id */
  59. private TextField tfPjId = new TextField("Pj3101050003");
  60. /** 项目密码 */
  61. private TextField tfPjSecret = new TextField();
  62. /** 对象类型 */
  63. private ChoiceBox cbObjType = new ChoiceBox();
  64. /** 对象信息点 */
  65. private ChoiceBox cbObjInfoCodeArray = new ChoiceBox();
  66. /** 文件服务from地址 */
  67. private TextField tfImgFromURL = new TextField("http://47.93.33.207:28888/image-service");
  68. /** 文件服务from的systemId */
  69. private TextField tfImgFromSysId = new TextField(sysId_rvt);
  70. /** 文件服务from的secret */
  71. private TextField tfImgFromSecret = new TextField(secret_rvt);
  72. /** 接口类型 */
  73. private ChoiceBox cbImgFromApiType = new ChoiceBox(FXCollections.observableArrayList(apiTypes));
  74. /** 文件服务To地址 */
  75. private TextField tfImgToURL = new TextField("http://127.0.0.1:6666/image-service");
  76. /** 文件服务To的systemId */
  77. private TextField tfImgToSysId = new TextField(sysId_dpf);
  78. /** 文件服务To的secret */
  79. private TextField tfImgToSecret = new TextField(secret_dpf);
  80. /** 接口类型 */
  81. private ChoiceBox cbImgToApiType = new ChoiceBox(FXCollections.observableArrayList(apiTypes));
  82. /** 是否自动去除key值前缀中的目录 */
  83. ToggleButton tbKeyModify = new ToggleButton(keyValueTip+"-开");
  84. /** 执行校验按钮 */
  85. private Button btnValid = new Button("参数校验");
  86. /** 文件传输执行按钮 */
  87. private Button btnExecute = new Button("开始传输");
  88. /** 执行信息 */
  89. private Label lblExecute_sts = new Label();
  90. /** 提示信息 */
  91. private Label lblTips_sts = new Label();
  92. private ProgressBar progressBar_sts = new ProgressBar(0);
  93. public static void main(String[] args) {
  94. launch(args);
  95. }
  96. /**
  97. * 初始化基础控件
  98. */
  99. private void initComponents() {
  100. bindDTO();
  101. tfDPF.setPrefWidth(appWidth * .7);
  102. tfPjId.setPrefWidth(appWidth * .25);
  103. tfPjSecret.setPrefWidth(appWidth * .25);
  104. cbObjType.setItems(FXCollections.observableArrayList(objTypes));
  105. cbObjType.setPrefWidth(appWidth * .1);
  106. // 设置默认选择第一项
  107. cbObjType.getSelectionModel().selectFirst();
  108. cbObjInfoCodeArray.setItems(FXCollections.observableArrayList(objToInfoCode.get(cbObjType.getSelectionModel().getSelectedItem().toString())));
  109. cbObjInfoCodeArray.getSelectionModel().selectFirst();
  110. cbObjInfoCodeArray.setPrefWidth(appWidth * .25);
  111. tfImgFromURL.setPrefWidth(appWidth * .5);
  112. tfImgFromSysId.setPrefWidth(appWidth * .25);
  113. tfImgFromSecret.setPrefWidth(appWidth * .25);
  114. cbImgFromApiType.setPrefWidth(appWidth * .15);
  115. cbImgFromApiType.getSelectionModel().selectFirst();
  116. tfImgToURL.setPrefWidth(appWidth * .5);
  117. tfImgToSysId.setPrefWidth(appWidth * .25);
  118. tfImgToSecret.setPrefWidth(appWidth * .25);
  119. cbImgToApiType.setPrefWidth(appWidth * .15);
  120. cbImgToApiType.getSelectionModel().select(1);
  121. btnValid.setPrefSize(appWidth * .15, 30);
  122. btnExecute.setPrefSize(appWidth * .15, 30);
  123. progressBar_sts.setPrefWidth(appWidth * .55);
  124. tbKeyModify.setSelected(true);
  125. tbKeyModify.setStyle("-fx-base: #75bd43");
  126. tbKeyModify.setOnAction((ob)->{
  127. if(tbKeyModify.isSelected()) {
  128. tbKeyModify.setText(keyValueTip+"-开");
  129. tbKeyModify.setStyle("-fx-base: #75bd43");
  130. }else {
  131. tbKeyModify.setText(keyValueTip+"-关");
  132. tbKeyModify.setStyle("-fx-base: #bbbbbb");
  133. }
  134. });
  135. // 点击验证参数按钮
  136. btnValid.setOnAction(e -> {
  137. disableSet(true);
  138. lblTips_sts.textProperty().unbind();
  139. lblTips_sts.setText("");
  140. lblExecute_sts.textProperty().unbind();
  141. progressBar_sts.progressProperty().unbind();
  142. progressBar_sts.setProgress(0);
  143. showTipsInfo("校验参数...");
  144. Task<Boolean> worker = WorkerFactory.getValidParamWorker(this);
  145. progressBar_sts.progressProperty().bind(worker.progressProperty());
  146. new Thread(worker).start();
  147. });
  148. // 点击文件迁移按钮
  149. btnExecute.setOnAction(e -> {
  150. disableSet(true);
  151. lblTips_sts.textProperty().unbind();
  152. lblTips_sts.setText("");
  153. lblExecute_sts.textProperty().unbind();
  154. lblExecute_sts.setText("");
  155. progressBar_sts.progressProperty().unbind();
  156. progressBar_sts.setProgress(-1);
  157. Task<Boolean> worker = WorkerFactory.getTransRateWorker(this);
  158. lblTips_sts.textProperty().bind(worker.titleProperty());
  159. lblExecute_sts.textProperty().bind(worker.messageProperty());
  160. progressBar_sts.progressProperty().bind(worker.progressProperty());
  161. new Thread(worker).start();
  162. });
  163. cbObjType.getSelectionModel().selectedIndexProperty().addListener((obv, ov, nv)->{
  164. String objType = cbObjType.getItems().get(nv.intValue()) + "";
  165. cbObjInfoCodeArray.setItems(FXCollections.observableArrayList(objToInfoCode.get(objType)));
  166. cbObjInfoCodeArray.getSelectionModel().selectFirst();
  167. if("Fl".equals(objType)) {
  168. tfImgFromSysId.setText(sysId_rvt);
  169. tfImgFromSecret.setText(secret_rvt);
  170. }else {
  171. tfImgFromSysId.setText(sysId_dpf);
  172. tfImgFromSecret.setText(secret_dpf);
  173. }
  174. });
  175. }
  176. /**
  177. * 设置视图中的所有控件是否为不可编辑状态
  178. * @param disable true-控件不可编辑;false-控件可编辑
  179. */
  180. public void disableSet(boolean disable) {
  181. Field[] allFields = SagaFileMoveApp.class.getDeclaredFields();
  182. for(Field field : allFields) {
  183. if(field.getName().endsWith("_sts")) {
  184. continue;
  185. }
  186. try {
  187. if(Node.class.isAssignableFrom(field.get(this).getClass())) {
  188. Node node = (Node) field.get(this);
  189. node.setDisable(disable);
  190. }
  191. }catch (Exception e) {}
  192. }
  193. }
  194. public void showTipsSuccess(String info) {
  195. lblExecute_sts.setTextFill(Color.DARKGREEN);
  196. lblExecute_sts.setText(info);
  197. }
  198. public void showTipsInfo(String info) {
  199. lblExecute_sts.setTextFill(Color.BLACK);
  200. lblExecute_sts.setText(info);
  201. }
  202. public void showTipsError(String errMsg) {
  203. lblExecute_sts.setTextFill(Color.RED);
  204. lblExecute_sts.setText(errMsg);
  205. }
  206. public void showTipsWarn(String warnMsg) {
  207. lblExecute_sts.setTextFill(Color.DARKORANGE);
  208. lblExecute_sts.setText(warnMsg);
  209. }
  210. /**
  211. * 将控件的值绑定到DTO对象的属性上
  212. */
  213. private void bindDTO() {
  214. dto.dpf.bind(tfDPF.textProperty());
  215. dto.imgFromApiType.bind(cbImgFromApiType.valueProperty());
  216. dto.imgFromSecret.bind(tfImgFromSecret.textProperty());
  217. dto.imgFromSysId.bind(tfImgFromSysId.textProperty());
  218. dto.imgFromUrl.bind(tfImgFromURL.textProperty());
  219. dto.imgToApiType.bind(cbImgToApiType.valueProperty());
  220. dto.imgToSecret.bind(tfImgToSecret.textProperty());
  221. dto.imgToSysId.bind(tfImgToSysId.textProperty());
  222. dto.imgToUrl.bind(tfImgToURL.textProperty());
  223. dto.objInfoCode.bind(cbObjInfoCodeArray.valueProperty());
  224. dto.objType.bind(cbObjType.valueProperty());
  225. dto.pjId.bind(tfPjId.textProperty());
  226. dto.pjSecret.bind(tfPjSecret.textProperty());
  227. dto.keyModify.bind(tbKeyModify.selectedProperty());
  228. }
  229. @Override
  230. public void start(Stage primaryStage) throws Exception {
  231. initComponents();
  232. // 底层border布局
  233. BorderPane baseBorderPane = new BorderPane();
  234. // 菜单栏
  235. MenuBar menuBar = new MenuBar();
  236. menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
  237. menuBar.getMenus().addAll(getHelpMenu());
  238. // 主视图内容布局
  239. Pane centerPane = getCenterPane();
  240. baseBorderPane.setTop(menuBar);
  241. baseBorderPane.setCenter(centerPane);
  242. primaryStage.setResizable(false);
  243. Scene scene = new Scene(baseBorderPane, appWidth, appHeight);
  244. primaryStage.setScene(scene);
  245. primaryStage.show();
  246. }
  247. /**
  248. * 获取主要内容的布局面板实例
  249. * @return
  250. */
  251. private Pane getCenterPane() {
  252. Pane centerPane = new VBox();
  253. centerPane.setPadding(new Insets(0, 5, 0, 5));
  254. TitledPane paneObjParam = getObjTitlePane();
  255. TitledPane paneImgFrom = getImgTitlePane(true);
  256. TitledPane paneImgTo = getImgTitlePane(false);
  257. Pane paneExe = getExePane();
  258. Pane paneConsole = getConsolePane();
  259. centerPane.getChildren().addAll(paneObjParam, paneImgFrom, paneImgTo, paneExe, paneConsole);
  260. Insets nodeInsets = new Insets(0, 0, 15, 0);
  261. VBox.setMargin(paneObjParam, nodeInsets);
  262. VBox.setMargin(paneImgFrom, nodeInsets);
  263. return centerPane;
  264. }
  265. /**
  266. * 获取执行控制面板
  267. * @return
  268. */
  269. private Pane getExePane() {
  270. HBox contentBox = new HBox(btnValid, btnExecute, progressBar_sts, lblTips_sts);
  271. HBox.setMargin(btnExecute, new Insets(0, 20, 0, 15));
  272. HBox.setMargin(progressBar_sts, new Insets(0, 5, 0, 0));
  273. contentBox.setAlignment(Pos.CENTER_LEFT);
  274. contentBox.setPadding(new Insets(15, 0, 0, 0));
  275. return contentBox;
  276. }
  277. /**
  278. * 获取提示信息输出面板
  279. * @return
  280. */
  281. private Pane getConsolePane() {
  282. HBox contentBox = new HBox(lblExecute_sts);
  283. contentBox.setPadding(new Insets(15, 0, 0, 0));
  284. return contentBox;
  285. }
  286. /**
  287. * 生成包含数据平台、项目、对象配置参数的带标题的布局实例
  288. * @return
  289. */
  290. private TitledPane getObjTitlePane() {
  291. String title = "物理对象 - 配置传输哪个项目,哪类对象,哪个信息点对应的文件数据";
  292. String titlePaneBack = "-fx-background-color: wheat";
  293. LinkedHashMap<String, Node> projectMap = new LinkedHashMap<>();
  294. projectMap.put("*项目id ", tfPjId);
  295. projectMap.put("项目密码 ", tfPjSecret);
  296. LinkedHashMap<String, Node> objTypeMap = new LinkedHashMap<>();
  297. objTypeMap.put("*对象类型 ", cbObjType);
  298. objTypeMap.put("*对象信息点 ", cbObjInfoCodeArray);
  299. VBox contentPane = new VBox(getHBoxPane("*数据平台 ", tfDPF),
  300. getHBoxPane(projectMap), getHBoxPane(objTypeMap));
  301. contentPane.setPadding(new Insets(5, 0, 5,10));
  302. contentPane.setStyle("-fx-background-color: antiquewhite");
  303. TitledPane titledPane = new TitledPane(title, contentPane);
  304. titledPane.setCollapsible(false);
  305. return titledPane;
  306. }
  307. /**
  308. * 生成包含文件服务参数控件的带标题的布局实例
  309. * @param isFrom true-数据来源方的文件服务;false-数据接收方的文件服务
  310. * @return
  311. */
  312. private TitledPane getImgTitlePane(boolean isFrom) {
  313. String titleFrom = "From:即获取文件资源数据所访问的image-service服务";
  314. String titleTo = "To:即获上传文件资源所访问的image-service服务";
  315. String title = "文件服务 - " + (isFrom ? titleFrom : titleTo);
  316. String titlePaneBack = "-fx-background-color: wheat";
  317. Node systemId = null, secret = null, serviceURL = null, apiType;
  318. if(isFrom) {
  319. systemId = tfImgFromSysId;
  320. secret = tfImgFromSecret;
  321. serviceURL = tfImgFromURL;
  322. apiType = cbImgFromApiType;
  323. titlePaneBack = "-fx-background-color: bisque";
  324. }else {
  325. systemId = tfImgToSysId;
  326. secret = tfImgToSecret;
  327. serviceURL = tfImgToURL;
  328. apiType = cbImgToApiType;
  329. }
  330. LinkedHashMap<String, Node> urlAndApiTypeMap = new LinkedHashMap<>();
  331. urlAndApiTypeMap.put("*服务URL ", serviceURL);
  332. urlAndApiTypeMap.put("*接口类型 ", apiType);
  333. LinkedHashMap<String, Node> paramMap = new LinkedHashMap<>();
  334. paramMap.put("*systemId ", systemId);
  335. paramMap.put("*secret ", secret);
  336. if(!isFrom) {
  337. paramMap.put("", tbKeyModify);
  338. }
  339. VBox contentPane = new VBox(getHBoxPane(urlAndApiTypeMap),
  340. getHBoxPane(paramMap));
  341. contentPane.setPadding(new Insets(5, 0, 5,10));
  342. contentPane.setStyle(titlePaneBack);
  343. TitledPane titledPane = new TitledPane(title, contentPane);
  344. titledPane.setCollapsible(false);
  345. return titledPane;
  346. }
  347. /**
  348. * 获取水平排布的含有Label和Node节点两个控件面板实例
  349. * @param label 标签内容
  350. * @param node 控件节点
  351. * @return
  352. */
  353. private Pane getHBoxPane(String label, Node node) {
  354. LinkedHashMap<String, Node> map = new LinkedHashMap<>();
  355. map.put(label, node);
  356. return getHBoxPane(map);
  357. }
  358. /**
  359. * 获取水平排布的含多对(Label:Node)节点组的面板实例
  360. * @param label_textField {标签名:控件节点}
  361. * @return
  362. */
  363. private Pane getHBoxPane(LinkedHashMap<String, Node> label_textField) {
  364. HBox pane = new HBox();
  365. Insets nodeInsets = new Insets(0, 15, 0, 0);
  366. for(String name : label_textField.keySet()) {
  367. Label label = new Label(name);
  368. Node node = label_textField.get(name);
  369. pane.getChildren().addAll(label, node);
  370. HBox.setMargin(node, nodeInsets);
  371. }
  372. pane.setPadding(new Insets(5, 5, 5, 0));
  373. pane.setAlignment(Pos.CENTER_LEFT);
  374. return pane;
  375. }
  376. /**
  377. * 获取帮助菜单按钮
  378. * @return
  379. */
  380. private Menu getHelpMenu() {
  381. // 菜单项
  382. MenuItem mi_help = new MenuItem("Help");
  383. mi_help.setOnAction((e)->{
  384. new FileMoveHelpDialog().showAndWait();
  385. });
  386. MenuItem mi_about = new MenuItem("About");
  387. mi_about.setOnAction((e)->{
  388. new MessageDialog("About", aboutInfo, 300, 120).showAndWait();
  389. });
  390. SeparatorMenuItem seline = new SeparatorMenuItem();
  391. Menu helpMenu = new Menu("Help");
  392. helpMenu.getItems().addAll(mi_help, seline, mi_about);
  393. return helpMenu;
  394. }
  395. }