Example usage for org.apache.wicket.model Model of

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

Introduction

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

Prototype

public static <T extends Serializable> Model<T> of() 

Source Link

Document

Factory methods for Model which uses type inference to make code shorter.

Usage

From source file:com.evolveum.midpoint.gui.api.component.ResourceTypeAssignmentPopupTabPanel.java

License:Apache License

@Override
protected void initParametersPanel(Fragment parametersPanel) {
    initModels();/*www  .  j  a  va  2s  .  com*/

    WebMarkupContainer kindContainer = new WebMarkupContainer(ID_KIND_CONTAINER);
    kindContainer.setOutputMarkupId(true);
    parametersPanel.add(kindContainer);

    DropDownChoicePanel<ShadowKindType> kindSelector = WebComponentUtil.createEnumPanel(ShadowKindType.class,
            ID_KIND, WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), Model.of(),
            ResourceTypeAssignmentPopupTabPanel.this, true);
    kindSelector.setOutputMarkupId(true);
    kindSelector.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            kindValueUpdatePerformed(target);
        }
    });
    kindSelector.getBaseFormComponent().add(new VisibleEnableBehaviour() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0;
        }
    });
    kindSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    kindSelector.setOutputMarkupPlaceholderTag(true);
    kindContainer.add(kindSelector);

    WebMarkupContainer intentContainer = new WebMarkupContainer(ID_INTENT_CONTAINER);
    intentContainer.setOutputMarkupId(true);
    parametersPanel.add(intentContainer);

    DropDownChoicePanel<String> intentSelector = new DropDownChoicePanel<String>(ID_INTENT, Model.of(),
            intentValues, true);
    intentSelector.getBaseFormComponent().add(new VisibleEnableBehaviour() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getKindValue() != null && getSelectedObjectsList() != null
                    && getSelectedObjectsList().size() > 0;
        }
    });
    intentSelector.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            intentValueUpdatePerformed(target);
        }
    });
    intentSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    intentSelector.setOutputMarkupId(true);
    intentSelector.setOutputMarkupPlaceholderTag(true);
    intentContainer.add(intentSelector);

    WebMarkupContainer associationContainer = new WebMarkupContainer(ID_ASSOCIATION_CONTAINER);
    associationContainer.setOutputMarkupId(true);
    associationContainer.add(new VisibleBehaviour(() -> isEntitlementAssignment()));
    parametersPanel.add(associationContainer);

    DropDownChoicePanel<RefinedAssociationDefinition> associationSelector = new DropDownChoicePanel<>(
            ID_ASSOCIATION, Model.of(), associationValuesModel,
            new IChoiceRenderer<RefinedAssociationDefinition>() {
                private static final long serialVersionUID = 1L;

                @Override
                public Object getDisplayValue(RefinedAssociationDefinition refinedAssociationDefinition) {
                    return WebComponentUtil.getAssociationDisplayName(refinedAssociationDefinition);
                }

                @Override
                public String getIdValue(RefinedAssociationDefinition refinedAssociationDefinition, int index) {
                    return Integer.toString(index);
                }

                @Override
                public RefinedAssociationDefinition getObject(String id,
                        IModel<? extends List<? extends RefinedAssociationDefinition>> choices) {
                    return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
                }
            }, true);
    associationSelector.setOutputMarkupId(true);
    associationSelector.getBaseFormComponent().add(new VisibleEnableBehaviour() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0
                    && getKindValue() != null && StringUtils.isNotEmpty(getIntentValue());
        }
    });
    associationSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    associationSelector.setOutputMarkupPlaceholderTag(true);
    associationContainer.add(associationSelector);

}

From source file:com.evolveum.midpoint.web.component.assignment.AbstractAssignmentDetailsPanel.java

License:Apache License

