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

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

Introduction

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

Prototype

public static void closeCurrent(final IPartialPageRequestHandler target) 

Source Link

Document

Hides the modal window.

Usage

From source file:com.doculibre.constellio.wicket.panels.admin.elevate.modal.DocIdsPanel.java

License:Open Source License

public DocIdsPanel(String id, final String queryText, final boolean elevatedDocs) {
    super(id);//from w w  w.  j  a va2s . c o m

    docIdsModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            List<String> docIds = new ArrayList<String>();
            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            if (elevatedDocs) {
                SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText);
                docIds = elevateServices.getElevatedDocIds(querySimpleSearch);
            } else {
                docIds = elevateServices.getExcludedDocIds(collection);
            }
            return docIds;
        }
    };

    add(new ListView("docIds", docIdsModel) {
        @Override
        protected void populateItem(ListItem item) {
            final String docId = (String) item.getModelObject();

            AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = collectionAdminPanel.getCollection();
            RecordServices recordServices = ConstellioSpringUtils.getRecordServices();
            Record record = recordServices.get(docId, collection);
            if (record == null) {
                FederationServices federationServices = ConstellioSpringUtils.getFederationServices();
                if (collection.isFederationOwner()) {
                    List<RecordCollection> includedCollections = federationServices
                            .listIncludedCollections(collection);
                    for (RecordCollection includedCollection : includedCollections) {
                        record = recordServices.get(docId, includedCollection);
                        if (record != null) {
                            break;
                        }
                    }
                }
                if (record == null && collection.isIncludedInFederation()) {
                    List<RecordCollection> ownerCollections = federationServices
                            .listOwnerCollections(collection);
                    for (RecordCollection ownerCollection : ownerCollections) {
                        record = recordServices.get(docId, ownerCollection);
                        if (record != null) {
                            break;
                        }
                    }
                }
            }
            if (record != null) {
                final RecordModel recordModel = new RecordModel(record);
                String displayURL = record.getDisplayUrl();
                item.add(new Label("docId", displayURL));

                WebMarkupContainer deleteLink = new AjaxLink("deleteLink") {
                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent(
                                AdminCollectionPanel.class);
                        RecordCollection collection = collectionAdminPanel.getCollection();
                        Record record = recordModel.getObject();

                        ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();

                        SolrServer solrServer = SolrCoreContext.getSolrServer(collection);
                        try {
                            ConstellioPersistenceUtils.beginTransaction();
                            if (elevatedDocs) {
                                SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText);
                                elevateServices.cancelElevation(record, querySimpleSearch);
                            } else {
                                elevateServices.cancelExclusion(record, collection);
                            }
                            try {
                                solrServer.commit();
                            } catch (Throwable t) {
                                try {
                                    solrServer.rollback();
                                } catch (Exception e) {
                                    throw new RuntimeException(t);
                                }
                            }
                        } finally {
                            ConstellioPersistenceUtils.finishTransaction(false);
                        }

                        Component parent;
                        if (elevatedDocs) {
                            SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText);
                            boolean empty = elevateServices.getElevatedDocIds(querySimpleSearch).isEmpty();
                            if (empty) {
                                ModalWindow.closeCurrent(target);
                                parent = null;
                            } else {
                                parent = WicketResourceUtils.findOutputMarkupIdParent(DocIdsPanel.this);
                            }
                        } else {
                            parent = WicketResourceUtils.findOutputMarkupIdParent(DocIdsPanel.this);
                        }
                        if (parent != null) {
                            target.addComponent(parent);
                        }
                    }

                    @Override
                    protected IAjaxCallDecorator getAjaxCallDecorator() {
                        return new AjaxCallDecorator() {
                            @Override
                            public CharSequence decorateScript(CharSequence script) {
                                String confirmMsg = getLocalizer().getString("confirmDelete", DocIdsPanel.this);
                                return "if (confirm('" + confirmMsg + "')) {" + script
                                        + "} else { return false; }";
                            }
                        };
                    }

                    @Override
                    public void detachModels() {
                        recordModel.detach();
                        super.detachModels();
                    }
                };
                item.add(deleteLink);
            } else {
                item.setVisible(false);
            }
        }
    });
}

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

