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:aqubi.samples.wicket.page.extension.ModalContentPage.java

License:Apache License

/**
 * /*w  ww .  j  a  va  2s . com*/
 * @param modalWindowPage
 * @param window
 */
@SuppressWarnings("serial")
public ModalContentPage(final ModalWindowPage modalWindowPage, final ModalWindow window) {
    add(new AjaxLink<Void>("closeOK") {
        public void onClick(AjaxRequestTarget target) {
            if (modalWindowPage != null)
                modalWindowPage.setResult("Modal window - close link OK");
            window.close(target);
        }
    });

    add(new AjaxLink<Void>("closeCancel") {
        public void onClick(AjaxRequestTarget target) {
            if (modalWindowPage != null)
                modalWindowPage.setResult("Modal window  - close link Cancel");
            window.close(target);
        }
    });

}

From source file:ca.travelagency.traveler.SelectPanel.java

License:Apache License

public SelectPanel(String id, final IModel<Traveler> model, final Form<InvoiceTraveler> travelerForm,
        final ModalWindow modalWindow) {
    super(id);//from  w  w  w. ja v  a2  s  .  c  o  m

    AjaxLink<Void> link = new AjaxLink<Void>(LINK) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            travelerForm.getModelObject().copy(model.getObject());
            target.add(travelerForm);
            modalWindow.close(target);
            target.appendJavaScript(JSUtils.INITIALIZE);
        }
    };
    link.add(new Label(LABEL, Model.of(model.getObject().getName())));
    add(link);
}

From source file:com.cubeia.backoffice.web.user.UserReportPanel.java

License:Open Source License

public UserReportPanel(String id, final ModalWindow modal) {
    super(id);//w w  w  . j a v  a2 s  . com

    Form<?> form = new Form<Void>("form");
    form.setOutputMarkupId(true);
    form.add(new AjaxSubmitLink("reportLink", form) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            String url = getRequest().getContextPath() + "reportbuilder/reports/users/?format=" + format;
            target.appendJavaScript("document.location = '" + url + "'");
            modal.close(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            // nothing to do here...
        }
    });

    RadioGroup<String> formatGroup = new RadioGroup<String>("formatGroup",
            new PropertyModel<String>(this, "format"));
    formatGroup.add(new Radio<String>("csv", Model.of("csv")));
    formatGroup.add(new Radio<String>("xls", Model.of("xls")));
    formatGroup.add(new Radio<String>("pdf", Model.of("pdf")));
    form.add(formatGroup);
    add(form);
}

From source file:com.doculibre.constellio.wicket.panels.admin.indexField.AddEditIndexFieldPanel.java

License:Open Source License

