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

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

Introduction

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

Prototype

public ModalWindow setTitle(IModel<String> title) 

Source Link

Document

Sets the title of window.

Usage

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

License:Apache License

protected ModalWindow createModalWindow(final String id, IModel<String> title, int width, int height) {
    final ModalWindow modal = new ModalWindow(id);
    add(modal);// ww  w. j a v a  2 s  . c o m

    modal.setResizable(false);
    modal.setTitle(title);
    modal.setCookieName(PageBase.class.getSimpleName() + ((int) (Math.random() * 100)));

    modal.setInitialWidth(width);
    modal.setWidthUnit("px");
    modal.setInitialHeight(height);
    modal.setHeightUnit("px");

    modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {

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

    modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        @Override
        public void onClose(AjaxRequestTarget target) {
            modal.close(target);
        }
    });

    modal.add(new AbstractDefaultAjaxBehavior() {

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            response.render(OnDomReadyHeaderItem.forScript("Wicket.Window.unloadConfirmation = false;"));
            response.render(JavaScriptHeaderItem.forScript(
                    "$(document).ready(function() {\n" + "  $(document).bind('keyup', function(evt) {\n"
                            + "    if (evt.keyCode == 27) {\n" + getCallbackScript() + "\n"
                            + "        evt.preventDefault();\n" + "    }\n" + "  });\n" + "});",
                    id));
        }

        @Override
        protected void respond(AjaxRequestTarget target) {
            modal.close(target);

        }
    });

    return modal;
}

From source file:com.evolveum.midpoint.web.page.admin.configuration.component.ObjectSelectionPage.java

License:Apache License

public static <T extends ObjectType> void prepareDialog(ModalWindow dialog,
        ObjectSelectionPanel.Context context, final Component callingComponent, String titleResourceKey,
        final String idToRefresh) {
    dialog.setPageCreator(new ObjectSelectionPage.PageCreator(dialog, context));
    dialog.setInitialWidth(800);/*from w  ww. j ava 2s  .c o  m*/
    dialog.setInitialHeight(500);
    dialog.setTitle(PageBase.createStringResourceStatic(callingComponent, titleResourceKey));
    dialog.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
        // We are not able to refresh targets residing in the parent page
        // from inside the modal window -> so we have to do it in this
        // context, when the modal window is being closed.
        public void onClose(AjaxRequestTarget target) {
            target.add(callingComponent.get(idToRefresh));
        }
    });
    dialog.showUnloadConfirmation(false);
    dialog.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    dialog.setCookieName(ObjectSelectionPanel.class.getSimpleName() + ((int) (Math.random() * 100)));
    dialog.setWidthUnit("px");
}

From source file:com.evolveum.midpoint.web.page.PageTemplate.java

License:Apache License

protected ModalWindow createModalWindow(final String id, IModel<String> title, int width, int height) {
    final ModalWindow modal = new ModalWindow(id);
    add(modal);//  ww  w. j  av  a2 s.c o m

    modal.setResizable(false);
    modal.setTitle(title);
    modal.setCookieName(PageTemplate.class.getSimpleName() + ((int) (Math.random() * 100)));

    modal.setInitialWidth(width);
    modal.setWidthUnit("px");
    modal.setInitialHeight(height);
    modal.setHeightUnit("px");

    modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {

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

    modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        @Override
        public void onClose(AjaxRequestTarget target) {
            modal.close(target);
        }
    });

    modal.add(new AbstractDefaultAjaxBehavior() {

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            response.render(OnDomReadyHeaderItem.forScript("Wicket.Window.unloadConfirmation = false;"));
            response.render(JavaScriptHeaderItem.forScript(
                    "$(document).ready(function() {\n" + "  $(document).bind('keyup', function(evt) {\n"
                            + "    if (evt.keyCode == 27) {\n" + getCallbackScript() + "\n"
                            + "        evt.preventDefault();\n" + "    }\n" + "  });\n" + "});",
                    id));
        }

        @Override
        protected void respond(AjaxRequestTarget target) {
            modal.close(target);
        }
    });

    return modal;
}

From source file:com.socialsite.course.NewCoursePanel.java

License:Open Source License

