List of usage examples for org.apache.wicket.markup.html.list ListView ListView
public ListView(final String id, final List<T> list)
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) {//from w w w . j a v 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.results.tagging.SearchResultTaggingPanel.java
License:Open Source License
public SearchResultTaggingPanel(String id, final SolrDocument doc, final IDataProvider dataProviderParam) { super(id);/* www. java2 s. c o 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.search.advanced.AdvancedSearchPanel.java
License:Open Source License
public AdvancedSearchPanel(String id, final IModel simpleSearchModel) { super(id);// w ww.ja va 2s . c om add(HeaderContributor.forJavaScript(MYPAGE_JS)); final IModel ruleTypesModel = new LoadableDetachableModel() { protected Object load() { RecordCollectionServices recordCollectionServices = ConstellioSpringUtils .getRecordCollectionServices(); SimpleSearch search = (SimpleSearch) simpleSearchModel.getObject(); RecordCollection recordCollection = recordCollectionServices.get(search.getCollectionName()); List<RuleTypeChoice> choices = new ArrayList<RuleTypeChoice>(); for (AdvancedSearchEnabledRule enabledRule : recordCollection.getAdvancedSearchEnabledRules()) { IndexField indexField = enabledRule.getIndexField(); SearchRule rule = SearchRulesFactory.constructSearchRule(indexField); if (rule != null) { SimpleParams params = rule.toSimpleParams(true); RuleTypeChoice choice = new RuleTypeChoice(); String title = indexField.getLabel(IndexField.LABEL_TITLE, ConstellioSession.get().getLocale()); choice.name = title != null ? title : indexField.getName(); choice.params = params; choices.add(choice); } } Collections.sort(choices); RuleTypeChoice defaultFieldSearch = new RuleTypeChoice(); defaultFieldSearch.name = new StringResourceModel("defaultField", AdvancedSearchPanel.this, null) .getString(); defaultFieldSearch.params = SearchRulesFactory.getDefaultFieldSearchRule().toSimpleParams(true); choices.add(0, defaultFieldSearch); return choices; } }; IModel rulesModel = new LoadableDetachableModel() { @Override protected Object load() { SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); SearchRule rootSearchRule = simpleSearch.getAdvancedSearchRule(); List<SearchRule> rules; if (rootSearchRule == null) { rules = new ArrayList<SearchRule>(); } else { rules = rootSearchRule.toList(); } return rules; } }; add(new ListView("rules", rulesModel) { @Override protected void populateItem(ListItem item) { SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); final SimpleSearch clonedSimpleSearch = simpleSearch.clone(); final SearchRule rule = (SearchRule) item.getModelObject(); Component ruleComponent = SearchRulePanelFactory.constructPanel("rule", clonedSimpleSearch, rule, ruleTypesModel); //int leftSpace = 25 * Math.max(0, rule.getLevel() - 1); int leftSpace = 25 * rule.getLevel(); ruleComponent.add(new SimpleAttributeModifier("style", "margin-left:" + leftSpace + "px;")); item.add(ruleComponent); item.add(newDeleteButton(clonedSimpleSearch, rule)); item.add(newAddRuleButton(clonedSimpleSearch, rule)); item.add(newAddGroupButton(clonedSimpleSearch, rule)); } }); }
From source file:com.doculibre.constellio.wicket.panels.search.SearchFormPanel.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) public SearchFormPanel(String id, final IModel simpleSearchModel) { super(id);// ww w. j av a2 s. c om searchForm = new WebMarkupContainer("searchForm", new CompoundPropertyModel(simpleSearchModel)); simpleSearchFormDiv = new WebMarkupContainer("simpleSearchFormDiv") { @Override public boolean isVisible() { SimpleSearch search = (SimpleSearch) simpleSearchModel.getObject(); return search.getAdvancedSearchRule() == null; } }; advancedSearchFormDiv = new WebMarkupContainer("advancedSearchFormDiv") { @Override public boolean isVisible() { SimpleSearch search = (SimpleSearch) simpleSearchModel.getObject(); return search.getAdvancedSearchRule() != null; } }; advancedSearchPanel = new AdvancedSearchPanel("advanceForm", simpleSearchModel); searchForm.add(new AttributeModifier("action", new LoadableDetachableModel() { @Override protected Object load() { PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class); return urlFor(pageFactoryPlugin.getSearchResultsPage(), new PageParameters()); } })); hiddenFields = new ListView("hiddenFields", new LoadableDetachableModel() { @Override protected Object load() { List<SimpleParam> hiddenParams = new ArrayList<SimpleParam>(); HiddenSearchFormParamsPlugin hiddenSearchFormParamsPlugin = PluginFactory .getPlugin(HiddenSearchFormParamsPlugin.class); if (hiddenSearchFormParamsPlugin != null) { WebRequestCycle webRequestCycle = (WebRequestCycle) RequestCycle.get(); HttpServletRequest request = webRequestCycle.getWebRequest().getHttpServletRequest(); SimpleParams hiddenSimpleParams = hiddenSearchFormParamsPlugin.getHiddenParams(request); for (String paramName : hiddenSimpleParams.keySet()) { for (String paramValue : hiddenSimpleParams.getList(paramName)) { hiddenParams.add(new SimpleParam(paramName, paramValue)); } } } SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); SimpleSearch clone = simpleSearch.clone(); SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils .getSearchInterfaceConfigServices(); SearchInterfaceConfig config = searchInterfaceConfigServices.get(); if (!config.isKeepFacetsNewSearch()) { // Will be true if we just clicked on a delete link // on the CurrentSearchPanel if (!clone.isRefinedSearch()) { clone.getSearchedFacets().clear(); clone.setCloudKeyword(null); } // We must click on a delete link on // CurrentSearchPanel so that it is considered // again as refined clone.setRefinedSearch(false); } clone.initFacetPages(); List<String> ignoredParamNames = Arrays.asList("query", "searchType", "page", "singleSearchLocale"); SimpleParams searchParams = clone.toSimpleParams(); for (String paramName : searchParams.keySet()) { if (!ignoredParamNames.contains(paramName) && !paramName.contains(SearchRule.ROOT_PREFIX)) { List<String> paramValues = searchParams.getList(paramName); for (String paramValue : paramValues) { SimpleParam hiddenParam = new SimpleParam(paramName, paramValue); hiddenParams.add(hiddenParam); } } } return hiddenParams; } }) { @Override protected void populateItem(ListItem item) { SimpleParam hiddenParam = (SimpleParam) item.getModelObject(); if (hiddenParam.value != null) { item.add(new SimpleAttributeModifier("name", hiddenParam.name)); item.add(new SimpleAttributeModifier("value", hiddenParam.value)); } else { item.setVisible(false); } } }; SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils .getSearchInterfaceConfigServices(); SearchInterfaceConfig config = searchInterfaceConfigServices.get(); if (config.isSimpleSearchAutocompletion() && ((SimpleSearch) simpleSearchModel.getObject()).getAdvancedSearchRule() == null) { AutoCompleteSettings settings = new AutoCompleteSettings(); settings.setCssClassName("simpleSearchAutoCompleteChoices"); IModel model = new Model(((SimpleSearch) simpleSearchModel.getObject()).getQuery()); WordsAndValueAutoCompleteRenderer render = new WordsAndValueAutoCompleteRenderer() { @Override protected String getTextValue(String word, Object value) { return word; } }; queryField = new TextAndValueAutoCompleteTextField("query", model, String.class, settings, render) { @Override public String getInputName() { return super.getId(); } @Override protected Iterator getChoicesForWord(String word) { SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); String collectionName = simpleSearch.getCollectionName(); AutocompleteServices autocompleteServices = ConstellioSpringUtils.getAutocompleteServices(); RecordCollectionServices collectionServices = ConstellioSpringUtils .getRecordCollectionServices(); RecordCollection collection = collectionServices.get(collectionName); List<String> suggestions = autocompleteServices.suggestSimpleSearch(word, collection, getLocale()); return suggestions.iterator(); } @Override protected boolean supportMultipleWords() { return false; } }; } else { queryField = new TextField("query") { @Override public String getInputName() { return super.getId(); } }; } searchTypeField = new RadioGroup("searchType") { @Override public String getInputName() { return super.getId(); } }; IModel languages = new LoadableDetachableModel() { protected Object load() { Set<String> localeCodes = new HashSet<String>(); SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); RecordCollectionServices recordCollectionServices = ConstellioSpringUtils .getRecordCollectionServices(); RecordCollection collection = recordCollectionServices.get(simpleSearch.getCollectionName()); List<Locale> searchableLocales = ConstellioSpringUtils.getSearchableLocales(); if (!collection.isOpenSearch()) { localeCodes.add(""); if (!searchableLocales.isEmpty()) { for (Locale searchableLocale : searchableLocales) { localeCodes.add(searchableLocale.getLanguage()); } } else { IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices(); IndexField languageField = indexFieldServices.get(IndexField.LANGUAGE_FIELD, collection); for (String localeCode : indexFieldServices.suggestValues(languageField)) { localeCodes.add(localeCode); } } } else { localeCodes.add(""); if (!searchableLocales.isEmpty()) { for (Locale searchableLocale : searchableLocales) { localeCodes.add(searchableLocale.getLanguage()); } } else { for (Locale availableLocale : Locale.getAvailableLocales()) { localeCodes.add(availableLocale.getLanguage()); } } } List<Locale> locales = new ArrayList<Locale>(); for (String localeCode : localeCodes) { locales.add(new Locale(localeCode)); } Collections.sort(locales, new Comparator<Locale>() { @Override public int compare(Locale locale1, Locale locale2) { Locale locale1Display; Locale locale2Display; SearchInterfaceConfig config = ConstellioSpringUtils.getSearchInterfaceConfigServices() .get(); if (config.isTranslateLanguageNames()) { locale1Display = locale2Display = getLocale(); } else { locale1Display = locale1; locale2Display = locale2; } List<Locale> searchableLocales = ConstellioSpringUtils.getSearchableLocales(); if (searchableLocales.isEmpty()) { searchableLocales = ConstellioSpringUtils.getSupportedLocales(); } Integer indexOfLocale1; Integer indexOfLocale2; if (locale1.getLanguage().equals(getLocale().getLanguage())) { indexOfLocale1 = Integer.MIN_VALUE; } else { indexOfLocale1 = searchableLocales.indexOf(locale1); } if (locale2.getLanguage().equals(getLocale().getLanguage())) { indexOfLocale2 = Integer.MIN_VALUE; } else { indexOfLocale2 = searchableLocales.indexOf(locale2); } if (indexOfLocale1 == -1) { indexOfLocale1 = Integer.MAX_VALUE; } if (indexOfLocale2 == -1) { indexOfLocale2 = Integer.MAX_VALUE; } if (!indexOfLocale1.equals(Integer.MAX_VALUE) || !indexOfLocale2.equals(Integer.MAX_VALUE)) { return indexOfLocale1.compareTo(indexOfLocale2); } else if (StringUtils.isBlank(locale1.getLanguage())) { return Integer.MIN_VALUE; } else { return locale1.getDisplayLanguage(locale1Display) .compareTo(locale2.getDisplayLanguage(locale2Display)); } } }); return locales; } }; IChoiceRenderer languageRenderer = new ChoiceRenderer() { @Override public Object getDisplayValue(Object object) { Locale locale = (Locale) object; String text; if (locale.getLanguage().isEmpty()) { text = (String) new StringResourceModel("all", SearchFormPanel.this, null).getObject(); } else { Locale localeDisplay; SearchInterfaceConfig config = ConstellioSpringUtils.getSearchInterfaceConfigServices().get(); if (config.isTranslateLanguageNames()) { localeDisplay = getLocale(); } else { localeDisplay = locale; } text = StringUtils.capitalize(locale.getDisplayLanguage(localeDisplay)); } return text; } @Override public String getIdValue(Object object, int index) { return ((Locale) object).getLanguage(); } }; IModel languageModel = new Model() { @Override public Object getObject() { SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); Locale singleSearchLocale = simpleSearch.getSingleSearchLocale(); if (singleSearchLocale == null) { SearchedFacet facet = simpleSearch.getSearchedFacet(IndexField.LANGUAGE_FIELD); List<String> values = facet == null ? new ArrayList<String>() : facet.getIncludedValues(); singleSearchLocale = values.isEmpty() ? null : new Locale(values.get(0)); } if (singleSearchLocale == null) { singleSearchLocale = getLocale(); } return singleSearchLocale; } @Override public void setObject(Object object) { Locale singleSearchLocale = (Locale) object; SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject(); simpleSearch.setSingleSearchLocale(singleSearchLocale); } }; languageDropDown = new DropDownChoice("singleSearchLocale", languageModel, languages, languageRenderer) { @Override public String getInputName() { return "singleSearchLocale"; } @Override public boolean isVisible() { SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils .getSearchInterfaceConfigServices(); SearchInterfaceConfig config = searchInterfaceConfigServices.get(); return config.isLanguageInSearchForm(); } @Override protected CharSequence getDefaultChoice(Object selected) { return ""; }; }; searchButton = new Button("searchButton") { @Override public String getMarkupId() { return super.getId(); } @Override public String getInputName() { return super.getId(); } }; String submitImgUrl = "" + urlFor(new ResourceReference(BaseConstellioPage.class, "images/ico_loupe.png")); add(searchForm); searchForm.add(simpleSearchFormDiv); searchForm.add(advancedSearchFormDiv); searchForm.add(hiddenFields); queryField.add(new SetFocusBehavior(queryField)); addChoice(SimpleSearch.ALL_WORDS); addChoice(SimpleSearch.AT_LEAST_ONE_WORD); addChoice(SimpleSearch.EXACT_EXPRESSION); simpleSearchFormDiv.add(queryField); simpleSearchFormDiv.add(searchTypeField); simpleSearchFormDiv.add(languageDropDown); simpleSearchFormDiv.add(searchButton); advancedSearchFormDiv.add(advancedSearchPanel); searchButton.add(new SimpleAttributeModifier("src", submitImgUrl)); }
From source file:com.doculibre.constellio.wicket.panels.spellchecker.SpellCheckerPanel.java
License:Open Source License
private void initComponents() { searchTxtField.setOutputMarkupId(true); searchButton.setOutputMarkupId(true); IModel suggestedSearchKeyListModel = new LoadableDetachableModel() { @Override/*from w w w. j a v a2 s . c o m*/ protected Object load() { ListOrderedMap suggestedSearch = getSuggestedSearch(); return suggestedSearch.keyList(); } }; // Tags <li> add(new ListView("suggestion", suggestedSearchKeyListModel) { @SuppressWarnings("unchecked") @Override protected void populateItem(ListItem item) { ListOrderedMap suggestedSearch = getSuggestedSearch(); String originalWord = (String) item.getModelObject(); List<String> suggestionsForWord = (List<String>) suggestedSearch.get(originalWord); boolean hasSuggestionForWord = suggestionsForWord != null && !suggestionsForWord.isEmpty(); boolean hasManySuggestionsForWord = hasSuggestionForWord && suggestionsForWord.size() > 1; final int wordIndex = item.getIndex(); // <li> suggested word Component suggestedWordComponent; if (hasSuggestionForWord) { suggestedWordComponent = new Label("motSuggere", originalWord); suggestedWordComponent.add(new SimpleAttributeModifier("id", "mot" + wordIndex)); } else { suggestedWordComponent = new WebMarkupContainer("motSuggere"); suggestedWordComponent.setVisible(false); } if (hasManySuggestionsForWord) { suggestedWordComponent.add(new SimpleAttributeModifier("rel", "suggestion" + item.getIndex())); } item.add(suggestedWordComponent); suggestedWordComponent.add(getLaunchSuggestedSearchOnclickModifier()); // <li> vide pour avoir une flche en cas de suggestions multiples //WebMarkupContainer flecheMotSuggereContainer = new WebMarkupContainer("flecheMotSuggere"); //flecheMotSuggereContainer.setVisible(plusieursMotsSuggeres); //flecheMotSuggereContainer.add(new SimpleAttributeModifier("rel", "suggestion" + item.getIndex())); //item.add(flecheMotSuggereContainer); // <li> si pas de suggestion Component noSuggestionWordComponent; if (!hasSuggestionForWord) { noSuggestionWordComponent = new Label("motNonSuggere", originalWord); } else { noSuggestionWordComponent = new WebMarkupContainer("motNonSuggere"); noSuggestionWordComponent.setVisible(false); } item.add(noSuggestionWordComponent); noSuggestionWordComponent.add(getLaunchSuggestedSearchOnclickModifier()); } }); // Tags <div> add(new ListView("autresSuggestionsMot", suggestedSearchKeyListModel) { @SuppressWarnings("unchecked") @Override protected void populateItem(ListItem item) { ListOrderedMap suggestedSearch = getSuggestedSearch(); String originalWord = (String) item.getModelObject(); List<String> suggestedWords = (List<String>) suggestedSearch.get(originalWord); boolean hasSuggestedWord = suggestedWords != null && !suggestedWords.isEmpty(); boolean hasManySuggestedWords = hasSuggestedWord && suggestedWords.size() > 1; final int wordIndex = item.getIndex(); if (hasManySuggestedWords) { item.add(new SimpleAttributeModifier("id", "suggestion" + wordIndex)); item.add(new ListView("lienRemplacerMot", suggestedWords) { @Override protected void populateItem(ListItem item) { String suggestedWord = (String) item.getModelObject(); WebMarkupContainer lien = new WebMarkupContainer("lien"); item.add(lien); lien.add(new Label("libelle", suggestedWord)); StringBuffer jsReplaceWord = new StringBuffer("remplacerMot('"); jsReplaceWord.append(JavascriptUtils.escapeQuotes(suggestedWord)); jsReplaceWord.append("', "); jsReplaceWord.append(wordIndex); jsReplaceWord.append(");"); if (!hasManySuggestions()) { jsReplaceWord.append(getLaunchSuggestedSearchJSCall()); } lien.add(new SimpleAttributeModifier("onclick", jsReplaceWord)); } }); } else { item.setVisible(false); } } }); }
From source file:com.doculibre.constellio.wicket.panels.thesaurus.SkosConceptModalPanel.java
License:Open Source License
public SkosConceptModalPanel(String id, SkosConcept skosConcept) { super(id);//from w w w. j a v a 2s . c om this.skosConceptModel = new ReloadableEntityModel<SkosConcept>(skosConcept); final IModel localeModel = new PropertyModel(this, "locale"); detailsLink = newDetailsLink("detailsLink", skosConcept); prefLabel = new Label("prefLabel", new SkosConceptPrefLabelModel(skosConcept, localeModel)); altLabelsListView = new ListView("altLabels", new LoadableDetachableModel() { @Override protected Object load() { SkosConcept skosConcept = skosConceptModel.getObject(); return new ArrayList<String>(skosConcept.getAltLabels(getLocale())); } }) { @Override protected void populateItem(ListItem item) { String altLabel = (String) item.getModelObject(); item.add(new Label("altLabel", altLabel)); } @SuppressWarnings("unchecked") @Override public boolean isVisible() { List<String> items = (List<String>) getModelObject(); return !items.isEmpty(); } }; skosNotesLabel = new Label("skosNotes", skosConcept.getSkosNotes()); broaderListView = new ListView("broader", new LoadableDetachableModel() { @Override protected Object load() { SkosConcept skosConcept = skosConceptModel.getObject(); return new ArrayList<SkosConcept>(skosConcept.getBroader()); } }) { @Override protected void populateItem(ListItem item) { SkosConcept broader = (SkosConcept) item.getModelObject(); AbstractLink detailsLink = newDetailsLink("detailsLink", broader); item.add(detailsLink); detailsLink.add(new Label("prefLabel", new SkosConceptPrefLabelModel(broader, localeModel))); } @SuppressWarnings("unchecked") @Override public boolean isVisible() { List<SkosConcept> items = (List<SkosConcept>) getModelObject(); return !items.isEmpty(); } }; narrowerListView = new ListView("narrower", new LoadableDetachableModel() { @Override protected Object load() { SkosConcept skosConcept = skosConceptModel.getObject(); return new ArrayList<SkosConcept>(skosConcept.getNarrower()); } }) { @Override protected void populateItem(ListItem item) { SkosConcept narrower = (SkosConcept) item.getModelObject(); AbstractLink detailsLink = newDetailsLink("detailsLink", narrower); item.add(detailsLink); detailsLink.add(new Label("prefLabel", new SkosConceptPrefLabelModel(narrower, localeModel))); } @SuppressWarnings("unchecked") @Override public boolean isVisible() { List<SkosConcept> items = (List<SkosConcept>) getModelObject(); return !items.isEmpty(); } }; relatedListView = new ListView("related", new LoadableDetachableModel() { @Override protected Object load() { SkosConcept skosConcept = skosConceptModel.getObject(); return new ArrayList<SkosConcept>(skosConcept.getRelated()); } }) { @Override protected void populateItem(ListItem item) { SkosConcept related = (SkosConcept) item.getModelObject(); AbstractLink detailsLink = newDetailsLink("detailsLink", related); item.add(detailsLink); detailsLink.add(new Label("prefLabel", new SkosConceptPrefLabelModel(related, localeModel))); } @SuppressWarnings("unchecked") @Override public boolean isVisible() { List<SkosConcept> items = (List<SkosConcept>) getModelObject(); return !items.isEmpty(); } }; add(detailsLink); detailsLink.add(prefLabel); add(altLabelsListView); add(skosNotesLabel); add(broaderListView); add(narrowerListView); add(relatedListView); }
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);//from www.ja va 2s .co m 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.effectivemaven.centrepoint.web.ListProjectsPage.java
License:Apache License
/** * Constructor// w ww.j a va 2 s . c o m */ @SuppressWarnings("serial") public ListProjectsPage() { super(); setPageTitle("Project List"); // add a feedback panel for errors and messages add(new FeedbackPanel("feedback")); List<Project> projects = new ArrayList<Project>(projectStore.getAllProjects()); ListView<Project> projectListView = new ListView<Project>("projects", projects) { @Override public void populateItem(final ListItem<Project> listItem) { Project project = listItem.getModelObject(); PageParameters pageParameters = new PageParameters(); pageParameters.add("id", project.getId()); Link<ViewProjectPage> link = new BookmarkablePageLink<ViewProjectPage>("link", ViewProjectPage.class, pageParameters); link.add(new Label("name", project.getName())); listItem.add(link); listItem.add(new MultiLineLabel("description", project.getDescription())); } }; add(projectListView); if (projects.isEmpty()) { // add message to the feedback panel info("There are currently no projects."); } addOperationLink(createOperationLink("Add a New Project", AddProjectFromMavenPage.class)); }
From source file:com.effectivemaven.centrepoint.web.TemplatePage.java
License:Apache License
@SuppressWarnings("serial") private void addComponents(final String id) { add(new Label("build", buildNumber.getBuildMessage())); add(new Label("title", new PropertyModel<String>(this, "pageTitle"))); add(new BookmarkablePageLink<String>("homeLink", ListProjectsPage.class)); operationsListView = createListOfLinks("operations", operationLinks); operationsListView.setVisible(false); add(operationsListView);//from ww w . ja v a2 s . com panelsListView = new ListView<Panel>("panels", panels) { @SuppressWarnings("unchecked") @Override protected void populateItem(ListItem<Panel> listItem) { Panel panel = listItem.getModelObject(); listItem.add(new Label("name", panel.plugin.getTitle(panel.project))); listItem.add(createListOfLinks("items", panel.links)); if (panel.plugin instanceof ConfigurablePanel) { ConfigurablePanel<ExtensionModel> plugin = (ConfigurablePanel<ExtensionModel>) panel.plugin; PageParameters params = new PageParameters(); params.add("id", id); params.add("panel", plugin.getId()); Link<ViewProjectPage> link = new BookmarkablePageLink<ViewProjectPage>("editPanelLink", EditPanelConfigurationPage.class, params); listItem.add(link); } else { WebMarkupContainer container = new WebMarkupContainer("editPanelLink"); container.setVisible(false); listItem.add(container); } } }; panelsListView.setVisible(false); add(panelsListView); }
From source file:com.effectivemaven.centrepoint.web.TemplatePage.java
License:Apache License
@SuppressWarnings("serial") ListView<AbstractLink> createListOfLinks(String path, List<AbstractLink> links) { return new ListView<AbstractLink>(path, links) { @Override// w ww . j a va 2s.co m protected void populateItem(ListItem<AbstractLink> listItem) { AbstractLink link = listItem.getModelObject(); listItem.add(link); } }; }