r421 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence tutti-service/src/main/java/fr/ifremer/tutti/service tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db
Author: tchemit Date: 2013-02-15 15:49:24 +0100 (Fri, 15 Feb 2013) New Revision: 421 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/421 Log: ajout manage db Added: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/ClosedPersistenceService.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/ManageDbAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/CloseDbAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/InstallDbAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/OpenDbAction.java Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.jaxx 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/TuttiScreen.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java Added: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java (rev 0) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,461 @@ +package fr.ifremer.tutti.persistence; + +/* + * #%L + * Tutti :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 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.data.AccidentalBatch; +import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.MacroWasteBatch; +import fr.ifremer.tutti.persistence.entities.data.PlanktonBatch; +import fr.ifremer.tutti.persistence.entities.data.Program; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.persistence.entities.referential.Country; +import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; +import fr.ifremer.tutti.persistence.entities.referential.Gear; +import fr.ifremer.tutti.persistence.entities.referential.Person; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.Vessel; +import fr.ifremer.tutti.persistence.entities.referential.Zone; + +import java.io.IOException; +import java.util.List; + +/** + * Mock implementation With no persistence at all behind. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class TuttiPersistenceNoDbImpl implements TuttiPersistence { + + @Override + public String getImplementationName() { + return "Mock persistence service implementation"; + } + + @Override + public List<Zone> getAllProgramZone() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Country> getAllCountry() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<FishingOperationLocation> getAllFishingOperationStrata(String zoneId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<FishingOperationLocation> getAllFishingOperationSubStrata(String zoneId, String strataId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<FishingOperationLocation> getAllFishingOperationLocation(String zoneId, String strataId, String subStrataId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Vessel> getAllScientificVessel() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Vessel> getAllFishingVessel() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Species> getAllSpecies() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Species> getAllReferentSpecies() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Species> getAllSpecies(TuttiProtocol protocol) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Caracteristic> getAllCaracteristic() { + throw new RuntimeException("method not implemented"); + } + + @Override + public Caracteristic getSizeCategoryCaracteristic() { + throw new RuntimeException("method not implemented"); + } + + @Override + public Caracteristic getSexCaracteristic() { + throw new RuntimeException("method not implemented"); + } + + @Override + public Caracteristic getSortedUnsortedCaracteristic() { + throw new RuntimeException("method not implemented"); + } + + @Override + public Caracteristic getMaturityCaracteristic() { + throw new RuntimeException("method not implemented"); + } + + @Override + public Caracteristic getMacroWasteCategoryCaracteristic() { + throw new RuntimeException("method not implemented"); + } + + @Override + public Caracteristic getMacroWasteSizeCategoryCaracteristic() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Gear> getAllScientificGear() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Gear> getAllFishingGear() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Person> getAllPerson() { + throw new RuntimeException("method not implemented"); + } + + @Override + public Person getPerson(Integer personId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public Gear getGear(Integer gearCode) { + throw new RuntimeException("method not implemented"); + } + + @Override + public Vessel getVessel(String vesselCode) { + throw new RuntimeException("method not implemented"); + } + + @Override + public boolean isSortedQualitativeValue(CaracteristicQualitativeValue value) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Species> importTemporarySpecies(List<Species> species) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Vessel> importTemporaryVessel(List<Vessel> vessels) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Person> importTemporaryPerson(List<Person> persons) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Gear> importTemporaryGear(List<Gear> gears) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Program> getAllProgram() { + throw new RuntimeException("method not implemented"); + } + + @Override + public Program getProgram(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public Program createProgram(Program bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public Program saveProgram(Program bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<Cruise> getAllCruise(String programId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public Cruise getCruise(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public Cruise createCruise(Cruise bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public Cruise saveCruise(Cruise bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<String> getAllProtocolNames() { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<TuttiProtocol> getAllProtocol() { + throw new RuntimeException("method not implemented"); + } + + @Override + public boolean isProtocolExist(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public TuttiProtocol getProtocol(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public TuttiProtocol createProtocol(TuttiProtocol bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public TuttiProtocol saveProtocol(TuttiProtocol bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public void deleteProtocol(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<FishingOperation> getAllFishingOperation(String cruiseId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public FishingOperation getFishingOperation(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public FishingOperation createFishingOperation(FishingOperation bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public FishingOperation saveFishingOperation(FishingOperation bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public CatchBatch getCatchBatchFromFishingOperation(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public CatchBatch createCatchBatch(CatchBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public CatchBatch saveCatchBatch(CatchBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public SpeciesBatch createSpeciesBatch(SpeciesBatch bean, String parentBatchId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public SpeciesBatch saveSpeciesBatch(SpeciesBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public void deleteSpeciesBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public void deleteSpeciesSubBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public void changeSpeciesBatchSpecies(String batchId, Species species) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(String speciesBatchId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId, List<SpeciesBatchFrequency> frequencies) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<BenthosBatch> getAllBenthosBatch(String fishingOperationId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public BenthosBatch getBenthosBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public BenthosBatch createBenthosBatch(BenthosBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public BenthosBatch saveBenthosBatch(BenthosBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public void deleteBenthosBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<PlanktonBatch> getAllPlanktonBatch(String fishingOperationId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public PlanktonBatch getPlanktonBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public PlanktonBatch createPlanktonBatch(PlanktonBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public PlanktonBatch savePlanktonBatch(PlanktonBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public void deletePlanktonBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<MacroWasteBatch> getAllMacroWasteBatch(String fishingOperationId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public MacroWasteBatch getMacroWasteBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public MacroWasteBatch createMacroWasteBatch(MacroWasteBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public MacroWasteBatch saveMacroWasteBatch(MacroWasteBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public void deleteMacroWasteBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<AccidentalBatch> getAllAccidentalBatch(String fishingOperationId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public AccidentalBatch getAccidentalBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public AccidentalBatch createAccidentalBatch(AccidentalBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public AccidentalBatch saveAccidentalBatch(AccidentalBatch bean) { + throw new RuntimeException("method not implemented"); + } + + @Override + public void deleteAccidentalBatch(String id) { + throw new RuntimeException("method not implemented"); + } + + @Override + public void init() { + } + + @Override + public void close() throws IOException { + } +} Property changes on: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/ClosedPersistenceService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/ClosedPersistenceService.java (rev 0) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/ClosedPersistenceService.java 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,71 @@ +package fr.ifremer.tutti.service; + +/* + * #%L + * Tutti :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 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.TuttiPersistenceNoDbImpl; +import fr.ifremer.tutti.persistence.config.TuttiPersistenceConfig; +import fr.ifremer.tutti.service.config.TuttiServiceConfig; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Persistence service which always use the mock driver (means db is closed). + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class ClosedPersistenceService extends PersistenceService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ClosedPersistenceService.class); + + @Override + public void init() { + + if (log.isInfoEnabled()) { + log.info("Open persistence driver " + getImplementationName()); + } + + TuttiServiceConfig serviceConfig = context.getConfig(); + + TuttiPersistenceConfig config = serviceConfig.getPersistenceConfig(); + TuttiPersistenceConfig.setInstance(config); + + driver = new TuttiPersistenceNoDbImpl(); + + if (log.isInfoEnabled()) { + log.info("Will open persistence driver " + + driver.getImplementationName()); + } + + driver.init(); + } + + @Override + public boolean isDbLoaded() { + return false; + } +} Property changes on: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/ClosedPersistenceService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-02-15 14:02:59 UTC (rev 420) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-02-15 14:49:24 UTC (rev 421) @@ -25,7 +25,7 @@ */ import fr.ifremer.tutti.persistence.TuttiPersistence; -import fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl; +import fr.ifremer.tutti.persistence.TuttiPersistenceNoDbImpl; import fr.ifremer.tutti.persistence.config.TuttiPersistenceConfig; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; @@ -47,8 +47,6 @@ import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.persistence.entities.referential.Zone; -import fr.ifremer.tutti.persistence.service.ProtocolPersistenceService; -import fr.ifremer.tutti.persistence.service.ProtocolPersistenceServiceImpl; import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; import fr.ifremer.tutti.service.config.TuttiServiceConfig; import org.apache.commons.io.IOUtils; @@ -56,7 +54,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.transaction.annotation.Transactional; -import java.io.File; import java.io.IOException; import java.util.List; @@ -89,6 +86,10 @@ return "Tutti Persistence Service"; } + public boolean isDbLoaded() { + return !(driver instanceof TuttiPersistenceNoDbImpl); + } + @Override public void init() { @@ -117,65 +118,67 @@ // still on dev driver - File storageDirectory = TuttiPersistenceDevImpl.getStorageDirectory(serviceConfig.getApplicationConfig()); +// File storageDirectory = TuttiPersistenceDevImpl.getStorageDirectory(serviceConfig.getApplicationConfig()); - if (log.isWarnEnabled()) { +// if (log.isWarnEnabled()) { +// +// log.warn("--------------------------------------------------------------------"); +// log.warn(""); +// log.warn("Could not find database directory at " + config.getDbDirectory()); +// log.warn("Will still use dev dataStorage in " + storageDirectory); +// log.warn(""); +// log.warn("--------------------------------------------------------------------"); +// } - log.warn("--------------------------------------------------------------------"); - log.warn(""); - log.warn("Could not find database directory at " + config.getDbDirectory()); - log.warn("Will still use dev dataStorage in " + storageDirectory); - log.warn(""); - log.warn("--------------------------------------------------------------------"); - } + driver = new TuttiPersistenceNoDbImpl(); - driver = new TuttiPersistenceDevImpl(serviceConfig.getApplicationConfig()) { +// driver = new TuttiPersistenceDevImpl(serviceConfig.getApplicationConfig()) { +// +// ProtocolPersistenceService protocolPersistenceService = new ProtocolPersistenceServiceImpl(); +// +// @Override +// public void init() { +// super.init(); +// +// protocolPersistenceService.init(); +// } +// +// @Override +// public boolean isProtocolExist(String id) { +// return protocolPersistenceService.isProtocolExist(id); +// } +// +// @Override +// public List<String> getAllProtocolNames() { +// return protocolPersistenceService.getAllProtocolNames(); +// } +// +// @Override +// public List<TuttiProtocol> getAllProtocol() { +// return protocolPersistenceService.getAllProtocol(); +// } +// +// @Override +// public TuttiProtocol getProtocol(String id) { +// return protocolPersistenceService.getProtocol(id); +// } +// +// @Override +// public TuttiProtocol createProtocol(TuttiProtocol bean) { +// return protocolPersistenceService.createProtocol(bean); +// } +// +// @Override +// public TuttiProtocol saveProtocol(TuttiProtocol bean) { +// return protocolPersistenceService.saveProtocol(bean); +// } +// +// @Override +// public void deleteProtocol(String id) { +// protocolPersistenceService.deleteProtocol(id); +// } +// }; - ProtocolPersistenceService protocolPersistenceService = new ProtocolPersistenceServiceImpl(); - - @Override - public void init() { - super.init(); - - protocolPersistenceService.init(); - } - - @Override - public boolean isProtocolExist(String id) { - return protocolPersistenceService.isProtocolExist(id); - } - - @Override - public List<String> getAllProtocolNames() { - return protocolPersistenceService.getAllProtocolNames(); - } - - @Override - public List<TuttiProtocol> getAllProtocol() { - return protocolPersistenceService.getAllProtocol(); - } - - @Override - public TuttiProtocol getProtocol(String id) { - return protocolPersistenceService.getProtocol(id); - } - - @Override - public TuttiProtocol createProtocol(TuttiProtocol bean) { - return protocolPersistenceService.createProtocol(bean); - } - - @Override - public TuttiProtocol saveProtocol(TuttiProtocol bean) { - return protocolPersistenceService.saveProtocol(bean); - } - - @Override - public void deleteProtocol(String id) { - protocolPersistenceService.deleteProtocol(id); - } - }; - if (log.isInfoEnabled()) { log.info("Will open persistence driver " + driver.getImplementationName()); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.css 2013-02-15 14:02:59 UTC (rev 420) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.css 2013-02-15 14:49:24 UTC (rev 421) @@ -50,7 +50,17 @@ actionIcon: exit; } +#menuActionUpdate { + _tuttiAction: {UpdateApplicationAction.class}; +} + +#menuActionManageDb { + enabled: {model.getScreen() != TuttiScreen.MANAGE_DB}; + _tuttiAction: {ManageDbAction.class}; +} + #menuActions { + enabled: {model.isDbLoaded()}; text: "tutti.menu.actions"; toolTipText: "tutti.menu.actions.tip"; mnemonic: A; @@ -92,10 +102,11 @@ _tuttiAction: {ValidateSelectedCruiseCatchesAction.class}; } -#menuReferential{ - text: "tutti.menu.referential"; - toolTipText: "tutti.menu.referential.tip"; - mnemonic: S; +#menuAdministration{ + enabled: {model.isDbLoaded()}; + text: "tutti.menu.administration"; + toolTipText: "tutti.menu.administration.tip"; + mnemonic: A; } #menuImportTemporaryReferential { @@ -103,11 +114,8 @@ _tuttiAction: {ImportTemporaryReferentialAction.class}; } -#menuUpdateReferential { - _tuttiAction: {UpdateReferentialAction.class}; -} - #menuSynchronisations { + enabled: {model.isDbLoaded()}; text: "tutti.menu.synchronisations"; toolTipText: "tutti.menu.synchronisations.tip"; mnemonic: S; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.jaxx 2013-02-15 14:02:59 UTC (rev 420) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUI.jaxx 2013-02-15 14:49:24 UTC (rev 421) @@ -58,7 +58,10 @@ <JMenu id='menuFile'> <JMenuItem id='menuFileConfiguration' onActionPerformed="getHandler().showConfig()"/> + <JMenuItem id='menuActionUpdate'/> <JSeparator/> + <JMenuItem id='menuActionManageDb'/> + <JSeparator/> <JMenuItem id='menuFileExit' onActionPerformed='getHandler().closeTutti()'/> </JMenu> @@ -72,10 +75,8 @@ <JMenuItem id='menuActionValidateCatches'/> </JMenu> - <JMenu id='menuReferential'> - + <JMenu id='menuAdministration'> <JMenuItem id='menuImportTemporaryReferential'/> - <JMenuItem id='menuUpdateReferential'/> </JMenu> <JMenu id='menuSynchronisations'> 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 2013-02-15 14:02:59 UTC (rev 420) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/MainUIHandler.java 2013-02-15 14:49:24 UTC (rev 421) @@ -31,6 +31,7 @@ import fr.ifremer.tutti.ui.swing.config.TuttiApplicationConfig; import fr.ifremer.tutti.ui.swing.config.TuttiConfigUI; import fr.ifremer.tutti.ui.swing.content.cruise.EditCruiseUI; +import fr.ifremer.tutti.ui.swing.content.db.DbManagerUI; import fr.ifremer.tutti.ui.swing.content.home.SelectCruiseUI; import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI; import fr.ifremer.tutti.ui.swing.content.program.EditProgramUI; @@ -69,7 +70,7 @@ protected JComponent currentBody; - protected final PersistenceService persistenceService; + protected PersistenceService persistenceService; protected MainUIHandler(TuttiUIContext context, MainUI ui) { super(context, ui); @@ -125,8 +126,14 @@ TuttiScreen screen; - screen = TuttiScreen.SELECT_CRUISE; + if (context.isDbExist() && context.isDbLoaded()) { + screen = TuttiScreen.SELECT_CRUISE; + } else { + + screen = TuttiScreen.MANAGE_DB; + } + context.setScreen(screen); } @@ -310,6 +317,13 @@ Icon icon; switch (screen) { default: + case MANAGE_DB: + + screenUI = new DbManagerUI(ui); + screenTitle = _("tutti.title.manageDb"); + icon = ui.getMenuActionManageDb().getIcon(); + break; + case SELECT_CRUISE: screenUI = new SelectCruiseUI(ui); @@ -462,7 +476,6 @@ title += _("tutti.title.noSelectedProtocol"); - } else { // selected protocol @@ -475,4 +488,15 @@ return title; } + public void reloadPersistenceService() { + + this.persistenceService = context.reloadPersistenceService(); + + context.setProgramId(null); + context.setProgramId(null); + } + + public PersistenceService getPersistenceService() { + return persistenceService; + } } Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/ManageDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/ManageDbAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/ManageDbAction.java 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,71 @@ +package fr.ifremer.tutti.ui.swing; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * To manage db in Tutti. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class ManageDbAction extends AbstractChangeScreenAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(ManageDbAction.class); + + public ManageDbAction(MainUIHandler handler) { + super(handler, + "mnanageDb", + "manage-db", + _("tutti.action.manageDb"), + _("tutti.action.manageDb.tip"), + true + ); + setMnemonic('P'); + } + + @Override + protected void doAction(ActionEvent e) { + if (log.isDebugEnabled()) { + log.debug("open manage db screen"); + } + getContext().setScreen(getNextScreen()); + } + + @Override + protected TuttiScreen getNextScreen() { + return TuttiScreen.MANAGE_DB; + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/ManageDbAction.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/TuttiScreen.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiScreen.java 2013-02-15 14:02:59 UTC (rev 420) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiScreen.java 2013-02-15 14:49:24 UTC (rev 421) @@ -33,6 +33,13 @@ public enum TuttiScreen { /** + * To manager db used by Tutti. + * + * @since 1.0 + */ + MANAGE_DB, + + /** * To select program and cruise. * * @since 0.1 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 2013-02-15 14:02:59 UTC (rev 420) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java 2013-02-15 14:49:24 UTC (rev 421) @@ -30,9 +30,11 @@ import fr.ifremer.tutti.persistence.RessourceClassLoader; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.Program; +import fr.ifremer.tutti.service.ClosedPersistenceService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiService; import fr.ifremer.tutti.service.TuttiServiceContext; +import fr.ifremer.tutti.service.TuttiTechnicalException; import fr.ifremer.tutti.ui.swing.config.TuttiApplicationConfig; import fr.ifremer.tutti.ui.swing.util.UIMessageNotifier; import fr.ifremer.tutti.ui.swing.util.action.TuttiActionUI; @@ -91,6 +93,10 @@ PROPERTY_CRUISE_ID, PROPERTY_PROTOCOL_ID); + public static final String PROPERTY_DB_EXIST = "dbExist"; + + public static final String PROPERTY_DB_LOADED = "dbLoaded"; + /** * Application context (only one for all the application). * @@ -126,6 +132,11 @@ */ protected final SwingSession swingSession; + /** + * Erro helper. + * + * @since 1.0 + */ protected final TuttiErrorHelper errorHelper; /** @@ -174,6 +185,20 @@ private TuttiActionUI actionUI; + /** + * Flag to know if there is an exsiting db. + * + * @since 1.0 + */ + private boolean dbExist; + + /** + * Flag to know if there is a loaded db. + * + * @since 1.0 + */ + private boolean dbLoaded; + public static TuttiUIContext newContext(TuttiApplicationConfig config) { Preconditions.checkNotNull(config); Preconditions.checkState(applicationContext == null, @@ -210,9 +235,27 @@ } public <S extends TuttiService> S getService(Class<S> serviceType) { + if (PersistenceService.class.equals(serviceType) && !useRealPersistenceService()) { + serviceType = (Class<S>) ClosedPersistenceService.class; + } return serviceContext.getService(serviceType); } + public boolean useRealPersistenceService() { + return isDbExist() && isDbLoaded(); + } + + public PersistenceService reloadPersistenceService() { + + try { + serviceContext.close(); + } catch (IOException e) { + throw new TuttiTechnicalException("Could not close services", e); + } + + return getService(PersistenceService.class); + } + public TuttiApplicationConfig getConfig() { return config; } @@ -245,11 +288,28 @@ return StringUtils.isNotBlank(programId); } - public TuttiScreen getScreen() { return screen; } + public boolean isDbExist() { + return dbExist; + } + + public void setDbExist(boolean dbExist) { + this.dbExist = dbExist; + firePropertyChange(PROPERTY_DB_EXIST, null, dbExist); + } + + public boolean isDbLoaded() { + return dbLoaded; + } + + public void setDbLoaded(boolean dbLoaded) { + this.dbLoaded = dbLoaded; + firePropertyChange(PROPERTY_DB_LOADED, null, dbLoaded); + } + public void setProgramId(String programId) { boolean oldProgramFilled = isProgramFilled(); boolean oldCruiseFilled = isCruiseFilled(); @@ -301,7 +361,6 @@ public void init() { - try { config.getServiceConfig().prepareDirectories(); } catch (IOException e) { @@ -385,70 +444,87 @@ setProtocolId(getConfig().getProtocolId()); } - //check if programId is sane - PersistenceService service = getService(PersistenceService.class); + boolean dbExists = + getConfig().getServiceConfig().getPersistenceConfig().isDbExists(); - if (isProtocolFilled()) { + setDbExist(dbExists); - if (!service.isProtocolExist(protocolId)) { + if (!dbExists) { - // not found in this db + setProtocolId(null); + setProgramId(null); + setCruiseId(null); + setDbLoaded(false); - if (log.isWarnEnabled()) { - log.warn("Remove invalid protocolId: " + protocolId); - } + } else { - setProtocolId(null); - } - } + setDbLoaded(true); - if (isProgramFilled()) { + //check if programId is sane + PersistenceService service = getService(PersistenceService.class); - Program program = service.getProgram(programId); - if (program == null) { + if (isProtocolFilled()) { - // not found in this db + if (!service.isProtocolExist(protocolId)) { - if (log.isWarnEnabled()) { - log.warn("Remove invalid programId: " + programId); + // not found in this db + + if (log.isWarnEnabled()) { + log.warn("Remove invalid protocolId: " + protocolId); + } + + setProtocolId(null); } + } - setProgramId(null); - setCruiseId(null); + if (isProgramFilled()) { - } else { + Program program = service.getProgram(programId); + if (program == null) { - if (log.isInfoEnabled()) { - log.info("ProgramId valid: " + programId); - } + // not found in this db - setProgramId(programId); + if (log.isWarnEnabled()) { + log.warn("Remove invalid programId: " + programId); + } - // test cruiseId - if (isCruiseFilled()) { + setProgramId(null); + setCruiseId(null); - Cruise cruise = service.getCruise(cruiseId); + } else { - if (cruise != null && - !cruise.getProgram().getId().equals(programId)) { - - // not matchin program, reset cruise id - cruise = null; + if (log.isInfoEnabled()) { + log.info("ProgramId valid: " + programId); } - if (cruise == null) { + setProgramId(programId); - // not found in this db + // test cruiseId + if (isCruiseFilled()) { - if (log.isWarnEnabled()) { - log.warn("Remove invalid cruiseId: " + cruiseId); + Cruise cruise = service.getCruise(cruiseId); + + if (cruise != null && + !cruise.getProgram().getId().equals(programId)) { + + // not matchin program, reset cruise id + cruise = null; } - setCruiseId(null); - } else { + if (cruise == null) { - if (log.isInfoEnabled()) { - log.info("CruiseId valid: " + cruiseId); + // not found in this db + + if (log.isWarnEnabled()) { + log.warn("Remove invalid cruiseId: " + cruiseId); + } + setCruiseId(null); + + } else { + + if (log.isInfoEnabled()) { + log.info("CruiseId valid: " + cruiseId); + } } } } Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/CloseDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/CloseDbAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/CloseDbAction.java 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,78 @@ +package fr.ifremer.tutti.ui.swing.content.db; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 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.config.TuttiPersistenceConfig; +import fr.ifremer.tutti.ui.swing.AbstractMainUITuttiAction; +import fr.ifremer.tutti.ui.swing.MainUIHandler; +import fr.ifremer.tutti.ui.swing.TuttiScreen; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * To close db attached to Tutti. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class CloseDbAction extends AbstractMainUITuttiAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(CloseDbAction.class); + + public CloseDbAction(MainUIHandler handler) { + super(handler, + "closeDb", + "close-db", + _("tutti.action.closeDb"), + _("tutti.action.closeDb.tip"), + true); + } + + @Override + protected void doAction(ActionEvent event) { + + if (log.isInfoEnabled()) { + log.info("Will close db..."); + } + + String jdbcUrl = TuttiPersistenceConfig.getInstance().getJdbcUrl(); + + getContext().setDbLoaded(false); + + getHandler().reloadPersistenceService(); + + sendMessage(String.format("La base de données '%s' est fermée.", jdbcUrl)); + + // goto the only screen possible in this state + getContext().setScreen(TuttiScreen.MANAGE_DB); + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/CloseDbAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.css 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,54 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 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% + */ +#informationLabel { + actionIcon: information; + text: {handler.updateMessage(model.isDbExist(), model.isDbLoaded())}; + horizontalAlignment: {JLabel.CENTER}; +} + +#installDbButton { + enabled: {!model.isDbExist()}; + _tuttiAction: {InstallDbAction.class}; +} + +#openDbButton { + enabled: {model.isDbExist() && !model.isDbLoaded()}; + _tuttiAction: {OpenDbAction.class}; +} + +#upgradeDbButton { + enabled: {model.isDbExist() && model.isDbLoaded()}; + _tuttiAction: {UpdateReferentialAction.class}; +} + +#closeDbButton { + enabled: {model.isDbExist() && model.isDbLoaded()}; + _tuttiAction: {CloseDbAction.class}; +} + +#exportDbButton { + enabled: false; + /*enabled: {model.isDbExist() && model.isDbLoaded()};*/ + _tuttiAction: {ExportDbAction.class}; +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.jaxx 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,67 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 - 2013 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% + --> +<JPanel id='noDbUITopPanel' layout='{new BorderLayout()}' + implements='fr.ifremer.tutti.ui.swing.TuttiUI<TuttiUIContext, DbManagerUIHandler>'> + + <import> + + fr.ifremer.tutti.ui.swing.TuttiUI + fr.ifremer.tutti.ui.swing.TuttiUIContext + fr.ifremer.tutti.ui.swing.UpdateReferentialAction + + static org.nuiton.i18n.I18n._ + </import> + + <script><![CDATA[ + + public DbManagerUI(TuttiUI parentUI) { + JAXXUtil.initContext(this, parentUI); + DbManagerUIHandler handler = new DbManagerUIHandler(parentUI.getHandler().getContext(), this); + setContextValue(handler); + handler.beforeInitUI(); + } + + protected void $afterCompleteSetup() { + handler.afterInitUI(); + } + ]]></script> + + <DbManagerUIHandler id='handler' + initializer='getContextValue(DbManagerUIHandler.class)'/> + + <TuttiUIContext id='model' + initializer='getContextValue(TuttiUIContext.class)'/> + + <JPanel id='centerPanel' layout='{new BorderLayout()}' + constraints='BorderLayout.CENTER'> + <JLabel id='informationLabel' constraints='BorderLayout.CENTER'/> + <JPanel constraints='BorderLayout.SOUTH' layout='{new GridLayout(0, 1)}'> + <JButton id='installDbButton'/> + <JButton id='openDbButton'/> + <JButton id='upgradeDbButton'/> + <JButton id='exportDbButton'/> + <JButton id='closeDbButton'/> + </JPanel> + </JPanel> +</JPanel> \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUIHandler.java 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,118 @@ +package fr.ifremer.tutti.ui.swing.content.db; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 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.ui.swing.AbstractTuttiUIHandler; +import fr.ifremer.tutti.ui.swing.TuttiUIContext; +import jaxx.runtime.validator.swing.SwingValidator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.SwingUtilities; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import static org.nuiton.i18n.I18n._; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class DbManagerUIHandler extends AbstractTuttiUIHandler<TuttiUIContext, DbManagerUI> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(DbManagerUIHandler.class); + + public DbManagerUIHandler(TuttiUIContext context, DbManagerUI ui) { + super(context, ui); + } + + @Override + public void beforeInitUI() { + context.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + String propertyName = evt.getPropertyName(); + String message; + + + } + }); + } + + public String updateMessage(boolean dbExist, boolean dbLoaded) { + String message; + + if (dbExist) { + if (dbLoaded) { + + // db loaded + message = _("tutti.information.db.loaded"); + + } else { + + // no db loaded + message = _("tutti.information.no.db.loaded"); + } + } else { + + // db does not exist + message = "tutti.information.no.db.exist"; + ui.getInformationLabel().setText(_(message)); + } + return message; + } + + @Override + public void afterInitUI() { + + initUI(ui); + + ui.applyDataBinding(DbManagerUI.BINDING_INSTALL_DB_BUTTON_ENABLED); + ui.applyDataBinding(DbManagerUI.BINDING_OPEN_DB_BUTTON_ENABLED); + ui.applyDataBinding(DbManagerUI.BINDING_CLOSE_DB_BUTTON_ENABLED); + ui.applyDataBinding(DbManagerUI.BINDING_UPGRADE_DB_BUTTON_ENABLED); + + SwingUtilities.invokeLater( + new Runnable() { + @Override + public void run() { + ui.repaint(); + } + } + ); + } + + @Override + public void onCloseUI() { + } + + @Override + public SwingValidator<TuttiUIContext> getValidator() { + return null; + } + +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,67 @@ +package fr.ifremer.tutti.ui.swing.content.db; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 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.ui.swing.AbstractMainUITuttiAction; +import fr.ifremer.tutti.ui.swing.MainUIHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * To export a db attached to Tutti. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class ExportDbAction extends AbstractMainUITuttiAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(ExportDbAction.class); + + public ExportDbAction(MainUIHandler handler) { + super(handler, + "exportDb", + "export-db", + _("tutti.action.exportDb"), + _("tutti.action.exportDb.tip"), + true); + } + + @Override + protected void doAction(ActionEvent event) { + + if (log.isInfoEnabled()) { + log.info("Will export db..."); + } + + //TODO + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/InstallDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/InstallDbAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/InstallDbAction.java 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,104 @@ +package fr.ifremer.tutti.ui.swing.content.db; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 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.ProgressionModel; +import fr.ifremer.tutti.persistence.config.TuttiPersistenceConfig; +import fr.ifremer.tutti.ui.swing.AbstractMainUITuttiAction; +import fr.ifremer.tutti.ui.swing.MainUIHandler; +import fr.ifremer.tutti.ui.swing.TuttiApplicationUpdaterCallBack; +import fr.ifremer.tutti.ui.swing.config.TuttiApplicationConfig; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationUpdater; + +import java.awt.event.ActionEvent; +import java.io.File; + +import static org.nuiton.i18n.I18n._; + +/** + * To install db when no db is attached to Tutti. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class InstallDbAction extends AbstractMainUITuttiAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(InstallDbAction.class); + + public InstallDbAction(MainUIHandler handler) { + super(handler, + "installDb", + "install-db", + _("tutti.action.installDb"), + _("tutti.action.installDb.tip"), + true); + } + + @Override + protected void doAction(ActionEvent event) { + TuttiApplicationConfig config = getContext().getConfig(); + + File current = config.getDataDirectory(); + String url = config.getUpdateUrl(); + + if (log.isInfoEnabled()) { + log.info(String.format("Try to install db (current data location: %s), using update url: %s", current, url)); + } + ApplicationUpdater up = new ApplicationUpdater(); + + File dest = new File(config.getTuttiBasedir(), "NEW"); + ProgressionModel progressionModel = new ProgressionModel(); + getContext().getActionUI().getModel().setProgressionModel(progressionModel); + progressionModel.setMessage("Recherche de mises à jour de base"); + + TuttiApplicationUpdaterCallBack callback = new TuttiApplicationUpdaterCallBack(getContext(), progressionModel); + callback.setTypes(TuttiApplicationUpdaterCallBack.UpdateType.DB); + + up.update(url, current, dest, false, callback); + + sendMessage("Nouvelle base de données installée."); + + String jdbcUrl = TuttiPersistenceConfig.getInstance().getJdbcUrl(); + + progressionModel.setMessage(String.format("Ouverture de la base de données *%s*.", jdbcUrl)); + + getContext().setDbExist(true); + + // open db + new OpenDbAction(getHandler()).actionPerformed(event); + } + + @Override + protected void releaseAction(ActionEvent event) { + super.releaseAction(event); + getContext().getActionUI().getModel().setProgressionModel(null); + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/InstallDbAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/OpenDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/OpenDbAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/OpenDbAction.java 2013-02-15 14:49:24 UTC (rev 421) @@ -0,0 +1,73 @@ +package fr.ifremer.tutti.ui.swing.content.db; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 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.config.TuttiPersistenceConfig; +import fr.ifremer.tutti.ui.swing.AbstractMainUITuttiAction; +import fr.ifremer.tutti.ui.swing.MainUIHandler; +import fr.ifremer.tutti.ui.swing.TuttiScreen; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * To open existing db. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class OpenDbAction extends AbstractMainUITuttiAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = + LogFactory.getLog(OpenDbAction.class); + + public OpenDbAction(MainUIHandler handler) { + super(handler, + "openDb", + "open-db", + _("tutti.action.openDb"), + _("tutti.action.openDb.tip"), + true); + } + + @Override + protected void doAction(ActionEvent event) { + + getContext().setDbLoaded(true); + getHandler().reloadPersistenceService(); + + String jdbcUrl = TuttiPersistenceConfig.getInstance().getJdbcUrl(); + + sendMessage(String.format("La base de données '%s' est ouverte.", jdbcUrl)); + + getContext().setScreen(TuttiScreen.SELECT_CRUISE); + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/OpenDbAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
tchemit@users.forge.codelutin.com