This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit e2aea45600c62bb7b44129e8f09913300513b30f Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Nov 19 20:07:51 2015 +0100 Début de revue du code de l'application swing : y'a du boulot... --- .../observe/ObserveSwingApplicationContext.java | 17 +- .../fr/ird/observe/db/ObserveReferentialCache.java | 5 +- .../fr/ird/observe/db/ObserveSwingDataSource.java | 61 +++--- .../ird/observe/ui/actions/ShowConfigAction.java | 32 +-- .../actions/shared/MoveTripLonglinesUIAction.java | 9 +- .../ui/actions/shared/MoveTripSeinesUIAction.java | 11 +- .../ui/actions/shared/MoveTripsUIAction.java | 5 +- .../ird/observe/ui/content/ContentUIHandler.java | 184 ++++++++++++++--- .../observe/ui/content/ContentUIInitializer.java | 228 --------------------- .../ird/observe/ui/content/ObserveContentUI.java | 2 - .../ird/observe/ui/content/list/ContentListUI.css | 2 +- .../ird/observe/ui/content/list/ContentListUI.jaxx | 6 +- .../ui/content/list/ContentListUIHandler.java | 4 +- .../impl/longline/ActivityLonglinesUIHandler.java | 2 +- .../impl/longline/ActivityLonglinesUIModel.java | 2 - .../list/impl/longline/TripLonglinesUIHandler.java | 2 +- .../list/impl/longline/TripLonglinesUIModel.java | 10 +- .../list/impl/seine/ActivitySeinesUIHandler.java | 2 +- .../content/list/impl/seine/RoutesUIHandler.java | 2 +- .../list/impl/seine/TripSeinesUIHandler.java | 2 +- .../content/list/impl/seine/TripSeinesUIModel.java | 29 +++ .../ui/content/open/ContentOpenableUIHandler.java | 9 +- .../impl/longline/ActivityLonglineUIHandler.java | 1 + .../open/impl/longline/TripLonglineUIHandler.java | 1 + .../open/impl/seine/ActivitySeineUIHandler.java | 1 + .../ui/content/open/impl/seine/RouteUIHandler.java | 1 + .../open/impl/seine/TripSeineUIHandler.java | 20 +- .../ui/content/ref/ContentReferenceUIHandler.java | 91 +++++++- .../ref/ReferentialContentUIInitializer.java | 116 +---------- .../ui/content/table/ContentTableUIHandler.java | 48 +---- .../impl/longline/CatchLonglineUIHandler.java | 28 ++- .../longline/GearUseFeaturesLonglineUIHandler.java | 29 +-- .../impl/seine/GearUseFeaturesSeineUIHandler.java | 4 +- .../src/main/resources/observe-log4j.properties | 2 +- 34 files changed, 444 insertions(+), 524 deletions(-) diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java b/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java index 4d1bba6..8fcd31e 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java @@ -24,8 +24,11 @@ package fr.ird.observe; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import fr.ird.observe.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.db.DataContext; +import fr.ird.observe.services.dto.IdDto; +import fr.ird.observe.services.dto.ReferenceDto; +import fr.ird.observe.util.gps.GPSService; +import fr.ird.observe.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.db.ObserveSwingDataSource; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.event.ObserveSwingDataSourceEvent; @@ -67,9 +70,6 @@ import fr.ird.observe.ui.actions.shared.DeleteDataUIAction; import fr.ird.observe.ui.actions.shared.DeleteReferenceUIAction; import fr.ird.observe.ui.actions.shared.GoDownUIAction; import fr.ird.observe.ui.actions.shared.GoUpUIAction; -import fr.ird.observe.ui.actions.shared.MoveActivityLonglinesUIAction; -import fr.ird.observe.ui.actions.shared.MoveActivitySeinesUIAction; -import fr.ird.observe.ui.actions.shared.MoveRoutesUIAction; import fr.ird.observe.ui.actions.shared.MoveTripLonglinesUIAction; import fr.ird.observe.ui.actions.shared.MoveTripSeinesUIAction; import fr.ird.observe.ui.actions.shared.ReOpenUIAction; @@ -79,7 +79,6 @@ import fr.ird.observe.ui.actions.shared.SelectNodeUIAction; import fr.ird.observe.ui.actions.shared.SelectOpenNodeUIAction; import fr.ird.observe.ui.content.ContentUI; import fr.ird.observe.ui.tree.ObserveTreeHelper; -import fr.ird.observe.util.gps.GPSService; import fr.ird.observe.validation.ObserveSwingValidator; import fr.ird.observe.validation.ValidationContext; import jaxx.runtime.JAXXUtil; @@ -213,6 +212,11 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext im Decorator<O> value = provider.getDecoratorByType(clazz, name); return value; } + public <R extends IdDto> Decorator<ReferenceDto<R>> getReferenceDecorator(Class<R> dtoType) { + Decorator<ReferenceDto> decorator1 = getDecorator(ReferenceDto.class, dtoType.getSimpleName()); + return (Decorator) decorator1; + } + public ObserveSwingApplicationConfig getConfig() { return CONFIG_ENTRY_DEF.getContextValue(this); @@ -914,9 +918,6 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext im registerMainAction(actionMap, new DeleteReferenceUIAction(ui)); registerMainAction(actionMap, new MoveTripLonglinesUIAction(ui)); registerMainAction(actionMap, new MoveTripSeinesUIAction(ui)); - registerMainAction(actionMap, new MoveRoutesUIAction(ui)); - registerMainAction(actionMap, new MoveActivitySeinesUIAction(ui)); - registerMainAction(actionMap, new MoveActivityLonglinesUIAction(ui)); } public void registerMainAction(ActionMap actionMap, AbstractUIAction action) { diff --git a/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveReferentialCache.java b/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveReferentialCache.java index 559b4c0..76abd27 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveReferentialCache.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveReferentialCache.java @@ -12,6 +12,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.Closeable; +import java.io.Serializable; import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; @@ -21,7 +22,9 @@ import java.util.Map; * * @author Tony Chemit - chemit@codelutin.com */ -public class ObserveReferentialCache implements Closeable { +public class ObserveReferentialCache implements Closeable, Serializable { + + private static final long serialVersionUID = 1L; /** Logger. */ private static final Log log = LogFactory.getLog(ObserveReferentialCache.class); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveSwingDataSource.java b/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveSwingDataSource.java index cd53d2a..39401f2 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveSwingDataSource.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveSwingDataSource.java @@ -90,13 +90,13 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements return configuration.getLabel(); } - public String getAuthenticationToken() { - String result = null; - if (connection != null) { - result = connection.getAuthenticationToken(); - } - return result; - } +// public String getAuthenticationToken() { +// String result = null; +// if (connection != null) { +// result = connection.getAuthenticationToken(); +// } +// return result; +// } public boolean canWriteData() { boolean result = connection != null && connection.canWriteData(); @@ -140,7 +140,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements public void open() throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException, BabModelVersionException { - Preconditions.checkState(!isOpen(), "Connection is already open"); + checkIsNotAlreadyOpen(); fireNewMessage(t("observe.storage.message.opening", getLabel())); fireOpening(); @@ -156,7 +156,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements public void create(DataSourceCreateConfigurationDto createDto) throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException { - Preconditions.checkState(!isOpen(), "Connection is already open"); + checkIsNotAlreadyOpen(); fireNewMessage(t("observe.storage.message.creating", getLabel())); fireOpening(); @@ -172,7 +172,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements @Override public void close() { - Preconditions.checkState(isOpen(), "Connection is not open"); + checkIsOpen(); fireNewMessage(t("observe.storage.message.closing", getLabel())); fireClosing(); @@ -192,7 +192,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements public void destroy() { - Preconditions.checkState(isOpen(), "Connection is not open"); + checkIsOpen(); fireNewMessage(t("observe.storage.message.destroying", getLabel())); fireClosing(); @@ -212,6 +212,8 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements public Set<ObserveDbUserDto> getUsers() { + checkIsNotOpen(); + DataSourceService dataSourceService = newService(DataSourceService.class); Set<ObserveDbUserDto> users = dataSourceService.getUsers(getConfiguration()); @@ -222,6 +224,8 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements public void applySecurity(Set<ObserveDbUserDto> users) { + checkIsNotOpen(); + DataSourceService dataSourceService = newService(DataSourceService.class); dataSourceService.applySecurity(getConfiguration(), users); @@ -229,7 +233,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements public void migrateData(ObserveDataSourceInformation dataSourceInformation, Version targetVersion) throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException { - Preconditions.checkState(!isOpen(), "Connection is open"); + checkIsNotOpen(); Version dbVersion = dataSourceInformation.getVersion(); if (!dataSourceInformation.getMigrations().isEmpty()) { @@ -269,7 +273,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements public void loadReferenceSets(FormDto<?> formDto) { - Preconditions.checkState(!isOpen(), "Connection is open"); + checkIsOpen(); ReferenceSetService referenceSetService = newService(ReferenceSetService.class); @@ -374,7 +378,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements public ObserveDataSourceInformation checkCanConnect() throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException { - Preconditions.checkState(connection == null, "Connection is already open"); + checkIsNotAlreadyOpen(); DataSourceService dataSourceService = newService(DataSourceService.class); @@ -401,15 +405,15 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements listenerList.add(ObserveSwingDataSourceListener.class, listener); } - public boolean containsObserveSwingDataSourceListener(ObserveSwingDataSourceListener listener) { - ObserveSwingDataSourceListener[] listeners = getObserveSwingDataSourceListener(); - for (ObserveSwingDataSourceListener l : listeners) { - if (l.equals(listener)) { - return true; - } - } - return false; - } +// public boolean containsObserveSwingDataSourceListener(ObserveSwingDataSourceListener listener) { +// ObserveSwingDataSourceListener[] listeners = getObserveSwingDataSourceListener(); +// for (ObserveSwingDataSourceListener l : listeners) { +// if (l.equals(listener)) { +// return true; +// } +// } +// return false; +// } public ObserveSwingDataSourceListener[] getObserveSwingDataSourceListener() { return listenerList.getListeners(ObserveSwingDataSourceListener.class); @@ -468,4 +472,15 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements } } + protected void checkIsOpen() { + Preconditions.checkState(isOpen(), "Connection is not open"); + } + + protected void checkIsNotAlreadyOpen() { + Preconditions.checkState(!isOpen(), "Connection is already open"); + } + + protected void checkIsNotOpen() { + Preconditions.checkState(!isOpen(), "Connection is open"); + } } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java index 89010d2..e1c313d 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java @@ -30,6 +30,7 @@ import fr.ird.observe.db.ObserveSwingDataSource; import fr.ird.observe.services.dto.IdDtos; import fr.ird.observe.services.dto.ReferenceDto; import fr.ird.observe.services.dto.ReferenceSetDto; +import fr.ird.observe.services.dto.referential.ReferentialReferenceDto; import fr.ird.observe.services.dto.referential.SpeciesListDto; import fr.ird.observe.services.service.ReferentialService; import fr.ird.observe.ui.ObserveMainUI; @@ -59,6 +60,7 @@ import java.awt.event.MouseEvent; import java.util.Collection; import java.util.EventObject; import java.util.Map; +import java.util.Set; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -122,10 +124,10 @@ public class ShowConfigAction extends AbstractAction { ReferentialService service = dataSource.newService(ReferentialService.class); ReferenceSetDto<SpeciesListDto> referentialReferenceSet = service.getReferentialReferenceSet(SpeciesListDto.class); - Collection<ReferenceDto> speciesLists = referentialReferenceSet.getReference(); - Map<String, ReferenceDto> speciesListMap = IdDtos.splitById(speciesLists); + Set<ReferentialReferenceDto<SpeciesListDto>> speciesLists = (Set) referentialReferenceSet.getReference(); + Map<String, ReferentialReferenceDto<SpeciesListDto>> speciesListMap = IdDtos.splitById(speciesLists); - Decorator referenceDecorator = ObserveSwingApplicationContext.get().getDecoratorService().getReferenceDecorator(SpeciesListDto.class); + Decorator<ReferentialReferenceDto<SpeciesListDto>> referenceDecorator = ObserveSwingApplicationContext.get().getDecoratorService().getReferenceDecorator(SpeciesListDto.class); editor = new SpeciesListTableCellEditor(speciesLists, speciesListMap, referenceDecorator); renderer = new SpeciesListsTableCellRenderer(speciesListMap, referenceDecorator); @@ -411,11 +413,11 @@ public class ShowConfigAction extends AbstractAction { private static final long serialVersionUID = 1L; - private final Map<String, ReferenceDto> entityMap; + private final Map<String, ReferentialReferenceDto<SpeciesListDto>> entityMap; - private final Decorator decorator; + private final Decorator<ReferentialReferenceDto<SpeciesListDto>> decorator; - public SpeciesListsTableCellRenderer(Map<String, ReferenceDto> entityMap, Decorator decorator) { + public SpeciesListsTableCellRenderer(Map<String, ReferentialReferenceDto<SpeciesListDto>> entityMap, Decorator<ReferentialReferenceDto<SpeciesListDto>> decorator) { this.entityMap = entityMap; this.decorator = decorator; } @@ -426,7 +428,7 @@ public class ShowConfigAction extends AbstractAction { int row, int column) { String speciesListId = String.valueOf(value); - ReferenceDto speciesList = entityMap.get(speciesListId); + ReferenceDto<SpeciesListDto> speciesList = entityMap.get(speciesListId); return super.getTableCellRendererComponent(table, decorator.toString(speciesList), isSelected, hasFocus, row, column); } @@ -436,23 +438,23 @@ public class ShowConfigAction extends AbstractAction { private static final long serialVersionUID = 1L; - private final Map<String, ReferenceDto> entityMap; + private final Map<String, ReferentialReferenceDto<SpeciesListDto>> entityMap; - private final Decorator decorator; + private final Decorator<ReferentialReferenceDto<SpeciesListDto>> decorator; - protected SpeciesListTableCellEditor(Collection<ReferenceDto> entities, - Map<String, ReferenceDto> entityMap, - Decorator decorator) { + protected SpeciesListTableCellEditor(Collection<ReferentialReferenceDto<SpeciesListDto>> entities, + Map<String, ReferentialReferenceDto<SpeciesListDto>> entityMap, + Decorator<ReferentialReferenceDto<SpeciesListDto>> decorator) { super(new JComboBox()); this.entityMap = entityMap; this.decorator = decorator; - final BeanFilterableComboBox<ReferenceDto> component = new BeanFilterableComboBox<>(); + final BeanFilterableComboBox<ReferentialReferenceDto<SpeciesListDto>> component = new BeanFilterableComboBox<>(); component.setI18nPrefix("observe.common."); component.setShowReset(true); - component.setBeanType(ReferenceDto.class); + component.setBeanType((Class) ReferenceDto.class); setClickCountToStart(1); @@ -474,7 +476,7 @@ public class ShowConfigAction extends AbstractAction { public Object getCellEditorValue() { String result = null; Object selectedItem = component.getSelectedItem(); - if (selectedItem !=null && ReferenceDto.class.isInstance(selectedItem)) { + if (selectedItem != null && ReferenceDto.class.isInstance(selectedItem)) { ReferenceDto reference = (ReferenceDto) selectedItem; result = reference.getId(); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripLonglinesUIAction.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripLonglinesUIAction.java index f6dbdfa..57003e4 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripLonglinesUIAction.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripLonglinesUIAction.java @@ -41,6 +41,13 @@ public class MoveTripLonglinesUIAction extends MoveTripsUIAction { } @Override + protected List<ReferenceDto<TripLonglineDto>> getSelectedDatas(ContentUI<?> ui) { + TripLonglinesUI tripLonglinesUI = (TripLonglinesUI) ui; + TripLonglinesUIModel model = tripLonglinesUI.getModel(); + return model.getSelectedDatas(); + } + + @Override protected GearType getGearType(ContentUI<?> ui) { return GearType.longline; } @@ -55,7 +62,7 @@ public class MoveTripLonglinesUIAction extends MoveTripsUIAction { protected void updateModelData(ContentUI<?> ui) { TripLonglinesUI tripLonglinesUI = (TripLonglinesUI) ui; TripLonglinesUIModel model = tripLonglinesUI.getModel(); - List<ReferenceDto> data = new ArrayList<>(model.getData()); + List<ReferenceDto<TripLonglineDto>> data = new ArrayList<>(model.getData()); data.removeAll(model.getSelectedDatas()); model.setData(data); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripSeinesUIAction.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripSeinesUIAction.java index ebbd01b..1cf53db 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripSeinesUIAction.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripSeinesUIAction.java @@ -18,7 +18,7 @@ import java.util.List; * @author Kevin Morin (Code Lutin) * @since 5.0 */ -public class MoveTripSeinesUIAction extends MoveTripsUIAction { +public class MoveTripSeinesUIAction extends MoveTripsUIAction<TripSeineDto> { private static final long serialVersionUID = 1L; @@ -41,6 +41,13 @@ public class MoveTripSeinesUIAction extends MoveTripsUIAction { } @Override + protected List<ReferenceDto<TripSeineDto>> getSelectedDatas(ContentUI<?> ui) { + TripSeinesUI tripSeinesUI = (TripSeinesUI) ui; + TripSeinesUIModel model = tripSeinesUI.getModel(); + return model.getSelectedDatas(); + } + + @Override protected GearType getGearType(ContentUI<?> ui) { return GearType.seine; } @@ -55,7 +62,7 @@ public class MoveTripSeinesUIAction extends MoveTripsUIAction { protected void updateModelData(ContentUI<?> ui) { TripSeinesUI tripSeinesUI = (TripSeinesUI) ui; TripSeinesUIModel model = tripSeinesUI.getModel(); - List<ReferenceDto> data = new ArrayList<>(model.getData()); + List<ReferenceDto<TripSeineDto>> data = new ArrayList<>(model.getData()); data.removeAll(model.getSelectedDatas()); model.setData(data); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripsUIAction.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripsUIAction.java index 47760f2..17a7b9c 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripsUIAction.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/actions/shared/MoveTripsUIAction.java @@ -45,6 +45,7 @@ import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import java.awt.event.ActionEvent; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import static org.nuiton.i18n.I18n.n; @@ -56,7 +57,7 @@ import static org.nuiton.i18n.I18n.t; * @author Kevin Morin (Code Lutin) * @since 5.0 */ -public abstract class MoveTripsUIAction extends AbstractUIAction { +public abstract class MoveTripsUIAction<T extends IdDto> extends AbstractUIAction { private static final long serialVersionUID = 1L; @@ -105,7 +106,7 @@ public abstract class MoveTripsUIAction extends AbstractUIAction { if (programId != null) { // change the program of the selected trips - List<ReferenceDto> selectedDatas = ((ContentListUIModel) ui.getModel()).getSelectedDatas(); + List<ReferenceDto<T>> selectedDatas = ((ContentListUIModel) ui.getModel()).getSelectedDatas(); List<String> tripIds = Lists.transform(selectedDatas, ReferenceDtos.getIdFunction()); List<Integer> positions = getPositions(tripIds, programId); 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 8b12298..3dc601c 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 @@ -21,15 +21,19 @@ */ package fr.ird.observe.ui.content; +import com.google.common.base.Optional; import fr.ird.observe.ObserveOpenDataManager; import fr.ird.observe.ObserveSwingApplicationContext; import fr.ird.observe.ObserveSwingBinderService; import fr.ird.observe.ObserveSwingTechnicalException; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.db.ObserveSwingDataSource; +import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.services.dto.AbstractObserveDto; +import fr.ird.observe.services.dto.FormDto; import fr.ird.observe.services.dto.IdDto; +import fr.ird.observe.services.dto.ReferenceDto; +import fr.ird.observe.services.dto.ReferenceSetDto; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.ui.DecoratorService; import fr.ird.observe.ui.UIHelper; @@ -42,6 +46,7 @@ import fr.ird.observe.validation.ValidationContext; import jaxx.runtime.JAXXContext; import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.swing.JAXXButtonGroup; +import jaxx.runtime.swing.editor.bean.BeanComboBox; import jaxx.runtime.swing.editor.bean.BeanListHeader; import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import jaxx.runtime.validator.swing.SwingValidatorUtil; @@ -52,6 +57,7 @@ import org.nuiton.decorator.Decorator; import org.nuiton.decorator.DecoratorUtil; import org.nuiton.decorator.JXPathDecorator; import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor; +import org.nuiton.jaxx.widgets.select.FilterableDoubleList; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.AbstractButton; @@ -65,6 +71,8 @@ import java.awt.Component; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; import static org.nuiton.i18n.I18n.t; @@ -255,7 +263,7 @@ public abstract class ContentUIHandler<E extends IdDto> { * @return {@code true} si on peut écrire (donc éditer), {@code false} autrement. */ protected abstract boolean computeCanWrite(ObserveSwingDataSource dataSsource); - + protected final String getSelectedParentId() { String s = null; if (parentType != null) { @@ -316,13 +324,14 @@ public abstract class ContentUIHandler<E extends IdDto> { public void initUI() throws Exception { - final ContentUIInitializer<E, ObserveContentUI<E>> uiInitializer = new ContentUIInitializer<E, ObserveContentUI<E>>(ui); + final ContentUIInitializer<E, ObserveContentUI<E>> uiInitializer = new ContentUIInitializer<>(ui); uiInitializer.initUI(); getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_FORM_DTO, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { - uiInitializer.referentialDataUpdated(); + updateReferenceSets(true); } }); @@ -365,18 +374,6 @@ public abstract class ContentUIHandler<E extends IdDto> { return icon; } -//FIXME -// protected void onLoad(TopiaContext tx, E bean) throws TopiaException { -// -// // par defaut on charge l'objet de la base dans le bean d'édition -// getLoadBinder().load(bean, getBean(), true); -// } - - //FIXME -// protected E onPreCreate(TopiaContext tx, Object parentBean, E bean) throws TopiaException { -// return bean; -// } - public void startEditUI(String... binding) { E editBean = getBean(); @@ -606,7 +603,7 @@ public abstract class ContentUIHandler<E extends IdDto> { DecoratorUtil.sort((JXPathDecorator<E>) decorator, data, 0); return data; } else { - List<E> result = new ArrayList<E>(); + List<E> result = new ArrayList<>(); return result; } } @@ -625,19 +622,6 @@ public abstract class ContentUIHandler<E extends IdDto> { } } - protected E onCreate(Object parentBean, E editBean) { - return editBean; - } - - protected E onUpdate(Object parentBean, E beanToSave) { - // rien par defaut - return beanToSave; - } - - protected void onDelete(Object parentBean, E beanToDelete) { - // rien par defaut - } - protected void addInfoMessage(String message) { addMessage(ui, NuitonValidatorScope.INFO, @@ -788,6 +772,146 @@ public abstract class ContentUIHandler<E extends IdDto> { } + protected void updateReferenceSets(boolean reloadReferenceSets) { + + if (reloadReferenceSets && ContentMode.READ != getModel().getMode()) { + + getDataSource().loadReferenceSets(getModel().getFormDto()); + + } + + 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 <R extends IdDto> void updateData(FilterableDoubleList<ReferenceDto<R>> list) { + + Class<R> dtoClass = getDtoClass(list); + FormDto<E> formDto = getModel().getFormDto(); + List<ReferenceDto<R>> data; + + if (formDto != null && ReferentialDto.class.isAssignableFrom(dtoClass)) { + + //FIXME Bien vérifier que cela fonctionne + ReferenceSetDto<R> referenceSetDto = formDto.getReferenceSetDto(dtoClass, list.getModel().getProperty()); + + data = new ArrayList<>(referenceSetDto.getReference()); + + } else { + + data = new ArrayList<>(); + + } + + // sort data from first decorator context + Decorator<ReferenceDto<R>> decorator = getReferenceDecorator(dtoClass); + DecoratorUtil.sort((JXPathDecorator<ReferenceDto<R>>) decorator, data, 0); + + //FIXME A finir (bien vérifier que la sélection n'est plus dans l'univers) + List<ReferenceDto<R>> selected = list.getModel().getSelected(); + list.setUniverse(data); + list.setSelected(selected); + + list.putClientProperty("data", data); + } + + protected <R extends IdDto> void updateData(BeanListHeader<ReferenceDto<R>> list) { + + Class<R> dtoClass = getDtoClass(list); + FormDto<E> formDto = getModel().getFormDto(); + List<ReferenceDto<R>> data; + + if (formDto != null && ReferentialDto.class.isAssignableFrom(dtoClass)) { + + ReferenceSetDto<R> referenceSetDto = formDto.getReferenceSetDto(dtoClass); + data = new ArrayList<>(referenceSetDto.getReference()); + + } else { + data = new ArrayList<>(); + } + + // sort data from first decorator context + Decorator<ReferenceDto<R>> decorator = getReferenceDecorator(dtoClass); + DecoratorUtil.sort((JXPathDecorator<ReferenceDto<R>>) decorator, data, 0); + + list.setData(data); + list.putClientProperty("data", data); + } + + + protected <R extends IdDto> void updateData(BeanComboBox<ReferenceDto<R>> comboBox) { + + Class<R> dtoClass = getDtoClass(comboBox); + + Boolean noLoad = (Boolean) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_NO_LOAD); + + List<ReferenceDto<R>> data; + FormDto<E> formDto = getModel().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 + Optional<ReferenceSetDto<R>> optionalReferenceSetDto = formDto.tryToGetReferenceSetDto(dtoClass, comboBox.getProperty()); + + if (optionalReferenceSetDto.isPresent()) { + + ReferenceSetDto<R> referenceSetDto = optionalReferenceSetDto.get(); + LinkedHashSet<ReferenceDto<R>> reference = referenceSetDto.getReference(); + data.addAll(reference); + + } + + } + + if (log.isInfoEnabled()) { + log.info("entity list [" + dtoClass.getName() + "] : " + data.size()); + } + + comboBox.setData(data); + } + + protected <R extends IdDto> Class<R> getDtoClass(JComponent list) { + Object clientProperty = list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_ENTITY_CLASS); + return (Class<R>) clientProperty; + } + + protected <R extends IdDto> Decorator<ReferenceDto<R>> getReferenceDecorator(Class<R> dtoType) { + Decorator<ReferenceDto<R>> decorator = ObserveSwingApplicationContext.get().getReferenceDecorator(dtoType); + return decorator; + } + + // protected static class LogPropertyChanges implements PropertyChangeListener { // // private final ImmutableSet<String> propertyNames; 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 177147e..14bfd19 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 @@ -22,14 +22,11 @@ package fr.ird.observe.ui.content; * #L% */ -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import fr.ird.observe.ObserveSwingApplicationContext; import fr.ird.observe.services.dto.FormDto; import fr.ird.observe.services.dto.IdDto; import fr.ird.observe.services.dto.ReferenceDto; -import fr.ird.observe.services.dto.ReferenceSetDto; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.dto.referential.ReferentialDtos; import fr.ird.observe.services.dto.referential.ReferentialReferenceDto; @@ -57,7 +54,6 @@ import org.jdesktop.swingx.JXMonthView; import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor; import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; import org.nuiton.decorator.Decorator; -import org.nuiton.decorator.DecoratorUtil; import org.nuiton.decorator.JXPathDecorator; import org.nuiton.jaxx.application.bean.JavaBeanObjectUtil; import org.nuiton.jaxx.widgets.datetime.DateTimeEditor; @@ -99,7 +95,6 @@ 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; @@ -299,36 +294,6 @@ 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); @@ -675,37 +640,6 @@ 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)) { - - //FIXME Bien vérifier que cela fonctionne - ReferenceSetDto<E> referenceSetDto = formDto.getReferenceSetDto(dtoClass, list.getModel().getProperty()); - - data = new ArrayList<>(referenceSetDto.getReference()); - - } 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); - - //FIXME A finir (bien vérifier que la sélection n'est plus dans l'univers) - List selected = list.getModel().getSelected(); - list.setUniverse(data); - list.setSelected(selected); - - 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é. @@ -745,31 +679,6 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E // 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 (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.setData(data); - list.putClientProperty("data", data); - } - /** * Prépare un component de choix d'entités pour un type d'entité donné et * pour un service de persistance donné. @@ -841,143 +750,6 @@ public class ContentUIInitializer<E extends IdDto, UI extends ObserveContentUI<E } - 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, comboBox.getProperty()); - LinkedHashSet<ReferenceDto> reference = referenceSetDto.getReference(); - - data.addAll(reference); - - } - - if (log.isInfoEnabled()) { - log.info("entity list [" + dtoClass.getName() + "] : " + data.size()); - } - - comboBox.setData(data); - } - - /** - * Un écouteur de changement les entités d'un type donné contenues dans une - * liste graphique donnée. - * - * @param <E> le type des entités - */ - protected static class EntityListPropertyChangeListener - <E extends IdDto> implements PropertyChangeListener { - - /** le type des entités */ - private Class<E> entityClass; - - /** la liste graphique */ - private BeanListHeader<E> list; - - public EntityListPropertyChangeListener(Class<E> entityClass, - BeanListHeader<E> list) { - this.entityClass = entityClass; - this.list = list; - } - - @SuppressWarnings({"unchecked"}) - @Override - public void propertyChange(PropertyChangeEvent evt) { - - List<E> newValue = (List<E>) evt.getNewValue(); - - Decorator<E> decorator = (Decorator<E>) - list.getClientProperty("decorator"); - - if (log.isDebugEnabled()) { - log.debug("reloading entities list for [" + entityClass + - "], size : " + newValue.size()); - } - - DecoratorUtil.sort((JXPathDecorator<E>) decorator, newValue, 0); - E selectedValue = list.getSelectedValue(); - list.putClientProperty("data", newValue); - list.setData(Collections.<E>emptyList()); - list.setData(newValue); - if (selectedValue != null && newValue.contains(selectedValue)) { - - // reselect it - list.getList().setSelectedValue(selectedValue, true); - } - } - } - - /** - * Un écouteur de changement les entités d'un type donné contenues dans une - * liste graphique donnée. - * - * @param <E> le type des entités - */ - protected static class EntityDoubleListPropertyChangeListener - <E extends IdDto> implements PropertyChangeListener { - - /** le type des entités */ - private Class<E> entityClass; - - /** la liste graphique */ - private FilterableDoubleList<E> list; - - public EntityDoubleListPropertyChangeListener(Class<E> entityClass, - FilterableDoubleList<E> list) { - this.entityClass = entityClass; - this.list = list; - } - - @SuppressWarnings({"unchecked"}) - @Override - public void propertyChange(PropertyChangeEvent evt) { - - List<E> newValue = (List<E>) evt.getNewValue(); - - Decorator<E> decorator = (Decorator<E>) - list.getClientProperty("decorator"); - - if (log.isDebugEnabled()) { - log.debug("reloading entities list for [" + entityClass + - "], size : " + newValue.size()); - } - - DecoratorUtil.sort((JXPathDecorator<E>) decorator, newValue, 0); - list.putClientProperty("data", newValue); - - List<E> selectedValues = new ArrayList<E>(list.getModel().getSelected()); - - list.setUniverse(Collections.<E>emptyList()); - list.setUniverse(newValue); - - selectedValues.retainAll(newValue); - - // reselect it - list.setSelected(selectedValues); - - } - } - /** * Un renderer de liste d'entites d'un referentiel dans le quel on veut * differencier les entites qui sont desactivees. diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ObserveContentUI.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ObserveContentUI.java index 5c8799b..4d736c2 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ObserveContentUI.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ObserveContentUI.java @@ -41,8 +41,6 @@ import javax.swing.JToolBar; */ public interface ObserveContentUI<E extends IdDto> extends JAXXObject { - String CLIENT_PROPERTY_LIST_PREDICATE = "listPredicate"; - String CLIENT_PROPERTY_LIST_NO_LOAD = "listNoLoad"; String CLIENT_PROPERTY_ENTITY_CLASS = "entityClass"; diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUI.css b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUI.css index aae257d..d919ca3 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUI.css +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUI.css @@ -29,7 +29,7 @@ } #listHeader { - beanType:{ReferenceDto.class}; + beanType:{(Class)ReferenceDto.class}; _doInit:{getModel().getChildType()}; showReset:true; list:{list}; diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUI.jaxx b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUI.jaxx index 8b0fffc..6180809 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUI.jaxx +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUI.jaxx @@ -57,8 +57,8 @@ <script><![CDATA[ -public final ReferenceDto getSelectedData() { - return (ReferenceDto) getSelectedBean(list); +public final ReferenceDto<C> getSelectedData() { + return (ReferenceDto<C>) getSelectedBean(list); } public final List<ReferenceDto> getSelectedDatas() { @@ -75,7 +75,7 @@ public final List<ReferenceDto> getSelectedDatas() { <JList id='list' onMouseClicked='getHandler().onDataSelected(event)'/> - <BeanListHeader id='listHeader' genericType='ReferenceDto' _entityClass="getModel().getChildType()"/> + <BeanListHeader id='listHeader' genericType='ReferenceDto< C >' _entityClass="getModel().getChildType()"/> </JScrollPane> diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java index 68f7e19..b6db1fe 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java @@ -64,7 +64,7 @@ public abstract class ContentListUIHandler<E extends IdDto, C extends IdDto> ext * @param bean the container of entities to display * @return the list of entities to display */ - protected abstract List<ReferenceDto> getChilds(E bean); + protected abstract List<ReferenceDto<C>> getChilds(E bean); @Override protected boolean computeCanWrite(ObserveSwingDataSource source) { @@ -130,7 +130,7 @@ public abstract class ContentListUIHandler<E extends IdDto, C extends IdDto> ext loadParentBean(); E bean = getBean(); - List<ReferenceDto> data = getChilds(bean); + List<ReferenceDto<C>> data = getChilds(bean); model.setData(data); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java index ff6699f..620c684 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java @@ -114,7 +114,7 @@ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLonglin } @Override - protected List<ReferenceDto> getChilds(TripLonglineDto bean) { + protected List<ReferenceDto<ActivityLonglineDto>> getChilds(TripLonglineDto bean) { ActivityLonglineService service = ObserveSwingApplicationContext.get().newService(ActivityLonglineService.class); ReferenceSetDto<ActivityLonglineDto> activityLonglineStubByRoute = service.getActivityLonglineByTripLongline(bean.getId()); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIModel.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIModel.java index bc0966d..2f54ec9 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIModel.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIModel.java @@ -22,11 +22,9 @@ package fr.ird.observe.ui.content.list.impl.longline; * #L% */ -import fr.ird.observe.ObserveSwingBinderService; import fr.ird.observe.services.dto.longline.ActivityLonglineDto; import fr.ird.observe.services.dto.longline.TripLonglineDto; import fr.ird.observe.ui.content.list.ContentListUIModel; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java index e05c7c1..620bcab 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java @@ -97,7 +97,7 @@ public class TripLonglinesUIHandler extends ContentListUIHandler<ProgramDto, Tri } @Override - protected List<ReferenceDto> getChilds(ProgramDto bean) { + protected List<ReferenceDto<TripLonglineDto>> getChilds(ProgramDto bean) { TripLonglineService service = ObserveSwingApplicationContext.get().newService(TripLonglineService.class); ReferenceSetDto<TripLonglineDto> tripLonglineByProgram = service.getTripLonglineByProgram(bean.getId()); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIModel.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIModel.java index a3be385..332347c 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIModel.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIModel.java @@ -49,18 +49,18 @@ public class TripLonglinesUIModel extends ContentListUIModel<ProgramDto, TripLon public static final String PROPERTY_SELECTED_DATAS = "selectedDatas"; /** entité sélectionnée dans la liste */ - protected List<ReferenceDto> selectedDatas; + protected List<ReferenceDto<TripLonglineDto>> selectedDatas; public TripLonglinesUIModel() { super(ProgramDto.class, TripLonglineDto.class); } - public List<ReferenceDto> getSelectedDatas() { + public List<ReferenceDto<TripLonglineDto>> getSelectedDatas() { return selectedDatas; } - public void setSelectedDatas(List<ReferenceDto> selectedDatas) { - List<ReferenceDto> old = getSelectedDatas(); + public void setSelectedDatas(List<ReferenceDto<TripLonglineDto>> selectedDatas) { + List<ReferenceDto<TripLonglineDto>> old = getSelectedDatas(); this.selectedDatas = selectedDatas; if (log.isDebugEnabled()) { log.debug("New selected datas : " + selectedDatas); @@ -69,7 +69,7 @@ public class TripLonglinesUIModel extends ContentListUIModel<ProgramDto, TripLon } @Override - public void setData(List<ReferenceDto> data) { + public void setData(List<ReferenceDto<TripLonglineDto>> data) { super.setData(data); setSelectedDatas(null); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java index 494df6b..b0f1701 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java @@ -112,7 +112,7 @@ public class ActivitySeinesUIHandler extends ContentListUIHandler<RouteDto, Acti } @Override - protected List<ReferenceDto> getChilds(RouteDto bean) { + protected List<ReferenceDto<ActivitySeineDto>> getChilds(RouteDto bean) { ActivitySeineService service = ObserveSwingApplicationContext.get().newService(ActivitySeineService.class); ReferenceSetDto<ActivitySeineDto> activitySeineByRoute = service.getActivitySeineByRoute(bean.getId()); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java index aeb31c8..9f591c6 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java @@ -109,7 +109,7 @@ public class RoutesUIHandler extends ContentListUIHandler<TripSeineDto, RouteDto } @Override - protected List<ReferenceDto> getChilds(TripSeineDto bean) { + protected List<ReferenceDto<RouteDto>> getChilds(TripSeineDto bean) { RouteService service = ObserveSwingApplicationContext.get().newService(RouteService.class); ReferenceSetDto<RouteDto> routeByTripSeine = service.getRouteByTripSeine(bean.getId()); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java index 0333cc2..f978250 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java @@ -94,7 +94,7 @@ public class TripSeinesUIHandler extends ContentListUIHandler<ProgramDto, TripSe } @Override - protected List<ReferenceDto> getChilds(ProgramDto bean) { + protected List<ReferenceDto<TripSeineDto>> getChilds(ProgramDto bean) { TripSeineService service = ObserveSwingApplicationContext.get().newService(TripSeineService.class); ReferenceSetDto<TripSeineDto> tripSeineByProgram = service.getTripSeineByProgram(bean.getId()); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIModel.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIModel.java index 7236f31..28d8952 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIModel.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIModel.java @@ -43,8 +43,37 @@ public class TripSeinesUIModel extends ContentListUIModel<ProgramDto, TripSeineD */ private static final Log log = LogFactory.getLog(TripSeinesUIModel.class); +<<<<<<< 91f61e4c040cb3dcca05b04dcccd582b94a3145c +======= + public static final String PROPERTY_SELECTED_DATAS = "selectedDatas"; + + /** entité sélectionnée dans la liste */ + protected List<ReferenceDto<TripSeineDto>> selectedDatas; + +>>>>>>> Début de revue du code de l'application swing : y'a du boulot... public TripSeinesUIModel() { super(ProgramDto.class, TripSeineDto.class); } +<<<<<<< 91f61e4c040cb3dcca05b04dcccd582b94a3145c +======= + public List<ReferenceDto<TripSeineDto>> getSelectedDatas() { + return selectedDatas; + } + + public void setSelectedDatas(List<ReferenceDto<TripSeineDto>> selectedDatas) { + List<ReferenceDto<TripSeineDto>> old = getSelectedDatas(); + this.selectedDatas = selectedDatas; + if (log.isDebugEnabled()) { + log.debug("New selected datas : " + selectedDatas); + } + firePropertyChange(PROPERTY_SELECTED_DATAS, old, selectedDatas); + } + + @Override + public void setData(List<ReferenceDto<TripSeineDto>> data) { + super.setData(data); + setSelectedDatas(null); + } +>>>>>>> Début de revue du code de l'application swing : y'a du boulot... } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java index ce4ca00..b77f81d 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java @@ -22,8 +22,8 @@ package fr.ird.observe.ui.content.open; import fr.ird.observe.ObserveSwingApplicationContext; -import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.db.ObserveSwingDataSource; +import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.services.dto.IdDto; import fr.ird.observe.services.dto.longline.TripLonglineDto; import fr.ird.observe.services.dto.seine.TripSeineDto; @@ -100,6 +100,9 @@ public abstract class ContentOpenableUIHandler<E extends IdDto> extends ContentU ContentOpenableUI<E> ui = getUi(); + // On charge les ensembles de références utilisées dans les combobox + updateReferenceSets(true); + // on repaint le parent (le program devient alors ouvert) ObserveTreeHelper treeHelper = getTreeHelper(ui); treeHelper.reloadSelectedNode(true, true); @@ -279,8 +282,8 @@ public abstract class ContentOpenableUIHandler<E extends IdDto> extends ContentU protected final void finalizeOpenUI(ContentMode mode, boolean create) { - // utilisation du mode requis - setContentMode(mode); +// // utilisation du mode requis +// setContentMode(mode); boolean historicalData = false; diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java index 7da80d5..0b26e67 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java @@ -185,6 +185,7 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity } + setContentMode(mode); getModel().setFormDto(formDto); ActivityLonglineDtos.copyActivityLonglineDto(formDto.getForm(), bean); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java index 69c4c2c..695cd74 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java @@ -195,6 +195,7 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline formDto = getTripLonglineService().loadToEdit(tripId); } + setContentMode(mode); getModel().setFormDto(formDto); TripLonglineDtos.copyTripLonglineDto(formDto.getForm(), bean); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java index 50b65c2..ba98e15 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java @@ -213,6 +213,7 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei } + setContentMode(mode); getModel().setFormDto(formDto); ActivitySeineDtos.copyActivitySeineDto(formDto.getForm(), bean); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java index 441f15f..0e043aa 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java @@ -146,6 +146,7 @@ public class RouteUIHandler extends ContentOpenableUIHandler<RouteDto> { } + setContentMode(mode); getModel().setFormDto(formDto); RouteDtos.copyRouteDto(formDto.getForm(), editBean); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java index 60c87b6..5eeee20 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java @@ -67,7 +67,6 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeineDto> { } - @Override public TripSeineUI getUi() { return (TripSeineUI) super.getUi(); @@ -124,6 +123,7 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeineDto> { tripMap.getHandler().setConfig(config); getUi().getTripSeineTabPane().addChangeListener(new ChangeListener() { + @Override public void stateChanged(ChangeEvent e) { JTabbedPane tripSeineTabPane = (JTabbedPane) e.getSource(); @@ -134,6 +134,7 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeineDto> { if (buildTripMap) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { @@ -179,23 +180,30 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeineDto> { if (create) { // create mode - if (log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info(prefix + "create a new trip"); } formDto = getTripSeineService().preCreate(programId); + } else if (mode == ContentMode.READ) { + + // read mode + if (log.isInfoEnabled()) { + log.info(prefix + "read existing trip " + tripId); + } + formDto = getTripSeineService().loadToRead(tripId); + } else { - // update mode + // edit mode if (log.isInfoEnabled()) { - log.info(prefix + "using existing trip " + tripId); + log.info(prefix + "edit existing trip " + tripId); } formDto = getTripSeineService().loadToEdit(tripId); } - getDataSource().loadReferenceSets(formDto); - + setContentMode(mode); getModel().setFormDto(formDto); TripSeineDtos.copyTripSeineDto(formDto.getForm(), bean); 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 2ef95d4..c582143 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 @@ -42,6 +42,7 @@ import fr.ird.observe.ui.DecoratorService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; +import fr.ird.observe.ui.content.ObserveContentUI; import fr.ird.observe.ui.tree.ObserveTreeHelper; import fr.ird.observe.ui.usage.UsagesUI; import fr.ird.observe.ui.util.SpringUtilities; @@ -49,6 +50,7 @@ import fr.ird.observe.validation.ValidationContext; import jaxx.runtime.JAXXContext; import jaxx.runtime.swing.CardLayout2Ext; import jaxx.runtime.swing.ErrorDialogUI; +import jaxx.runtime.swing.editor.bean.BeanComboBox; import jaxx.runtime.swing.editor.bean.BeanListHeader; import jaxx.runtime.validator.swing.SwingValidatorUtil; import org.apache.commons.lang3.StringUtils; @@ -56,6 +58,9 @@ import org.apache.commons.lang3.time.FastDateFormat; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; +import org.nuiton.decorator.DecoratorUtil; +import org.nuiton.decorator.JXPathDecorator; +import org.nuiton.jaxx.widgets.select.FilterableDoubleList; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -86,6 +91,8 @@ import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -465,7 +472,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content ContentReferenceUIModel<E> model = getModel(); // Chargement des données - uiInitializer.referentialDataUpdated(); + updateReferenceSets(true); ContentReferenceUI<E> ui = getUi(); @@ -641,7 +648,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content addInfoMessage(t("observe.message.referentiel.editable")); } - uiInitializer.referentialDataUpdated(); + updateReferenceSets(false); } @Override @@ -904,4 +911,84 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content return ObserveSwingApplicationContext.get().newService(ReferentialService.class); } + @Override + protected <R extends IdDto> void updateData(BeanComboBox<ReferenceDto<R>> comboBox) { + + Class<R> dtoClass = getDtoClass(comboBox); + + Boolean noLoad = (Boolean) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_NO_LOAD); + + List<ReferenceDto<R>> data; + + if (noLoad != null && noLoad) { + + 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<R> referentialReferenceSet = getReferentialService().getReferentialReferenceSet((Class) dtoClass); + LinkedHashSet<ReferenceDto<R>> reference = referentialReferenceSet.getReference(); + + data.addAll(reference); + + } + + if (log.isInfoEnabled()) { + log.info("entity list [" + dtoClass.getName() + "] : " + data.size()); + } + + comboBox.setData(data); + } + + @Override + protected <R extends IdDto> void updateData(BeanListHeader<ReferenceDto<R>> list) { + + Class<R> dtoClass = getDtoClass(list); + + // Attention ici on charge les references avec aussi les données techniques + // On en a besoin pour l'écran justement des informations techniques d'une entité en cours d'édition + ReferenceSetDto<R> referentialReferenceSet = getReferentialService().getReferentialReferenceSetWithTechnicalInformations((Class) dtoClass); + + List<ReferenceDto<R>> data = new ArrayList<>(referentialReferenceSet.getReference()); + + Decorator<ReferenceDto<R>> decorator = getReferenceDecorator(dtoClass); + DecoratorUtil.sort((JXPathDecorator<ReferenceDto<R>>) decorator, data, 0); + + list.setData(data); + list.putClientProperty("data", data); + } + + @Override + protected <R extends IdDto> void updateData(FilterableDoubleList<ReferenceDto<R>> list) { + Class<R> dtoClass = getDtoClass(list); + List<ReferenceDto<R>> data; + + if (ReferentialDto.class.isAssignableFrom(dtoClass)) { + + ReferentialService service = getReferentialService(); + ReferenceSetDto<R> referentialReferenceSet = service.getReferentialReferenceSet((Class) dtoClass); + + data = new ArrayList<>(referentialReferenceSet.getReference()); + + } else { + + data = new ArrayList<>(); + + } + + // sort data from first decorator context + Decorator<ReferenceDto<R>> decorator = getReferenceDecorator(dtoClass); + DecoratorUtil.sort((JXPathDecorator<ReferenceDto<R>>) decorator, data, 0); + + list.setUniverse(data); + list.putClientProperty("data", data); + } + + } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java index 9e835ba..88f9116 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java @@ -22,27 +22,8 @@ package fr.ird.observe.ui.content.ref; * #L% */ -import fr.ird.observe.ObserveSwingApplicationContext; -import fr.ird.observe.services.dto.ReferenceDto; -import fr.ird.observe.services.dto.ReferenceSetDto; import fr.ird.observe.services.dto.referential.ReferentialDto; -import fr.ird.observe.services.service.ReferentialService; import fr.ird.observe.ui.content.ContentUIInitializer; -import fr.ird.observe.ui.content.ObserveContentUI; -import jaxx.runtime.swing.editor.bean.BeanComboBox; -import jaxx.runtime.swing.editor.bean.BeanListHeader; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.decorator.DecoratorUtil; -import org.nuiton.decorator.JXPathDecorator; -import org.nuiton.jaxx.widgets.select.FilterableDoubleList; - -import javax.swing.JComponent; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; /** * Created on 11/28/14. @@ -52,8 +33,8 @@ import java.util.List; */ public class ReferentialContentUIInitializer<E extends ReferentialDto, UI extends ContentReferenceUI<E>> extends ContentUIInitializer<E, UI> { - /** Logger. */ - private static final Log log = LogFactory.getLog(ReferentialContentUIInitializer.class); +// /** Logger. */ +// private static final Log log = LogFactory.getLog(ReferentialContentUIInitializer.class); public ReferentialContentUIInitializer(UI ui) { super(ui); @@ -69,95 +50,8 @@ public class ReferentialContentUIInitializer<E extends ReferentialDto, UI extend } - @Override - protected void updateData(BeanComboBox comboBox) { - - Class<? extends ReferentialDto> dtoClass = getDtoClass(comboBox); - - Boolean noLoad = (Boolean) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_NO_LOAD); - - List<ReferenceDto> data; - - if (noLoad != null && noLoad) { - - 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 referentialReferenceSet = getReferentialService().getReferentialReferenceSet(dtoClass); - LinkedHashSet<ReferenceDto> reference = referentialReferenceSet.getReference(); - - data.addAll(reference); - - } - - if (log.isInfoEnabled()) { - log.info("entity list [" + dtoClass.getName() + "] : " + data.size()); - } - - comboBox.setData(data); - } - - @Override - protected void updateData(BeanListHeader list) { - - Class<? extends ReferentialDto> dtoClass = getDtoClass(list); - - // Attention ici on charge les references avec aussi les données techniques - // On en a besoin pour l'écran justement des informations techniques d'une entité en cours d'édition - ReferenceSetDto referentialReferenceSet = getReferentialService().getReferentialReferenceSetWithTechnicalInformations(dtoClass); - - List<ReferenceDto> data = new ArrayList<>(referentialReferenceSet.getReference()); - - Decorator<ReferenceDto> decorator = getDecorator(dtoClass); - DecoratorUtil.sort((JXPathDecorator<ReferenceDto>) decorator, data, 0); - - list.setData(data); - list.putClientProperty("data", data); - } - - @Override - protected void updateData(FilterableDoubleList list) { - Class<? extends ReferentialDto> dtoClass = getDtoClass(list); - List<ReferenceDto> data; - - if (ReferentialDto.class.isAssignableFrom(dtoClass)) { - - ReferentialService service = getReferentialService(); - ReferenceSetDto referentialReferenceSet = service.getReferentialReferenceSet(dtoClass); - - data = new ArrayList<>(referentialReferenceSet.getReference()); - - } else { - - data = new ArrayList<>(); - - } - - // sort data from first decorator context - Decorator<ReferenceDto> decorator = getDecorator(dtoClass); - DecoratorUtil.sort((JXPathDecorator<ReferenceDto>) decorator, data, 0); - - list.setUniverse(data); - list.putClientProperty("data", data); - } - - protected ReferentialService getReferentialService() { - return ObserveSwingApplicationContext.get().newService(ReferentialService.class); - } - - protected Decorator<ReferenceDto> getDecorator(Class<? extends ReferentialDto> dtoClass) { - return ObserveSwingApplicationContext.get().getDecorator(ReferenceDto.class, dtoClass.getSimpleName()); - } - - protected Class<? extends ReferentialDto> getDtoClass(JComponent list) { - return (Class<? extends ReferentialDto>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_ENTITY_CLASS); - } +// protected Decorator<ReferenceDto> getDecorator(Class<? extends ReferentialDto> dtoClass) { +// return ObserveSwingApplicationContext.get().getDecorator(ReferenceDto.class, dtoClass.getSimpleName()); +// } } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java index 9598fd3..026074e 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java @@ -21,29 +21,20 @@ */ package fr.ird.observe.ui.content.table; -import com.google.common.collect.Collections2; import fr.ird.observe.ObserveSwingApplicationContext; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.db.ObserveSwingDataSource; +import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.services.dto.IdDto; -import fr.ird.observe.services.dto.ReferenceDto; -import fr.ird.observe.services.dto.ReferenceDtos; -import fr.ird.observe.services.dto.referential.ReferentialReferenceDto; -import fr.ird.observe.services.dto.referential.SpeciesDto; -import fr.ird.observe.services.dto.referential.SpeciesListDto; -import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; import fr.ird.observe.ui.content.ContentUIModel; -import fr.ird.observe.ui.content.ObserveContentUI; import fr.ird.observe.ui.tree.ObserveNode; import jaxx.runtime.swing.ErrorDialogUI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.validator.NuitonValidatorScope; -import javax.swing.JComponent; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; @@ -51,11 +42,7 @@ import javax.swing.table.DefaultTableCellRenderer; import java.awt.Rectangle; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -261,43 +248,12 @@ public abstract class ContentTableUIHandler<E extends IdDto, D extends IdDto> ex getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_FORM_DTO, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - uiInitializer.referentialDataUpdated(); + updateReferenceSets(false); } }); } - //FIXME Ne plus utiliser cela mais directement le labelSet sur la propriété Species qui contient la liste des espèces - public Set<String> loadSpeciesList(String speciesListId, String errorMessage) { - - Set<String> speciesIds; - - try { - ReferenceDto<SpeciesListDto> speciesList = getModel().getFormDto().getReferenceById(SpeciesListDto.class, speciesListId); - LinkedHashSet<ReferentialReferenceDto<SpeciesDto>> species = - (LinkedHashSet<ReferentialReferenceDto<SpeciesDto>>) speciesList.getPropertyValue(SpeciesListDto.PROPERTY_SPECIES); - speciesIds = new HashSet<>(Collections2.transform(species, - ReferenceDtos.newReferenceDtoIdFunction())); - - } catch (Exception e) { - UIHelper.displayWarning(t("observe.title.speciesList.not.found"), t(errorMessage)); - speciesIds = Collections.emptySet(); - - } - return speciesIds; - - } - - //FIXME Ne plus utiliser cela mais directement le labelSet sur la propriété Species qui contient la liste des espèces - protected void prepareSpeciesList(String speciesListId, JComponent speciesComponent, String errorMessage) { - - Set<String> speciesIds = loadSpeciesList(speciesListId, errorMessage); - - speciesComponent.putClientProperty( - ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE, - ReferenceDtos.newContainsIdPredicate(speciesIds)); - } - @Override public void openUI() throws Exception { diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index 0169cd4..a4f40db 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -90,6 +90,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat // Compute valid state of tab from the error table protected final TableModelListener computeTabValidStateListener = new TableModelListener() { + @Override public void tableChanged(TableModelEvent e) { @@ -100,6 +101,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat }; private final PropertyChangeListener catchFateChanged = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { onCatchFateChanged((ReferenceDto<CatchFateLonglineDto>) evt.getNewValue(), (CatchLonglineDto) evt.getSource()); @@ -107,6 +109,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat }; private final PropertyChangeListener branchlineChanged = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { onBranchlineChanged((ReferenceDto<BranchlineDto>) evt.getNewValue()); @@ -114,6 +117,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat }; private final PropertyChangeListener depredatedChanged = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { onDepretadedChanged((Boolean) evt.getNewValue(), (CatchLonglineDto) evt.getSource()); @@ -369,13 +373,13 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, ReferenceDto.class, SizeMeasureTypeDto.class.getSimpleName())); UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - Decorator<ReferenceDto> decorator = ObserveSwingApplicationContext.get().getDecorator(ReferenceDto.class, SizeMeasureTypeDto.class.getSimpleName()); + Decorator<ReferenceDto<SizeMeasureTypeDto>> decorator = getReferenceDecorator(SizeMeasureTypeDto.class); ReferentialService referentialService = ObserveSwingApplicationContext.get().newService(ReferentialService.class); ReferenceSetDto<SizeMeasureTypeDto> sizeMeasureTypeDtoRefSet = referentialService.getReferentialReferenceSet(SizeMeasureTypeDto.class); - ArrayList<ReferenceDto> sizeMeasureTypes = Lists.newArrayList(sizeMeasureTypeDtoRefSet.getReference()); + ArrayList<ReferenceDto<SizeMeasureTypeDto>> sizeMeasureTypes = Lists.newArrayList(sizeMeasureTypeDtoRefSet.getReference()); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(sizeMeasureTypes, decorator)); UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); @@ -399,13 +403,13 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, ReferenceDto.class, WeightMeasureTypeDto.class.getSimpleName())); UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - Decorator<ReferenceDto> decorator = ObserveSwingApplicationContext.get().getDecorator(ReferenceDto.class, WeightMeasureTypeDto.class.getSimpleName()); + Decorator<ReferenceDto<WeightMeasureTypeDto>> decorator = getReferenceDecorator(WeightMeasureTypeDto.class); ReferentialService referentialService = ObserveSwingApplicationContext.get().newService(ReferentialService.class); ReferenceSetDto<WeightMeasureTypeDto> weightMeasureTypeDtoRefSet = referentialService.getReferentialReferenceSet(WeightMeasureTypeDto.class); - ArrayList<ReferenceDto> weightMeasureTypes = Lists.newArrayList(weightMeasureTypeDtoRefSet.getReference()); + ArrayList<ReferenceDto<WeightMeasureTypeDto>> weightMeasureTypes = Lists.newArrayList(weightMeasureTypeDtoRefSet.getReference()); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(weightMeasureTypes, decorator)); UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); @@ -417,6 +421,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat } getTableModel().addPropertyChangeListener(ContentTableModel.CREATE_PROPERTY, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { Boolean oldValue = (Boolean) evt.getOldValue(); @@ -438,6 +443,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat uiInitializer.initUI(); getModel().addPropertyChangeListener(CatchLonglineUIModel.PROPERTY_SHOW_INDIVIDUAL_TABS, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { Boolean newValue = (Boolean) evt.getNewValue(); @@ -446,6 +452,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat }); getModel().addPropertyChangeListener(CatchLonglineUIModel.PROPERTY_EDITABLE, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { Boolean newValue = (Boolean) evt.getNewValue(); @@ -454,15 +461,16 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat }); getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_FORM_DTO, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { - uiInitializer.referentialDataUpdated(); + updateReferenceSets(false); } }); setTableModelEditable(getModel().isEditable()); - LonglinePositionHelper<CatchLonglineDto> positionHelper = new LonglinePositionHelper<CatchLonglineDto>( + LonglinePositionHelper<CatchLonglineDto> positionHelper = new LonglinePositionHelper<>( getUi().getSection(), getUi().getBasket(), getUi().getBranchline(), @@ -509,9 +517,9 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat LonglinePositionHelper<CatchLonglineDto> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); positionHelper.initSections(formDto.getReferenceSetDto(SectionDto.class, CatchLonglineDto.PROPERTY_SECTION), - formDto.getReferenceSetDto(BasketDto.class, CatchLonglineDto.PROPERTY_BASKET), - formDto.getReferenceSetDto(BranchlineDto.class, CatchLonglineDto.PROPERTY_BRANCHLINE), - formDto.getForm().getCatchLongline()); + formDto.getReferenceSetDto(BasketDto.class, CatchLonglineDto.PROPERTY_BASKET), + formDto.getReferenceSetDto(BranchlineDto.class, CatchLonglineDto.PROPERTY_BRANCHLINE), + formDto.getForm().getCatchLongline()); SetLonglineCatchDtos.copySetLonglineCatchDto(formDto.getForm(), getBean()); @@ -791,7 +799,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat protected void computeTabValidState(SwingValidatorMessageTableModel errorTableModel) { - Set<String> errorProperties = new HashSet<String>(); + Set<String> errorProperties = new HashSet<>(); int rowCount = errorTableModel.getRowCount(); for (int i = 0; i < rowCount; i++) { diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index 41d6668..9445037 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -94,6 +94,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip // Compute valid state of tab from the error table protected final TableModelListener computeTabValidStateListener = new TableModelListener() { + @Override public void tableChanged(TableModelEvent e) { @@ -222,7 +223,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip n("observe.gearUseFeaturesLongline.table.comment"), n("observe.gearUseFeaturesLongline.table.comment.tip")); - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, ReferenceDto.class, GearDto.class.getSimpleName())); + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, ReferenceDto.class, GearDto.class.getSimpleName())); UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); UIHelper.setTableColumnRenderer(table, 2, UIHelper.newBooleanTableCellRenderer(renderer)); UIHelper.setTableColumnRenderer(table, 3, UIHelper.newStringTableCellRenderer(renderer, 10, true)); @@ -243,13 +244,13 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip table.getTableHeader().setReorderingAllowed(false); - Decorator<ReferenceDto> decorator = ObserveSwingApplicationContext.get().getDecorator(ReferenceDto.class, GearCaracteristicDto.class.getSimpleName()); + Decorator<ReferenceDto<GearCaracteristicDto>> decorator = getReferenceDecorator(GearCaracteristicDto.class); ReferentialService referentialService = ObserveSwingApplicationContext.get().newService(ReferentialService.class); ReferenceSetDto<GearCaracteristicDto> gearCaracteristicDtoRefSet = referentialService.getReferentialReferenceSet(GearCaracteristicDto.class); - ArrayList<ReferenceDto> gearCaracteristics = Lists.newArrayList(gearCaracteristicDtoRefSet.getReference()); + ArrayList<ReferenceDto<GearCaracteristicDto>> gearCaracteristics = Lists.newArrayList(gearCaracteristicDtoRefSet.getReference()); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(gearCaracteristics, decorator)); UIHelper.setTableColumnEditor(table, 1, new GearUseFeatureMeasurementCellEditor(0)); @@ -287,6 +288,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip super.initUI(); getModel().addPropertyChangeListener(GearUseFeaturesLonglineUIModel.PROPERTY_EDITABLE, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { Boolean newValue = (Boolean) evt.getNewValue(); @@ -349,7 +351,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip if (!selectionEmpty) { - GearUseFeaturesMeasurementLonglineDto data = tableModel.getSelectedRow(); + GearUseFeaturesMeasurementLonglineDto data = tableModel.getSelectedRow(); if (log.isInfoEnabled()) { log.info("Delete: " + data); @@ -443,7 +445,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip protected void computeTabValidState(SwingValidatorMessageTableModel errorTableModel) { - Set<String> errorProperties = new HashSet<String>(); + Set<String> errorProperties = new HashSet<>(); int rowCount = errorTableModel.getRowCount(); for (int i = 0; i < rowCount; i++) { @@ -471,14 +473,15 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip List<GearUseFeaturesMeasurementLonglineDto> measurements = Lists.newArrayList( Iterables.transform(gearDto.getGearCaracteristic(), - new Function<ReferentialReferenceDto<GearCaracteristicDto>, GearUseFeaturesMeasurementLonglineDto>() { - @Override - public GearUseFeaturesMeasurementLonglineDto apply(ReferentialReferenceDto<GearCaracteristicDto> input) { - GearUseFeaturesMeasurementLonglineDto measurementLonglineDto = new GearUseFeaturesMeasurementLonglineDto(); - measurementLonglineDto.setGearCaracteristic(input); - return measurementLonglineDto; - } - })); + new Function<ReferentialReferenceDto<GearCaracteristicDto>, GearUseFeaturesMeasurementLonglineDto>() { + + @Override + public GearUseFeaturesMeasurementLonglineDto apply(ReferentialReferenceDto<GearCaracteristicDto> input) { + GearUseFeaturesMeasurementLonglineDto measurementLonglineDto = new GearUseFeaturesMeasurementLonglineDto(); + measurementLonglineDto.setGearCaracteristic(input); + return measurementLonglineDto; + } + })); return measurements; } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index 14f209a..c76fbe8 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -239,13 +239,13 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei table.getTableHeader().setReorderingAllowed(false); - Decorator<ReferenceDto> decorator = ObserveSwingApplicationContext.get().getDecorator(ReferenceDto.class, GearCaracteristicDto.class.getSimpleName()); + Decorator<ReferenceDto<GearCaracteristicDto>> decorator = getReferenceDecorator(GearCaracteristicDto.class); ReferentialService referentialService = ObserveSwingApplicationContext.get().newService(ReferentialService.class); ReferenceSetDto<GearCaracteristicDto> gearCaracteristicDtoRefSet = referentialService.getReferentialReferenceSet(GearCaracteristicDto.class); - ArrayList<ReferenceDto> gearCaracteristics = Lists.newArrayList(gearCaracteristicDtoRefSet.getReference()); + ArrayList<ReferenceDto<GearCaracteristicDto>> gearCaracteristics = Lists.newArrayList(gearCaracteristicDtoRefSet.getReference()); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(gearCaracteristics, decorator)); UIHelper.setTableColumnEditor(table, 1, new GearUseFeatureMeasurementCellEditor(0)); diff --git a/observe-application-swing/src/main/resources/observe-log4j.properties b/observe-application-swing/src/main/resources/observe-log4j.properties index 027fd89..61ae1eb 100644 --- a/observe-application-swing/src/main/resources/observe-log4j.properties +++ b/observe-application-swing/src/main/resources/observe-log4j.properties @@ -45,7 +45,7 @@ log4j.logger.fr.ird.observe.entities.Entities=DEBUG log4j.logger.fr.ird.observe.validation.field=WARN log4j.logger.fr.ird.observe.ui.tree=INFO -log4j.logger.fr.ird.observe.decorator.ObserveDecorator=ERROR +log4j.logger.fr.ird.observe.ui.util.decorator=ERROR log4j.logger.org.nuiton.topia.migration=INFO log4j.logger.org.nuiton.config=INFO -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.