public AddEditIndexFieldPanel(String id, IndexField indexField) {
    super(id);//from ww  w . j  a v  a  2s  .  c o m
    this.indexFieldModel = new ReloadableEntityModel<IndexField>(indexField);
    for (CopyField copyFieldDest : indexField.getCopyFieldsDest()) {
        copyFieldsDest.add(new CopyFieldDTO(copyFieldDest));
    }
    for (CopyField copyFieldSource : indexField.getCopyFieldsDest()) {
        copyFieldsSource.add(new CopyFieldDTO(copyFieldSource));
    }
    for (ConnectorInstanceMeta meta : indexField.getConnectorInstanceMetas()) {
        metas.add(new ConnectorInstanceMetaDTO(meta));
    }

    add(new FeedbackPanel("feedback"));

    Form form = new Form("form", new CompoundPropertyModel(indexFieldModel));
    add(form);
    form.add(new SetFocusBehavior(form));

    String titleKey = indexField.getId() == null ? "add" : "edit";
    IModel titleModel = new StringResourceModel(titleKey, this, null);
    form.add(new Label("title", titleModel));

    TextField nameField = new RequiredTextField("name");
    nameField.add(new StringValidator.MaximumLengthValidator(255));
    nameField.setEnabled(!indexField.isInternalField());
    form.add(nameField);

    final CheckBox indexedCheckbox = new CheckBox("indexed");
    indexedCheckbox.setEnabled(!indexField.isInternalField());
    form.add(indexedCheckbox);

    //      final CheckBox storedCheckbox = new CheckBox("stored");
    //      storedCheckbox.setEnabled(!indexField.isInternalField());
    //      form.add(storedCheckbox);

    final CheckBox dynamicFieldCheckbox = new CheckBox("dynamicField");
    dynamicFieldCheckbox.setEnabled(!indexField.isInternalField());
    form.add(dynamicFieldCheckbox);

    final CheckBox multiValuedCheckbox = new CheckBox("multiValued");
    multiValuedCheckbox.setEnabled(!indexField.isInternalField());
    form.add(multiValuedCheckbox);

    final CheckBox sortableCheckbox = new CheckBox("sortable");
    form.add(sortableCheckbox);

    final CheckBox highlightedCheckbox = new CheckBox("highlighted");
    form.add(highlightedCheckbox);

    final ModalWindow fieldTypeModal = new ModalWindow("fieldTypeModal");
    form.add(fieldTypeModal);
    fieldTypeModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY);

    IModel fieldTypesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices();
            return fieldTypeServices.list();
        }
    };

    IChoiceRenderer fieldTypeRenderer = new ChoiceRenderer("name");

    final DropDownChoice fieldTypeField = new DropDownChoice("fieldType", fieldTypesModel, fieldTypeRenderer);
    form.add(fieldTypeField);
    fieldTypeField.setOutputMarkupId(true);
    fieldTypeField.setEnabled(indexField.isAnalyzingCustomizable());

    AjaxLink addFieldTypeLink = new AjaxLink("addFieldTypeLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            AddEditFieldTypePanel addEditFieldTypePanel = new AddEditFieldTypePanel(
                    fieldTypeModal.getContentId(), new FieldType(), fieldTypeField);
            fieldTypeModal.setContent(addEditFieldTypePanel);
            fieldTypeModal.show(target);
        }
    };
    form.add(addFieldTypeLink);
    addFieldTypeLink.setVisible(indexField.isAnalyzingCustomizable());

    form.add(new MetaListPanel("metas").setVisible(indexField.isAnalyzingCustomizable()));
    form.add(new CopyFieldListPanel("copyFieldsDest", true).setVisible(indexField.isAnalyzingCustomizable()));

    IModel localesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            return collection.getLocales();
        }
    };
    MultiLocaleComponentHolder nameHolder = new MultiLocaleComponentHolder("label", indexFieldModel,
            localesModel) {
        @Override
        protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) {
            TextField nameField = new TextField("nameLocale", componentModel);
            item.add(nameField);
            item.add(new LocaleNameLabel("localeName", locale, true) {
                @Override
                public boolean isVisible() {
                    AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                            AdminCollectionPanel.class);
                    RecordCollection collection = collectionAdminPanel.getCollection();
                    return collection.getLocales().size() > 1;
                }
            });
        }
    };
    form.add(nameHolder);

    Button submitButton = new AjaxButton("submitButton") {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            IndexField indexField = indexFieldModel.getObject();

            EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
            if (!entityManager.getTransaction().isActive()) {
                entityManager.getTransaction().begin();
            }

            List<ConnectorInstanceMeta> existingMetas = new ArrayList<ConnectorInstanceMeta>(
                    indexField.getConnectorInstanceMetas());
            // Remove deleted metas
            List<ConnectorInstanceMeta> formMetas = new ArrayList<ConnectorInstanceMeta>();
            for (ConnectorInstanceMetaDTO metaDTO : getMetas()) {
                formMetas.add(metaDTO.toConnectorInstanceMeta());
            }
            for (Iterator<ConnectorInstanceMeta> it = existingMetas.iterator(); it.hasNext();) {
                ConnectorInstanceMeta meta = it.next();
                meta = entityManager.merge(meta);
                if (!hasMeta(meta, formMetas)) {
                    indexField.removeConnectorInstanceMeta(meta);
                }
            }
            // Add new
            for (ConnectorInstanceMetaDTO metaDTO : getMetas()) {
                ConnectorInstanceMeta meta = metaDTO.toConnectorInstanceMeta();
                if (!hasMeta(meta, existingMetas)) {
                    meta = entityManager.merge(meta);
                    indexField.addConnectorInstanceMeta(meta);
                }
            }

            Set<CopyField> existingCopyFieldsSource = indexField.getCopyFieldsSource();
            // Remove deleted copy fields
            for (Iterator<CopyField> it = existingCopyFieldsSource.iterator(); it.hasNext();) {
                CopyField copyField = it.next();
                if (!getCopyFieldsSource().contains(new CopyFieldDTO(copyField))) {
                    it.remove();
                }
            }
            // Add new or update set
            for (CopyFieldDTO copyFieldDTO : getCopyFieldsSource()) {
                CopyField copyField = copyFieldDTO.toCopyField();
                copyField.setIndexFieldSource(indexField);
                if (copyField.getId() != null) {
                    entityManager.merge(copyField);
                } else {
                    existingCopyFieldsSource.add(copyField);
                }
            }

            Set<CopyField> existingCopyFieldsDest = indexField.getCopyFieldsDest();
            // Remove deleted copy fields
            for (Iterator<CopyField> it = existingCopyFieldsDest.iterator(); it.hasNext();) {
                CopyField copyField = it.next();
                if (!getCopyFieldsDest().contains(new CopyFieldDTO(copyField))) {
                    it.remove();
                }
            }
            // Add new or update set
            for (CopyFieldDTO copyFieldDTO : getCopyFieldsDest()) {
                CopyField copyField = copyFieldDTO.toCopyField();
                copyField.setIndexFieldDest(indexField);
                if (copyField.getId() != null) {
                    entityManager.merge(copyField);
                } else {
                    existingCopyFieldsDest.add(copyField);
                }
            }

            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            indexField.setRecordCollection(collection);

            IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices();
            FederationServices federationServices = ConstellioSpringUtils.getFederationServices();

            if (indexField.isSortable()) {
                if (indexFieldServices.getSortFieldOf(indexField) == null) {
                    indexFieldServices.newSortFieldFor(indexField);
                }
            }

            AutocompleteServices autocompleteServices = ConstellioSpringUtils.getAutocompleteServices();
            if (indexField.isAutocompleted()) {
                autocompleteServices.setAutoCompleteToField(indexField);
            } else {
                autocompleteServices.removeAutoCompleteFromField(indexField);
            }

            if (collection.isIncludedInFederation()) {
                List<String> conflicts = new ArrayList<String>();
                List<IndexField> newFederationFields = new ArrayList<IndexField>();
                List<RecordCollection> ownerCollections = federationServices.listOwnerCollections(collection);
                for (RecordCollection ownerCollection : ownerCollections) {
                    String indexFieldName = indexField.getName();
                    IndexField ownerIndexField = ownerCollection.getIndexField(indexFieldName);
                    if (ownerIndexField == null) {
                        IndexField copy = federationServices.copy(indexField, ownerCollection);
                        newFederationFields.add(copy);
                    }
                    if (federationServices.isConflict(indexFieldName, ownerCollection, collection)) {
                        Locale displayLocale = ownerCollection.getDisplayLocale(getLocale());
                        conflicts.add(ownerCollection.getTitle(displayLocale));
                    }
                }
                if (conflicts.isEmpty()) {
                    indexFieldServices.makePersistent(indexField);
                    for (IndexField newFederationField : newFederationFields) {
                        indexFieldServices.makePersistent(newFederationField);
                    }
                } else {
                    for (String collectionTitle : conflicts) {
                        error(getLocalizer().getString("conflict", this) + " : " + collectionTitle);
                    }
                }
            } else {
                indexFieldServices.makePersistent(indexField);
            }

            entityManager.getTransaction().commit();

            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);

            target.addComponent(modalWindow.findParent(AdminIndexFieldsPanel.class));
        }
    };
    form.add(submitButton);

    Button cancelButton = new AjaxButton("cancelButton") {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);
        }
    }.setDefaultFormProcessing(false);
    form.add(cancelButton);
}

