Convert “new post reply found” 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 listeners that the given Sone is now marked as known.
50          *
51          * @see CoreListener#markSoneKnown(Sone)
52          * @param sone
53          *            The known Sone
54          */
55         void fireMarkSoneKnown(Sone sone) {
56                 for (CoreListener coreListener : getListeners()) {
57                         coreListener.markSoneKnown(sone);
58                 }
59         }
60
61         /**
62          * Notifies all listeners that the given post is now marked as known.
63          *
64          * @param post
65          *            The known post
66          */
67         void fireMarkPostKnown(Post post) {
68                 for (CoreListener coreListener : getListeners()) {
69                         coreListener.markPostKnown(post);
70                 }
71         }
72
73         /**
74          * Notifies all listeners that the given reply is now marked as known.
75          *
76          * @param reply
77          *            The known reply
78          */
79         void fireMarkReplyKnown(PostReply reply) {
80                 for (CoreListener coreListener : getListeners()) {
81                         coreListener.markReplyKnown(reply);
82                 }
83         }
84
85         /**
86          * Notifies all listener that the given Sone was removed.
87          *
88          * @see CoreListener#soneRemoved(Sone)
89          * @param sone
90          *            The removed Sone
91          */
92         void fireSoneRemoved(Sone sone) {
93                 for (CoreListener coreListener : getListeners()) {
94                         coreListener.soneRemoved(sone);
95                 }
96         }
97
98         /**
99          * Notifies all listener that the given post was removed.
100          *
101          * @see CoreListener#postRemoved(Post)
102          * @param post
103          *            The removed post
104          */
105         void firePostRemoved(Post post) {
106                 for (CoreListener coreListener : getListeners()) {
107                         coreListener.postRemoved(post);
108                 }
109         }
110
111         /**
112          * Notifies all listener that the given reply was removed.
113          *
114          * @see CoreListener#replyRemoved(PostReply)
115          * @param reply
116          *            The removed reply
117          */
118         void fireReplyRemoved(PostReply reply) {
119                 for (CoreListener coreListener : getListeners()) {
120                         coreListener.replyRemoved(reply);
121                 }
122         }
123
124         /**
125          * Notifies all listeners that the given Sone was locked.
126          *
127          * @see CoreListener#soneLocked(Sone)
128          * @param sone
129          *            The Sone that was locked
130          */
131         void fireSoneLocked(Sone sone) {
132                 for (CoreListener coreListener : getListeners()) {
133                         coreListener.soneLocked(sone);
134                 }
135         }
136
137         /**
138          * Notifies all listeners that the given Sone was unlocked.
139          *
140          * @see CoreListener#soneUnlocked(Sone)
141          * @param sone
142          *            The Sone that was unlocked
143          */
144         void fireSoneUnlocked(Sone sone) {
145                 for (CoreListener coreListener : getListeners()) {
146                         coreListener.soneUnlocked(sone);
147                 }
148         }
149
150         /**
151          * Notifies all listeners that the insert of the given Sone has started.
152          *
153          * @see SoneInsertListener#insertStarted(Sone)
154          * @param sone
155          *            The Sone being inserted
156          */
157         void fireSoneInserting(Sone sone) {
158                 for (CoreListener coreListener : getListeners()) {
159                         coreListener.soneInserting(sone);
160                 }
161         }
162
163         /**
164          * Notifies all listeners that the insert of the given Sone has finished
165          * successfully.
166          *
167          * @see SoneInsertListener#insertFinished(Sone, long)
168          * @param sone
169          *            The Sone that was inserted
170          * @param insertDuration
171          *            The insert duration (in milliseconds)
172          */
173         void fireSoneInserted(Sone sone, long insertDuration) {
174                 for (CoreListener coreListener : getListeners()) {
175                         coreListener.soneInserted(sone, insertDuration);
176                 }
177         }
178
179         /**
180          * Notifies all listeners that the insert of the given Sone was aborted.
181          *
182          * @see SoneInsertListener#insertStarted(Sone)
183          * @param sone
184          *            The Sone being inserted
185          * @param cause
186          *            The cause for the abortion (may be {@code null}
187          */
188         void fireSoneInsertAborted(Sone sone, Throwable cause) {
189                 for (CoreListener coreListener : getListeners()) {
190                         coreListener.soneInsertAborted(sone, cause);
191                 }
192         }
193
194         /**
195          * Notifies all listeners that a new version was found.
196          *
197          * @see CoreListener#updateFound(Version, long, long)
198          * @param version
199          *            The new version
200          * @param releaseTime
201          *            The release time of the new version
202          * @param latestEdition
203          *            The latest edition of the Sone homepage
204          */
205         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
206                 for (CoreListener coreListener : getListeners()) {
207                         coreListener.updateFound(version, releaseTime, latestEdition);
208                 }
209         }
210
211         /**
212          * Notifies all listeners that an image has started being inserted.
213          *
214          * @see CoreListener#imageInsertStarted(Image)
215          * @param image
216          *            The image that is now inserted
217          */
218         void fireImageInsertStarted(Image image) {
219                 for (CoreListener coreListener : getListeners()) {
220                         coreListener.imageInsertStarted(image);
221                 }
222         }
223
224         /**
225          * Notifies all listeners that an image insert was aborted by the user.
226          *
227          * @see CoreListener#imageInsertAborted(Image)
228          * @param image
229          *            The image that is not inserted anymore
230          */
231         void fireImageInsertAborted(Image image) {
232                 for (CoreListener coreListener : getListeners()) {
233                         coreListener.imageInsertAborted(image);
234                 }
235         }
236
237         /**
238          * Notifies all listeners that an image was successfully inserted.
239          *
240          * @see CoreListener#imageInsertFinished(Image)
241          * @param image
242          *            The image that was inserted
243          */
244         void fireImageInsertFinished(Image image) {
245                 for (CoreListener coreListener : getListeners()) {
246                         coreListener.imageInsertFinished(image);
247                 }
248         }
249
250         /**
251          * Notifies all listeners that an image failed to be inserted.
252          *
253          * @see CoreListener#imageInsertFailed(Image, Throwable)
254          * @param image
255          *            The image that could not be inserted
256          * @param cause
257          *            The cause of the failure
258          */
259         void fireImageInsertFailed(Image image, Throwable cause) {
260                 for (CoreListener coreListener : getListeners()) {
261                         coreListener.imageInsertFailed(image, cause);
262                 }
263         }
264
265 }