License:Open Source License

/**
 * Called if this panel is uses Ajax.//w ww .java 2 s. c o  m
 * 
 * @param target
 */
protected void defaultReturnAction(AjaxRequestTarget target) {
    ModalWindow modal = (ModalWindow) findParent(ModalWindow.class);
    if (modal != null) {
        Component refreshParent = WicketResourceUtils.findOutputMarkupIdParent(modal);
        ModalWindow.closeCurrent(target);
        if (refreshParent != null) {
            target.addComponent(refreshParent);
        }
    } else {
        Component refreshParent = WicketResourceUtils.findOutputMarkupIdParent(this);
        if (refreshParent != null) {
            this.replaceWith(newReturnComponent(getId()));
            target.addComponent(refreshParent);
        }
    }
}

From source file:com.doculibre.constellio.wicket.panels.elevate.queries.EditRecordElevatedQueriesPanel.java

License:Open Source License

public EditRecordElevatedQueriesPanel(String id, Record record, final SimpleSearch simpleSearch) {
    super(id);/*  w w w .java2  s .c om*/
    this.recordModel = new RecordModel(record);
    this.simpleSearch = simpleSearch;
    final String collectionName = simpleSearch.getCollectionName();

    ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
    RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
    RecordCollection collection = collectionServices.get(collectionName);
    List<String> elevatedQueries = elevateServices.getElevatedQueries(record, collection);
    queries.addAll(elevatedQueries);

    String titleKey = "queries";
    IModel titleModel = new StringResourceModel(titleKey, this, null);
    add(new Label("panelTitle", titleModel));

    queriesContainer = new WebMarkupContainer("queriesContainer");
    add(queriesContainer);
    queriesContainer.setOutputMarkupId(true);

    add(new AddQueryForm("addForm"));

    queriesContainer.add(new ListView("queries", queries) {
        @Override
        protected void populateItem(ListItem item) {
            final String query = (String) item.getModelObject();
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            SimpleSearch simpleSearch = elevateServices.toSimpleSearch(query);
            item.add(new SimpleSearchQueryPanel("query", simpleSearch));

            item.add(new AjaxLink("deleteLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    queries.remove(query);
                    target.addComponent(queriesContainer);
                }

                @Override
                protected IAjaxCallDecorator getAjaxCallDecorator() {
                    return new AjaxCallDecorator() {
                        @Override
                        public CharSequence decorateScript(CharSequence script) {
                            String confirmMsg = getLocalizer().getString("confirmDelete",
                                    EditRecordElevatedQueriesPanel.this);
                            return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }";
                        }
                    };
                }
            });
        }
    });

    Form form = new Form("form");
    add(form);
    form.add(new AjaxButton("submitButton") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices();
            RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
            RecordCollection collection = collectionServices.get(collectionName);
            Record record = recordModel.getObject();
            List<String> originalQueries = elevateServices.getElevatedQueries(record, collection);
            for (String originalQuery : originalQueries) {
                if (!queries.contains(originalQuery)) {
                    SimpleSearch originalQuerySimpleSearch = elevateServices.toSimpleSearch(originalQuery);
                    elevateServices.cancelElevation(record, originalQuerySimpleSearch);
                }
            }

            for (String query : queries) {
                SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(query);
                if (!elevateServices.isElevated(record, querySimpleSearch)) {
                    elevateServices.elevate(record, querySimpleSearch);
                }
            }
            ModalWindow.closeCurrent(target);
        }
    });
    form.add(new AjaxButton("cancelButton") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            ModalWindow.closeCurrent(target);
        }
    }.setDefaultFormProcessing(false));
}

From source file:com.doculibre.constellio.wicket.panels.results.tagging.SearchResultEditTaggingPanel.java

License:Open Source License

