Convert “Sone removed” into EventBus-based event.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / CoreListenerManager.java
1 /*
2  * Sone - CoreListenerManager.java - Copyright © 2010–2012 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.core;
19
20 import net.pterodactylus.sone.data.Image;
21 import net.pterodactylus.sone.data.Post;
22 import net.pterodactylus.sone.data.PostReply;
23 import net.pterodactylus.sone.data.Sone;
24 import net.pterodactylus.util.event.AbstractListenerManager;
25 import net.pterodactylus.util.version.Version;
26
27 /**
28  * Manager for {@link CoreListener}s.
29  *
30  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31  */
32 public class CoreListenerManager extends AbstractListenerManager<Core, CoreListener> {
33
34         /**
35          * Creates a new core listener manager.
36          *
37          * @param source
38          *            The Core
39          */
40         public CoreListenerManager(Core source) {
41                 super(source);
42         }
43
44         //
45         // ACTIONS
46         //
47
48         /**
49          * Notifies all listener that the given post was removed.
50          *
51          * @see CoreListener#postRemoved(Post)
52          * @param post
53          *            The removed post
54          */
55         void firePostRemoved(Post post) {
56                 for (CoreListener coreListener : getListeners()) {
57                         coreListener.postRemoved(post);
58                 }
59         }
60
61         /**
62          * Notifies all listener that the given reply was removed.
63          *
64          * @see CoreListener#replyRemoved(PostReply)
65          * @param reply
66          *            The removed reply
67          */
68         void fireReplyRemoved(PostReply reply) {
69                 for (CoreListener coreListener : getListeners()) {
70                         coreListener.replyRemoved(reply);
71                 }
72         }
73
74         /**
75          * Notifies all listeners that the given Sone was locked.
76          *
77          * @see CoreListener#soneLocked(Sone)
78          * @param sone
79          *            The Sone that was locked
80          */
81         void fireSoneLocked(Sone sone) {
82                 for (CoreListener coreListener : getListeners()) {
83                         coreListener.soneLocked(sone);
84                 }
85         }
86
87         /**
88          * Notifies all listeners that the given Sone was unlocked.
89          *
90          * @see CoreListener#soneUnlocked(Sone)
91          * @param sone
92          *            The Sone that was unlocked
93          */
94         void fireSoneUnlocked(Sone sone) {
95                 for (CoreListener coreListener : getListeners()) {
96                         coreListener.soneUnlocked(sone);
97                 }
98         }
99
100         /**
101          * Notifies all listeners that the insert of the given Sone has started.
102          *
103          * @see SoneInsertListener#insertStarted(Sone)
104          * @param sone
105          *            The Sone being inserted
106          */
107         void fireSoneInserting(Sone sone) {
108                 for (CoreListener coreListener : getListeners()) {
109                         coreListener.soneInserting(sone);
110                 }
111         }
112
113         /**
114          * Notifies all listeners that the insert of the given Sone has finished
115          * successfully.
116          *
117          * @see SoneInsertListener#insertFinished(Sone, long)
118          * @param sone
119          *            The Sone that was inserted
120          * @param insertDuration
121          *            The insert duration (in milliseconds)
122          */
123         void fireSoneInserted(Sone sone, long insertDuration) {
124                 for (CoreListener coreListener : getListeners()) {
125                         coreListener.soneInserted(sone, insertDuration);
126                 }
127         }
128
129         /**
130          * Notifies all listeners that the insert of the given Sone was aborted.
131          *
132          * @see SoneInsertListener#insertStarted(Sone)
133          * @param sone
134          *            The Sone being inserted
135          * @param cause
136          *            The cause for the abortion (may be {@code null}
137          */
138         void fireSoneInsertAborted(Sone sone, Throwable cause) {
139                 for (CoreListener coreListener : getListeners()) {
140                         coreListener.soneInsertAborted(sone, cause);
141                 }
142         }
143
144         /**
145          * Notifies all listeners that a new version was found.
146          *
147          * @see CoreListener#updateFound(Version, long, long)
148          * @param version
149          *            The new version
150          * @param releaseTime
151          *            The release time of the new version
152          * @param latestEdition
153          *            The latest edition of the Sone homepage
154          */
155         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
156                 for (CoreListener coreListener : getListeners()) {
157                         coreListener.updateFound(version, releaseTime, latestEdition);
158                 }
159         }
160
161         /**
162          * Notifies all listeners that an image has started being inserted.
163          *
164          * @see CoreListener#imageInsertStarted(Image)
165          * @param image
166          *            The image that is now inserted
167          */
168         void fireImageInsertStarted(Image image) {
169                 for (CoreListener coreListener : getListeners()) {
170                         coreListener.imageInsertStarted(image);
171                 }
172         }
173
174         /**
175          * Notifies all listeners that an image insert was aborted by the user.
176          *
177          * @see CoreListener#imageInsertAborted(Image)
178          * @param image
179          *            The image that is not inserted anymore
180          */
181         void fireImageInsertAborted(Image image) {
182                 for (CoreListener coreListener : getListeners()) {
183                         coreListener.imageInsertAborted(image);
184                 }
185         }
186
187         /**
188          * Notifies all listeners that an image was successfully inserted.
189          *
190          * @see CoreListener#imageInsertFinished(Image)
191          * @param image
192          *            The image that was inserted
193          */
194         void fireImageInsertFinished(Image image) {
195                 for (CoreListener coreListener : getListeners()) {
196                         coreListener.imageInsertFinished(image);
197                 }
198         }
199
200         /**
201          * Notifies all listeners that an image failed to be inserted.
202          *
203          * @see CoreListener#imageInsertFailed(Image, Throwable)
204          * @param image
205          *            The image that could not be inserted
206          * @param cause
207          *            The cause of the failure
208          */
209         void fireImageInsertFailed(Image image, Throwable cause) {
210                 for (CoreListener coreListener : getListeners()) {
211                         coreListener.imageInsertFailed(image, cause);
212                 }
213         }
214
215 }