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/PreferencesBean.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PreferencesBean.java
(rev 0)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PreferencesBean.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 <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PreferencesBean
+{
+
+ /** . */
+ List entries;
+
+ /** . */
+ int selectedIndex;
+
+ /** . */
+ private boolean mutable;
+
+ public PreferencesBean(boolean mutable)
+ {
+ this.entries = new ArrayList();
+ this.selectedIndex = -1;
+ this.mutable = mutable;
+ }
+
+ public boolean isMutable()
+ {
+ return mutable;
+ }
+
+ public int getSelectedIndex()
+ {
+ return selectedIndex;
+ }
+
+ public void setSelectedIndex(int selectedIndex)
+ {
+ if (selectedIndex < 0 || selectedIndex >= entries.size())
+ {
+ throw new IllegalArgumentException();
+ }
+ this.selectedIndex = selectedIndex;
+ }
+
+ public void unselectEntry()
+ {
+ selectedIndex = -1;
+ }
+
+ public PreferenceBean getSelectedEntry()
+ {
+ if (selectedIndex < 0 || selectedIndex >= 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 == false)
+ {
+ throw new IllegalStateException("Cannot add mutable entry to a non mutable
preferences bean");
+ }
+
+ //
+ addEntry(new PreferenceBean(prefInfo, value));
+ }
+
+ private void addEntry(PreferenceBean pref)
+ {
+ if (pref.container != null)
+ {
+ throw new IllegalArgumentException("Already contained somewhere");
+ }
+ pref.container = this;
+ entries.add(pref);
+ Collections.sort(entries);
+ }
+
+ public List getEntries()
+ {
+ return Collections.unmodifiableList(entries);
+ }
+
+ public int getSize()
+ {
+ return entries.size();
+ }
+}