Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Services.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.addons.debug.commands;
  23. import com.dmdirc.addons.debug.Debug;
  24. import com.dmdirc.addons.debug.DebugCommand;
  25. import com.dmdirc.commandparser.CommandArguments;
  26. import com.dmdirc.commandparser.commands.IntelligentCommand;
  27. import com.dmdirc.commandparser.commands.context.CommandContext;
  28. import com.dmdirc.interfaces.WindowModel;
  29. import com.dmdirc.plugins.Service;
  30. import com.dmdirc.plugins.ServiceManager;
  31. import com.dmdirc.plugins.ServiceProvider;
  32. import com.dmdirc.ui.input.AdditionalTabTargets;
  33. import javax.annotation.Nonnull;
  34. import javax.inject.Inject;
  35. import javax.inject.Provider;
  36. /**
  37. * Outputs information regarding available services.
  38. */
  39. public class Services extends DebugCommand implements IntelligentCommand {
  40. /** The service manager to get services from. */
  41. private final ServiceManager serviceManager;
  42. /**
  43. * Creates a new instance of the command.
  44. *
  45. * @param commandProvider The provider to use to access the main debug command.
  46. * @param serviceManager The service manager to get services from.
  47. */
  48. @Inject
  49. public Services(final Provider<Debug> commandProvider, final ServiceManager serviceManager) {
  50. super(commandProvider);
  51. this.serviceManager = serviceManager;
  52. }
  53. @Override
  54. public String getName() {
  55. return "services";
  56. }
  57. @Override
  58. public String getUsage() {
  59. return "[full] - Outputs available servers, optionally showing which"
  60. + " are active and which are not";
  61. }
  62. @Override
  63. public void execute(@Nonnull final WindowModel origin,
  64. final CommandArguments args, final CommandContext context) {
  65. sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Available Services:");
  66. for (Service service : serviceManager.getAllServices()) {
  67. sendLine(origin, args.isSilent(), FORMAT_OUTPUT, " "
  68. + service.toString());
  69. if (args.getArguments().length > 0
  70. && args.getArguments()[0].equals("full")) {
  71. for (ServiceProvider provider : service.getProviders()) {
  72. sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
  73. " " + provider.getProviderName()
  74. + " [Active: " + provider.isActive() + "]");
  75. }
  76. }
  77. }
  78. }
  79. @Override
  80. public AdditionalTabTargets getSuggestions(final int arg,
  81. final IntelligentCommandContext context) {
  82. final AdditionalTabTargets res = new AdditionalTabTargets();
  83. res.excludeAll();
  84. if (arg == 1) {
  85. res.add("full");
  86. }
  87. return res;
  88. }
  89. }