use of javafx.beans.property.SimpleObjectProperty 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.SimpleObjectProperty in project Gargoyle by callakrsos.
the class DatabaseUrlManagementView method initialize.
@SuppressWarnings({ "rawtypes", "unchecked" })
@FXML
public void initialize() {
// /tbDatabase.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
colKey.setCellValueFactory(param -> {
Object object = param.getValue().get("seqNum");
return new SimpleObjectProperty<>(object);
});
String property = ResourceLoader.getInstance().get(ResourceLoader.DBMS_SUPPORT);
// 사용되지않은 코드
// String colOrder =
// ResourceLoader.getInstance().get(ResourceLoader.DATABASE_COLUMN_ORDER);
// 2015.11.30 데이터에 []코드를 삭제하면서 아래 코드존재가 불필요해서 주석
// 오류가 발생하여 임시 처리.
// if (colOrder != null) {
// colOrder = colOrder.replace("[", "");
// colOrder = colOrder.replace("]", "");
// }
List<Code> dbms = Stream.of(StringUtils.tokenizeToStringArray(property, ",")).map(t -> new Code(t, t)).collect(Collectors.toList());
colDbms = new ComboBoxTableColumn<>("dbms", FXCollections.observableArrayList(dbms), "code", "codeNm");
tbDatabase.getColumns().add(1, colDbms);
tbDatabase.getColumns().get(1).setText("DBMS");
tbDatabase.getColumns().get(1).setId("colDbms");
colColor = new ColorPickerTableColumn<Map<String, Object>>(colColor, "color");
colColor.setMaxWidth(50);
tbDatabase.getColumns().add(1, colColor);
tbDatabase.getColumns().get(1).setText("Color");
tbDatabase.getColumns().get(1).setId("colColor");
/*********************************************************/
// 파일 DagDrop 이벤트. URL에 새 데이터 add.
tbDatabase.setOnDragDropped(ev -> {
if (ev.getDragboard().hasFiles()) {
List<File> files = ev.getDragboard().getFiles();
files.stream().map(v -> {
return v.getAbsolutePath();
}).forEach(str -> {
Map<String, Object> map = new HashMap<String, Object>();
map.put(ResourceLoader.BASE_KEY_JDBC_URL, str);
tbDatabase.getItems().add(map);
});
ev.setDropCompleted(true);
ev.consume();
}
});
tbDatabase.setOnDragOver(ev -> {
if (ev.getDragboard().hasFiles()) {
ev.acceptTransferModes(TransferMode.LINK);
ev.consume();
}
});
/*********************************************************/
colPopup = new ButtonTableColumn() {
@Override
public void clickHandle(int nRow) {
try {
showSqlPane(nRow);
} catch (Exception e) {
DialogUtil.showExceptionDailog(e);
LOGGER.error(ValueUtil.toString(e));
}
}
};
colPing = new ButtonTableColumn("Ping") {
@Override
public void clickHandle(int nRow) {
try {
ping(nRow);
} catch (Exception e) {
DialogUtil.showExceptionDailog(e);
LOGGER.error(ValueUtil.toString(e));
}
}
};
colPopup.setMaxWidth(50);
tbDatabase.getColumns().add(1, colPopup);
tbDatabase.getColumns().get(1).setText("Popup");
tbDatabase.getColumns().get(1).setId("colPopup");
tbDatabase.getColumns().add(colPing);
setColumnText(colAlias, "alias");
colUrl.setPrefWidth(300);
setColumnText(colUrl, ResourceLoader.BASE_KEY_JDBC_URL);
setColumnText(colUserName, ResourceLoader.BASE_KEY_JDBC_ID);
setColumnText(colUserPassword, ResourceLoader.BASE_KEY_JDBC_PASS, param -> new PasswordTextFieldTableCell());
// colUserPassword.setCellValueFactory(param -> {
// Object initialValue =
// param.getValue().get(ResourceLoader.BASE_KEY_JDBC_PASS);
// SimpleObjectProperty<Object> simpleObjectProperty = new
// SimpleObjectProperty<>(initialValue);
// simpleObjectProperty.addListener((oba, oldval, newval) ->
// param.getValue().put(ResourceLoader.BASE_KEY_JDBC_PASS, newval));
// return simpleObjectProperty;
// });
// colUserPassword.setCellFactory(param -> new
// PasswordTextFieldTableCell());
observableArrayList = loadResource();
tbDatabase.getItems().addAll(observableArrayList);
}
use of javafx.beans.property.SimpleObjectProperty in project Gargoyle by callakrsos.
the class DialogUtil method showInputDialog.
public static Optional<Pair<String, String>> showInputDialog(Window owner, String title, String message, String inputValue, Predicate<String> satisfied) {
BaseDialogComposite composite = new BaseDialogComposite(title, message);
Button btnOk = new Button("OK");
btnOk.setMinWidth(80d);
Button btnCancel = new Button("Cancel");
btnCancel.setMinWidth(80d);
composite.addButton(btnOk);
composite.addButton(btnCancel);
TextField text = new TextField();
composite.setGraphic(text);
Optional<Pair<String, String>> empty = Optional.empty();
SimpleObjectProperty<Optional<Pair<String, String>>> prop = new SimpleObjectProperty<>(empty);
// Modal
composite.show(owner, stage -> {
stage.initModality(Modality.APPLICATION_MODAL);
text.requestFocus();
text.addEventHandler(KeyEvent.KEY_RELEASED, ev -> {
if (ev.getCode() == KeyCode.ENTER) {
Optional<Pair<String, String>> pair = Optional.of(new Pair<>("OK", text.getText()));
prop.set(pair);
if (satisfied != null) {
if (satisfied.test(text.getText())) {
stage.close();
}
}
} else {
if (satisfied != null) {
if (satisfied.test(text.getText())) {
btnOk.setDisable(false);
} else
btnOk.setDisable(true);
}
}
});
btnOk.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
Optional<Pair<String, String>> pair = Optional.of(new Pair<>("OK", text.getText()));
prop.set(pair);
stage.close();
});
btnCancel.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
stage.close();
});
});
return prop.get();
// Create the custom dialog.
// Dialog<Pair<String, String>> dialog = new Dialog<>();
// dialog.setTitle(title);
// dialog.setHeaderText(message);
// TextField text = new TextField();
// text.setFocusTraversable(true);
//
// dialog.setGraphic(text);
// text.requestFocus();
//
// // Set the button types.
// ButtonType okBtn = new ButtonType("OK", ButtonData.OK_DONE);
//
// dialog.getDialogPane().getButtonTypes().add(okBtn);
//
// dialog.setResultConverter(dialogButton -> {
// if (dialogButton == okBtn) {
// return new Pair<>("OK", text.getText());
// } else {
// return null;
// }
// });
//
// if (inputValue != null && inputValue != "") {
// text.setText(inputValue);
// }
//
// dialog.initModality(Modality.APPLICATION_MODAL);
// dialog.initOwner(owner);
// dialog.getGraphic().requestFocus();
// // dialog.initModality(Modality.APPLICATION_MODAL);
// // graphic.setFocusTraversable(true);
//
// Optional<Pair<String, String>> result = dialog.showAndWait();
//
// result.ifPresent(consumer);
//
// return result;
}
use of javafx.beans.property.SimpleObjectProperty in project Gargoyle by callakrsos.
the class DialogUtil method showInputCustomDialog.
/**
* Graphics 부분을 커스텀 처리할 수 있는 InputDialog
*
* @작성자 : KYJ
* @작성일 : 2016. 10. 21.
* @param owner
* @param title
* @param message
* @param customGrahics
* @return
*/
public static <T extends Node, V> Optional<Pair<String, V>> showInputCustomDialog(Window owner, String title, String message, CustomInputDialogAction<T, V> customGrahics) {
BaseDialogComposite composite = new BaseDialogComposite(title, message);
Button btnOk = new Button("OK");
btnOk.setMinWidth(80d);
Button btnCancel = new Button("Cancel");
btnCancel.setMinWidth(80d);
composite.addButton(btnOk);
composite.addButton(btnCancel);
Optional<Pair<String, V>> empty = Optional.empty();
SimpleObjectProperty<Optional<Pair<String, V>>> prop = new SimpleObjectProperty<>(empty);
T node = customGrahics.getNode();
composite.setGraphic(node);
// Modal
composite.show(owner, stage -> {
stage.initModality(Modality.APPLICATION_MODAL);
stage.initStyle(StageStyle.UTILITY);
node.requestFocus();
stage.addEventHandler(KeyEvent.KEY_PRESSED, ev -> {
if (ev.getCode() == KeyCode.ENTER) {
Optional<Pair<String, V>> pair = Optional.of(new Pair<>("OK", customGrahics.okClickValue()));
prop.set(pair);
stage.close();
}
});
btnOk.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
Optional<Pair<String, V>> pair = Optional.of(new Pair<>("OK", customGrahics.okClickValue()));
prop.set(pair);
stage.close();
});
btnCancel.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
Optional<Pair<String, V>> pair = Optional.of(new Pair<>("Cancel", customGrahics.cancelClickValue()));
prop.set(pair);
stage.close();
});
});
return prop.get();
}
use of javafx.beans.property.SimpleObjectProperty in project jgnash by ccavanaugh.
the class RecurringViewController method initialize.
@FXML
private void initialize() {
tableView.setTableMenuButtonVisible(true);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
// hide the horizontal scrollbar and prevent ghosting
tableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
final TableColumn<Reminder, String> descriptionColumn = new TableColumn<>(resources.getString("Column.Description"));
descriptionColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDescription()));
tableView.getColumns().add(descriptionColumn);
final TableColumn<Reminder, String> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
accountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDescription()));
accountColumn.setCellValueFactory(param -> {
if (param.getValue().getAccount() != null) {
return new SimpleObjectProperty<>(param.getValue().getAccount().toString());
}
return null;
});
tableView.getColumns().add(accountColumn);
final TableColumn<Reminder, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
amountColumn.setCellValueFactory(param -> {
if (param.getValue().getTransaction() != null) {
return new SimpleObjectProperty<>(param.getValue().getTransaction().getAmount(param.getValue().getAccount()));
}
return null;
});
amountColumn.setCellFactory(new Callback<TableColumn<Reminder, BigDecimal>, TableCell<Reminder, BigDecimal>>() {
@Override
public TableCell<Reminder, BigDecimal> call(TableColumn<Reminder, BigDecimal> param) {
return new TableCell<Reminder, BigDecimal>() {
{
setStyle("-fx-alignment: center-right;");
}
@Override
protected void updateItem(final BigDecimal amount, final boolean empty) {
super.updateItem(amount, empty);
if (!empty && getTableRow() != null && getTableRow().getItem() != null) {
final Reminder reminder = (Reminder) getTableRow().getItem();
if (reminder.getTransaction() != null) {
setText(CommodityFormat.getFullNumberFormat(reminder.getAccount().getCurrencyNode()).format(amount));
if (amount != null && amount.signum() < 0) {
setId(StyleClass.NORMAL_NEGATIVE_CELL_ID);
} else {
setId(StyleClass.NORMAL_CELL_ID);
}
} else {
setText(CommodityFormat.getFullNumberFormat(reminder.getAccount().getCurrencyNode()).format(BigDecimal.ZERO));
}
}
}
};
}
});
tableView.getColumns().add(amountColumn);
final TableColumn<Reminder, String> frequencyColumn = new TableColumn<>(resources.getString("Column.Freq"));
frequencyColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getReminderType().toString()));
tableView.getColumns().add(frequencyColumn);
final TableColumn<Reminder, Boolean> enabledColumn = new TableColumn<>(resources.getString("Column.Enabled"));
enabledColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue().isEnabled()));
enabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(enabledColumn));
tableView.getColumns().add(enabledColumn);
final TableColumn<Reminder, LocalDate> lastPosted = new TableColumn<>(resources.getString("Column.LastPosted"));
lastPosted.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLastDate()));
lastPosted.setCellFactory(cell -> new ShortDateTableCell<>());
tableView.getColumns().add(lastPosted);
final TableColumn<Reminder, LocalDate> due = new TableColumn<>(resources.getString("Column.Due"));
due.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getIterator().next()));
due.setCellFactory(cell -> new ShortDateTableCell<>());
tableView.getColumns().add(due);
sortedReminderList.comparatorProperty().bind(tableView.comparatorProperty());
tableView.setItems(sortedReminderList);
selectedReminder.bind(tableView.getSelectionModel().selectedItemProperty());
// bind enabled state of the buttons to the selected reminder property
deleteButton.disableProperty().bind(Bindings.isNull(selectedReminder));
modifyButton.disableProperty().bind(Bindings.isNull(selectedReminder));
MessageBus.getInstance().registerListener(this, MessageChannel.SYSTEM, MessageChannel.REMINDER);
JavaFXUtils.runLater(this::loadTable);
startTimer();
// Update the period when the snooze value changes
Options.reminderSnoozePeriodProperty().addListener((observable, oldValue, newValue) -> {
stopTimer();
startTimer();
});
}
Aggregations