Example usage for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel

List of usage examples for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel

Introduction

In this page you can find the example usage for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel.

Prototype

AbstractReadOnlyModel

Source Link

Usage

From source file:com.evolveum.midpoint.web.component.search.SearchItemPanel.java

License:Apache License

private void initPopover() {
    WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER);
    popover.setOutputMarkupId(true);//from  w ww. j av  a  2  s .c o m
    add(popover);

    WebMarkupContainer popoverBody = new WebMarkupContainer(ID_POPOVER_BODY);
    popoverBody.setOutputMarkupId(true);
    popover.add(popoverBody);

    ListView values = new ListView<DisplayableValue>(ID_VALUES,
            new PropertyModel<List<DisplayableValue>>(popoverModel, SearchItem.F_VALUES)) {

        @Override
        protected void populateItem(final ListItem<DisplayableValue> item) {
            item.add(AttributeModifier.replace("style", new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    return item.getIndex() != 0 ? "margin-top: 5px;" : null;
                }
            }));

            SearchPopupPanel fragment = createPopoverFragment(item.getModel());
            fragment.setRenderBodyOnly(true);
            item.add(fragment);
        }
    };
    popoverBody.add(values);

    AjaxSubmitButton update = new AjaxSubmitButton(ID_UPDATE, createStringResource("SearchItemPanel.update")) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            updateItemPerformed(target);
        }
    };
    popoverBody.add(update);

    AjaxButton close = new AjaxButton(ID_CLOSE, createStringResource("SearchItemPanel.close")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            closeEditPopoverPerformed(target);
        }
    };
    popoverBody.add(close);
}

From source file:com.evolveum.midpoint.web.component.search.SearchItemPanel.java

License:Apache License

private IModel<List<DisplayableValue>> createBooleanChoices() {
    return new AbstractReadOnlyModel<List<DisplayableValue>>() {

        @Override/*from  w  w  w  .j  a v  a 2s .co m*/
        public List<DisplayableValue> getObject() {
            List<DisplayableValue> list = new ArrayList<>();
            list.add(new SearchValue(Boolean.TRUE, getString("Boolean.TRUE")));
            list.add(new SearchValue(Boolean.FALSE, getString("Boolean.FALSE")));

            return list;
        }
    };
}

From source file:com.evolveum.midpoint.web.component.search.SearchItemPanel.java

License:Apache License

private IModel<String> createLabelModel() {
    return new AbstractReadOnlyModel<String>() {

        @Override// w  w  w .j a  va2  s  .co m
        public String getObject() {
            SearchItem item = getModelObject();

            StringBuilder sb = new StringBuilder();
            sb.append(item.getName());
            sb.append(": ");

            List<String> values = new ArrayList<>();
            for (DisplayableValue value : (List<DisplayableValue>) item.getValues()) {
                if (StringUtils.isNotEmpty(value.getLabel())) {
                    values.add(value.getLabel());
                }
            }

            if (!values.isEmpty()) {
                String or = createStringResource("SearchItemPanel.or").getString();

                sb.append('"');
                sb.append(StringUtils.join(values, "\" " + or + " \""));
                sb.append('"');
            } else {
                String all = createStringResource("SearchItemPanel.all").getString();
                sb.append(all);
            }

            return sb.toString();
        }
    };
}

From source file:com.evolveum.midpoint.web.component.search.SearchPanel.java

License:Apache License

private IModel<String> createAdvancedGroupLabelStyle() {
    return new AbstractReadOnlyModel<String>() {

        @Override/*from w  w w.  j a va2  s  .c o m*/
        public String getObject() {
            Search search = getModelObject();

            return StringUtils.isEmpty(search.getAdvancedError()) ? "fa-check-circle-o"
                    : "fa-exclamation-triangle";
        }
    };
}

From source file:com.evolveum.midpoint.web.component.search.SearchPanel.java

License:Apache License

private IModel<String> createAdvancedGroupStyle() {
    return new AbstractReadOnlyModel<String>() {

        @Override//from  w w  w  . j  av  a  2 s  . c  om
        public String getObject() {
            Search search = getModelObject();

            return StringUtils.isEmpty(search.getAdvancedError()) ? "has-success" : "has-error";
        }
    };
}

From source file:com.evolveum.midpoint.web.component.search.SearchPanel.java

License:Apache License

private IModel<String> createAdvancedModel() {
    return new AbstractReadOnlyModel<String>() {

        @Override// www.  j av  a2s.c om
        public String getObject() {
            Search search = getModelObject();
            String key = search.isShowAdvanced() ? "SearchPanel.basic" : "SearchPanel.advanced";

            return createStringResource(key).getString();
        }
    };
}

From source file:com.evolveum.midpoint.web.component.TabbedPanel.java

License:Apache License

/**
 * Constructor/*from   w w w .j  a v  a  2s .  c  o m*/
 *
 * @param id    component id
 * @param tabs  list of ITab objects used to represent tabs
 * @param model model holding the index of the selected tab
 */
