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);
}
}
}
}
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);
}
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);
}
}
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);
}
Aggregations