public NewCoursePanel(String id) {
    super(id);//from www  .  jav  a 2 s .com
    final ModalWindow courseModal;
    add(courseModal = new ModalWindow("coursemodal"));

    courseModal.setContent(new NewCourseModal(courseModal.getContentId()));
    courseModal.setTitle("Create new Course");
    courseModal.setCookieName("coursemodal");

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

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

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

        public void onClose(AjaxRequestTarget target) {

        }
    });

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

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

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

License:Open Source License

/**
 * //w w w . j  av a 2  s .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.iconunderstandability.page.report.bmi.IconOrderPage.java

License:Open Source License

public IconOrderPage(ModalWindow modalWindow, List<TermAssignment> termAssignments, Locale aStudyLocale) {
    super(modalWindow);

    modalWindow.setTitle(new StringResourceModel("assi_diff", this, null));

    this.studyLocale = aStudyLocale;

    addToForm(new PropertyListView("termAssignments", termAssignments) {

        private static final long serialVersionUID = 1L;

        @Override//  w w w . j av a 2  s .c  o  m
        protected void populateItem(ListItem item) {
            item.add(new Label("term", new LocalizedPropertyModel(item.getModelObject(), "term", studyLocale)));

            item.add(new Label("assignment"));
        }

    });
}

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/*  w  w  w.  ja  va2s .c om*/
        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.configuration.project.projectbrowser.MyProjectListViewPanel.java

License:Open Source License

/**
 * Create a dialog to create a new project.
 * /*  ww  w .  j  a  va  2s.com*/
 * @return
 *       A CustomModalWindow
 */
private ModalWindow createNewProjectModalWindow(final Project parentProject, final EventHandler callback) {
    final ModalWindow projectModalWindow = new CustomModalWindow("createNewProjectModalWindow");

    projectModalWindow.setTitle(new StringResourceModel("newProject", MyProjectListViewPanel.this, null));

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

        @Override
        public Page createPage() {
            return new EditProjectPage(projectModalWindow) {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onFinish(AjaxRequestTarget target, String projectName) {
                    Project project = projectService.createPreConfiguredProject(projectName);

                    /**
                     * @see #933. User can add subproject, so there must be
                     * getUser(project) called
                     */
                    projectDao.finalizeProject(project, UserWeaveSession.get().getUser());

                    UserWeaveSession.get().setCreatedEntityId(project.getId());
                }

            };
        }
    });

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

        @Override
        public void onClose(AjaxRequestTarget target) {
            Integer projectId = UserWeaveSession.get().getCreatedEntityId();

            if (projectId != null) {
                EntityEvent.Selected(target, projectDao.findById(projectId)).fire(callback);

                projectId = null;
            }
        }
    });

    return projectModalWindow;
}

From source file:com.userweave.pages.configuration.study.details.AreYouSurePage.java

License:Open Source License

public AreYouSurePage(final ModalWindow window, final StudyState state) {
    super(window);

    this.state = state;

    if (state == StudyState.INIT) {
        window.setTitle(new StringResourceModel("init_need", this, null));

        addToForm(new Label("sure", new StringResourceModel("activate_sure", this, null)));
        addToForm(new Label("testing", new StringResourceModel("activate_testing", this, null)));
    } else {//from  w  w w  . jav  a2  s .c o m
        window.setTitle(new StringResourceModel("running_need", this, null));

        addToForm(new Label("sure", new StringResourceModel("close_sure", this, null)));
        addToForm(new Label("testing", new StringResourceModel("close_testing", this, null)));
    }
}

From source file:de.alpharogroup.wicket.components.examples.ajaxtabs.addable.AddableTabbedPanel.java

License:Apache License

