Search in sources :

Example 1 with TableCell

use of javafx.scene.control.TableCell 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 TableCell

use of javafx.scene.control.TableCell 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 3 with TableCell

use of javafx.scene.control.TableCell 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)

Example 4 with TableCell

use of javafx.scene.control.TableCell in project jgnash by ccavanaugh.

the class ImportPageTwoController method buildTableView.

private void buildTableView() {
    final TableColumn<ImportTransaction, ImportState> stateColumn = new TableColumn<>();
    stateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getState()));
    stateColumn.setCellFactory(param -> {
        TableCell<ImportTransaction, ImportState> cell = new ImportStateTableCell();
        cell.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
            if (event.getClickCount() > 1) {
                final ImportTransaction t = tableView.getItems().get(((TableCell<?, ?>) event.getSource()).getTableRow().getIndex());
                if (t.getState() == ImportState.EQUAL) {
                    t.setState(ImportState.NOT_EQUAL);
                } else if (t.getState() == ImportState.NOT_EQUAL) {
                    t.setState(ImportState.EQUAL);
                } else if (t.getState() == ImportState.NEW) {
                    t.setState(ImportState.IGNORE);
                } else if (t.getState() == ImportState.IGNORE) {
                    t.setState(ImportState.NEW);
                }
                Platform.runLater(tableView::refresh);
            }
        });
        return cell;
    });
    tableView.getColumns().add(stateColumn);
    final TableColumn<ImportTransaction, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDatePosted()));
    dateColumn.setCellFactory(param -> new ShortDateTableCell<>());
    tableView.getColumns().add(dateColumn);
    final TableColumn<ImportTransaction, String> numberColumn = new TableColumn<>(resources.getString("Column.Num"));
    numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCheckNumber()));
    tableView.getColumns().add(numberColumn);
    final TableColumn<ImportTransaction, String> payeeColumn = new TableColumn<>(resources.getString("Column.Payee"));
    payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
    tableView.getColumns().add(payeeColumn);
    final TableColumn<ImportTransaction, String> memoColumn = new TableColumn<>(resources.getString("Column.Memo"));
    memoColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getMemo()));
    tableView.getColumns().add(memoColumn);
    final TableColumn<ImportTransaction, Account> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
    accountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getAccount());
        }
        return null;
    });
    accountColumn.setCellFactory(param -> new AccountComboBoxTableCell<>());
    accountColumn.setEditable(true);
    accountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setAccount(event.getNewValue());
        lastAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(accountColumn);
    incomeAccountColumn = new TableColumn<>(resources.getString("Column.Income"));
    incomeAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getGainsAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getGainsAccount());
        }
        return null;
    });
    incomeAccountColumn.setCellFactory(param -> new IncomeAccountComboBoxTableCell<>());
    incomeAccountColumn.setEditable(true);
    incomeAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setGainsAccount(event.getNewValue());
        lastGainsAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(incomeAccountColumn);
    expenseAccountColumn = new TableColumn<>(resources.getString("Column.Expense"));
    expenseAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getFeesAccount() != null) {
            if (param.getValue().getFees().compareTo(BigDecimal.ZERO) != 0) {
                return new SimpleObjectProperty<>(param.getValue().getFeesAccount());
            } else {
                return new SimpleObjectProperty<>(NOP_EXPENSE_ACCOUNT);
            }
        }
        return null;
    });
    expenseAccountColumn.setCellFactory(param -> new ExpenseAccountComboBoxTableCell<>());
    expenseAccountColumn.setEditable(true);
    expenseAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setFeesAccount(event.getNewValue());
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(expenseAccountColumn);
    final TableColumn<ImportTransaction, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getAmount()));
    amountColumn.setCellFactory(param -> new BigDecimalTableCell<>(numberFormat));
    amountColumn.setCellFactory(param -> {
        final TableCell<ImportTransaction, BigDecimal> cell = new BigDecimalTableCell<>(numberFormat);
        cell.indexProperty().addListener((observable, oldValue, newValue) -> {
            final int index = newValue.intValue();
            if (index >= 0 && index < tableView.itemsProperty().get().size()) {
                cell.setTooltip(new Tooltip(tableView.itemsProperty().get().get(index).getToolTip()));
            }
        });
        return cell;
    });
    tableView.getColumns().add(amountColumn);
    typeColumn = new TableColumn<>(resources.getString("Column.Type"));
    typeColumn.setCellValueFactory(param -> {
        TransactionType transactionType = TransactionType.SINGLENTRY;
        if (param.getValue().isInvestmentTransaction()) {
            transactionType = param.getValue().getTransactionType();
        } else if (!param.getValue().getAccount().equals(baseAccount)) {
            transactionType = TransactionType.DOUBLEENTRY;
        }
        return new SimpleStringProperty(transactionType.toString());
    });
    tableView.getColumns().add(typeColumn);
}
Also used : Account(jgnash.engine.Account) TransactionType(jgnash.engine.TransactionType) ImportState(jgnash.convert.imports.ImportState) LocalDate(java.time.LocalDate) ImportTransaction(jgnash.convert.imports.ImportTransaction) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) TableCell(javafx.scene.control.TableCell) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) Tooltip(javafx.scene.control.Tooltip) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty)

Example 5 with TableCell

use of javafx.scene.control.TableCell in project trex-stateless-gui by cisco-system-traffic-generator.

the class CheckBoxTableViewCell method call.

/**
     *
     * @param p
     * @return
     */
@Override
public TableCell call(TableColumn p) {
    return new TableCell<Object, Boolean>() {

        private final CheckBox checkBox;

        {
            checkBox = new CheckBox();
            checkBox.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (checkboxChangeHandler != null) {
                    checkboxChangeHandler.stateChanged(getTableRow().getIndex(), newValue);
                }
            });
            this.setGraphic(checkBox);
            this.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            this.setEditable(true);
        }

        @Override
        public void updateItem(Boolean item, boolean empty) {
            super.updateItem(item, empty);
            if (!empty) {
                checkBox.setSelected(item);
                setGraphic(checkBox);
            } else {
                this.setGraphic(null);
            }
        }
    };
}
Also used : TableCell(javafx.scene.control.TableCell) CheckBox(javafx.scene.control.CheckBox) ObservableValue(javafx.beans.value.ObservableValue)

Aggregations

TableCell (javafx.scene.control.TableCell)10 TableColumn (javafx.scene.control.TableColumn)5 Callback (javafx.util.Callback)5 ObjectProperty (javafx.beans.property.ObjectProperty)4 ObservableValue (javafx.beans.value.ObservableValue)4 Method (java.lang.reflect.Method)3 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)3 ComboBoxTableCell (javafx.scene.control.cell.ComboBoxTableCell)3 BigDecimal (java.math.BigDecimal)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 FXML (javafx.fxml.FXML)2 CellDataFeatures (javafx.scene.control.TableColumn.CellDataFeatures)2