Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe Commits: 061b5ecc by Tony CHEMIT at 2018-09-21T14:06:26Z Introduce actions for admin tabs - - - - - d1918dda by Tony CHEMIT at 2018-09-21T14:06:55Z L'assistant calcul de donnés demande abusivement (ou pas) de configurer une connexion - Closes #961 - - - - - 9 changed files: - + client/src/main/java/fr/ird/observe/client/ui/actions/admin/ObtainLeftSourceUIAction.java - + client/src/main/java/fr/ird/observe/client/ui/actions/admin/ObtainRightSourceUIAction.java - + client/src/main/java/fr/ird/observe/client/ui/admin/AdminTabUIInitializer.java - client/src/main/java/fr/ird/observe/client/ui/admin/config/ConfigModel.java - client/src/main/java/fr/ird/observe/client/ui/admin/config/ConfigUI.jaxx - client/src/main/java/fr/ird/observe/client/ui/admin/config/ConfigUI.jcss - client/src/main/java/fr/ird/observe/client/ui/admin/config/ConfigUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/content/ObserveActionMap.java - client/src/main/java/fr/ird/observe/client/ui/storage/StorageUIModel.java Changes: ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/admin/ObtainLeftSourceUIAction.java ===================================== @@ -0,0 +1,69 @@ +package fr.ird.observe.client.ui.actions.admin; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ui.ObserveKeyStrokes; +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.actions.UIActionSupport; +import fr.ird.observe.client.ui.admin.AdminUIModel; +import fr.ird.observe.client.ui.admin.config.ConfigUI; +import fr.ird.observe.client.ui.storage.StorageUILauncher; +import fr.ird.observe.client.ui.storage.StorageUIModel; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.awt.Window; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n.n; + +/** + * Created by tchemit on 21/09/2018. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class ObtainLeftSourceUIAction extends UIActionSupport { + + public static final String ACTION_NAME = ObtainLeftSourceUIAction.class.getName(); + private static final Logger log = LogManager.getLogger(ObtainLeftSourceUIAction.class); + + private final ConfigUI ui; + + public ObtainLeftSourceUIAction(ObserveMainUI mainUI, ConfigUI ui) { + super(mainUI, ACTION_NAME, n("observe.action.configure"), null, "config", ObserveKeyStrokes.KEY_STROKE_CONFIGURE_LOCAL_SOURCE, true); + this.ui = ui; + } + + @Override + public void actionPerformed(ActionEvent e) { + log.info("start obtain left connexion"); + StorageUIModel sourceModel = ui.getLocalSourceModel(); + StorageUILauncher.obtainConnexion(ui, ui.getParentContainer(Window.class), sourceModel); + log.debug("After modifiy source model isValid : " + sourceModel.isValid() + " / " + sourceModel.isValidStep()); + + AdminUIModel model = ui.getModel(); + model.getConfigModel().removeLocalSource(); + model.getConfigModel().getLocalSourceModel().validate(); + model.validate(); + } +} ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/admin/ObtainRightSourceUIAction.java ===================================== @@ -0,0 +1,68 @@ +package fr.ird.observe.client.ui.actions.admin; + +/*- + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ui.ObserveKeyStrokes; +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.actions.UIActionSupport; +import fr.ird.observe.client.ui.admin.AdminUIModel; +import fr.ird.observe.client.ui.admin.config.ConfigUI; +import fr.ird.observe.client.ui.storage.StorageStep; +import fr.ird.observe.client.ui.storage.StorageUILauncher; +import fr.ird.observe.client.ui.storage.StorageUIModel; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.awt.Window; +import java.awt.event.ActionEvent; + +import static org.nuiton.i18n.I18n.n; + +/** + * Created by tchemit on 21/09/2018. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class ObtainRightSourceUIAction extends UIActionSupport { + + public static final String ACTION_NAME = ObtainRightSourceUIAction.class.getName(); + private static final Logger log = LogManager.getLogger(ObtainRightSourceUIAction.class); + + private final ConfigUI ui; + + public ObtainRightSourceUIAction(ObserveMainUI mainUI, ConfigUI ui) { + super(mainUI, ACTION_NAME, n("observe.action.configure"), null, "config", ObserveKeyStrokes.KEY_STROKE_CONFIGURE_REMOTE_SOURCE, true); + this.ui = ui; + } + + @Override + public void actionPerformed(ActionEvent e) { + log.info("start obtain right connexion"); + StorageUIModel sourceModel = ui.getCentralSourceModel(); + StorageUILauncher.obtainConnexion(ui, ui.getParentContainer(Window.class), sourceModel); + AdminUIModel model = ui.getModel(); + model.getConfigModel().removeCentralSource(); + model.getConfigModel().getCentralSourceModel().validate(StorageStep.CONFIG); + model.validate(); + } +} ===================================== client/src/main/java/fr/ird/observe/client/ui/admin/AdminTabUIInitializer.java ===================================== @@ -0,0 +1,442 @@ +package fr.ird.observe.client.ui.admin; + +/* + * #%L + * ObServe :: Client + * %% + * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.ImmutableMap; +import fr.ird.observe.client.ObserveSwingApplicationContext; +import fr.ird.observe.client.ui.ObserveKeyStrokes; +import fr.ird.observe.client.ui.actions.UIActionSupport; +import fr.ird.observe.client.ui.actions.content.GoToSubTab1UIAction; +import fr.ird.observe.client.ui.actions.content.GoToSubTab2UIAction; +import fr.ird.observe.client.ui.actions.content.GoToSubTab3UIAction; +import fr.ird.observe.client.ui.actions.content.GoToTab1UIAction; +import fr.ird.observe.client.ui.actions.content.GoToTab2UIAction; +import fr.ird.observe.client.ui.actions.content.GoToTab3UIAction; +import fr.ird.observe.client.ui.actions.content.GoToTab4UIAction; +import fr.ird.observe.client.ui.actions.content.GoToTab5UIAction; +import fr.ird.observe.client.ui.actions.content.GoToTab6UIAction; +import fr.ird.observe.client.ui.actions.content.GoToTabUIActionSupport; +import fr.ird.observe.client.ui.content.ObserveActionMap; +import fr.ird.observe.client.ui.util.UIHelper; +import fr.ird.observe.dto.I18nEnumHelper; +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.dto.decoration.ObserveI18nLabelsBuilder; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.nuiton.jaxx.runtime.swing.editor.EnumEditor; +import org.nuiton.jaxx.runtime.swing.renderer.EnumEditorRenderer; +import org.nuiton.jaxx.widgets.datetime.DateTimeEditor; +import org.nuiton.jaxx.widgets.datetime.TimeEditor; +import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor; +import org.nuiton.jaxx.widgets.select.BeanComboBox; +import org.nuiton.jaxx.widgets.select.BeanFilterableComboBox; +import org.nuiton.jaxx.widgets.select.BeanListHeader; +import org.nuiton.jaxx.widgets.select.FilterableDoubleList; +import org.nuiton.jaxx.widgets.text.BigTextEditor; + +import javax.swing.AbstractButton; +import javax.swing.InputMap; +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JLabel; +import javax.swing.JSpinner; +import javax.swing.JTabbedPane; +import javax.swing.JTextField; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyEvent; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +/** + * To initialize ui. + * <p> + * Created on 9/26/14. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 3.7 + */ +public class AdminTabUIInitializer<UI extends AdminTabUI> { + + public static final String OBSERVE_ACTION = "observeAction"; + + public static final String GLOBAL_ACTION = "globalAction"; + + private static final String CLIENT_PROPERTY_PROPERTY_NAME = "propertyName"; + + private static final String CLIENT_PROPERTY_RESET_PROPERTY_NAME = "resetPropertyName"; + + private static final String CLIENT_PROPERTY_NOT_BLOCKING = "notBlocking"; + + /** Logger. */ + private static final Logger log = LogManager.getLogger(AdminTabUIInitializer.class); + + protected final UI ui; + + protected final DecoratorService decoratorService; + + public AdminTabUIInitializer(UI ui) { + this.ui = ui; + this.decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); + } + + public void initUI() { + + 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, inputMap); + + for (String name : ui.get$objectMap().keySet()) { + Object o = ui.getObjectById(name); + + if (o == null) { + continue; + } + +// if (o instanceof JComponent) { +// +// init((JComponent) o, doNotBlockComponentIds); +// } + + if (o instanceof AbstractButton) { + init(actionMap, (AbstractButton) o); + continue; + } + +// if (o instanceof BeanComboBox<?>) { +// init((BeanComboBox<?>) o); +// continue; +// } +// if (o instanceof BeanFilterableComboBox<?>) { +// init((BeanFilterableComboBox<?>) o); +// continue; +// } + +// if (o instanceof BeanListHeader<?>) { +// init((BeanListHeader) o); +// continue; +// } + +// if (o instanceof FilterableDoubleList<?>) { +// init((FilterableDoubleList<?>) o); +// continue; +// } + +// if (o instanceof TimeEditor) { +// init((TimeEditor) o); +// continue; +// } + +// if (o instanceof DateTimeEditor) { +// init((DateTimeEditor) o); +// continue; +// } + +// if (o instanceof CoordinatesEditor) { +// init((CoordinatesEditor) o); +// continue; +// } + +// if (o instanceof EnumEditor) { +// init((EnumEditor<?>) o); +// continue; +// } + +// if (o instanceof BigTextEditor) { +// init((BigTextEditor) o); +// continue; +// } +// if (o instanceof JTabbedPane) { +// init((JTabbedPane) o); +// continue; +// } +// if (o instanceof JLabel) { +// init((JLabel) o); +// continue; +// } + + } + + } + + private void init(JLabel editor) { + String editorName = StringUtils.removeEnd(editor.getName(), "Label"); + Object objectById = ui.getObjectById(editorName); + if (objectById instanceof JComponent) { + editor.setLabelFor((Component) objectById); + } + } + + protected void init(ObserveActionMap actionMap, AbstractButton editor) { + String actionId = (String) editor.getClientProperty(OBSERVE_ACTION); + if (actionId == null) { + return; + } + + // on a trouve une action commune + UIActionSupport action = actionMap.newAction(actionId, ui); + Objects.requireNonNull(action, "action [" + actionId + "] not found for ui " + ui.getClass().getName()); + + log.debug("init common action " + actionId); + action.initAction(ui, editor); + +// actionId = (String) editor.getClientProperty(GLOBAL_ACTION); +// if (actionId != null) { +// action = (UIActionSupport) actionMap.get(actionId); +// Objects.requireNonNull(action, "action [" + actionId + "] not found for ui " + ui.getClass().getName()); +// KeyStroke acceleratorKey = action.getAcceleratorKey(); +// ObserveKeyStrokes.addKeyStroke(editor, acceleratorKey); +// } + + } + + @SuppressWarnings("unchecked") + protected void init(BeanComboBox beanComboBox) { + if (log.isDebugEnabled()) { + log.debug("init combobox for " + beanComboBox.getBeanType()); + } + Class referenceType = beanComboBox.getBeanType(); + beanComboBox.setI18nLabelBuilder(ObserveI18nLabelsBuilder.createFromReferenceType(referenceType)); + beanComboBox.setI18nPrefix("observe.common."); + beanComboBox.setMinimumSize(new Dimension(0, 24)); + + if (StringUtils.isEmpty(beanComboBox.getProperty())) { + beanComboBox.setProperty(beanComboBox.getName()); + } + } + + @SuppressWarnings("unchecked") + protected void init(BeanFilterableComboBox BeanFilterableComboBox) { + if (log.isDebugEnabled()) { + log.debug("init combobox for " + BeanFilterableComboBox.getBeanType()); + } + BeanFilterableComboBox.getCombobox().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), "none"); + Class referenceType = BeanFilterableComboBox.getBeanType(); + BeanFilterableComboBox.setI18nLabelBuilder(ObserveI18nLabelsBuilder.createFromReferenceType(referenceType)); + BeanFilterableComboBox.setI18nPrefix("observe.common."); + BeanFilterableComboBox.setMinimumSize(new Dimension(0, 24)); + + if (StringUtils.isEmpty(BeanFilterableComboBox.getProperty())) { + BeanFilterableComboBox.setProperty(BeanFilterableComboBox.getName()); + } + } + + @SuppressWarnings("unchecked") + protected void init(BeanListHeader beanList) { + + beanList.setI18nPrefix("observe.common."); + + log.debug("init list for " + beanList.getBeanType()); + + Class referenceType = beanList.getBeanType(); + beanList.setI18nLabelBuilder(ObserveI18nLabelsBuilder.createFromReferenceType(referenceType)); + } + + @SuppressWarnings("unchecked") + protected void init(FilterableDoubleList beanList) { + + beanList.setI18nPrefix("observe.common."); + Class referenceType = beanList.getBeanType(); + beanList.setI18nLabelBuilder(ObserveI18nLabelsBuilder.createFromReferenceType(referenceType)); + beanList.getAddButton().setFocusable(false); + beanList.getRemoveButton().setFocusable(false); + + log.debug("init list for " + beanList.getBeanType()); + } + + protected void init(BigTextEditor editor) { + log.debug("init big text editor " + editor.getName()); + if (editor.getProperty() == null) { + editor.setProperty(editor.getName()); + } + } + + protected void init(TimeEditor editor) { + log.debug("init time editor " + editor.getName()); + editor.init(); + if (isAutoSelectOnFocus(editor)) { + + addAutoSelectOnFocus((JSpinner.DateEditor) editor.getHourEditor().getEditor()); + addAutoSelectOnFocus((JSpinner.DateEditor) editor.getMinuteEditor().getEditor()); + + } + } + + protected void init(DateTimeEditor editor) { + log.debug("init date time editor " + editor.getName()); + editor.init(); + editor.getSliderHidor().setFocusable(false); + if (isAutoSelectOnFocus(editor)) { + + addAutoSelectOnFocus((JSpinner.DateEditor) editor.getHourEditor().getEditor()); + addAutoSelectOnFocus((JSpinner.DateEditor) editor.getMinuteEditor().getEditor()); + addAutoSelectOnFocus(editor.getDayDateEditor().getEditor()); + editor.getDayDateEditor().getEditor().addFocusListener(new FocusAdapter() { + + private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + + @Override + public void focusLost(FocusEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + if (source.isEditValid()) { + try { + Date newDate = simpleDateFormat.parse(editor.getDayDateEditor().getEditor().getText()); + Object oldValue = editor.getModel().getPropertyDayDate() == null ? null : UIHelper.getProperty(editor.getModel().getBean(), editor.getModel().getPropertyDayDate()); + if (!Objects.equals(oldValue, newDate)) { + editor.getDayDateEditor().commitEdit(); + log.debug("quit date editor, commit value: " + source.getValue()); + } + } catch (ParseException e1) { + // l'édition est valide donc pas de problème ici + } + } + super.focusLost(e); + } + }); + + } + } + + private void addAutoSelectOnFocus(JSpinner.DateEditor hourEditor) { + addAutoSelectOnFocus(hourEditor.getTextField()); + } + + protected void init(CoordinatesEditor editor) { + log.debug("init coordinates editor " + editor.getName()); + editor.setFormat(ObserveSwingApplicationContext.get().getConfig().getCoordinateFormat()); + editor.init(); + editor.getDmdFormat().setFocusable(false); + editor.getDmsFormat().setFocusable(false); + editor.getDdFormat().setFocusable(false); + + } + + protected void init(JTabbedPane tabbedPane) { + boolean mainTabbedPane = GoToTabUIActionSupport.MAIN_TABBED_PANE.equals(tabbedPane.getName()); + boolean subTabbedPane = GoToTabUIActionSupport.SUB_TABBED_PANE.equals(tabbedPane.getName()); + if (!mainTabbedPane && !subTabbedPane) { + return; + } + int tabCount = tabbedPane.getTabCount(); + InputMap inputMap = ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); + if (mainTabbedPane) { + ObserveKeyStrokes.addKeyStrokeToMainTabbedPane(tabbedPane); + if (tabCount > 0) { + inputMap.put(ObserveKeyStrokes.KEY_STROKE_GO_TAB_1, GoToTab1UIAction.ACTION_NAME); + } + if (tabCount > 1) { + inputMap.put(ObserveKeyStrokes.KEY_STROKE_GO_TAB_2, GoToTab2UIAction.ACTION_NAME); + } + if (tabCount > 2) { + inputMap.put(ObserveKeyStrokes.KEY_STROKE_GO_TAB_3, GoToTab3UIAction.ACTION_NAME); + } + if (tabCount > 3) { + inputMap.put(ObserveKeyStrokes.KEY_STROKE_GO_TAB_4, GoToTab4UIAction.ACTION_NAME); + } + if (tabCount > 4) { + inputMap.put(ObserveKeyStrokes.KEY_STROKE_GO_TAB_5, GoToTab5UIAction.ACTION_NAME); + } + if (tabCount > 5) { + inputMap.put(ObserveKeyStrokes.KEY_STROKE_GO_TAB_6, GoToTab6UIAction.ACTION_NAME); + } + } + if (subTabbedPane) { + ObserveKeyStrokes.addKeyStrokeToSubTabbedPane(tabbedPane); + if (tabCount > 0) { + inputMap.put(ObserveKeyStrokes.KEY_STROKE_GO_SUB_TAB_1, GoToSubTab1UIAction.ACTION_NAME); + } + if (tabCount > 1) { + inputMap.put(ObserveKeyStrokes.KEY_STROKE_GO_SUB_TAB_2, GoToSubTab2UIAction.ACTION_NAME); + } + if (tabCount > 2) { + inputMap.put(ObserveKeyStrokes.KEY_STROKE_GO_SUB_TAB_3, GoToSubTab3UIAction.ACTION_NAME); + } + } + + } + + protected void init(JComponent editor, Set<String> notBlockingComponents) { + final Boolean propertyName = (Boolean) editor.getClientProperty(CLIENT_PROPERTY_NOT_BLOCKING); + if (propertyName != null) { + + if (editor instanceof FilterableDoubleList) { + + notBlockingComponents.add("universeListPane"); + notBlockingComponents.add("selectedListPane"); + + } else { + + notBlockingComponents.add(editor.getName()); + + } + } + } + + protected <B extends Enum<B>> void init(EnumEditor<B> editor) { + log.debug("init enumEditor editor " + editor.getName()); + ImmutableMap.Builder<B, String> labelsBuilder = ImmutableMap.builder(); + for (B e : EnumSet.allOf(editor.getType())) { + String label = I18nEnumHelper.getLabel(e); + labelsBuilder.put(e, label); + } + editor.setRenderer(new EnumEditorRenderer<>(labelsBuilder.build())); + editor.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), "none"); + } + + private boolean isAutoSelectOnFocus(JComponent comp) { + Boolean selectOnFocus = (Boolean) comp.getClientProperty("selectOnFocus"); + return BooleanUtils.isTrue(selectOnFocus); + } + + private void addAutoSelectOnFocus(JTextField jTextField) { + jTextField.addFocusListener(new FocusAdapter() { + + @Override + public void focusGained(final FocusEvent e) { + SwingUtilities.invokeLater(() -> { + JTextField source = (JTextField) e.getSource(); + source.selectAll(); + }); + + } + }); + } + +} ===================================== client/src/main/java/fr/ird/observe/client/ui/admin/config/ConfigModel.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.client.ui.admin.config; * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. @@ -38,8 +38,8 @@ 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.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.beans.PropertyChangeListener; import java.io.File; @@ -59,11 +59,15 @@ import static org.nuiton.i18n.I18n.t; */ public class ConfigModel extends AdminActionModel { - /** Logger */ - private static final Logger log = LogManager.getLogger(ConfigModel.class); public static final String PROPERTY_LOCAL_SOURCE_LABEL = "localSourceLabel"; public static final String PROPERTY_CENTRAL_SOURCE_LABEL = "centralSourceLabel"; - + public static final PropertyChangeListener LOG_PROPERTY_CHANGE_LISTENER = new AdminUIModel.LogPropertyChanged(); + /** Logger */ + private static final Logger log = LogManager.getLogger(ConfigModel.class); + /** la configuration de la base source */ + protected final StorageUIModel localSourceModel; + /** la configuration de la base central */ + protected final StorageUIModel centralSourceModel; /** 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 */ @@ -72,10 +76,6 @@ public class ConfigModel extends AdminActionModel { 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"); @@ -158,7 +158,6 @@ public class ConfigModel extends AdminActionModel { } - public String getLocalSourceLabel() { return localSourceLabel; } @@ -179,7 +178,6 @@ public class ConfigModel extends AdminActionModel { firePropertyChange(PROPERTY_CENTRAL_SOURCE_LABEL, oldValue, centralSourceLabel); } - public boolean validate(AdminUIModel uiModel) { boolean validate = true; @@ -430,8 +428,6 @@ public class ConfigModel extends AdminActionModel { return validate; } - public static final PropertyChangeListener LOG_PROPERTY_CHANGE_LISTENER = new AdminUIModel.LogPropertyChanged(); - protected void startCentralSourceModel(AdminUI ui) { AdminUIModel uiModel = ui.getModel(); @@ -562,6 +558,9 @@ public class ConfigModel extends AdminActionModel { DbMode dbMode = localSourceModel.getDbMode(); localSourceModel.start(dbMode); +// if (previousSource != null && !previousSource.isLocal()) { +// localSourceModel.testRemote(); +// } if (log.isDebugEnabled()) { localSourceModel.removePropertyChangeListener(LOG_PROPERTY_CHANGE_LISTENER); ===================================== client/src/main/java/fr/ird/observe/client/ui/admin/config/ConfigUI.jaxx ===================================== @@ -28,6 +28,8 @@ _failedIcon='SwingUtil.getUIManagerActionIcon("connect_no")'> <import> + fr.ird.observe.client.ui.actions.admin.ObtainLeftSourceUIAction + fr.ird.observe.client.ui.actions.admin.ObtainRightSourceUIAction fr.ird.observe.client.ui.admin.AdminActionModel fr.ird.observe.client.ui.admin.AdminUI fr.ird.observe.client.ui.admin.AdminStep @@ -121,7 +123,7 @@ public void addMessage(AdminStep step, String text) { <JLabel id='localSourceLabel'/> </cell> <cell> - <JButton id='configureLocalSource' onActionPerformed='handler.obtainIncomingConnexion()'/> + <JButton id='configureLocalSource'/> </cell> <cell anchor='east'> <JLabel id='localSourceStatus'/> @@ -145,7 +147,7 @@ public void addMessage(AdminStep step, String text) { <JLabel id='centralSourceLabel'/> </cell> <cell> - <JButton id='configureCentralSource' onActionPerformed='handler.obtainRemoteConnexion()'/> + <JButton id='configureCentralSource'/> </cell> <cell anchor='east'> <JLabel id='centralSourceStatus'/> ===================================== client/src/main/java/fr/ird/observe/client/ui/admin/config/ConfigUI.jcss ===================================== @@ -95,8 +95,7 @@ } #configureLocalSource { - text:"observe.action.configure"; - actionIcon:"config"; + _observeAction:{ObtainLeftSourceUIAction.ACTION_NAME}; } #localSourceStatus { @@ -118,8 +117,7 @@ } #configureCentralSource { - text:"observe.action.configure"; - actionIcon:"config"; + _observeAction:{ObtainRightSourceUIAction.ACTION_NAME}; } #centralSourceStatus { ===================================== client/src/main/java/fr/ird/observe/client/ui/admin/config/ConfigUIHandler.java ===================================== @@ -6,15 +6,15 @@ * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public + * + * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% @@ -23,25 +23,18 @@ package fr.ird.observe.client.ui.admin.config; import fr.ird.observe.client.ObserveSwingApplicationContext; import fr.ird.observe.client.ObserveTextGenerator; -import fr.ird.observe.client.ui.ObserveKeyStrokes; import fr.ird.observe.client.ui.admin.AdminStep; import fr.ird.observe.client.ui.admin.AdminTabUIHandler; -import fr.ird.observe.client.ui.admin.AdminUIModel; -import fr.ird.observe.client.ui.storage.StorageStep; -import fr.ird.observe.client.ui.storage.StorageUILauncher; +import fr.ird.observe.client.ui.admin.AdminTabUIInitializer; import fr.ird.observe.client.ui.storage.StorageUIModel; import fr.ird.observe.client.ui.util.UIHelper; import fr.ird.observe.services.configuration.ObserveDataSourceInformation; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.nuiton.jaxx.runtime.spi.UIHandler; -import javax.swing.AbstractAction; import javax.swing.JCheckBox; -import javax.swing.JComponent; import javax.swing.JLabel; -import java.awt.Window; -import java.awt.event.ActionEvent; import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -59,24 +52,7 @@ public class ConfigUIHandler extends AdminTabUIHandler<ConfigUI> implements UIHa @Override public void afterInit(ConfigUI ui) { - - ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ObserveKeyStrokes.KEY_STROKE_CONFIGURE_LOCAL_SOURCE, "obtainLocalSource"); - ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ObserveKeyStrokes.KEY_STROKE_CONFIGURE_REMOTE_SOURCE, "obtainRemoteSource"); - ui.getActionMap().put("obtainLocalSource", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - ui.doActionPerformed__on__configureLocalSource(e); - } - }); - ui.getActionMap().put("obtainRemoteSource", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - ui.doActionPerformed__on__configureCentralSource(e); - } - }); - - ObserveKeyStrokes.addKeyStroke(ui.getConfigureLocalSource(), ObserveKeyStrokes.KEY_STROKE_CONFIGURE_LOCAL_SOURCE); - ObserveKeyStrokes.addKeyStroke(ui.getConfigureCentralSource(), ObserveKeyStrokes.KEY_STROKE_CONFIGURE_REMOTE_SOURCE); + new AdminTabUIInitializer<>(ui).initUI(); super.afterInit(ui); UIHelper.setLayerUI(ui.getOperations(), parentUI.getOperationBlockLayerUI()); UIHelper.setLayerUI(ui.getConfig(), parentUI.getConfigBlockLayerUI()); @@ -121,29 +97,29 @@ public class ConfigUIHandler extends AdminTabUIHandler<ConfigUI> implements UIHa return operations.contains(scope); } - public void obtainIncomingConnexion() { - StorageUIModel sourceModel = ui.getLocalSourceModel(); - StorageUILauncher.obtainConnexion(ui, ui.getParentContainer(Window.class), sourceModel); - if (log.isDebugEnabled()) { - log.debug("After modifiy source model isValid : " + sourceModel.isValid() + " / " + sourceModel.isValidStep()); - } - AdminUIModel model = ui.getModel(); - model.getConfigModel().removeLocalSource(); - model.getConfigModel().getLocalSourceModel().validate(); - model.validate(); - } - - public void obtainRemoteConnexion() { - if (log.isInfoEnabled()) { - log.info("start obtain remote connexion"); - } - StorageUIModel sourceModel = ui.getCentralSourceModel(); - StorageUILauncher.obtainConnexion(ui, ui.getParentContainer(Window.class), sourceModel); - AdminUIModel model = ui.getModel(); - model.getConfigModel().removeCentralSource(); - model.getConfigModel().getCentralSourceModel().validate(StorageStep.CONFIG); - model.validate(); - } +// public void obtainIncomingConnexion() { +// StorageUIModel sourceModel = ui.getLocalSourceModel(); +// StorageUILauncher.obtainConnexion(ui, ui.getParentContainer(Window.class), sourceModel); +// if (log.isDebugEnabled()) { +// log.debug("After modifiy source model isValid : " + sourceModel.isValid() + " / " + sourceModel.isValidStep()); +// } +// AdminUIModel model = ui.getModel(); +// model.getConfigModel().removeLocalSource(); +// model.getConfigModel().getLocalSourceModel().validate(); +// model.validate(); +// } +// +// public void obtainRemoteConnexion() { +// if (log.isInfoEnabled()) { +// log.info("start obtain remote connexion"); +// } +// StorageUIModel sourceModel = ui.getCentralSourceModel(); +// StorageUILauncher.obtainConnexion(ui, ui.getParentContainer(Window.class), sourceModel); +// AdminUIModel model = ui.getModel(); +// model.getConfigModel().removeCentralSource(); +// model.getConfigModel().getCentralSourceModel().validate(StorageStep.CONFIG); +// model.validate(); +// } protected String updateDataSourcePolicy(StorageUIModel sourceModel, boolean valid) { String text = null; ===================================== client/src/main/java/fr/ird/observe/client/ui/content/ObserveActionMap.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.client.ui.content; * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. @@ -30,8 +30,8 @@ import fr.ird.observe.client.ui.ObserveMainUI; import fr.ird.observe.client.ui.actions.UIActionSupport; import fr.ird.observe.client.ui.actions.main.global.GlobalUIActionSupport; import org.apache.commons.beanutils.ConstructorUtils; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.reflections.Reflections; import javax.swing.AbstractButton; @@ -163,4 +163,16 @@ public class ObserveActionMap extends ActionMap { } + public <A extends UIActionSupport> A newAction(String key, Object args) { + + try { + @SuppressWarnings("unchecked") Class<A> actionType = (Class<A>) Class.forName(key); + log.debug("Create action: " + key + ", type: " + actionType.getName()); + return ConstructorUtils.invokeConstructor(actionType, new Object[]{ui, args}, new Class[]{ObserveMainUI.class, args.getClass()}); + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { + throw new ObserveSwingTechnicalException("Hum, can't creation action for type: " + key, e); + } + + } + } ===================================== client/src/main/java/fr/ird/observe/client/ui/storage/StorageUIModel.java ===================================== @@ -590,15 +590,17 @@ public class StorageUIModel extends WizardModel<StorageStep> { public void start(DbMode dbMode) { - if (log.isDebugEnabled()) { - log.debug("Will use dbMode : " + dbMode + " vs previous mode " + getDbMode()); - } + boolean testRemote = dataSourceInformation != null; + + log.debug("Will use dbMode : " + dbMode + " vs previous mode " + getDbMode()); setDbMode(dbMode); startCentralSourceModel(); startCentralDataSourceModel(); start(); + + firePropertyChange(DB_MODE_PROPERTY_NAME, getDbMode()); firePropertyChange(CREATION_MODE_PROPERTY_NAME, getCreationMode()); firePropertyChange(DUMP_FILE_PROPERTY_NAME, getDumpFile()); @@ -623,6 +625,11 @@ public class StorageUIModel extends WizardModel<StorageStep> { firePropertyChange(CAN_MIGRATE_PROPERTY_NAME, isCanMigrate()); firePropertyChange(SHOW_MIGRATION_SQL_PROPERTY_NAME, isShowMigrationSql()); firePropertyChange(SHOW_MIGRATION_PROGRESSION_PROPERTY_NAME, isShowMigrationProgression()); + + if (testRemote && !isLocal()) { + log.info("Test previous data source configuration..."); + testRemote(); + } } public boolean isCanUseLocalService() { @@ -1130,7 +1137,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { boolean oldValue = this.localStorageExist; this.localStorageExist = localStorageExist; firePropertyChange(LOCAL_STORAGE_EXIST_PROPERTY_NAME, oldValue, - localStorageExist); + localStorageExist); validate(); } @@ -1585,10 +1592,13 @@ public class StorageUIModel extends WizardModel<StorageStep> { config = pgConfig; } else if (isEditServerConfig()) { try { - URL url = new URL(serverUrl); + if (restConfig.getServerUrl() != null && serverUrl == null) { - restConfig.setServerUrl(url); + } else { + URL url = new URL(serverUrl); + restConfig.setServerUrl(url); + } config = restConfig; } catch (MalformedURLException e) { View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/049d8449d164655b7c54df4bcfb... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/049d8449d164655b7c54df4bcfb... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT