use of com.codename1.rad.attributes.SelectedCondition in project CodeRAD by shannah.
the class DefaultActionViewFactory method update.
public static void update(MultiButton btn, Entity entity, ActionNode action) {
boolean repaint = false;
boolean revalidate = false;
Condition cond = action.getCondition();
if (cond != null) {
boolean hidden = !cond.getValue().test(entity);
if (hidden != btn.isHidden()) {
btn.setHidden(hidden);
btn.setVisible(!hidden);
revalidate = true;
}
}
EnabledCondition enabledCond = action.getEnabledCondition();
if (enabledCond != null) {
boolean enabled = enabledCond.getValue().test(entity);
if (enabled != btn.isEnabled()) {
btn.setEnabled(enabled);
repaint = true;
}
}
if (action.getLabel() != null) {
// String currTextVal = btn.getText();
String newTextVal = action.getLabelText(entity);
String currTextVal = btn.getTextLines();
if (!Objects.equals(currTextVal.trim(), newTextVal.trim())) {
btn.setTextLines(newTextVal.trim());
repaint = true;
}
}
if (!action.isTextStyle() && !"".equals(btn.getTextLines().trim())) {
btn.setTextLine1("");
btn.setTextLine2("");
btn.setTextLine3("");
btn.setTextLine4("");
repaint = true;
}
if (action.getUIID() != null) {
String currUiid = btn.getUIID();
String newUiid = action.getUIID(entity, "Button");
if (!Objects.equals(currUiid, newUiid)) {
btn.setUIID(newUiid);
repaint = true;
}
}
if (btn.isCheckBox()) {
SelectedCondition selectedCond = action.getSelectedCondition();
if (selectedCond != null) {
boolean selected = selectedCond.getValue().test(entity);
if (selected != btn.isSelected()) {
btn.setSelected(selected);
repaint = true;
ActionNode newState = selected ? action.getSelected() : action.getUnselected();
ActionNode oldState = selected ? action.getUnselected() : action.getSelected();
if (oldState != newState) {
String currText = btn.getText();
String newText = newState.getLabelText(entity);
if (!newState.isTextStyle()) {
newText = "";
}
if (!Objects.equals(newText, currText)) {
btn.setText(newText);
}
}
}
}
}
Badge badge = action.getBadge();
if (badge != null) {
btn.setBadgeText(badge.getValue(entity));
BadgeUIID badgeUiid = action.getBadgeUIID();
if (badgeUiid != null) {
btn.setBadgeUIID(badgeUiid.getValue());
}
}
if (revalidate || repaint) {
Form f = btn.getComponentForm();
if (f != null) {
if (revalidate) {
Component entityView = findEntityViewParent(btn);
if (entityView instanceof Container) {
((Container) entityView).revalidateLater();
} else {
entityView.repaint();
}
} else {
btn.repaint();
}
}
}
}
use of com.codename1.rad.attributes.SelectedCondition in project CodeRAD by shannah.
the class DefaultActionViewFactory method update.
public static void update(Button btn, Entity entity, ActionNode action) {
boolean repaint = false;
boolean revalidate = false;
Condition cond = action.getCondition();
if (cond != null) {
boolean hidden = !cond.getValue().test(entity);
if (hidden != btn.isHidden()) {
btn.setHidden(hidden);
btn.setVisible(!hidden);
revalidate = true;
}
}
EnabledCondition enabledCond = action.getEnabledCondition();
if (enabledCond != null) {
boolean enabled = enabledCond.getValue().test(entity);
if (enabled != btn.isEnabled()) {
btn.setEnabled(enabled);
repaint = true;
}
}
if (action.getLabel() != null) {
String currTextVal = btn.getText();
String newTextVal = action.getLabelText(entity);
if (!Objects.equals(currTextVal, newTextVal)) {
btn.setText(newTextVal);
repaint = true;
}
}
if (!action.isTextStyle() && !"".equals(btn.getText().trim())) {
btn.setText("");
repaint = true;
}
if (action.getUIID() != null) {
String currUiid = btn.getUIID();
String newUiid = action.getUIID(entity, "Button");
if (!Objects.equals(currUiid, newUiid)) {
btn.setUIID(newUiid);
repaint = true;
}
}
if (btn instanceof CheckBox) {
SelectedCondition selectedCond = action.getSelectedCondition();
if (selectedCond != null) {
boolean selected = selectedCond.getValue().test(entity);
if (selected != btn.isSelected()) {
((CheckBox) btn).setSelected(selected);
repaint = true;
ActionNode newState = selected ? action.getSelected() : action.getUnselected();
ActionNode oldState = selected ? action.getUnselected() : action.getSelected();
if (oldState != newState) {
String currText = btn.getText();
String newText = newState.getLabelText(entity);
if (!newState.isTextStyle()) {
newText = "";
}
if (!Objects.equals(newText, currText)) {
btn.setText(newText);
}
}
}
}
}
Badge badge = action.getBadge();
if (badge != null) {
btn.setBadgeText(badge.getValue(entity));
BadgeUIID badgeUiid = action.getBadgeUIID();
if (badgeUiid != null) {
btn.setBadgeUIID(badgeUiid.getValue());
}
}
if (revalidate || repaint) {
Form f = btn.getComponentForm();
if (f != null) {
if (revalidate) {
Component entityView = findEntityViewParent(btn);
if (entityView instanceof Container) {
((Container) entityView).revalidateLater();
} else {
entityView.repaint();
}
} else {
btn.repaint();
}
}
}
}
Aggregations