Search in sources :

Example 11 with CompoundPropertyModel

use of org.apache.wicket.model.CompoundPropertyModel in project syncope by apache.

the class HistoryConfDetails method initDropdownDiffConfForm.

private Form<?> initDropdownDiffConfForm() {
    final Form<T> form = new Form<>("form");
    form.setModel(new CompoundPropertyModel<>(selectedHistoryConfTO));
    form.setOutputMarkupId(true);
    final Map<String, String> namesMap = getDropdownNamesMap(availableHistoryConfTOs);
    List<String> keys = new ArrayList<>(namesMap.keySet());
    final AjaxDropDownChoicePanel<String> dropdownElem = new AjaxDropDownChoicePanel<>("compareDropdown", getString("compare"), new PropertyModel<>(selectedHistoryConfTO, "key"), false);
    dropdownElem.setChoices(keys);
    dropdownElem.setChoiceRenderer(new IChoiceRenderer<String>() {

        private static final long serialVersionUID = -6265603675261014912L;

        @Override
        public Object getDisplayValue(final String value) {
            return namesMap.get(value) == null ? value : namesMap.get(value);
        }

        @Override
        public String getIdValue(final String value, final int i) {
            return value;
        }

        @Override
        public String getObject(final String id, final IModel<? extends List<? extends String>> choices) {
            return id;
        }
    });
    dropdownElem.setNullValid(true);
    dropdownElem.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            List<T> elemsToCompare = new ArrayList<>();
            elemsToCompare.add(selectedHistoryConfTO);
            final String selectedKey = dropdownElem.getModelObject();
            if (selectedKey != null) {
                if (!selectedKey.isEmpty()) {
                    T confToCompare = availableHistoryConfTOs.stream().filter(object -> object.getKey().equals(selectedKey)).findAny().orElse(null);
                    elemsToCompare.add(confToCompare);
                    showConfigurationDiffPanel(elemsToCompare);
                } else {
                    showConfigurationSinglePanel();
                }
            }
            target.add(jsonPanel);
        }
    });
    form.add(dropdownElem);
    return form;
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) Form(org.apache.wicket.markup.html.form.Form) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) SyncopeConsoleSession(org.apache.syncope.client.console.SyncopeConsoleSession) ResourceHistoryConfTO(org.apache.syncope.common.lib.to.ResourceHistoryConfTO) JsonDiffPanel(org.apache.syncope.client.console.wicket.markup.html.form.JsonDiffPanel) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IModel(org.apache.wicket.model.IModel) ResourceRestClient(org.apache.syncope.client.console.rest.ResourceRestClient) JsonEditorPanel(org.apache.syncope.client.console.wicket.markup.html.form.JsonEditorPanel) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) BaseModal(org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractHistoryConf(org.apache.syncope.common.lib.to.AbstractHistoryConf) IOException(java.io.IOException) PageReference(org.apache.wicket.PageReference) Collectors(java.util.stream.Collectors) List(java.util.List) ConnInstanceHistoryConfTO(org.apache.syncope.common.lib.to.ConnInstanceHistoryConfTO) PropertyModel(org.apache.wicket.model.PropertyModel) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) ConnectorRestClient(org.apache.syncope.client.console.rest.ConnectorRestClient) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with CompoundPropertyModel

use of org.apache.wicket.model.CompoundPropertyModel in project syncope by apache.

the class UserDirectoryPanel method getActions.

