Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe

Commits:

20 changed files:

Changes:

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/ContentUIHandler.java
    ... ... @@ -30,10 +30,10 @@ import fr.ird.observe.client.datasource.api.ObserveSwingDataSource;
    30 30
     import fr.ird.observe.client.datasource.editor.api.DataSourceEditor;
    
    31 31
     import fr.ird.observe.client.datasource.editor.api.content.actions.ContentUIActionSupport;
    
    32 32
     import fr.ird.observe.client.datasource.editor.api.content.actions.ResetForm;
    
    33
    +import fr.ird.observe.client.datasource.editor.api.content.actions.create.CreateNewContentTableUIEntry;
    
    33 34
     import fr.ird.observe.client.datasource.editor.api.content.actions.open.ContentOpen;
    
    34 35
     import fr.ird.observe.client.datasource.editor.api.content.data.table.ContentTableUI;
    
    35 36
     import fr.ird.observe.client.datasource.editor.api.content.data.table.ContentTableUIModel;
    
    36
    -import fr.ird.observe.client.datasource.editor.api.content.data.table.actions.CreateNewContentTableUIEntry;
    
    37 37
     import fr.ird.observe.client.datasource.editor.api.content.referential.ContentReferentialUII18nHelper;
    
    38 38
     import fr.ird.observe.client.datasource.editor.api.content.spi.ContentUIReferenceCache;
    
    39 39
     import fr.ird.observe.client.datasource.editor.api.content.spi.ReferentialReferencesFilter;
    
    ... ... @@ -124,7 +124,7 @@ public abstract class ContentUIHandler<U extends ContentUI> implements ObserveSe
    124 124
         private final Map<ContentTableUI<?, ?, ?>, JPanel> subUiMap = new LinkedHashMap<>();
    
    125 125
         protected String prefix;
    
    126 126
         protected U ui;
    
    127
    -    protected ImmutableSet<CreateNewContentTableUIEntry<?, ?>> newContentTableUIEntries;
    
    127
    +    protected ImmutableSet<CreateNewContentTableUIEntry<?>> newContentTableUIEntries;
    
    128 128
         private ObserveLayoutFocusTraversalPolicy<U> focusTraversalPolicy;
    
    129 129
         private boolean init;
    
    130 130
         private JTabbedPaneValidator tabbedPaneValidator;
    
    ... ... @@ -308,6 +308,18 @@ public abstract class ContentUIHandler<U extends ContentUI> implements ObserveSe
    308 308
             installChangeModeAction();
    
    309 309
             NodeCapability<?> capability = ui.getModel().getSource().getCapability();
    
    310 310
             if (capability instanceof ContainerCapability) {
    
    311
    +//            newContentOpenableUIEntries = CreateNewOpenableUI.installOpenableCreateActions(ui, (ContainerCapability<?>) capability);
    
    312
    +//            if (newContentOpenableUIEntries != null) {
    
    313
    +//                getModel().getStates().addPropertyChangeListener(evt -> {
    
    314
    +//                    String propertyName = evt.getPropertyName();
    
    315
    +//                    if (propertyName.equals(ContentUIModelStates.PROPERTY_UPDATING_MODE) ||
    
    316
    +//                            propertyName.equals(ContentUIModelStates.PROPERTY_MODIFIED)) {
    
    317
    +//                        ContentUIModelStates source = (ContentUIModelStates) evt.getSource();
    
    318
    +//                        boolean enabled = source.isUpdatingMode() && !source.isModified();
    
    319
    +//                        source.firePropertyChange(CreateNewOpenableUI.PROPERTY_NAME_UPDATING_MODE_AND_NOT_MODIFIED, enabled);
    
    320
    +//                    }
    
    321
    +//                });
    
    322
    +//            }
    
    311 323
                 newContentTableUIEntries = CreateNewContentTableUIEntry.installTableCreateActions(ui, (ContainerCapability<?>) capability);
    
    312 324
                 if (newContentTableUIEntries != null) {
    
    313 325
                     getModel().getStates().addPropertyChangeListener(evt -> {
    
    ... ... @@ -320,6 +332,7 @@ public abstract class ContentUIHandler<U extends ContentUI> implements ObserveSe
    320 332
                         }
    
    321 333
                     });
    
    322 334
                 }
    
    335
    +
    
    323 336
             }
    
    324 337
     //        if (ui.getConfigurePopup().getSubElements().length == 0) {
    
    325 338
     //            ui.getToggleConfigure().setEnabled(false);
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/InsertMenuAction.java
    ... ... @@ -34,6 +34,7 @@ import javax.swing.JPopupMenu;
    34 34
      * @since 8.0.1
    
    35 35
      */
    
    36 36
     public interface InsertMenuAction<U extends ContentUI> extends MenuAction {
    
    37
    +    String PROPERTY_NAME_UPDATING_MODE_AND_NOT_MODIFIED = "updatingModeAndNotModified";
    
    37 38
     
    
    38 39
         U getUi();
    
    39 40
     
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/table/actions/CreateNewContentTableUIEntry.javaclient/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/create/CreateNewContentTableUIEntry.java
    1
    -package fr.ird.observe.client.datasource.editor.api.content.data.table.actions;
    
    1
    +package fr.ird.observe.client.datasource.editor.api.content.actions.create;
    
    2 2
     
    
    3 3
     /*-
    
    4 4
      * #%L
    
    ... ... @@ -47,26 +47,26 @@ import java.awt.event.ActionEvent;
    47 47
     import java.util.function.Function;
    
    48 48
     
    
    49 49
     /**
    
    50
    - * To create a new entry from the outised world.
    
    50
    + * To create a new table data entry from the outside world.
    
    51 51
      * <p>
    
    52 52
      * Created on 26/11/2020.
    
    53 53
      *
    
    54 54
      * @author Tony Chemit - dev@tchemit.fr
    
    55 55
      * @since 8.0.1
    
    56 56
      */
    
    57
    -public class CreateNewContentTableUIEntry<N extends ContentTableUINavigationNode, U extends ContentUI> extends ContentUIActionSupport<U> implements InsertMenuAction<U> {
    
    58
    -    public static final String PROPERTY_NAME_UPDATING_MODE_AND_NOT_MODIFIED = "updatingModeAndNotModified";
    
    57
    +public class CreateNewContentTableUIEntry<U extends ContentUI> extends ContentUIActionSupport<U> implements InsertMenuAction<U> {
    
    58
    +
    
    59 59
         private static final Logger log = LogManager.getLogger(CreateNewContentTableUIEntry.class);
    
    60
    -    private final Function<NavigationNode, N> getNode;
    
    60
    +    private final Function<NavigationNode, NavigationNode> getNode;
    
    61 61
     
    
    62
    -    public static <N extends ContentTableUINavigationNode, U extends ContentUI> CreateNewContentTableUIEntry<N, U> installAction(U ui, AbstractButton editor, SimpleDtoServiceContext<?, ?> spi, Function<NavigationNode, N> getNode) {
    
    63
    -        CreateNewContentTableUIEntry<N, U> action = new CreateNewContentTableUIEntry<>(spi, getNode);
    
    62
    +    public static <U extends ContentUI> CreateNewContentTableUIEntry<U> installAction(U ui, AbstractButton editor, SimpleDtoServiceContext<?, ?> spi, Function<NavigationNode, NavigationNode> getNode) {
    
    63
    +        CreateNewContentTableUIEntry<U> action = new CreateNewContentTableUIEntry<>(spi, getNode);
    
    64 64
             init(ui, editor, action);
    
    65 65
             return action;
    
    66 66
         }
    
    67 67
     
    
    68
    -    public static ImmutableSet<CreateNewContentTableUIEntry<?, ?>> installTableCreateActions(ContentUI ui, ContainerCapability<?> capability) {
    
    69
    -        ImmutableSet.Builder<CreateNewContentTableUIEntry<?, ?>> builder = ImmutableSet.builder();
    
    68
    +    public static ImmutableSet<CreateNewContentTableUIEntry<?>> installTableCreateActions(ContentUI ui, ContainerCapability<?> capability) {
    
    69
    +        ImmutableSet.Builder<CreateNewContentTableUIEntry<?>> builder = ImmutableSet.builder();
    
    70 70
             for (Class<? extends NavigationNode> acceptedNodeType : capability.getAcceptedNodeTypes()) {
    
    71 71
                 if (ContentTableUINavigationNode.class.isAssignableFrom(acceptedNodeType)) {
    
    72 72
                     @SuppressWarnings("unchecked") Class<? extends ContentTableUINavigationNode> nodeType = (Class<? extends ContentTableUINavigationNode>) acceptedNodeType;
    
    ... ... @@ -85,7 +85,7 @@ public class CreateNewContentTableUIEntry<N extends ContentTableUINavigationNode
    85 85
             return builder.build();
    
    86 86
         }
    
    87 87
     
    
    88
    -    public CreateNewContentTableUIEntry(SimpleDtoServiceContext<?, ?> spi, Function<NavigationNode, N> getNode) {
    
    88
    +    public CreateNewContentTableUIEntry(SimpleDtoServiceContext<?, ?> spi, Function<NavigationNode, NavigationNode> getNode) {
    
    89 89
             super(null, null, "add", null);
    
    90 90
             this.getNode = getNode;
    
    91 91
             Class<? extends DataDto> dtoType = spi.getDtoType();
    
    ... ... @@ -97,7 +97,7 @@ public class CreateNewContentTableUIEntry<N extends ContentTableUINavigationNode
    97 97
         @Override
    
    98 98
         protected void doActionPerformed(ActionEvent e, U ui) {
    
    99 99
             NavigationTree tree = getDataSourceEditor().getNavigationUI().getTree();
    
    100
    -        N selectedNode = getNode.apply(tree.getSelectedNode());
    
    100
    +        NavigationNode selectedNode = getNode.apply(tree.getSelectedNode());
    
    101 101
             tree.selectSafeNode(selectedNode);
    
    102 102
             ContentTableUI<?, ?, ?> newContentUI = (ContentTableUI<?, ?, ?>) getDataSourceEditor().getContentUIManager().getSelectedContentUI();
    
    103 103
             newContentUI.getNewEntry().doClick();
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/open/actions/CreateNewOpenable.javaclient/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/create/CreateNewOpenableUI.java
    1
    -package fr.ird.observe.client.datasource.editor.api.content.data.open.actions;
    
    1
    +package fr.ird.observe.client.datasource.editor.api.content.actions.create;
    
    2 2
     
    
    3 3
     /*-
    
    4 4
      * #%L
    
    ... ... @@ -22,16 +22,24 @@ package fr.ird.observe.client.datasource.editor.api.content.data.open.actions;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    +import com.google.common.collect.ImmutableSet;
    
    25 26
     import fr.ird.observe.client.datasource.editor.api.DataSourceEditor;
    
    27
    +import fr.ird.observe.client.datasource.editor.api.content.ContentUI;
    
    28
    +import fr.ird.observe.client.datasource.editor.api.content.actions.ContentUIActionSupport;
    
    26 29
     import fr.ird.observe.client.datasource.editor.api.content.actions.InsertMenuAction;
    
    27 30
     import fr.ird.observe.client.datasource.editor.api.content.actions.mode.ChangeMode;
    
    31
    +import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUI;
    
    28 32
     import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUII18nHelper;
    
    29 33
     import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUINavigationNode;
    
    30 34
     import fr.ird.observe.client.datasource.editor.api.content.data.open.ContentOpenableUI;
    
    31 35
     import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTree;
    
    32 36
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNode;
    
    37
    +import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationScope;
    
    38
    +import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationScopes;
    
    39
    +import fr.ird.observe.client.datasource.editor.api.navigation.tree.capability.ContainerCapability;
    
    33 40
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.capability.ReferenceContainerCapability;
    
    34 41
     import fr.ird.observe.client.util.DtoIconHelper;
    
    42
    +import fr.ird.observe.dto.IdDto;
    
    35 43
     import fr.ird.observe.dto.data.DataDto;
    
    36 44
     import fr.ird.observe.dto.reference.DataDtoReference;
    
    37 45
     import fr.ird.observe.spi.context.OpenableDtoServiceContext;
    
    ... ... @@ -41,30 +49,86 @@ import org.apache.logging.log4j.LogManager;
    41 49
     import org.apache.logging.log4j.Logger;
    
    42 50
     
    
    43 51
     import javax.swing.AbstractButton;
    
    52
    +import javax.swing.JMenuItem;
    
    44 53
     import java.awt.event.ActionEvent;
    
    45
    -import java.util.Objects;
    
    46 54
     import java.util.function.Function;
    
    55
    +import java.util.function.Predicate;
    
    47 56
     
    
    48 57
     /**
    
    49
    - * Created on 11/11/16.
    
    58
    + * To create a new openable data from the outside world.
    
    59
    + * Created on 03/12/2020.
    
    50 60
      *
    
    51 61
      * @author Tony Chemit - dev@tchemit.fr
    
    52
    - * @since 6.0
    
    62
    + * @since 8.0.1
    
    53 63
      */
    
    54
    -public final class CreateNewOpenable<R extends DataDtoReference, D extends DataDto, U extends ContentOpenableUI<D, U>> extends ContentOpenableUIActionSupport<D, U> implements InsertMenuAction<U> {
    
    64
    +public class CreateNewOpenableUI<D extends DataDto, U extends ContentUI> extends ContentUIActionSupport<U> implements InsertMenuAction<U> {
    
    55 65
     
    
    56
    -    private static final Logger log = LogManager.getLogger(CreateNewOpenable.class);
    
    66
    +    private static final Logger log = LogManager.getLogger(CreateNewOpenableUI.class);
    
    67
    +    private final OpenableDtoServiceContext<D, ?, ?> spi;
    
    68
    +    private final Function<NavigationNode, NavigationNode> getNode;
    
    69
    +    private final Predicate<Class<D>> typePredicate;
    
    57 70
     
    
    58
    -    private final OpenableDtoServiceContext<?, R, ?> spi;
    
    59
    -    private final Function<NavigationNode, NavigationNode> beforeNodeFunction;
    
    71
    +    public static ImmutableSet<CreateNewOpenableUI<?, ?>> installOpenableCreateActions(ContentUI ui, ContainerCapability<?> capability) {
    
    72
    +        ImmutableSet.Builder<CreateNewOpenableUI<?, ?>> builder = ImmutableSet.builder();
    
    73
    +        for (Class<? extends NavigationNode> acceptedNodeType : capability.getAcceptedNodeTypes()) {
    
    74
    +            if (ContentListUINavigationNode.class.isAssignableFrom(acceptedNodeType)) {
    
    75
    +                JMenuItem editor = new JMenuItem();
    
    76
    +                NavigationScope navigationScope = NavigationScopes.getNavigationScope(acceptedNodeType);
    
    77
    +                @SuppressWarnings("unchecked") Class<? extends ContentListUINavigationNode> nodeType = (Class<? extends ContentListUINavigationNode>) acceptedNodeType;
    
    78
    +                OpenableDtoServiceContext<?, ?, ?> spi = navigationScope.computeOpenSpi();
    
    79
    +                String fieldName = "add" + acceptedNodeType.getSimpleName().replace("UINavigationNode", "");
    
    80
    +                editor.setName(fieldName);
    
    81
    +                ui.getModel().getStates().addPropertyChangeListener(PROPERTY_NAME_UPDATING_MODE_AND_NOT_MODIFIED, evt -> editor.setEnabled((Boolean) evt.getNewValue()));
    
    82
    +                log.debug("Create new action: " + fieldName);
    
    83
    +                ui.get$objectMap().put(editor.getName(), editor);
    
    84
    +                Function<NavigationNode, NavigationNode> getNode = n -> n.findChildByType(nodeType);
    
    85
    +                builder.add(installAction(ui, editor, spi, getNode));
    
    86
    +            }
    
    87
    +        }
    
    88
    +        return builder.build();
    
    89
    +    }
    
    90
    +
    
    91
    +    public static <D extends DataDto, U extends ContentOpenableUI< ?, ?>> CreateNewOpenableUI<D, U> installAction2(U ui, Class<? extends NavigationNode> acceptedNodeType, Class<D> dtoType, Predicate<Class<D>> typePredicate) {
    
    92
    +        JMenuItem editor = new JMenuItem();
    
    93
    +        NavigationScope navigationScope = NavigationScopes.getNavigationScope(acceptedNodeType);
    
    94
    +        @SuppressWarnings("unchecked") Class<? extends ContentListUINavigationNode> nodeType = (Class<? extends ContentListUINavigationNode>) acceptedNodeType;
    
    95
    +        OpenableDtoServiceContext<D, ?, ?> spi = navigationScope.computeOpenSpi();
    
    96
    +        String fieldName = "add" + acceptedNodeType.getSimpleName().replace("UINavigationNode", "");
    
    97
    +        editor.setName(fieldName);
    
    98
    +        ui.getModel().getStates().addPropertyChangeListener(PROPERTY_NAME_UPDATING_MODE_AND_NOT_MODIFIED, evt -> editor.setEnabled((Boolean) evt.getNewValue()));
    
    99
    +        log.debug("Create new action: " + fieldName);
    
    100
    +        ui.get$objectMap().put(editor.getName(), editor);
    
    101
    +        Function<NavigationNode, NavigationNode> getNode = n -> n.findChildByType(nodeType);
    
    102
    +
    
    103
    +        CreateNewOpenableUI<D, U> action = new CreateNewOpenableUI<>(spi, getNode, typePredicate);
    
    104
    +        init(ui, ui.getCreate(), action);
    
    105
    +        return action;
    
    106
    +    }
    
    107
    +
    
    108
    +    public static <D extends DataDto, U extends ContentListUI<?, ?, ?>> CreateNewOpenableUI<D, U> installAction(U ui, Predicate<Class<D>> typePredicate) {
    
    109
    +        CreateNewOpenableUI<D, U> action = new CreateNewOpenableUI<>(ui.getModel().getScope().computeOpenSpi(), Function.identity(), typePredicate);
    
    110
    +        init(ui, ui.getCreate(), action);
    
    111
    +        return action;
    
    112
    +    }
    
    60 113
     
    
    61
    -    public static <D extends DataDto, U extends ContentOpenableUI<D, U>> void installAction(U ui) {
    
    62
    -        installAction(ui, ui.getCreate(), ui.getModel().getSource().getSpi(), t -> t);
    
    114
    +    public static <D extends DataDto, U extends ContentOpenableUI<D, U>> CreateNewOpenableUI<D, U> installAction(U ui, Predicate<Class<D>> typePredicate) {
    
    115
    +        CreateNewOpenableUI<D, U> action = new CreateNewOpenableUI<>(ui.getModel().getScope().computeOpenSpi(), Function.identity(), typePredicate);
    
    116
    +        init(ui, ui.getCreate(), action);
    
    117
    +        return action;
    
    63 118
         }
    
    64 119
     
    
    65
    -    public static <R extends DataDtoReference, D extends DataDto, U extends ContentOpenableUI<D, U>> void installAction(U ui, AbstractButton editor, OpenableDtoServiceContext<?, R, ?> spi, Function<NavigationNode, NavigationNode> beforeNodeFunction) {
    
    66
    -        CreateNewOpenable<R, D, U> action = new CreateNewOpenable<>(ui.getModel().getSource().getScope().getMainType(), spi, beforeNodeFunction);
    
    120
    +    public static <D extends DataDto, U extends ContentOpenableUI<D, U>> CreateNewOpenableUI<D, U> installAction(U ui) {
    
    121
    +        return installAction(ui, t -> true);
    
    122
    +    }
    
    123
    +
    
    124
    +    public static <D extends DataDto, U extends ContentListUI<?, ?, ?>> CreateNewOpenableUI<D, U> installAction(U ui) {
    
    125
    +        return installAction(ui, t -> true);
    
    126
    +    }
    
    127
    +
    
    128
    +    public static <D extends DataDto, U extends ContentUI> CreateNewOpenableUI<D, U> installAction(U ui, AbstractButton editor, OpenableDtoServiceContext<D, ?, ?> spi, Function<NavigationNode, NavigationNode> getNode) {
    
    129
    +        CreateNewOpenableUI<D, U> action = new CreateNewOpenableUI<>(spi, getNode, t -> true);
    
    67 130
             init(ui, editor, action);
    
    131
    +        return action;
    
    68 132
         }
    
    69 133
     
    
    70 134
         public static void closeAndCreate(DataSourceEditor dataSourceEditor, NavigationNode parentNode, NavigationTree tree, EditNode<?> editNode, DataDtoReference reference) {
    
    ... ... @@ -79,24 +143,28 @@ public final class CreateNewOpenable<R extends DataDtoReference, D extends DataD
    79 143
             }
    
    80 144
         }
    
    81 145
     
    
    82
    -    public CreateNewOpenable(Class<D> dataType, OpenableDtoServiceContext<?, R, ?> spi, Function<NavigationNode, NavigationNode> beforeNodeFunction) {
    
    83
    -        super(dataType, null, null, null, null);
    
    84
    -        this.spi = Objects.requireNonNull(spi);
    
    85
    -        this.beforeNodeFunction = Objects.requireNonNull(beforeNodeFunction);
    
    146
    +    public CreateNewOpenableUI(OpenableDtoServiceContext<D, ?, ?> spi, Function<NavigationNode, NavigationNode> getNode, Predicate<Class<D>> typePredicate) {
    
    147
    +        super(null, null, "add", null);
    
    148
    +        this.spi = spi;
    
    149
    +        this.getNode = getNode;
    
    150
    +        this.typePredicate = typePredicate;
    
    86 151
             Class<? extends DataDto> dtoType = spi.getDtoType();
    
    87 152
             setIcon(DtoIconHelper.getIcon(dtoType));
    
    88 153
             setText(ContentListUII18nHelper.getListActionCreate(dtoType));
    
    89
    -        setTooltipText(ContentListUII18nHelper.getListActionCreateTip(dtoType));
    
    154
    +        setTooltipText(ContentListUII18nHelper.getListActionCreate(dtoType));
    
    90 155
         }
    
    91 156
     
    
    92 157
         @Override
    
    93
    -    protected void doActionPerformed(ActionEvent event, U ui) {
    
    94
    -        NavigationTree tree = getDataSourceEditor().getNavigationUI().getTree();
    
    95
    -        NavigationNode selectedNode = beforeNodeFunction.apply(tree.getSelectedNode());
    
    96
    -        Class<? extends DataDtoReference> referenceType = selectedNode.getScope().getMainReferenceType();
    
    97
    -        ContentListUINavigationNode parentNode = (ContentListUINavigationNode) selectedNode.upToReferenceContainerNode(referenceType);
    
    98
    -        DataDtoReference newReference = spi.newReference(ui.getModel().getClientUIContext().getDecoratorService().getReferentialLocale());
    
    99
    -        closeAndCreate(getDataSourceEditor(), parentNode, tree, selectedNode.getInitializer().getEditNode(), newReference);
    
    158
    +    protected boolean canExecuteAction(ActionEvent e) {
    
    159
    +        return super.canExecuteAction(e) && (typePredicate == null || typePredicate.test(spi.getDtoType()));
    
    100 160
         }
    
    101 161
     
    
    162
    +    @Override
    
    163
    +    protected void doActionPerformed(ActionEvent e, U ui) {
    
    164
    +        NavigationTree tree = getDataSourceEditor().getNavigationUI().getTree();
    
    165
    +        NavigationNode parentNode = getNode.apply(tree.getSelectedNode());
    
    166
    +        EditNode<? extends IdDto> editNode = parentNode.getInitializer().getEditNode();
    
    167
    +        DataDtoReference newReference = spi.newReference(parentNode.getInitializer().getReferentialLocale());
    
    168
    +        closeAndCreate(getDataSourceEditor(), parentNode, tree, editNode, newReference);
    
    169
    +    }
    
    102 170
     }

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/mode/ChangeMode.java
    ... ... @@ -79,7 +79,7 @@ public class ChangeMode<U extends ContentUI> extends ContentUIActionSupport<U> {
    79 79
         }
    
    80 80
     
    
    81 81
         public static void closeData(DataSourceEditor dataSourceEditor, EditNode<?> nodeToClose) throws CloseEditNodeVetoException {
    
    82
    -        if (nodeToClose.isDisabled()) {
    
    82
    +        if (Objects.requireNonNull(nodeToClose).isDisabled()) {
    
    83 83
                 return;
    
    84 84
             }
    
    85 85
             ClientUIContext clientUIContext = ClientUIContextApplicationComponent.value();
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/mode/ChangeModeExecutor.java
    ... ... @@ -57,62 +57,45 @@ public class ChangeModeExecutor<U extends ContentUI> {
    57 57
     
    
    58 58
         protected void doClose(U ui, DataSourceEditor dataSourceEditor, ChangeModeRequest request) {
    
    59 59
             try {
    
    60
    -            EditNode<?> editNode = ui.getModel().getSource().getInitializer().getEditNode();
    
    60
    +            SelectNode<?> selectedNode = request.getSelectNode(ui);
    
    61
    +            EditNode<?> editNode = request.getEditNode(ui);
    
    62
    +            String id = request.getSelectedId(ui, selectedNode);
    
    63
    +            log.info(String.format("Will close: %s → (select: %s - edit: %s)", id, selectedNode, editNode));
    
    61 64
                 ChangeMode.closeData(dataSourceEditor, editNode);
    
    62 65
                 if (ui.getModel().getStates().isUpdatingMode()) {
    
    63 66
                     ui.stopEdit();
    
    64 67
                 }
    
    65 68
                 afterClose(ui, dataSourceEditor);
    
    66
    -            //FIXME See what does it means ?
    
    67
    -//            getMainUI().getHandler().updateContentSize();
    
    68 69
             } catch (CloseEditNodeVetoException e1) {
    
    69 70
                 log.error("Could not close data from callback", e1);
    
    70
    -//            UIHelper.handlingError(e1);
    
    71 71
             }
    
    72 72
         }
    
    73 73
     
    
    74 74
         protected void doOpen(U ui, DataSourceEditor dataSourceEditor, ChangeModeRequest request) {
    
    75
    -
    
    76
    -        SelectNode<?> selectedNode = request.getSelectNode(ui);
    
    77
    -        EditNode<?> editNode = request.getEditNode(ui);
    
    78
    -        String id = request.getSelectedId(ui, selectedNode);
    
    79
    -        log.info(String.format("Will open: %s → %s", id, selectedNode));
    
    80
    -        NavigationTree tree = dataSourceEditor.getNavigationUI().getTree();
    
    81
    -        NavigationNode previousOpenedNode = editNode.isEnabled() ? tree.getRootNode().findNode(editNode) : null;
    
    82 75
             try {
    
    76
    +            SelectNode<?> selectedNode = request.getSelectNode(ui);
    
    77
    +            EditNode<?> editNode = request.getEditNode(ui);
    
    78
    +            String id = request.getSelectedId(ui, selectedNode);
    
    79
    +            log.info(String.format("Will open: %s → (select: %s - edit: %s)", id, selectedNode, editNode));
    
    80
    +            NavigationTree tree = dataSourceEditor.getNavigationUI().getTree();
    
    81
    +            NavigationNode previousOpenedNode = editNode.isEnabled() ? tree.getRootNode().findNode(editNode) : null;
    
    83 82
                 ChangeMode.openData(editNode, selectedNode, id);
    
    84 83
                 afterOpen(dataSourceEditor, previousOpenedNode, id);
    
    85 84
             } catch (CloseEditNodeVetoException e1) {
    
    86 85
                 log.error("Could not close data from callback", e1);
    
    87
    -            //UIHelper.handlingError(e1);
    
    88 86
             }
    
    89 87
         }
    
    90 88
     
    
    91 89
         protected void afterClose(U ui, DataSourceEditor dataSourceEditor) {
    
    92
    -
    
    93
    -//        ContentOpenableUIModel<D> model = ui.getModel();
    
    94
    -//        D bean = model.getStates().getBean();
    
    95
    -
    
    96 90
             ui.stopEdit();
    
    97
    -
    
    98
    -//        model.setMode(ContentMode.READ);
    
    99
    -//        removeAllMessages(ui);
    
    100
    -//        String closeMessage = ContentOpenableUII18nHelper.getMessageNotOpen(model.getScope().getMainType());
    
    101
    -//        ContentUIHandler.addMessage(ui, NuitonValidatorScope.INFO, ContentOpenableUII18nHelper.getType(bean.getClass()), closeMessage);
    
    102
    -
    
    103 91
             NavigationTree tree = dataSourceEditor.getNavigationUI().getTree();
    
    104
    -
    
    105 92
             NavigationNode node = tree.getSelectedNode();
    
    106 93
             node.getParent().refreshToRoot();
    
    107 94
             node.nodeChangedDeep();
    
    108
    -//        if (node.getLevel() > 1) {
    
    109
    -//            tree.selectSafeNode(node.getParent());
    
    110
    -//        }
    
    95
    +
    
    111 96
             log.info("Will reselect node: " + node);
    
    112 97
             SwingUtilities.invokeLater(() -> tree.reSelectSafeNode(node));
    
    113 98
     
    
    114
    -//        ui.getHandler().updateActions();
    
    115
    -
    
    116 99
             //FIXME Focus forcing!!!
    
    117 100
     //        ui.getHandler().grabFocusOnForm();
    
    118 101
     
    
    ... ... @@ -120,12 +103,6 @@ public class ChangeModeExecutor<U extends ContentUI> {
    120 103
     
    
    121 104
         protected void afterOpen(DataSourceEditor dataSourceEditor, NavigationNode previousOpenedNode, String id) {
    
    122 105
     
    
    123
    -//        ui.stopEdit();
    
    124
    -//        ui.getModel().setMode(ContentMode.UPDATE);
    
    125
    -//
    
    126
    -//        // On charge les ensembles de références utilisées dans les combobox
    
    127
    -//        ui.getModel().updateUiWithReferenceSetsFromModel();
    
    128
    -
    
    129 106
             // on repaint le parent (le program devient alors ouvert)
    
    130 107
             NavigationTree tree = dataSourceEditor.getNavigationUI().getTree();
    
    131 108
     
    
    ... ... @@ -137,19 +114,12 @@ public class ChangeModeExecutor<U extends ContentUI> {
    137 114
             if (previousOpenedNode == null || !Objects.equals(previousOpenedNode.getParent(), selectedNode.getParent())) {
    
    138 115
                 selectedNode.getParent().refreshToRoot();
    
    139 116
             }
    
    117
    +        selectedNode.reloadNodeData();
    
    140 118
             selectedNode.nodeChangedDeep();
    
    141
    -//        if (selectedNode.getLevel() > 1) {
    
    142
    -//            tree.selectSafeNode(selectedNode.getParent());
    
    143
    -//        }
    
    144
    -        afterOpenReselectNode(tree, id);
    
    145
    -//        ContentUIHandler.removeAllMessages(ui);
    
    146
    -//
    
    147
    -//        // on lance l'édition
    
    148
    -//        ui.startEdit();
    
    119
    +        afterOpenReselectNode(tree, selectedNode, id);
    
    149 120
         }
    
    150 121
     
    
    151
    -    protected void afterOpenReselectNode(NavigationTree tree, String id) {
    
    152
    -        NavigationNode selectedNode = tree.getSelectedNode();
    
    122
    +    protected void afterOpenReselectNode(NavigationTree tree, NavigationNode selectedNode, String id) {
    
    153 123
             log.info("Will reselect node: " + selectedNode);
    
    154 124
             SwingUtilities.invokeLater(() -> tree.reSelectSafeNode(selectedNode));
    
    155 125
         }
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/edit/ContentEditUINavigationNode.java
    ... ... @@ -90,12 +90,14 @@ public abstract class ContentEditUINavigationNode extends NavigationNode {
    90 90
             if (notPersisted) {
    
    91 91
                 getInitializer().updateSelectNodeId(id);
    
    92 92
             }
    
    93
    -        if (notPersisted) {
    
    93
    +        // reload node data first
    
    94
    +        reloadNodeData();
    
    95
    +
    
    96
    +        if (notPersisted && isContainer()) {
    
    97
    +            // can now load children if any
    
    94 98
                 dirty();
    
    95 99
                 populateChildrenIfNotLoaded();
    
    96 100
             }
    
    97
    -        // reload node data
    
    98
    -        reloadNodeData();
    
    99 101
     
    
    100 102
             ReferenceContainerCapability<?> capability = (ReferenceContainerCapability<?>) parent.getCapability();
    
    101 103
             int newPosition = capability.getNodePosition(reference);
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/list/ContentListUIHandler.java
    ... ... @@ -125,8 +125,7 @@ public abstract class ContentListUIHandler<D extends DataDto, R extends DataDtoR
    125 125
             ChangeModeRequest request = ui.getModel().toChangeModeRequest();
    
    126 126
             ChangeModeExecutor<U> executor = new ChangeModeExecutor<U>() {
    
    127 127
                 @Override
    
    128
    -            protected void afterOpenReselectNode(NavigationTree tree, String id) {
    
    129
    -                NavigationNode selectedNode = tree.getSelectedNode();
    
    128
    +            protected void afterOpenReselectNode(NavigationTree tree, NavigationNode selectedNode, String id) {
    
    130 129
                     Class<? extends DataDtoReference> referenceType = ui.getModel().getSource().getScope().getMainReferenceType();
    
    131 130
                     NavigationNode referenceNode = tree.getSelectedNode().downToReferenceNode(referenceType, id);
    
    132 131
                     log.info(String.format("Will reselect node: %s", selectedNode));
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/list/actions/CreateNew.java deleted
    1
    -package fr.ird.observe.client.datasource.editor.api.content.data.list.actions;
    
    2
    -
    
    3
    -/*-
    
    4
    - * #%L
    
    5
    - * ObServe Client :: DataSource :: Editor :: API
    
    6
    - * %%
    
    7
    - * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
    
    8
    - * %%
    
    9
    - * This program is free software: you can redistribute it and/or modify
    
    10
    - * it under the terms of the GNU General Public License as
    
    11
    - * published by the Free Software Foundation, either version 3 of the
    
    12
    - * License, or (at your option) any later version.
    
    13
    - *
    
    14
    - * This program is distributed in the hope that it will be useful,
    
    15
    - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    - * GNU General Public License for more details.
    
    18
    - *
    
    19
    - * You should have received a copy of the GNU General Public
    
    20
    - * License along with this program.  If not, see
    
    21
    - * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    - * #L%
    
    23
    - */
    
    24
    -
    
    25
    -import fr.ird.observe.client.datasource.editor.api.content.actions.InsertMenuAction;
    
    26
    -import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUI;
    
    27
    -import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUII18nHelper;
    
    28
    -import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUIModel;
    
    29
    -import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUINavigationNode;
    
    30
    -import fr.ird.observe.client.datasource.editor.api.content.data.open.actions.CreateNewOpenable;
    
    31
    -import fr.ird.observe.client.datasource.editor.api.navigation.NavigationTree;
    
    32
    -import fr.ird.observe.client.util.DtoIconHelper;
    
    33
    -import fr.ird.observe.dto.data.DataDto;
    
    34
    -import fr.ird.observe.dto.reference.DataDtoReference;
    
    35
    -
    
    36
    -import java.awt.event.ActionEvent;
    
    37
    -import java.util.Objects;
    
    38
    -import java.util.function.Predicate;
    
    39
    -
    
    40
    -/**
    
    41
    - * Created on 11/11/16.
    
    42
    - *
    
    43
    - * @author Tony Chemit - dev@tchemit.fr
    
    44
    - * @since 6.0
    
    45
    - */
    
    46
    -public final class CreateNew<D extends DataDto, R extends DataDtoReference, U extends ContentListUI<D, R, U>> extends ContentListUIActionSupport<D, R, U> implements InsertMenuAction<U> {
    
    47
    -
    
    48
    -    private final Predicate<Class<D>> typePredicate;
    
    49
    -
    
    50
    -    public static <D extends DataDto, R extends DataDtoReference, U extends ContentListUI<D, R, U>> void installAction(U ui) {
    
    51
    -        installAction(ui, t -> true);
    
    52
    -    }
    
    53
    -
    
    54
    -    public static <D extends DataDto, R extends DataDtoReference, U extends ContentListUI<D, R, U>> void installAction(U ui, Predicate<Class<D>> typePredicate) {
    
    55
    -        CreateNew<D, R, U> action = new CreateNew<>(ui.getModel().getSource().getScope().getMainType(), typePredicate);
    
    56
    -        init(ui, Objects.requireNonNull(ui).getCreate(), action);
    
    57
    -    }
    
    58
    -
    
    59
    -    protected CreateNew(Class<D> dataType, Predicate<Class<D>> typePredicate) {
    
    60
    -        super(dataType, null, null, "add", null);
    
    61
    -        this.typePredicate = typePredicate;
    
    62
    -        setText(ContentListUII18nHelper.getListActionCreate(dataType));
    
    63
    -        setTooltipText(ContentListUII18nHelper.getListActionCreateTip(dataType));
    
    64
    -        setIcon(DtoIconHelper.getIcon(dataType));
    
    65
    -    }
    
    66
    -
    
    67
    -    @Override
    
    68
    -    protected boolean canExecuteAction(ActionEvent e) {
    
    69
    -        return super.canExecuteAction(e) && (typePredicate == null || typePredicate.test(getDataType()));
    
    70
    -    }
    
    71
    -
    
    72
    -    @Override
    
    73
    -    protected void doActionPerformed(ActionEvent e, U ui) {
    
    74
    -        NavigationTree tree = getDataSourceEditor().getNavigationUI().getTree();
    
    75
    -        ContentListUIModel<D, R> model = ui.getModel();
    
    76
    -        ContentListUINavigationNode parentNode = (ContentListUINavigationNode) tree.getSelectedNode();
    
    77
    -        DataDtoReference newReference = parentNode.getSpi().newReference(parentNode.getInitializer().getReferentialLocale());
    
    78
    -        CreateNewOpenable.closeAndCreate(getDataSourceEditor(), parentNode, tree, model.getSource().getInitializer().getEditNode(), newReference);
    
    79
    -    }
    
    80
    -}

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/open/ContentOpenableUIHandler.java
    ... ... @@ -26,7 +26,6 @@ import fr.ird.observe.client.datasource.editor.api.content.actions.ResetForm;
    26 26
     import fr.ird.observe.client.datasource.editor.api.content.actions.id.ShowTechnicalInformations;
    
    27 27
     import fr.ird.observe.client.datasource.editor.api.content.actions.mode.ChangeMode;
    
    28 28
     import fr.ird.observe.client.datasource.editor.api.content.actions.open.ContentOpen;
    
    29
    -import fr.ird.observe.client.datasource.editor.api.content.data.open.actions.CreateNewOpenable;
    
    30 29
     import fr.ird.observe.client.datasource.editor.api.content.data.open.actions.DeleteOpenable;
    
    31 30
     import fr.ird.observe.client.datasource.editor.api.content.data.open.actions.SaveOpenable;
    
    32 31
     import fr.ird.observe.dto.data.DataDto;
    
    ... ... @@ -40,6 +39,8 @@ public abstract class ContentOpenableUIHandler<D extends DataDto, U extends Cont
    40 39
     
    
    41 40
         protected abstract void installMoveAction();
    
    42 41
     
    
    42
    +    protected abstract void installCreateNewAction();
    
    43
    +
    
    43 44
         @Override
    
    44 45
         public ContentOpenableUIModel<D> getModel() {
    
    45 46
             return ui.getModel();
    
    ... ... @@ -62,7 +63,7 @@ public abstract class ContentOpenableUIHandler<D extends DataDto, U extends Cont
    62 63
     
    
    63 64
         @Override
    
    64 65
         protected void initActions() {
    
    65
    -        installCreateAction();
    
    66
    +        installCreateNewAction();
    
    66 67
             installResetAction();
    
    67 68
             installSaveAction();
    
    68 69
             installMoveAction();
    
    ... ... @@ -75,10 +76,6 @@ public abstract class ContentOpenableUIHandler<D extends DataDto, U extends Cont
    75 76
             ChangeMode.installAction(ui);
    
    76 77
         }
    
    77 78
     
    
    78
    -    protected void installCreateAction() {
    
    79
    -        CreateNewOpenable.installAction(ui);
    
    80
    -    }
    
    81
    -
    
    82 79
         protected void installSaveAction() {
    
    83 80
             SaveOpenable.installAction(ui);
    
    84 81
         }
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/NavigationHandler.java
    ... ... @@ -86,17 +86,26 @@ public abstract class NavigationHandler<N extends NavigationNode> {
    86 86
             return getIcon(getNode().getScope().isSubNode());
    
    87 87
         }
    
    88 88
     
    
    89
    +    /**
    
    90
    +     * @return {@code true} if this node can build some children
    
    91
    +     */
    
    89 92
         public boolean canBuildChildren() {
    
    90
    -        return getNode().isNotLoaded() && getNode().isContainer();
    
    93
    +        return getNode().isContainer();
    
    91 94
         }
    
    92 95
     
    
    96
    +    /**
    
    97
    +     * @return {@code true} if this node can load his children while opening
    
    98
    +     */
    
    93 99
         public boolean canLoadChildrenOnOpen() {
    
    94
    -        // by default no sub loading
    
    95
    -        return getNode().isContainer() && getNode().getRoot().getHandler().canLoadChildrenOnOpen();
    
    100
    +        // by default no sub loading except if loadChildrenOnOpen configuration property is on
    
    101
    +        return canBuildChildren() && getNode().getRoot().getHandler().canLoadChildrenOnOpen();
    
    96 102
         }
    
    97 103
     
    
    98 104
         public void open() {
    
    99 105
             N node = getNode();
    
    106
    +        // We can't predicate if structure was modified, so let's always refresh internal states
    
    107
    +        //FIXME Find a way to make this more smooth (listen datasource modification API (to create!!!))
    
    108
    +        node.dirtyStructure();
    
    100 109
             node.getContext().open();
    
    101 110
             if (node.isLoaded()) {
    
    102 111
                 // already loaded, nothing more to do
    
    ... ... @@ -107,7 +116,7 @@ public abstract class NavigationHandler<N extends NavigationNode> {
    107 116
             }
    
    108 117
             node.loaded();
    
    109 118
     
    
    110
    -        if (canLoadChildrenOnOpen()) {
    
    119
    +        if (node.isRoot() || canLoadChildrenOnOpen()) {
    
    111 120
                 Enumeration<?> children = getNode().children();
    
    112 121
                 while (children.hasMoreElements()) {
    
    113 122
                     NavigationNode childrenNode = (NavigationNode) children.nextElement();
    
    ... ... @@ -126,13 +135,6 @@ public abstract class NavigationHandler<N extends NavigationNode> {
    126 135
             return getNode().getChildCount();
    
    127 136
         }
    
    128 137
     
    
    129
    -//    public void init() {
    
    130
    -    // nothing to do by default
    
    131
    -//        if (getNode().getScope().isAutoLoad()) {
    
    132
    -//            getNode().loaded();
    
    133
    -//        }
    
    134
    -//    }
    
    135
    -
    
    136 138
         public final Icon getIcon(boolean small) {
    
    137 139
             String iconPath = getNode().getScope().getIconPath();
    
    138 140
             return DtoIconHelper.getIcon(Objects.requireNonNull(iconPath), small);
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/NavigationNode.java
    ... ... @@ -180,8 +180,16 @@ public abstract class NavigationNode extends DefaultMutableTreeNode implements W
    180 180
         }
    
    181 181
     
    
    182 182
         public final void dirty() {
    
    183
    +        if (isNotLoaded()) {
    
    184
    +            // Avoid re-entrant code
    
    185
    +            return;
    
    186
    +        }
    
    183 187
             loaded = false;
    
    184 188
             log.info(String.format("%s Make dirty node %s", getInitializer().getLogPrefix(), this));
    
    189
    +        dirtyStructure();
    
    190
    +    }
    
    191
    +
    
    192
    +    public void dirtyStructure() {
    
    185 193
             withPrevious.clear();
    
    186 194
             withNext.clear();
    
    187 195
             previous.clear();
    
    ... ... @@ -189,6 +197,10 @@ public abstract class NavigationNode extends DefaultMutableTreeNode implements W
    189 197
         }
    
    190 198
     
    
    191 199
         public final void loaded() {
    
    200
    +        if (isLoaded()) {
    
    201
    +            // Avoid re-entrant code
    
    202
    +            return;
    
    203
    +        }
    
    192 204
             loaded = true;
    
    193 205
             // when node is loaded, refresh ui
    
    194 206
             getTreeModel().ifPresent(t -> nodeChanged());
    
    ... ... @@ -309,6 +321,7 @@ public abstract class NavigationNode extends DefaultMutableTreeNode implements W
    309 321
         }
    
    310 322
     
    
    311 323
         public final void reloadNodeData() {
    
    324
    +        dirty();
    
    312 325
             Object userObject = getContext().reload();
    
    313 326
             setUserObject(userObject);
    
    314 327
             loaded();
    
    ... ... @@ -327,9 +340,9 @@ public abstract class NavigationNode extends DefaultMutableTreeNode implements W
    327 340
         //--------------------------------------------------------------------------------------------
    
    328 341
     
    
    329 342
         public final void updateNode() {
    
    330
    -        dirty();
    
    331 343
             reloadNodeData();
    
    332 344
             removeAllChildren();
    
    345
    +        dirty();
    
    333 346
             populateChildrenIfNotLoaded();
    
    334 347
             loaded();
    
    335 348
         }
    
    ... ... @@ -366,22 +379,6 @@ public abstract class NavigationNode extends DefaultMutableTreeNode implements W
    366 379
             }
    
    367 380
         }
    
    368 381
     
    
    369
    -    //--------------------------------------------------------------------------------------------
    
    370
    -    // Modify structure methods
    
    371
    -    //--------------------------------------------------------------------------------------------
    
    372
    -
    
    373
    -    public boolean isAdjusting() {
    
    374
    -        return adjusting;
    
    375
    -    }
    
    376
    -
    
    377
    -    public void adjusting() {
    
    378
    -        this.adjusting = true;
    
    379
    -    }
    
    380
    -
    
    381
    -    public void unAdjusting() {
    
    382
    -        this.adjusting = false;
    
    383
    -    }
    
    384
    -
    
    385 382
         public final void refreshToRoot() {
    
    386 383
             if (!isRoot()) {
    
    387 384
                 log.info(String.format("Refresh to Root node: %s", this));
    
    ... ... @@ -398,6 +395,22 @@ public abstract class NavigationNode extends DefaultMutableTreeNode implements W
    398 395
             }
    
    399 396
         }
    
    400 397
     
    
    398
    +    //--------------------------------------------------------------------------------------------
    
    399
    +    // Modify structure methods
    
    400
    +    //--------------------------------------------------------------------------------------------
    
    401
    +
    
    402
    +    public boolean isAdjusting() {
    
    403
    +        return adjusting;
    
    404
    +    }
    
    405
    +
    
    406
    +    public void adjusting() {
    
    407
    +        this.adjusting = true;
    
    408
    +    }
    
    409
    +
    
    410
    +    public void unAdjusting() {
    
    411
    +        this.adjusting = false;
    
    412
    +    }
    
    413
    +
    
    401 414
         @Override
    
    402 415
         public void insert(MutableTreeNode newChild, int childIndex) {
    
    403 416
             Optional<NavigationTreeModel> treeModel = getTreeModel();
    

  • client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/LlTripActionHelper.java
    ... ... @@ -24,7 +24,6 @@ package fr.ird.observe.client.datasource.editor.ll.data;
    24 24
     
    
    25 25
     import fr.ird.observe.client.datasource.editor.api.content.ContentUI;
    
    26 26
     import fr.ird.observe.client.datasource.editor.api.content.data.TripActionHelper;
    
    27
    -import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUI;
    
    28 27
     import fr.ird.observe.dto.data.DataDto;
    
    29 28
     import fr.ird.observe.dto.data.ll.common.TripReference;
    
    30 29
     
    
    ... ... @@ -38,15 +37,15 @@ import java.util.function.Predicate;
    38 37
      */
    
    39 38
     public class LlTripActionHelper extends TripActionHelper {
    
    40 39
     
    
    41
    -    public static <D extends DataDto> Predicate<Class<D>> createNewLandingActionPredicate(ContentListUI<D, ?, ?> ui) {
    
    40
    +    public static <D extends DataDto> Predicate<Class<D>> createNewLandingActionPredicate(ContentUI ui) {
    
    42 41
             return (Class<D> r) -> new LlTripActionHelper(ui).gotoTripLogbookTab();
    
    43 42
         }
    
    44 43
     
    
    45
    -    public static <D extends DataDto> Predicate<Class<D>> createNewLogbookActionPredicate(ContentListUI<D, ?, ?> ui) {
    
    44
    +    public static <D extends DataDto> Predicate<Class<D>> createNewLogbookActionPredicate(ContentUI ui) {
    
    46 45
             return (Class<D> r) -> new LlTripActionHelper(ui).gotoTripLogbookTab();
    
    47 46
         }
    
    48 47
     
    
    49
    -    public static <D extends DataDto> Predicate<Class<D>> createNewObservationActionPredicate(ContentListUI<D, ?, ?> ui) {
    
    48
    +    public static <D extends DataDto> Predicate<Class<D>> createNewObservationActionPredicate(ContentUI ui) {
    
    50 49
             return (Class<D> r) -> new LlTripActionHelper(ui).gotoTripObservationTab();
    
    51 50
         }
    
    52 51
     
    

  • client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/logbook/ActivitySampleUIMoveTreeAdapter.java
    ... ... @@ -38,7 +38,7 @@ public class ActivitySampleUIMoveTreeAdapter extends DefaultSingleMoveTreeAdapte
    38 38
         public static void moveFromActivityToActivity(NavigationTree tree, ActivitySampleUINavigationNode referenceNode, String activityId) {
    
    39 39
             ActivityUINavigationNode newContainerNode = referenceNode.getParent().getParent()
    
    40 40
                     .getActivityUINavigationNode(activityId);
    
    41
    -        newContainerNode.refreshToRoot();
    
    41
    +        newContainerNode.updateNode();
    
    42 42
             ActivitySampleUINavigationNode node = newContainerNode.getActivitySampleUINavigationNode();
    
    43 43
             tree.selectSafeNode(node);
    
    44 44
         }
    
    ... ... @@ -46,7 +46,7 @@ public class ActivitySampleUIMoveTreeAdapter extends DefaultSingleMoveTreeAdapte
    46 46
         public static void moveFromTripToActivity(NavigationTree tree, SampleUINavigationNode referenceNode, String activityId) {
    
    47 47
             ActivityUINavigationNode newContainerNode = referenceNode.getParent().getParent()
    
    48 48
                     .getLogbookActivityListUINavigationNode().getActivityUINavigationNode(activityId);
    
    49
    -        newContainerNode.reloadNodeData();
    
    49
    +        newContainerNode.updateNode();
    
    50 50
             ActivitySampleUINavigationNode node = newContainerNode.getActivitySampleUINavigationNode();
    
    51 51
             tree.selectSafeNode(node);
    
    52 52
         }
    

  • client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/PsTripActionHelper.java
    ... ... @@ -24,7 +24,6 @@ package fr.ird.observe.client.datasource.editor.ps.data;
    24 24
     
    
    25 25
     import fr.ird.observe.client.datasource.editor.api.content.ContentUI;
    
    26 26
     import fr.ird.observe.client.datasource.editor.api.content.data.TripActionHelper;
    
    27
    -import fr.ird.observe.client.datasource.editor.api.content.data.list.ContentListUI;
    
    28 27
     import fr.ird.observe.dto.data.DataDto;
    
    29 28
     import fr.ird.observe.dto.data.ps.common.TripReference;
    
    30 29
     
    
    ... ... @@ -40,11 +39,11 @@ public class PsTripActionHelper extends TripActionHelper {
    40 39
     
    
    41 40
         // Ready for v9
    
    42 41
         @SuppressWarnings("unused")
    
    43
    -    public static <D extends DataDto> Predicate<Class<D>> createNewLogbookActionPredicate(ContentListUI<D, ?, ?> ui) {
    
    42
    +    public static <D extends DataDto> Predicate<Class<D>> createNewLogbookActionPredicate(ContentUI ui) {
    
    44 43
             return (Class<D> r) -> new PsTripActionHelper(ui).gotoTripLogbookTab();
    
    45 44
         }
    
    46 45
     
    
    47
    -    public static <D extends DataDto> Predicate<Class<D>> createNewObservationActionPredicate(ContentListUI<D, ?, ?> ui) {
    
    46
    +    public static <D extends DataDto> Predicate<Class<D>> createNewObservationActionPredicate(ContentUI ui) {
    
    48 47
             return (Class<D> r) -> new PsTripActionHelper(ui).gotoTripObservationTab();
    
    49 48
         }
    
    50 49
     
    

  • client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/common/TripUIHandler.java
    ... ... @@ -21,12 +21,11 @@
    21 21
      */
    
    22 22
     package fr.ird.observe.client.datasource.editor.ps.data.common;
    
    23 23
     
    
    24
    +import fr.ird.observe.client.datasource.editor.api.content.actions.create.CreateNewOpenableUI;
    
    24 25
     import fr.ird.observe.client.datasource.editor.api.content.data.TripUIHelper;
    
    25 26
     import fr.ird.observe.client.datasource.editor.api.content.data.open.ContentOpenableUILayoutFocusTraversalPolicy;
    
    26
    -import fr.ird.observe.client.datasource.editor.api.content.data.open.actions.CreateNewOpenable;
    
    27 27
     import fr.ird.observe.client.datasource.editor.api.content.spi.ContentUIReferenceCache;
    
    28 28
     import fr.ird.observe.client.datasource.editor.ps.data.observation.ActivityUINavigationNode;
    
    29
    -import fr.ird.observe.client.datasource.editor.ps.data.observation.RouteUINavigationNode;
    
    30 29
     import fr.ird.observe.dto.data.ps.common.TripDto;
    
    31 30
     import fr.ird.observe.dto.form.Form;
    
    32 31
     
    
    ... ... @@ -61,16 +60,12 @@ class TripUIHandler extends GeneratedTripUIHandler {
    61 60
         }
    
    62 61
     
    
    63 62
         @Override
    
    64
    -    protected void installCreateAction() {
    
    65
    -        super.installCreateAction();
    
    66
    -        CreateNewOpenable.installAction(ui,
    
    67
    -                                        ui.getAddRoute(),
    
    68
    -                                        RouteUINavigationNode.SPI,
    
    69
    -                                        n -> ((TripUINavigationNode) n).getRouteListUINavigationNode());
    
    70
    -        CreateNewOpenable.installAction(ui,
    
    71
    -                                        ui.getAddActivity(),
    
    72
    -                                        ActivityUINavigationNode.SPI,
    
    73
    -                                        n -> ((TripUINavigationNode) n).getRouteListUINavigationNode().getRouteUINavigationNode(ui.getModel().getClientUIContext().getObserveEditModel().getPs().getObservationRoute().getId()).getActivityListUINavigationNode());
    
    63
    +    protected void installCreateNewAction() {
    
    64
    +        super.installCreateNewAction();
    
    65
    +        CreateNewOpenableUI.installAction(ui,
    
    66
    +                                          ui.getAddActivity(),
    
    67
    +                                          ActivityUINavigationNode.SPI,
    
    68
    +                                          n -> ((TripUINavigationNode) n).getRouteListUINavigationNode().getRouteUINavigationNode(ui.getModel().getClientUIContext().getObserveEditModel().getPs().getObservationRoute().getId()).getActivityListUINavigationNode());
    
    74 69
         }
    
    75 70
     
    
    76 71
         @Override
    

  • client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/RouteUIHandler.java
    ... ... @@ -22,7 +22,6 @@
    22 22
     package fr.ird.observe.client.datasource.editor.ps.data.observation;
    
    23 23
     
    
    24 24
     import fr.ird.observe.client.datasource.editor.api.content.data.open.ContentOpenableUILayoutFocusTraversalPolicy;
    
    25
    -import fr.ird.observe.client.datasource.editor.api.content.data.open.actions.CreateNewOpenable;
    
    26 25
     
    
    27 26
     import java.awt.Component;
    
    28 27
     import java.awt.Container;
    
    ... ... @@ -51,13 +50,4 @@ class RouteUIHandler extends GeneratedRouteUIHandler {
    51 50
                 }
    
    52 51
             };
    
    53 52
         }
    
    54
    -
    
    55
    -    @Override
    
    56
    -    protected void installCreateAction() {
    
    57
    -        super.installCreateAction();
    
    58
    -        CreateNewOpenable.installAction(ui,
    
    59
    -                                        ui.getAddActivity(),
    
    60
    -                                        ActivityUINavigationNode.SPI,
    
    61
    -                                        n -> ((RouteUINavigationNode) n).getActivityListUINavigationNode());
    
    62
    -    }
    
    63 53
     }

  • client/datasource/editor/spi/src/main/java/fr/ird/observe/client/datasource/editor/spi/content/CapabilityDescriptor.java
    ... ... @@ -22,9 +22,13 @@ package fr.ird.observe.client.datasource.editor.spi.content;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    +import fr.ird.observe.dto.IdDto;
    
    25 26
     import fr.ird.observe.dto.reference.DtoReference;
    
    26 27
     import fr.ird.observe.spi.module.BusinessProject;
    
    28
    +import fr.ird.observe.toolkit.dto.navigation.edit.EditNode;
    
    29
    +import org.apache.commons.lang3.StringUtils;
    
    27 30
     
    
    31
    +import java.util.List;
    
    28 32
     import java.util.Objects;
    
    29 33
     import java.util.Optional;
    
    30 34
     
    
    ... ... @@ -100,10 +104,19 @@ public class CapabilityDescriptor {
    100 104
                 "        if (reference instanceof %1$s.%2$sReference) {\n" +
    
    101 105
                 "            return actualPosition + getNode().getChildrenPosition((%1$s.%2$sReference) reference, %3$s);\n" +
    
    102 106
                 "        }\n";
    
    107
    +    public static final String INSTALL_CREATE_NEW_ACTION = "" +
    
    108
    +            "        CreateNewOpenableUI.installAction(ui);\n";
    
    109
    +    public static final String INSTALL_CREATE_NEW_ACTION_WITH_PREDICATE = "" +
    
    110
    +            "        CreateNewOpenableUI.installAction(ui, %1$s.%2$s(ui));\n";
    
    111
    +    public static final String INSTALL_CREATE_NEW_ACTION_WITH_PREDICATE2 = "" +
    
    112
    +            "        CreateNewOpenableUI.installAction2(ui, %1$s.class, %2$s.class, %3$s.%4$s(ui));\n";
    
    113
    +    public static final String INSTALL_CREATE_NEW_ACTION2 = "" +
    
    114
    +            "        CreateNewOpenableUI.installAction2(ui, %1$s.class, %2$s.class, t-> true);\n";
    
    103 115
         private final ContentNodeType contentNodeType;
    
    104 116
         private final CapacityNodeType capacityNodeType;
    
    105 117
         private final String nodeTypeName;
    
    106 118
         private final String optionalPredicate;
    
    119
    +    private final Class<? extends IdDto> optionalDtoType;
    
    107 120
         private final Class<? extends DtoReference> optionalReferenceType;
    
    108 121
         private final String nodeTypePackage;
    
    109 122
         private final String nodeTypeSimpleName;
    
    ... ... @@ -113,13 +126,46 @@ public class CapabilityDescriptor {
    113 126
             CapacityNodeType capacityNodeType = CapacityNodeType.parseKey(key);
    
    114 127
             String optionalPredicate = capacityNodeType.getPredicate(key);
    
    115 128
             Class<? extends DtoReference> optionalReferenceType = capacityNodeType.getReference(businessProject, nodeTypeName);
    
    116
    -        return new CapabilityDescriptor(contentNodeType, capacityNodeType, nodeTypeName, optionalPredicate, optionalReferenceType);
    
    129
    +        Class<? extends IdDto> optionalDtoType = contentNodeType.getDto(businessProject, nodeTypeName);
    
    130
    +        return new CapabilityDescriptor(contentNodeType, capacityNodeType, nodeTypeName, optionalPredicate, optionalDtoType, optionalReferenceType);
    
    117 131
         }
    
    118 132
     
    
    119
    -    public CapabilityDescriptor(ContentNodeType contentNodeType, CapacityNodeType capacityNodeType, String nodeTypeName, String optionalPredicate, Class<? extends DtoReference> optionalReferenceType) {
    
    133
    +    public static String generateCapabilityAddNewOpenAction(CapacityNodeType capacityNodeType, ContentNodeType contentNodeType, String nodeTypeName, List<String> imports, EditNode<?> editNode, String packageName, boolean notMainNode) {
    
    134
    +        if (contentNodeType == ContentNodeType.OPEN) {
    
    135
    +            if (notMainNode) {
    
    136
    +                if (editNode.getLevel() == 2) {
    
    137
    +                    String predicateMethodName = String.format("createNew%sActionPredicate", StringUtils.capitalize(editNode.getSubModule().getName().toLowerCase()));
    
    138
    +                    String helperName = StringUtils.capitalize(editNode.getModule().getName().toLowerCase()) + "TripActionHelper";
    
    139
    +                    imports.add(packageName.substring(0, packageName.lastIndexOf(".") + 1) + helperName);
    
    140
    +                    return String.format(INSTALL_CREATE_NEW_ACTION_WITH_PREDICATE2, nodeTypeName, editNode.getType().getName(), helperName, predicateMethodName);
    
    141
    +                }
    
    142
    +                return String.format(INSTALL_CREATE_NEW_ACTION2, nodeTypeName, editNode.getType().getName());
    
    143
    +            }
    
    144
    +            return INSTALL_CREATE_NEW_ACTION;
    
    145
    +        }
    
    146
    +        if (contentNodeType == ContentNodeType.LIST) {
    
    147
    +            if (editNode.getLevel() == 2) {
    
    148
    +                String predicateMethodName = String.format("createNew%sActionPredicate", StringUtils.capitalize(editNode.getSubModule().getName().toLowerCase()));
    
    149
    +                String helperName = StringUtils.capitalize(editNode.getModule().getName().toLowerCase()) + "TripActionHelper";
    
    150
    +                imports.add(packageName.substring(0, packageName.lastIndexOf(".") + 1) + helperName);
    
    151
    +                if (notMainNode) {
    
    152
    +                    return String.format(INSTALL_CREATE_NEW_ACTION_WITH_PREDICATE2, nodeTypeName, editNode.getType().getName(), helperName, predicateMethodName);
    
    153
    +                }
    
    154
    +                return String.format(INSTALL_CREATE_NEW_ACTION_WITH_PREDICATE, helperName, predicateMethodName);
    
    155
    +            }
    
    156
    +            if (notMainNode) {
    
    157
    +                return String.format(INSTALL_CREATE_NEW_ACTION2, nodeTypeName, editNode.getType().getName());
    
    158
    +            }
    
    159
    +            return INSTALL_CREATE_NEW_ACTION;
    
    160
    +        }
    
    161
    +        return "";
    
    162
    +    }
    
    163
    +
    
    164
    +    public CapabilityDescriptor(ContentNodeType contentNodeType, CapacityNodeType capacityNodeType, String nodeTypeName, String optionalPredicate, Class<? extends IdDto> optionalDtoType, Class<? extends DtoReference> optionalReferenceType) {
    
    120 165
             this.contentNodeType = Objects.requireNonNull(contentNodeType);
    
    121 166
             this.capacityNodeType = Objects.requireNonNull(capacityNodeType);
    
    122 167
             this.nodeTypeName = Objects.requireNonNull(nodeTypeName);
    
    168
    +        this.optionalDtoType = optionalDtoType;
    
    123 169
             int lastIndex = nodeTypeName.lastIndexOf(".");
    
    124 170
             nodeTypePackage = nodeTypeName.substring(0, lastIndex);
    
    125 171
             nodeTypeSimpleName = nodeTypeName.substring(lastIndex + 1);
    
    ... ... @@ -160,6 +206,10 @@ public class CapabilityDescriptor {
    160 206
             return optionalReferenceType;
    
    161 207
         }
    
    162 208
     
    
    209
    +    public Class<? extends IdDto> getOptionalDtoType() {
    
    210
    +        return optionalDtoType;
    
    211
    +    }
    
    212
    +
    
    163 213
         public String getOptionalReferenceTypeCleanSimpleName() {
    
    164 214
             return optionalReferenceType.getSimpleName().replace("Reference", "");
    
    165 215
         }
    
    ... ... @@ -291,6 +341,10 @@ public class CapabilityDescriptor {
    291 341
             }
    
    292 342
         }
    
    293 343
     
    
    344
    +    public String generateCapabilityAddNewOpenAction(List<String> imports, EditNode<?> editNode, String packageName, boolean notMainNode) {
    
    345
    +        return generateCapabilityAddNewOpenAction(capacityNodeType, contentNodeType, nodeTypeName, imports, editNode, packageName, notMainNode);
    
    346
    +    }
    
    347
    +
    
    294 348
         protected String getOptionalReferenceTypePackage() {
    
    295 349
             return optionalReferenceType.getPackage().getName();
    
    296 350
         }
    

  • client/datasource/editor/spi/src/main/java/fr/ird/observe/client/datasource/editor/spi/content/ContentNodeType.java
    ... ... @@ -49,6 +49,10 @@ import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNod
    49 49
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavigationContext;
    
    50 50
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavigationNode;
    
    51 51
     import fr.ird.observe.client.datasource.editor.spi.DetectContentFiles;
    
    52
    +import fr.ird.observe.dto.IdDto;
    
    53
    +import fr.ird.observe.spi.module.BusinessModule;
    
    54
    +import fr.ird.observe.spi.module.BusinessProject;
    
    55
    +import io.ultreia.java4all.lang.Objects2;
    
    52 56
     
    
    53 57
     /**
    
    54 58
      * Created on 15/11/2020.
    
    ... ... @@ -86,12 +90,22 @@ public enum ContentNodeType {
    86 90
             public boolean accept(DetectContentFiles detectContentFiles, String jaxxUiPath) {
    
    87 91
                 return detectContentFiles.isContentOpenableUI(jaxxUiPath);
    
    88 92
             }
    
    93
    +
    
    94
    +        @Override
    
    95
    +        public Class<? extends IdDto> getDto(BusinessProject businessProject, String nodeTypeName) {
    
    96
    +            return getDto0(businessProject, nodeTypeName);
    
    97
    +        }
    
    89 98
         },
    
    90 99
         LIST(ContentListUINavigationNode.class, ContentListUINavigationContext.class, ContentListUIModel.class) {
    
    91 100
             @Override
    
    92 101
             public boolean accept(DetectContentFiles detectContentFiles, String jaxxUiPath) {
    
    93 102
                 return detectContentFiles.isContentListUI(jaxxUiPath);
    
    94 103
             }
    
    104
    +
    
    105
    +        @Override
    
    106
    +        public Class<? extends IdDto> getDto(BusinessProject businessProject, String nodeTypeName) {
    
    107
    +            return getDto0(businessProject, nodeTypeName);
    
    108
    +        }
    
    95 109
         },
    
    96 110
         REFERENTIAL_HOME(ReferentialHomeUINavigationNode.class, ReferentialHomeUINavigationContext.class, ReferentialHomeUIModel.class) {
    
    97 111
             @Override
    
    ... ... @@ -139,4 +153,29 @@ public enum ContentNodeType {
    139 153
         public Class<? extends ContentUIModel> getUiModelType() {
    
    140 154
             return uiModelType;
    
    141 155
         }
    
    156
    +
    
    157
    +
    
    158
    +    public Class<? extends IdDto> getDto(BusinessProject businessProject, String nodeTypeName) {
    
    159
    +        return null;
    
    160
    +    }
    
    161
    +
    
    162
    +    Class<? extends IdDto> getDto0(BusinessProject businessProject, String nodeTypeName) {
    
    163
    +        String nodeTypePackage = nodeTypeName.substring(0, nodeTypeName.lastIndexOf("."));
    
    164
    +        BusinessModule childBusinessModule = businessProject.getBusinessModule(nodeTypePackage);
    
    165
    +        String childReferenceName = nodeTypeName
    
    166
    +                .replace("ListUI", "UI")
    
    167
    +                .replace("UINavigationNode", "")
    
    168
    +                .replace("fr.ird.observe.client.datasource.editor", "fr.ird.observe.dto")
    
    169
    +                .replace(childBusinessModule.getName() + ".", "")
    
    170
    +                .replace("referential.", "referential." + childBusinessModule.getName() + ".")
    
    171
    +                .replace("data.", "data." + childBusinessModule.getName() + ".");
    
    172
    +
    
    173
    +        String referenceTypePackage = childReferenceName.substring(0, childReferenceName.lastIndexOf('.'));
    
    174
    +        String referenceTypeSimpleName = childReferenceName.substring(childReferenceName.lastIndexOf('.') + 1) + "Dto";
    
    175
    +        if (referenceTypeSimpleName.startsWith("Activity") && !referenceTypeSimpleName.startsWith("ActivityD")) {
    
    176
    +            referenceTypeSimpleName = referenceTypeSimpleName.substring("Activity".length());
    
    177
    +        }
    
    178
    +        return Objects2.forName(referenceTypePackage + "." + referenceTypeSimpleName);
    
    179
    +    }
    
    180
    +
    
    142 181
     }

  • client/datasource/editor/spi/src/main/java/fr/ird/observe/client/datasource/editor/spi/content/helper/ContentUIHandlerHelper.java
    ... ... @@ -22,10 +22,15 @@ package fr.ird.observe.client.datasource.editor.spi.content.helper;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    -import fr.ird.observe.client.datasource.editor.api.content.data.list.actions.CreateNew;
    
    25
    +import fr.ird.observe.client.datasource.editor.api.content.actions.create.CreateNewOpenableUI;
    
    26 26
     import fr.ird.observe.client.datasource.editor.api.content.data.list.actions.MoveMultiple;
    
    27 27
     import fr.ird.observe.client.datasource.editor.api.content.data.open.actions.MoveOpenable;
    
    28
    +import fr.ird.observe.client.datasource.editor.spi.content.CapabilityDescriptor;
    
    29
    +import fr.ird.observe.client.datasource.editor.spi.content.CapacityNodeType;
    
    30
    +import fr.ird.observe.client.datasource.editor.spi.content.ContentNodeType;
    
    28 31
     import fr.ird.observe.client.datasource.editor.spi.content.GenerateContentUISupport;
    
    32
    +import fr.ird.observe.client.datasource.editor.spi.content.GenerateJavaFileSupport;
    
    33
    +import fr.ird.observe.dto.IdDto;
    
    29 34
     import fr.ird.observe.toolkit.dto.navigation.edit.EditNode;
    
    30 35
     import fr.ird.observe.toolkit.dto.navigation.select.SelectNode;
    
    31 36
     import org.apache.commons.lang3.StringUtils;
    
    ... ... @@ -63,15 +68,10 @@ public class ContentUIHandlerHelper extends ContentUIHelperSupport {
    63 68
                 "    protected void installMoveAction() {\n" +
    
    64 69
                 "        MoveMultiple.installMoveAction(ui, ui.getModel().getParentService()::%1$s);\n" +
    
    65 70
                 "    }\n\n";
    
    66
    -    public static final String INSTALL_CREATE_NEW_ACTION = "" +
    
    71
    +    public static final String INSTALL_CREATE_NEW_ACTION_METHOD = "" +
    
    67 72
                 "    @Override\n" +
    
    68 73
                 "    protected void installCreateNewAction() {\n" +
    
    69
    -            "        CreateNew.installAction(ui);\n" +
    
    70
    -            "    }\n\n";
    
    71
    -    public static final String INSTALL_CREATE_NEW_ACTION_WITH_PREDICATE = "" +
    
    72
    -            "    @Override\n" +
    
    73
    -            "    protected void installCreateNewAction() {\n" +
    
    74
    -            "        CreateNew.installAction(ui, %1$s.%2$s(ui));\n" +
    
    74
    +            "%2$s" +
    
    75 75
                 "    }\n\n";
    
    76 76
         public static final String ON_END_OPEN_UI = "" +
    
    77 77
                 "    @Override\n" +
    
    ... ... @@ -80,6 +80,39 @@ public class ContentUIHandlerHelper extends ContentUIHelperSupport {
    80 80
                 "        super.onEndOpenUI();\n" +
    
    81 81
                 "    }\n\n";
    
    82 82
     
    
    83
    +
    
    84
    +    public static String generateCreateNewAction(List<String> imports, GenerateJavaFileSupport generator, EditNode<?> editNode) {
    
    85
    +        StringBuilder createChildrenMethodBuilder = new StringBuilder();
    
    86
    +        String mainMethod = CapabilityDescriptor.generateCapabilityAddNewOpenAction(CapacityNodeType.REFERENCE, ContentNodeType.OPEN, generator.scopeBuilder.nodeType, imports, editNode, generator.packageName, false);
    
    87
    +        createChildrenMethodBuilder.append(mainMethod);
    
    88
    +        if (generator.capabilitiesDescriptor != null) {
    
    89
    +            for (CapabilityDescriptor capabilityDescriptor : generator.capabilitiesDescriptor) {
    
    90
    +                Class<? extends IdDto> dtoType = capabilityDescriptor.getOptionalDtoType();
    
    91
    +                if (dtoType == null) {
    
    92
    +                    continue;
    
    93
    +                }
    
    94
    +                EditNode<?> childEditNode = generator.editModel.forDtoType(dtoType).orElse(null);
    
    95
    +                if (childEditNode != null) {
    
    96
    +                    String addNodeMethod = capabilityDescriptor.generateCapabilityAddNewOpenAction(imports, childEditNode, generator.packageName, true);
    
    97
    +                    createChildrenMethodBuilder.append(addNodeMethod);
    
    98
    +                }
    
    99
    +            }
    
    100
    +        }
    
    101
    +        return String.format(INSTALL_CREATE_NEW_ACTION_METHOD, generator.cleanClassName, createChildrenMethodBuilder.toString());
    
    102
    +    }
    
    103
    +
    
    104
    +    public static String generateListCreateNewAction(List<String> imports, GenerateJavaFileSupport generator, EditNode<?> editNode) {
    
    105
    +        StringBuilder createChildrenMethodBuilder = new StringBuilder();
    
    106
    +        String mainMethod = CapabilityDescriptor.generateCapabilityAddNewOpenAction(CapacityNodeType.REFERENCE, ContentNodeType.OPEN, generator.scopeBuilder.nodeChildType, imports, editNode, generator.packageName, false);
    
    107
    +        createChildrenMethodBuilder.append(mainMethod);
    
    108
    +//        for (CapabilityDescriptor capabilityDescriptor : generator.capabilitiesDescriptor) {
    
    109
    +//            capabilityDescriptor.getOptionalReferenceType()
    
    110
    +//            String addNodeMethod = capabilityDescriptor.generateCapabilityAddNewOpenAction(imports, editNode, generator.packageName, true);
    
    111
    +//            createChildrenMethodBuilder.append(addNodeMethod);
    
    112
    +//        }
    
    113
    +        return String.format(INSTALL_CREATE_NEW_ACTION_METHOD, generator.cleanClassName, createChildrenMethodBuilder.toString());
    
    114
    +    }
    
    115
    +
    
    83 116
         public ContentUIHandlerHelper(GenerateContentUISupport generator) {
    
    84 117
             super(generator);
    
    85 118
         }
    
    ... ... @@ -101,7 +134,9 @@ public class ContentUIHandlerHelper extends ContentUIHelperSupport {
    101 134
                     if (editNode.getLevel() == 1) {
    
    102 135
                         methodName = "getParentBrothers";
    
    103 136
                     }
    
    137
    +                imports.add(CreateNewOpenableUI.class.getName());
    
    104 138
                     extraMethods += String.format(INSTALL_MOVE_SIMPLE_ACTION, methodName);
    
    139
    +                extraMethods += generateCreateNewAction(imports, generator, editNode);
    
    105 140
                 }
    
    106 141
                 return generate(ContentUIHandlerHelper.UI_HANDLER_GENERATED, imports, generator.cleanClassName, uiHandler, dtoType, extraMethods);
    
    107 142
             }
    
    ... ... @@ -110,20 +145,12 @@ public class ContentUIHandlerHelper extends ContentUIHelperSupport {
    110 145
             String helperName = StringUtils.capitalize(editNode.getModule().getName().toLowerCase()) + "TripActionHelper";
    
    111 146
             imports.add(generator.packageName.substring(0, generator.packageName.lastIndexOf(".") + 1) + helperName);
    
    112 147
             imports.add(MoveMultiple.class.getName());
    
    113
    -        imports.add(CreateNew.class.getName());
    
    114
    -        switch (editNode.getLevel()) {
    
    115
    -            case 1:
    
    116
    -                extraMethods += String.format(ON_END_OPEN_UI, helperName);
    
    117
    -                extraMethods += INSTALL_CREATE_NEW_ACTION;
    
    118
    -                methodName = "getParentBrothers";
    
    119
    -                break;
    
    120
    -            case 2:
    
    121
    -                String predicateMethodName = String.format("createNew%sActionPredicate", StringUtils.capitalize(editNode.getSubModule().getName().toLowerCase()));
    
    122
    -                extraMethods += String.format(INSTALL_CREATE_NEW_ACTION_WITH_PREDICATE, helperName, predicateMethodName);
    
    123
    -                break;
    
    124
    -            default:
    
    125
    -                extraMethods += INSTALL_CREATE_NEW_ACTION;
    
    148
    +        imports.add(CreateNewOpenableUI.class.getName());
    
    149
    +        if (editNode.getLevel() == 1) {
    
    150
    +            extraMethods += String.format(ON_END_OPEN_UI, helperName);
    
    151
    +            methodName = "getParentBrothers";
    
    126 152
             }
    
    153
    +        extraMethods += generateListCreateNewAction(imports, generator, editNode);
    
    127 154
             extraMethods += String.format(INSTALL_MOVE_ACTION, methodName);
    
    128 155
             return generate(ContentUIHandlerHelper.UI_HANDLER_GENERATED2, imports, generator.cleanClassName, uiHandler, dtoType, extraType, extraMethods);
    
    129 156
         }