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.admin.crud.SingleColumnCRUDPanel.java
License:Open Source License
@Override protected List<IColumn> getDataColumns() { List<IColumn> dataColumns = new ArrayList<IColumn>(); IColumn detailsColumn = new HeaderlessColumn() { @Override/*from w w w . j a va2s. c o m*/ public void populateItem(Item cellItem, String componentId, final IModel rowItemModel) { Item rowItem = (Item) cellItem.findParent(Item.class); final int rowIndex = getFirstRowItemAbsoluteIndex() + rowItem.getIndex(); cellItem.add(new ModalLinkHolder(componentId) { @Override public WebMarkupContainer newLink(String id) { AbstractLink link; if (isUseModalsDetails()) { link = new AjaxLink(id) { @Override public void onClick(AjaxRequestTarget target) { ModalWindow detailsModal = getModalWindow(); detailsModal.setInitialHeight(MODAL_HEIGHT); detailsModal.setInitialWidth(MODAL_WIDTH); detailsModal.setTitle(getLabelModel()); onClickDetailsLink(rowItemModel, target, detailsModal, rowIndex); } }; } else { link = new Link(id) { @Override public void onClick() { onClickDetailsLink(rowItemModel, null, null, rowIndex); } }; } link.setEnabled(isDetailsLink(rowItemModel, rowIndex)); return link; } @Override protected Component newLabel(String id, IModel labelModel) { return createDetailsLabelComponent(id, rowItemModel, rowIndex); } }); } @Override public Component getHeader(String componentId) { Component header = createDetailsColumnHeader(componentId); if (header == null) { header = super.getHeader(componentId); } return header; } }; dataColumns.add(detailsColumn); return dataColumns; }
From source file:com.doculibre.constellio.wicket.panels.admin.elevate.ElevateQueryListPanel.java
License:Open Source License
public ElevateQueryListPanel(String id) { super(id);//from w w w . jav a 2s .co m add(new DocIdsPanel("excludedDocIdsPanel", null, false)); IModel elevateQueriesModel = new LoadableDetachableModel() { @Override protected Object load() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); String solrCoreName = collection.getName(); ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); return elevateServices.getQueries(solrCoreName); } }; add(new ListView("queries", elevateQueriesModel) { @Override protected void populateItem(ListItem item) { final String queryText = (String) item.getModelObject(); ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); final SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText); int nbDocs = elevateServices.getElevatedDocIds(querySimpleSearch).size(); item.add(new Label("nbDocs", "" + nbDocs)); final ModalWindow detailsModal = new ModalWindow("detailsModal"); item.add(detailsModal); detailsModal.setInitialHeight(SingleColumnCRUDPanel.MODAL_HEIGHT); detailsModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY); WebMarkupContainer detailsLink = new AjaxLink("detailsLink") { @Override public void onClick(AjaxRequestTarget target) { detailsModal .setContent(new ElevateQueryDocIdsPanel(detailsModal.getContentId(), queryText)); // detailsModal.setTitle(queryText); detailsModal.setWindowClosedCallback(new WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { target.addComponent(ElevateQueryListPanel.this); } }); detailsModal.show(target); } }; item.add(detailsLink); detailsLink.add(new SimpleSearchQueryPanel("queryText", querySimpleSearch)); WebMarkupContainer deleteLink = new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); elevateServices.deleteQuery(querySimpleSearch); target.addComponent(ElevateQueryListPanel.this); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { String confirmMsg = getLocalizer().getString("confirmDelete", ElevateQueryListPanel.this); return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }"; } }; } }; item.add(deleteLink); } }); }
From source file:com.doculibre.constellio.wicket.panels.admin.elevate.modal.DocIdsPanel.java
License:Open Source License
public DocIdsPanel(String id, final String queryText, final boolean elevatedDocs) { super(id);/* ww w.ja v a 2s.c o m*/ docIdsModel = new LoadableDetachableModel() { @Override protected Object load() { List<String> docIds = new ArrayList<String>(); AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); if (elevatedDocs) { SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText); docIds = elevateServices.getElevatedDocIds(querySimpleSearch); } else { docIds = elevateServices.getExcludedDocIds(collection); } return docIds; } }; add(new ListView("docIds", docIdsModel) { @Override protected void populateItem(ListItem item) { final String docId = (String) item.getModelObject(); AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); RecordServices recordServices = ConstellioSpringUtils.getRecordServices(); Record record = recordServices.get(docId, collection); if (record == null) { FederationServices federationServices = ConstellioSpringUtils.getFederationServices(); if (collection.isFederationOwner()) { List<RecordCollection> includedCollections = federationServices .listIncludedCollections(collection); for (RecordCollection includedCollection : includedCollections) { record = recordServices.get(docId, includedCollection); if (record != null) { break; } } } if (record == null && collection.isIncludedInFederation()) { List<RecordCollection> ownerCollections = federationServices .listOwnerCollections(collection); for (RecordCollection ownerCollection : ownerCollections) { record = recordServices.get(docId, ownerCollection); if (record != null) { break; } } } } if (record != null) { final RecordModel recordModel = new RecordModel(record); String displayURL = record.getDisplayUrl(); item.add(new Label("docId", displayURL)); WebMarkupContainer deleteLink = new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); Record record = recordModel.getObject(); ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); SolrServer solrServer = SolrCoreContext.getSolrServer(collection); try { ConstellioPersistenceUtils.beginTransaction(); if (elevatedDocs) { SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText); elevateServices.cancelElevation(record, querySimpleSearch); } else { elevateServices.cancelExclusion(record, collection); } try { solrServer.commit(); } catch (Throwable t) { try { solrServer.rollback(); } catch (Exception e) { throw new RuntimeException(t); } } } finally { ConstellioPersistenceUtils.finishTransaction(false); } Component parent; if (elevatedDocs) { SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText); boolean empty = elevateServices.getElevatedDocIds(querySimpleSearch).isEmpty(); if (empty) { ModalWindow.closeCurrent(target); parent = null; } else { parent = WicketResourceUtils.findOutputMarkupIdParent(DocIdsPanel.this); } } else { parent = WicketResourceUtils.findOutputMarkupIdParent(DocIdsPanel.this); } if (parent != null) { target.addComponent(parent); } } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { String confirmMsg = getLocalizer().getString("confirmDelete", DocIdsPanel.this); return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }"; } }; } @Override public void detachModels() { recordModel.detach(); super.detachModels(); } }; item.add(deleteLink); } else { item.setVisible(false); } } }); }
From source file:com.doculibre.constellio.wicket.panels.admin.facets.FacetListPanel.java
License:Open Source License
@Override protected List<IColumn> getDataColumns() { List<IColumn> dataColumns = super.getDataColumns(); dataColumns.add(new HeaderlessColumn() { @Override/* ww w . j av a 2s.c o m*/ public void populateItem(Item cellItem, String componentId, final IModel rowModel) { cellItem.add(new ModalLinkHolder(componentId, new StringResourceModel("labelledValues", FacetListPanel.this, null)) { @Override protected WebMarkupContainer newLink(String id) { return new AjaxLink(id) { @Override public void onClick(AjaxRequestTarget target) { ModalWindow labelledValuesModal = getModalWindow(); CollectionFacet facet = (CollectionFacet) rowModel.getObject(); EditFacetLabelledValuesPanel editLabelledValuesModal = new EditFacetLabelledValuesPanel( labelledValuesModal.getContentId(), facet); labelledValuesModal.setContent(editLabelledValuesModal); labelledValuesModal.show(target); } @Override public boolean isVisible() { CollectionFacet facet = (CollectionFacet) rowModel.getObject(); return facet.isFieldFacet(); } }; } }); } }); dataColumns.add(new HeaderlessColumn() { @Override public void populateItem(Item cellItem, String componentId, final IModel rowModel) { cellItem.add(new ModalLinkHolder(componentId, new StringResourceModel("queries", FacetListPanel.this, null)) { @Override protected WebMarkupContainer newLink(String id) { return new AjaxLink(id) { @Override public void onClick(AjaxRequestTarget target) { ModalWindow queriesModal = getModalWindow(); CollectionFacet facet = (CollectionFacet) rowModel.getObject(); EditFacetLabelledValuesPanel editQueriesPanel = new EditFacetLabelledValuesPanel( queriesModal.getContentId(), facet); queriesModal.setContent(editQueriesPanel); queriesModal.show(target); } @Override public boolean isVisible() { CollectionFacet facet = (CollectionFacet) rowModel.getObject(); return facet.isQueryFacet(); } }; } }); } }); // Move up dataColumns.add(new HeaderlessColumn() { @Override public void populateItem(Item cellItem, String componentId, final IModel rowModel) { cellItem.add(new ImgLinkHolder(componentId) { @Override protected WebMarkupContainer newLink(String id) { return new AjaxLink(id) { @Override public void onClick(AjaxRequestTarget target) { FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); CollectionFacet facet = (CollectionFacet) rowModel.getObject(); RecordCollection collection = facet.getRecordCollection(); List<CollectionFacet> collectionFacets = collection.getCollectionFacets(); int index = collectionFacets.indexOf(facet); // Cannot move higher! if (index > 0) { CollectionFacet previousFacet = collectionFacets.set(index - 1, facet); collectionFacets.set(index, previousFacet); EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } facetServices.makePersistent(facet); facetServices.makePersistent(previousFacet); entityManager.getTransaction().commit(); entityManager.clear(); target.addComponent(findParent(AdminCollectionPanel.class)); } } }; } @Override protected Component newImg(String id) { return new NonCachingImage(id, new ResourceReference(BaseConstellioPage.class, "images/up.png")); } }); } }); // Move down dataColumns.add(new HeaderlessColumn() { @Override public void populateItem(Item cellItem, String componentId, final IModel rowModel) { cellItem.add(new ImgLinkHolder(componentId) { @Override protected WebMarkupContainer newLink(String id) { return new AjaxLink(id) { @Override public void onClick(AjaxRequestTarget target) { FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); CollectionFacet facet = (CollectionFacet) rowModel.getObject(); RecordCollection collection = facet.getRecordCollection(); List<CollectionFacet> collectionFacets = collection.getCollectionFacets(); int index = collectionFacets.indexOf(facet); // Cannot move lower! if (index < collectionFacets.size() - 1) { CollectionFacet previousFacet = collectionFacets.set(index + 1, facet); collectionFacets.set(index, previousFacet); EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } facetServices.makePersistent(facet); facetServices.makePersistent(previousFacet); entityManager.getTransaction().commit(); entityManager.clear(); target.addComponent(findParent(AdminCollectionPanel.class)); } } }; } @Override protected Component newImg(String id) { return new NonCachingImage(id, new ResourceReference(BaseConstellioPage.class, "images/down.png")); } }); } }); return dataColumns; }
From source file:com.doculibre.constellio.wicket.panels.admin.facets.values.EditFacetLabelledValuesPanel.java
License:Open Source License
public EditFacetLabelledValuesPanel(String id, CollectionFacet facet) { super(id);//from w ww . jav a2 s .c om this.facetModel = new ReloadableEntityModel<CollectionFacet>(facet); String titleKey = facet.isQueryFacet() ? "queries" : "labelledValues"; IModel titleModel = new StringResourceModel(titleKey, this, null); add(new Label("panelTitle", titleModel)); valuesContainer = new WebMarkupContainer("valuesContainer"); add(valuesContainer); valuesContainer.setOutputMarkupId(true); add(new FilterForm("filterForm")); add(new AddLabelForm("addForm")); final IModel localesModel = new LoadableDetachableModel() { @Override protected Object load() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); return new ArrayList<Locale>(collection.getLocales()); } }; valuesContainer.add(new ListView("locales", localesModel) { @Override protected void populateItem(ListItem item) { Locale locale = (Locale) item.getModelObject(); item.add(new LocaleNameLabel("localeName", locale, true) { @Override public boolean isVisible() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); return collection.getLocales().size() > 1; } }); } }); IModel labelledValuesModel = new LoadableDetachableModel() { @Override protected Object load() { List<String> facetValues; FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); CollectionFacet facet = facetModel.getObject(); if (facet.isFieldFacet()) { facetValues = facetServices.suggestValues(facet, filter); } else { facetValues = new ArrayList<String>(); for (I18NLabel labelledValue : facet.getLabelledValues()) { facetValues.add(labelledValue.getKey()); } } return facetValues; } }; valuesContainer.add(new ListView("items", labelledValuesModel) { @Override protected void populateItem(ListItem item) { final String facetValue = (String) item.getModelObject(); final IModel newFacetValueModel = new Model(facetValue); AjaxEditableLabel editableLabel = new AjaxEditableLabel("value", newFacetValueModel) { @Override protected void onSubmit(AjaxRequestTarget target) { CollectionFacet facet = facetModel.getObject(); String newFacetValue = (String) newFacetValueModel.getObject(); if (newFacetValue == null || !newFacetValue.equals(facetValue)) { FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); for (I18NLabel i18nLabel : facet.getLabelledValues()) { if (i18nLabel.getKey().equals(facetValue)) { if (newFacetValue == null) { EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } facet.getLabels().remove(i18nLabel); facetServices.makePersistent(facet); entityManager.getTransaction().commit(); entityManager.clear(); } else { i18nLabel.setKey(newFacetValue); EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } facetServices.makePersistent(facet); entityManager.getTransaction().commit(); entityManager.clear(); } } } } super.onSubmit(target); } }; item.add(editableLabel); MultiLocaleComponentHolder labelledValuesHolder = new MultiLocaleComponentHolder("labels", facetValue, facetModel, "labelledValue", localesModel) { @Override protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) { AjaxEditableLabel editableLabel = new AjaxEditableLabel("editableLabel", componentModel) { @Override protected void onSubmit(AjaxRequestTarget target) { CollectionFacet facet = facetModel.getObject(); FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } facetServices.makePersistent(facet); entityManager.getTransaction().commit(); entityManager.clear(); super.onSubmit(target); } }; item.add(editableLabel); } }; item.add(labelledValuesHolder); item.add(new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { CollectionFacet facet = facetModel.getObject(); FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } for (Iterator<I18NLabel> it = facet.getLabelledValues().iterator(); it.hasNext();) { I18NLabel labelledValue = it.next(); if (labelledValue.getKey().equals(facetValue)) { it.remove(); } } facetServices.makePersistent(facet); entityManager.getTransaction().commit(); target.addComponent(valuesContainer); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { String confirmMsg = getLocalizer().getString("confirmDelete", EditFacetLabelledValuesPanel.this); return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }"; } }; } }); } }); }
From source file:com.doculibre.constellio.wicket.panels.admin.fieldType.AddEditFieldTypePanel.java
License:Open Source License
public AddEditFieldTypePanel(String id, FieldType fieldType, Component refreshComponentP) { super(id, true); this.fieldTypeModel = new ReloadableEntityModel<FieldType>(fieldType); this.refreshComponent = refreshComponentP; Form form = getForm();//from ww w. j a v a2 s .com form.setModel(new CompoundPropertyModel(fieldTypeModel)); TextField nameField = new RequiredTextField("name"); nameField.add(new StringValidator.MaximumLengthValidator(255)); form.add(nameField); final ModalWindow fieldTypeClassModal = new ModalWindow("fieldTypeClassModal"); form.add(fieldTypeClassModal); fieldTypeClassModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY); IModel fieldTypeClassesModel = new LoadableDetachableModel() { @Override protected Object load() { FieldTypeClassServices fieldTypeClassServices = ConstellioSpringUtils.getFieldTypeClassServices(); return fieldTypeClassServices.list(); } }; IChoiceRenderer fieldTypeClassRenderer = new ChoiceRenderer("className"); final DropDownChoice fieldTypeClassField = new DropDownChoice("fieldTypeClass", fieldTypeClassesModel, fieldTypeClassRenderer); form.add(fieldTypeClassField); fieldTypeClassField.setOutputMarkupId(true); AjaxLink addFieldTypeClassLink = new AjaxLink("addFieldTypeClassLink") { @Override public void onClick(AjaxRequestTarget target) { AddEditFieldTypeClassPanel addEditFieldTypeClassPanel = new AddEditFieldTypeClassPanel( fieldTypeClassModal.getContentId(), new FieldTypeClass(), fieldTypeClassField); fieldTypeClassModal.setContent(addEditFieldTypeClassPanel); fieldTypeClassModal.show(target); } }; form.add(addFieldTypeClassLink); analyzerPanel = new AddEditAnalyzerFieldPanel("analyzerPanel", new LoadableDetachableModel() { @Override protected Object load() { FieldType fieldType = fieldTypeModel.getObject(); return fieldType.getAnalyzer() != null ? fieldType.getAnalyzer() : new Analyzer(); } }); form.add(analyzerPanel); queryAnalyzerPanel = new AddEditAnalyzerFieldPanel("queryAnalyzerPanel", new LoadableDetachableModel() { @Override protected Object load() { FieldType fieldType = fieldTypeModel.getObject(); return fieldType.getQueryAnalyzer() != null ? fieldType.getQueryAnalyzer() : new Analyzer(); } }); form.add(queryAnalyzerPanel); TextField precisionStepField = new TextField("precisionStep", Integer.class); form.add(precisionStepField); TextField positionIncrementGapField = new TextField("positionIncrementGap", Integer.class); form.add(positionIncrementGapField); final CheckBox sortMissingLastCheckbox = new CheckBox("sortMissingLast"); form.add(sortMissingLastCheckbox); final CheckBox omitNormsCheckbox = new CheckBox("omitNorms"); form.add(omitNormsCheckbox); final CheckBox multiValuedCheckbox = new CheckBox("multiValued"); form.add(multiValuedCheckbox); }
From source file:com.doculibre.constellio.wicket.panels.admin.group.participation.ParticipationListPanel.java
License:Open Source License
@Override protected WebMarkupContainer createDeleteLink(String id, final IModel entityModel, final int index) { return new AjaxLink(id) { @Override/*from www .j a va 2 s . c o m*/ public void onClick(AjaxRequestTarget target) { AddEditGroupPanel addEditGroupPanel = (AddEditGroupPanel) findParent(AddEditGroupPanel.class); addEditGroupPanel.getParticipations().remove(index); target.addComponent(ParticipationListPanel.this); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { String confirmMsg = getLocalizer().getString("confirmDelete", ParticipationListPanel.this); return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }"; } }; } }; }
From source file:com.doculibre.constellio.wicket.panels.admin.indexField.AddEditIndexFieldPanel.java
License:Open Source License
public AddEditIndexFieldPanel(String id, IndexField indexField) { super(id);/*from www. jav a 2 s . c o m*/ this.indexFieldModel = new ReloadableEntityModel<IndexField>(indexField); for (CopyField copyFieldDest : indexField.getCopyFieldsDest()) { copyFieldsDest.add(new CopyFieldDTO(copyFieldDest)); } for (CopyField copyFieldSource : indexField.getCopyFieldsDest()) { copyFieldsSource.add(new CopyFieldDTO(copyFieldSource)); } for (ConnectorInstanceMeta meta : indexField.getConnectorInstanceMetas()) { metas.add(new ConnectorInstanceMetaDTO(meta)); } add(new FeedbackPanel("feedback")); Form form = new Form("form", new CompoundPropertyModel(indexFieldModel)); add(form); form.add(new SetFocusBehavior(form)); String titleKey = indexField.getId() == null ? "add" : "edit"; IModel titleModel = new StringResourceModel(titleKey, this, null); form.add(new Label("title", titleModel)); TextField nameField = new RequiredTextField("name"); nameField.add(new StringValidator.MaximumLengthValidator(255)); nameField.setEnabled(!indexField.isInternalField()); form.add(nameField); final CheckBox indexedCheckbox = new CheckBox("indexed"); indexedCheckbox.setEnabled(!indexField.isInternalField()); form.add(indexedCheckbox); // final CheckBox storedCheckbox = new CheckBox("stored"); // storedCheckbox.setEnabled(!indexField.isInternalField()); // form.add(storedCheckbox); final CheckBox dynamicFieldCheckbox = new CheckBox("dynamicField"); dynamicFieldCheckbox.setEnabled(!indexField.isInternalField()); form.add(dynamicFieldCheckbox); final CheckBox multiValuedCheckbox = new CheckBox("multiValued"); multiValuedCheckbox.setEnabled(!indexField.isInternalField()); form.add(multiValuedCheckbox); final CheckBox sortableCheckbox = new CheckBox("sortable"); form.add(sortableCheckbox); final CheckBox highlightedCheckbox = new CheckBox("highlighted"); form.add(highlightedCheckbox); final ModalWindow fieldTypeModal = new ModalWindow("fieldTypeModal"); form.add(fieldTypeModal); fieldTypeModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY); IModel fieldTypesModel = new LoadableDetachableModel() { @Override protected Object load() { FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices(); return fieldTypeServices.list(); } }; IChoiceRenderer fieldTypeRenderer = new ChoiceRenderer("name"); final DropDownChoice fieldTypeField = new DropDownChoice("fieldType", fieldTypesModel, fieldTypeRenderer); form.add(fieldTypeField); fieldTypeField.setOutputMarkupId(true); fieldTypeField.setEnabled(indexField.isAnalyzingCustomizable()); AjaxLink addFieldTypeLink = new AjaxLink("addFieldTypeLink") { @Override public void onClick(AjaxRequestTarget target) { AddEditFieldTypePanel addEditFieldTypePanel = new AddEditFieldTypePanel( fieldTypeModal.getContentId(), new FieldType(), fieldTypeField); fieldTypeModal.setContent(addEditFieldTypePanel); fieldTypeModal.show(target); } }; form.add(addFieldTypeLink); addFieldTypeLink.setVisible(indexField.isAnalyzingCustomizable()); form.add(new MetaListPanel("metas").setVisible(indexField.isAnalyzingCustomizable())); form.add(new CopyFieldListPanel("copyFieldsDest", true).setVisible(indexField.isAnalyzingCustomizable())); IModel localesModel = new LoadableDetachableModel() { @Override protected Object load() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); return collection.getLocales(); } }; MultiLocaleComponentHolder nameHolder = new MultiLocaleComponentHolder("label", indexFieldModel, localesModel) { @Override protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) { TextField nameField = new TextField("nameLocale", componentModel); item.add(nameField); item.add(new LocaleNameLabel("localeName", locale, true) { @Override public boolean isVisible() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); return collection.getLocales().size() > 1; } }); } }; form.add(nameHolder); Button submitButton = new AjaxButton("submitButton") { @Override public void onSubmit(AjaxRequestTarget target, Form form) { IndexField indexField = indexFieldModel.getObject(); EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } List<ConnectorInstanceMeta> existingMetas = new ArrayList<ConnectorInstanceMeta>( indexField.getConnectorInstanceMetas()); // Remove deleted metas List<ConnectorInstanceMeta> formMetas = new ArrayList<ConnectorInstanceMeta>(); for (ConnectorInstanceMetaDTO metaDTO : getMetas()) { formMetas.add(metaDTO.toConnectorInstanceMeta()); } for (Iterator<ConnectorInstanceMeta> it = existingMetas.iterator(); it.hasNext();) { ConnectorInstanceMeta meta = it.next(); meta = entityManager.merge(meta); if (!hasMeta(meta, formMetas)) { indexField.removeConnectorInstanceMeta(meta); } } // Add new for (ConnectorInstanceMetaDTO metaDTO : getMetas()) { ConnectorInstanceMeta meta = metaDTO.toConnectorInstanceMeta(); if (!hasMeta(meta, existingMetas)) { meta = entityManager.merge(meta); indexField.addConnectorInstanceMeta(meta); } } Set<CopyField> existingCopyFieldsSource = indexField.getCopyFieldsSource(); // Remove deleted copy fields for (Iterator<CopyField> it = existingCopyFieldsSource.iterator(); it.hasNext();) { CopyField copyField = it.next(); if (!getCopyFieldsSource().contains(new CopyFieldDTO(copyField))) { it.remove(); } } // Add new or update set for (CopyFieldDTO copyFieldDTO : getCopyFieldsSource()) { CopyField copyField = copyFieldDTO.toCopyField(); copyField.setIndexFieldSource(indexField); if (copyField.getId() != null) { entityManager.merge(copyField); } else { existingCopyFieldsSource.add(copyField); } } Set<CopyField> existingCopyFieldsDest = indexField.getCopyFieldsDest(); // Remove deleted copy fields for (Iterator<CopyField> it = existingCopyFieldsDest.iterator(); it.hasNext();) { CopyField copyField = it.next(); if (!getCopyFieldsDest().contains(new CopyFieldDTO(copyField))) { it.remove(); } } // Add new or update set for (CopyFieldDTO copyFieldDTO : getCopyFieldsDest()) { CopyField copyField = copyFieldDTO.toCopyField(); copyField.setIndexFieldDest(indexField); if (copyField.getId() != null) { entityManager.merge(copyField); } else { existingCopyFieldsDest.add(copyField); } } AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); indexField.setRecordCollection(collection); IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices(); FederationServices federationServices = ConstellioSpringUtils.getFederationServices(); if (indexField.isSortable()) { if (indexFieldServices.getSortFieldOf(indexField) == null) { indexFieldServices.newSortFieldFor(indexField); } } AutocompleteServices autocompleteServices = ConstellioSpringUtils.getAutocompleteServices(); if (indexField.isAutocompleted()) { autocompleteServices.setAutoCompleteToField(indexField); } else { autocompleteServices.removeAutoCompleteFromField(indexField); } if (collection.isIncludedInFederation()) { List<String> conflicts = new ArrayList<String>(); List<IndexField> newFederationFields = new ArrayList<IndexField>(); List<RecordCollection> ownerCollections = federationServices.listOwnerCollections(collection); for (RecordCollection ownerCollection : ownerCollections) { String indexFieldName = indexField.getName(); IndexField ownerIndexField = ownerCollection.getIndexField(indexFieldName); if (ownerIndexField == null) { IndexField copy = federationServices.copy(indexField, ownerCollection); newFederationFields.add(copy); } if (federationServices.isConflict(indexFieldName, ownerCollection, collection)) { Locale displayLocale = ownerCollection.getDisplayLocale(getLocale()); conflicts.add(ownerCollection.getTitle(displayLocale)); } } if (conflicts.isEmpty()) { indexFieldServices.makePersistent(indexField); for (IndexField newFederationField : newFederationFields) { indexFieldServices.makePersistent(newFederationField); } } else { for (String collectionTitle : conflicts) { error(getLocalizer().getString("conflict", this) + " : " + collectionTitle); } } } else { indexFieldServices.makePersistent(indexField); } entityManager.getTransaction().commit(); ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class); modalWindow.close(target); target.addComponent(modalWindow.findParent(AdminIndexFieldsPanel.class)); } }; form.add(submitButton); Button cancelButton = new AjaxButton("cancelButton") { @Override public void onSubmit(AjaxRequestTarget target, Form form) { ModalWindow modalWindow = (ModalWindow) findParent(ModalWindow.class); modalWindow.close(target); } }.setDefaultFormProcessing(false); form.add(cancelButton); }
From source file:com.doculibre.constellio.wicket.panels.admin.indexField.copyField.CopyFieldListPanel.java
License:Open Source License
@Override protected WebMarkupContainer createDeleteLink(String id, final IModel entityModel, final int index) { return new AjaxLink(id) { @SuppressWarnings("unchecked") @Override/* ww w . jav a 2 s . c o m*/ public void onClick(AjaxRequestTarget target) { List<CopyFieldDTO> copyFields = (List<CopyFieldDTO>) CopyFieldListPanel.this.getModelObject(); copyFields.remove(index); target.addComponent(CopyFieldListPanel.this); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { String confirmMsg = getLocalizer().getString("confirmDelete", CopyFieldListPanel.this); return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }"; } }; } }; }
From source file:com.doculibre.constellio.wicket.panels.admin.indexField.IndexFieldListPanel.java
License:Open Source License
@Override protected List<IColumn> getDataColumns() { List<IColumn> dataColumns = new ArrayList<IColumn>(); AjaxOnUpdateHandler updateIndexFieldHandler = new AjaxOnUpdateHandler() { @Override//ww w. j a va 2 s . co m public void onUpdate(ReloadableEntityModel<IndexField> entityModel, AjaxRequestTarget target) { updateIndexField(entityModel.getObject(), target); } }; dataColumns.add(getAjaxEditableLabelColumn("name")); dataColumns.add(getAjaxCheckboxColumn("indexed", updateIndexFieldHandler)); dataColumns.add(getAjaxCheckboxColumn("multiValued", updateIndexFieldHandler)); dataColumns.add(new HeaderlessColumn() { @Override public void populateItem(Item cellItem, String componentId, final IModel rowModel) { cellItem.add(new ModalLinkHolder(componentId, new StringResourceModel("labelledValues", IndexFieldListPanel.this, null)) { @Override protected WebMarkupContainer newLink(String id) { return new AjaxLink(id) { @Override public void onClick(AjaxRequestTarget target) { ModalWindow labelledValuesModal = getModalWindow(); IndexField indexField = (IndexField) rowModel.getObject(); EditIndexFieldLabelledValuesPanel editLabelledValuesModal = new EditIndexFieldLabelledValuesPanel( labelledValuesModal.getContentId(), indexField); labelledValuesModal.setContent(editLabelledValuesModal); labelledValuesModal.show(target); } }; } }); } }); return dataColumns; }