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