You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ActionManager.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.actions;
  23. import com.dmdirc.Precondition;
  24. import com.dmdirc.actions.internal.WhoisNumericFormatter;
  25. import com.dmdirc.config.ConfigBinding;
  26. import com.dmdirc.events.AppErrorEvent;
  27. import com.dmdirc.events.ClientClosedEvent;
  28. import com.dmdirc.events.DMDircEvent;
  29. import com.dmdirc.events.DisplayableEvent;
  30. import com.dmdirc.events.UserErrorEvent;
  31. import com.dmdirc.interfaces.ActionController;
  32. import com.dmdirc.interfaces.ActionListener;
  33. import com.dmdirc.interfaces.actions.ActionComparison;
  34. import com.dmdirc.interfaces.actions.ActionComponent;
  35. import com.dmdirc.interfaces.actions.ActionType;
  36. import com.dmdirc.interfaces.config.IdentityController;
  37. import com.dmdirc.logger.ErrorLevel;
  38. import com.dmdirc.updater.components.ActionGroupComponent;
  39. import com.dmdirc.updater.manager.UpdateManager;
  40. import com.dmdirc.util.collections.MapList;
  41. import com.dmdirc.util.resourcemanager.ZipResourceManager;
  42. import java.io.File;
  43. import java.io.IOException;
  44. import java.lang.reflect.Method;
  45. import java.util.ArrayList;
  46. import java.util.Collections;
  47. import java.util.HashMap;
  48. import java.util.List;
  49. import java.util.Map;
  50. import java.util.Set;
  51. import javax.inject.Provider;
  52. import org.slf4j.LoggerFactory;
  53. import net.engio.mbassy.bus.MBassador;
  54. import net.engio.mbassy.listener.Handler;
  55. import static com.google.common.base.Preconditions.checkArgument;
  56. import static com.google.common.base.Preconditions.checkNotNull;
  57. /**
  58. * Manages all actions for the client.
  59. */
  60. public class ActionManager implements ActionController {
  61. private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ActionManager.class);
  62. /** The ActionManager Instance. */
  63. private static ActionManager me;
  64. /** The identity manager to load configuration from. */
  65. private final IdentityController identityManager;
  66. /** The factory to use to create actions. */
  67. private final ActionFactory factory;
  68. /** Provider for action wrappers. */
  69. private final Provider<Set<ActionGroup>> actionWrappersProvider;
  70. /** Provider of an update manager. */
  71. private final Provider<UpdateManager> updateManagerProvider;
  72. /** A list of registered action types. */
  73. private final List<ActionType> types = new ArrayList<>();
  74. /** A list of registered action components. */
  75. private final List<ActionComponent> components = new ArrayList<>();
  76. /** A list of registered action comparisons. */
  77. private final List<ActionComparison> comparisons = new ArrayList<>();
  78. /** A map linking types and a list of actions that're registered for them. */
  79. private final MapList<ActionType, Action> actions = new MapList<>();
  80. /** A map linking groups and a list of actions that're in them. */
  81. private final Map<String, ActionGroup> groups = new HashMap<>();
  82. /** A map of objects to synchronise on for concurrency groups. */
  83. private final Map<String, Object> locks = new HashMap<>();
  84. /** A map of the action type groups to the action types within. */
  85. private final MapList<String, ActionType> typeGroups = new MapList<>();
  86. /** The listeners that we have registered. */
  87. private final MapList<ActionType, ActionListener> listeners = new MapList<>();
  88. /** The global event bus to monitor. */
  89. private final MBassador eventBus;
  90. /** The directory to load and save actions in. */
  91. private final String directory;
  92. /** Indicates whether or not user actions should be killed (not processed). */
  93. @ConfigBinding(domain = "actions", key = "killswitch")
  94. private boolean killSwitch;
  95. /**
  96. * Creates a new instance of ActionManager.
  97. *
  98. * @param identityManager The IdentityManager to load configuration from.
  99. * @param factory The factory to use to create new actions.
  100. * @param actionWrappersProvider Provider of action wrappers.
  101. * @param updateManagerProvider Provider of an update manager, to register components.
  102. * @param eventBus The global event bus to monitor.
  103. * @param directory The directory to load and save actions in.
  104. */
  105. public ActionManager(
  106. final IdentityController identityManager,
  107. final ActionFactory factory,
  108. final Provider<Set<ActionGroup>> actionWrappersProvider,
  109. final Provider<UpdateManager> updateManagerProvider,
  110. final MBassador eventBus,
  111. final String directory) {
  112. this.identityManager = identityManager;
  113. this.factory = factory;
  114. this.actionWrappersProvider = actionWrappersProvider;
  115. this.updateManagerProvider = updateManagerProvider;
  116. this.eventBus = eventBus;
  117. this.directory = directory;
  118. }
  119. /**
  120. * Create the singleton instance of the Action Manager.
  121. *
  122. * @param actionManager The manager to return for calls to {@link #getActionManager()}.
  123. *
  124. * @deprecated Singleton use should be removed.
  125. */
  126. @Deprecated
  127. public static void setActionManager(final ActionManager actionManager) {
  128. me = actionManager;
  129. }
  130. /**
  131. * Returns a singleton instance of the Action Manager.
  132. *
  133. * @return A singleton ActionManager instance
  134. */
  135. public static ActionManager getActionManager() {
  136. return me;
  137. }
  138. /**
  139. * Initialiases the actions manager.
  140. *
  141. * @param colourComparisons The colour comparisons to use.
  142. */
  143. // TODO: Refactor to take a list of comparisons/sources.
  144. public void initialise(final ColourActionComparison colourComparisons) {
  145. LOG.info("Initialising the actions manager");
  146. identityManager.getGlobalConfiguration().getBinder().bind(this, ActionManager.class);
  147. registerTypes(CoreActionType.values());
  148. registerComparisons(CoreActionComparison.values());
  149. registerComparisons(colourComparisons.getComparisons());
  150. registerComponents(CoreActionComponent.values());
  151. for (ActionGroup wrapper : actionWrappersProvider.get()) {
  152. addGroup(wrapper);
  153. }
  154. new WhoisNumericFormatter(identityManager.getAddonSettings(), eventBus).register();
  155. eventBus.subscribe(this);
  156. }
  157. @Override
  158. public void saveAllActions() {
  159. for (ActionGroup group : groups.values()) {
  160. for (Action action : group) {
  161. action.save();
  162. }
  163. }
  164. }
  165. /**
  166. * Saves all actions when the client is being closed.
  167. *
  168. * @param event The event that was raised.
  169. */
  170. @Handler
  171. public void handleClientClosed(final ClientClosedEvent event) {
  172. LOG.debug("Client closed - saving all actions");
  173. saveAllActions();
  174. }
  175. @Override
  176. public void registerSetting(final String name, final String value) {
  177. LOG.debug("Registering new action setting: {} = {}", name, value);
  178. identityManager.getAddonSettings().setOption("actions", name, value);
  179. }
  180. @Override
  181. public void addGroup(final ActionGroup group) {
  182. groups.put(group.getName(), group);
  183. }
  184. @Override
  185. public void registerTypes(final ActionType[] newTypes) {
  186. for (ActionType type : newTypes) {
  187. checkNotNull(type);
  188. if (!types.contains(type)) {
  189. LOG.debug("Registering action type: {}", type);
  190. types.add(type);
  191. typeGroups.add(type.getType().getGroup(), type);
  192. }
  193. }
  194. }
  195. @Override
  196. public void registerComponents(final ActionComponent[] comps) {
  197. for (ActionComponent comp : comps) {
  198. checkNotNull(comp);
  199. LOG.debug("Registering action component: {}", comp);
  200. components.add(comp);
  201. }
  202. }
  203. @Override
  204. public void registerComparisons(final ActionComparison[] comps) {
  205. for (ActionComparison comp : comps) {
  206. checkNotNull(comp);
  207. LOG.debug("Registering action comparison: {}", comp);
  208. comparisons.add(comp);
  209. }
  210. }
  211. @Override
  212. public Map<String, ActionGroup> getGroupsMap() {
  213. return Collections.unmodifiableMap(groups);
  214. }
  215. @Override
  216. public MapList<String, ActionType> getGroupedTypes() {
  217. return new MapList<>(typeGroups);
  218. }
  219. @Override
  220. public void loadUserActions() {
  221. actions.clear();
  222. for (ActionGroup group : groups.values()) {
  223. group.clear();
  224. }
  225. final File dir = new File(directory);
  226. if (!dir.exists()) {
  227. try {
  228. dir.mkdirs();
  229. dir.createNewFile();
  230. } catch (IOException ex) {
  231. eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, null,
  232. "I/O error when creating actions directory: " + ex.getMessage(), ""));
  233. }
  234. }
  235. if (dir.listFiles() == null) {
  236. eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
  237. "Unable to load user action files", ""));
  238. } else {
  239. for (File file : dir.listFiles()) {
  240. if (file.isDirectory()) {
  241. loadActions(file);
  242. }
  243. }
  244. }
  245. registerComponents(updateManagerProvider.get());
  246. }
  247. /**
  248. * Creates new ActionGroupComponents for each action group.
  249. *
  250. * @param updateManager The update manager to register components with
  251. */
  252. private void registerComponents(final UpdateManager updateManager) {
  253. for (ActionGroup group : groups.values()) {
  254. if (group.getComponent() != -1 && group.getVersion() != null) {
  255. updateManager.addComponent(new ActionGroupComponent(group));
  256. }
  257. }
  258. }
  259. /**
  260. * Loads action files from a specified group directory.
  261. *
  262. * @param dir The directory to scan.
  263. */
  264. @Precondition("The specified File is not null and represents a directory")
  265. private void loadActions(final File dir) {
  266. checkNotNull(dir);
  267. checkArgument(dir.isDirectory());
  268. LOG.debug("Loading actions from directory: {}", dir.getAbsolutePath());
  269. if (!groups.containsKey(dir.getName())) {
  270. groups.put(dir.getName(), new ActionGroup(dir.getName()));
  271. }
  272. for (File file : dir.listFiles()) {
  273. factory.getAction(dir.getName(), file.getName());
  274. }
  275. }
  276. @Override
  277. public void addAction(final Action action) {
  278. checkNotNull(action);
  279. LOG.debug("Registering action: {}/{} (status: {})", action.getGroup(), action.getName(),
  280. action.getStatus());
  281. if (action.getStatus() != ActionStatus.FAILED) {
  282. for (ActionType trigger : action.getTriggers()) {
  283. LOG.trace("Action has trigger {}", trigger);
  284. actions.add(trigger, action);
  285. }
  286. }
  287. getOrCreateGroup(action.getGroup()).add(action);
  288. }
  289. @Override
  290. public ActionGroup getOrCreateGroup(final String name) {
  291. if (!groups.containsKey(name)) {
  292. groups.put(name, new ActionGroup(name));
  293. }
  294. return groups.get(name);
  295. }
  296. @Override
  297. public void removeAction(final Action action) {
  298. checkNotNull(action);
  299. actions.removeFromAll(action);
  300. getOrCreateGroup(action.getGroup()).remove(action);
  301. }
  302. @Override
  303. public void reregisterAction(final Action action) {
  304. removeAction(action);
  305. addAction(action);
  306. }
  307. @Override
  308. public boolean triggerEvent(final ActionType type,
  309. final StringBuffer format, final Object... arguments) {
  310. checkNotNull(type);
  311. checkNotNull(type.getType());
  312. checkArgument(type.getType().getArity() == arguments.length);
  313. LOG.trace("Calling listeners for event of type {}", type);
  314. boolean res = false;
  315. if (listeners.containsKey(type)) {
  316. for (ActionListener listener : new ArrayList<>(listeners.get(type))) {
  317. try {
  318. listener.processEvent(type, format, arguments);
  319. } catch (Exception e) {
  320. eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e,
  321. "Error processing action: " + e.getMessage(), ""));
  322. }
  323. }
  324. }
  325. if (!killSwitch) {
  326. res = triggerActions(type, format, arguments);
  327. }
  328. return !res;
  329. }
  330. /**
  331. * Triggers actions that respond to the specified type.
  332. *
  333. * @param type The type of the event to process
  334. * @param format The format of the message that's going to be displayed for the event.
  335. * Actions may change this format.
  336. * @param arguments The arguments for the event
  337. *
  338. * @return True if the event should be skipped, or false if it can continue
  339. */
  340. @Precondition("The specified ActionType is not null")
  341. private boolean triggerActions(final ActionType type,
  342. final StringBuffer format, final Object... arguments) {
  343. checkNotNull(type);
  344. boolean res = false;
  345. LOG.trace("Executing actions for event of type {}", type);
  346. if (actions.containsKey(type)) {
  347. for (Action action : new ArrayList<>(actions.get(type))) {
  348. try {
  349. if (action.getConcurrencyGroup() == null) {
  350. res |= action.trigger(format, arguments);
  351. } else {
  352. synchronized (locks) {
  353. if (!locks.containsKey(action.getConcurrencyGroup())) {
  354. locks.put(action.getConcurrencyGroup(), new Object());
  355. }
  356. }
  357. synchronized (locks.get(action.getConcurrencyGroup())) {
  358. res |= action.trigger(format, arguments);
  359. }
  360. }
  361. } catch (LinkageError | Exception e) {
  362. eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e,
  363. "Error processing action: " + e.getMessage(), ""));
  364. }
  365. }
  366. }
  367. return res;
  368. }
  369. /**
  370. * Processes an event from the event bus.
  371. *
  372. * @param event The event that was raised.
  373. */
  374. @Handler
  375. public void processEvent(final DMDircEvent event) {
  376. final ActionType type = getType(getLegacyActionTypeName(event));
  377. if (type == null) {
  378. LOG.warn("Unable to locate legacy type for event {}", event.getClass().getName());
  379. return;
  380. }
  381. final Class<?>[] argTypes = type.getType().getArgTypes();
  382. final Object[] arguments = getLegacyArguments(event, argTypes);
  383. if (event instanceof DisplayableEvent) {
  384. final DisplayableEvent displayable = (DisplayableEvent) event;
  385. final StringBuffer buffer = new StringBuffer(displayable.getDisplayFormat());
  386. triggerEvent(type, buffer, arguments);
  387. displayable.setDisplayFormat(buffer.toString());
  388. } else {
  389. triggerEvent(type, null, arguments);
  390. }
  391. }
  392. /**
  393. * Gets the name of the legacy {@link ActionType} to which the given event corresponds.
  394. *
  395. * @param event The event to obtain the name of.
  396. *
  397. * @return The legacy action type name.
  398. */
  399. private static String getLegacyActionTypeName(final DMDircEvent event) {
  400. return event.getClass().getSimpleName()
  401. .replaceAll("Event$", "")
  402. .replaceAll("(.)([A-Z])", "$1_$2")
  403. .toUpperCase();
  404. }
  405. /**
  406. * Attempts to obtain a legacy arguments array from the given event. Arguments will be matched
  407. * based on their expected classes. Where an event provides multiple getters of the same type,
  408. * the one closest in index to the argument index will be used.
  409. *
  410. * @param event The event to get legacy arguments for.
  411. * @param argTypes The type of arguments expected for the action type.
  412. *
  413. * @return An array of objects containing the legacy arguments.
  414. */
  415. private static Object[] getLegacyArguments(final DMDircEvent event, final Class<?>[] argTypes) {
  416. final Object[] arguments = new Object[argTypes.length];
  417. final Method[] methods = event.getClass().getMethods();
  418. for (int i = 0; i < argTypes.length; i++) {
  419. final Class<?> target = argTypes[i];
  420. Method best = null;
  421. int bestDistance = Integer.MAX_VALUE;
  422. for (int j = 0; j < methods.length; j++) {
  423. final Method method = methods[j];
  424. if (method.getParameterTypes().length == 0
  425. && method.getName().startsWith("get")
  426. && !method.getName().equals("getDisplayFormat")
  427. && method.getReturnType().equals(target)
  428. && Math.abs(j - i) < bestDistance) {
  429. bestDistance = Math.abs(j - i);
  430. best = method;
  431. }
  432. }
  433. if (best == null) {
  434. LOG.error("Unable to find method on event {} to satisfy argument #{} of class {}",
  435. event.getClass().getName(), i, target.getName());
  436. arguments[i] = null;
  437. } else {
  438. try {
  439. arguments[i] = best.invoke(event);
  440. } catch (ReflectiveOperationException ex) {
  441. LOG.error("Unable to invoke method {} on {} to get action argument",
  442. best.getName(), event.getClass().getName(), ex);
  443. }
  444. }
  445. }
  446. return arguments;
  447. }
  448. @Override
  449. public ActionGroup createGroup(final String group) {
  450. checkNotNull(group);
  451. checkArgument(!group.isEmpty());
  452. checkArgument(!groups.containsKey(group));
  453. final File file = new File(directory + group);
  454. if (file.isDirectory() || file.mkdir()) {
  455. final ActionGroup actionGroup = new ActionGroup(group);
  456. groups.put(group, actionGroup);
  457. return actionGroup;
  458. } else {
  459. throw new IllegalArgumentException("Unable to create action group directory"
  460. + "\n\nDir: " + directory + group);
  461. }
  462. }
  463. @Override
  464. public void deleteGroup(final String group) {
  465. checkNotNull(group);
  466. checkArgument(!group.isEmpty());
  467. checkArgument(groups.containsKey(group));
  468. for (Action action : groups.get(group).getActions()) {
  469. removeAction(action);
  470. }
  471. final File dir = new File(directory + group);
  472. if (dir.isDirectory()) {
  473. for (File file : dir.listFiles()) {
  474. if (!file.delete()) {
  475. eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
  476. "Unable to remove file: " + file.getAbsolutePath(), ""));
  477. return;
  478. }
  479. }
  480. }
  481. if (!dir.delete()) {
  482. eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
  483. "Unable to remove directory: " + dir.getAbsolutePath(), ""));
  484. return;
  485. }
  486. groups.remove(group);
  487. }
  488. @Override
  489. public void changeGroupName(final String oldName, final String newName) {
  490. checkNotNull(oldName);
  491. checkArgument(!oldName.isEmpty());
  492. checkNotNull(newName);
  493. checkArgument(!newName.isEmpty());
  494. checkArgument(groups.containsKey(oldName));
  495. checkArgument(!groups.containsKey(newName));
  496. checkArgument(!newName.equals(oldName));
  497. createGroup(newName);
  498. for (Action action : groups.get(oldName).getActions()) {
  499. action.setGroup(newName);
  500. getOrCreateGroup(oldName).remove(action);
  501. getOrCreateGroup(newName).add(action);
  502. }
  503. deleteGroup(oldName);
  504. }
  505. @Override
  506. public ActionType getType(final String type) {
  507. if (type == null || type.isEmpty()) {
  508. return null;
  509. }
  510. for (ActionType target : types) {
  511. if (target.name().equals(type)) {
  512. return target;
  513. }
  514. }
  515. return null;
  516. }
  517. @Override
  518. public List<ActionType> findCompatibleTypes(final ActionType type) {
  519. checkNotNull(type);
  520. final List<ActionType> res = new ArrayList<>();
  521. for (ActionType target : types) {
  522. if (!target.equals(type) && target.getType().equals(type.getType())) {
  523. res.add(target);
  524. }
  525. }
  526. return res;
  527. }
  528. @Override
  529. public List<ActionComponent> findCompatibleComponents(final Class<?> target) {
  530. checkNotNull(target);
  531. final List<ActionComponent> res = new ArrayList<>();
  532. for (ActionComponent subject : components) {
  533. if (subject.appliesTo().equals(target)) {
  534. res.add(subject);
  535. }
  536. }
  537. return res;
  538. }
  539. @Override
  540. public List<ActionComparison> findCompatibleComparisons(final Class<?> target) {
  541. checkNotNull(target);
  542. final List<ActionComparison> res = new ArrayList<>();
  543. for (ActionComparison subject : comparisons) {
  544. if (subject.appliesTo().equals(target)) {
  545. res.add(subject);
  546. }
  547. }
  548. return res;
  549. }
  550. @Override
  551. public ActionComponent getComponent(final String type) {
  552. checkNotNull(type);
  553. checkArgument(!type.isEmpty());
  554. for (ActionComponent target : components) {
  555. if (target.name().equals(type)) {
  556. return target;
  557. }
  558. }
  559. return null;
  560. }
  561. @Override
  562. public ActionComparison getComparison(final String type) {
  563. checkNotNull(type);
  564. checkArgument(!type.isEmpty());
  565. for (ActionComparison target : comparisons) {
  566. if (target.name().equals(type)) {
  567. return target;
  568. }
  569. }
  570. return null;
  571. }
  572. /**
  573. * Installs an action pack located at the specified path.
  574. *
  575. * @param path The full path of the action pack .zip.
  576. *
  577. * @throws IOException If the zip cannot be extracted
  578. */
  579. public static void installActionPack(final String path) throws IOException {
  580. final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
  581. ziprm.extractResources("", getActionManager().directory);
  582. getActionManager().loadUserActions();
  583. new File(path).delete();
  584. }
  585. @Override
  586. public void registerListener(final ActionListener listener, final ActionType... types) {
  587. for (ActionType type : types) {
  588. listeners.add(type, listener);
  589. }
  590. }
  591. @Override
  592. public void unregisterListener(final ActionListener listener, final ActionType... types) {
  593. for (ActionType type : types) {
  594. listeners.remove(type, listener);
  595. }
  596. }
  597. @Override
  598. public void unregisterListener(final ActionListener listener) {
  599. listeners.removeFromAll(listener);
  600. }
  601. }