This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 1ca68ba6afeffe30caeb4fd7531627aee59539d4 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon May 4 15:26:42 2015 +0200 correction initStorage, toujour utilisé les valeurs des combobox pour la positiond'une ligne --- .../ObserveServiceFactoryProviderTopia.java | 11 +- .../data/longline/ActivityLonglineServiceImpl.java | 2 +- .../data/longline/SetLonglineServiceImpl.java | 35 ++--- .../main/java/fr/ird/observe/ObserveContext.java | 149 +++++++++++---------- .../impl/longline/LonglinePositionHelper.java | 48 +++++-- 5 files changed, 142 insertions(+), 103 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java index 8e8b951..da22f6a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java @@ -7,6 +7,8 @@ import fr.ird.observe.db.DataSource; import fr.ird.observe.db.impl.H2DataSource; import fr.ird.observe.db.impl.PGDataSource; import org.apache.commons.lang3.reflect.ConstructorUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; import java.lang.reflect.InvocationHandler; @@ -23,11 +25,7 @@ import java.util.Set; */ public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactoryProvider { -// private ObserveApplicationContext applicationContext; -// -// public void setApplicationContext(ObserveApplicationContext applicationContext) { -// this.applicationContext = applicationContext; -// } + private static final Log log = LogFactory.getLog(ObserveServiceFactoryProviderTopia.class); @Override public boolean acceptDataSource(DataSource dataSource) { @@ -134,6 +132,9 @@ public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactory Object result = method.invoke(target, args); return result; } catch (InvocationTargetException e) { + if (log.isErrorEnabled()) { + log.error("Error in method " + method.getName(), e); + } throw e.getCause(); } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index d2bb21a..43b3dd8 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -100,7 +100,7 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen public ActivityLongline onCreate(TripLongline parent, ActivityLongline toCreate) { ActivityLongline created = getDao().create(); - copy(ActivityLongline.class, BinderService.EDIT, toCreate, created); + copy(ActivityLongline.class, BinderService.EDIT, toCreate, created, false); parent.addActivityLongline(created); return created; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java index ad7c4da..1ed6810 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -1,5 +1,6 @@ package fr.ird.observe.services.data.longline; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Basket; @@ -9,7 +10,6 @@ import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SetLonglineDAO; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.lang3.time.DateUtils; -import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.TopiaDAO; import java.util.Date; @@ -27,36 +27,37 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se TopiaDAO<Section> dao = getDao(Section.class); - List<Section> sections = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); + List<Section> sectionsSaved = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); - if (!sections.isEmpty()) { + List<Section> sections = Lists.newLinkedList(); - Decorator<Section> sectionDecorator = getDecoratorByType(Section.class, null); - Decorator<Basket> basketDecorator = getDecoratorByType(Basket.class, null); - Decorator<Branchline> branchlineDecorator = getDecoratorByType(Branchline.class, null); + for (Section sectionSaved : sectionsSaved) { - for (Section section : sections) { + Section section = dao.newInstance(); - sectionDecorator.toString(section); + copyExcluding(Section.class, BinderService.EDIT_DETAIL_COMPOSITION, sectionSaved, section, Section.PROPERTY_BASKET); - if (!section.isBasketEmpty()) { + for (Basket basketSaved : sectionSaved.getBasket()) { - for (Basket basket : section.getBasket()) { + Basket basket = getDao(Basket.class).newInstance(); - basketDecorator.toString(basket); + copyExcluding(Basket.class, BinderService.EDIT_DETAIL_COMPOSITION, basketSaved, basket, Basket.PROPERTY_BRANCHLINE); - if (!basket.isBranchlineEmpty()) { + for (Branchline branchlineSaved : basketSaved.getBranchline()) { - for (Branchline branchline : basket.getBranchline()) { + Branchline branchline = getDao(Branchline.class).newInstance(); - branchlineDecorator.toString(branchline); + copy(Branchline.class, BinderService.EDIT_DETAIL_COMPOSITION, branchlineSaved, branchline); - } - } + basket.addBranchline(branchline); - } } + + section.addBasket(basket); + } + + sections.add(section); } return sections; diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java index 5f1713a..0d05c39 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java @@ -24,6 +24,7 @@ package fr.ird.observe; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListenerAdapter; import fr.ird.observe.db.impl.H2DataSource; @@ -31,8 +32,10 @@ import fr.ird.observe.services.ObserveService; import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.OpenableService; import fr.ird.observe.ui.ObserveMainUI; +import fr.ird.observe.ui.ObserveMainUIHandler; import fr.ird.observe.ui.ObserveUIMode; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.actions.ChangeStorageAction; import fr.ird.observe.ui.actions.shared.AbstractUIAction; import fr.ird.observe.ui.actions.shared.CancelCreateUIAction; import fr.ird.observe.ui.actions.shared.CloseAndCreateUIAction; @@ -63,6 +66,7 @@ import java.awt.Component; import java.util.Arrays; import java.util.List; +import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; /** @@ -246,78 +250,79 @@ public class ObserveContext extends ObserveApplicationContext { return services; } -// public void initStorage(ObserveConfig config, -// ObserveMainUI mainUI, -// boolean askToCreate) { -// try { -// if (config.isLocalStorageExist()) { -// -// // une base locale existe, on l'ouvre -// loadLocalStorage(); -// -// // on peut retourner sur cette base -// mainUI.setMode(ObserveUIMode.DB); -// } else { -// -// // on peut retourner sur cette base -// mainUI.setMode(ObserveUIMode.NO_DB); -// -// if (askToCreate) { -// -// // demande à l'utilisateur s'il veut créer la base locale -// createStorage(config, mainUI.getHandler()); -// } -// } -// if (log.isInfoEnabled()) { -// log.info(t("observe.init.storage.done")); -// } -// } catch (Exception e) { -// ErrorDialogUI.showError(e); -// if (log.isErrorEnabled()) { -// log.error(e.getMessage(), e); -// } -// } -// } - -// protected void createStorage(ObserveConfig config, -// ObserveMainUIHandler uiHandler) { -// -// int reponse = UIHelper.askUser( -// t("observe.title.no.local.db.found"), -// t("observe.message.no.local.db.found", -// config.getLocalDBDirectory()), -// JOptionPane.QUESTION_MESSAGE, -// new Object[]{ -// t("observe.choice.useRemoteStorage"), -// t("observe.choice.createLocalStorage"), -// t("observe.choice.doNothing") -// }, -// 1 -// ); -// if (log.isDebugEnabled()) { -// log.debug("response : " + reponse); -// } -// -// DbMode dbMode = null; -// String title = null; -// if (reponse != JOptionPane.CLOSED_OPTION && reponse < 2) { -// -// if (reponse == 1) { -// // creation de la base locale -// dbMode = DbMode.CREATE_LOCAL; -// title = n("observe.title.create.local.db"); -// } else { -// // connexion à une base distante -// dbMode = DbMode.USE_REMOTE; -// title = n("observe.title.load.remote.db"); -// } -// } -// if (dbMode != null) { -//// uiHandler.launchChangeStorage(getObserveMainUI(), dbMode, title); -// -// new ChangeStorageAction(getObserveMainUI(), dbMode, title).run(); -// } -// } + public void initStorage(ObserveConfig config, + ObserveMainUI mainUI, + boolean askToCreate) { + try { + if (config.isLocalStorageExist()) { + + // une base locale existe, on l'ouvre + loadLocalStorage(); + + // on peut retourner sur cette base + mainUI.setMode(ObserveUIMode.DB); + } else { + + // on peut retourner sur cette base + mainUI.setMode(ObserveUIMode.NO_DB); + + if (askToCreate) { + + // demande à l'utilisateur s'il veut créer la base locale + createStorage(config, mainUI.getHandler()); + } + } + if (log.isInfoEnabled()) { + log.info(t("observe.init.storage.done")); + } + } catch (Exception e) { + ErrorDialogUI.showError(e); + if (log.isErrorEnabled()) { + log.error(e.getMessage(), e); + } + } + } + + protected void createStorage(ObserveConfig config, + ObserveMainUIHandler uiHandler) { + + int reponse = UIHelper.askUser( + t("observe.title.no.local.db.found"), + t("observe.message.no.local.db.found", + config.getLocalDBDirectory()), + JOptionPane.QUESTION_MESSAGE, + new Object[]{ + t("observe.choice.useRemoteStorage"), + t("observe.choice.createLocalStorage"), + t("observe.choice.doNothing") + }, + 1 + ); + if (log.isDebugEnabled()) { + log.debug("response : " + reponse); + } + + DbMode dbMode = null; + String title = null; + if (reponse != JOptionPane.CLOSED_OPTION && reponse < 2) { + + if (reponse == 1) { + // creation de la base locale + dbMode = DbMode.CREATE_LOCAL; + title = n("observe.title.create.local.db"); + } else { + // connexion à une base distante + dbMode = DbMode.USE_REMOTE; + title = + n("observe.title.load.remote.db"); + } + } + if (dbMode != null) { +// uiHandler.launchChangeStorage(getObserveMainUI(), dbMode, title); + + new ChangeStorageAction(getObserveMainUI(), dbMode, title).run(); + } + } protected void loadLocalStorage() throws Exception { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java index f2f9e31..69c4b5d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java @@ -22,6 +22,9 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ +import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.longline.Basket; import fr.ird.observe.entities.longline.Baskets; @@ -32,6 +35,7 @@ import fr.ird.observe.entities.longline.LonglinePositionAware; import fr.ird.observe.entities.longline.Section; import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.collections4.CollectionUtils; +import org.nuiton.topia.persistence.TopiaEntity; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -56,6 +60,9 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { // To avoid any propagation when doing some works on locations protected boolean locationIsAdjusting; + // si l'entité est en cour de modification + protected boolean entityAdjusting; + List<Section> sectionUniverse; List<Basket> basketUniverse; @@ -72,7 +79,9 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { PropertyChangeListener sectionChanged = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - onSectionChanged((Section) evt.getNewValue(), (E) evt.getSource()); + if (! entityAdjusting) { + onSectionChanged((Section) evt.getNewValue(), (E) evt.getSource()); + } } }; tableEditBean.addPropertyChangeListener(CatchLongline.PROPERTY_SECTION, sectionChanged); @@ -215,7 +224,10 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { protected void onSectionChanged(Section newValue, E entity) { + Preconditions.checkState(! entityAdjusting, "entity should not be adjusting"); + locationIsAdjusting = true; + entityAdjusting = true; try { @@ -236,25 +248,31 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { if (newValue != null) { + Section newValueInUniverse = findInList(sectionUniverse, newValue.getTopiaId()); + entity.setSection(newValueInUniverse); + // une section est sélectionnée // on remplit uniquement les paniers de cette section - List<Basket> baskets = newValue.getBasket(); + List<Basket> baskets = newValueInUniverse.getBasket(); uiBasket.setData(baskets); if (basket != null && baskets.contains(basket)) { // un panier est sélectionné + Basket basketInUniverse = findInList(baskets, basket.getTopiaId()); + // on repmlit uniquement les avançons du panier - List<Branchline> branchlines = basket.getBranchline(); + List<Branchline> branchlines = basketInUniverse.getBranchline(); uiBranchline.setData(branchlines); - entity.setBasket(basket); + entity.setBasket(basketInUniverse); if (branchline != null && branchlines.contains(branchline)) { // un avançon est sélectionné - entity.setBranchline(branchline); + Branchline branchlineInUniverse = findInList(branchlines, branchline.getTopiaId()); + entity.setBranchline(branchlineInUniverse); } @@ -263,13 +281,25 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { } } finally { - + entityAdjusting = false; locationIsAdjusting = false; } } + protected <F extends TopiaEntity> F findInList(List<F> entities, final String topiaId) { + F result = Iterables.find(entities, new Predicate<F>() { + @Override + public boolean apply(F input) { + return topiaId.equals(input.getTopiaId()); + + } + }, null); + return result; + } + + protected void onBasketChanged(Basket newValue, E entity) { if (!locationIsAdjusting) { @@ -282,12 +312,14 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { // on vide l'ensemble des avançons uiBranchline.setData(Collections.<Branchline>emptyList()); - if (newValue != null) { + if (newValue != null && ! uiBasket.isEmpty()) { // un panier est selectionne + Basket newValueInUniverse = findInList(uiBasket.getData(), newValue.getTopiaId()); + // on remplit uniquement les avançons des paniers - List<Branchline> branchlines = newValue.getBranchline(); + List<Branchline> branchlines = newValueInUniverse.getBranchline(); uiBranchline.setData(branchlines); if (branchline != null && branchlines.contains(branchline)) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.