You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
5.7 KiB

6 years ago
package xyz.wbsite.dbtool.javafx.ctrl;
import javafx.event.ActionEvent;
6 years ago
import javafx.event.Event;
import javafx.event.EventHandler;
6 years ago
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TableView;
import javafx.scene.control.TreeView;
import javafx.scene.layout.Pane;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
6 years ago
import javafx.stage.Stage;
import xyz.wbsite.dbtool.javafx.JavaFxApplication;
6 years ago
import xyz.wbsite.dbtool.javafx.enums.DataBase;
6 years ago
import xyz.wbsite.dbtool.javafx.listener.GenerateOptionListener;
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
import xyz.wbsite.dbtool.javafx.tool.Dialog;
import java.io.File;
public class MainController {
private ProjectManager dBmanger = ManagerFactory.getdBManager();
@FXML
private TreeView dbtree;
@FXML
private Pane detail;
@FXML
private TableView feilds;
@FXML
private Button add;
@FXML
private Button sub;
@FXML
private CheckBox addSysFields;
private JavaFxApplication main;
public ProjectManager getdBmanger() {
return dBmanger;
}
public void setdBmanger(ProjectManager dBmanger) {
this.dBmanger = dBmanger;
}
public JavaFxApplication getMain() {
return main;
}
public void setMain(JavaFxApplication main) {
this.main = main;
}
public Button getAdd() {
return add;
}
public void setAdd(Button add) {
this.add = add;
}
public Button getSub() {
return sub;
}
public CheckBox getAddSysFields() {
return addSysFields;
}
public void setAddSysFields(CheckBox addSysFields) {
this.addSysFields = addSysFields;
}
public void setSub(Button sub) {
this.sub = sub;
}
public TableView getFeilds() {
return feilds;
}
public void setFeilds(TableView feilds) {
this.feilds = feilds;
}
public TreeView getDbtree() {
return dbtree;
}
public void setDbtree(TreeView dbtree) {
this.dbtree = dbtree;
}
public Pane getDetail() {
return detail;
}
public void setDetail(Pane detail) {
this.detail = detail;
}
@FXML
public void modelOpen(ActionEvent actionEvent) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("选择模型文件");
fileChooser.setInitialDirectory(dBmanger.getPath());
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("模型文件", "*.xml", "*.XML"));
6 years ago
Stage stage = new Stage();
File file = fileChooser.showOpenDialog(stage);
6 years ago
if (file != null && file.exists()) {
dBmanger.invalidate(file);//初始化模型树 - 到内容
main.loadingProjectTree();//加载模型树 - 到组件
main.loadingProject();
6 years ago
}
}
@FXML
public void modelSave(ActionEvent actionEvent) {
6 years ago
if (dBmanger.getPath() == null || "".equals(dBmanger.getPath())) {
DirectoryChooser directoryChooser = new DirectoryChooser();
Stage stage = new Stage();
File file = directoryChooser.showDialog(stage);
if (file == null) {
System.err.println("请选择目录!");
} else {
dBmanger.setPath(file);
System.out.println(file.getAbsolutePath());
6 years ago
}
}
dBmanger.save();
}
@FXML
public void modelSaveAs(ActionEvent actionEvent) {
6 years ago
DirectoryChooser directoryChooser = new DirectoryChooser();
Stage stage = new Stage();
File file = directoryChooser.showDialog(stage);
if (file != null) {
dBmanger.save(file);
6 years ago
}
}
@FXML
public void modelCreate(ActionEvent actionEvent) {
dBmanger.modelCreate();
main.loadingProjectTree();
main.loadingProject();
}
@FXML
public void modelDelete(ActionEvent actionEvent) {
Dialog.showConfirmDialog("确认删除当前模型?", new EventHandler() {
6 years ago
@Override
public void handle(Event event) {
dBmanger.delete();
dBmanger.invalidate();
6 years ago
main.loadingProjectTree();
main.loadingProject();
}
});
6 years ago
}
@FXML
public void modelImport(ActionEvent actionEvent) {
6 years ago
Dialog.showDBConnectInput();
}
@FXML
public void modelGenerate(ActionEvent actionEvent) {
this.modelSave(null);
6 years ago
if (dBmanger.doCheck()) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setInitialDirectory(dBmanger.getPath());
6 years ago
Stage stage = new Stage();
File file = directoryChooser.showDialog(stage);
if (file != null) {
//展示生成方式
Dialog.showGenerateOption(new GenerateOptionListener() {
@Override
public void onGenerate(String option, DataBase dataBase) {
System.out.println("生成目录:" + file.getAbsolutePath());
dBmanger.generate(file.getAbsolutePath(), option, dataBase);
}
});
}
}
}
6 years ago
@FXML
public void generateVue(ActionEvent actionEvent) {
Dialog.showVue();
}
6 years ago
@FXML
public void generateApi(ActionEvent actionEvent) {
Dialog.showApi();
}
6 years ago
@FXML
public void generateAndroid(ActionEvent actionEvent) {
Dialog.showAndroid();
}
6 years ago
@FXML
public void generateSBMDB(ActionEvent actionEvent) {
Dialog.showSBMDB();
}
6 years ago
}

Powered by TurnKey Linux.