use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.
the class MainUIController method loadLeftDBTree.
void loadLeftDBTree() {
TreeItem rootTreeItem = leftDBTree.getRoot();
rootTreeItem.getChildren().clear();
try {
List<DatabaseConfig> dbConfigs = ConfigHelper.loadDatabaseConfig();
for (DatabaseConfig dbConfig : dbConfigs) {
TreeItem<String> treeItem = new TreeItem<>();
treeItem.setValue(dbConfig.getName());
ImageView dbImage = new ImageView("icons/computer.png");
dbImage.setFitHeight(16);
dbImage.setFitWidth(16);
dbImage.setUserData(dbConfig);
treeItem.setGraphic(dbImage);
rootTreeItem.getChildren().add(treeItem);
}
} catch (Exception e) {
_LOG.error("connect db failed, reason", e);
AlertUtil.showErrorAlert(e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e));
}
}
use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.
the class MainUIController method displayTables.
private void displayTables(TreeItem<String> treeItem) {
if (treeItem == null) {
return;
}
if (!treeItem.isExpanded()) {
return;
}
DatabaseConfig selectedConfig = (DatabaseConfig) treeItem.getGraphic().getUserData();
try {
String filter = filterTreeBox.getText();
List<String> tables = DbUtil.getTableNames(selectedConfig, filter);
if (tables.size() > 0) {
ObservableList<TreeItem<String>> children = treeItem.getChildren();
children.clear();
for (String tableName : tables) {
TreeItem<String> newTreeItem = new TreeItem<>();
ImageView imageView = new ImageView("icons/table.png");
imageView.setFitHeight(16);
imageView.setFitWidth(16);
newTreeItem.setGraphic(imageView);
newTreeItem.setValue(tableName);
children.add(newTreeItem);
}
} else if (StringUtils.isNotBlank(filter)) {
treeItem.getChildren().clear();
}
if (StringUtils.isNotBlank(filter)) {
ImageView imageView = new ImageView("icons/filter.png");
imageView.setFitHeight(16);
imageView.setFitWidth(16);
imageView.setUserData(treeItem.getGraphic().getUserData());
treeItem.setGraphic(imageView);
} else {
ImageView dbImage = new ImageView("icons/computer.png");
dbImage.setFitHeight(16);
dbImage.setFitWidth(16);
dbImage.setUserData(treeItem.getGraphic().getUserData());
treeItem.setGraphic(dbImage);
}
} catch (SQLRecoverableException e) {
_LOG.error(e.getMessage(), e);
AlertUtil.showErrorAlert("连接超时");
} catch (Exception e) {
_LOG.error(e.getMessage(), e);
AlertUtil.showErrorAlert(e.getMessage());
}
}
use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.
the class MainUIController method initialize.
@Override
public void initialize(URL location, ResourceBundle resources) {
ImageView dbImage = new ImageView("icons/computer.png");
dbImage.setFitHeight(40);
dbImage.setFitWidth(40);
connectionLabel.setGraphic(dbImage);
connectionLabel.setOnMouseClicked(event -> {
TabPaneController controller = (TabPaneController) loadFXMLPage("新建数据库连接", FXMLPage.NEW_CONNECTION, false);
controller.setMainUIController(this);
controller.showDialogStage();
});
ImageView configImage = new ImageView("icons/config-list.png");
configImage.setFitHeight(40);
configImage.setFitWidth(40);
configsLabel.setGraphic(configImage);
configsLabel.setOnMouseClicked(event -> {
GeneratorConfigController controller = (GeneratorConfigController) loadFXMLPage("配置", FXMLPage.GENERATOR_CONFIG, false);
controller.setMainUIController(this);
controller.showDialogStage();
});
useExample.setOnMouseClicked(event -> {
if (useExample.isSelected()) {
offsetLimitCheckBox.setDisable(false);
} else {
offsetLimitCheckBox.setDisable(true);
}
});
// selectedProperty().addListener 解决应用配置的时候未触发Clicked事件
useLombokPlugin.selectedProperty().addListener((observable, oldValue, newValue) -> {
needToStringHashcodeEquals.setDisable(newValue);
});
leftDBTree.setShowRoot(false);
leftDBTree.setRoot(new TreeItem<>());
Callback<TreeView<String>, TreeCell<String>> defaultCellFactory = TextFieldTreeCell.forTreeView();
filterTreeBox.addEventHandler(KeyEvent.KEY_PRESSED, ev -> {
if (ev.getCode() == KeyCode.ENTER) {
ObservableList<TreeItem<String>> schemas = leftDBTree.getRoot().getChildren();
schemas.filtered(TreeItem::isExpanded).forEach(this::displayTables);
ev.consume();
}
});
leftDBTree.setCellFactory((TreeView<String> tv) -> {
TreeCell<String> cell = defaultCellFactory.call(tv);
cell.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
int level = leftDBTree.getTreeItemLevel(cell.getTreeItem());
TreeCell<String> treeCell = (TreeCell<String>) event.getSource();
TreeItem<String> treeItem = treeCell.getTreeItem();
if (level == 1) {
final ContextMenu contextMenu = new ContextMenu();
MenuItem item1 = new MenuItem("关闭连接");
item1.setOnAction(event1 -> treeItem.getChildren().clear());
MenuItem item2 = new MenuItem("编辑连接");
item2.setOnAction(event1 -> {
DatabaseConfig selectedConfig = (DatabaseConfig) treeItem.getGraphic().getUserData();
TabPaneController controller = (TabPaneController) loadFXMLPage("编辑数据库连接", FXMLPage.NEW_CONNECTION, false);
controller.setMainUIController(this);
controller.setConfig(selectedConfig);
controller.showDialogStage();
});
MenuItem item3 = new MenuItem("删除连接");
item3.setOnAction(event1 -> {
DatabaseConfig selectedConfig = (DatabaseConfig) treeItem.getGraphic().getUserData();
try {
ConfigHelper.deleteDatabaseConfig(selectedConfig);
this.loadLeftDBTree();
} catch (Exception e) {
AlertUtil.showErrorAlert("Delete connection failed! Reason: " + e.getMessage());
}
});
contextMenu.getItems().addAll(item1, item2, item3);
cell.setContextMenu(contextMenu);
}
if (event.getClickCount() == 2) {
if (treeItem == null) {
return;
}
treeItem.setExpanded(true);
if (level == 1) {
displayTables(treeItem);
} else if (level == 2) {
// left DB tree level3
String tableName = treeCell.getTreeItem().getValue();
selectedDatabaseConfig = (DatabaseConfig) treeItem.getParent().getGraphic().getUserData();
this.tableName = tableName;
tableNameField.setText(tableName);
domainObjectNameField.setText(MyStringUtils.dbStringToCamelStyle(tableName));
mapperName.setText(domainObjectNameField.getText().concat("DAO"));
}
}
});
return cell;
});
loadLeftDBTree();
setTooltip();
// 默认选中第一个,否则如果忘记选择,没有对应错误提示
encodingChoice.getSelectionModel().selectFirst();
}
use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.
the class OverSshController method saveConfig.
public void saveConfig() {
DatabaseConfig databaseConfig = extractConfigFromUi();
if (StringUtils.isAnyEmpty(databaseConfig.getName(), databaseConfig.getHost(), databaseConfig.getPort(), databaseConfig.getUsername(), databaseConfig.getEncoding(), databaseConfig.getDbType(), databaseConfig.getSchema())) {
AlertUtil.showWarnAlert("密码以外其他字段必填");
return;
}
try {
ConfigHelper.saveDatabaseConfig(this.isUpdate, primayKey, databaseConfig);
this.tabPaneController.getDialogStage().close();
mainUIController.loadLeftDBTree();
} catch (Exception e) {
logger.error(e.getMessage(), e);
AlertUtil.showErrorAlert(e.getMessage());
}
}
use of com.zzg.mybatis.generator.model.DatabaseConfig in project mybatis-generator-gui by zouzg.
the class DbConnectionController method testConnection.
@FXML
void testConnection() {
DatabaseConfig config = extractConfigForUI();
if (config == null) {
return;
}
try {
DbUtil.getConnection(config);
AlertUtil.showInfoAlert("连接成功");
} catch (Exception e) {
_LOG.error(e.getMessage(), e);
AlertUtil.showWarnAlert("连接失败");
}
}
Aggregations