This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit dc681734ae429db09202120679cff6629580e684 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Nov 28 13:50:06 2016 +0100 refs #8429 [iso] réusinage du boot des wizard + ajout des mnemonics --- .../src/main/config/ObserveSwingApplication.ini | 6 + ...pplication-swing-configuration_en_GB.properties | 1 + ...pplication-swing-configuration_es_ES.properties | 1 + ...pplication-swing-configuration_fr_FR.properties | 1 + .../src/main/filters/observe-ui.properties | 3 + .../observe/application/swing/ObserveRunner.java | 7 +- .../ObserveSwingApplicationDataSourcesManager.java | 51 +- .../application/swing/ui/MnemonicHelper.java | 130 +++ .../application/swing/ui/ObserveMainUI.jaxx | 43 +- .../application/swing/ui/ObserveMainUI.jcss | 72 +- .../application/swing/ui/ObserveMainUIHandler.java | 512 +-------- ...IHandler.java => ObserveMainUIInitializer.java} | 157 +-- .../application/swing/ui/ObserveUICallback.java | 2 +- .../ird/observe/application/swing/ui/UIHelper.java | 108 +- .../swing/ui/actions/ShowConfigAction.java | 20 +- .../swing/ui/actions/ToFullScreenAction.java | 41 + .../swing/ui/actions/ToWindowScreenAction.java | 40 + .../actions/content/AbstractContentUIAction.java | 2 +- .../ui/actions/global/AbstractGlobalUIAction.java | 1 - .../swing/ui/actions/shared/AbstractUIAction.java | 49 +- .../ui/actions/shared/SelectOpenNodeUIAction.java | 2 +- .../application/swing/ui/admin/AdminTabUI.jaxx | 42 +- .../application/swing/ui/admin/AdminTabUI.jcss | 2 +- .../swing/ui/admin/AdminTabUIHandler.java | 59 +- .../application/swing/ui/admin/AdminUI.jaxx | 57 +- .../application/swing/ui/admin/AdminUIHandler.java | 91 +- .../swing/ui/admin/AdminUILauncher.java | 9 +- .../application/swing/ui/admin/AdminUIModel.java | 1150 ++------------------ .../swing/ui/admin/config/ConfigModel.java | 673 ++++++++++++ .../swing/ui/admin/config/ConfigUI.jaxx | 49 +- .../swing/ui/admin/config/ConfigUI.jcss | 4 +- .../swing/ui/admin/config/ConfigUIHandler.java | 58 +- .../swing/ui/admin/config/SelectDataModel.java | 229 ++++ .../swing/ui/admin/config/SelectDataUI.jaxx | 20 +- .../swing/ui/admin/config/SelectDataUI.jcss | 4 - .../swing/ui/admin/config/SelectDataUIHandler.java | 50 + .../ui/admin/consolidate/ConsolidateModel.java | 29 + .../swing/ui/admin/consolidate/ConsolidateUI.jaxx | 27 +- .../ui/admin/consolidate/ConsolidateUIHandler.java | 30 +- .../swing/ui/admin/export/ExportModel.java | 6 + .../swing/ui/admin/export/ExportUI.jaxx | 12 - .../swing/ui/admin/export/ExportUIHandler.java | 44 +- .../swing/ui/admin/report/ReportModel.java | 66 ++ .../swing/ui/admin/report/ReportUI.jaxx | 23 +- .../swing/ui/admin/report/ReportUIHandler.java | 67 +- .../swing/ui/admin/resume/ShowResumeModel.java | 21 + .../swing/ui/admin/resume/ShowResumeUI.jaxx | 18 +- .../swing/ui/admin/resume/ShowResumeUIHandler.java | 30 +- .../swing/ui/admin/save/SaveLocalModel.java | 51 +- .../swing/ui/admin/save/SaveLocalUI.jaxx | 26 +- .../swing/ui/admin/save/SaveLocalUIHandler.java | 31 +- .../admin/synchronize/data/DataSynchroModel.java | 11 + .../ui/admin/synchronize/data/DataSynchroUI.jaxx | 14 - .../synchronize/data/DataSynchroUIHandler.java | 70 +- .../referential/legacy/SynchronizeModel.java | 6 + .../referential/legacy/SynchronizeUI.jaxx | 13 +- .../referential/legacy/SynchronizeUIHandler.java | 38 +- .../referential/ng/ReferentialSynchroModel.java | 43 + .../referential/ng/ReferentialSynchroUI.jaxx | 13 +- .../ng/ReferentialSynchroUIHandler.java | 42 +- .../swing/ui/admin/validate/ValidateModel.java | 69 +- .../swing/ui/admin/validate/ValidateUI.jaxx | 29 +- .../swing/ui/admin/validate/ValidateUIHandler.java | 59 +- .../swing/ui/content/ContentUIInitializer.java | 42 +- .../swing/ui/content/ContentUIManager.java | 31 + .../swing/ui/content/ObserveFocusManager.java | 2 +- .../LonglineDetailCompositionUIInitializer.java | 14 +- .../open/impl/longline/ActivityLonglineUI.jcss | 4 + .../impl/longline/CatchLonglineUIHandler.java | 4 +- .../application/swing/ui/storage/StorageUI.jaxx | 47 +- .../swing/ui/storage/StorageUIHandler.java | 304 +++--- .../swing/ui/storage/StorageUILauncher.java | 35 +- .../swing/ui/storage/tabs/BackupUI.jaxx | 15 +- .../swing/ui/storage/tabs/BackupUIHandler.java | 74 ++ .../swing/ui/storage/tabs/ChooseDbModeUI.jaxx | 8 +- .../swing/ui/storage/tabs/ChooseDbModeUI.jcss | 4 +- .../ui/storage/tabs/ChooseDbModeUIHandler.java | 77 ++ .../swing/ui/storage/tabs/ConfigDataUI.jaxx | 27 +- .../swing/ui/storage/tabs/ConfigDataUIHandler.java | 92 ++ .../swing/ui/storage/tabs/ConfigReferentielUI.jaxx | 45 +- .../storage/tabs/ConfigReferentielUIHandler.java | 117 ++ .../swing/ui/storage/tabs/ConfigUI.jaxx | 10 +- .../swing/ui/storage/tabs/ConfigUI.jcss | 24 +- .../swing/ui/storage/tabs/ConfigUIHandler.java | 149 +++ .../swing/ui/storage/tabs/ConfirmUI.jaxx | 10 - .../swing/ui/storage/tabs/ConfirmUIHandler.java | 21 + .../swing/ui/storage/tabs/RolesTableModel.java | 2 +- .../application/swing/ui/storage/tabs/RolesUI.jaxx | 8 +- .../swing/ui/storage/tabs/RolesUIHandler.java | 74 ++ .../swing/ui/storage/tabs/SelectDataUI.jaxx | 10 - .../swing/ui/storage/tabs/SelectDataUIHandler.java | 22 + .../swing/ui/storage/tabs/StorageTabUI.jaxx | 10 +- .../swing/ui/storage/tabs/StorageTabUIHandler.java | 478 +------- .../application/swing/ui/storage/tabs/package.html | 2 +- .../i18n/application-swing_en_GB.properties | 4 + .../i18n/application-swing_es_ES.properties | 4 + .../i18n/application-swing_fr_FR.properties | 4 + .../src/main/resources/icons/action-fullScreen.png | Bin 0 -> 687 bytes .../main/resources/icons/action-windowScreen.png | Bin 0 -> 727 bytes .../actions/validate/ValidateServiceRestTest.java | 18 +- .../actions/validate/ValidateServiceTopia.java | 12 +- .../actions/validate/ValidateServiceTopiaTest.java | 14 +- .../actions/validate/ValidateDataResult.java | 6 +- .../validate/ValidateReferentialsResult.java | 7 +- 104 files changed, 2961 insertions(+), 3504 deletions(-) diff --git a/application-swing-configuration/src/main/config/ObserveSwingApplication.ini b/application-swing-configuration/src/main/config/ObserveSwingApplication.ini index 6087171..e6af8a9 100644 --- a/application-swing-configuration/src/main/config/ObserveSwingApplication.ini +++ b/application-swing-configuration/src/main/config/ObserveSwingApplication.ini @@ -503,6 +503,12 @@ key = ui.noFocusBorderColor.color type = java.awt.Color defaultValue = "java.awt.Color[r=192,g=192,b=192]" +[option showMnemonic] +description = observe.config.ui.showMnemonic +key = ui.showMnemonic +type = boolean +defaultValue = true + [action help] description = observe.action.commandline.help action = "fr.ird.observe.application.swing.ObserveCLAction#help" diff --git a/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_en_GB.properties b/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_en_GB.properties index c75c8f5..01a1a88 100644 --- a/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_en_GB.properties +++ b/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_en_GB.properties @@ -79,6 +79,7 @@ observe.config.ui.fullscreen=Flag sets to true to lauch application in full scre observe.config.ui.loadLocalStorage=Flag sets to true to load local data source when application starts observe.config.ui.locale=Application's language observe.config.ui.noFocusBorderColor=Color of the not focus container border +observe.config.ui.showMnemonic=Show mnemonic on actions observe.config.ui.showNumberEditorButton=Flag sets to true to show button to invoke popup on number's editors observe.config.ui.showTimeEditorSlider=Show timer slider observe.config.ui.storeRemoteStorage=Flag sets to true to store in config a remote connexion (except passwords) diff --git a/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_es_ES.properties b/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_es_ES.properties index b3ad83e..283976a 100644 --- a/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_es_ES.properties +++ b/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_es_ES.properties @@ -79,6 +79,7 @@ observe.config.ui.fullscreen=Para mostrar en modo pantalla completa la aplicaci observe.config.ui.loadLocalStorage=Cambiar la base local al iniciar la aplicación observe.config.ui.locale=Idioma de la aplicación (fr_FR, en_GB o es_ES) observe.config.ui.noFocusBorderColor=Couleur de la bordure de la zone qui n'a pas le focus \#TODO +observe.config.ui.showMnemonic=Afficher les racourcis clavier \#TODO observe.config.ui.showNumberEditorButton=Para mostrar el botón que permite usar el editor numérico a la izquierda de cada campo numérico observe.config.ui.showTimeEditorSlider=Para mostrar la regla de edición de las horas observe.config.ui.storeRemoteStorage=Para activar la copia de seguridad de la configuración de la fuente de datos remota diff --git a/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_fr_FR.properties b/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_fr_FR.properties index 5207b9a..0cbe9ca 100644 --- a/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_fr_FR.properties +++ b/application-swing-configuration/src/main/resources/i18n/application-swing-configuration_fr_FR.properties @@ -79,6 +79,7 @@ observe.config.ui.fullscreen=Pour afficher l'application en mode pleine écran observe.config.ui.loadLocalStorage=Charger la base locale au démarrage de l'application observe.config.ui.locale=Langue utilisée par l'application (fr_FR, en_GB ou es_ES) observe.config.ui.noFocusBorderColor=Couleur de la bordure de la zone qui n'a pas le focus +observe.config.ui.showMnemonic=Afficher les racourcis clavier observe.config.ui.showNumberEditorButton=Pour afficher le bouton qui permet d'utiliser l'éditeur numérique à gauche de chaque champs numérique observe.config.ui.showTimeEditorSlider=Pour afficher la réglette d'édition des heures observe.config.ui.storeRemoteStorage=Pour activer la sauvegarde de la configuration de la source distante diff --git a/application-swing/src/main/filters/observe-ui.properties b/application-swing/src/main/filters/observe-ui.properties index 45bbae6..ca42153 100644 --- a/application-swing/src/main/filters/observe-ui.properties +++ b/application-swing/src/main/filters/observe-ui.properties @@ -196,6 +196,9 @@ icon.action.collapse=action-collapse.png icon.action.select=action-select.png icon.action.unselect=action-unselect.png +icon.action.full-screen=action-fullScreen.png +icon.action.window-screen=action-windowScreen.png + icon.action.wizard-state-pending=action-wizard-state-pending-16.png icon.action.wizard-state-running=action-wizard-state-running-16.png icon.action.wizard-state-need_fix=action-wizard-state-need_fix-16.png diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveRunner.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveRunner.java index 4bed2ac..ab27518 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveRunner.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveRunner.java @@ -24,7 +24,7 @@ package fr.ird.observe.application.swing; import com.google.common.base.Preconditions; import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.ObserveMainUIHandler; +import fr.ird.observe.application.swing.ui.ObserveMainUIInitializer; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.actions.StartServerModeAction; import fr.ird.observe.application.swing.ui.util.FloatConverter; @@ -558,7 +558,6 @@ public abstract class ObserveRunner extends ApplicationRunner { File dir = config.getResourcesDirectory(); File file = ObserveResourceManager.Resource.ui.getFile(dir); - if (!file.exists()) { String message = t("observe.runner.copy.default.ui.file", file); @@ -586,9 +585,7 @@ public abstract class ObserveRunner extends ApplicationRunner { private ObserveMainUI startUI(ObserveSwingApplicationContext context, ObserveSwingApplicationConfig config) { - ObserveMainUIHandler uiHandler = context.getContextValue(ObserveMainUIHandler.class); - - ObserveMainUI ui = uiHandler.initUI(context, config); + ObserveMainUI ui = ObserveMainUIInitializer.initUI(context, config); UIHelper.setMainUIVisible(ui); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveSwingApplicationDataSourcesManager.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveSwingApplicationDataSourcesManager.java index b11d0fa..920de11 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveSwingApplicationDataSourcesManager.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ObserveSwingApplicationDataSourcesManager.java @@ -33,6 +33,7 @@ import fr.ird.observe.application.swing.db.event.ObserveSwingDataSourceListenerA import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.ObserveUIMode; import fr.ird.observe.application.swing.ui.actions.ChangeStorageAction; +import fr.ird.observe.application.swing.ui.storage.StorageUIModel; import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.configuration.rest.ObserveDataSourceConfigurationRest; @@ -75,6 +76,50 @@ public class ObserveSwingApplicationDataSourcesManager implements Closeable { private ObserveSwingDataSource dataSource; /** + * Prépare une service de persistance à partir d'un modèle. + * + * Le service ne sera pas ouvert. + * + * @param model le modèle de la source de données + * @return le service de persistance initialisé mais non ouvert. + */ + public ObserveSwingDataSource newDataSourceFromModel(StorageUIModel model) { + + ObserveSwingDataSource dataSource = null; + ObserveDataSourceConfiguration configuration; + switch (model.getDbMode()) { + case CREATE_LOCAL: + case USE_LOCAL: + configuration = model.toH2StorageConfig(t("observe.storage.label.local")); + + dataSource = newDataSource(configuration); + + dataSource.addObserveSwingDataSourceListener( + new ObserveSwingDataSourceListenerAdapter() { + + @Override + public void onOpened(ObserveSwingDataSourceEvent event) { + ObserveSwingApplicationContext context = ObserveSwingApplicationContext.get(); + // la base locale existe desormais + context.getConfig().setLocalStorageExist(true); + } + }); + + break; + case USE_REMOTE: + configuration = model.toPGStorageConfig(t("observe.storage.label.remote")); + dataSource = newDataSource(configuration); + break; + case USE_SERVER: + configuration = model.toRestStorageConfig(t("observe.storage.label.server")); + dataSource = newDataSource(configuration); + break; + } + + return dataSource; + } + + /** * Construit une source de données sur la base locale de l'application. * * <b>Note:</b> La base locale doit exister, sinon on soulève une @@ -373,7 +418,7 @@ public class ObserveSwingApplicationDataSourcesManager implements Closeable { applicationContext.getConfig().saveTreeOpenNodeIds(dataContext.getOpenIds()); dataContext.populateOpens(); - mainUI.getHandler().cleanNavigationUI(mainUI); + mainUI.getInitializer().cleanNavigationUI(); // mainUI.getTreeHelper().cleanNavigationUI(mainUI); // on met a jour l'état dans la config @@ -435,7 +480,7 @@ public class ObserveSwingApplicationDataSourcesManager implements Closeable { DataContext dataContext = mainUI.getDataContext(); dataContext.setEnabled(true); - mainUI.getHandler().cleanNavigationUI(mainUI); + mainUI.getInitializer().cleanNavigationUI(); String[] openIds = config.getTreeOpenNodeIds(); @@ -444,7 +489,7 @@ public class ObserveSwingApplicationDataSourcesManager implements Closeable { } dataContext.populateOpens(openIds); - mainUI.getHandler().loadNavigationUI(mainUI); + mainUI.getInitializer().loadNavigationUI(); mainUI.setMode(ObserveUIMode.DB); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/MnemonicHelper.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/MnemonicHelper.java new file mode 100644 index 0000000..40e2f16 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/MnemonicHelper.java @@ -0,0 +1,130 @@ +package fr.ird.observe.application.swing.ui; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.actions.shared.AbstractUIAction; +import jaxx.runtime.JAXXObject; +import org.apache.commons.lang3.StringUtils; + +import javax.swing.AbstractButton; +import javax.swing.KeyStroke; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.util.LinkedHashSet; +import java.util.Objects; +import java.util.Set; + +import static javax.swing.Action.ACCELERATOR_KEY; +import static javax.swing.Action.NAME; +import static javax.swing.Action.SHORT_DESCRIPTION; +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 6.0 + */ +public class MnemonicHelper { + + public static final KeyStroke KEY_STROKE_STORAGE_DO_CONFIGURE_REMOTE_SERVER = KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK); + public static final KeyStroke KEY_STROKE_STORAGE_DO_BACKUP = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK); + public static final KeyStroke KEY_STROKE_STORAGE_DO_CHOOSE_DIRECTORY = KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK); + public static final KeyStroke KEY_STROKE_STORAGE_KEEP_CONFIGURATION = KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_MASK); + public static final KeyStroke KEY_STROKE_STORAGE_DO_USE_SSL = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK); + public static final KeyStroke KEY_STROKE_STORAGE_DO_CHOOSE_FILE = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK); + public static final KeyStroke KEY_STROKE_ESCAPE = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + + private static String keyStrokeToStr(KeyStroke actionKey) { + String result = ""; + if (actionKey != null) { + result = " (" + StringUtils.removeStart(actionKey.toString().replace("pressed", "+"), "+ ") + ")"; + } + return result; + } + + public static void addKeyStroke(AbstractButton component, KeyStroke actionKey) { + + boolean showMnemonic = isShowMnemonic(); + if (showMnemonic) { + String actionStr = keyStrokeToStr(actionKey); + String text = component.getText() + actionStr; + component.setText(text); + String tip = component.getToolTipText() + actionStr; + component.setToolTipText(tip); + } + } + + protected static boolean isShowMnemonic() { + return ObserveSwingApplicationContext.get().getConfig().isShowMnemonic(); + } + + public static void addKeyStore(AbstractUIAction action, String acceleratorKey, String label, String shortDescription) { + + String acceleratorStr = ""; + if (acceleratorKey != null) { + KeyStroke keyStroke = KeyStroke.getKeyStroke(acceleratorKey); + Objects.requireNonNull(keyStroke, "KeyStroke invalide: " + acceleratorKey); + action.putValue(ACCELERATOR_KEY, keyStroke); + acceleratorStr = isShowMnemonic() ? keyStrokeToStr(keyStroke) : ""; + } + + action.putValue(NAME, t(label) + acceleratorStr); + action.putValue(SHORT_DESCRIPTION, t(shortDescription) + acceleratorStr); + } + + public static void addKeyStroke2(AbstractButton editor, KeyStroke keyStroke) { + String tip = (String) editor.getClientProperty("toolTipText"); + boolean showMnemonic = isShowMnemonic(); + if (tip != null) { + if (keyStroke != null && showMnemonic) { + tip += keyStrokeToStr(keyStroke); + } + editor.setToolTipText(tip); + } + + String text = (String) editor.getClientProperty("text"); + if (text != null) { + if (keyStroke != null && showMnemonic) { + text += keyStrokeToStr(keyStroke); + } + editor.setText(text); + } + + } + + public static void addKeyStrokeFromMnemonic(AbstractButton editor) { + int mnemonic = editor.getMnemonic(); + if (mnemonic > 0) { + if (isShowMnemonic()) { + String accelerator = " (Alt + " + (char) mnemonic + ")"; + if (editor.getText() != null) { + editor.setText(editor.getText() + accelerator); + } + if (editor.getToolTipText() != null) { + editor.setToolTipText(editor.getToolTipText() + accelerator); + } + } + } + } + + public static void addKeyStrokeFromMnemonic(JAXXObject jaxxObject) { + Set<JAXXObject> done = new LinkedHashSet<>(); + addKeyStrokeFromMnemonic(jaxxObject, done); + } + + protected static void addKeyStrokeFromMnemonic(JAXXObject jaxxObject, Set<JAXXObject> done) { + + if (done.contains(jaxxObject)) { + return; + } + done.add(jaxxObject); + + jaxxObject.get$objectMap().values().stream().filter(o -> o instanceof AbstractButton).forEach( + o -> addKeyStrokeFromMnemonic((AbstractButton) o) + ); + + jaxxObject.get$objectMap().values().stream().filter(o -> o instanceof JAXXObject).forEach( + o -> addKeyStrokeFromMnemonic((JAXXObject) o, done) + ); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx index 5dcc505..28356e0 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jaxx @@ -35,14 +35,34 @@ fr.ird.observe.services.dto.seine.TripSeineDto fr.ird.observe.services.dto.constants.ReferentialLocale - fr.ird.observe.application.swing.ui.actions.content.ReOpenUIAction - fr.ird.observe.application.swing.ui.admin.AdminStep + + fr.ird.observe.application.swing.ui.actions.ChangeApplicationLanguageAction + fr.ird.observe.application.swing.ui.actions.ChangeDbLanguageAction fr.ird.observe.application.swing.ui.actions.ChangeStorageAction + fr.ird.observe.application.swing.ui.actions.CloseApplicationAction + fr.ird.observe.application.swing.ui.actions.CloseHelpAction fr.ird.observe.application.swing.ui.actions.CloseStorageAction + fr.ird.observe.application.swing.ui.actions.GotoSiteAction + fr.ird.observe.application.swing.ui.actions.ImportStorageFromFileAction + fr.ird.observe.application.swing.ui.actions.LaunchAdminAction + fr.ird.observe.application.swing.ui.actions.ReloadResourcesAction + fr.ird.observe.application.swing.ui.actions.ReloadApplicationAction + fr.ird.observe.application.swing.ui.actions.ReloadDefaultConfigurationAction fr.ird.observe.application.swing.ui.actions.ReloadStorageAction fr.ird.observe.application.swing.ui.actions.SaveStorageToFileAction + fr.ird.observe.application.swing.ui.actions.ShowAboutAction fr.ird.observe.application.swing.ui.actions.ShowStorageInfoAction + fr.ird.observe.application.swing.ui.actions.StartH2WebServerAction + fr.ird.observe.application.swing.ui.actions.StartServerModeAction + fr.ird.observe.application.swing.ui.actions.StopH2WebServerAction + fr.ird.observe.application.swing.ui.actions.StopServerModeAction + fr.ird.observe.application.swing.ui.actions.ToFullScreenAction + fr.ird.observe.application.swing.ui.actions.ToWindowScreenAction + fr.ird.observe.application.swing.ui.actions.content.CloseOpenUIAction + fr.ird.observe.application.swing.ui.actions.content.DeleteDataUIAction + fr.ird.observe.application.swing.ui.actions.content.ReOpenUIAction + fr.ird.observe.application.swing.ui.content.ContentUIManager fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeHeader @@ -74,6 +94,7 @@ <SaveStorageToFileAction id="saveStorageToFileAction" constructorParams='this'/> <ShowStorageInfoAction id="showStorageInfoAction" constructorParams='this'/> + <ObserveMainUIInitializer id='initializer' constructorParams='this'/> <ContentUIManager id='contentUIManager' initializer='ObserveSwingApplicationContext.get().getContentUIManager()'/> @@ -89,7 +110,7 @@ <ObserveSwingApplicationConfig id='config' initializer='ObserveSwingApplicationContext.get().getConfig()'/> - <ObserveMainUIHandler id='handler' initializer='getContextValue(ObserveMainUIHandler.class)'/> + <!--<ObserveMainUIHandler id='handler' initializer='getContextValue(ObserveMainUIHandler.class)'/>--> <DataContext id='dataContext' initializer='ObserveSwingApplicationContext.get().getDataContext()'/> @@ -99,6 +120,8 @@ <Boolean id='focusOnNavigation' javaBean='false'/> + <Boolean id='showMnemonic' javaBean='config.isShowMnemonic()'/> + <CardLayout2 id='contentLayout'/> <CardLayout2Ext id='bodyLayout' constructorParams='this, "body"'/> @@ -108,15 +131,15 @@ <script><![CDATA[ protected Icon updateStorageSatutIcon(boolean isOpened) { - return getHandler().updateStorageSatutIcon(this); + return handler.updateStorageSatutIcon(); } protected String updateStorageSatutText(boolean isOpened) { - return getHandler().updateStorageSatutText(this); + return handler.updateStorageSatutText(); } protected String updateStorageStatutToolTipText(boolean isOpened) { - return getHandler().updateStorageStatutToolTipText(this); + return handler.updateStorageStatutToolTipText(); } @Override @@ -137,10 +160,6 @@ protected void finalize() throws Throwable { destroy(); } -void $afterCompleteSetup() { - getHandler().$afterCompleteSetup(this); -} - ]]> </script> @@ -149,6 +168,8 @@ void $afterCompleteSetup() { <JMenu id='menuFile'> <JMenuItem id='menuFileReloadApplication'/> + <JMenuItem id='menuFileToFullScreen'/> + <JMenuItem id='menuFileToWindowScreen'/> <JMenuItem id='menuFileCloseApplication'/> </JMenu> @@ -204,7 +225,7 @@ void $afterCompleteSetup() { </JMenu> </JMenu> <JSeparator/> - <JMenuItem id='menuFileConfiguration'/> + <JMenuItem id='menuConfigurationConfiguration'/> <JMenuItem id='menuConfigurationReloadDefault'/> <JMenuItem id='menuConfigurationReloadResources'/> </JMenu> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jcss index 057f220..dab2a24 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUI.jcss @@ -50,15 +50,15 @@ JSplitPane { // trip menu #navigationOpenAction { - action: {new fr.ird.observe.application.swing.ui.actions.content.ReOpenUIAction(this)}; + action: {new ReOpenUIAction(this)}; } #navigationCloseAction { - action: {new fr.ird.observe.application.swing.ui.actions.content.CloseOpenUIAction(this)}; + action: {new CloseOpenUIAction(this)}; } #navigationDeleteAction { - action: {new fr.ird.observe.application.swing.ui.actions.content.DeleteDataUIAction(this)}; + action: {new DeleteDataUIAction(this)}; } #menuFile { @@ -67,7 +67,17 @@ JSplitPane { enabled: {getHandler().acceptMode(getMode(), !isBusy(), !isMainFromSynchro(), ObserveUIMode.NO_DB, ObserveUIMode.DB)}; } -#menuFileConfiguration { +#menuFileToFullScreen { + action:{new ToFullScreenAction(this)}; + visible:{!config.isFullScreen()} +} + +#menuFileToWindowScreen { + action:{new ToWindowScreenAction(this)}; + visible:{config.isFullScreen()} +} + +#menuConfigurationConfiguration { action: {new fr.ird.observe.application.swing.ui.actions.ShowConfigAction(this)}; } @@ -94,17 +104,17 @@ JSplitPane { } #menuApplicationLanguageFR { - action: {new fr.ird.observe.application.swing.ui.actions.ChangeApplicationLanguageAction(this, Locale.FRANCE, t("observe.action.locale.fr"), t("observe.action.locale.fr.tip"))}; + action: {new ChangeApplicationLanguageAction(this, Locale.FRANCE, t("observe.action.locale.fr"), t("observe.action.locale.fr.tip"))}; enabled: {!getHandler().acceptLocale(getConfig().getLocale(), "fr_FR")}; } #menuApplicationLanguageUK { - action: {new fr.ird.observe.application.swing.ui.actions.ChangeApplicationLanguageAction(this, Locale.UK, t("observe.action.locale.uk"), t("observe.action.locale.uk.tip"))}; + action: {new ChangeApplicationLanguageAction(this, Locale.UK, t("observe.action.locale.uk"), t("observe.action.locale.uk.tip"))}; enabled: {!getHandler().acceptLocale(getConfig().getLocale(), "en_GB")}; } #menuApplicationLanguageES { - action: {new fr.ird.observe.application.swing.ui.actions.ChangeApplicationLanguageAction(this, new Locale("es","ES"), t("observe.action.locale.es"), t("observe.action.locale.es.tip"))}; + action: {new ChangeApplicationLanguageAction(this, new Locale("es","ES"), t("observe.action.locale.es"), t("observe.action.locale.es.tip"))}; enabled: {!getHandler().acceptLocale(getConfig().getLocale(), "es_ES")}; } @@ -116,35 +126,35 @@ JSplitPane { } #menuDbLanguageFR { - action: {new fr.ird.observe.application.swing.ui.actions.ChangeDbLanguageAction(this, ReferentialLocale.FR, t("observe.action.locale.fr"), t("observe.action.db.locale.fr.tip"))}; + action: {new ChangeDbLanguageAction(this, ReferentialLocale.FR, t("observe.action.locale.fr"), t("observe.action.db.locale.fr.tip"))}; enabled: {!getHandler().acceptLocale(getConfig().getDbLocale(), "fr_FR")}; } #menuDbLanguageUK { - action: {new fr.ird.observe.application.swing.ui.actions.ChangeDbLanguageAction(this, ReferentialLocale.UK, t("observe.action.locale.uk"), t("observe.action.db.locale.uk.tip"))}; + action: {new ChangeDbLanguageAction(this, ReferentialLocale.UK, t("observe.action.locale.uk"), t("observe.action.db.locale.uk.tip"))}; enabled: {!getHandler().acceptLocale(getConfig().getDbLocale(), "en_GB")}; } #menuDbLanguageES { - action: {new fr.ird.observe.application.swing.ui.actions.ChangeDbLanguageAction(this, ReferentialLocale.ES, t("observe.action.locale.es"), t("observe.action.db.locale.es.tip"))}; + action: {new ChangeDbLanguageAction(this, ReferentialLocale.ES, t("observe.action.locale.es"), t("observe.action.db.locale.es.tip"))}; enabled: {!getHandler().acceptLocale(getConfig().getDbLocale(), "es_ES")}; } #menuConfigurationReloadDefault { - action: {new fr.ird.observe.application.swing.ui.actions.ReloadDefaultConfigurationAction(this)}; + action: {new ReloadDefaultConfigurationAction(this)}; } #menuConfigurationReloadResources { - action: {new fr.ird.observe.application.swing.ui.actions.ReloadResourcesAction(this)}; + action: {new ReloadResourcesAction(this)}; visible: {getConfig().isDevMode()}; } #menuFileReloadApplication { - action: {new fr.ird.observe.application.swing.ui.actions.ReloadApplicationAction(this)}; + action: {new ReloadApplicationAction(this)}; } #menuFileCloseApplication { - action: {new fr.ird.observe.application.swing.ui.actions.CloseApplicationAction(this)}; + action: {new CloseApplicationAction(this)}; } #menuStorage { @@ -154,7 +164,7 @@ JSplitPane { } #menuStorageInfo { - action: {new fr.ird.observe.application.swing.ui.actions.ShowStorageInfoAction(this)}; + action: {new ShowStorageInfoAction(this)}; } #reloadStorageAction { @@ -180,7 +190,7 @@ JSplitPane { } #menuStorageStartServerMode { - action: {new fr.ird.observe.application.swing.ui.actions.StartServerModeAction(this)}; + action: {new StartServerModeAction(this)}; visible: {getHandler().acceptMode(getMode(), getConfig().isLocalStorageExist() && !isBusy() && !isMainFromSynchro(), ObserveUIMode.NO_DB)}; } @@ -189,7 +199,7 @@ JSplitPane { } #menuStorageLoadFromFile { - action: {new fr.ird.observe.application.swing.ui.actions.ImportStorageFromFileAction(this)}; + action: {new ImportStorageFromFileAction(this)}; enabled: {getHandler().acceptMode(getMode(), ObserveUIMode.DB, ObserveUIMode.NO_DB)}; } @@ -205,36 +215,36 @@ JSplitPane { } #menuActionsDataSynchro { - action: {new fr.ird.observe.application.swing.ui.actions.LaunchAdminAction(this, AdminStep.DATA_SYNCHRONIZE)}; + action: {new LaunchAdminAction(this, AdminStep.DATA_SYNCHRONIZE)}; } #menuActionsReferentialSynchro { - action: {new fr.ird.observe.application.swing.ui.actions.LaunchAdminAction(this, AdminStep.REFERENTIAL_SYNCHRONIZE)}; + action: {new LaunchAdminAction(this, AdminStep.REFERENTIAL_SYNCHRONIZE)}; } #menuActionsSynchronize { - action: {new fr.ird.observe.application.swing.ui.actions.LaunchAdminAction(this, AdminStep.SYNCHRONIZE)}; + action: {new LaunchAdminAction(this, AdminStep.SYNCHRONIZE)}; } #menuActionsValidateData { - action: {new fr.ird.observe.application.swing.ui.actions.LaunchAdminAction(this, AdminStep.VALIDATE)}; + action: {new LaunchAdminAction(this, AdminStep.VALIDATE)}; } #menuActionsExportData { - action: {new fr.ird.observe.application.swing.ui.actions.LaunchAdminAction(this, AdminStep.EXPORT_DATA)}; + action: {new LaunchAdminAction(this, AdminStep.EXPORT_DATA)}; } #menuActionsReport { - action: {new fr.ird.observe.application.swing.ui.actions.LaunchAdminAction(this, AdminStep.REPORT)}; + action: {new LaunchAdminAction(this, AdminStep.REPORT)}; } #menuActionsConsolidate { - action: {new fr.ird.observe.application.swing.ui.actions.LaunchAdminAction(this, AdminStep.CONSOLIDATE)}; + action: {new LaunchAdminAction(this, AdminStep.CONSOLIDATE)}; } #menuNavigation { text: "observe.menu.navigation"; - mnemonic: n; + mnemonic: N; enabled: {getHandler().acceptMode(getMode(), !isBusy(), ObserveUIMode.DB)}; } @@ -299,11 +309,11 @@ JSplitPane { } #menuHelpSite { - action: {new fr.ird.observe.application.swing.ui.actions.GotoSiteAction(this)}; + action: {new GotoSiteAction(this)}; } #menuHelpAbout { - action: {new fr.ird.observe.application.swing.ui.actions.ShowAboutAction(this)}; + action: {new ShowAboutAction(this)}; } #storageStatus { @@ -338,7 +348,7 @@ JSplitPane { } #closeHelp { - action: {new fr.ird.observe.application.swing.ui.actions.CloseHelpAction(this)}; + action: {new CloseHelpAction(this)}; borderPainted: false; rolloverEnabled: false; focusable: false; @@ -429,17 +439,17 @@ JSplitPane { } #startH2WebServer{ - action: {new fr.ird.observe.application.swing.ui.actions.StartH2WebServerAction(this)}; + action: {new StartH2WebServerAction(this)}; enabled: {!isH2WebServer()}; } #stopH2WebServer{ - action: {new fr.ird.observe.application.swing.ui.actions.StopH2WebServerAction(this)}; + action: {new StopH2WebServerAction(this)}; enabled: {isH2WebServer()}; } #stopServerMode { - action: {new fr.ird.observe.application.swing.ui.actions.StopServerModeAction(this)}; + action: {new StopServerModeAction(this)}; } #serverModeParameters { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java index 3937401..f9bdaba 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java @@ -22,48 +22,10 @@ package fr.ird.observe.application.swing.ui; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig; -import fr.ird.observe.application.swing.db.DataContext; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.decoration.DecoratorService; -import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.content.ContentMode; -import fr.ird.observe.application.swing.ui.content.ContentUI; -import fr.ird.observe.application.swing.ui.content.ContentUIManager; -import fr.ird.observe.application.swing.ui.content.ContentUIModel; -import fr.ird.observe.application.swing.ui.tree.ObserveNavigationTreeShowPopupAction; -import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; -import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; -import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; -import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport; -import fr.ird.observe.application.swing.ui.tree.navigation.nodes.StringNavigationTreeNodeSupport; -import fr.ird.observe.application.swing.ui.util.ObserveSwingValidatorMessageTableModel; -import fr.ird.observe.application.swing.ui.util.ObserveValidatorMessageTableRenderer; -import fr.ird.observe.services.dto.AbstractObserveDto; -import fr.ird.observe.services.dto.constants.ReferentialLocale; -import jaxx.runtime.context.DefaultApplicationContext; -import jaxx.runtime.context.JAXXInitialContext; -import jaxx.runtime.swing.ErrorDialogUI; -import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; -import jaxx.runtime.validator.swing.SwingValidatorUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.i18n.I18n; +import jaxx.runtime.spi.UIHandler; import javax.swing.Icon; -import javax.swing.JComponent; -import javax.swing.SwingUtilities; -import javax.swing.border.Border; -import javax.swing.border.LineBorder; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.tree.TreePath; -import java.awt.Component; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.List; import java.util.Locale; import static org.nuiton.i18n.I18n.t; @@ -75,323 +37,13 @@ import static org.nuiton.i18n.I18n.t; * @see ObserveMainUI * @since 1.0 */ -@DefaultApplicationContext.AutoLoad -public class ObserveMainUIHandler { - - /** Logger */ - private static final Log log = LogFactory.getLog(ObserveMainUIHandler.class); - - private static final String EMPTY_SELECTION = "emptySelection"; - - public void changeNavigationNode(ObserveMainUI ui, TreeSelectionEvent event) { - - ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); - if (source == null || !source.isOpen()) { - - // no open data source - if (log.isDebugEnabled()) { - log.debug("No open Data source."); - } - return; - } - if (ui.getNavigation().isSelectionEmpty()) { - if (log.isDebugEnabled()) { - log.debug("No selection, show empty panel..."); - } - - boolean foundEmptySelection = false; - for (Component component : ui.getContent().getComponents()) { - if (component.getName().equals(EMPTY_SELECTION)) { - foundEmptySelection = true; - } - } - if (!foundEmptySelection) { - ui.getContent().add(ui.getEmptySelection(), EMPTY_SELECTION); - } - ui.getContentLayout().show(ui.getContent(), EMPTY_SELECTION); - return; - } - - TreePath path = event.getPath(); - NavigationTreeNodeSupport node = (NavigationTreeNodeSupport) path.getLastPathComponent(); - ContentUIManager manager = ui.getContentUIManager(); - - // obtain the ui type to show - Class<? extends ContentUI<?, ?>> uiClass = manager.convertNodeToContentUI(node); - if (log.isDebugEnabled()) { - log.debug("new selected path = " + node + ", ui = " + uiClass); - } - - if (uiClass == null) { - - // pas d'ui trouvé, on ne fait donc rien - return; - } - - ui.setBusy(true); - - try { - - doOpencontent(ui, path, uiClass); - - } catch (Exception e) { - UIHelper.handlingError(e); - } finally { - ui.setBusy(false); - String params; - if (node instanceof StringNavigationTreeNodeSupport) { - params = t(((StringNavigationTreeNodeSupport) node).getData()); - } else { - params = t(ObserveI18nDecoratorHelper.getTypeI18nKey(node.getDataType())); - } - ui.getStatus().setStatus(t("observe.action.open.screen", params)); - } - } - - public void doOpencontent(ObserveMainUI ui, TreePath path, Class<? extends ContentUI<?, ?>> uiClass) { - - ContentUIManager manager = ui.getContentUIManager(); - - // compute the selected ids to put in data context - Object[] nodes = path.getPath(); - List<String> ids = new ArrayList<>(); - for (Object o : nodes) { - NavigationTreeNodeSupport n = (NavigationTreeNodeSupport) o; - - if (n instanceof ReferenceNavigationTreeNodeSupport) { - ids.add(n.getId()); - } - } - - if (log.isDebugEnabled()) { - log.debug("new selected ids from tree = " + ids); - } - String[] selectedIds = ids.toArray(new String[ids.size()]); - - // update selected ids in data context - DataContext context = ui.getDataContext(); - context.populateSelectedIds(selectedIds); - - JComponent focusOwner = (JComponent) ui.getFocusOwner(); - boolean focusOnNavigation = false; - - if (focusOwner != null) { - if (ui.getNavigation().equals(focusOwner)) { - focusOnNavigation = true; - } - if (ui.getNavigationTreeHeader().equals(focusOwner)) { - focusOnNavigation = true; - } - if (ui.getNavigationView().equals(focusOwner)) { - focusOnNavigation = true; - } - if (!focusOnNavigation) { - Container focusOwnerParent = focusOwner.getParent(); - while (focusOwnerParent != null) { - if (ui.getNavigation().equals(focusOwnerParent)) { - focusOnNavigation = true; - break; - } - if (ui.getNavigationTreeHeader().equals(focusOwnerParent)) { - focusOnNavigation = true; - break; - } - if (ui.getNavigationView().equals(focusOwnerParent)) { - focusOnNavigation = true; - break; - } - focusOwnerParent = focusOwnerParent.getParent(); - } - } - } - - if (focusOnNavigation) { - if (log.isInfoEnabled()) { - log.info("Focus on navigation: " + focusOwner); - } - } - - // on recherche l'ui (voir si elle existe déjà) - ContentUI<?, ?> content = manager.getContent(uiClass); - - if (content == null) { - - content = manager.createContent(uiClass); - } - - // on ouvre l'écran - manager.openContent(content); - - if (focusOnNavigation) SwingUtilities.invokeLater(focusOwner::requestFocusInWindow); - } - - /** - * Methode pour initialiser l'ui principale sans l'afficher. - * - * @param context le context applicatif - * @param config la configuration a utiliser - * @return l'ui instancie et initialisee mais non visible encore - */ - public ObserveMainUI initUI(ObserveSwingApplicationContext context, ObserveSwingApplicationConfig config) { - - SwingValidatorMessageTableModel errorModel = new ObserveSwingValidatorMessageTableModel(); - - DecoratorService decoratorService = context.getDecoratorService(); - - boolean reloadDecorators = false; - Locale currentLocale = I18n.getDefaultLocale(); - Locale configurationLocale = config.getLocale(); - if (!configurationLocale.equals(currentLocale)) { - if (log.isInfoEnabled()) { - log.info("re-init I18n with locale " + configurationLocale); - } - I18n.setDefaultLocale(configurationLocale); - reloadDecorators = true; - } - if (!config.getDbLocale().equals(decoratorService.getReferentialLocale().getLocale())) { - if (log.isInfoEnabled()) { - log.info("re-init db with locale " + config.getDbLocale()); - } - decoratorService.setReferentialLocale(ReferentialLocale.valueOf(config.getDbLocale())); - - reloadDecorators = true; - } - - if (reloadDecorators) { - if (log.isInfoEnabled()) { - log.info("reload decorators"); - } - decoratorService.reload(); - } - - JAXXInitialContext tx = new JAXXInitialContext(); - tx.add(context).add(errorModel); - - // show main ui - ObserveMainUI ui = new ObserveMainUI(tx); - ui.setUndecorated(config.isFullScreen()); - - String title = t("observe.title.welcome.admin") + (" v " + config.getVersion()); - ui.setTitle(title); - - context.setMainUI(ui); - - ErrorDialogUI.init(ui); - - // set fullscreen propery on main ui - ui.getGraphicsConfiguration().getDevice().setFullScreenWindow(config.isFullScreen() ? ui : null); - - new ObserveNavigationTreeShowPopupAction(ui.getNavigation(), ui.getNavigationScrollPane(), ui.getNavigationPopup()); - - return ui; - } +public class ObserveMainUIHandler implements UIHandler<ObserveMainUI> { public static final String H2_SERVER_URL_PATTERN = "jdbc:h2:%s/%s/obstuna"; - public static void restartEdit() { - ContentUI<?, ?> selectedUI = ObserveSwingApplicationContext.get().getContentUIManager().getSelectedContentUI(); - if (selectedUI == null) { - - // pas d'écran selectionne - return; - } - ContentUIModel<? extends AbstractObserveDto> model = selectedUI.getModel(); - if (!model.isEditable()) { - - // modele non editable - return; - } - - ContentMode contentMode = model.getMode(); - if (ContentMode.UPDATE != contentMode) { + private ObserveMainUI ui; - // ecran non en mode mis a jour - return; - } - - if (log.isDebugEnabled()) { - log.debug("Will restart edit for " + selectedUI.getName()); - } - selectedUI.restartEdit(); - - } - - /** - * Permet de recharger l'ui principale et de changer de le mode - * d'affichage. - * - * @param rootContext le contexte applicatif - * @param config la configuration a utiliser - */ - protected void reloadUI(ObserveSwingApplicationContext rootContext, ObserveSwingApplicationConfig config) { - -// // must remove all properties listener on config - config.removeJaxxPropertyChangeListener(); - - // scan main ui - ObserveMainUI ui = rootContext.getMainUI(); - - ObserveSwingDataSource mainStorage = rootContext.getDataSourcesManager().getMainDataSource(); - - ObserveUIMode oldMode = null; - String[] ids = null; - if (ui != null) { - - oldMode = ui.getMode(); - - ids = ui.getNavigation().getSelectedIds(); - - ErrorDialogUI.init(null); - - rootContext.removeMainUI(); - - ui.dispose(); - - ui.setVisible(false); - - System.runFinalization(); - } - - focusBorder = null; - noFocusBorder = null; - ui = initUI(rootContext, config); - - if (oldMode == null) { - if (mainStorage == null) { - oldMode = ObserveUIMode.NO_DB; - - } else { - oldMode = ObserveUIMode.DB; - } - } - - ui.setMode(oldMode); - - if (oldMode == ObserveUIMode.DB) { - - // on met à jour le modèle de navigation - NavigationTreeModel treeModel = ui.getNavigation().getTreeModel(); - treeModel.setLoadSeine(ui.getNavigationTreeHeader().getShowSeine().isSelected()); - treeModel.setLoadLongline(ui.getNavigationTreeHeader().getShowLongline().isSelected()); - treeModel.setLoadReferential(ui.getNavigationTreeHeader().getShowReferential().isSelected()); - treeModel.setLoadEmptyProgram(ui.getNavigationTreeHeader().getShowEmptyProgram().isSelected()); - - treeModel.populate(); - - // on conserve les noeuds a reselectionner - rootContext.setNodesToReselect(ids); - - // selection du noeud d'ouverture (le noeud precedemment selectionne, - // ou le noeud le plus ouvert - // ou le premier program si aucune donnée ouverte) - ui.getNavigation().selectInitialNode(); - } - - // show ui - UIHelper.setMainUIVisible(ui); - } - - protected Icon updateStorageSatutIcon(ObserveMainUI ui) { + protected Icon updateStorageSatutIcon() { Icon icon; if (ui.getConfig().isMainStorageOpened()) { @@ -411,7 +63,7 @@ public class ObserveMainUIHandler { return icon; } - protected String updateStorageSatutText(ObserveMainUI ui) { + protected String updateStorageSatutText() { String text; if (ui.getConfig().isMainStorageOpened()) { ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); @@ -422,7 +74,7 @@ public class ObserveMainUIHandler { return text; } - protected String updateStorageStatutToolTipText(ObserveMainUI ui) { + protected String updateStorageStatutToolTipText() { String text; if (ui.getConfig().isMainStorageOpened()) { ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); @@ -463,153 +115,13 @@ public class ObserveMainUIHandler { return l != null && l.toString().equals(expected); } - protected void $afterCompleteSetup(ObserveMainUI ui) { - - // bad binding, force value - ui.getStopH2WebServer().setEnabled(false); - - ui.getStatus().init(); - - // ajout d'un ecouteur sur la navigation pour toujours mettre la scrollbar - // tout à droite a chaque selection - ui.getNavigation().addTreeSelectionListener(e -> changeNavigationNode(ui, e)); - - SwingValidatorUtil.installUI(ui.getErrorTable(), new ObserveValidatorMessageTableRenderer()); - - // installation layer de blocage en mode busy - UIHelper.setLayerUI(ui.getBody(), ui.getBusyBlockLayerUI()); - - // ecoute des changements de l'état busy - ui.addPropertyChangeListener(ObserveMainUI.PROPERTY_BUSY, evt -> { - boolean newvalue = (boolean) evt.getNewValue(); - updateBusyState(ui, newvalue); - }); - - ui.addPropertyChangeListener(ObserveMainUI.PROPERTY_FOCUS_ON_NAVIGATION, evt -> { - boolean newvalue = (boolean) evt.getNewValue(); - updateFocusOnNavigation(ui, newvalue); - }); - - ui.getNavigationView().addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent e) { - ui.setFocusOnNavigation(true); - } - }); - ui.getNavigation().addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent e) { - ui.setFocusOnNavigation(true); - } - }); - ui.getNavigationTreeHeader().addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent e) { - ui.setFocusOnNavigation(true); - } - }); - ui.getSplitpane2().addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent e) { - ui.setFocusOnNavigation(false); - } - }); - } - - private Border focusBorder; - private Border noFocusBorder; - - public Border getFocusBorder() { - if (focusBorder == null) { - focusBorder = new LineBorder(ObserveSwingApplicationContext.get().getConfig().getFocusBorderColor(), 3, true); - } - return focusBorder; + @Override + public void beforeInit(ObserveMainUI ui) { + this.ui = ui; } - public Border getNoFocusBorder() { - if (noFocusBorder == null) { - noFocusBorder = new LineBorder(ObserveSwingApplicationContext.get().getConfig().getNoFocusBorderColor(), 3, true); - } - return noFocusBorder; - } - - private void updateFocusOnNavigation(ObserveMainUI ui, boolean newvalue) { - if (newvalue) { - if (log.isDebugEnabled()) { - log.debug("Focus on navigation"); - } - ui.getNavigationView().setBorder(getFocusBorder()); - ui.getSplitpane2().setBorder(getNoFocusBorder()); - } else { - if (log.isDebugEnabled()) { - log.debug("Focus on content"); - } - ui.getNavigationView().setBorder(getNoFocusBorder()); - ui.getSplitpane2().setBorder(getFocusBorder()); - } - } - - protected void updateBusyState(ObserveMainUI ui, boolean busy) { - if (busy) { - // ui bloquee - if (log.isDebugEnabled()) { - log.debug("block ui in busy mode"); - } - ui.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - } else { - // ui debloquee - if (log.isDebugEnabled()) { - log.debug("unblock ui in none busy mode"); - } - ui.setCursor(Cursor.getDefaultCursor()); - } - } - - /** - * Nettoye des ui tout ce qui concerne un modèle de navigation. - * - * <b>Note:</b> cette méthode doit être appelée avant tout rechargement de - * modèle de naivgation. - * - * @param mainUI l'ui principale - */ - public void cleanNavigationUI(ObserveMainUI mainUI) { - - // reset content uis - mainUI.getContentLayout().reset(mainUI.getContent()); - - // clean messages - mainUI.getContextValue(SwingValidatorMessageTableModel.class).clear(); - - // clean tree model - NavigationTree tree = mainUI.getNavigation(); - - tree.clearModel(); - - // no tree navigation view - tree.setVisible(false); - - } - - /** - * Charge dans l'ui un nouveau modèle de navigation. - * - * <b>Note:</b> cette méthode doit être appelée après tout rechargement de modèle de naivgation. - **/ - public void loadNavigationUI(ObserveMainUI mainUI) { - - NavigationTree tree = mainUI.getNavigation(); - - NavigationTreeModel treeModel = tree.getTreeModel(); - treeModel.populate(); - - // select initial node - tree.selectInitialNode(); - - tree.setVisible(true); - - mainUI.setFocusOnNavigation(true); - - SwingUtilities.invokeLater(tree::requestFocusInWindow); + @Override + public void afterInit(ObserveMainUI ui) { + ui.getInitializer().initialize(); } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIInitializer.java similarity index 76% copy from application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java copy to application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIInitializer.java index 3937401..38a76ff 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveMainUIInitializer.java @@ -27,10 +27,8 @@ import fr.ird.observe.application.swing.db.DataContext; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.application.swing.ui.content.ContentMode; import fr.ird.observe.application.swing.ui.content.ContentUI; import fr.ird.observe.application.swing.ui.content.ContentUIManager; -import fr.ird.observe.application.swing.ui.content.ContentUIModel; import fr.ird.observe.application.swing.ui.tree.ObserveNavigationTreeShowPopupAction; import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTreeModel; @@ -39,9 +37,7 @@ import fr.ird.observe.application.swing.ui.tree.navigation.nodes.ReferenceNaviga import fr.ird.observe.application.swing.ui.tree.navigation.nodes.StringNavigationTreeNodeSupport; import fr.ird.observe.application.swing.ui.util.ObserveSwingValidatorMessageTableModel; import fr.ird.observe.application.swing.ui.util.ObserveValidatorMessageTableRenderer; -import fr.ird.observe.services.dto.AbstractObserveDto; import fr.ird.observe.services.dto.constants.ReferentialLocale; -import jaxx.runtime.context.DefaultApplicationContext; import jaxx.runtime.context.JAXXInitialContext; import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; @@ -50,7 +46,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.i18n.I18n; -import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.SwingUtilities; import javax.swing.border.Border; @@ -75,15 +70,20 @@ import static org.nuiton.i18n.I18n.t; * @see ObserveMainUI * @since 1.0 */ -@DefaultApplicationContext.AutoLoad -public class ObserveMainUIHandler { +public class ObserveMainUIInitializer { /** Logger */ - private static final Log log = LogFactory.getLog(ObserveMainUIHandler.class); + private static final Log log = LogFactory.getLog(ObserveMainUIInitializer.class); private static final String EMPTY_SELECTION = "emptySelection"; - public void changeNavigationNode(ObserveMainUI ui, TreeSelectionEvent event) { + private final ObserveMainUI ui; + + public ObserveMainUIInitializer(ObserveMainUI ui) { + this.ui = ui; + } + + public void changeNavigationNode(TreeSelectionEvent event) { ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); if (source == null || !source.isOpen()) { @@ -232,7 +232,7 @@ public class ObserveMainUIHandler { * @param config la configuration a utiliser * @return l'ui instancie et initialisee mais non visible encore */ - public ObserveMainUI initUI(ObserveSwingApplicationContext context, ObserveSwingApplicationConfig config) { + public static ObserveMainUI initUI(ObserveSwingApplicationContext context, ObserveSwingApplicationConfig config) { SwingValidatorMessageTableModel errorModel = new ObserveSwingValidatorMessageTableModel(); @@ -286,36 +286,6 @@ public class ObserveMainUIHandler { return ui; } - public static final String H2_SERVER_URL_PATTERN = "jdbc:h2:%s/%s/obstuna"; - - public static void restartEdit() { - ContentUI<?, ?> selectedUI = ObserveSwingApplicationContext.get().getContentUIManager().getSelectedContentUI(); - if (selectedUI == null) { - - // pas d'écran selectionne - return; - } - ContentUIModel<? extends AbstractObserveDto> model = selectedUI.getModel(); - if (!model.isEditable()) { - - // modele non editable - return; - } - - ContentMode contentMode = model.getMode(); - if (ContentMode.UPDATE != contentMode) { - - // ecran non en mode mis a jour - return; - } - - if (log.isDebugEnabled()) { - log.debug("Will restart edit for " + selectedUI.getName()); - } - selectedUI.restartEdit(); - - } - /** * Permet de recharger l'ui principale et de changer de le mode * d'affichage. @@ -323,9 +293,9 @@ public class ObserveMainUIHandler { * @param rootContext le contexte applicatif * @param config la configuration a utiliser */ - protected void reloadUI(ObserveSwingApplicationContext rootContext, ObserveSwingApplicationConfig config) { + public void reloadUI(ObserveSwingApplicationContext rootContext, ObserveSwingApplicationConfig config) { -// // must remove all properties listener on config + // must remove all properties listener on config config.removeJaxxPropertyChangeListener(); // scan main ui @@ -391,79 +361,9 @@ public class ObserveMainUIHandler { UIHelper.setMainUIVisible(ui); } - protected Icon updateStorageSatutIcon(ObserveMainUI ui) { - Icon icon; + protected void initialize() { - if (ui.getConfig().isMainStorageOpened()) { - - ObserveSwingDataSource service = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); - - if (service.isLocal()) { - icon = (Icon) ui.storageStatus.getClientProperty("localIcon"); - } else if (service.isRemote()) { - icon = (Icon) ui.storageStatus.getClientProperty("remoteIcon"); - } else { - icon = (Icon) ui.storageStatus.getClientProperty("serverIcon"); - } - } else { - icon = (Icon) ui.storageStatus.getClientProperty("noneIcon"); - } - return icon; - } - - protected String updateStorageSatutText(ObserveMainUI ui) { - String text; - if (ui.getConfig().isMainStorageOpened()) { - ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); - text = source.getLabel(); - } else { - text = t("observe.message.db.none.loaded"); - } - return text; - } - - protected String updateStorageStatutToolTipText(ObserveMainUI ui) { - String text; - if (ui.getConfig().isMainStorageOpened()) { - ObserveSwingDataSource source = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); - text = t("observe.message.loaded.tip", source.getLabel()); - } else { - text = t("observe.message.db.none.loaded.tip"); - } - return text; - } - - public boolean acceptMode(ObserveUIMode mode, ObserveUIMode... modes) { - return acceptMode(mode, true, modes); - } - - public boolean acceptMode(ObserveUIMode mode, boolean condition, ObserveUIMode... modes) { - if (condition) { - for (ObserveUIMode m : modes) { - if (m.equals(mode)) { - return true; - } - } - } - return false; - } - - public boolean acceptMode(ObserveUIMode mode, boolean notBusy, boolean condition, ObserveUIMode... modes) { - if (notBusy && condition) { - for (ObserveUIMode m : modes) { - if (m.equals(mode)) { - return true; - } - } - } - return false; - } - - public boolean acceptLocale(Locale l, String expected) { - return l != null && l.toString().equals(expected); - } - - protected void $afterCompleteSetup(ObserveMainUI ui) { + MnemonicHelper.addKeyStrokeFromMnemonic(ui); // bad binding, force value ui.getStopH2WebServer().setEnabled(false); @@ -472,7 +372,7 @@ public class ObserveMainUIHandler { // ajout d'un ecouteur sur la navigation pour toujours mettre la scrollbar // tout à droite a chaque selection - ui.getNavigation().addTreeSelectionListener(e -> changeNavigationNode(ui, e)); + ui.getNavigation().addTreeSelectionListener(this::changeNavigationNode); SwingValidatorUtil.installUI(ui.getErrorTable(), new ObserveValidatorMessageTableRenderer()); @@ -482,12 +382,12 @@ public class ObserveMainUIHandler { // ecoute des changements de l'état busy ui.addPropertyChangeListener(ObserveMainUI.PROPERTY_BUSY, evt -> { boolean newvalue = (boolean) evt.getNewValue(); - updateBusyState(ui, newvalue); + updateBusyState(newvalue); }); ui.addPropertyChangeListener(ObserveMainUI.PROPERTY_FOCUS_ON_NAVIGATION, evt -> { boolean newvalue = (boolean) evt.getNewValue(); - updateFocusOnNavigation(ui, newvalue); + updateFocusOnNavigation(newvalue); }); ui.getNavigationView().addMouseListener(new MouseAdapter() { @@ -533,7 +433,7 @@ public class ObserveMainUIHandler { return noFocusBorder; } - private void updateFocusOnNavigation(ObserveMainUI ui, boolean newvalue) { + private void updateFocusOnNavigation(boolean newvalue) { if (newvalue) { if (log.isDebugEnabled()) { log.debug("Focus on navigation"); @@ -549,7 +449,7 @@ public class ObserveMainUIHandler { } } - protected void updateBusyState(ObserveMainUI ui, boolean busy) { + protected void updateBusyState(boolean busy) { if (busy) { // ui bloquee if (log.isDebugEnabled()) { @@ -568,21 +468,18 @@ public class ObserveMainUIHandler { /** * Nettoye des ui tout ce qui concerne un modèle de navigation. * - * <b>Note:</b> cette méthode doit être appelée avant tout rechargement de - * modèle de naivgation. - * - * @param mainUI l'ui principale + * <b>Note:</b> cette méthode doit être appelée avant tout rechargement de modèle de naivgation. */ - public void cleanNavigationUI(ObserveMainUI mainUI) { + public void cleanNavigationUI() { // reset content uis - mainUI.getContentLayout().reset(mainUI.getContent()); + ui.getContentLayout().reset(ui.getContent()); // clean messages - mainUI.getContextValue(SwingValidatorMessageTableModel.class).clear(); + ui.getContextValue(SwingValidatorMessageTableModel.class).clear(); // clean tree model - NavigationTree tree = mainUI.getNavigation(); + NavigationTree tree = ui.getNavigation(); tree.clearModel(); @@ -596,9 +493,9 @@ public class ObserveMainUIHandler { * * <b>Note:</b> cette méthode doit être appelée après tout rechargement de modèle de naivgation. **/ - public void loadNavigationUI(ObserveMainUI mainUI) { + public void loadNavigationUI() { - NavigationTree tree = mainUI.getNavigation(); + NavigationTree tree = ui.getNavigation(); NavigationTreeModel treeModel = tree.getTreeModel(); treeModel.populate(); @@ -608,7 +505,7 @@ public class ObserveMainUIHandler { tree.setVisible(true); - mainUI.setFocusOnNavigation(true); + ui.setFocusOnNavigation(true); SwingUtilities.invokeLater(tree::requestFocusInWindow); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveUICallback.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveUICallback.java index 81578ab..4a1bcff 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveUICallback.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/ObserveUICallback.java @@ -68,7 +68,7 @@ public enum ObserveUICallback implements Runnable { ObserveSwingApplicationContext context = ObserveSwingApplicationContext.get(); ObserveMainUI ui = context.getMainUI(); ObserveSwingApplicationConfig config = ui.getConfig(); - ui.getHandler().reloadUI(context, config); + ui.getInitializer().reloadUI(context, config); } }, db(n("observe.action.reload.storage"), diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/UIHelper.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/UIHelper.java index 89b80cc..ac9e3f1 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/UIHelper.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/UIHelper.java @@ -49,21 +49,16 @@ import javax.swing.JTable; import javax.swing.JTree; import javax.swing.SwingUtilities; import javax.swing.UIDefaults; -import javax.swing.event.HyperlinkEvent; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import java.awt.Color; import java.awt.Component; -import java.awt.Desktop; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.io.File; import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; import java.util.Arrays; -import java.util.List; import static org.nuiton.i18n.I18n.t; @@ -168,43 +163,25 @@ public class UIHelper extends SwingUtil { } - public static int askUser(String title, - String message, - int typeMessage, - Object[] options, - int defaultOption) { - return askUser( - null, - title, - message, - typeMessage, - options, - defaultOption - ); + public static int askUser(String title, String message, int typeMessage, Object[] options, int defaultOption) { + return askUser(null, title, message, typeMessage, options, defaultOption); } - public static int askUser(Component parent, - String title, - Object message, - int typeMessage, - Object[] options, - int defaultOption) { + public static int askUser(Component parent, String title, Object message, int typeMessage, Object[] options, int defaultOption) { if (parent == null) { ObserveSwingApplicationContext tx = ObserveSwingApplicationContext.get(); if (tx != null) { parent = ObserveSwingApplicationContext.get().getMainUI(); } } - return JOptionPane.showOptionDialog( - parent, - message, - title, - JOptionPane.DEFAULT_OPTION, - typeMessage, - null, - options, - options[defaultOption] - ); + return JOptionPane.showOptionDialog(parent, + message, + title, + JOptionPane.DEFAULT_OPTION, + typeMessage, + null, + options, + options[defaultOption]); } /** @@ -219,11 +196,7 @@ public class UIHelper extends SwingUtil { * @return le fichier choisi ou le fichier incoming si l'opération a été * annulée */ - public static File chooseFile(Component parent, - String title, - String buttonLabel, - File incoming, - String... filters) { + public static File chooseFile(Component parent, String title, String buttonLabel, File incoming, String... filters) { JaxxFileChooser.ToLoadFile toLoadFile = JaxxFileChooser.forLoadingFile() .setParent(parent) @@ -236,7 +209,7 @@ public class UIHelper extends SwingUtil { toLoadFile.setStartDirectory(parentDirectoryIfExist); } File file = toLoadFile.choose(); - ; + if (log.isDebugEnabled()) { log.debug(title + " : " + file); } @@ -253,10 +226,7 @@ public class UIHelper extends SwingUtil { * @return le répertoire choisi ou le répertoire incoming si l'opération a * été annulée */ - public static File chooseDirectory(Component parent, - String title, - String buttonLabel, - File incoming) { + public static File chooseDirectory(Component parent, String title, String buttonLabel, File incoming) { JaxxFileChooser.ToLoadDirectory toLoadDirectory = JaxxFileChooser.forLoadingDirectory() .setParent(parent) @@ -298,10 +268,7 @@ public class UIHelper extends SwingUtil { * @return {@code true} si l'utilisateur a confitmé la suppression, * {@code false} sinon. */ - public static <E extends IdDto> boolean confirmForEntityDelete( - JAXXObject parent, - Class<E> beanClass, - E bean) { + public static <E extends IdDto> boolean confirmForEntityDelete(JAXXObject parent, Class<E> beanClass, E bean) { return confirmForEntityDelete(parent, beanClass, bean, null); } @@ -317,11 +284,7 @@ public class UIHelper extends SwingUtil { * @return {@code true} si l'utilisateur a confitmé la suppression, * {@code false} sinon. */ - public static <E extends IdDto> boolean confirmForEntityDelete( - JAXXObject parent, - Class<E> beanClass, - E bean, - String extraMessage) { + public static <E extends IdDto> boolean confirmForEntityDelete(JAXXObject parent, Class<E> beanClass, E bean, String extraMessage) { ObserveMainUI mainUI = ObserveSwingApplicationContext.get().getMainUI(); if (parent == null) { @@ -440,44 +403,6 @@ public class UIHelper extends SwingUtil { SwingUtilities.invokeLater(() -> ui.setVisible(true)); } - public static <E extends IdDto> E getEntity(List<E> list, E entity) { - for (E e : list) { - if (e.getId().equals(entity.getId())) { - return e; - } - } - return null; - } - - /** - * Open a link coming from a {@link HyperlinkEvent}. - * - * And try to open the link if an url in a browser. - * - * @param he the event to treate - * @since 1.6.0 - */ - public static void openLink(HyperlinkEvent he) { - if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - - if (Desktop.isDesktopSupported()) { - try { - URL u = he.getURL(); - if (u.getProtocol().equalsIgnoreCase("mailto") || - u.getProtocol().equalsIgnoreCase("http") || - u.getProtocol().equalsIgnoreCase("ftp") || - u.getProtocol().equalsIgnoreCase("file")) { - Desktop.getDesktop().browse(u.toURI()); - } - } catch (IOException | URISyntaxException e) { - if (log.isErrorEnabled()) { - log.error("Error while opening link", e); - } - } - } - } - } - public static void stopEditing(JTable table) { TableCellEditor cellEditor = table.getCellEditor(); if (cellEditor != null) { @@ -577,7 +502,6 @@ public class UIHelper extends SwingUtil { } - public static void initUI(JScrollPane selectedTreePane, JTree tree) { // customize tree selection colors diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ShowConfigAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ShowConfigAction.java index 1b1a036..1c455f9 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ShowConfigAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ShowConfigAction.java @@ -29,7 +29,6 @@ import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationCon import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; import fr.ird.observe.application.swing.ui.ObserveMainUI; -import fr.ird.observe.application.swing.ui.ObserveMainUIHandler; import fr.ird.observe.application.swing.ui.ObserveUICallback; import fr.ird.observe.services.dto.referential.ReferentialReference; import fr.ird.observe.services.dto.referential.SpeciesListDto; @@ -43,7 +42,6 @@ import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.renderer.DefaultTableRenderer; import org.nuiton.config.ConfigOptionDef; import org.nuiton.decorator.Decorator; -import org.nuiton.decorator.MultiJXPathDecorator; import javax.swing.AbstractAction; import javax.swing.DefaultCellEditor; @@ -137,7 +135,7 @@ public class ShowConfigAction extends AbstractAction { helper.setFinalizer(new MainCallBackFinalizer(ObserveUICallback.application.name())); - helper.setCloseAction(ObserveMainUIHandler::restartEdit); + helper.setCloseAction(ObserveSwingApplicationContext.get().getContentUIManager()::restartEdit); addApplicatinOptions(helper); addUiOptions(helper); @@ -178,6 +176,7 @@ public class ShowConfigAction extends AbstractAction { helper.addOption(ObserveSwingApplicationConfigOption.SHOW_NUMBER_EDITOR_BUTTON); helper.addOption(ObserveSwingApplicationConfigOption.AUTO_POPUP_NUMBER_EDITOR); helper.addOption(ObserveSwingApplicationConfigOption.SHOW_DATE_TIME_EDITOR_SLIDER); + helper.addOption(ObserveSwingApplicationConfigOption.SHOW_MNEMONIC); helper.addOption(ObserveSwingApplicationConfigOption.COORDINATE_FORMAT); helper.addOption(ObserveSwingApplicationConfigOption.FOCUS_BORDER_COLOR); @@ -292,15 +291,6 @@ public class ShowConfigAction extends AbstractAction { return super.addOption(def).setOptionShortLabel(def.getDescription()); } - public ConfigUIModelBuilder addOption(ObserveSwingApplicationConfigOption option, ObserveUICallback callBack) { - - addOption(option); - setOptionCallBack(callBack.name()); - - return modelBuilder; - - } - public ConfigUIModelBuilder registerCallBack(ObserveUICallback callback) { String name = callback.name(); @@ -363,7 +353,7 @@ public class ShowConfigAction extends AbstractAction { this.entityMap = entityMap; this.decorator = decorator; - final BeanFilterableComboBox<ReferentialReference<SpeciesListDto>> component = new BeanFilterableComboBox<>(); + BeanFilterableComboBox<ReferentialReference<SpeciesListDto>> component = new BeanFilterableComboBox<>(); component.setI18nPrefix("observe.common."); component.setShowReset(true); component.setBeanType((Class) ReferentialReference.class); @@ -379,7 +369,7 @@ public class ShowConfigAction extends AbstractAction { public void setValue(Object value) { if (value != null && String.class.isInstance(value)) { - value = SpeciesListTableCellEditor.this.entityMap.get(value); + value = SpeciesListTableCellEditor.this.entityMap.get(String.valueOf(value)); } component.setSelectedItem(value); } @@ -415,7 +405,7 @@ public class ShowConfigAction extends AbstractAction { } }; - component.init((MultiJXPathDecorator) this.decorator, Lists.newArrayList(entities)); + component.init(this.decorator, Lists.newArrayList(entities)); } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ToFullScreenAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ToFullScreenAction.java new file mode 100644 index 0000000..5580057 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ToFullScreenAction.java @@ -0,0 +1,41 @@ +package fr.ird.observe.application.swing.ui.actions; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import jaxx.runtime.SwingUtil; + +import javax.swing.AbstractAction; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 6.0 + */ +public class ToFullScreenAction extends AbstractAction { + + private static final long serialVersionUID = 3038774900992805790L; + + private final ObserveMainUI ui; + + public ToFullScreenAction(ObserveMainUI ui) { + + super(t("observe.action.toFullScreen"), SwingUtil.getUIManagerActionIcon("full-screen")); + this.ui = ui; + putValue(SHORT_DESCRIPTION, t("observe.action.toFullScreen.tip")); + putValue(MNEMONIC_KEY, (int) 'S'); + + } + + @Override + public void actionPerformed(ActionEvent e) { + + ui.getConfig().setFullScreen(true); + + ui.getInitializer().reloadUI(ObserveSwingApplicationContext.get(), ui.getConfig()); + + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ToWindowScreenAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ToWindowScreenAction.java new file mode 100644 index 0000000..6e75251 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/ToWindowScreenAction.java @@ -0,0 +1,40 @@ +package fr.ird.observe.application.swing.ui.actions; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.ObserveMainUI; +import jaxx.runtime.SwingUtil; + +import javax.swing.AbstractAction; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 6.0 + */ +public class ToWindowScreenAction extends AbstractAction { + + private static final long serialVersionUID = 3038774900992805790L; + + private final ObserveMainUI ui; + + public ToWindowScreenAction(ObserveMainUI ui) { + + super(t("observe.action.toWindowScreen"), SwingUtil.getUIManagerActionIcon("window-screen")); + this.ui = ui; + putValue(SHORT_DESCRIPTION, t("observe.action.toWindowScreen.tip")); + putValue(MNEMONIC_KEY, (int) 'S'); + + } + + @Override + public void actionPerformed(ActionEvent e) { + + ui.getConfig().setFullScreen(false); + ui.getInitializer().reloadUI(ObserveSwingApplicationContext.get(), ui.getConfig()); + + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/AbstractContentUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/AbstractContentUIAction.java index 805a94b..6744253 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/AbstractContentUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/AbstractContentUIAction.java @@ -45,7 +45,7 @@ public abstract class AbstractContentUIAction extends AbstractUIAction { @Override public final void actionPerformed(ActionEvent e) { - if (!canExecuteAction(e)) { + if (!canExecuteAction()) { return; } ContentUI<?, ?> contentUI = getContentUI(e); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/global/AbstractGlobalUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/global/AbstractGlobalUIAction.java index 05c1a5d..b8a3502 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/global/AbstractGlobalUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/global/AbstractGlobalUIAction.java @@ -49,7 +49,6 @@ public abstract class AbstractGlobalUIAction extends AbstractUIAction { if (focusOnNavigation) { -// SwingUtilities.invokeLater(focusOwner::grabFocus); SwingUtilities.invokeLater(focusOwner::requestFocusInWindow); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/AbstractUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/AbstractUIAction.java index 2f9be25..fcfd9bf 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/AbstractUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/AbstractUIAction.java @@ -22,6 +22,7 @@ package fr.ird.observe.application.swing.ui.actions.shared; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ui.MnemonicHelper; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.content.ContentUI; import jaxx.runtime.SwingUtil; @@ -56,29 +57,11 @@ public abstract class AbstractUIAction extends AbstractAction { private final ObserveMainUI mainUI; - public AbstractUIAction(ObserveMainUI mainUI, - String actionCommandKey, - String label, - String shortDescription, - String actionIcon, - String acceleratorKey) { + public AbstractUIAction(ObserveMainUI mainUI, String actionCommandKey, String label, String shortDescription, String actionIcon, String acceleratorKey) { super(t(label), SwingUtil.getUIManagerActionIcon(actionIcon)); putValue(ACTION_COMMAND_KEY, actionCommandKey); this.mainUI = mainUI; - if (acceleratorKey != null) { - - KeyStroke keyStroke = KeyStroke.getKeyStroke(acceleratorKey); - Objects.requireNonNull(keyStroke, "KeyStroke invalide: " + acceleratorKey); - putValue(ACCELERATOR_KEY, keyStroke); - - String acceleratorStr = " (" + keyStroke.toString().replace(" pressed ", " + ") + ")"; - - putValue(NAME, t(label) + acceleratorStr); - putValue(SHORT_DESCRIPTION, t(shortDescription) + acceleratorStr); - } else { - - putValue(SHORT_DESCRIPTION, t(shortDescription)); - } + MnemonicHelper.addKeyStore(this, acceleratorKey, label, shortDescription); } public KeyStroke getAcceleratorKey() { @@ -97,34 +80,20 @@ public abstract class AbstractUIAction extends AbstractAction { editor.setAction(this); editor.putClientProperty("ui", ui); putValue(EDITOR, editor); + KeyStroke keyStroke = getAcceleratorKey(); if (keyStroke != null) { + String actionCommandKey = getActionCommandKey(); -// ui.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke, actionCommandKey); ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, actionCommandKey); ui.getActionMap().put(actionCommandKey, this); } } public void updateAction(ContentUI<?, ?> ui, AbstractButton editor) { - String tip = (String) editor.getClientProperty("toolTipText"); - if (tip != null) { - KeyStroke keyStroke = getAcceleratorKey(); - if (keyStroke != null) { - String acceleratorStr = " (" + keyStroke.toString().replace(" pressed ", " + ") + ")"; - tip += acceleratorStr; - } - editor.setToolTipText(tip); - } - String text = (String) editor.getClientProperty("text"); - if (text != null) { - KeyStroke keyStroke = getAcceleratorKey(); - if (keyStroke != null) { - String acceleratorStr = " (" + keyStroke.toString().replace(" pressed ", " + ") + ")"; - text += acceleratorStr; - } - editor.setText(text); - } + + MnemonicHelper.addKeyStroke2(editor, getAcceleratorKey()); + String actionIcon = (String) editor.getClientProperty("actionIcon"); if (actionIcon != null) { Icon icon = SwingUtil.getUIManagerActionIcon(actionIcon); @@ -133,7 +102,7 @@ public abstract class AbstractUIAction extends AbstractAction { } - protected boolean canExecuteAction(ActionEvent e) { + protected boolean canExecuteAction() { JComponent editor = getEditor(); if ((editor == null || (editor.isVisible() && editor.isEnabled()))) { return true; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectOpenNodeUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectOpenNodeUIAction.java index b7c14f0..6a38c34 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectOpenNodeUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/shared/SelectOpenNodeUIAction.java @@ -51,7 +51,7 @@ public class SelectOpenNodeUIAction extends AbstractUIAction { @Override public void actionPerformed(ActionEvent e) { - if (!canExecuteAction(e)) { + if (!canExecuteAction()) { return; } JComponent c = (JComponent) e.getSource(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUI.jaxx index 76a36e8..f76cb7b 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUI.jaxx @@ -44,27 +44,23 @@ <AdminUIModel id='model' initializer='getContextValue(AdminUIModel.class)'/> - <AdminActionModel id='stepModel' initializer='model.getStepModel(getStep())'/> + <StorageUIModel id='localSourceModel' initializer='getModel().getConfigModel().getLocalSourceModel()'/> - <StorageUIModel id='localSourceModel' initializer='getModel().getLocalSourceModel()'/> + <StorageUIModel id='centralSourceModel' initializer='getModel().getConfigModel().getCentralSourceModel()'/> - <StorageUIModel id='centralSourceModel' initializer='getModel().getCentralSourceModel()'/> + <AdminTabUIHandler id='internalHandler'/> - <AdminTabUIHandler id='handler' initializer='null'/> + <script><![CDATA[ - <AdminStep id='step' initializer='null'/> +public abstract AdminTabUIHandler getHandler(); - <script><![CDATA[ +public abstract AdminActionModel getStepModel(); -public abstract void initUI(AdminUI ui); +public AdminStep getStep() { return getStepModel().getStep(); } -protected AdminTabUI(AdminStep step, AdminUI parentContext) { - this.step = step; +protected AdminTabUI(AdminUI parentContext) { UIHelper.checkJAXXContextEntry(parentContext, UIHelper.newContextEntryDef(AdminUIModel.class)); UIHelper.initContext(this, parentContext); - $initialize(); - // pour etre sur que step est positionne (la methode d'init supprime la reference... - this.step = step; } public void destroy() { @@ -106,12 +102,10 @@ public void updateState(WizardState newState) { <!-- content --> <JPanel id='content' decorator='boxed' constraints='BorderLayout.CENTER'> - <JPanel id='PENDING_content' - constraints='WizardState.PENDING.name()'/> + <JPanel id='PENDING_content' constraints='WizardState.PENDING.name()'/> - <Table id="NEED_FIX_panel" fill='both' - constraints='WizardState.NEED_FIX.name()'> + <Table id="NEED_FIX_panel" fill='both' constraints='WizardState.NEED_FIX.name()'> <row> <cell fill='both'> <JPanel id="NEED_FIX_labelPanel"> @@ -128,8 +122,7 @@ public void updateState(WizardState newState) { </Table> - <Table id="FAILED_panel" fill='both' - constraints='WizardState.FAILED.name()'> + <Table id="FAILED_panel" fill='both' constraints='WizardState.FAILED.name()'> <row> <cell fill='both'> <JLabel id='FAILED_label'/> @@ -143,8 +136,7 @@ public void updateState(WizardState newState) { </Table> - <Table id="RUNNING_panel" fill='both' - constraints='WizardState.RUNNING.name()'> + <Table id="RUNNING_panel" fill='both' constraints='WizardState.RUNNING.name()'> <row> <cell fill='both' weighty='0.3'> <JPanel id="RUNNING_top"> @@ -159,8 +151,7 @@ public void updateState(WizardState newState) { </row> </Table> - <Table id="SUCCESSED_panel" fill='both' - constraints='WizardState.SUCCESSED.name()'> + <Table id="SUCCESSED_panel" fill='both' constraints='WizardState.SUCCESSED.name()'> <row> <cell fill='both' weighty='0.3'> <JLabel id='SUCCESSED_label'/> @@ -190,9 +181,8 @@ public void updateState(WizardState newState) { <JToolBar id='progressionTop' constraints='"PROGRESSION_TOP"'> <JLabel id='progressionTopLabel'/> <javax.swing.Box.Filler - constructorParams='UIHelper.newMinDimension(), UIHelper.newMinDimension(), UIHelper.newMaxXDimension()'/> - <JButton id="progressionTopCopyCliptBoard" - onActionPerformed='UIHelper.copyToClipBoard(progression.getText())'/> + constructorParams='UIHelper.newMinDimension(), UIHelper.newMinDimension(), UIHelper.newMaxXDimension()'/> + <JButton id="progressionTopCopyCliptBoard" onActionPerformed='UIHelper.copyToClipBoard(progression.getText())'/> </JToolBar> </JPanel> @@ -203,6 +193,6 @@ public void updateState(WizardState newState) { <JPanel id='invisiblePanel' visible="false" constraints='BorderLayout.EAST'> - </JPanel> + </JPanel> </JPanel> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUI.jcss index 859c38e..f1c3597 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUI.jcss @@ -30,7 +30,7 @@ } #progress { - string:{getHandler().getProgressString(model.getStepIndex(model.getStep()), model.getSteps().size())}; + /*string:{internalHandler.getProgressString(model.getStepIndex(model.getStep()), model.getSteps().size())};*/ value:{1 + model.getStepIndex(model.getStep())}; maximum:{model.getSteps().size()}; indeterminate:{model.getModelState() == WizardState.RUNNING}; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUIHandler.java index 3e8f11f..89857df 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminTabUIHandler.java @@ -56,26 +56,50 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class AdminTabUIHandler { +public class AdminTabUIHandler<U extends AdminTabUI> { /** Logger */ private static final Log log = LogFactory.getLog(AdminTabUIHandler.class); - protected final AdminTabUI ui; + protected U ui; - protected final AdminUIModel model; + protected AdminUIModel model; protected AdminUI parentUI; /** Service de decoration. */ private DecoratorService decoratorService; - public AdminTabUIHandler(AdminTabUI ui) { + public void beforeInit(U ui) { this.ui = ui; - model = ui.getModel(); + this.model = ui.getModel(); + this.parentUI = ui.getContextValue(AdminUI.class, "parent"); } - public AdminTabUI getUi() { + public void afterInit(U ui) { + + model.addPropertyChangeListener(AdminUIModel.STEP_PROPERTY_NAME, e -> ui.getProgress().setString(getProgressString(model.getStepIndex(model.getStep()), model.getSteps().size()))); + model.addPropertyChangeListener(AdminUIModel.STEPS_PROPERTY_NAME, e -> ui.getProgress().setString(getProgressString(model.getStepIndex(model.getStep()), model.getSteps().size()))); + + AdminStep step = ui.getStep(); + + //FIXME ? ui.addPropertyChangeListener(parentUI); + + if (log.isDebugEnabled()) { + log.debug("common for [" + step + "] for main ui " + parentUI.getClass().getName() + "@" + System.identityHashCode(ui)); + } + + String stepLabel = I18nEnumHelper.getLabel(step); + ui.getRUNNING_label().setText(t("observe.actions.operation.message.running", stepLabel)); + ui.SUCCESSED_label.setText(t("observe.actions.operation.message.successed", stepLabel)); + ui.NEED_FIX_label.setText(t("observe.actions.operation.message.needFix", stepLabel)); + ui.CANCELED_label.setText(t("observe.actions.operation.message.canceled", stepLabel)); + ui.FAILED_label.setText(t("observe.actions.operation.message.failed", stepLabel)); + ui.progression.setVisible(true); + ui.progressionTop.setVisible(true); + } + + public U getUi() { return ui; } @@ -90,27 +114,6 @@ public class AdminTabUIHandler { return decoratorService; } - public void initTabUI(AdminUI ui, AdminTabUI tabUI) { - - parentUI = ui; - AdminStep step = tabUI.getStep(); - - tabUI.addPropertyChangeListener(tabUI); - - if (log.isDebugEnabled()) { - log.debug("common for [" + step + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } - - String stepLabel = I18nEnumHelper.getLabel(step); - tabUI.getRUNNING_label().setText(t("observe.actions.operation.message.running", stepLabel)); - tabUI.SUCCESSED_label.setText(t("observe.actions.operation.message.successed", stepLabel)); - tabUI.NEED_FIX_label.setText(t("observe.actions.operation.message.needFix", stepLabel)); - tabUI.CANCELED_label.setText(t("observe.actions.operation.message.canceled", stepLabel)); - tabUI.FAILED_label.setText(t("observe.actions.operation.message.failed", stepLabel)); - tabUI.progression.setVisible(true); - tabUI.progressionTop.setVisible(true); - } - public void updateState(AdminTabUI ui, WizardState newState) { if (newState == null) { newState = WizardState.PENDING; @@ -202,8 +205,6 @@ public class AdminTabUIHandler { ReferentialReference<ProgramDto> program, DataReference trip) { -// DecoratorService decoratorService = getDecoratorService(); - if (tripResult.isDeleted()) { String message = sendLogResultMessage(deleteI18nKey, programDecorator, program, trip, tripResult.getDeleteTime()); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUI.jaxx index fd25de8..fd567b7 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUI.jaxx @@ -23,6 +23,7 @@ <JPanel id='synchroPanel' implements='jaxx.runtime.swing.wizard.ext.WizardExtUI<AdminStep, AdminUIModel>'> <import> + fr.ird.observe.application.swing.ui.MnemonicHelper fr.ird.observe.application.swing.ui.UIHelper jaxx.runtime.JAXXContext @@ -38,10 +39,6 @@ <!-- le modèle du wizard --> <AdminUIModel id='model' initializer='getContextValue(AdminUIModel.class)'/> - <!-- le controleur d'ui --> - <AdminUIHandler id='handler' - initializer='getContextValue(AdminUIHandler.class)'/> - <!-- le bloqueur d'ui utilisé par l'assistant --> <BlockingLayerUI id='tabBusyBlockLayerUI'/> @@ -72,7 +69,7 @@ public AdminUI(JAXXContext parentContext, String title, String tip, ImageIcon ic } public void destroy() { - getHandler().destroy(this); + handler.destroy(); } @Override @@ -83,88 +80,76 @@ protected void finalize() throws Throwable { @Override public void start() { - getHandler().start(this); + handler.start(); } public void cancel() { - getHandler().cancel(this); + handler.cancel(); } public void dispose() { - getHandler().dispose(this); + handler.dispose(); } @Override public AdminStep getSelectedStep() { - return getHandler().getSelectedStep(this); + return handler.getSelectedStep(); } @Override public AdminTabUI getStepUI(AdminStep step) { - return getHandler().getStepUI(this, step); + return handler.getStepUI(step); } @Override public AdminTabUI getStepUI(int stepIndex) { - return getHandler().getStepUI(this, stepIndex); + return handler.getStepUI(stepIndex); } @Override public AdminTabUI getSelectedStepUI() { - return getHandler().getSelectedStepUI(this); + return handler.getSelectedStepUI(); } public void blockOperations() { - getHandler().blockOperations(this); + handler.blockOperations(); } @Override public void onWasInit() { - getHandler().onWasInit(this); + handler.onWasInit(); } @Override public void onWasStarted() { - getHandler().onWasStarted(this); + handler.onWasStarted(); } @Override public void onModelStateChanged(WizardState newState) { - getHandler().onModelStateChanged(this, newState); + handler.onModelStateChanged(newState); } @Override public void onOperationStateChanged(AdminStep step, WizardState newState) { - getHandler().onOperationStateChanged(this, step, newState); + handler.onOperationStateChanged(step, newState); } @Override public void onStepChanged(AdminStep oldStep, AdminStep newStep) { - getHandler().onStepChanged(this, oldStep, newStep); + handler.onStepChanged(oldStep, newStep); } @Override public void onStepsChanged(AdminStep[] steps) { - getHandler().onStepsChanged(this, steps); + handler.onStepsChanged(steps); } -void $afterCompleteSetup() { - if (!allComponentsCreated || !contextInitialized) { - // pour partir quand l'ui n'est pas complementement initialise - // par example dans l'init de la classe parent - return; - } - - // installation du dispatcher de modifications du modele - WizardExtUtil.installWizardUIListeners(this); - WizardExtUtil.addTraceLogListener(log, getModel()); -} ]]> </script> <!-- les onglets --> - <JTabbedPane id='tabs' decorator='boxed' - constraints='BorderLayout.CENTER' + <JTabbedPane id='tabs' decorator='boxed' constraints='BorderLayout.CENTER' onStateChanged='if (!model.isValueAdjusting()) { model.gotoStep(getSelectedStep()); }'/> <!-- les actions --> @@ -178,14 +163,12 @@ void $afterCompleteSetup() { <cell weightx='0.5' fill="both"> <!-- quitter apres une annulation ou une erreur --> - <JButton id='closeOnCanceledOrFailedAction' - onActionPerformed='getHandler().cancel(this)'/> + <JButton id='closeOnCanceledOrFailedAction' onActionPerformed='handler.cancel()'/> </cell> <cell weightx='0.5' fill="both"> <!-- pour aller sur l'onglet précédent --> - <JButton id="previousAction" - onActionPerformed='model.gotoPreviousStep()'/> + <JButton id="previousAction" onActionPerformed='model.gotoPreviousStep()'/> </cell> <cell weightx='0.5' fill="both"> @@ -195,7 +178,7 @@ void $afterCompleteSetup() { <cell weightx='0.5' fill="both"> <!-- quitter quand les opérations sont exécutées correctement --> - <JButton id="closeAction" onActionPerformed='getHandler().close(this)'/> + <JButton id="closeAction" onActionPerformed='handler.close()'/> </cell> </row> </Table> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIHandler.java index 565cc11..98409c8 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIHandler.java @@ -24,12 +24,13 @@ package fr.ird.observe.application.swing.ui.admin; import fr.ird.observe.application.swing.I18nEnumHelper; import fr.ird.observe.application.swing.ObserveActionExecutor; import fr.ird.observe.application.swing.ObserveRunner; +import fr.ird.observe.application.swing.ui.MnemonicHelper; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; import fr.ird.observe.application.swing.ui.admin.config.SelectDataUI; import fr.ird.observe.application.swing.ui.admin.resume.ShowResumeUI; import fr.ird.observe.application.swing.ui.admin.save.SaveLocalUI; -import fr.ird.observe.application.swing.ui.tree.selection.SelectionTree; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.wizard.WizardUILancher; import jaxx.runtime.swing.wizard.ext.WizardExtUtil; import jaxx.runtime.swing.wizard.ext.WizardState; @@ -39,7 +40,6 @@ import org.apache.commons.logging.LogFactory; import javax.swing.Icon; import javax.swing.JCheckBox; import javax.swing.JComponent; -import javax.swing.SwingUtilities; import javax.swing.border.TitledBorder; import java.awt.Component; import java.util.Arrays; @@ -53,12 +53,28 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class AdminUIHandler { +public class AdminUIHandler implements UIHandler<AdminUI> { /** Logger */ private static final Log log = LogFactory.getLog(AdminUIHandler.class); - public AdminStep getSelectedStep(AdminUI ui) { + private AdminUI ui; + + @Override + public void beforeInit(AdminUI ui) { + this.ui = ui; + } + + @Override + public void afterInit(AdminUI ui) { + + // installation du dispatcher de modifications du modele + WizardExtUtil.installWizardUIListeners(ui); + WizardExtUtil.addTraceLogListener(log, ui.getModel()); + MnemonicHelper.addKeyStrokeFromMnemonic(ui); + } + + public AdminStep getSelectedStep() { int index = ui.getTabs().getSelectedIndex(); AdminTabUI c = null; if (index > -1) { @@ -67,26 +83,26 @@ public class AdminUIHandler { return c == null ? null : c.getStep(); } - public AdminTabUI getStepUI(AdminUI ui, AdminStep step) { + public AdminTabUI getStepUI(AdminStep step) { if (step != null) { return (AdminTabUI) ui.getObjectById(step.name()); } return null; } - public AdminTabUI getStepUI(AdminUI ui, int stepIndex) { + public AdminTabUI getStepUI(int stepIndex) { if (stepIndex > ui.getTabs().getTabCount()) { return null; } return (AdminTabUI) ui.getTabs().getComponentAt(stepIndex); } - public AdminTabUI getSelectedStepUI(AdminUI ui) { - AdminStep step = getSelectedStep(ui); - return getStepUI(ui, step); + public AdminTabUI getSelectedStepUI() { + AdminStep step = getSelectedStep(); + return getStepUI(step); } - public void blockOperations(AdminUI ui) { + public void blockOperations() { ui.getModel().setValueAdjusting(true); for (AdminStep op : AdminStep.values()) { @@ -104,19 +120,19 @@ public class AdminUIHandler { ui.getModel().setValueAdjusting(false); } - public void onWasInit(AdminUI ui) { + public void onWasInit() { if (log.isDebugEnabled()) { log.debug(ui.getName() + " model was init at " + new Date()); } } - public void onWasStarted(AdminUI ui) { + public void onWasStarted() { if (log.isDebugEnabled()) { log.debug(ui.getName() + " model was started at " + new Date()); } } - public void onStepsChanged(AdminUI ui, AdminStep[] steps) { + public void onStepsChanged(AdminStep[] steps) { if (log.isDebugEnabled()) { log.debug("Will use these steps : " + Arrays.toString(steps)); @@ -160,7 +176,7 @@ public class AdminUIHandler { if (log.isDebugEnabled()) { log.debug("Will init tabUI [" + c.getName() + "]"); } - c.initUI(ui); +// c.initUI(ui); JComponent content = c.getContent(); UIHelper.setLayerUI(content, ui.getBusyBlockLayerUI()); @@ -175,7 +191,7 @@ public class AdminUIHandler { ui.getModel().setValueAdjusting(false); } - public void onStepChanged(AdminUI ui, AdminStep oldStep, AdminStep newStep) { + public void onStepChanged(AdminStep oldStep, AdminStep newStep) { if (log.isTraceEnabled()) { log.trace(newStep); } @@ -189,11 +205,11 @@ public class AdminUIHandler { ConfigUI configUI = (ConfigUI) ui.getStepUI(AdminStep.CONFIG); - model.setLocalSourceLabel(t("observe.storage.config.left.storage")); - model.setCentralSourceLabel(t("observe.storage.config.right.storage")); + model.getConfigModel().setLocalSourceLabel(t("observe.storage.config.left.storage")); + model.getConfigModel().setCentralSourceLabel(t("observe.storage.config.right.storage")); - configUI.getLocalSourceConfig().setBorder(new TitledBorder(model.getLocalSourceLabel())); - configUI.getCentralSourceConfig().setBorder(new TitledBorder(model.getCentralSourceLabel())); + configUI.getLocalSourceConfig().setBorder(new TitledBorder(model.getConfigModel().getLocalSourceLabel())); + configUI.getCentralSourceConfig().setBorder(new TitledBorder(model.getConfigModel().getCentralSourceLabel())); } @@ -221,39 +237,22 @@ public class AdminUIHandler { if (oldStep != null && oldStep.ordinal() < AdminStep.SELECT_DATA.ordinal()) { // préparation de l'arbre de sélection - onSelectDataOpen((SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA)); + SelectDataUI selectDataUI = (SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA); + selectDataUI.getHandler().onSelectDataOpen(); } } } - protected void onSelectDataOpen(SelectDataUI stepUI) { - - SelectionTree selectTree = stepUI.getSelectTree(); - selectTree.clearSelection(); - - SwingUtilities.invokeLater(selectTree::grabFocus); - - if (selectTree.getTreeModel().isNotEmpty()) { - - selectTree.setSelectionRow(0); - } - if (stepUI.getModel().getSafeLocalSource(true).isLocal()) { - SwingUtilities.invokeLater(selectTree::expandAll); - } - - } - /** * Call back lorsque l'état du modèle a changé. * * Ici, on va rendre accessible (ou pas) les onglets selon l'état du modèle. * - * @param ui l'ui concernée * @param newState le nouvel état. */ - public void onModelStateChanged(AdminUI ui, WizardState newState) { + public void onModelStateChanged(WizardState newState) { if (log.isDebugEnabled()) { log.debug(newState); } @@ -329,7 +328,7 @@ public class AdminUIHandler { } } - public void onOperationStateChanged(AdminUI ui, AdminStep step, WizardState newState) { + public void onOperationStateChanged(AdminStep step, WizardState newState) { if (log.isDebugEnabled()) { log.debug(step + " - " + newState); } @@ -345,7 +344,7 @@ public class AdminUIHandler { } } - public void start(AdminUI ui) { + public void start() { try { // on demarre le modele @@ -360,7 +359,7 @@ public class AdminUIHandler { } } - public void close(AdminUI ui) { + public void close() { Runnable action = WizardUILancher.APPLY_DEF.getContextValue(ui); @@ -369,7 +368,7 @@ public class AdminUIHandler { executor.addAction(t("observe.action.admin.close"), action); } - public void cancel(AdminUI ui) { + public void cancel() { Runnable action = WizardUILancher.CANCEL_DEF.getContextValue(ui); @@ -378,7 +377,7 @@ public class AdminUIHandler { executor.addAction(t("observe.action.admin.cancel"), action); } - public void destroy(AdminUI ui) { + public void destroy() { ui.getModel().destroy(); if (log.isDebugEnabled()) { log.debug("destroy ui " + ui.getName()); @@ -394,8 +393,8 @@ public class AdminUIHandler { UIHelper.destroy(ui); } - public void dispose(AdminUI ui) { - destroy(ui); + public void dispose() { + destroy(); } public Icon getTabIcon(WizardState state) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUILauncher.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUILauncher.java index ded8255..43697c7 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUILauncher.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUILauncher.java @@ -26,6 +26,7 @@ import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.ObserveUIMode; import fr.ird.observe.application.swing.ui.UIHelper; +import fr.ird.observe.application.swing.ui.admin.config.ConfigModel; import jaxx.runtime.JAXXContext; import jaxx.runtime.swing.wizard.BusyChangeListener; import jaxx.runtime.swing.wizard.WizardUILancher; @@ -223,8 +224,8 @@ public class AdminUILauncher extends WizardUILancher<AdminStep, AdminUIModel, Ad try { - model.doCloseSource(model.getCentralSource(), false); - model.doCloseSource(model.getLocalSource(), false); + ConfigModel.doCloseSource(model.getConfigModel().getCentralSource()); + ConfigModel.doCloseSource(model.getConfigModel().getLocalSource()); if (!(parent instanceof ObserveMainUI)) { JDialog dialog = (JDialog) parent; @@ -246,7 +247,7 @@ public class AdminUILauncher extends WizardUILancher<AdminStep, AdminUIModel, Ad mainUI.removeContextValue(model.getClass()); - ObserveSwingDataSource source = model.getPreviousSource(); + ObserveSwingDataSource source = model.getConfigModel().getPreviousSource(); if (source == null) { @@ -255,7 +256,7 @@ public class AdminUILauncher extends WizardUILancher<AdminStep, AdminUIModel, Ad return; } - model.doCloseSource(source, false); + ConfigModel.doCloseSource(source); // on attache la source a l'ui ObserveSwingApplicationContext.get().getDataSourcesManager().prepareMainStorage(source, false); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIModel.java index a4c383f..afe74db 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/AdminUIModel.java @@ -21,63 +21,31 @@ */ package fr.ird.observe.application.swing.ui.admin; -import fr.ird.observe.application.swing.I18nEnumHelper; -import fr.ird.observe.application.swing.ObserveSwingApplicationContext; -import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.application.swing.configuration.constants.DbMode; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; +import fr.ird.observe.application.swing.ui.admin.config.ConfigModel; +import fr.ird.observe.application.swing.ui.admin.config.SelectDataModel; import fr.ird.observe.application.swing.ui.admin.consolidate.ConsolidateModel; import fr.ird.observe.application.swing.ui.admin.export.ExportModel; import fr.ird.observe.application.swing.ui.admin.report.ReportModel; +import fr.ird.observe.application.swing.ui.admin.resume.ShowResumeModel; import fr.ird.observe.application.swing.ui.admin.save.SaveLocalModel; import fr.ird.observe.application.swing.ui.admin.synchronize.data.DataSynchroModel; -import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ReferentialSynchronizeMode; import fr.ird.observe.application.swing.ui.admin.synchronize.referential.legacy.SynchronizeModel; import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng.ReferentialSynchroModel; import fr.ird.observe.application.swing.ui.admin.validate.ValidateModel; -import fr.ird.observe.application.swing.ui.storage.StorageUIHandler; -import fr.ird.observe.application.swing.ui.storage.StorageUIModel; -import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; -import fr.ird.observe.application.swing.validation.ValidationModelMode; -import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; -import fr.ird.observe.services.configuration.ObserveDataSourceInformation; -import fr.ird.observe.services.dto.DataReference; -import fr.ird.observe.services.dto.DataReferenceSet; -import fr.ird.observe.services.dto.IdHelper; -import fr.ird.observe.services.dto.ObserveModelType; -import fr.ird.observe.services.dto.longline.TripLonglineDto; -import fr.ird.observe.services.dto.seine.TripSeineDto; -import fr.ird.observe.services.service.BabModelVersionException; -import fr.ird.observe.services.service.DatabaseConnexionNotAuthorizedException; -import fr.ird.observe.services.service.DatabaseDestroyNotAuthorizedException; -import fr.ird.observe.services.service.DatabaseNotFoundException; -import fr.ird.observe.services.service.actions.validate.ValidateService; -import fr.ird.observe.services.service.data.longline.TripLonglineService; -import fr.ird.observe.services.service.data.seine.TripSeineService; import jaxx.runtime.swing.wizard.ext.WizardExtModel; import jaxx.runtime.swing.wizard.ext.WizardState; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.validator.NuitonValidatorScope; -import javax.swing.border.TitledBorder; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; import java.util.List; -import java.util.Objects; import java.util.Set; -import static fr.ird.observe.application.swing.ObserveResourceManager.Resource; -import static fr.ird.observe.application.swing.configuration.constants.DbMode.USE_LOCAL; -import static fr.ird.observe.application.swing.configuration.constants.DbMode.USE_REMOTE; -import static fr.ird.observe.application.swing.configuration.constants.DbMode.USE_SERVER; -import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; /** @@ -90,176 +58,37 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { // public static final String SELECTION_MODEL_CHANGED_PROPERTY_NAME = "selectionModelChanged"; public static final String SELECTED_TRIP_PROPERTY_NAME = "selectedTrip"; - public static final String PROPERTY_LOCAL_SOURCE_LABEL = "localSourceLabel"; - public static final String PROPERTY_CENTRAL_SOURCE_LABEL = "centralSourceLabel"; /** Logger */ private static final Log log = LogFactory.getLog(AdminUIModel.class); public static final PropertyChangeListener LOG_PROPERTY_CHANGE_LISTENER = new LogPropertyChanged(); - /** la source de données en cours d'utilisation par l'application */ - protected ObserveSwingDataSource previousSource; + protected final ConfigModel configModel = new ConfigModel(); - /** la source de données sur laquel on veut travailler */ - protected ObserveSwingDataSource localSource; + protected final SelectDataModel selectDataModel = new SelectDataModel(); - /** la source de données sur laquel on veut travailler */ - protected ObserveDataSourceInformation localSourceInformation; - - /** la source de données dite central (contenant le référentiel valide) */ - protected ObserveSwingDataSource centralSource; - - /** la configuration de la base source */ - protected final StorageUIModel localSourceModel; - - /** la configuration de la base central */ - protected final StorageUIModel centralSourceModel; - - /** le controleur pour configurer les sources */ - protected StorageUIHandler storageHandler; - - protected SelectionTreeModel selectionDataModel; + protected final ShowResumeModel showResumeModel = new ShowResumeModel(); /** la liste des modes disponibles en entrée */ protected final EnumSet<DbMode> availableIncomingModes; private final PropertyChangeListener listenStepChanged; - private final PropertyChangeListener listenSelectModified; - - private final PropertyChangeListener listenValidationModified; - - private final PropertyChangeListener listenReportModified; - - private final PropertyChangeListener listenerSelectedDataForReport; - - private final PropertyChangeListener listenConsolidateModified; - - private final PropertyChangeListener listenSaveLocalChanged; - private final PropertyChangeListener listenReferentialConfigChanged; - - private String localSourceLabel = t("observe.storage.config.source.storage"); - private String centralSourceLabel = t("observe.storage.config.referentiel.storage"); - - public String getLocalSourceLabel() { - return localSourceLabel; - } - - public void setLocalSourceLabel(String localSourceLabel) { - Object oldValue = getLocalSourceLabel(); - this.localSourceLabel = localSourceLabel; - firePropertyChange(PROPERTY_LOCAL_SOURCE_LABEL, oldValue, localSourceLabel); - } - - public String getCentralSourceLabel() { - return centralSourceLabel; - } - - public void setCentralSourceLabel(String centralSourceLabel) { - Object oldValue = getCentralSourceLabel(); - this.centralSourceLabel = centralSourceLabel; - firePropertyChange(PROPERTY_CENTRAL_SOURCE_LABEL, oldValue, centralSourceLabel); - } - - public void setSelectionDataModel(SelectionTreeModel selectionDataModel) { - this.selectionDataModel = selectionDataModel; + @Override + public void firePropertyChange(String propertyName, Object newValue) { + super.firePropertyChange(propertyName, newValue); } public AdminUIModel() { super(AdminStep.class); - localSourceModel = new StorageUIModel() { - - @Override - public String getLabel() { - String txt; - if (containsOperation(AdminStep.REFERENTIAL_SYNCHRONIZE) || containsOperation(AdminStep.DATA_SYNCHRONIZE)) { - txt = n("observe.storage.label.synchro.leftSource"); - } else { - txt = n("observe.storage.label.synchro.incoming"); - } - String params; - - if (getDbMode() == USE_SERVER) { - params = t("observe.storage.server.db") + " " + getRemoteUrl(); - } else if (getDbMode() == USE_REMOTE) { - params = t("observe.storage.remote.db") + " " + getRemoteUrl(); - } else { - params = t("observe.storage.locale.db") + " " + getH2Config().getDirectory().getAbsolutePath(); - } - txt = t(txt, params); - return txt; - } - - @Override - public void validate() { - super.validate(); - - // on declanche la revalidation du modèle - firePropertyChange(VALID_PROPERTY_NAME, isValid()); - } - - }; - - centralSourceModel = new StorageUIModel() { - - @Override - public String getLabel() { - String txt; - if (containsOperation(AdminStep.REFERENTIAL_SYNCHRONIZE) || containsOperation(AdminStep.DATA_SYNCHRONIZE)) { - txt = n("observe.storage.label.synchro.rightSource"); - } else { - txt = n("observe.storage.label.synchro.referentiel"); - } - String params; - - if (getDbMode() == USE_SERVER) { - params = t("observe.storage.server.db") + " " + getRemoteUrl(); - } else if (getDbMode() == USE_REMOTE) { - params = t("observe.storage.remote.db") + " " + getRemoteUrl(); - } else { - params = t("observe.storage.locale.db") + " " + getH2Config().getDirectory().getAbsolutePath(); - } - txt = t(txt, params); - return txt; - } - - @Override - public void validate() { - super.validate(); - - // on declanche la revalidation du modèle - firePropertyChange(VALID_PROPERTY_NAME, isValid()); - } - }; - availableIncomingModes = EnumSet.noneOf(DbMode.class); if (log.isDebugEnabled()) { log.debug("model [" + this + "] is instanciate."); } - listenReferentialConfigChanged = evt -> { - - - if (isWasStarted()) { - - // on ne propage plus rien (il n'y a plus de configuration possible...) - if (log.isDebugEnabled()) { - log.debug("Stop propagation, was started... " + evt.getPropertyName()); - } - return; - } - - if (ReferentialSynchroModel.SYNCHRONIZE_MODE_PROPERTY_NAME.equals(evt.getPropertyName())) { - - validate(); - - } - - }; - listenStepChanged = evt -> { if (isWasStarted()) { @@ -280,8 +109,8 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (containsOperation(AdminStep.REFERENTIAL_SYNCHRONIZE) || containsOperation(AdminStep.DATA_SYNCHRONIZE)) { - setLocalSourceLabel(t("observe.storage.config.left.storage")); - setCentralSourceLabel(t("observe.storage.config.right.storage")); + getConfigModel().setLocalSourceLabel(t("observe.storage.config.left.storage")); + getConfigModel().setCentralSourceLabel(t("observe.storage.config.right.storage")); } @@ -309,154 +138,61 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (newStep == AdminStep.SELECT_DATA) { - initSelectionModel(); - - } - - }; - listenSelectModified = evt -> { - SelectionTreeModel source = (SelectionTreeModel) evt.getSource(); - if (log.isDebugEnabled()) { - log.debug(String.format("selection data model [%s] changed on %s, new value = %s", - source, evt.getPropertyName(), evt.getNewValue())); - } - validate(); - if (log.isDebugEnabled()) { - log.debug("nb selected export datas = " + source.getSelectedCount()); - } + getSelectDataModel().initSelectionModel(this); - // on declanche la revalidation du modèle - firePropertyChange(VALID_STEP_PROPERTY_NAME, validStep); - }; - listenValidationModified = evt -> { - ValidateModel source = (ValidateModel) evt.getSource(); - if (log.isDebugEnabled()) { - log.debug("validation model [" + source + "] changed on " + - evt.getPropertyName() + ", new value = " + - evt.getNewValue()); } - validate(); - if (log.isDebugEnabled()) { - log.debug("nb validators = " + - source.getValidators().size() - ); - } - firePropertyChange(VALID_STEP_PROPERTY_NAME, validStep); - }; - listenReportModified = evt -> { - ReportModel source = (ReportModel) evt.getSource(); - if (log.isDebugEnabled()) { - log.debug("report model [" + source + "] changed on " + - evt.getPropertyName() + ", new value = " + - evt.getNewValue()); - } - validate(); - firePropertyChange(VALID_STEP_PROPERTY_NAME, validStep); - }; - listenerSelectedDataForReport = evt -> { - - // la modification de la sélection entraine la suppression d'un report sélectionné - getReportModel().setSelectedReport(null); - // cela entraine aussi la modification de la marée sélectionnée - firePropertyChange(SELECTED_TRIP_PROPERTY_NAME, getSelectedTrip()); - - }; - listenConsolidateModified = evt -> { - ConsolidateModel source = (ConsolidateModel) evt.getSource(); - if (log.isDebugEnabled()) { - log.debug("consolidate model [" + source + "] changed on " + - evt.getPropertyName() + ", new value = " + - evt.getNewValue()); - } - validate(); - firePropertyChange(VALID_STEP_PROPERTY_NAME, validStep); }; - listenSaveLocalChanged = evt -> { - - String propertyName = evt.getPropertyName(); - if (SaveLocalModel.BACKUP_FILE_PROPERTY_NAME.equals(propertyName)) { - - validate(); - return; - } - - if (SaveLocalModel.LOCAL_SOURCE_NEED_SAVE_PROPERTY_NAME.equals(propertyName)) { - boolean localSourceNeedSave = (Boolean) evt.getNewValue(); - if (localSourceNeedSave) { - // l'opération de sauvegarde est obligatoire - setStepState(AdminStep.SAVE_LOCAL, WizardState.PENDING); - } - validate(); - return; - } - - if (log.isDebugEnabled()) { - log.debug("Skip property " + propertyName); - } - }; } - private void initSelectionModel() { - - SelectionTreeModel selectionDataModel = getSelectionDataModel(); - - ObserveSwingDataSource dataSource = getSafeLocalSource(true); - - if (dataSource.isLocal()) { - selectionDataModel.setShowEmptyTrips(false); - } - - boolean selectAllTrips = true; - if (containsOperation(AdminStep.REPORT)) { - - // on remplit le modèle de sélection uniquement avec le bon type de marées - ReportModel reportModel = getReportModel(); - ObserveModelType reportType = reportModel.getModelType(); - boolean loadSeineTrip = ObserveModelType.PS == reportType; - - selectionDataModel.setLoadLongline(!loadSeineTrip); - selectionDataModel.setLoadSeine(loadSeineTrip); - - selectAllTrips = false; - - } - - // on remplit le modèle de sélection - - selectionDataModel.populate(dataSource); - - if (containsOperation(AdminStep.EXPORT_DATA)) { + public ValidateModel getValidateModel() { + return (ValidateModel) getStepModel(AdminStep.VALIDATE); + } - // on doit aussi calculer les ids des marées distantes - ObserveSwingDataSource safeCentralSource = getSafeCentralSource(true); + public SynchronizeModel getSynchronizeReferentielModel() { + return (SynchronizeModel) getStepModel(AdminStep.SYNCHRONIZE); + } - List<DataReference<?>> existingTrip = new ArrayList<>(); + public ConfigModel getConfigModel() { + return configModel; + } - TripSeineService tripSeineService = safeCentralSource.newTripSeineService(); - DataReferenceSet<TripSeineDto> tripSeineSet = tripSeineService.getAllTripSeine(); - existingTrip.addAll(tripSeineSet.getReferences()); + public ShowResumeModel getShowResumeModel() { + return showResumeModel; + } - TripLonglineService tripLonglineService = safeCentralSource.newTripLonglineService(); - DataReferenceSet<TripLonglineDto> tripLonglineSet = tripLonglineService.getAllTripLongline(); - existingTrip.addAll(tripLonglineSet.getReferences()); + public SelectDataModel getSelectDataModel() { + return selectDataModel; + } - selectionDataModel.setExistingTrips(existingTrip); + public ExportModel getExportModel() { + return (ExportModel) getStepModel(AdminStep.EXPORT_DATA); + } + public ReportModel getReportModel() { + return (ReportModel) getStepModel(AdminStep.REPORT); + } - } + public ConsolidateModel getConsolidateModel() { + return (ConsolidateModel) getStepModel(AdminStep.CONSOLIDATE); + } - if (dataSource.isLocal() && selectAllTrips) { + public SaveLocalModel getSaveLocalModel() { + return (SaveLocalModel) getStepModel(AdminStep.SAVE_LOCAL); + } - // on sélectionne toutes les marées - selectionDataModel.selectAllTrips(); - } + public DataSynchroModel getDataSynchroModel() { + return (DataSynchroModel) getStepModel(AdminStep.DATA_SYNCHRONIZE); + } + public ReferentialSynchroModel getReferentialSynchroModel() { + return (ReferentialSynchroModel) getStepModel(AdminStep.REFERENTIAL_SYNCHRONIZE); } - public SelectionTreeModel getSelectionDataModel() { - return selectionDataModel; + @Override + public AdminActionModel getStepModel(AdminStep operation) { + return (AdminActionModel) super.getStepModel(operation); } public boolean needSelect() { @@ -472,25 +208,8 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { return false; } - public DataReference getSelectedTrip() { - Set<DataReference<?>> data = getSelectionDataModel().getSelectedData(); - if (data.isEmpty()) { - - // pas de Trip selectionne - return null; - } - DataReference dto = data.iterator().next(); - if (IdHelper.isTrip(dto)) { - return dto; - } - - // la donnée n'est pas une marée - return null; - } - - @Override - public AdminActionModel getStepModel(AdminStep operation) { - return (AdminActionModel) super.getStepModel(operation); + public boolean isValidStep() { + return validStep; } /** @@ -552,10 +271,6 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { availableIncomingModes.clear(); - storageHandler = ui.getContextValue(StorageUIHandler.class); - - ObserveSwingApplicationConfig config = ObserveSwingApplicationContext.get().getConfig(); - // demarrage du modèle : on fixe ici une fois pour toute les liste // des onglets visibles start(); @@ -568,122 +283,29 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { log.info("enables operations = " + operations); } - // on positionne la source courante de l'application comme service - // entrant (on se sert de la configuration de ce service s'il existe - // pour la source locale). - ObserveSwingDataSource previousSource = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); - setPreviousSource(previousSource); - - startIncomingSourceModel(ui); - - startCentralSourceModel(ui); - - startSelectModel(); + getConfigModel().start(ui); - // avant le demarrage du wizard, on ferme toujours la source - // en cours d'utilisation - - if (previousSource != null && previousSource.isOpen()) { - - if (log.isDebugEnabled()) { - log.debug("Close previous source " + - previousSource.getLabel()); - } - doCloseSource(previousSource, false); - } + getSelectDataModel().start(this); if (containsOperation(AdminStep.SAVE_LOCAL)) { - - File backupfile = config.newBackupDataFile(); - - getSaveLocalModel().setBackupFile(backupfile); - getSaveLocalModel().setDoBackup(true); - getSaveLocalModel().removePropertyChangeListener(listenSaveLocalChanged); - getSaveLocalModel().addPropertyChangeListener(listenSaveLocalChanged); + getSaveLocalModel().start(this); } - if (containsOperation(AdminStep.VALIDATE)) { - - getValidateModel().removePropertyChangeListener(listenValidationModified); - getValidateModel().addPropertyChangeListener(listenValidationModified); - getValidateModel().addScope(NuitonValidatorScope.ERROR); - getValidateModel().setModelMode(ValidationModelMode.DATA); - getValidateModel().setContextName(ValidateService.SERVICE_VALIDATION_CONTEXT); - getValidateModel().setGenerateReport(true); - if (!config.getValidationReportDirectory().exists()) { - boolean b = config.getValidationReportDirectory().mkdirs(); - if (!b) { - throw new RuntimeException("Could not create directory " + config.getValidationReportDirectory()); - } - } - File reportFile = new File(config.getValidationReportDirectory(), - getValidateModel().getDefaultReportFilename()); - getValidateModel().setReportFile(reportFile); + getValidateModel().start(this); } - if (containsOperation(AdminStep.REPORT)) { - - File reportFile = Resource.report.getFile(config.getReportDirectory()); - - if (reportFile.exists()) { - if (log.isInfoEnabled()) { - log.info("Will use report file : " + reportFile); - } - - getReportModel().setReportFile(reportFile); - } else { - if (log.isWarnEnabled()) - log.warn("Default report file " + reportFile + " does not exists."); - } - - // on ecoute la modification du modèle - getReportModel().removePropertyChangeListener(listenReportModified); - getReportModel().addPropertyChangeListener(listenReportModified); - - // on ecoute la modification de la sélection - getSelectionDataModel().removePropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, listenerSelectedDataForReport); - getSelectionDataModel().addPropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, listenerSelectedDataForReport); - - getReportModel().updateReports(); + getReportModel().start(this); } - if (containsOperation(AdminStep.CONSOLIDATE)) { - - // Anything to init ? - getConsolidateModel().removePropertyChangeListener(listenConsolidateModified); - getConsolidateModel().addPropertyChangeListener(listenConsolidateModified); + getConsolidateModel().start(this); } - if (containsOperation(AdminStep.DATA_SYNCHRONIZE)) { - - ConfigUI configUI = (ConfigUI) ui.getStepUI(AdminStep.CONFIG); - - configUI.getLocalSourceConfig().setBorder(new TitledBorder(getLocalSourceLabel())); - configUI.getCentralSourceConfig().setBorder(new TitledBorder(getCentralSourceLabel())); - + getDataSynchroModel().start(ui); } if (containsOperation(AdminStep.REFERENTIAL_SYNCHRONIZE)) { - - getReferentialSynchroModel().removePropertyChangeListener(listenReferentialConfigChanged); - getReferentialSynchroModel().addPropertyChangeListener(listenReferentialConfigChanged); - - getReferentialSynchroModel().addPropertyChangeListener(ReferentialSynchroModel.SYNCHRONIZE_MODE_PROPERTY_NAME, evt -> { - - ReferentialSynchronizeMode newValue = (ReferentialSynchronizeMode) evt.getNewValue(); - - if (ui.getTabs().getComponentCount() > 1 && newValue != null) { - ui.getTabs().setTitleAt(1, t("observe.actions.synchro.referential.withMode", I18nEnumHelper.getLabel(newValue))); - } - - }); - - getReferentialSynchroModel().setSynchronizeMode(ReferentialSynchronizeMode.FROM_LEFT_TO_RIGHT); - + getReferentialSynchroModel().start(ui); } - // on ecoute les modifications d'étapes pour remplir les modèles de sélection - // si nécessaire - removePropertyChangeListener(STEP_PROPERTY_NAME, listenStepChanged); addPropertyChangeListener(STEP_PROPERTY_NAME, listenStepChanged); @@ -695,294 +317,12 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { validate(); } - protected void startCentralSourceModel(AdminUI ui) { - - if (!isNeedReferentielDataSource()) { - - // pas besoin de la base distante - return; - } - - // par default, on tente d'utiliser la base distance - centralSourceModel.init(ui, null); - centralSourceModel.setCanCreateLocalService(false); - boolean canUseLocalSource = getOperations().contains(AdminStep.DATA_SYNCHRONIZE) - || getOperations().contains(AdminStep.SYNCHRONIZE) - || getOperations().contains(AdminStep.REFERENTIAL_SYNCHRONIZE); - centralSourceModel.setCanUseLocalService(canUseLocalSource); - centralSourceModel.setCanUseRemoteService(true); - centralSourceModel.setCanUseServerService(true); - centralSourceModel.start(USE_REMOTE); - - if (log.isDebugEnabled()) { - centralSourceModel.removePropertyChangeListener(LOG_PROPERTY_CHANGE_LISTENER); - centralSourceModel.addPropertyChangeListener(LOG_PROPERTY_CHANGE_LISTENER); - } - - // on teste si la connexion distante existe - if (centralSourceModel.isValid()) { - centralSourceModel.testRemote(); - } - } - - protected void startIncomingSourceModel(AdminUI ui) { - - if (!isNeedIncomingDataSource()) { - - // pas besoin de la base locale - return; - } - - ObserveSwingDataSource previousSource = getPreviousSource(); - - ObserveDataSourceConfiguration previousSourceConfig = null; - ObserveDataSourceInformation previousSourceInfo = null; - - EnumSet<DbMode> authorizedModes = getIncomingDataSourceMode(); - EnumSet<DbMode> modes = EnumSet.noneOf(DbMode.class); - - if (authorizedModes.contains(USE_LOCAL)) { - - // ce mode est disponible uniquement si une base locale existe - if (ObserveSwingApplicationContext.get().getConfig().isLocalStorageExist()) { - modes.add(USE_LOCAL); - } - } - - if (authorizedModes.contains(USE_REMOTE)) { - - modes.add(USE_REMOTE); - } - - if (authorizedModes.contains(USE_SERVER)) { - - modes.add(USE_SERVER); - } - - if (authorizedModes.contains(DbMode.CREATE_LOCAL)) { - - modes.add(DbMode.CREATE_LOCAL); - } - - if (previousSource != null) { - - try { - previousSourceConfig = previousSource.getConfiguration().clone(); - previousSourceInfo = previousSource.getInformation(); - } catch (CloneNotSupportedException e) { - if (log.isErrorEnabled()) { - log.error("con not clone previous data configuration", e); - } - } - - if (previousSource.isRemote()) { - - if (!modes.contains(USE_REMOTE)) { - - // pas autorise a utiliser cette source en entree - previousSource = null; - } - } - - if (previousSource != null && previousSource.isServer()) { - - if (!modes.contains(USE_SERVER)) { - - // pas autorise a utiliser cette source en entree - previousSource = null; - } - } - - if (previousSource != null && previousSource.isLocal()) { - - if (!modes.contains(USE_LOCAL)) { - - // pas autorise a utiliser cette source en entree - previousSource = null; - } - } - } - - availableIncomingModes.addAll(modes); - - localSourceModel.setCanCreateLocalService(modes.contains(DbMode.CREATE_LOCAL)); - localSourceModel.setCanUseLocalService(modes.contains(USE_LOCAL)); - localSourceModel.setCanUseRemoteService(modes.contains(USE_REMOTE)); - localSourceModel.setCanUseServerService(modes.contains(USE_SERVER)); - - if (previousSource == null) { - - // on intialize le modèle de la source locale à partir du service entrant (s'il existe) - localSourceModel.init(ui, null); - - } else { - - // on intialize le modèle de la source locale à partir du service entrant (s'il existe) - localSourceModel.initFromPreviousConfig(previousSourceConfig, previousSourceInfo); - } - - DbMode dbMode = localSourceModel.getDbMode(); - localSourceModel.start(dbMode); - - if (log.isDebugEnabled()) { - localSourceModel.removePropertyChangeListener(LOG_PROPERTY_CHANGE_LISTENER); - localSourceModel.addPropertyChangeListener(LOG_PROPERTY_CHANGE_LISTENER); - } - } - - protected void startSelectModel() { - - if (!needSelect()) { - - // pas d'opération avec une sélection de données, rien a faire ici - return; - } - - SelectionTreeModel selectionModel = getSelectionDataModel(); - - if (containsOperation(AdminStep.EXPORT_DATA)) { - - selectionModel.setLoadLongline(true); - selectionModel.setLoadSeine(true); - selectionModel.setLoadReferential(false); - selectionModel.setUseOpenData(false); - } - - if (containsOperation(AdminStep.REPORT)) { - - selectionModel.setUseOpenData(true); - selectionModel.setLoadLongline(true); - selectionModel.setLoadSeine(true); - selectionModel.setLoadReferential(false); - } - - if (containsOperation(AdminStep.VALIDATE)) { - - selectionModel.setUseOpenData(true); - selectionModel.setLoadLongline(true); - selectionModel.setLoadSeine(true); - selectionModel.setLoadReferential(true); - } - - if (containsOperation(AdminStep.CONSOLIDATE)) { - - selectionModel.setUseOpenData(true); - selectionModel.setLoadLongline(true); - selectionModel.setLoadSeine(true); - selectionModel.setLoadReferential(false); - } - - selectionModel.addPropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, listenSelectModified); - } - @Override public void destroy() { - localSourceModel.destroy(); - centralSourceModel.destroy(); -// selectionDataModel.destroy(); + getConfigModel().destroy(); super.destroy(); } - public ObserveSwingDataSource getPreviousSource() { - return previousSource; - } - - public void setPreviousSource(ObserveSwingDataSource previousSource) { - this.previousSource = previousSource; - } - - public ObserveSwingDataSource getLocalSource() { - return localSource; - } - - public ObserveDataSourceInformation getLocalSourceInformation() { - if (localSourceInformation == null) { - - ObserveSwingDataSource localSource = getSafeLocalSource(false); - - try { - - localSourceInformation = localSource.checkCanConnect(); - - } catch (Exception e) { - //FIXME ! il faut faire quelque chose dans ce cas précis, au moins avertir l'utilisateur - if (log.isErrorEnabled()) { - log.error("unable to find local source information", e); - } - } - - } - - return localSourceInformation; - } - - public ObserveSwingDataSource getCentralSource() { - return centralSource; - } - - public ObserveSwingDataSource getSafeLocalSource(boolean open) { - if (localSource == null || open && !localSource.isOpen()) { - - localSource = createDataSource(getLocalSourceModel()); - } - if (open) { - - doOpenSource(localSource); - } - return localSource; - } - - public ObserveSwingDataSource getSafeCentralSource(boolean open) { - if (centralSource == null || open && !centralSource.isOpen()) { - - centralSource = createDataSource(getCentralSourceModel()); - } - if (open) { - doOpenSource(centralSource); - } - return centralSource; - } - - public StorageUIModel getLocalSourceModel() { - return localSourceModel; - } - - public StorageUIModel getCentralSourceModel() { - return centralSourceModel; - } - - public ValidateModel getValidateModel() { - return (ValidateModel) getStepModel(AdminStep.VALIDATE); - } - - public SynchronizeModel getSynchronizeReferentielModel() { - return (SynchronizeModel) getStepModel(AdminStep.SYNCHRONIZE); - } - - public ExportModel getExportModel() { - return (ExportModel) getStepModel(AdminStep.EXPORT_DATA); - } - - public ReportModel getReportModel() { - return (ReportModel) getStepModel(AdminStep.REPORT); - } - - public ConsolidateModel getConsolidateModel() { - return (ConsolidateModel) getStepModel(AdminStep.CONSOLIDATE); - } - - public SaveLocalModel getSaveLocalModel() { - return (SaveLocalModel) getStepModel(AdminStep.SAVE_LOCAL); - } - - public DataSynchroModel getDataSynchroModel() { - return (DataSynchroModel) getStepModel(AdminStep.DATA_SYNCHRONIZE); - } - - public ReferentialSynchroModel getReferentialSynchroModel() { - return (ReferentialSynchroModel) getStepModel(AdminStep.REFERENTIAL_SYNCHRONIZE); - } - @Override public void cancel() { super.cancel(); @@ -1019,14 +359,14 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (AdminStep.SYNCHRONIZE == step) { // pour exporter les données utilisateurs - // l'objectOperation de synchronisation de référentiel est nécessaire + // l'opération de synchronisation de référentiel est nécessaire getOperations().remove(AdminStep.EXPORT_DATA); } if (AdminStep.CONSOLIDATE == step) { // pour exporter les données utilisateurs ou effectuer des reports - // l'objectOperation de calcul des données est nécessaire + // l'opération de calcul des données est nécessaire getOperations().remove(AdminStep.EXPORT_DATA); getOperations().remove(AdminStep.REPORT); } @@ -1045,307 +385,27 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { return false; } - SelectionTreeModel selectionModel = getSelectionDataModel(); - switch (step) { case CONFIG: - if (isNeedIncomingDataSource()) { - if (!localSourceModel.isValid()) { - if (log.isDebugEnabled()) { - log.debug("incoming service is not valid"); - } - validate = false; - } - } - if (isNeedReferentielDataSource()) { - if (!centralSourceModel.isValid()) { - if (log.isDebugEnabled()) { - log.debug("referentiel service is not valid"); - } - validate = false; - } - } - - if (containsOperation(AdminStep.VALIDATE)) { - - // il faut avoir selectionner un context - // il faut avoir au moins selectionner un scope - if (StringUtils.isEmpty(getValidateModel().getContextName())) { - if (log.isDebugEnabled()) { - log.debug("no validation context name"); - } - return false; - } - if (getValidateModel().getScopes().isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("no validation scopes"); - } - return false; - } - if (getValidateModel().getModelMode() == null) { - if (log.isDebugEnabled()) { - log.debug("no validation model mode"); - } - return false; - } - if (getValidateModel().isGenerateReport()) { - - // le fichier de rapport ne doit pas exister - File file = getValidateModel().getReportFile(); - - if (file.exists()) { - if (log.isDebugEnabled()) { - log.debug("report file already exists"); - } - return false; - } - - // le repertoire du rapport doit exister - File parentFile = file.getParentFile(); - if (parentFile == null || !parentFile.exists()) { - return false; - } - } - if (getValidateModel().getValidators().isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("no validators detected"); - } - return false; - } - - // la base precedente doit etre ouverte - ObserveDataSourceInformation dataSourceInformation = getLocalSourceInformation(); - - // si le test de connection a echoue - if (dataSourceInformation == null) { - if (log.isDebugEnabled()) { - log.debug("can not connect to data source "); - } - return false; - } - - - // pour valider une base il faut les droits - if (selectionModel.isUseData()) { - - // il faut les droits en Lecture sur les donnes - if (!(dataSourceInformation.canReadData())) { - if (log.isDebugEnabled()) { - log.debug("can not read data"); - } - return false; - } - } - if (selectionModel.isLoadReferential()) { - - // il faut les droits en L sur le referentiel - if (!(dataSourceInformation.canReadReferential())) { - if (log.isDebugEnabled()) { - log.debug("can not read referentiel"); - } - return false; - } - } - } - if (validate && containsOperation(AdminStep.DATA_SYNCHRONIZE)) { - - // les deux bases (source et referentiel) doivent etre different - validate = validateNotSameDataSources(); - - ObserveDataSourceInformation leftDataSourceInformation = getLocalSourceInformation(); - if (!(leftDataSourceInformation.canReadData() && leftDataSourceInformation.canWriteData())) { - if (log.isDebugEnabled()) { - log.debug("can not read and write data on left data source"); - } - return false; - } - - if (centralSourceModel.getDataSourceInformation() != null) { - - ObserveDataSourceInformation rightDataSourceInformation = centralSourceModel.getDataSourceInformation(); - if (!(rightDataSourceInformation.canReadData() && rightDataSourceInformation.canWriteData())) { - if (log.isDebugEnabled()) { - log.debug("can not read and write data on right data source"); - } - return false; - } - - } - - } - - if (validate && containsOperation(AdminStep.REFERENTIAL_SYNCHRONIZE)) { - - // les deux bases (source et referentiel) doivent etre different - validate = validateNotSameDataSources(); - - ObserveDataSourceInformation leftDataSourceInformation = getLocalSourceInformation(); - if (leftDataSourceInformation == null) { - return false; - } - if (!(leftDataSourceInformation.canReadReferential())) { - if (log.isDebugEnabled()) { - log.debug("can not read and write referential on left data source"); - } - return false; - } - - ObserveDataSourceInformation rightDataSourceInformation = centralSourceModel.getDataSourceInformation(); - if (rightDataSourceInformation == null) { - return false; - } - - if (!(rightDataSourceInformation.canReadReferential())) { - if (log.isDebugEnabled()) { - log.debug("can not read and write referential on right data source"); - } - return false; - } - - ReferentialSynchronizeMode synchronizeMode = getReferentialSynchroModel().getSynchronizeMode(); - if (synchronizeMode == null) { - return false; - } - - if (synchronizeMode.isLeftWrite()) { - - validate = localSourceModel.isLocal() || leftDataSourceInformation.canWriteReferential(); - - } - - if (synchronizeMode.isRightWrite()) { - - validate = centralSourceModel.isLocal() || rightDataSourceInformation.canWriteReferential(); - - } - - } - - if (containsOperation(AdminStep.SYNCHRONIZE)) { - - if (!localSourceModel.isValid()) { - return false; - } - - ObserveDataSourceInformation leftDataSourceInformation = getLocalSourceInformation(); - if (leftDataSourceInformation == null) { - return false; - } - - if (!centralSourceModel.isValid()) { - return false; - } - - ObserveDataSourceInformation rightDataSourceInformation = centralSourceModel.getDataSourceInformation(); - if (rightDataSourceInformation == null) { - return false; - } - - if (!(rightDataSourceInformation.canReadReferential())) { - if (log.isDebugEnabled()) { - log.debug("can not read referential on central source"); - } - return false; - } - - // les deux bases (source et referentiel) doivent etre different - validate = validateNotSameDataSources(); - - } - if (containsOperation(AdminStep.EXPORT_DATA)) { - - // il faut une base locale et une connexion distante - // avec des droits d'écriture de données - validate &= centralSourceModel.getDataSourceInformation() != null - && centralSourceModel.getDataSourceInformation().canWriteData(); - - } - - if (containsOperation(AdminStep.REPORT)) { - - // il faut le fichier di'mport existe - File reportFile = getReportModel().getReportFile(); - validate &= reportFile != null && - reportFile.exists(); - } - break; + return getConfigModel().validate(this); case SELECT_DATA: - - if (containsOperation(AdminStep.VALIDATE)) { - - // la config doit etre ok - validate = validate(AdminStep.CONFIG); - if (validate) { - - // il faut au moins une donnee de selectionnee - boolean empty = selectionModel.isSelectionEmpty(); - validate = !empty; - } - } - if (containsOperation(AdminStep.EXPORT_DATA)) { - - // la config doit etre ok - validate &= validate(AdminStep.CONFIG); - if (validate) { - - // il faut au moins une donnee de selectionnee - boolean empty = selectionModel.isSelectionEmpty(); - validate = !empty; - } - } - if (containsOperation(AdminStep.CONSOLIDATE)) { - - // la config doit etre ok - validate &= validate(AdminStep.CONFIG); - if (validate) { - - // il faut au moins une donnee de selectionnee - boolean empty = selectionModel.isSelectionEmpty(); - validate = !empty; - } - } - if (containsOperation(AdminStep.REPORT)) { - - // la config doit etre ok - validate &= validate(AdminStep.CONFIG); - if (validate) { - - // il faut exactement une Trip de selectionnee - int selectedCount = selectionModel.getSelectedCount(); - validate = selectedCount == 1; - } - } - break; + return getSelectDataModel().validate(this); case VALIDATE: - validate = validate(AdminStep.SELECT_DATA) && - getStepState(step) == WizardState.SUCCESSED; - break; + return getValidateModel().validate(this); case EXPORT_DATA: - validate = validate(AdminStep.SELECT_DATA) && - getStepState(step) == WizardState.SUCCESSED; - break; + return getExportModel().validate(this); case CONSOLIDATE: - validate = validate(AdminStep.SELECT_DATA) && - getStepState(step) == WizardState.SUCCESSED; - break; + return getConsolidateModel().validate(this); case REPORT: - - // pour acceder a l'onglet des report, il faut que - // l'onglet de sélection des données soit ok - validate = validate(AdminStep.SELECT_DATA); - break; + return getReportModel().validate(this); case SYNCHRONIZE: - validate = getStepState(step) == WizardState.SUCCESSED; - break; + return getSynchronizeReferentielModel().validate(this, step); case SAVE_LOCAL: - // valide si l'action a ete executee avec success - validate = !getSaveLocalModel().isDoBackup() || - getStepState(step) == WizardState.SUCCESSED; - break; + return getSaveLocalModel().validate(this, step); case SHOW_RESUME: - validate = true; + return getShowResumeModel().validate(this); } - return validate; + return true; } @Override @@ -1425,21 +485,6 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { return universe.toArray(new AdminStep[universe.size()]); } - public void removeLocalSource() { - if (localSource != null) { - doCloseSource(localSource, false); - localSource = null; - localSourceInformation = null; - } - } - - public void removeCentralSource() { - if (centralSource != null) { - doCloseSource(centralSource, false); - centralSource = null; - } - } - protected void updateSaveLocalOperation() { boolean shouldAdd = false; for (AdminStep s : operations) { @@ -1458,40 +503,11 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } } - protected ObserveSwingDataSource createDataSource(StorageUIModel model) { - - return storageHandler.newDataSourceFromModel(model); - } - - protected void doOpenSource(ObserveSwingDataSource source) { - - if (source != null && !source.isOpen()) { - try { - source.open(); - } catch (DatabaseConnexionNotAuthorizedException | DatabaseNotFoundException | BabModelVersionException e) { - throw new IllegalStateException("Could not open " + source, e); - } - } - - } - - protected void doCloseSource(ObserveSwingDataSource source, boolean destroy) { - - if (source != null && source.isOpen()) { - if (destroy) { - try { - source.destroy(); - } catch (DatabaseDestroyNotAuthorizedException e) { - throw new IllegalStateException("Could not destroy " + source, e); - } - } else { - source.close(); - } - } - + public <E> EnumSet<DbMode> getAvailableIncomingModes() { + return availableIncomingModes; } - private static class LogPropertyChanged implements PropertyChangeListener { + public static class LogPropertyChanged implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); @@ -1504,24 +520,4 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } } - private boolean validateNotSameDataSources() { - boolean validate = true; - DbMode dbMode = localSourceModel.getDbMode(); - if (dbMode != null && dbMode == centralSourceModel.getDbMode()) { - switch (dbMode) { - case USE_REMOTE: - validate = !Objects.equals(localSourceModel.getPgConfig().getJdbcUrl(), centralSourceModel.getPgConfig().getJdbcUrl()); - break; - case USE_SERVER: - validate = !Objects.equals(localSourceModel.getRestConfig().getServerUrl(), centralSourceModel.getRestConfig().getServerUrl()) - || !Objects.equals(localSourceModel.getRestConfig().getOptionalDatabaseName(), centralSourceModel.getRestConfig().getOptionalDatabaseName()); - - break; - default: - validate = false; - } - } - return validate; - } - } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigModel.java new file mode 100644 index 0000000..e4644c0 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigModel.java @@ -0,0 +1,673 @@ +package fr.ird.observe.application.swing.ui.admin.config; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.configuration.constants.DbMode; +import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.admin.AdminActionModel; +import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUI; +import fr.ird.observe.application.swing.ui.admin.AdminUIModel; +import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ReferentialSynchronizeMode; +import fr.ird.observe.application.swing.ui.storage.StorageUIModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; +import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; +import fr.ird.observe.services.configuration.ObserveDataSourceInformation; +import fr.ird.observe.services.service.BabModelVersionException; +import fr.ird.observe.services.service.DatabaseConnexionNotAuthorizedException; +import fr.ird.observe.services.service.DatabaseNotFoundException; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.beans.PropertyChangeListener; +import java.io.File; +import java.util.EnumSet; +import java.util.Objects; + +import static fr.ird.observe.application.swing.configuration.constants.DbMode.USE_LOCAL; +import static fr.ird.observe.application.swing.configuration.constants.DbMode.USE_REMOTE; +import static fr.ird.observe.application.swing.configuration.constants.DbMode.USE_SERVER; +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 28/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 6.0 + */ +public class ConfigModel extends AdminActionModel { + + /** Logger */ + private static final Log log = LogFactory.getLog(ConfigModel.class); + public static final String PROPERTY_LOCAL_SOURCE_LABEL = "localSourceLabel"; + public static final String PROPERTY_CENTRAL_SOURCE_LABEL = "centralSourceLabel"; + + /** la source de données en cours d'utilisation par l'application */ + protected ObserveSwingDataSource previousSource; + /** la source de données sur laquel on veut travailler */ + protected ObserveSwingDataSource localSource; + /** la source de données sur laquel on veut travailler */ + protected ObserveDataSourceInformation localSourceInformation; + /** la source de données dite central (contenant le référentiel valide) */ + protected ObserveSwingDataSource centralSource; + /** la configuration de la base source */ + protected final StorageUIModel localSourceModel; + /** la configuration de la base central */ + protected final StorageUIModel centralSourceModel; + private String localSourceLabel = t("observe.storage.config.source.storage"); + private String centralSourceLabel = t("observe.storage.config.referentiel.storage"); + + public ConfigModel() { + super(AdminStep.CONFIG); + localSourceModel = new StorageUIModel() { + + @Override + public String getLabel() { + String txt = getLocalSourceLabel(); + String params; + + if (getDbMode() == USE_SERVER) { + params = t("observe.storage.server.db") + " " + getRemoteUrl(); + } else if (getDbMode() == USE_REMOTE) { + params = t("observe.storage.remote.db") + " " + getRemoteUrl(); + } else { + params = t("observe.storage.locale.db") + " " + getH2Config().getDirectory().getAbsolutePath(); + } + txt = t(txt, params); + return txt; + } + + @Override + public void validate() { + super.validate(); + + // on declanche la revalidation du modèle + firePropertyChange(VALID_PROPERTY_NAME, isValid()); + } + + }; + + centralSourceModel = new StorageUIModel() { + + @Override + public String getLabel() { + String txt = getCentralSourceLabel(); + String params; + + if (getDbMode() == USE_SERVER) { + params = t("observe.storage.server.db") + " " + getRemoteUrl(); + } else if (getDbMode() == USE_REMOTE) { + params = t("observe.storage.remote.db") + " " + getRemoteUrl(); + } else { + params = t("observe.storage.locale.db") + " " + getH2Config().getDirectory().getAbsolutePath(); + } + txt = t(txt, params); + return txt; + } + + @Override + public void validate() { + super.validate(); + + // on declanche la revalidation du modèle + firePropertyChange(VALID_PROPERTY_NAME, isValid()); + } + }; + + } + + public static void doOpenSource(ObserveSwingDataSource source) { + + if (source != null && !source.isOpen()) { + try { + source.open(); + } catch (DatabaseConnexionNotAuthorizedException | DatabaseNotFoundException | BabModelVersionException e) { + throw new IllegalStateException("Could not open " + source, e); + } + } + + } + + public static void doCloseSource(ObserveSwingDataSource source) { + + if (source != null && source.isOpen()) { + source.close(); + } + + } + + + public String getLocalSourceLabel() { + return localSourceLabel; + } + + public void setLocalSourceLabel(String localSourceLabel) { + Object oldValue = getLocalSourceLabel(); + this.localSourceLabel = localSourceLabel; + firePropertyChange(PROPERTY_LOCAL_SOURCE_LABEL, oldValue, localSourceLabel); + } + + public String getCentralSourceLabel() { + return centralSourceLabel; + } + + public void setCentralSourceLabel(String centralSourceLabel) { + Object oldValue = getCentralSourceLabel(); + this.centralSourceLabel = centralSourceLabel; + firePropertyChange(PROPERTY_CENTRAL_SOURCE_LABEL, oldValue, centralSourceLabel); + } + + + public boolean validate(AdminUIModel uiModel) { + + boolean validate = true; + + StorageUIModel centralSourceModel = getCentralSourceModel(); + StorageUIModel localSourceModel = getLocalSourceModel(); + + if (uiModel.isNeedIncomingDataSource()) { + if (!localSourceModel.isValid()) { + if (log.isDebugEnabled()) { + log.debug("incoming service is not valid"); + } + validate = false; + } + } + if (uiModel.isNeedReferentielDataSource()) { + if (!centralSourceModel.isValid()) { + if (log.isDebugEnabled()) { + log.debug("referentiel service is not valid"); + } + validate = false; + } + } + + if (!validate) { + return false; + } + + if (uiModel.containsOperation(AdminStep.VALIDATE)) { + + // il faut avoir selectionner un context + // il faut avoir au moins selectionner un scope + if (StringUtils.isEmpty(uiModel.getValidateModel().getContextName())) { + if (log.isDebugEnabled()) { + log.debug("no validation context name"); + } + return false; + } + if (uiModel.getValidateModel().getScopes().isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("no validation scopes"); + } + return false; + } + if (uiModel.getValidateModel().getModelMode() == null) { + if (log.isDebugEnabled()) { + log.debug("no validation model mode"); + } + return false; + } + if (uiModel.getValidateModel().isGenerateReport()) { + + // le fichier de rapport ne doit pas exister + File file = uiModel.getValidateModel().getReportFile(); + + if (file.exists()) { + if (log.isDebugEnabled()) { + log.debug("report file already exists"); + } + return false; + } + + // le repertoire du rapport doit exister + File parentFile = file.getParentFile(); + if (parentFile == null || !parentFile.exists()) { + return false; + } + } + if (uiModel.getValidateModel().getValidators().isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("no validators detected"); + } + return false; + } + + // la base precedente doit etre ouverte + ObserveDataSourceInformation dataSourceInformation = getLocalSourceInformation(); + + // si le test de connection a echoue + if (dataSourceInformation == null) { + if (log.isDebugEnabled()) { + log.debug("can not connect to data source "); + } + return false; + } + + + // pour valider une base il faut les droits + SelectionTreeModel selectionModel = uiModel.getSelectDataModel().getSelectionDataModel(); + if (selectionModel.isUseData()) { + + // il faut les droits en Lecture sur les donnes + if (!(dataSourceInformation.canReadData())) { + if (log.isDebugEnabled()) { + log.debug("can not read data"); + } + return false; + } + } + if (selectionModel.isLoadReferential()) { + + // il faut les droits en L sur le referentiel + if (!(dataSourceInformation.canReadReferential())) { + if (log.isDebugEnabled()) { + log.debug("can not read referentiel"); + } + return false; + } + } + } + + if (uiModel.containsOperation(AdminStep.DATA_SYNCHRONIZE)) { + + // les deux bases (source et referentiel) doivent etre different + validate = validateNotSameDataSources(); + + ObserveDataSourceInformation leftDataSourceInformation = getLocalSourceInformation(); + if (!(leftDataSourceInformation.canReadData() && leftDataSourceInformation.canWriteData())) { + if (log.isDebugEnabled()) { + log.debug("can not read and write data on left data source"); + } + return false; + } + + if (centralSourceModel.getDataSourceInformation() != null) { + + ObserveDataSourceInformation rightDataSourceInformation = centralSourceModel.getDataSourceInformation(); + if (!(rightDataSourceInformation.canReadData() && rightDataSourceInformation.canWriteData())) { + if (log.isDebugEnabled()) { + log.debug("can not read and write data on right data source"); + } + return false; + } + + } + + } + + if (validate && uiModel.containsOperation(AdminStep.REFERENTIAL_SYNCHRONIZE)) { + + // les deux bases (source et referentiel) doivent etre different + validate = validateNotSameDataSources(); + + ObserveDataSourceInformation leftDataSourceInformation = getLocalSourceInformation(); + if (leftDataSourceInformation == null) { + return false; + } + if (!(leftDataSourceInformation.canReadReferential())) { + if (log.isDebugEnabled()) { + log.debug("can not read and write referential on left data source"); + } + return false; + } + + ObserveDataSourceInformation rightDataSourceInformation = centralSourceModel.getDataSourceInformation(); + if (rightDataSourceInformation == null) { + return false; + } + + if (!(rightDataSourceInformation.canReadReferential())) { + if (log.isDebugEnabled()) { + log.debug("can not read and write referential on right data source"); + } + return false; + } + + ReferentialSynchronizeMode synchronizeMode = uiModel.getReferentialSynchroModel().getSynchronizeMode(); + if (synchronizeMode == null) { + return false; + } + + if (synchronizeMode.isLeftWrite()) { + + validate = localSourceModel.isLocal() || leftDataSourceInformation.canWriteReferential(); + + } + + if (synchronizeMode.isRightWrite()) { + + validate = centralSourceModel.isLocal() || rightDataSourceInformation.canWriteReferential(); + + } + + } + + if (uiModel.containsOperation(AdminStep.SYNCHRONIZE)) { + + if (!localSourceModel.isValid()) { + return false; + } + + ObserveDataSourceInformation leftDataSourceInformation = getLocalSourceInformation(); + if (leftDataSourceInformation == null) { + return false; + } + + if (!centralSourceModel.isValid()) { + return false; + } + + ObserveDataSourceInformation rightDataSourceInformation = centralSourceModel.getDataSourceInformation(); + if (rightDataSourceInformation == null) { + return false; + } + + if (!(rightDataSourceInformation.canReadReferential())) { + if (log.isDebugEnabled()) { + log.debug("can not read referential on central source"); + } + return false; + } + + // les deux bases (source et referentiel) doivent etre different + validate = validateNotSameDataSources(); + + } + if (uiModel.containsOperation(AdminStep.EXPORT_DATA)) { + + // il faut une base locale et une connexion distante + // avec des droits d'écriture de données + validate &= centralSourceModel.getDataSourceInformation() != null + && centralSourceModel.getDataSourceInformation().canWriteData(); + + } + + if (uiModel.containsOperation(AdminStep.REPORT)) { + + // il faut le fichier di'mport existe + File reportFile = uiModel.getReportModel().getReportFile(); + validate &= reportFile != null && reportFile.exists(); + } + + return validate; + } + + public static final PropertyChangeListener LOG_PROPERTY_CHANGE_LISTENER = new AdminUIModel.LogPropertyChanged(); + + protected void startCentralSourceModel(AdminUI ui) { + + AdminUIModel uiModel = ui.getModel(); + if (!uiModel.isNeedReferentielDataSource()) { + + // pas besoin de la base distante + return; + } + + // par default, on tente d'utiliser la base distance + centralSourceModel.init(ui, null); + centralSourceModel.setCanCreateLocalService(false); + boolean canUseLocalSource = uiModel.getOperations().contains(AdminStep.DATA_SYNCHRONIZE) + || uiModel.getOperations().contains(AdminStep.SYNCHRONIZE) + || uiModel.getOperations().contains(AdminStep.REFERENTIAL_SYNCHRONIZE); + centralSourceModel.setCanUseLocalService(canUseLocalSource); + centralSourceModel.setCanUseRemoteService(true); + centralSourceModel.setCanUseServerService(true); + centralSourceModel.start(USE_REMOTE); + + if (log.isDebugEnabled()) { + centralSourceModel.removePropertyChangeListener(LOG_PROPERTY_CHANGE_LISTENER); + centralSourceModel.addPropertyChangeListener(LOG_PROPERTY_CHANGE_LISTENER); + } + + // on teste si la connexion distante existe + if (centralSourceModel.isValid()) { + centralSourceModel.testRemote(); + } + } + + protected void startIncomingSourceModel(AdminUI ui) { + + AdminUIModel uiModel = ui.getModel(); + + if (!uiModel.isNeedIncomingDataSource()) { + + // pas besoin de la base locale + return; + } + + ObserveSwingDataSource previousSource = getPreviousSource(); + + ObserveDataSourceConfiguration previousSourceConfig = null; + ObserveDataSourceInformation previousSourceInfo = null; + + EnumSet<DbMode> authorizedModes = uiModel.getIncomingDataSourceMode(); + EnumSet<DbMode> modes = EnumSet.noneOf(DbMode.class); + + if (authorizedModes.contains(USE_LOCAL)) { + + // ce mode est disponible uniquement si une base locale existe + if (ObserveSwingApplicationContext.get().getConfig().isLocalStorageExist()) { + modes.add(USE_LOCAL); + } + } + + if (authorizedModes.contains(USE_REMOTE)) { + + modes.add(USE_REMOTE); + } + + if (authorizedModes.contains(USE_SERVER)) { + + modes.add(USE_SERVER); + } + + if (authorizedModes.contains(DbMode.CREATE_LOCAL)) { + + modes.add(DbMode.CREATE_LOCAL); + } + + if (previousSource != null) { + + try { + previousSourceConfig = previousSource.getConfiguration().clone(); + previousSourceInfo = previousSource.getInformation(); + } catch (CloneNotSupportedException e) { + if (log.isErrorEnabled()) { + log.error("con not clone previous data configuration", e); + } + } + + if (previousSource.isRemote()) { + + if (!modes.contains(USE_REMOTE)) { + + // pas autorise a utiliser cette source en entree + previousSource = null; + } + } + + if (previousSource != null && previousSource.isServer()) { + + if (!modes.contains(USE_SERVER)) { + + // pas autorise a utiliser cette source en entree + previousSource = null; + } + } + + if (previousSource != null && previousSource.isLocal()) { + + if (!modes.contains(USE_LOCAL)) { + + // pas autorise a utiliser cette source en entree + previousSource = null; + } + } + } + + uiModel.getAvailableIncomingModes().addAll(modes); + + localSourceModel.setCanCreateLocalService(modes.contains(DbMode.CREATE_LOCAL)); + localSourceModel.setCanUseLocalService(modes.contains(USE_LOCAL)); + localSourceModel.setCanUseRemoteService(modes.contains(USE_REMOTE)); + localSourceModel.setCanUseServerService(modes.contains(USE_SERVER)); + + if (previousSource == null) { + + // on intialize le modèle de la source locale à partir du service entrant (s'il existe) + localSourceModel.init(ui, null); + + } else { + + // on intialize le modèle de la source locale à partir du service entrant (s'il existe) + localSourceModel.initFromPreviousConfig(previousSourceConfig, previousSourceInfo); + } + + DbMode dbMode = localSourceModel.getDbMode(); + localSourceModel.start(dbMode); + + if (log.isDebugEnabled()) { + localSourceModel.removePropertyChangeListener(LOG_PROPERTY_CHANGE_LISTENER); + localSourceModel.addPropertyChangeListener(LOG_PROPERTY_CHANGE_LISTENER); + } + } + + public boolean validateNotSameDataSources() { + boolean validate = true; + DbMode dbMode = localSourceModel.getDbMode(); + if (dbMode != null && dbMode == centralSourceModel.getDbMode()) { + switch (dbMode) { + case USE_REMOTE: + validate = !Objects.equals(localSourceModel.getPgConfig().getJdbcUrl(), centralSourceModel.getPgConfig().getJdbcUrl()); + break; + case USE_SERVER: + validate = !Objects.equals(localSourceModel.getRestConfig().getServerUrl(), centralSourceModel.getRestConfig().getServerUrl()) + || !Objects.equals(localSourceModel.getRestConfig().getOptionalDatabaseName(), centralSourceModel.getRestConfig().getOptionalDatabaseName()); + + break; + default: + validate = false; + } + } + return validate; + } + + + public void start(AdminUI ui) { + + // on positionne la source courante de l'application comme service + // entrant (on se sert de la configuration de ce service s'il existe + // pour la source locale). + ObserveSwingDataSource previousSource = ObserveSwingApplicationContext.get().getDataSourcesManager().getMainDataSource(); + setPreviousSource(previousSource); + + // avant le demarrage du wizard, on ferme toujours la source + // en cours d'utilisation + + if (previousSource != null && previousSource.isOpen()) { + + if (log.isDebugEnabled()) { + log.debug("Close previous source " + previousSource.getLabel()); + } + doCloseSource(previousSource); + } + + startIncomingSourceModel(ui); + + startCentralSourceModel(ui); + + } + + @Override + public void destroy() { + super.destroy(); + localSourceModel.destroy(); + centralSourceModel.destroy(); + } + + public ObserveSwingDataSource getPreviousSource() { + return previousSource; + } + + public void setPreviousSource(ObserveSwingDataSource previousSource) { + this.previousSource = previousSource; + } + + public ObserveSwingDataSource getLocalSource() { + return localSource; + } + + public ObserveDataSourceInformation getLocalSourceInformation() { + if (localSourceInformation == null) { + + ObserveSwingDataSource localSource = getSafeLocalSource(false); + + try { + + localSourceInformation = localSource.checkCanConnect(); + + } catch (Exception e) { + //FIXME ! il faut faire quelque chose dans ce cas précis, au moins avertir l'utilisateur + if (log.isErrorEnabled()) { + log.error("unable to find local source information", e); + } + } + + } + + return localSourceInformation; + } + + public ObserveSwingDataSource getCentralSource() { + return centralSource; + } + + public ObserveSwingDataSource getSafeLocalSource(boolean open) { + if (localSource == null || open && !localSource.isOpen()) { + + localSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSourceFromModel(getLocalSourceModel()); + } + if (open) { + + doOpenSource(localSource); + } + return localSource; + } + + public ObserveSwingDataSource getSafeCentralSource(boolean open) { + if (centralSource == null || open && !centralSource.isOpen()) { + + centralSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSourceFromModel(getCentralSourceModel()); + } + if (open) { + doOpenSource(centralSource); + } + return centralSource; + } + + public StorageUIModel getLocalSourceModel() { + return localSourceModel; + } + + public StorageUIModel getCentralSourceModel() { + return centralSourceModel; + } + + + public void removeLocalSource() { + if (localSource != null) { + doCloseSource(localSource); + localSource = null; + localSourceInformation = null; + } + } + + public void removeCentralSource() { + if (centralSource != null) { + doCloseSource(centralSource); + centralSource = null; + } + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jaxx index 8aad3ca..15efd26 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jaxx @@ -28,9 +28,11 @@ _failedIcon='SwingUtil.getUIManagerActionIcon("connect_no")'> <import> + fr.ird.observe.application.swing.ui.admin.AdminActionModel fr.ird.observe.application.swing.ui.admin.AdminUI fr.ird.observe.application.swing.ui.admin.AdminStep fr.ird.observe.application.swing.ui.admin.AdminTabUI + fr.ird.observe.application.swing.ui.storage.StorageUIModel jaxx.runtime.SwingUtil java.awt.Color @@ -40,25 +42,14 @@ </import> - <fr.ird.observe.application.swing.ui.admin.AdminActionModel id='stepModel' initializer='null'/> + <ConfigModel id='stepModel' initializer='getModel().getConfigModel()'/> - <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='localSourceModel'/> + <StorageUIModel id='localSourceModel'/> - <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='centralSourceModel'/> - - <ConfigUIHandler id='handler' constructorParams='this'/> + <StorageUIModel id='centralSourceModel'/> <script><![CDATA[ -public ConfigUI(AdminUI parentContext) { - super(AdminStep.CONFIG, parentContext); -} - -@Override -public void initUI(AdminUI ui) { - getHandler().initTabUI(ui, this); -} - @Override public void addMessage(AdminStep step, String text) { // on enregistre pas les messages pour cette étape @@ -71,53 +62,50 @@ public void addMessage(AdminStep step, String text) { <JPanel id="configLabelPanel" constraints='BorderLayout.NORTH'> <JLabel id="configLabel"/> </JPanel> - <Table fill='both' - weightx='1' - insets='0' - constraints='BorderLayout.CENTER'> + <Table fill='both' weightx='1' insets='0' constraints='BorderLayout.CENTER'> <row> <cell> <Table id='operations' decorator='boxed' fill='both' weightx='1'> <row> <cell> <JCheckBox id='SYNCHRONIZE' - onItemStateChanged='getHandler().updateOperationState((JCheckBox)event.getSource())'/> + onItemStateChanged='handler.updateOperationState((JCheckBox)event.getSource())'/> </cell> </row> <row> <cell> <JCheckBox id='DATA_SYNCHRONIZE' - onItemStateChanged='getHandler().updateOperationState((JCheckBox)event.getSource())'/> + onItemStateChanged='handler.updateOperationState((JCheckBox)event.getSource())'/> </cell> </row> <row> <cell> <JCheckBox id='REFERENTIAL_SYNCHRONIZE' - onItemStateChanged='getHandler().updateOperationState((JCheckBox)event.getSource())'/> + onItemStateChanged='handler.updateOperationState((JCheckBox)event.getSource())'/> </cell> </row> <row> <cell> <JCheckBox id='CONSOLIDATE' - onItemStateChanged='getHandler().updateOperationState((JCheckBox)event.getSource())'/> + onItemStateChanged='handler.updateOperationState((JCheckBox)event.getSource())'/> </cell> </row> <row> <cell> <JCheckBox id='VALIDATE' - onItemStateChanged='getHandler().updateOperationState((JCheckBox)event.getSource())'/> + onItemStateChanged='handler.updateOperationState((JCheckBox)event.getSource())'/> </cell> </row> <row> <cell> <JCheckBox id='EXPORT_DATA' - onItemStateChanged='getHandler().updateOperationState((JCheckBox)event.getSource())'/> + onItemStateChanged='handler.updateOperationState((JCheckBox)event.getSource())'/> </cell> </row> <row> <cell> <JCheckBox id='REPORT' - onItemStateChanged='getHandler().updateOperationState((JCheckBox)event.getSource())'/> + onItemStateChanged='handler.updateOperationState((JCheckBox)event.getSource())'/> </cell> </row> </Table> @@ -133,8 +121,7 @@ public void addMessage(AdminStep step, String text) { <JLabel id='localSourceLabel'/> </cell> <cell> - <JButton id='configureLocalSource' - onActionPerformed='getHandler().obtainIncomingConnexion()'/> + <JButton id='configureLocalSource' onActionPerformed='handler.obtainIncomingConnexion()'/> </cell> <cell anchor='east'> <JLabel id='localSourceStatus'/> @@ -145,11 +132,6 @@ public void addMessage(AdminStep step, String text) { <JLabel id='localSourcePolicy'/> </cell> </row> - <!--row> - <cell fill='both' columns="2"> - <JLabel id='localSourceInfoLabel'/> - </cell> - </row--> </Table> </cell> </row> @@ -163,8 +145,7 @@ public void addMessage(AdminStep step, String text) { <JLabel id='centralSourceLabel'/> </cell> <cell> - <JButton id='configureCentralSource' - onActionPerformed='getHandler().obtainRemoteConnexion()'/> + <JButton id='configureCentralSource' onActionPerformed='handler.obtainRemoteConnexion()'/> </cell> <cell anchor='east'> <JLabel id='centralSourceStatus'/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jcss index eb46511..0cf0629 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUI.jcss @@ -85,7 +85,7 @@ } #localSourceConfig { - border:{new TitledBorder(model.getLocalSourceLabel())}; + border:{new TitledBorder(getStepModel().getLocalSourceLabel())}; visible:{model.isNeedIncomingDataSource()}; } @@ -110,7 +110,7 @@ #centralSourceConfig { visible:{model.isNeedReferentielDataSource()}; - border:{new TitledBorder(model.getCentralSourceLabel())}; + border:{new TitledBorder(stepModel.getCentralSourceLabel())}; } #centralSourceLabel { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUIHandler.java index b8cee91..287c22f 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/ConfigUIHandler.java @@ -25,14 +25,12 @@ import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ObserveTextGenerator; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; -import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.application.swing.ui.storage.StorageStep; import fr.ird.observe.application.swing.ui.storage.StorageUILauncher; import fr.ird.observe.application.swing.ui.storage.StorageUIModel; -import fr.ird.observe.application.swing.ui.tree.selection.SelectionTree; import fr.ird.observe.services.configuration.ObserveDataSourceInformation; +import jaxx.runtime.spi.UIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -49,45 +47,17 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class ConfigUIHandler extends AdminTabUIHandler { +public class ConfigUIHandler extends AdminTabUIHandler<ConfigUI> implements UIHandler<ConfigUI> { /** Logger */ private static final Log log = LogFactory.getLog(ConfigUIHandler.class); - public ConfigUIHandler(AdminTabUI ui) { - super(ui); - } - - public void initTabUI(AdminUI ui, ConfigUI tabUI) { - - super.initTabUI(ui, tabUI); - - if (log.isDebugEnabled()) { - log.debug("specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } - - UIHelper.setLayerUI(tabUI.getOperations(), ui.getOperationBlockLayerUI()); - UIHelper.setLayerUI(tabUI.getConfig(), ui.getConfigBlockLayerUI()); - UIHelper.setLayerUI(tabUI.getContent(), null); - } - - public void initTabUI(AdminUI ui, SelectDataUI tabUI) { - - super.initTabUI(ui, tabUI); - - if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } - - UIHelper.setLayerUI(tabUI.getContent(), null); - UIHelper.setLayerUI(tabUI.getSelectTreePane(), ui.getConfigBlockLayerUI()); - - SelectionTree tree = tabUI.getSelectTree(); - ui.getModel().setSelectionDataModel(tree.getTreeModel()); - - tree.installUI(); - //FIXME Init tree ? -// UIHelper.initUI(tabUI.getSelectTreePane(), tree); + @Override + public void afterInit(ConfigUI ui) { + super.afterInit(ui); + UIHelper.setLayerUI(ui.getOperations(), parentUI.getOperationBlockLayerUI()); + UIHelper.setLayerUI(ui.getConfig(), parentUI.getConfigBlockLayerUI()); + UIHelper.setLayerUI(ui.getContent(), null); } public void updateOperationState(JCheckBox checkBox) { @@ -122,8 +92,7 @@ public class ConfigUIHandler extends AdminTabUIHandler { return AdminStep.valueOf(checkBox.getName()); } - public boolean isOperationSelected(Set<AdminStep> operations, - JCheckBox checkBox) { + public boolean isOperationSelected(Set<AdminStep> operations, JCheckBox checkBox) { AdminStep scope = getOperation(checkBox); return operations.contains(scope); } @@ -134,8 +103,8 @@ public class ConfigUIHandler extends AdminTabUIHandler { if (log.isDebugEnabled()) { log.debug("After modifiy source model isValid : " + sourceModel.isValid() + " / " + sourceModel.isValidStep()); } - model.removeLocalSource(); - model.getLocalSourceModel().validate(); + model.getConfigModel().removeLocalSource(); + model.getConfigModel().getLocalSourceModel().validate(); model.validate(); } @@ -145,8 +114,8 @@ public class ConfigUIHandler extends AdminTabUIHandler { } StorageUIModel sourceModel = ui.getCentralSourceModel(); StorageUILauncher.obtainConnexion(ui, ui.getParentContainer(Window.class), sourceModel); - model.removeCentralSource(); - model.getCentralSourceModel().validate(StorageStep.CONFIG); + model.getConfigModel().removeCentralSource(); + model.getConfigModel().getCentralSourceModel().validate(StorageStep.CONFIG); model.validate(); } @@ -170,5 +139,4 @@ public class ConfigUIHandler extends AdminTabUIHandler { return text; } - } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataModel.java new file mode 100644 index 0000000..58160ba --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataModel.java @@ -0,0 +1,229 @@ +package fr.ird.observe.application.swing.ui.admin.config; + +import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.admin.AdminActionModel; +import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUIModel; +import fr.ird.observe.application.swing.ui.admin.report.ReportModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; +import fr.ird.observe.services.dto.DataReference; +import fr.ird.observe.services.dto.DataReferenceSet; +import fr.ird.observe.services.dto.IdHelper; +import fr.ird.observe.services.dto.ObserveModelType; +import fr.ird.observe.services.dto.longline.TripLonglineDto; +import fr.ird.observe.services.dto.seine.TripSeineDto; +import fr.ird.observe.services.service.data.longline.TripLonglineService; +import fr.ird.observe.services.service.data.seine.TripSeineService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * Created on 28/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 6.0 + */ +public class SelectDataModel extends AdminActionModel { + + /** Logger */ + private static final Log log = LogFactory.getLog(SelectDataModel.class); + + protected SelectionTreeModel selectionDataModel; + + public SelectDataModel() { + super(AdminStep.SELECT_DATA); + } + + public SelectionTreeModel getSelectionDataModel() { + return selectionDataModel; + } + + public void setSelectionDataModel(SelectionTreeModel selectionDataModel) { + this.selectionDataModel = selectionDataModel; + } + + + public void initSelectionModel(AdminUIModel uiModel) { + + SelectionTreeModel selectionDataModel = getSelectionDataModel(); + + ObserveSwingDataSource dataSource = uiModel.getConfigModel().getSafeLocalSource(true); + + if (dataSource.isLocal()) { + selectionDataModel.setShowEmptyTrips(false); + } + + boolean selectAllTrips = true; + if (uiModel.containsOperation(AdminStep.REPORT)) { + + // on remplit le modèle de sélection uniquement avec le bon type de marées + ReportModel reportModel = uiModel.getReportModel(); + ObserveModelType reportType = reportModel.getModelType(); + boolean loadSeineTrip = ObserveModelType.PS == reportType; + + selectionDataModel.setLoadLongline(!loadSeineTrip); + selectionDataModel.setLoadSeine(loadSeineTrip); + + selectAllTrips = false; + + } + + // on remplit le modèle de sélection + + selectionDataModel.populate(dataSource); + + if (uiModel.containsOperation(AdminStep.EXPORT_DATA)) { + + // on doit aussi calculer les ids des marées distantes + ObserveSwingDataSource safeCentralSource = uiModel.getConfigModel().getSafeCentralSource(true); + + List<DataReference<?>> existingTrip = new ArrayList<>(); + + TripSeineService tripSeineService = safeCentralSource.newTripSeineService(); + DataReferenceSet<TripSeineDto> tripSeineSet = tripSeineService.getAllTripSeine(); + existingTrip.addAll(tripSeineSet.getReferences()); + + TripLonglineService tripLonglineService = safeCentralSource.newTripLonglineService(); + DataReferenceSet<TripLonglineDto> tripLonglineSet = tripLonglineService.getAllTripLongline(); + existingTrip.addAll(tripLonglineSet.getReferences()); + + selectionDataModel.setExistingTrips(existingTrip); + + + } + + if (dataSource.isLocal() && selectAllTrips) { + + // on sélectionne toutes les marées + selectionDataModel.selectAllTrips(); + } + + } + + public DataReference getSelectedTrip() { + Set<DataReference<?>> data = getSelectionDataModel().getSelectedData(); + if (data.isEmpty()) { + + // pas de Trip selectionne + return null; + } + DataReference dto = data.iterator().next(); + if (IdHelper.isTrip(dto)) { + return dto; + } + + // la donnée n'est pas une marée + return null; + } + + public void start(AdminUIModel uiModel) { + + if (!uiModel.needSelect()) { + + // pas d'opération avec une sélection de données, rien a faire ici + return; + } + + SelectionTreeModel selectionModel = getSelectionDataModel(); + + if (uiModel.containsOperation(AdminStep.EXPORT_DATA)) { + + selectionModel.setLoadLongline(true); + selectionModel.setLoadSeine(true); + selectionModel.setLoadReferential(false); + selectionModel.setUseOpenData(false); + } + + if (uiModel.containsOperation(AdminStep.REPORT)) { + + selectionModel.setUseOpenData(true); + selectionModel.setLoadLongline(true); + selectionModel.setLoadSeine(true); + selectionModel.setLoadReferential(false); + } + + if (uiModel.containsOperation(AdminStep.VALIDATE)) { + + selectionModel.setUseOpenData(true); + selectionModel.setLoadLongline(true); + selectionModel.setLoadSeine(true); + selectionModel.setLoadReferential(true); + } + + if (uiModel.containsOperation(AdminStep.CONSOLIDATE)) { + + selectionModel.setUseOpenData(true); + selectionModel.setLoadLongline(true); + selectionModel.setLoadSeine(true); + selectionModel.setLoadReferential(false); + } + + selectionModel.addPropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, evt -> { + SelectionTreeModel source = (SelectionTreeModel) evt.getSource(); + if (log.isDebugEnabled()) { + log.debug(String.format("selection data model [%s] changed on %s, new value = %s", + source, evt.getPropertyName(), evt.getNewValue())); + } + uiModel.validate(); + if (log.isDebugEnabled()) { + log.debug("nb selected export datas = " + source.getSelectedCount()); + } + }); + } + + public boolean validate(AdminUIModel uiModel) { + + boolean validate = true; + + if (uiModel.containsOperation(AdminStep.VALIDATE)) { + + // la config doit etre ok + validate = uiModel.validate(AdminStep.CONFIG); + if (validate) { + + // il faut au moins une donnee de selectionnee + boolean empty = selectionDataModel.isSelectionEmpty(); + validate = !empty; + } + } + if (uiModel.containsOperation(AdminStep.EXPORT_DATA)) { + + // la config doit etre ok + validate &= uiModel.validate(AdminStep.CONFIG); + if (validate) { + + // il faut au moins une donnee de selectionnee + boolean empty = selectionDataModel.isSelectionEmpty(); + validate = !empty; + } + } + if (uiModel.containsOperation(AdminStep.CONSOLIDATE)) { + + // la config doit etre ok + validate &= uiModel.validate(AdminStep.CONFIG); + if (validate) { + + // il faut au moins une donnee de selectionnee + boolean empty = selectionDataModel.isSelectionEmpty(); + validate = !empty; + } + } + if (uiModel.containsOperation(AdminStep.REPORT)) { + + // la config doit etre ok + validate &= uiModel.validate(AdminStep.CONFIG); + if (validate) { + + // il faut exactement une Trip de selectionnee + int selectedCount = selectionDataModel.getSelectedCount(); + validate = selectedCount == 1; + } + } + + return validate; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jaxx index 296703b..b7a720e 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jaxx @@ -28,32 +28,14 @@ <import> fr.ird.observe.application.swing.ui.UIHelper - fr.ird.observe.application.swing.ui.admin.AdminActionModel - fr.ird.observe.application.swing.ui.admin.AdminUI - fr.ird.observe.application.swing.ui.admin.AdminStep fr.ird.observe.application.swing.ui.tree.selection.SelectionTree - fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeHeader jaxx.runtime.SwingUtil </import> - <ConfigUIHandler id='handler' constructorParams='this'/> - - <AdminActionModel id='stepModel' initializer='null'/> - - <script><![CDATA[ -public SelectDataUI(AdminUI parentContext) { - super(AdminStep.SELECT_DATA, parentContext); -} - -public void initUI(AdminUI ui) { - getHandler().initTabUI(ui, this); -} - -]]> - </script> + <SelectDataModel id='stepModel' initializer='getModel().getSelectDataModel()'/> <JPanel id='PENDING_content'> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jcss index 4e863e0..0aaaacd 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUI.jcss @@ -25,12 +25,8 @@ } #selectTree { - /*rootVisible:false; - largeModel:true;*/ minimumSize:{UIHelper.newMinDimension()}; font-size:11; - /*showsRootHandles:false; - toggleClickCount:100;*/ } #selectTreePane { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUIHandler.java new file mode 100644 index 0000000..5b5aa2f --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/config/SelectDataUIHandler.java @@ -0,0 +1,50 @@ +package fr.ird.observe.application.swing.ui.admin.config; + +import fr.ird.observe.application.swing.ui.UIHelper; +import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTree; +import jaxx.runtime.spi.UIHandler; + +import javax.swing.SwingUtilities; + +/** + * Created on 28/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 6.0 + */ +public class SelectDataUIHandler extends AdminTabUIHandler<SelectDataUI> implements UIHandler<SelectDataUI> { + + @Override + public void afterInit(SelectDataUI ui) { + super.afterInit(this.ui); + + UIHelper.setLayerUI(ui.getContent(), null); + UIHelper.setLayerUI(ui.getSelectTreePane(), parentUI.getConfigBlockLayerUI()); + + SelectionTree tree = ui.getSelectTree(); + model.getSelectDataModel().setSelectionDataModel(tree.getTreeModel()); + + tree.installUI(); + //FIXME Init tree ? +// UIHelper.initUI(tabUI.getSelectTreePane(), tree); + } + + + public void onSelectDataOpen() { + + SelectionTree selectTree = ui.getSelectTree(); + selectTree.clearSelection(); + + SwingUtilities.invokeLater(selectTree::grabFocus); + + if (selectTree.getTreeModel().isNotEmpty()) { + + selectTree.setSelectionRow(0); + } + if (ui.getModel().getConfigModel().getSafeLocalSource(true).isLocal()) { + SwingUtilities.invokeLater(selectTree::expandAll); + } + + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateModel.java index e85495e..7a121cd 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateModel.java @@ -24,6 +24,12 @@ package fr.ird.observe.application.swing.ui.admin.consolidate; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.ui.admin.AdminActionModel; import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUIModel; +import jaxx.runtime.swing.wizard.ext.WizardState; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.beans.PropertyChangeListener; /** * Modele pour preparer une validation de donnees d'une base. @@ -33,6 +39,9 @@ import fr.ird.observe.application.swing.ui.admin.AdminStep; */ public class ConsolidateModel extends AdminActionModel { + /** Logger */ + private static final Log log = LogFactory.getLog(ConsolidateModel.class); + /** la source de données où effectuer la consolidation des données */ private ObserveSwingDataSource source; @@ -53,4 +62,24 @@ public class ConsolidateModel extends AdminActionModel { super.destroy(); source = null; } + + public void start(AdminUIModel uiModel) { + + // Anything to init ? + + PropertyChangeListener listenConsolidateModified = evt -> { + ConsolidateModel source = (ConsolidateModel) evt.getSource(); + if (log.isDebugEnabled()) { + log.debug("consolidate model [" + source + "] changed on " + evt.getPropertyName() + ", new value = " + evt.getNewValue()); + } + uiModel.validate(); + }; + + removePropertyChangeListener(listenConsolidateModified); + addPropertyChangeListener(listenConsolidateModified); + } + + public boolean validate(AdminUIModel uiModel) { + return uiModel.validate(AdminStep.SELECT_DATA) && uiModel.getStepState(step) == WizardState.SUCCESSED; + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUI.jaxx index f62ea91..5b7e4ce 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUI.jaxx @@ -21,7 +21,7 @@ --> <!-- ********************************************** --> -<!-- L'écran de validation des données observers --> +<!-- L'écran de validation des données observées --> <!-- ********************************************** --> <fr.ird.observe.application.swing.ui.admin.AdminTabUI> @@ -32,32 +32,13 @@ fr.ird.observe.application.swing.ui.admin.AdminUI </import> - <ConsolidateUIHandler id='handler' constructorParams='this'/> - - <ConsolidateModel id='stepModel' - initializer='getModel().getConsolidateModel()'/> - - <script><![CDATA[ -public ConsolidateUI(AdminUI parentContext) { - super(AdminStep.CONSOLIDATE, parentContext); -} - -@Override -public void initUI(AdminUI ui) { - log.info("for [" + getStep() + "]"); - getHandler().initTabUI(ui, this); -} - -]]> - </script> + <ConsolidateModel id='stepModel' initializer='getModel().getConsolidateModel()'/> <JPanel id='PENDING_content'> - <Table constraints='BorderLayout.CENTER' fill='both' weightx='1' - weighty='1'> + <Table constraints='BorderLayout.CENTER' fill='both' weightx='1' weighty='1'> <row> <cell> - <JButton id='startButton' - onActionPerformed="getHandler().startAction()"/> + <JButton id='startButton' onActionPerformed="getHandler().startAction()"/> </cell> </row> </Table> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUIHandler.java index 3661e00..f3f958b 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/consolidate/ConsolidateUIHandler.java @@ -23,14 +23,13 @@ package fr.ird.observe.application.swing.ui.admin.consolidate; import com.google.common.collect.ImmutableSet; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; -import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.service.actions.consolidate.ConsolidateActivitySeineDataResult; import fr.ird.observe.services.service.actions.consolidate.ConsolidateDataService; import fr.ird.observe.services.service.actions.consolidate.ConsolidateTripSeineDataRequest; import fr.ird.observe.services.service.actions.consolidate.ConsolidateTripSeineDataResult; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -47,33 +46,23 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.5 */ -public class ConsolidateUIHandler extends AdminTabUIHandler { +public class ConsolidateUIHandler extends AdminTabUIHandler<ConsolidateUI> implements UIHandler<ConsolidateUI> { /** Logger */ private static final Log log = LogFactory.getLog(ConsolidateUIHandler.class); - public ConsolidateUIHandler(AdminTabUI ui) { - super(ui); + @Override + public void afterInit(ConsolidateUI ui) { + super.afterInit(ui); + ui.getStartButton().setText(t("observe.actions.synchro.launch.operation", t(ui.getStep().getOperationLabel()))); } public ConsolidateModel getStepModel() { return model.getConsolidateModel(); } - public void initTabUI(AdminUI ui, ConsolidateUI tabUI) { - - super.initTabUI(ui, tabUI); - - if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } - - tabUI.getStartButton().setText(t("observe.actions.synchro.launch.operation", t(tabUI.getStep().getOperationLabel()))); - - } - public void startAction() { - addAdminWorker(((ConsolidateUI) ui).getStartButton().getToolTipText(), this::doAction); + addAdminWorker(ui.getStartButton().getToolTipText(), this::doAction); } public WizardState doAction() throws Exception { @@ -81,9 +70,9 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { log.debug(this); } - getStepModel().setSource(model.getSafeLocalSource(false)); + getStepModel().setSource(model.getConfigModel().getSafeLocalSource(false)); - Set<DataReference<?>> trips = model.getSelectionDataModel().getSelectedData(); + Set<DataReference<?>> trips = model.getSelectDataModel().getSelectionDataModel().getSelectedData(); ImmutableSet<String> tripIds = ImmutableSet.copyOf(trips.stream() .filter(DataReference.newTripSeinePredicate()) .map(DataReference.ID_FUNCTION) @@ -129,5 +118,4 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { return WizardState.SUCCESSED; } - } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportModel.java index bb72f62..044a196 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportModel.java @@ -27,9 +27,11 @@ import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecor import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; import fr.ird.observe.application.swing.ui.admin.AdminActionModel; import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUIModel; import fr.ird.observe.services.dto.longline.TripLonglineDto; import fr.ird.observe.services.dto.referential.ProgramDto; import fr.ird.observe.services.dto.seine.TripSeineDto; +import jaxx.runtime.swing.wizard.ext.WizardState; import java.util.ArrayList; import java.util.List; @@ -133,4 +135,8 @@ public class ExportModel extends AdminActionModel { this.insertMissingReferentials = insertMissingReferentials; firePropertyChange("insertMissingReferentials", null, insertMissingReferentials); } + + public boolean validate(AdminUIModel uiModel) { + return uiModel.validate(AdminStep.SELECT_DATA) && uiModel.getStepState(step) == WizardState.SUCCESSED; + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUI.jaxx index f55dea5..97dd25a 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUI.jaxx @@ -32,24 +32,12 @@ jaxx.runtime.swing.wizard.ext.WizardState </import> - <ExportModel id='stepModel' initializer='getModel().getExportModel()'/> - <ExportUIHandler id='handler' constructorParams='this'/> - <!-- le modèles des activités dont on a pu calculé un point gps --> <TripToExportTableModel id='tripsModel' onTableChanged='startAction.setEnabled(tripsModel.hasSelection())'/> <script><![CDATA[ -public ExportUI(AdminUI parentContext) { - super(AdminStep.EXPORT_DATA, parentContext); -} - -@Override -public void initUI(AdminUI ui) { - log.info("for [" + getStep() + "]"); - getHandler().initTabUI(ui, this); -} @Override public void destroy() { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java index 2ac9563..6529e9d 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/export/ExportUIHandler.java @@ -30,9 +30,7 @@ import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecor import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; -import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.application.swing.ui.usage.UsagesUI; @@ -51,6 +49,7 @@ import fr.ird.observe.services.service.data.ImportTripResult; import fr.ird.observe.services.service.data.TripManagementService; import fr.ird.observe.services.service.referential.MissingReferentialResult; import fr.ird.observe.services.service.referential.ReferentialService; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.editor.MyDefaultCellEditor; import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.collections4.CollectionUtils; @@ -78,34 +77,30 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class ExportUIHandler extends AdminTabUIHandler { +public class ExportUIHandler extends AdminTabUIHandler<ExportUI> implements UIHandler<ExportUI> { /** Logger */ private static final Log log = LogFactory.getLog(ExportUIHandler.class); - public ExportUIHandler(AdminTabUI ui) { - super(ui); - } - - public void initTabUI(AdminUI ui, ExportUI tabUI) { - - super.initTabUI(ui, tabUI); + @Override + public void afterInit(ExportUI ui) { + super.afterInit(ui); if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); + log.debug(" specialized for [" + ui.getStep() + "] for main ui " + parentUI.getClass().getName() + "@" + System.identityHashCode(this.ui)); } - tabUI.getPrepareAction().setText(t("observe.actions.synchro.prepare.operation", t(tabUI.getStep().getOperationLabel()))); - tabUI.getStartAction().setText(t("observe.actions.synchro.launch.operation", t(tabUI.getStep().getOperationLabel()))); + ui.getPrepareAction().setText(t("observe.actions.synchro.prepare.operation", t(ui.getStep().getOperationLabel()))); + ui.getStartAction().setText(t("observe.actions.synchro.launch.operation", t(ui.getStep().getOperationLabel()))); - ConfigUI configabUI = (ConfigUI) ui.getStepUI(AdminStep.CONFIG); + ConfigUI configabUI = (ConfigUI) parentUI.getStepUI(AdminStep.CONFIG); configabUI.getCentralSourceInfoLabel().setText(t("observe.action.config.export.required.write.data")); configabUI.getCentralSourceLabel().setText(t("observe.action.config.export.required.write.data")); // tableau de l'export de données - final JTable table4 = tabUI.getTrips(); + final JTable table4 = ui.getTrips(); table4.setRowHeight(24); UIHelper.fixTableColumnWidth(table4, 0, 20); @@ -158,17 +153,15 @@ public class ExportUIHandler extends AdminTabUIHandler { public void doPrepareAction() { - addAdminWorker(((ExportUI) ui).getPrepareAction().getToolTipText(), this::doPrepareAction0); + addAdminWorker(ui.getPrepareAction().getToolTipText(), this::doPrepareAction0); } public void doStartAction() { - ExportUI tabUI = (ExportUI) ui; - - int[] rows = tabUI.getTripsModel().getSelected(); - tabUI.getModel().getExportModel().setExportDataSelectedIndex(rows); + int[] rows = ui.getTripsModel().getSelected(); + ui.getModel().getExportModel().setExportDataSelectedIndex(rows); - addAdminWorker(tabUI.getStartAction().getToolTipText(), this::doStartAction0); + addAdminWorker(ui.getStartAction().getToolTipText(), this::doStartAction0); } @@ -184,7 +177,7 @@ public class ExportUIHandler extends AdminTabUIHandler { stepModel.setTripSeineDecorator(tripSeineDecorator); stepModel.setTripLonglineDecorator(tripLonglineDecorator); - ObserveSwingDataSource centralSource = model.getSafeCentralSource(false); + ObserveSwingDataSource centralSource = model.getConfigModel().getSafeCentralSource(false); stepModel.setCentralSource(centralSource); @@ -194,7 +187,7 @@ public class ExportUIHandler extends AdminTabUIHandler { return WizardState.FAILED; } - ObserveSwingDataSource source = model.getSafeLocalSource(false); + ObserveSwingDataSource source = model.getConfigModel().getSafeLocalSource(false); stepModel.setSource(source); @@ -209,7 +202,7 @@ public class ExportUIHandler extends AdminTabUIHandler { sendMessage(t("observe.actions.exportData.message.prepare.data")); // récupération des couples (program, marees) sur la base temporaire - SelectionTreeModel selectionModel = model.getSelectionDataModel(); + SelectionTreeModel selectionModel = model.getSelectDataModel().getSelectionDataModel(); stepModel.setData(selectionModel.getSelectedTripEntries()); List<TripEntry> entries = stepModel.getData(); @@ -227,6 +220,7 @@ public class ExportUIHandler extends AdminTabUIHandler { return WizardState.NEED_FIX; } + private WizardState doStartAction0() throws Exception { ExportModel stepModel = model.getExportModel(); @@ -346,6 +340,4 @@ public class ExportUIHandler extends AdminTabUIHandler { return WizardState.SUCCESSED; } - - } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportModel.java index aa9ba74..3ce26e8 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportModel.java @@ -21,14 +21,21 @@ */ package fr.ird.observe.application.swing.ui.admin.report; +import fr.ird.observe.application.swing.ObserveResourceManager; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.application.swing.ui.admin.AdminActionModel; import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUIModel; +import fr.ird.observe.application.swing.ui.admin.config.SelectDataModel; +import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.services.dto.ObserveModelType; import fr.ird.observe.services.dto.actions.report.Report; import fr.ird.observe.services.service.actions.report.ReportBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.beans.PropertyChangeListener; import java.io.File; import java.io.IOException; import java.net.URL; @@ -38,6 +45,9 @@ import java.util.TreeMap; import java.util.regex.Pattern; import java.util.stream.Collectors; +import static fr.ird.observe.application.swing.ui.admin.AdminUIModel.SELECTED_TRIP_PROPERTY_NAME; +import static jaxx.runtime.swing.wizard.WizardModel.VALID_STEP_PROPERTY_NAME; + /** * Le modèle utilisé pour la fonctionnalité de génération de rapport. * @@ -270,4 +280,60 @@ public class ReportModel extends AdminActionModel { log.info("Detects " + (reports.size() - 1) + " report(s)."); } } + + public void start(AdminUIModel uiModel) { + + ObserveSwingApplicationConfig config = ObserveSwingApplicationContext.get().getConfig(); + + File reportFile = ObserveResourceManager.Resource.report.getFile(config.getReportDirectory()); + + if (reportFile.exists()) { + if (log.isInfoEnabled()) { + log.info("Will use report file : " + reportFile); + } + + setReportFile(reportFile); + } else { + if (log.isWarnEnabled()) + log.warn("Default report file " + reportFile + " does not exists."); + } + + // on ecoute la modification du modèle + PropertyChangeListener listenReportModified = evt -> { + ReportModel source = (ReportModel) evt.getSource(); + if (log.isDebugEnabled()) { + log.debug("report model [" + source + "] changed on " + evt.getPropertyName() + ", new value = " + evt.getNewValue()); + } + uiModel.validate(); + }; + + SelectDataModel selectDataModel = uiModel.getSelectDataModel(); + + removePropertyChangeListener(listenReportModified); + addPropertyChangeListener(listenReportModified); + + // on ecoute la modification de la sélection + PropertyChangeListener listenerSelectedDataForReport = evt -> { + + // la modification de la sélection entraine la suppression d'un report sélectionné + setSelectedReport(null); + + // cela entraine aussi la modification de la marée sélectionnée + uiModel.firePropertyChange(SELECTED_TRIP_PROPERTY_NAME, selectDataModel.getSelectedTrip()); + + }; + + SelectionTreeModel selectionDataModel = selectDataModel.getSelectionDataModel(); + selectionDataModel.removePropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, listenerSelectedDataForReport); + selectionDataModel.addPropertyChangeListener(SelectionTreeModel.SELECTED_COUNT, listenerSelectedDataForReport); + + updateReports(); + + } + + public boolean validate(AdminUIModel uiModel) { + // pour acceder a l'onglet des report, il faut que + // l'onglet de sélection des données soit ok + return uiModel.validate(AdminStep.SELECT_DATA); + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUI.jaxx index 508b09b..0c359fe 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUI.jaxx @@ -38,22 +38,11 @@ javax.swing.JComboBox </import> - <ReportUIHandler id='handler' constructorParams='this'/> - <ReportModel id='stepModel' javaBean='getModel().getReportModel()'/> - <ResultTableModel id='resultModel' - javaBean='getStepModel().getResultModel()'/> + <ResultTableModel id='resultModel' javaBean='getStepModel().getResultModel()'/> <script><![CDATA[ -public ReportUI(AdminUI parentContext) { - super(AdminStep.REPORT, parentContext); -} - -@Override -public void initUI(AdminUI ui) { - getHandler().initTabUI(ui, this); -} public void destroy() { getHandler().destroy(); @@ -71,26 +60,22 @@ public void destroy() { <JToolBar id='toolbar' constraints='BorderLayout.WEST'> <!-- suppression de la sélection du report --> - <JButton id="resetSelectedReport" - onActionPerformed="getHandler().updateSelectedReport(null)"/> + <JButton id="resetSelectedReport" onActionPerformed="getHandler().updateSelectedReport(null)"/> </JToolBar> <!-- selecteur de report --> <JComboBox id='reportSelector' constraints='BorderLayout.CENTER' onItemStateChanged='getHandler().updateSelectedReportFromEvent(event)'/> - <!--onItemStateChanged='if (event.getStateChange() == ItemEvent.SELECTED) getHandler().updateSelectedReport((Report) ((JComboBox)event.getSource()).getSelectedItem());'/>--> - <JScrollPane id='reportDescriptionPane' - constraints='BorderLayout.SOUTH'> + <JScrollPane id='reportDescriptionPane' constraints='BorderLayout.SOUTH'> <JTextArea id='reportDescription'/> </JScrollPane> </JPanel> <!-- selecteur de variables --> - <JScrollPane id='reportVariableSelectorPane' - constraints='BorderLayout.CENTER'> + <JScrollPane id='reportVariableSelectorPane' constraints='BorderLayout.CENTER'> <JPanel id='reportVariableSelectorPanel'> </JPanel> </JScrollPane> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUIHandler.java index abfe150..e84bed0 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/report/ReportUIHandler.java @@ -26,9 +26,7 @@ import fr.ird.observe.application.swing.ObserveSwingTechnicalException; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; -import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; import fr.ird.observe.services.dto.DataDto; import fr.ird.observe.services.dto.DataReference; @@ -39,6 +37,7 @@ import fr.ird.observe.services.dto.actions.report.ReportVariable; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.service.actions.report.ReportService; import jaxx.runtime.context.JAXXInitialContext; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.editor.bean.BeanComboBox; import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.logging.Log; @@ -70,7 +69,7 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class ReportUIHandler extends AdminTabUIHandler { +public class ReportUIHandler extends AdminTabUIHandler<ReportUI> implements UIHandler<ReportUI> { public static final String VARIABLE_NAME = "variableName"; @@ -81,22 +80,18 @@ public class ReportUIHandler extends AdminTabUIHandler { private final Runnable revalidateTabUI; - public ReportUIHandler(AdminTabUI ui) { - super(ui); - revalidateTabUI = () -> getUi().revalidate(); + public ReportUIHandler() { + revalidateTabUI = getUi()::revalidate; } - public void initTabUI(AdminUI ui, final ReportUI tabUI) { - - super.initTabUI(ui, tabUI); - + @Override + public void afterInit(ReportUI ui) { + super.afterInit(ui); if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + - "] for main ui " + ui.getClass().getName() + - "@" + System.identityHashCode(ui)); + log.debug(" specialized for [" + ui.getStep() + "] for main ui " + parentUI.getClass().getName() + "@" + System.identityHashCode(this.ui)); } - UIHelper.setLayerUI(tabUI.getContent(), ui.getConfigBlockLayerUI()); + UIHelper.setLayerUI(ui.getContent(), parentUI.getConfigBlockLayerUI()); ReportModel stepModel = getStepModel(); stepModel.addPropertyChangeListener(evt -> { @@ -113,10 +108,10 @@ public class ReportUIHandler extends AdminTabUIHandler { if (ReportModel.REPORTS_PROPERTY_NAME.equals(propertyName)) { List<?> reports = (List<?>) newValue; - onReportsChanged(tabUI, reports); + onReportsChanged(ui, reports); } else if (ReportModel.SELECTED_REPORT_PROPERTY_NAME.equals(propertyName)) { Report report = (Report) newValue; - onSelectedReportChanged(tabUI, source, report); + onSelectedReportChanged(ui, source, report); } else if (ReportModel.VARIABLES_PROPERTY_NAME.equals(propertyName)) { Map<String, Object> variables = (Map<String, Object>) newValue; onVariablesChanges(source, variables); @@ -128,19 +123,19 @@ public class ReportUIHandler extends AdminTabUIHandler { } }); - tabUI.getReportSelector().setRenderer(new DefaultListCellRenderer() { - private static final long serialVersionUID = 1L; + ui.getReportSelector().setRenderer(new DefaultListCellRenderer() { + private static final long serialVersionUID = 1L; - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - if (value == null) { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + if (value == null) { - // on affiche une message de sélection de report - value = t("observe.message.select.report"); - } - return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - } - } + // on affiche une message de sélection de report + value = t("observe.message.select.report"); + } + return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + } + } ); // ajout du renderer sur le tableau @@ -180,15 +175,15 @@ public class ReportUIHandler extends AdminTabUIHandler { return comp; } }; - tabUI.getResultTable().setDefaultRenderer(Object.class, renderer); - tabUI.getResultTable().setDefaultRenderer(String.class, renderer); + ui.getResultTable().setDefaultRenderer(Object.class, renderer); + ui.getResultTable().setDefaultRenderer(String.class, renderer); // initialisation de l'ui de configuration if (log.isInfoEnabled()) { - log.info("Init extra configuration for " + tabUI.getName()); + log.info("Init extra configuration for " + ui.getName()); } - ConfigUI configUI = (ConfigUI) ui.getStepUI(AdminStep.CONFIG); + ConfigUI configUI = (ConfigUI) parentUI.getStepUI(AdminStep.CONFIG); JAXXInitialContext tx = new JAXXInitialContext().add(configUI).add(this); ReportConfigUI extraConfig = new ReportConfigUI(tx); @@ -314,11 +309,11 @@ public class ReportUIHandler extends AdminTabUIHandler { try { - ObserveSwingDataSource dataSource = getModel().getSafeLocalSource(true); + ObserveSwingDataSource dataSource = getModel().getConfigModel().getSafeLocalSource(true); ReportService reportService = dataSource.newReportService(); - report = reportService.populateVariables(report, getModel().getSelectedTrip().getId()); + report = reportService.populateVariables(report, getModel().getSelectDataModel().getSelectedTrip().getId()); } catch (Exception e) { throw new ObserveSwingTechnicalException("unable to populate report : " + report.getName(), e); @@ -408,7 +403,7 @@ public class ReportUIHandler extends AdminTabUIHandler { Report report = model.getSelectedReport(); - DataReference trip = getModel().getSelectedTrip(); + DataReference trip = getModel().getSelectDataModel().getSelectedTrip(); if (log.isDebugEnabled()) { log.debug("Build result for report [" + report.getName() + "] on " + trip); @@ -423,7 +418,7 @@ public class ReportUIHandler extends AdminTabUIHandler { long startTime = TimeLog.getTime(); - ObserveSwingDataSource dataSource = getModel().getSafeLocalSource(true); + ObserveSwingDataSource dataSource = getModel().getConfigModel().getSafeLocalSource(true); if (!dataSource.isOpen()) { dataSource.open(); } @@ -473,7 +468,7 @@ public class ReportUIHandler extends AdminTabUIHandler { } public void destroy() { - ObserveSwingDataSource dataSource = model.getSafeLocalSource(false); + ObserveSwingDataSource dataSource = model.getConfigModel().getSafeLocalSource(false); if (dataSource.isOpen()) { dataSource.close(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeModel.java new file mode 100644 index 0000000..65a0218 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeModel.java @@ -0,0 +1,21 @@ +package fr.ird.observe.application.swing.ui.admin.resume; + +import fr.ird.observe.application.swing.ui.admin.AdminActionModel; +import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUIModel; + +/** + * Created on 28/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 6.0 + */ +public class ShowResumeModel extends AdminActionModel { + public ShowResumeModel() { + super(AdminStep.SHOW_RESUME); + } + + public boolean validate(AdminUIModel uiModel) { + return true; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeUI.jaxx index d6d38a6..08610d2 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeUI.jaxx @@ -28,6 +28,7 @@ <import> fr.ird.observe.application.swing.ui.UIHelper + fr.ird.observe.application.swing.ui.admin.AdminActionModel fr.ird.observe.application.swing.ui.admin.AdminUI fr.ird.observe.application.swing.ui.admin.AdminStep fr.ird.observe.application.swing.ui.admin.AdminTabUI @@ -35,19 +36,9 @@ java.awt.Dimension </import> - <ShowResumeUIHandler id='handler' constructorParams='this'/> - - <fr.ird.observe.application.swing.ui.admin.AdminActionModel id='stepModel' initializer='null'/> + <ShowResumeModel id='stepModel' initializer='getModel().getShowResumeModel()'/> <script><![CDATA[ -public ShowResumeUI(AdminUI parentContext) { - super(AdminStep.SHOW_RESUME, parentContext); -} - -@Override -public void initUI(AdminUI ui) { - getHandler().initTabUI(ui, this); -} @Override public void destroy() { @@ -75,13 +66,12 @@ public void addMessage(AdminStep step, String text) { </row> <row> <cell> - <JScrollPane id='globalProgressionPane' - columnHeaderView='{globalProgressionTop}'> + <JScrollPane id='globalProgressionPane' columnHeaderView='{globalProgressionTop}'> <JTextArea id='globalProgression'/> <JToolBar id='globalProgressionTop'> <JLabel id='globalProgressionTopLabel'/> <javax.swing.Box.Filler - constructorParams='UIHelper.newMinDimension(), UIHelper.newMinDimension(), UIHelper.newMaxXDimension()'/> + constructorParams='UIHelper.newMinDimension(), UIHelper.newMinDimension(), UIHelper.newMaxXDimension()'/> <JButton id="globalProgressionCopyToClipBoard" onActionPerformed='UIHelper.copyToClipBoard(globalProgression.getText())'/> </JToolBar> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeUIHandler.java index 6244531..66f7d57 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/resume/ShowResumeUIHandler.java @@ -25,10 +25,8 @@ import fr.ird.observe.application.swing.I18nEnumHelper; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.wizard.ext.WizardState; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import static org.nuiton.i18n.I18n.t; @@ -38,32 +36,14 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class ShowResumeUIHandler extends AdminTabUIHandler { - - /** Logger */ - private static final Log log = LogFactory.getLog(ShowResumeUIHandler.class); - - public ShowResumeUIHandler(ShowResumeUI ui) { - super(ui); - } +public class ShowResumeUIHandler extends AdminTabUIHandler<ShowResumeUI> implements UIHandler<ShowResumeUI> { @Override - public ShowResumeUI getUi() { - return (ShowResumeUI) super.getUi(); - } - - public void initTabUI(AdminUI ui, ShowResumeUI tabUI) { - - super.initTabUI(ui, tabUI); - - if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } - - UIHelper.setLayerUI(tabUI.getContent(), null); + public void afterInit(ShowResumeUI ui) { + super.afterInit(ui); + UIHelper.setLayerUI(ui.getContent(), null); } - public void updateText() { StringBuilder buffer = new StringBuilder(); if (!model.isWasStarted()) { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalModel.java index b7f7eb9..a40d528 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalModel.java @@ -21,11 +21,16 @@ */ package fr.ird.observe.application.swing.ui.admin.save; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.application.swing.ui.admin.AdminActionModel; import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUIModel; +import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.beans.PropertyChangeListener; import java.io.File; import java.util.HashSet; import java.util.Set; @@ -119,10 +124,10 @@ public class SaveLocalModel extends AdminActionModel { */ public boolean isCanSaveLocal() { boolean validate = !doBackup || - backupFile != null && - !backupFile.exists() && - backupFile.getName().endsWith(".sql.gz") && - backupFile.getParentFile().exists(); + backupFile != null && + !backupFile.exists() && + backupFile.getName().endsWith(".sql.gz") && + backupFile.getParentFile().exists(); if (log.isDebugEnabled()) { log.debug("can save ? " + validate); @@ -137,4 +142,42 @@ public class SaveLocalModel extends AdminActionModel { setLocalSourceNeedSave(true); } + public void start(AdminUIModel uiModel) { + ObserveSwingApplicationConfig config = ObserveSwingApplicationContext.get().getConfig(); + + File backupfile = config.newBackupDataFile(); + setBackupFile(backupfile); + setDoBackup(true); + + PropertyChangeListener listenSaveLocalChanged = evt -> { + + String propertyName = evt.getPropertyName(); + + if (SaveLocalModel.BACKUP_FILE_PROPERTY_NAME.equals(propertyName)) { + + uiModel.validate(); + return; + } + + if (SaveLocalModel.LOCAL_SOURCE_NEED_SAVE_PROPERTY_NAME.equals(propertyName)) { + boolean localSourceNeedSave = (Boolean) evt.getNewValue(); + if (localSourceNeedSave) { + // l'opération de sauvegarde est obligatoire + uiModel.setStepState(AdminStep.SAVE_LOCAL, WizardState.PENDING); + } + uiModel.validate(); + return; + } + + if (log.isDebugEnabled()) { + log.debug("Skip property " + propertyName); + } + }; + addPropertyChangeListener(listenSaveLocalChanged); + } + + public boolean validate(AdminUIModel uiModel, AdminStep step) { + // valide si l'action a ete executee avec success + return !isDoBackup() || uiModel.getStepState(step) == WizardState.SUCCESSED; + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalUI.jaxx index 2786e15..1c59b97 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalUI.jaxx @@ -36,24 +36,9 @@ java.io.File </import> - <SaveLocalUIHandler id='handler' constructorParams='this'/> - <SaveLocalModel id='stepModel' initializer='getModel().getSaveLocalModel()'/> - <CardLayout2Ext id='pendingLayout' - constructorParams='this, "PENDING_content_panel"'/> - - <script><![CDATA[ -public SaveLocalUI(AdminUI parentContext) { - super(AdminStep.SAVE_LOCAL, parentContext); -} - -@Override -public void initUI(AdminUI ui) { - getHandler().initTabUI(ui, this); -} -]]> - </script> + <CardLayout2Ext id='pendingLayout' constructorParams='this, "PENDING_content_panel"'/> <JPanel id='PENDING_content'> <Table constraints='BorderLayout.CENTER' fill='both'> @@ -68,8 +53,7 @@ public void initUI(AdminUI ui) { <cell fill='both' weighty='1' weightx='1'> <JPanel id='PENDING_content_panel'> - <JButton id="continueAction" constraints='"no"' - onActionPerformed='getHandler().skipOperation()'/> + <JButton id="continueAction" constraints='"no"' onActionPerformed='getHandler().skipOperation()'/> <JPanel layout='{new BorderLayout()}' constraints='"do"'> @@ -91,8 +75,7 @@ public void initUI(AdminUI ui) { onKeyReleased='getHandler().changeDirectory(new File(((JTextField)event.getSource()).getText()))'/> </cell> <cell anchor="east"> - <JButton id="backupFileChooseAction" - onActionPerformed="getHandler().chooseBackupFile()"/> + <JButton id="backupFileChooseAction" onActionPerformed="getHandler().chooseBackupFile()"/> </cell> </row> <row> @@ -106,8 +89,7 @@ public void initUI(AdminUI ui) { </row> <row> <cell fill='both' columns="3"> - <JButton id="startAction" - onActionPerformed="getHandler().doStartAction()"/> + <JButton id="startAction" onActionPerformed="getHandler().doStartAction()"/> </cell> </row> </Table> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalUIHandler.java index f4484d0..88da083 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/save/SaveLocalUIHandler.java @@ -25,11 +25,11 @@ import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.application.swing.ui.admin.synchronize.referential.legacy.SynchronizeModel; +import fr.ird.observe.services.service.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeContext; import fr.ird.observe.services.service.sql.AddSqlScriptProducerRequest; import fr.ird.observe.services.service.sql.SqlScriptProducerService; -import fr.ird.observe.services.service.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeContext; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; @@ -47,32 +47,18 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class SaveLocalUIHandler extends AdminTabUIHandler { +public class SaveLocalUIHandler extends AdminTabUIHandler<SaveLocalUI> implements UIHandler<SaveLocalUI> { /** Logger */ private static final Log log = LogFactory.getLog(SaveLocalUIHandler.class); protected ObserveSwingDataSource source; - public SaveLocalUIHandler(SaveLocalUI ui) { - super(ui); - } - @Override - public SaveLocalUI getUi() { - return (SaveLocalUI) super.getUi(); - } - - public void initTabUI(AdminUI ui, SaveLocalUI tabUI) { - - super.initTabUI(ui, tabUI); - - if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } - - String message = t("observe.actions.synchro.launch.operation", t(tabUI.getStep().getOperationLabel())); - tabUI.getStartAction().setText(message); + public void afterInit(SaveLocalUI ui) { + super.afterInit(ui); + String message = t("observe.actions.synchro.launch.operation", t(ui.getStep().getOperationLabel())); + ui.getStartAction().setText(message); } @@ -132,7 +118,7 @@ public class SaveLocalUIHandler extends AdminTabUIHandler { log.debug(this); } - source = model.getSafeLocalSource(false); + source = model.getConfigModel().getSafeLocalSource(false); SaveLocalModel stepModel = model.getSaveLocalModel(); if (!stepModel.isLocalSourceNeedSave()) { @@ -182,5 +168,4 @@ public class SaveLocalUIHandler extends AdminTabUIHandler { sendMessage(t("observe.actions.synchro.referential.message.apply.done", new Date())); } - } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroModel.java index 19abcde..b5f5342 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroModel.java @@ -25,12 +25,15 @@ package fr.ird.observe.application.swing.ui.admin.synchronize.data; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.ui.admin.AdminActionModel; import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUI; +import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; import fr.ird.observe.application.swing.ui.admin.synchronize.data.task.DataSynchronizeTaskSupport; import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.swing.DefaultListModel; +import javax.swing.border.TitledBorder; /** * Created on 02/08/16. @@ -152,4 +155,12 @@ public class DataSynchroModel extends AdminActionModel { } } + + public void start(AdminUI ui) { + + ConfigUI configUI = (ConfigUI) ui.getStepUI(AdminStep.CONFIG); + configUI.getLocalSourceConfig().setBorder(new TitledBorder(ui.getModel().getConfigModel().getLocalSourceLabel())); + configUI.getCentralSourceConfig().setBorder(new TitledBorder(ui.getModel().getConfigModel().getCentralSourceLabel())); + + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jaxx index 203d32e..2c01b63 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUI.jaxx @@ -36,22 +36,8 @@ </import> - <DataSynchroUIHandler id='handler' constructorParams='this'/> - <DataSynchroModel id='stepModel' initializer='getModel().getDataSynchroModel()'/> - <script><![CDATA[ -public DataSynchroUI(AdminUI parentContext) { - super(AdminStep.DATA_SYNCHRONIZE, parentContext); -} - -public void initUI(AdminUI ui) { - getHandler().initTabUI(ui, this); -} - -]]> - </script> - <JPanel id='PENDING_content'> <Table constraints='BorderLayout.CENTER' fill='both' weightx='1' weighty='1'> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUIHandler.java index 5ac903a..28a7937 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/data/DataSynchroUIHandler.java @@ -28,7 +28,6 @@ import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferen import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; import fr.ird.observe.application.swing.ui.admin.synchronize.data.task.CopyToLeftDataSynchronizeTask; import fr.ird.observe.application.swing.ui.admin.synchronize.data.task.CopyToRightDataSynchronizeTask; @@ -48,9 +47,8 @@ import fr.ird.observe.services.service.data.ExportTripResult; import fr.ird.observe.services.service.data.ImportTripRequest; import fr.ird.observe.services.service.data.ImportTripResult; import fr.ird.observe.services.service.data.TripManagementService; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.wizard.ext.WizardState; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import javax.swing.DefaultListModel; import javax.swing.border.TitledBorder; @@ -66,40 +64,14 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 5.0 */ -public class DataSynchroUIHandler extends AdminTabUIHandler { - - /** Logger */ - private static final Log log = LogFactory.getLog(DataSynchroUIHandler.class); - - public DataSynchroUIHandler(DataSynchroUI ui) { - super(ui); - } - - public DataSynchroModel getStepModel() { - return model.getDataSynchroModel(); - } +public class DataSynchroUIHandler extends AdminTabUIHandler<DataSynchroUI> implements UIHandler<DataSynchroUI> { @Override - public DataSynchroUI getUi() { - return (DataSynchroUI) super.getUi(); - } - - @Override - public void updateState(AdminTabUI ui, WizardState newState) { - super.updateState(ui, newState); - } - - public void initTabUI(AdminUI ui, DataSynchroUI tabUI) { - - super.initTabUI(ui, tabUI); - - if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } - + public void afterInit(DataSynchroUI ui) { + super.afterInit(this.ui); DataSynchroModel stepModel = getStepModel(); - SelectionTree leftTree = tabUI.getLeftTree(); + SelectionTree leftTree = ui.getLeftTree(); SelectionTreeModel leftSelectionDataModel = leftTree.getTreeModel(); stepModel.setLeftSelectionDataModel(leftSelectionDataModel); leftSelectionDataModel.setLoadLongline(true); @@ -108,7 +80,7 @@ public class DataSynchroUIHandler extends AdminTabUIHandler { leftSelectionDataModel.setShowEmptyTrips(false); - SelectionTree rightTree = tabUI.getRightTree(); + SelectionTree rightTree = ui.getRightTree(); SelectionTreeModel rightSelectionDataModel = rightTree.getTreeModel(); stepModel.setRightSelectionDataModel(rightSelectionDataModel); rightSelectionDataModel.setLoadLongline(true); @@ -124,8 +96,8 @@ public class DataSynchroUIHandler extends AdminTabUIHandler { SelectionTreeModel model = (SelectionTreeModel) evt.getSource(); boolean withDataSelected = !model.isSelectionEmpty(); - tabUI.getCopyToRight().setEnabled(withDataSelected); - tabUI.getDeleteFromLeft().setEnabled(withDataSelected); + ui.getCopyToRight().setEnabled(withDataSelected); + ui.getDeleteFromLeft().setEnabled(withDataSelected); }); stepModel.getRightSelectionDataModel().addPropertyChangeListener(evt -> { @@ -133,13 +105,22 @@ public class DataSynchroUIHandler extends AdminTabUIHandler { SelectionTreeModel model = (SelectionTreeModel) evt.getSource(); boolean withDataSelected = !model.isSelectionEmpty(); - tabUI.getCopyToLeft().setEnabled(withDataSelected); - tabUI.getDeleteFromRight().setEnabled(withDataSelected); + ui.getCopyToLeft().setEnabled(withDataSelected); + ui.getDeleteFromRight().setEnabled(withDataSelected); }); } + public DataSynchroModel getStepModel() { + return model.getDataSynchroModel(); + } + + @Override + public void updateState(AdminTabUI ui, WizardState newState) { + super.updateState(ui, newState); + } + public void doStartAction() { addAdminWorker(getUi().getStartAction().getToolTipText(), this::doStartAction0); @@ -225,25 +206,25 @@ public class DataSynchroUIHandler extends AdminTabUIHandler { DataSynchroModel stepModel = getStepModel(); ConfigUI configUI = (ConfigUI) parentUI.getStepUI(AdminStep.CONFIG); - ObserveSwingDataSource leftSource = getModel().getSafeLocalSource(true); + ObserveSwingDataSource leftSource = getModel().getConfigModel().getSafeLocalSource(true); stepModel.setLeftSource(leftSource); - ObserveSwingDataSource rightSource = getModel().getSafeCentralSource(true); + ObserveSwingDataSource rightSource = getModel().getConfigModel().getSafeCentralSource(true); stepModel.setRightSource(rightSource); - tabUI.getLeftTreePane().setBorder(new TitledBorder(getModel().getLocalSourceModel().getLabel())); + tabUI.getLeftTreePane().setBorder(new TitledBorder(getModel().getConfigModel().getLocalSourceModel().getLabel())); stepModel.populateLeftSelectionModel(); // updateSelectionModel(tabUI.getLeftTree(), leftSource); sendMessage(t("observe.actions.synchro.referential.message.data.leftData.loaded")); - configUI.getLocalSourceConfig().setBorder(new TitledBorder(getModel().getLocalSourceLabel())); + configUI.getLocalSourceConfig().setBorder(new TitledBorder(getModel().getConfigModel().getLocalSourceLabel())); - tabUI.getRightTreePane().setBorder(new TitledBorder(getModel().getCentralSourceModel().getLabel())); + tabUI.getRightTreePane().setBorder(new TitledBorder(getModel().getConfigModel().getCentralSourceModel().getLabel())); stepModel.populateRightSelectionModel(); // updateSelectionModel(tabUI.getRightTree(), rightSource); sendMessage(t("observe.actions.synchro.referential.message.data.rightData.loaded")); - configUI.getCentralSourceConfig().setBorder(new TitledBorder(getModel().getCentralSourceLabel())); + configUI.getCentralSourceConfig().setBorder(new TitledBorder(getModel().getConfigModel().getCentralSourceLabel())); return WizardState.NEED_FIX; @@ -360,5 +341,4 @@ public class DataSynchroUIHandler extends AdminTabUIHandler { return WizardState.SUCCESSED; } - } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeModel.java index 36d0359..5410c75 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeModel.java @@ -22,6 +22,7 @@ package fr.ird.observe.application.swing.ui.admin.synchronize.referential.legacy; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.admin.AdminUIModel; import fr.ird.observe.services.service.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeCallbackResults; import fr.ird.observe.services.service.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeContext; import fr.ird.observe.services.service.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeEngine; @@ -29,6 +30,7 @@ import fr.ird.observe.services.service.actions.synchro.referential.legacy.Unidir import fr.ird.observe.application.swing.ui.admin.AdminActionModel; import fr.ird.observe.application.swing.ui.admin.AdminStep; import jaxx.runtime.swing.model.JaxxDefaultListModel; +import jaxx.runtime.swing.wizard.ext.WizardState; import javax.swing.DefaultListSelectionModel; import java.util.List; @@ -121,4 +123,8 @@ public class SynchronizeModel extends AdminActionModel { obsoleteReferencesSelectionModel.clearSelection(); obsoleteReferences.clear(); } + + public boolean validate(AdminUIModel uiModel, AdminStep step) { + return uiModel.getStepState(step) == WizardState.SUCCESSED; + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeUI.jaxx index d522583..2bd538e 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeUI.jaxx @@ -38,21 +38,11 @@ <!-- un etat pour savoir quand on peut activer l'action apply --> <Boolean id='canApply' javaBean='false'/> - <SynchronizeUIHandler id='handler' constructorParams='this'/> - <SynchronizeModel id='stepModel' initializer='getModel().getSynchronizeReferentielModel()'/> <CardLayout2 id='safeRefsPanelLayout'/> <script><![CDATA[ -public SynchronizeUI(AdminUI parentContext) { - super(AdminStep.SYNCHRONIZE, parentContext); -} - -@Override -public void initUI(AdminUI ui) { - getHandler().initTabUI(ui, this); -} @Override public void destroy() { @@ -74,8 +64,7 @@ protected void apply() { </script> <JPanel id='PENDING_content'> - <Table constraints='BorderLayout.CENTER' fill='both' weightx='1' - weighty='1'> + <Table constraints='BorderLayout.CENTER' fill='both' weightx='1' weighty='1'> <row> <cell> <JButton id='startAction' onActionPerformed="getHandler().doStartAction()"/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeUIHandler.java index fe17c3d..698327a 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/legacy/SynchronizeUIHandler.java @@ -22,9 +22,11 @@ package fr.ird.observe.application.swing.ui.admin.synchronize.referential.legacy; import com.google.common.collect.ImmutableSet; +import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; -import fr.ird.observe.application.swing.db.ObserveSwingDataSource; +import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.dto.referential.ReferentialReference; import fr.ird.observe.services.service.actions.synchro.referential.diff.ReferentialSynchronizeDiffsEngine; @@ -35,9 +37,7 @@ import fr.ird.observe.services.service.actions.synchro.referential.legacy.Unidir import fr.ird.observe.services.service.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeEngine; import fr.ird.observe.services.service.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeLocalService; import fr.ird.observe.services.service.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeResult; -import fr.ird.observe.application.swing.ui.admin.AdminStep; -import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.CardLayout2; import jaxx.runtime.swing.editor.bean.BeanComboBox; import jaxx.runtime.swing.model.JaxxDefaultListModel; @@ -66,35 +66,21 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class SynchronizeUIHandler extends AdminTabUIHandler { +public class SynchronizeUIHandler extends AdminTabUIHandler<SynchronizeUI> implements UIHandler<SynchronizeUI> { /** Logger */ private static final Log log = LogFactory.getLog(SynchronizeUIHandler.class); - public SynchronizeUIHandler(SynchronizeUI ui) { - super(ui); - } - public SynchronizeModel getStepModel() { return model.getSynchronizeReferentielModel(); } @Override - public SynchronizeUI getUi() { - return (SynchronizeUI) super.getUi(); - } + public void afterInit(SynchronizeUI ui) { + super.afterInit(ui); + ui.getStartAction().setText(t("observe.actions.synchro.referential.legacy.launch.operation", t(ui.getStep().getOperationLabel()))); - public void initTabUI(AdminUI ui, SynchronizeUI tabUI) { - - super.initTabUI(ui, tabUI); - - if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } - - tabUI.getStartAction().setText(t("observe.actions.synchro.referential.legacy.launch.operation", t(tabUI.getStep().getOperationLabel()))); - - DefaultListSelectionModel obsoleteReferenceSelectionModel = tabUI.getModel().getSynchronizeReferentielModel().getObsoleteReferencesSelectionModel(); + DefaultListSelectionModel obsoleteReferenceSelectionModel = ui.getModel().getSynchronizeReferentielModel().getObsoleteReferencesSelectionModel(); obsoleteReferenceSelectionModel.addListSelectionListener(this::updateSelectedObsoleteEntity); obsoleteReferenceSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); @@ -116,10 +102,10 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { // on cree les sources de données - ObserveSwingDataSource source = model.getSafeLocalSource(false); + ObserveSwingDataSource source = model.getConfigModel().getSafeLocalSource(false); stepModel.setSource(source); - ObserveSwingDataSource centralSource = model.getSafeCentralSource(false); + ObserveSwingDataSource centralSource = model.getConfigModel().getSafeCentralSource(false); stepModel.setCentralSource(centralSource); openSource(source); @@ -223,8 +209,6 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { return; } - SynchronizeUI ui = getUi(); - int row = getStepModel().getObsoleteReferencesSelectionModel().getMinSelectionIndex(); JaxxDefaultListModel<ObsoleteReferentialReference> obsoleteReferences = getStepModel().getObsoleteReferences(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroModel.java index 7b3d242..4606e91 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroModel.java @@ -22,9 +22,11 @@ package fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng; * #L% */ +import fr.ird.observe.application.swing.I18nEnumHelper; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.ui.admin.AdminActionModel; import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ReferentialSynchronizeMode; import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng.task.AddReferentialSynchronizeTask; import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng.task.DeleteReferentialSynchronizeTask; @@ -40,9 +42,12 @@ import fr.ird.observe.services.service.actions.synchro.referential.ng.Referentia import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; +import static org.nuiton.i18n.I18n.t; + /** * Created on 02/08/16. * @@ -318,4 +323,42 @@ public class ReferentialSynchroModel extends AdminActionModel { ReferentialSynchronizeService rightService = rightSource.newReferentialSynchronizeService(); return new ReferentialSynchronizeServiceEngine(leftService, rightService); } + + public void start(AdminUI ui) { + + PropertyChangeListener listenReferentialConfigChanged = evt -> { + + + if (ui.getModel().isWasStarted()) { + + // on ne propage plus rien (il n'y a plus de configuration possible...) + if (log.isDebugEnabled()) { + log.debug("Stop propagation, was started... " + evt.getPropertyName()); + } + return; + } + + if (ReferentialSynchroModel.SYNCHRONIZE_MODE_PROPERTY_NAME.equals(evt.getPropertyName())) { + + ui.getModel().validate(); + + } + + }; + + removePropertyChangeListener(listenReferentialConfigChanged); + addPropertyChangeListener(listenReferentialConfigChanged); + + addPropertyChangeListener(ReferentialSynchroModel.SYNCHRONIZE_MODE_PROPERTY_NAME, evt -> { + + ReferentialSynchronizeMode newValue = (ReferentialSynchronizeMode) evt.getNewValue(); + + if (ui.getTabs().getComponentCount() > 1 && newValue != null) { + ui.getTabs().setTitleAt(1, t("observe.actions.synchro.referential.withMode", I18nEnumHelper.getLabel(newValue))); + } + + }); + + setSynchronizeMode(ReferentialSynchronizeMode.FROM_LEFT_TO_RIGHT); + } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUI.jaxx index 1ec9b95..586a5db 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUI.jaxx @@ -43,8 +43,6 @@ </import> - <ReferentialSynchroUIHandler id='handler' constructorParams='this'/> - <ReferentialSynchroModel id='stepModel' javaBean='getModel().getReferentialSynchroModel()'/> <ReferentialSynchronizeTreeModel id="leftTreeModel" javaBean="getStepModel().getLeftTreeModel()"/> @@ -54,13 +52,6 @@ </JPanel> <script><![CDATA[ -public ReferentialSynchroUI(AdminUI parentContext) { - super(AdminStep.REFERENTIAL_SYNCHRONIZE, parentContext); -} - -public void initUI(AdminUI ui) { - getHandler().initTabUI(ui, this); -} @Override public void destroy() { @@ -76,7 +67,7 @@ public void destroy() { weighty='1'> <row> <cell> - <JButton id='startAction' onActionPerformed="getHandler().doStartAction()"/> + <JButton id='startAction' onActionPerformed="handler.doStartAction()"/> </cell> </row> </Table> @@ -86,7 +77,7 @@ public void destroy() { <Table id='contentNorth' fill="both" weighty="1"> <row> <cell weightx="0.5"> - <JScrollPane id='leftTreePane' columnHeaderView='{leftTreeHeader}'> + <JScrollPane id='leftTreePane' columnHeaderView='{leftTreeHeader}'> <JTree id='leftTree'/> <BeanTreeHeader id='leftTreeHeader' tree='{leftTree}'/> </JScrollPane> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUIHandler.java index 3e1f712..9917a8b 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/synchronize/referential/ng/ReferentialSynchroUIHandler.java @@ -26,7 +26,6 @@ import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ReferentialSynchronizeMode; import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng.tree.ReferentialSynchronizeTreeModel; @@ -34,10 +33,9 @@ import fr.ird.observe.application.swing.ui.admin.synchronize.referential.ng.tree import fr.ird.observe.services.service.actions.synchro.referential.diff.ReferentialSynchronizeDiffService; import fr.ird.observe.services.service.actions.synchro.referential.diff.ReferentialSynchronizeDiffsEngine; import jaxx.runtime.context.JAXXInitialContext; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.lang3.tuple.Pair; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import javax.swing.JScrollPane; import javax.swing.JTree; @@ -53,15 +51,11 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 5.0 */ -public class ReferentialSynchroUIHandler extends AdminTabUIHandler { - - /** Logger */ - private static final Log log = LogFactory.getLog(ReferentialSynchroUIHandler.class); +public class ReferentialSynchroUIHandler extends AdminTabUIHandler<ReferentialSynchroUI> implements UIHandler<ReferentialSynchroUI> { private final TreeSelectionListener treeSelectionListener; - public ReferentialSynchroUIHandler(ReferentialSynchroUI ui) { - super(ui); + public ReferentialSynchroUIHandler() { this.treeSelectionListener = evt -> updateEnabledActions(); } @@ -70,19 +64,10 @@ public class ReferentialSynchroUIHandler extends AdminTabUIHandler { } @Override - public ReferentialSynchroUI getUi() { - return (ReferentialSynchroUI) super.getUi(); - } - - public void initTabUI(AdminUI ui, ReferentialSynchroUI tabUI) { + public void afterInit(ReferentialSynchroUI ui) { + super.afterInit(this.ui); - super.initTabUI(ui, tabUI); - - if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } - - ConfigUI configUI = (ConfigUI) ui.getStepUI(AdminStep.CONFIG); + ConfigUI configUI = (ConfigUI) parentUI.getStepUI(AdminStep.CONFIG); JAXXInitialContext tx = new JAXXInitialContext().add(configUI).add(this); ReferentialSynchroConfigUI extraConfig = new ReferentialSynchroConfigUI(tx); configUI.getExtraConfig().add(extraConfig); @@ -99,10 +84,10 @@ public class ReferentialSynchroUIHandler extends AdminTabUIHandler { ReferentialSynchroModel stepModel = getStepModel(); - ObserveSwingDataSource leftSource = getModel().getSafeLocalSource(true); + ObserveSwingDataSource leftSource = getModel().getConfigModel().getSafeLocalSource(true); stepModel.setLeftSource(leftSource); - ObserveSwingDataSource rightSource = getModel().getSafeCentralSource(true); + ObserveSwingDataSource rightSource = getModel().getConfigModel().getSafeCentralSource(true); stepModel.setRightSource(rightSource); ReferentialSynchronizeDiffService leftDiffSynchronizeService = leftSource.newReferentialSynchronizeDiffService(); @@ -123,17 +108,17 @@ public class ReferentialSynchroUIHandler extends AdminTabUIHandler { initTree(ui.getLeftTree(), ui.getLeftTreePane(), stepModel.getLeftTreeModel(), - getModel().getLocalSourceModel().getLabel(), + getModel().getConfigModel().getLocalSourceModel().getLabel(), t("observe.actions.synchro.referential.message.referential.leftData.loaded")); initTree(ui.getRightTree(), ui.getRightTreePane(), stepModel.getRightTreeModel(), - getModel().getCentralSourceModel().getLabel(), + getModel().getConfigModel().getCentralSourceModel().getLabel(), t("observe.actions.synchro.referential.message.referential.rightData.loaded")); return WizardState.NEED_FIX; - + } private void updateEnabledActions() { @@ -204,10 +189,9 @@ public class ReferentialSynchroUIHandler extends AdminTabUIHandler { } ConfigUI configUI = (ConfigUI) parentUI.getStepUI(AdminStep.CONFIG); - configUI.getLocalSourceConfig().setBorder(new TitledBorder(getModel().getLocalSourceLabel())); - configUI.getCentralSourceConfig().setBorder(new TitledBorder(getModel().getCentralSourceLabel())); + configUI.getLocalSourceConfig().setBorder(new TitledBorder(getModel().getConfigModel().getLocalSourceLabel())); + configUI.getCentralSourceConfig().setBorder(new TitledBorder(getModel().getConfigModel().getCentralSourceLabel())); } - } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateModel.java index a5a8292..d25676f 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateModel.java @@ -22,22 +22,28 @@ package fr.ird.observe.application.swing.ui.admin.validate; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.application.swing.ui.admin.AdminActionModel; import fr.ird.observe.application.swing.ui.admin.AdminStep; +import fr.ird.observe.application.swing.ui.admin.AdminUIModel; import fr.ird.observe.application.swing.validation.ValidationModelMode; import fr.ird.observe.services.dto.AbstractReference; import fr.ird.observe.services.dto.IdDto; import fr.ird.observe.services.service.actions.validate.ValidateResultForDto; import fr.ird.observe.services.service.actions.validate.ValidateResultForDtoType; +import fr.ird.observe.services.service.actions.validate.ValidateService; import fr.ird.observe.services.service.actions.validate.ValidatorDto; import fr.ird.observe.services.service.actions.validate.ValidatorHelper; +import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.validator.NuitonValidatorScope; +import java.beans.PropertyChangeListener; import java.io.File; +import java.util.ArrayList; import java.util.Date; import java.util.EnumSet; import java.util.List; @@ -53,18 +59,11 @@ import java.util.TreeMap; */ public class ValidateModel extends AdminActionModel { - public static final String PROPERTY_ALL_CONTEXT_NAMES = "allContextNames"; - public static final String PROPERTY_CONTEXT_NAME = "contextName"; - public static final String PROPERTY_SCOPES = "scopes"; - public static final String PROPERTY_MODEL_MODE = "modelMode"; - public static final String PROPERTY_GENERATE_REPORT = "generateReport"; - public static final String PROPERTY_REPORT_FILE = "reportFile"; - public static final String PROPERTY_MESSAGES = "messages"; /** le pattern du fichier de rapport après validation */ @@ -95,7 +94,7 @@ public class ValidateModel extends AdminActionModel { protected Set<ValidatorDto> validators; /** le dictionnaire des paths d'entites detectees */ - protected Map<Class<? extends IdDto>, ValidateResultForDtoType> messages; + protected Map<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> messages; public ValidateModel() { super(AdminStep.VALIDATE); @@ -177,11 +176,11 @@ public class ValidateModel extends AdminActionModel { return validators; } - public Map<Class<? extends IdDto>, ValidateResultForDtoType> getMessages() { + public Map<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> getMessages() { return messages; } - public void setMessages(Map<Class<? extends IdDto>, ValidateResultForDtoType> messages) { + public void setMessages(Map<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> messages) { Object oldValue = this.messages; this.messages = messages; firePropertyChange(PROPERTY_MESSAGES, oldValue, messages); @@ -201,13 +200,13 @@ public class ValidateModel extends AdminActionModel { public List<AbstractReference> getMessagesDto(Class dtoType) { - List<AbstractReference> result = Lists.newArrayList(); + List<AbstractReference> result = new ArrayList<>(); if (messages != null) { - ValidateResultForDtoType resultForDtoType = messages.get(dtoType); + ValidateResultForDtoType<?> resultForDtoType = messages.get(dtoType); - ImmutableSet<ValidateResultForDto> validateResultForDto = resultForDtoType.getValidateResultForDto(); + ImmutableSet<? extends ValidateResultForDto<?>> validateResultForDto = resultForDtoType.getValidateResultForDto(); for (ValidateResultForDto resultForDto : validateResultForDto) { @@ -217,13 +216,14 @@ public class ValidateModel extends AdminActionModel { return result; } - public ValidateResultForDto getMessages(AbstractReference referenceDto) { + public <D extends IdDto> ValidateResultForDto<D> getMessages(AbstractReference<D> referenceDto) { - ValidateResultForDto result = null; + ValidateResultForDto<D> result = null; if (messages != null) { - ValidateResultForDtoType resultForDtoType = messages.get(referenceDto.getType()); + Class<D> type = referenceDto.getType(); + ValidateResultForDtoType<D> resultForDtoType = (ValidateResultForDtoType) messages.get(type); result = resultForDtoType.getValidateResult(referenceDto); @@ -255,7 +255,38 @@ public class ValidateModel extends AdminActionModel { } } - public ImmutableSet<ValidatorDto> getAllValidators() { - return allValidators; + public void start(AdminUIModel uiModel) { + + ObserveSwingApplicationConfig config = ObserveSwingApplicationContext.get().getConfig(); + + PropertyChangeListener listenValidationModified = evt -> { + ValidateModel source = (ValidateModel) evt.getSource(); + if (log.isDebugEnabled()) { + log.debug("validation model [" + source + "] changed on " + evt.getPropertyName() + ", new value = " + evt.getNewValue()); + } + uiModel.validate(); + if (log.isDebugEnabled()) { + log.debug("nb validators = " + source.getValidators().size() + ); + } + }; + + addPropertyChangeListener(listenValidationModified); + addScope(NuitonValidatorScope.ERROR); + setModelMode(ValidationModelMode.DATA); + setContextName(ValidateService.SERVICE_VALIDATION_CONTEXT); + setGenerateReport(true); + if (!config.getValidationReportDirectory().exists()) { + boolean b = config.getValidationReportDirectory().mkdirs(); + if (!b) { + throw new RuntimeException("Could not create directory " + config.getValidationReportDirectory()); + } + } + File reportFile = new File(config.getValidationReportDirectory(), getDefaultReportFilename()); + setReportFile(reportFile); + } + + public boolean validate(AdminUIModel uiModel) { + return uiModel.validate(AdminStep.SELECT_DATA) && uiModel.getStepState(step) == WizardState.SUCCESSED; } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUI.jaxx index c40b605..9b44fab 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUI.jaxx @@ -45,8 +45,6 @@ </import> - <ValidateUIHandler id='handler' constructorParams='this'/> - <ValidateModel id='stepModel' initializer='getModel().getValidateModel()'/> <DefaultListModel id='typeModel' genericType='Class<?>'/> @@ -56,35 +54,25 @@ <ValidationMessageTableModel id='messagesModel'/> <DefaultListSelectionModel id='typeSelectionModel' - onValueChanged='if (!event.getValueIsAdjusting() && !typeSelectionModel.isSelectionEmpty()) { getHandler().updateSelectedType(); }'/> + onValueChanged='if (!event.getValueIsAdjusting() && !typeSelectionModel.isSelectionEmpty()) { handler.updateSelectedType(); }'/> <DefaultListSelectionModel id='refSelectionModel' - onValueChanged='if (!event.getValueIsAdjusting() && !refSelectionModel.isSelectionEmpty()) { getHandler().updateSelectedRef(); }'/> + onValueChanged='if (!event.getValueIsAdjusting() && !refSelectionModel.isSelectionEmpty()) { handler.updateSelectedRef(); }'/> <script><![CDATA[ -public ValidateUI(AdminUI parentContext) { - super(AdminStep.VALIDATE, parentContext); -} - -@Override -public void initUI(AdminUI ui) { - getHandler().initTabUI(ui, this); -} @Override public void updateState(WizardState newState) { - getHandler().updateState(this, newState); + handler.updateState(this, newState); } ]]> </script> <JPanel id='PENDING_content'> - <Table constraints='BorderLayout.CENTER' fill='both' weightx='1' - weighty='1'> + <Table constraints='BorderLayout.CENTER' fill='both' weightx='1' weighty='1'> <row> <cell> - <JButton id='startButton' - onActionPerformed="getHandler().startAction()"/> + <JButton id='startButton' onActionPerformed="handler.startAction()"/> </cell> </row> </Table> @@ -98,10 +86,10 @@ public void updateState(WizardState newState) { <JXTitledPanel id='navigationView'> <JSplitPane id='splitpane2'> <JScrollPane> - <JList id='typeList'/> + <JList id='typeList' genericType="Class<?>"/> </JScrollPane> <JScrollPane> - <JList id='refList'/> + <JList id='refList' genericType='AbstractReference<?>'/> </JScrollPane> </JSplitPane> </JXTitledPanel> @@ -120,8 +108,7 @@ public void updateState(WizardState newState) { <JLabel id='resumeLabel' constraints='BorderLayout.CENTER'/> <JPanel constraints='BorderLayout.SOUTH' layout='{new BorderLayout()}'> - <JButton id='saveReport' constraints='BorderLayout.CENTER' - onActionPerformed='getHandler().saveReport()'/> + <JButton id='saveReport' constraints='BorderLayout.CENTER' onActionPerformed='handler.saveReport()'/> </JPanel> </JPanel> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUIHandler.java index 91857ce..1188435 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/admin/validate/ValidateUIHandler.java @@ -24,16 +24,13 @@ package fr.ird.observe.application.swing.ui.admin.validate; import com.google.common.base.Charsets; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.admin.AdminStep; -import fr.ird.observe.application.swing.ui.admin.AdminTabUI; import fr.ird.observe.application.swing.ui.admin.AdminTabUIHandler; -import fr.ird.observe.application.swing.ui.admin.AdminUI; import fr.ird.observe.application.swing.ui.admin.config.ConfigUI; import fr.ird.observe.application.swing.ui.admin.config.SelectDataUI; import fr.ird.observe.application.swing.ui.tree.selection.SelectionTreeModel; @@ -56,6 +53,7 @@ import fr.ird.observe.services.service.actions.validate.ValidationMessage; import fr.ird.observe.services.service.actions.validate.ValidatorDto; import jaxx.runtime.SwingUtil; import jaxx.runtime.context.JAXXInitialContext; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; @@ -73,6 +71,7 @@ import java.io.IOException; import java.util.Collections; import java.util.Date; import java.util.EnumSet; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -81,20 +80,15 @@ import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; -//import jaxx.runtime.validator.swing.SwingValidator; - /** * Le controleur des onglets. * * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class ValidateUIHandler extends AdminTabUIHandler { - -// public static final String[] EMPTY_STRING_ARRAY = new String[]{}; +public class ValidateUIHandler extends AdminTabUIHandler<ValidateUI> implements UIHandler<ValidateUI> { - public static final String LINE = - "--------------------------------------------------------------------------------"; + public static final String LINE = "--------------------------------------------------------------------------------"; /** Logger */ private static final Log log = LogFactory.getLog(ValidateUIHandler.class); @@ -105,19 +99,11 @@ public class ValidateUIHandler extends AdminTabUIHandler { protected Decorator<ProgramDto> dProgram; - public ValidateUIHandler(AdminTabUI ui) { - super(ui); - } - - public void initTabUI(AdminUI ui, ValidateUI tabUI) { - - super.initTabUI(ui, tabUI); - - if (log.isDebugEnabled()) { - log.debug(" specialized for [" + tabUI.getStep() + "] for main ui " + ui.getClass().getName() + "@" + System.identityHashCode(ui)); - } + @Override + public void afterInit(ValidateUI ui) { + super.afterInit(ui); - JTable messageTable = tabUI.getMessageTable(); + JTable messageTable = ui.getMessageTable(); messageTable.setDefaultRenderer(Object.class, new ObserveValidationMessageTableRenderer()); messageTable.getRowSorter().setSortKeys( @@ -132,24 +118,23 @@ public class ValidateUIHandler extends AdminTabUIHandler { n("observe.actions.validate.validator.message.header.tip")); SwingUtil.fixTableColumnWidth(messageTable, 0, 25); - ValidateEntityListCellRenderer listRenderer = - new ValidateEntityListCellRenderer(tabUI.getStepModel()); - tabUI.getTypeList().setCellRenderer(listRenderer); - tabUI.getRefList().setCellRenderer(listRenderer); + ValidateEntityListCellRenderer listRenderer = new ValidateEntityListCellRenderer(ui.getStepModel()); + ui.getTypeList().setCellRenderer(listRenderer); + ui.getRefList().setCellRenderer(listRenderer); - tabUI.getStartButton().setText(t("observe.actions.synchro.launch.operation", t(tabUI.getStep().getOperationLabel()))); + ui.getStartButton().setText(t("observe.actions.synchro.launch.operation", t(ui.getStep().getOperationLabel()))); // initialisation de l'ui de configuration if (log.isInfoEnabled()) { - log.info("Init extra configuration for " + tabUI.getName()); + log.info("Init extra configuration for " + ui.getName()); } - ConfigUI configUI = (ConfigUI) ui.getStepUI(AdminStep.CONFIG); + ConfigUI configUI = (ConfigUI) parentUI.getStepUI(AdminStep.CONFIG); JAXXInitialContext tx = new JAXXInitialContext().add(configUI).add(this); ValidateConfigUI extraConfig = new ValidateConfigUI(tx); configUI.getExtraConfig().add(extraConfig); - final SelectDataUI selectTabUI = (SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA); + final SelectDataUI selectTabUI = (SelectDataUI) parentUI.getStepUI(AdminStep.SELECT_DATA); getModel().getValidateModel().addPropertyChangeListener(ValidateModel.PROPERTY_MODEL_MODE, evt -> { ValidationModelMode value = (ValidationModelMode) evt.getNewValue(); @@ -324,7 +309,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { launchValidation(); - Map<Class<? extends IdDto>, ValidateResultForDtoType> messages = model.getValidateModel().getMessages(); + Map<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> messages = model.getValidateModel().getMessages(); if (messages == null || messages.isEmpty()) { // pas de validation ou bien pas d'erreurs rencontrées @@ -345,7 +330,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { // on recupere la source de données - source = model.getSafeLocalSource(false); + source = model.getConfigModel().getSafeLocalSource(false); DecoratorService decoratorService = getDecoratorService(); @@ -386,9 +371,9 @@ public class ValidateUIHandler extends AdminTabUIHandler { ValidateModel stepModel = model.getValidateModel(); stepModel.setMessages(null); - SelectionTreeModel dataModel = model.getSelectionDataModel(); + SelectionTreeModel dataModel = model.getSelectDataModel().getSelectionDataModel(); - ObserveSwingDataSource dataSourceToValidate = model.getLocalSource(); + ObserveSwingDataSource dataSourceToValidate = model.getConfigModel().getLocalSource(); if (!dataSourceToValidate.isOpen()) { dataSourceToValidate.open(); @@ -396,7 +381,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { ValidateService validateService = dataSourceToValidate.newValidateService(); - Map<Class<? extends IdDto>, ValidateResultForDtoType> messages = Maps.newHashMap(); + Map<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> messages = new HashMap<>(); if (dataModel.isLoadReferential()) { @@ -472,7 +457,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { builder.append(t("observe.actions.validate.report.scopes", validationModel.getScopes())).append('\n'); builder.append(t("observe.actions.validate.report.contextName", validationModel.getContextName())).append('\n'); - Map<Class<? extends IdDto>, ValidateResultForDtoType> messages = validationModel.getMessages(); + Map<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> messages = validationModel.getMessages(); builder.append(t("observe.actions.validate.report.entities.with.messages", messages.size())).append('\n'); builder.append(LINE).append('\n').append('\n'); @@ -531,7 +516,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { } } - public String updateValidatorResumeLabel(boolean valid) { + public String updateValidatorResumeLabel(@SuppressWarnings("unused") boolean valid) { ValidateModel validateModel = getModel().getValidateModel(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIInitializer.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIInitializer.java index 6d15481..4a3360d 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIInitializer.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIInitializer.java @@ -30,6 +30,7 @@ import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; import fr.ird.observe.application.swing.decoration.decorators.DataReferenceDecorator; import fr.ird.observe.application.swing.decoration.decorators.ReferentialReferenceDecorator; +import fr.ird.observe.application.swing.ui.MnemonicHelper; import fr.ird.observe.application.swing.ui.actions.shared.AbstractUIAction; import fr.ird.observe.application.swing.ui.util.BooleanEditor; import fr.ird.observe.application.swing.ui.util.tripMap.ObserveMapPane; @@ -43,7 +44,6 @@ import fr.ird.observe.services.dto.referential.ReferentialReference; import jaxx.runtime.JAXXValidator; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.JAXXWidgetUtil; -import jaxx.runtime.swing.OneClicListSelectionModel; import jaxx.runtime.swing.editor.EnumEditor; import jaxx.runtime.swing.editor.NumberEditor; import jaxx.runtime.swing.editor.bean.BeanComboBox; @@ -71,6 +71,7 @@ import org.nuiton.util.DateUtil; import javax.swing.AbstractAction; import javax.swing.AbstractButton; import javax.swing.Action; +import javax.swing.InputMap; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; @@ -79,7 +80,6 @@ import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JScrollBar; import javax.swing.JSpinner; -import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.KeyStroke; @@ -120,6 +120,8 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> public static final String OBSERVE_ACTION = "observeAction"; + public static final String GLOBAL_ACTION = "globalAction"; + public static final String CLIENT_PROPERTY_PROPERTY_NAME = "propertyName"; public static final String CLIENT_PROPERTY_RESET_PROPERTY_NAME = "resetPropertyName"; @@ -138,7 +140,7 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> this.decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); } - public static TableCellEditor newFloatColumnEditor(JTable table) { + public static TableCellEditor newFloatColumnEditor() { NumberCellEditor<Float> editor = JAXXWidgetUtil.newNumberTableCellEditor(Float.class, false); editor.getNumberEditor().setSelectAllTextOnError(true); @@ -148,7 +150,7 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> } - public static TableCellEditor newIntegerColumnEditor(JTable table) { + public static TableCellEditor newIntegerColumnEditor() { NumberCellEditor<Integer> editor = JAXXWidgetUtil.newNumberTableCellEditor(Integer.class, false); editor.getNumberEditor().setSelectAllTextOnError(true); @@ -168,8 +170,7 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> public static <B> ComboBoxCellEditor newDataColumnEditor(JComboBox<B> comboBox, List<B> data, Decorator<B> decorator) { - ListCellRenderer<B> renderer = new DecoratorListCellRenderer(decorator); - comboBox.setRenderer(renderer); + comboBox.setRenderer(new DecoratorListCellRenderer(decorator)); prepareComboBoxData(comboBox, data); @@ -202,13 +203,13 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> } ObserveActionMap actionMap = ObserveSwingApplicationContext.get().getActionMap(); - + InputMap inputMap = ObserveSwingApplicationContext.get().getMainUI().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); // initialisation des éditeurs Set<String> doNotBlockComponentIds = new HashSet<>(); ui.getActionMap().setParent(actionMap); - ui.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW ,ObserveSwingApplicationContext.get().getMainUI().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); + ui.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap); for (String name : ui.get$objectMap().keySet()) { Object o = ui.getObjectById(name); @@ -277,7 +278,7 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> } if (o instanceof EnumEditor) { - init((EnumEditor) o); + init((EnumEditor<?>) o); continue; } @@ -339,6 +340,14 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> action.initAction(ui, editor); + actionId = (String) editor.getClientProperty(GLOBAL_ACTION); + if (actionId != null) { + action = (AbstractUIAction) actionMap.get(actionId); + Objects.requireNonNull(action, "action [" + actionId + "] not found for ui " + ui.getClass().getName()); + KeyStroke acceleratorKey = action.getAcceleratorKey(); + MnemonicHelper.addKeyStroke(editor, acceleratorKey); + } + } protected void init(NumberEditor editor) { @@ -655,21 +664,6 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>> } /** - * Ajoute à une liste graphique donnée le comportement de - * sélection-déselection en un seul click. - * - * TODO: il faudrait que cela ne perturbe pas le comportement des raccourcis clavier. - * - * @param list la liste graphique à traiter - */ - protected void prepareToogleListSelectionModel(JList list) { - - OneClicListSelectionModel model = new OneClicListSelectionModel(list.getSelectionModel(), list.getModel()); - list.setSelectionModel(model); - - } - - /** * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. * diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIManager.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIManager.java index 4aab8bf..14cb25d 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIManager.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIManager.java @@ -26,6 +26,7 @@ import fr.ird.observe.application.swing.ObserveSwingSessionHelper; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; +import fr.ird.observe.services.dto.AbstractObserveDto; import jaxx.runtime.JAXXContext; import jaxx.runtime.context.JAXXInitialContext; import jaxx.runtime.swing.CardLayout2; @@ -190,6 +191,36 @@ public class ContentUIManager { return closed; } + public void restartEdit() { + + ContentUI<?, ?> selectedUI = getSelectedContentUI(); + if (selectedUI == null) { + + // pas d'écran selectionne + return; + } + ContentUIModel<? extends AbstractObserveDto> model = selectedUI.getModel(); + if (!model.isEditable()) { + + // modele non editable + return; + } + + ContentMode contentMode = model.getMode(); + if (ContentMode.UPDATE != contentMode) { + + // ecran non en mode mis a jour + return; + } + + if (log.isDebugEnabled()) { + log.debug("Will restart edit for " + selectedUI.getName()); + } + selectedUI.restartEdit(); + + } + + @Override protected void finalize() throws Throwable { super.finalize(); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ObserveFocusManager.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ObserveFocusManager.java index a0c6f4d..1f2a3b2 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ObserveFocusManager.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ObserveFocusManager.java @@ -447,7 +447,7 @@ public class ObserveFocusManager { case 0: return ui.getGear(); } - return super.getFirstComponent(aContainer); + return null; } @Override diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java index 39b1b29..cb795ab 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java @@ -101,7 +101,7 @@ public class LonglineDetailCompositionUIInitializer extends ContentUIInitializer UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); UIHelper.setTableColumnRenderer(table, 2, UIHelper.newDecorateTableCellRenderer(renderer, SectionTemplate.class)); - UIHelper.setTableColumnEditor(table, 1, newIntegerColumnEditor(table)); + UIHelper.setTableColumnEditor(table, 1, newIntegerColumnEditor()); DecoratorService decoratorService = ui.getHandler().getDecoratorService(); Decorator<SectionTemplate> sectionTemplateDecorator = decoratorService.getDecoratorByType(SectionTemplate.class); @@ -141,9 +141,9 @@ public class LonglineDetailCompositionUIInitializer extends ContentUIInitializer UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnEditor(table, 1, newIntegerColumnEditor(table)); - UIHelper.setTableColumnEditor(table, 2, newFloatColumnEditor(table)); - UIHelper.setTableColumnEditor(table, 3, newFloatColumnEditor(table)); + UIHelper.setTableColumnEditor(table, 1, newIntegerColumnEditor()); + UIHelper.setTableColumnEditor(table, 2, newFloatColumnEditor()); + UIHelper.setTableColumnEditor(table, 3, newFloatColumnEditor()); BasketsTableModel tableModel = model.getBasketsTableModel(); tableModel.installTableKeyListener(table); @@ -177,9 +177,9 @@ public class LonglineDetailCompositionUIInitializer extends ContentUIInitializer UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnEditor(table, 1, newIntegerColumnEditor(table)); - UIHelper.setTableColumnEditor(table, 2, newFloatColumnEditor(table)); - UIHelper.setTableColumnEditor(table, 3, newFloatColumnEditor(table)); + UIHelper.setTableColumnEditor(table, 1, newIntegerColumnEditor()); + UIHelper.setTableColumnEditor(table, 2, newFloatColumnEditor()); + UIHelper.setTableColumnEditor(table, 3, newFloatColumnEditor()); BranchlinesTableModel tableModel = model.getBranchlinesTableModel(); tableModel.installTableKeyListener(table); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/longline/ActivityLonglineUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/longline/ActivityLonglineUI.jcss index 78d3299..4797dac 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/longline/ActivityLonglineUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/impl/longline/ActivityLonglineUI.jcss @@ -74,21 +74,25 @@ } #reopen { + _globalAction:{"openCloseDataGlobal"}; _toolTipText:{t("observe.content.action.reopen.activity.tip")}; } #close { + _globalAction:{"openCloseDataGlobal"}; enabled:{!model.isModified() && (model.isHistoricalData() || model.isValid())}; _toolTipText:{t("observe.action.close.activity.tip")}; } #closeAndCreate { + _globalAction:{"newNextGlobal"}; enabled:{!model.isModified() && (model.isHistoricalData() || model.isValid())}; _text:{t("observe.content.action.closeAndCreate.activity")}; _toolTipText:{t("observe.content.action.closeAndCreate.activity.tip")}; } #delete { + _globalAction:{"deleteDataGlobal"}; _toolTipText:{t("observe.action.delete.activity.tip")}; } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/CatchLonglineUIHandler.java index 58ddda8..39ed50f 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -551,7 +551,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat Lists.newArrayList(getDataSource().getReferentialReferences(SizeMeasureTypeDto.class)); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(sizeMeasureTypes, decorator)); - UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); + UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor()); initInlineTable(ui.getSizeMeasuresScrollPane(), table, @@ -582,7 +582,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLonglineCat Lists.newArrayList(getDataSource().getReferentialReferences(WeightMeasureTypeDto.class)); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(weightMeasureTypes, decorator)); - UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); + UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor()); initInlineTable(ui.getWeightMeasuresScrollPane(), table, diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUI.jaxx index c97d7f0..dd1d78d 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUI.jaxx @@ -20,10 +20,8 @@ #L% --> -<JDialog id="storageMain" - implements='jaxx.runtime.swing.wizard.WizardUI<StorageStep, StorageUIModel>' - width='550' height='600' defaultCloseOperation='dispose_on_close' - > +<JDialog id="storageMain" implements='jaxx.runtime.swing.wizard.WizardUI<StorageStep, StorageUIModel>' + width='550' height='600' defaultCloseOperation='dispose_on_close'> <import> fr.ird.observe.application.swing.ui.UIHelper @@ -43,8 +41,6 @@ javax.swing.UIManager </import> - <StorageUIHandler id='handler' initializer='getContextValue(StorageUIHandler.class)'/> - <StorageUIModel id='model' javaBean='getContextValue(StorageUIModel.class)'/> <!-- le bloqueur d'ui lorsqu'une action est en cours ou annulée --> @@ -68,12 +64,6 @@ private boolean contextInitialized; public StorageUI(Window owner, JAXXContext parentContext) { super(owner); - // verification du context parent - UIHelper.checkJAXXContextEntry(parentContext, UIHelper.newContextEntryDef(StorageUIHandler.class)); - UIHelper.checkJAXXContextEntry(parentContext, UIHelper.newContextEntryDef(StorageUIModel.class)); - UIHelper.checkJAXXContextEntry(parentContext, UIHelper.newContextEntryDef("apply", Runnable.class)); - UIHelper.checkJAXXContextEntry(parentContext, UIHelper.newContextEntryDef("cancel", Runnable.class)); - if (owner != null) { setContextValue(owner, "parent"); } @@ -82,7 +72,7 @@ public StorageUI(Window owner, JAXXContext parentContext) { } public void destroy() { - getHandler().destroy(this); + handler.destroy(); } @Override @@ -102,7 +92,7 @@ protected void finalize() throws Throwable { @Override public void start() { - getHandler().start(this); + handler.start(); } @Override @@ -129,35 +119,28 @@ public StorageTabUI getStepUI(int stepIndex) { if (stepIndex > tabs.getTabCount()) { return null; } - return (StorageTabUI) tabs.getComponentAt(stepIndex); + return (StorageTabUI) tabs.getComponentAt(stepIndex); } @Override public StorageTabUI getSelectedStepUI() { StorageStep step = getSelectedStep(); - StorageTabUI ui = getStepUI(step); - return ui; + return getStepUI(step); } @Override public void onStepChanged(StorageStep oldStep, StorageStep newStep) { - getHandler().onStepChanged(this, oldStep, newStep); + handler.onStepChanged(oldStep, newStep); } @Override -public void onStepsChanged(StorageStep[] steps) { - -} +public void onStepsChanged(StorageStep[] steps) { } -void $afterCompleteSetup() { - getHandler().initUI(this); -} ]]> </script> <!-- les onglets --> - <JTabbedPane id='tabs' decorator='boxed' - constraints='BorderLayout.CENTER' + <JTabbedPane id='tabs' decorator='boxed' constraints='BorderLayout.CENTER' onStateChanged='if (getSelectedStep() != null) { getModel().gotoStep(getSelectedStep()); }'/> <!-- les actions --> @@ -165,23 +148,19 @@ void $afterCompleteSetup() { <row> <cell weightx='0.5' fill="both"> <!-- pour annuler --> - <JButton id="cancelAction" - onActionPerformed='getHandler().launchCancel(this)'/> + <JButton id="cancelAction" onActionPerformed='getHandler().launchCancel()'/> </cell> <cell weightx='0.5' fill="both"> <!-- pour aller sur l'onglet précédent --> - <JButton id="previousAction" - onActionPerformed='getModel().gotoPreviousStep()'/> + <JButton id="previousAction" onActionPerformed='getModel().gotoPreviousStep()'/> </cell> <cell weightx='0.5' fill="both"> <!-- pour aller sur l'onglet suivant --> - <JButton id="nextAction" - onActionPerformed='getModel().gotoNextStep()'/> + <JButton id="nextAction" onActionPerformed='getModel().gotoNextStep()'/> </cell> <cell weightx='0.5' fill="both"> <!-- pour apliquer la configuration --> - <JButton id="applyAction" - onActionPerformed='getHandler().launchApply(this)'/> + <JButton id="applyAction" onActionPerformed='getHandler().launchApply()'/> </cell> </row> </Table> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIHandler.java index 895cd31..daf3777 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUIHandler.java @@ -33,9 +33,8 @@ import fr.ird.observe.application.swing.configuration.constants.CreationMode; import fr.ird.observe.application.swing.configuration.constants.DbMode; import fr.ird.observe.application.swing.db.ObserveSwingDataSource; import fr.ird.observe.application.swing.db.constants.ConnexionStatus; -import fr.ird.observe.application.swing.db.event.ObserveSwingDataSourceEvent; -import fr.ird.observe.application.swing.db.event.ObserveSwingDataSourceListenerAdapter; import fr.ird.observe.application.swing.decoration.DecoratorService; +import fr.ird.observe.application.swing.ui.MnemonicHelper; import fr.ird.observe.application.swing.ui.ObserveMainUI; import fr.ird.observe.application.swing.ui.UIHelper; import fr.ird.observe.application.swing.ui.storage.tabs.RolesTableModel; @@ -52,7 +51,7 @@ import fr.ird.observe.services.dto.DataSourceCreateConfigurationDto; import fr.ird.observe.services.dto.ObserveDbUserDto; import fr.ird.observe.services.service.sql.AddSqlScriptProducerRequest; import fr.ird.observe.services.service.sql.SqlScriptProducerService; -import jaxx.runtime.context.DefaultApplicationContext.AutoLoad; +import jaxx.runtime.spi.UIHandler; import jaxx.runtime.swing.wizard.WizardUILancher; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; @@ -62,14 +61,11 @@ import javax.swing.AbstractAction; import javax.swing.ActionMap; import javax.swing.InputMap; import javax.swing.JComponent; -import javax.swing.JRadioButton; import javax.swing.JTabbedPane; -import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import java.awt.Component; import java.awt.Window; import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -87,138 +83,14 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.0 */ -@AutoLoad -public class StorageUIHandler { +public class StorageUIHandler implements UIHandler<StorageUI> { /** Logger */ private static final Log log = LogFactory.getLog(StorageUIHandler.class); - /** - * Prépare une service de persistance à partir d'un modèle. - * - * Le service ne sera pas ouvert. - * - * @param model le modèle de la source de données - * @return le service de persistance initialisé mais non ouvert. - */ - public ObserveSwingDataSource newDataSourceFromModel( - StorageUIModel model) { - - ObserveSwingDataSource dataSource = null; - ObserveDataSourceConfiguration configuration; - switch (model.getDbMode()) { - case CREATE_LOCAL: - case USE_LOCAL: - configuration = model.toH2StorageConfig(t("observe.storage.label.local")); - - dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(configuration); - - dataSource.addObserveSwingDataSourceListener( - new ObserveSwingDataSourceListenerAdapter() { - - @Override - public void onOpened(ObserveSwingDataSourceEvent event) { - ObserveSwingApplicationContext context = ObserveSwingApplicationContext.get(); - // la base locale existe desormais - context.getConfig().setLocalStorageExist(true); - } - }); - - break; - case USE_REMOTE: - configuration = model.toPGStorageConfig(t("observe.storage.label.remote")); - dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(configuration); - break; - case USE_SERVER: - configuration = model.toRestStorageConfig(t("observe.storage.label.server")); - dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(configuration); - break; - } - - return dataSource; - } - - public void initUI(StorageUI ui) { - - InputMap inputMap = ui.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); - ActionMap actionMap = ui.getRootPane().getActionMap(); - - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); - actionMap.put("cancel", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - ui.doActionPerformed__on__cancelAction(e); - } - }); - StorageUIModel model = ui.getModel(); + private StorageUI ui; - // on écoute les changements d'étapes - model.addPropertyChangeListener(StorageUIModel.STEP_PROPERTY_NAME, evt -> { - StorageUIModel model1 = (StorageUIModel) evt.getSource(); - StorageStep oldStep = (StorageStep) evt.getOldValue(); - StorageStep newStep = (StorageStep) evt.getNewValue(); - if (log.isDebugEnabled()) { - log.debug("step has changed <old:" + oldStep + ", new:" + newStep + ">"); - } - int oldStepIndex = oldStep == null ? -1 : model1.getStepIndex(oldStep); - int newStepIndex = model1.getStepIndex(newStep); - JTabbedPane tabs = ui.getTabs(); - if (oldStepIndex + 1 == newStepIndex) { - - // creation d'un nouvel onglet - StorageTabUI c = (StorageTabUI) ui.getObjectById(newStep.name()); - String title = I18nEnumHelper.getLabel(newStep); - String tip = I18nEnumHelper.getDescription(newStep); - - if (log.isDebugEnabled()) { - log.debug("Create tab " + title + " ui = " + c); - } - tabs.addTab(title, null, c, tip); - tabs.setMnemonicAt(newStepIndex, title.charAt(0)); - - // selection du nouvel onglet - int index = tabs.indexOfComponent(c); - if (index > -1) { - tabs.setSelectedIndex(index); - } - ui.onStepChanged(oldStep, newStep); - - } else if (oldStepIndex > newStepIndex) { - - // il s'agit d'un retour en arrière - // on supprime tous les onglets obsoletes - int index = newStepIndex + 1; - while (tabs.getTabCount() > index) { - if (log.isDebugEnabled()) { - log.debug("remove tab : " + index); - } - tabs.remove(index); - } - - ui.onStepChanged(oldStep, newStep); - } else { - throw new IllegalStateException("can not go from " + oldStep + " to " + newStep); - } - }); - - // initialisation des onglets - ui.CHOOSE_DB_MODE.init(); - ui.CONFIG.init(); - ui.CONFIG_REFERENTIEL.init(); - ui.CONFIG_DATA.init(); - ui.BACKUP.init(); - ui.SELECT_DATA.init(); - ui.ROLES.init(); - ui.CONFIRM.init(); - - // recuperation de la source de données en cours d'utilisation - ObserveDataSourceConfiguration dataSourceConfiguration = ui.getContextValue(ObserveDataSourceConfiguration.class); - - // chargement du modèle - model.init(ui, dataSourceConfiguration); - } - - public void start(StorageUI ui) { + public void start() { // on demarre le modele pour le type de base connu ui.getModel().start(ui.getModel().getDbMode()); @@ -229,7 +101,7 @@ public class StorageUIHandler { UIHelper.center(ui.getContextValue(Window.class, "parent"), ui); SwingUtilities.invokeLater(() -> { - JComponent focusOwner = getFocusComponent(ui, ui.getModel().getStep()); + JComponent focusOwner = getFocusComponent(ui.getModel().getStep()); if (focusOwner != null) { focusOwner.grabFocus(); } @@ -239,7 +111,7 @@ public class StorageUIHandler { ui.setVisible(true); } - public JComponent getFocusComponent(StorageUI ui, StorageStep newStep) { + public JComponent getFocusComponent(StorageStep newStep) { DbMode dbMode = ui.getModel().getDbMode(); JComponent focusOwner; @@ -324,7 +196,7 @@ public class StorageUIHandler { return focusOwner; } - public void onStepChanged(StorageUI ui, StorageStep oldStep, StorageStep newStep) { + public void onStepChanged(StorageStep oldStep, StorageStep newStep) { if (newStep == null) { return; } @@ -347,14 +219,6 @@ public class StorageUIHandler { } - if (StorageStep.CHOOSE_DB_MODE == newStep) { - JRadioButton focusOwner = ui.getCHOOSE_DB_MODE().getUseLocalMode(); - if (!focusOwner.isEnabled() || ui.getCHOOSE_DB_MODE().getUseRemoteMode().isSelected()) { - focusOwner = ui.getCHOOSE_DB_MODE().getUseRemoteMode(); - } - focusOwner.requestFocusInWindow(); - } - if (StorageStep.CONFIG_REFERENTIEL == newStep && mustRecompute) { // mise à jour de l'univers des étapes (ajout/suppression étape confg_data et select_data possible) @@ -385,19 +249,19 @@ public class StorageUIHandler { if (StorageStep.CONFIRM == newStep) { // generation du rapport - String text = computeReport(ui, oldStep); + String text = computeReport(oldStep); ui.CONFIRM.getResume().setText(text); } - JComponent focusComponent = getFocusComponent(ui, newStep); + JComponent focusComponent = getFocusComponent(newStep); if (focusComponent != null) { focusComponent.requestFocusInWindow(); } } - public void launchApply(final StorageUI ui) { + public void launchApply() { ui.getModel().setAlreadyApplied(true); @@ -427,7 +291,7 @@ public class StorageUIHandler { } } - public void launchCancel(StorageUI ui) { + public void launchCancel() { Runnable action = WizardUILancher.CANCEL_DEF.getContextValue(ui); @@ -504,7 +368,6 @@ public class StorageUIHandler { if (log.isErrorEnabled()) { log.error(t("observe.error.storage.could.not.load.local.db", e.getMessage()), e); } -// UIHelper.handlingError(t("observe.error.storage.could.not.load.local.db", e.getMessage()), e); // on conserve l'état localDbIsSane = false; @@ -589,8 +452,6 @@ public class StorageUIHandler { localDataSource.close(); } -// localDataSource = null; - if (log.isDebugEnabled()) { log.debug("Will create new storage..."); } @@ -599,7 +460,7 @@ public class StorageUIHandler { try { - currentDataSource = newDataSourceFromModel(model); + currentDataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSourceFromModel(model); // si on utilise la base local on lance une migration de la base si necessaire if (DbMode.USE_LOCAL.equals((model.getDbMode()))) { @@ -691,9 +552,10 @@ public class StorageUIHandler { * @param model le model de la source de données */ public void storeRemoteConfig(StorageUIModel model) { + ObserveSwingApplicationConfig config = ObserveSwingApplicationContext.get().getConfig(); - // on sauvegarde dans le parametrage dans la configuration de - // l'application + + // on sauvegarde dans le parametrage dans la configuration de l'application if (model.isEditRemoteConfig()) { @@ -748,17 +610,7 @@ public class StorageUIHandler { } } - public String computeReport(StorageUI ui, StorageStep step) { - if (log.isDebugEnabled()) { - log.debug("Build report from step " + step); - } - StorageUIModel model = ui.getModel(); - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - ObserveTextGenerator textGenerator = applicationContext.getTextGenerator(); - return textGenerator.getDataSourceConnectionReport(model); - } - - public void destroy(StorageUI ui) { + public void destroy() { ui.getModel().destroy(); if (log.isDebugEnabled()) { log.debug("destroy ui " + ui.getName()); @@ -774,8 +626,100 @@ public class StorageUIHandler { UIHelper.destroy(ui); } - protected DecoratorService getDecoratorService() { - return ObserveSwingApplicationContext.get().getDecoratorService(); + @Override + public void beforeInit(StorageUI ui) { + this.ui = ui; + + // verification du context parent + UIHelper.checkJAXXContextEntry(ui, UIHelper.newContextEntryDef(StorageUIModel.class)); + UIHelper.checkJAXXContextEntry(ui, UIHelper.newContextEntryDef("apply", Runnable.class)); + UIHelper.checkJAXXContextEntry(ui, UIHelper.newContextEntryDef("cancel", Runnable.class)); + + } + + @Override + public void afterInit(StorageUI storageUI) { + + InputMap inputMap = ui.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); + ActionMap actionMap = ui.getRootPane().getActionMap(); + + inputMap.put(MnemonicHelper.KEY_STROKE_ESCAPE, "cancel"); + actionMap.put("cancel", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + ui.doActionPerformed__on__cancelAction(e); + } + }); + MnemonicHelper.addKeyStroke(ui.getCancelAction(), MnemonicHelper.KEY_STROKE_ESCAPE); + + MnemonicHelper.addKeyStrokeFromMnemonic(ui); + + StorageUIModel model = ui.getModel(); + + // on écoute les changements d'étapes + model.addPropertyChangeListener(StorageUIModel.STEP_PROPERTY_NAME, evt -> { + StorageUIModel model1 = (StorageUIModel) evt.getSource(); + StorageStep oldStep = (StorageStep) evt.getOldValue(); + StorageStep newStep = (StorageStep) evt.getNewValue(); + if (log.isDebugEnabled()) { + log.debug("step has changed <old:" + oldStep + ", new:" + newStep + ">"); + } + int oldStepIndex = oldStep == null ? -1 : model1.getStepIndex(oldStep); + int newStepIndex = model1.getStepIndex(newStep); + JTabbedPane tabs = ui.getTabs(); + if (oldStepIndex + 1 == newStepIndex) { + + // creation d'un nouvel onglet + StorageTabUI c = (StorageTabUI) ui.getObjectById(newStep.name()); + String title = I18nEnumHelper.getLabel(newStep); + String tip = I18nEnumHelper.getDescription(newStep); + + if (log.isDebugEnabled()) { + log.debug("Create tab " + title + " ui = " + c); + } + tabs.addTab(title, null, c, tip); + tabs.setMnemonicAt(newStepIndex, title.charAt(0)); + + // selection du nouvel onglet + int index = tabs.indexOfComponent(c); + if (index > -1) { + tabs.setSelectedIndex(index); + } + ui.onStepChanged(oldStep, newStep); + + } else if (oldStepIndex > newStepIndex) { + + // il s'agit d'un retour en arrière + // on supprime tous les onglets obsoletes + int index = newStepIndex + 1; + while (tabs.getTabCount() > index) { + if (log.isDebugEnabled()) { + log.debug("remove tab : " + index); + } + tabs.remove(index); + } + + ui.onStepChanged(oldStep, newStep); + } else { + throw new IllegalStateException("can not go from " + oldStep + " to " + newStep); + } + }); + +// // initialisation des onglets +// ui.CHOOSE_DB_MODE.init(); +// ui.CONFIG.init(); +// ui.CONFIG_REFERENTIEL.init(); +// ui.CONFIG_DATA.init(); +// ui.BACKUP.init(); +// ui.SELECT_DATA.init(); +// ui.ROLES.init(); +// ui.CONFIRM.init(); + + // recuperation de la source de données en cours d'utilisation + ObserveDataSourceConfiguration dataSourceConfiguration = ui.getContextValue(ObserveDataSourceConfiguration.class); + + // chargement du modèle + model.init(ui, dataSourceConfiguration); } protected void initSelectData(StorageUI ui) { @@ -822,21 +766,16 @@ public class StorageUIHandler { if (selectAll) { treeModel.selectAllTrips(); - SwingUtilities.invokeLater(() -> selectDataUI.getSelectTree().expandAll()); + SwingUtilities.invokeLater(selectDataUI.getSelectTree()::expandAll); } // positionnement du model de selection de données dans le model du wizard model.setSelectDataModel(treeModel); - if (selectAll) { - treeModel.selectAllTrips(); - SwingUtilities.invokeLater(() -> selectDataUI.getSelectTree().expandAll()); - } - if (selectDataUI.getSelectTree().getRowCount() > 0) { selectDataUI.getSelectTree().setSelectionRow(0); } - SwingUtilities.invokeLater(selectDataUI.getSelectTree()::grabFocus); + SwingUtilities.invokeLater(selectDataUI.getSelectTree()::requestFocusInWindow); } finally { if (closeSource) { @@ -860,13 +799,12 @@ public class StorageUIHandler { switch (model.getDbMode()) { case USE_REMOTE: ObserveDataSourceConfigurationTopiaPG pgConfig = model.getPgConfig(); - dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(pgConfig); break; case USE_SERVER: ObserveDataSourceConfigurationRest restConfig = model.getRestConfig(); dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(restConfig); - + break; } if (dataSource != null) { @@ -892,4 +830,18 @@ public class StorageUIHandler { } + protected String computeReport(StorageStep step) { + if (log.isDebugEnabled()) { + log.debug("Build report from step " + step); + } + StorageUIModel model = ui.getModel(); + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + ObserveTextGenerator textGenerator = applicationContext.getTextGenerator(); + return textGenerator.getDataSourceConnectionReport(model); + } + + protected DecoratorService getDecoratorService() { + return ObserveSwingApplicationContext.get().getDecoratorService(); + } + } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUILauncher.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUILauncher.java index 948ceb0..bb3f4e0 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUILauncher.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/StorageUILauncher.java @@ -24,7 +24,6 @@ package fr.ird.observe.application.swing.ui.storage; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.configuration.ObserveSwingApplicationConfig; import fr.ird.observe.application.swing.configuration.constants.DbMode; -import fr.ird.observe.application.swing.ui.ObserveMainUIHandler; import fr.ird.observe.application.swing.ui.UIHelper; import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; @@ -55,17 +54,12 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod protected final String title; - public StorageUILauncher(JAXXContext context, - Window frame, - StorageUIModel model, - String title) { + public StorageUILauncher(JAXXContext context, Window frame, StorageUIModel model, String title) { super(context, frame, StorageUI.class, StorageUIModel.class, model); this.title = title; } - public StorageUILauncher(JAXXContext context, - Window frame, - String title) { + public StorageUILauncher(JAXXContext context, Window frame, String title) { super(context, frame, StorageUI.class, StorageUIModel.class); this.title = title; } @@ -99,7 +93,7 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod } ui.getModel().setBusy(true); super.doCancel(ui); - ObserveMainUIHandler.restartEdit(); + ObserveSwingApplicationContext.get().getContentUIManager().restartEdit(); } @Override @@ -180,7 +174,7 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod @Override protected void doAction(StorageUI ui) { super.doAction(ui); - getStorageUIHandler().doChangeStorage(ui.getModel()); + ui.getHandler().doChangeStorage(ui.getModel()); } }.start(); @@ -237,11 +231,10 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod */ public static void obtainConnexion(JAXXContext context, Window mainUI, StorageUIModel model, String title, DbMode dbMode) { - if (mainUI == null) { mainUI = ObserveSwingApplicationContext.get().getMainUI(); } - addStorageUIHandler(context); +// addStorageUIHandler(context); StorageUILauncher launcher = new StorageUILauncher(context, mainUI, model, title) { @Override @@ -307,7 +300,6 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod if (mainUI == null) { mainUI = ObserveSwingApplicationContext.get().getMainUI(); } - addStorageUIHandler(context); StorageUILauncher launcher = new StorageUILauncher(context, mainUI, model, t("observe.title.connect.existingDB")) { @Override @@ -362,23 +354,6 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod launcher.start(); } - protected static void addStorageUIHandler(JAXXContext context) { - StorageUIHandler handler = context.getContextValue(StorageUIHandler.class); - if (handler == null) { - - handler = new StorageUIHandler(); - context.setContextValue(handler); - - if (log.isWarnEnabled()) { - log.warn("Register in context an storage handler : " + handler); - } - } else { - if (log.isWarnEnabled()) { - log.warn("Use existing handler " + handler); - } - } - } - public String getTitle() { return title; } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/BackupUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/BackupUI.jaxx index 909cf37..70909b3 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/BackupUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/BackupUI.jaxx @@ -35,15 +35,6 @@ <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='model'/> - <script><![CDATA[ - -@Override -public void init() { - getHandler().initUI(this); -} -]]> - </script> - <JPanel id='content'> <Table fill='both' constraints='BorderLayout.CENTER'> <row> @@ -61,11 +52,11 @@ public void init() { </cell> <cell weightx='1' fill="horizontal"> <JTextField id='directoryText' - onKeyReleased='getHandler().changeDirectory(this, new File(((JTextField)event.getSource()).getText()))'/> + onKeyReleased='getHandler().changeDirectory(new File(((JTextField)event.getSource()).getText()))'/> </cell> <cell anchor="east"> <JButton id="chooseFileAction" - onActionPerformed="getHandler().chooseBackupFile(this)"/> + onActionPerformed="getHandler().chooseBackupFile()"/> </cell> </row> <row> @@ -74,7 +65,7 @@ public void init() { </cell> <cell weightx='1' fill="horizontal" columns="2"> <JTextField id='filenameText' - onKeyReleased='getHandler().changeFilename(this, ((JTextField) event.getSource()).getText())'/> + onKeyReleased='getHandler().changeFilename(((JTextField) event.getSource()).getText())'/> </cell> </row> </Table> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/BackupUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/BackupUIHandler.java new file mode 100644 index 0000000..016bfc1 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/BackupUIHandler.java @@ -0,0 +1,74 @@ +package fr.ird.observe.application.swing.ui.storage.tabs; + +import fr.ird.observe.application.swing.ui.MnemonicHelper; +import fr.ird.observe.application.swing.ui.UIHelper; +import fr.ird.observe.application.swing.ui.storage.StorageStep; +import jaxx.runtime.spi.UIHandler; + +import javax.swing.AbstractAction; +import java.awt.event.ActionEvent; +import java.io.File; + +import static javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW; +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since X + */ +public class BackupUIHandler extends StorageTabUIHandler<BackupUI> implements UIHandler<BackupUI> { + + public static final String ACTION_DO_BACKUP = "doBackup"; + public static final String ACTION_DO_CHOOSE_DIRECTORY = "doChooseDirectory"; + + @Override + public void afterInit(BackupUI ui) { + if (ui.getStep() != null) { + ui.setDescriptionText(t(ui.getStep().getDescription())); + + ui.getActionMap().put(ACTION_DO_BACKUP, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (StorageStep.BACKUP == ui.getModel().getStep()) { + ui.getDoBackup().doClick(); + } + } + }); + ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(MnemonicHelper.KEY_STROKE_STORAGE_DO_BACKUP, ACTION_DO_BACKUP); + MnemonicHelper.addKeyStroke(ui.getDoBackup(), MnemonicHelper.KEY_STROKE_STORAGE_DO_BACKUP); + + ui.getActionMap().put(ACTION_DO_CHOOSE_DIRECTORY, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (StorageStep.BACKUP == ui.getModel().getStep()) { + ui.getChooseFileAction().doClick(); + } + } + }); + ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(MnemonicHelper.KEY_STROKE_STORAGE_DO_CHOOSE_DIRECTORY, ACTION_DO_CHOOSE_DIRECTORY); + MnemonicHelper.addKeyStroke(ui.getChooseFileAction(), MnemonicHelper.KEY_STROKE_STORAGE_DO_CHOOSE_DIRECTORY); + } + } + + + public void chooseBackupFile() { + File f = UIHelper.chooseDirectory(ui, + t("observe.title.choose.db.dump.directory"), + t("observe.action.choose.db.dump.directory"), + new File(ui.getDirectoryText().getText())); + if (f != null) { + changeDirectory(f); + } + } + + public void changeDirectory(File f) { + ui.getModel().setBackupFile(new File(f, ui.getFilenameText().getText())); + } + + public void changeFilename(String filename) { + ui.getModel().setBackupFile(new File(ui.getDirectoryText().getText(), filename)); + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jaxx index 180bf8c..96d8a69 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jaxx @@ -43,16 +43,12 @@ <ButtonGroup id='dbMode' onStateChanged='getModel().setDbMode((DbMode) dbMode.getSelectedValue())'/> - <ButtonGroup id='creationMode' onStateChanged='getModel().setCreationMode((CreationMode) creationMode.getSelectedValue())'/> + <ButtonGroup id='creationMode' + onStateChanged='getModel().setCreationMode((CreationMode) creationMode.getSelectedValue())'/> <CardLayout2Ext id='creationModeLayout' constructorParams='this, "creationModeContent"'/> <script><![CDATA[ -@Override -public void init() { - getHandler().initUI(this); -} - protected String updateMigrationPolicy(boolean canMigrate) { if (canMigrate) { return t("observe.storage.report.can.migrate", config.getModelVersion()); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jcss index 6909e3c..de5aeca 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUI.jcss @@ -85,7 +85,7 @@ #importInternalDumpMode { value:{CreationMode.IMPORT_INTERNAL_DUMP}; text:{getHandler().updateInternalDumpModeLabel(config.isInitialDumpExist())}; - visible:{getHandler().updateCreationModeLayout(ChooseDbModeUI.this, config.isInitialDumpExist(), importInternalDumpMode)}; + visible:{getHandler().updateCreationModeLayout(config.isInitialDumpExist(), importInternalDumpMode)}; selected:{model.getCreationMode() == CreationMode.IMPORT_INTERNAL_DUMP}; } @@ -98,7 +98,7 @@ /** non utilisé dans cette version d'ObServe */ #importLocalStorageMode { - visible:{getHandler().updateCreationModeLayout(ChooseDbModeUI.this, false, importLocalStorageMode)}; + visible:{getHandler().updateCreationModeLayout(false, importLocalStorageMode)}; value:{CreationMode.IMPORT_LOCAL_STORAGE}; text:{I18nEnumHelper.getLabel(CreationMode.IMPORT_LOCAL_STORAGE)}; selected:{model.getCreationMode() == CreationMode.IMPORT_LOCAL_STORAGE}; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUIHandler.java new file mode 100644 index 0000000..9fbfeeb --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ChooseDbModeUIHandler.java @@ -0,0 +1,77 @@ +package fr.ird.observe.application.swing.ui.storage.tabs; + +import fr.ird.observe.application.swing.I18nEnumHelper; +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ObserveTextGenerator; +import fr.ird.observe.application.swing.configuration.constants.CreationMode; +import fr.ird.observe.application.swing.ui.storage.StorageStep; +import fr.ird.observe.application.swing.ui.storage.StorageUIModel; +import jaxx.runtime.spi.UIHandler; + +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import java.awt.Component; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.util.Date; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since X + */ +public class ChooseDbModeUIHandler extends StorageTabUIHandler<ChooseDbModeUI> implements UIHandler<ChooseDbModeUI> { + + @Override + public void afterInit(ChooseDbModeUI ui) { + PropertyChangeListener listener = evt -> { + StorageUIModel model = (StorageUIModel) evt.getSource(); + + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + ObserveTextGenerator textGenerator = applicationContext.getTextGenerator(); + String txt = textGenerator.getLoadDataSourceResume(model); + ui.getResume().setText(txt); + }; + StorageUIModel model = ui.getModel(); + model.addPropertyChangeListener(StorageUIModel.DB_MODE_PROPERTY_NAME, listener); + model.addPropertyChangeListener(StorageUIModel.CREATION_MODE_PROPERTY_NAME, listener); + ui.setDescriptionText(t(StorageStep.CHOOSE_DB_MODE.getDescription())); + } + + protected String updateInternalDumpModeLabel(@SuppressWarnings("unused") boolean dumpExist) { + File f = ObserveSwingApplicationContext.get().getConfig().getInitialDbDump(); + String text; + if (f.exists()) { + text = t("observe.storage.internalDump.last.modified", new Date(f.lastModified())); + } else { + text = t("observe.storage.internalDump.not.exist"); + } + return I18nEnumHelper.getLabel(CreationMode.IMPORT_INTERNAL_DUMP) + text; + } + + public boolean updateCreationModeLayout(boolean visible, JRadioButton button) { + JPanel panel = ui.getUseCreateMode(); + if (visible) { + for (Component c : panel.getComponents()) { + if (button.equals(c)) { + // button already in + return true; + } + } + + panel.add(button); + } else { + for (Component c : panel.getComponents()) { + if (button.equals(c)) { + // button still in + panel.remove(c); + return false; + } + } + } + return visible; + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigDataUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigDataUI.jaxx index b593340..c3b50ce 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigDataUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigDataUI.jaxx @@ -37,21 +37,14 @@ <StorageStep id='step' initializer='StorageStep.CONFIG_DATA'/> <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='model'/> - <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='centralSourceModel' initializer='model.getDataSourceModel()'/> + <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='centralSourceModel' + initializer='model.getDataSourceModel()'/> <ButtonGroup id='creationMode' onStateChanged='model.setDataImportMode((CreationMode) creationMode.getSelectedValue())'/> <CardLayout id='configLayout'/> - <script><![CDATA[ -@Override -public void init() { - getHandler().initUI(this); -} -]]> - </script> - <JPanel id='content' layout='{new BorderLayout()}'> <Table id="dataSourceConfig" insets="1" weightx='1' fill='both' @@ -92,19 +85,17 @@ public void init() { onKeyReleased='centralSourceModel.setDumpFile(new File(((JTextField)event.getSource()).getText())); model.validate();'/> </cell> <cell anchor="east"> - <JButton id="fileChooserAction" - onActionPerformed="getHandler().chooseDumpFile(this)"/> + <JButton id="fileChooserAction" onActionPerformed="handler.chooseDumpFile()"/> </cell> </row> </Table> <!-- importer les données a partir d'une base distante --> - <Table id='IMPORT_REMOTE_STORAGE' fill="both" - constraints='"IMPORT_REMOTE_STORAGE"'> + <Table id='IMPORT_REMOTE_STORAGE' fill="both" constraints='"IMPORT_REMOTE_STORAGE"'> <row> <cell> <JLabel - text='observe.storage.importRemoteStorageData.config'/> + text='observe.storage.importRemoteStorageData.config'/> </cell> </row> <row> @@ -112,8 +103,7 @@ public void init() { <JLabel id='centralSourceLabel'/> </cell> <cell> - <JButton id='configureCentralSource' - onActionPerformed='getHandler().obtainRemoteConnexion(this)'/> + <JButton id='configureCentralSource' onActionPerformed='handler.obtainRemoteConnexion()'/> </cell> <cell anchor='east'> <JLabel id='centralSourceStatus'/> @@ -132,8 +122,7 @@ public void init() { </Table> <!-- importer les données a partir d'une base distante --> - <Table id='IMPORT_SERVER_STORAGE' fill="both" - constraints='"IMPORT_SERVER_STORAGE"'> + <Table id='IMPORT_SERVER_STORAGE' fill="both" constraints='"IMPORT_SERVER_STORAGE"'> <row> <cell> <JLabel @@ -146,7 +135,7 @@ public void init() { </cell> <cell> <JButton id='configureCentralSourceServer' - onActionPerformed='getHandler().obtainServerConnexion(this)'/> + onActionPerformed='handler.obtainServerConnexion()'/> </cell> <cell anchor='east'> <JLabel id='centralSourceServerStatus'/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigDataUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigDataUIHandler.java new file mode 100644 index 0000000..290c43b --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigDataUIHandler.java @@ -0,0 +1,92 @@ +package fr.ird.observe.application.swing.ui.storage.tabs; + +import fr.ird.observe.application.swing.configuration.constants.CreationMode; +import fr.ird.observe.application.swing.ui.UIHelper; +import fr.ird.observe.application.swing.ui.storage.StorageStep; +import fr.ird.observe.application.swing.ui.storage.StorageUILauncher; +import fr.ird.observe.application.swing.ui.storage.StorageUIModel; +import jaxx.runtime.spi.UIHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JComponent; +import java.awt.Window; +import java.beans.PropertyChangeListener; +import java.io.File; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since X + */ +public class ConfigDataUIHandler extends StorageTabUIHandler<ConfigDataUI> implements UIHandler<ConfigDataUI> { + + /** Logger */ + private static final Log log = LogFactory.getLog(ConfigDataUIHandler.class); + + @Override + public void afterInit(ConfigDataUI ui) { + if (ui.getStep() != null) { + ui.setDescriptionText(t(ui.getStep().getDescription())); + + PropertyChangeListener listener = evt -> { + String propertyName = evt.getPropertyName(); + if (StorageUIModel.DATA_IMPORT_MODE_PROPERTY_NAME.equals(propertyName)) { + CreationMode id = (CreationMode) evt.getNewValue(); + + if (id != null) { + refreshConfig(id.name()); + + } + + } + }; + ui.getModel().addPropertyChangeListener(listener); + ui.getModel().setDataImportMode(CreationMode.EMPTY); + } + } + + public void refreshConfig(String configId) { + JComponent c = (JComponent) ui.getObjectById(configId); + if (c != null) { + if (log.isDebugEnabled()) { + log.debug(configId); + } + ui.configLayout.show(ui.configContent, configId); + } + } + + public void chooseDumpFile() { + File f = UIHelper.chooseFile(ui, + t("observe.title.choose.db.dump"), + t("observe.action.choose.db.dump"), + ui.getModel().getDumpFile(), + "^.+\\.sql\\.gz$", + t("observe.action.choose.db.dump.description")); + ui.getCentralSourceModel().setDumpFile(f); + ui.getModel().validate(); + } + + public void obtainRemoteConnexion() { + StorageUIModel sourceModel = ui.getCentralSourceModel(); + StorageUILauncher.obtainRemoteConnexion(ui.getDelegateContext(), ui.getParentContainer(Window.class), sourceModel); + + sourceModel.validate(StorageStep.CONFIG); + + ui.getModel().validate(); + } + + + public void obtainServerConnexion() { + StorageUIModel sourceModel = ui.getCentralSourceModel(); + StorageUILauncher.obtainServerConnexion(ui.getDelegateContext(), ui.getParentContainer(Window.class), sourceModel); + + sourceModel.validate(StorageStep.CONFIG); + + ui.getModel().validate(); + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigReferentielUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigReferentielUI.jaxx index 7a63d6e..4360e0e 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigReferentielUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigReferentielUI.jaxx @@ -41,21 +41,13 @@ <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='model'/> <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='centralSourceModel' - initializer='model.getCentralSourceModel()'/> + initializer='model.getCentralSourceModel()'/> <ButtonGroup id='creationMode' onStateChanged='model.setReferentielImportMode((CreationMode) creationMode.getSelectedValue())'/> <CardLayout id='configLayout'/> - <script><![CDATA[ -@Override -public void init() { - getHandler().initUI(this); -} -]]> - </script> - <JPanel id='content' layout='{new BorderLayout()}'> <Table id="referentielSourceConfig" insets="1" weightx='1' fill='both' @@ -64,12 +56,9 @@ public void init() { <cell anchor='north'> <JPanel id='referentielModeConfig'> <JRadioButton id="noImportReferentiel" styleClass='creationMode'/> - <JRadioButton id="importReferentielFromBackup" - styleClass='creationMode'/> - <JRadioButton id="importReferentielFromRemote" - styleClass='creationMode'/> - <JRadioButton id="importReferentielFromServer" - styleClass='creationMode'/> + <JRadioButton id="importReferentielFromBackup" styleClass='creationMode'/> + <JRadioButton id="importReferentielFromRemote" styleClass='creationMode'/> + <JRadioButton id="importReferentielFromServer" styleClass='creationMode'/> </JPanel> </cell> </row> @@ -87,12 +76,10 @@ public void init() { </Table> <!-- importer le référentiel a partir d'une sauvegarde --> - <Table id='IMPORT_EXTERNAL_DUMP' - constraints='"IMPORT_EXTERNAL_DUMP"'> + <Table id='IMPORT_EXTERNAL_DUMP' constraints='"IMPORT_EXTERNAL_DUMP"'> <row> <cell> - <JLabel - text='observe.storage.importExternalDumpReferentiel.config'/> + <JLabel text='observe.storage.importExternalDumpReferentiel.config'/> </cell> </row> <row weighty='1'> @@ -101,19 +88,17 @@ public void init() { onKeyReleased='centralSourceModel.setDumpFile(new File(((JTextField)event.getSource()).getText())); model.validate();'/> </cell> <cell anchor="east"> - <JButton id="fileChooserAction" - onActionPerformed="getHandler().chooseDumpFile(this)"/> + <JButton id="fileChooserAction" onActionPerformed="handler.chooseDumpFile()"/> </cell> </row> </Table> <!-- importer le référentiel a partir d'une base distante --> - <Table id='IMPORT_REMOTE_STORAGE' fill="both" - constraints='"IMPORT_REMOTE_STORAGE"'> + <Table id='IMPORT_REMOTE_STORAGE' fill="both" constraints='"IMPORT_REMOTE_STORAGE"'> <row> <cell> <JLabel - text='observe.storage.importRemoteStorageReferentiel.config'/> + text='observe.storage.importRemoteStorageReferentiel.config'/> </cell> </row> <row> @@ -121,8 +106,7 @@ public void init() { <JLabel id='centralSourceLabel'/> </cell> <cell> - <JButton id='configureCentralSource' - onActionPerformed='getHandler().obtainRemoteConnexion(this)'/> + <JButton id='configureCentralSource' onActionPerformed='handler.obtainRemoteConnexion()'/> </cell> <cell anchor='east'> <JLabel id='centralSourceStatus'/> @@ -141,12 +125,10 @@ public void init() { </Table> <!-- importer le référentiel a partir d'un serveur distant --> - <Table id='IMPORT_SERVER_STORAGE' fill="both" - constraints='"IMPORT_SERVER_STORAGE"'> + <Table id='IMPORT_SERVER_STORAGE' fill="both" constraints='"IMPORT_SERVER_STORAGE"'> <row> <cell> - <JLabel - text='observe.storage.importServerStorageReferentiel.config'/> + <JLabel text='observe.storage.importServerStorageReferentiel.config'/> </cell> </row> <row> @@ -154,8 +136,7 @@ public void init() { <JLabel id='centralSourceServerLabel'/> </cell> <cell> - <JButton id='configureCentralSourceServer' - onActionPerformed='getHandler().obtainServerConnexion(this)'/> + <JButton id='configureCentralSourceServer' onActionPerformed='handler.obtainServerConnexion()'/> </cell> <cell anchor='east'> <JLabel id='centralSourceServerStatus'/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigReferentielUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigReferentielUIHandler.java new file mode 100644 index 0000000..11b3ebb --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigReferentielUIHandler.java @@ -0,0 +1,117 @@ +package fr.ird.observe.application.swing.ui.storage.tabs; + +import fr.ird.observe.application.swing.configuration.constants.CreationMode; +import fr.ird.observe.application.swing.ui.MnemonicHelper; +import fr.ird.observe.application.swing.ui.UIHelper; +import fr.ird.observe.application.swing.ui.storage.StorageStep; +import fr.ird.observe.application.swing.ui.storage.StorageUILauncher; +import fr.ird.observe.application.swing.ui.storage.StorageUIModel; +import jaxx.runtime.spi.UIHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.AbstractAction; +import javax.swing.JComponent; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.beans.PropertyChangeListener; +import java.io.File; + +import static javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW; +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since X + */ +public class ConfigReferentielUIHandler extends StorageTabUIHandler<ConfigReferentielUI> implements UIHandler<ConfigReferentielUI> { + + /** Logger */ + private static final Log log = LogFactory.getLog(ConfigReferentielUIHandler.class); + + public static final String ACTION_DO_CONFIGURE_REMOTE_SOURCE = "doConfigureRemoteSource"; + public static final String ACTION_DO_CONFIGURE_REMOTE_SERVER = "doConfigureRemoteServer"; + + @Override + public void afterInit(ConfigReferentielUI ui) { + + if (ui.getStep() != null) { + ui.setDescriptionText(t(ui.getStep().getDescription())); + + PropertyChangeListener listener = evt -> { + String propertyName = evt.getPropertyName(); + if (StorageUIModel.REFERENTIEL_IMPORT_MODE_PROPERTY_NAME.equals(propertyName)) { + CreationMode id = (CreationMode) evt.getNewValue(); + refreshConfig(id.name()); + } + }; + ui.getModel().addPropertyChangeListener(listener); + ui.getModel().setReferentielImportMode(CreationMode.IMPORT_EXTERNAL_DUMP); + + ui.getActionMap().put(ACTION_DO_CONFIGURE_REMOTE_SOURCE, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (StorageStep.CONFIG_REFERENTIEL == ui.getModel().getStep()) { + ui.getConfigureCentralSource().doClick(); + } + } + }); + ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(MnemonicHelper.KEY_STROKE_STORAGE_DO_CHOOSE_DIRECTORY, ACTION_DO_CONFIGURE_REMOTE_SOURCE); + MnemonicHelper.addKeyStroke(ui.getConfigureCentralSource(), MnemonicHelper.KEY_STROKE_STORAGE_DO_CHOOSE_DIRECTORY); + + ui.getActionMap().put(ACTION_DO_CONFIGURE_REMOTE_SERVER, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (StorageStep.CONFIG_REFERENTIEL == ui.getModel().getStep()) { + ui.getConfigureCentralSourceServer().doClick(); + } + } + }); + ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(MnemonicHelper.KEY_STROKE_STORAGE_DO_CONFIGURE_REMOTE_SERVER, ACTION_DO_CONFIGURE_REMOTE_SERVER); + MnemonicHelper.addKeyStroke(ui.getConfigureCentralSourceServer(), MnemonicHelper.KEY_STROKE_STORAGE_DO_CONFIGURE_REMOTE_SERVER); + } + } + + public void refreshConfig(String configId) { + JComponent c = (JComponent) ui.getObjectById(configId); + if (c != null) { + if (log.isDebugEnabled()) { + log.debug(configId); + } + ui.configLayout.show(ui.configContent, configId); + } + } + + public void chooseDumpFile() { + File f = UIHelper.chooseFile(ui, + t("observe.title.choose.db.dump"), + t("observe.action.choose.db.dump"), + ui.getModel().getDumpFile(), + "^.+\\.sql\\.gz$", + t("observe.action.choose.db.dump.description")); + ui.getCentralSourceModel().setDumpFile(f); + ui.getModel().validate(); + } + + public void obtainRemoteConnexion() { + StorageUIModel sourceModel = ui.getCentralSourceModel(); + StorageUILauncher.obtainRemoteConnexion(ui.getDelegateContext(), ui.getParentContainer(Window.class), sourceModel); + + sourceModel.validate(StorageStep.CONFIG); + + ui.getModel().validate(); + } + + public void obtainServerConnexion() { + StorageUIModel sourceModel = ui.getCentralSourceModel(); + StorageUILauncher.obtainServerConnexion(ui.getDelegateContext(), ui.getParentContainer(Window.class), sourceModel); + + sourceModel.validate(StorageStep.CONFIG); + + ui.getModel().validate(); + } + + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUI.jaxx index 39f9735..e66ce8d 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUI.jaxx @@ -48,14 +48,6 @@ <CardLayout id='configLayout'/> - <script><![CDATA[ -@Override -public void init() { - getHandler().initUI(this); -} -]]> - </script> - <JPanel id='content' layout='{new BorderLayout()}'> <Table fill='both' weightx='1' constraints='BorderLayout.CENTER'> <row> @@ -75,7 +67,7 @@ public void init() { onKeyReleased='getModel().setDumpFile(new File(((JTextField)event.getSource()).getText()))'/> </cell> <cell anchor="east"> - <JButton id="fileChooserAction" onActionPerformed="getHandler().chooseDumpFile(this)"/> + <JButton id="fileChooserAction" onActionPerformed="handler.chooseDumpFile()"/> </cell> </row> </Table> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUI.jcss b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUI.jcss index d08fa62..f69a574 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUI.jcss +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUI.jcss @@ -29,7 +29,7 @@ } #dumpFile { - text:{model.getDumpFile()+""}; + text:{model.getDumpFile() + ""}; } #fileChooserAction { @@ -99,21 +99,6 @@ selected:{model.isUseSsl()}; } -/*#remoteSslCertificatFile { - text:{model.getSslCertificatFile()+""}; - enabled:{model.isUseSsl()}; -} - -#remoteSslCertificatFileChooseaction { - actionIcon:"fileChooser"; - enabled:{model.isUseSsl()}; -} - -#remoteSslCertificatPassword { - enabled:{model.isUseSsl()}; - text:{model.getSslCertificatPassword()==null ? "" : new String(model.getSslCertificatPassword())}; -}*/ - #testRemoteAction { text:"observe.action.test.remote"; toolTipText:"observe.action.test.remote.tip"; @@ -123,14 +108,13 @@ } #connexionStatusPanel { - /*minimumSize:{new Dimension(10,80)};*/ columnHeaderView:{connexionStatusLabel}; - border:{new LineBorder(getHandler().updateConnexionStatutColor(ConfigUI.this, model.getConnexionStatus()),2)}; + border:{new LineBorder(handler.updateConnexionStatutColor(model.getConnexionStatus()),2)}; } #connexionStatusLabel { text:{I18nEnumHelper.getLabel(model.getConnexionStatus())}; - icon:{getHandler().updateConnexionStatutIcon(ConfigUI.this, model.getConnexionStatus())}; + icon:{handler.updateConnexionStatutIcon(model.getConnexionStatus())}; } #connexionStatus { @@ -139,7 +123,7 @@ font-size:11; contentType : "text/html"; editorKit : {new HTMLEditorKit()}; - text:{getHandler().updateConnexionStatutText(ConfigUI.this, model.getConnexionStatus())}; + text:{handler.updateConnexionStatutText(model.getConnexionStatus())}; _untestedColor:{Color.GRAY}; _successColor:{Color.GREEN}; _failedColor:{Color.RED}; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUIHandler.java new file mode 100644 index 0000000..9205202 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfigUIHandler.java @@ -0,0 +1,149 @@ +package fr.ird.observe.application.swing.ui.storage.tabs; + +import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.ObserveTextGenerator; +import fr.ird.observe.application.swing.configuration.constants.DbMode; +import fr.ird.observe.application.swing.db.constants.ConnexionStatus; +import fr.ird.observe.application.swing.ui.MnemonicHelper; +import fr.ird.observe.application.swing.ui.UIHelper; +import fr.ird.observe.application.swing.ui.storage.StorageStep; +import fr.ird.observe.application.swing.ui.storage.StorageUIModel; +import jaxx.runtime.spi.UIHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.AbstractAction; +import javax.swing.Icon; +import javax.swing.JComponent; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.beans.PropertyChangeListener; +import java.io.File; + +import static javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW; +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since X + */ +public class ConfigUIHandler extends StorageTabUIHandler<ConfigUI> implements UIHandler<ConfigUI> { + + /** Logger */ + private static final Log log = LogFactory.getLog(ConfigUIHandler.class); + + public static final String ACTION_DO_CHOOSE_FILE = "doChooseFile"; + public static final String ACTION_DO_USE_SSL = "doUseSsl"; + public static final String ACTION_DO_KEEP_CONFIGURATION = "doKeepConfiguration"; + + @Override + public void afterInit(ConfigUI ui) { + +// MnemonicHelper.addKeyStrokeFromMnemonic(ui); + PropertyChangeListener listener = evt -> { + StorageUIModel model = (StorageUIModel) evt.getSource(); + String propertyName = evt.getPropertyName(); + if (StorageUIModel.CREATION_MODE_PROPERTY_NAME.equals(propertyName) || + StorageUIModel.DB_MODE_PROPERTY_NAME.equals(propertyName)) { + String id = null; + if (model.getDbMode() == DbMode.USE_REMOTE) { + id = DbMode.USE_REMOTE.name(); + } else if (model.getDbMode() == DbMode.USE_SERVER) { + id = DbMode.USE_SERVER.name(); + } else { + if (model.getCreationMode() != null) { + id = model.getCreationMode().name(); + } + } + if (id != null) { + refreshConfig(ui, id); + } + } + }; + ui.getModel().addPropertyChangeListener(listener); + + ui.getActionMap().put(ACTION_DO_CHOOSE_FILE, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (StorageStep.CONFIG == ui.getModel().getStep()) { + ui.getFileChooserAction().doClick(); + } + } + }); + ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(MnemonicHelper.KEY_STROKE_STORAGE_DO_CHOOSE_FILE, ACTION_DO_CHOOSE_FILE); + MnemonicHelper.addKeyStroke(ui.getFileChooserAction(), MnemonicHelper.KEY_STROKE_STORAGE_DO_CHOOSE_FILE); + + ui.getActionMap().put(ACTION_DO_USE_SSL, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (StorageStep.CONFIG == ui.getModel().getStep()) { + ui.getRemoteUseSsl().doClick(); + } + } + }); + ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(MnemonicHelper.KEY_STROKE_STORAGE_DO_USE_SSL, ACTION_DO_USE_SSL); + MnemonicHelper.addKeyStroke(ui.getRemoteUseSsl(), MnemonicHelper.KEY_STROKE_STORAGE_DO_USE_SSL); + + ui.getActionMap().put(ACTION_DO_KEEP_CONFIGURATION, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (StorageStep.CONFIG == ui.getModel().getStep()) { + ui.getStoreRemoteConfig().doClick(); + } + } + }); + ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(MnemonicHelper.KEY_STROKE_STORAGE_KEEP_CONFIGURATION, ACTION_DO_KEEP_CONFIGURATION); + MnemonicHelper.addKeyStroke(ui.getStoreRemoteConfig(), MnemonicHelper.KEY_STROKE_STORAGE_KEEP_CONFIGURATION); + } + + public void refreshConfig(ConfigUI ui, String configId) { + JComponent c = (JComponent) ui.getObjectById(configId); + if (c != null) { + if (log.isDebugEnabled()) { + log.debug(configId); + } + ui.configLayout.show(ui.configContent, configId); + String text = (String) c.getClientProperty("description"); + ui.setDescriptionText(t(text)); + if (c.equals(ui.IMPORT_REMOTE_STORAGE)) { + ui.IMPORT_REMOTE_STORAGE_content.add(ui.remoteConfig, BorderLayout.CENTER); + } else if (c.equals(ui.IMPORT_SERVER_STORAGE)) { + ui.IMPORT_SERVER_STORAGE_content.add(ui.remoteConfig, BorderLayout.CENTER); + } else if (c.equals(ui.USE_REMOTE)) { + ui.USE_REMOTE_content.add(ui.remoteConfig, BorderLayout.CENTER); + } else if (c.equals(ui.USE_SERVER)) { + ui.USE_SERVER_content.add(ui.remoteConfig, BorderLayout.CENTER); + } + } + } + + + public Icon updateConnexionStatutIcon(ConnexionStatus status) { + return (Icon) ui.getConnexionStatus().getClientProperty(status.name().toLowerCase() + "Icon"); + } + + public Color updateConnexionStatutColor(ConnexionStatus status) { + return (Color) ui.getConnexionStatus().getClientProperty(status.name().toLowerCase() + "Color"); + } + + public String updateConnexionStatutText(@SuppressWarnings("unused") ConnexionStatus status) { + ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); + ObserveTextGenerator textGenerator = applicationContext.getTextGenerator(); + return textGenerator.getConnexionTestResultMessage(ui.getModel()); + } + + public void chooseDumpFile() { + File f = UIHelper.chooseFile(ui, + t("observe.title.choose.db.dump"), + t("observe.action.choose.db.dump"), + ui.getModel().getDumpFile(), + "^.+\\.sql\\.gz$", + t("observe.action.choose.db.dump.description")); + ui.getModel().setDumpFile(f); + } + + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfirmUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfirmUI.jaxx index 5a849af..eef41bf 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfirmUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfirmUI.jaxx @@ -32,16 +32,6 @@ <StorageStep id='step' initializer='StorageStep.CONFIRM'/> - <fr.ird.observe.application.swing.ui.storage.StorageUIModel id='model'/> - - <script><![CDATA[ -@Override -public void init() { - getHandler().initUI(this); -} -]]> - </script> - <JPanel id='content'> <JScrollPane id="resumePane" constraints='BorderLayout.CENTER'> <JTextPane id='resume'/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfirmUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfirmUIHandler.java new file mode 100644 index 0000000..867e4c6 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/ConfirmUIHandler.java @@ -0,0 +1,21 @@ +package fr.ird.observe.application.swing.ui.storage.tabs; + +import jaxx.runtime.spi.UIHandler; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since X + */ +public class ConfirmUIHandler extends StorageTabUIHandler<ConfirmUI> implements UIHandler<ConfirmUI> { + + @Override + public void afterInit(ConfirmUI ui) { + if (ui.getStep() != null) { + ui.setDescriptionText(t(ui.getStep().getDescription())); + } + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesTableModel.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesTableModel.java index 8aeb544..1f2d56a 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesTableModel.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesTableModel.java @@ -138,7 +138,7 @@ public class RolesTableModel extends AbstractTableModel { default: throw new IllegalStateException( "can not get value for row " + rowIndex + - ", col " + columnIndex); + ", col " + columnIndex); } } return value; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesUI.jaxx index 199223d..c45a678 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesUI.jaxx @@ -36,19 +36,13 @@ <StorageUIModel id='model'/> - <SecurityModel id='securityModel' - initializer='model.getSecurityModel()'/> + <SecurityModel id='securityModel' initializer='model.getSecurityModel()'/> <!-- les roles récupérés depuis la base distante --> <RolesTableModel id='rolesModel'/> <script><![CDATA[ -@Override -public void init() { - getHandler().initUI(this); -} - public String updateAdministrateur(String role) { return t("observe.storage.security.administrateur", role); } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesUIHandler.java new file mode 100644 index 0000000..7123fc4 --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/RolesUIHandler.java @@ -0,0 +1,74 @@ +package fr.ird.observe.application.swing.ui.storage.tabs; + +import fr.ird.observe.application.swing.ui.UIHelper; +import jaxx.runtime.spi.UIHandler; +import jaxx.runtime.swing.editor.MyDefaultCellEditor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since X + */ +public class RolesUIHandler extends StorageTabUIHandler<RolesUI> implements UIHandler<RolesUI> { + + /** Logger */ + private static final Log log = LogFactory.getLog(RolesUIHandler.class); + + @Override + public void afterInit(RolesUI ui) { + if (ui.getStep() != null) { + ui.setDescriptionText(t(ui.getStep().getDescription())); + } + ui.getSecurityModel().addPropertyChangeListener(evt -> { + if (log.isDebugEnabled()) { + log.debug("Security model changed [" + evt.getPropertyName() + "] <" + evt.getOldValue() + " : " + evt.getNewValue() + ">"); + } + ui.getModel().validate(); + }); + + JTable table = ui.getRoles(); + table.setRowHeight(24); + + UIHelper.fixTableColumnWidth(table, 1, 100); + UIHelper.fixTableColumnWidth(table, 2, 100); + UIHelper.fixTableColumnWidth(table, 3, 100); + UIHelper.fixTableColumnWidth(table, 4, 100); + + DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); + + UIHelper.setI18nTableHeaderRenderer( + table, + RolesTableModel.COLUMN_NAMES[0], + RolesTableModel.COLUMN_NAME_TIPS[0], + RolesTableModel.COLUMN_NAMES[1], + RolesTableModel.COLUMN_NAME_TIPS[1], + RolesTableModel.COLUMN_NAMES[2], + RolesTableModel.COLUMN_NAME_TIPS[2], + RolesTableModel.COLUMN_NAMES[3], + RolesTableModel.COLUMN_NAME_TIPS[3], + RolesTableModel.COLUMN_NAMES[4], + RolesTableModel.COLUMN_NAME_TIPS[4] + ); + + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newStringTableCellRenderer(renderer, 50, true)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newBooleanTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 2, UIHelper.newBooleanTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 3, UIHelper.newBooleanTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 4, UIHelper.newBooleanTableCellRenderer(renderer)); + + UIHelper.setTableColumnEditor(table, 1, MyDefaultCellEditor.newBooleanEditor()); + UIHelper.setTableColumnEditor(table, 2, MyDefaultCellEditor.newBooleanEditor()); + UIHelper.setTableColumnEditor(table, 3, MyDefaultCellEditor.newBooleanEditor()); + UIHelper.setTableColumnEditor(table, 4, MyDefaultCellEditor.newBooleanEditor()); + + } + +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jaxx index d1b9882..44d97c6 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUI.jaxx @@ -35,16 +35,6 @@ <StorageStep id='step' initializer='StorageStep.SELECT_DATA'/> - <StorageUIModel id='model'/> - - <script><![CDATA[ -@Override -public void init() { - getHandler().initUI(this); -} -]]> - </script> - <JPanel id='content'> <JScrollPane id='selectedTreePane' constraints='BorderLayout.CENTER' columnHeaderView='{selectTreeHeader}'> <SelectionTree id='selectTree'/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUIHandler.java new file mode 100644 index 0000000..55972ab --- /dev/null +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/SelectDataUIHandler.java @@ -0,0 +1,22 @@ +package fr.ird.observe.application.swing.ui.storage.tabs; + +import jaxx.runtime.spi.UIHandler; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 27/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since X + */ +public class SelectDataUIHandler extends StorageTabUIHandler<SelectDataUI> implements UIHandler<SelectDataUI> { + + @Override + public void afterInit(SelectDataUI ui) { + if (ui.getStep() != null) { + ui.setDescriptionText(t(ui.getStep().getDescription())); + } + ui.getSelectTree().installUI(); + } +} diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUI.jaxx index fd9af88..2762099 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUI.jaxx @@ -24,8 +24,7 @@ <!-- La base des contenu d'onglet --> <!-- **************************** --> -<JPanel id="tabPanel" - abstract='true' +<JPanel id="tabPanel" abstract='true' implements='jaxx.runtime.swing.wizard.WizardStepUI<StorageStep, StorageUIModel>'> <import> @@ -43,17 +42,12 @@ static org.nuiton.i18n.I18n.n </import> - <StorageTabUIHandler id='handler'/> - - <StorageUIModel id='model' - initializer='getContextValue(StorageUIModel.class)'/> + <StorageUIModel id='model' initializer='getContextValue(StorageUIModel.class)'/> <script><![CDATA[ public abstract StorageStep getStep(); -public abstract void init(); - public void destroy() { description.setText(""); UIHelper.destroy(this); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUIHandler.java index 32dde07..477bcdd 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/StorageTabUIHandler.java @@ -21,43 +21,14 @@ */ package fr.ird.observe.application.swing.ui.storage.tabs; -import fr.ird.observe.application.swing.I18nEnumHelper; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; import fr.ird.observe.application.swing.ObserveTextGenerator; -import fr.ird.observe.application.swing.configuration.constants.CreationMode; -import fr.ird.observe.application.swing.configuration.constants.DbMode; -import fr.ird.observe.application.swing.db.constants.ConnexionStatus; -import fr.ird.observe.application.swing.ui.UIHelper; -import fr.ird.observe.application.swing.ui.storage.StorageStep; -import fr.ird.observe.application.swing.ui.storage.StorageUILauncher; import fr.ird.observe.application.swing.ui.storage.StorageUIModel; import fr.ird.observe.services.configuration.ObserveDataSourceInformation; -import jaxx.runtime.swing.editor.MyDefaultCellEditor; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import jaxx.runtime.JAXXObject; -import javax.swing.AbstractAction; -import javax.swing.AbstractButton; -import javax.swing.Icon; -import javax.swing.JComponent; import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JTable; -import javax.swing.KeyStroke; -import javax.swing.table.DefaultTableCellRenderer; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Window; -import java.awt.event.ActionEvent; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.Date; -import static javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW; import static org.nuiton.i18n.I18n.t; /** @@ -66,447 +37,9 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 1.4 */ -public class StorageTabUIHandler { +public class StorageTabUIHandler<U extends JAXXObject> { - private static final Log log = LogFactory.getLog(StorageTabUIHandler.class); - public static final String ACTION_DO_CHOOSE_FILE = "doChooseFile"; - public static final String ACTION_DO_USE_SSL = "doUseSsl"; - public static final String ACTION_DO_KEEP_CONFIGURATION = "doKeepConfiguration"; - public static final String ACTION_DO_CONFIGURE_REMOTE_SOURCE = "doConfigureRemoteSource"; - public static final String ACTION_DO_CONFIGURE_REMOTE_SERVER = "doConfigureRemoteServer"; - public static final String ACTION_DO_BACKUP = "doBackup"; - public static final String ACTION_DO_CHOOSE_DIRECTORY = "doChooseDirectory"; - public static final KeyStroke KEY_STROKE_DO_CONFIGURE_REMOTE_SERVER = KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK); - public static final KeyStroke KEY_STROKE_DO_BACKUP = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK); - public static final KeyStroke KEY_STROKE_DO_CHOOSE_DIRECTORY = KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK); - public static final KeyStroke KEY_STROKE_KEEP_CONFIGURATION = KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_MASK); - public static final KeyStroke KEY_STROKE_DO_USE_SSL = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK); - public static final KeyStroke KEY_STROKE_DO_CHOOSE_FILE = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK); - - public boolean updateCreationModeLayout(ChooseDbModeUI ui, boolean visible, JRadioButton button) { - JPanel panel = ui.getUseCreateMode(); - if (visible) { - for (Component c : panel.getComponents()) { - if (button.equals(c)) { - // button already in - return true; - } - } - - panel.add(button); - } else { - for (Component c : panel.getComponents()) { - if (button.equals(c)) { - // button still in - panel.remove(c); - return false; - } - } - } - return visible; - } - - public void initUI(final ChooseDbModeUI ui) { - - PropertyChangeListener listener = evt -> { - StorageUIModel model = (StorageUIModel) evt.getSource(); - - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - ObserveTextGenerator textGenerator = applicationContext.getTextGenerator(); - String txt = textGenerator.getLoadDataSourceResume(model); - ui.getResume().setText(txt); - }; - StorageUIModel model = ui.getModel(); - model.addPropertyChangeListener(StorageUIModel.DB_MODE_PROPERTY_NAME, listener); - model.addPropertyChangeListener(StorageUIModel.CREATION_MODE_PROPERTY_NAME, listener); - ui.setDescriptionText(t(ui.getStep().getDescription())); - } - - public void initUI(ConfigUI ui) { - - PropertyChangeListener listener = evt -> { - StorageUIModel model = (StorageUIModel) evt.getSource(); - String propertyName = evt.getPropertyName(); - if (StorageUIModel.CREATION_MODE_PROPERTY_NAME.equals(propertyName) || - StorageUIModel.DB_MODE_PROPERTY_NAME.equals(propertyName)) { - String id = null; - if (model.getDbMode() == DbMode.USE_REMOTE) { - id = DbMode.USE_REMOTE.name(); - } else if (model.getDbMode() == DbMode.USE_SERVER) { - id = DbMode.USE_SERVER.name(); - } else { - if (model.getCreationMode() != null) { - id = model.getCreationMode().name(); - } - } - if (id != null) { - refreshConfig(ui, id); - } - } - }; - ui.getModel().addPropertyChangeListener(listener); - - ui.getActionMap().put(ACTION_DO_CHOOSE_FILE, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (StorageStep.CONFIG == ui.getModel().getStep()) { - ui.getFileChooserAction().doClick(); - } - } - }); - ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KEY_STROKE_DO_CHOOSE_FILE, ACTION_DO_CHOOSE_FILE); - addKeyStroke(ui.getFileChooserAction(), KEY_STROKE_DO_CHOOSE_FILE); - - ui.getActionMap().put(ACTION_DO_USE_SSL, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (StorageStep.CONFIG == ui.getModel().getStep()) { - ui.getRemoteUseSsl().doClick(); - } - } - }); - ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KEY_STROKE_DO_USE_SSL, ACTION_DO_USE_SSL); - addKeyStroke(ui.getRemoteUseSsl(), KEY_STROKE_DO_USE_SSL); - - ui.getActionMap().put(ACTION_DO_KEEP_CONFIGURATION, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (StorageStep.CONFIG == ui.getModel().getStep()) { - ui.getStoreRemoteConfig().doClick(); - } - } - }); - ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KEY_STROKE_KEEP_CONFIGURATION, ACTION_DO_KEEP_CONFIGURATION); - addKeyStroke(ui.getStoreRemoteConfig(), KEY_STROKE_KEEP_CONFIGURATION); - } - - public void initUI(ConfigReferentielUI ui) { - if (ui.getStep() != null) { - ui.setDescriptionText(t(ui.getStep().getDescription())); - - PropertyChangeListener listener = evt -> { - String propertyName = evt.getPropertyName(); - if (StorageUIModel.REFERENTIEL_IMPORT_MODE_PROPERTY_NAME.equals(propertyName)) { - CreationMode id = (CreationMode) evt.getNewValue(); - refreshConfig(ui, id.name()); - } - }; - ui.getModel().addPropertyChangeListener(listener); - ui.getModel().setReferentielImportMode(CreationMode.IMPORT_EXTERNAL_DUMP); - - ui.getActionMap().put(ACTION_DO_CONFIGURE_REMOTE_SOURCE, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (StorageStep.CONFIG_REFERENTIEL == ui.getModel().getStep()) { - ui.getConfigureCentralSource().doClick(); - } - } - }); - ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KEY_STROKE_DO_CHOOSE_DIRECTORY, ACTION_DO_CONFIGURE_REMOTE_SOURCE); - addKeyStroke(ui.getConfigureCentralSource(), KEY_STROKE_DO_CHOOSE_DIRECTORY); - - ui.getActionMap().put(ACTION_DO_CONFIGURE_REMOTE_SERVER, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (StorageStep.CONFIG_REFERENTIEL == ui.getModel().getStep()) { - ui.getConfigureCentralSourceServer().doClick(); - } - } - }); - ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KEY_STROKE_DO_CONFIGURE_REMOTE_SERVER, ACTION_DO_CONFIGURE_REMOTE_SERVER); - addKeyStroke(ui.getConfigureCentralSourceServer(), KEY_STROKE_DO_CONFIGURE_REMOTE_SERVER); - } - } - - public void initUI(ConfigDataUI ui) { - if (ui.getStep() != null) { - ui.setDescriptionText(t(ui.getStep().getDescription())); - - PropertyChangeListener listener = evt -> { - String propertyName = evt.getPropertyName(); - if (StorageUIModel.DATA_IMPORT_MODE_PROPERTY_NAME.equals(propertyName)) { - CreationMode id = (CreationMode) evt.getNewValue(); - - if (id != null) { - refreshConfig(ui, id.name()); - - } - - } - }; - ui.getModel().addPropertyChangeListener(listener); - ui.getModel().setDataImportMode(CreationMode.EMPTY); - } - } - - public void initUI(RolesUI ui) { - if (ui.getStep() != null) { - ui.setDescriptionText(t(ui.getStep().getDescription())); - } - - ui.getSecurityModel().addPropertyChangeListener(evt -> { - if (log.isDebugEnabled()) { - log.debug("Security model changed [" + evt.getPropertyName() + "] <" + evt.getOldValue() + " : " + evt.getNewValue() + ">"); - } - ui.getModel().validate(); - }); - - JTable table = ui.getRoles(); - table.setRowHeight(24); - - UIHelper.fixTableColumnWidth(table, 1, 100); - UIHelper.fixTableColumnWidth(table, 2, 100); - UIHelper.fixTableColumnWidth(table, 3, 100); - UIHelper.fixTableColumnWidth(table, 4, 100); - - DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); - - UIHelper.setI18nTableHeaderRenderer( - table, - RolesTableModel.COLUMN_NAMES[0], - RolesTableModel.COLUMN_NAME_TIPS[0], - RolesTableModel.COLUMN_NAMES[1], - RolesTableModel.COLUMN_NAME_TIPS[1], - RolesTableModel.COLUMN_NAMES[2], - RolesTableModel.COLUMN_NAME_TIPS[2], - RolesTableModel.COLUMN_NAMES[3], - RolesTableModel.COLUMN_NAME_TIPS[3], - RolesTableModel.COLUMN_NAMES[4], - RolesTableModel.COLUMN_NAME_TIPS[4] - ); - - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newStringTableCellRenderer(renderer, 50, true)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newBooleanTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 2, UIHelper.newBooleanTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 3, UIHelper.newBooleanTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 4, UIHelper.newBooleanTableCellRenderer(renderer)); - - UIHelper.setTableColumnEditor(table, 1, MyDefaultCellEditor.newBooleanEditor()); - UIHelper.setTableColumnEditor(table, 2, MyDefaultCellEditor.newBooleanEditor()); - UIHelper.setTableColumnEditor(table, 3, MyDefaultCellEditor.newBooleanEditor()); - UIHelper.setTableColumnEditor(table, 4, MyDefaultCellEditor.newBooleanEditor()); - - } - - public void initUI(SelectDataUI ui) { - if (ui.getStep() != null) { - ui.setDescriptionText(t(ui.getStep().getDescription())); - } - ui.getSelectTree().installUI(); - } - - public void initUI(BackupUI ui) { - if (ui.getStep() != null) { - ui.setDescriptionText(t(ui.getStep().getDescription())); - - ui.getActionMap().put(ACTION_DO_BACKUP, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (StorageStep.BACKUP == ui.getModel().getStep()) { - ui.getDoBackup().doClick(); - } - } - }); - ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KEY_STROKE_DO_BACKUP, ACTION_DO_BACKUP); - addKeyStroke(ui.getDoBackup(), KEY_STROKE_DO_BACKUP); - - ui.getActionMap().put(ACTION_DO_CHOOSE_DIRECTORY, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (StorageStep.BACKUP == ui.getModel().getStep()) { - ui.getChooseFileAction().doClick(); - } - } - }); - ui.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KEY_STROKE_DO_CHOOSE_DIRECTORY, ACTION_DO_CHOOSE_DIRECTORY); - addKeyStroke(ui.getChooseFileAction(), KEY_STROKE_DO_CHOOSE_DIRECTORY); - } - } - - protected void addKeyStroke(AbstractButton component, KeyStroke actionKey) { - - String actionStr = actionKey.toString().replace("pressed", " + "); - String text = component.getText() + " (" + actionStr + ")"; - component.setText(text); - String tip = component.getToolTipText() + " (" + actionStr + ")"; - component.setToolTipText(tip); - - } - - public void initUI(ConfirmUI ui) { - if (ui.getStep() != null) { - ui.setDescriptionText(t(ui.getStep().getDescription())); - } - } - - public void chooseBackupFile(BackupUI ui) { - File f = UIHelper.chooseDirectory(ui, - t("observe.title.choose.db.dump.directory"), - t("observe.action.choose.db.dump.directory"), - new File(ui.getDirectoryText().getText())); - if (f != null) { - changeDirectory(ui, f); - } - } - - public void changeDirectory(BackupUI ui, File f) { - ui.getModel().setBackupFile(new File(f, ui.getFilenameText().getText())); - } - - public void changeFilename(BackupUI ui, String filename) { - ui.getModel().setBackupFile(new File(ui.getDirectoryText().getText(), filename)); - } - - public void refreshConfig(ConfigUI ui, String configId) { - JComponent c = (JComponent) ui.getObjectById(configId); - if (c != null) { - if (log.isDebugEnabled()) { - log.debug(configId); - } - ui.configLayout.show(ui.configContent, configId); - String text = (String) c.getClientProperty("description"); - ui.setDescriptionText(t(text)); - if (c.equals(ui.IMPORT_REMOTE_STORAGE)) { - ui.IMPORT_REMOTE_STORAGE_content.add(ui.remoteConfig, BorderLayout.CENTER); - } else if (c.equals(ui.IMPORT_SERVER_STORAGE)) { - ui.IMPORT_SERVER_STORAGE_content.add(ui.remoteConfig, BorderLayout.CENTER); - } else if (c.equals(ui.USE_REMOTE)) { - ui.USE_REMOTE_content.add(ui.remoteConfig, BorderLayout.CENTER); - } else if (c.equals(ui.USE_SERVER)) { - ui.USE_SERVER_content.add(ui.remoteConfig, BorderLayout.CENTER); - } - } - } - - public void refreshConfig(ConfigReferentielUI ui, String configId) { - JComponent c = (JComponent) ui.getObjectById(configId); - if (c != null) { - if (log.isDebugEnabled()) { - log.debug(configId); - } - ui.configLayout.show(ui.configContent, configId); - } - } - - public void refreshConfig(ConfigDataUI ui, String configId) { - JComponent c = (JComponent) ui.getObjectById(configId); - if (c != null) { - if (log.isDebugEnabled()) { - log.debug(configId); - } - ui.configLayout.show(ui.configContent, configId); - } - } - - public Icon updateConnexionStatutIcon(ConfigUI ui, ConnexionStatus status) { - return (Icon) ui.getConnexionStatus().getClientProperty(status.name().toLowerCase() + "Icon"); - } - - public Color updateConnexionStatutColor(ConfigUI ui, ConnexionStatus status) { - return (Color) ui.getConnexionStatus().getClientProperty(status.name().toLowerCase() + "Color"); - } - - public String updateConnexionStatutText(ConfigUI ui, @SuppressWarnings("unused") ConnexionStatus status) { - ObserveSwingApplicationContext applicationContext = ObserveSwingApplicationContext.get(); - ObserveTextGenerator textGenerator = applicationContext.getTextGenerator(); - return textGenerator.getConnexionTestResultMessage(ui.getModel()); - } - - public void chooseDumpFile(ConfigUI ui) { - File f = UIHelper.chooseFile(ui, - t("observe.title.choose.db.dump"), - t("observe.action.choose.db.dump"), - ui.getModel().getDumpFile(), - "^.+\\.sql\\.gz$", - t("observe.action.choose.db.dump.description")); - ui.getModel().setDumpFile(f); - } - - public void chooseDumpFile(ConfigReferentielUI ui) { - File f = UIHelper.chooseFile(ui, - t("observe.title.choose.db.dump"), - t("observe.action.choose.db.dump"), - ui.getModel().getDumpFile(), - "^.+\\.sql\\.gz$", - t("observe.action.choose.db.dump.description")); - ui.getCentralSourceModel().setDumpFile(f); - ui.getModel().validate(); - } - - public void chooseDumpFile(ConfigDataUI ui) { - File f = UIHelper.chooseFile(ui, - t("observe.title.choose.db.dump"), - t("observe.action.choose.db.dump"), - ui.getModel().getDumpFile(), - "^.+\\.sql\\.gz$", - t("observe.action.choose.db.dump.description")); - ui.getCentralSourceModel().setDumpFile(f); - ui.getModel().validate(); - } - - protected String updateInternalDumpModeLabel(@SuppressWarnings("unused") boolean dumpExist) { - File f = ObserveSwingApplicationContext.get().getConfig().getInitialDbDump(); - String text; - if (f.exists()) { - text = t("observe.storage.internalDump.last.modified", new Date(f.lastModified())); - } else { - text = t("observe.storage.internalDump.not.exist"); - } - return I18nEnumHelper.getLabel(CreationMode.IMPORT_INTERNAL_DUMP) + text; - } - - public void obtainRemoteConnexion(ConfigReferentielUI ui) { - StorageUIModel sourceModel = ui.getCentralSourceModel(); - StorageUILauncher.obtainRemoteConnexion( - ui.getDelegateContext(), - ui.getParentContainer(Window.class), - sourceModel - ); - - sourceModel.validate(StorageStep.CONFIG); - - ui.getModel().validate(); - } - - public void obtainServerConnexion(ConfigReferentielUI ui) { - StorageUIModel sourceModel = ui.getCentralSourceModel(); - StorageUILauncher.obtainServerConnexion( - ui.getDelegateContext(), - ui.getParentContainer(Window.class), - sourceModel - ); - - sourceModel.validate(StorageStep.CONFIG); - - ui.getModel().validate(); - } - - public void obtainRemoteConnexion(ConfigDataUI ui) { - StorageUIModel sourceModel = ui.getCentralSourceModel(); - StorageUILauncher.obtainRemoteConnexion( - ui.getDelegateContext(), - ui.getParentContainer(Window.class), - sourceModel - ); - - sourceModel.validate(StorageStep.CONFIG); - - ui.getModel().validate(); - } - - - public void obtainServerConnexion(ConfigDataUI ui) { - StorageUIModel sourceModel = ui.getCentralSourceModel(); - StorageUILauncher.obtainServerConnexion( - ui.getDelegateContext(), - ui.getParentContainer(Window.class), - sourceModel - ); - - sourceModel.validate(StorageStep.CONFIG); - - ui.getModel().validate(); - } + protected U ui; public String updateStorageLabel(StorageUIModel service, boolean serviceValid, JLabel label, boolean remote) { String text; @@ -542,4 +75,9 @@ public class StorageTabUIHandler { return text; } + + public final void beforeInit(U ui) { + this.ui = ui; + } + } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/package.html b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/package.html index c45a704..1f2ab2b 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/package.html +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/storage/tabs/package.html @@ -22,7 +22,7 @@ <html> <body> <h1>Le paquetage des implantations de contenu d'onglet pour l'ui des - storages</h1> + storages</h1> TODO </body> </html> diff --git a/application-swing/src/main/resources/i18n/application-swing_en_GB.properties b/application-swing/src/main/resources/i18n/application-swing_en_GB.properties index e7cf855..fb784e1 100644 --- a/application-swing/src/main/resources/i18n/application-swing_en_GB.properties +++ b/application-swing/src/main/resources/i18n/application-swing_en_GB.properties @@ -135,6 +135,10 @@ observe.action.stop.server.mode.tip=Stop server mode on local database observe.action.storage.applyAction=Apply observe.action.test.remote=Test connexion observe.action.test.remote.tip=Click here to validate remote connexion +observe.action.toFullScreen=Full screen mode +observe.action.toFullScreen.tip=Reload application in full screen mode +observe.action.toWindowScreen=Window screen mode +observe.action.toWindowScreen.tip=Reload application in wondow screen mode observe.actions.consolidate=Consolidate data observe.actions.consolidate.description=Consolidate observed data observe.actions.consolidate.message.activity=Computed data for activity %1$s diff --git a/application-swing/src/main/resources/i18n/application-swing_es_ES.properties b/application-swing/src/main/resources/i18n/application-swing_es_ES.properties index 9ab8c56..1a7dde7 100644 --- a/application-swing/src/main/resources/i18n/application-swing_es_ES.properties +++ b/application-swing/src/main/resources/i18n/application-swing_es_ES.properties @@ -135,6 +135,10 @@ observe.action.stop.server.mode.tip=Parar el modo servidor de la base local observe.action.storage.applyAction=Aplicar observe.action.test.remote=Comprobar la conexión observe.action.test.remote.tip=Pulsar para comprobar la conexión con el servidor remoto +observe.action.toFullScreen=Mode plein écran \#TODO +observe.action.toFullScreen.tip=Recharcher l'application en mode plein écran \#TODO +observe.action.toWindowScreen=Mode fenêtre \#TODO +observe.action.toWindowScreen.tip=Recharger l'application en mode fenêtre \#TODO observe.actions.consolidate=Calcular los datos observe.actions.consolidate.description=Calcular los datos que no fueron observados observe.actions.consolidate.message.activity=Datos calculados para la actividad %1$s diff --git a/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties b/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties index 517ecb4..842fc0c 100644 --- a/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties +++ b/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties @@ -135,6 +135,10 @@ observe.action.stop.server.mode.tip=Arrêter le mode serveur de la base locale observe.action.storage.applyAction=Appliquer observe.action.test.remote=Valider la connexion observe.action.test.remote.tip=Cliquer pour valider la connexion au serveur distant +observe.action.toFullScreen=Mode plein écran +observe.action.toFullScreen.tip=Recharcher l'application en mode plein écran +observe.action.toWindowScreen=Mode fenêtre +observe.action.toWindowScreen.tip=Recharger l'application en mode fenêtre observe.actions.consolidate=Calculer les données observe.actions.consolidate.description=Calculer les données non observées observe.actions.consolidate.message.activity=Données calculées pour l'activité %1$s diff --git a/application-swing/src/main/resources/icons/action-fullScreen.png b/application-swing/src/main/resources/icons/action-fullScreen.png new file mode 100644 index 0000000..6845e04 Binary files /dev/null and b/application-swing/src/main/resources/icons/action-fullScreen.png differ diff --git a/application-swing/src/main/resources/icons/action-windowScreen.png b/application-swing/src/main/resources/icons/action-windowScreen.png new file mode 100644 index 0000000..fc6638e Binary files /dev/null and b/application-swing/src/main/resources/icons/action-windowScreen.png differ diff --git a/services-rest/src/test/java/fr/ird/observe/services/rest/service/actions/validate/ValidateServiceRestTest.java b/services-rest/src/test/java/fr/ird/observe/services/rest/service/actions/validate/ValidateServiceRestTest.java index 48ddb22..32f5085 100644 --- a/services-rest/src/test/java/fr/ird/observe/services/rest/service/actions/validate/ValidateServiceRestTest.java +++ b/services-rest/src/test/java/fr/ird/observe/services/rest/service/actions/validate/ValidateServiceRestTest.java @@ -38,12 +38,14 @@ import fr.ird.observe.services.dto.referential.PersonDto; import fr.ird.observe.services.dto.referential.ProgramDto; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.dto.referential.SexDto; +import fr.ird.observe.services.dto.referential.SizeMeasureTypeDto; import fr.ird.observe.services.dto.referential.SpeciesDto; import fr.ird.observe.services.dto.referential.SpeciesGroupDto; import fr.ird.observe.services.dto.referential.SpeciesListDto; import fr.ird.observe.services.dto.referential.VesselDto; import fr.ird.observe.services.dto.referential.VesselSizeCategoryDto; import fr.ird.observe.services.dto.referential.VesselTypeDto; +import fr.ird.observe.services.dto.referential.WeightMeasureTypeDto; import fr.ird.observe.services.dto.referential.longline.BaitHaulingStatusDto; import fr.ird.observe.services.dto.referential.longline.BaitSettingStatusDto; import fr.ird.observe.services.dto.referential.longline.BaitTypeDto; @@ -64,11 +66,9 @@ import fr.ird.observe.services.dto.referential.longline.SensorBrandDto; import fr.ird.observe.services.dto.referential.longline.SensorDataFormatDto; import fr.ird.observe.services.dto.referential.longline.SensorTypeDto; import fr.ird.observe.services.dto.referential.longline.SettingShapeDto; -import fr.ird.observe.services.dto.referential.SizeMeasureTypeDto; import fr.ird.observe.services.dto.referential.longline.StomacFullnessDto; import fr.ird.observe.services.dto.referential.longline.TripTypeDto; import fr.ird.observe.services.dto.referential.longline.VesselActivityLonglineDto; -import fr.ird.observe.services.dto.referential.WeightMeasureTypeDto; import fr.ird.observe.services.dto.referential.seine.DetectionModeDto; import fr.ird.observe.services.dto.referential.seine.ObjectFateDto; import fr.ird.observe.services.dto.referential.seine.ObjectOperationDto; @@ -153,7 +153,7 @@ public class ValidateServiceRestTest extends AbstractServiceRestTest { ValidateReferentialsResult result = service.validateReferentials(request); Assert.assertNotNull(result); - ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType> resultByType = result.getResultByType(); + ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType<? extends IdDto>> resultByType = result.getResultByType(); Assert.assertNotNull(resultByType); Assert.assertEquals(59, resultByType.size()); @@ -232,7 +232,7 @@ public class ValidateServiceRestTest extends AbstractServiceRestTest { ValidateDataResult result = service.validateData(request); Assert.assertNotNull(result); - ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> resultByType = result.getResultByType(); + ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> resultByType = result.getResultByType(); Assert.assertNotNull(resultByType); Assert.assertEquals(5, resultByType.size()); @@ -256,7 +256,7 @@ public class ValidateServiceRestTest extends AbstractServiceRestTest { ValidateDataResult result = service.validateData(request); Assert.assertNotNull(result); - ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> resultByType = result.getResultByType(); + ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> resultByType = result.getResultByType(); Assert.assertNotNull(resultByType); Assert.assertEquals(8, resultByType.size()); @@ -271,9 +271,9 @@ public class ValidateServiceRestTest extends AbstractServiceRestTest { } - protected <D extends ReferentialDto> void assertValidateResultForReferentialDtoType(ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType> resultByType, Class<D> dtoType, int expectedCount) { + protected <D extends ReferentialDto> void assertValidateResultForReferentialDtoType(ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType<? extends IdDto>> resultByType, Class<D> dtoType, int expectedCount) { - ValidateResultForDtoType<D> validateResultForDtoType = resultByType.get(dtoType); + ValidateResultForDtoType<D> validateResultForDtoType = (ValidateResultForDtoType) resultByType.get(dtoType); Assert.assertNotNull(validateResultForDtoType); ImmutableSet<ValidateResultForDto<D>> validateResultForDtos = validateResultForDtoType.getValidateResultForDto(); Assert.assertNotNull(validateResultForDtos); @@ -285,9 +285,9 @@ public class ValidateServiceRestTest extends AbstractServiceRestTest { } - protected <D extends IdDto> void assertValidateResultForDtoType(ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> resultByType, Class<D> dtoType, int expectedCount) { + protected <D extends IdDto> void assertValidateResultForDtoType(ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> resultByType, Class<D> dtoType, int expectedCount) { - ValidateResultForDtoType<D> validateResultForDtoType = resultByType.get(dtoType); + ValidateResultForDtoType<D> validateResultForDtoType = (ValidateResultForDtoType) resultByType.get(dtoType); Assert.assertNotNull(validateResultForDtoType); ImmutableSet<ValidateResultForDto<D>> validateResultForDtos = validateResultForDtoType.getValidateResultForDto(); Assert.assertNotNull(validateResultForDtos); diff --git a/services-topia/src/main/java/fr/ird/observe/services/topia/service/actions/validate/ValidateServiceTopia.java b/services-topia/src/main/java/fr/ird/observe/services/topia/service/actions/validate/ValidateServiceTopia.java index bc7323c..261f3ee 100644 --- a/services-topia/src/main/java/fr/ird/observe/services/topia/service/actions/validate/ValidateServiceTopia.java +++ b/services-topia/src/main/java/fr/ird/observe/services/topia/service/actions/validate/ValidateServiceTopia.java @@ -119,7 +119,7 @@ public class ValidateServiceTopia extends ObserveServiceTopia implements Validat request.getValidationContext(), request.getScopes(), Entities.DATA_ENTITIES); - + ReferentialLocale referenceLocale = getReferentialLocale(); initValidationEngine(validationDataContext); @@ -132,7 +132,7 @@ public class ValidateServiceTopia extends ObserveServiceTopia implements Validat } - ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> validateResultForDtoTypeMap = buildResultForDtoTypes(detector); + ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> validateResultForDtoTypeMap = buildResultForDtoTypes(detector); return new ValidateDataResult(request, validateResultForDtoTypeMap); }); @@ -144,9 +144,9 @@ public class ValidateServiceTopia extends ObserveServiceTopia implements Validat } - private ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> buildResultForDtoTypes(ValidationMessageDetector detector) { + private ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> buildResultForDtoTypes(ValidationMessageDetector detector) { - ImmutableMap.Builder<Class<? extends IdDto>, ValidateResultForDtoType> forDtoTypeBuilder = new ImmutableMap.Builder<>(); + ImmutableMap.Builder<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> forDtoTypeBuilder = new ImmutableMap.Builder<>(); for (Class<? extends TopiaEntity> entityType : detector.getDetectedEntityTypes()) { @@ -164,7 +164,7 @@ public class ValidateServiceTopia extends ObserveServiceTopia implements Validat private <E extends ObserveReferentialEntity, D extends ReferentialDto> void buildResultForReferentialDtoType(Class<E> entityType, ValidationMessageDetector detector, - ImmutableMap.Builder<Class<? extends IdDto>, ValidateResultForDtoType> forDtoTypeBuilder) { + ImmutableMap.Builder<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> forDtoTypeBuilder) { ImmutableSet.Builder<ValidateResultForDto<D>> validateResultForDtoMapBuilder = new ImmutableSet.Builder<>(); @@ -188,7 +188,7 @@ public class ValidateServiceTopia extends ObserveServiceTopia implements Validat private <E extends ObserveDataEntity, D extends DataDto> void buildResultForDataDtoType(Class<E> entityType, ValidationMessageDetector detector, - ImmutableMap.Builder<Class<? extends IdDto>, ValidateResultForDtoType> forDtoTypeBuilder) { + ImmutableMap.Builder<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> forDtoTypeBuilder) { ImmutableSet.Builder<ValidateResultForDto<D>> validateResultForDtoMapBuilder = new ImmutableSet.Builder<>(); diff --git a/services-topia/src/test/java/fr/ird/observe/services/topia/service/actions/validate/ValidateServiceTopiaTest.java b/services-topia/src/test/java/fr/ird/observe/services/topia/service/actions/validate/ValidateServiceTopiaTest.java index 0de7b9b..3b7707b 100644 --- a/services-topia/src/test/java/fr/ird/observe/services/topia/service/actions/validate/ValidateServiceTopiaTest.java +++ b/services-topia/src/test/java/fr/ird/observe/services/topia/service/actions/validate/ValidateServiceTopiaTest.java @@ -138,7 +138,7 @@ public class ValidateServiceTopiaTest extends AbstractServiceTopiaTest { ValidateReferentialsResult result = service.validateReferentials(request); Assert.assertNotNull(result); - ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType> resultByType = result.getResultByType(); + ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType<? extends IdDto>> resultByType = result.getResultByType(); Assert.assertNotNull(resultByType); Assert.assertEquals(60, resultByType.size()); @@ -223,11 +223,11 @@ public class ValidateServiceTopiaTest extends AbstractServiceTopiaTest { ValidateDataResult result = service.validateData(request); Assert.assertNotNull(result); - ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> resultByType = result.getResultByType(); + ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> resultByType = result.getResultByType(); Assert.assertNotNull(resultByType); Assert.assertEquals(9, resultByType.size()); - for (Map.Entry<Class<? extends IdDto>, ValidateResultForDtoType> entry : resultByType.entrySet()) { + for (Map.Entry<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> entry : resultByType.entrySet()) { System.out.println("assertValidateResultForDtoType(resultByType, " + entry.getKey().getName() + ".class, " + entry.getValue().getValidateResultForDto().size() + ");"); } @@ -243,9 +243,9 @@ public class ValidateServiceTopiaTest extends AbstractServiceTopiaTest { } - protected <D extends ReferentialDto> void assertValidateResultForReferentialDtoType(ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType> resultByType, Class<D> dtoType, int expectedCount) { + protected <D extends ReferentialDto> void assertValidateResultForReferentialDtoType(ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType<? extends IdDto>> resultByType, Class<D> dtoType, int expectedCount) { - ValidateResultForDtoType<D> validateResultForDtoType = resultByType.get(dtoType); + ValidateResultForDtoType<D> validateResultForDtoType = (ValidateResultForDtoType) resultByType.get(dtoType); Assert.assertNotNull(validateResultForDtoType); ImmutableSet<ValidateResultForDto<D>> validateResultForDtos = validateResultForDtoType.getValidateResultForDto(); Assert.assertNotNull(validateResultForDtos); @@ -257,9 +257,9 @@ public class ValidateServiceTopiaTest extends AbstractServiceTopiaTest { } - protected <D extends IdDto> void assertValidateResultForDtoType(ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> resultByType, Class<D> dtoType, int expectedCount) { + protected <D extends IdDto> void assertValidateResultForDtoType(ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> resultByType, Class<D> dtoType, int expectedCount) { - ValidateResultForDtoType<D> validateResultForDtoType = resultByType.get(dtoType); + ValidateResultForDtoType<D> validateResultForDtoType = (ValidateResultForDtoType) resultByType.get(dtoType); Assert.assertNotNull(validateResultForDtoType); ImmutableSet<ValidateResultForDto<D>> validateResultForDtos = validateResultForDtoType.getValidateResultForDto(); Assert.assertNotNull(validateResultForDtos); diff --git a/services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateDataResult.java b/services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateDataResult.java index 3a1ba8c..a29a9b7 100644 --- a/services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateDataResult.java +++ b/services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateDataResult.java @@ -37,9 +37,9 @@ public class ValidateDataResult implements ObserveDto { protected final ValidateDataRequest validateDataRequest; - protected final ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> resultByType; + protected final ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> resultByType; - public ValidateDataResult(ValidateDataRequest validateDataRequest, ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> resultByType) { + public ValidateDataResult(ValidateDataRequest validateDataRequest, ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> resultByType) { this.validateDataRequest = validateDataRequest; this.resultByType = resultByType; } @@ -48,7 +48,7 @@ public class ValidateDataResult implements ObserveDto { return validateDataRequest; } - public ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType> getResultByType() { + public ImmutableMap<Class<? extends IdDto>, ValidateResultForDtoType<? extends IdDto>> getResultByType() { return resultByType; } diff --git a/services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateReferentialsResult.java b/services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateReferentialsResult.java index 912a63c..ddad793 100644 --- a/services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateReferentialsResult.java +++ b/services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateReferentialsResult.java @@ -23,6 +23,7 @@ package fr.ird.observe.services.service.actions.validate; */ import com.google.common.collect.ImmutableMap; +import fr.ird.observe.services.dto.IdDto; import fr.ird.observe.services.dto.ObserveDto; import fr.ird.observe.services.dto.referential.ReferentialDto; @@ -37,9 +38,9 @@ public class ValidateReferentialsResult implements ObserveDto { protected final ValidateReferentialsRequest validateReferentialsRequest; - protected final ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType> resultByType; + protected final ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType<? extends IdDto>> resultByType; - public ValidateReferentialsResult(ValidateReferentialsRequest validateReferentialsRequest, ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType> resultByType) { + public ValidateReferentialsResult(ValidateReferentialsRequest validateReferentialsRequest, ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType<? extends IdDto>> resultByType) { this.validateReferentialsRequest = validateReferentialsRequest; this.resultByType = resultByType; } @@ -48,7 +49,7 @@ public class ValidateReferentialsResult implements ObserveDto { return validateReferentialsRequest; } - public ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType> getResultByType() { + public ImmutableMap<Class<? extends ReferentialDto>, ValidateResultForDtoType<? extends IdDto>> getResultByType() { return resultByType; } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.