You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2019/11/12 13:28:07 UTC
[empire-db] branch master updated: EMPIREDB-282 Allow overrides for
value style classes
This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/master by this push:
new a8b7725 EMPIREDB-282 Allow overrides for value style classes
a8b7725 is described below
commit a8b77256e8a96273e3bfc42a1937318f8d501bf7
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Tue Nov 12 14:28:03 2019 +0100
EMPIREDB-282
Allow overrides for value style classes
---
.../apache/empire/jsf2/components/ValueTag.java | 11 +-----
.../apache/empire/jsf2/controls/InputControl.java | 40 ++++++++++++++++++++--
2 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ValueTag.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ValueTag.java
index 0afa94c..2083ed0 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ValueTag.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ValueTag.java
@@ -23,7 +23,6 @@ import java.io.IOException;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
-import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.DataType;
import org.apache.empire.jsf2.controls.InputControl;
@@ -81,15 +80,7 @@ public class ValueTag extends UIOutput // implements NamingContainer
// Detect type and additional style
String addlStyle = null;
DataType dataType = vi.getColumn().getDataType();
- if (dataType.isNumeric())
- { try {
- Object val = helper.getDataValue(true);
- if (val!=null && ObjectUtils.getLong(val)<0)
- addlStyle = "eValNeg";
- } catch(Exception e) {
- log.warn("Unable to detect sign of numeric value {}. Message is {}!", vi.getColumn().getName(), e.getMessage());
- }
- }
+ // get style
styleClass = helper.getTagStyleClass(dataType, addlStyle);
}
// render now
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
index eb497a2..e7928bf 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
@@ -36,6 +36,7 @@ import org.apache.empire.commons.ObjectUtils;
import org.apache.empire.commons.Options;
import org.apache.empire.commons.StringUtils;
import org.apache.empire.data.Column;
+import org.apache.empire.data.DataType;
import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.ItemNotFoundException;
import org.apache.empire.exceptions.UnexpectedReturnValueException;
@@ -49,8 +50,10 @@ public abstract class InputControl
private static final Logger log = LoggerFactory.getLogger(InputControl.class);
// format attributes
- public static final String FORMAT_NULL = "null:";
- public static final String FORMAT_NULL_ATTRIBUTE = "format:null";
+ public static final String FORMAT_NULL = "null:";
+ public static final String FORMAT_NULL_ATTRIBUTE = "format:null";
+ public static final String FORMAT_VALUE_STYLES = "valueStyles";
+ public static final String FORMAT_VALUE_STYLES_ATTRIBUTE = "format:valueStyles";
// HTML-TAGS
public static final String HTML_TAG_DIV = "div";
@@ -229,6 +232,8 @@ public abstract class InputControl
if (tagName!=null)
{ // write start tag
writer.startElement(tagName, comp);
+ if (hasFormatOption(vi, FORMAT_VALUE_STYLES, FORMAT_VALUE_STYLES_ATTRIBUTE))
+ styleClass = addDataValueStyle(vi, vi.getValue(true), styleClass);
if (StringUtils.isNotEmpty(styleClass))
writer.writeAttribute("class", styleClass, null);
if (StringUtils.isNotEmpty(tooltip))
@@ -376,6 +381,28 @@ public abstract class InputControl
return submittedValue;
}
+ /**
+ * adds style attributes related to the current value
+ * @param vi
+ * @param value the current value
+ * @param styleClass
+ * @return
+ */
+ protected String addDataValueStyle(ValueInfo vi, Object value, String styleClass)
+ {
+ DataType dataType = vi.getColumn().getDataType();
+ if (ObjectUtils.isEmpty(value))
+ { // Null
+ styleClass += " eValNull";
+ }
+ else if (dataType.isNumeric())
+ { // Check negative
+ if (ObjectUtils.getLong(value)<0)
+ styleClass += " eValNeg";
+ }
+ return styleClass;
+ }
+
protected void addAttachedObjects(UIComponent parent, FacesContext context, InputInfo ii, UIComponentBase inputComponent)
{
InputAttachedObjectsHandler aoh = InputControlManager.getAttachedObjectsHandler();
@@ -738,6 +765,15 @@ public abstract class InputControl
return (format != null ? format.indexOf(option) >= 0 : false);
}
+ protected boolean hasFormatOption(ValueInfo vi, String option, String columnAttributeName)
+ {
+ if (hasFormatOption(vi, option))
+ return true;
+ // column format provided?
+ Column column = vi.getColumn();
+ return (column!=null ? !ObjectUtils.isEmpty(column.getAttribute(columnAttributeName)) : false);
+ }
+
protected String getFormatOption(ValueInfo vi, String option)
{
// Is unit supplied with format