[Suiviobsmer-commits] r1055 - in trunk: wao-business/src/main/java/fr/ifremer/wao wao-business/src/main/java/fr/ifremer/wao/entity wao-business/src/main/java/fr/ifremer/wao/service wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/java/fr/ifremer/wao/ui/services wao-ui/src/main/resources/i18n wao-ui/src/main/webapp
Author: bleny Date: 2011-03-08 16:18:29 +0000 (Tue, 08 Mar 2011) New Revision: 1055 Log: better sampling plan layout in UI Added: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/TerrestrialDivisionImpl.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/SampleRowModelFactory.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ObsDebSamplingPlan.java trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties trunk/wao-ui/src/main/webapp/ObsDebSamplingPlan.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java 2011-03-07 17:15:10 UTC (rev 1054) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java 2011-03-08 16:18:29 UTC (rev 1055) @@ -24,8 +24,6 @@ package fr.ifremer.wao; -import fr.ifremer.wao.entity.TerrestrialDivision; -import fr.ifremer.wao.entity.TerrestrialDivisionDAO; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.mail.EmailException; import org.nuiton.topia.TopiaContext; Added: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/TerrestrialDivisionImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/TerrestrialDivisionImpl.java (rev 0) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/TerrestrialDivisionImpl.java 2011-03-08 16:18:29 UTC (rev 1055) @@ -0,0 +1,12 @@ +package fr.ifremer.wao.entity; + +public class TerrestrialDivisionImpl extends TerrestrialDivisionAbstract { + + @Override + public String toString() { + String toString = getObservationUnitCode() + " - " + getObservationUnitName(); + toString += "||" + getPort().getPortName(); + return toString; + } + +} Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2011-03-07 17:15:10 UTC (rev 1054) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2011-03-08 16:18:29 UTC (rev 1055) @@ -1043,24 +1043,24 @@ SamplingPlanImportModel samplingPlanImportModel = new SamplingPlanImportModel(terrestrialDivisions); try { - // SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); Import<SampleRow> samplingPlanImport = new Import<SampleRow>(samplingPlanImportModel, input); Iterator<SampleRow> it = samplingPlanImport.startImport(); while (it.hasNext()) { - SampleRow sampleRow = it.next(); - sampleRow.clearSampleMonth(); + SampleRow sampleRow = null; + try { + sampleRow = it.next(); + sampleRow.clearSampleMonth(); - SampleRowLog sampleRowLog = executeGetNewSampleRowLog(sampleRow, connectedUser); - - try { - // WaoUtils.createOrUpdate(SampleRow.class, sampleRow, dao, SampleRow.PROPERTY_OBS_PROGRAM_ORDINAL, SampleRow.PROPERTY_CODE); + SampleRowLog sampleRowLog = executeGetNewSampleRowLog(sampleRow, connectedUser); executeCreateUpdateSampleRow(transaction, sampleRow, new ArrayList<Boat>(), sampleRowLog); } catch (Exception e) { errorArgs.add(-1); - errorArgs.add(sampleRow.getCode()); + errorArgs.add(sampleRow == null ? "" : sampleRow.getCode()); //errorArgs.add(e.getMessage()); + transaction.rollbackTransaction(); throw new ImportRefusedException(e.getMessage(), -1, "field", e); } + } transaction.commitTransaction(); } finally { Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ObsDebSamplingPlan.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ObsDebSamplingPlan.java 2011-03-07 17:15:10 UTC (rev 1054) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ObsDebSamplingPlan.java 2011-03-08 16:18:29 UTC (rev 1055) @@ -1,14 +1,17 @@ package fr.ifremer.wao.ui.pages; +import fr.ifremer.wao.bean.ConnectedUser; import fr.ifremer.wao.bean.ObsProgram; import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.bean.SamplingFilterImpl; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.service.ServiceSampling; import fr.ifremer.wao.ui.data.SampleRowDataSource; +import fr.ifremer.wao.ui.services.SampleRowModelFactory; import org.apache.tapestry5.ComponentResources; import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.beaneditor.BeanModel; import org.apache.tapestry5.grid.GridDataSource; import org.apache.tapestry5.ioc.annotations.Inject; @@ -27,7 +30,12 @@ @Inject private ServiceSampling serviceSampling; + /********* Session ************/ + @SessionState + @Property + private ConnectedUser connectedUser; + /********* FILTERS ********/ public SamplingFilter getSamplingFilter() { @@ -54,9 +62,8 @@ public BeanModel<SampleRow> getObsdebSamplingPlanModel() { if (obsdebSamplingPlanModel == null) { - obsdebSamplingPlanModel = beanModelSource.createDisplayModel(SampleRow.class, resources.getMessages()); - obsdebSamplingPlanModel.include(SampleRow.PROPERTY_CODE, SampleRow.PROPERTY_DAY, SampleRow.PROPERTY_COMMENT); - obsdebSamplingPlanModel.add(SampleRow.PROPERTY_OBSERVATION_UNIT); + SampleRowModelFactory sampleRowModelFactory = new SampleRowModelFactory(beanModelSource, resources, connectedUser); + obsdebSamplingPlanModel = sampleRowModelFactory.newModel(); } return obsdebSamplingPlanModel; } Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/SampleRowModelFactory.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/SampleRowModelFactory.java (rev 0) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/SampleRowModelFactory.java 2011-03-08 16:18:29 UTC (rev 1055) @@ -0,0 +1,105 @@ +package fr.ifremer.wao.ui.services; + +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.bean.ConnectedUser; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.SampleRow; +import org.apache.tapestry5.ComponentResources; +import org.apache.tapestry5.PropertyConduit; +import org.apache.tapestry5.beaneditor.BeanModel; +import org.apache.tapestry5.services.BeanModelSource; + +import java.lang.annotation.Annotation; + +/** + * Used to generate a bean model for the grid used in sampling plan showed + * on page {@link fr.ifremer.wao.ui.pages.ObsDebSamplingPlan}. + * + * This factory will generate a model showing the columns that the user + * has the right to see. + * + * @author bleny + */ +public class SampleRowModelFactory { + + protected BeanModelSource beanModelSource; + + protected ComponentResources resources; + + protected ConnectedUser connectedUser; + + protected BeanModel<SampleRow> model; + + public SampleRowModelFactory(BeanModelSource beanModelSource, ComponentResources resources, ConnectedUser connectedUser) { + this.beanModelSource = beanModelSource; + this.resources = resources; + this.connectedUser = connectedUser; + } + + /** add a property in the model and make it not sortable + * @param property the name of the property to add + * @param conduit a PropertyConduit to get the String representation of the + * value of the property, may be null if toString can be used */ + protected void add(String property, PropertyConduit conduit) { + model.add(property, conduit); + model.get(property).sortable(false); + } + + protected void add(String property) { + model.add(property); + model.get(property).sortable(false); + } + + protected void initModel() { + add(SampleRow.PROPERTY_CODE); + add(SampleRow.PROPERTY_DAY, new SampleRowReaderPropertyConduit() { + + @Override + public String getValue(SampleRow sampleRow) { + return WaoUtils.formatDate(sampleRow.getDay()); + } + }); + add(SampleRow.PROPERTY_OBSERVATION_UNIT); + add(SampleRow.PROPERTY_COMMENT); + add("actions", null); + } + + + /** put in common some implementation of PropertyConduit interface. */ + protected static abstract class SampleRowReaderPropertyConduit implements PropertyConduit { + + public abstract String getValue(SampleRow sampleRow); + + @Override + public String get(Object instance) { + // cast and delegate + SampleRow sampleRow = (SampleRow) instance; + return getValue(sampleRow); + } + + /** all value returned are string */ + @Override + public Class getPropertyType() { + return String.class; + } + + /** should never be called */ + @Override + public void set(Object instance, Object value) { + throw new UnsupportedOperationException(); + } + + /** should never be called */ + @Override + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { + throw new UnsupportedOperationException(); + } + } + + public BeanModel<SampleRow> newModel() { + model = beanModelSource.createDisplayModel(SampleRow.class, resources.getMessages()); + model.include(); // empty the model to include only what we want + initModel(); + return model; + } +} Modified: trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties =================================================================== --- trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties 2011-03-07 17:15:10 UTC (rev 1054) +++ trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties 2011-03-08 16:18:29 UTC (rev 1055) @@ -102,11 +102,14 @@ wao.ui.field.FishingZone.facadeName=Facade wao.ui.field.FishingZone.sectorName=Sector wao.ui.field.SampleRow.code=Line code +wao.ui.field.SampleRow.comment=Comment wao.ui.field.SampleRow.dCF5Code= +wao.ui.field.SampleRow.day=Day wao.ui.field.SampleRow.dcf5Code=DCF5 code wao.ui.field.SampleRow.fishingZones=Fishing zone(s) wao.ui.field.SampleRow.libelle=Labels wao.ui.field.SampleRow.meshSize=Mesh size +wao.ui.field.SampleRow.observationUnit=Observation unit wao.ui.field.SampleRow.other=Other wao.ui.field.SampleRow.periodBegin=Begin wao.ui.field.SampleRow.periodEnd=End Modified: trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties =================================================================== --- trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties 2011-03-07 17:15:10 UTC (rev 1054) +++ trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties 2011-03-08 16:18:29 UTC (rev 1055) @@ -102,11 +102,14 @@ wao.ui.field.FishingZone.facadeName=Fa\u00E7ade wao.ui.field.FishingZone.sectorName=Zone wao.ui.field.SampleRow.code=Code ligne +wao.ui.field.SampleRow.comment=Commentaire wao.ui.field.SampleRow.dCF5Code=Codes +wao.ui.field.SampleRow.day=Jour wao.ui.field.SampleRow.dcf5Code=Code DCF Niv. 5 wao.ui.field.SampleRow.fishingZones=Zone(s) de p\u00EAche wao.ui.field.SampleRow.libelle=Libell\u00E9 wao.ui.field.SampleRow.meshSize=Maillage +wao.ui.field.SampleRow.observationUnit=Unit\u00E9 d'observation wao.ui.field.SampleRow.other=Autre wao.ui.field.SampleRow.periodBegin=D\u00E9but wao.ui.field.SampleRow.periodEnd=Fin Modified: trunk/wao-ui/src/main/webapp/ObsDebSamplingPlan.tml =================================================================== --- trunk/wao-ui/src/main/webapp/ObsDebSamplingPlan.tml 2011-03-07 17:15:10 UTC (rev 1054) +++ trunk/wao-ui/src/main/webapp/ObsDebSamplingPlan.tml 2011-03-08 16:18:29 UTC (rev 1055) @@ -1,8 +1,36 @@ <t:layout t:pageTitle="${message:wao.ui.page.SamplingPlan.title}" t:contentId="wao-obsdebsamplingplan" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> - <div t:type="grid" t:source="sampleRows" t:row="sampleRow" t:model="obsdebSamplingPlanModel" t:rowsPerPage="20"> + <h1>${message:wao.ui.samplingPlan.title}</h1> - </div> + <div t:type="grid" t:source="sampleRows" t:row="sampleRow" t:model="obsdebSamplingPlanModel" t:rowsPerPage="50"> + <!-- code --> + <p:codeHeader> + ${message:wao.ui.field.SampleRow.code} + </p:codeHeader> + <!-- day --> + <p:dayHeader> + ${message:wao.ui.field.SampleRow.day} + </p:dayHeader> + + <!-- observation unit --> + <p:observationUnitHeader> + ${message:wao.ui.field.SampleRow.observationUnit} + </p:observationUnitHeader> + + <!-- comment --> + <p:commentHeader> + ${message:wao.ui.field.SampleRow.comment} + </p:commentHeader> + + <!-- actions --> + <p:actionsHeader> + ${message:wao.ui.samplingPlan.actions} + </p:actionsHeader> + <p:actionsCell> + pas d'actions + </p:actionsCell> + </div> + </t:layout> \ No newline at end of file
participants (1)
-
bleny@users.labs.libre-entreprise.org