001/* 002 * (C) Copyright 2011-2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * tdelprat 018 * 019 */ 020 021package org.nuxeo.wizard.download; 022 023import java.util.ArrayList; 024import java.util.List; 025 026/** 027 * @author Tiry (tdelprat@nuxeo.com) 028 * @since 5.5 029 */ 030public class DownloadablePackageOption { 031 032 protected final DownloadPackage pkg; 033 034 protected boolean exclusive; 035 036 protected boolean selected = false; 037 038 protected String label; 039 040 protected List<DownloadablePackageOption> childrenPackages = new ArrayList<>(); 041 042 protected final String id; 043 044 protected DownloadablePackageOption parent; 045 046 public DownloadablePackageOption(DownloadPackage pkg, int idx) { 047 this.pkg = pkg; 048 // this.id = UUID.randomUUID().toString(); 049 id = "o" + idx; 050 } 051 052 public DownloadablePackageOption(DownloadPackage pkg, String id) { 053 this.pkg = pkg; 054 this.id = id; 055 } 056 057 public boolean isExclusive() { 058 return exclusive; 059 } 060 061 public void setExclusive(boolean exclusive) { 062 this.exclusive = exclusive; 063 } 064 065 public void setExclusive(String exclusive) { 066 if (exclusive != null) { 067 if ("true".equalsIgnoreCase(exclusive)) { 068 this.exclusive = true; 069 } else { 070 this.exclusive = false; 071 } 072 } 073 } 074 075 public boolean isSelected() { 076 return selected; 077 } 078 079 public void setSelected(boolean selected) { 080 this.selected = selected; 081 } 082 083 public List<DownloadablePackageOption> getChildrenPackages() { 084 return childrenPackages; 085 } 086 087 public void addChildPackage(DownloadablePackageOption child) { 088 childrenPackages.add(child); 089 child.setParent(this); 090 } 091 092 protected void setParent(DownloadablePackageOption parent) { 093 this.parent = parent; 094 } 095 096 public List<DownloadablePackageOption> getSiblingPackages() { 097 098 List<DownloadablePackageOption> siblings = new ArrayList<>(); 099 if (parent != null) { 100 for (DownloadablePackageOption sibling : parent.getChildrenPackages()) { 101 if (sibling.getId() != getId()) { 102 siblings.add(sibling); 103 } 104 } 105 } 106 return siblings; 107 } 108 109 public String getLabel() { 110 if (label == null && pkg != null) { 111 return pkg.getLabel(); 112 } 113 return label; 114 } 115 116 public void setLabel(String label) { 117 this.label = label; 118 } 119 120 public DownloadPackage getPackage() { 121 return pkg; 122 } 123 124 public String getId() { 125 return id; 126 } 127 128 public String getColor() { 129 if (pkg != null) { 130 return pkg.getColor(); 131 } 132 return ""; 133 } 134 135 /** 136 * @since 8.3 137 */ 138 public String getDescription() { 139 if (pkg != null) { 140 return pkg.getDescription(); 141 } 142 return ""; 143 } 144 145 /** 146 * @since 8.3 147 */ 148 public boolean isVirtual() { 149 if (pkg != null) { 150 return pkg.isVirtual(); 151 } 152 return false; 153 } 154 155 public String getTextColor() { 156 if (pkg != null) { 157 return pkg.getTextColor(); 158 } 159 return ""; 160 } 161 162 public DownloadablePackageOption getParent() { 163 return parent; 164 } 165 166 public String getShortLabel() { 167 if (pkg != null) { 168 return pkg.getShortLabel(); 169 } 170 return null; 171 } 172}