Author: tchemit Date: 2012-12-21 22:48:13 +0100 (Fri, 21 Dec 2012) New Revision: 107 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/107 Log: add message listener Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/UIMessageNotifier.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/CaracteristicRow.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2012-12-21 20:52:54 UTC (rev 106) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2012-12-21 21:48:13 UTC (rev 107) @@ -32,6 +32,7 @@ import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.ui.swing.config.TuttiConfig; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import fr.ifremer.tutti.ui.swing.util.UIMessageNotifier; import fr.ifremer.tutti.ui.swing.util.editor.SimpleTimeEditor; import jaxx.runtime.swing.editor.NumberEditor; import jaxx.runtime.swing.editor.bean.BeanComboBox; @@ -68,7 +69,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.1 */ -public abstract class AbstractTuttiUIHandler<M> { +public abstract class AbstractTuttiUIHandler<M> implements UIMessageNotifier { /** Logger. */ private static final Log log = @@ -88,6 +89,11 @@ this.context = context; } + @Override + public void showInformationMessage(String message) { + context.showInformationMessage(message); + } + public TuttiUIContext getContext() { return context; } @@ -288,6 +294,10 @@ return decorator; } + protected String decorate(Object object) { + return getDecorator(object.getClass(), null).toString(object); + } + protected <O> ListCellRenderer newListCellRender(Class<O> type) { return newListCellRender(type, null); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java 2012-12-21 20:52:54 UTC (rev 106) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java 2012-12-21 21:48:13 UTC (rev 107) @@ -75,6 +75,7 @@ super(context); this.ui = ui; this.persistenceService = context.getService(PersistenceService.class); + context.addMessageNotifier(this); } @Override @@ -308,6 +309,11 @@ } } + @Override + public final void showInformationMessage(String message) { + ui.getStatus().setStatus(message); + } + protected void setScreen(TuttiScreen screen) { try { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java 2012-12-21 20:52:54 UTC (rev 106) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java 2012-12-21 21:48:13 UTC (rev 107) @@ -33,6 +33,7 @@ import fr.ifremer.tutti.service.TuttiService; import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.ui.swing.config.TuttiConfig; +import fr.ifremer.tutti.ui.swing.util.UIMessageNotifier; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -51,7 +52,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.1 */ -public class TuttiUIContext extends AbstractBean implements Closeable { +public class TuttiUIContext extends AbstractBean implements Closeable, UIMessageNotifier { /** Logger. */ private static final Log log = LogFactory.getLog(TuttiUIContext.class); @@ -128,6 +129,13 @@ */ protected TuttiScreen screen; + /** + * Message notifiers. + * + * @since 0.3 + */ + protected final Set<UIMessageNotifier> messageNotifiers; + public static TuttiUIContext newContext(TuttiConfig config) { Preconditions.checkNotNull(config); Preconditions.checkState(applicationContext == null, @@ -140,6 +148,17 @@ this.config = config; this.serviceContext = new TuttiServiceContext(config.getServiceConfig()); this.swingSession = new SwingSession(getConfig().getUIConfigFile(), false); + UIMessageNotifier logMessageNotifier = new UIMessageNotifier() { + + @Override + public void showInformationMessage(String message) { + if (log.isInfoEnabled()) { + log.info(message); + } + } + }; + this.messageNotifiers = Sets.newHashSet(); + addMessageNotifier(logMessageNotifier); } public <S extends TuttiService> S getService(Class<S> serviceType) { @@ -323,8 +342,11 @@ public void close() { // Clear data references + messageNotifiers.clear(); + programId = null; cruiseId = null; + protocolId = null; IOUtils.closeQuietly(serviceContext); @@ -348,4 +370,15 @@ config.setProtocolId(protocolId); config.save(); } + + public void addMessageNotifier(UIMessageNotifier messageNotifier) { + this.messageNotifiers.add(messageNotifier); + } + + @Override + public void showInformationMessage(String message) { + for (UIMessageNotifier messageNotifier : messageNotifiers) { + messageNotifier.showInformationMessage(message); + } + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2012-12-21 20:52:54 UTC (rev 106) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIHandler.java 2012-12-21 21:48:13 UTC (rev 107) @@ -314,14 +314,21 @@ // save modified fishing operation FishingOperation toSave = beanToSave.toBean(); + showInformationMessage( + "[ Trait - Caractéristiques générales ] " + + "Sauvegarde des modifications de " + decorate(toSave) + + "."); + if (log.isInfoEnabled()) { log.info("FishingOperation " + toSave.getId() + " was modified, will save it."); } fishingOperationMonitor.clearModified(); + // persist current fishingOperation - parentUi.getHandler().saveFishingOperation(toSave); + persistenceService.saveFishingOperation(toSave); + //parentUi.getHandler().saveFishingOperation(toSave); } } @@ -341,7 +348,7 @@ model.fromBean(bean); // to be sure saisisseurs are updated - model.setSaisisseur(Lists.newArrayList(bean.getSaisisseur())); +// model.setSaisisseur(Lists.newArrayList(bean.getSaisisseur())); // to be sure combo list will be reloaded model.setStrata(null); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2012-12-21 20:52:54 UTC (rev 106) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2012-12-21 21:48:13 UTC (rev 107) @@ -125,6 +125,11 @@ " was modified, will save it."); } + showInformationMessage( + "[ Captures - Caractéristiques générales ] " + + "Sauvegarde des modifications de " + decorate(fishingOperation) + + "."); + persistenceService.saveFishingOperation(fishingOperation); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2012-12-21 20:52:54 UTC (rev 106) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2012-12-21 21:48:13 UTC (rev 107) @@ -420,6 +420,11 @@ log.info("Row " + bean + " was modified, will save it"); } + showInformationMessage( + "[ Captures - Espèces ] " + + "Sauvegarde des modifications de " + decorate(bean) + + "."); + saveRow(bean); // clear modified flag on the monitor Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/UIMessageNotifier.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/UIMessageNotifier.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/UIMessageNotifier.java 2012-12-21 21:48:13 UTC (rev 107) @@ -0,0 +1,36 @@ +package fr.ifremer.tutti.ui.swing.util; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +/** + * To notify somemessage in ui. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public interface UIMessageNotifier { + + void showInformationMessage(String message); +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/UIMessageNotifier.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/CaracteristicRow.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/CaracteristicRow.java 2012-12-21 20:52:54 UTC (rev 106) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/CaracteristicRow.java 2012-12-21 21:48:13 UTC (rev 107) @@ -1,5 +1,29 @@ package fr.ifremer.tutti.ui.swing.util.table; +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; /** Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/CaracteristicRow.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native