From: David ‘Bombe’ Roden Date: Wed, 16 Jan 2013 18:22:45 +0000 (+0100) Subject: Convert “Sone insert was aborted” into EventBus-based event. X-Git-Tag: 0.8.5^2~3^2~101 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8b6ea0e3f05c3b9f3041158f3bc54ed00828b207;p=Sone.git Convert “Sone insert was aborted” into EventBus-based event. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 9cf0e99..b69c866 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -43,6 +43,7 @@ import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent; import net.pterodactylus.sone.core.event.NewSoneFoundEvent; import net.pterodactylus.sone.core.event.PostRemovedEvent; import net.pterodactylus.sone.core.event.PostReplyRemovedEvent; +import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent; import net.pterodactylus.sone.core.event.SoneInsertedEvent; import net.pterodactylus.sone.core.event.SoneInsertingEvent; import net.pterodactylus.sone.core.event.SoneLockedEvent; @@ -2480,7 +2481,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis */ @Override public void insertAborted(Sone sone, Throwable cause) { - coreListenerManager.fireSoneInsertAborted(sone, cause); + eventBus.post(new SoneInsertAbortedEvent(sone, cause)); } // diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListener.java b/src/main/java/net/pterodactylus/sone/core/CoreListener.java index 7b5c15c..80c31c2 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListener.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListener.java @@ -20,7 +20,6 @@ package net.pterodactylus.sone.core; import java.util.EventListener; import net.pterodactylus.sone.data.Image; -import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.version.Version; /** @@ -32,17 +31,6 @@ import net.pterodactylus.util.version.Version; public interface CoreListener extends EventListener { /** - * Notifies a listener that the insert of the given Sone was aborted. - * - * @see SoneInsertListener#insertAborted(Sone, Throwable) - * @param sone - * The Sone that was inserted - * @param cause - * The cause for the abortion (may be {@code null}) - */ - public void soneInsertAborted(Sone sone, Throwable cause); - - /** * Notifies a listener that a new version has been found. * * @param version diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java index a4c3b78..b8df010 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java @@ -18,7 +18,6 @@ package net.pterodactylus.sone.core; import net.pterodactylus.sone.data.Image; -import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.event.AbstractListenerManager; import net.pterodactylus.util.version.Version; @@ -44,21 +43,6 @@ public class CoreListenerManager extends AbstractListenerManager. + */ + +package net.pterodactylus.sone.core.event; + +import net.pterodactylus.sone.data.Sone; + +/** + * Event that signals that a {@link Sone} insert was aborted. + * + * @author David ‘Bombe’ Roden + */ +public class SoneInsertAbortedEvent extends SoneEvent { + + /** The cause of the abortion. */ + private final Throwable cause; + + /** + * Creates a new “Sone was inserted” event. + * + * @param sone + * The Sone that was inserted + * @param cause + * The cause of the abortion + */ + public SoneInsertAbortedEvent(Sone sone, Throwable cause) { + super(sone); + this.cause = cause; + } + + // + // ACCESSORS + // + + /** + * Returns the cause of the abortion. + * + * @return The cause of the abortion (may be {@code null}) + */ + public Throwable cause() { + return cause; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 1c58bd3..7c16c09 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -45,6 +45,7 @@ import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent; import net.pterodactylus.sone.core.event.NewSoneFoundEvent; import net.pterodactylus.sone.core.event.PostRemovedEvent; import net.pterodactylus.sone.core.event.PostReplyRemovedEvent; +import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent; import net.pterodactylus.sone.core.event.SoneInsertedEvent; import net.pterodactylus.sone.core.event.SoneInsertingEvent; import net.pterodactylus.sone.core.event.SoneLockedEvent; @@ -1005,23 +1006,26 @@ public class WebInterface implements CoreListener { } } - // - // CORELISTENER METHODS - // - /** - * {@inheritDoc} + * Notifies the web interface that a {@link Sone} insert was aborted. + * + * @param soneInsertAbortedEvent + * The event */ - @Override - public void soneInsertAborted(Sone sone, Throwable cause) { - TemplateNotification soneInsertNotification = getSoneInsertNotification(sone); + @Subscribe + public void soneInsertAborted(SoneInsertAbortedEvent soneInsertAbortedEvent) { + TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertAbortedEvent.sone()); soneInsertNotification.set("soneStatus", "insert-aborted"); - soneInsertNotification.set("insert-error", cause); - if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) { + soneInsertNotification.set("insert-error", soneInsertAbortedEvent.cause()); + if (soneInsertAbortedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) { notificationManager.addNotification(soneInsertNotification); } } + // + // CORELISTENER METHODS + // + /** * {@inheritDoc} */