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

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

Introduction

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

Prototype

public void show(final IPartialPageRequestHandler target) 

Source Link

Document

Shows the modal window.

Usage

From source file:com.socialsite.image.ImagePanel.java

License:Open Source License

/**
 * /*ww w.  j  ava2s.co  m*/
 * @param component
 *            component id
 * @param id
 *            id used to fetch the image
 * @param imageType
 *            type of the image (userimage , courseimage etc)
 * @param thumb
 *            will show thumb image if true
 * @param lastModified
 *            lastmodified date of the image
 */
public ImagePanel(final String component, final long id, final ImageType imageType, final Date lastModified,
        final boolean thumb, final boolean changeLink) {
    super(component);

    this.changeLink = changeLink;

    // allow the modal window to update the panel
    setOutputMarkupId(true);
    final ResourceReference imageResource = new ResourceReference(imageType.name());
    final Image userImage;
    final ValueMap valueMap = new ValueMap();
    valueMap.add("id", id + "");

    // the version is used to change the url dynamically if the image is
    // changed. This will allow the browser to cache images
    // reference http://code.google.com/speed/page-speed/docs/caching.html
    // #Use fingerprinting to dynamically enable caching.
    valueMap.add("version", lastModified.getTime() + "");
    if (thumb) {
        valueMap.add("thumb", "true");
    }
    add(userImage = new Image("userimage", imageResource, valueMap));
    userImage.setOutputMarkupId(true);

    final ModalWindow modal;
    add(modal = new ModalWindow("modal"));

    modal.setContent(new UploadPanel(modal.getContentId()) {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public String onFileUploaded(final FileUpload upload) {

            if (upload == null || upload.getSize() == 0) {
                // No image was provided
                error("Please upload an image.");
            } else if (!checkContentType(upload.getContentType())) {
                error("Only images of types png, jpg, and gif are allowed.");
            } else {
                saveImage(upload.getBytes());
            }

            return null;
        }

        @Override
        public void onUploadFinished(final AjaxRequestTarget target, final String filename,
                final String newFileUrl) {

            final ResourceReference imageResource = new ResourceReference(imageType.name());

            final ValueMap valueMap = new ValueMap();
            valueMap.add("id", id + "");
            // change the image lively
            valueMap.add("version", new Date().getTime() + "");
            if (thumb) {
                valueMap.add("thumb", "true");
            }

            userImage.setImageResourceReference(imageResource, valueMap);
            // update the image after the user changes it
            target.addComponent(userImage);
        }
    });
    modal.setTitle(" Select the image ");
    modal.setCookieName("modal");

    modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public boolean onCloseButtonClicked(final AjaxRequestTarget target) {
            return true;
        }
    });

    modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public void onClose(final AjaxRequestTarget target) {
        }
    });

    add(new AjaxLink<Void>("changeimage") {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            if (changeLink) {
                // TODO allow admins to change the university image and
                // allow
                // staffs to change the course image
                // it. don't show it for thumb images
                return hasRole(SocialSiteRoles.OWNER) || hasRole(SocialSiteRoles.STAFF);
            }
            return false;

        }

        @Override
        public void onClick(final AjaxRequestTarget target) {
            modal.show(target);
        }
    });
}

From source file:com.userweave.module.methoden.questionnaire.page.report.question.RatingAndDimensionsReportPanel.java

License:Open Source License

public void addAntipodeRatingReport(Question q, AnswerStatistics<T> ratingStatistics, ListItem item, T object) {
    Label mean = new Label("meanRating", getValueModel(ratingStatistics.getRatingMean(object) + 1)) {
        private static final long serialVersionUID = 1L;

        @Override//from w  w w. j  a va2 s .c  o m
        public Locale getLocale() {
            // workaround for i18n, because the table sorter 
            // can't sort double values in german, because they
            // contain a , instead of an .
            return Locale.ENGLISH;
        }
    };

    item.add(mean);

    Label std = new Label("stdDeviation", getValueModel(ratingStatistics.getRatingStandardDeviation(object))) {
        private static final long serialVersionUID = 1L;

        @Override
        public Locale getLocale() {
            return Locale.ENGLISH;
        }
    };

    item.add(std);

    final ModalWindow window = createDetailsModal(q, object, item);

    window.setTitle(getModalWindowTitle(item));

    item.add(window);

    item.add(new AuthOnlyAjaxLink("showDetails") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            window.show(target);
        }
    });
}

