use of javafx.scene.control.TableCell 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);
}
use of javafx.scene.control.TableCell in project Gargoyle by callakrsos.
the class AbstractTableColumnInformationController method initialize.
@FXML
public void initialize() {
colNumber.setCellValueFactory(new NumberingCellValueFactory<TableColumnMetaVO>(tbColumns));
colKeyType.setCellFactory(param -> new TableCell<TableColumnMetaVO, KEY_TYPE>() {
@Override
protected void updateItem(KEY_TYPE item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
} else {
ImageView image = null;
switch(item) {
case PRI:
image = getImage(PRIMAKRY_KEY_IMAGE_NAME);
image.setFitWidth(getPrefWidth());
setGraphic(image);
break;
case MULTI:
image = getImage(MULTI_KEY_IMAGE_NAME);
image.setFitWidth(getPrefWidth());
setGraphic(image);
break;
case FOREIGN:
image = getImage(FOREIGN_KEY_IMAGE_NAME);
image.setFitWidth(getPrefWidth());
setGraphic(image);
break;
default:
image = new ImageView();
}
setGraphic(image);
}
}
});
colReference.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<TableColumnMetaVO, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(CellDataFeatures<TableColumnMetaVO, String> param) {
TableColumnMetaVO value = param.getValue();
SimpleStringProperty stringProperty = new SimpleStringProperty();
if (value != null && value.getRefs() != null) {
Optional<String> reduce = value.getRefs().stream().map(v -> v.getPkColumnName() + " -> [ " + v.getFkTableName() + "-" + v.getFkColumnName() + " ]").reduce((str1, str2) -> str1.concat("\n").concat(str2));
reduce.ifPresent(stringProperty::setValue);
}
return stringProperty;
}
});
colKeyType.setCellValueFactory(new PropertyValueFactory<>("keyType"));
colKeyType.setStyle("-fx-alignment:center");
this.tbColumns.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
FxUtil.installClipboardKeyEvent(this.tbColumns);
}
use of javafx.scene.control.TableCell in project Gargoyle by callakrsos.
the class CheckBoxTableCellExam method start.
/*
* (non-Javadoc)
*
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
@Override
public void start(Stage primaryStage) throws Exception {
TableView<SampleVO> center = new TableView<>();
center.setEditable(true);
TableColumn<SampleVO, Boolean> e = new TableColumn<SampleVO, Boolean>();
e.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<SampleVO, Boolean>, ObservableValue<Boolean>>() {
@Override
public ObservableValue<Boolean> call(CellDataFeatures<SampleVO, Boolean> param) {
return param.getValue().checked;
}
});
e.setCellFactory(new Callback<TableColumn<SampleVO, Boolean>, TableCell<SampleVO, Boolean>>() {
@Override
public TableCell<SampleVO, Boolean> call(TableColumn<SampleVO, Boolean> param) {
return new CheckBoxTableCell<SampleVO, Boolean>() {
/*
* (non-Javadoc)
*
* @see
* javafx.scene.control.cell.CheckBoxTableCell#updateItem(
* java.lang.Object, boolean)
*/
@Override
public void updateItem(Boolean item, boolean empty) {
super.updateItem(item, empty);
}
/*
* (non-Javadoc)
*
* @see
* javafx.scene.control.Cell#isItemChanged(java.lang.Object,
* java.lang.Object)
*/
@Override
protected boolean isItemChanged(Boolean oldItem, Boolean newItem) {
System.out.println(oldItem + " : " + newItem);
return super.isItemChanged(oldItem, newItem);
}
};
}
});
e.setEditable(true);
TableColumn<SampleVO, String> e2 = new TableColumn<SampleVO, String>();
e2.setCellValueFactory(new PropertyValueFactory<SampleVO, String>("name"));
center.getColumns().add(e);
center.getColumns().add(e2);
center.getItems().add(new SampleVO(true, "kim"));
center.getItems().add(new SampleVO(true, "young"));
BorderPane borderPane = new BorderPane(center);
primaryStage.setScene(new Scene(borderPane));
primaryStage.show();
}
use of javafx.scene.control.TableCell in project trex-stateless-gui by cisco-system-traffic-generator.
the class TextFieldTableViewCell method call.
@Override
public TableCell call(TableColumn param) {
return new TableCell<S, T>() {
private TextField textField;
{
textField = new TextField();
textField.setPrefSize(158, 22);
textField.setOnKeyPressed((KeyEvent event) -> {
if (event.getCode().equals(KeyCode.ENTER)) {
commitEdit((T) textField.getText());
}
});
textField.focusedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
if (!newValue) {
commitEdit((T) textField.getText());
}
});
textField.textProperty().bindBidirectional(textProperty());
}
@Override
public void updateItem(final T item, final boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
setGraphic(textField);
setText((String) getItem());
}
}
@Override
public void commitEdit(T item) {
if (!isEditing() && !item.equals(getItem())) {
TableView<S> table = getTableView();
if (table != null) {
TableColumn<S, T> column = getTableColumn();
CellEditEvent<S, T> event = new CellEditEvent<>(table, new TablePosition<S, T>(table, getIndex(), column), TableColumn.editCommitEvent(), item);
Event.fireEvent(column, event);
}
}
super.commitEdit(item);
}
};
}
use of javafx.scene.control.TableCell 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