From source file:com.doculibre.constellio.wicket.panels.admin.indexField.copyField.AddEditCopyFieldPanel.java

License:Open Source License

public AddEditCopyFieldPanel(String id, final int index, CopyField copyField, final boolean dest) {
    super(id);//from w ww . ja v a  2s  .c  o  m
    this.copyFieldModel = new EntityModel<CopyField>(copyField);

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    add(feedback);

    Form form = new Form("form", new CompoundPropertyModel(copyFieldModel));
    add(form);
    form.add(new SetFocusBehavior(form));

    String titleKey = copyField.getId() == null ? "add" : "edit";
    IModel titleModel = new StringResourceModel(titleKey, this, null);
    form.add(new Label("title", titleModel));

    IModel indexFieldsModel = new AdminCollectionIndexFieldsModel(this) {
        @Override
        protected boolean accept(IndexField potentialIndexField) {
            boolean accept;
            AddEditIndexFieldPanel addEditIndexFieldPanel = (AddEditIndexFieldPanel) findParent(
                    AddEditIndexFieldPanel.class);
            IndexField indexField = addEditIndexFieldPanel.getIndexField();
            if (indexField.getId() != null) {
                accept = !potentialIndexField.equals(indexField);
            } else {
                accept = true;
            }
            return accept;
        }
    };

    IChoiceRenderer indexFieldRenderer = new ChoiceRenderer() {
        @Override
        public Object getDisplayValue(Object object) {
            IndexField indexField = (IndexField) object;
            return indexField.getName();
        }
    };

    DropDownChoice indexFieldSource = new DropDownChoice("indexFieldSource", indexFieldsModel,
            indexFieldRenderer);
    indexFieldSource.setVisible(dest);
    form.add(indexFieldSource);

    final CheckBox sourceAllFieldsCheckbox = new CheckBox("sourceAllFields");
    sourceAllFieldsCheckbox.setVisible(dest);
    form.add(sourceAllFieldsCheckbox);

    DropDownChoice indexFieldDest = new DropDownChoice("indexFieldDest", indexFieldsModel, indexFieldRenderer);
    indexFieldDest.setRequired(true);
    indexFieldDest.setVisible(!dest);
    form.add(indexFieldDest);

    AjaxButton submitButton = new AjaxButton("submitButton") {
        @SuppressWarnings("unchecked")
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            CopyField copyField = copyFieldModel.getObject();

            CopyFieldListPanel copyFieldListPanel = (CopyFieldListPanel) findParent(CopyFieldListPanel.class);

            List<CopyFieldDTO> copyFields = (List<CopyFieldDTO>) copyFieldListPanel.getModelObject();
            if (index == -1) {
                copyFields.add(new CopyFieldDTO(copyField));
            } else {
                copyFields.set(index, new CopyFieldDTO(copyField));
            }

            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);

            target.addComponent(copyFieldListPanel);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, Form form) {
            target.addComponent(feedback);
        }
    };
    form.add(submitButton);

    Button cancelButton = new AjaxButton("cancelButton") {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);
        }
    }.setDefaultFormProcessing(false);
    form.add(cancelButton);
}

