Search in sources :

Example 1 with ObjectProperty

use of javafx.beans.property.ObjectProperty in project Gargoyle by callakrsos.

the class IExcelScreenHandler method valueMapper.

/**
	 * 테이블컬럼의 row에 해당하는 데이터가 무엇인지 정의한 값에 따라 엑셀에 표현됨.
	 * 
	 * StringConverter를 이용한 TableCell인경우 정의된 StringConvert를 이용한 데이터를 Excel의
	 * Cell에 쓰고, StringConverter를 이용하지않는 UI의 TableCell의 경우 데이터셋에 바인드된 값을 사용하게됨.
	 * 
	 * 작성된 API내에서 적절한 값이 아니라고 판단되는경우 Ovrride해서 재정의하도록한다.
	 * 
	 * @작성자 : KYJ
	 * @작성일 : 2016. 9. 9.
	 * @param table
	 *            사용자 화면에 정의된 tableView
	 * @param column
	 *            사용자 화면에 정의된 tableColumn
	 * @param columnIndex
	 *            사용자 화면에 정의된 tableColumn의 인덱스
	 * @param rowIndex
	 *            사용자 화면에 정의된 tableCell의 인덱스
	 * @return Object 테이블셀에 정의된 데이터를 리턴할 값으로, 리턴해주는 값이 엑셀에 write된다.
	 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public default default <T> Object valueMapper(TableView<?> table, TableColumn<?, ?> column, int columnIndex, int rowIndex) {
    Callback cellFactory = column.getCellFactory();
    if (cellFactory != null) {
        TableCell cell = (TableCell) cellFactory.call(column);
        if (cell != null) {
            StringConverter converter = null;
            if (cell instanceof TextFieldTableCell) {
                TextFieldTableCell txtCell = (TextFieldTableCell) cell;
                converter = txtCell.getConverter();
            } else //				} 
            if (cell instanceof ComboBoxTableCell) {
                ComboBoxTableCell txtCell = (ComboBoxTableCell) cell;
                converter = txtCell.getConverter();
            } else //				else if (cell instanceof HyperlinkTableCell) {
            //					HyperlinkTableCell txtCell = (HyperlinkTableCell) cell;
            //					converter = txtCell.getConverter();
            //				}
            /* else 기본값. */
            {
                try {
                    Method m = cell.getClass().getMethod("converterProperty");
                    if (m != null) {
                        Object object = m.invoke(cell);
                        if (object != null && object instanceof ObjectProperty) {
                            ObjectProperty<StringConverter> convert = (ObjectProperty<StringConverter>) object;
                            converter = convert.get();
                        }
                    }
                } catch (Exception e) {
                // Nothing...
                }
            }
            if (converter != null) {
                Object cellData = column.getCellData(rowIndex);
                return converter.toString(cellData);
            }
        }
    }
    return column.getCellData(rowIndex);
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) Callback(javafx.util.Callback) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) TableCell(javafx.scene.control.TableCell) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Method(java.lang.reflect.Method) StringConverter(javafx.util.StringConverter) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell)

Example 2 with ObjectProperty

use of javafx.beans.property.ObjectProperty in project Gargoyle by callakrsos.

the class CrudBaseGridView method saveBtnClickHandler.

/**
	 * 저장버튼 클릭 핸들러
	 *
	 * @param saveClickCallbackProperty2
	 *
	 * @Date 2015. 10. 10.
	 * @return
	 * @User KYJ
	 */
