org.efaps.admin.datamodel.ui.BooleanUI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of efaps-kernel Show documentation
Show all versions of efaps-kernel Show documentation
eFaps is a framework used to map objects with or without attached files to
a relational database and optional file systems (only for attaches files). Configurable access control can be provided down to object and attribute level depending on implementation and use case. Depending on requirements, events (like triggers) allow to implement business logic and to separate business logic from user interface.
The framework includes integrations (e.g. webdav, full text search) and a web application as 'simple' configurable user interface. Some best practises, example web application modules (e.g. team work module) support administrators and implementers using this framework.
/*
* Copyright 2003 - 2011 The eFaps Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Revision: $Rev: 6210 $
* Last Changed: $Date: 2011-02-18 16:02:56 -0500 (Fri, 18 Feb 2011) $
* Last Changed By: $Author: [email protected] $
*/
package org.efaps.admin.datamodel.ui;
import org.efaps.admin.datamodel.Attribute;
import org.efaps.admin.dbproperty.DBProperties;
import org.efaps.admin.ui.AbstractUserInterfaceObject.TargetMode;
import org.efaps.admin.ui.field.Field;
/**
* A boolean value is shown in create mode with radio boxen which are only
* preselected if a defaultvalue for the attribute was defined. In edit mode,
* the user could select a value. The value is received from the DBProperties
* using the AttributeName and a parameter.
* e.g.
* Key = TypeName/AttributeName.false
* Value = inactive
*
* @author The eFaps Team
* @version $Id: BooleanUI.java 6210 2011-02-18 21:02:56Z [email protected] $
*/
public class BooleanUI
extends AbstractUI
{
/**
* Needed for serialization.
*/
private static final long serialVersionUID = 1L;
/**
* {@inheritDoc}
*/
@Override
public String getEditHtml(final FieldValue _fieldValue)
{
final StringBuilder ret = new StringBuilder();
final Field field = _fieldValue.getField();
final Attribute attribute = _fieldValue.getAttribute();
final Boolean bool;
if (_fieldValue.getValue() instanceof Boolean) {
bool = (Boolean) _fieldValue.getValue();
} else if (_fieldValue.getValue() instanceof String && ((String) _fieldValue.getValue()).length() > 0) {
if (((String) _fieldValue.getValue()).equalsIgnoreCase("TRUE")) {
bool = true;
} else {
bool = false;
}
} else {
bool = null;
}
if (_fieldValue.getTargetMode().equals(TargetMode.SEARCH)) {
ret.append("")
.append("")
.append(getTrue(attribute)).append("
")
.append("").append(getFalse(attribute));
} else {
ret.append("").append(getTrue(attribute)).append("
")
.append("").append(getFalse(attribute));
}
return ret.toString();
}
/**
* {@inheritDoc}
*/
@Override
public String getReadOnlyHtml(final FieldValue _fieldValue)
{
String ret = null;
final Attribute attribute = _fieldValue.getAttribute();
if (_fieldValue.getValue() instanceof Boolean) {
final boolean bool = (Boolean) _fieldValue.getValue();
if (bool) {
ret = getTrue(attribute);
} else {
ret = getFalse(attribute);
}
}
return ret;
}
/**
* {@inheritDoc}
*/
@Override
public Object getObject4Compare(final FieldValue _fieldValue)
{
Object ret = null;
if (_fieldValue.getValue() instanceof Boolean) {
final boolean bool = (Boolean) _fieldValue.getValue();
if (bool) {
ret = getTrue(_fieldValue.getAttribute());
} else {
ret = getFalse(_fieldValue.getAttribute());
}
}
return ret;
}
/**
* {@inheritDoc}
*/
@Override
public int compare(final FieldValue _fieldValue,
final FieldValue _fieldValue2)
{
String value = null;
String value2 = null;
// in case we have a boolean
if (_fieldValue.getValue() instanceof Boolean && _fieldValue2.getValue() instanceof Boolean) {
if ((Boolean) _fieldValue.getValue()) {
value = getTrue(_fieldValue.getAttribute());
} else {
value = getFalse(_fieldValue.getAttribute());
}
if ((Boolean) _fieldValue2.getValue()) {
value2 = getTrue(_fieldValue.getAttribute());
} else {
value2 = getFalse(_fieldValue.getAttribute());
}
}
// in case we have allready a string
if (_fieldValue.getValue() instanceof String && _fieldValue2.getValue() instanceof String) {
value = (String) _fieldValue.getValue();
value2 = (String) _fieldValue2.getValue();
}
return value.compareTo(value2);
}
/**
* Method to evaluate a String representation for the boolean.
*
* @param _attribute Attribute the String representation is wanted for
* @return String representation, default "FALSE"
*/
private String getFalse(final Attribute _attribute)
{
String ret;
if (DBProperties.hasProperty(_attribute.getParent().getName() + "/" + _attribute.getName() + ".false")) {
ret = DBProperties.getProperty(_attribute.getParent().getName() + "/" + _attribute.getName() + ".false");
} else {
ret = "FALSE";
}
return ret;
}
/**
* Method to evaluate a String representation for the boolean.
*
* @param _attribute Attribute the String representation is wanted for
* @return String representation, default "TRUE"
*/
private String getTrue(final Attribute _attribute)
{
String ret;
if (DBProperties.hasProperty(_attribute.getParent().getName() + "/" + _attribute.getName() + ".true")) {
ret = DBProperties.getProperty(_attribute.getParent().getName() + "/" + _attribute.getName() + ".true");
} else {
ret = "TRUE";
}
return ret;
}
}