Author: dumoulin Date: 2009-02-11 09:43:56 +0000 (Wed, 11 Feb 2009) New Revision: 1559 Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java Log: add children only if not empty Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java 2009-02-03 10:37:54 UTC (rev 1558) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/Component.java 2009-02-11 09:43:56 UTC (rev 1559) @@ -24,6 +24,7 @@ import fr.cemagref.simexplorer.is.entities.composite.Components; import fr.cemagref.simexplorer.is.entities.composite.Constants; import fr.cemagref.simexplorer.is.entities.composite.Libraries; +import fr.cemagref.simexplorer.is.entities.composite.SimpleComposite; import fr.cemagref.simexplorer.is.entities.composite.Structures; import java.util.ArrayList; @@ -163,18 +164,18 @@ @Override public List<Entity> getChildren() { List<Entity> directChildren = super.getChildren(); - directChildren.add(constants); - directChildren.add(structures); - directChildren.add(codes); - directChildren.add(libraries); - directChildren.add(subComponents); + addChildrenIfNotEmpty(directChildren, constants); + addChildrenIfNotEmpty(directChildren, structures); + addChildrenIfNotEmpty(directChildren, codes); + addChildrenIfNotEmpty(directChildren, libraries); + addChildrenIfNotEmpty(directChildren, subComponents); return directChildren; } @Override public List<String> getRow() { List<String> row = new ArrayList<String>(); - row.add(EntityTypeEnum.getLibelle(this.getClass())+" ("+type+")"); + row.add(EntityTypeEnum.getLibelle(this.getClass()) + " (" + type + ")"); return row; } Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java 2009-02-03 10:37:54 UTC (rev 1558) +++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/data/LoggableElement.java 2009-02-11 09:43:56 UTC (rev 1559) @@ -1,19 +1,19 @@ /* -* ##% Copyright (C) 2008 Cemagref -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* ##% */ + * ##% Copyright (C) 2008 Cemagref + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * ##% */ package fr.cemagref.simexplorer.is.entities.data; import java.util.ArrayList; @@ -25,6 +25,7 @@ import fr.cemagref.simexplorer.is.entities.attachment.Attachment; import fr.cemagref.simexplorer.is.entities.composite.Attachments; import fr.cemagref.simexplorer.is.entities.composite.Descriptors; +import fr.cemagref.simexplorer.is.entities.composite.SimpleComposite; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; /** @@ -36,19 +37,14 @@ /** The name. */ private String name; - /** The description. */ private String description; - /** The descriptors. */ private Descriptors descriptors; - /** The attachments. */ private Attachments attachments; - /** The metadata IS, managed only by SimExplorer-IS. */ private MetaData metadataIS; - /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1; @@ -71,11 +67,17 @@ public List<Entity> getChildren() { List<Entity> children = new ArrayList<Entity>(); children.add(metadataIS); - children.add(attachments); - children.add(descriptors); + addChildrenIfNotEmpty(children, attachments); + addChildrenIfNotEmpty(children, descriptors); return children; } + protected void addChildrenIfNotEmpty(List<Entity> children, SimpleComposite child) { + if (child != null && child.size() > 0) { + children.add(child); + } + } + /** * Gets all children of LoggableElement type. * @@ -180,8 +182,9 @@ * @return the correct attachment */ public Attachment getAttachment(Integer attachmentIndex) { - if (attachmentIndex != null && attachmentIndex > -1 && attachments != null && !attachments.isEmpty() - && attachments.size() > attachmentIndex) { + if (attachmentIndex != null && attachmentIndex > -1 && attachments != + null && !attachments.isEmpty() && attachments.size() > + attachmentIndex) { return attachments.get(attachmentIndex); } return null; @@ -195,7 +198,8 @@ * @return the correct attachment */ public Attachment getAttachment(String attachmentUniqueId) { - if (attachmentUniqueId != null && attachments != null && !attachments.isEmpty()) { + if (attachmentUniqueId != null && attachments != null && + !attachments.isEmpty()) { for (Attachment attachment : attachments) { if (attachmentUniqueId.equals(attachment.getUniqueId())) { return attachment; @@ -231,5 +235,4 @@ public void setMetaData(MetaData metadataIS) { this.metadataIS = metadataIS; } - }