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

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

Introduction

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

Prototype

public ModalWindow(final String id) 

Source Link

Document

Creates a new modal window component.

Usage

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

License:Open Source License

public PopupSearchResultPanel(String id, SolrDocument doc, final SearchResultsDataProvider dataProvider) {
    super(id);//from  w ww. j  a va  2 s.c  o m

    RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
    String solrServerName = dataProvider.getSimpleSearch().getCollectionName();
    RecordCollection collection = collectionServices.get(solrServerName);

    IndexField uniqueKeyField = collection.getUniqueKeyIndexField();
    IndexField defaultSearchField = collection.getDefaultSearchIndexField();
    IndexField urlField = collection.getUrlIndexField();
    IndexField titleField = collection.getTitleIndexField();

    // title
    String documentID = (String) getFieldValue(doc, uniqueKeyField.getName());

    String documentTitle = (String) getFieldValue(doc, titleField.getName());

    if (StringUtils.isBlank(documentTitle)) {
        if (urlField == null) {
            documentTitle = (String) getFieldValue(doc, uniqueKeyField.getName());
        } else {
            documentTitle = (String) getFieldValue(doc, urlField.getName());
        }
    }
    if (documentTitle.length() > 120) {
        documentTitle = documentTitle.substring(0, 120) + " ...";
    }

    // content
    RecordServices recordServices = ConstellioSpringUtils.getRecordServices();
    Record record = recordServices.get(doc);

    RawContentServices rawContentServices = ConstellioSpringUtils.getRawContentServices();
    List<RawContent> rawContents = rawContentServices.getRawContents(record);
    StringBuilder content = new StringBuilder();
    for (RawContent raw : rawContents) {
        byte[] bytes = raw.getContent();
        content.append(new String(bytes));
    }

    String documentContent = content.toString();

    // date
    String documentLastModified = getFieldValue(doc, IndexField.LAST_MODIFIED_FIELD);

    // Description du document dans extrait:
    QueryResponse response = dataProvider.getQueryResponse();
    Map<String, Map<String, List<String>>> highlighting = response.getHighlighting();
    final String recordURL = record.getUrl();
    Map<String, List<String>> fieldsHighlighting = highlighting.get(recordURL);

    String extrait = getExcerptFromHighlight(defaultSearchField.getName(), fieldsHighlighting);

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

    detailsDocumentModal.setContent(
            new PopupDetailsPanel(detailsDocumentModal.getContentId(), documentContent, documentLastModified));
    detailsDocumentModal.setCookieName("detailsDocumentModal");

    String modalTitle = documentTitle;
    detailsDocumentModal.setTitle(modalTitle);

    AjaxLink detailsDocumentLink = new AjaxLink("detailsDocumentLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            detailsDocumentModal.show(target);
        }
    };
    add(detailsDocumentLink);

    final RecordModel recordModel = new RecordModel(record);
    AttributeAppender computeClickAttributeModifier = new AttributeAppender("onclick", true,
            new LoadableDetachableModel() {
                @Override
                protected Object load() {
                    Record record = recordModel.getObject();
                    SimpleSearch simpleSearch = dataProvider.getSimpleSearch();
                    WebRequest webRequest = (WebRequest) RequestCycle.get().getRequest();
                    HttpServletRequest httpRequest = webRequest.getHttpServletRequest();
                    return ComputeSearchResultClickServlet.getCallbackJavascript(httpRequest, simpleSearch,
                            record);
                }

                @Override
                protected void onDetach() {
                    recordModel.detach();
                    super.onDetach();
                }
            }, ";") {
        @Override
        protected String newValue(String currentValue, String appendValue) {
            return appendValue + currentValue;
        }
    };
    detailsDocumentLink.add(computeClickAttributeModifier);

    Label subjectLabel = new Label("subject", documentTitle);
    detailsDocumentLink.add(subjectLabel.setEscapeModelStrings(false));

    Label extraitLbl = new Label("documentContent", extrait);
    add(extraitLbl.setEscapeModelStrings(false));
    add(new Label("date", "Date : " + documentLastModified));

    add(new ElevatePanel("elevatePanel", record, dataProvider.getSimpleSearch()));
}

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) {/*  w  w  w. ja v  a  2 s .c  om*/
    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.results.tagging.SearchResultTaggingPanel.java

License:Open Source License

public SearchResultTaggingPanel(String id, final SolrDocument doc, final IDataProvider dataProviderParam) {
    super(id);//from w w w .  java  2  s  .co m

    RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
    final SimpleSearch simpleSearch;
    if (dataProviderParam instanceof FacetsDataProvider) {
        FacetsDataProvider dataProvider = (FacetsDataProvider) dataProviderParam;
        simpleSearch = dataProvider.getSimpleSearch();
    } else {
        SearchResultsDataProvider dataProvider = (SearchResultsDataProvider) dataProviderParam;
        simpleSearch = dataProvider.getSimpleSearch();
    }

    String collectionName = simpleSearch.getCollectionName();
    RecordCollection collection = collectionServices.get(collectionName);
    if (!collection.isOpenSearch()) {
        RecordServices recordServices = ConstellioSpringUtils.getRecordServices();
        Record record = recordServices.get(doc);
        recordModel = new RecordModel(record);

        final ModalWindow taggingModal = new ModalWindow("taggingModal");
        taggingModal.setTitle(new StringResourceModel("tags", this, null));
        taggingModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
        taggingModal.setInitialWidth(800);
        taggingModal.setInitialHeight(450);
        taggingModal.setCloseButtonCallback(new CloseButtonCallback() {
            @Override
            public boolean onCloseButtonClicked(AjaxRequestTarget target) {
                target.addComponent(SearchResultTaggingPanel.this);
                return true;
            }
        });
        add(taggingModal);

        IModel thesaurusListModel = new LoadableDetachableModel() {
            @Override
            protected Object load() {
                List<Thesaurus> thesaurusList = new ArrayList<Thesaurus>();
                RecordCollectionServices collectionServices = ConstellioSpringUtils
                        .getRecordCollectionServices();
                String collectionName = simpleSearch.getCollectionName();
                RecordCollection collection = collectionServices.get(collectionName);
                thesaurusList.add(null);// free text tags
                if (collection.getThesaurus() != null) {
                    thesaurusList.add(collection.getThesaurus());
                }
                return thesaurusList;
            }
        };

        add(new ListView("taggingLinks", thesaurusListModel) {
            @Override
            protected void populateItem(ListItem item) {
                Thesaurus thesaurus = (Thesaurus) item.getModelObject();
                final ReloadableEntityModel<Thesaurus> thesaurusModel = new ReloadableEntityModel<Thesaurus>(
                        thesaurus);
                final String thesaurusName;
                if (thesaurus == null) {
                    thesaurusName = getLocalizer().getString("tags", this);
                } else {
                    thesaurusName = getLocalizer().getString("thesaurus", this);
                }

                AjaxLink link = new AjaxLink("taggingLink") {
                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        Thesaurus thesaurus = thesaurusModel.getObject();
                        SearchResultEditTaggingPanel editTaggingPanel = new SearchResultEditTaggingPanel(
                                taggingModal.getContentId(), doc, dataProviderParam, thesaurus);
                        taggingModal.setContent(editTaggingPanel);
                        taggingModal.show(target);
                    }

                    @Override
                    public boolean isEnabled() {
                        boolean enabled = super.isEnabled();
                        if (enabled) {
                            Record record = recordModel.getObject();
                            if (record != null) {
                                ConstellioUser user = ConstellioSession.get().getUser();
                                if (user != null) {
                                    RecordCollection collection = record.getConnectorInstance()
                                            .getRecordCollection();
                                    enabled = user.hasCollaborationPermission(collection);
                                } else {
                                    enabled = false;
                                }
                            } else {
                                enabled = false;
                            }
                        }
                        return enabled;
                    }

                    @Override
                    public void detachModels() {
                        thesaurusModel.detach();
                        super.detachModels();
                    }
                };
                item.add(link);
                link.add(new Label("thesaurusName", thesaurusName));

                final IModel tagsModel = new LoadableDetachableModel() {
                    @Override
                    protected Object load() {
                        Record record = recordModel.getObject();
                        Thesaurus thesaurus = thesaurusModel.getObject();
                        return new ArrayList<RecordTag>(record.getIncludedRecordTags(thesaurus));
                    }
                };
                item.add(new ListView("tags", tagsModel) {
                    @SuppressWarnings("unchecked")
                    @Override
                    protected void populateItem(ListItem item) {
                        RecordTag recordTag = (RecordTag) item.getModelObject();
                        final RecordTagModel recordTagModel = new RecordTagModel(recordTag);
                        Link addTagLink = new Link("addTagLink") {
                            @Override
                            public void onClick() {
                                RecordTag recordTag = recordTagModel.getObject();
                                SimpleSearch clone = simpleSearch.clone();
                                clone.getTags().add(recordTag.getName(getLocale()));

                                PageFactoryPlugin pageFactoryPlugin = PluginFactory
                                        .getPlugin(PageFactoryPlugin.class);
                                if (StringUtils.isNotBlank(clone.getLuceneQuery())) {
                                    // ConstellioSession.get().addSearchHistory(clone);
                                    setResponsePage(pageFactoryPlugin.getSearchResultsPage(),
                                            SearchResultsPage.getParameters(clone));
                                } else {
                                    SimpleSearch newSearch = new SimpleSearch();
                                    newSearch.setCollectionName(simpleSearch.getCollectionName());
                                    newSearch.setSingleSearchLocale(simpleSearch.getSingleSearchLocale());
                                    setResponsePage(pageFactoryPlugin.getSearchFormPage(),
                                            SearchFormPage.getParameters(newSearch));
                                }
                            }

                            @Override
                            public void detachModels() {
                                recordTagModel.detach();
                                super.detachModels();
                            }
                        };
                        item.add(addTagLink);
                        List<RecordTag> recordTags = (List<RecordTag>) tagsModel.getObject();
                        String tag = recordTag.getName(getLocale());
                        if (item.getIndex() < recordTags.size() - 1) {
                            tag += ";";
                        }
                        addTagLink.add(new Label("tag", tag));
                        addTagLink.setEnabled(false);
                    }
                });
                item.add(new WebMarkupContainer("noTags") {
                    @SuppressWarnings("unchecked")
                    @Override
                    public boolean isVisible() {
                        List<RecordTag> recordTags = (List<RecordTag>) tagsModel.getObject();
                        return super.isVisible() && recordTags.isEmpty();
                    }
                });
            }
        });

    } else {
        setVisible(false);
    }
}

