123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /*
- * Copyright (c) 2006-2014 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.addons.serverlists;
-
- import com.dmdirc.interfaces.config.ConfigProvider;
- import com.dmdirc.interfaces.config.IdentityController;
-
- /**
- * Abstract base class for {@link ServerGroupItem}s.
- *
- * @since 0.6.4
- */
- public abstract class ServerGroupItemBase implements ServerGroupItem {
-
- /** The controller to read/write settings with. */
- private final IdentityController identityController;
- /** Whether or not this item has been modified. */
- private boolean modified;
- /** The name of the item. */
- private String name;
- /** The name of the profile to use. */
- private String profile;
-
- public ServerGroupItemBase(final IdentityController identityController) {
- this.identityController = identityController;
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isModified() {
- return modified;
- }
-
- /** {@inheritDoc} */
- @Override
- public void setModified(final boolean isModified) {
- this.modified = isModified;
- }
-
- /** {@inheritDoc} */
- @Override
- public String getName() {
- return name;
- }
-
- /** {@inheritDoc} */
- @Override
- public void setName(final String name) {
- setModified(true);
- this.name = name;
- }
-
- /** {@inheritDoc} */
- @Override
- public String getPath() {
- if (getParent() != null) {
- return getParent().getPath() + " → " + getName();
- }
- return getName();
- }
-
- /** {@inheritDoc} */
- @Override
- public String getProfile() {
- return profile;
- }
-
- /** {@inheritDoc} */
- @Override
- public void setProfile(final String profile) {
- setModified(true);
- this.profile = profile;
- }
-
- /**
- * Returns the parent group of this item, or
- * <code>null</code> if the item is a root group.
- *
- * @return This item's parent group
- */
- protected abstract ServerGroup getParent();
-
- /**
- * Returns the {@link ConfigProvider} which corresponds to this server's desired profile.
- *
- * @return This server's profile identity
- */
- protected ConfigProvider getProfileIdentity() {
- if (profile != null) {
- for (ConfigProvider identity : identityController.getProvidersByType("profile")) {
- if (profile.equals(identity.getName())) {
- return identity;
- }
- }
- }
-
- if (getParent() == null) {
- return identityController.getProvidersByType("profile").get(0);
- } else {
- return getParent().getProfileIdentity();
- }
- }
-
- }
|