This is an automated email from the git hooks/post-receive script. New commit to branch feature/17 in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit 229fa8db240ffe4875ffb22dd5135da98e1c116f Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Dec 21 11:53:25 2016 +0100 L'action créer une activité longline depuis l'écran des activités ne fonctionne pas (Closes #17, Closes #13) --- .../ui/actions/content/CloseAndCreateUIAction.java | 56 ++++++---- .../ui/actions/content/CreateOpenUIAction.java | 3 +- .../application/swing/ui/content/ContentUI.jaxx | 4 + .../swing/ui/content/ContentUIHandler.java | 117 +++++++++------------ .../ui/content/list/ContentListUIHandler.java | 3 +- .../ui/content/open/ContentOpenableUIHandler.java | 14 +-- 6 files changed, 93 insertions(+), 104 deletions(-) diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseAndCreateUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseAndCreateUIAction.java index eaaa9fe..2233b08 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseAndCreateUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CloseAndCreateUIAction.java @@ -32,8 +32,6 @@ import fr.ird.observe.application.swing.ui.content.open.impl.longline.ActivityLo import fr.ird.observe.application.swing.ui.content.open.impl.seine.ActivitySeineUI; import fr.ird.observe.application.swing.ui.tree.navigation.NavigationTree; import fr.ird.observe.application.swing.ui.tree.navigation.nodes.NavigationTreeNodeSupport; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; -import fr.ird.observe.services.dto.seine.ActivitySeineDto; import javax.swing.tree.TreePath; @@ -69,30 +67,37 @@ public class CloseAndCreateUIAction extends AbstractContentUIAction { return; } + DataContext dataContext = getMainUI().getDataContext(); if (ui instanceof ActivitySeinesUI) { - // cas particulier pour l'écran des activitys + // cas particulier pour l'écran des activités + + if (!dataContext.isOpenActivitySeine()) { + + ui.createData(); + return; + } NavigationTree tree = getMainUI().getNavigation(); - boolean wasCollapsed = isOpenActivityNodeCollapsed(tree, getMainUI().getDataContext()); + boolean wasCollapsed = isOpenActivityNodeCollapsed(tree, dataContext); - // selection du noeud de l'activity ouverte + // selection du noeud de l'activité ouverte getMainUI().getMenuNavigationActivity().doClick(); NavigationTreeNodeSupport selectedNode = tree.getSelectedNode(); - selectedNode = tree.getActivitySeineNode(selectedNode, getMainUI().getDataContext().getOpenActivitySeineId()); + selectedNode = tree.getActivitySeineNode(selectedNode, dataContext.getOpenActivitySeineId()); tree.selectNode(selectedNode); - // on conserve le path de l'activity + // on conserve le path de l'activité TreePath path = tree.getSelectionPath(); // recuperation de l'écran associé ActivitySeineUI selectedUI = (ActivitySeineUI) ObserveSwingApplicationContext.get().getContentUIManager().getSelectedContentUI(); - // fermeture de l'activity et création d'une nouvelle + // fermeture de l'activité et création d'une nouvelle selectedUI.closeAndCreateData(); if (wasCollapsed) { @@ -107,26 +112,31 @@ public class CloseAndCreateUIAction extends AbstractContentUIAction { if (ui instanceof ActivityLonglinesUI) { - // cas particulier pour l'écran des activitys + // cas particulier pour l'écran des activités + + if (!dataContext.isOpenActivityLongline()) { + + ui.createData(); + return; + } NavigationTree tree = getMainUI().getNavigation(); - boolean wasCollapsed = isOpenActivityNodeCollapsed(tree, getMainUI().getDataContext()); + boolean wasCollapsed = isOpenActivityNodeCollapsed(tree, dataContext); // selection du noeud de l'activity ouverte NavigationTreeNodeSupport selectedNode = tree.getSelectedNode(); - selectedNode = tree.getActivityLonglineNode(selectedNode, getMainUI().getDataContext().getOpenActivitySeineId()); + selectedNode = tree.getActivityLonglineNode(selectedNode, dataContext.getOpenActivitySeineId()); tree.selectNode(selectedNode); -// tree.selectOpenNode(ActivityLonglineDto.class); - // on conserve le path de l'activity + // on conserve le path de l'activité TreePath path = tree.getSelectionPath(); // recuperation de l'écran associé ActivityLonglineUI selectedUI = (ActivityLonglineUI) ObserveSwingApplicationContext.get().getContentUIManager().getSelectedContentUI(); - // fermeture de l'activity et création d'une nouvelle + // fermeture de l'activité et création d'une nouvelle selectedUI.closeAndCreateData(); if (wasCollapsed) { @@ -146,17 +156,21 @@ public class CloseAndCreateUIAction extends AbstractContentUIAction { // on regarde si le noeud de l'activité ouverte est collapsé - NavigationTreeNodeSupport node = tree.getSelectedNode(); - - TreePath path = tree.getSelectionPath(); + if (dataContext.isOpenActivity()) { - String id = dataContext.getOpenActivityId(); + NavigationTreeNodeSupport node = tree.getSelectedNode(); + TreePath path = tree.getSelectionPath(); - NavigationTreeNodeSupport node1 = tree.getChild(node, id); + String id = dataContext.getOpenActivityId(); + NavigationTreeNodeSupport node1 = tree.getChild(node, id); - TreePath activityPath = path.pathByAddingChild(node1); + if (node1 != null) { + TreePath activityPath = path.pathByAddingChild(node1); + return tree.isCollapsed(activityPath); + } + } - return tree.isCollapsed(activityPath); + return false; } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CreateOpenUIAction.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CreateOpenUIAction.java index 6c8ab92..feb847d 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CreateOpenUIAction.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/actions/content/CreateOpenUIAction.java @@ -44,8 +44,7 @@ public class CreateOpenUIAction extends AbstractContentUIAction { protected void actionPerformed(ContentUI<?, ?> contentUI) { if (contentUI instanceof ContentListUI) { - ContentListUI ui = (ContentListUI) contentUI; - ui.getHandler().addChild(); + contentUI.createData(); } } } diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUI.jaxx index e6a4e8c..07f70cf 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUI.jaxx @@ -124,6 +124,10 @@ public void delete() { getHandler().deleteUI(); } +public void createData() { + getHandler().createDataUI(); +} + ]]> </script> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIHandler.java index 384ae44..3cb348c 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ContentUIHandler.java @@ -80,6 +80,7 @@ import javax.swing.JPopupMenu; import javax.swing.JTextField; import javax.swing.JToolBar; import javax.swing.SpringLayout; +import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.border.TitledBorder; import java.awt.Component; @@ -315,22 +316,10 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U return ObserveSwingApplicationContext.get().getDecoratorService(); } - public void initUI() { - -// new ContentUIInitializer<>(ui).initUI(); -// -// getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_FORM, evt -> updateUiWithReferenceSetsFromModel()); -// -// installFocusTraversalPolicy(); - -// addFocusabelOnForm(); - - } - public void destroyUI() { UIHelper.removeAllDataBindings(getUi()); getModel().destroy(); - UIHelper.destroy((Component) getUi()); + UIHelper.destroy(getUi()); DefaultJAXXContext delegateContext = (DefaultJAXXContext) getUi().getDelegateContext(); delegateContext.clear(); } @@ -339,55 +328,6 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U ObserveSwingApplicationContext.get().getFocusManager().installFocusTraversalPolicy(ui); } -// protected void addFocusabelOnForm() { -// getModel().addPropertyChangeListener(ContentUIModel.PROPERTY_MODE, evt -> updateFocusable((ContentMode) evt.getNewValue())); -// updateFocusable(ContentMode.READ); -// } - -// public void updateFocusable(ContentMode newMode) { -// if (newMode == null) { -// return; -// } -// switch (newMode) { -// case CREATE: -// case UPDATE: -// ui.get$objectMap().values().stream().filter(o -> o instanceof JComponent).forEach(o -> { -// JComponent component = (JComponent) o; -// if (BooleanUtils.isTrue((Boolean) component.getClientProperty("protectFocus"))) { -// return; -// } -// if (component instanceof BeanComboBox) { -// BeanComboBox beanComboBox = (BeanComboBox) component; -// component = beanComboBox.getCombobox(); -// } -// Boolean focusable = (Boolean) component.getClientProperty("_focusable"); -// component.setFocusable(BooleanUtils.isTrue(focusable)); -// -// }); -// break; -// case READ: -// -// // remove all focusables -// ui.get$objectMap().values().stream().filter(o -> o instanceof JComponent).forEach(o -> { -// JComponent component = (JComponent) o; -// if (BooleanUtils.isTrue((Boolean) component.getClientProperty("protectFocus"))) { -// return; -// } -// if (component instanceof BeanComboBox) { -// BeanComboBox beanComboBox = (BeanComboBox) component; -// component = beanComboBox.getCombobox(); -// } -// boolean focusable = component.isFocusable(); -// if (focusable) { -// component.putClientProperty("_focusable", true); -// component.setFocusable(false); -// } -// -// }); -// break; -// } -// } - public void openUI() { boolean canWrite = computeCanWrite(getDataSource()); @@ -415,9 +355,49 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U updateActions(); + grabFocusOnform(); + + } + + /** + * Clôturer la marée ouverte puis en créer une nouvelle. + * + * @since 1.5 + */ + public void createDataUI() { + + // création d'une nouvelle donnée + + NavigationTree treeHelper = getTreeHelper(getUi()); + + treeHelper.reloadSelectedNode(false, true); + + NavigationTreeNodeSupport parentNode = treeHelper.getSelectedNode().getParent(); + if (log.isDebugEnabled()) { + log.debug("PARENT NODE = " + parentNode); + } + treeHelper.addUnsavedNode(parentNode, getBeanType()); + } + + protected void grabFocusOnform() { ObserveMainUI mainUI = ObserveSwingApplicationContext.get().getMainUI(); boolean focusOnNavigation = mainUI.getModel().isFocusOnNavigation(); - if (!focusOnNavigation) { + if (focusOnNavigation) { + SwingUtilities.invokeLater(() -> { + Component focusOwner = mainUI.getFocusOwner(); + if (!mainUI.getNavigation().equals(focusOwner)) { + + SwingUtilities.invokeLater(() -> { + mainUI.getNavigation().requestFocusInWindow(); + + if (log.isInfoEnabled()) { + log.info("Focus old owner: " + focusOwner); + log.info("Focus new owner: " + mainUI.getFocusOwner()); + } + }); + } + }); + } else { FocusTraversalPolicy focusTraversalPolicy = ui.getFocusTraversalPolicy(); if (focusTraversalPolicy != null) { JComponent firstComponent = (JComponent) focusTraversalPolicy.getFirstComponent(ui); @@ -456,6 +436,10 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U UIHelper.processDataBinding(ui, binding); } UIHelper.processDataBinding(ui, "reset.enabled", "save.enabled"); + + if (ui.getModel().isCreatingMode()) { + grabFocusOnform(); + } } public void stopEditUI() { @@ -526,6 +510,8 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U ui.startEdit(null); updateActions(); + + grabFocusOnform(); } protected final void saveUI(boolean refresh) { @@ -743,10 +729,7 @@ public abstract class ContentUIHandler<E extends IdDto, U extends ContentUI<E, U } protected boolean askToDelete(E bean) { - boolean accept = - UIHelper.confirmForEntityDelete(ui, getBeanType(), bean); - - return !accept; + return !UIHelper.confirmForEntityDelete(ui, getBeanType(), bean); } protected void afterDelete() { diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/list/ContentListUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/list/ContentListUIHandler.java index 3e7ebde..c5dd5a6 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/list/ContentListUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/list/ContentListUIHandler.java @@ -215,7 +215,8 @@ public abstract class ContentListUIHandler<E extends IdDto, C extends DataDto, U getUi().getShowTechnicalInformations().setEnabled(false); } - public void addChild() { + @Override + public void createDataUI() { NavigationTree treeHelper = getTreeHelper(ui); NavigationTreeNodeSupport parentNode = treeHelper.getSelectedNode(); treeHelper.addUnsavedNode(parentNode, getModel().getChildType()); diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/ContentOpenableUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/ContentOpenableUIHandler.java index bc2c5d9..78e33a5 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/ContentOpenableUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/open/ContentOpenableUIHandler.java @@ -99,8 +99,6 @@ public abstract class ContentOpenableUIHandler<E extends IdDto, U extends Conten // on repaint le parent (le program devient alors ouvert) NavigationTree treeHelper = getTreeHelper(ui); treeHelper.reloadSelectedNode(true, true); -// ObserveNode node = treeHelper.getSelectedNode(); -// treeHelper.refreshNode(node.getParent(), true); // on chage l'état 'canReopen' du model ui.getModel().setCanReopen(false); @@ -230,17 +228,7 @@ public abstract class ContentOpenableUIHandler<E extends IdDto, U extends Conten stopEditUI(); - // création d'une nouvelle donnée - - NavigationTree treeHelper = getTreeHelper(getUi()); - - treeHelper.reloadSelectedNode(false, true); - - NavigationTreeNodeSupport parentNode = treeHelper.getSelectedNode().getParent(); - if (log.isDebugEnabled()) { - log.debug("PARENT NODE = " + parentNode); - } - treeHelper.addUnsavedNode(parentNode, getBeanType()); + createDataUI(); } protected final void obtainChildPosition(E bean) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.