@Override
public ActionsPanel<UserTO> getActions(final IModel<UserTO> model) {
    final ActionsPanel<UserTO> panel = super.getActions(model);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            send(UserDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(new UserWrapper(new UserRestClient().read(model.getObject().getKey())), target));
        }
    }, ActionType.EDIT, StringUtils.join(new String[] { StandardEntitlement.USER_READ, StandardEntitlement.USER_UPDATE }, ",")).setRealm(realm);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            UserTO clone = SerializationUtils.clone(model.getObject());
            clone.setKey(null);
            clone.setUsername(model.getObject().getUsername() + "_clone");
            send(UserDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new UserWrapper(clone), target));
        }

        @Override
        protected boolean statusCondition(final UserTO modelObject) {
            return addAjaxLink.isVisibleInHierarchy() && realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.CLONE, StandardEntitlement.USER_CREATE).setRealm(realm);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            try {
                UserRestClient.class.cast(restClient).mustChangePassword(model.getObject().getETagValue(), !model.getObject().isMustChangePassword(), model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (Exception e) {
                LOG.error("While actioning object {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionType.MUSTCHANGEPASSWORD, StandardEntitlement.USER_UPDATE).setRealm(realm);
    if (wizardInModal) {
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -4875218360625971340L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                displayAttributeModal.setFormModel(formModel);
                target.add(displayAttributeModal.setContent(new ChangePasswordModal(displayAttributeModal, pageRef, new UserWrapper(model.getObject()))));
                displayAttributeModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                displayAttributeModal.show(true);
            }
        }, ActionType.PASSWORD_MANAGEMENT, StandardEntitlement.USER_UPDATE).setRealm(realm);
        if (SyncopeConsoleSession.get().getPlatformInfo().isPwdResetAllowed() && !SyncopeConsoleSession.get().getPlatformInfo().isPwdResetRequiringSecurityQuestions()) {
            panel.add(new ActionLink<UserTO>() {

                private static final long serialVersionUID = -7978723352517770644L;

                @Override
                public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                    try {
                        SyncopeConsoleSession.get().getAnonymousClient().getService(UserSelfService.class).requestPasswordReset(model.getObject().getUsername(), null);
                        SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                        target.add(container);
                    } catch (Exception e) {
                        LOG.error("While actioning object {}", model.getObject().getKey(), e);
                        SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                    }
                    ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
                }
            }, ActionType.REQUEST_PASSWORD_RESET, StandardEntitlement.USER_UPDATE).setRealm(realm);
        }
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                altDefaultModal.setFormModel(formModel);
                target.add(altDefaultModal.setContent(new AnyStatusModal<>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), "resource", true)));
                altDefaultModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                altDefaultModal.show(true);
            }
        }, ActionType.ENABLE, StandardEntitlement.USER_UPDATE).setRealm(realm);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                altDefaultModal.setFormModel(formModel);
                target.add(altDefaultModal.setContent(new AnyStatusModal<>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), "resource", false)));
                altDefaultModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                altDefaultModal.show(true);
            }
        }, ActionType.MANAGE_RESOURCES, StandardEntitlement.USER_UPDATE).setRealm(realm);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                target.add(utilityModal.setContent(new AnyPropagationTasks(utilityModal, AnyTypeKind.USER, model.getObject().getKey(), pageRef)));
                utilityModal.header(new StringResourceModel("any.propagation.tasks", model));
                utilityModal.show(true);
            }
        }, ActionType.PROPAGATION_TASKS, StandardEntitlement.TASK_LIST);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                target.add(utilityModal.setContent(new NotificationTasks(AnyTypeKind.USER, model.getObject().getKey(), pageRef)));
                utilityModal.header(new StringResourceModel("any.notification.tasks", model));
                utilityModal.show(true);
                target.add(utilityModal);
            }
        }, ActionType.NOTIFICATION_TASKS, StandardEntitlement.TASK_LIST);
    }
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            try {
                restClient.delete(model.getObject().getETagValue(), model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (Exception e) {
                LOG.error("While deleting object {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }

        @Override
        protected boolean statusCondition(final UserTO modelObject) {
            return realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.DELETE, StandardEntitlement.USER_DELETE, true).setRealm(realm);
    return panel;
}
Also used : CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) AnyWrapper(org.apache.syncope.client.console.wizards.any.AnyWrapper) NotificationTasks(org.apache.syncope.client.console.notifications.NotificationTasks) UserWrapper(org.apache.syncope.client.console.wizards.any.UserWrapper) UserRestClient(org.apache.syncope.client.console.rest.UserRestClient) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AnyStatusModal(org.apache.syncope.client.console.status.AnyStatusModal) AnyPropagationTasks(org.apache.syncope.client.console.tasks.AnyPropagationTasks) UserTO(org.apache.syncope.common.lib.to.UserTO) ChangePasswordModal(org.apache.syncope.client.console.status.ChangePasswordModal) StringResourceModel(org.apache.wicket.model.StringResourceModel) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Example 13 with CompoundPropertyModel

use of org.apache.wicket.model.CompoundPropertyModel in project syncope by apache.

the class RemediationDirectoryPanel method getActions.

@Override
protected ActionsPanel<RemediationTO> getActions(final IModel<RemediationTO> model) {
    ActionsPanel<RemediationTO> panel = super.getActions(model);
    panel.add(new ActionLink<RemediationTO>() {

        private static final long serialVersionUID = 6193210574968203299L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
            modal.header(new ResourceModel("error"));
            modal.setContent(new ExecMessageModal(model.getObject().getError()));
            modal.show(true);
            target.add(modal);
        }
    }, ActionLink.ActionType.VIEW_DETAILS, StandardEntitlement.REMEDIATION_READ);
    if (model.getObject().getOperation() == ResourceOperation.DELETE) {
        String entitlements = StringUtils.join(new String[] { StandardEntitlement.REMEDIATION_REMEDY, AnyTypeKind.USER.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.USER_DELETE : AnyTypeKind.GROUP.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.GROUP_DELETE : AnyEntitlement.DELETE.getFor(model.getObject().getAnyType()) }, ",");
        panel.add(new ActionLink<RemediationTO>() {

            private static final long serialVersionUID = 6193210574968203299L;

            @Override
            public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
                try {
                    restClient.remedy(model.getObject().getKey(), model.getObject().getKeyPayload());
                    SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                    target.add(container);
                } catch (SyncopeClientException e) {
                    LOG.error("While performing remediation {}", model.getObject().getKey(), e);
                    SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                }
                ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
            }
        }, ActionLink.ActionType.CLOSE, entitlements, true);
    } else {
        String entitlements = model.getObject().getOperation() == ResourceOperation.CREATE ? StringUtils.join(new String[] { StandardEntitlement.REMEDIATION_REMEDY, AnyTypeKind.USER.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.USER_CREATE : AnyTypeKind.GROUP.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.GROUP_CREATE : AnyEntitlement.CREATE.getFor(model.getObject().getAnyType()) }, ",") : StringUtils.join(new String[] { StandardEntitlement.REMEDIATION_REMEDY, AnyTypeKind.USER.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.USER_UPDATE : AnyTypeKind.GROUP.name().equals(model.getObject().getAnyType()) ? StandardEntitlement.GROUP_UPDATE : AnyEntitlement.UPDATE.getFor(model.getObject().getAnyType()) }, ",");
        panel.add(new ActionLink<RemediationTO>() {

            private static final long serialVersionUID = 6193210574968203299L;

            @Override
            public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
                modal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
                RemediationTO remediationTO = model.getObject();
                switch(remediationTO.getAnyType()) {
                    case "USER":
                        UserTO newUserTO;
                        UserTO previousUserTO;
                        if (remediationTO.getAnyPatchPayload() == null) {
                            newUserTO = (UserTO) remediationTO.getAnyTOPayload();
                            previousUserTO = null;
                        } else {
                            previousUserTO = new UserRestClient().read(remediationTO.getAnyPatchPayload().getKey());
                            newUserTO = AnyOperations.patch(previousUserTO, (UserPatch) remediationTO.getAnyPatchPayload());
                        }
                        AjaxWizard.EditItemActionEvent<UserTO> userEvent = new AjaxWizard.EditItemActionEvent<>(newUserTO, target);
                        userEvent.forceModalPanel(new RemediationUserWizardBuilder(model.getObject(), previousUserTO, newUserTO, new AnyTypeRestClient().read(remediationTO.getAnyType()).getClasses(), FormLayoutInfoUtils.fetch(Arrays.asList(remediationTO.getAnyType())).getLeft(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
                        send(RemediationDirectoryPanel.this, Broadcast.EXACT, userEvent);
                        break;
                    case "GROUP":
                        GroupTO newGroupTO;
                        GroupTO previousGroupTO;
                        if (remediationTO.getAnyPatchPayload() == null) {
                            newGroupTO = (GroupTO) remediationTO.getAnyTOPayload();
                            previousGroupTO = null;
                        } else {
                            previousGroupTO = new GroupRestClient().read(remediationTO.getAnyPatchPayload().getKey());
                            newGroupTO = AnyOperations.patch(previousGroupTO, (GroupPatch) remediationTO.getAnyPatchPayload());
                        }
                        AjaxWizard.EditItemActionEvent<GroupTO> groupEvent = new AjaxWizard.EditItemActionEvent<>(newGroupTO, target);
                        groupEvent.forceModalPanel(new RemediationGroupWizardBuilder(model.getObject(), previousGroupTO, newGroupTO, new AnyTypeRestClient().read(remediationTO.getAnyType()).getClasses(), FormLayoutInfoUtils.fetch(Arrays.asList(remediationTO.getAnyType())).getMiddle(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
                        send(RemediationDirectoryPanel.this, Broadcast.EXACT, groupEvent);
                        break;
                    default:
                        AnyObjectTO newAnyObjectTO;
                        AnyObjectTO previousAnyObjectTO;
                        if (remediationTO.getAnyPatchPayload() == null) {
                            newAnyObjectTO = (AnyObjectTO) remediationTO.getAnyTOPayload();
                            previousAnyObjectTO = null;
                        } else {
                            previousAnyObjectTO = new AnyObjectRestClient().read(remediationTO.getAnyPatchPayload().getKey());
                            newAnyObjectTO = AnyOperations.patch(previousAnyObjectTO, (AnyObjectPatch) remediationTO.getAnyPatchPayload());
                        }
                        AjaxWizard.EditItemActionEvent<AnyObjectTO> anyObjectEvent = new AjaxWizard.EditItemActionEvent<>(newAnyObjectTO, target);
                        anyObjectEvent.forceModalPanel(new RemediationAnyObjectWizardBuilder(model.getObject(), previousAnyObjectTO, newAnyObjectTO, new AnyTypeRestClient().read(remediationTO.getAnyType()).getClasses(), FormLayoutInfoUtils.fetch(Arrays.asList(remediationTO.getAnyType())).getRight().values().iterator().next(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
                        send(RemediationDirectoryPanel.this, Broadcast.EXACT, anyObjectEvent);
                }
            }
        }, ActionLink.ActionType.EDIT, entitlements);
    }
    panel.add(new ActionLink<RemediationTO>() {

        private static final long serialVersionUID = 6193210574968203299L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RemediationTO ignore) {
            try {
                restClient.delete(model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.REMEDIATION_DELETE, true);
    return panel;
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ResourceModel(org.apache.wicket.model.ResourceModel) StringResourceModel(org.apache.wicket.model.StringResourceModel) GroupRestClient(org.apache.syncope.client.console.rest.GroupRestClient) AnyObjectRestClient(org.apache.syncope.client.console.rest.AnyObjectRestClient) BasePage(org.apache.syncope.client.console.pages.BasePage) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) AnyTypeRestClient(org.apache.syncope.client.console.rest.AnyTypeRestClient) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RemediationTO(org.apache.syncope.common.lib.to.RemediationTO) UserRestClient(org.apache.syncope.client.console.rest.UserRestClient) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) UserTO(org.apache.syncope.common.lib.to.UserTO)

Example 14 with CompoundPropertyModel

use of org.apache.wicket.model.CompoundPropertyModel in project oc-explorer by devgateway.

the class ListViewSectionPanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);
    listWrapper = new TransparentWebMarkupContainer("listWrapper");
    listWrapper.setOutputMarkupId(true);
    add(listWrapper);
    listWrapper.add(new Label("panelTitle", title));
    listView = new ListView<T>("list", getModel()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<T> item) {
            // we wrap the item model on a compound model so we can use the field ids as property models
            final CompoundPropertyModel<T> compoundPropertyModel = new CompoundPropertyModel<>(item.getModel());
            // we set back the model as the compound model, thus ensures the rest of the items added will benefit
            item.setModel(compoundPropertyModel);
            // we add the rest of the items in the listItem
            populateCompoundListItem(item);
            // we add the remove button
            final BootstrapDeleteButton removeButton = getRemoveChildButton(item.getIndex());
            item.add(removeButton);
        }
    };
    listView.setReuseItems(true);
    listView.setOutputMarkupId(true);
    listWrapper.add(listView);
    final BootstrapAddButton addButton = getAddNewChildButton();
    add(addButton);
}
Also used : CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) BootstrapDeleteButton(org.devgateway.toolkit.forms.wicket.components.form.BootstrapDeleteButton) BootstrapAddButton(org.devgateway.toolkit.forms.wicket.components.form.BootstrapAddButton) TransparentWebMarkupContainer(org.apache.wicket.markup.html.TransparentWebMarkupContainer) Label(org.apache.wicket.markup.html.basic.Label)

Example 15 with CompoundPropertyModel

use of org.apache.wicket.model.CompoundPropertyModel in project openmeetings by apache.

the class CalendarPanel method onInitialize.

@Override
protected void onInitialize() {
    final Form<Date> form = new Form<>("form");
    add(form);
    dialog = new AppointmentDialog("appointment", this, new CompoundPropertyModel<>(getDefault()));
    add(dialog);
    boolean isRtl = isRtl();
    Options options = new Options();
    options.set("isRTL", isRtl);
    options.set("header", isRtl ? "{left: 'agendaDay,agendaWeek,month', center: 'title', right: 'today nextYear,next,prev,prevYear'}" : "{left: 'prevYear,prev,next,nextYear today', center: 'title', right: 'month,agendaWeek,agendaDay'}");
    options.set("allDaySlot", false);
    options.set("axisFormat", Options.asString("H(:mm)"));
    options.set("defaultEventMinutes", 60);
    options.set("timeFormat", Options.asString("H(:mm)"));
    options.set("buttonText", new JSONObject().put("month", getString("801")).put("week", getString("800")).put("day", getString("799")).put("today", getString("1555")).toString());
    JSONArray monthes = new JSONArray();
    JSONArray shortMonthes = new JSONArray();
    JSONArray days = new JSONArray();
    JSONArray shortDays = new JSONArray();
    // first week day must be Sunday
    days.put(0, getString("466"));
    shortDays.put(0, getString("459"));
    for (int i = 0; i < 12; i++) {
        monthes.put(i, getString(String.valueOf(469 + i)));
        shortMonthes.put(i, getString(String.valueOf(1556 + i)));
        if (i + 1 < 7) {
            days.put(i + 1, getString(String.valueOf(460 + i)));
            shortDays.put(i + 1, getString(String.valueOf(453 + i)));
        }
    }
    options.set("monthNames", monthes.toString());
    options.set("monthNamesShort", shortMonthes.toString());
    options.set("dayNames", days.toString());
    options.set("dayNamesShort", shortDays.toString());
    options.set("firstDay", cfgDao.getInt(CONFIG_CALENDAR_FIRST_DAY, 0));
    calendar = new Calendar("calendar", new AppointmentModel(), options) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onInitialize() {
            super.onInitialize();
            add(new CalendarFunctionsBehavior(getMarkupId()));
        }

        @Override
        public boolean isSelectable() {
            return true;
        }

        @Override
        public boolean isDayClickEnabled() {
            return true;
        }

        @Override
        public boolean isEventClickEnabled() {
            return true;
        }

        @Override
        public boolean isEventDropEnabled() {
            return true;
        }

        @Override
        public boolean isEventResizeEnabled() {
            return true;
        }

        // no need to override onDayClick
        @Override
        public void onSelect(AjaxRequestTarget target, CalendarView view, LocalDateTime start, LocalDateTime end, boolean allDay) {
            Appointment a = getDefault();
            LocalDateTime s = start, e = end;
            if (CalendarView.month == view) {
                LocalDateTime now = ZonedDateTime.now(getZoneId()).toLocalDateTime();
                s = start.withHour(now.getHour()).withMinute(now.getMinute());
                e = s.plus(1, ChronoUnit.HOURS);
            }
            a.setStart(getDate(s));
            a.setEnd(getDate(e));
            dialog.setModelObjectWithAjaxTarget(a, target);
            dialog.open(target);
        }

        @Override
        public void onEventClick(AjaxRequestTarget target, CalendarView view, int eventId) {
            Appointment a = apptDao.get((long) eventId);
            dialog.setModelObjectWithAjaxTarget(a, target);
            dialog.open(target);
        }

        @Override
        public void onEventDrop(AjaxRequestTarget target, int eventId, long delta, boolean allDay) {
            Appointment a = apptDao.get((long) eventId);
            if (!AppointmentDialog.isOwner(a)) {
                return;
            }
            java.util.Calendar cal = WebSession.getCalendar();
            cal.setTime(a.getStart());
            cal.add(java.util.Calendar.MILLISECOND, (int) delta);
            a.setStart(cal.getTime());
            cal.setTime(a.getEnd());
            cal.add(java.util.Calendar.MILLISECOND, (int) delta);
            a.setEnd(cal.getTime());
            apptDao.update(a, getUserId());
            if (a.getCalendar() != null) {
                updatedeleteAppointment(target, CalendarDialog.DIALOG_TYPE.UPDATE_APPOINTMENT, a);
            }
        }

        @Override
        public void onEventResize(AjaxRequestTarget target, int eventId, long delta) {
            Appointment a = apptDao.get((long) eventId);
            if (!AppointmentDialog.isOwner(a)) {
                return;
            }
            java.util.Calendar cal = WebSession.getCalendar();
            cal.setTime(a.getEnd());
            cal.add(java.util.Calendar.MILLISECOND, (int) delta);
            a.setEnd(cal.getTime());
            apptDao.update(a, getUserId());
            if (a.getCalendar() != null) {
                updatedeleteAppointment(target, CalendarDialog.DIALOG_TYPE.UPDATE_APPOINTMENT, a);
            }
        }
    };
    form.add(calendar);
    populateGoogleCalendars();
    add(refreshTimer);
    add(syncTimer);
    calendarDialog = new CalendarDialog("calendarDialog", this, new CompoundPropertyModel<>(getDefaultCalendar()));
    add(calendarDialog);
    calendarListContainer.setOutputMarkupId(true);
    calendarListContainer.add(new ListView<OmCalendar>("items", new LoadableDetachableModel<List<OmCalendar>>() {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<OmCalendar> load() {
            List<OmCalendar> cals = new ArrayList<>(apptManager.getCalendars(getUserId()));
            cals.addAll(apptManager.getGoogleCalendars(getUserId()));
            return cals;
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<OmCalendar> item) {
            item.setOutputMarkupId(true);
            final OmCalendar cal = item.getModelObject();
            item.add(new Button("item", new PropertyModel<String>(cal, "title")).add(new AjaxEventBehavior(EVT_CLICK) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    calendarDialog.open(target, CalendarDialog.DIALOG_TYPE.UPDATE_CALENDAR, cal);
                    target.add(calendarDialog);
                }
            }));
        }
    });
    add(new Button("syncCalendarButton").add(new AjaxEventBehavior(EVT_CLICK) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            syncCalendar(target);
        }
    }));
    add(new Button("submitCalendar").add(new AjaxEventBehavior(EVT_CLICK) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            calendarDialog.open(target, CalendarDialog.DIALOG_TYPE.UPDATE_CALENDAR, getDefaultCalendar());
            target.add(calendarDialog);
        }
    }));
    add(calendarListContainer);
    super.onInitialize();
}
Also used : LocalDateTime(java.time.LocalDateTime) Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) Options(com.googlecode.wicket.jquery.core.Options) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) Button(com.googlecode.wicket.jquery.ui.form.button.Button) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) CalendarView(com.googlecode.wicket.jquery.ui.calendar.CalendarView) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Calendar(com.googlecode.wicket.jquery.ui.calendar.Calendar) GoogleCalendar(com.googlecode.wicket.jquery.ui.calendar.EventSource.GoogleCalendar) JSONArray(com.github.openjson.JSONArray) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) PropertyModel(org.apache.wicket.model.PropertyModel) Date(java.util.Date) CalendarWebHelper.getDate(org.apache.openmeetings.web.util.CalendarWebHelper.getDate) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) JSONObject(com.github.openjson.JSONObject) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel)

Aggregations

CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)17 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 ArrayList (java.util.ArrayList)7 Form (org.apache.wicket.markup.html.form.Form)7 AjaxWizard (org.apache.syncope.client.console.wizards.AjaxWizard)5 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)5 StringResourceModel (org.apache.wicket.model.StringResourceModel)5 GitBlitException (com.gitblit.GitBlitException)4 SimpleAttributeModifier (org.apache.wicket.behavior.SimpleAttributeModifier)4 Button (org.apache.wicket.markup.html.form.Button)4 RegistrantAccessPermission (com.gitblit.models.RegistrantAccessPermission)3 StringChoiceRenderer (com.gitblit.wicket.StringChoiceRenderer)3 RegistrantPermissionsPanel (com.gitblit.wicket.panels.RegistrantPermissionsPanel)3 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)3 IndicatingAjaxLink (org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink)3 Label (org.apache.wicket.markup.html.basic.Label)3 Fragment (org.apache.wicket.markup.html.panel.Fragment)3 PropertyModel (org.apache.wicket.model.PropertyModel)3 RepositoryModel (com.gitblit.models.RepositoryModel)2 TeamModel (com.gitblit.models.TeamModel)2