From source file:com.doculibre.constellio.wicket.panels.admin.indexField.meta.AddMetaPanel.java

License:Open Source License

public AddMetaPanel(String id) {
    super(id);//from  w ww .j  a v a2s . c  o  m

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    add(feedback);

    Form form = new Form("form");
    add(form);
    form.add(new SetFocusBehavior(form));

    String titleKey = "add";
    IModel titleModel = new StringResourceModel(titleKey, this, null);
    form.add(new Label("title", titleModel));

    IModel connectorInstancesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            return new ArrayList<ConnectorInstance>(collection.getConnectorInstances());
        }
    };

    IModel connectorInstanceMetasModel = new LoadableDetachableModel() {
        @SuppressWarnings("unchecked")
        @Override
        protected Object load() {
            ConnectorInstance connectorInstance = connectorInstanceModel.getObject();
            List<ConnectorInstanceMeta> connectorInstanceMetas = new ArrayList<ConnectorInstanceMeta>();
            if (connectorInstance != null) {
                MetaListPanel metaListPanel = (MetaListPanel) findParent(MetaListPanel.class);
                List<ConnectorInstanceMetaDTO> metas = (List<ConnectorInstanceMetaDTO>) metaListPanel
                        .getModelObject();
                for (ConnectorInstanceMeta meta : connectorInstance.getConnectorInstanceMetas()) {
                    if (!hasMeta(meta, metas)) {
                        connectorInstanceMetas.add(meta);
                    }
                }
            }
            return connectorInstanceMetas;
        }
    };

    IChoiceRenderer connectorInstanceRenderer = new ChoiceRenderer("displayName");
    IChoiceRenderer metaRenderer = new ChoiceRenderer("name");

    final DropDownChoice connectorInstanceMeta = new DropDownChoice("connectorInstanceMeta", metaModel,
            connectorInstanceMetasModel, metaRenderer);
    connectorInstanceMeta.setRequired(true);
    connectorInstanceMeta.setOutputMarkupId(true);
    form.add(connectorInstanceMeta);

    DropDownChoice connectorInstance = new DropDownChoice("connectorInstance", connectorInstanceModel,
            connectorInstancesModel, connectorInstanceRenderer);
    connectorInstance.setRequired(true);
    connectorInstance.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(connectorInstanceMeta);
        }
    });
    form.add(connectorInstance);

    AjaxButton submitButton = new AjaxButton("submitButton") {
        @SuppressWarnings("unchecked")
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            ConnectorInstanceMeta meta = metaModel.getObject();

            MetaListPanel metaListPanel = (MetaListPanel) findParent(MetaListPanel.class);

            List<ConnectorInstanceMetaDTO> metas = (List<ConnectorInstanceMetaDTO>) metaListPanel
                    .getModelObject();
            metas.add(new ConnectorInstanceMetaDTO(meta));

            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);

            target.addComponent(metaListPanel);
        }

        @Override
        protected void onError(final AjaxRequestTarget target, Form form) {
            target.addComponent(feedback);
        }
    };
    form.add(submitButton);

    Button cancelButton = new AjaxButton("cancelButton") {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class);
            modalWindow.close(target);
        }
    }.setDefaultFormProcessing(false);
    form.add(cancelButton);
}

