Search in sources :

Example 6 with ObjectProperty

use of javafx.beans.property.ObjectProperty in project jgnash by ccavanaugh.

the class FXMLUtils method injectParent.

/**
     * Injects a value into a field of initialized type {@code ObjectProperty}.  The field must also be annotated
     * with {@code javax.inject.Inject}
     *
     * @param object {@code Object} to search for field
     * @param value  value to set
     * @see javafx.beans.property.ObjectProperty
     * @see InjectFXML
     */
@SuppressWarnings("unchecked")
private static void injectParent(final Object object, final Object value) {
    for (final Field field : getDeclaredFields(object.getClass())) {
        if (field.isAnnotationPresent(InjectFXML.class) && field.getName().equals("parent")) {
            field.setAccessible(true);
            try {
                final ObjectProperty<Object> property = (ObjectProperty<Object>) field.get(object);
                property.set(value);
            } catch (IllegalAccessException e) {
                Logger.getLogger(FXMLUtils.class.getName()).log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) Field(java.lang.reflect.Field)

Example 7 with ObjectProperty

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

the class EditableTableView method getStatements.

private STATUS getStatements(DML dml, BiFunction<STATUS, List<String>, STATUS> function) {
    List<String> saveSqlList = new ArrayList<>();
    List<Map<ColumnExpression, ObjectProperty<ValueExpression>>> items = Collections.emptyList();
    switch(dml) {
        case UPDATE:
            items = getItems().stream().filter(m -> {
                return !ColumnExpression.isContainsNewRowMeata(m);
            }).collect(Collectors.toList());
            break;
        case DELETE:
            items = this.removedList;
            break;
        case INSERT:
            items = getItems().stream().filter(m -> {
                return ColumnExpression.isContainsNewRowMeata(m);
            }).collect(Collectors.toList());
            break;
        default:
            break;
    }
    if (items.isEmpty())
        return STATUS.OK;
    int modifiedCnt = 0;
    //키값이 존재하지않는 테이블인경우 where조건은 수정되지않는 컬럼으로 사용.
    boolean isNotContainsPrimaryTable = false;
    //키값도 존재하지않을뿐더러 변경된 컬럼도 없는경우
    boolean isNotContainsModifiedTable = false;
    if (items != null && !items.isEmpty()) {
        long count = items.get(0).values().stream().filter(vo -> vo.getValue().isPrimaryKey).count();
        //키값 존재유무에 따른 플래그 update
        if (count == 0)
            isNotContainsPrimaryTable = true;
        //키값이 없는 상태에서 수정된 컬럼도 없는 경우 상태 update
        if (count == 0) {
            long modifiedCount = items.get(0).values().stream().filter(vo -> vo.getValue().isModified).count();
            if (modifiedCount == 0)
                isNotContainsModifiedTable = true;
        }
    }
    for (Map<ColumnExpression, ObjectProperty<ValueExpression>> m : items) {
        StringBuffer whereStatement = new StringBuffer();
        StringBuffer setStatement = new StringBuffer();
        StringBuffer columnsStatement = new StringBuffer();
        StringBuffer valuesStatement = new StringBuffer();
        Iterator<ColumnExpression> iterator = m.keySet().iterator();
        modifiedCnt = 0;
        while (iterator.hasNext()) {
            ColumnExpression colummExp = iterator.next();
            if (colummExp.isNewRowMeta())
                continue;
            if (colummExp.isMetadata)
                continue;
            //				else {
            ObjectProperty<ValueExpression> value = m.get(colummExp);
            ValueExpression valueExp = value.get();
            if (valueExp.isPrimaryKey) {
                //기본키값이 빈 경우 메세지.
                if (valueExp.getDisplayText() == null) /*|| valueExp.getDisplayText().isEmpty()*/
                {
                    return function.apply(STATUS.PK_VAL_IS_EMPTY, Collections.emptyList());
                }
                whereStatement.append(String.format("and %s  = '%s'", colummExp, valueExp.getRealValue()));
            }
            if (valueExp.isModified) {
                setStatement.append(String.format("%s  = %s,", colummExp, getValue(colummExp, valueExp)));
                modifiedCnt++;
                if (isNotContainsPrimaryTable) {
                    whereStatement.append(String.format("and %s  = '%s'", colummExp, valueExp.getRealValue()));
                }
            }
            if ((!valueExp.isPrimaryKey && !valueExp.isModified) && (isNotContainsPrimaryTable || isNotContainsModifiedTable)) {
                whereStatement.append(String.format("and %s  = '%s'", colummExp, valueExp.getRealValue()));
            }
            columnsStatement.append(String.format("%s,", colummExp));
            valuesStatement.append(String.format("'%s',", valueExp.getDisplayText()));
        //				}
        }
        int setStatementLength = setStatement.length();
        if (setStatementLength != 0) {
            setStatement.setLength(setStatementLength - 1);
        }
        int columnsStatementLength = columnsStatement.length();
        if (columnsStatementLength != 0) {
            columnsStatement.setLength(columnsStatementLength - 1);
        }
        int valuesStatementLength = valuesStatement.length();
        if (valuesStatementLength != 0) {
            valuesStatement.setLength(valuesStatementLength - 1);
        }
        switch(dml) {
            case INSERT:
                saveSqlList.add(String.format("insert into %s (%s) values (%s)", this.tableName.get(), columnsStatement.toString(), valuesStatement.toString()));
                break;
            case UPDATE:
                if (modifiedCnt > 0) {
                    saveSqlList.add(String.format("update %s set %s where 1=1 %s", this.tableName.get(), setStatement.toString(), whereStatement.toString()));
                }
                break;
            case DELETE:
                saveSqlList.add(String.format("delete from %s where 1=1 %s", this.tableName.get(), whereStatement.toString()));
                break;
        }
    }
    return function.apply(STATUS.OK, saveSqlList);
}
Also used : Connection(java.sql.Connection) DbUtil(com.kyj.fx.voeditor.visual.util.DbUtil) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) SQLException(java.sql.SQLException) TableCell(javafx.scene.control.TableCell) ListChangeListener(javafx.collections.ListChangeListener) ResultSet(java.sql.ResultSet) Map(java.util.Map) LinkedList(java.util.LinkedList) Objects(com.google.common.base.Objects) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Strings(com.sun.btrace.BTraceUtils.Strings) ColumnExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ColumnExpression) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TablePosition(javafx.scene.control.TablePosition) StringConverter(javafx.util.StringConverter) Collectors(java.util.stream.Collectors) ValueExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ValueExpression) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) Consumer(java.util.function.Consumer) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ValueUtil(kyj.Fx.dao.wizard.core.util.ValueUtil) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) Collections(java.util.Collections) ResultSetMetaData(java.sql.ResultSetMetaData) ObjectProperty(javafx.beans.property.ObjectProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ArrayList(java.util.ArrayList) ColumnExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ColumnExpression) ValueExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ValueExpression) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with ObjectProperty

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

