|
@@ -32,7 +32,6 @@ import com.dmdirc.events.DMDircEvent;
|
32
|
32
|
import com.dmdirc.events.DisplayableEvent;
|
33
|
33
|
import com.dmdirc.events.UserErrorEvent;
|
34
|
34
|
import com.dmdirc.interfaces.ActionController;
|
35
|
|
-import com.dmdirc.interfaces.ActionListener;
|
36
|
35
|
import com.dmdirc.interfaces.actions.ActionComparison;
|
37
|
36
|
import com.dmdirc.interfaces.actions.ActionComponent;
|
38
|
37
|
import com.dmdirc.interfaces.actions.ActionType;
|
|
@@ -50,6 +49,7 @@ import java.nio.file.Files;
|
50
|
49
|
import java.nio.file.Path;
|
51
|
50
|
import java.nio.file.Paths;
|
52
|
51
|
import java.util.ArrayList;
|
|
52
|
+import java.util.Collection;
|
53
|
53
|
import java.util.Collections;
|
54
|
54
|
import java.util.HashMap;
|
55
|
55
|
import java.util.List;
|
|
@@ -58,6 +58,7 @@ import java.util.Set;
|
58
|
58
|
|
59
|
59
|
import javax.inject.Provider;
|
60
|
60
|
|
|
61
|
+import org.slf4j.Logger;
|
61
|
62
|
import org.slf4j.LoggerFactory;
|
62
|
63
|
|
63
|
64
|
import net.engio.mbassy.listener.Handler;
|
|
@@ -70,7 +71,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
70
|
71
|
*/
|
71
|
72
|
public class ActionManager implements ActionController {
|
72
|
73
|
|
73
|
|
- private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ActionManager.class);
|
|
74
|
+ private static final Logger LOG = LoggerFactory.getLogger(ActionManager.class);
|
74
|
75
|
/** The ActionManager Instance. */
|
75
|
76
|
private static ActionManager me;
|
76
|
77
|
/** The identity manager to load configuration from. */
|
|
@@ -82,11 +83,11 @@ public class ActionManager implements ActionController {
|
82
|
83
|
/** Provider of an update manager. */
|
83
|
84
|
private final Provider<UpdateManager> updateManagerProvider;
|
84
|
85
|
/** A list of registered action types. */
|
85
|
|
- private final List<ActionType> types = new ArrayList<>();
|
|
86
|
+ private final Collection<ActionType> types = new ArrayList<>();
|
86
|
87
|
/** A list of registered action components. */
|
87
|
|
- private final List<ActionComponent> components = new ArrayList<>();
|
|
88
|
+ private final Collection<ActionComponent> components = new ArrayList<>();
|
88
|
89
|
/** A list of registered action comparisons. */
|
89
|
|
- private final List<ActionComparison> comparisons = new ArrayList<>();
|
|
90
|
+ private final Collection<ActionComparison> comparisons = new ArrayList<>();
|
90
|
91
|
/** A map linking types and a list of actions that're registered for them. */
|
91
|
92
|
private final MapList<ActionType, Action> actions = new MapList<>();
|
92
|
93
|
/** A map linking groups and a list of actions that're in them. */
|
|
@@ -95,8 +96,6 @@ public class ActionManager implements ActionController {
|
95
|
96
|
private final Map<String, Object> locks = new HashMap<>();
|
96
|
97
|
/** A map of the action type groups to the action types within. */
|
97
|
98
|
private final MapList<String, ActionType> typeGroups = new MapList<>();
|
98
|
|
- /** The listeners that we have registered. */
|
99
|
|
- private final MapList<ActionType, ActionListener> listeners = new MapList<>();
|
100
|
99
|
/** The global event bus to monitor. */
|
101
|
100
|
private final DMDircMBassador eventBus;
|
102
|
101
|
/** The directory to load and save actions in. */
|
|
@@ -367,24 +366,7 @@ public class ActionManager implements ActionController {
|
367
|
366
|
|
368
|
367
|
LOG.trace("Calling listeners for event of type {}", type);
|
369
|
368
|
|
370
|
|
- boolean res = false;
|
371
|
|
-
|
372
|
|
- if (listeners.containsKey(type)) {
|
373
|
|
- for (ActionListener listener : new ArrayList<>(listeners.get(type))) {
|
374
|
|
- try {
|
375
|
|
- listener.processEvent(type, format, arguments);
|
376
|
|
- } catch (Exception e) {
|
377
|
|
- eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e,
|
378
|
|
- "Error processing action: " + e.getMessage(), ""));
|
379
|
|
- }
|
380
|
|
- }
|
381
|
|
- }
|
382
|
|
-
|
383
|
|
- if (!killSwitch) {
|
384
|
|
- res = triggerActions(type, format, arguments);
|
385
|
|
- }
|
386
|
|
-
|
387
|
|
- return !res;
|
|
369
|
+ return killSwitch || !triggerActions(type, format, arguments);
|
388
|
370
|
}
|
389
|
371
|
|
390
|
372
|
/**
|
|
@@ -402,10 +384,9 @@ public class ActionManager implements ActionController {
|
402
|
384
|
final StringBuffer format, final Object... arguments) {
|
403
|
385
|
checkNotNull(type);
|
404
|
386
|
|
405
|
|
- boolean res = false;
|
406
|
|
-
|
407
|
387
|
LOG.trace("Executing actions for event of type {}", type);
|
408
|
388
|
|
|
389
|
+ boolean res = false;
|
409
|
390
|
if (actions.containsKey(type)) {
|
410
|
391
|
for (Action action : new ArrayList<>(actions.get(type))) {
|
411
|
392
|
try {
|
|
@@ -495,7 +476,7 @@ public class ActionManager implements ActionController {
|
495
|
476
|
final Method method = methods[j];
|
496
|
477
|
if (method.getParameterTypes().length == 0
|
497
|
478
|
&& method.getName().startsWith("get")
|
498
|
|
- && !method.getName().equals("getDisplayFormat")
|
|
479
|
+ && !"getDisplayFormat".equals(method.getName())
|
499
|
480
|
&& method.getReturnType().equals(target)
|
500
|
481
|
&& Math.abs(j - i) < bestDistance) {
|
501
|
482
|
bestDistance = Math.abs(j - i);
|
|
@@ -687,23 +668,4 @@ public class ActionManager implements ActionController {
|
687
|
668
|
Files.delete(path);
|
688
|
669
|
}
|
689
|
670
|
|
690
|
|
- @Override
|
691
|
|
- public void registerListener(final ActionListener listener, final ActionType... types) {
|
692
|
|
- for (ActionType type : types) {
|
693
|
|
- listeners.add(type, listener);
|
694
|
|
- }
|
695
|
|
- }
|
696
|
|
-
|
697
|
|
- @Override
|
698
|
|
- public void unregisterListener(final ActionListener listener, final ActionType... types) {
|
699
|
|
- for (ActionType type : types) {
|
700
|
|
- listeners.remove(type, listener);
|
701
|
|
- }
|
702
|
|
- }
|
703
|
|
-
|
704
|
|
- @Override
|
705
|
|
- public void unregisterListener(final ActionListener listener) {
|
706
|
|
- listeners.removeFromAll(listener);
|
707
|
|
- }
|
708
|
|
-
|
709
|
671
|
}
|