Example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow close

List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow close

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow close.

Prototype

public void close(final IPartialPageRequestHandler target) 

Source Link

Document

Closes the modal window.

Usage

From source file:org.sakaiproject.profile2.tool.pages.windows.AddFriend.java

License:Educational Community License

public AddFriend(String id, final ModalWindow window, final FriendAction friendActionModel, final String userX,
        final String userY) {
    super(id);//from   w w w  .  ja v  a2  s  . com

    //get friendName
    final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY),
            new StringBuffer());

    //window setup
    window.setTitle(new StringResourceModel("title.friend.add", null, new Object[] { friendName }));
    window.setInitialHeight(150);
    window.setInitialWidth(500);
    window.setResizable(false);

    //prefs and privacy
    ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(userY);
    ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(userY);

    //image
    ProfileImage image = new ProfileImage("image", new Model<String>(userY));
    image.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
    add(image);

    //text
    final Label text = new Label("text",
            new StringResourceModel("text.friend.add", null, new Object[] { friendName }));
    text.setEscapeModelStrings(false);
    text.setOutputMarkupId(true);
    add(text);

    //setup form      
    Form form = new Form("form");
    form.setOutputMarkupId(true);

    //submit button
    AjaxFallbackButton submitButton = new AjaxFallbackButton("submit", new ResourceModel("button.friend.add"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            /* double checking */

            //friend?
            if (connectionsLogic.isUserXFriendOfUserY(userX, userY)) {
                text.setDefaultModel(new StringResourceModel("error.friend.already.confirmed", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //has a friend request already been made to this person?
            if (connectionsLogic.isFriendRequestPending(userX, userY)) {
                text.setDefaultModel(new StringResourceModel("error.friend.already.pending", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //has a friend request been made from this person to the current user?
            if (connectionsLogic.isFriendRequestPending(userY, userX)) {
                text.setDefaultModel(new StringResourceModel("error.friend.already.pending", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //if ok, request friend
            if (connectionsLogic.requestFriend(userX, userY)) {
                friendActionModel.setRequested(true);

                //post event
                sakaiProxy.postEvent(ProfileConstants.EVENT_FRIEND_REQUEST, "/profile/" + userY, true);

                window.close(target);
            } else {
                text.setDefaultModel(
                        new StringResourceModel("error.friend.add.failed", null, new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

        }
    };
    //submitButton.add(new FocusOnLoadBehaviour());
    submitButton.add(new AttributeModifier("title", true,
            new StringResourceModel("accessibility.connection.add", null, new Object[] { friendName })));
    form.add(submitButton);

    //cancel button
    AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {
            friendActionModel.setRequested(false);
            window.close(target);
        }
    };
    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    //add form
    add(form);
}

From source file:org.sakaiproject.profile2.tool.pages.windows.ConfirmFriend.java

License:Educational Community License

public ConfirmFriend(String id, final ModalWindow window, final FriendAction friendActionModel,
        final String userX, final String userY) {
    super(id);/*from  w ww  .ja  v  a  2 s  .  com*/

    //get friendName
    final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY),
            new StringBuffer());

    //window setup
    window.setTitle(new StringResourceModel("title.friend.confirm", null, new Object[] { friendName }));
    window.setInitialHeight(150);
    window.setInitialWidth(500);
    window.setResizable(false);

    //prefs and privacy
    ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(userY);
    ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(userY);

    //image
    ProfileImage image = new ProfileImage("image", new Model<String>(userY));
    image.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
    add(image);

    //text
    final Label text = new Label("text",
            new StringResourceModel("text.friend.confirm", null, new Object[] { friendName }));
    text.setEscapeModelStrings(false);
    text.setOutputMarkupId(true);
    add(text);

    //setup form      
    Form form = new Form("form");
    form.setOutputMarkupId(true);

    //submit button
    AjaxFallbackButton submitButton = new AjaxFallbackButton("submit",
            new ResourceModel("button.friend.confirm"), form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            /* double checking */

            //must exist a pending friend request FROM userY to userX in order to confirm it
            boolean friendRequestFromThisPerson = connectionsLogic.isFriendRequestPending(userY, userX);

            if (!friendRequestFromThisPerson) {
                text.setDefaultModel(new StringResourceModel("error.friend.not.pending.confirm", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //if ok, request friend
            if (connectionsLogic.confirmFriendRequest(userY, userX)) {
                friendActionModel.setConfirmed(true);

                //post event
                sakaiProxy.postEvent(ProfileConstants.EVENT_FRIEND_CONFIRM, "/profile/" + userY, true);

                window.close(target);
            } else {
                text.setDefaultModel(new StringResourceModel("error.friend.confirm.failed", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

        }
    };
    //submitButton.add(new FocusOnLoadBehaviour());
    submitButton.add(new AttributeModifier("title", true,
            new StringResourceModel("accessibility.connection.confirm", null, new Object[] { friendName })));
    form.add(submitButton);

    //cancel button
    AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {
            friendActionModel.setConfirmed(false);
            window.close(target);
        }
    };
    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    //add form
    add(form);

}

From source file:org.sakaiproject.profile2.tool.pages.windows.IgnoreFriend.java

License:Educational Community License

public IgnoreFriend(String id, final ModalWindow window, final FriendAction friendActionModel,
        final String userX, final String userY) {
    super(id);//  w  w  w.  j  a v  a2  s. co m

    //get friendName
    final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY),
            new StringBuffer());

    //window setup
    window.setTitle(new ResourceModel("title.friend.ignore"));
    window.setInitialHeight(150);
    window.setInitialWidth(500);
    window.setResizable(false);

    //prefs and privacy
    ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(userY);
    ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(userY);

    //image
    ProfileImage image = new ProfileImage("image", new Model<String>(userY));
    image.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
    add(image);

    //text
    final Label text = new Label("text",
            new StringResourceModel("text.friend.ignore", null, new Object[] { friendName }));
    text.setEscapeModelStrings(false);
    text.setOutputMarkupId(true);
    add(text);

    //setup form      
    Form form = new Form("form");
    form.setOutputMarkupId(true);

    //submit button
    AjaxFallbackButton submitButton = new AjaxFallbackButton("submit",
            new ResourceModel("button.friend.ignore"), form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            /* double checking */

            //must exist a pending friend request FROM userY to userX in order to ignore it
            boolean friendRequestFromThisPerson = connectionsLogic.isFriendRequestPending(userY, userX);

            if (!friendRequestFromThisPerson) {
                text.setDefaultModel(new StringResourceModel("error.friend.not.pending.ignore", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //if ok, ignore friend request
            if (connectionsLogic.ignoreFriendRequest(userY, userX)) {
                friendActionModel.setIgnored(true);

                //post event
                sakaiProxy.postEvent(ProfileConstants.EVENT_FRIEND_IGNORE, "/profile/" + userY, true);

                window.close(target);
            } else {
                text.setDefaultModel(new StringResourceModel("error.friend.ignore.failed", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

        }
    };
    //submitButton.add(new FocusOnLoadBehaviour());
    submitButton.add(new AttributeModifier("title", true,
            new StringResourceModel("accessibility.connection.ignore", null, new Object[] { friendName })));
    form.add(submitButton);

    //cancel button
    AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {
            friendActionModel.setIgnored(false);
            window.close(target);
        }
    };
    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    //add form
    add(form);

}

From source file:org.sakaiproject.profile2.tool.pages.windows.RemoveFriend.java

License:Educational Community License

public RemoveFriend(String id, final ModalWindow window, final FriendAction friendActionModel,
        final String userX, final String userY) {
    super(id);//  ww w  .ja  va2 s .c om

    //get friendName
    final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY),
            new StringBuffer());

    //window setup
    window.setTitle(new ResourceModel("title.friend.remove"));
    window.setInitialHeight(150);
    window.setInitialWidth(500);
    window.setResizable(false);

    //prefs and privacy
    ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(userY);
    ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(userY);

    //image
    ProfileImage image = new ProfileImage("image", new Model<String>(userY));
    image.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
    add(image);

    //text
    final Label text = new Label("text",
            new StringResourceModel("text.friend.remove", null, new Object[] { friendName }));
    text.setEscapeModelStrings(false);
    text.setOutputMarkupId(true);
    add(text);

    //setup form      
    Form form = new Form("form");
    form.setOutputMarkupId(true);

    //submit button
    AjaxFallbackButton submitButton = new AjaxFallbackButton("submit",
            new ResourceModel("button.friend.remove"), form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            /* double checking */

            //must be friend in order to remove them
            boolean friend = connectionsLogic.isUserXFriendOfUserY(userX, userY);

            if (!friend) {
                text.setDefaultModel(
                        new StringResourceModel("error.friend.not.friend", null, new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //if ok, remove friend
            if (connectionsLogic.removeFriend(userX, userY)) {
                friendActionModel.setRemoved(true);

                //post event
                sakaiProxy.postEvent(ProfileConstants.EVENT_FRIEND_REMOVE, "/profile/" + userY, true);

                window.close(target);
            } else {
                text.setDefaultModel(new StringResourceModel("error.friend.remove.failed", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

        }
    };
    //submitButton.add(new FocusOnLoadBehaviour());
    submitButton.add(new AttributeModifier("title", true,
            new StringResourceModel("accessibility.connection.remove", null, new Object[] { friendName })));
    form.add(submitButton);

    //cancel button
    AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {
            friendActionModel.setRemoved(false);
            window.close(target);
        }
    };
    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    //add form
    add(form);

}

From source file:org.sakaiproject.profile2.tool.pages.windows.RemoveWallItem.java

License:Educational Community License

public RemoveWallItem(String id, final ModalWindow window, final WallAction wallAction, final String userUuid,
        final WallItem wallItem) {

    super(id);/*ww  w  .ja v a2  s . c  o  m*/

    window.setTitle(new ResourceModel("title.wall.remove"));
    window.setInitialHeight(150);
    window.setInitialWidth(500);
    window.setResizable(false);

    // add profile image of wall post creator
    ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(wallItem.getCreatorUuid());
    ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(wallItem.getCreatorUuid());

    ProfileImage image = new ProfileImage("image", new Model<String>(wallItem.getCreatorUuid()));
    image.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
    add(image);

    final Label text;
    if (false == wallItem.getCreatorUuid().equals(userUuid)) {
        text = new Label("text", new StringResourceModel("text.wall.remove.other", null,
                new Object[] { sakaiProxy.getUserDisplayName(wallItem.getCreatorUuid()) }));
    } else {
        text = new Label("text", new StringResourceModel("text.wall.remove.mine", null, new Object[] {}));
    }
    text.setEscapeModelStrings(false);
    text.setOutputMarkupId(true);
    add(text);

    Form form = new Form("form");
    form.setOutputMarkupId(true);

    AjaxFallbackButton submitButton = new AjaxFallbackButton("submit", new ResourceModel("button.wall.remove"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            wallAction.setItemRemoved(wallLogic.removeWallItemFromWall(wallItem));

            window.close(target);
        }
    };
    //submitButton.add(new FocusOnLoadBehaviour());

    final AttributeModifier accessibilityLabel;
    if (false == wallItem.getCreatorUuid().equals(userUuid)) {
        accessibilityLabel = new AttributeModifier("title", true,
                new StringResourceModel("accessibility.wall.remove.other", null, new Object[] {}));
    } else {
        accessibilityLabel = new AttributeModifier("title", true,
                new StringResourceModel("accessibility.wall.remove.mine", null, new Object[] {}));
    }
    submitButton.add(accessibilityLabel);
    form.add(submitButton);

    AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {
            window.close(target);
        }
    };

    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    add(form);
}

From source file:org.syncope.console.pages.AbstractSchedTaskModalPage.java

License:Apache License

public AbstractSchedTaskModalPage(final ModalWindow window, final SchedTaskTO taskTO,
        final PageReference callerPageRef) {

    super(taskTO);

    crontab = new CrontabContainer("crontab", new PropertyModel<String>(taskTO, "cronExpression"),
            taskTO.getCronExpression());
    form.add(crontab);/*from  w w w .j a  v  a2 s. c o  m*/

    final AjaxTextFieldPanel lastExec = new AjaxTextFieldPanel("lastExec", getString("lastExec"),
            new DateFormatROModel(new PropertyModel<String>(taskTO, "lastExec")), false);
    lastExec.setEnabled(false);
    profile.add(lastExec);

    final AjaxTextFieldPanel nextExec = new AjaxTextFieldPanel("nextExec", getString("nextExec"),
            new DateFormatROModel(new PropertyModel<String>(taskTO, "nextExec")), false);
    nextExec.setEnabled(false);
    profile.add(nextExec);

    final IndicatingAjaxButton submit = new IndicatingAjaxButton("apply", new ResourceModel("apply")) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form form) {

            SchedTaskTO taskTO = (SchedTaskTO) form.getModelObject();
            taskTO.setCronExpression(
                    !StringUtils.hasText(taskTO.getCronExpression()) ? null : crontab.getCronExpression());

            try {
                if (taskTO.getId() > 0) {
                    if (taskTO instanceof SyncTaskTO) {
                        taskRestClient.updateSyncTask((SyncTaskTO) taskTO);
                    } else {
                        taskRestClient.updateSchedTask(taskTO);
                    }
                } else {
                    if (taskTO instanceof SyncTaskTO) {
                        taskRestClient.createSyncTask((SyncTaskTO) taskTO);
                    } else {
                        taskRestClient.createSchedTask(taskTO);
                    }
                }

                ((BasePage) callerPageRef.getPage()).setModalResult(true);

                window.close(target);
            } catch (SyncopeClientCompositeErrorException e) {
                LOG.error("While creating or updating task", e);
                error(getString("error") + ":" + e.getMessage());
                target.add(feedbackPanel);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form form) {

            target.add(feedbackPanel);
        }
    };

    if (taskTO.getId() > 0) {
        MetaDataRoleAuthorizationStrategy.authorize(submit, RENDER,
                xmlRolesReader.getAllAllowedRoles("Tasks", "update"));
    } else {
        MetaDataRoleAuthorizationStrategy.authorize(submit, RENDER,
                xmlRolesReader.getAllAllowedRoles("Tasks", "create"));
    }

    form.add(submit);
}

From source file:org.syncope.console.pages.ApprovalModalPage.java

License:Apache License

public ApprovalModalPage(final PageReference callerPageRef, final ModalWindow window,
        final WorkflowFormTO formTO) {

    super();//from  ww  w .  j av a 2 s  .  com

    IModel<List<WorkflowFormPropertyTO>> formProps = new LoadableDetachableModel<List<WorkflowFormPropertyTO>>() {

        private static final long serialVersionUID = 3169142472626817508L;

        @Override
        protected List<WorkflowFormPropertyTO> load() {
            return formTO.getProperties();
        }
    };

    final ListView<WorkflowFormPropertyTO> propView = new ListView<WorkflowFormPropertyTO>("propView",
            formProps) {

        private static final long serialVersionUID = 9101744072914090143L;

        @Override
        protected void populateItem(final ListItem<WorkflowFormPropertyTO> item) {

            final WorkflowFormPropertyTO prop = item.getModelObject();

            Label label = new Label("key", prop.getName() == null ? prop.getId() : prop.getName());
            item.add(label);

            FieldPanel field = null;
            switch (prop.getType()) {
            case Boolean:
                field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(),
                        new Model(Boolean.valueOf(prop.getValue())), true)
                                .setChoices(Arrays.asList(new String[] { "Yes", "No" }));
                break;

            case Date:
                SimpleDateFormat df = StringUtils.isNotBlank(prop.getDatePattern())
                        ? new SimpleDateFormat(prop.getDatePattern())
                        : new SimpleDateFormat();
                Date parsedDate = null;
                if (StringUtils.isNotBlank(prop.getValue())) {
                    try {
                        parsedDate = df.parse(prop.getValue());
                    } catch (ParseException e) {
                        LOG.error("Unparsable date: {}", prop.getValue(), e);
                    }
                }

                field = new DateTimeFieldPanel("value", label.getDefaultModelObjectAsString(),
                        new Model(parsedDate), true, df.toLocalizedPattern());
                break;

            case Enum:
                MapChoiceRenderer<String, String> enumCR = new MapChoiceRenderer<String, String>(
                        prop.getEnumValues());

                field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(),
                        new Model(prop.getValue()), true).setChoiceRenderer(enumCR).setChoices(new Model() {

                            private static final long serialVersionUID = -858521070366432018L;

                            @Override
                            public Serializable getObject() {
                                return new ArrayList(prop.getEnumValues().keySet());
                            }
                        });
                break;

            case Long:
                field = new AjaxNumberFieldPanel("value", label.getDefaultModelObjectAsString(),
                        new Model(Long.valueOf(prop.getValue())), Long.class, true);
                break;

            case String:
            default:
                field = new AjaxTextFieldPanel("value", PARENT_PATH, new Model(prop.getValue()), true);
                break;
            }

            field.setReadOnly(!prop.isWritable());
            if (prop.isRequired()) {
                field.addRequiredLabel();
            }

            item.add(field);
        }
    };

    final AjaxButton submit = new IndicatingAjaxButton("apply", new Model(getString("submit"))) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {

            Map<String, WorkflowFormPropertyTO> props = formTO.getPropertiesAsMap();

            for (int i = 0; i < propView.size(); i++) {
                ListItem<WorkflowFormPropertyTO> item = (ListItem<WorkflowFormPropertyTO>) propView.get(i);
                String input = ((FieldPanel) item.get("value")).getField().getInput();

                if (!props.containsKey(item.getModelObject().getId())) {
                    props.put(item.getModelObject().getId(), new WorkflowFormPropertyTO());
                }

                if (item.getModelObject().isWritable()) {
                    switch (item.getModelObject().getType()) {
                    case Boolean:
                        props.get(item.getModelObject().getId()).setValue(String.valueOf(input.equals("0")));
                        break;

                    case Date:
                    case Enum:
                    case String:
                    case Long:
                    default:
                        props.get(item.getModelObject().getId()).setValue(input);
                        break;
                    }
                }
            }

            formTO.setProperties(props.values());
            try {
                restClient.submitForm(formTO);

                ((Todo) callerPageRef.getPage()).setModalResult(true);
                window.close(target);
            } catch (SyncopeClientCompositeErrorException e) {
                error(getString("error") + ":" + e.getMessage());
                LOG.error("While submitting form {}", formTO, e);
                target.add(feedbackPanel);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {

            target.add(feedbackPanel);
        }
    };

    Form form = new Form("form");
    form.add(propView);
    form.add(submit);

    MetaDataRoleAuthorizationStrategy.authorize(form, ENABLE,
            xmlRolesReader.getAllAllowedRoles("Approval", "submit"));

    add(form);
}

From source file:org.syncope.console.pages.ConfigurationModalPage.java

License:Apache License

/**
 * ConfigurationModalPage constructor.//from   w w w .j a  v a2 s  . c  o m
 * 
 * @param callPageRef base
 * @param window
 * @param configurationTO
 * @param createFlag true for CREATE and false for UPDATE operation
 */
public ConfigurationModalPage(final PageReference callPageRef, final ModalWindow window,
        final ConfigurationTO configurationTO, final boolean createFlag) {

    Form form = new Form("form", new CompoundPropertyModel(configurationTO));

    final AjaxTextFieldPanel key = new AjaxTextFieldPanel("key", "key",
            new PropertyModel(configurationTO, "key"), false);
    form.add(key);
    key.setEnabled(createFlag);
    key.addRequiredLabel();

    final AjaxTextFieldPanel value = new AjaxTextFieldPanel("value", "value",
            new PropertyModel(configurationTO, "value"), false);
    form.add(value);
    value.addRequiredLabel();

    submit = new IndicatingAjaxButton("apply", new Model<String>(getString("submit"))) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form form) {

            boolean res = false;

            if (createFlag) {
                res = configurationsRestClient.createConfiguration(configurationTO);

                if (!res) {
                    error(getString("error_insert"));
                }
            } else {
                res = configurationsRestClient.updateConfiguration(configurationTO);

                if (!res) {
                    error(getString("error_updating"));
                }
            }

            if (res) {
                Configuration callerPage = (Configuration) callPageRef.getPage();
                callerPage.setModalResult(true);

                window.close(target);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form form) {

            target.add(feedbackPanel);
        }
    };

    String allowedRoles = createFlag ? xmlRolesReader.getAllAllowedRoles("Configuration", "create")
            : xmlRolesReader.getAllAllowedRoles("Configuration", "update");

    MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles);

    form.add(submit);

    add(form);
}

From source file:org.syncope.console.pages.ConnectorModalPage.java

License:Apache License

public ConnectorModalPage(final PageReference callerPageRef, final ModalWindow window,
        final ConnInstanceTO connectorTO) {

    super();//www .j  a va 2  s  .  com

    selectedCapabilities = new ArrayList(connectorTO.getId() == 0 ? EnumSet.noneOf(ConnectorCapability.class)
            : connectorTO.getCapabilities());

    final IModel<List<ConnectorCapability>> capabilities = new LoadableDetachableModel<List<ConnectorCapability>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override
        protected List<ConnectorCapability> load() {
            return Arrays.asList(ConnectorCapability.values());
        }
    };

    final IModel<List<ConnBundleTO>> bundles = new LoadableDetachableModel<List<ConnBundleTO>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override
        protected List<ConnBundleTO> load() {
            return restClient.getAllBundles();
        }
    };

    bundleTO = getSelectedBundleTO(bundles.getObject(), connectorTO);
    properties = getProperties(bundleTO, connectorTO);

    final AjaxTextFieldPanel connectorName = new AjaxTextFieldPanel("connectorName", "connector name",
            new PropertyModel<String>(connectorTO, "connectorName"), false);

    connectorName.setOutputMarkupId(true);
    connectorName.setEnabled(false);

    final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name",
            new PropertyModel<String>(connectorTO, "displayName"), false);

    displayName.setOutputMarkupId(true);
    displayName.addRequiredLabel();

    final AjaxTextFieldPanel version = new AjaxTextFieldPanel("version", "version",
            new PropertyModel<String>(connectorTO, "version"), false);

    displayName.setOutputMarkupId(true);
    version.setEnabled(false);

    final AjaxDropDownChoicePanel<ConnBundleTO> bundle = new AjaxDropDownChoicePanel<ConnBundleTO>("bundle",
            "bundle", new Model<ConnBundleTO>(bundleTO), false);

    bundle.setStyleShet("long_dynamicsize");

    bundle.setChoices(bundles.getObject());

    bundle.setChoiceRenderer(new ChoiceRenderer<ConnBundleTO>() {

        private static final long serialVersionUID = -1945543182376191187L;

        @Override
        public Object getDisplayValue(final ConnBundleTO object) {
            return object.getBundleName() + " " + object.getVersion();
        }

        @Override
        public String getIdValue(final ConnBundleTO object, final int index) {
            // idValue must include version as well in order to cope
            // with multiple version of the same bundle.
            return object.getBundleName() + "#" + object.getVersion();
        }
    });

    ((DropDownChoice) bundle.getField()).setNullValid(true);
    bundle.setRequired(true);

    bundle.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            //reset all informations stored in connectorTO
            connectorTO.setConfiguration(new HashSet<ConnConfProperty>());

            ((DropDownChoice) bundle.getField()).setNullValid(false);
            target.add(bundle.getField());

            target.add(connectorName);
            target.add(version);

            target.add(propertiesContainer);
        }
    });

    bundle.getField().setModel(new IModel<ConnBundleTO>() {

        private static final long serialVersionUID = -3736598995576061229L;

        @Override
        public ConnBundleTO getObject() {
            return bundleTO;
        }

        @Override
        public void setObject(final ConnBundleTO object) {
            if (object != null && connectorTO != null) {
                connectorTO.setBundleName(object.getBundleName());
                connectorTO.setVersion(object.getVersion());
                connectorTO.setConnectorName(object.getConnectorName());
                properties = getProperties(object, connectorTO);
                bundleTO = object;
            }
        }

        @Override
        public void detach() {
        }
    });

    bundle.addRequiredLabel();
    bundle.setEnabled(connectorTO.getId() == 0);

    final ListView<ConnConfProperty> view = new ListView<ConnConfProperty>("connectorProperties",
            new PropertyModel(this, "properties")) {

        private static final long serialVersionUID = 9101744072914090143L;

        @Override
        protected void populateItem(final ListItem<ConnConfProperty> item) {
            final ConnConfProperty property = item.getModelObject();

            final Label label = new Label("connPropAttrSchema",
                    property.getSchema().getDisplayName() == null
                            || property.getSchema().getDisplayName().isEmpty() ? property.getSchema().getName()
                                    : property.getSchema().getDisplayName());

            item.add(label);

            final FieldPanel field;

            boolean required = false;

            boolean isArray = false;

            if (GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType())
                    || GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) {

                field = new AjaxPasswordFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model(),
                        true);

                ((PasswordTextField) field.getField()).setResetPassword(false);

                required = property.getSchema().isRequired();

            } else {
                Class propertySchemaClass;

                try {
                    propertySchemaClass = ClassUtils.forName(property.getSchema().getType(),
                            ClassUtils.getDefaultClassLoader());
                } catch (Exception e) {
                    LOG.error("Error parsing attribute type", e);
                    propertySchemaClass = String.class;
                }

                if (NUMBER.contains(propertySchemaClass)) {
                    field = new AjaxNumberFieldPanel("panel", label.getDefaultModelObjectAsString(),
                            new Model(), ClassUtils.resolvePrimitiveIfNecessary(propertySchemaClass), true);

                    required = property.getSchema().isRequired();
                } else if (Boolean.class.equals(propertySchemaClass)
                        || boolean.class.equals(propertySchemaClass)) {
                    field = new AjaxCheckBoxPanel("panel", label.getDefaultModelObjectAsString(), new Model(),
                            true);
                } else {

                    field = new AjaxTextFieldPanel("panel", label.getDefaultModelObjectAsString(), new Model(),
                            true);

                    required = property.getSchema().isRequired();
                }

                if (String[].class.equals(propertySchemaClass)) {
                    isArray = true;
                }
            }

            field.setTitle(property.getSchema().getHelpMessage());

            if (isArray) {
                field.removeRequiredLabel();

                if (property.getValues().isEmpty()) {
                    property.getValues().add(null);
                }

                item.add(new MultiValueSelectorPanel<String>("panel",
                        new PropertyModel<List<String>>(property, "values"), String.class, field));
            } else {
                if (required) {
                    field.addRequiredLabel();
                }

                field.setNewModel(property.getValues());
                item.add(field);
            }

            final AjaxCheckBoxPanel overridable = new AjaxCheckBoxPanel("connPropAttrOverridable",
                    "connPropAttrOverridable", new PropertyModel(property, "overridable"), true);

            item.add(overridable);
            connectorTO.getConfiguration().add(property);
        }
    };

    final Form connectorForm = new Form("form");
    connectorForm.setModel(new CompoundPropertyModel(connectorTO));

    final Form connectorPropForm = new Form("connectorPropForm");
    connectorPropForm.setModel(new CompoundPropertyModel(connectorTO));
    connectorPropForm.setOutputMarkupId(true);

    propertiesContainer = new WebMarkupContainer("container");
    propertiesContainer.setOutputMarkupId(true);
    propertiesContainer.add(connectorPropForm);

    connectorForm.add(propertiesContainer);
    connectorPropForm.add(view);

    final AjaxLink check = new IndicatingAjaxLink("check", new ResourceModel("check")) {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {

            connectorTO.setBundleName(bundleTO.getBundleName());
            connectorTO.setVersion(bundleTO.getVersion());

            if (restClient.check(connectorTO).booleanValue()) {
                info(getString("success_connection"));
            } else {
                error(getString("error_connection"));
            }

            target.add(feedbackPanel);
        }
    };

    connectorPropForm.add(check);

    final AjaxButton submit = new IndicatingAjaxButton("apply", new Model(getString("submit"))) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form form) {

            final ConnInstanceTO conn = (ConnInstanceTO) form.getDefaultModelObject();

            conn.setBundleName(bundleTO.getBundleName());

            // Set the model object's capabilites to
            // capabilitiesPalette's converted Set
            if (!selectedCapabilities.isEmpty()) {
                // exception if selectedCapabilities is empy
                conn.setCapabilities(EnumSet.copyOf(selectedCapabilities));
            } else {
                conn.setCapabilities(EnumSet.noneOf(ConnectorCapability.class));
            }
            try {
                if (connectorTO.getId() == 0) {
                    restClient.create(conn);
                } else {
                    restClient.update(conn);
                }

                ((Resources) callerPageRef.getPage()).setModalResult(true);
                window.close(target);
            } catch (SyncopeClientCompositeErrorException e) {
                error(getString("error") + ":" + e.getMessage());
                target.add(feedbackPanel);
                ((Resources) callerPageRef.getPage()).setModalResult(false);
                LOG.error("While creating or updating connector {}", conn);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form form) {

            target.add(feedbackPanel);
        }
    };

    String roles = connectorTO.getId() == 0 ? xmlRolesReader.getAllAllowedRoles("Connectors", "create")
            : xmlRolesReader.getAllAllowedRoles("Connectors", "update");

    MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, roles);

    connectorForm.add(connectorName);
    connectorForm.add(displayName);
    connectorForm.add(bundle);
    connectorForm.add(version);

    capabilitiesPalette = new CheckBoxMultipleChoice("capabilitiesPalette",
            new PropertyModel(this, "selectedCapabilities"), capabilities);
    connectorForm.add(capabilitiesPalette);

    connectorForm.add(submit);

    add(connectorForm);
}

From source file:org.syncope.console.pages.DerivedSchemaModalPage.java

License:Apache License

@Override
public void setSchemaModalPage(final PageReference callerPageRef, final ModalWindow window,
        AbstractBaseBean schema, final boolean createFlag) {

    if (schema == null) {
        schema = new DerivedSchemaTO();
    }/*w ww  .  java 2  s . c  o m*/

    final Form schemaForm = new Form("form");

    schemaForm.setModel(new CompoundPropertyModel(schema));

    final AjaxTextFieldPanel name = new AjaxTextFieldPanel("name", getString("name"),
            new PropertyModel<String>(schema, "name"), false);
    name.addRequiredLabel();

    final AjaxTextFieldPanel expression = new AjaxTextFieldPanel("expression", getString("expression"),
            new PropertyModel<String>(schema, "expression"), false);
    expression.addRequiredLabel();

    name.setEnabled(createFlag);

    final IndicatingAjaxButton submit = new IndicatingAjaxButton("apply", new ResourceModel("submit")) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form form) {

            DerivedSchemaTO schemaTO = (DerivedSchemaTO) form.getDefaultModelObject();

            try {
                if (createFlag) {
                    restClient.createDerivedSchema(kind, schemaTO);
                } else {
                    restClient.updateDerivedSchema(kind, schemaTO);
                }
                if (callerPageRef.getPage() instanceof BasePage) {
                    ((BasePage) callerPageRef.getPage()).setModalResult(true);
                }

                window.close(target);
            } catch (SyncopeClientCompositeErrorException e) {
                error(getString("error") + ":" + e.getMessage());
                target.add(feedbackPanel);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form form) {

            target.add(feedbackPanel);
        }
    };

    String allowedRoles;

    if (createFlag) {
        allowedRoles = xmlRolesReader.getAllAllowedRoles("Schema", "create");
    } else {
        allowedRoles = xmlRolesReader.getAllAllowedRoles("Schema", "update");
    }

    MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles);

    schemaForm.add(name);
    schemaForm.add(expression);

    schemaForm.add(submit);

    add(schemaForm);
}