protected <C extends Containerable> void initLayout() {

    final IModel<C> displayNameModel = new IModel<C>() {

        private static final long serialVersionUID = 1L;

        @Override/*from   www .j  a v  a2  s  . com*/
        public C getObject() {
            AssignmentType assignment = getModelObject().getContainerValue().getValue();
            if (assignment.getTargetRef() != null) {
                Task task = getPageBase().createSimpleTask("Load target");
                com.evolveum.midpoint.schema.result.OperationResult result = task.getResult();
                return (C) WebModelServiceUtils
                        .loadObject(assignment.getTargetRef(), getPageBase(), task, result).asObjectable();
            }
            if (assignment.getConstruction() != null && assignment.getConstruction().getResourceRef() != null) {
                Task task = getPageBase().createSimpleTask("Load resource");
                com.evolveum.midpoint.schema.result.OperationResult result = task.getResult();
                return (C) WebModelServiceUtils
                        .loadObject(assignment.getConstruction().getResourceRef(), getPageBase(), task, result)
                        .asObjectable();
            } else if (assignment.getPersonaConstruction() != null) {
                return (C) assignment.getPersonaConstruction();
            } else if (assignment.getPolicyRule() != null) {
                return (C) assignment.getPolicyRule();
            }

            return null;
        }

    };

    DisplayNamePanel<C> displayNamePanel = new DisplayNamePanel<C>(ID_DISPLAY_NAME, displayNameModel) {

        @Override
        protected QName getRelation() {
            // TODO: is this correct ?
            AssignmentType assignment = AbstractAssignmentDetailsPanel.this.getModelObject().getContainerValue()
                    .getValue();
            if (assignment.getTargetRef() != null) {
                return assignment.getTargetRef().getRelation();
            } else {
                return null;
            }
        }

        @Override
        protected IModel<String> getKindIntentLabelModel() {
            AssignmentType assignment = AbstractAssignmentDetailsPanel.this.getModelObject().getContainerValue()
                    .getValue();
            if (assignment.getConstruction() != null) {
                return createStringResource("DisplayNamePanel.kindIntentLabel",
                        assignment.getConstruction().getKind(), assignment.getConstruction().getIntent());
            }
            return Model.of();
        }

    };

    displayNamePanel.setOutputMarkupId(true);
    add(displayNamePanel);

    PageAdminObjectDetails<F> pageBase = (PageAdminObjectDetails<F>) getPageBase();

    ItemPath assignmentPath = getModelObject().getPath();

    Form form = new Form<>("form");

    ContainerValueWrapper<AssignmentType> containerWrapper = getModelObject();
    if (containerWrapper == null) {
    }

    ContainerValuePanel<AssignmentType> assignmentPanel = new ContainerValuePanel(ID_BASIC_ASSIGNMENT_PANEL,
            getModel(), true, form, itemWrapper -> getAssignmentBasicTabVisibity(itemWrapper, assignmentPath),
            pageBase);
    add(assignmentPanel);

    ContainerWrapperFromObjectWrapperModel<ActivationType, F> activationModel = new ContainerWrapperFromObjectWrapperModel<>(
            pageBase.getObjectModel(), assignmentPath.append(AssignmentType.F_ACTIVATION));
    PrismContainerPanel<ActivationType> acitvationContainer = new PrismContainerPanel<>(ID_ACTIVATION_PANEL,
            activationModel, true, form,
            itemWrapper -> getActivationVisibileItems(itemWrapper.getPath(), assignmentPath), pageBase);
    add(acitvationContainer);

    initContainersPanel(form, pageBase);
}

From source file:com.evolveum.midpoint.web.component.assignment.AssignmentPanel.java

License:Apache License

private IModel<String> getKindIntentLabelModelForDisplayNamePanel(
        ContainerValueWrapper<AssignmentType> modelObject) {
    AssignmentType assignment = modelObject.getContainerValue().getValue();
    if (assignment.getConstruction() != null) {
        return createStringResource("DisplayNamePanel.kindIntentLabel", assignment.getConstruction().getKind(),
                assignment.getConstruction().getIntent());
    }/*from www .  ja  v a2  s. c o m*/
    return Model.of();
}

From source file:com.evolveum.midpoint.web.component.assignment.AssignmentPanel.java

License:Apache License

protected IModel<ContainerWrapper> getSpecificContainerModel(
        ContainerValueWrapper<AssignmentType> modelObject) {
    return Model.of();
}