public AddableTabbedPanel(final String id, final IModel<TabbedPanelModels<String>> model) {
    super(id, model);

    setDefaultModel(new CompoundPropertyModel<TabbedPanelModels<String>>(model));
    final List<TabModel<String>> tabModels = model.getObject().getTabModels();
    for (int i = 0; i < tabModels.size(); i++) {
        tabs.add(new AbstractContentTab<TabModel<String>>(tabModels.get(i).getTitle(),
                Model.of(tabModels.get(i)), Model.of("x")) {
            private static final long serialVersionUID = 1L;

            @Override/*from  w  w  w .  j  av a 2  s .  c  o  m*/
            public Panel getPanel(final String panelId) {
                final Panel p = new TabPanel(panelId, getContent().getObject().getContent());
                return p;
            }
        });
    }

    add(ajaxTabbedPanel = new AjaxAddableTabbedPanel<ICloseableTab>("tabs", tabs) {
        private static final long serialVersionUID = 1L;

        @Override
        protected Component newAddTab(final String id, final IModel<String> model) {
            final WebMarkupContainer addTabContainer = new WebMarkupContainer(id);
            addTabContainer.setOutputMarkupId(true);
            addTabContainer.add(new AttributeAppender("class", " label"));
            final ModalWindow modalWindow = newAddTabModalWindow("modalWindow", Model.of("Add new tab"));
            addTabContainer.add(modalWindow);
            final AjaxLink<Void> openModal = new AjaxLink<Void>("openModal") {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    target.prependJavaScript("Wicket.Window.unloadConfirmation = false;");
                    modalWindow.show(target);
                }
            };
            openModal.setOutputMarkupId(true);
            openModal.add(newAddTabButtonLabel("addTabLabel", Model.of("+")));
            openModal.add(new AttributeAppender("class", " label-success"));
            addTabContainer.add(openModal);
            return addTabContainer;
        }

        @Override
        protected Label newaddTabLabel(final String id, final IModel<String> model) {
            return ComponentFactory.newLabel(id, model);
        }

        @Override
        protected IModel<String> newAddTabLabelModel() {
            return Model.of("+");
        }

        @Override
        protected ModalWindow newAddTabModalWindow(final String id, final IModel<String> model) {
            final ModalWindow modalWindow = new ModalWindow(id);
            modalWindow.setOutputMarkupId(true);
            modalWindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
            modalWindow.setTitle(model.getObject());
            modalWindow.setInitialHeight(200);
            modalWindow.setInitialWidth(300);
            modalWindow.setContent(
                    new SaveDialogPanel<String>(modalWindow.getContentId(), Model.of(new String())) {
                        /**
                         * The serialVersionUID.
                         */
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected void onCancel(final AjaxRequestTarget target, final Form<?> form) {
                            super.onCancel(target, form);
                            modalWindow.close(target);
                        }

                        @SuppressWarnings("unchecked")
                        @Override
                        protected void onSave(AjaxRequestTarget target, final Form<?> form) {
                            super.onSave(target, form);
                            if (target == null) {
                                target = ComponentFinder.findAjaxRequestTarget();
                            }
                            final Object value = getModel();
                            String v = null;
                            if (value instanceof IModel) {
                                final Object obj = ((IModel<?>) value).getObject();
                                if (obj instanceof String) {
                                    v = (String) obj;
                                }
                            }
                            target.add(ajaxTabbedPanel);

                            final TabModel<String> newTabModel = new TabModel<>(Model.of(v), Model.of(v),
                                    Model.of("x"));

                            final AbstractContentTab<TabModel<String>> tab = new AbstractContentTab<TabModel<String>>(
                                    newTabModel.getTitle(), Model.of(newTabModel), Model.of("x")) {
                                private static final long serialVersionUID = 1L;

                                @Override
                                public Panel getPanel(final String panelId) {
                                    final Panel p = new TabPanel(panelId,
                                            getContent().getObject().getContent());
                                    return p;
                                }
                            };
                            final Object object = AddableTabbedPanel.this.getDefaultModelObject();
                            final TabbedPanelModels<String> tabbedModel = (TabbedPanelModels<String>) object;
                            final List<TabModel<String>> tabModels = tabbedModel.getTabModels();
                            tabModels.add(newTabModel);
                            ajaxTabbedPanel.onNewTab(target, tab);
                            modalWindow.close(target);
                        }
                    });
            return modalWindow;
        }

        @Override
        protected WebMarkupContainer newCloseLink(final String linkId, final int index) {
            final WebMarkupContainer wmc = super.newCloseLink(linkId, index);
            wmc.add(new AttributeAppender("class", "close label label-warning"));
            return wmc;

        }

        @Override
        protected WebMarkupContainer newLink(final String linkId, final int index) {
            final WebMarkupContainer wmc = super.newLink(linkId, index);
            wmc.add(new AttributeAppender("class", "label label-success"));
            return wmc;
        }
    });
}