Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
621d20eb
by Tony Chemit at 2020-06-30T13:41:44+02:00
5 changed files:
- client-core/src/main/java/fr/ird/observe/client/ObserveSwingApplicationContext.java
- client-core/src/main/java/fr/ird/observe/client/main/actions/CloseApplicationAction.java
- client-core/src/main/java/fr/ird/observe/client/main/actions/ReloadApplicationAction.java
- client-core/src/main/java/fr/ird/observe/client/main/callback/ReloadApplicationCallback.java
- client-runner/src/main/java/fr/ird/observe/client/RunObserve.java
Changes:
| ... | ... | @@ -22,7 +22,7 @@ |
| 22 | 22 |
package fr.ird.observe.client;
|
| 23 | 23 |
|
| 24 | 24 |
import fr.ird.observe.client.configuration.ClientConfig;
|
| 25 |
-import fr.ird.observe.client.configuration.ClientConfigApplicationComponent;
|
|
| 25 |
+import fr.ird.observe.client.datasource.api.ObserveSwingDataSource;
|
|
| 26 | 26 |
import fr.ird.observe.services.ObserveServiceMainFactory;
|
| 27 | 27 |
import fr.ird.observe.services.ObserveServiceMainFactoryApplicationComponent;
|
| 28 | 28 |
import fr.ird.observe.spi.DtoModelHelper;
|
| ... | ... | @@ -30,6 +30,8 @@ import io.ultreia.java4all.application.context.ApplicationContext; |
| 30 | 30 |
import org.apache.logging.log4j.LogManager;
|
| 31 | 31 |
import org.apache.logging.log4j.Logger;
|
| 32 | 32 |
|
| 33 |
+import java.util.Optional;
|
|
| 34 |
+ |
|
| 33 | 35 |
import static io.ultreia.java4all.i18n.I18n.n;
|
| 34 | 36 |
|
| 35 | 37 |
/**
|
| ... | ... | @@ -43,6 +45,7 @@ import static io.ultreia.java4all.i18n.I18n.n; |
| 43 | 45 |
public class ObserveSwingApplicationContext extends ApplicationContext {
|
| 44 | 46 |
|
| 45 | 47 |
private static final Logger log = LogManager.getLogger(ObserveSwingApplicationContext.class);
|
| 48 |
+ private static ObserveSwingDataSource dataSourceToReload;
|
|
| 46 | 49 |
|
| 47 | 50 |
public static ObserveSwingApplicationContext init(ClientConfig config) {
|
| 48 | 51 |
ClientConfigFinderInstance.config = config;
|
| ... | ... | @@ -90,4 +93,12 @@ public class ObserveSwingApplicationContext extends ApplicationContext { |
| 90 | 93 |
n("observe.runner.initStorage.title.no.local.db.found");
|
| 91 | 94 |
|
| 92 | 95 |
}
|
| 96 |
+ |
|
| 97 |
+ public static void setDataSourceToReload(ObserveSwingDataSource dataSourceToReload) {
|
|
| 98 |
+ ObserveSwingApplicationContext.dataSourceToReload = dataSourceToReload;
|
|
| 99 |
+ }
|
|
| 100 |
+ |
|
| 101 |
+ public static Optional<ObserveSwingDataSource> getDataSourceToReload() {
|
|
| 102 |
+ return Optional.ofNullable(dataSourceToReload);
|
|
| 103 |
+ }
|
|
| 93 | 104 |
}
|
| ... | ... | @@ -28,6 +28,7 @@ import org.apache.logging.log4j.LogManager; |
| 28 | 28 |
import org.apache.logging.log4j.Logger;
|
| 29 | 29 |
import org.nuiton.jaxx.runtime.swing.application.ApplicationRunner;
|
| 30 | 30 |
|
| 31 |
+import javax.swing.KeyStroke;
|
|
| 31 | 32 |
import java.awt.event.ActionEvent;
|
| 32 | 33 |
|
| 33 | 34 |
import static io.ultreia.java4all.i18n.I18n.t;
|
| ... | ... | @@ -46,6 +47,22 @@ public class CloseApplicationAction extends MainUIActionSupport implements Runna |
| 46 | 47 |
super(t("observe.action.exit"), t("observe.action.exit.tip"), "exit", 'Q');
|
| 47 | 48 |
}
|
| 48 | 49 |
|
| 50 |
+ public CloseApplicationAction(String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) {
|
|
| 51 |
+ super(label, shortDescription, actionIcon, acceleratorKey);
|
|
| 52 |
+ }
|
|
| 53 |
+ |
|
| 54 |
+ public CloseApplicationAction(String actionCommandKey, String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) {
|
|
| 55 |
+ super(actionCommandKey, label, shortDescription, actionIcon, acceleratorKey);
|
|
| 56 |
+ }
|
|
| 57 |
+ |
|
| 58 |
+ public CloseApplicationAction(String label, String shortDescription, String actionIcon, char acceleratorKey) {
|
|
| 59 |
+ super(label, shortDescription, actionIcon, acceleratorKey);
|
|
| 60 |
+ }
|
|
| 61 |
+ |
|
| 62 |
+ public CloseApplicationAction(String actionCommandKey, String label, String shortDescription, String actionIcon, char acceleratorKey) {
|
|
| 63 |
+ super(actionCommandKey, label, shortDescription, actionIcon, acceleratorKey);
|
|
| 64 |
+ }
|
|
| 65 |
+ |
|
| 49 | 66 |
@Override
|
| 50 | 67 |
public void run() {
|
| 51 | 68 |
|
| ... | ... | @@ -22,12 +22,13 @@ package fr.ird.observe.client.main.actions; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import fr.ird.observe.client.main.ObserveMainUI;
|
|
| 25 |
+import fr.ird.observe.client.ObserveSwingApplicationContext;
|
|
| 26 |
+import fr.ird.observe.client.datasource.api.ObserveSwingDataSource;
|
|
| 26 | 27 |
import fr.ird.observe.client.main.body.NoBodyContentComponent;
|
| 28 |
+import fr.ird.observe.client.util.UIHelper;
|
|
| 27 | 29 |
import org.apache.logging.log4j.LogManager;
|
| 28 | 30 |
import org.apache.logging.log4j.Logger;
|
| 29 |
- |
|
| 30 |
-import java.awt.event.ActionEvent;
|
|
| 31 |
+import org.nuiton.jaxx.runtime.swing.application.ApplicationRunner;
|
|
| 31 | 32 |
|
| 32 | 33 |
import static io.ultreia.java4all.i18n.I18n.t;
|
| 33 | 34 |
|
| ... | ... | @@ -37,7 +38,7 @@ import static io.ultreia.java4all.i18n.I18n.t; |
| 37 | 38 |
* @author Tony Chemit - dev@tchemit.fr
|
| 38 | 39 |
* @since 8.0
|
| 39 | 40 |
*/
|
| 40 |
-public class ReloadApplicationAction extends MainUIActionSupport {
|
|
| 41 |
+public class ReloadApplicationAction extends CloseApplicationAction {
|
|
| 41 | 42 |
|
| 42 | 43 |
private static final Logger log = LogManager.getLogger(ReloadApplicationAction.class);
|
| 43 | 44 |
|
| ... | ... | @@ -46,14 +47,28 @@ public class ReloadApplicationAction extends MainUIActionSupport { |
| 46 | 47 |
}
|
| 47 | 48 |
|
| 48 | 49 |
@Override
|
| 49 |
- protected void doActionPerformed(ActionEvent event, ObserveMainUI ui) {
|
|
| 50 |
- |
|
| 50 |
+ public void run() {
|
|
| 51 | 51 |
log.info("ObServe reloading...");
|
| 52 |
+ |
|
| 52 | 53 |
boolean canContinue = ui.changeBodyContent(NoBodyContentComponent.class);
|
| 53 |
-// boolean canContinue = ContentUIManagerApplicationComponent.value().closeSelectedContentUI();
|
|
| 54 |
- if (canContinue) {
|
|
| 55 |
- getClientUIContext().getUiCallbackManager().run("application");
|
|
| 54 |
+ if (!canContinue) {
|
|
| 55 |
+ return;
|
|
| 56 |
+ }
|
|
| 57 |
+ |
|
| 58 |
+ ObserveSwingDataSource mainDataSource = getObserveDataSourcesManager().getMainDataSource();
|
|
| 59 |
+ if (mainDataSource != null) {
|
|
| 60 |
+ if (mainDataSource.isOpen()) {
|
|
| 61 |
+ try {
|
|
| 62 |
+ mainDataSource.close();
|
|
| 63 |
+ } catch (Exception e) {
|
|
| 64 |
+ UIHelper.handlingError("Can't close data source", e);
|
|
| 65 |
+ mainDataSource = null;
|
|
| 66 |
+ }
|
|
| 67 |
+ }
|
|
| 68 |
+ ObserveSwingApplicationContext.setDataSourceToReload(mainDataSource);
|
|
| 56 | 69 |
}
|
| 70 |
+ ApplicationRunner.getRunner().setReload(true);
|
|
| 57 | 71 |
|
| 72 |
+ super.run();
|
|
| 58 | 73 |
}
|
| 59 | 74 |
}
|
| ... | ... | @@ -25,9 +25,8 @@ package fr.ird.observe.client.main.callback; |
| 25 | 25 |
import com.google.auto.service.AutoService;
|
| 26 | 26 |
import fr.ird.observe.client.ClientUIContext;
|
| 27 | 27 |
import fr.ird.observe.client.main.ObserveMainUI;
|
| 28 |
-import fr.ird.observe.client.main.actions.CloseApplicationAction;
|
|
| 28 |
+import fr.ird.observe.client.main.actions.ReloadApplicationAction;
|
|
| 29 | 29 |
import org.nuiton.jaxx.runtime.swing.SwingUtil;
|
| 30 |
-import org.nuiton.jaxx.runtime.swing.application.ApplicationRunner;
|
|
| 31 | 30 |
|
| 32 | 31 |
import javax.swing.Icon;
|
| 33 | 32 |
|
| ... | ... | @@ -64,8 +63,7 @@ public class ReloadApplicationCallback implements ObserveUICallback { |
| 64 | 63 |
|
| 65 | 64 |
@Override
|
| 66 | 65 |
public void run() {
|
| 67 |
- ApplicationRunner.getRunner().setReload(true);
|
|
| 68 |
- CloseApplicationAction action = new CloseApplicationAction();
|
|
| 66 |
+ ReloadApplicationAction action = new ReloadApplicationAction();
|
|
| 69 | 67 |
action.setUi(mainUI);
|
| 70 | 68 |
action.run();
|
| 71 | 69 |
}
|
| ... | ... | @@ -75,6 +75,7 @@ import java.util.Arrays; |
| 75 | 75 |
import java.util.Date;
|
| 76 | 76 |
import java.util.EnumSet;
|
| 77 | 77 |
import java.util.Locale;
|
| 78 |
+import java.util.Optional;
|
|
| 78 | 79 |
import java.util.Set;
|
| 79 | 80 |
import java.util.logging.Level;
|
| 80 | 81 |
|
| ... | ... | @@ -271,7 +272,9 @@ public class RunObserve extends ApplicationRunner implements WithBackupsManager, |
| 271 | 272 |
//
|
| 272 | 273 |
// return;
|
| 273 | 274 |
// }
|
| 274 |
- if (!config.isLoadLocalStorage()) {
|
|
| 275 |
+ Optional<ObserveSwingDataSource> dataSourceToReload = ObserveSwingApplicationContext.getDataSourceToReload();
|
|
| 276 |
+ ObserveSwingApplicationContext.setDataSourceToReload(null);
|
|
| 277 |
+ if (!config.isLoadLocalStorage() && !dataSourceToReload.isPresent()) {
|
|
| 275 | 278 |
|
| 276 | 279 |
// on ne charge rien au démarrage
|
| 277 | 280 |
log.info(t("observe.runner.loaded", config.getVersion()));
|
| ... | ... | @@ -280,7 +283,8 @@ public class RunObserve extends ApplicationRunner implements WithBackupsManager, |
| 280 | 283 |
|
| 281 | 284 |
// 4 - init storage
|
| 282 | 285 |
|
| 283 |
- Runnable initStorage = () -> initStorage(config, ui);
|
|
| 286 |
+ |
|
| 287 |
+ Runnable initStorage = () -> initStorage(config, ui, dataSourceToReload.orElse(null));
|
|
| 284 | 288 |
getObserveActionExecutor().addAction(t("observe.runner.load.database"), initStorage);
|
| 285 | 289 |
|
| 286 | 290 |
}
|
| ... | ... | @@ -364,57 +368,65 @@ public class RunObserve extends ApplicationRunner implements WithBackupsManager, |
| 364 | 368 |
//FIXME Need to have a unified API and only one
|
| 365 | 369 |
//FIXME first try to open specified ds (here local ds)
|
| 366 | 370 |
//FIXME if can not load local ds, then feedback it and propose to load automatic backup, or to create a new local ds
|
| 367 |
- private void initStorage(ClientConfig config, JFrame ui) {
|
|
| 371 |
+ private void initStorage(ClientConfig config, JFrame ui, ObserveSwingDataSource previousDataSource) {
|
|
| 368 | 372 |
|
| 369 | 373 |
ObserveMainUI mainUI = (ObserveMainUI) ui;
|
| 370 | 374 |
ObserveDataSourcesManager dataSourcesManager = getObserveDataSourcesManager();
|
| 371 | 375 |
BackupsManager backupsManager = getBackupsManager();
|
| 372 | 376 |
|
| 373 |
- BackupStorage lastAutomaticBackup = backupsManager.getAutomaticBackups().stream().findFirst().orElse(null);
|
|
| 374 |
- |
|
| 375 |
- boolean askToCreate = true;
|
|
| 376 |
- if (config.isLocalStorageExist()) {
|
|
| 377 |
+ if (previousDataSource != null) {
|
|
| 377 | 378 |
|
| 378 |
- // une base locale existe, on l'ouvre
|
|
| 379 |
+ // reuse previous data source
|
|
| 380 |
+ previousDataSource.setProgressModel(new ProgressModel());
|
|
| 381 |
+ mainUI.getMainUIBodyContentManager().getBodyTyped(DataSourceEditor.class, DataSourceEditorBodyContent.class).loadStorage(mainUI, previousDataSource, true);
|
|
| 379 | 382 |
|
| 380 |
- ObserveSwingDataSource dataSource = dataSourcesManager.newLocalDataSource();
|
|
| 381 |
- dataSource.setProgressModel(new ProgressModel());
|
|
| 383 |
+ } else if (config.isLoadLocalStorage()){
|
|
| 382 | 384 |
|
| 383 |
- try {
|
|
| 385 |
+ boolean askToCreate = true;
|
|
| 386 |
+ BackupStorage lastAutomaticBackup = backupsManager.getAutomaticBackups().stream().findFirst().orElse(null);
|
|
| 384 | 387 |
|
| 385 |
- ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect(false);
|
|
| 386 |
- dataSource.setOwner(dataSourceInformation.isOwner());
|
|
| 387 |
- dataSource.setSuperUser(dataSourceInformation.isSuperUser());
|
|
| 388 |
- dataSource.migrateDataIfPossible(dataSourceInformation, config.getModelVersion());
|
|
| 388 |
+ if (config.isLocalStorageExist()) {
|
|
| 389 | 389 |
|
| 390 |
- // la source sera utilisée dans les ui
|
|
| 391 |
- mainUI.getMainUIBodyContentManager().getBodyTyped(DataSourceEditor.class, DataSourceEditorBodyContent.class).loadStorage(mainUI, dataSource, true);
|
|
| 390 |
+ // une base locale existe, on l'ouvre
|
|
| 392 | 391 |
|
| 393 |
- askToCreate = false;
|
|
| 394 |
- } catch (Exception e) {
|
|
| 392 |
+ ObserveSwingDataSource dataSource = dataSourcesManager.newLocalDataSource();
|
|
| 393 |
+ dataSource.setProgressModel(new ProgressModel());
|
|
| 395 | 394 |
|
| 396 |
- if (lastAutomaticBackup != null) {
|
|
| 395 |
+ try {
|
|
| 397 | 396 |
|
| 398 |
- log.error("Could not load local database", e);
|
|
| 397 |
+ ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect(false);
|
|
| 398 |
+ dataSource.setOwner(dataSourceInformation.isOwner());
|
|
| 399 |
+ dataSource.setSuperUser(dataSourceInformation.isSuperUser());
|
|
| 400 |
+ dataSource.migrateDataIfPossible(dataSourceInformation, config.getModelVersion());
|
|
| 399 | 401 |
|
| 400 |
- InitStorageModel initStorageModel = new InitStorageModel(config.getLocalDBDirectory(), lastAutomaticBackup);
|
|
| 402 |
+ // la source sera utilisée dans les ui
|
|
| 403 |
+ mainUI.getMainUIBodyContentManager().getBodyTyped(DataSourceEditor.class, DataSourceEditorBodyContent.class).loadStorage(mainUI, dataSource, true);
|
|
| 401 | 404 |
|
| 402 |
- JOptionPane.showMessageDialog(
|
|
| 403 |
- mainUI,
|
|
| 404 |
- t("observe.runner.initStorage.local.db.error", initStorageModel.getBackupDate()),
|
|
| 405 |
- t("observe.runner.title.error.dialog"),
|
|
| 406 |
- JOptionPane.WARNING_MESSAGE
|
|
| 407 |
- );
|
|
| 408 |
- loadBackup(dataSourcesManager, mainUI, lastAutomaticBackup);
|
|
| 409 | 405 |
askToCreate = false;
|
| 406 |
+ } catch (Exception e) {
|
|
| 407 |
+ |
|
| 408 |
+ if (lastAutomaticBackup != null) {
|
|
| 409 |
+ |
|
| 410 |
+ log.error("Could not load local database", e);
|
|
| 411 |
+ |
|
| 412 |
+ InitStorageModel initStorageModel = new InitStorageModel(config.getLocalDBDirectory(), lastAutomaticBackup);
|
|
| 413 |
+ |
|
| 414 |
+ JOptionPane.showMessageDialog(
|
|
| 415 |
+ mainUI,
|
|
| 416 |
+ t("observe.runner.initStorage.local.db.error", initStorageModel.getBackupDate()),
|
|
| 417 |
+ t("observe.runner.title.error.dialog"),
|
|
| 418 |
+ JOptionPane.WARNING_MESSAGE
|
|
| 419 |
+ );
|
|
| 420 |
+ loadBackup(dataSourcesManager, mainUI, lastAutomaticBackup);
|
|
| 421 |
+ askToCreate = false;
|
|
| 422 |
+ }
|
|
| 410 | 423 |
}
|
| 411 |
- }
|
|
| 412 |
- }
|
|
| 413 | 424 |
|
| 414 |
- if (askToCreate) {
|
|
| 415 |
- askToCreateLocalDatabase(mainUI, config, dataSourcesManager, lastAutomaticBackup);
|
|
| 425 |
+ if (askToCreate) {
|
|
| 426 |
+ askToCreateLocalDatabase(mainUI, config, dataSourcesManager, lastAutomaticBackup);
|
|
| 427 |
+ }
|
|
| 428 |
+ }
|
|
| 416 | 429 |
}
|
| 417 |
- |
|
| 418 | 430 |
log.info(t("observe.runner.initStorage.done"));
|
| 419 | 431 |
}
|
| 420 | 432 |
|