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.model.portal.PortalObject;
025:
026: /**
027: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
028: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
029: * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot com">Boleslaw Dawidowicz</a>
030: * @version $Revision: 8785 $
031: */
032: public class PropertyBean implements Comparable {
033:
034: /** . */
035: protected String value;
036:
037: /** . */
038: private final PropertyBeanContainer container;
039:
040: /** . */
041: protected final PropertyInfo info;
042:
043: /** . */
044: protected boolean inherited;
045:
046: /** . */
047: protected boolean inheritable;
048:
049: public PropertyBean(PropertyBeanContainer container,
050: PropertyInfo info, boolean inherited, boolean inheritable,
051: String value) {
052: this .container = container;
053: this .info = info;
054: this .inherited = inherited;
055: this .inheritable = inheritable;
056: this .value = value;
057: }
058:
059: public boolean isInheritable() {
060: return inheritable;
061: }
062:
063: public String getName() {
064: return info.getName();
065: }
066:
067: public boolean isReadOnly() {
068: return info.getAccessMode() == PropertyInfo.READ_ONLY_ACCESS_MODE;
069: }
070:
071: public String getDescription() {
072: return info.getDescription().getDefaultString();
073: }
074:
075: public String getDisplayName() {
076: return info.getDisplayName().getDefaultString();
077: }
078:
079: public boolean isInherited() {
080: return inherited;
081: }
082:
083: public Object getValue() {
084: if (info.getType().equals("java.lang.Boolean")) {
085: return Boolean.valueOf(value);
086: } else {
087: return value;
088: }
089: }
090:
091: public void setValue(Object value) {
092: this .value = value.toString();
093:
094: // Need to use the container as it will contain the refreshed object
095: PortalObject portalObject = container.getRelatedObject();
096:
097: //if value is inherited check if updated value is the same - if yes, don't update to keep inheritance
098: if (isInherited()) {
099: String parentValue = portalObject.getProperty(getName());
100: if (value.equals(parentValue)) {
101: return;
102: }
103: }
104:
105: //
106: portalObject.setDeclaredProperty(getName(), value.toString());
107: }
108:
109: public int compareTo(Object o) {
110: PropertyBean that = (PropertyBean) o;
111: return info.getName().compareTo(that.getName());
112: }
113:
114: public String getType() {
115: return info.getType();
116: }
117:
118: public boolean isControlProperty() {
119: return PropertiesInfo.isControlProperty(info.getName());
120: }
121:
122: public String toString() {
123: return "PropertyBean[name=" + info.getName() + ",value="
124: + value + "]";
125: }
126: }
|