001/*
002 * (C) Copyright 2011-2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     tdelprat
016 *
017 */
018
019package org.nuxeo.wizard.download;
020
021import java.util.ArrayList;
022import java.util.List;
023
024/**
025 * @author Tiry (tdelprat@nuxeo.com)
026 * @since 5.5
027 */
028public class DownloadablePackageOption {
029
030    protected final DownloadPackage pkg;
031
032    protected boolean exclusive;
033
034    protected boolean selected = false;
035
036    protected String label;
037
038    protected List<DownloadablePackageOption> childrenPackages = new ArrayList<>();
039
040    protected final String id;
041
042    protected DownloadablePackageOption parent;
043
044    public DownloadablePackageOption(DownloadPackage pkg, int idx) {
045        this.pkg = pkg;
046        // this.id = UUID.randomUUID().toString();
047        id = "o" + idx;
048    }
049
050    public DownloadablePackageOption(DownloadPackage pkg, String id) {
051        this.pkg = pkg;
052        this.id = id;
053    }
054
055    public boolean isExclusive() {
056        return exclusive;
057    }
058
059    public void setExclusive(boolean exclusive) {
060        this.exclusive = exclusive;
061    }
062
063    public void setExclusive(String exclusive) {
064        if (exclusive != null) {
065            if ("true".equalsIgnoreCase(exclusive)) {
066                this.exclusive = true;
067            } else {
068                this.exclusive = false;
069            }
070        }
071    }
072
073    public boolean isSelected() {
074        return selected;
075    }
076
077    public void setSelected(boolean selected) {
078        this.selected = selected;
079    }
080
081    public List<DownloadablePackageOption> getChildrenPackages() {
082        return childrenPackages;
083    }
084
085    public void addChildPackage(DownloadablePackageOption child) {
086        childrenPackages.add(child);
087        child.setParent(this);
088    }
089
090    protected void setParent(DownloadablePackageOption parent) {
091        this.parent = parent;
092    }
093
094    public List<DownloadablePackageOption> getSiblingPackages() {
095
096        List<DownloadablePackageOption> siblings = new ArrayList<>();
097        if (parent != null) {
098            for (DownloadablePackageOption sibling : parent.getChildrenPackages()) {
099                if (sibling.getId() != getId()) {
100                    siblings.add(sibling);
101                }
102            }
103        }
104        return siblings;
105    }
106
107    public String getLabel() {
108        if (label == null && pkg != null) {
109            return pkg.getLabel();
110        }
111        return label;
112    }
113
114    public void setLabel(String label) {
115        this.label = label;
116    }
117
118    public DownloadPackage getPackage() {
119        return pkg;
120    }
121
122    public String getId() {
123        return id;
124    }
125
126    public String getColor() {
127        if (pkg != null) {
128            return pkg.getColor();
129        }
130        return "";
131    }
132
133    public String getTextColor() {
134        if (pkg != null) {
135            return pkg.getTextColor();
136        }
137        return "";
138    }
139
140    public DownloadablePackageOption getParent() {
141        return parent;
142    }
143
144    public String getShortLabel() {
145        if (pkg != null) {
146            return pkg.getShortLabel();
147        }
148        return null;
149    }
150}