-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from roboalex2/feature/only-ask-once
update dialog offers to be reminded in 24h
- Loading branch information
Showing
3 changed files
with
99 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package at.esque.kafka.alerts; | ||
|
||
import at.esque.kafka.Main; | ||
import at.esque.kafka.alerts.model.UpdateDialogResult; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.*; | ||
import javafx.stage.Window; | ||
|
||
import java.util.Optional; | ||
|
||
public class UpdateAlert { | ||
public static UpdateDialogResult show(String title, String header, String content) { | ||
return show(title, header, content, null); | ||
} | ||
|
||
public static UpdateDialogResult show(String title, String header, String content, Window owner) { | ||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION); | ||
alert.setTitle(title); | ||
alert.setHeaderText(header); | ||
alert.setContentText(content); | ||
Main.applyIcon(alert); | ||
|
||
ButtonType open = new ButtonType("Open", ButtonBar.ButtonData.FINISH); | ||
ButtonType askAgain = new ButtonType("Ask in 24h again", ButtonBar.ButtonData.OK_DONE); | ||
ButtonType cancel = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE); | ||
|
||
alert.getButtonTypes().setAll(open, askAgain, cancel); | ||
|
||
|
||
Main.applyStylesheet(alert.getDialogPane().getScene()); | ||
|
||
Node okButton = alert.getDialogPane().lookupButton(open); | ||
okButton.getStyleClass().add("primary"); | ||
|
||
if (owner != null) { | ||
alert.initOwner(owner); | ||
} | ||
|
||
Optional<ButtonType> result = alert.showAndWait(); | ||
return switch (result.get().getButtonData()) { | ||
case FINISH -> UpdateDialogResult.OPEN; | ||
case OK_DONE -> UpdateDialogResult.REMIND_LATER; | ||
case CANCEL_CLOSE -> UpdateDialogResult.CANCEL; | ||
default -> UpdateDialogResult.CANCEL; | ||
}; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/at/esque/kafka/alerts/model/UpdateDialogResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package at.esque.kafka.alerts.model; | ||
|
||
public enum UpdateDialogResult { | ||
OPEN, | ||
CANCEL, | ||
REMIND_LATER | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters