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.

Action.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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.DMDircMBassador;
  24. import com.dmdirc.GlobalWindow;
  25. import com.dmdirc.config.prefs.PreferencesSetting;
  26. import com.dmdirc.config.prefs.PreferencesType;
  27. import com.dmdirc.events.ActionCreatedEvent;
  28. import com.dmdirc.events.ActionDeletedEvent;
  29. import com.dmdirc.events.ActionUpdatedEvent;
  30. import com.dmdirc.interfaces.ActionController;
  31. import com.dmdirc.interfaces.actions.ActionComparison;
  32. import com.dmdirc.interfaces.actions.ActionComponent;
  33. import com.dmdirc.interfaces.actions.ActionType;
  34. import com.dmdirc.interfaces.config.ConfigChangeListener;
  35. import com.dmdirc.interfaces.config.IdentityController;
  36. import com.dmdirc.logger.ErrorLevel;
  37. import com.dmdirc.logger.Logger;
  38. import com.dmdirc.updater.Version;
  39. import com.dmdirc.util.io.ConfigFile;
  40. import com.dmdirc.util.io.InvalidConfigFileException;
  41. import java.io.IOException;
  42. import java.nio.file.FileSystem;
  43. import java.nio.file.Files;
  44. import java.util.ArrayList;
  45. import java.util.Arrays;
  46. import java.util.HashMap;
  47. import java.util.List;
  48. import java.util.Map;
  49. import javax.inject.Provider;
  50. /**
  51. * Describes a single action.
  52. */
  53. public class Action extends ActionModel implements ConfigChangeListener {
  54. /** The domain name for condition trees. */
  55. private static final String DOMAIN_CONDITIONTREE = "conditiontree";
  56. /** The domain name for format changes. */
  57. private static final String DOMAIN_FORMAT = "format";
  58. /** The domain name for meta-data. */
  59. private static final String DOMAIN_METADATA = "metadata";
  60. /** The domain name for response information. */
  61. private static final String DOMAIN_RESPONSE = "response";
  62. /** The domain name for triggers. */
  63. private static final String DOMAIN_TRIGGERS = "triggers";
  64. /** The domain name for concurrency. */
  65. private static final String DOMAIN_CONCURRENCY = "concurrency";
  66. /** The domain name for misc settings. */
  67. private static final String DOMAIN_MISC = "misc";
  68. /** The base directory to save actions in. */
  69. private final String actionsDirectory;
  70. /** The controller to use to read and update settings. */
  71. private final IdentityController identityController;
  72. /** The controller to use to retrieve components, comparisons, etc. */
  73. private final ActionController actionController;
  74. /** Event bus to post events to. */
  75. private final DMDircMBassador eventBus;
  76. /** The file system to read/write actions to. */
  77. private final FileSystem filesystem;
  78. /** The config file we're using. */
  79. protected ConfigFile config;
  80. /** The location of the file we're reading/saving. */
  81. private String location;
  82. /**
  83. * Creates a new instance of Action. The group and name specified must be the group and name of
  84. * a valid action already saved to disk.
  85. *
  86. * @param filesystem The file system to read/write actions to
  87. * @param eventBus Event bus to post events to
  88. * @param globalWindowProvider Provider of global windows for triggering actions.
  89. * @param substitutorFactory Factory to use to create action substitutors.
  90. * @param actionController The controller that owns this action.
  91. * @param identityController The controller to use to retrieve and update settings.
  92. * @param actionsDirectory The base directory to store actions in.
  93. * @param group The group the action belongs to
  94. * @param name The name of the action
  95. */
  96. public Action(final FileSystem filesystem, final DMDircMBassador eventBus,
  97. final Provider<GlobalWindow> globalWindowProvider,
  98. final ActionSubstitutorFactory substitutorFactory,
  99. final ActionController actionController, final IdentityController identityController,
  100. final String actionsDirectory, final String group, final String name) {
  101. super(globalWindowProvider, substitutorFactory, group, name);
  102. this.filesystem = filesystem;
  103. this.eventBus = eventBus;
  104. this.actionController = actionController;
  105. this.identityController = identityController;
  106. this.actionsDirectory = actionsDirectory;
  107. this.location = actionsDirectory + group + filesystem.getSeparator() + name;
  108. try {
  109. config = new ConfigFile(location);
  110. config.read();
  111. loadActionFromConfig();
  112. actionController.addAction(this);
  113. } catch (InvalidConfigFileException ex) {
  114. error(ActionErrorType.FILE, "Unable to parse action file: " + ex.getMessage());
  115. } catch (IOException ex) {
  116. error(ActionErrorType.FILE, "I/O error when loading action: " + ex.getMessage());
  117. }
  118. identityController.getGlobalConfiguration().addChangeListener("disable_action",
  119. (group + "/" + name).replace(' ', '.'), this);
  120. checkDisabled();
  121. }
  122. /**
  123. * Creates a new instance of Action with the specified properties and saves it to disk.
  124. *
  125. * @param filesystem The file system to read/write actions to
  126. * @param eventBus Event bus to post events to
  127. * @param globalWindowProvider Provider of global windows for triggering actions.
  128. * @param substitutorFactory Factory to use to create action substitutors.
  129. * @param actionController The controller that owns this action.
  130. * @param identityController The controller to use to retrieve and update settings.
  131. * @param actionsDirectory The base directory to store actions in.
  132. * @param group The group the action belongs to
  133. * @param name The name of the action
  134. * @param triggers The triggers to use
  135. * @param response The response to use
  136. * @param conditions The conditions to use
  137. * @param conditionTree The condition tree to use
  138. * @param newFormat The new formatter to use
  139. */
  140. public Action(final FileSystem filesystem, final DMDircMBassador eventBus,
  141. final Provider<GlobalWindow> globalWindowProvider,
  142. final ActionSubstitutorFactory substitutorFactory,
  143. final ActionController actionController, final IdentityController identityController,
  144. final String actionsDirectory, final String group, final String name,
  145. final ActionType[] triggers, final String[] response,
  146. final List<ActionCondition> conditions, final ConditionTree conditionTree,
  147. final String newFormat) {
  148. super(globalWindowProvider, substitutorFactory, group, name,
  149. triggers, response, conditions, conditionTree, newFormat);
  150. this.filesystem = filesystem;
  151. this.eventBus = eventBus;
  152. this.actionController = actionController;
  153. this.identityController = identityController;
  154. this.actionsDirectory = actionsDirectory;
  155. this.location = actionsDirectory + group + filesystem.getSeparator()
  156. + name.replaceAll("[^A-Za-z0-9\\-_]", "_");
  157. try {
  158. Files.createDirectories(filesystem.getPath(actionsDirectory, group));
  159. } catch (IOException ex) {
  160. //TODO we don't handle the error now, but we should
  161. }
  162. save();
  163. identityController.getGlobalConfiguration().addChangeListener("disable_action",
  164. (group + "/" + name).replace(' ', '.'), this);
  165. checkDisabled();
  166. actionController.addAction(this);
  167. //TODO This needs to be done somewhere else, remove eventbus when it is.
  168. eventBus.publishAsync(new ActionCreatedEvent(this));
  169. }
  170. /**
  171. * Loads this action from the config instance.
  172. */
  173. protected void loadActionFromConfig() {
  174. if (config.isFlatDomain(DOMAIN_TRIGGERS)) {
  175. if (!loadTriggers(config.getFlatDomain(DOMAIN_TRIGGERS))) {
  176. return;
  177. }
  178. } else {
  179. error(ActionErrorType.TRIGGERS, "No trigger specified");
  180. return;
  181. }
  182. if (config.isFlatDomain(DOMAIN_RESPONSE)) {
  183. response = new String[config.getFlatDomain(DOMAIN_RESPONSE).size()];
  184. int i = 0;
  185. for (String line : config.getFlatDomain(DOMAIN_RESPONSE)) {
  186. response[i++] = line;
  187. }
  188. } else {
  189. error(ActionErrorType.RESPONSE, "No response specified");
  190. return;
  191. }
  192. if (config.isFlatDomain(DOMAIN_FORMAT)) {
  193. newFormat = config.getFlatDomain(DOMAIN_FORMAT).isEmpty() ? ""
  194. : config.getFlatDomain(DOMAIN_FORMAT).get(0);
  195. }
  196. for (int cond = 0; config.isKeyDomain("condition " + cond); cond++) {
  197. if (!readCondition(config.getKeyDomain("condition " + cond))) {
  198. return;
  199. }
  200. }
  201. if (config.isFlatDomain(DOMAIN_CONDITIONTREE)
  202. && config.getFlatDomain(DOMAIN_CONDITIONTREE).size() > 0) {
  203. conditionTree = ConditionTree.parseString(
  204. config.getFlatDomain(DOMAIN_CONDITIONTREE).get(0));
  205. if (conditionTree == null) {
  206. error(ActionErrorType.CONDITION_TREE, "Unable to parse condition tree");
  207. return;
  208. }
  209. if (conditionTree.getMaximumArgument() >= conditions.size()) {
  210. error(ActionErrorType.CONDITION_TREE, "Condition tree references condition "
  211. + conditionTree.getMaximumArgument() + " but there are"
  212. + " only " + conditions.size() + " conditions");
  213. return;
  214. }
  215. }
  216. if (config.isKeyDomain(DOMAIN_CONCURRENCY)
  217. && config.getKeyDomain(DOMAIN_CONCURRENCY).containsKey("group")) {
  218. setConcurrencyGroup(config.getKeyDomain(DOMAIN_CONCURRENCY).get("group"));
  219. }
  220. if (config.isKeyDomain(DOMAIN_MISC)
  221. && config.getKeyDomain(DOMAIN_MISC).containsKey("stopping")) {
  222. setStopping(Boolean.parseBoolean(config.getKeyDomain(DOMAIN_MISC).get("stopping")));
  223. }
  224. if (status == ActionStatus.DISABLED) {
  225. status = ActionStatus.ACTIVE;
  226. }
  227. checkMetaData();
  228. }
  229. /**
  230. * Checks to see if this action contains group meta-data, and adds it to the group as
  231. * appropriate.
  232. */
  233. private void checkMetaData() {
  234. if (config.isKeyDomain(DOMAIN_METADATA)) {
  235. final ActionGroup myGroup = actionController.getOrCreateGroup(group);
  236. final Map<String, String> data = config.getKeyDomain(DOMAIN_METADATA);
  237. if (data.containsKey("description")) {
  238. myGroup.setDescription(data.get("description"));
  239. }
  240. if (data.containsKey("author")) {
  241. myGroup.setAuthor(data.get("author"));
  242. }
  243. if (data.containsKey("version")) {
  244. myGroup.setVersion(new Version(data.get("version")));
  245. }
  246. if (data.containsKey("component")) {
  247. try {
  248. myGroup.setComponent(Integer.parseInt(data.get("component")));
  249. } catch (NumberFormatException ex) {
  250. // Do nothing
  251. }
  252. }
  253. }
  254. for (int i = 0; config.isKeyDomain("setting " + i); i++) {
  255. final ActionGroup myGroup = actionController.getOrCreateGroup(group);
  256. final Map<String, String> data = config.getKeyDomain("setting " + i);
  257. if (data.containsKey("type") && data.containsKey("setting")
  258. && data.containsKey("title") && data.containsKey("default")
  259. && data.containsKey("tooltip")) {
  260. actionController.registerSetting(data.get("setting"), data.get("default"));
  261. myGroup.getSettings().put(data.get("setting"), new PreferencesSetting(
  262. PreferencesType.valueOf(data.get("type")), "actions",
  263. data.get("setting"), data.get("title"), data.get("tooltip"),
  264. identityController.getGlobalConfiguration(),
  265. identityController.getUserSettings()));
  266. }
  267. }
  268. }
  269. /**
  270. * Loads a list of triggers with the specified names.
  271. *
  272. * @param newTriggers A list of trigger names
  273. *
  274. * @return True if all triggers are valid and compatible, false otherwise.
  275. */
  276. private boolean loadTriggers(final List<String> newTriggers) {
  277. triggers = new ActionType[newTriggers.size()];
  278. for (int i = 0; i < triggers.length; i++) {
  279. triggers[i] = actionController.getType(newTriggers.get(i));
  280. if (triggers[i] == null) {
  281. error(ActionErrorType.TRIGGERS, "Invalid trigger specified: " + newTriggers.get(i));
  282. return false;
  283. } else if (i != 0 && !triggers[i].getType().equals(triggers[0].getType())) {
  284. error(ActionErrorType.TRIGGERS, "Triggers are not compatible");
  285. return false;
  286. }
  287. }
  288. return true;
  289. }
  290. /**
  291. * Called to save the action.
  292. */
  293. public void save() {
  294. if (!isModified()) {
  295. return;
  296. }
  297. final ConfigFile newConfig = new ConfigFile(location);
  298. final List<String> triggerNames = new ArrayList<>();
  299. final List<String> responseLines = new ArrayList<>();
  300. responseLines.addAll(Arrays.asList(response));
  301. for (ActionType trigger : triggers) {
  302. if (trigger == null) {
  303. Logger.appError(ErrorLevel.LOW, "ActionType was null",
  304. new IllegalArgumentException("Triggers: "
  305. + Arrays.toString(triggers)));
  306. continue;
  307. }
  308. triggerNames.add(trigger.toString());
  309. }
  310. newConfig.addDomain(DOMAIN_TRIGGERS, triggerNames);
  311. newConfig.addDomain(DOMAIN_RESPONSE, responseLines);
  312. if (conditionTree != null) {
  313. newConfig.addDomain(DOMAIN_CONDITIONTREE, new ArrayList<String>());
  314. newConfig.getFlatDomain(DOMAIN_CONDITIONTREE).add(conditionTree.toString());
  315. }
  316. if (newFormat != null) {
  317. newConfig.addDomain(DOMAIN_FORMAT, new ArrayList<String>());
  318. newConfig.getFlatDomain(DOMAIN_FORMAT).add(newFormat);
  319. }
  320. if (concurrencyGroup != null) {
  321. newConfig.addDomain(DOMAIN_CONCURRENCY, new HashMap<String, String>());
  322. newConfig.getKeyDomain(DOMAIN_CONCURRENCY).put("group", concurrencyGroup);
  323. }
  324. if (stop) {
  325. newConfig.addDomain(DOMAIN_MISC, new HashMap<String, String>());
  326. newConfig.getKeyDomain(DOMAIN_MISC).put("stopping", "true");
  327. }
  328. int i = 0;
  329. for (ActionCondition condition : conditions) {
  330. final Map<String, String> data = new HashMap<>();
  331. data.put("argument", String.valueOf(condition.getArg()));
  332. if (condition.getArg() == -1) {
  333. data.put("starget", condition.getStarget());
  334. } else {
  335. data.put("component", condition.getComponent().toString());
  336. }
  337. data.put("comparison", condition.getComparison().toString());
  338. data.put("target", condition.getTarget());
  339. newConfig.addDomain("condition " + i, data);
  340. i++;
  341. }
  342. if (config != null) {
  343. // Preserve any meta-data
  344. if (config.isKeyDomain(DOMAIN_METADATA)) {
  345. newConfig.addDomain(DOMAIN_METADATA, config.getKeyDomain(DOMAIN_METADATA));
  346. }
  347. for (i = 0; config.isKeyDomain("setting " + i); i++) {
  348. newConfig.addDomain("setting " + i, config.getKeyDomain("setting " + i));
  349. }
  350. }
  351. try {
  352. newConfig.write();
  353. resetModified();
  354. } catch (IOException ex) {
  355. Logger.userError(ErrorLevel.HIGH, "I/O error when saving action: "
  356. + group + "/" + name + ": " + ex.getMessage());
  357. }
  358. eventBus.publishAsync(new ActionUpdatedEvent(this));
  359. }
  360. /**
  361. * Reads a condition from the specified configuration section.
  362. *
  363. * @param data The relevant section of the action configuration
  364. *
  365. * @return True if the condition is valid, false otherwise
  366. */
  367. private boolean readCondition(final Map<String, String> data) {
  368. int arg;
  369. ActionComponent component = null;
  370. ActionComparison comparison;
  371. String target;
  372. String starget = null;
  373. // ------ Read the argument
  374. try {
  375. arg = Integer.parseInt(data.get("argument"));
  376. } catch (NumberFormatException ex) {
  377. error(ActionErrorType.CONDITIONS,
  378. "Invalid argument number specified: " + data.get("argument"));
  379. return false;
  380. }
  381. if (arg < -1 || arg >= triggers[0].getType().getArity()) {
  382. error(ActionErrorType.CONDITIONS, "Invalid argument number specified: " + arg);
  383. return false;
  384. }
  385. // ------ Read the component or the source
  386. if (arg == -1) {
  387. starget = data.get("starget");
  388. if (starget == null) {
  389. error(ActionErrorType.CONDITIONS, "No starget specified");
  390. return false;
  391. }
  392. } else {
  393. component = readComponent(data, arg);
  394. if (component == null) {
  395. return false;
  396. }
  397. }
  398. // ------ Read the comparison
  399. comparison = actionController.getComparison(data.get("comparison"));
  400. if (comparison == null) {
  401. error(ActionErrorType.CONDITIONS, "Invalid comparison specified: "
  402. + data.get("comparison"));
  403. return false;
  404. }
  405. if ((arg != -1 && !comparison.appliesTo().equals(component.getType()))
  406. || (arg == -1 && !comparison.appliesTo().equals(String.class))) {
  407. error(ActionErrorType.CONDITIONS,
  408. "Comparison cannot be applied to specified component: " + data.get("comparison"));
  409. return false;
  410. }
  411. // ------ Read the target
  412. target = data.get("target");
  413. if (target == null) {
  414. error(ActionErrorType.CONDITIONS, "No target specified for condition");
  415. return false;
  416. }
  417. if (arg == -1) {
  418. conditions.add(new ActionCondition(starget, comparison, target));
  419. } else {
  420. conditions.add(new ActionCondition(arg, component, comparison, target));
  421. }
  422. return true;
  423. }
  424. /**
  425. * Reads a component from the specified data section for the specified argument.
  426. *
  427. * @param data The relevant section of the action configuration
  428. * @param arg The argument number that the component should apply to
  429. *
  430. * @return The corresponding ActionComponent, or null if the specified component is invalid.
  431. */
  432. private ActionComponent readComponent(final Map<String, String> data, final int arg) {
  433. final String componentName = data.get("component");
  434. ActionComponent component;
  435. if (componentName.indexOf('.') == -1) {
  436. component = actionController.getComponent(componentName);
  437. } else {
  438. try {
  439. component = new ActionComponentChain(triggers[0].getType().getArgTypes()[arg],
  440. componentName, actionController);
  441. } catch (IllegalArgumentException iae) {
  442. error(ActionErrorType.CONDITIONS, iae.getMessage());
  443. return null;
  444. }
  445. }
  446. if (component == null) {
  447. error(ActionErrorType.CONDITIONS, "Unknown component: " + componentName);
  448. return null;
  449. }
  450. if (!component.appliesTo().equals(triggers[0].getType().getArgTypes()[arg])) {
  451. error(ActionErrorType.CONDITIONS,
  452. "Component cannot be applied to specified arg in condition: " + componentName);
  453. return null;
  454. }
  455. return component;
  456. }
  457. /**
  458. * Raises a trivial error, informing the user of the problem.
  459. *
  460. * @param type The type of error that occurred.
  461. * @param message The message to be raised
  462. */
  463. private void error(final ActionErrorType type, final String message) {
  464. this.error = message;
  465. this.errorType = type;
  466. this.status = ActionStatus.FAILED;
  467. Logger.userError(ErrorLevel.LOW, "Error when parsing action: "
  468. + group + "/" + name + ": " + message);
  469. }
  470. @Override
  471. public void setName(final String newName) {
  472. super.setName(newName);
  473. try {
  474. Files.delete(filesystem.getPath(location));
  475. } catch (IOException ex) {
  476. //TODO we don't handle the error now, but we should
  477. }
  478. location = actionsDirectory + group + filesystem.getSeparator() + newName;
  479. save();
  480. }
  481. @Override
  482. public void setGroup(final String newGroup) {
  483. super.setGroup(newGroup);
  484. try {
  485. Files.delete(filesystem.getPath(location));
  486. } catch (IOException ex) {
  487. //TODO we don't handle the error now, but we should
  488. }
  489. final String dir = actionsDirectory + group + filesystem.getSeparator();
  490. location = dir + name;
  491. try {
  492. Files.createDirectories(filesystem.getPath(location));
  493. } catch (IOException ex) {
  494. //TODO we don't handle the error now, but we should
  495. }
  496. save();
  497. }
  498. /**
  499. * Deletes this action.
  500. */
  501. public void delete() {
  502. eventBus.publishAsync(new ActionDeletedEvent(actionController.getOrCreateGroup(getGroup()), this));
  503. try {
  504. Files.delete(filesystem.getPath(location));
  505. } catch (IOException ex) {
  506. //TODO we don't handle the error now, but we should
  507. }
  508. }
  509. @Override
  510. public String toString() {
  511. final String parent = super.toString();
  512. return parent.substring(0, parent.length() - 1) + ",location=" + location + "]";
  513. }
  514. @Override
  515. public void configChanged(final String domain, final String key) {
  516. checkDisabled();
  517. }
  518. /**
  519. * Checks if this action is disabled or not.
  520. *
  521. * @since 0.6.3
  522. */
  523. protected void checkDisabled() {
  524. final String key = (group + "/" + name).replace(' ', '.');
  525. final boolean disabled = identityController.getGlobalConfiguration().hasOptionBool(
  526. "disable_action", key)
  527. && identityController.getGlobalConfiguration().getOptionBool("disable_action", key);
  528. if (disabled && status == ActionStatus.ACTIVE) {
  529. status = ActionStatus.DISABLED;
  530. } else if (!disabled && status == ActionStatus.DISABLED) {
  531. status = ActionStatus.ACTIVE;
  532. }
  533. }
  534. /**
  535. * Sets whether this action is enabled or not.
  536. *
  537. * @param enabled true to enable, false to disable
  538. */
  539. public void setEnabled(final boolean enabled) {
  540. if (enabled) {
  541. identityController.getUserSettings().unsetOption("disable_action",
  542. (group + "/" + name).replace(' ', '.'));
  543. } else {
  544. identityController.getUserSettings().setOption("disable_action",
  545. (group + "/" + name).replace(' ', '.'), true);
  546. }
  547. }
  548. }