Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.serverlists;
  23. import com.dmdirc.config.Identity;
  24. import com.dmdirc.config.IdentityManager;
  25. /**
  26. * Abstract base class for {@link ServerGroupItem}s.
  27. *
  28. * @author chris
  29. * @since 0.6.4
  30. */
  31. public abstract class ServerGroupItemBase implements ServerGroupItem {
  32. /** Whether or not this item has been modified. */
  33. private boolean modified;
  34. /** The name of the item. */
  35. private String name;
  36. /** The name of the profile to use. */
  37. private String profile;
  38. /** {@inheritDoc} */
  39. @Override
  40. public boolean isModified() {
  41. return modified;
  42. }
  43. /** {@inheritDoc} */
  44. @Override
  45. public void setModified(final boolean isModified) {
  46. this.modified = isModified;
  47. }
  48. /** {@inheritDoc} */
  49. @Override
  50. public String getName() {
  51. return name;
  52. }
  53. /** {@inheritDoc} */
  54. @Override
  55. public void setName(final String name) {
  56. setModified(true);
  57. this.name = name;
  58. }
  59. /** {@inheritDoc} */
  60. @Override
  61. public String getPath() {
  62. if (getParent() != null) {
  63. return getParent().getPath() + " → " + getName();
  64. }
  65. return getName();
  66. }
  67. /** {@inheritDoc} */
  68. @Override
  69. public String getProfile() {
  70. return profile;
  71. }
  72. /** {@inheritDoc} */
  73. @Override
  74. public void setProfile(final String profile) {
  75. setModified(true);
  76. this.profile = profile;
  77. }
  78. /**
  79. * Returns the parent group of this item, or <code>null</code> if the
  80. * item is a root group.
  81. *
  82. * @return This item's parent group
  83. */
  84. protected abstract ServerGroup getParent();
  85. /**
  86. * Returns the {@link Identity} which corresponds to this server's desired
  87. * profile.
  88. *
  89. * @return This server's profile identity
  90. */
  91. protected Identity getProfileIdentity() {
  92. if (profile != null) {
  93. for (Identity identity : IdentityManager.getCustomIdentities("profile")) {
  94. if (profile.equals(identity.getName())) {
  95. return identity;
  96. }
  97. }
  98. }
  99. if (getParent() == null) {
  100. return IdentityManager.getCustomIdentities("profile").get(0);
  101. } else {
  102. return getParent().getProfileIdentity();
  103. }
  104. }
  105. }