private EventHandler<MouseEvent> saveBtnClickHandler(ObjectProperty<Consumer<List<T>>> saveClickCallbackProperty) {
    return new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            try {
                Consumer<List<T>> callback = saveClickCallbackProperty.get();
                if (callback == null) {
                    errorMsgCallback.accept("saveClickCallback 함수에 에러메세지 콜백을 등록하세요.");
                    return;
                }
                gridview.fireEvent(event);
                List<T> items = getItems();
                //필수값 검증로직 추가. 2016.12.08
                AbstractVoNullChecker<T> nullCheckHandler = new DefaultVoNullChecker<>(CrudBaseGridView.this);
                nullCheckHandler.setList(items);
                Optional<Field> findFirst = nullCheckHandler.findFirst();
                boolean present = findFirst.isPresent();
                if (present) {
                    String msgFieldName = nullCheckHandler.getMsgNameByfield();
                    //						String message = ValueUtil.getMessage("MSG_W_000001", msgFieldName);
                    int emptyIndex = nullCheckHandler.getEmptyIndex();
                    Set<Node> findAllByNodes = CrudBaseGridView.this.lookupAll("TableRow");
                    findAllByNodes.stream().map(n -> (TableRow) n).filter(r -> {
                        return emptyIndex == r.getIndex();
                    }).findFirst().ifPresent(n -> {
                        Timeline timeline = new Timeline();
                        timeline.setCycleCount(10);
                        timeline.setAutoReverse(true);
                        KeyFrame keyFrame = new KeyFrame(Duration.millis(500), new KeyValue(n.styleProperty(), "-fx-border-color : red ; -fx-border-width : 1px"));
                        KeyFrame keyFrame2 = new KeyFrame(Duration.millis(500), new KeyValue(n.styleProperty(), ""));
                        KeyValue keyValueX = new KeyValue(n.styleProperty(), "-fx-border-color : red ; -fx-border-width : 1px");
                        KeyValue keyValueY = new KeyValue(n.styleProperty(), "");
                        KeyFrame keyFrame3 = new KeyFrame(Duration.seconds(2), "", keyValueX, keyValueY);
                        timeline.getKeyFrames().add(keyFrame3);
                        timeline.play();
                    });
                    getSelectionModel().select(emptyIndex);
                    //						DialogUtil.showMessageDialog(SharedMemory.getPrimaryStage(), msgFieldName + " Field is empty.");
                    return;
                }
                List<T> arrayList = new ArrayList<T>(items);
                arrayList.addAll(deleteItems);
                callback.accept(arrayList);
                // 사용자 정의 로직이 이상없으면 deleteItems 항목도 비운다.
                deleteItems.clear();
            } catch (Exception e) {
                throw e;
            }
        }
    };
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) MouseEvent(javafx.scene.input.MouseEvent) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Insets(javafx.geometry.Insets) KeyValue(javafx.animation.KeyValue) HBox(javafx.scene.layout.HBox) KeyFrame(javafx.animation.KeyFrame) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Node(javafx.scene.Node) TableRow(javafx.scene.control.TableRow) Set(java.util.Set) Timeline(javafx.animation.Timeline) Field(java.lang.reflect.Field) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) ActionEvent(javafx.event.ActionEvent) Duration(javafx.util.Duration) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) MouseEvent(javafx.scene.input.MouseEvent) KeyValue(javafx.animation.KeyValue) Node(javafx.scene.Node) ArrayList(java.util.ArrayList) EventHandler(javafx.event.EventHandler) Field(java.lang.reflect.Field) Timeline(javafx.animation.Timeline) TableRow(javafx.scene.control.TableRow) KeyFrame(javafx.animation.KeyFrame) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList)

Example 3 with ObjectProperty

use of javafx.beans.property.ObjectProperty in project Gargoyle by callakrsos.

the class MacroBaseSkin method start.

/**
	 * Start 버튼을 클릭하면 결과가 리턴된다. param으로 입력받은 데이터는 textArea에서 적혀져있는 텍스트문자열.
	 *
	 * 2016-10-25 Skin클래스안으로 이동처리.
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2016. 10. 25.
	 * @param tbResult
	 * @param param
	 * @throws Exception
	 */