public TabbedPanel(final String id, final IModel<List<T>> tabs, IModel<Integer> model) {
    super(id, model);

    this.tabs = Args.notNull(tabs, "tabs");

    final IModel<Integer> tabCount = new AbstractReadOnlyModel<Integer>() {
        private static final long serialVersionUID = 1L;

        @Override
        public Integer getObject() {
            return tabs.getObject().size();
        }
    };

    WebMarkupContainer tabsContainer = newTabsContainer("tabs-container");
    add(tabsContainer);

    // add the loop used to generate tab names
    tabsContainer.add(new Loop("tabs", tabCount) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final LoopItem item) {
            final int index = item.getIndex();
            final T tab = TabbedPanel.this.tabs.getObject().get(index);

            final WebMarkupContainer titleLink = newLink("link", index);

            titleLink.add(newTitle("title", tab.getTitle(), index));
            item.add(titleLink);
        }

        @Override
        protected LoopItem newItem(final int iteration) {
            return newTabContainer(iteration);
        }
    });

    add(newPanel());
}

From source file:com.evolveum.midpoint.web.component.util.FocusListInlineMenuHelper.java

License:Apache License

private IModel<String> createDeleteConfirmString() {
    return new AbstractReadOnlyModel<String>() {
        @Override/*  w  w  w.  j  a  v a2s. c  o  m*/
        public String getObject() {
            if (singleDelete == null) {
                return parentPage
                        .createStringResource("FocusListInlineMenuHelper.message.deleteObjectConfirm",
                                focusListComponent.getObjectListPanel().getSelectedObjects().size())
                        .getString();
            } else {
                return parentPage
                        .createStringResource("FocusListInlineMenuHelper.message.deleteObjectConfirmSingle",
                                singleDelete.getName())
                        .getString();
            }
        }
    };
}

From source file:com.evolveum.midpoint.web.component.wf.processes.itemApproval.ItemApprovalHistoryPanel.java

License:Apache License

private void initLayout(UserProfileStorage.TableId tableId, int pageSize) {

    add(new DecisionsPanel(ID_DECISIONS_DONE, new AbstractReadOnlyModel<List<DecisionDto>>() {
        @Override//from  w  ww.  java2s  .  c  om
        public List<DecisionDto> getObject() {
            List<DecisionDto> rv = new ArrayList<>();
            WfContextType wfContextType = getModelObject();
            if (wfContextType == null) {
                return rv;
            }
            ItemApprovalProcessStateType instanceState = (ItemApprovalProcessStateType) wfContextType
                    .getProcessSpecificState();
            List<DecisionType> allDecisions = instanceState.getDecisions();
            if (allDecisions == null) {
                return rv;
            }
            for (DecisionType decision : allDecisions) {
                rv.add(new DecisionDto(decision));
            }
            return rv;
        }
    }, tableId, pageSize));

}

From source file:com.evolveum.midpoint.web.component.wf.processes.itemApproval.ItemApprovalPanel.java

License:Apache License

