
com.viaoa.web.html.oa.OAInputCheckBox Maven / Gradle / Ivy
package com.viaoa.web.html.oa;
import com.viaoa.hub.*;
import com.viaoa.object.*;
import com.viaoa.uicontroller.OAUIPropertyController;
import com.viaoa.util.OACompare;
import com.viaoa.web.html.HtmlTD;
import com.viaoa.web.html.form.OAForm;
import com.viaoa.web.html.form.OAFormSubmitEvent;
import com.viaoa.web.html.input.InputCheckBox;
//qqqqqqqq option to dynamically create check boxes for a multilist
/**
* Binds Input CheckBox to an Hub + propertyName
*
*/
public class OAInputCheckBox extends InputCheckBox implements OAHtmlComponentInterface, OAHtmlTableComponentInterface {
private final OAUIPropertyController oaUiControl;
private Object onValue, offValue;
private static class LastRefresh {
OAObject objUsed;
Object value;
}
private final LastRefresh lastRefresh = new LastRefresh();
public OAInputCheckBox(String id, Hub hub, String propName) {
this(id, hub, propName, true, false);
}
public OAInputCheckBox(String id, Hub hub, String propName, Object onValue, Object offValue) {
super(id);
this.onValue = onValue;
this.offValue = offValue;
oaUiControl = new OAUIPropertyController(hub, propName) {
@Override
protected void onCompleted(String completedMessage, String title) {
OAForm form = getForm();
if (form != null) {
form.addMessage(completedMessage);
form.addConsoleMessage(title + " - " + completedMessage);
}
}
@Override
protected void onError(String errorMessage, String detailMessage) {
OAForm form = getForm();
if (form != null) {
form.addError(errorMessage);
form.addConsoleMessage(errorMessage + " - " + detailMessage);
}
}
};
}
public Hub getHub() {
return oaUiControl.getHub();
}
public String getPropertyName() {
return oaUiControl.getPropertyName();
}
public String getFormat() {
return oaUiControl.getFormat();
}
public void setFormat(String format) {
oaUiControl.setFormat(format);
}
@Override
protected void onSubmitAfterLoadValues(OAFormSubmitEvent formSubmitEvent) {
if (getHub() == null || getPropertyName() == null) {
return;
}
if (lastRefresh.objUsed == null) return;
// make sure that it did not change
Object objPrev = oaUiControl.getValue(lastRefresh.objUsed);
if (!OACompare.isEqual(objPrev, lastRefresh.value)) {
formSubmitEvent.addSyncError("OAInputCheckBox Id="+getId());
return;
}
boolean b = isChecked();
oaUiControl.onSetProperty(lastRefresh.objUsed, b ? onValue : offValue);
}
@Override
protected void beforeGetScript() {
OAForm form = getOAHtmlComponent().getForm();
final boolean bIsFormEnabled = form == null || form.getEnabled();
lastRefresh.objUsed = (OAObject) oaUiControl.getHub().getAO();
lastRefresh.value = oaUiControl.getValue(lastRefresh.objUsed);
boolean b = oaUiControl.isEnabled();
setEnabled(bIsFormEnabled && b);
b = oaUiControl.isVisible();
setVisible(b);
b = (lastRefresh.objUsed == null) ? false : OACompare.isEqual(onValue, lastRefresh.value);
setChecked(b);
}
@Override
public String getTableCellRenderer(Hub hubTable, HtmlTD td, int row) {
OAObject obj;
if (hubTable != null && hubTable != getHub()) {
obj = (OAObject) hubTable.getAt(row);
if (obj != null) {
String pp = OAObjectReflectDelegate.getPropertyPathBetweenHubs(hubTable, getHub());
obj = (OAObject) obj.getProperty(pp);
}
}
else {
obj = (OAObject) getHub().get(row);
}
String s;
if (obj == null) s = "";
else {
boolean b = obj.isVisible(getPropertyName());
if (!b) s = "";
else {
s = obj.getPropertyAsString(getPropertyName(), getFormat());
if (s == null) s = "";
else td.addClass("oaNoTextOverflow");
}
}
return s;
}
@Override
public String getTableCellEditor(Hub hubTable, HtmlTD td, int row, boolean bHasFocus) {
OAObject obj;
if (hubTable != null && hubTable != getHub()) {
obj = (OAObject) hubTable.getAt(row);
if (obj != null) {
String pp = OAObjectReflectDelegate.getPropertyPathBetweenHubs(hubTable, getHub());
obj = (OAObject) obj.getProperty(pp);
}
}
else {
obj = (OAObject) getHub().get(row);
}
String s = "";
return s;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy