From portal-commits at lists.jboss.org Fri Mar 2 21:43:49 2007 Content-Type: multipart/mixed; boundary="===============0098785859478759749==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r6495 - trunk/core-admin/src/main/org/jboss/portal/core/admin/ui. Date: Fri, 02 Mar 2007 21:43:49 -0500 Message-ID: --===============0098785859478759749== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: julien(a)jboss.com Date: 2007-03-02 21:43:49 -0500 (Fri, 02 Mar 2007) New Revision: 6495 Added: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PreferencesBean= .java Log: forgot to add one class in the previous commits Added: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/Preferences= Bean.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PreferencesBea= n.java (rev 0) +++ trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PreferencesBea= n.java 2007-03-03 02:43:49 UTC (rev 6495) @@ -0,0 +1,130 @@ +/*************************************************************************= ***** + * JBoss, a division of Red Hat = * + * Copyright 2006, Red Hat Middleware, LLC, and individual = * + * contributors as indicated by the @authors tag. See the = * + * copyright.txt in the distribution for a full listing of = * + * individual contributors. = * + * = * + * This is free software; you can redistribute it and/or modify it = * + * under the terms of the GNU Lesser General Public License as = * + * published by the Free Software Foundation; either version 2.1 of = * + * the License, or (at your option) any later version. = * + * = * + * This software 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 = * + * Lesser General Public License for more details. = * + * = * + * You should have received a copy of the GNU Lesser General Public = * + * License along with this software; if not, write to the Free = * + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA = * + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. = * + *************************************************************************= *****/ +package org.jboss.portal.core.admin.ui; + +import org.jboss.portal.portlet.info.PreferenceInfo; +import org.jboss.portal.common.value.Value; + +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + +/** + * @author Julien Viet + * @version $Revision: 1.1 $ + */ +public class PreferencesBean +{ + + /** . */ + List entries; + + /** . */ + int selectedIndex; + + /** . */ + private boolean mutable; + + public PreferencesBean(boolean mutable) + { + this.entries =3D new ArrayList(); + this.selectedIndex =3D -1; + this.mutable =3D mutable; + } + + public boolean isMutable() + { + return mutable; + } + + public int getSelectedIndex() + { + return selectedIndex; + } + + public void setSelectedIndex(int selectedIndex) + { + if (selectedIndex < 0 || selectedIndex >=3D entries.size()) + { + throw new IllegalArgumentException(); + } + this.selectedIndex =3D selectedIndex; + } + + public void unselectEntry() + { + selectedIndex =3D -1; + } + + public PreferenceBean getSelectedEntry() + { + if (selectedIndex < 0 || selectedIndex >=3D entries.size()) + { + return null; + } + return (PreferenceBean)entries.get(selectedIndex); + } + + public void addEntry(PreferenceInfo prefInfo) + { + if (mutable) + { + throw new IllegalStateException("Cannot add non mutable entry to = a mutable preferences bean"); + } + + // + addEntry(new PreferenceBean(prefInfo, null)); + } + + public void addEntry(PreferenceInfo prefInfo, Value value) + { + if (mutable =3D=3D false) + { + throw new IllegalStateException("Cannot add mutable entry to a no= n mutable preferences bean"); + } + + // + addEntry(new PreferenceBean(prefInfo, value)); + } + + private void addEntry(PreferenceBean pref) + { + if (pref.container !=3D null) + { + throw new IllegalArgumentException("Already contained somewhere"); + } + pref.container =3D this; + entries.add(pref); + Collections.sort(entries); + } + + public List getEntries() + { + return Collections.unmodifiableList(entries); + } + + public int getSize() + { + return entries.size(); + } +} --===============0098785859478759749==--