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.

AliasDialogModel.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.interfaces.ui;
  23. import com.dmdirc.commandparser.aliases.Alias;
  24. import com.dmdirc.util.validators.Validator;
  25. import java.util.Collection;
  26. import java.util.Optional;
  27. /**
  28. * Model representing a list of aliases in a dialog.
  29. */
  30. public interface AliasDialogModel {
  31. /**
  32. * Loads the model.
  33. */
  34. void loadModel();
  35. /**
  36. * Gets the aliases in this model.
  37. *
  38. * @return Aliases in this model
  39. */
  40. Collection<Alias> getAliases();
  41. /**
  42. * Returns an alias with the given name from the model.
  43. *
  44. * @param name Name of the alias to find
  45. *
  46. * @return An option Alias from the model
  47. */
  48. Optional<Alias> getAlias(final String name);
  49. /**
  50. * Adds an alias to the model.
  51. *
  52. * @param name Name for the new alias
  53. * @param minArguments Minimum number of arguments for the new alias
  54. * @param substitution Substitution for the new alias
  55. */
  56. void addAlias(String name, int minArguments, String substitution);
  57. /**
  58. * Edits the specified alias in the model.
  59. *
  60. * @param name Name of the alias to edit
  61. * @param minArguments Minimum number of arguments for the new alias
  62. * @param substitution Substitution for the new alias
  63. */
  64. void editAlias(final String name, int minArguments, String substitution);
  65. /**
  66. * Renames an existing alias in the model.
  67. *
  68. * @param oldName Old name for the alias
  69. * @param newName New name for the alias
  70. */
  71. void renameAlias(final String oldName, final String newName);
  72. /**
  73. * Removes the named alias from the model.
  74. *
  75. * @param name Name of the alias to remove
  76. */
  77. void removeAlias(final String name);
  78. /**
  79. * Saves the contents of this model to the alias manager.
  80. */
  81. void save();
  82. /**
  83. * Sets the selected alias.
  84. *
  85. * @param alias Optional alias to set
  86. */
  87. void setSelectedAlias(final Optional<Alias> alias);
  88. /**
  89. * Returns the currently selected alias.
  90. *
  91. * @return Optional for the selected alias
  92. */
  93. Optional<Alias> getSelectedAlias();
  94. /**
  95. * Gets the name of the selected alias.
  96. *
  97. * @return Selected alias name
  98. */
  99. String getSelectedAliasName();
  100. /**
  101. * Gets the minimum arguments of the selected alias.
  102. *
  103. * @return Selected alias minimum arguments
  104. */
  105. int getSelectedAliasMinimumArguments();
  106. /**
  107. * Gets the substitution of the selected alias.
  108. *
  109. * @return Selected alias substitution
  110. */
  111. String getSelectedAliasSubstitution();
  112. /**
  113. * Sets the name of the selected alias.
  114. *
  115. * @param aliasName New name
  116. */
  117. void setSelectedAliasName(final String aliasName);
  118. /**
  119. * Sets the minimum arguments of the selected alias.
  120. *
  121. * @param minArgs New minimum arguments
  122. */
  123. void setSelectedAliasMinimumArguments(final int minArgs);
  124. /**
  125. * Sets the substitution of the selected alias.
  126. *
  127. * @param substitution New substitution
  128. */
  129. void setSelectedAliasSubstitution(final String substitution);
  130. /**
  131. * Tests whether the current command is valid.
  132. *
  133. * @return true if valid
  134. */
  135. boolean isCommandValid();
  136. /**
  137. * Tests whether the current minimum arguments is valid.
  138. *
  139. * @return true if valid
  140. */
  141. boolean isMinimumArgumentsValid();
  142. /**
  143. * Tests whether the current substitution is valid.
  144. *
  145. * @return true if valid
  146. */
  147. boolean isSubstitutionValid();
  148. /**
  149. * Tests whether the dialog can be saved.
  150. *
  151. * @return true if valid
  152. */
  153. boolean isSelectedAliasValid();
  154. /**
  155. * Tests whether the dialog is allowed to change the selection.
  156. *
  157. * @return true if allowed
  158. */
  159. boolean isChangeAliasAllowed();
  160. /**
  161. * Gets a validator for changing the command of an existing alias.
  162. *
  163. * @return Command name validator
  164. */
  165. Validator<String> getCommandValidator();
  166. /**
  167. * Gets a validator for the command of a new alias.
  168. *
  169. * @return Command name validator
  170. */
  171. Validator<String> getNewCommandValidator();
  172. /**
  173. * Gets a validator for the minimum arguments of an alias.
  174. *
  175. * @return Arguments validator
  176. */
  177. Validator<Integer> getMinimumArgumentsValidator();
  178. /**
  179. * Gets a validator for the substitution of an alias.
  180. *
  181. * @return Substitution validator
  182. */
  183. Validator<String> getSubstitutionValidator();
  184. /**
  185. * Adds an alias listener, will be notified of changes to the model.
  186. *
  187. * @param listener Listener to add
  188. */
  189. void addListener(final AliasDialogModelListener listener);
  190. /**
  191. * Removes a listener from the model.
  192. *
  193. * @param listener Listener to add
  194. */
  195. void removeListener(final AliasDialogModelListener listener);
  196. }