From source file:com.userweave.pages.base.BaseUserWeavePage.java

License:Open Source License

/**
 * Adds the imprint and contacts link to the footer part
 * of this page.//from  w ww.j  a v  a2  s  .  c om
 */
protected void addFooterComponents() {
    add(new BookmarkablePageLink<Void>("imprint", ImprintPage.class));

    // Worflow: see #1275
    if (UserWeaveSession.get().isAuthenticated()) {
        final ModalWindow window = createContactModalWindow();

        add(window);

        add(new AjaxLink<Void>("contact") {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                window.show(target);
            }
        });
    } else {
        add(new ExternalLink("contact", "mailto:" + "info@userweave.net"));

        add(new WebMarkupContainer("contactModal"));
    }
}

From source file:com.userweave.pages.configuration.project.userpanel.UserListPanel.java

License:Open Source License

private AjaxLink getDeleteLink(final ModalWindow deleteModal, final ModalWindow unableToDeleteUserModal,
        final boolean joinEqualsProjectAdmin, final int numberOfProjectAdmins, final Project project) {
    AjaxLink deleteLink = new AjaxLink("delete") {
        private static final long serialVersionUID = 1L;

        @Override/*from  w  ww  .ja  v  a2 s  .c  o m*/
        public void onClick(AjaxRequestTarget target) {
            // A user, who is project admin and the only one
            // who is registered, can't delete himself from
            // the project as long as not all studies are either
            // finished or in init state. See #974
            //            if(joinEqualsProjectAdmin &&
            //               !isAtLeastOneOtherAdminRegistered(project, user) &&
            //               runningStudiesExistsInProject(project))

            // an admin can only be deleted, if either there
            // are other admins or no running studies exist in
            // project.
            if (joinEqualsProjectAdmin && numberOfProjectAdmins <= 1
                    && runningStudiesExistsInProject(project)) {
                unableToDeleteUserModal.show(target);
            } else {
                deleteModal.show(target);
            }
        }
    };

    return deleteLink;
}

From source file:com.userweave.pages.configuration.project.userpanel.UserPanel.java

License:Open Source License

/**
 * Creates a link and a window to write a message to 
 * all project users./*  w  w w.ja va 2s  .c  o  m*/
 * 
 * @param project
 *       The project, the users belonging to.
 */
private void addWriteMessageLinkAndDialog(final Project project) {
    final ModalWindow window = createMessageModal(project);

    add(window);

    add(new AjaxLink("writeMessageLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            window.show(target);
        }
    });
}

From source file:com.userweave.pages.test.DisplaySurveyUI.java

License:Open Source License

private void addModalWindow(SurveyExecution surveyExecution) {
    String ID = "modalWindow";
    if (surveyExecution == null || evaluateError(surveyExecution) != ErrorType.NONE
            || studyService.isAtLeastOneAdminRegistered(surveyExecution.getStudy().getParentProject())) {
        add(new WebMarkupContainer(ID));
    } else {/*from  w w  w.j av  a  2 s. c o  m*/
        final ModalWindow modalWindow = new CustomModalWindow(ID);
        modalWindow.setInitialHeight(379);
        add(modalWindow);

        modalWindow.add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onTimer(AjaxRequestTarget target) {
                this.stop();
                modalWindow.show(target);
            }
        });

        modalWindow.setPageCreator(new ModalWindow.PageCreator() {
            private static final long serialVersionUID = 1L;

            @Override
            public Page createPage() {
                return new InformAboutIncompleteRegistrationPage(modalWindow);
            }
        });
    }

}

From source file:com.userweave.pages.user.registration.UserRegistrationForm.java

License:Open Source License

