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.

212 lines
5.4 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.Stage;
import xyz.wbsite.dbtool.javafx.JavaFxApplication;
import xyz.wbsite.dbtool.javafx.enumeration.DataBase;
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.po.Project;
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 showFileChooser(ActionEvent actionEvent) {
DirectoryChooser directoryChooser = new DirectoryChooser();
Stage stage = new Stage();
File file = directoryChooser.showDialog(stage);
if (file != null && file.exists()) {
dBmanger.setPath(file.getAbsolutePath());
dBmanger.invalidate();
main.loadingProjectTree();
System.out.println(file.getAbsolutePath());
}
}
public boolean doSave(ActionEvent actionEvent) {
if (dBmanger.getPath() == null || "".equals(dBmanger.getPath())) {
DirectoryChooser directoryChooser = new DirectoryChooser();
Stage stage = new Stage();
File file = directoryChooser.showDialog(stage);
if (file == null) {
return false;
}
dBmanger.setPath(file.getAbsolutePath());
System.out.println(file.getAbsolutePath());
}
dBmanger.save();
System.out.println("自动保存成功");
return true;
}
@FXML
public void save(ActionEvent actionEvent) {
doSave(actionEvent);
}
@FXML
public void saveAs(ActionEvent actionEvent) {
DirectoryChooser directoryChooser = new DirectoryChooser();
Stage stage = new Stage();
File file = directoryChooser.showDialog(stage);
if (file != null) {
dBmanger.setPath(file.getAbsolutePath());
dBmanger.save();
}
}
@FXML
public void clear(ActionEvent actionEvent) {
6 years ago
Dialog.showConfirmDialog("确认清空所有信息?", new EventHandler() {
@Override
public void handle(Event event) {
dBmanger.clear();
main.loadingProjectTree();
main.loadingProject();
}
});
6 years ago
}
@FXML
public void showConnectInfo(ActionEvent actionEvent) {
Dialog.showDBConnectInput();
}
@FXML
public void generate(ActionEvent actionEvent) {
if (!this.doSave(null)) {
return;
}
if (dBmanger.doCheck()) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setInitialDirectory(new File(dBmanger.getPath()));
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
}

Powered by TurnKey Linux.