the class EditableTableView method readByTableName.

private void readByTableName(String sql, String tableName, boolean appendHist) throws Exception {
    LOGGER.debug(sql);
    getColumns().clear();
    getItems().clear();
    removedList.clear();
    columnMap.clear();
    try (Connection connection = connectionSupplier.get()) {
        List<String> pks = DbUtil.pks(connection, tableName);
        Map<String, Boolean> columnsToMap = DbUtil.columnsToMap(connection, tableName, rs -> {
            try {
                return rs.getString(4);
            } catch (Exception e) {
                return null;
            }
        }, rs -> {
            try {
                return Boolean.valueOf("YES".equals(rs.getString(18)));
            } catch (Exception e) {
                return false;
            }
        });
        LOGGER.debug("nullable columns ? {} ", columnsToMap);
        DbUtil.select(connection, sql, FETCH_COUNT, LIMIT_ROW_COUNT, new BiFunction<ResultSetMetaData, ResultSet, List<Map<String, Object>>>() {

            @Override
            public List<Map<String, Object>> apply(ResultSetMetaData t, ResultSet u) {
                try {
                    int columnCount = t.getColumnCount();
                    for (int i = 1; i <= columnCount; i++) {
                        String columnName = t.getColumnName(i);
                        ColumnExpression columnExp = new ColumnExpression(columnName);
                        columnExp.isPrimaryColumn = pks.contains(columnName);
                        columnExp.isNullableColumn = columnsToMap.containsKey(columnName) && (columnsToMap.get(columnName) == true);
                        columnExp.setColumnType(t.getColumnType(i));
                        TableColumn<Map<ColumnExpression, ObjectProperty<ValueExpression>>, ValueExpression> e = new TableColumn<>(columnName);
                        e.setUserData(columnExp);
                        e.setCellValueFactory(DynamicCallback.fromTableColumn(columnExp));
                        e.setCellFactory(DEFAULT_CELL_FACTORY);
                        e.setEditable(true);
                        columnMap.put(columnName, columnExp);
                        getColumns().add(e);
                    }
                    while (u.next()) {
                        Map<ColumnExpression, ObjectProperty<ValueExpression>> hashMap = new HashMap<>();
                        for (int i = 1; i <= columnCount; i++) {
                            String columnName = t.getColumnName(i);
                            //new ColumnExpression(columnName);
                            ColumnExpression columnExp = columnMap.get(columnName);
                            ValueExpression valueExp = new ValueExpression();
                            valueExp.displayText.set(u.getString(columnName));
                            valueExp.isPrimaryKey = pks.contains(columnName);
                            valueExp.realValue.set(u.getObject(columnName));
                            valueExp.setColumnExpression(columnExp);
                            hashMap.put(columnExp, new SimpleObjectProperty<>(valueExp));
                        }
                        getItems().removeListener(itemChangeListener);
                        getItems().add(hashMap);
                        getItems().addListener(itemChangeListener);
                    }
                } catch (SQLException e) {
                    LOGGER.error(ValueUtil.toString(e));
                }
                return null;
            }
        });
        if (appendHist) {
            if (history.size() >= HISTORY_LIMITED_SIZE) {
                history.removeFirst();
            }
            history.add(sql);
        }
        this.tableName.set(tableName);
    }
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) SQLException(java.sql.SQLException) Connection(java.sql.Connection) TableColumn(javafx.scene.control.TableColumn) SQLException(java.sql.SQLException) ResultSetMetaData(java.sql.ResultSetMetaData) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ColumnExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ColumnExpression) ValueExpression(com.kyj.fx.voeditor.visual.component.grid.EditableTableView.ValueExpression) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ObservableList(javafx.collections.ObservableList) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 9 with ObjectProperty

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

the class FxTableViewUtil method getDisplayText.

/**
	 * 테이블컬럼에서 화면에 보여주는 텍스트를 리턴한다.
	 * @작성자 : KYJ
	 * @작성일 : 2017. 3. 31. 
	 * @param tc
	 * @param row
	 * @return
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Object getDisplayText(TableColumn<?, ?> tc, int row) {
    Callback cellFactory = tc.getCellFactory();
    if (cellFactory != null) /*&& cellObservableValue != null*/
    {
        //			Object value = cellObservableValue.getValue();
        Object call = cellFactory.call(tc);
        if (call != null && call instanceof TableCell) {
            TableCell cell = (TableCell) call;
            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 = tc.getCellData(row);
                return converter.toString(cellData);
            }
        }
        return call;
    }
    return tc.getCellData(row);
}
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