public UserRegistrationForm(String id, IModel userModel, final ModalWindow agbModalWindow) {
    super(id);// www  . ja  va 2s . co  m

    setModel(new CompoundPropertyModel(userModel));

    WebMarkupContainer container = new WebMarkupContainer("container");
    add(container);

    companyContainer = new WebMarkupContainer("companyContainer");
    container.add(companyContainer);
    companyContainer.setOutputMarkupPlaceholderTag(true);
    // set initial visibility
    companyContainer.setVisible(getUser().getBusinessRole() == BusinessRole.Company);

    //add(new TextField("email").setRequired(true).setEnabled(getUser().getEmail() == null));

    add(new CheckBox("verified").setEnabled(false));

    //add(new ExternalLink("agb",new Model("http://usability-methods.com/en/termsofuse") , new StringResourceModel("agb", this, null)));

    add(new AjaxLink("agb") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            agbModalWindow.show(target);
        }

    });

    container.add(new TextField("surname").setRequired(true));
    container.add(new TextField("forename").setRequired(true));

    container.add(new DropDownChoice("locale", LocalizationUtils.getSupportedConfigurationFrontendLocales(),
            new LocaleChoiceRenderer(null)));

    container.add(new RadioChoice("gender", Arrays.asList(User.Gender.values()),
            new LocalizedGenderChoiceRenderer(this)).setSuffix(""));

    container.add(new CallnumberPanel("callnumberPanel", new PropertyModel(getModel(), "callnumber")));

    RadioChoice businessRole = new RadioChoice("businessRole", Arrays.asList(User.BusinessRole.values()),
            new LocalizedBusinessRoleChoiceRenderer(this)).setSuffix("");
    businessRole.add(new IValidator() {

        @Override
        public void validate(IValidatable validatable) {
            Object o = validatable.getValue();

            User.BusinessRole val = (User.BusinessRole) o;

            if (val == BusinessRole.Company) {
                company.setRequired(true);
            } else {
                company.setRequired(false);
            }
        }
    });

    businessRole.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            boolean actsAsCompany = getUser().getBusinessRole() == BusinessRole.Company;
            companyContainer.setVisible(actsAsCompany);
            target.addComponent(companyContainer);
        }
    });
    container.add(businessRole);

    companyContainer.add(new DropDownChoice("position", Arrays.asList(User.Position.values()),
            new LocalizedPositionChoiceRenderer(this)));

    companyContainer.add(new TextField("employment"));

    companyContainer.add(company = new TextField("company"));
    //add(new TextField("education"));               
    companyContainer.add(new TextField("companyUrl"));
    companyContainer.add(new TextField("VATIN"));

    container.add(new AddressForRegistrationPanel("addressPanel", new PropertyModel(getModel(), "address")));

    container.add(new CheckBox("receiveNews"));
    //add(new CheckBox("verified").setRequired(true).setEnabled(!getUser().isVerified()));

    container.add(new DefaultButton("saveButton", new StringResourceModel("save", this, null), this) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            UserRegistrationForm.this.onSave(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form form) {
            target.addComponent(UserRegistrationForm.this.get("feedback"));

        }
    });

    add(new FeedbackPanel("feedback").setOutputMarkupId(true));
}

From source file:com.userweave.pages.user.verification.UserVerificationForm.java

License:Open Source License

public UserVerificationForm(String id, IModel userModel, final ModalWindow agbModalWindow) {
    super(id);//from  ww w .j  a va 2 s.c om

    setModel(new CompoundPropertyModel(userModel));

    AjaxCheckBox acb = new AjaxCheckBox("verified") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            toggleVisibility(this, target);
        }
    };

    add(acb);

    add(new AjaxLink("agb") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            agbModalWindow.show(target);
        }

    });

    container = new WebMarkupContainer("container");
    add(container);

    container.setVisible(false);

    container.setOutputMarkupPlaceholderTag(true);

    container.add(new TextField("surname").setRequired(true));
    container.add(new TextField("forename").setRequired(true));

    container.add(createReceiveNewsChoice());

    container.add(new DefaultButton("saveButton", new StringResourceModel("save", this, null), this) {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            UserVerificationForm.this.onSave(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form form) {
            target.addComponent(UserVerificationForm.this.get("feedback"));

        }
    });

    addLocaleChoice();

    add(new FeedbackPanel("feedback").setOutputMarkupId(true));
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.forms.wizard.AddExperimentEnvironmentForm.java

License:Apache License

