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

Commits:

5 changed files:

Changes:

  • client-configuration/src/main/java/fr/ird/observe/client/datasource/dcp/FloatingObjectPresetsManager.java
    ... ... @@ -84,11 +84,11 @@ public class FloatingObjectPresetsManager {
    84 84
             switch (model) {
    
    85 85
                 case ps_observation:
    
    86 86
                     directory = config.getDcpPsObservationPresetsDirectory().toPath();
    
    87
    -                map = this.psObservation;
    
    87
    +                map = getPsObservationPresets();
    
    88 88
                     break;
    
    89 89
                 case ps_logbook:
    
    90 90
                     directory = config.getDcpPsLogbookPresetsDirectory().toPath();
    
    91
    -                map = this.psLogbook;
    
    91
    +                map = getPsLogbookPresets();
    
    92 92
                     break;
    
    93 93
                 default:
    
    94 94
                     throw new IllegalStateException("Can't deal with model: " + model);
    
    ... ... @@ -119,6 +119,14 @@ public class FloatingObjectPresetsManager {
    119 119
         }
    
    120 120
     
    
    121 121
         public Set<FloatingObjectPreset> getPsObservation() {
    
    122
    +        return ImmutableSet.copyOf(getPsObservationPresets().values());
    
    123
    +    }
    
    124
    +
    
    125
    +    public Set<FloatingObjectPreset> getPsLogbook() {
    
    126
    +        return ImmutableSet.copyOf(getPsLogbookPresets().values());
    
    127
    +    }
    
    128
    +
    
    129
    +    public Map<Path, FloatingObjectPreset> getPsObservationPresets() {
    
    122 130
             if (psObservation == null) {
    
    123 131
                 log.info("Loading ps observation dcp presets...");
    
    124 132
                 try {
    
    ... ... @@ -129,10 +137,10 @@ public class FloatingObjectPresetsManager {
    129 137
                     psObservation = new TreeMap<>();
    
    130 138
                 }
    
    131 139
             }
    
    132
    -        return ImmutableSet.copyOf(psObservation.values());
    
    140
    +        return psObservation;
    
    133 141
         }
    
    134 142
     
    
    135
    -    public Set<FloatingObjectPreset> getPsLogbook() {
    
    143
    +    public Map<Path, FloatingObjectPreset> getPsLogbookPresets() {
    
    136 144
             if (psLogbook == null) {
    
    137 145
                 log.info("Loading ps logbook dcp presets...");
    
    138 146
                 try {
    
    ... ... @@ -143,22 +151,16 @@ public class FloatingObjectPresetsManager {
    143 151
                     psLogbook = new TreeMap<>();
    
    144 152
                 }
    
    145 153
             }
    
    146
    -        return ImmutableSet.copyOf(psLogbook.values());
    
    147
    -    }
    
    148
    -
    
    149
    -    public Map<Path, FloatingObjectPreset> getPsObservationL() {
    
    150
    -        return psObservation;
    
    151
    -    }
    
    152
    -
    
    153
    -    public Map<Path, FloatingObjectPreset> getPsLogbookL() {
    
    154 154
             return psLogbook;
    
    155 155
         }
    
    156 156
     
    
    157
    -    public void setPsObservation(Map<Path, FloatingObjectPreset> psObservation) {
    
    158
    -        this.psObservation = psObservation;
    
    157
    +    public void setPsObservationPresets(Map<Path, FloatingObjectPreset> psObservationPresets) {
    
    158
    +        this.psObservation = psObservationPresets;
    
    159
    +        log.info(String.format("Set %d ps observation dcp presets.", psObservationPresets.size()));
    
    159 160
         }
    
    160 161
     
    
    161
    -    public void setPsLogbook(Map<Path, FloatingObjectPreset> psLogbook) {
    
    162
    -        this.psLogbook = psLogbook;
    
    162
    +    public void setPsLogbookPresets(Map<Path, FloatingObjectPreset> psLogbookPresets) {
    
    163
    +        this.psLogbook = psLogbookPresets;
    
    164
    +        log.info(String.format("Set %d ps logbook dcp presets.", psLogbookPresets.size()));
    
    163 165
         }
    
    164 166
     }

  • client-core/src/main/java/fr/ird/observe/client/datasource/api/ObserveSwingDataSource.java
    ... ... @@ -643,8 +643,14 @@ public class ObserveSwingDataSource extends ObserveServicesProviderSupport imple
    643 643
         public void sanitize(BoundedRangeModel progressModel, FloatingObjectPresetsManager dataSource) {
    
    644 644
             int size = dataSource.size();
    
    645 645
             log.info(String.format("Will sanitize %d preset(s).", size));
    
    646
    -        sanitize(dataSource.getPsObservationL(), progressModel);
    
    647
    -        sanitize(dataSource.getPsLogbookL(), progressModel);
    
    646
    +        {
    
    647
    +            Map<Path, FloatingObjectPreset> sanitize = sanitize(dataSource.getPsObservationPresets(), progressModel);
    
    648
    +            dataSource.setPsObservationPresets(sanitize);
    
    649
    +        }
    
    650
    +        {
    
    651
    +            Map<Path, FloatingObjectPreset> sanitize = sanitize(dataSource.getPsLogbookPresets(), progressModel);
    
    652
    +            dataSource.setPsLogbookPresets(sanitize);
    
    653
    +        }
    
    648 654
             log.info(String.format("Found %d safe preset(s).", dataSource.size()));
    
    649 655
         }
    
    650 656
     
    

  • client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/observation/FloatingObjectUIHandler.java
    ... ... @@ -21,7 +21,7 @@
    21 21
      */
    
    22 22
     package fr.ird.observe.client.datasource.editor.content.data.ps.observation;
    
    23 23
     
    
    24
    -import fr.ird.observe.client.datasource.dcp.FloatingObjectPresetsManagerApplicationComponent;
    
    24
    +import fr.ird.observe.client.datasource.dcp.WithFloatingObjectPresetsManager;
    
    25 25
     import fr.ird.observe.client.datasource.editor.content.data.edit.ContentEditUIHandler;
    
    26 26
     import fr.ird.observe.client.datasource.editor.content.data.edit.ContentEditUILayoutFocusTraversalPolicy;
    
    27 27
     import fr.ird.observe.client.datasource.editor.content.data.ps.observation.dcp.FloatingObjectPartsTreeTableModel;
    
    ... ... @@ -65,7 +65,7 @@ import static io.ultreia.java4all.i18n.I18n.t;
    65 65
      * @author Tony Chemit - dev@tchemit.fr
    
    66 66
      * @since 1.0
    
    67 67
      */
    
    68
    -public class FloatingObjectUIHandler extends ContentEditUIHandler<FloatingObjectDto, FloatingObjectReference, FloatingObjectUI> implements UIHandler<FloatingObjectUI> {
    
    68
    +public class FloatingObjectUIHandler extends ContentEditUIHandler<FloatingObjectDto, FloatingObjectReference, FloatingObjectUI> implements UIHandler<FloatingObjectUI>, WithFloatingObjectPresetsManager {
    
    69 69
     
    
    70 70
         private static final Logger log = LogManager.getLogger(FloatingObjectUIHandler.class);
    
    71 71
         private static final Icon ICON_NOT_A_REFERENCE = SwingUtil.createImageIcon("star-empty.png");
    
    ... ... @@ -97,18 +97,13 @@ public class FloatingObjectUIHandler extends ContentEditUIHandler<FloatingObject
    97 97
                 FloatingObjectPreset newValue = (FloatingObjectPreset) e.getNewValue();
    
    98 98
                 ui.getFloatingObjectReferenceActions().removeAll();
    
    99 99
                 ui.getAddFloatingObjectPreset().setEnabled(newValue == null);
    
    100
    -//            ui.getEditFloatingObjectReference().setEnabled(newValue != null);
    
    101
    -//            ui.getRemoveFloatingObjectReference().setEnabled(newValue != null);
    
    102 100
                 if (newValue == null) {
    
    103 101
                     ui.getFloatingObjectReferenceLabel().setIcon(ICON_NOT_A_REFERENCE);
    
    104 102
                     ui.getFloatingObjectReferenceLabel().setText(t("observe.data.ps.observation.FloatingObject.not.a.reference"));
    
    105 103
                     ui.getFloatingObjectReferenceActions().add(ui.getAddFloatingObjectPreset());
    
    106
    -//                ui.getEditFloatingObjectReference().setEnabled(false);
    
    107 104
                 } else {
    
    108 105
                     ui.getFloatingObjectReferenceLabel().setIcon(ICON_IS_A_REFERENCE);
    
    109 106
                     ui.getFloatingObjectReferenceLabel().setText(t("observe.data.ps.observation.FloatingObject.is.a.reference", newValue.getLabel(getDecoratorService().getReferentialLocale())));
    
    110
    -//                ui.getFloatingObjectReferenceActions().add(ui.getEditFloatingObjectReference());
    
    111
    -//                ui.getFloatingObjectReferenceActions().add(ui.getRemoveFloatingObjectReference());
    
    112 107
                 }
    
    113 108
             });
    
    114 109
     
    
    ... ... @@ -161,7 +156,7 @@ public class FloatingObjectUIHandler extends ContentEditUIHandler<FloatingObject
    161 156
             Optional<FloatingObjectPreset> floatingObjectReference;
    
    162 157
     
    
    163 158
             if (dcpId == null) {
    
    164
    -            floatingObjectReference = Optional.ofNullable(FloatingObjectPresetsManagerApplicationComponent.value().getReferenceToUse());
    
    159
    +            floatingObjectReference = Optional.ofNullable(getFloatingObjectPresetsManager().getReferenceToUse());
    
    165 160
                 form = getPsObservationFloatingObjectService().preCreate(activityId, floatingObjectReference.orElse(null));
    
    166 161
             } else {
    
    167 162
                 form = getPsObservationFloatingObjectService().loadForm(dcpId);
    

  • client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/observation/actions/ActivityUIAddFloatingObject.java
    ... ... @@ -24,14 +24,15 @@ package fr.ird.observe.client.datasource.editor.content.data.ps.observation.acti
    24 24
     
    
    25 25
     import fr.ird.observe.client.ClientUIContext;
    
    26 26
     import fr.ird.observe.client.datasource.dcp.FloatingObjectPresetsManager;
    
    27
    -import fr.ird.observe.client.datasource.dcp.FloatingObjectPresetsManagerApplicationComponent;
    
    27
    +import fr.ird.observe.client.datasource.dcp.WithFloatingObjectPresetsManager;
    
    28 28
     import fr.ird.observe.client.datasource.editor.DataSourceEditor;
    
    29 29
     import fr.ird.observe.client.datasource.editor.content.ObservePsKeyStrokes;
    
    30 30
     import fr.ird.observe.client.datasource.editor.content.actions.ContentUIActionSupport;
    
    31 31
     import fr.ird.observe.client.datasource.editor.content.data.ps.observation.ActivityUI;
    
    32 32
     import fr.ird.observe.client.datasource.editor.tree.navigation.NavigationTree;
    
    33 33
     import fr.ird.observe.dto.data.ps.dcp.FloatingObjectPreset;
    
    34
    -import fr.ird.observe.dto.decoration.DecoratorServiceApplicationComponent;
    
    34
    +import fr.ird.observe.dto.data.ps.dcp.FloatingObjectPresetModel;
    
    35
    +import fr.ird.observe.dto.decoration.WithDecoratorService;
    
    35 36
     import fr.ird.observe.navigation.tree.MultipleReferenceContainerNode;
    
    36 37
     import org.apache.logging.log4j.LogManager;
    
    37 38
     import org.apache.logging.log4j.Logger;
    
    ... ... @@ -57,7 +58,7 @@ import static io.ultreia.java4all.i18n.I18n.t;
    57 58
      * @author Tony Chemit - dev@tchemit.fr
    
    58 59
      * @since 6.0
    
    59 60
      */
    
    60
    -public class ActivityUIAddFloatingObject extends ContentUIActionSupport<ActivityUI> {
    
    61
    +public class ActivityUIAddFloatingObject extends ContentUIActionSupport<ActivityUI> implements WithFloatingObjectPresetsManager {
    
    61 62
     
    
    62 63
         private static final Logger log = LogManager.getLogger(ActivityUIAddFloatingObject.class);
    
    63 64
     
    
    ... ... @@ -65,9 +66,22 @@ public class ActivityUIAddFloatingObject extends ContentUIActionSupport<Activity
    65 66
             super(t("observe.data.ps.observation.Activity.action.addFloatingObject"), t("observe.data.ps.observation.Activity.action.addFloatingObject.tip"), "add", ObservePsKeyStrokes.KEY_STROKE_ADD_DCP);
    
    66 67
         }
    
    67 68
     
    
    68
    -    public static boolean choosePreset() {
    
    69
    -        FloatingObjectPresetsManager floatingObjectPresetsManager = FloatingObjectPresetsManagerApplicationComponent.value();
    
    70
    -        Set<FloatingObjectPreset> psObservation = floatingObjectPresetsManager.getPsObservation();
    
    69
    +    @Override
    
    70
    +    protected void doActionPerformed(ActionEvent e, ActivityUI ui) {
    
    71
    +
    
    72
    +        boolean doContinue = choosePreset();
    
    73
    +        if (!doContinue) {
    
    74
    +            return;
    
    75
    +        }
    
    76
    +
    
    77
    +        NavigationTree tree = getDataSourceEditor().getNavigationUI().getTree();
    
    78
    +        MultipleReferenceContainerNode<?, ?> parentNode = (MultipleReferenceContainerNode<?, ?>) tree.getSelectedNode();
    
    79
    +        doCreate(getDataSourceEditor(), parentNode);
    
    80
    +    }
    
    81
    +
    
    82
    +    boolean choosePreset() {
    
    83
    +        FloatingObjectPresetsManager floatingObjectPresetsManager = getFloatingObjectPresetsManager();
    
    84
    +        Set<FloatingObjectPreset> psObservation = floatingObjectPresetsManager.getPresets(FloatingObjectPresetModel.ps_observation);
    
    71 85
             if (!psObservation.isEmpty()) {
    
    72 86
     
    
    73 87
                 JPanel userConfigs = new JPanel(new GridLayout(0, 2));
    
    ... ... @@ -97,29 +111,16 @@ public class ActivityUIAddFloatingObject extends ContentUIActionSupport<Activity
    97 111
             return true;
    
    98 112
         }
    
    99 113
     
    
    100
    -    @Override
    
    101
    -    protected void doActionPerformed(ActionEvent e, ActivityUI ui) {
    
    102
    -
    
    103
    -        boolean doContinue = choosePreset();
    
    104
    -        if (!doContinue) {
    
    105
    -            return;
    
    106
    -        }
    
    107
    -
    
    108
    -        NavigationTree tree = getDataSourceEditor().getNavigationUI().getTree();
    
    109
    -        MultipleReferenceContainerNode<?, ?> parentNode = (MultipleReferenceContainerNode<?, ?>) tree.getSelectedNode();
    
    110
    -        doCreate(getDataSourceEditor(), parentNode);
    
    111
    -    }
    
    112
    -
    
    113
    -    public static void doCreate(DataSourceEditor editor, MultipleReferenceContainerNode<?, ?> parentNode) {
    
    114
    +    void doCreate(DataSourceEditor editor, MultipleReferenceContainerNode<?, ?> parentNode) {
    
    114 115
             try {
    
    115 116
                 NavigationTree tree = editor.getNavigationUI().getTree();
    
    116 117
                 tree.addUnsavedNode(parentNode);
    
    117 118
             } finally {
    
    118
    -            FloatingObjectPresetsManagerApplicationComponent.value().setReferenceToUse(null);
    
    119
    +            getFloatingObjectPresetsManager().setReferenceToUse(null);
    
    119 120
             }
    
    120 121
         }
    
    121 122
     
    
    122
    -    private static class UsePresetAction extends AbstractAction {
    
    123
    +    private static class UsePresetAction extends AbstractAction implements WithDecoratorService {
    
    123 124
     
    
    124 125
             private final FloatingObjectPreset preset;
    
    125 126
             private final KeyStroke keyStroke;
    
    ... ... @@ -129,7 +130,7 @@ public class ActivityUIAddFloatingObject extends ContentUIActionSupport<Activity
    129 130
                 this.preset = Objects.requireNonNull(preset);
    
    130 131
                 this.keyStroke = Objects.requireNonNull(KeyStroke.getKeyStroke("F" + index));
    
    131 132
                 putValue(ActivityUIAddFloatingObject.class.getName(), getClass().getName() + "_" + index);
    
    132
    -            putValue(NAME, DecoratorServiceApplicationComponent.value().getDecoratorByType(preset.getClass()).toString(preset));
    
    133
    +            putValue(NAME, getDecoratorService().getDecoratorByType(preset.getClass()).toString(preset));
    
    133 134
             }
    
    134 135
     
    
    135 136
             public void install(JButton parent, JOptionPane pane) {
    
    ... ... @@ -144,7 +145,6 @@ public class ActivityUIAddFloatingObject extends ContentUIActionSupport<Activity
    144 145
             public void actionPerformed(ActionEvent e) {
    
    145 146
                 log.info(String.format("Choose dcp preset: %s", preset.getLabel1()));
    
    146 147
                 pane.setValue(preset);
    
    147
    -//            Objects.requireNonNull(SwingUtilities.getAncestorOfClass(Dialog.class, pane)).setVisible(false);
    
    148 148
             }
    
    149 149
         }
    
    150 150
     }

  • client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/observation/actions/FloatingObjectUIAddFloatingObjectPreset.java
    ... ... @@ -24,11 +24,11 @@ package fr.ird.observe.client.datasource.editor.content.data.ps.observation.acti
    24 24
     
    
    25 25
     import fr.ird.observe.client.ClientUIContext;
    
    26 26
     import fr.ird.observe.client.datasource.dcp.FloatingObjectPresetsManager;
    
    27
    -import fr.ird.observe.client.datasource.dcp.FloatingObjectPresetsManagerApplicationComponent;
    
    27
    +import fr.ird.observe.client.datasource.dcp.WithFloatingObjectPresetsManager;
    
    28 28
     import fr.ird.observe.client.datasource.dcp.presets.observation.FloatingObjectPresetUI;
    
    29 29
     import fr.ird.observe.client.datasource.dcp.presets.observation.FloatingObjectPresetUIModel;
    
    30
    -import fr.ird.observe.client.datasource.editor.content.actions.ContentUIActionSupport;
    
    31 30
     import fr.ird.observe.client.datasource.editor.content.ObservePsKeyStrokes;
    
    31
    +import fr.ird.observe.client.datasource.editor.content.actions.ContentUIActionSupport;
    
    32 32
     import fr.ird.observe.client.datasource.editor.content.data.ps.observation.FloatingObjectUI;
    
    33 33
     import fr.ird.observe.dto.data.ps.dcp.FloatingObjectPreset;
    
    34 34
     import io.ultreia.java4all.application.context.ApplicationContext;
    
    ... ... @@ -52,7 +52,7 @@ import static io.ultreia.java4all.i18n.I18n.t;
    52 52
      *
    
    53 53
      * @author Tony Chemit - dev@tchemit.fr
    
    54 54
      */
    
    55
    -public class FloatingObjectUIAddFloatingObjectPreset extends ContentUIActionSupport<FloatingObjectUI> {
    
    55
    +public class FloatingObjectUIAddFloatingObjectPreset extends ContentUIActionSupport<FloatingObjectUI> implements WithFloatingObjectPresetsManager {
    
    56 56
     
    
    57 57
         private static final Logger log = LogManager.getLogger(FloatingObjectUIAddFloatingObjectPreset.class);
    
    58 58
     
    
    ... ... @@ -101,7 +101,7 @@ public class FloatingObjectUIAddFloatingObjectPreset extends ContentUIActionSupp
    101 101
             if (model.getBuoy2() != null) {
    
    102 102
                 model.setBuoy2(configPanel.getBuoy2().getModel().toBean());
    
    103 103
             }
    
    104
    -        FloatingObjectPresetsManager floatingObjectPresetsManager = FloatingObjectPresetsManagerApplicationComponent.value();
    
    104
    +        FloatingObjectPresetsManager floatingObjectPresetsManager = getFloatingObjectPresetsManager();
    
    105 105
             floatingObjectPresetsManager.add(model);
    
    106 106
             ui.getModel().setReference(model);
    
    107 107
         }