From source file:com.doculibre.constellio.wicket.panels.admin.tagging.AddEditFreeTextTagPanel.java

License:Open Source License

public AddEditFreeTextTagPanel(String id, FreeTextTag freeTextTag, Component refreshComponentP) {
    super(id);// w  w w.  j a v a 2 s .  com
    this.freeTextTagModel = new ReloadableEntityModel<FreeTextTag>(freeTextTag);
    this.refreshComponent = refreshComponentP;

    add(new FeedbackPanel("feedback"));

    Form form = new Form("form", new CompoundPropertyModel(freeTextTagModel));
    add(form);
    form.add(new SetFocusBehavior(form));

    String titleKey = freeTextTag.getId() == null ? "add" : "edit";
    IModel titleModel = new StringResourceModel(titleKey, this, null);
    form.add(new Label("title", titleModel));

    TextField freeTextField = new RequiredTextField("freeText");
    freeTextField.add(new StringValidator.MaximumLengthValidator(255));
    form.add(freeTextField);

    Button submitButton = new AjaxButton("submitButton") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            FreeTextTag freeTextTag = freeTextTagModel.getObject();

            FreeTextTagServices taggingServices = ConstellioSpringUtils.getFreeTextTagServices();
            EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
            if (!entityManager.getTransaction().isActive()) {
                entityManager.getTransaction().begin();
            }

            taggingServices.makePersistent(freeTextTag);
            entityManager.getTransaction().commit();

            ModalWindow modal = (ModalWindow) findParent(ModalWindow.class);
            if (modal != null) {
                modal.close(target);
            }
            if (refreshComponent != null) {
                if (refreshComponent instanceof FormComponent) {
                    refreshComponent.setModelObject(freeTextTag);
                }
                target.addComponent(refreshComponent);
            } else {
                AdminLeftMenuPanel parent = (AdminLeftMenuPanel) findParent(AdminLeftMenuPanel.class);
                AddEditFreeTextTagPanel.this
                        .replaceWith(new FreeTextTagListPanel(AddEditFreeTextTagPanel.this.getId()));
                target.addComponent(parent);
            }
        }

    };
    form.add(submitButton);

    Button cancelButton = new AjaxButton("cancelButton") {
        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            ModalWindow modal = (ModalWindow) findParent(ModalWindow.class);
            if (modal != null) {
                modal.close(target);
            }
            if (refreshComponent != null) {
                target.addComponent(refreshComponent);
            } else {
                AdminLeftMenuPanel parent = (AdminLeftMenuPanel) findParent(AdminLeftMenuPanel.class);
                AddEditFreeTextTagPanel.this
                        .replaceWith(new FreeTextTagListPanel(AddEditFreeTextTagPanel.this.getId()));
                target.addComponent(parent);
            }
        }
    }.setDefaultFormProcessing(false);
    form.add(cancelButton);
}