private void addModalWindowAndButton(MarkupContainer container, final String cookieName,
        final String buttonName, final String targetClass, final ModalWindow window) {

    AjaxButton ajaxButton = new AjaxButton(buttonName) {
        private static final long serialVersionUID = 1L;

        @Override//from  w ww. j  a v  a2  s  .c  o m
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            window.setCookieName(cookieName);
            window.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = 1L;

                @Override
                public Page createPage() {
                    try {
                        Constructor<?> cons = null;
                        cons = Class.forName(targetClass).getConstructor(PageReference.class,
                                ModalWindow.class);

                        return (Page) cons.newInstance(getPage().getPageReference(), window);
                    } catch (NoSuchMethodException e) {
                        log.error(e.getMessage(), e);
                    } catch (IllegalAccessException e) {
                        log.error(e.getMessage(), e);
                    } catch (InstantiationException e) {
                        log.error(e.getMessage(), e);
                    } catch (InvocationTargetException e) {
                        log.error(e.getMessage(), e);
                    } catch (ClassNotFoundException e) {
                        log.error(e.getMessage(), e);
                    }
                    return null;
                }
            });
            window.show(target);
        }
    };
    ajaxButton.setDefaultFormProcessing(false);
    container.add(ajaxButton);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.forms.wizard.AddExperimentScenarioForm.java

License:Apache License

private void addModalWindowAndButton(MarkupContainer container, final String cookieName,
        final String buttonName, final String targetClass, final ModalWindow window) {

    window.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 1L;

        @Override/*from   ww  w.ja v  a  2 s . c  o m*/
        public void onClose(AjaxRequestTarget target) {
            ChoiceRenderer<Person> renderer = new ChoiceRenderer<Person>("fullName", "personId");
            List<Person> choices = personFacade.getAllRecords();
            Collections.sort(choices);
            coexperimenters.setChoiceRenderer(renderer);
            coexperimenters.setChoices(choices);

            ChoiceRenderer<ResearchGroup> groupRenderer = new ChoiceRenderer<ResearchGroup>("title",
                    "researchGroupId");
            List<ResearchGroup> groupChoices = researchGroupFacade
                    .getResearchGroupsWhereAbleToWriteInto(EEGDataBaseSession.get().getLoggedUser());
            researchGroupChoice.setChoiceRenderer(groupRenderer);
            researchGroupChoice.setChoices(groupChoices);

            licenses.clear();
            licenses.addAll(model.getObject().getExperimentLicences());
            licenses.addAll(EEGDataBaseSession.get().getCreateExperimentLicenseMap().values());

            target.add(AddExperimentScenarioForm.this);
        }

    });

    AjaxButton ajaxButton = new AjaxButton(buttonName) {
        private static final long serialVersionUID = 1L;

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

            window.setCookieName(cookieName);
            window.setPageCreator(new ModalWindow.PageCreator() {

                private static final long serialVersionUID = 1L;

                @Override
                @SuppressWarnings("serial")
                public Page createPage() {
                    try {
                        Constructor<?> cons = null;
                        if (targetClass.equals(AddLicensePage.class.getName())) {
                            p = new AddLicensePage(getPage().getPageReference(), window, model) {
                                @Override
                                protected void onSubmitAction(IModel<ExperimentLicence> experimentLicenseModel,
                                        Integer licenseId, AjaxRequestTarget target, Form<?> form) {
                                    ExperimentLicence experimentLicense = experimentLicenseModel.getObject();
                                    EEGDataBaseSession.get().addLicenseToCreateLicenseMap(licenseId,
                                            experimentLicense);
                                    ModalWindow.closeCurrent(target);
                                }
                            };
                            return (Page) p;
                        } else {
                            cons = Class.forName(targetClass).getConstructor(PageReference.class,
                                    ModalWindow.class);
                            return (Page) cons.newInstance(getPage().getPageReference(), window);
                        }
                    } catch (NoSuchMethodException e) {
                        log.error(e.getMessage(), e);
                    } catch (IllegalAccessException e) {
                        log.error(e.getMessage(), e);
                    } catch (InstantiationException e) {
                        log.error(e.getMessage(), e);
                    } catch (InvocationTargetException e) {
                        log.error(e.getMessage(), e);
                    } catch (ClassNotFoundException e) {
                        log.error(e.getMessage(), e);
                    }
                    return null;
                }
            });
            window.show(target);
        }
    };

    ajaxButton.setDefaultFormProcessing(false);
    container.add(ajaxButton);
}