public void start(TableView<Map<String, String>> tbResult, String param) throws Exception {
    Connection connection = getSkinnable().getConnectionSupplier().get();
    tbResult.getItems().clear();
    tbResult.getColumns().clear();
    //		try {
    String[] split = param.split(";");
    connection.setAutoCommit(false);
    try {
        for (String sql : split) {
            String _sql = sql.trim();
            if (_sql.isEmpty())
                continue;
            boolean dml = DbUtil.isDml(_sql);
            if (dml) {
                LOGGER.debug("do update : {}", _sql);
                DbUtil.update(connection, _sql);
            } else {
                LOGGER.debug("do select : {}", _sql);
                DbUtil.select(connection, _sql, 30, 1000, new BiFunction<ResultSetMetaData, ResultSet, List<Map<String, ObjectProperty<Object>>>>() {

                    @Override
                    public List<Map<String, ObjectProperty<Object>>> apply(ResultSetMetaData t, ResultSet rs) {
                        try {
                            int columnCount = t.getColumnCount();
                            for (int i = 1; i <= columnCount; i++) {
                                String columnName = t.getColumnName(i);
                                TableColumn<Map<String, String>, String> tbCol = new TableColumn<>(columnName);
                                tbCol.setCellFactory(new Callback<TableColumn<Map<String, String>, String>, TableCell<Map<String, String>, String>>() {

                                    @Override
                                    public TableCell<Map<String, String>, String> call(TableColumn<Map<String, String>, String> param) {
                                        return new TableCell<Map<String, String>, String>() {

                                            @Override
                                            protected void updateItem(String item, boolean empty) {
                                                super.updateItem(item, empty);
                                                if (empty) {
                                                    setGraphic(null);
                                                } else {
                                                    setGraphic(new Label(item));
                                                }
                                            }
                                        };
                                    }
                                });
                                tbCol.setCellValueFactory(param -> {
                                    return new SimpleStringProperty(param.getValue().get(columnName));
                                });
                                tbResult.getColumns().add(tbCol);
                            }
                            while (rs.next()) {
                                Map<String, String> hashMap = new HashMap<>();
                                for (int i = 1; i <= columnCount; i++) {
                                    String columnName = t.getColumnName(i);
                                    String value = rs.getString(columnName);
                                    hashMap.put(columnName, value);
                                }
                                tbResult.getItems().add(hashMap);
                            }
                        } catch (SQLException e) {
                            throw new RuntimeException(e);
                        }
                        return Collections.emptyList();
                    }
                });
            }
        }
        connection.commit();
    } catch (Exception e) {
        connection.rollback();
        throw new RuntimeException(e);
    } finally {
        DbUtil.close(connection);
    }
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) Connection(java.sql.Connection) DbUtil(com.kyj.fx.voeditor.visual.util.DbUtil) TextArea(javafx.scene.control.TextArea) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) BlendMode(javafx.scene.effect.BlendMode) SQLException(java.sql.SQLException) TableCell(javafx.scene.control.TableCell) KeyBinding(com.sun.javafx.scene.control.behavior.KeyBinding) Insets(javafx.geometry.Insets) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) Map(java.util.Map) BehaviorSkinBase(com.sun.javafx.scene.control.skin.BehaviorSkinBase) BehaviorBase(com.sun.javafx.scene.control.behavior.BehaviorBase) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Orientation(javafx.geometry.Orientation) KeyCode(javafx.scene.input.KeyCode) HBox(javafx.scene.layout.HBox) NumberTextField(com.kyj.fx.voeditor.visual.component.NumberTextField) ObjectProperty(javafx.beans.property.ObjectProperty) SplitPane(javafx.scene.control.SplitPane) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) Consumer(java.util.function.Consumer) Platform(javafx.application.Platform) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) ActionEvent(javafx.event.ActionEvent) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SelectionMode(javafx.scene.control.SelectionMode) ValueUtil(kyj.Fx.dao.wizard.core.util.ValueUtil) BorderPane(javafx.scene.layout.BorderPane) Collections(java.util.Collections) ResultSetMetaData(java.sql.ResultSetMetaData) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Label(javafx.scene.control.Label) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) SQLException(java.sql.SQLException) ResultSetMetaData(java.sql.ResultSetMetaData) Callback(javafx.util.Callback) TableCell(javafx.scene.control.TableCell) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ObjectProperty

