From 35f5541e1457fe638e07d1992e3ecb978398ebe6 Mon Sep 17 00:00:00 2001 From: Owen Zou Date: Sat, 21 Jan 2017 21:07:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MainUIController.java | 15 ++++---- .../zzg/mybatis/generator/util/DbUtil.java | 8 ++-- .../generator/view/UIProgressCallback.java | 38 +++++++------------ src/main/resources/fxml/MainUI.fxml | 16 ++++---- 4 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java b/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java index e1ebfa7d..440dfd30 100644 --- a/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java +++ b/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java @@ -82,11 +82,8 @@ public class MainUIController extends BaseFXController { private CheckBox commentCheckBox; @FXML private CheckBox annotationCheckBox; - @FXML private TreeView leftDBTree; - @FXML - private TextArea consoleTextArea; // Current selected databaseConfig private DatabaseConfig selectedDatabaseConfig; // Current selected tableName @@ -130,7 +127,7 @@ public void initialize(URL location, ResourceBundle resources) { TreeItem treeItem = treeCell.getTreeItem(); if (level == 1) { final ContextMenu contextMenu = new ContextMenu(); - MenuItem item1 = new MenuItem("新建连接"); + MenuItem item1 = new MenuItem("关闭连接"); item1.setOnAction(event1 -> { treeItem.getChildren().clear(); }); @@ -169,7 +166,7 @@ public void initialize(URL location, ResourceBundle resources) { } } catch (CommunicationsException e) { _LOG.error(e.getMessage(), e); - AlertUtil.showErrorAlert("Connection timeout"); + AlertUtil.showErrorAlert("连接超时"); } catch (Exception e) { _LOG.error(e.getMessage(), e); AlertUtil.showErrorAlert(e.getMessage()); @@ -231,7 +228,7 @@ public void chooseProjectFolder() { @FXML public void generateCode() { if (tableName == null) { - AlertUtil.showErrorAlert("Please select table from left DB treee first"); + AlertUtil.showErrorAlert("Please select table from left DB tree first"); return; } GeneratorConfig generatorConfig = getGeneratorConfigFromUI(); @@ -244,8 +241,10 @@ public void generateCode() { bridge.setDatabaseConfig(selectedDatabaseConfig); bridge.setIgnoredColumns(ignoredColumns); bridge.setColumnOverrides(columnOverrides); - bridge.setProgressCallback(new UIProgressCallback(consoleTextArea)); - try { + UIProgressCallback alert = new UIProgressCallback(Alert.AlertType.INFORMATION); + bridge.setProgressCallback(alert); + alert.show(); + try { bridge.generate(); } catch (Exception e) { AlertUtil.showErrorAlert(e.getMessage()); diff --git a/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java b/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java index e3b71d30..310cc5ee 100644 --- a/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java +++ b/src/main/java/com/zzg/mybatis/generator/util/DbUtil.java @@ -16,12 +16,12 @@ public class DbUtil { private static final Logger _LOG = LoggerFactory.getLogger(DbUtil.class); - private static final int DB_CONNECTION_TIMEOUTS_SENCONDS = 10; + private static final int DB_CONNECTION_TIMEOUTS_SECONDS = 1; public static Connection getConnection(DatabaseConfig config) throws ClassNotFoundException, SQLException { DbType dbType = DbType.valueOf(config.getDbType()); Class.forName(dbType.getDriverClass()); - DriverManager.setLoginTimeout(DB_CONNECTION_TIMEOUTS_SENCONDS); + DriverManager.setLoginTimeout(DB_CONNECTION_TIMEOUTS_SECONDS); String url = getConnectionUrlWithSchema(config); _LOG.info("getConnection, connection url: {}", url); return DriverManager.getConnection(url, config.getUsername(), config.getPassword()); @@ -32,7 +32,7 @@ public static List getTableNames(DatabaseConfig config) throws Exception Class.forName(dbType.getDriverClass()); String url = getConnectionUrlWithSchema(config); _LOG.info("getTableNames, connection url: {}", url); - DriverManager.setLoginTimeout(DB_CONNECTION_TIMEOUTS_SENCONDS); + DriverManager.setLoginTimeout(DB_CONNECTION_TIMEOUTS_SECONDS); Connection conn = DriverManager.getConnection(url, config.getUsername(), config.getPassword()); DatabaseMetaData md = conn.getMetaData(); ResultSet rs = md.getTables(null, null, null, null); @@ -46,7 +46,7 @@ public static List getTableNames(DatabaseConfig config) throws Exception public static List getTableColumns(DatabaseConfig dbConfig, String tableName) throws Exception { DbType dbType = DbType.valueOf(dbConfig.getDbType()); Class.forName(dbType.getDriverClass()); - DriverManager.setLoginTimeout(DB_CONNECTION_TIMEOUTS_SENCONDS); + DriverManager.setLoginTimeout(DB_CONNECTION_TIMEOUTS_SECONDS); String url = getConnectionUrlWithSchema(dbConfig); _LOG.info("getTableColumns, connection url: {}", url); Connection conn = DriverManager.getConnection(url, dbConfig.getUsername(), dbConfig.getPassword()); diff --git a/src/main/java/com/zzg/mybatis/generator/view/UIProgressCallback.java b/src/main/java/com/zzg/mybatis/generator/view/UIProgressCallback.java index 2bdeb03e..1c8238d3 100644 --- a/src/main/java/com/zzg/mybatis/generator/view/UIProgressCallback.java +++ b/src/main/java/com/zzg/mybatis/generator/view/UIProgressCallback.java @@ -1,57 +1,45 @@ package com.zzg.mybatis.generator.view; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import javafx.scene.control.Alert; -import javafx.scene.control.TextArea; import org.mybatis.generator.api.ProgressCallback; -import java.util.ArrayList; -import java.util.List; - /** * Created by Owen on 6/21/16. */ -public class UIProgressCallback implements ProgressCallback { - - private TextArea consoleTextArea; +public class UIProgressCallback extends Alert implements ProgressCallback { - private StringBuilder sb; + private StringProperty progressText = new SimpleStringProperty(); - public UIProgressCallback(TextArea textArea) { - sb = new StringBuilder(); - this.consoleTextArea = textArea; + public UIProgressCallback(AlertType alertType) { + super(alertType); + this.contentTextProperty().bindBidirectional(progressText); } @Override public void introspectionStarted(int totalTasks) { - sb.append("introspection started\n"); - consoleTextArea.setText(sb.toString()); - } + progressText.setValue("开始代码检查"); + } @Override public void generationStarted(int totalTasks) { - sb.append("generate started\n"); - consoleTextArea.setText(sb.toString()); + progressText.setValue("开始代码生成"); } @Override public void saveStarted(int totalTasks) { - sb.append("save started\n"); - consoleTextArea.setText(sb.toString()); + progressText.setValue("开始保存生成的文件"); } @Override public void startTask(String taskName) { - sb.append("start task\n"); - consoleTextArea.setText(sb.toString()); + progressText.setValue("代码生成任务开始"); } @Override public void done() { - sb.append("generation done\n"); - consoleTextArea.setText(sb.toString()); - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setContentText("Generation Completed"); - alert.show(); + progressText.setValue("代码生成完成"); } @Override diff --git a/src/main/resources/fxml/MainUI.fxml b/src/main/resources/fxml/MainUI.fxml index d9d42710..09d18c78 100644 --- a/src/main/resources/fxml/MainUI.fxml +++ b/src/main/resources/fxml/MainUI.fxml @@ -49,16 +49,16 @@
- + - + - + @@ -70,13 +70,14 @@ - - + + - + + -