use of javafx.beans.property.ReadOnlyObjectWrapper in project bitsquare by bitsquare.
the class ArbitratorSelectionView method addArbitratorsGroup.
private void addArbitratorsGroup() {
TableGroupHeadline tableGroupHeadline = new TableGroupHeadline("Which arbitrators do you accept");
GridPane.setRowIndex(tableGroupHeadline, ++gridRow);
GridPane.setColumnSpan(tableGroupHeadline, 2);
GridPane.setMargin(tableGroupHeadline, new Insets(40, -10, -10, -10));
root.getChildren().add(tableGroupHeadline);
tableView = new TableView<>();
GridPane.setRowIndex(tableView, gridRow);
GridPane.setColumnSpan(tableView, 2);
GridPane.setMargin(tableView, new Insets(60, -10, 5, -10));
root.getChildren().add(tableView);
autoSelectAllMatchingCheckBox = addCheckBox(root, ++gridRow, "Auto select all arbitrators with matching language");
GridPane.setColumnSpan(autoSelectAllMatchingCheckBox, 2);
GridPane.setHalignment(autoSelectAllMatchingCheckBox, HPos.LEFT);
GridPane.setColumnIndex(autoSelectAllMatchingCheckBox, 0);
GridPane.setMargin(autoSelectAllMatchingCheckBox, new Insets(0, -10, 0, -10));
autoSelectAllMatchingCheckBox.setOnAction(event -> model.setAutoSelectArbitrators(autoSelectAllMatchingCheckBox.isSelected()));
TableColumn<ArbitratorListItem, String> dateColumn = new TableColumn("Registration date");
dateColumn.setSortable(false);
dateColumn.setCellValueFactory(param -> new ReadOnlyObjectWrapper(param.getValue().getRegistrationDate()));
dateColumn.setMinWidth(140);
dateColumn.setMaxWidth(140);
TableColumn<ArbitratorListItem, String> nameColumn = new TableColumn("Onion address");
nameColumn.setSortable(false);
nameColumn.setCellValueFactory(param -> new ReadOnlyObjectWrapper(param.getValue().getAddressString()));
nameColumn.setMinWidth(90);
TableColumn<ArbitratorListItem, String> languagesColumn = new TableColumn("Languages");
languagesColumn.setSortable(false);
languagesColumn.setCellValueFactory(param -> new ReadOnlyObjectWrapper(param.getValue().getLanguageCodes()));
languagesColumn.setMinWidth(130);
TableColumn<ArbitratorListItem, ArbitratorListItem> selectionColumn = new TableColumn<ArbitratorListItem, ArbitratorListItem>("Accept") {
{
setMinWidth(60);
setMaxWidth(60);
setSortable(false);
}
};
selectionColumn.setCellValueFactory((arbitrator) -> new ReadOnlyObjectWrapper<>(arbitrator.getValue()));
selectionColumn.setCellFactory(new Callback<TableColumn<ArbitratorListItem, ArbitratorListItem>, TableCell<ArbitratorListItem, ArbitratorListItem>>() {
@Override
public TableCell<ArbitratorListItem, ArbitratorListItem> call(TableColumn<ArbitratorListItem, ArbitratorListItem> column) {
return new TableCell<ArbitratorListItem, ArbitratorListItem>() {
private final CheckBox checkBox = new CheckBox();
private TableRow tableRow;
private BooleanProperty selectedProperty;
private void updateDisableState(final ArbitratorListItem item) {
boolean selected = model.isAcceptedArbitrator(item.arbitrator);
item.setIsSelected(selected);
boolean hasMatchingLanguage = model.hasMatchingLanguage(item.arbitrator);
if (!hasMatchingLanguage) {
model.onRemoveArbitrator(item.arbitrator);
if (selected)
item.setIsSelected(false);
}
boolean isMyOwnRegisteredArbitrator = model.isMyOwnRegisteredArbitrator(item.arbitrator);
checkBox.setDisable(!hasMatchingLanguage || isMyOwnRegisteredArbitrator);
tableRow = getTableRow();
if (tableRow != null) {
tableRow.setOpacity(hasMatchingLanguage && !isMyOwnRegisteredArbitrator ? 1 : 0.4);
if (isMyOwnRegisteredArbitrator) {
tableRow.setTooltip(new Tooltip("An arbitrator cannot select himself for trading."));
tableRow.setOnMouseClicked(e -> new Popup().warning("An arbitrator cannot select himself for trading.").show());
} else if (!hasMatchingLanguage) {
tableRow.setTooltip(new Tooltip("No matching language."));
tableRow.setOnMouseClicked(e -> new Popup().warning("You can only select arbitrators who are speaking at least 1 common language.").show());
} else {
tableRow.setOnMouseClicked(null);
tableRow.setTooltip(null);
}
}
}
@Override
public void updateItem(final ArbitratorListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
selectedProperty = item.isSelectedProperty();
languageCodesListChangeListener = c -> updateDisableState(item);
model.languageCodes.addListener(languageCodesListChangeListener);
isSelectedChangeListener = (observable, oldValue, newValue) -> checkBox.setSelected(newValue);
selectedProperty.addListener(isSelectedChangeListener);
checkBox.setSelected(model.isAcceptedArbitrator(item.arbitrator));
checkBox.setOnAction(e -> {
if (checkBox.isSelected()) {
onAddArbitrator(item);
} else if (model.isDeselectAllowed(item)) {
onRemoveArbitrator(item);
} else {
new Popup().warning("You need to have at least one arbitrator selected.").show();
checkBox.setSelected(true);
}
item.setIsSelected(checkBox.isSelected());
});
updateDisableState(item);
setGraphic(checkBox);
} else {
model.languageCodes.removeListener(languageCodesListChangeListener);
if (selectedProperty != null)
selectedProperty.removeListener(isSelectedChangeListener);
setGraphic(null);
if (checkBox != null)
checkBox.setOnAction(null);
if (tableRow != null)
tableRow.setOnMouseClicked(null);
}
}
};
}
});
tableView.getColumns().addAll(dateColumn, nameColumn, languagesColumn, selectionColumn);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
}
use of javafx.beans.property.ReadOnlyObjectWrapper in project bitsquare by bitsquare.
the class TraderDisputeView method getStateColumn.
private TableColumn<Dispute, Dispute> getStateColumn() {
TableColumn<Dispute, Dispute> column = new TableColumn<Dispute, Dispute>("State") {
{
setMinWidth(50);
}
};
column.setCellValueFactory((dispute) -> new ReadOnlyObjectWrapper<>(dispute.getValue()));
column.setCellFactory(new Callback<TableColumn<Dispute, Dispute>, TableCell<Dispute, Dispute>>() {
@Override
public TableCell<Dispute, Dispute> call(TableColumn<Dispute, Dispute> column) {
return new TableCell<Dispute, Dispute>() {
public ReadOnlyBooleanProperty closedProperty;
public ChangeListener<Boolean> listener;
@Override
public void updateItem(final Dispute item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
listener = (observable, oldValue, newValue) -> {
setText(newValue ? "Closed" : "Open");
getTableRow().setOpacity(newValue ? 0.4 : 1);
};
closedProperty = item.isClosedProperty();
closedProperty.addListener(listener);
boolean isClosed = item.isClosed();
setText(isClosed ? "Closed" : "Open");
getTableRow().setOpacity(isClosed ? 0.4 : 1);
} else {
if (closedProperty != null) {
closedProperty.removeListener(listener);
closedProperty = null;
}
setText("");
}
}
};
}
});
return column;
}
use of javafx.beans.property.ReadOnlyObjectWrapper in project bitsquare by bitsquare.
the class DepositView method setAddressColumnCellFactory.
private void setAddressColumnCellFactory() {
addressColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue()));
addressColumn.setCellFactory(new Callback<TableColumn<DepositListItem, DepositListItem>, TableCell<DepositListItem, DepositListItem>>() {
@Override
public TableCell<DepositListItem, DepositListItem> call(TableColumn<DepositListItem, DepositListItem> column) {
return new TableCell<DepositListItem, DepositListItem>() {
private HyperlinkWithIcon field;
@Override
public void updateItem(final DepositListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
String addressString = item.getAddressString();
field = new HyperlinkWithIcon(addressString, AwesomeIcon.EXTERNAL_LINK);
field.setOnAction(event -> {
openBlockExplorer(item);
tableView.getSelectionModel().select(item);
});
field.setTooltip(new Tooltip("Open external blockchain explorer for " + "address: " + addressString));
setGraphic(field);
} else {
setGraphic(null);
if (field != null)
field.setOnAction(null);
}
}
};
}
});
}
use of javafx.beans.property.ReadOnlyObjectWrapper in project bitsquare by bitsquare.
the class TransactionsView method setDetailsColumnCellFactory.
private void setDetailsColumnCellFactory() {
detailsColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue()));
detailsColumn.setCellFactory(new Callback<TableColumn<TransactionsListItem, TransactionsListItem>, TableCell<TransactionsListItem, TransactionsListItem>>() {
@Override
public TableCell<TransactionsListItem, TransactionsListItem> call(TableColumn<TransactionsListItem, TransactionsListItem> column) {
return new TableCell<TransactionsListItem, TransactionsListItem>() {
private HyperlinkWithIcon field;
@Override
public void updateItem(final TransactionsListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
if (item.getDetailsAvailable()) {
field = new HyperlinkWithIcon(item.getDetails(), AwesomeIcon.INFO_SIGN);
field.setOnAction(event -> openDetailPopup(item));
field.setTooltip(new Tooltip("Open popup for details"));
setGraphic(field);
} else {
setGraphic(new Label(item.getDetails()));
}
} else {
setGraphic(null);
if (field != null)
field.setOnAction(null);
}
}
};
}
});
}
use of javafx.beans.property.ReadOnlyObjectWrapper in project bitsquare by bitsquare.
the class LockedView method setDetailsColumnCellFactory.
private void setDetailsColumnCellFactory() {
detailsColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue()));
detailsColumn.setCellFactory(new Callback<TableColumn<LockedListItem, LockedListItem>, TableCell<LockedListItem, LockedListItem>>() {
@Override
public TableCell<LockedListItem, LockedListItem> call(TableColumn<LockedListItem, LockedListItem> column) {
return new TableCell<LockedListItem, LockedListItem>() {
private HyperlinkWithIcon field;
@Override
public void updateItem(final LockedListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
Optional<Tradable> tradableOptional = getTradable(item);
if (tradableOptional.isPresent()) {
field = new HyperlinkWithIcon("Locked in MultiSig for trade with ID: " + item.getAddressEntry().getShortOfferId(), AwesomeIcon.INFO_SIGN);
field.setOnAction(event -> openDetailPopup(item));
field.setTooltip(new Tooltip("Open popup for details"));
setGraphic(field);
} else if (item.getAddressEntry().getContext() == AddressEntry.Context.ARBITRATOR) {
setGraphic(new Label("Arbitrator's fee"));
} else {
setGraphic(new Label("No details available"));
}
} else {
setGraphic(null);
if (field != null)
field.setOnAction(null);
}
}
};
}
});
}
Aggregations