Skip to content

Commit

Permalink
fix cancel button not showing up or working for random animation
Browse files Browse the repository at this point in the history
  • Loading branch information
iTitus committed Jul 2, 2024
1 parent ec34ac5 commit 2662122
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/main/java/de/prob2/ui/operations/OperationsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -32,6 +33,7 @@
import de.prob2.ui.internal.StopActions;
import de.prob2.ui.internal.executor.BackgroundUpdater;
import de.prob2.ui.internal.executor.CliTaskExecutor;
import de.prob2.ui.internal.executor.FxThreadExecutor;
import de.prob2.ui.layout.BindableGlyph;
import de.prob2.ui.layout.FontSize;
import de.prob2.ui.prob2fx.CurrentTrace;
Expand Down Expand Up @@ -212,15 +214,13 @@ protected void updateItem(OperationItem item, boolean empty) {
private final StageManager stageManager;
private final Config config;
private final CliTaskExecutor cliExecutor;
private final FxThreadExecutor fxExecutor;
private final Comparator<CharSequence> alphanumericComparator;
private final BackgroundUpdater updater;
private final AtomicBoolean needsUpdateAfterBusy;

@Inject
private OperationsView(final CurrentTrace currentTrace, final Locale locale, final StageManager stageManager,
final Injector injector, final I18n i18n, final StatusBar statusBar,
final DisablePropertyController disablePropertyController, final StopActions stopActions,
final Config config, final CliTaskExecutor cliExecutor) {
private OperationsView(final CurrentTrace currentTrace, final Locale locale, final StageManager stageManager, final Injector injector, final I18n i18n, final StatusBar statusBar, final DisablePropertyController disablePropertyController, final StopActions stopActions, final Config config, final CliTaskExecutor cliExecutor, FxThreadExecutor fxExecutor) {
this.showDisabledOps = new SimpleBooleanProperty(this, "showDisabledOps", true);
this.showUnambiguous = new SimpleBooleanProperty(this, "showUnambiguous", false);
this.sortMode = new SimpleObjectProperty<>(this, "sortMode", OperationsView.SortMode.MODEL_ORDER);
Expand All @@ -232,6 +232,7 @@ private OperationsView(final CurrentTrace currentTrace, final Locale locale, fin
this.stageManager = stageManager;
this.config = config;
this.cliExecutor = cliExecutor;
this.fxExecutor = fxExecutor;
this.updater = new BackgroundUpdater("OperationsView Updater");
this.needsUpdateAfterBusy = new AtomicBoolean(false);
stopActions.add(this.updater::shutdownNow);
Expand Down Expand Up @@ -548,13 +549,20 @@ public void random(ActionEvent event) {
} else {
throw new AssertionError("Unhandled random animation event source: " + event.getSource());
}

cliExecutor.execute(() -> {
final Trace trace = currentTrace.get();
if (trace != null) {
currentTrace.set(trace.randomAnimation(operationCount));
}
});

Trace currentTrace = this.currentTrace.get();
if (currentTrace != null) {
this.cliExecutor.submit(() -> currentTrace.randomAnimation(operationCount)).whenCompleteAsync((res, exc) -> {
if (exc != null) {
if (!(exc instanceof CancellationException)) {
LOGGER.error("error while randomly animating", exc);
this.stageManager.showUnhandledExceptionAlert(exc, this.getScene().getWindow());
}
} else if (res != null) {
this.currentTrace.set(res);
}
}, this.fxExecutor);
}
}

private OperationsView.SortMode getSortMode() {
Expand Down

0 comments on commit 2662122

Please sign in to comment.