From source file:com.evolveum.midpoint.gui.api.page.PageBase.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);//from  w w w.  j a  va 2  s  . com

    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.component.assignment.AssignmentTablePanel.java

License:Apache License

private void addSelectedAssignablePerformed(AjaxRequestTarget target, List<ObjectType> newAssignments) {
    ModalWindow window = (ModalWindow) get(ID_MODAL_ASSIGN);
    window.close(target);

    if (newAssignments.isEmpty()) {
        warn(getString("AssignmentTablePanel.message.noAssignmentSelected"));
        target.add(getPageBase().getFeedbackPanel());
        return;/*from ww w  .  j  a  v  a2 s.c o  m*/
    }

    List<AssignmentEditorDto> assignments = assignmentModel.getObject();

    for (ObjectType object : newAssignments) {
        try {

            if (object instanceof ResourceType) {
                addSelectedResourceAssignPerformed((ResourceType) object);
                continue;
            }

            AssignmentEditorDtoType aType = AssignmentEditorDtoType.getType(object.getClass());

            ObjectReferenceType targetRef = new ObjectReferenceType();
            targetRef.setOid(object.getOid());
            targetRef.setType(aType.getQname());

            AssignmentType assignment = new AssignmentType();
            assignment.setTargetRef(targetRef);

            AssignmentEditorDto dto = new AssignmentEditorDto(object, aType, UserDtoStatus.ADD, assignment);
            dto.setMinimized(false);
            dto.setShowEmpty(true);

            assignments.add(dto);
        } catch (Exception e) {
            error(getString("AssignmentTablePanel.message.couldntAssignObject", object.getName(),
                    e.getMessage()));
            LoggingUtils.logException(LOGGER, "Couldn't assign object", e);
        }
    }

    target.add(getPageBase().getFeedbackPanel(), get(ID_ASSIGNMENTS));
}

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

License:Apache License

private void addSelectedAssignableActionsPerformed(AjaxRequestTarget target, List<AutzActionsTableDto> toAdd) {
    ModalWindow window = (ModalWindow) get(ID_MODAL_ACTIONS_ASSIGN);
    window.close(target);

    if (toAdd.isEmpty()) {
        warn(getString("AutzActionsTablePanel.message.noAssignmentSelected"));
        target.add(getPageBase().getFeedbackPanel());
        return;//from  w w w .  j a v  a 2  s . c  o m
    } else {
        List<AutzActionsTableDto> authActions = getModel().getObject();
        authActions.addAll(toAdd);
        target.add(getPageBase().getFeedbackPanel(), get(ID_AUTZACTIONS));
    }

}