Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: e2ae3d0e by Tony Chemit at 2020-12-17T08:19:32+01:00 Miss a reference contract (no code on RTP) - - - - - 5094b739 by Tony Chemit at 2020-12-17T08:27:37+01:00 Petit problème erratique sur l'ouverture de nœud dans l'arbre - Closes #1667 - - - - - 16 changed files: - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/DataSourceEditorHandler.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/DataSourceEditorLayerUI.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/DataSourceEditorModel.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/ContentUIManager.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/create/CreateNewContentTableUIEntry.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/mode/ChangeMode.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/TripActionHelper.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/edit/actions/SaveEditUIAdapter.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/open/actions/SaveOpenableUIAdapter.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/NavigationTree.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/NavigationTreeSelectionListenerImpl.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/NavigationTreeShowPopupHandler.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/NavigationUIInitializer.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/root/RootNavigationNode.java - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/RouteCloseCallback.java - models/dto/src/main/models/Observe-01-referential-common.model Changes: ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/DataSourceEditorHandler.java ===================================== @@ -25,6 +25,7 @@ package fr.ird.observe.client.datasource.editor.api; import fr.ird.observe.client.ClientUIContext; import fr.ird.observe.client.WithClientUIContext; import fr.ird.observe.client.datasource.editor.api.actions.ChangeEditorFocus; +import fr.ird.observe.client.datasource.editor.api.content.ContentUI; import fr.ird.observe.client.datasource.editor.api.content.ContentUIManager; import fr.ird.observe.client.datasource.editor.api.content.validation.ContentMessageTableRenderer; import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTree; @@ -32,12 +33,15 @@ import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTreeMode import fr.ird.observe.client.util.ProgressModel; import fr.ird.observe.client.util.UIHelper; import fr.ird.observe.client.util.init.UIInitHelper; +import fr.ird.observe.client.util.session.ObserveSwingSessionHelper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.nuiton.jaxx.runtime.spi.UIHandler; import org.nuiton.jaxx.validator.swing.SwingValidatorUtil; +import javax.swing.JComponent; import javax.swing.SwingUtilities; +import java.awt.BorderLayout; import java.util.Objects; /** @@ -49,6 +53,8 @@ public class DataSourceEditorHandler implements UIHandler<DataSourceEditor>, Wit private static final Logger log = LogManager.getLogger(DataSourceEditorHandler.class); private DataSourceEditor ui; + private ObserveSwingSessionHelper swingSessionHelper; + private boolean contentAdjusting; @Override public void beforeInit(DataSourceEditor ui) { @@ -57,8 +63,9 @@ public class DataSourceEditorHandler implements UIHandler<DataSourceEditor>, Wit ui.setContextValue(model.getDatasourceMenuModel()); ui.setContextValue(model.getNavigationMenuModel()); ClientUIContext clientUIContext = getClientUIContext(); + swingSessionHelper = clientUIContext.getObserveSwingSessionHelper(); ui.setContextValue(clientUIContext.getClientConfig()); - ui.setContextValue(new ContentUIManager(clientUIContext.getMainUI().getMainUIBodyContentManager(), clientUIContext.getObserveSwingSessionHelper())); + ui.setContextValue(new ContentUIManager(clientUIContext.getMainUI().getMainUIBodyContentManager())); } @Override @@ -77,6 +84,43 @@ public class DataSourceEditorHandler implements UIHandler<DataSourceEditor>, Wit // register this action since there is no editor on which attach this action ChangeEditorFocus.init(ui, null, ChangeEditorFocus.class); + + ui.getModel().addPropertyChangeListener(DataSourceEditorModel.PROPERTY_CONTENT, evt -> onContentChanged((ContentUI) evt.getOldValue(), (ContentUI) evt.getNewValue())); + } + + private void onContentChanged(ContentUI previousContentUI, ContentUI contentUI) { + if (contentAdjusting) { + return; + } + contentAdjusting = true; + try { + log.info(String.format("Content ui changed from: %s to %s", previousContentUI == null ? null : previousContentUI.getModel().getPrefix(), contentUI == null ? null : contentUI.getModel().getPrefix())); + if (previousContentUI != null) { + log.info(String.format("[%s] Will destroy previous content ui", previousContentUI.getClass().getSimpleName())); + previousContentUI.destroy(); + } + if (contentUI == null) { + setNoContent(); + } else { + setContent(contentUI); + openContent(contentUI); + } + } catch (Exception e) { + setNoContent(); + ui.getModel().setContent(null); + } finally { + contentAdjusting = false; + } + } + + private void setNoContent() { + setContent(ui.getEmptySelection()); + } + + private void setContent(JComponent content) { + log.info("Set content: " + content.getName()); + ui.getContent().removeAll(); + ui.getContent().add(content, BorderLayout.CENTER); } public void updateContentSize() { @@ -88,21 +132,28 @@ public class DataSourceEditorHandler implements UIHandler<DataSourceEditor>, Wit ui.getContentSplitPane().setDividerLocation(plusSize); } + public void openContent(ContentUI contentUI) { + log.info(String.format("%sWill open ui", contentUI.getModel().getPrefix())); + contentUI.open(); + updateContentSize(); + swingSessionHelper.addComponent(contentUI, true); + swingSessionHelper.save(); + log.info(String.format("%s opened", contentUI.getModel().getPrefix())); + SwingUtilities.invokeLater(contentUI::opened); + } + /** - * Charge dans l'ui un nouveau modèle de navigation. + * Charge dans l'interface graphique 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. + * <b>Note:</b> cette méthode doit être appelée après tout rechargement de modèle de navigation. * * @param progressModel the progress model to interact with ui */ public void loadNavigationUI(ProgressModel progressModel) { - NavigationTree tree = ui.getNavigationUI().getTree(); - NavigationTreeModel treeModel = tree.getModel(); treeModel.populate(false); progressModel.increments(); - // select initial node try { tree.selectInitialNode(); @@ -110,9 +161,7 @@ public class DataSourceEditorHandler implements UIHandler<DataSourceEditor>, Wit log.error("Could not load initial node", e); } progressModel.increments(); - tree.setVisible(true); - ui.getModel().setFocusOnNavigation(true); } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/DataSourceEditorLayerUI.java ===================================== @@ -117,7 +117,7 @@ public class DataSourceEditorLayerUI extends AbstractLayerUI<JComponent> impleme log.debug("Set focus on content"); editor.getNavigationView().setBorder(getNoFocusBorder()); editor.getContentSplitPane().setBorder(getFocusBorder()); - ContentUI contentUI = editor.getContentUIManager().getSelectedContentUI(); + ContentUI contentUI = editor.getModel().getContent(); if (contentUI != null) { Component focusComponent = contentUI.getModel().getStates().getFormFocusOwner(); if (focusComponent == null) { ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/DataSourceEditorModel.java ===================================== @@ -39,7 +39,7 @@ import java.util.Objects; public class DataSourceEditorModel extends AbstractJavaBean { public static final String PROPERTY_FOCUS_ON_NAVIGATION = "focusOnNavigation"; - private static final String PROPERTY_CONTENT = "content"; + public static final String PROPERTY_CONTENT = "content"; /** * Shared message table model. */ @@ -78,6 +78,11 @@ public class DataSourceEditorModel extends AbstractJavaBean { return content; } + @SuppressWarnings("unchecked") + public <U extends ContentUI> U getTypedContent() { + return (U) content; + } + public void setContent(ContentUI content) { ContentUI oldValue = getContent(); this.content = content; ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/ContentUIManager.java ===================================== @@ -25,17 +25,11 @@ import fr.ird.observe.client.datasource.editor.api.DataSourceEditor; import fr.ird.observe.client.datasource.editor.api.DataSourceEditorBodyContent; import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNode; import fr.ird.observe.client.main.body.MainUIBodyContentManager; -import fr.ird.observe.client.util.UIHelper; -import fr.ird.observe.client.util.session.ObserveSwingSessionHelper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.nuiton.jaxx.runtime.JAXXContext; import org.nuiton.jaxx.runtime.context.JAXXInitialContext; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; -import java.awt.BorderLayout; -import java.awt.Component; import java.lang.reflect.Constructor; /** @@ -49,7 +43,6 @@ public class ContentUIManager { private static final Logger log = LogManager.getLogger(ContentUIManager.class); - private final ObserveSwingSessionHelper swingSessionHelper; private final DataSourceEditorBodyContent dataSourceEditorBody; public static JAXXInitialContext newContext(ContentUI parent) { @@ -63,178 +56,54 @@ public class ContentUIManager { .add(dataSourceEditor); } - public ContentUIManager(MainUIBodyContentManager mainUIBodyContentManager, ObserveSwingSessionHelper swingSessionHelper) { - this.swingSessionHelper = swingSessionHelper; + public ContentUIManager(MainUIBodyContentManager mainUIBodyContentManager) { this.dataSourceEditorBody = mainUIBodyContentManager.getBodyTyped(DataSourceEditor.class, DataSourceEditorBodyContent.class); } - public <U extends ContentUI> U getContent() { - JPanel layoutContent = getLayoutContent(); - Component currentContent = layoutContent.getComponent(0); - if (!(currentContent instanceof ContentUI)) { - return null; - } - @SuppressWarnings("unchecked") U content = (U) currentContent; - log.debug(String.format("Will use existing content: %s", content.getClass().getName())); - return content; - } - public void closeSafeSelectedContentUI() { - ContentUI selectedContentUI = getSelectedContentUI(); + ContentUI selectedContentUI = getDataSourceEditor().getModel().getContent(); if (selectedContentUI != null) { selectedContentUI.getHandler().getContentOpen().closeSafeUI(); } } public <U extends ContentUI> U createContent(NavigationNode node, Class<U> uiClass) { - DataSourceEditor dataSourceEditor = getDataSourceEditor(); - JAXXInitialContext jaxxInitialContext = newContext(dataSourceEditor, node); - U result; try { Constructor<U> constructor = uiClass.getConstructor(JAXXContext.class); log.info(String.format("[%s] Will create new ui", uiClass.getSimpleName())); - result = constructor.newInstance(jaxxInitialContext); + JAXXInitialContext jaxxInitialContext = newContext(getDataSourceEditor(), node); + return constructor.newInstance(jaxxInitialContext); } catch (Exception e) { throw new IllegalStateException("Could not create content ui " + uiClass, e); } - try { - // ajout du content dans son parent - getLayoutContent().removeAll(); - getLayoutContent().add(result, BorderLayout.CENTER); - log.debug(String.format("Add new content: %s", result.getClass().getName())); - return result; - } catch (Exception e) { - throw new IllegalStateException("Could not init content ui " + uiClass, e); - } - } - - public void openContent(ContentUI content) { - log.info(String.format("%sWill open ui", content.getModel().getPrefix())); - boolean withError = false; - try { - content.open(); - } catch (Exception e) { - //FIXME:BodyContent See what to do exactly in this case, remove everything ? - UIHelper.handlingError(e); - withError = true; - } finally { - if (!withError) { - getLayoutContent().removeAll(); - getLayoutContent().add(content, BorderLayout.CENTER); - getDataSourceEditor().updateContentSize(); - - swingSessionHelper.addComponent(content, true); - swingSessionHelper.save(); - log.info(String.format("%s opened", content.getModel().getPrefix())); - - SwingUtilities.invokeLater(content::opened); - } - } - } - - public void close() { - getLayoutContent().removeAll(); - getLayoutContent().add(getDataSourceEditor().getEmptySelection(), BorderLayout.CENTER); - } - - public ContentUI getSelectedContentUI() { - return getSelectedContentUI(getDataSourceEditor()); - } - - public boolean closeSelectedContentUI() { - return closeSelectedContentUI(getDataSourceEditor()); } /** * Essaye de fermer l'écran d'édition s'il existe. * - * @param dataSourceEditor l'ui principale - * @return {@code true} si le contenu a bien été fermé, {@code false} si on - * ne peut pas fermer l'écran + * @return {@code true} si le contenu a bien été fermé, {@code false} si on ne peut pas fermer l'écran * @since 1.5 */ - public boolean closeSelectedContentUI(DataSourceEditor dataSourceEditor) { - ContentUI ui = getSelectedContentUI(dataSourceEditor); + public boolean closeSelectedContentUI() { + ContentUI ui = getDataSourceEditor().getModel().getContent(); if (ui == null) { // no content ui return true; } log.info(String.format("[%s] Will close ui", ui.getClass().getSimpleName())); - boolean closed = false; + boolean closed; try { closed = ui.close(); } catch (Exception e) { - UIHelper.handlingError(e); + log.error(String.format("%sCould not close ui", ui.getModel().getPrefix()), e); + // still we accept to qui the content + closed = true; } return closed; } - public void removeSelectedContentUI() { - ContentUI selectedContentUI = getSelectedContentUI(); - if (selectedContentUI != null) { - try { - getLayoutContent().removeAll(); - } catch (Exception e) { - e.printStackTrace(); - } - log.info(String.format("[%s] Will destroy ui", selectedContentUI.getClass().getSimpleName())); - selectedContentUI.destroy(); - } - getLayoutContent().add(getDataSourceEditor().getEmptySelection(), BorderLayout.CENTER); - } - - //FIXME:BodyContent Who used this ? -// public void restartEdit() { -// -// ContentUI selectedUI = getSelectedContentUI(); -// if (selectedUI == null) { -// // pas d'écran selectionne -// return; -// } -// ContentUIModel model = selectedUI.getModel(); -// if (!model.isEditable()) { -// // modele non editable -// return; -// } -// -// if (!model.isUpdatingMode()) { -// // ecran non en mode mis a jour -// return; -// } -// -// log.info(String.format("[%s] Will restart edit ui", selectedUI.getClass().getSimpleName())); -// selectedUI.restartEdit(); -// } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - close(); - } - - private JPanel getLayoutContent() { - return getDataSourceEditor().getContent(); - } - private DataSourceEditor getDataSourceEditor() { return dataSourceEditorBody.get(); } - private ContentUI getSelectedContentUI(DataSourceEditor ui) { - if (ui == null) { - // no ui, so no modification - return null; - } - ContentUI result = null; - JPanel container = ui.getContent(); - if (container.getComponentCount() < 1) { - return null; - } - Component currentContent = container.getComponent(0); - if (currentContent instanceof ContentUI) { - result = (ContentUI) currentContent; - } - return result; - } - } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/create/CreateNewContentTableUIEntry.java ===================================== @@ -83,7 +83,7 @@ public class CreateNewContentTableUIEntry<U extends ContentUI> extends ContentUI ContentTableUI<?, ?, ?> newContentUI; if (!source.equals(selectedNode)) { tree.selectSafeNode(selectedNode); - newContentUI = (ContentTableUI<?, ?, ?>) getDataSourceEditor().getContentUIManager().getSelectedContentUI(); + newContentUI = (ContentTableUI<?, ?, ?>) getDataSourceEditor().getModel().getContent(); } else { newContentUI = (ContentTableUI<?, ?, ?>) ui; } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/mode/ChangeMode.java ===================================== @@ -251,22 +251,18 @@ public class ChangeMode<U extends ContentUI> extends ContentUIActionSupport<U> { } public void rebuildEditableZone(U ui) { -// ui.getActions().setVisible(true); ui.getHandler().getDataSourceEditor().getMessageView().setVisible(true); SwingUtilities.invokeLater(ui.getHandler()::fixFormSize); getDataSourceEditor().updateContentSize(); -// ui.getHandler().fixFormSize(); } protected void rebuildNotEditableZone(U ui) { -// ui.getActions().setVisible(false); ui.getHandler().getDataSourceEditor().getMessageView().setVisible(false); ui.getHandler().fixFormSize(); getDataSourceEditor().updateContentSize(); SwingUtilities.invokeLater(ui.getHandler()::fixFormSize); } - protected void rebuildFocus(U ui, ContentMode mode) { ContentUIModel model = ui.getModel(); model.setFormFocusOwner(null); ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/TripActionHelper.java ===================================== @@ -136,7 +136,7 @@ public abstract class TripActionHelper implements WithClientUIContext { NavigationTree tree = ui.getHandler().getDataSourceEditor().getNavigationUI().getTree(); NavigationNode tripNode = tree.getSelectedNode().upToReferenceNode(getReferenceType()); tree.selectSafeNode(tripNode); - TripUI<?> tripUI = (TripUI<?>) ui.getHandler().getDataSourceEditor().getContentUIManager().getSelectedContentUI(); + TripUI<?> tripUI = (TripUI<?>) ui.getHandler().getDataSourceEditor().getModel().getContent(); // set availability flag to true tripUI.getModel().set(availabilityPropertyName, true); // go to meta-data tab ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/edit/actions/SaveEditUIAdapter.java ===================================== @@ -59,7 +59,7 @@ public class SaveEditUIAdapter<U extends ContentEditUI<?, U>> implements SaveAda dataSourceEditor.getNavigationUI().getTree().reSelectSafeNode(node); // apply extra actions from previous opened content (go back to correct tab if any, ...) - U newUi = dataSourceEditor.getContentUIManager().getContent(); + U newUi = dataSourceEditor.getModel().getTypedContent(); newUi.resetFromPreviousUi(ui); } } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/open/actions/SaveOpenableUIAdapter.java ===================================== @@ -69,12 +69,12 @@ public class SaveOpenableUIAdapter<U extends ContentOpenableUI<?, U>> implements dataSourceEditor.getNavigationUI().getTree().reSelectSafeNode(node); // apply extra actions from previous opened content (go back to correct tab if any, ...) - U newUi = dataSourceEditor.getContentUIManager().getContent(); + U newUi = dataSourceEditor.getModel().getTypedContent(); newUi.resetFromPreviousUi(ui); if (request.isNotPersisted() && predicate.test(bean)) { // reload ui and do click - U content = dataSourceEditor.getContentUIManager().getContent(); + U content = dataSourceEditor.getModel().getTypedContent(); SwingUtilities.invokeLater(() -> buttonGetter.apply(content).doClick()); } } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/NavigationTree.java ===================================== @@ -45,42 +45,9 @@ public class NavigationTree extends JXTree { public NavigationTree() { super(new NavigationTreeModel()); - setLargeModel(true); setRootVisible(false); - -// addTreeWillExpandListener(new TreeWillExpandListener() { -// -// @Override -// public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { -// getSelectionModel().fireTreeWillExpandEvent(event); -// openNode(event.getPath()); -// } -// -// @Override -// public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { -// //FIXME check this is working ? -// getSelectionModel().fireTreeWillCollapseEvent(event); -// } -// }); -// addTreeSelectionListener(e -> { -// if (!e.isAddedPath()) { -// return; -// } -// openNode(e.getPath()); -// }); - - } - -// public boolean getScrollableTracksViewportWidth() { -// return true; -// } - -// @Override -// public boolean isFixedRowHeight() { -// return true; -// } - + } @Override public void updateUI() { @@ -157,9 +124,9 @@ public class NavigationTree extends JXTree { NavigationNode selectedNode = getModel().getInitialNode(); log.info(String.format("Initial selected node: %s", selectedNode)); if (selectedNode != null) { - selectSafeNode(selectedNode); + reSelectSafeNode(selectedNode); } - SwingUtilities.invokeLater(this::grabFocus); + SwingUtilities.invokeLater(this::requestFocusInWindow); } /** @@ -180,7 +147,7 @@ public class NavigationTree extends JXTree { selectFirstNode(); } } - SwingUtilities.invokeLater(this::grabFocus); + SwingUtilities.invokeLater(this::requestFocusInWindow); } public void addUnsavedNode(NavigationNode parentNode, NavigationNode result) { ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/NavigationTreeSelectionListenerImpl.java ===================================== @@ -24,6 +24,7 @@ package fr.ird.observe.client.datasource.editor.api.navigation; import fr.ird.observe.client.ClientUIContext; import fr.ird.observe.client.datasource.api.ObserveSwingDataSource; +import fr.ird.observe.client.datasource.editor.api.DataSourceEditorModel; import fr.ird.observe.client.datasource.editor.api.content.ContentUI; import fr.ird.observe.client.datasource.editor.api.content.ContentUIManager; import fr.ird.observe.client.datasource.editor.api.navigation.event.NavigationTreeSelectionEvent; @@ -48,9 +49,11 @@ class NavigationTreeSelectionListenerImpl implements fr.ird.observe.client.datas private final ClientUIContext clientUIContext; private final ContentUIManager contentUIManager; private final NavigationUI ui; + private final DataSourceEditorModel dataSourceEditorModel; private final NavigationTree tree; - NavigationTreeSelectionListenerImpl(ContentUIManager contentUIManager, NavigationUI ui, NavigationTree tree) { + NavigationTreeSelectionListenerImpl(DataSourceEditorModel dataSourceEditorModel, ContentUIManager contentUIManager, NavigationUI ui, NavigationTree tree) { + this.dataSourceEditorModel = Objects.requireNonNull(dataSourceEditorModel); this.tree = Objects.requireNonNull(tree); this.clientUIContext = tree.getRootNode().getClientUIContext(); this.contentUIManager = Objects.requireNonNull(contentUIManager); @@ -70,9 +73,8 @@ class NavigationTreeSelectionListenerImpl implements fr.ird.observe.client.datas } @Override - public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { + public void treeWillExpand(TreeExpansionEvent event) { // do nothing -// tree.getSelectionModel().fireTreeWillExpandEvent(event); TreePath path = event.getPath(); NavigationNode node = (NavigationNode) path.getLastPathComponent(); log.info(String.format("Will expand - do open node: %s", node)); @@ -82,7 +84,7 @@ class NavigationTreeSelectionListenerImpl implements fr.ird.observe.client.datas @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { //FIXME check this is working ? -// tree.getSelectionModel().fireTreeWillCollapseEvent(event); + tree.getSelectionModel().fireTreeWillCollapseEvent(event); NavigationNode node = (NavigationNode) event.getPath().getLastPathComponent(); @@ -111,12 +113,13 @@ class NavigationTreeSelectionListenerImpl implements fr.ird.observe.client.datas if (source == null || !source.isOpen()) { //FIXME Is this can really happen ? not sure // no open data source - log.debug("No open Data source."); + log.warn("No open Data source."); return; } if (tree.isSelectionEmpty()) { - log.debug("No selection, show empty panel..."); - contentUIManager.removeSelectedContentUI(); + log.info("No selection, show empty panel..."); + dataSourceEditorModel.setContent(null); +// contentUIManager.removeSelectedContentUI(); return; } @@ -125,6 +128,7 @@ class NavigationTreeSelectionListenerImpl implements fr.ird.observe.client.datas String params = node.toString(); String message = t("observe.ui.action.open.screen", params); + log.info("Open selection: " + message); node.open(); @@ -137,75 +141,23 @@ class NavigationTreeSelectionListenerImpl implements fr.ird.observe.client.datas // obtain the ui type to show Class<? extends ContentUI> uiClass = node.getScope().getContentUiType(); - log.info(String.format("new selected path = %s, ui = %s", node, uiClass)); + log.info(String.format("Will open content for node = %s, ui = %s", node, uiClass)); - //FIXME Just for test - if (uiClass == null) { - //FIXME We should always have a ui associated to node, improve this code to not accept this state - // no ui found, do nothing - return; - } // compute the selected ids to put in data context node.getContext().storeSelectedNodes(node); - //FIXME:Focus this is not the place to set focus -// boolean focusOnNavigation = false; -// JComponent focusOwner; -// ObserveMainUI mainUI = getClientUIContext().getMainUI(); -// Component focusOwner1 = mainUI.getFocusOwner(); -// if (focusOwner1 == null || focusOwner1.equals(ui) || focusOwner1.equals(mainUI)) { -// focusOnNavigation = true; -// focusOwner = ui.getNavigationUI().getTree(); -// } else { -// focusOwner = (JComponent) mainUI.getFocusOwner(); -// -// if (focusOwner != null) { -// if (ui.getNavigationUI().getTree().equals(focusOwner)) { -// focusOnNavigation = true; -// } -// if (ui.getNavigationUI().equals(focusOwner)) { -// focusOnNavigation = true; -// } -// if (ui.getNavigationView().equals(focusOwner)) { -// focusOnNavigation = true; -// } -// if (!focusOnNavigation) { -// Container focusOwnerParent = focusOwner.getParentReference(); -// while (focusOwnerParent != null) { -// if (ui.getNavigationUI().getTree().equals(focusOwnerParent)) { -// focusOnNavigation = true; -// break; -// } -// if (ui.getNavigationUI().equals(focusOwnerParent)) { -// focusOnNavigation = true; -// break; -// } -// if (ui.getNavigationView().equals(focusOwnerParent)) { -// focusOnNavigation = true; -// break; -// } -// focusOwnerParent = focusOwnerParent.getParentReference(); -// } -// } -// } -// } -// if (focusOnNavigation) { -// log.debug("Focus on navigation: " + focusOwner); +// ContentUI previousSelectedContent = contentUIManager.getSelectedContentUI(); +// if (previousSelectedContent != null) { +// contentUIManager.removeSelectedContentUI(); // } - ContentUI previousSelectedContent = contentUIManager.getSelectedContentUI(); - if (previousSelectedContent != null) { - contentUIManager.removeSelectedContentUI(); - } - // create new content ContentUI content = contentUIManager.createContent(node, node.getScope().getContentUiType()); // open content - contentUIManager.openContent(content); + dataSourceEditorModel.setContent(content); +// contentUIManager.openContent(content); ObserveUtil.cleanMemory(); - -// if (focusOnNavigation) SwingUtilities.invokeLater(focusOwner::requestFocusInWindow); } } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/NavigationTreeShowPopupHandler.java ===================================== @@ -22,9 +22,9 @@ package fr.ird.observe.client.datasource.editor.api.navigation; * #L% */ +import fr.ird.observe.client.datasource.editor.api.DataSourceEditorModel; import fr.ird.observe.client.datasource.editor.api.content.ContentUI; import fr.ird.observe.client.datasource.editor.api.content.ContentUIHandler; -import fr.ird.observe.client.datasource.editor.api.content.ContentUIManager; import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNode; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -57,10 +57,10 @@ public class NavigationTreeShowPopupHandler implements KeyListener, MouseListene private final JPopupMenu popup; private final NavigationTree tree; private final JMenuItem noAction; - private final ContentUIManager contentUIManager; + private final DataSourceEditorModel dataSourceEditorModel; - NavigationTreeShowPopupHandler(ContentUIManager contentUIManager, NavigationTree tree, JPopupMenu popup, JMenuItem noAction) { - this.contentUIManager = Objects.requireNonNull(contentUIManager); + NavigationTreeShowPopupHandler(DataSourceEditorModel dataSourceEditorModel, NavigationTree tree, JPopupMenu popup, JMenuItem noAction) { + this.dataSourceEditorModel = Objects.requireNonNull(dataSourceEditorModel); this.popup = Objects.requireNonNull(popup); this.tree = Objects.requireNonNull(tree); this.noAction = Objects.requireNonNull(noAction); @@ -84,7 +84,7 @@ public class NavigationTreeShowPopupHandler implements KeyListener, MouseListene // clean popup popup.removeAll(); popup.setLabel(selectedNode.toString()); - ContentUI selectedContentUI = contentUIManager.getSelectedContentUI(); + ContentUI selectedContentUI = dataSourceEditorModel.getContent(); ContentUIHandler<?> handler = selectedContentUI.getHandler(); int length = 0; List<AbstractButton> actions = handler.getNavigationPopupActions(); @@ -187,7 +187,7 @@ public class NavigationTreeShowPopupHandler implements KeyListener, MouseListene // try to change selection TreePath pathForRow = tree.getPathForRow(closestRowForLocation); - if (pathForRow==null) { + if (pathForRow == null) { e.consume(); return; } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/NavigationUIInitializer.java ===================================== @@ -23,6 +23,7 @@ package fr.ird.observe.client.datasource.editor.api.navigation; */ import fr.ird.observe.client.configuration.NavigationTreeConfigBean; +import fr.ird.observe.client.datasource.editor.api.DataSourceEditorModel; import fr.ird.observe.client.datasource.editor.api.content.ContentUIManager; import fr.ird.observe.client.datasource.editor.api.navigation.actions.ConfigureMenuAction; import fr.ird.observe.client.util.init.UIInitHelper; @@ -115,9 +116,10 @@ class NavigationUIInitializer extends UIInitializerSupport<NavigationUI, UIIniti editor.setCellRenderer(new NavigationTreeCellRenderer()); editor.getModel().loadConfig(); NavigationUI ui = initializerContext.getUi(); + DataSourceEditorModel dataSourceEditorModel = Objects.requireNonNull(ui.getContextValue(DataSourceEditorModel.class)); ContentUIManager contentUIManager = Objects.requireNonNull(ui.getContextValue(ContentUIManager.class)); - editor.installShowPopupHandler(new NavigationTreeShowPopupHandler(contentUIManager, editor, ui.getNavigationPopup(), ui.getNoAction())); - NavigationTreeSelectionListenerImpl selectionListener = new NavigationTreeSelectionListenerImpl(contentUIManager, ui, editor); + editor.installShowPopupHandler(new NavigationTreeShowPopupHandler(dataSourceEditorModel, editor, ui.getNavigationPopup(), ui.getNoAction())); + NavigationTreeSelectionListenerImpl selectionListener = new NavigationTreeSelectionListenerImpl(dataSourceEditorModel, contentUIManager, ui, editor); editor.addNavigationTreeSelectionListener(selectionListener); editor.addTreeWillExpandListener(selectionListener); editor.addTreeSelectionListener(selectionListener); ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/root/RootNavigationNode.java ===================================== @@ -104,9 +104,9 @@ public class RootNavigationNode extends NavigationNode { public NavigationNode findNodeFromPreviousSelectedNode(NavigationNode oldSelectedNode) { NavigationNode result = this; TreeNode[] pathToRoot = oldSelectedNode.getPath(); - for (int i = 1; i < pathToRoot.length; i++) { + for (TreeNode treeNode : pathToRoot) { NavigationNode next; - NavigationNode oldNode = (NavigationNode) pathToRoot[i]; + NavigationNode oldNode = (NavigationNode) treeNode; if (oldNode.getScope().isSelectNode()) { next = result.findChildByType(oldNode.getClass(), oldNode.getInitializer().getSelectNodeId()); } else { ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/RouteCloseCallback.java ===================================== @@ -146,7 +146,7 @@ public class RouteCloseCallback implements EditNodeCloseCallback, WithClientUICo parentNode.addEmptyActivityUINavigationNode(); // on récupère l'écran d'édition - ActivityUI selectedUI = (ActivityUI) dataSourceEditor.getContentUIManager().getSelectedContentUI(); + ActivityUI selectedUI = (ActivityUI) dataSourceEditor.getModel().getContent(); // on recupère l'activité de fin de veille VesselActivityReference vesselActivitySeine = null; ===================================== models/dto/src/main/models/Observe-01-referential-common.model ===================================== @@ -58,7 +58,7 @@ longitude + {*:1} Float | mayNotNull quadrant + {*:1} Integer | mayNotNull country {*:0..1} fr.ird.observe.dto.referential.common.CountryReference | notNull -referential.common.LengthLengthParameter > referential.common.LengthFormulaSupport | references=uri,oceanLabel,sexLabel,species,startDate,endDate,inputSizeMeasureType,outputSizeMeasureType,inputOutputFormula,outputInputFormula +referential.common.LengthLengthParameter > referential.common.LengthFormulaSupport >> reference.ReferentialDtoReferenceWithNoCodeAware | references=uri,oceanLabel,sexLabel,species,startDate,endDate,inputSizeMeasureType,outputSizeMeasureType,inputOutputFormula,outputInputFormula inputOutputFormula + {*:1} String | notNull inputOutputFormulaValid + {*:1} boolean outputInputFormula + {*:1} String | notNull @@ -66,7 +66,7 @@ outputInputFormulaValid + {*:1} boolean inputSizeMeasureType {*:1} fr.ird.observe.dto.referential.common.SizeMeasureTypeReference | notNull outputSizeMeasureType {*:1} fr.ird.observe.dto.referential.common.SizeMeasureTypeReference | notNull -referential.common.LengthWeightParameter > referential.common.LengthFormulaSupport | references=uri,oceanLabel,sexLabel,species,startDate,endDate,lengthWeightFormula,weightLengthFormula,sizeMeasureType +referential.common.LengthWeightParameter > referential.common.LengthFormulaSupport >> reference.ReferentialDtoReferenceWithNoCodeAware | references=uri,oceanLabel,sexLabel,species,startDate,endDate,lengthWeightFormula,weightLengthFormula,sizeMeasureType lengthWeightFormula + {*:1} String | notNull weightLengthFormula + {*:1} String | notNull meanLength + {*:1} Float | strictlyPositiveNumber View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/95c108a128ade08e284ab2a49... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/95c108a128ade08e284ab2a49... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT