use of com.codename1.rad.models.Entity in project CodeRAD by shannah.
the class NodeUtilFunctions method buildActionsBar.
static void buildActionsBar(Node node, Container target, Entity entity, Actions right, Actions left, Actions overflow, Actions middle) {
Container actionsBar = new Container(new BorderLayout());
Container actionsBarRight = new Container(new BorderLayout());
if (middle != null && middle.size() > 0) {
GridLayout layout = new GridLayout(middle.size());
Container cnt = new Container(layout);
middle.addToContainer(cnt, entity);
actionsBar.add(BorderLayout.CENTER, cnt);
}
if (left != null) {
Container cnt = new Container(BoxLayout.x());
for (ActionNode action : left) {
cnt.add(action.getViewFactory().createActionView(entity, action));
}
if (actionsBar.getComponentCount() > 0) {
actionsBar.add(BorderLayout.WEST, cnt);
} else {
actionsBar.add(BorderLayout.CENTER, cnt);
}
}
if (right != null) {
Container cnt = new Container(BoxLayout.x());
$(cnt).setAlignment(RIGHT);
for (ActionNode action : right) {
// System.out.println("right node "+action);
cnt.add(action.getViewFactory().createActionView(entity, action));
}
// System.out.println("Adding to right "+cnt);
actionsBarRight.add(BorderLayout.CENTER, cnt);
}
if (overflow != null && !overflow.isEmpty()) {
PopupMenu popup = new PopupMenu();
for (ActionNode action : overflow) {
Property.Label label = action.getLabel();
String labelStr = label != null ? label.getValue() : "";
Command cmd = new Command(labelStr) {
@Override
public void actionPerformed(ActionEvent evt) {
action.fireEvent(entity, target);
}
};
if (action.getImageIcon() != null) {
cmd.setIcon(action.getImageIcon().getValue());
} else if (action.getMaterialIcon() != null) {
cmd.setMaterialIcon(action.getMaterialIcon().getValue());
}
popup.addCommand(cmd);
}
actionsBarRight.add(BorderLayout.EAST, new Button(popup.getCommand()));
}
if (actionsBarRight.getComponentCount() > 0) {
actionsBar.add(BorderLayout.EAST, actionsBarRight);
}
if (actionsBar.getComponentCount() > 0) {
target.add(actionsBar);
}
}
use of com.codename1.rad.models.Entity in project CodeRAD by shannah.
the class Actions method addToContainer.
public void addToContainer(Container cnt, Entity entity, ComponentSelector.ComponentMapper wrapper) {
boolean requiresFlowLayoutWrapperForBadge = (cnt.getLayout() instanceof GridLayout || cnt.getLayout() instanceof BorderLayout || cnt.getLayout() instanceof BoxLayout);
for (ActionNode n : this) {
if (requiresFlowLayoutWrapperForBadge && n.getBadge() != null) {
// If there is a badge, we'll wrap it in a flowlayout
Container fl = FlowLayout.encloseCenter(n.createView(entity));
fl.getStyle().stripMarginAndPadding();
if (wrapper == null) {
cnt.addComponent(fl);
} else {
cnt.addComponent(wrapper.map(fl));
}
} else {
if (wrapper == null) {
cnt.addComponent(n.createView(entity));
} else {
cnt.addComponent(wrapper.map(n.createView(entity)));
}
}
}
}
use of com.codename1.rad.models.Entity in project CodeRAD by shannah.
the class ProfileAvatarsTitleComponent method initUI.
private void initUI() {
setLayout(new BorderLayout());
wrapper = new Container(new FanLayout(FanLayout.X_AXIS));
avatarWrapperViewController.setView(wrapper);
$(wrapper).selectAllStyles().setPadding(0).setMargin(0).setBorder(Border.createEmpty());
int len = getEntity().size();
for (int i = len - 1; i >= 0; i--) {
// for (Entity child : getEntity()) {
Entity child = getEntity().get(i);
ProfileAvatarView v = createAvatar(child);
wrapper.add(v);
}
add(CENTER, wrapper);
StringBuilder text = new StringBuilder();
Property nameProp = getEntity().getRowType().findProperty(Thing.name);
if (getEntity().size() > 0) {
if (nameProp != null) {
text.append(getEntity().get(0).getEntity().getText(nameProp));
}
}
if (getEntity().size() == 2) {
if (nameProp != null) {
text.append(" & ").append(getEntity().get(1).getEntity().getText(nameProp));
}
}
if (getEntity().size() > 2) {
if (text.length() == 0) {
text.append(getEntity().size()).append(" People");
} else {
text.append(" and ").append(getEntity().size() - 1).append(" others");
}
}
Label lbl = new Label(text.toString());
lbl.setUIID("AccountAvatarsTitleComponentText");
add(SOUTH, FlowLayout.encloseCenter(lbl));
}
use of com.codename1.rad.models.Entity in project CodeRAD by shannah.
the class ProfileAvatarsTitleComponent method createAvatar.
/**
* Creates individual avatar component.
* @param row
* @return
*/
private ProfileAvatarView createAvatar(Entity row) {
// We will intercept the individual avatar actions by inserting our own actions here.
// We will then handle the clicks and long presses ourselves, because
// we may need to expand the list of avatars and allow the user to
// choose an avatar from the list.
ViewNode childNode = new ViewNode(UI.actions(ProfileAvatarView.PROFILE_AVATAR_CLICKED, interceptAvatarClicked), UI.actions(ProfileAvatarView.PROFILE_AVATAR_LONG_PRESS, interceptAvatarLongPress));
childNode.setParent(getViewNode());
ProfileAvatarView v = new ProfileAvatarView(row, childNode, avatarSizeMM);
return v;
}
use of com.codename1.rad.models.Entity 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();
}
}
}
}
Aggregations