Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 7d737dec by Tony Chemit at 2021-02-17T17:09:54+01:00 Make Ps-Observation-DCP addPreset action works again (added in Actions menu with accelerator F9). - - - - - 70b71ffc by Tony Chemit at 2021-02-17T17:09:54+01:00 Fix NavigationNode.findById method (do not use the isLeaf method, prefer use concrete getChildCount since we are sure at this point that children nodes are loaded) - - - - - 84ab2eee by Tony Chemit at 2021-02-17T17:09:54+01:00 Add nice isEmptyNode method to force leaf property on some node. - - - - - ee10922f by Tony Chemit at 2021-02-17T17:09:54+01:00 Better catch of exceptions in DeleteExecutor. - - - - - f450d7ae by Tony Chemit at 2021-02-17T17:09:54+01:00 Amélioration du rendu des coordonnées - Closes #1792 - - - - - 9445e2c4 by Tony Chemit at 2021-02-17T18:18:29+01:00 Correction des tri sur les dates - See #1792 - - - - - 22 changed files: - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/ObserveKeyStrokesEditorApi.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/delete/DeleteExecutor.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/open/ContentOpenableUINavigationHandler.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/open/ContentOpenableUINavigationInitializer.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/NavigationNode.java - client/datasource/editor/common/src/main/i18n/getters/jaxx.getter - client/datasource/editor/ps/src/main/i18n/getters/jaxx.getter - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUI.jaxx - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUI.jcss - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUIHandler.java - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUIModel.java - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUIModelStates.java - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/actions/FloatingObjectUIAddFloatingObjectPreset.java - + client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/dcp/UsePresetAction.java - models/dto/java/src/main/i18n/getters/java.getter - models/dto/java/src/main/java/fr/ird/observe/dto/data/ps/observation/ActivityReference.java - models/dto/java/src/main/java/fr/ird/observe/dto/decoration/ObserveI18nLabelsBuilder.java - + models/dto/java/src/test/java/fr/ird/observe/dto/decoration/ObserveI18nLabelsBuilderTest.java - pom.xml - services/i18n/src/main/i18n/translations/services_en_GB.properties - services/i18n/src/main/i18n/translations/services_es_ES.properties - services/i18n/src/main/i18n/translations/services_fr_FR.properties Changes: ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/ObserveKeyStrokesEditorApi.java ===================================== @@ -67,6 +67,7 @@ public class ObserveKeyStrokesEditorApi extends ObserveKeyStrokesSupport { public static final KeyStroke KEY_STROKE_DELETE_DATA_GLOBAL = KeyStroke.getKeyStroke("pressed F6"); public static final KeyStroke KEY_STROKE_MOVE = KeyStroke.getKeyStroke("pressed F7"); public static final KeyStroke KEY_STROKE_DUPLICATE = KeyStroke.getKeyStroke("pressed F7"); + public static final KeyStroke KEY_STROKE_ADD_PRESET = KeyStroke.getKeyStroke("pressed F9"); public static final KeyStroke KEY_STROKE_GENERATE = KeyStroke.getKeyStroke("pressed F9"); public static final KeyStroke KEY_STROKE_CHANGE_ID = KeyStroke.getKeyStroke("pressed F9"); public static final KeyStroke KEY_STROKE_SHOW_TECHNICAL_INFORMATIONS = KeyStroke.getKeyStroke("pressed F10"); ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/actions/delete/DeleteExecutor.java ===================================== @@ -30,7 +30,6 @@ import org.apache.logging.log4j.Logger; import org.nuiton.jaxx.runtime.swing.application.ActionExecutor; import javax.swing.SwingUtilities; -import java.lang.reflect.InvocationTargetException; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -94,8 +93,8 @@ public class DeleteExecutor { DeleteTreeAdapter<?> treeAdapter = this.treeAdapter.apply(request); try { SwingUtilities.invokeAndWait(() -> treeAdapter.adaptTree(request, tree)); - } catch (InterruptedException | InvocationTargetException e) { - log.error(e); + } catch (Exception e) { + UIHelper.handlingError(e); } log.info(String.format("Delete adapt tree [end..] %s", ids)); } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/open/ContentOpenableUINavigationHandler.java ===================================== @@ -53,7 +53,7 @@ public abstract class ContentOpenableUINavigationHandler<N extends ContentOpenab @Override public final boolean isLeaf() { - return getNode().getInitializer().isNotPersisted() || super.isLeaf(); + return getNode().getInitializer().isNotPersisted() || getNode().getInitializer().isLeaf() || super.isLeaf(); } @Override ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/open/ContentOpenableUINavigationInitializer.java ===================================== @@ -27,6 +27,8 @@ import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationIni import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationScope; import fr.ird.observe.dto.reference.DataDtoReference; import fr.ird.observe.dto.reference.DtoReference; +import io.ultreia.java4all.bean.definition.JavaBeanPropertyDefinition; +import io.ultreia.java4all.util.SingletonSupplier; import java.util.Objects; @@ -38,6 +40,10 @@ import java.util.Objects; */ public final class ContentOpenableUINavigationInitializer extends NavigationInitializer<ContentOpenableUINavigationContext> { + /** + * flag to force a node to be a leaf even if it is not loaded. + */ + private final SingletonSupplier<Boolean> leaf; private DtoReference parentReference; private DataDtoReference reference; @@ -45,60 +51,74 @@ public final class ContentOpenableUINavigationInitializer extends NavigationInit super(scope); this.parentReference = Objects.requireNonNull(parentReference); this.reference = Objects.requireNonNull(reference); + this.leaf = SingletonSupplier.of(this::computeLeaf); + } + + private Boolean computeLeaf() { + @SuppressWarnings("unchecked") JavaBeanPropertyDefinition<DataDtoReference, ?> propertyDefinition = (JavaBeanPropertyDefinition<DataDtoReference, ?>) reference.javaBeanDefinition().properties().get("emptyNode"); + if (propertyDefinition != null && propertyDefinition.canRead()) { + return (Boolean) propertyDefinition.get(reference); + } + return false; } @Override - protected DataDtoReference init(NavigationContext<ContentOpenableUINavigationContext> context) { + protected final DataDtoReference init(NavigationContext<ContentOpenableUINavigationContext> context) { context.initReference(parentReference); context.initReference(reference); return getReference(); } @Override - protected void open(NavigationContext<ContentOpenableUINavigationContext> context) { + protected final void open(NavigationContext<ContentOpenableUINavigationContext> context) { updateSelectNodeId(getSelectId()); } @Override - protected void reload(NavigationContext<ContentOpenableUINavigationContext> context) { + protected final void reload(NavigationContext<ContentOpenableUINavigationContext> context) { this.parentReference = context.reloadReference(getParentReference()); this.reference = context.reloadReference(getReference()); + leaf.clear(); } @Override - public String toString() { + public final String toString() { return super.toString() + "" + getSelectId(); } - public DtoReference getParentReference() { + public final DtoReference getParentReference() { return parentReference; } - public DataDtoReference getReference() { + public final DataDtoReference getReference() { return reference; } - public String getSelectId() { + public final String getSelectId() { return getReference().getId(); } - public String getSelectedParentId() { + public final String getSelectedParentId() { return getParentReference().getId(); } - public boolean isOpen() { + public final boolean isOpen() { return Objects.equals(getSelectId(), getEditNodeId()); } - public boolean isPersisted() { + public final boolean isPersisted() { return getSelectId() != null; } - public boolean isNotPersisted() { + public final boolean isNotPersisted() { return getSelectId() == null; } - public void setReference(DataDtoReference reference) { + public final boolean isLeaf() { + return leaf.get(); + } + + public final void setReference(DataDtoReference reference) { this.reference = Objects.requireNonNull(reference); } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/NavigationNode.java ===================================== @@ -450,17 +450,10 @@ public abstract class NavigationNode extends DefaultMutableTreeNode implements W super.remove(childIndex); } -// @Override -// public void removeFromParent() { -// NavigationNode parent = getParent(); -// int index = parent.getIndex(this); -// parent.remove(index); -// } - public void removeChildren(Set<String> ids) { for (String id : ids) { NavigationNode childNode = findChildById(id); - childNode.removeFromParent(); + Objects.requireNonNull(childNode, String.format("Could not find child node from %s with id: '%s'.", id, this)).removeFromParent(); } } @@ -488,7 +481,7 @@ public abstract class NavigationNode extends DefaultMutableTreeNode implements W // il faut charger les fils du nœud pour effectuer la recherche populateChildrenIfNotLoaded(); - if (isLeaf()) { + if (getChildCount() == 0) { // au final le nœud est une feuille, donc ne convient pas return null; } ===================================== client/datasource/editor/common/src/main/i18n/getters/jaxx.getter ===================================== @@ -1,4 +1,5 @@ observe.Id.comment +observe.Id.coordinate observe.Id.country observe.Id.description observe.Id.ocean ===================================== client/datasource/editor/ps/src/main/i18n/getters/jaxx.getter ===================================== @@ -1,4 +1,5 @@ observe.Id.comment +observe.Id.coordinate observe.Id.country observe.Id.homeId observe.Id.ocean ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUI.jaxx ===================================== @@ -320,5 +320,5 @@ <JPanel id="invisible"> <JLabel id='noBaliseEditor' styleClass="skipI18n"/> </JPanel> - <JMenuItem id="addFloatingObjectPreset"/> + <JMenuItem id="addPreset"/> </fr.ird.observe.client.datasource.editor.api.content.data.edit.ContentEditUI> ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUI.jcss ===================================== @@ -36,7 +36,7 @@ } #addFloatingObjectPreset { - enabled:{states.isUpdatingMode() && states.getReference() == null}; + enabled:{!states.isCreatingMode() && states.getReference() == null}; } #objectOperation { ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUIHandler.java ===================================== @@ -21,6 +21,7 @@ */ package fr.ird.observe.client.datasource.editor.ps.data.observation; +import fr.ird.observe.client.datasource.editor.ps.data.observation.actions.FloatingObjectUIAddFloatingObjectPreset; import fr.ird.observe.client.datasource.editor.ps.data.observation.dcp.FloatingObjectPartsTreeTableModel; import fr.ird.observe.dto.ProtectedIdsPs; import fr.ird.observe.dto.data.ps.TypeTransmittingBuoyOperation; @@ -79,14 +80,19 @@ public class FloatingObjectUIHandler extends GeneratedFloatingObjectUIHandler { model.getStates().getBean().addPropertyChangeListener(FloatingObjectDto.PROPERTY_OBJECT_OPERATION, e -> updateMaterials((ObjectOperationReference) e.getNewValue())); } - //FIXME:Focus ui.getModel().getStates().isCreatingMode() ? getUi().getObjectOperation() : getUi().getSupportVesselName() + @Override + protected void installExtraActions() { + super.installExtraActions(); + FloatingObjectUIAddFloatingObjectPreset.init(ui, ui.getAddPreset(), FloatingObjectUIAddFloatingObjectPreset.class); + } +//FIXME:Focus ui.getModel().getStates().isCreatingMode() ? getUi().getObjectOperation() : getUi().getSupportVesselName() @Override public void onOpenForm(Form<?> form) { FloatingObjectUIModel model = getModel(); - Optional<FloatingObjectPreset> floatingObjectReference = model.getStates().getReference(); + FloatingObjectPreset floatingObjectReference = model.getStates().getReference(); FloatingObjectDto bean = model.getStates().getBean(); @@ -98,7 +104,7 @@ public class FloatingObjectUIHandler extends GeneratedFloatingObjectUIHandler { TypeTransmittingBuoyOperation typeTransmittingBuoyOperation = bean.getTypeTransmittingBuoyOperation(); ui.getTypeOperation().setSelectedItem(typeTransmittingBuoyOperation); - ui.getTable().openTable(model, bean.isPersisted() || floatingObjectReference.isPresent()); + ui.getTable().openTable(model, bean.isPersisted() || floatingObjectReference != null); Optional.ofNullable(bean.getFirstBuoy()).ifPresent(b -> b.copy(getUi().getTransmittingBuoy1())); Optional.ofNullable(bean.getSecondBuoy()).ifPresent(b -> b.copy(getUi().getTransmittingBuoy2())); ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUIModel.java ===================================== @@ -22,33 +22,12 @@ package fr.ird.observe.client.datasource.editor.ps.data.observation; * #L% */ -import fr.ird.observe.client.ClientUIContext; import fr.ird.observe.client.WithClientUIContext; -import fr.ird.observe.client.datasource.dcp.FloatingObjectPresetsManager; -import fr.ird.observe.client.datasource.editor.ps.ObservePsKeyStrokes; +import fr.ird.observe.client.datasource.editor.ps.data.observation.dcp.UsePresetAction; import fr.ird.observe.dto.data.ps.dcp.FloatingObjectPreset; -import fr.ird.observe.dto.data.ps.dcp.FloatingObjectPresetModel; import fr.ird.observe.dto.data.ps.observation.FloatingObjectDto; -import fr.ird.observe.dto.decoration.WithDecoratorService; import fr.ird.observe.dto.form.Form; import fr.ird.observe.services.ObserveServicesProvider; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.swing.AbstractAction; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.KeyStroke; -import java.awt.Font; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.util.Objects; -import java.util.Set; - -import static fr.ird.observe.client.datasource.editor.api.content.referential.usage.UsageUIHandlerSupport.findButton; -import static io.ultreia.java4all.i18n.I18n.t; /** * Created on 9/28/14. @@ -58,36 +37,6 @@ import static io.ultreia.java4all.i18n.I18n.t; */ public class FloatingObjectUIModel extends GeneratedFloatingObjectUIModel implements WithClientUIContext { - private static final Logger log = LogManager.getLogger(FloatingObjectUIModel.class); - - public static class UsePresetAction extends AbstractAction implements WithDecoratorService { - - private final FloatingObjectPreset preset; - private final KeyStroke keyStroke; - private JOptionPane pane; - - public UsePresetAction(FloatingObjectPreset preset, int index) { - this.preset = Objects.requireNonNull(preset); - this.keyStroke = Objects.requireNonNull(KeyStroke.getKeyStroke("F" + index)); - putValue(UsePresetAction.class.getName(), getClass().getName() + "_" + index); - putValue(NAME, getDecoratorService().getDecoratorByType(preset.getClass()).toString(preset)); - } - - public void install(JButton parent, JOptionPane pane) { - this.pane = pane; - String actionMapKey = (String) getValue(UsePresetAction.class.getName()); - pane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, actionMapKey); - pane.getActionMap().put(actionMapKey, this); - ObservePsKeyStrokes.addKeyStroke(parent, keyStroke); - } - - @Override - public void actionPerformed(ActionEvent e) { - log.info(String.format("Choose dcp preset: %s", preset.getLabel1())); - pane.setValue(preset); - } - } - public FloatingObjectUIModel(FloatingObjectUINavigationNode source) { super(source); } @@ -95,50 +44,16 @@ public class FloatingObjectUIModel extends GeneratedFloatingObjectUIModel implem @Override public void open() { FloatingObjectUIModelStates states = getStates(); - if (states.getReference().isPresent()) { - log.info(String.format("%s Will use dcp preset: %s", getPrefix(), states.getReference())); - } super.open(); if (states.isCreatingMode()) { - FloatingObjectPreset reference = chooseFloatingObjectPreset(); + FloatingObjectPreset reference = UsePresetAction.chooseFloatingObjectPreset(getClientUIContext()); states.setReference(reference); } } @Override public Form<FloatingObjectDto> preCreateForm(ObserveServicesProvider servicesProvider, String parentId) { - return servicesProvider.getPsObservationFloatingObjectService().preCreate2(parentId, getStates().getReference().orElse(null)); - } - - private FloatingObjectPreset chooseFloatingObjectPreset() { - - FloatingObjectPresetsManager floatingObjectPresetsManager = getClientUIContext().getFloatingObjectPresetsManager(); - Set<FloatingObjectPreset> psObservation = floatingObjectPresetsManager.getPresets(FloatingObjectPresetModel.ps_observation); - if (!psObservation.isEmpty()) { - - JPanel userConfigs = new JPanel(new GridLayout(0, 2)); - - String replaceText = t("observe.ui.choice.dcp.default") + " (Enter)"; - Object[] options = {replaceText}; - JOptionPane pane = new JOptionPane(userConfigs, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[0]); - JButton jButton = Objects.requireNonNull(findButton(pane, replaceText)); - Font font = jButton.getFont().deriveFont(18f); - jButton.setFont(font.deriveFont(Font.ITALIC)); - int index = 0; - for (FloatingObjectPreset preset : psObservation) { - UsePresetAction a = new UsePresetAction(preset, ++index); - JButton b = new JButton(a); - b.setFont(font); - userConfigs.add(b); - a.install(b, pane); - } - ClientUIContext.askUser(pane, t("observe.data.ps.observation.FloatingObjectReference.choose.title"), options); - Object value = pane.getValue(); - if (value instanceof FloatingObjectPreset) { - return (FloatingObjectPreset) value; - } - } - return null; + return servicesProvider.getPsObservationFloatingObjectService().preCreate2(parentId, getStates().getReference()); } } ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/FloatingObjectUIModelStates.java ===================================== @@ -153,8 +153,8 @@ public class FloatingObjectUIModelStates extends GeneratedFloatingObjectUIModelS return whenLeaving.get(dto); } - public Optional<FloatingObjectPreset> getReference() { - return Optional.ofNullable(reference); + public FloatingObjectPreset getReference() { + return reference; } public void setReference(FloatingObjectPreset reference) { ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/actions/FloatingObjectUIAddFloatingObjectPreset.java ===================================== @@ -24,8 +24,9 @@ package fr.ird.observe.client.datasource.editor.ps.data.observation.actions; import fr.ird.observe.client.ClientUIContext; import fr.ird.observe.client.datasource.dcp.FloatingObjectPresetsManager; +import fr.ird.observe.client.datasource.editor.api.ObserveKeyStrokesEditorApi; +import fr.ird.observe.client.datasource.editor.api.content.actions.ConfigureMenuAction; import fr.ird.observe.client.datasource.editor.api.content.actions.ContentUIActionSupport; -import fr.ird.observe.client.datasource.editor.api.content.actions.InsertMenuAction; import fr.ird.observe.client.datasource.editor.ps.data.dcp.presets.FloatingObjectPresetUI; import fr.ird.observe.client.datasource.editor.ps.data.observation.FloatingObjectUI; import fr.ird.observe.client.util.UIHelper; @@ -51,13 +52,14 @@ import static io.ultreia.java4all.i18n.I18n.t; * * @author Tony Chemit - dev@tchemit.fr */ -public class FloatingObjectUIAddFloatingObjectPreset extends ContentUIActionSupport<FloatingObjectUI> implements InsertMenuAction<FloatingObjectUI> { +public class FloatingObjectUIAddFloatingObjectPreset extends ContentUIActionSupport<FloatingObjectUI> implements ConfigureMenuAction<FloatingObjectUI> { private static final Logger log = LogManager.getLogger(FloatingObjectUIAddFloatingObjectPreset.class); public FloatingObjectUIAddFloatingObjectPreset() { super(t("observe.data.ps.observation.FloatingObjectReference.action.add"), - t("observe.data.ps.observation.FloatingObjectReference.action.add.tip"), "add-preset", null); + t("observe.data.ps.observation.FloatingObjectReference.action.add.tip"), "add-preset", + ObserveKeyStrokesEditorApi.KEY_STROKE_ADD_PRESET); } @Override ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/dcp/UsePresetAction.java ===================================== @@ -0,0 +1,114 @@ +package fr.ird.observe.client.datasource.editor.ps.data.observation.dcp; + +/*- + * #%L + * ObServe Client :: DataSource :: Editor :: PS + * %% + * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ird.observe.client.ClientUIContext; +import fr.ird.observe.client.WithClientUIContext; +import fr.ird.observe.client.datasource.dcp.FloatingObjectPresetsManager; +import fr.ird.observe.client.datasource.editor.api.ObserveKeyStrokesEditorApi; +import fr.ird.observe.client.datasource.editor.ps.ObservePsKeyStrokes; +import fr.ird.observe.dto.data.ps.dcp.FloatingObjectPreset; +import fr.ird.observe.dto.data.ps.dcp.FloatingObjectPresetModel; +import fr.ird.observe.dto.decoration.WithDecoratorService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.swing.AbstractAction; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.KeyStroke; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.util.Objects; +import java.util.Set; + +import static fr.ird.observe.client.datasource.editor.api.content.referential.usage.UsageUIHandlerSupport.findButton; +import static io.ultreia.java4all.i18n.I18n.t; + +/** + * Created on 17/02/2021. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 8.0.6 + */ +public class UsePresetAction extends AbstractAction implements WithDecoratorService { + private static final Logger log = LogManager.getLogger(UsePresetAction.class); + private final FloatingObjectPreset preset; + private final KeyStroke keyStroke; + private JOptionPane pane; + + public static FloatingObjectPreset chooseFloatingObjectPreset(ClientUIContext context) { + + FloatingObjectPresetsManager floatingObjectPresetsManager = context.getFloatingObjectPresetsManager(); + Set<FloatingObjectPreset> psObservation = floatingObjectPresetsManager.getPresets(FloatingObjectPresetModel.ps_observation); + if (!psObservation.isEmpty()) { + + JPanel userConfigs = new JPanel(new GridLayout(0, 2)); + + String replaceText = ObserveKeyStrokesEditorApi.suffixTextWithKeyStroke(t("observe.ui.choice.dcp.default"), KeyStroke.getKeyStroke("pressed ENTER")); + Object[] options = {replaceText}; + JOptionPane pane = new JOptionPane(userConfigs, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[0]); + JButton jButton = Objects.requireNonNull(findButton(pane, replaceText)); + Font font = jButton.getFont().deriveFont(18f); + jButton.setFont(font.deriveFont(Font.ITALIC)); + int index = 0; + for (FloatingObjectPreset preset : psObservation) { + UsePresetAction a = new UsePresetAction(preset, ++index); + JButton b = new JButton(a); + b.setFont(font); + userConfigs.add(b); + a.install(b, pane); + } + ClientUIContext.askUser(pane, t("observe.data.ps.observation.FloatingObjectReference.choose.title"), options); + Object value = pane.getValue(); + if (value instanceof FloatingObjectPreset) { + return (FloatingObjectPreset) value; + } + } + return null; + } + + public UsePresetAction(FloatingObjectPreset preset, int index) { + this.preset = Objects.requireNonNull(preset); + this.keyStroke = Objects.requireNonNull(KeyStroke.getKeyStroke("F" + index)); + putValue(UsePresetAction.class.getName(), getClass().getName() + "_" + index); + putValue(NAME, getDecoratorService().getDecoratorByType(preset.getClass()).toString(preset)); + } + + public void install(JButton parent, JOptionPane pane) { + this.pane = pane; + String actionMapKey = (String) getValue(UsePresetAction.class.getName()); + pane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke, actionMapKey); + pane.getActionMap().put(actionMapKey, this); + ObservePsKeyStrokes.addKeyStroke(parent, keyStroke); + } + + @Override + public void actionPerformed(ActionEvent e) { + log.info(String.format("Choose dcp preset: %s", preset.getLabel1())); + pane.setValue(preset); + } +} ===================================== models/dto/java/src/main/i18n/getters/java.getter ===================================== @@ -1,4 +1,5 @@ observe.Id.comment +observe.Id.coordinate observe.Id.country observe.Id.description observe.Id.gearCharacteristic ===================================== models/dto/java/src/main/java/fr/ird/observe/dto/data/ps/observation/ActivityReference.java ===================================== @@ -93,4 +93,8 @@ public class ActivityReference extends GeneratedActivityReference { public void setFloatingObject(ImmutableList<FloatingObjectReference> floatingObject) { this.floatingObject = floatingObject; } + + public final boolean isEmptyNode() { + return getSet() == null && (floatingObject == null || floatingObject.isEmpty()); + } } ===================================== models/dto/java/src/main/java/fr/ird/observe/dto/decoration/ObserveI18nLabelsBuilder.java ===================================== @@ -69,6 +69,7 @@ public class ObserveI18nLabelsBuilder extends BeanPropertyI18nKeyProducerSupport n("validator.scope.info.label"); n("validator.scope.warning.label"); n("observe.Id.comment"); + n("observe.Id.coordinate"); n("observe.Id.country"); n("observe.Id.homeId"); n("observe.Id.sex"); @@ -130,7 +131,16 @@ public class ObserveI18nLabelsBuilder extends BeanPropertyI18nKeyProducerSupport if (latitude == null || longitude == null) { return t("observe.common.no.coordinate"); } - return String.format("(%s°;%s°)", Numbers.roundThreeDigits(latitude), Numbers.roundThreeDigits(longitude)); + return String.format("(%s°;%s°)", fillCoordinateComponent(2,latitude), fillCoordinateComponent(3,longitude)); + } + + public static String fillCoordinateComponent(int integerPartDigit, Float component) { + boolean withSign = component<0; + String round = String.valueOf(Numbers.roundThreeDigits(component)); + int index = round.indexOf("."); + return (withSign?"-":" ") + +StringUtils.leftPad(round.substring(0,index).replace("-", ""), integerPartDigit, "0") + + StringUtils.rightPad(round.substring(index), 5, "0"); } public ObserveI18nLabelsBuilder() { @@ -182,6 +192,7 @@ public class ObserveI18nLabelsBuilder extends BeanPropertyI18nKeyProducerSupport .put("quadrant", idDtoPrefix) .put("whenArriving", idDtoPrefix) .put("whenLeaving", idDtoPrefix) + .put("coordinate", idDtoPrefix) .put("species", referentialDtoPrefix) .put(ReferentialDto.PROPERTY_URI, referentialDtoPrefix) ===================================== models/dto/java/src/test/java/fr/ird/observe/dto/decoration/ObserveI18nLabelsBuilderTest.java ===================================== @@ -0,0 +1,50 @@ +package fr.ird.observe.dto.decoration; + +/*- + * #%L + * ObServe Models :: Dto :: Java + * %% + * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created on 17/02/2021. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 8.0.6 + */ +public class ObserveI18nLabelsBuilderTest { + + @Test + public void fillCoordinateComponent() { + assertFillCoordinateComponent(1.02f, " 001.0200"); + assertFillCoordinateComponent(-1.02f, "-001.0200"); + assertFillCoordinateComponent(-10.02f, "-010.0200"); + assertFillCoordinateComponent(-10.032f, "-010.0320"); + assertFillCoordinateComponent(10.032f, " 010.0320"); + assertFillCoordinateComponent(-100.0321f,"-100.0321"); + } + + private void assertFillCoordinateComponent(Float component, String excepted) { + String actual = ObserveI18nLabelsBuilder.fillCoordinateComponent(3,component); + Assert.assertEquals(excepted, actual); + } +} ===================================== pom.xml ===================================== @@ -147,7 +147,7 @@ <maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format> <buildDate>${maven.build.timestamp}</buildDate> - <toolkit.version>5.0.3</toolkit.version> + <toolkit.version>5.0.4-SNAPSHOT</toolkit.version> <lib.version.ognl>3.1.28</lib.version.ognl> <!--can't use 1.4.197 (date has changed + blob also)--> ===================================== services/i18n/src/main/i18n/translations/services_en_GB.properties ===================================== @@ -1,9 +1,10 @@ boolean.false=No boolean.true=Yes observe.Id.comment=Comment +observe.Id.coordinate=Coordinate observe.Id.country=Country observe.Id.description=Description -observe.Id.gearCharacteristic=Caracteristic +observe.Id.gearCharacteristic=Characteristic observe.Id.homeId=Home id observe.Id.latitude=Latitude observe.Id.longitude=Longitude @@ -45,9 +46,9 @@ observe.constant.NonTargetCatchReleaseStatus.P=Perfect observe.constant.NonTargetCatchReleaseStatus.S=Bad observe.constant.NonTargetCatchReleaseStatus.U=Unknown observe.constant.ObserveModelType.LL=Longline -observe.constant.ObserveModelType.LL.description=Display Palangre's programs +observe.constant.ObserveModelType.LL.description=Display Longline programs observe.constant.ObserveModelType.PS=Seine -observe.constant.ObserveModelType.PS.description=Display Seine's programs +observe.constant.ObserveModelType.PS.description=Display Senne programs observe.constant.TripMapPointType.llActivityLogbook=Logbook - Other activity observe.constant.TripMapPointType.llActivityLogbookInHarbour=Logbook - At Harbour observe.constant.TripMapPointType.llActivityLogbookWithHaulingEnd=Logbook - Hauling end ===================================== services/i18n/src/main/i18n/translations/services_es_ES.properties ===================================== @@ -1,6 +1,7 @@ boolean.false=No boolean.true=Si observe.Id.comment=Commentario +observe.Id.coordinate=Coordinate \#TODO observe.Id.country=País observe.Id.description=Descripción observe.Id.gearCharacteristic=Característica ===================================== services/i18n/src/main/i18n/translations/services_fr_FR.properties ===================================== @@ -1,6 +1,7 @@ boolean.false=Non boolean.true=Oui observe.Id.comment=Commentaire +observe.Id.coordinate=Coordonnées observe.Id.country=Pays observe.Id.description=Description observe.Id.gearCharacteristic=Caractéristique View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/d48b24a9f6efef849b39853d6... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/d48b24a9f6efef849b39853d6... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT