Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if selected proposal is null #2636

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -146,9 +146,9 @@ public class ProposalsView extends ActivatableView<GridPane, Void> implements Bs
private TableColumn<ProposalsListItem, ProposalsListItem> lastColumn;
private String shownVoteOnProposalWindowForTxId = "";

private final double initialProposalTableViewHeight = 180;
private final double pixelsPerProposalTableRow = (initialProposalTableViewHeight - 28) / 4.0;
private final Function<Double, Double> proposalTableViewHeight = (screenSize) -> {
double initialProposalTableViewHeight = 180;
double pixelsPerProposalTableRow = (initialProposalTableViewHeight - 28) / 4.0;
int extraRows = screenSize <= INITIAL_WINDOW_HEIGHT ? 0 : (int) ((screenSize - INITIAL_WINDOW_HEIGHT) / pixelsPerProposalTableRow);
return extraRows == 0 ? initialProposalTableViewHeight : Math.ceil(initialProposalTableViewHeight + (extraRows * pixelsPerProposalTableRow));
};
Expand Down Expand Up @@ -506,10 +506,6 @@ private void updateStateAfterVote() {
tableView.refresh();
}

private ProposalsListItem getBallotListItem() {
return selectedItem;
}

private void updateViews() {
boolean isBlindVotePhaseButNotLastBlock = isBlindVotePhaseButNotLastBlock();
boolean hasVotedOnProposal = hasVotedOnProposal();
Expand Down Expand Up @@ -589,6 +585,20 @@ private void updateViews() {
lastColumn.setText("");
break;
}

if (selectedItem == null && listItems.size() > 0 && selectProposalWindow.isDisplayed()) {
Proposal proposal = selectProposalWindow.getProposal();

Optional<ProposalsListItem> proposalsListItem = listItems.stream()
.filter(item -> item.getProposal().equals(proposal))
.findAny();

selectProposalWindow.onHide(() -> proposalsListItem.ifPresent(
listItem -> tableView.getSelectionModel().select(listItem)));

shownVoteOnProposalWindowForTxId = "";
selectProposalWindow.hide();
}
}

private boolean hasVotedOnProposal() {
Expand Down
4 changes: 4 additions & 0 deletions desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java
Expand Up @@ -942,6 +942,10 @@ protected double getDuration(double duration) {
return useAnimation && GlobalSettings.getUseAnimations() ? duration : 1;
}

public boolean isDisplayed() {
return isDisplayed;
}

@Override
public String toString() {
return "Popup{" +
Expand Down
Expand Up @@ -49,6 +49,7 @@ public class SelectProposalWindow extends Overlay<SelectProposalWindow> {
private Optional<Runnable> rejectHandlerOptional;
private Optional<Runnable> ignoreHandlerOptional;
private Optional<Runnable> removeHandlerOptional;
private Optional<Runnable> hideHandlerOptional;
private Proposal proposal;
private EvaluatedProposal evaluatedProposal;
private Ballot ballot;
Expand Down Expand Up @@ -99,6 +100,10 @@ public void onRemove(Runnable removeHandler) {
this.removeHandlerOptional = Optional.of(removeHandler);
}

public void onHide(Runnable hideHandler) {
this.hideHandlerOptional = Optional.of(hideHandler);
}

///////////////////////////////////////////////////////////////////////////////////////////
// Protected
///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -125,6 +130,14 @@ protected void addMessage() {
addContent(proposal, evaluatedProposal, ballot);
}

@Override
protected void onHidden() {
if (hideHandlerOptional != null) {
hideHandlerOptional.ifPresent(Runnable::run);
hideHandlerOptional = null;
}
}

private void addContent(Proposal proposal, EvaluatedProposal evaluatedProposal, Ballot ballot) {
ProposalDisplay proposalDisplay = new ProposalDisplay(gridPane, bsqFormatter, daoFacade, changeParamValidator,
navigation, preferences);
Expand Down Expand Up @@ -225,4 +238,8 @@ private Optional<Vote> getVote(@Nullable Ballot ballot) {
else
return ballot.getVoteAsOptional();
}

public Proposal getProposal() {
return proposal;
}
}