Convert “post 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.PostReply;
22 import net.pterodactylus.sone.data.Sone;
23 import net.pterodactylus.util.event.AbstractListenerManager;
24 import net.pterodactylus.util.version.Version;
25
26 /**
27  * Manager for {@link CoreListener}s.
28  *
29  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30  */
31 public class CoreListenerManager extends AbstractListenerManager<Core, CoreListener> {
32
33         /**
34          * Creates a new core listener manager.
35          *
36          * @param source
37          *            The Core
38          */
39         public CoreListenerManager(Core source) {
40                 super(source);
41         }
42
43         //
44         // ACTIONS
45         //
46
47         /**
48          * Notifies all listener that the given reply was removed.
49          *
50          * @see CoreListener#replyRemoved(PostReply)
51          * @param reply
52          *            The removed reply
53          */
54         void fireReplyRemoved(PostReply reply) {
55                 for (CoreListener coreListener : getListeners()) {
56                         coreListener.replyRemoved(reply);
57                 }
58         }
59
60         /**
61          * Notifies all listeners that the given Sone was locked.
62          *
63          * @see CoreListener#soneLocked(Sone)
64          * @param sone
65          *            The Sone that was locked
66          */
67         void fireSoneLocked(Sone sone) {
68                 for (CoreListener coreListener : getListeners()) {
69                         coreListener.soneLocked(sone);
70                 }
71         }
72
73         /**
74          * Notifies all listeners that the given Sone was unlocked.
75          *
76          * @see CoreListener#soneUnlocked(Sone)
77          * @param sone
78          *            The Sone that was unlocked
79          */
80         void fireSoneUnlocked(Sone sone) {
81                 for (CoreListener coreListener : getListeners()) {
82                         coreListener.soneUnlocked(sone);
83                 }
84         }
85
86         /**
87          * Notifies all listeners that the insert of the given Sone has started.
88          *
89          * @see SoneInsertListener#insertStarted(Sone)
90          * @param sone
91          *            The Sone being inserted
92          */
93         void fireSoneInserting(Sone sone) {
94                 for (CoreListener coreListener : getListeners()) {
95                         coreListener.soneInserting(sone);
96                 }
97         }
98
99         /**
100          * Notifies all listeners that the insert of the given Sone has finished
101          * successfully.
102          *
103          * @see SoneInsertListener#insertFinished(Sone, long)
104          * @param sone
105          *            The Sone that was inserted
106          * @param insertDuration
107          *            The insert duration (in milliseconds)
108          */
109         void fireSoneInserted(Sone sone, long insertDuration) {
110                 for (CoreListener coreListener : getListeners()) {
111                         coreListener.soneInserted(sone, insertDuration);
112                 }
113         }
114
115         /**
116          * Notifies all listeners that the insert of the given Sone was aborted.
117          *
118          * @see SoneInsertListener#insertStarted(Sone)
119          * @param sone
120          *            The Sone being inserted
121          * @param cause
122          *            The cause for the abortion (may be {@code null}
123          */
124         void fireSoneInsertAborted(Sone sone, Throwable cause) {
125                 for (CoreListener coreListener : getListeners()) {
126                         coreListener.soneInsertAborted(sone, cause);
127                 }
128         }
129
130         /**
131          * Notifies all listeners that a new version was found.
132          *
133          * @see CoreListener#updateFound(Version, long, long)
134          * @param version
135          *            The new version
136          * @param releaseTime
137          *            The release time of the new version
138          * @param latestEdition
139          *            The latest edition of the Sone homepage
140          */
141         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
142                 for (CoreListener coreListener : getListeners()) {
143                         coreListener.updateFound(version, releaseTime, latestEdition);
144                 }
145         }
146
147         /**
148          * Notifies all listeners that an image has started being inserted.
149          *
150          * @see CoreListener#imageInsertStarted(Image)
151          * @param image
152          *            The image that is now inserted
153          */
154         void fireImageInsertStarted(Image image) {
155                 for (CoreListener coreListener : getListeners()) {
156                         coreListener.imageInsertStarted(image);
157                 }
158         }
159
160         /**
161          * Notifies all listeners that an image insert was aborted by the user.
162          *
163          * @see CoreListener#imageInsertAborted(Image)
164          * @param image
165          *            The image that is not inserted anymore
166          */
167         void fireImageInsertAborted(Image image) {
168                 for (CoreListener coreListener : getListeners()) {
169                         coreListener.imageInsertAborted(image);
170                 }
171         }
172
173         /**
174          * Notifies all listeners that an image was successfully inserted.
175          *
176          * @see CoreListener#imageInsertFinished(Image)
177          * @param image
178          *            The image that was inserted
179          */
180         void fireImageInsertFinished(Image image) {
181                 for (CoreListener coreListener : getListeners()) {
182                         coreListener.imageInsertFinished(image);
183                 }
184         }
185
186         /**
187          * Notifies all listeners that an image failed to be inserted.
188          *
189          * @see CoreListener#imageInsertFailed(Image, Throwable)
190          * @param image
191          *            The image that could not be inserted
192          * @param cause
193          *            The cause of the failure
194          */
195         void fireImageInsertFailed(Image image, Throwable cause) {
196                 for (CoreListener coreListener : getListeners()) {
197                         coreListener.imageInsertFailed(image, cause);
198                 }
199         }
200
201 }