use of javafx.beans.property.ObjectProperty 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)

Example 5 with ObjectProperty

use of javafx.beans.property.ObjectProperty in project Gargoyle by callakrsos.

the class FxTableViewUtil method getValue.

/**
	 * 테이블컬럼의 row에 해당하는 데이터가 무엇인지 정의한 값을 리턴.
	 *
	 * StringConverter를 이용한 TableCell인경우 정의된 StringConvert를 이용한 데이터를 Excel의
	 * Cell에 쓰고, StringConverter를 이용하지않는 UI의 TableCell의 경우 데이터셋에 바인드된 값을 사용하게됨.
	 *
	 * 작성된 API내에서 적절한 값이 아니라고 판단되는경우 Ovrride해서 재정의하도록한다.
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2016. 9. 9.
	 * @param table
	 *            사용자 화면에 정의된 tableView
	 * @param column
	 *            사용자 화면에 정의된 tableColumn
	 * @param columnIndex
	 *            사용자 화면에 정의된 tableColumn의 인덱스
	 * @param rowIndex
	 *            사용자 화면에 정의된 tableCell의 인덱스
	 * @return Object 테이블셀에 정의된 데이터를 리턴할 값으로, 리턴해주는 값이 엑셀에 write된다.
	 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Object getValue(TableView<?> table, TableColumn<?, ?> column, int rowIndex) {
    Callback cellFactory = column.getCellFactory();
    if (cellFactory != null) {
        TableCell cell = (TableCell) cellFactory.call(column);
        if (cell != null) {
            StringConverter converter = null;
            if (cell instanceof TextFieldTableCell) {
                TextFieldTableCell txtCell = (TextFieldTableCell) cell;
                converter = txtCell.getConverter();
            } else if (cell instanceof ComboBoxTableCell) {
                ComboBoxTableCell txtCell = (ComboBoxTableCell) cell;
                converter = txtCell.getConverter();
            } else /* else 기본값. */
            {
                try {
                    Method m = cell.getClass().getMethod("converterProperty");
                    if (m != null) {
                        Object object = m.invoke(cell);
                        if (object != null && object instanceof ObjectProperty) {
                            ObjectProperty<StringConverter> convert = (ObjectProperty<StringConverter>) object;
                            converter = convert.get();
                        }
                    }
                } catch (Exception e) {
                // Nothing...
                }
            }
            if (converter != null) {
                Object cellData = column.getCellData(rowIndex);
                return converter.toString(cellData);
            }
        }
    }
    return column.getCellData(rowIndex);
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) Callback(javafx.util.Callback) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) TableCell(javafx.scene.control.TableCell) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Method(java.lang.reflect.Method) StringConverter(javafx.util.StringConverter) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell)

Aggregations

ObjectProperty (javafx.beans.property.ObjectProperty)9 TableCell (javafx.scene.control.TableCell)5 Callback (javafx.util.Callback)5 Connection (java.sql.Connection)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 TableColumn (javafx.scene.control.TableColumn)4 TextFieldTableCell (javafx.scene.control.cell.TextFieldTableCell)4 StringConverter (javafx.util.StringConverter)4 ColumnExpression (com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ColumnExpression)3 Method (java.lang.reflect.Method)3 ResultSet (java.sql.ResultSet)3 ResultSetMetaData (java.sql.ResultSetMetaData)3 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Consumer (java.util.function.Consumer)3 Button (javafx.scene.control.Button)3 ComboBoxTableCell (javafx.scene.control.cell.ComboBoxTableCell)3 BorderPane (javafx.scene.layout.BorderPane)3