001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (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.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 * <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 016 * 017 * $Id: LayoutRowDescriptor.java 26053 2007-10-16 01:45:43Z atchertchian $ 018 */ 019 020package org.nuxeo.ecm.platform.forms.layout.descriptors; 021 022import java.io.Serializable; 023import java.util.HashMap; 024import java.util.Map; 025 026import org.nuxeo.common.xmap.annotation.XNode; 027import org.nuxeo.common.xmap.annotation.XNodeList; 028import org.nuxeo.common.xmap.annotation.XNodeMap; 029import org.nuxeo.common.xmap.annotation.XObject; 030import org.nuxeo.ecm.platform.forms.layout.api.LayoutRowDefinition; 031import org.nuxeo.ecm.platform.forms.layout.api.WidgetReference; 032import org.nuxeo.ecm.platform.forms.layout.api.impl.LayoutRowDefinitionImpl; 033 034/** 035 * Layout row descriptor. 036 * 037 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 038 */ 039@XObject("row") 040public class LayoutRowDescriptor { 041 042 @XNode("@name") 043 String name; 044 045 @XNode("@selectedByDefault") 046 boolean selectedByDefault = true; 047 048 @XNode("@alwaysSelected") 049 boolean alwaysSelected = false; 050 051 @XNodeList(value = "widget", type = WidgetReferenceDescriptor[].class, componentType = WidgetReferenceDescriptor.class) 052 WidgetReferenceDescriptor[] widgets = new WidgetReferenceDescriptor[0]; 053 054 @XNodeMap(value = "properties", key = "@mode", type = HashMap.class, componentType = PropertiesDescriptor.class) 055 Map<String, PropertiesDescriptor> properties = new HashMap<String, PropertiesDescriptor>(); 056 057 public String getName() { 058 return name; 059 } 060 061 public boolean isSelectedByDefault() { 062 return selectedByDefault; 063 } 064 065 public boolean isAlwaysSelected() { 066 return alwaysSelected; 067 } 068 069 public int getSize() { 070 return widgets.length; 071 } 072 073 public String[] getWidgets() { 074 String[] names = new String[widgets.length]; 075 for (int i = 0; i < widgets.length; i++) { 076 names[i] = widgets[i].getName(); 077 } 078 return names; 079 } 080 081 public Map<String, Serializable> getProperties(String layoutMode) { 082 return WidgetDescriptor.getProperties(properties, layoutMode); 083 } 084 085 public Map<String, Map<String, Serializable>> getProperties() { 086 return WidgetDescriptor.getProperties(properties); 087 } 088 089 public LayoutRowDefinition getLayoutRowDefinition() { 090 WidgetReference[] cwidgets = null; 091 if (widgets != null) { 092 cwidgets = new WidgetReference[widgets.length]; 093 for (int i = 0; i < widgets.length; i++) { 094 cwidgets[i] = widgets[i].getWidgetReference(); 095 } 096 } 097 LayoutRowDefinition clone = new LayoutRowDefinitionImpl(name, getProperties(), cwidgets, alwaysSelected, 098 selectedByDefault); 099 return clone; 100 } 101}