Author: bpoussin Date: 2016-11-09 19:44:50 +0100 (Wed, 09 Nov 2016) New Revision: 4372 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4372 Log: amelioration des propositions Evolution #8737: Export / Import des ?\195?\169l?\195?\169ments d'une r?\195?\169gion, soit pour import dans une autre r?\195?\169gion, soit pour fusion de deux r?\195?\169gions Modified: trunk/src/main/java/fr/ifremer/isisfish/entities/RegionImportJson.java Modified: trunk/src/main/java/fr/ifremer/isisfish/entities/RegionImportJson.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/entities/RegionImportJson.java 2016-11-09 17:45:08 UTC (rev 4371) +++ trunk/src/main/java/fr/ifremer/isisfish/entities/RegionImportJson.java 2016-11-09 18:44:50 UTC (rev 4372) @@ -25,6 +25,7 @@ import javax.swing.JComboBox; import javax.swing.JOptionPane; import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang3.ClassUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.math.matrix.MatrixND; @@ -50,10 +51,17 @@ public class RegionImportJson { static public interface RegionMerge { - static public enum AnwserType {ABORT, IMPORT, IMPORT_ALL_TYPE, IMPORT_ALL, REUSE, NONE}; + static public enum AnwserType { + NONE, + REUSE, REUSE_ONE_TYPE, REUSE_ONE, + IMPORT, IMPORT_ALL_TYPE, IMPORT_ALL, + ABORT + }; static public class RegionMergeContext { protected boolean abort = false; + protected boolean reuseOne = false; + protected Set<Class> reuseOneType = new HashSet<Class>(); protected boolean importAll = false; protected Set<Class> importAllType = new HashSet<Class>(); protected AnwserType lastAnswer = null; @@ -67,6 +75,10 @@ this.importAll = importAll; } + public Class getCurrentType() { + return currentType; + } + public TopiaEntity getReuseEntity() { return reuseEntity; } @@ -75,13 +87,13 @@ return lastAnswer; } - protected void setLastAnswer(TopiaEntity e) { - this.lastAnswer = AnwserType.REUSE; - this.reuseEntity = e; + protected void setLastAnswer(AnwserType lastAnswer) { + this.setLastAnswer(lastAnswer, null); } - protected void setLastAnswer(AnwserType lastAnswer) { + protected void setLastAnswer(AnwserType lastAnswer, TopiaEntity e) { this.lastAnswer = lastAnswer; + this.reuseEntity = e; switch (lastAnswer) { case ABORT: abort = true; @@ -94,6 +106,14 @@ importAll = true; this.lastAnswer = AnwserType.IMPORT; break; + case REUSE_ONE_TYPE: + reuseOneType.add(currentType); + this.lastAnswer = AnwserType.REUSE; + break; + case REUSE_ONE: + reuseOne = true; + this.lastAnswer = AnwserType.REUSE; + break; default: break; } @@ -109,6 +129,16 @@ } return lastAnswer; } + + public AnwserType initAnswer(Class type, Set<TopiaEntity> possible) { + lastAnswer = null; + currentType = type; + if (possible != null && possible.size() == 1 && (reuseOne || reuseOneType.contains(type))) { + lastAnswer = AnwserType.REUSE; + this.reuseEntity = possible.iterator().next(); + } + return lastAnswer; + } } /** @@ -159,11 +189,30 @@ LinkedHashSet<TopiaEntity> possible = new LinkedHashSet<TopiaEntity>(); possible.add(dao.findByTopiaId(id)); - if (details.containsKey("name")) { - possible.addAll(dao.findAllByProperty("name", details.get("name"))); + if (Equation.class.isAssignableFrom(context.getCurrentType())) { + if (details.containsKey("name") && details.containsKey("category")) { + possible.addAll(dao.findAllByProperties("name", details.get("name"), "category", details.get("category"))); + } + } else { + if (details.containsKey("name")) { + possible.addAll(dao.findAllByProperty("name", details.get("name"))); + } } -// possible.addAll(dao.findAllByProperties(details)); + context.initAnswer(type, possible); + + if (context.lastAnswer != null) { + return context; + } + + if (Equation.class.isAssignableFrom(context.getCurrentType())) { + if (details.containsKey("category")) { + possible.addAll(dao.findAllByProperty("category", details.get("category"))); + } + } else { + possible.addAll(dao.findAll()); + } + ask(context, toString, details, possible); return context; @@ -178,6 +227,8 @@ Object[] options = new Object[] { "None", // for null "Reuse selected object", + "Reuse if only one (same type)", + "Reuse if only one (all type)", "Import", "Import All this type", "Import All", @@ -187,12 +238,15 @@ int result = JOptionPane.showOptionDialog(null, new Object[]{ - String.format("You try to import '%s'", toString), + String.format("You try to import '%s' (%s)", toString, + ClassUtils.getShortClassName(context.getCurrentType())), "", "Possible answer are:", "None: don't import nor reuse object", "Reuse: use object already in current Region (make your choice in next combobox).", select, + "Reuse if only one (same type): Answer Reuse and for next time use object found in current Region if only one match 'id' or 'name' for this type", + "Reuse if only one (all type): Answer Reuse and for next time use object found in current Region if only one match 'id' or 'name' for all object", "Import: import object from file.", "Import All this type: auto answer Import for this question and all next question for same object type", "Import All: auto answer Import for this question and all next question.", @@ -205,23 +259,30 @@ options, options[0]); + TopiaEntity selectEntity = (TopiaEntity)select.getSelectedItem(); switch (result) { case 0: context.setLastAnswer(AnwserType.NONE); break; case 1: - context.setLastAnswer((TopiaEntity)select.getSelectedItem()); + context.setLastAnswer(AnwserType.REUSE, selectEntity); break; case 2: + context.setLastAnswer(AnwserType.REUSE_ONE_TYPE, selectEntity); + break; + case 3: + context.setLastAnswer(AnwserType.REUSE_ONE, selectEntity); + break; + case 4: context.setLastAnswer(AnwserType.IMPORT); break; - case 3: + case 5: context.setLastAnswer(AnwserType.IMPORT_ALL_TYPE); break; - case 4: + case 6: context.setLastAnswer(AnwserType.IMPORT_ALL); break; - case 5: + case 7: context.setLastAnswer(AnwserType.ABORT); break; default: