001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.core.admin.ui;
023:
024: import org.jboss.portal.core.admin.ui.actions.PropertyAction;
025: import org.jboss.portal.core.model.portal.PortalObject;
026:
027: import javax.faces.model.DataModel;
028: import javax.faces.model.ListDataModel;
029: import javax.faces.model.SelectItem;
030: import java.util.ArrayList;
031: import java.util.Iterator;
032: import java.util.List;
033: import java.util.SortedMap;
034: import java.util.TreeMap;
035:
036: /**
037: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
038: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
039: * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot com">Boleslaw Dawidowicz</a>
040: * @version $Revision: 8785 $
041: */
042: public class PropertiesBean extends PropertyBeanContainer {
043:
044: /** . */
045: private final SortedMap entryMap;
046:
047: /** . */
048: private final PortalObjectManagerBean pomgr;
049:
050: /** . */
051: private final PropertiesInfo info;
052:
053: /** . */
054: private int selectedIndex;
055:
056: /** . */
057: private List items;
058:
059: /** . */
060: private String propertyActionRef;
061:
062: public PropertiesBean(PortalObjectManagerBean pomgr) {
063: // Get the selected object
064: PortalObject selectedObject = pomgr.getSelectedObject();
065:
066: //
067: PropertiesInfo info = new PropertiesInfo(selectedObject);
068:
069: //
070: SortedMap entryMap = new TreeMap();
071:
072: //
073: boolean inheritable = selectedObject.getType() != PortalObject.TYPE_CONTEXT;
074:
075: //
076: for (Iterator i = selectedObject.getProperties().keySet()
077: .iterator(); i.hasNext();) {
078: String propertyName = (String) i.next();
079: String propertyValue = selectedObject
080: .getProperty(propertyName);
081: PropertyInfo propertyInfo = info
082: .getPropertyInfo(propertyName);
083: boolean inherited = !selectedObject.getDeclaredProperties()
084: .containsKey(propertyName);
085:
086: // If null it is probably an inherited property that does not have meaning for that particular object
087: // Filter, keep only public properties
088: if (propertyInfo != null
089: && propertyInfo.getScope() == PropertyInfo.PUBLIC_SCOPE) {
090: PropertyBean propertyBean = new PropertyBean(this ,
091: propertyInfo, inherited, inheritable,
092: propertyValue);
093: entryMap.put(propertyName, propertyBean);
094: }
095: }
096:
097: //
098: this .info = info;
099: this .pomgr = pomgr;
100: this .entryMap = entryMap;
101: this .selectedIndex = -1;
102: }
103:
104: public int getSelectedIndex() {
105: return selectedIndex;
106: }
107:
108: public void setSelectedIndex(int selectedIndex) {
109: if (selectedIndex < 0 || selectedIndex >= entryMap.size()) {
110: throw new IllegalArgumentException();
111: }
112: this .selectedIndex = selectedIndex;
113: }
114:
115: public void unselectEntry() {
116: selectedIndex = -1;
117: }
118:
119: public DataModel getEntries() {
120: return new ListDataModel(new ArrayList(entryMap.values()));
121: }
122:
123: public int getSize() {
124: return entryMap.size();
125: }
126:
127: public SelectItem[] getPropertyItems() {
128: if (items == null) {
129: items = new ArrayList();
130: for (Iterator i = info.getNames().iterator(); i.hasNext();) {
131: String propertyName = (String) i.next();
132:
133: // Add only missing property
134: if (!entryMap.containsKey(propertyName)) {
135: PropertyInfo propertyInfo = info
136: .getPropertyInfo(propertyName);
137:
138: // Add only property user can change state
139: if (propertyInfo.getScope() == PropertyInfo.PUBLIC_SCOPE
140: && propertyInfo.getAccessMode() == PropertyInfo.READ_WRITE_ACCESS_MODE
141: && !PropertiesInfo
142: .isControlProperty(propertyName)) {
143: items.add(new SelectItem(
144: propertyInfo.getName(), propertyInfo
145: .getDisplayName()
146: .getDefaultString(),
147: propertyInfo.getDescription()
148: .getDefaultString()));
149: }
150: }
151: }
152: }
153:
154: //
155: return (SelectItem[]) items
156: .toArray(new SelectItem[items.size()]);
157: }
158:
159: public PortalObject getRelatedObject() {
160: return pomgr.getSelectedObject();
161: }
162:
163: public PropertyAction getAction() {
164: return pomgr.propertyAction;
165: }
166: }
|