r147 - in trunk: cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils cantharella.service/src/main/java/nc/ird/cantharella/service/model cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule cantharella.web/src/main/java/nc/ird/cantharella/web/utils/columns
Author: echatellier Date: 2013-02-21 15:02:23 +0100 (Thu, 21 Feb 2013) New Revision: 147 Url: http://forge.codelutin.com/projects/cantharella/repository/revisions/147 Log: Add tooltip support for document column on document attachable Added: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentTooltipColumn$DocumentTooltipPanel.html trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentTooltipColumn.java Modified: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils/DocumentAttachable.java trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/model/MoleculeProvenanceBean.java trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/SearchServiceImpl.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentPageHelper.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/columns/LinkableImagePropertyColumn.java Modified: trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils/DocumentAttachable.java =================================================================== --- trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils/DocumentAttachable.java 2013-02-21 12:33:49 UTC (rev 146) +++ trunk/cantharella.data/src/main/java/nc/ird/cantharella/data/model/utils/DocumentAttachable.java 2013-02-21 14:02:23 UTC (rev 147) @@ -22,6 +22,7 @@ */ package nc.ird.cantharella.data.model.utils; +import java.io.Serializable; import java.util.List; import nc.ird.cantharella.data.model.Document; @@ -31,7 +32,7 @@ * * @author Eric Chatellier */ -public interface DocumentAttachable { +public interface DocumentAttachable extends Serializable { /** * Get document attached to entity. Modified: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/model/MoleculeProvenanceBean.java =================================================================== --- trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/model/MoleculeProvenanceBean.java 2013-02-21 12:33:49 UTC (rev 146) +++ trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/model/MoleculeProvenanceBean.java 2013-02-21 14:02:23 UTC (rev 147) @@ -24,14 +24,16 @@ */ import java.io.Serializable; -import java.util.Objects; +import java.util.List; +import nc.ird.cantharella.data.model.Document; import nc.ird.cantharella.data.model.Extrait; import nc.ird.cantharella.data.model.Fraction; import nc.ird.cantharella.data.model.Lot; import nc.ird.cantharella.data.model.Molecule; import nc.ird.cantharella.data.model.MoleculeProvenance; import nc.ird.cantharella.data.model.Produit; +import nc.ird.cantharella.data.model.utils.DocumentAttachable; import nc.ird.cantharella.service.services.MoleculeService; /** @@ -43,7 +45,7 @@ * Last update: $Date$ * by : $Author$ */ -public class MoleculeProvenanceBean implements Serializable { +public class MoleculeProvenanceBean implements DocumentAttachable, Serializable { private static final long serialVersionUID = 1L; /** @@ -92,4 +94,21 @@ return result; } + /** {@inheritDoc} */ + @Override + public List<Document> getDocuments() { + return molecule.getDocuments(); + } + + /** {@inheritDoc} */ + @Override + public void addDocument(Document document) { + molecule.addDocument(document); + } + + /** {@inheritDoc} */ + @Override + public void removeDocument(Document document) { + molecule.removeDocument(document); + } } Modified: trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/SearchServiceImpl.java =================================================================== --- trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/SearchServiceImpl.java 2013-02-21 12:33:49 UTC (rev 146) +++ trunk/cantharella.service/src/main/java/nc/ird/cantharella/service/services/impl/SearchServiceImpl.java 2013-02-21 14:02:23 UTC (rev 147) @@ -136,7 +136,8 @@ org.hibernate.Query hibSpecimen = getQuery(fullTextSession, Specimen.class, strQuery, utilisateur); org.hibernate.Query hibLot = getQuery(fullTextSession, Lot.class, strQuery, utilisateur); org.hibernate.Query hibExtraction = getQuery(fullTextSession, Extraction.class, strQuery, utilisateur); - org.hibernate.Query hibPurification = getQuery(fullTextSession, Purification.class, strQuery, utilisateur); + org.hibernate.Query hibPurification = getQuery(fullTextSession, Purification.class, strQuery, + utilisateur); org.hibernate.Query hibResultatTestBio = getQuery(fullTextSession, ResultatTestBio.class, strQuery, utilisateur); org.hibernate.Query hibStation = getQuery(fullTextSession, Station.class, strQuery, utilisateur); Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentPageHelper.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentPageHelper.java 2013-02-21 12:33:49 UTC (rev 146) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentPageHelper.java 2013-02-21 14:02:23 UTC (rev 147) @@ -71,8 +71,8 @@ * @param documentAttachable entity to get documents * @param currentPage current page */ - public static void initAttachedDocumentsManageTable(final TemplatePage templatePage, - final Form<Void> formView, final DocumentAttachable documentAttachable, final CallerPage currentPage) { + public static void initAttachedDocumentsManageTable(final TemplatePage templatePage, final Form<Void> formView, + final DocumentAttachable documentAttachable, final CallerPage currentPage) { List<Document> documents = documentAttachable.getDocuments(); @@ -88,22 +88,23 @@ List<IColumn<Document, String>> columns = new ArrayList<IColumn<Document, String>>(); - columns.add(new LinkPropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.titre")), "titre", - "titre") { + columns.add(new LinkPropertyColumn<Document, String>( + new Model<String>(templatePage.getString("Document.titre")), "titre", "titre") { @Override public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { templatePage.setResponsePage(new ReadDocumentPage(model.getObject(), documentAttachable, currentPage)); } }); - columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.typeDocument")), - "typeDocument.nom", "typeDocument.nom")); + columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage + .getString("Document.typeDocument")), "typeDocument.nom", "typeDocument.nom")); - columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.createur")), "createur", - "createur")); + columns.add(new PropertyColumn<Document, String>( + new Model<String>(templatePage.getString("Document.createur")), "createur", "createur")); - columns.add(new LinkableImagePropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.link")), - "images/download.png", templatePage.getString("Document.link"), templatePage.getString("Document.link")) { + columns.add(new LinkableImagePropertyColumn<Document, String>(new Model<String>(templatePage + .getString("Document.link")), "images/download.png", templatePage.getString("Document.link"), + templatePage.getString("Document.link")) { @Override public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { Document document = model.getObject(); @@ -117,8 +118,9 @@ final DataTable<Document, String> attachedDocumentTable = new AjaxFallbackDefaultDataTable<Document, String>( "ListDocumentsPage.AttachedDocuments", columns, attachedDocumentsDataProvider, WebContext.ROWS_PER_PAGE); - columns.add(new AjaxButtonPropertyColumn<Document, String>(new Model<String>(templatePage.getString("Actions")), - new Model<String>(templatePage.getString("Delete")), formView) { + columns.add(new AjaxButtonPropertyColumn<Document, String>( + new Model<String>(templatePage.getString("Actions")), new Model<String>(templatePage + .getString("Delete")), formView) { @Override public void onSubmit(AjaxRequestTarget target, Form<?> form, IModel<Document> model) { Document document = model.getObject(); @@ -157,8 +159,8 @@ * @param documentAttachable entity to get documents * @param currentPage current page */ - public static void initAttachedDocumentsReadTable(final TemplatePage templatePage, final DocumentAttachable documentAttachable, - final CallerPage currentPage) { + public static void initAttachedDocumentsReadTable(final TemplatePage templatePage, + final DocumentAttachable documentAttachable, final CallerPage currentPage) { List<Document> documents = documentAttachable.getDocuments(); @@ -167,22 +169,23 @@ List<IColumn<Document, String>> columns = new ArrayList<IColumn<Document, String>>(); - columns.add(new LinkPropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.titre")), "titre", - "titre") { + columns.add(new LinkPropertyColumn<Document, String>( + new Model<String>(templatePage.getString("Document.titre")), "titre", "titre") { @Override public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { templatePage.setResponsePage(new ReadDocumentPage(model.getObject(), documentAttachable, currentPage)); } }); - columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.typeDocument")), - "typeDocument.nom", "typeDocument.nom")); + columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage + .getString("Document.typeDocument")), "typeDocument.nom", "typeDocument.nom")); - columns.add(new PropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.createur")), "createur", - "createur")); + columns.add(new PropertyColumn<Document, String>( + new Model<String>(templatePage.getString("Document.createur")), "createur", "createur")); - columns.add(new LinkableImagePropertyColumn<Document, String>(new Model<String>(templatePage.getString("Document.link")), - "images/download.png", templatePage.getString("Document.link"), templatePage.getString("Document.link")) { + columns.add(new LinkableImagePropertyColumn<Document, String>(new Model<String>(templatePage + .getString("Document.link")), "images/download.png", templatePage.getString("Document.link"), + templatePage.getString("Document.link")) { @Override public void onClick(Item<ICellPopulator<Document>> item, String componentId, IModel<Document> model) { Added: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentTooltipColumn$DocumentTooltipPanel.html =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentTooltipColumn$DocumentTooltipPanel.html (rev 0) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentTooltipColumn$DocumentTooltipPanel.html 2013-02-21 14:02:23 UTC (rev 147) @@ -0,0 +1,32 @@ +<!-- + #%L + Cantharella :: Web + $Id: SimpleTooltipPanel.html 133 2013-02-19 11:02:25Z echatellier $ + $HeadURL: http://svn.forge.codelutin.com/svn/cantharella/trunk/cantharella.web/src/mai... $ + %% + Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --> +<!DOCTYPE html> +<html xmlns:wicket="http://wicket.apache.org"> +<body> +<wicket:panel> + <a wicket:id="link"> + <img wicket:id="tooltip" alt="i" /> + </a> +</wicket:panel> +</body> +</html> \ No newline at end of file Added: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentTooltipColumn.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentTooltipColumn.java (rev 0) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentTooltipColumn.java 2013-02-21 14:02:23 UTC (rev 147) @@ -0,0 +1,111 @@ +/* + * #%L + * Cantharella :: Web + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 IRD (Institut de Recherche pour le Developpement) and by respective authors (see below) + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package nc.ird.cantharella.web.pages.domain.document; + +import java.util.List; + +import nc.ird.cantharella.data.model.Document; +import nc.ird.cantharella.data.model.utils.DocumentAttachable; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.wicket.AttributeModifier; +import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; +import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; +import org.apache.wicket.markup.html.WebComponent; +import org.apache.wicket.markup.html.image.Image; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.request.resource.ContextRelativeResource; + +/** + * Column displaying an image and model as tooltip. + * @author Eric Chatellier + * @param <T> Generic type + * @param <S> the type of the sort property + */ +public abstract class DocumentTooltipColumn<T extends DocumentAttachable, S> extends AbstractColumn<T, S> { + + /** + * Constructor + * @param displayModel header display model + * @param documentAttachableModel document attachable model + */ + public DocumentTooltipColumn(IModel<String> displayModel) { + super(displayModel); + } + + /** {@inheritDoc} */ + @Override + public void populateItem(Item<ICellPopulator<T>> item, String componentId, IModel<T> model) { + + List<Document> documents = model.getObject().getDocuments(); + StringBuilder builder = new StringBuilder(); + if (CollectionUtils.isNotEmpty(documents)) { + for (Document document : documents) { + builder.append(document.getTitre()); + builder.append("\n"); + } + } + + DocumentTooltipPanel panel = new DocumentTooltipPanel(componentId, model, Model.of(builder.toString())); + panel.setVisibilityAllowed(CollectionUtils.isNotEmpty(documents)); + item.add(panel); + } + + /** + * Called when link is clicked. + * @param model current model + */ + public abstract void onClick(IModel<T> model); + + /** + * Panel which include a linkable image. Used with the LinkableImagePropertyColumn$LinkablePanel.html file + */ + public class DocumentTooltipPanel extends Panel { + + /** + * Constructor + * @param id Component id + * @param model model + * @param messageModel Message Model displayed over the image + */ + public DocumentTooltipPanel(String id, final IModel<T> model, IModel<?> messageModel) { + super(id); + + Link<T> link = new Link<T>("link") { + @Override + public void onClick() { + DocumentTooltipColumn.this.onClick(model); + } + }; + add(link); + + WebComponent img = new Image("tooltip", new ContextRelativeResource("images/attachment.png")); + img.add(new AttributeModifier("title", messageModel)); + link.add(img); + } + } +} \ No newline at end of file Property changes on: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/DocumentTooltipColumn.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java 2013-02-21 12:33:49 UTC (rev 146) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/document/ManageDocumentPage.java 2013-02-21 14:02:23 UTC (rev 147) @@ -159,7 +159,7 @@ final CallerPage currentPage = new CallerPage(this); // get configuration - long documentMaxUploadSize = ((WebApplicationImpl)getApplication()).getDocumentMaxUploadSize(); + long documentMaxUploadSize = ((WebApplicationImpl) getApplication()).getDocumentMaxUploadSize(); // Initialisation du modèle try { @@ -267,7 +267,7 @@ // Fichier formView.add(new SimpleTooltipPanel("Document.file.info", new Model<String>(getString("Document.file.info", - Model.of(new Object[]{documentMaxUploadSize}))))); + Model.of(new Object[] { documentMaxUploadSize }))))); formView.add(fileUploadField); // Action : création du document Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java 2013-02-21 12:33:49 UTC (rev 146) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/pages/domain/molecule/ListMoleculesPage.java 2013-02-21 14:02:23 UTC (rev 147) @@ -31,6 +31,7 @@ import nc.ird.cantharella.service.services.MoleculeService; import nc.ird.cantharella.web.config.WebContext; import nc.ird.cantharella.web.pages.TemplatePage; +import nc.ird.cantharella.web.pages.domain.document.DocumentTooltipColumn; import nc.ird.cantharella.web.pages.domain.lot.ReadLotPage; import nc.ird.cantharella.web.utils.CallerPage; import nc.ird.cantharella.web.utils.behaviors.MoleculeViewBehavior; @@ -44,7 +45,6 @@ import nc.ird.cantharella.web.utils.security.AuthRole; import nc.ird.cantharella.web.utils.security.AuthRoles; -import org.apache.commons.collections.CollectionUtils; import org.apache.wicket.MarkupContainer; import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; @@ -162,18 +162,12 @@ .getString("Molecule.masseMolaire")), "molecule.masseMolaire", "molecule.masseMolaire", DecimalDisplFormat.SMALL, templatePage.getLocale())); - columns.add(new LinkableImagePropertyColumn<MoleculeProvenanceBean, String>("images/attachment.png", - templatePage.getString("Read"), templatePage.getString("Read")) { + columns.add(new DocumentTooltipColumn<MoleculeProvenanceBean, String>(Model.of("")) { @Override - public void onClick(Item<ICellPopulator<MoleculeProvenanceBean>> item, String componentId, - IModel<MoleculeProvenanceBean> model) { - templatePage.setResponsePage(new ReadMoleculePage(model.getObject().getIdMolecule(), callerPage)); + public void onClick(IModel<MoleculeProvenanceBean> model) { + int idMolecule = model.getObject().getIdMolecule(); + templatePage.setResponsePage(new ReadMoleculePage(idMolecule, callerPage)); } - - @Override - protected boolean isVisibleAllowed(IModel<MoleculeProvenanceBean> model) { - return CollectionUtils.isNotEmpty(model.getObject().getMolecule().getDocuments()); - } }); columns.add(new BooleanPropertyColumn<MoleculeProvenanceBean, String>(new Model<String>(templatePage Modified: trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/columns/LinkableImagePropertyColumn.java =================================================================== --- trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/columns/LinkableImagePropertyColumn.java 2013-02-21 12:33:49 UTC (rev 146) +++ trunk/cantharella.web/src/main/java/nc/ird/cantharella/web/utils/columns/LinkableImagePropertyColumn.java 2013-02-21 14:02:23 UTC (rev 147) @@ -77,20 +77,10 @@ @Override public void populateItem(Item<ICellPopulator<T>> item, String componentId, IModel<T> model) { LinkableImagePanel panel = new LinkableImagePanel(item, componentId, model); - panel.setVisibilityAllowed(isVisibleAllowed(model)); item.add(panel); } /** - * Overridable method to mask panel. - * @param model model - * @return true if panel is visible - */ - protected boolean isVisibleAllowed(IModel<T> model) { - return true; - } - - /** * Override this method to react to link clicks. Your own/internal row id will most likely be inside the model. * @param item Item * @param componentId Component id
participants (1)
-
echatellier@users.forge.codelutin.com