From source file:com.doculibre.constellio.wicket.panels.thesaurus.ThesaurusSuggestionPanel.java

License:Open Source License

public ThesaurusSuggestionPanel(String id, final SimpleSearch simpleSearch, final Locale displayLocale) {
    super(id);/*w  w  w  . jav  a  2s.com*/

    boolean visible = false;

    RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
    SkosServices skosServices = ConstellioSpringUtils.getSkosServices();

    String collectionName = simpleSearch.getCollectionName();
    if (simpleSearch.isQueryValid()) {
        String query = simpleSearch.getQuery();
        if (StringUtils.isNotBlank(query) && !SimpleSearch.SEARCH_ALL.equals(query)) {
            RecordCollection collection = collectionServices.get(collectionName);
            if (collection != null) {
                Thesaurus thesaurus = collection.getThesaurus();
                if (thesaurus != null) {
                    Locale locale = collection.getDisplayLocale(getLocale());
                    Set<SkosConcept> prefLabelMatches = skosServices.getByPrefLabel(query, thesaurus, locale);
                    Set<SkosConcept> altLabelMatches = skosServices.searchAltLabels(query, thesaurus, locale);
                    if (prefLabelMatches.size() == 1) {
                        SkosConcept skosConcept = prefLabelMatches.iterator().next();
                        final ReloadableEntityModel<SkosConcept> skosConceptModel = new ReloadableEntityModel<SkosConcept>(
                                skosConcept);

                        prefLabelLink = new WebMarkupContainer("prefLabelLink");
                        prefLabelLink.setVisible(false);
                        prefLabelLabel = new WebMarkupContainer("prefLabelLabel");
                        prefLabelLink.setVisible(false);

                        semanticNetworkLink = new AjaxLink("semanticNetworkLink") {
                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                SkosConcept skosConcept = skosConceptModel.getObject();
                                semanticNetworkModal.setContent(new SkosConceptModalPanel(
                                        semanticNetworkModal.getContentId(), skosConcept) {
                                    @Override
                                    protected AbstractLink newDetailsLink(String id, SkosConcept skosConcept) {
                                        String prefLabel = "" + skosConcept.getPrefLabel(displayLocale);
                                        prefLabel = prefLabel.toLowerCase();
                                        SimpleSearch clone = simpleSearch.clone();
                                        clone.setQuery(prefLabel);

                                        PageFactoryPlugin pageFactoryPlugin = PluginFactory
                                                .getPlugin(PageFactoryPlugin.class);
                                        return new BookmarkablePageLink(id,
                                                pageFactoryPlugin.getSearchResultsPage(),
                                                SearchResultsPage.getParameters(clone));
                                    }
                                });
                                semanticNetworkModal.show(target);
                            }

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

                        String prefLabel = "" + skosConcept.getPrefLabel(displayLocale);
                        prefLabel = prefLabel.toLowerCase();
                        semanticNetworkLabel = new Label("semanticNetworkLabel", prefLabel);
                        semanticNetworkModal = new ModalWindow("semanticNetworkModal");

                        disambiguation = new WebMarkupContainer("disambiguation");
                        disambiguation.setVisible(false);

                        add(prefLabelLink);
                        prefLabelLink.add(prefLabelLabel);
                        add(semanticNetworkLink);
                        semanticNetworkLink.add(semanticNetworkLabel);
                        add(semanticNetworkModal);
                        add(disambiguation);

                        visible = true;
                    } else if (prefLabelMatches.size() > 1) {
                        prefLabelLink = new WebMarkupContainer("prefLabelLink");
                        prefLabelLink.setVisible(false);
                        prefLabelLabel = new WebMarkupContainer("prefLabelLabel");
                        prefLabelLink.setVisible(false);

                        semanticNetworkLink = new WebMarkupContainer("semanticNetworkLink");
                        semanticNetworkLink.setVisible(false);
                        semanticNetworkLabel = new WebMarkupContainer("semanticNetworkLabel");
                        semanticNetworkLabel.setVisible(false);
                        semanticNetworkModal = new ModalWindow("semanticNetworkModal");
                        semanticNetworkModal.setVisible(false);

                        List<String> disambiguationPrefLabels = new ArrayList<String>();
                        for (SkosConcept skosConcept : prefLabelMatches) {
                            String prefLabel = "" + skosConcept.getPrefLabel(displayLocale);
                            prefLabel = prefLabel.toLowerCase();
                            disambiguationPrefLabels.add(prefLabel);
                        }
                        disambiguation = new ListView("disambiguation", disambiguationPrefLabels) {
                            @Override
                            protected void populateItem(ListItem item) {
                                String prefLabel = (String) item.getModelObject();
                                SimpleSearch clone = simpleSearch.clone();
                                clone.setQuery(prefLabel);

                                PageFactoryPlugin pageFactoryPlugin = PluginFactory
                                        .getPlugin(PageFactoryPlugin.class);
                                Link prefLabelLink = new BookmarkablePageLink("prefLabelLink",
                                        pageFactoryPlugin.getSearchResultsPage(),
                                        SearchResultsPage.getParameters(clone));
                                Label prefLabelLabel = new Label("prefLabel", prefLabel);
                                item.add(prefLabelLink);
                                prefLabelLink.add(prefLabelLabel);
                            }
                        };

                        add(prefLabelLink);
                        prefLabelLink.add(prefLabelLabel);
                        add(semanticNetworkLink);
                        add(semanticNetworkModal);
                        add(disambiguation);

                        visible = true;
                    } else if (!altLabelMatches.isEmpty()) {
                        SkosConcept firstAltLabelConcept = altLabelMatches.iterator().next();
                        String prefLabel = "" + firstAltLabelConcept.getPrefLabel(displayLocale);
                        prefLabel = prefLabel.toLowerCase();
                        SimpleSearch clone = simpleSearch.clone();
                        clone.setQuery(prefLabel);

                        PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
                        prefLabelLink = new BookmarkablePageLink("prefLabelLink",
                                pageFactoryPlugin.getSearchResultsPage(),
                                SearchResultsPage.getParameters(clone));
                        prefLabelLabel = new Label("prefLabelLabel", prefLabel);

                        semanticNetworkLink = new WebMarkupContainer("semanticNetworkLink");
                        semanticNetworkLink.setVisible(false);
                        semanticNetworkLabel = new WebMarkupContainer("semanticNetworkLabel");
                        semanticNetworkLabel.setVisible(false);
                        semanticNetworkModal = new ModalWindow("semanticNetworkModal");
                        semanticNetworkModal.setVisible(false);

                        disambiguation = new WebMarkupContainer("disambiguation");
                        disambiguation.setVisible(false);

                        add(prefLabelLink);
                        prefLabelLink.add(prefLabelLabel);
                        add(semanticNetworkLink);
                        add(semanticNetworkModal);
                        add(disambiguation);

                        visible = true;
                    }
                }
            }
        }
    }
    setVisible(visible);
}

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);/*www  .java2 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.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);/*from   w  w w .  ja va2 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.BaseFocusPanel.java

License:Apache License

private void initResourceModal() {
    ModalWindow window = new ModalWindow(MODAL_ID_RESOURCE);

    final SimpleUserResourceProvider provider = new SimpleUserResourceProvider(this, shadowModel) {
        @Override// w  w  w .  j  a  va2s  .  co m
        protected void handlePartialError(OperationResult result) {
            showResult(result);
        }
    };

    ResourcesSelectionPanel.Context context = new ResourcesSelectionPanel.Context(this) {
        @Override
        public BaseFocusPanel getRealParent() {
            return WebMiscUtil.theSameForPage(BaseFocusPanel.this, getCallingPageReference());
        }

        @Override
        public SimpleUserResourceProvider getProvider() {
            return provider;
        }

        @Override
        public void addPerformed(AjaxRequestTarget target, List<ResourceType> newResources) {
            getRealParent().addSelectedAccountPerformed(target, newResources);
        }
    };
    ResourcesSelectionPage.prepareDialog(window, context, this, "pageAdminFocus.title.selectResource",
            ID_SHADOWS);

    add(window);
}

From source file:com.evolveum.midpoint.web.page.admin.BaseFocusPanel.java

License:Apache License

private void initAssignableModal() {

    ModalWindow window = new ModalWindow(MODAL_ID_ADD_ORG);
    AssignableOrgSelectionPanel.Context context = new AssignableOrgSelectionPanel.Context(this) {
        @Override/*w ww . ja  v  a  2s .  c  o m*/
        public BaseFocusPanel getRealParent() {
            return WebMiscUtil.theSameForPage(BaseFocusPanel.this, getCallingPageReference());
        }

        @Override
        protected void addPerformed(AjaxRequestTarget target, List<ObjectType> selected) {
            getRealParent().addSelectedOrgPerformed(target, selected);
        }

        @Override
        protected void handlePartialError(OperationResult result) {
            getRealParent().showResult(result);
        }

        @Override
        public String getSubmitKey() {
            return "assignablePopupContent.button.add";
        }
    };
    AssignableOrgSelectionPage.prepareDialog(window, context, this, "pageAdminFocus.title.selectAssignable",
            ID_ORGS);
    context.setType(OrgType.class);
    add(window);

    ModalWindow assignmentPreviewPopup = new AssignmentPreviewDialog(MODAL_ID_ASSIGNMENTS_PREVIEW, null, null);
    add(assignmentPreviewPopup);
}

