Refactor the implementation for "Red color whole label of empty mandatory fields"
(transplanted from 07073ae97fb3462921d1ce8734830efabd22cece)
This commit is contained in:
parent
ba2bbb7107
commit
c252c4475c
|
@ -28,8 +28,8 @@ import org.zkoss.zk.ui.Component;
|
|||
*/
|
||||
public class Label extends org.zkoss.zul.Label
|
||||
{
|
||||
/**
|
||||
*
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -6818124304324329510L;
|
||||
|
||||
|
@ -105,16 +105,5 @@ public class Label extends org.zkoss.zul.Label
|
|||
|
||||
public Component rightAlign() {
|
||||
return LayoutUtils.makeRightAlign(this);
|
||||
}
|
||||
|
||||
private boolean m_zoomable = false;
|
||||
|
||||
public boolean isZoomable() {
|
||||
return m_zoomable;
|
||||
}
|
||||
|
||||
public void setZoomable(boolean zoomable) {
|
||||
m_zoomable = zoomable;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,5 +218,14 @@ public class WAccountEditor extends WEditor implements ContextMenuListener
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullOrEmpty() {
|
||||
Object value = getValue();
|
||||
if (value != null && ((Integer) value).intValue() == 0)
|
||||
value = null;
|
||||
|
||||
return value == null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ import org.zkoss.zul.Image;
|
|||
*/
|
||||
public abstract class WEditor implements EventListener, PropertyChangeListener
|
||||
{
|
||||
private static final String[] lISTENER_EVENTS = {};
|
||||
private static final String[] lISTENER_EVENTS = {};
|
||||
|
||||
public static final int MAX_DISPLAY_LENGTH = 35;
|
||||
|
||||
|
@ -490,21 +490,28 @@ public abstract class WEditor implements EventListener, PropertyChangeListener
|
|||
hasFocus = b;
|
||||
}
|
||||
|
||||
public void setMandatoryLabels() {
|
||||
Object value = getValue();
|
||||
if (this instanceof WAccountEditor && value != null && ((Integer) value).intValue() == 0) // special case
|
||||
value = null;
|
||||
public void updateLabelStyle() {
|
||||
if (getLabel() != null) {
|
||||
markMandatory(mandatory && !readOnly && getGridField().isEditable(true) && (value == null || value.toString().trim().length() == 0));
|
||||
boolean mandatoryStyle = mandatory && !readOnly && getGridField().isEditable(true) && isNullOrEmpty();
|
||||
getLabel().setStyle( (isZoomable() ? STYLE_ZOOMABLE_LABEL : "") + (mandatoryStyle ? STYLE_EMPTY_MANDATORY_LABEL : STYLE_NORMAL_LABEL));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNullOrEmpty() {
|
||||
Object value = getValue();
|
||||
return value == null || value.toString().trim().length() == 0;
|
||||
}
|
||||
|
||||
public boolean isZoomable() {
|
||||
WEditorPopupMenu menu = getPopupMenu();
|
||||
if (menu != null && menu.isZoomEnabled() && this instanceof IZoomableEditor) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String STYLE_ZOOMABLE_LABEL = "cursor: pointer; text-decoration: underline;";
|
||||
private static final String STYLE_NORMAL_LABEL = "color:black;";
|
||||
private static final String STYLE_NORMAL_LABEL = "color: black;";
|
||||
private static final String STYLE_EMPTY_MANDATORY_LABEL = "color: red;";
|
||||
|
||||
private void markMandatory(boolean mandatory) {
|
||||
getLabel().setStyle( (getLabel().isZoomable() ? STYLE_ZOOMABLE_LABEL : "") + (mandatory ? STYLE_EMPTY_MANDATORY_LABEL : STYLE_NORMAL_LABEL));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -479,7 +479,6 @@ DataStatusListener, IADTabpanel, VetoableChangeListener
|
|||
Label label = editor.getLabel();
|
||||
if (popupMenu.isZoomEnabled() && editor instanceof IZoomableEditor)
|
||||
{
|
||||
label.setZoomable(true);
|
||||
label.addEventListener(Events.ON_CLICK, new ZoomListener((IZoomableEditor) editor));
|
||||
}
|
||||
|
||||
|
@ -542,7 +541,7 @@ DataStatusListener, IADTabpanel, VetoableChangeListener
|
|||
|
||||
for (WEditor comp : editors)
|
||||
{
|
||||
comp.setMandatoryLabels();
|
||||
comp.updateLabelStyle();
|
||||
}
|
||||
|
||||
// Selective
|
||||
|
|
Loading…
Reference in New Issue