Search in sources :

Example 1 with EditableTableView

use of com.kyj.fx.voeditor.visual.component.grid.EditableTableView in project Gargoyle by callakrsos.

the class EditableTableViewExam method start.

@Override
public void start(Stage primaryStage) throws Exception {
    Button btnExec = new Button("Exec.");
    Button btnAdd = new Button("Add ");
    Button btnRemove = new Button("Remove");
    Button btnSave = new Button("Save");
    btnAdd.setDisable(true);
    TextField textField = new TextField();
    HBox hBox = new HBox(5, textField, btnExec, btnAdd, btnRemove, btnSave);
    EditableTableView editableTableView = new EditableTableView(new Supplier<Connection>() {

        @Override
        public Connection get() {
            try {
                return DbUtil.getConnection();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });
    editableTableView.tableNameProperty().addListener((oba, oldval, newval) -> {
        btnAdd.setDisable(false);
    });
    //  editableTableView.execute("tbm_sm_realtime_search");
    btnExec.setOnAction(e -> {
        String tableName = textField.getText();
        try {
            editableTableView.readByTableName("select * from " + tableName, tableName);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    });
    btnAdd.setOnAction(ev -> {
        editableTableView.getItems().add(new HashMap<>());
        editableTableView.getSelectionModel().selectLast();
        editableTableView.scrollTo(editableTableView.getItems().size() - 1);
    });
    btnRemove.setOnAction(ev -> {
        editableTableView.getItems().removeAll(editableTableView.getSelectionModel().getSelectedItems());
    });
    btnSave.setOnAction(ev -> {
        try {
            editableTableView.save();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    });
    editableTableView.setOnMouseClicked(ev -> {
        Map<ColumnExpression, ObjectProperty<ValueExpression>> selectedItem = editableTableView.getSelectionModel().getSelectedItem();
        System.out.println(selectedItem);
    });
    BorderPane root = new BorderPane(editableTableView);
    root.setTop(hBox);
    Scene value = new Scene(root);
    //  ".table-row{ -fx-background-color: red; }"
    //  value.getStylesheets().add(EditableTableViewExam.class.getResource("EditableTableViewExam.css").toExternalForm());
    primaryStage.setScene(value);
    primaryStage.show();
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) HBox(javafx.scene.layout.HBox) BorderPane(javafx.scene.layout.BorderPane) EditableTableView(com.kyj.fx.voeditor.visual.component.grid.EditableTableView) Connection(java.sql.Connection) Scene(javafx.scene.Scene) Button(javafx.scene.control.Button) ColumnExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ColumnExpression) TextField(javafx.scene.control.TextField)

Aggregations

EditableTableView (com.kyj.fx.voeditor.visual.component.grid.EditableTableView)1 ColumnExpression (com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ColumnExpression)1 Connection (java.sql.Connection)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 Scene (javafx.scene.Scene)1 Button (javafx.scene.control.Button)1 TextField (javafx.scene.control.TextField)1 BorderPane (javafx.scene.layout.BorderPane)1 HBox (javafx.scene.layout.HBox)1