001/* 002 * (C) Copyright 2006-2007 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 * <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 018 * 019 * $Id: LayoutRowImpl.java 28478 2008-01-04 12:53:58Z sfermigier $ 020 */ 021 022package org.nuxeo.ecm.platform.forms.layout.api.impl; 023 024import java.io.Serializable; 025import java.util.Collections; 026import java.util.List; 027import java.util.Map; 028 029import org.nuxeo.ecm.platform.forms.layout.api.LayoutRow; 030import org.nuxeo.ecm.platform.forms.layout.api.Widget; 031 032/** 033 * Implementation for layout rows. 034 * 035 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 036 */ 037public class LayoutRowImpl implements LayoutRow { 038 039 private static final long serialVersionUID = 1528198770297610864L; 040 041 protected String name; 042 043 protected boolean selectedByDefault = true; 044 045 protected boolean alwaysSelected = false; 046 047 protected Widget[] widgets; 048 049 protected Map<String, Serializable> properties; 050 051 protected String definitionId; 052 053 // needed by GWT serialization 054 protected LayoutRowImpl() { 055 super(); 056 } 057 058 /** 059 * @deprecated since 5.5: use {@link #LayoutRowImpl(String, boolean, boolean, List, Map, String)} 060 */ 061 @Deprecated 062 public LayoutRowImpl(List<Widget> widgets, Map<String, Serializable> properties) { 063 this.widgets = widgets.toArray(new Widget[0]); 064 this.properties = properties; 065 name = null; 066 selectedByDefault = true; 067 alwaysSelected = false; 068 } 069 070 /** 071 * @deprecated since 5.5: use {@link #LayoutRowImpl(String, boolean, boolean, List, Map, String)} 072 */ 073 @Deprecated 074 public LayoutRowImpl(String name, boolean selectedByDefault, boolean alwaysSelected, List<Widget> widgets, 075 Map<String, Serializable> properties) { 076 this(name, selectedByDefault, alwaysSelected, widgets, properties, null); 077 } 078 079 /** 080 * @since 5.5 081 */ 082 public LayoutRowImpl(String name, boolean selectedByDefault, boolean alwaysSelected, List<Widget> widgets, 083 Map<String, Serializable> properties, String definitionId) { 084 this.name = name; 085 this.selectedByDefault = selectedByDefault; 086 this.alwaysSelected = alwaysSelected; 087 this.widgets = widgets.toArray(new Widget[0]); 088 this.properties = properties; 089 this.definitionId = definitionId; 090 } 091 092 public String getName() { 093 return name; 094 } 095 096 @Override 097 public String getTagConfigId() { 098 // XXX check if widget instances should be taken into account. 099 return definitionId; 100 } 101 102 public boolean isAlwaysSelected() { 103 return alwaysSelected; 104 } 105 106 public boolean isSelectedByDefault() { 107 return selectedByDefault; 108 } 109 110 public Widget[] getWidgets() { 111 return widgets; 112 } 113 114 public int getSize() { 115 if (widgets != null) { 116 return widgets.length; 117 } 118 return 0; 119 } 120 121 public Map<String, Serializable> getProperties() { 122 if (properties == null) { 123 return Collections.emptyMap(); 124 } 125 return Collections.unmodifiableMap(properties); 126 } 127 128 public Serializable getProperty(String name) { 129 if (properties != null) { 130 return properties.get(name); 131 } 132 return null; 133 } 134 135 @Override 136 public String toString() { 137 final StringBuilder buf = new StringBuilder(); 138 139 buf.append("LayoutRowImpl"); 140 buf.append(" {"); 141 buf.append(" name="); 142 buf.append(name); 143 buf.append(", properties="); 144 buf.append(properties); 145 buf.append('}'); 146 147 return buf.toString(); 148 } 149 150}