From source file:com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoicePanel.java

License:Apache License

private void initGenericDialog(final Class<C> type, final List<PrismPropertyValue> values) {
    final ModalWindow dialog = new ModalWindow(MODAL_ID_OBJECT_SELECTION_POPUP);

    ObjectSelectionPanel.Context context = new ObjectSelectionPanel.Context(this) {
        private static final long serialVersionUID = 1L;

        // See analogous discussion in ChooseTypePanel
        public AssociationValueChoicePanel getRealParent() {
            return WebComponentUtil.theSameForPage(AssociationValueChoicePanel.this, getCallingPageReference());
        }// w  ww  . j a  va  2  s  .  c om

        @Override
        public void chooseOperationPerformed(AjaxRequestTarget target, ObjectType object) {
            getRealParent().choosePerformed(target, object);
        }

        @Override
        public Collection<SelectorOptions<GetOperationOptions>> getDataProviderOptions() {
            return getAssociationsSearchOptions();
        }

        @Override
        public ObjectQuery getDataProviderQuery() {
            return query;
        }

        @Override
        public boolean isSearchEnabled() {
            //TODO don't commit
            return false;
        }

        @Override
        public Class<? extends ObjectType> getObjectTypeClass() {
            return type;
        }

    };

    ObjectSelectionPage.prepareDialog(dialog, context, this, "chooseTypeDialog.title", ID_TEXT_WRAPPER);
    add(dialog);
}

