List of usage examples for org.apache.wicket.ajax.markup.html AjaxLink AjaxLink
public AjaxLink(final String id)
From source file:com.doculibre.constellio.wicket.panels.results.SearchResultsPanel.java
License:Open Source License
public SearchResultsPanel(String id, final SearchResultsDataProvider dataProvider) { super(id);//from ww w. j a v a 2 s. co m setOutputMarkupId(true); List<TransfertSearchResultsPlugin> plugins = PluginFactory.getPlugins(TransfertSearchResultsPlugin.class); this.transfertLink = new AjaxLink("transfertLink") { @Override public void onClick(AjaxRequestTarget target) { transfertPanel.setVisible(true); transfertLink.setVisible(false); transfertActive = true; target.addComponent(SearchResultsPanel.this); } }; transfertLink.setVisible(!plugins.isEmpty() && ConstellioSession.get().getUser() != null && ConstellioSpringUtils.getIntelliGIDServiceInfo() != null); add(transfertLink); this.transfertPanel = new WebMarkupContainer("transfertPanel"); transfertPanel.setOutputMarkupId(true); transfertPanel.setVisible(false); add(transfertPanel); IModel allNoneModel = new Model() { @Override public Object getObject() { return allNone; } @Override public void setObject(Object object) { allNone = (Boolean) object; if (allNone) { Iterator it = dataProvider.iterator(0, dataProvider.size()); while (it.hasNext()) { SolrDocument document = (SolrDocument) it.next(); dataProvider.getSimpleSearch().getSelectedResults() .add(new Long(document.getFieldValue(IndexField.RECORD_ID_FIELD).toString())); } } else { dataProvider.getSimpleSearch().getSelectedResults().clear(); } } }; allNoneCheckbox = new AjaxCheckBox("allNoneCheckbox", allNoneModel) { @Override protected void onUpdate(AjaxRequestTarget target) { target.addComponent(SearchResultsPanel.this); } }; allNoneCheckbox.setOutputMarkupId(true); transfertPanel.add(allNoneCheckbox); errorMessageLabel = new Label("errorMessageLabel", new PropertyModel(this, "errorMessage")); errorMessageLabel.setOutputMarkupId(true); transfertPanel.add(errorMessageLabel); transfertPanel.add(new ListView("transfertButtons", plugins) { @Override protected void populateItem(ListItem item) { final TransfertSearchResultsPlugin plugin = ((TransfertSearchResultsPlugin) item.getModelObject()); AjaxLink link = new AjaxLink("launchTransfertLink") { @Override public void onClick(AjaxRequestTarget target) { errorMessage = null; List<Record> records = new ArrayList<Record>(); SimpleSearch search = dataProvider.getSimpleSearch(); RecordCollection collection = ConstellioSpringUtils.getRecordCollectionServices() .get(search.getCollectionName()); for (Long recordId : search.getSelectedResults()) { records.add(ConstellioSpringUtils.getRecordServices().get(recordId, collection)); } if (!records.isEmpty()) { doTransfert(plugin, target, records); } } private void doTransfert(final TransfertSearchResultsPlugin plugin, AjaxRequestTarget target, List<Record> records) { List<Record> transferedRecords = new ArrayList<Record>(); List<String> ids = new ArrayList<String>(); for (Record record : records) { try { ids.add(plugin.transfert(record)); transferedRecords.add(record); } catch (Throwable t) { t.printStackTrace(); errorMessage = t.getMessage(); break; } } if (errorMessage != null) { try { for (int i = 0; i < ids.size(); i++) { plugin.cancel(transferedRecords.get(i), ids.get(i)); } } catch (Throwable t) { t.printStackTrace(); } } else { plugin.afterTransfert(transferedRecords, ids); } target.addComponent(errorMessageLabel); } }; item.add(link); link.add(new Label("launchTransfertLabel", plugin.getLabelText())); } }); this.dataView = new DataView(DATA_VIEW_ID, dataProvider, dataProvider.getResultsPerPage()) { @Override protected void populateItem(Item item) { SolrDocument doc = (SolrDocument) item.getModelObject(); final Long id; RecordServices recordServices = ConstellioSpringUtils.getRecordServices(); if (doc.getFieldValue(IndexField.RECORD_ID_FIELD) != null) { Record record = recordServices.get(doc); id = record.getId(); if (record != null) { ConnectorInstance connectorInstance = record.getConnectorInstance(); final ReloadableEntityModel<ConnectorInstance> connectorInstanceModel = new ReloadableEntityModel<ConnectorInstance>( connectorInstance); ConnectorType connectorType = connectorInstance.getConnectorType(); ResourceReference imageResourceReference = new ResourceReference( "connectorType_" + connectorType.getId()) { @Override protected Resource newResource() { ConnectorInstance connectorInstance = (ConnectorInstance) connectorInstanceModel .getObject(); ConnectorType connectorType = connectorInstance.getConnectorType(); Resource imageResource; byte[] iconBytes = connectorType.getIconFileContent(); // Convert resource path to absolute path relative to base package if (iconBytes != null) { imageResource = new ByteArrayResource("image", iconBytes); } else { imageResource = PackageResource.get(ConnectorListPanel.class, "default_icon.gif"); } return imageResource; } }; item.add(new NonCachingImage("icon", imageResourceReference) { @Override public void detachModels() { connectorInstanceModel.detach(); super.detachModels(); } @Override public boolean isVisible() { boolean visible = super.isVisible(); if (visible) { SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils .getSearchInterfaceConfigServices(); SearchInterfaceConfig searchInterfaceConfig = searchInterfaceConfigServices .get(); visible = searchInterfaceConfig.isUseIconsInSearchResults(); } return visible; } }); } else { item.setVisible(false); } } else { item.add(new WebMarkupContainer("icon").setVisible(false)); id = null; } item.add(getSearchResultPanel("searchResultPanel", item, dataProvider)); item.add(new SearchResultTaggingPanel("taggingPanel", doc, dataProvider)); newRecordCheckbox(dataProvider, item, id); } private void newRecordCheckbox(final SearchResultsDataProvider dataProvider, Item item, final Long id) { IModel isChecked = new Model() { @Override public Object getObject() { return id != null && dataProvider.getSimpleSearch().getSelectedResults().contains(id); } @Override public void setObject(Object object) { if (id != null) { Boolean state = (Boolean) object; dataProvider.getSimpleSearch().getSelectedResults().remove(id); if (state) { dataProvider.getSimpleSearch().getSelectedResults().add(id); } else { allNone = false; } } } }; item.add(new AjaxCheckBox("checkedResults", isChecked) { @Override protected void onUpdate(AjaxRequestTarget target) { target.addComponent(allNoneCheckbox); } @Override public boolean isVisible() { return transfertActive; } }); } }; add(dataView); dataView.setOutputMarkupId(true); int page = dataProvider.getSimpleSearch().getPage(); int pageCount = dataView.getPageCount(); dataView.setCurrentPage(page == -1 ? pageCount - 1 : page); ConstellioPagingNavigator pagingNavigator = new ConstellioPagingNavigator("resultsPN", dataView); add(pagingNavigator); add(new WebMarkupContainer("noResultsMessage") { @Override public boolean isVisible() { return dataProvider.size() == 0; } }); }
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 ww .j a v a2 s. com 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 . ja v a 2 s. c om*/ 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);//from w ww.j a v a 2s .c o 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.eltiland.ui.course.components.tree.ELTDefaultAbstractTree.java
License:Apache License
/** * Creates a link of type specified by current linkType. When the links is clicked it calls the * specified callback.//from w ww.j a v a 2 s.c om * * @param parent The parent component * @param id The component id * @param callback The link call back * @return The link component */ protected MarkupContainer newLink(final MarkupContainer parent, final String id, final ILinkCallback callback) { if (getLinkType() == LinkType.REGULAR) { return new Link<Void>(id) { private static final long serialVersionUID = 1L; /** * {@inheritDoc} */ @Override public void onClick() { callback.onClick(null); } }; } else if (getLinkType() == LinkType.AJAX) { return new AjaxLink<Void>(id) { private static final long serialVersionUID = 1L; /** * {@inheritDoc} */ @Override public void onClick(final AjaxRequestTarget target) { callback.onClick(target); } }; } else { return new AjaxFallbackLink<Void>(id) { private static final long serialVersionUID = 1L; /** * {@inheritDoc} */ @Override public void onClick(final AjaxRequestTarget target) { callback.onClick(target); } }; } }
From source file:com.evolveum.midpoint.gui.api.component.password.PasswordPanel.java
License:Apache License
private void initLayout(final IModel<ProtectedStringType> model, final boolean isReadOnly, boolean showRemoveButton) { setOutputMarkupId(true);/* w w w . ja v a 2s .c om*/ passwordInputVisble = model.getObject() == null; // TODO: remove // LOGGER.trace("PASSWORD model: {}", model.getObject()); final WebMarkupContainer inputContainer = new WebMarkupContainer(ID_INPUT_CONTAINER) { @Override public boolean isVisible() { return passwordInputVisble; } }; inputContainer.setOutputMarkupId(true); add(inputContainer); final PasswordTextField password1 = new PasswordTextField(ID_PASSWORD_ONE, new PasswordModel(model)); password1.setRequired(false); password1.setResetPassword(false); password1.setOutputMarkupId(true); password1.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); inputContainer.add(password1); final PasswordTextField password2 = new PasswordTextField(ID_PASSWORD_TWO, new Model<String>()); password2.setRequired(false); password2.setResetPassword(false); password2.setOutputMarkupId(true); password2.add(new EmptyOnBlurAjaxFormUpdatingBehaviour()); inputContainer.add(password2); password1.add(new AjaxFormComponentUpdatingBehavior("change") { @Override protected void onUpdate(AjaxRequestTarget target) { boolean required = !StringUtils.isEmpty(password1.getModel().getObject()); password2.setRequired(required); //fix of MID-2463 // target.add(password2); // target.appendJavaScript("$(\"#"+ password2.getMarkupId() +"\").focus()"); } }); password2.add(new PasswordValidator(password1, password2)); final WebMarkupContainer linkContainer = new WebMarkupContainer(ID_LINK_CONTAINER) { @Override public boolean isVisible() { return !passwordInputVisble; } }; inputContainer.setOutputMarkupId(true); linkContainer.setOutputMarkupId(true); add(linkContainer); final Label passwordSetLabel = new Label(ID_PASSWORD_SET, new ResourceModel("passwordPanel.passwordSet")); linkContainer.add(passwordSetLabel); final Label passwordRemoveLabel = new Label(ID_PASSWORD_REMOVE, new ResourceModel("passwordPanel.passwordRemoveLabel")); passwordRemoveLabel.setVisible(false); linkContainer.add(passwordRemoveLabel); AjaxLink link = new AjaxLink(ID_CHANGE_PASSWORD_LINK) { @Override public void onClick(AjaxRequestTarget target) { onLinkClick(target); } @Override public boolean isVisible() { return !passwordInputVisble; } }; link.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return !isReadOnly; } }); link.setBody(new ResourceModel("passwordPanel.passwordChange")); link.setOutputMarkupId(true); linkContainer.add(link); final WebMarkupContainer removeButtonContainer = new WebMarkupContainer(ID_REMOVE_BUTTON_CONTAINER); AjaxLink removePassword = new AjaxLink(ID_REMOVE_PASSWORD_LINK) { @Override public void onClick(AjaxRequestTarget target) { onRemovePassword(model, target); } }; removePassword.setVisible(showRemoveButton); removePassword.setBody(new ResourceModel("passwordPanel.passwordRemove")); removePassword.setOutputMarkupId(true); removeButtonContainer.add(removePassword); add(removeButtonContainer); }
From source file:com.evolveum.midpoint.gui.api.component.result.OperationResultPanel.java
License:Apache License
private void initHeader(WebMarkupContainer box) { WebMarkupContainer iconType = new WebMarkupContainer(ID_ICON_TYPE); iconType.setOutputMarkupId(true);//from ww w.jav a 2s . c o m iconType.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { StringBuilder sb = new StringBuilder(); OpResult message = getModelObject(); switch (message.getStatus()) { case IN_PROGRESS: case NOT_APPLICABLE: sb.append(" fa-info"); break; case SUCCESS: sb.append(" fa-check"); break; case FATAL_ERROR: sb.append(" fa-ban"); break; case PARTIAL_ERROR: case UNKNOWN: case WARNING: case HANDLED_ERROR: default: sb.append(" fa-warning"); } return sb.toString(); } })); box.add(iconType); Label message = createMessage(); AjaxLink<String> showMore = new AjaxLink<String>(ID_MESSAGE) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { OpResult result = OperationResultPanel.this.getModelObject(); result.setShowMore(!result.isShowMore()); result.setAlreadyShown(false); // hack to be able to expand/collapse OpResult after rendered. target.add(OperationResultPanel.this); } }; showMore.add(message); box.add(showMore); AjaxLink<String> backgroundTask = new AjaxLink<String>(ID_BACKGROUND_TASK) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { final OpResult opResult = OperationResultPanel.this.getModelObject(); String oid = opResult.getBackgroundTaskOid(); if (oid == null || !opResult.isBackgroundTaskVisible()) { return; // just for safety } ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(oid, ObjectTypes.TASK); WebComponentUtil.dispatchToObjectDetailsPage(ref, getPageBase(), false); } }; backgroundTask.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return getModelObject().getBackgroundTaskOid() != null && getModelObject().isBackgroundTaskVisible(); } }); box.add(backgroundTask); AjaxLink<String> showAll = new AjaxLink<String>(ID_SHOW_ALL) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { showHideAll(true, OperationResultPanel.this.getModelObject(), target); } }; showAll.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return !OperationResultPanel.this.getModelObject().isShowMore(); } }); box.add(showAll); AjaxLink<String> hideAll = new AjaxLink<String>(ID_HIDE_ALL) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { showHideAll(false, OperationResultPanel.this.getModel().getObject(), target); } }; hideAll.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return OperationResultPanel.this.getModelObject().isShowMore(); } }); box.add(hideAll); AjaxLink<String> close = new AjaxLink<String>("close") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { close(target); } }; box.add(close); DownloadLink downloadXml = new DownloadLink("downloadXml", new AbstractReadOnlyModel<File>() { private static final long serialVersionUID = 1L; @Override public File getObject() { String home = getPageBase().getMidpointConfiguration().getMidpointHome(); File f = new File(home, "result"); DataOutputStream dos = null; try { dos = new DataOutputStream(new FileOutputStream(f)); dos.writeBytes(OperationResultPanel.this.getModel().getObject().getXml()); } catch (IOException e) { LOGGER.error("Could not download result: {}", e.getMessage(), e); } finally { IOUtils.closeQuietly(dos); } return f; } }); downloadXml.setDeleteAfterDownload(true); box.add(downloadXml); }
From source file:com.evolveum.midpoint.gui.api.component.result.OperationResultPanel.java
License:Apache License
private void initError(WebMarkupContainer operationPanel, final IModel<OpResult> model, Page parentPage) { Label errorLabel = new Label("errorLabel", parentPage.getString("FeedbackAlertMessageDetails.error")); errorLabel.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override//from www .ja v a2s. c om public boolean isVisible() { // return true; return StringUtils.isNotBlank(model.getObject().getExceptionsStackTrace()); } }); errorLabel.setOutputMarkupId(true); operationPanel.add(errorLabel); Label errorMessage = new Label("errorMessage", new PropertyModel<String>(model, "exceptionMessage")); errorMessage.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { // return true; return StringUtils.isNotBlank(model.getObject().getExceptionsStackTrace()); } }); errorMessage.setOutputMarkupId(true); operationPanel.add(errorMessage); final Label errorStackTrace = new Label(ID_ERROR_STACK_TRACE, new PropertyModel<String>(model, "exceptionsStackTrace")); errorStackTrace.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { // return true; return model.getObject().isShowError(); } }); errorStackTrace.setOutputMarkupId(true); operationPanel.add(errorStackTrace); AjaxLink errorStackTraceLink = new AjaxLink("errorStackTraceLink") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { OpResult result = OperationResultPanel.this.getModelObject(); result.setShowError(!model.getObject().isShowError()); result.setAlreadyShown(false); // hack to be able to expand/collapse OpResult after rendered. // model.getObject().setShowError(!model.getObject().isShowError()); target.add(OperationResultPanel.this); } }; errorStackTraceLink.setOutputMarkupId(true); errorStackTraceLink.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return StringUtils.isNotBlank(model.getObject().getExceptionsStackTrace()); } }); operationPanel.add(errorStackTraceLink); }
From source file:com.evolveum.midpoint.gui.api.page.PageBase.java
License:Apache License
private void initTitleLayout() { WebMarkupContainer pageTitleContainer = new WebMarkupContainer(ID_PAGE_TITLE_CONTAINER); pageTitleContainer.add(createUserStatusBehaviour(true)); add(pageTitleContainer);/*from w w w .ja va 2s . c om*/ WebMarkupContainer pageTitle = new WebMarkupContainer(ID_PAGE_TITLE); pageTitleContainer.add(pageTitle); Label pageTitleReal = new Label(ID_PAGE_TITLE_REAL, createPageTitleModel()); pageTitleReal.setRenderBodyOnly(true); pageTitle.add(pageTitleReal); ListView breadcrumbs = new ListView<Breadcrumb>(ID_BREADCRUMB, new AbstractReadOnlyModel<List<Breadcrumb>>() { private static final long serialVersionUID = 1L; @Override public List<Breadcrumb> getObject() { return getSessionStorage().getBreadcrumbs(); } }) { @Override protected void populateItem(ListItem<Breadcrumb> item) { final Breadcrumb dto = item.getModelObject(); AjaxLink bcLink = new AjaxLink(ID_BC_LINK) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { redirectBackToBreadcrumb(dto); } }; item.add(bcLink); bcLink.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isEnabled() { return dto.isUseLink(); } }); WebMarkupContainer bcIcon = new WebMarkupContainer(ID_BC_ICON); bcIcon.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return dto.getIcon() != null && dto.getIcon().getObject() != null; } }); bcIcon.add(AttributeModifier.replace("class", dto.getIcon())); bcLink.add(bcIcon); Label bcName = new Label(ID_BC_NAME, dto.getLabel()); bcLink.add(bcName); item.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return dto.isVisible(); } }); } }; add(breadcrumbs); }
From source file:com.evolveum.midpoint.gui.api.page.PageBase.java
License:Apache License
private void initLayout() { AjaxLink logo = new AjaxLink(ID_LOGO) { private static final long serialVersionUID = 1L; @Override/*from www.j av a 2 s . c om*/ public void onClick(AjaxRequestTarget target) { SessionStorage storage = MidPointAuthWebSession.getSession().getSessionStorage(); storage.clearBreadcrumbs(); Class<? extends Page> page = MidPointApplication.get().getHomePage(); setResponsePage(page); } }; add(logo); Label title = new Label(ID_TITLE, createPageTitleModel()); title.setRenderBodyOnly(true); add(title); initHeaderLayout(); initTitleLayout(); initDebugBarLayout(); List<SideBarMenuItem> menuItems = createMenuItems(); SideBarMenuPanel sidebarMenu = new SideBarMenuPanel(ID_SIDEBAR_MENU, new Model((Serializable) menuItems)); sidebarMenu.add(createUserStatusBehaviour(true)); add(sidebarMenu); WebMarkupContainer version = new WebMarkupContainer(ID_VERSION) { private static final long serialVersionUID = 1L; @Deprecated public String getDescribe() { return PageBase.this.getDescribe(); } }; version.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return RuntimeConfigurationType.DEVELOPMENT.equals(getApplication().getConfigurationType()); } }); add(version); WebMarkupContainer feedbackContainer = new WebMarkupContainer(ID_FEEDBACK_CONTAINER); feedbackContainer.setOutputMarkupId(true); add(feedbackContainer); FeedbackAlerts feedbackList = new FeedbackAlerts(ID_FEEDBACK); feedbackList.setOutputMarkupId(true); feedbackContainer.add(feedbackList); MainPopupDialog mainPopup = new MainPopupDialog(ID_MAIN_POPUP); mainPopup.setOutputMarkupId(true); add(mainPopup); }