This is an automated email from the git hooks/post-receive script. New commit to branch feature/7610 in repository observe. See http://git.codelutin.com/observe.git commit 56915d055a17bdf01f621ae164df6ee7816ab044 Author: Kevin Morin <morin@codelutin.com> Date: Thu Oct 15 17:44:21 2015 +0200 modification des decorateurs pour aller chercher en profondeur les attributs des referencedto qui sont eux même attributs (exemple de LengthWeightParameterDto : ocean est un attribut de type referencedto, il faut qu'on aille chercher le label) (refs #7610) --- .../java/fr/ird/observe/ui/DecoratorService.java | 297 +++++++++++---------- .../ui/content/ref/ContentReferenceUIHandler.java | 20 +- .../decorator/LengthWeightParameterDecorator.java | 14 +- .../ui/util/decorator/NonTargetCatchDecorator.java | 9 +- .../util/decorator/NonTargetLengthDecorator.java | 9 +- .../decorator/ObjectObservedSpeciesDecorator.java | 9 +- .../ui/util/decorator/ObserveDecorator.java | 56 +++- .../ui/util/decorator/ReferenceDecorator.java | 26 +- .../ui/util/decorator/SpeciesDecorator.java | 9 +- .../ui/util/decorator/TripLonglineDecorator.java | 4 +- .../ui/util/decorator/TripSeineDecorator.java | 4 +- 11 files changed, 246 insertions(+), 211 deletions(-) diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/DecoratorService.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/DecoratorService.java index 997181a..6e4d744 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/DecoratorService.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/DecoratorService.java @@ -46,6 +46,7 @@ import fr.ird.observe.services.dto.referential.OceanDto; import fr.ird.observe.services.dto.referential.OrganismDto; import fr.ird.observe.services.dto.referential.PersonDto; import fr.ird.observe.services.dto.referential.ProgramDto; +import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.dto.referential.SexDto; import fr.ird.observe.services.dto.referential.SpeciesDto; import fr.ird.observe.services.dto.referential.SpeciesGroupDto; @@ -96,6 +97,7 @@ import fr.ird.observe.services.dto.referential.seine.WeightCategoryDto; import fr.ird.observe.services.dto.referential.seine.WindDto; import fr.ird.observe.services.dto.seine.ActivitySeineDto; import fr.ird.observe.services.dto.seine.FloatingObjectDto; +import fr.ird.observe.services.dto.seine.GearUseFeaturesMeasurementSeineDto; import fr.ird.observe.services.dto.seine.ObjectSchoolEstimateDto; import fr.ird.observe.services.dto.seine.RouteDto; import fr.ird.observe.services.dto.seine.SchoolEstimateDto; @@ -108,6 +110,7 @@ import fr.ird.observe.ui.util.decorator.LengthWeightParameterDecorator; import fr.ird.observe.ui.util.decorator.NonTargetCatchDecorator; import fr.ird.observe.ui.util.decorator.NonTargetLengthDecorator; import fr.ird.observe.ui.util.decorator.ObjectObservedSpeciesDecorator; +import fr.ird.observe.ui.util.decorator.ObserveDecorator; import fr.ird.observe.ui.util.decorator.ReferenceDecorator; import fr.ird.observe.ui.util.decorator.SpeciesDecorator; import fr.ird.observe.ui.util.decorator.TripLonglineDecorator; @@ -392,6 +395,8 @@ public class DecoratorService extends DecoratorProvider { n("observe.common.branchlineLength"); n("observe.common.tracelineLength"); + n("observe.common.gearUseFeaturesMeasurementSeine"); + } @Override @@ -405,191 +410,211 @@ public class DecoratorService extends DecoratorProvider { Locale locale = referentialLocale.getLocale(); String libelle = referentialLocale.getLibelle(); - registerJXPathDecorator(ProgramDto.class, - t("observe.common.program") + - " ${" + libelle + "}$s"); - registerReferenceDtoDecorator(ProgramDto.class, t("observe.common.program") + " ${label}$s"); - registerJXPathDecorator(RouteDto.class, - "${date}$td/%1$tm/%1$tY"); + registerReferenceDtoDecorator(ProgramDto.class, + t("observe.common.program") + " ${" + libelle + "}$s", + t("observe.common.program") + " ${label}$s"); registerReferenceDtoDecorator(RouteDto.class, "${date}$td/%1$tm/%1$tY"); - registerMultiJXPathDecorator( - ActivitySeineDto.class, - "${time}$tH:%1$tM##${vesselActivitySeine/" + libelle + "}$s", - "##", " - "); - registerReferenceDtoDecorator(ActivitySeineDto.class, "${time}$tH:%1$tM##${vesselActivitySeine}$s"); - registerMultiJXPathDecorator( - ActivityLonglineDto.class, - "${timeStamp}$td/%1$tm/%1$tY %1$tH:%1$tM##${vesselActivityLongline/" + libelle + "}$s", - "##", " - "); + registerReferenceDtoDecorator(ActivitySeineDto.class, + "${time}$tH:%1$tM##${vesselActivitySeine/label}$s", + "${time}$tH:%1$tM##${vesselActivitySeine}$s", + " - "); registerReferenceDtoDecorator(ActivityLonglineDto.class, - "${timeStamp}$td/%1$tm/%1$tY %1$tH:%1$tM##${vesselActivityLongline}$s"); - registerMultiJXPathDecorator(PersonDto.class, "${lastName}$s##${firstName}$s", "##", " "); + "${timeStamp}$td/%1$tm/%1$tY %1$tH:%1$tM##${vesselActivityLongline/label}$s", + "${timeStamp}$td/%1$tm/%1$tY %1$tH:%1$tM##${vesselActivityLongline}$s", + " - "); registerReferenceDtoDecorator(PersonDto.class, "${lastName}$s##${firstName}$s"); - registerDefaultReferenceDtoDecorator(SexDto.class); + registerReferentialReferenceDtoDecorator(SexDto.class, libelle); //FIXME Use startDate - endDate - registerDefaultReferenceDtoDecorator(FpaZoneDto.class); - registerDefaultReferenceDtoDecorator(OceanDto.class); - registerDefaultReferenceDtoDecorator(DetectionModeDto.class); - registerDefaultReferenceDtoDecorator(VesselDto.class); - registerDefaultReferenceDtoDecorator(CountryDto.class); + registerReferentialReferenceDtoDecorator(FpaZoneDto.class, libelle); + registerReferentialReferenceDtoDecorator(OceanDto.class, libelle); + registerReferentialReferenceDtoDecorator(DetectionModeDto.class, libelle); + registerReferentialReferenceDtoDecorator(VesselDto.class, libelle); + registerReferentialReferenceDtoDecorator(CountryDto.class, libelle); registerReferenceDtoDecorator(VesselSizeCategoryDto.class, "${code}$s##${gaugeLabel}$s##${capacityLabel}$s"); - registerDefaultReferenceDtoDecorator(VesselTypeDto.class); - registerDefaultReferenceDtoDecorator(VesselActivitySeineDto.class); - registerDefaultReferenceDtoDecorator(SurroundingActivityDto.class); - registerDefaultReferenceDtoDecorator(ObservedSystemDto.class); + registerReferentialReferenceDtoDecorator(VesselTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(VesselActivitySeineDto.class, libelle); + registerReferentialReferenceDtoDecorator(SurroundingActivityDto.class, libelle); + registerReferentialReferenceDtoDecorator(ObservedSystemDto.class, libelle); registerReferenceDtoDecorator(WindDto.class, "${code}$s##${label}$s##${speedRange}$s"); - registerMultiJXPathDecorator( - FloatingObjectDto.class, - "DCP ${objectType/" + libelle + "}$s", "##", " - "); - registerReferenceDtoDecorator(FloatingObjectDto.class, "DCP ${objectType}$s"); + registerReferenceDtoDecorator(FloatingObjectDto.class, "DCP ${objectType/" + libelle + "}$s", "DCP ${objectType}$s", " - "); //FIXME Remove this - registerJXPathDecorator(SetSeineDto.class, t("observe.common.setSeine")); + registerObserveDecorator(SetSeineDto.class, t("observe.common.setSeine")); //FIXME Remove this - registerJXPathDecorator(SetLonglineDto.class, t("observe.common.setLongline")); - registerDefaultReferenceDtoDecorator(ObjectFateDto.class); - registerDefaultReferenceDtoDecorator(OrganismDto.class); - registerDefaultReferenceDtoDecorator(ObjectTypeDto.class); - registerDefaultReferenceDtoDecorator(ObjectOperationDto.class); - registerDefaultReferenceDtoDecorator(SpeciesStatusDto.class); - registerDefaultReferenceDtoDecorator(TransmittingBuoyTypeDto.class); - registerDefaultReferenceDtoDecorator(TransmittingBuoyOperationDto.class); - registerDefaultReferenceDtoDecorator(ReasonForNullSetDto.class); - registerDefaultReferenceDtoDecorator(ReasonForNoFishingDto.class); - registerDefaultReferenceDtoDecorator(WeightCategoryDto.class); - registerDefaultReferenceDtoDecorator(ReasonForDiscardDto.class); - registerDefaultReferenceDtoDecorator(SpeciesFateDto.class); - registerDefaultReferenceDtoDecorator(SpeciesGroupDto.class); - registerDefaultReferenceDtoDecorator(SpeciesListDto.class); - - registerDefaultReferenceDtoDecorator(BaitHaulingStatusDto.class); - registerDefaultReferenceDtoDecorator(BaitSettingStatusDto.class); - registerDefaultReferenceDtoDecorator(BaitTypeDto.class); - registerDefaultReferenceDtoDecorator(CatchFateLonglineDto.class); - registerDefaultReferenceDtoDecorator(EncounterTypeDto.class); - registerDefaultReferenceDtoDecorator(HealthnessDto.class); - registerDefaultReferenceDtoDecorator(HookPositionDto.class); - registerDefaultReferenceDtoDecorator(HookSizeDto.class); - registerDefaultReferenceDtoDecorator(HookTypeDto.class); - registerDefaultReferenceDtoDecorator(ItemVerticalPositionDto.class); - registerDefaultReferenceDtoDecorator(ItemHorizontalPositionDto.class); - registerDefaultReferenceDtoDecorator(LightsticksColorDto.class); - registerDefaultReferenceDtoDecorator(LightsticksTypeDto.class); - registerDefaultReferenceDtoDecorator(LineTypeDto.class); - registerDefaultReferenceDtoDecorator(MaturityStatusDto.class); - registerDefaultReferenceDtoDecorator(MitigationTypeDto.class); + registerObserveDecorator(SetLonglineDto.class, t("observe.common.setLongline")); + registerReferentialReferenceDtoDecorator(ObjectFateDto.class, libelle); + registerReferentialReferenceDtoDecorator(OrganismDto.class, libelle); + registerReferentialReferenceDtoDecorator(ObjectTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(ObjectOperationDto.class, libelle); + registerReferentialReferenceDtoDecorator(SpeciesStatusDto.class, libelle); + registerReferentialReferenceDtoDecorator(TransmittingBuoyTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(TransmittingBuoyOperationDto.class, libelle); + registerReferentialReferenceDtoDecorator(ReasonForNullSetDto.class, libelle); + registerReferentialReferenceDtoDecorator(ReasonForNoFishingDto.class, libelle); + registerReferentialReferenceDtoDecorator(WeightCategoryDto.class, libelle); + registerReferentialReferenceDtoDecorator(ReasonForDiscardDto.class, libelle); + registerReferentialReferenceDtoDecorator(SpeciesFateDto.class, libelle); + registerReferentialReferenceDtoDecorator(SpeciesGroupDto.class, libelle); + registerReferentialReferenceDtoDecorator(SpeciesListDto.class, libelle); + + registerReferentialReferenceDtoDecorator(BaitHaulingStatusDto.class, libelle); + registerReferentialReferenceDtoDecorator(BaitSettingStatusDto.class, libelle); + registerReferentialReferenceDtoDecorator(BaitTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(CatchFateLonglineDto.class, libelle); + registerReferentialReferenceDtoDecorator(EncounterTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(HealthnessDto.class, libelle); + registerReferentialReferenceDtoDecorator(HookPositionDto.class, libelle); + registerReferentialReferenceDtoDecorator(HookSizeDto.class, libelle); + registerReferentialReferenceDtoDecorator(HookTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(ItemVerticalPositionDto.class, libelle); + registerReferentialReferenceDtoDecorator(ItemHorizontalPositionDto.class, libelle); + registerReferentialReferenceDtoDecorator(LightsticksColorDto.class, libelle); + registerReferentialReferenceDtoDecorator(LightsticksTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(LineTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(MaturityStatusDto.class, libelle); + registerReferentialReferenceDtoDecorator(MitigationTypeDto.class, libelle); registerReferenceDtoDecorator(SensorBrandDto.class, "${code}$s##${brandName}$s"); - registerDefaultReferenceDtoDecorator(SensorDataFormatDto.class); - registerDefaultReferenceDtoDecorator(SensorTypeDto.class); - registerDefaultReferenceDtoDecorator(SettingShapeDto.class); - registerDefaultReferenceDtoDecorator(SizeMeasureTypeDto.class); - registerDefaultReferenceDtoDecorator(StomacFullnessDto.class); - registerDefaultReferenceDtoDecorator(TripTypeDto.class); - registerDefaultReferenceDtoDecorator(VesselActivityLonglineDto.class); - registerDefaultReferenceDtoDecorator(WeightMeasureTypeDto.class); - registerDefaultReferenceDtoDecorator(GearCaracteristicTypeDto.class); - registerDefaultReferenceDtoDecorator(GearCaracteristicDto.class); - registerDefaultReferenceDtoDecorator(GearDto.class); + registerReferentialReferenceDtoDecorator(SensorDataFormatDto.class, libelle); + registerReferentialReferenceDtoDecorator(SensorTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(SettingShapeDto.class, libelle); + registerReferentialReferenceDtoDecorator(SizeMeasureTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(StomacFullnessDto.class, libelle); + registerReferentialReferenceDtoDecorator(TripTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(VesselActivityLonglineDto.class, libelle); + registerReferentialReferenceDtoDecorator(WeightMeasureTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(GearCaracteristicTypeDto.class, libelle); + registerReferentialReferenceDtoDecorator(GearCaracteristicDto.class, libelle); + registerReferentialReferenceDtoDecorator(GearDto.class, libelle); registerReferenceDtoDecorator(HarbourDto.class, "${code}$s##${name}$s##${locode}$s"); - registerMultiJXPathDecorator( - ObjectSchoolEstimateDto.class, - "${species/scientificLabel}$s##${weight}$d", "##", - " - "); - registerMultiJXPathDecorator( - SchoolEstimateDto.class, - "${species/scientificLabel}$s##${weight}$d##${meanWeight}$d", "##", " - "); - registerMultiJXPathDecorator( + registerObserveDecorator(ObjectSchoolEstimateDto.class, "${species/scientificLabel}$s##${weight}$d"); + registerObserveDecorator(SchoolEstimateDto.class, "${species/scientificLabel}$s##${weight}$d##${meanWeight}$d"); + registerObserveDecorator( TargetCatchDto.class, - "${weightCategory/species/scientificLabel}$s##${weightCategory/" + libelle + "}$s##${weight}$f", "##", " - "); - registerMultiJXPathDecorator( + "${weightCategory/species/scientificLabel}$s##${weightCategory/label}$s##${weight}$f"); + registerObserveDecorator( TargetLengthDto.class, - "${species/scientificLabel}$s##${length}$f##${count}$d", "##", " - "); + "${species/scientificLabel}$s##${length}$f##${count}$d"); - registerMultiJXPathDecorator( + registerObserveDecorator( TransmittingBuoyDto.class, - "${transmittingBuoyType/" + libelle + "}$s##${transmittingBuoyOperation/" + libelle + "}$s##${code}$s", "##", - " - "); + "${transmittingBuoyType/label}$s##${transmittingBuoyOperation/label}$s##${code}$s"); String settingIdentifier = l(locale, "observe.common.settingIdentifier"); String haulingIdentifier = l(locale, "observe.common.haulingIdentifier"); - registerMultiJXPathDecorator( + registerObserveDecorator( SectionDto.class, - " ${settingIdentifier}$s (" + settingIdentifier + ")##${haulingIdentifier}$s (" + haulingIdentifier + ")", "##", " - "); + " ${settingIdentifier}$s (" + settingIdentifier + ")##${haulingIdentifier}$s (" + haulingIdentifier + ")"); - registerMultiJXPathDecorator( + registerObserveDecorator( BasketDto.class, - " ${settingIdentifier}$s (" + settingIdentifier + ")##${haulingIdentifier}$s (" + haulingIdentifier + ")", "##", " - "); + " ${settingIdentifier}$s (" + settingIdentifier + ")##${haulingIdentifier}$s (" + haulingIdentifier + ")"); - registerMultiJXPathDecorator( + registerObserveDecorator( BranchlineDto.class, - " ${settingIdentifier}$s (" + settingIdentifier + ")##${haulingIdentifier}$s (" + haulingIdentifier + ")", "##", " - "); + " ${settingIdentifier}$s (" + settingIdentifier + ")##${haulingIdentifier}$s (" + haulingIdentifier + ")"); - registerJXPathDecorator(SectionDto.class, HAULING_IDENTIFIER, "${haulingIdentifier}$s"); - registerJXPathDecorator(BasketDto.class, HAULING_IDENTIFIER, "${haulingIdentifier}$s"); - registerJXPathDecorator(BranchlineDto.class, HAULING_IDENTIFIER, "${haulingIdentifier}$s"); + registerObserveDecorator(HAULING_IDENTIFIER, SectionDto.class, "${haulingIdentifier}$s"); + registerObserveDecorator(HAULING_IDENTIFIER, BasketDto.class, "${haulingIdentifier}$s"); + registerObserveDecorator(HAULING_IDENTIFIER, BranchlineDto.class, "${haulingIdentifier}$s"); // TripSeine decorator - registerDecorator(new TripSeineDecorator(libelle)); - registerReferenceDtoDecorator(TripSeineDto.class, - "${startDate}$td/%1$tm/%1$tY##${endDate}$td/%2$tm/%2$tY##${vessel}$s##${observer}$s"); - + registerDecorator(new TripSeineDecorator()); + registerDecorator(TripSeineDto.class.getSimpleName(), + new ReferenceDecorator("${startDate}$td/%1$tm/%1$tY##${endDate}$td/%2$tm/%2$tY##${vessel}$s##${observer}$s")); // TripLongline decorator - registerDecorator(new TripLonglineDecorator(libelle)); - registerReferenceDtoDecorator(TripLonglineDto.class, - "${startDate}$td/%1$tm/%1$tY##${endDate}$td/%2$tm/%2$tY##${vessel}$s##${observer}$s"); + registerDecorator(new TripLonglineDecorator()); + registerDecorator(TripLonglineDto.class.getSimpleName(), + new ReferenceDecorator("${startDate}$td/%1$tm/%1$tY##${endDate}$td/%2$tm/%2$tY##${vessel}$s##${observer}$s")); String oldCode = l(locale, "observe.common.oldCode3L"); // Species decorator - registerDecorator(new SpeciesDecorator(libelle, oldCode)); - registerReferenceDtoDecorator(SpeciesDto.class, - "${faoCode}$s##${scientificLabel}$s##" + oldCode + " ${homeId}$s"); + registerDecorator(new SpeciesDecorator( oldCode)); + registerDecorator(SpeciesDto.class.getSimpleName(), + new ReferenceDecorator("${faoCode}$s##${scientificLabel}$s##" + oldCode + " ${homeId}$s")); // ObjectObservedSpecies decorator - registerDecorator(new ObjectObservedSpeciesDecorator(libelle)); + registerDecorator(new ObjectObservedSpeciesDecorator()); // NonTargetCatch decorator - registerDecorator(new NonTargetCatchDecorator(libelle)); + registerDecorator(new NonTargetCatchDecorator()); // NonTargetLength decorator - registerDecorator(new NonTargetLengthDecorator(libelle)); + registerDecorator(new NonTargetLengthDecorator()); // LengthWeightParameter decorator - registerDecorator(new LengthWeightParameterDecorator(libelle)); - registerReferenceDtoDecorator(LengthWeightParameterDto.class, - "${sex/label}$s##${ocean/label}$s##${species/scientificLabel}$s##" + - t("observe.common.lengthWeightFormula") + " ${lengthWeightFormula}$s"); + registerDecorator(new LengthWeightParameterDecorator()); + registerDecorator(LengthWeightParameterDto.class.getSimpleName(), + new ReferenceDecorator("${sex/label}$s##${ocean/label}$s##${species/scientificLabel}$s##" + + t("observe.common.lengthWeightFormula") + " ${lengthWeightFormula}$s")); // gps decorators - registerJXPathDecorator(ActivitySeineDto.class, - "activity-gps", - t("observe.common.gps.activity")); - registerJXPathDecorator(GPSPoint.class, - "gpsPoint-gps", - t("observe.common.gps.gpsPoint")); - registerJXPathDecorator(GPSPointInterval.class, - "gpsPointInterval-gps", - t("observe.common.gps.gpsPointInterval")); - - registerMultiJXPathDecorator(GPSPoint.class, - "${time}$td/%1$tm/%1$tY %1$tH:%1$tM##${latitude}$s##${longitude}$s", - "##", " "); - - registerMultiJXPathDecorator(SectionTemplate.class, "${id}$s##${floatlineLengths}$s", "##", " "); - - registerJXPathDecorator(CatchLonglineDto.class, "${homeId}$s"); - registerJXPathDecorator(TdrDto.class, "${homeId}$s"); + registerObserveDecorator("activity-gps", + ActivitySeineDto.class, + t("observe.common.gps.activity")); + registerObserveDecorator("gpsPoint-gps", + GPSPoint.class, + t("observe.common.gps.gpsPoint")); + registerObserveDecorator(GPSPointInterval.class, + "gpsPointInterval-gps", + t("observe.common.gps.gpsPointInterval")); + + registerObserveDecorator(GPSPoint.class, + "${time}$td/%1$tm/%1$tY %1$tH:%1$tM##${latitude}$s##${longitude}$s", + " "); + + registerObserveDecorator(SectionTemplate.class, "${id}$s##${floatlineLengths}$s", " "); + + registerObserveDecorator(CatchLonglineDto.class, "${homeId}$s"); + registerObserveDecorator(TdrDto.class, "${homeId}$s"); + + //FIXME how to decorate ? + registerObserveDecorator(GearUseFeaturesMeasurementSeineDto.class, "${id}$s"); } - protected <T extends IdDto> void registerDefaultReferenceDtoDecorator(Class<T> referenceType) { - registerReferenceDtoDecorator(referenceType, "${code}$s##${label}$s"); + protected <T extends ReferentialDto> void registerReferentialReferenceDtoDecorator(Class<T> referenceType, + String libelle) { + registerDecorator(referenceType.getSimpleName(), new ReferenceDecorator("${code}$s##${label}$s")); + registerObserveDecorator(referenceType, "${code}$s##${" + libelle + "}$s", " "); } + protected <T extends IdDto> void registerReferenceDtoDecorator(Class<T> referenceType, String expression) { - registerDecorator(referenceType.getSimpleName(), new ReferenceDecorator(expression)); + registerReferenceDtoDecorator(referenceType, expression, expression); + } + + protected <T extends IdDto> void registerReferenceDtoDecorator(Class<T> referenceType, + String expression, + String referenceExpression) { + registerReferenceDtoDecorator(referenceType, expression, referenceExpression, " "); + } + + protected <T extends IdDto> void registerReferenceDtoDecorator(Class<T> referenceType, + String expression, + String referenceExpression, + String separator) { + registerDecorator(referenceType.getSimpleName(), new ReferenceDecorator(referenceExpression)); + registerObserveDecorator(referenceType, expression, separator); + } + + + protected <T> void registerObserveDecorator(Class<T> referenceType, String expression) { + registerDecorator(new ObserveDecorator<>(referenceType, expression)); + } + + protected <T> void registerObserveDecorator(Class<T> referenceType, String expression, String separator) { + registerDecorator(new ObserveDecorator<>(referenceType, expression, separator)); + } + + protected <T> void registerObserveDecorator(String context, Class<T> referenceType, String expression) { + registerDecorator(context, new ObserveDecorator<>(referenceType, expression)); + } + + protected <T> void registerObserveDecorator(String context, Class<T> referenceType, String expression, String separator) { + registerDecorator(context, new ObserveDecorator<>(referenceType, expression, separator)); } } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java index 51ffcab..f09d0d9 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java @@ -52,6 +52,7 @@ import jaxx.runtime.swing.CardLayout2Ext; import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.swing.editor.bean.BeanListHeader; import jaxx.runtime.validator.swing.SwingValidatorUtil; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; @@ -258,10 +259,10 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content String[] columns = new String[nbColumns]; System.arraycopy(naturalIds, 0, columns, 1, naturalIds.length); - columns[0] = Introspector.decapitalize(beanType.getSimpleName()); + columns[0] = StringUtils.removeEnd(Introspector.decapitalize(beanType.getSimpleName()), "Dto"); DecoratorService dService = getDecoratorService(); - Decorator<E> decorator = dService.getDecoratorByType(beanType); + Decorator<ReferenceDto> decorator = dService.getDecoratorByType(ReferenceDto.class, beanType.getSimpleName()); for (ReferenceDto<E> e : entities.getReference()) { @@ -270,7 +271,10 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content data[0] = decorator.toString(e); for (String property : naturalIds) { - Object o = e.getPropertyValue(property); + Object o = null; + if (e.getPropertyNames().contains(property)) { + o = e.getPropertyValue(property); + } if (ContentReferenceUIModel.DEFAULT_PROPERTIES[0].equals(property) && o == null) { // cas special du code à 0, le loador ne retourne pas // de valeur car c'est la valeur par defaut d'un type @@ -390,11 +394,11 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content content.add(new JLabel(bean.getId())); //FIXME -// content.add(new JLabel(t("observe.common.topiaCreateDate"))); -// content.add(new JLabel(bean.getTopiaCreateDate().toString())); -// -// content.add(new JLabel(t("observe.common.topiaVersion"))); -// content.add(new JLabel(bean.getTopiaVersion() + "")); + content.add(new JLabel(t("observe.common.topiaCreateDate"))); + content.add(new JLabel("test")); + + content.add(new JLabel(t("observe.common.topiaVersion"))); + content.add(new JLabel("test")); SpringUtilities.makeCompactGrid(content, 3, 2, 5, 5, 5, 5); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/LengthWeightParameterDecorator.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/LengthWeightParameterDecorator.java index 61916f2..08a5fcf 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/LengthWeightParameterDecorator.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/LengthWeightParameterDecorator.java @@ -36,14 +36,11 @@ public class LengthWeightParameterDecorator extends ObserveDecorator<LengthWeigh private static final long serialVersionUID = 1L; - private final String libelle; - - public LengthWeightParameterDecorator(String libelle) throws IllegalArgumentException, NullPointerException { + public LengthWeightParameterDecorator() throws IllegalArgumentException, NullPointerException { super(LengthWeightParameterDto.class, - "${gender}$s##${ocean/" + libelle + "}$s##${species/scientificLabel}$s##" + + "${sex}$s##${ocean/label}$s##${species/scientificLabel}$s##" + t("observe.common.lengthWeightFormula") + " ${lengthWeightFormula}$s" ); - this.libelle = libelle; } @SuppressWarnings({"unchecked"}) @@ -64,14 +61,11 @@ public class LengthWeightParameterDecorator extends ObserveDecorator<LengthWeigh value = super.getTokenValue(jxcontext, token); if (token.equals("species/scientificLabel") && "xx".equals(value)) { - value = super.getTokenValue(jxcontext, - "species/" + - libelle); + value = super.getTokenValue(jxcontext, "species/label"); } if (token.equals("sex")) { value = super.getTokenValue(jxcontext, - "sex/" + - libelle); + "sex/label"); value = t("observe.common.sex") + ' ' + value; } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/NonTargetCatchDecorator.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/NonTargetCatchDecorator.java index f7e9e4b..0fde90a 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/NonTargetCatchDecorator.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/NonTargetCatchDecorator.java @@ -34,13 +34,10 @@ public class NonTargetCatchDecorator extends ObserveDecorator<NonTargetCatchDto> private static final long serialVersionUID = 1L; - private final String libelle; - - public NonTargetCatchDecorator(String libelle) { + public NonTargetCatchDecorator() { super(NonTargetCatchDto.class, - "${species/scientificLabel}$s##${speciesFate/" + libelle + "}$s" + "${species/scientificLabel}$s##${speciesFate/label}$s" ); - this.libelle = libelle; } @Override @@ -49,7 +46,7 @@ public class NonTargetCatchDecorator extends ObserveDecorator<NonTargetCatchDto> Comparable<Comparable<?>> value = super.getTokenValue(jxcontext, token); if (token.equals("species/scientificLabel") && "xx".equals(String.valueOf(value))) { - value = super.getTokenValue(jxcontext, "species/" + libelle); + value = super.getTokenValue(jxcontext, "species/label"); } return value; } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/NonTargetLengthDecorator.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/NonTargetLengthDecorator.java index 77c753d..140b737 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/NonTargetLengthDecorator.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/NonTargetLengthDecorator.java @@ -34,13 +34,10 @@ public class NonTargetLengthDecorator extends ObserveDecorator<NonTargetLengthDt private static final long serialVersionUID = 1L; - private final String libelle; - - public NonTargetLengthDecorator(String libelle) throws IllegalArgumentException, NullPointerException { + public NonTargetLengthDecorator() throws IllegalArgumentException, NullPointerException { super(NonTargetLengthDto.class, "${species/scientificLabel}$s##${length}$f##${gender}$s" ); - this.libelle = libelle; } @SuppressWarnings({"unchecked"}) @@ -51,10 +48,10 @@ public class NonTargetLengthDecorator extends ObserveDecorator<NonTargetLengthDt super.getTokenValue(jxcontext, token); if (token.equals("species/scientificLabel") && "xx".equals(value)) { - value = super.getTokenValue(jxcontext, "species/" + libelle); + value = super.getTokenValue(jxcontext, "species/label"); } if ("sex".equals(token)) { - value = super.getTokenValue(jxcontext, "sex/" + libelle); + value = super.getTokenValue(jxcontext, "sex/label"); } return (Comparable<Comparable<?>>) value; } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ObjectObservedSpeciesDecorator.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ObjectObservedSpeciesDecorator.java index cba7594..0122e9f 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ObjectObservedSpeciesDecorator.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ObjectObservedSpeciesDecorator.java @@ -34,20 +34,17 @@ public class ObjectObservedSpeciesDecorator extends ObserveDecorator<ObjectObser private static final long serialVersionUID = 1L; - private final String libelle; - - public ObjectObservedSpeciesDecorator(String libelle) { + public ObjectObservedSpeciesDecorator() { super(ObjectObservedSpeciesDto.class, - "${species/scientificLabel}$s##${speciesStatus/" + libelle + "}$s##${count}$d" + "${species/scientificLabel}$s##${speciesStatus/label}$s##${count}$d" ); - this.libelle = libelle; } @Override protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { Comparable<Comparable<?>> value = super.getTokenValue(jxcontext, token); if (token.equals("species/scientificLabel") && "xx".equals(String.valueOf(value))) { - value = super.getTokenValue(jxcontext, "species/" + libelle); + value = super.getTokenValue(jxcontext, "species/label"); } return value; } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ObserveDecorator.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ObserveDecorator.java index 887777f..401495d 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ObserveDecorator.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ObserveDecorator.java @@ -21,11 +21,15 @@ */ package fr.ird.observe.ui.util.decorator; +import fr.ird.observe.services.dto.ReferenceDto; import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.MultiJXPathDecorator; +import java.io.Serializable; + import static org.nuiton.i18n.I18n.t; /** @@ -34,7 +38,8 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 2.4 */ -public abstract class ObserveDecorator<E> extends MultiJXPathDecorator<E> implements Cloneable { +public class ObserveDecorator<E> extends MultiJXPathDecorator<E> implements Cloneable { + private static final long serialVersionUID = 1L; /** Logger. */ @@ -44,11 +49,14 @@ public abstract class ObserveDecorator<E> extends MultiJXPathDecorator<E> implem public static final String DEFAULT_SEPARATOR_REPLACEMENT = " - "; - protected ObserveDecorator(Class<E> internalClass, String expression) { + public ObserveDecorator(Class<E> internalClass, String expression) { super(internalClass, expression, DEFAULT_SEPARATOR, DEFAULT_SEPARATOR_REPLACEMENT); } + public ObserveDecorator(Class<E> internalClass, String expression, String separator) { + super(internalClass, expression, DEFAULT_SEPARATOR, separator); + } @Override public final Object clone() throws CloneNotSupportedException { @@ -60,8 +68,22 @@ public abstract class ObserveDecorator<E> extends MultiJXPathDecorator<E> implem String token) { // assume all values are comparable Comparable<Comparable<?>> value; + try { - value = (Comparable<Comparable<?>>) jxcontext.getValue(token); + + String[] tokens = token.split("/"); + + Object value0 = jxcontext.getValue(tokens[0]); + + if (value0 instanceof ReferenceDto) { + + value = getValueFromReferenceDto(tokens, (ReferenceDto) value0, 1); + + } else { + + value = (Comparable<Comparable<?>>) jxcontext.getValue(token); + } + if (value == null) { value = (Comparable<Comparable<?>>) getDefaultNullValue(token); } @@ -73,6 +95,34 @@ public abstract class ObserveDecorator<E> extends MultiJXPathDecorator<E> implem return value; } + protected Comparable<Comparable<?>> getValueFromReferenceDto(String[] tokens, ReferenceDto referenceBean, int startIndex) { + + for (int i = startIndex, max = tokens.length - 1 ; i < max ; i++) { + + if (referenceBean.getPropertyNames().contains(tokens[i])) { + + Serializable propertyValue = referenceBean.getPropertyValue(tokens[i]); + + if (propertyValue == null || !(propertyValue instanceof ReferenceDto)) { + + return (Comparable<Comparable<?>>) getDefaultUndefinedValue(StringUtils.join(tokens, "/")); + + } + + referenceBean = (ReferenceDto) propertyValue; + } + } + + Comparable<Comparable<?>> value = null; + + String lastToken = tokens[tokens.length - 1]; + if (referenceBean.getPropertyNames().contains(lastToken)) { + value = (Comparable<Comparable<?>>) referenceBean.getPropertyValue(lastToken); + } + + return value; + } + protected Comparable<?> getDefaultUndefinedValue(String token) { if (log.isWarnEnabled()) { log.warn("No defined value for token [" + token + "]"); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ReferenceDecorator.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ReferenceDecorator.java index 62926af..84443a8 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ReferenceDecorator.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/ReferenceDecorator.java @@ -4,8 +4,6 @@ import fr.ird.observe.services.dto.ReferenceDto; import fr.ird.observe.services.dto.referential.ReferentialDto; import org.apache.commons.jxpath.JXPathContext; -import java.io.Serializable; - import static org.nuiton.i18n.I18n.t; /** @@ -27,31 +25,9 @@ public class ReferenceDecorator extends ObserveDecorator<ReferenceDto> implement if (contextBean instanceof ReferenceDto) { - ReferenceDto referenceBean = (ReferenceDto) contextBean; - String[] tokens = token.split("/"); - for (int i = 0 ; i < tokens.length - 1 ; i++) { - - if (referenceBean.getPropertyNames().contains(tokens[i])) { - - Serializable propertyValue = referenceBean.getPropertyValue(tokens[i]); - - if (propertyValue == null || !(propertyValue instanceof ReferenceDto)) { - - return (Comparable<Comparable<?>>) getDefaultUndefinedValue(token); - - } - - referenceBean = (ReferenceDto) propertyValue; - } - } - - String lastToken = tokens[tokens.length - 1]; - if (referenceBean.getPropertyNames().contains(lastToken)) { - value = (Comparable<Comparable<?>>) referenceBean.getPropertyValue(lastToken); - } - + value = getValueFromReferenceDto(tokens, (ReferenceDto) contextBean, 0); if (value == null) { value = (Comparable<Comparable<?>>) getDefaultNullValue(tokens[0]); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/SpeciesDecorator.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/SpeciesDecorator.java index 373bd1d..deaa492 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/SpeciesDecorator.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/SpeciesDecorator.java @@ -36,8 +36,6 @@ public class SpeciesDecorator extends ObserveDecorator<SpeciesDto> { private static final long serialVersionUID = 1L; - private final String libelle; - static { // pour avoir les traduction sur le nom de la propriété @@ -46,16 +44,13 @@ public class SpeciesDecorator extends ObserveDecorator<SpeciesDto> { n("observe.common.species/scientificLabel"); n("observe.common.scientificLabel"); n("observe.common.homeId"); - - } - public SpeciesDecorator(String libelle, String oldCode) { + public SpeciesDecorator(String oldCode) { super(SpeciesDto.class, "${faoCode}$s##${scientificLabel}$s##" + oldCode + " ${homeId}$s" ); - this.libelle = libelle; } @Override @@ -63,7 +58,7 @@ public class SpeciesDecorator extends ObserveDecorator<SpeciesDto> { Comparable<?> value; value = super.getTokenValue(jxcontext, token); if (token.equals(SpeciesDto.PROPERTY_SCIENTIFIC_LABEL) && "xx".equals(value)) { - value = super.getTokenValue(jxcontext, libelle); + value = super.getTokenValue(jxcontext, "label"); } return (Comparable<Comparable<?>>) value; } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/TripLonglineDecorator.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/TripLonglineDecorator.java index 3379b30..8a31565 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/TripLonglineDecorator.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/TripLonglineDecorator.java @@ -33,9 +33,9 @@ public class TripLonglineDecorator extends ObserveDecorator<TripLonglineDto> { private static final long serialVersionUID = 1L; - public TripLonglineDecorator(String libelle) throws IllegalArgumentException, NullPointerException { + public TripLonglineDecorator() throws IllegalArgumentException, NullPointerException { super(TripLonglineDto.class, - "${startDate}$td/%1$tm/%1$tY##${endDate}$td/%2$tm/%2$tY##${vessel/" + libelle + "}$s##${observerLabel}$s" + "${startDate}$td/%1$tm/%1$tY##${endDate}$td/%2$tm/%2$tY##${vessel/label}$s##${observerLabel}$s" ); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/TripSeineDecorator.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/TripSeineDecorator.java index 264ee96..5b61153 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/TripSeineDecorator.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/util/decorator/TripSeineDecorator.java @@ -34,9 +34,9 @@ public class TripSeineDecorator extends ObserveDecorator<TripSeineDto> { private static final long serialVersionUID = 1L; - public TripSeineDecorator(String libelle) throws IllegalArgumentException, NullPointerException { + public TripSeineDecorator() throws IllegalArgumentException, NullPointerException { super(TripSeineDto.class, - "${startDate}$td/%1$tm/%1$tY##${endDate}$td/%2$tm/%2$tY##${vessel/" + libelle + "}$s##${observerLabel}$s" + "${startDate}$td/%1$tm/%1$tY##${endDate}$td/%2$tm/%2$tY##${vessel/label}$s##${observerLabel}$s" ); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.