From source file:com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoicePanel.java

License:Apache License

private void initUserOrgDialog() {
    final ModalWindow dialog = new ModalWindow(MODAL_ID_OBJECT_SELECTION_POPUP);
    ObjectSelectionPanel.Context context = new ObjectSelectionPanel.Context(this) {
        private static final long serialVersionUID = 1L;

        // See analogous discussion in ChooseTypePanel
        public AssociationValueChoicePanel getRealParent() {
            return WebComponentUtil.theSameForPage(AssociationValueChoicePanel.this, getCallingPageReference());
        }// w  w w  .j a va  2 s  .c  om

        @Override
        public void chooseOperationPerformed(AjaxRequestTarget target, ObjectType object) {
            getRealParent().choosePerformed(target, object);
        }

        @Override
        public boolean isSearchEnabled() {
            return true;
        }

        @Override
        public Class<? extends ObjectType> getObjectTypeClass() {
            return UserType.class;
        }

        @Override
        protected WebMarkupContainer createExtraContentContainer(String extraContentId,
                final ObjectSelectionPanel objectSelectionPanel) {
            return new UserOrgReferenceChoosePanel(extraContentId, Boolean.FALSE) {
                @Override
                protected void onReferenceTypeChangePerformed(AjaxRequestTarget target, Boolean newValue) {
                    objectSelectionPanel.updateTableByTypePerformed(target,
                            Boolean.FALSE.equals(newValue) ? UserType.class : OrgType.class);
                }
            };
        }
    };

    ObjectSelectionPage.prepareDialog(dialog, context, this, "chooseTypeDialog.title", ID_TEXT_WRAPPER);
    add(dialog);
}