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.

ActionFactory.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) 2006-2015 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.DMDircMBassador;
  24. import com.dmdirc.GlobalWindow;
  25. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  26. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  27. import com.dmdirc.interfaces.ActionController;
  28. import com.dmdirc.interfaces.actions.ActionType;
  29. import com.dmdirc.interfaces.config.IdentityController;
  30. import java.nio.file.Path;
  31. import java.util.List;
  32. import javax.inject.Inject;
  33. import javax.inject.Provider;
  34. import javax.inject.Singleton;
  35. /**
  36. * Factory for creating {@link Action}s.
  37. */
  38. @Singleton
  39. public class ActionFactory {
  40. /** The controller that will own actions. */
  41. private final Provider<ActionController> actionController;
  42. /** The controller to use to retrieve and update settings. */
  43. private final Provider<IdentityController> identityController;
  44. /** The global window to use for actions without windows. */
  45. private final Provider<GlobalWindow> globalWindowProvider;
  46. /** The factory to use to create substitutors. */
  47. private final ActionSubstitutorFactory substitutorFactory;
  48. /** The base directory to store actions in. */
  49. private final Path actionsDirectory;
  50. /** Event bus to post events on. */
  51. private final DMDircMBassador eventBus;
  52. /**
  53. * Creates a new instance of {@link ActionFactory}.
  54. *
  55. * @param eventBus The event bus to post events on.
  56. * @param actionController The controller that will own actions.
  57. * @param identityController The controller to use to retrieve and update settings.
  58. * @param globalWindowProvider The global window to use for actions without windows.
  59. * @param substitutorFactory The factory to use to create substitutors.
  60. * @param actionsDirectory The base directory to store actions in.
  61. */
  62. @Inject
  63. public ActionFactory(final DMDircMBassador eventBus, final Provider<ActionController> actionController,
  64. final Provider<IdentityController> identityController,
  65. final Provider<GlobalWindow> globalWindowProvider,
  66. final ActionSubstitutorFactory substitutorFactory,
  67. @Directory(DirectoryType.ACTIONS) final Path actionsDirectory) {
  68. this.eventBus = eventBus;
  69. this.actionController = actionController;
  70. this.identityController = identityController;
  71. this.globalWindowProvider = globalWindowProvider;
  72. this.substitutorFactory = substitutorFactory;
  73. this.actionsDirectory = actionsDirectory;
  74. }
  75. /**
  76. * Creates a new instance of Action. The group and name specified must be the group and name of
  77. * a valid action already saved to disk.
  78. *
  79. * @param group The group the action belongs to
  80. * @param name The name of the action
  81. *
  82. * @return A relevant action.
  83. */
  84. public Action getAction(final String group, final String name) {
  85. return new Action(
  86. eventBus, globalWindowProvider,
  87. substitutorFactory,
  88. actionController.get(),
  89. identityController.get(),
  90. actionsDirectory,
  91. group,
  92. name);
  93. }
  94. /**
  95. * Creates a new instance of Action with the specified properties and saves it to disk.
  96. *
  97. * @param group The group the action belongs to
  98. * @param name The name of the action
  99. * @param triggers The triggers to use
  100. * @param response The response to use
  101. * @param conditions The conditions to use
  102. * @param conditionTree The condition tree to use
  103. * @param newFormat The new formatter to use
  104. *
  105. * @return A relevant action.
  106. */
  107. public Action getAction(final String group, final String name,
  108. final ActionType[] triggers, final String[] response,
  109. final List<ActionCondition> conditions,
  110. final ConditionTree conditionTree, final String newFormat) {
  111. return new Action(
  112. eventBus, globalWindowProvider,
  113. substitutorFactory,
  114. actionController.get(),
  115. identityController.get(),
  116. actionsDirectory,
  117. group,
  118. name,
  119. triggers,
  120. response,
  121. conditions,
  122. conditionTree,
  123. newFormat);
  124. }
  125. }