From source file:com.gitblit.wicket.panels.CommentPanel.java

License:Apache License

@Override
protected void onInitialize() {
    super.onInitialize();

    Form<String> form = new Form<String>("editorForm");
    add(form);/* w w  w .  j a  v  a  2 s .  c om*/

    form.add(new AjaxButton("submit", new Model<String>(getString("gb.comment")), form) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(AjaxRequestTarget target) {
            String txt = markdownEditor.getText();
            if (change == null) {
                // new comment
                Change newComment = new Change(user.username);
                newComment.comment(txt);
                if (!ticket.isWatching(user.username)) {
                    newComment.watch(user.username);
                }
                RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
                TicketModel updatedTicket = app().tickets().updateTicket(repository, ticket.number, newComment);
                if (updatedTicket != null) {
                    app().tickets().createNotifier().sendMailing(updatedTicket);
                    redirectTo(pageClass,
                            WicketUtils.newObjectParameter(updatedTicket.repository, "" + ticket.number));
                } else {
                    error("Failed to add comment!");
                }
            } else {
                // TODO update comment
            }
        }

        /**
         * Steal from BasePage to realize redirection.
         * 
         * @see BasePage
         * @author krulls@GitHub; ECG Leipzig GmbH, Germany, 2015
         * 
         * @param pageClass
         * @param parameters
         * @return
         */
        private void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
            String absoluteUrl = GitBlitRequestUtils.toAbsoluteUrl(pageClass, parameters);
            getRequestCycle().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(absoluteUrl));
        }

    }.setVisible(ticket != null && ticket.number > 0));

    final IModel<String> markdownPreviewModel = Model.of();
    markdownPreview = new Label("markdownPreview", markdownPreviewModel);
    markdownPreview.setEscapeModelStrings(false);
    markdownPreview.setOutputMarkupId(true);
    add(markdownPreview);

    markdownEditor = new MarkdownTextArea("markdownEditor", markdownPreviewModel, markdownPreview);
    markdownEditor.setRepository(repositoryName);
    WicketUtils.setInputPlaceholder(markdownEditor, getString("gb.leaveComment"));
    add(markdownEditor);
}

From source file:com.github.ilmoeuro.hackmikkeli2016.ui.HmLink.java

License:Open Source License

public HmLink(String id, SerializableAction action) {
    super(id, Model.of());
    this.action = action;
}

From source file:com.romeikat.datamessie.core.base.ui.panel.AsynchronousUpdatePanel.java

License:Open Source License

/**
 * Creates the panel./*  w  ww . j  a v a 2s. co  m*/
 *
 * @param id
 * @param callableParameterModel
 * @param updateInterval
 */
public AsynchronousUpdatePanel(final String id, final Duration updateInterval) {
    super(id, Model.of());

    final Callable<T> callable = createCallable();
    future = EXECUTOR.submit(callable);

    // Behaviour
    final FutureUpdateBehavior<T> behaviour = createBehavior(updateInterval);
    add(behaviour);

    // Loading...
    final Label loadingLabel = createLoadingLabel(STATUS_COMPONENT_ID);
    add(loadingLabel);
}

From source file:cz.muni.exceptions.web.pages.ExceptionDetailPage.java

License:Apache License

private IModel<Ticket> preparePageModel(PageParameters params) {
    StringValue idValue = params.get("ticketId");
    if (idValue.isEmpty()) {
        getSession()//from   w w w .j  a v  a 2  s . c  o m
                .error("Ooops!! It's not possible to show ticket detail, because id of ticket wasn't provided");
        throw new RestartResponseException(ExceptionsPage.class);
    }

    Long id = null;
    try {
        id = Long.parseLong(idValue.toString());
        Ticket ticket = ticketService.getTicket(id);
        return new CompoundPropertyModel<Ticket>(ticket);
    } catch (NumberFormatException ex) {
        getSession().error("Oopps!! Ticket does not exists.");
        throw new RestartResponseException(ExceptionsPage.class);
    } catch (Exception ex) {
        getSession().error("Ooppss!! We have some technical difficulties. Please try later.");
        return Model.of();
    }
}