private void initLayout() {

    Label itemToBeApprovedLabel = new Label(ID_ITEM_TO_BE_APPROVED_LABEL,
            new StringResourceModel("${}", new AbstractReadOnlyModel<String>() {
                @Override/* w ww  . jav a 2  s. c o  m*/
                public String getObject() {
                    if (!model.getObject().isAnswered()) {
                        return "ItemApprovalPanel.itemToBeApproved";
                    } else {
                        Boolean result = model.getObject().getAnswerAsBoolean();
                        if (result == null) {
                            return "ItemApprovalPanel.itemThatWasCompleted"; // actually, this should not happen, if the process is ItemApproval
                        } else if (result) {
                            return "ItemApprovalPanel.itemThatWasApproved";
                        } else {
                            return "ItemApprovalPanel.itemThatWasRejected";
                        }
                    }
                }
            }));
    itemToBeApprovedLabel.add(new AttributeModifier("color", new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            if (!model.getObject().isAnswered()) {
                return "black"; // should not be visible, anyway
            } else {
                Boolean result = model.getObject().getAnswerAsBoolean();
                if (result == null) {
                    return "black"; // actually, this should not happen, if the process is ItemApproval
                } else if (result) {
                    return "green";
                } else {
                    return "red";
                }
            }
        }
    }));
    add(itemToBeApprovedLabel);

    Label itemToBeApproved = new Label(ID_ITEM_TO_BE_APPROVED, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {

            ItemApprovalProcessState instanceState = (ItemApprovalProcessState) model.getObject()
                    .getInstanceState().getProcessSpecificState();
            ItemApprovalRequestType approvalRequestType = instanceState.getApprovalRequest();

            if (approvalRequestType == null) {
                return "?";
            } else {
                Object item = approvalRequestType.getItemToApprove();
                if (item instanceof AssignmentType) {
                    AssignmentType assignmentType = (AssignmentType) item;
                    if (assignmentType.getTarget() != null) {
                        return assignmentType.getTarget().toString();
                    } else if (assignmentType.getTargetRef() != null) {
                        return assignmentType.getTargetRef().getOid() + " ("
                                + assignmentType.getTargetRef().getType() + ")";
                    } else {
                        return "?";
                    }
                } else {
                    return item != null ? item.toString() : "(none)";
                }
            }
        }
    });
    add(itemToBeApproved);

    // todo i18n
    Label approvalSchema = new Label(ID_APPROVAL_SCHEMA, new AbstractReadOnlyModel() {
        @Override
        public Object getObject() {
            StringBuilder retval = new StringBuilder();

            ItemApprovalProcessState instanceState = (ItemApprovalProcessState) model.getObject()
                    .getInstanceState().getProcessSpecificState();
            ItemApprovalRequestType approvalRequestType = instanceState.getApprovalRequest();

            if (approvalRequestType == null) {
                return "?";
            } else {
                ApprovalSchemaType approvalSchema = approvalRequestType.getApprovalSchema();
                if (approvalSchema != null) {
                    if (approvalSchema.getName() != null) {
                        retval.append("<b>");
                        retval.append(StringEscapeUtils.escapeHtml(approvalSchema.getName()));
                        retval.append("</b>");
                    }
                    if (approvalSchema.getDescription() != null) {
                        retval.append(" (");
                        retval.append(StringEscapeUtils.escapeHtml(approvalSchema.getDescription()));
                        retval.append(")");
                    }
                    if (approvalSchema.getName() != null || approvalSchema.getDescription() != null) {
                        retval.append("<br/>");
                    }
                    retval.append("Levels:<p/><ol>");
                    for (ApprovalLevelType level : approvalSchema.getLevel()) {
                        retval.append("<li>");
                        if (level.getName() != null) {
                            retval.append(StringEscapeUtils.escapeHtml(level.getName()));
                        } else {
                            retval.append("unnamed level");
                        }
                        if (level.getDescription() != null) {
                            retval.append(" (");
                            retval.append(StringEscapeUtils.escapeHtml(level.getDescription()));
                            retval.append(")");
                        }
                        if (level.getEvaluationStrategy() != null) {
                            retval.append(" [" + level.getEvaluationStrategy() + "]");
                        }
                        if (level.getAutomaticallyApproved() != null) {
                            String desc = level.getAutomaticallyApproved().getDescription();
                            if (desc != null) {
                                retval.append(" (auto-approval condition: " + StringEscapeUtils.escapeHtml(desc)
                                        + ")");
                            } else {
                                retval.append(" (auto-approval condition present)");
                            }
                        }
                        retval.append("<br/>Approvers:<ul>");
                        for (ObjectReferenceType approverRef : level.getApproverRef()) {
                            retval.append("<li>");
                            retval.append(approverRef.getOid());
                            if (approverRef.getType() != null) {
                                retval.append(" (" + approverRef.getType().getLocalPart() + ")");
                            }
                            if (approverRef.getDescription() != null) {
                                retval.append(" - " + approverRef.getDescription());
                            }
                            retval.append("</li>");
                        }
                        for (ExpressionType expression : level.getApproverExpression()) {
                            retval.append("<li>Expression: ");
                            // todo display the expression
                            if (expression.getDescription() != null) {
                                retval.append(StringEscapeUtils.escapeHtml(expression.getDescription()));
                            } else {
                                retval.append("(...)");
                            }
                            retval.append("</li>");
                        }
                    }

                    retval.append("</ul>"); // ends the list of approvers
                    retval.append("</ol>"); // ends the list of levels
                }
            }
            return retval.toString();
        }
    });
    approvalSchema.setEscapeModelStrings(false);
    add(approvalSchema);

    add(new Label(ID_DECISIONS_DONE_LABEL,
            new StringResourceModel("ItemApprovalPanel.decisionsDoneWhenFinishedIs_${finished}", model)));

    add(new DecisionsPanel(ID_DECISIONS_DONE, new AbstractReadOnlyModel<List<DecisionDto>>() {
        @Override
        public List<DecisionDto> getObject() {
            List<DecisionDto> retval = new ArrayList<>();
            ItemApprovalProcessState instanceState = (ItemApprovalProcessState) model.getObject()
                    .getInstanceState().getProcessSpecificState();
            List<DecisionType> allDecisions = instanceState.getDecisions();
            if (allDecisions != null) {
                for (DecisionType decision : allDecisions) {
                    retval.add(new DecisionDto(decision));
                }
            }
            return retval;
        }
    }));

    VisibleEnableBehaviour visibleIfRunning = new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return !model.getObject().isFinished();
        }
    };

    Label workItemsPanelLabel = new Label(ID_CURRENT_WORK_ITEMS_LABEL,
            new ResourceModel("ItemApprovalPanel.currentWorkItems"));
    workItemsPanelLabel.add(visibleIfRunning);
    add(workItemsPanelLabel);

    WorkItemsPanel workItemsPanel = new WorkItemsPanel(ID_CURRENT_WORK_ITEMS,
            new PropertyModel<List<WorkItemDto>>(model, "workItems"));
    workItemsPanel.add(visibleIfRunning);
    add(workItemsPanel);
}