public SearchResultEditTaggingPanel(String id, final SolrDocument doc, final IDataProvider dataProvider,
        Thesaurus source) {//  ww w.  j av a2  s  . c o  m
    super(id);
    if (source == null) {
        freeTextTags = true;
        source = new Thesaurus(getLocalizer().getString("freeTextTags", SearchResultEditTaggingPanel.this));
    }
    RecordServices recordServices = ConstellioSpringUtils.getRecordServices();
    Record record = recordServices.get(doc);
    recordModel = new RecordModel(record);
    taggingSourceModel = new EntityModel<Thesaurus>(source);

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

    IModel taggingSourceChoicesModel = new LoadableDetachableModel() {
        @Override
        protected Object load() {
            List<Object> taggingSources = new ArrayList<Object>();

            taggingSources.add(
                    new Thesaurus(getLocalizer().getString("freeTextTags", SearchResultEditTaggingPanel.this)));

            SkosServices skosServices = ConstellioSpringUtils.getSkosServices();
            Record record = recordModel.getObject();
            ConnectorInstance connectorInstance = record.getConnectorInstance();
            RecordCollection collection = connectorInstance.getRecordCollection();
            Map<String, Object> criteria = new HashMap<String, Object>();
            criteria.put("recordCollection", collection);
            taggingSources.addAll(skosServices.list(criteria));

            return taggingSources;
        }
    };
    IChoiceRenderer taggingSourceRenderer = new ChoiceRenderer("dcTitle");
    taggingSourceField = new DropDownChoice("taggingSource", taggingSourceModel, taggingSourceChoicesModel,
            taggingSourceRenderer);
    taggingSourceField.setVisible(isSourceSelectionVisible());
    taggingSourceField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(availableTagsContainer);
            target.addComponent(appliedTagsContainer);
            target.addComponent(filterAddField);
            target.addComponent(filterAddButton);
        }
    });

    filterAddField = new TextField("filterAddField", new Model());
    filterAddField.setOutputMarkupId(true);
    filterAddField.add(new AjaxFormComponentUpdatingBehavior("onkeyup") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String input = filterAddField.getModelObjectAsString();
            availableTagsModel.setFilter(input);
            appliedTagsModel.setFilter(input);
            if (isFreeTextTagSource()) {
                target.addComponent(availableTagsContainer);
                target.addComponent(appliedTagsContainer);
            }
        }
    });

    filterAddButton = new AjaxButton("filterAddButton") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            String tagName = (String) filterAddField.getModelObject();
            if (StringUtils.isNotBlank(tagName)) {
                if (isFreeTextTagSource()) {
                    FreeTextTagServices freeTextTagServices = ConstellioSpringUtils.getFreeTextTagServices();
                    FreeTextTag existingTag = freeTextTagServices.get(tagName);
                    if (existingTag == null) {
                        FreeTextTag newTag = new FreeTextTag();
                        newTag.setFreeText(tagName);

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

                        availableTagsModel.setFilter(null);
                        appliedTagsModel.setFilter(null);
                        filterAddField.clearInput();
                        filterAddField.setModelObject(null);
                        target.addComponent(filterAddField);
                        target.addComponent(availableTagsContainer);
                        target.addComponent(appliedTagsContainer);
                    }
                } else {
                    target.addComponent(availableTagsContainer);
                }
            }
        }
    };
    filterAddButton.add(new AttributeModifier("value", true, new LoadableDetachableModel() {
        @Override
        protected Object load() {
            String key = isFreeTextTagSource() ? "add" : "filter";
            return getLocalizer().getString(key, SearchResultEditTaggingPanel.this);
        }
    }));

    availableTagsContainer = new WebMarkupContainer("availableTagsContainer");
    availableTagsContainer.setOutputMarkupId(true);
    availableTagsModel = new FilteredObjectsModel() {
        @Override
        protected List<Object> filter(String filter) {
            List<Object> matches = new ArrayList<Object>();
            Thesaurus taggingSource = taggingSourceModel.getObject();

            if (taggingSource == null || taggingSource.getId() == null) {
                if (StringUtils.isNotBlank(filter)) {
                    filter = filter + "*";
                }
                FreeTextTagServices taggingServices = ConstellioSpringUtils.getFreeTextTagServices();
                if (StringUtils.isBlank(filter)) {
                    List<FreeTextTag> first100 = taggingServices.list(100);
                    matches.addAll(first100);
                } else {
                    Set<FreeTextTag> searchResults = taggingServices.search(filter);
                    matches.addAll(searchResults);
                }
            } else {
                SkosServices skosServices = ConstellioSpringUtils.getSkosServices();
                Set<SkosConcept> searchResults = skosServices.searchAllLabels(filter, taggingSource, null);
                matches.addAll(searchResults);
            }
            return matches;
        }
    };
    availableTagsListView = new ListView("availableTags", availableTagsModel) {
        @Override
        protected void populateItem(ListItem item) {
            ConstellioEntity tagSource = (ConstellioEntity) item.getModelObject();
            final ReloadableEntityModel<ConstellioEntity> tagSourceModel = new ReloadableEntityModel<ConstellioEntity>(
                    tagSource);
            final ModalWindow detailsModal = new ModalWindow("detailsModal");
            item.add(detailsModal);

            final AjaxLink detailsLink = new AjaxLink("detailsLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource instanceof SkosConcept) {
                        SkosConcept skosConcept = (SkosConcept) tagSource;
                        detailsModal.setContent(
                                new SkosConceptModalPanel(detailsModal.getContentId(), skosConcept));
                        detailsModal.show(target);
                    }
                }
            };
            item.add(detailsLink);
            detailsLink.setEnabled(tagSource instanceof SkosConcept);

            detailsLink.add(new Label("name", new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    String name;
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource != null) {
                        if (tagSource instanceof FreeTextTag) {
                            FreeTextTag freeTextTag = (FreeTextTag) tagSource;
                            name = freeTextTag.getFreeText();
                        } else {
                            SkosConcept skosConcept = (SkosConcept) tagSource;
                            name = skosConcept.getPrefLabel(getLocale());
                        }
                    } else {
                        name = "null";
                    }
                    return name;
                }
            }));

            item.add(new AjaxLink("addLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    Record record = recordModel.getObject();
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource instanceof FreeTextTag) {
                        FreeTextTag freeTextTag = (FreeTextTag) tagSource;
                        record.addFreeTextTag(freeTextTag, true);
                    } else {
                        SkosConcept skosConcept = (SkosConcept) tagSource;
                        record.addSkosConcept(skosConcept, true);
                    }
                    record.setUpdateIndex(true);

                    RecordServices recordServices = ConstellioSpringUtils.getRecordServices();

                    SolrServer solrServer = SolrCoreContext
                            .getSolrServer(record.getConnectorInstance().getRecordCollection());
                    try {
                        ConstellioPersistenceUtils.beginTransaction();
                        recordServices.makePersistent(record);
                        try {
                            solrServer.commit();
                        } catch (Throwable t) {
                            try {
                                solrServer.rollback();
                            } catch (Exception e) {
                                throw new RuntimeException(t);
                            }
                        }
                    } finally {
                        ConstellioPersistenceUtils.finishTransaction(false);
                    }

                    target.addComponent(availableTagsContainer);
                    target.addComponent(appliedTagsContainer);
                }

                @Override
                public boolean isVisible() {
                    boolean visible = super.isVisible();
                    if (visible) {
                        Record record = recordModel.getObject();
                        if (tagSourceModel.getObject() instanceof FreeTextTag) {
                            FreeTextTag freeTextTag = (FreeTextTag) tagSourceModel.getObject();
                            visible = !record.hasFreeTextTag(freeTextTag);
                        } else {
                            SkosConcept skosConcept = (SkosConcept) tagSourceModel.getObject();
                            visible = !record.hasSkosConcept(skosConcept);
                        }
                    }
                    return visible;
                }

                @Override
                public void detachModels() {
                    tagSourceModel.detach();
                    super.detachModels();
                }
            });
        }
    };

    appliedTagsContainer = new WebMarkupContainer("appliedTagsContainer");
    appliedTagsContainer.setOutputMarkupId(true);
    appliedTagsModel = new FilteredObjectsModel() {
        @Override
        protected List<RecordTag> filter(String filter) {
            List<RecordTag> matches = new ArrayList<RecordTag>();
            Record record = recordModel.getObject();
            Thesaurus source = taggingSourceModel.getObject();
            for (RecordTag recordTag : record.getIncludedRecordTags(freeTextTags ? null : source, true)) {
                //                    if (StringUtils.isEmpty(filter)
                //                        || recordTag.getName(getLocale()).toLowerCase().indexOf(filter.toLowerCase()) != -1) {
                matches.add(recordTag);
                //                    }
            }
            return matches;
        }
    };
    appliedTagsListView = new ListView("appliedTags", appliedTagsModel) {
        @Override
        protected void populateItem(ListItem item) {
            RecordTag recordTag = (RecordTag) item.getModelObject();
            final RecordTagModel recordTagModel = new RecordTagModel(recordTag);

            ConstellioEntity tagSource;
            if (recordTag.getFreeTextTag() != null) {
                tagSource = recordTag.getFreeTextTag();
            } else {
                tagSource = recordTag.getSkosConcept();
            }
            final ReloadableEntityModel<ConstellioEntity> tagSourceModel = new ReloadableEntityModel<ConstellioEntity>(
                    tagSource);
            final ModalWindow detailsModal = new ModalWindow("detailsModal");
            item.add(detailsModal);

            final AjaxLink detailsLink = new AjaxLink("detailsLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource instanceof SkosConcept) {
                        SkosConcept skosConcept = (SkosConcept) tagSource;
                        detailsModal.setContent(
                                new SkosConceptModalPanel(detailsModal.getContentId(), skosConcept));
                        detailsModal.show(target);
                    }
                }
            };
            item.add(detailsLink);
            detailsLink.setEnabled(tagSource instanceof SkosConcept);

            detailsLink.add(new Label("name", new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    String name;
                    ConstellioEntity tagSource = (ConstellioEntity) tagSourceModel.getObject();
                    if (tagSource != null) {
                        if (tagSource instanceof FreeTextTag) {
                            FreeTextTag freeTextTag = (FreeTextTag) tagSource;
                            name = freeTextTag.getFreeText();
                        } else {
                            SkosConcept skosConcept = (SkosConcept) tagSource;
                            name = skosConcept.getPrefLabel(getLocale());
                        }
                    } else {
                        name = "null";
                    }
                    return name;
                }
            }));
            detailsLink.add(new AttributeModifier("style", true, new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    RecordTag recordTag = recordTagModel.getObject();
                    return recordTag.isExcluded() ? "text-decoration: line-through;" : "text-decoration:none";
                }
            }));
            item.add(new AjaxLink("removeLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    Record record = recordModel.getObject();
                    RecordTag recordTag = recordTagModel.getObject();
                    boolean excluded = recordTag.isExcluded();
                    if (excluded) {
                        record.getRecordTags().remove(recordTag);
                    } else {
                        recordTag.setManual(true);
                        recordTag.setExcluded(true);
                    }
                    record.setUpdateIndex(true);

                    RecordServices recordServices = ConstellioSpringUtils.getRecordServices();

                    SolrServer solrServer = SolrCoreContext
                            .getSolrServer(record.getConnectorInstance().getRecordCollection());
                    try {
                        ConstellioPersistenceUtils.beginTransaction();
                        recordServices.makePersistent(record);
                        try {
                            solrServer.commit();
                        } catch (Throwable t) {
                            try {
                                solrServer.rollback();
                            } catch (Exception e) {
                                throw new RuntimeException(t);
                            }
                        }
                    } finally {
                        ConstellioPersistenceUtils.finishTransaction(false);
                    }

                    target.addComponent(availableTagsContainer);
                    target.addComponent(appliedTagsContainer);
                }

                @Override
                public void detachModels() {
                    recordTagModel.detach();
                    tagSourceModel.detach();
                    super.detachModels();
                }
            });
        }
    };

    closeLink = new AjaxLink("closeLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            SearchResultTaggingPanel parent = (SearchResultTaggingPanel) findParent(
                    SearchResultTaggingPanel.class);
            target.addComponent(parent);
            ModalWindow.closeCurrent(target);
        }
    };

    add(taggingSourceField);
    add(new Label("sourceName", source.getDcTitle()).setVisible(!isSourceSelectionVisible()));
    add(filterAddForm);
    filterAddForm.add(filterAddField);
    filterAddForm.add(filterAddButton);

    add(availableTagsContainer);
    availableTagsContainer.add(availableTagsListView);

    add(appliedTagsContainer);
    appliedTagsContainer.add(appliedTagsListView);

    add(closeLink);
}

