|
@@ -27,16 +27,11 @@ import com.dmdirc.DMDircMBassador;
|
27
|
27
|
import com.dmdirc.Invite;
|
28
|
28
|
import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
|
29
|
29
|
import com.dmdirc.addons.ui_swing.MainFrame;
|
30
|
|
-import com.dmdirc.addons.ui_swing.UIUtilities;
|
31
|
30
|
import com.dmdirc.addons.ui_swing.events.SwingEventBus;
|
32
|
31
|
import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
|
33
|
|
-import com.dmdirc.events.ServerConnectErrorEvent;
|
34
|
|
-import com.dmdirc.events.ServerConnectedEvent;
|
35
|
|
-import com.dmdirc.events.ServerDisconnectedEvent;
|
|
32
|
+import com.dmdirc.events.ServerInviteExpiredEvent;
|
36
|
33
|
import com.dmdirc.events.ServerInviteReceivedEvent;
|
37
|
34
|
import com.dmdirc.interfaces.Connection;
|
38
|
|
-import com.dmdirc.interfaces.ConnectionManager;
|
39
|
|
-import com.dmdirc.interfaces.InviteListener;
|
40
|
35
|
import com.dmdirc.ui.IconManager;
|
41
|
36
|
|
42
|
37
|
import java.awt.Window;
|
|
@@ -56,7 +51,7 @@ import net.engio.mbassy.listener.Handler;
|
56
|
51
|
/**
|
57
|
52
|
* A status bar component to show invites to the user and enable them to accept or dismiss them.
|
58
|
53
|
*/
|
59
|
|
-public class InviteLabel extends StatusbarPopupPanel<JLabel> implements InviteListener {
|
|
54
|
+public class InviteLabel extends StatusbarPopupPanel<JLabel> {
|
60
|
55
|
|
61
|
56
|
/** A version number for this class. */
|
62
|
57
|
private static final long serialVersionUID = 1;
|
|
@@ -74,20 +69,13 @@ public class InviteLabel extends StatusbarPopupPanel<JLabel> implements InviteLi
|
74
|
69
|
private final SwingEventBus swingEventBus;
|
75
|
70
|
/** Active connection. */
|
76
|
71
|
private Optional<Connection> activeConnection;
|
77
|
|
- /** Connection manager. */
|
78
|
|
- private final ConnectionManager connectionManager;
|
79
|
72
|
|
80
|
73
|
@Inject
|
81
|
|
- public InviteLabel(
|
82
|
|
- final DMDircMBassador eventBus,
|
83
|
|
- @GlobalConfig final IconManager iconManager,
|
84
|
|
- final ConnectionManager connectionManager,
|
85
|
|
- final MainFrame mainFrame,
|
86
|
|
- final SwingEventBus swingEventBus) {
|
|
74
|
+ public InviteLabel(final DMDircMBassador eventBus, @GlobalConfig final IconManager iconManager,
|
|
75
|
+ final MainFrame mainFrame, final SwingEventBus swingEventBus) {
|
87
|
76
|
super(new JLabel());
|
88
|
77
|
|
89
|
78
|
this.parentWindow = mainFrame;
|
90
|
|
- this.connectionManager = connectionManager;
|
91
|
79
|
this.eventBus = eventBus;
|
92
|
80
|
this.swingEventBus = swingEventBus;
|
93
|
81
|
this.activeConnection = Optional.empty();
|
|
@@ -106,7 +94,6 @@ public class InviteLabel extends StatusbarPopupPanel<JLabel> implements InviteLi
|
106
|
94
|
* Initialises the invite label, adding appropriate listeners.
|
107
|
95
|
*/
|
108
|
96
|
public void init() {
|
109
|
|
- connectionManager.getConnections().forEach(c-> c.addInviteListener(this));
|
110
|
97
|
swingEventBus.subscribe(this);
|
111
|
98
|
eventBus.subscribe(this);
|
112
|
99
|
update();
|
|
@@ -138,49 +125,23 @@ public class InviteLabel extends StatusbarPopupPanel<JLabel> implements InviteLi
|
138
|
125
|
* Updates the invite label for the currently active server.
|
139
|
126
|
*/
|
140
|
127
|
private void update() {
|
141
|
|
- UIUtilities.invokeLater(() -> {
|
142
|
|
- if (!activeConnection.isPresent() || activeConnection.get().getInvites().isEmpty()) {
|
143
|
|
- setVisible(false);
|
144
|
|
- closeDialog();
|
145
|
|
- } else {
|
146
|
|
- refreshDialog();
|
147
|
|
- setVisible(true);
|
148
|
|
- }
|
149
|
|
- });
|
150
|
|
- }
|
151
|
|
-
|
152
|
|
- @Override
|
153
|
|
- public void inviteReceived(final Connection connection, final Invite invite) {
|
154
|
|
- update();
|
155
|
|
- }
|
156
|
|
-
|
157
|
|
- @Override
|
158
|
|
- public void inviteExpired(final Connection connection, final Invite invite) {
|
159
|
|
- update();
|
|
128
|
+ if (!activeConnection.isPresent() || activeConnection.get().getInvites().isEmpty()) {
|
|
129
|
+ setVisible(false);
|
|
130
|
+ closeDialog();
|
|
131
|
+ } else {
|
|
132
|
+ refreshDialog();
|
|
133
|
+ setVisible(true);
|
|
134
|
+ }
|
160
|
135
|
}
|
161
|
136
|
|
162
|
137
|
@Handler(invocation = EdtHandlerInvocation.class)
|
163
|
138
|
public void handleInviteReceived(final ServerInviteReceivedEvent event) {
|
164
|
|
-
|
165
|
|
- }
|
166
|
|
-
|
167
|
|
- @Handler
|
168
|
|
- public void handleServerConnected(final ServerConnectedEvent event) {
|
169
|
|
- event.getConnection().addInviteListener(this);
|
170
|
|
- }
|
171
|
|
-
|
172
|
|
- @Handler
|
173
|
|
- public void handleServerDisconnected(final ServerDisconnectedEvent event) {
|
174
|
|
- handleServerRemoved(event.getConnection());
|
175
|
|
- }
|
176
|
|
-
|
177
|
|
- @Handler
|
178
|
|
- public void handleServerConnectError(final ServerConnectErrorEvent event) {
|
179
|
|
- handleServerRemoved(event.getConnection());
|
|
139
|
+ update();
|
180
|
140
|
}
|
181
|
141
|
|
182
|
|
- private void handleServerRemoved(final Connection connection) {
|
183
|
|
- connection.removeInviteListener(this);
|
|
142
|
+ @Handler(invocation = EdtHandlerInvocation.class)
|
|
143
|
+ public void handleInviteExpired(final ServerInviteExpiredEvent event) {
|
|
144
|
+ update();
|
184
|
145
|
}
|
185
|
146
|
|
186
|
147
|
@Override
|