Skip to content

Commit

Permalink
优化界面
Browse files Browse the repository at this point in the history
  • Loading branch information
zouzg committed Jan 21, 2017
1 parent 07713cc commit 35f5541
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,8 @@ public class MainUIController extends BaseFXController {
private CheckBox commentCheckBox;
@FXML
private CheckBox annotationCheckBox;

@FXML
private TreeView<String> leftDBTree;
@FXML
private TextArea consoleTextArea;
// Current selected databaseConfig
private DatabaseConfig selectedDatabaseConfig;
// Current selected tableName
Expand Down Expand Up @@ -130,7 +127,7 @@ public void initialize(URL location, ResourceBundle resources) {
TreeItem<String> 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();
});
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/zzg/mybatis/generator/util/DbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -32,7 +32,7 @@ public static List<String> 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);
Expand All @@ -46,7 +46,7 @@ public static List<String> getTableNames(DatabaseConfig config) throws Exception
public static List<UITableColumnVO> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/main/resources/fxml/MainUI.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@
<center>
<SplitPane dividerPositions="0.15">
<items>
<AnchorPane prefHeight="618.0" prefWidth="175.0">
<AnchorPane maxWidth="250.0" minWidth="100.0" prefHeight="618.0" prefWidth="175.0">
<children>
<TreeView fx:id="leftDBTree" layoutX="-14.0" prefHeight="545.0" prefWidth="126.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<TreeView fx:id="leftDBTree" layoutX="-14.0" maxWidth="0.0" prefHeight="545.0" prefWidth="126.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane>
<children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<GridPane alignment="TOP_RIGHT" layoutX="5.0" layoutY="29.0" prefHeight="404.0" prefWidth="732.0" vgap="5.0" AnchorPane.leftAnchor="-5.0" AnchorPane.rightAnchor="10.0">
<GridPane alignment="TOP_RIGHT" layoutX="5.0" layoutY="29.0" prefHeight="501.0" prefWidth="771.0" vgap="5.0" AnchorPane.leftAnchor="-5.0" AnchorPane.rightAnchor="10.0">
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" maxWidth="157.0" minWidth="132.0" prefWidth="138.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="688.0" minWidth="10.0" prefWidth="170.0" />
Expand All @@ -70,13 +70,14 @@
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="44.0" minHeight="10.0" prefHeight="27.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="25.0" minHeight="8.0" prefHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="72.0" minHeight="10.0" prefHeight="56.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="33.0" minHeight="8.0" prefHeight="33.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="63.0" minHeight="8.0" prefHeight="63.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="92.0" minHeight="62.0" prefHeight="62.0" />
</rowConstraints>
<children>
<Label text="Connector Jar" />
Expand Down Expand Up @@ -197,7 +198,7 @@
<children>
<HBox alignment="CENTER_LEFT" spacing="10.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="8">
<children>
<CheckBox fx:id="offsetLimitCheckBox" mnemonicParsing="false" selected="true" text="Pagination" GridPane.columnIndex="1" GridPane.rowIndex="8" />
<CheckBox fx:id="offsetLimitCheckBox" minWidth="100.0" mnemonicParsing="false" selected="true" text="Pagination" GridPane.columnIndex="1" GridPane.rowIndex="8" />
<CheckBox fx:id="commentCheckBox" mnemonicParsing="false" selected="true" text="Use DB Table Column Comments As Java Model Comments" />
</children>
</HBox>
Expand Down Expand Up @@ -241,7 +242,6 @@
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>
<TextArea fx:id="consoleTextArea" editable="false" focusTraversable="false" layoutY="429.0" prefHeight="77.0" prefWidth="722.0" styleClass="consoleTextArea" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="429.0" />
</children>
</AnchorPane>
</items>
Expand Down

0 comments on commit 35f5541

Please sign in to comment.