From source file:com.doculibre.constellio.wicket.panels.signIn.ConstellioSignInPanel.java

License:Open Source License

public ConstellioSignInPanel(String id) {
    super(id);//from  ww  w  . j av a  2s.c  o  m

    final FeedbackPanel feedbackPanel = (FeedbackPanel) get("feedback");
    feedbackPanel.setOutputMarkupId(true);

    Form signinForm = (Form) get("signInForm");
    signinForm.add(new SetFocusBehavior(signinForm));

    signinForm.add(new AjaxButton("submitButton", signinForm) {
        /**
         * Will be called after the onSubmit() method of the signinForm
         * 
         * @see org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink#onSubmit(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.markup.html.form.Form)
         */
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            if (signIn(getUsername(), getPassword())) {
                ConstellioUser currentUser = ConstellioSession.get().getUser();
                if (currentUser.isAdmin()) {
                    PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
                    setResponsePage(pageFactoryPlugin.getAdminPage());
                } else {
                    ModalWindow.closeCurrent(target);
                }
            } else {
                target.addComponent(feedbackPanel);
            }
        }

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

    signinForm.add(new AjaxButton("cancelButton", signinForm) {
        /**
         * Will be called after the onSubmit() method of the signinForm
         * 
         * @see org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink#onSubmit(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.markup.html.form.Form)
         */
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            ModalWindow.closeCurrent(target);
        }
    }.setDefaultFormProcessing(false));
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.components.ExperimentPackageDetailPanel.java

License:Apache License

/**
 * Add window which allows to add new license to the package.
 *//*from  w  w  w .  ja v  a  2  s . c o  m*/
@SuppressWarnings("serial")
private void addLicenseAddWindow() {
    addLicenseWindow = new ModalWindow("addLicenseWindow");
    addLicenseWindow.setAutoSize(true);
    addLicenseWindow.setResizable(true);
    addLicenseWindow.setMinimalWidth(600);
    addLicenseWindow.setMinimalHeight(400);
    addLicenseWindow.setWidthUnit("px");
    addLicenseWindow.showUnloadConfirmation(false);

    // prepare list of licenses not associated with the package yet
    IModel<List<License>> licensesToAdd = new LoadableDetachableModel<List<License>>() {
        @Override
        protected List<License> load() {
            List<License> list = licenseFacade.getAllRecords();
            list.removeAll(licensePriceMap.keySet());
            return list;
        }
    };

    LicensePriceForm addLicenseForm = new LicensePriceForm(addLicenseWindow.getContentId(), licensesToAdd) {

        @Override
        protected void onSubmitAction(License license, BigDecimal price, AjaxRequestTarget target,
                Form<?> form) {
            licensePriceMap.put(license, price);
            ModalWindow.closeCurrent(target);
            target.add(licenseSelect);
        }

        @Override
        protected void onCancelAction(AjaxRequestTarget target, Form<?> form) {
            ModalWindow.closeCurrent(target);
        }

    };

    addLicenseWindow.setContent(addLicenseForm);
    this.add(addLicenseWindow);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.components.ExperimentPackageManagePanel.java

License:Apache License

private void addExperimentsViewWindow() {
    viewLicenseWindow = new ModalWindow("viewLicenseWindow");
    viewLicenseWindow.setAutoSize(true);
    viewLicenseWindow.setResizable(false);
    viewLicenseWindow.setMinimalWidth(600);
    viewLicenseWindow.setWidthUnit("px");
    viewLicenseWindow.showUnloadConfirmation(false);
    add(viewLicenseWindow);//from  w  ww. ja va  2 s .com

    viewLicenseWindow.setContent(new ViewLicensePanel(viewLicenseWindow.getContentId(), licenseModel, true) {
        @Override
        protected void onRemoveAction(IModel<License> model, AjaxRequestTarget target, Form<?> form) {
            licenseFacade.removeLicenseFromPackage(model.getObject(), epModel.getObject());
            ModalWindow.closeCurrent(target);
            target.add(header);
            experimentsToAddModel.detach(); // list of experiments to add must be reloaded for the actual set of licenses
        }
    });
    viewLicenseWindow.setTitle(ResourceUtils.getModel("dataTable.heading.licenseTitle"));
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.components.ExperimentPackageManagePanel.java

License:Apache License

/**
 * Add window which allows to add experiments to the package.
 *//*from www .  ja  v a2 s. c  o  m*/
private void addExperimentsAddWindow() {
    addExperimentsWindow = new ModalWindow("addExperimentsWindow");
    addExperimentsWindow.setAutoSize(true);
    addExperimentsWindow.setResizable(false);
    addExperimentsWindow.setMinimalWidth(600);
    addExperimentsWindow.setWidthUnit("px");

    experimentsToAddModel = this.listExperimentsToAdd();

    Panel content = new ExperimentListForm(addExperimentsWindow.getContentId(),
            ResourceUtils.getModel("pageTitle.addExperimenToPackage"), experimentsToAddModel) {
        @Override
        protected void onSubmitAction(List<Experiment> selectedExperiments, AjaxRequestTarget target,
                Form<?> form) {
            experimentPackageFacade.addExperimentsToPackage(selectedExperiments, epModel.getObject());
            ModalWindow.closeCurrent(target);
            experimentsModel.detach();
            experimentsToAddModel.detach();
            target.add(experimentListCont);
        }

        @Override
        protected void onCancelAction(List<Experiment> selectedExperiments, AjaxRequestTarget target,
                Form<?> form) {
            ModalWindow.closeCurrent(target);
            target.add(experimentListCont);
        }
    };

    addExperimentsWindow.setContent(content);
    this.add(addExperimentsWindow);
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.components.ExperimentPackageManagePanel.java

License:Apache License

/**
 * Add window which allows to add new license to the package.
 *//* www  .j a v  a2s  .c  o  m*/
private void addLicenseAddWindow() {
    addLicenseWindow = new ModalWindow("addLicenseWindow");
    addLicenseWindow.setAutoSize(true);
    addLicenseWindow.setResizable(false);
    addLicenseWindow.setMinimalWidth(600);
    addLicenseWindow.setMinimalHeight(400);
    addLicenseWindow.setWidthUnit("px");
    addLicenseWindow.showUnloadConfirmation(false);

    // prepare list of licenses not associated with the package yet
    IModel<List<License>> licenses = new LoadableDetachableModel<List<License>>() {
        @Override
        protected List<License> load() {
            List<License> list = licenseFacade.getAllRecords();
            list.removeAll(licenseFacade.getLicensesForPackage(epModel.getObject()));
            return list;
        }
    };

    LicensePriceForm addLicenseForm = new LicensePriceForm(addLicenseWindow.getContentId(), licenses) {

        @Override
        protected void onSubmitAction(License license, BigDecimal price, AjaxRequestTarget target,
                Form<?> form) {
            ExperimentPackageLicense expPacLic = new ExperimentPackageLicense();
            expPacLic.setExperimentPackage(epModel.getObject());
            expPacLic.setLicense(license);
            expPacLic.setPrice(price);
            experimentPackageLicenseFacade.create(expPacLic);
            ModalWindow.closeCurrent(target);
            target.add(header);
            experimentsToAddModel.detach(); // list of experiments to add must be reloaded for the actual set of licenses
            // TODO check all experiments contained in the package for the new license
        }

        @Override
        protected void onCancelAction(AjaxRequestTarget target, Form<?> form) {
            ModalWindow.closeCurrent(target);
            target.add(header);
        }

    };

    addLicenseWindow.setContent(addLicenseForm);
    this.add(addLicenseWindow);
}

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/*  w  w w.  j a v  a2 s . com*/
        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);
}