branch feature/7586 created (now 9d449cb)
This is an automated email from the git hooks/post-receive script. New change to branch feature/7586 in repository observe. See http://git.codelutin.com/observe.git at 9d449cb correction du remplissage des données referentielles des combo et listes This branch includes the following new commits: new 9d449cb correction du remplissage des données referentielles des combo et listes The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 9d449cbd028240dbb2163f5dd79a0ec13c291f7a Author: Kevin Morin <morin@codelutin.com> Date: Mon Oct 5 17:03:15 2015 +0200 correction du remplissage des données referentielles des combo et listes -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7586 in repository observe. See http://git.codelutin.com/observe.git commit 9d449cbd028240dbb2163f5dd79a0ec13c291f7a Author: Kevin Morin <morin@codelutin.com> Date: Mon Oct 5 17:03:15 2015 +0200 correction du remplissage des données referentielles des combo et listes --- .../java/fr/ird/observe/ui/DecoratorService.java | 1 + .../ird/observe/ui/content/ContentUIHandler.java | 11 +- .../observe/ui/content/ContentUIInitializer.java | 215 ++++++++++++++------- .../fr/ird/observe/ui/content/ContentUIModel.java | 5 +- .../java/fr/ird/observe/services/dto/FormDto.java | 7 +- 5 files changed, 160 insertions(+), 79 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 af78e48..6cc81f0 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 @@ -420,6 +420,7 @@ public class DecoratorService extends DecoratorProvider { registerReferenceDtoDecorator(ActivityLonglineDto.class, "${timeStamp}$td/%1$tm/%1$tY %1$tH:%1$tM##${vesselActivityLongline/" + libelle + "}$s"); registerMultiJXPathDecorator(PersonDto.class, "${lastName}$s##${firstName}$s", "##", " "); + registerReferenceDtoDecorator(PersonDto.class, "${lastName}$s##${firstName}$s"); registerDefaultReferenceDtoDecorator(SexDto.class, libelle); //FIXME Use startDate - endDate registerDefaultReferenceDtoDecorator(FpaZoneDto.class, libelle); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 0049a00..f771ad5 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -55,6 +55,8 @@ import org.nuiton.validator.NuitonValidatorScope; import javax.swing.*; import java.awt.*; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; @@ -302,9 +304,16 @@ public abstract class ContentUIHandler<E extends IdDto> { public void initUI() throws Exception { - ContentUIInitializer<E, ObserveContentUI<E>> uiInitializer = new ContentUIInitializer<E, ObserveContentUI<E>>(ui); + final ContentUIInitializer<E, ObserveContentUI<E>> uiInitializer = new ContentUIInitializer<E, ObserveContentUI<E>>(ui); uiInitializer.initUI(); + getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_FORM_DTO, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + uiInitializer.referentialDataUpdated(); + } + }); + } public void openUI() throws Exception { diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java index 3aa315d..1b2c5fc 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java @@ -84,6 +84,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -283,6 +284,36 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E } } + public void referentialDataUpdated() { + + // initialisation des éditeurs + + for (String name : ui.get$objectMap().keySet()) { + Object o = ui.getObjectById(name); + + if (o == null) { + continue; + } + + if (o instanceof BeanComboBox<?>) { + updateData((BeanComboBox<?>) o); + continue; + } + + if (o instanceof BeanListHeader<?>) { + updateData((BeanListHeader<?>) o); + continue; + } + + if (o instanceof FilterableDoubleList<?>) { + updateData((FilterableDoubleList<?>) o); + continue; + } + + } + + } + protected void initBlockLayerUI(String... doNotBlockComponentIds) { ui.getBlockLayerUI().setAcceptedComponentTypes(ObserveMapPane.class, JScrollBar.class); ui.getBlockLayerUI().setAcceptedComponentNames(doNotBlockComponentIds); @@ -604,31 +635,15 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E Class<E> dtoClass = (Class<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_ENTITY_CLASS); // init list - Decorator<ReferenceDto> decorator = tx.getDecorator(ReferenceDto.class, dtoClass.getName()); + Decorator<ReferenceDto> decorator = tx.getDecorator(ReferenceDto.class, dtoClass.getSimpleName()); if (log.isDebugEnabled()) { log.debug("Will use decorator " + decorator); } list.putClientProperty("decorator", decorator); - List<ReferenceDto> data = null; - - if (ReferentialDto.class.isAssignableFrom(dtoClass)) { - - Predicate<ReferenceDto> predicate = (Predicate<ReferenceDto>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - - ReferenceSetDto<E> referenceSetDto = getFormDto().getReferenceSetDto(dtoClass); - data = new ArrayList<>(Collections2.filter(referenceSetDto.getReference(), predicate)); -// data = tx.getDataService().getList(storageService, realEntityClass, predicate); - - } else { - data = new ArrayList<>(); - } - - // sort data from first decorator context - DecoratorUtil.sort((JXPathDecorator<ReferenceDto>) decorator, data, 0); // set datas to list and init renderer - list.init((JXPathDecorator<ReferenceDto>) decorator, data, Collections.<ReferenceDto>emptyList()); + list.init((JXPathDecorator<ReferenceDto>) decorator, Collections.<ReferenceDto>emptyList(), Collections.<ReferenceDto>emptyList()); // get the renderer initialized ListCellRenderer renderer = list.getSelectedList().getCellRenderer(); @@ -637,8 +652,6 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E list.getSelectedList().setCellRenderer(new ReferentielListCellRenderer(renderer)); list.getUniverseList().setCellRenderer(new ReferentielListCellRenderer(renderer)); - list.putClientProperty("data", data); - //FIXME // listen on cache modification // EntityDoubleListPropertyChangeListener<E> listener = @@ -647,6 +660,31 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E // service.addReferentielPropertyChangeListener(entityClass, listener); } + protected <E extends IdDto> void updateData(FilterableDoubleList list) { + Class<E> dtoClass = (Class<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_ENTITY_CLASS); + FormDto formDto = getFormDto(); + List<ReferenceDto> data; + + if (formDto != null && ReferentialDto.class.isAssignableFrom(dtoClass)) { + + Predicate<ReferenceDto> predicate = (Predicate<ReferenceDto>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); + + ReferenceSetDto<E> referenceSetDto = formDto.getReferenceSetDto(dtoClass); + data = new ArrayList<>(Collections2.filter(referenceSetDto.getReference(), predicate)); + + } else { + data = new ArrayList<>(); + } + + // sort data from first decorator context + ObserveSwingApplicationContext tx = ObserveSwingApplicationContext.get(); + Decorator<ReferenceDto> decorator = tx.getDecorator(ReferenceDto.class, dtoClass.getSimpleName()); + DecoratorUtil.sort((JXPathDecorator<ReferenceDto>) decorator, data, 0); + + list.setUniverse(data); + list.putClientProperty("data", data); + } + /** * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. @@ -669,13 +707,33 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E list.putClientProperty("decorator", decorator); + // set datas to list and init renderer + list.init((JXPathDecorator<ReferenceDto>) decorator, Collections.<ReferenceDto>emptyList()); + + // get the renderer initialized + ListCellRenderer renderer = list.getList().getCellRenderer(); + + // add the specific renderer + list.getList().setCellRenderer(new ReferentielListCellRenderer(renderer)); + + //FIXME + // listen on cache modification +// EntityListPropertyChangeListener<E> listener = +// new EntityListPropertyChangeListener<E>(dtoClass, list); +// DataService service = ObserveContext.get().getDataService(); +// service.addReferentielPropertyChangeListener(entityClass, listener); + } + + protected <E extends IdDto> void updateData(BeanListHeader list) { + Class<E> dtoClass = (Class<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_ENTITY_CLASS); + FormDto formDto = getFormDto(); List<ReferenceDto> data; - if (ReferentialDto.class.isAssignableFrom(dtoClass)) { + if (formDto != null && ReferentialDto.class.isAssignableFrom(dtoClass)) { Predicate<ReferenceDto> predicate = (Predicate<ReferenceDto>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - ReferenceSetDto<E> referenceSetDto = getFormDto().getReferenceSetDto(dtoClass); + ReferenceSetDto<E> referenceSetDto = formDto.getReferenceSetDto(dtoClass); data = new ArrayList<>(Collections2.filter(referenceSetDto.getReference(), predicate)); } else { @@ -683,25 +741,12 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E } // sort data from first decorator context + ObserveSwingApplicationContext tx = ObserveSwingApplicationContext.get(); + Decorator<ReferenceDto> decorator = tx.getDecorator(ReferenceDto.class, dtoClass.getSimpleName()); DecoratorUtil.sort((JXPathDecorator<ReferenceDto>) decorator, data, 0); - // set datas to list and init renderer - list.init((JXPathDecorator<ReferenceDto>) decorator, data); - - // get the renderer initialized - ListCellRenderer renderer = list.getList().getCellRenderer(); - - // add the specific renderer - list.getList().setCellRenderer(new ReferentielListCellRenderer(renderer)); - + list.setData(data); list.putClientProperty("data", data); - - //FIXME - // listen on cache modification -// EntityListPropertyChangeListener<E> listener = -// new EntityListPropertyChangeListener<E>(dtoClass, list); -// DataService service = ObserveContext.get().getDataService(); -// service.addReferentielPropertyChangeListener(entityClass, listener); } /** @@ -719,43 +764,10 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E // init combobox Class<E> dtoClass = (Class<E>) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_ENTITY_CLASS); - Decorator<ReferenceDto> decorator = context.getDecorator(ReferenceDto.class, dtoClass.getName()); - - Boolean noLoad = (Boolean) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_NO_LOAD); - - List<ReferenceDto> data = null; - - if (noLoad != null && noLoad) { - - if (log.isInfoEnabled()) { - log.info("Skip loading of entity list [" + dtoClass.getName() + "] (listNoLoad property found)"); - } - data = Collections.emptyList(); - - } else { - - // get complete data list from service - Predicate<ReferenceDto> predicate = (Predicate<ReferenceDto>) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - - ReferenceSetDto<E> referenceSetDto = getFormDto().getReferenceSetDto(dtoClass); - data = new ArrayList<>(Collections2.filter(referenceSetDto.getReference(), predicate)); - - } - - boolean referentialEntity = ReferentialDto.class.isAssignableFrom(dtoClass); - if (referentialEntity) { - - //TC-20100208 : on ne veut pas voir les elements du referentiel non actif - ReferentialDtos.filterReferentialListByStatus((List) data); - - } - - if (log.isInfoEnabled()) { - log.info("entity list [" + dtoClass.getName() + "] : " + data.size()); - } + Decorator<ReferenceDto> decorator = context.getDecorator(ReferenceDto.class, dtoClass.getSimpleName()); // add data list to combo box - comboBox.init((JXPathDecorator<ReferenceDto>) decorator, data); + comboBox.init((JXPathDecorator<ReferenceDto>) decorator, Collections.<ReferenceDto>emptyList()); final ListCellRenderer renderer = comboBox.getCombobox().getRenderer(); @@ -781,13 +793,14 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E return comp; } }; + comboBox.getCombobox().setRenderer(toolTipRenderer); if (log.isDebugEnabled()) { log.debug("combo list [" + dtoClass.getName() + "] : " + comboBox.getData().size()); } - if (referentialEntity) { +// if (referentialEntity) { //FIXME // listen on cache modification @@ -803,8 +816,62 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E // }; // service.addReferentielPropertyChangeListener(entityClass, listener); +// } + + } + + protected <E extends IdDto> void updateData(BeanComboBox comboBox) { + ObserveSwingApplicationContext context = ObserveSwingApplicationContext.get(); + + // init combobox + Class<E> dtoClass = (Class<E>) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_ENTITY_CLASS); + Decorator<ReferenceDto> decorator = context.getDecorator(ReferenceDto.class, dtoClass.getSimpleName()); + + Boolean noLoad = (Boolean) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_NO_LOAD); + + List<ReferenceDto> data = null; + FormDto formDto = getFormDto(); + + if (noLoad != null && noLoad || formDto == null) { + + if (log.isInfoEnabled()) { + log.info("Skip loading of entity list [" + dtoClass.getName() + "] (listNoLoad property found)"); + } + data = Collections.emptyList(); + + } else { + + data = new ArrayList<>(); + + // get complete data list from service + ReferenceSetDto<E> referenceSetDto = formDto.getReferenceSetDto(dtoClass); + LinkedHashSet<ReferenceDto> reference = referenceSetDto.getReference(); + + Predicate<ReferenceDto> predicate = (Predicate<ReferenceDto>) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); + + if (predicate != null) { + + data.addAll(Collections2.filter(reference, predicate)); + } else { + + data.addAll(reference); + } + + } + + boolean referentialEntity = ReferentialDto.class.isAssignableFrom(dtoClass); + if (referentialEntity) { + + //TC-20100208 : on ne veut pas voir les elements du referentiel non actif + ReferentialDtos.filterReferentialListByStatus((List) data); + + } + + if (log.isInfoEnabled()) { + log.info("entity list [" + dtoClass.getName() + "] : " + data.size()); } + comboBox.setData(data); } /** diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java index 1c12d36..4d9f4ea 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java @@ -60,9 +60,10 @@ public abstract class ContentUIModel<E extends IdDto> extends AbstractSerializab public static final String PROPERTY_CAN_WRITE = "canWrite"; + public static final String PROPERTY_FORM_DTO = "formDto"; + /** Logger */ static private final Log log = LogFactory.getLog(ContentUIModel.class); - private static final long serialVersionUID = 1L; protected final Class<E> beanType; @@ -148,7 +149,9 @@ public abstract class ContentUIModel<E extends IdDto> extends AbstractSerializab } public void setFormDto(FormDto<E> formDto) { + Object oldValue = getFormDto(); this.formDto = formDto; + firePropertyChange(PROPERTY_FORM_DTO, oldValue, formDto); } public ContentMode getMode() { diff --git a/observe-services-model/src/main/java/fr/ird/observe/services/dto/FormDto.java b/observe-services-model/src/main/java/fr/ird/observe/services/dto/FormDto.java index 95356d6..56ee9aa 100644 --- a/observe-services-model/src/main/java/fr/ird/observe/services/dto/FormDto.java +++ b/observe-services-model/src/main/java/fr/ird/observe/services/dto/FormDto.java @@ -22,6 +22,7 @@ package fr.ird.observe.services.dto; * #L% */ +import com.google.common.base.Optional; import com.google.common.collect.Iterables; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.dto.referential.ReferentialReferenceDto; @@ -52,11 +53,11 @@ public class FormDto<R extends IdDto> extends AbstractFormDto { public <D extends IdDto> ReferenceSetDto<D> getReferenceSetDto(Class<D> type) { - ReferenceSetDto referenceSetDto = Iterables.find(getLabels(), ReferenceSetDtos.newTypePredicate(type)); - if (referenceSetDto == null) { + Optional<ReferenceSetDto> referenceSetDto = Iterables.tryFind(getLabels(), ReferenceSetDtos.newTypePredicate(type)); + if (!referenceSetDto.isPresent()) { throw new ReferenceSetNotFoundException(this, type); } - return referenceSetDto; + return referenceSetDto.get(); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
participants (1)
-
codelutin.com scm