Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe
Commits:
-
fd9b4b6d
by Tony CHEMIT at 2018-07-10T13:25:41Z
9 changed files:
- + client/src/main/java/fr/ird/observe/client/ui/actions/content/LonglineDetailCompositionDeleteAllSectionsAction.java
- + client/src/main/java/fr/ird/observe/client/ui/actions/content/LonglineDetailCompositionGenerateAllSectionsAction.java
- client/src/main/java/fr/ird/observe/client/ui/content/data/longline/BasketsTableModel.java
- client/src/main/java/fr/ird/observe/client/ui/content/data/longline/BranchlinesTableModel.java
- client/src/main/java/fr/ird/observe/client/ui/content/data/longline/LonglineDetailCompositionUI.jaxx
- client/src/main/java/fr/ird/observe/client/ui/content/data/longline/LonglineDetailCompositionUI.jcss
- client/src/main/java/fr/ird/observe/client/ui/content/data/longline/LonglineDetailCompositionUIHandler.java
- client/src/main/java/fr/ird/observe/client/ui/content/data/longline/LonglineDetailCompositionUIValidationHelper.java
- client/src/main/java/fr/ird/observe/client/ui/content/data/longline/SectionsTableModel.java
Changes:
| 1 |
+package fr.ird.observe.client.ui.actions.content;
|
|
| 2 |
+ |
|
| 3 |
+import fr.ird.observe.client.ObserveSwingApplicationContext;
|
|
| 4 |
+import fr.ird.observe.client.ui.ObserveKeyStrokes;
|
|
| 5 |
+import fr.ird.observe.client.ui.ObserveMainUI;
|
|
| 6 |
+import fr.ird.observe.client.ui.content.ContentUI;
|
|
| 7 |
+import fr.ird.observe.client.ui.content.data.longline.LonglineDetailCompositionUI;
|
|
| 8 |
+import fr.ird.observe.client.ui.content.data.longline.LonglineDetailCompositionUIValidationHelper;
|
|
| 9 |
+import fr.ird.observe.client.ui.content.data.longline.SectionsTableModel;
|
|
| 10 |
+import fr.ird.observe.client.ui.util.UIHelper;
|
|
| 11 |
+import fr.ird.observe.dto.data.longline.SectionWithTemplate;
|
|
| 12 |
+import org.apache.commons.logging.Log;
|
|
| 13 |
+import org.apache.commons.logging.LogFactory;
|
|
| 14 |
+ |
|
| 15 |
+import javax.swing.JOptionPane;
|
|
| 16 |
+import java.util.ArrayList;
|
|
| 17 |
+ |
|
| 18 |
+import static org.nuiton.i18n.I18n.t;
|
|
| 19 |
+ |
|
| 20 |
+/**
|
|
| 21 |
+ * Created by tchemit on 10/07/2018.
|
|
| 22 |
+ *
|
|
| 23 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 24 |
+ */
|
|
| 25 |
+public class LonglineDetailCompositionDeleteAllSectionsAction extends AbstractContentUIAction {
|
|
| 26 |
+ |
|
| 27 |
+ public static final String ACTION_NAME = LonglineDetailCompositionDeleteAllSectionsAction.class.getName();
|
|
| 28 |
+ private static final Log log = LogFactory.getLog(LonglineDetailCompositionDeleteAllSectionsAction.class);
|
|
| 29 |
+ |
|
| 30 |
+ public LonglineDetailCompositionDeleteAllSectionsAction(ObserveMainUI mainUI) {
|
|
| 31 |
+ super(mainUI, NAME, t("observe.common.LonglineDetailCompositionDto.action.deleteAllSections"), t("observe.common.LonglineDetailCompositionDto.action.deleteAllSections.tip"), "delete", ObserveKeyStrokes.KEY_STROKE_DELETE_DATA_GLOBAL);
|
|
| 32 |
+ }
|
|
| 33 |
+ |
|
| 34 |
+ @Override
|
|
| 35 |
+ protected void actionPerformed(ContentUI<?, ?> contentUI) {
|
|
| 36 |
+ |
|
| 37 |
+ LonglineDetailCompositionUI ui = (LonglineDetailCompositionUI) contentUI;
|
|
| 38 |
+ |
|
| 39 |
+ LonglineDetailCompositionUIValidationHelper validationHelper = ui.getHandler().getValidationHelper();
|
|
| 40 |
+ |
|
| 41 |
+ if (log.isInfoEnabled()) {
|
|
| 42 |
+ log.info("Generate all sections.");
|
|
| 43 |
+ }
|
|
| 44 |
+ |
|
| 45 |
+ SectionsTableModel sectionsTableModel = ui.getSectionsTableModel();
|
|
| 46 |
+ if (sectionsTableModel.isEmpty()) {
|
|
| 47 |
+ |
|
| 48 |
+ // no section
|
|
| 49 |
+ return;
|
|
| 50 |
+ }
|
|
| 51 |
+ |
|
| 52 |
+ boolean canDelete = true;
|
|
| 53 |
+ for (SectionWithTemplate sectionWithTemplate : sectionsTableModel.getNotEmptyData()) {
|
|
| 54 |
+ |
|
| 55 |
+ if (!ui.getHandler().canDeleteSection(sectionWithTemplate.getDelegate())) {
|
|
| 56 |
+ canDelete = false;
|
|
| 57 |
+ break;
|
|
| 58 |
+ }
|
|
| 59 |
+ }
|
|
| 60 |
+ |
|
| 61 |
+ if (!canDelete) {
|
|
| 62 |
+ |
|
| 63 |
+ // there is some references, can't delete
|
|
| 64 |
+ UIHelper.displayWarning(t("observe.common.LonglineDetailCompositionDto.section.cant.delete.title"), t("observe.common.LonglineDetailCompositionDto.section.cant.delete.message"));
|
|
| 65 |
+ return;
|
|
| 66 |
+ |
|
| 67 |
+ }
|
|
| 68 |
+ |
|
| 69 |
+ ObserveMainUI mainUI = ObserveSwingApplicationContext.get().getMainUI();
|
|
| 70 |
+ int response = UIHelper.askUser(mainUI,
|
|
| 71 |
+ t("observe.title.delete"),
|
|
| 72 |
+ t("observe.common.LonglineDetailCompositionDto.section.delete.message"),
|
|
| 73 |
+ JOptionPane.WARNING_MESSAGE,
|
|
| 74 |
+ new Object[]{t("observe.choice.confirm.delete"),
|
|
| 75 |
+ t("observe.choice.cancel")},
|
|
| 76 |
+ 1);
|
|
| 77 |
+ |
|
| 78 |
+ if (response != 0) {
|
|
| 79 |
+ |
|
| 80 |
+ // user cancel
|
|
| 81 |
+ return;
|
|
| 82 |
+ }
|
|
| 83 |
+ |
|
| 84 |
+ if (log.isInfoEnabled()) {
|
|
| 85 |
+ log.info("Remove all sections.");
|
|
| 86 |
+ }
|
|
| 87 |
+ |
|
| 88 |
+ validationHelper.setObjectValueAdjusting(true);
|
|
| 89 |
+ |
|
| 90 |
+ try {
|
|
| 91 |
+ |
|
| 92 |
+ sectionsTableModel.setData(new ArrayList<>());
|
|
| 93 |
+ ui.getBean().getSection().clear();
|
|
| 94 |
+ ui.getModel().setModified(true);
|
|
| 95 |
+ |
|
| 96 |
+ } finally {
|
|
| 97 |
+ |
|
| 98 |
+ validationHelper.setObjectValueAdjusting(false);
|
|
| 99 |
+ validationHelper.whenSectionChanged();
|
|
| 100 |
+ |
|
| 101 |
+ }
|
|
| 102 |
+ }
|
|
| 103 |
+ |
|
| 104 |
+}
|
| 1 |
+package fr.ird.observe.client.ui.actions.content;
|
|
| 2 |
+ |
|
| 3 |
+import com.google.common.collect.Lists;
|
|
| 4 |
+import fr.ird.observe.client.ui.ObserveKeyStrokes;
|
|
| 5 |
+import fr.ird.observe.client.ui.ObserveMainUI;
|
|
| 6 |
+import fr.ird.observe.client.ui.content.ContentUI;
|
|
| 7 |
+import fr.ird.observe.client.ui.content.data.longline.BasketsTableModel;
|
|
| 8 |
+import fr.ird.observe.client.ui.content.data.longline.BranchlinesTableModel;
|
|
| 9 |
+import fr.ird.observe.client.ui.content.data.longline.LonglineDetailCompositionUI;
|
|
| 10 |
+import fr.ird.observe.client.ui.content.data.longline.LonglineDetailCompositionUIValidationHelper;
|
|
| 11 |
+import fr.ird.observe.client.ui.content.data.longline.SectionTemplatesTableModel;
|
|
| 12 |
+import fr.ird.observe.client.ui.content.data.longline.SectionsTableModel;
|
|
| 13 |
+import fr.ird.observe.client.ui.util.UIHelper;
|
|
| 14 |
+import fr.ird.observe.dto.data.longline.BasketDto;
|
|
| 15 |
+import fr.ird.observe.dto.data.longline.BranchlineDto;
|
|
| 16 |
+import fr.ird.observe.dto.data.longline.SectionDto;
|
|
| 17 |
+import fr.ird.observe.dto.data.longline.SectionTemplate;
|
|
| 18 |
+import fr.ird.observe.dto.data.longline.SectionWithTemplate;
|
|
| 19 |
+import fr.ird.observe.dto.data.longline.SetLonglineDetailCompositionDto;
|
|
| 20 |
+import org.apache.commons.logging.Log;
|
|
| 21 |
+import org.apache.commons.logging.LogFactory;
|
|
| 22 |
+ |
|
| 23 |
+import java.util.ArrayList;
|
|
| 24 |
+import java.util.LinkedList;
|
|
| 25 |
+import java.util.List;
|
|
| 26 |
+import java.util.stream.Collectors;
|
|
| 27 |
+ |
|
| 28 |
+import static org.nuiton.i18n.I18n.t;
|
|
| 29 |
+ |
|
| 30 |
+/**
|
|
| 31 |
+ * Created by tchemit on 10/07/2018.
|
|
| 32 |
+ *
|
|
| 33 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 34 |
+ */
|
|
| 35 |
+public class LonglineDetailCompositionGenerateAllSectionsAction extends AbstractContentUIAction {
|
|
| 36 |
+ |
|
| 37 |
+ public static final String ACTION_NAME = LonglineDetailCompositionGenerateAllSectionsAction.class.getName();
|
|
| 38 |
+ private static final Log log = LogFactory.getLog(LonglineDetailCompositionGenerateAllSectionsAction.class);
|
|
| 39 |
+ public LonglineDetailCompositionGenerateAllSectionsAction(ObserveMainUI mainUI) {
|
|
| 40 |
+ |
|
| 41 |
+ super(mainUI, ACTION_NAME, t("observe.common.LonglineDetailCompositionDto.action.generateAllSections"), t("observe.common.LonglineDetailCompositionDto.action.generateAllSections.tip"), "generate", ObserveKeyStrokes.KEY_STROKE_NEW_NEXT_DATA);
|
|
| 42 |
+ }
|
|
| 43 |
+ |
|
| 44 |
+ @Override
|
|
| 45 |
+ protected void actionPerformed(ContentUI<?, ?> contentUI) {
|
|
| 46 |
+ |
|
| 47 |
+ LonglineDetailCompositionUI ui = (LonglineDetailCompositionUI) contentUI;
|
|
| 48 |
+ |
|
| 49 |
+ LonglineDetailCompositionUIValidationHelper validationHelper = ui.getHandler().getValidationHelper();
|
|
| 50 |
+ |
|
| 51 |
+ if (log.isInfoEnabled()) {
|
|
| 52 |
+ log.info("Generate all sections.");
|
|
| 53 |
+ }
|
|
| 54 |
+ |
|
| 55 |
+ SetLonglineDetailCompositionDto bean = ui.getBean();
|
|
| 56 |
+ Integer nbSections = bean.getTotalSectionsCount();
|
|
| 57 |
+ Integer basketsCount = bean.getBasketsPerSectionCount();
|
|
| 58 |
+ Integer nbBranchlines = bean.getBranchlinesPerBasketCount();
|
|
| 59 |
+ |
|
| 60 |
+ SectionTemplate template = null;
|
|
| 61 |
+ |
|
| 62 |
+ SectionTemplatesTableModel sectionTemplatesTableModel = ui.getSectionTemplatesTableModel();
|
|
| 63 |
+ List<SectionTemplate> sectionTemplates = sectionTemplatesTableModel.getNotEmptyData();
|
|
| 64 |
+ if (sectionTemplates.size() == 1) {
|
|
| 65 |
+ |
|
| 66 |
+ template = sectionTemplates.get(0);
|
|
| 67 |
+ |
|
| 68 |
+ boolean compliantWithBasketCount = template.isCompiliantWithBasketCount(basketsCount);
|
|
| 69 |
+ if (!compliantWithBasketCount) {
|
|
| 70 |
+ |
|
| 71 |
+ if (log.isWarnEnabled()) {
|
|
| 72 |
+ log.warn("sectionTemplate " + template + " is not compliant with basketCount: " + basketsCount);
|
|
| 73 |
+ }
|
|
| 74 |
+ |
|
| 75 |
+ UIHelper.displayWarning(t("observe.common.LonglineDetailCompositionDto.title.section.cant.use.firstTemplate"), t("observe.common.LonglineDetailCompositionDto.firstTemplate.template.notCompilant.basketCount", template.getFloatlineLengths(), basketsCount));
|
|
| 76 |
+ |
|
| 77 |
+ template = null;
|
|
| 78 |
+ |
|
| 79 |
+ }
|
|
| 80 |
+ |
|
| 81 |
+ }
|
|
| 82 |
+ |
|
| 83 |
+ boolean usingTemplate = template != null;
|
|
| 84 |
+ |
|
| 85 |
+ if (usingTemplate) {
|
|
| 86 |
+ |
|
| 87 |
+ if (log.isInfoEnabled()) {
|
|
| 88 |
+ log.info("Will use sectionTemplate: " + template);
|
|
| 89 |
+ }
|
|
| 90 |
+ }
|
|
| 91 |
+ |
|
| 92 |
+ validationHelper.setObjectValueAdjusting(true);
|
|
| 93 |
+ |
|
| 94 |
+ try {
|
|
| 95 |
+ |
|
| 96 |
+ SectionsTableModel sectionsTableModel = ui.getSectionsTableModel();
|
|
| 97 |
+ BasketsTableModel basketsTableModel = ui.getBasketsTableModel();
|
|
| 98 |
+ BranchlinesTableModel branchlinesTableModel = ui.getBranchlinesTableModel();
|
|
| 99 |
+ |
|
| 100 |
+ List<SectionWithTemplate> sections = new ArrayList<>(nbSections);
|
|
| 101 |
+ |
|
| 102 |
+ for (int sectionNumber = 0; sectionNumber < nbSections; sectionNumber++) {
|
|
| 103 |
+ |
|
| 104 |
+ SectionWithTemplate section = sectionsTableModel.createNewRow();
|
|
| 105 |
+ sections.add(section);
|
|
| 106 |
+ |
|
| 107 |
+ for (int basketNumber = 0; basketNumber < basketsCount; basketNumber++) {
|
|
| 108 |
+ |
|
| 109 |
+ BasketDto basket = basketsTableModel.createNewRow();
|
|
| 110 |
+ section.addBasket(basket);
|
|
| 111 |
+ |
|
| 112 |
+ for (int branchlineNumber = 0; branchlineNumber < nbBranchlines; branchlineNumber++) {
|
|
| 113 |
+ |
|
| 114 |
+ BranchlineDto branchline = branchlinesTableModel.createNewRow();
|
|
| 115 |
+ basket.addBranchline(branchline);
|
|
| 116 |
+ |
|
| 117 |
+ }
|
|
| 118 |
+ |
|
| 119 |
+ LinkedList<BranchlineDto> branchlines = Lists.newLinkedList(basket.getBranchline());
|
|
| 120 |
+ branchlinesTableModel.rearrangeIds(branchlines);
|
|
| 121 |
+ |
|
| 122 |
+ }
|
|
| 123 |
+ |
|
| 124 |
+ List<BasketDto> baskets = Lists.newLinkedList(section.getBasket());
|
|
| 125 |
+ basketsTableModel.rearrangeIds(baskets);
|
|
| 126 |
+ |
|
| 127 |
+ if (usingTemplate) {
|
|
| 128 |
+ |
|
| 129 |
+ section.setSectionTemplate(template);
|
|
| 130 |
+ template.applyToBaskets(baskets);
|
|
| 131 |
+ |
|
| 132 |
+ }
|
|
| 133 |
+ |
|
| 134 |
+ }
|
|
| 135 |
+ |
|
| 136 |
+ sectionsTableModel.rearrangeIds(sections);
|
|
| 137 |
+ sectionsTableModel.setData(sections);
|
|
| 138 |
+ |
|
| 139 |
+ List<SectionDto> sectionHelper = sections.stream()
|
|
| 140 |
+ .map(SectionWithTemplate::getDelegate)
|
|
| 141 |
+ .collect(Collectors.toList());
|
|
| 142 |
+ |
|
| 143 |
+ ui.getBean().addAllSection(sectionHelper);
|
|
| 144 |
+ |
|
| 145 |
+ ui.getModel().setModified(true);
|
|
| 146 |
+ |
|
| 147 |
+ } finally {
|
|
| 148 |
+ |
|
| 149 |
+ validationHelper.setObjectValueAdjusting(false);
|
|
| 150 |
+ validationHelper.whenSectionChanged();
|
|
| 151 |
+ |
|
| 152 |
+ }
|
|
| 153 |
+ }
|
|
| 154 |
+ |
|
| 155 |
+}
|
| ... | ... | @@ -40,7 +40,7 @@ public class BasketsTableModel extends LonglineCompositionTableModelSupport<Bask |
| 40 | 40 |
}
|
| 41 | 41 |
|
| 42 | 42 |
@Override
|
| 43 |
- protected BasketDto createNewRow() {
|
|
| 43 |
+ public BasketDto createNewRow() {
|
|
| 44 | 44 |
return new BasketDto();
|
| 45 | 45 |
}
|
| 46 | 46 |
|
| ... | ... | @@ -49,7 +49,7 @@ public class BranchlinesTableModel extends LonglineCompositionTableModelSupport< |
| 49 | 49 |
}
|
| 50 | 50 |
|
| 51 | 51 |
@Override
|
| 52 |
- protected BranchlineDto createNewRow() {
|
|
| 52 |
+ public BranchlineDto createNewRow() {
|
|
| 53 | 53 |
|
| 54 | 54 |
BranchlineDto branchline = new BranchlineDto();
|
| 55 | 55 |
branchline.setTimerTimeOnBoard(defaultDate);
|
| ... | ... | @@ -26,6 +26,8 @@ |
| 26 | 26 |
<import>
|
| 27 | 27 |
fr.ird.observe.client.ObserveSwingApplicationContext
|
| 28 | 28 |
fr.ird.observe.dto.data.longline.SetLonglineDetailCompositionDto
|
| 29 |
+ fr.ird.observe.client.ui.actions.content.LonglineDetailCompositionDeleteAllSectionsAction
|
|
| 30 |
+ fr.ird.observe.client.ui.actions.content.LonglineDetailCompositionGenerateAllSectionsAction
|
|
| 29 | 31 |
fr.ird.observe.client.ui.actions.content.ResetEditUIAction
|
| 30 | 32 |
fr.ird.observe.client.ui.actions.content.SaveEditUIAction
|
| 31 | 33 |
fr.ird.observe.client.ui.actions.main.global.ResetDataGlobalUIAction
|
| ... | ... | @@ -146,8 +148,8 @@ |
| 146 | 148 |
<JPanel layout='{new BorderLayout()}'>
|
| 147 | 149 |
|
| 148 | 150 |
<JPanel id="compositionActionPanel" constraints='BorderLayout.NORTH' layout='{new GridLayout()}'>
|
| 149 |
- <JButton id='generateAll' onActionPerformed='getHandler().generateAllSections()'/>
|
|
| 150 |
- <JButton id='deleteAll' onActionPerformed='getHandler().deleteAllSections()'/>
|
|
| 151 |
+ <JButton id='generateAll' />
|
|
| 152 |
+ <JButton id='deleteAll' />
|
|
| 151 | 153 |
</JPanel>
|
| 152 | 154 |
|
| 153 | 155 |
<JPanel id="compositionTablesPanel" constraints='BorderLayout.CENTER' layout='{new GridLayout(0,1)}'>
|
| ... | ... | @@ -81,17 +81,13 @@ |
| 81 | 81 |
}
|
| 82 | 82 |
|
| 83 | 83 |
#generateAll {
|
| 84 |
- text: "observe.common.LonglineDetailCompositionDto.action.generateAllSections";
|
|
| 85 |
- toolTipText: "observe.common.LonglineDetailCompositionDto.action.generateAllSections.tip";
|
|
| 86 |
- actionIcon: generate;
|
|
| 84 |
+ _observeAction:{LonglineDetailCompositionGenerateAllSectionsAction.ACTION_NAME};
|
|
| 87 | 85 |
visible: {model.isUpdatingMode()};
|
| 88 | 86 |
enabled: {model.isCanGenerate() && sectionsTableModel.isEmpty()};
|
| 89 | 87 |
}
|
| 90 | 88 |
|
| 91 | 89 |
#deleteAll {
|
| 92 |
- text: "observe.common.LonglineDetailCompositionDto.action.deleteAllSections";
|
|
| 93 |
- toolTipText: "observe.common.LonglineDetailCompositionDto.action.deleteAllSections.tip";
|
|
| 94 |
- actionIcon: delete;
|
|
| 90 |
+ _observeAction:{LonglineDetailCompositionDeleteAllSectionsAction.ACTION_NAME};
|
|
| 95 | 91 |
visible: {model.isUpdatingMode()};
|
| 96 | 92 |
enabled: {!sectionsTableModel.isEmpty()};
|
| 97 | 93 |
}
|
| ... | ... | @@ -22,7 +22,6 @@ package fr.ird.observe.client.ui.content.data.longline; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import com.google.common.collect.Lists;
|
|
| 26 | 25 |
import fr.ird.observe.client.ObserveSwingApplicationContext;
|
| 27 | 26 |
import fr.ird.observe.client.db.ClientDataContext;
|
| 28 | 27 |
import fr.ird.observe.client.db.ObserveSwingDataSource;
|
| ... | ... | @@ -64,10 +63,8 @@ import javax.swing.event.TableModelListener; |
| 64 | 63 |
import java.beans.PropertyChangeListener;
|
| 65 | 64 |
import java.util.ArrayList;
|
| 66 | 65 |
import java.util.LinkedHashSet;
|
| 67 |
-import java.util.LinkedList;
|
|
| 68 | 66 |
import java.util.List;
|
| 69 | 67 |
import java.util.Optional;
|
| 70 |
-import java.util.stream.Collectors;
|
|
| 71 | 68 |
|
| 72 | 69 |
import static com.google.common.collect.Lists.newArrayList;
|
| 73 | 70 |
import static org.nuiton.i18n.I18n.t;
|
| ... | ... | @@ -490,174 +487,6 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong |
| 490 | 487 |
return continueSave;
|
| 491 | 488 |
}
|
| 492 | 489 |
|
| 493 |
- public void generateAllSections() {
|
|
| 494 |
- |
|
| 495 |
- if (log.isInfoEnabled()) {
|
|
| 496 |
- log.info("Generate all sections.");
|
|
| 497 |
- }
|
|
| 498 |
- |
|
| 499 |
- SetLonglineDetailCompositionDto bean = getBean();
|
|
| 500 |
- Integer nbSections = bean.getTotalSectionsCount();
|
|
| 501 |
- Integer basketsCount = bean.getBasketsPerSectionCount();
|
|
| 502 |
- Integer nbBranchlines = bean.getBranchlinesPerBasketCount();
|
|
| 503 |
- |
|
| 504 |
- SectionTemplate template = null;
|
|
| 505 |
- |
|
| 506 |
- SectionTemplatesTableModel sectionTemplatesTableModel = getSectionTemplatesTableModel();
|
|
| 507 |
- List<SectionTemplate> sectionTemplates = sectionTemplatesTableModel.getNotEmptyData();
|
|
| 508 |
- if (sectionTemplates.size() == 1) {
|
|
| 509 |
- |
|
| 510 |
- template = sectionTemplates.get(0);
|
|
| 511 |
- |
|
| 512 |
- boolean compliantWithBasketCount = template.isCompiliantWithBasketCount(basketsCount);
|
|
| 513 |
- if (!compliantWithBasketCount) {
|
|
| 514 |
- |
|
| 515 |
- if (log.isWarnEnabled()) {
|
|
| 516 |
- log.warn("sectionTemplate " + template + " is not compliant with basketCount: " + basketsCount);
|
|
| 517 |
- }
|
|
| 518 |
- |
|
| 519 |
- UIHelper.displayWarning(t("observe.common.LonglineDetailCompositionDto.title.section.cant.use.firstTemplate"), t("observe.common.LonglineDetailCompositionDto.firstTemplate.template.notCompilant.basketCount", template.getFloatlineLengths(), basketsCount));
|
|
| 520 |
- |
|
| 521 |
- template = null;
|
|
| 522 |
- |
|
| 523 |
- }
|
|
| 524 |
- |
|
| 525 |
- }
|
|
| 526 |
- |
|
| 527 |
- boolean usingTemplate = template != null;
|
|
| 528 |
- |
|
| 529 |
- if (usingTemplate) {
|
|
| 530 |
- |
|
| 531 |
- if (log.isInfoEnabled()) {
|
|
| 532 |
- log.info("Will use sectionTemplate: " + template);
|
|
| 533 |
- }
|
|
| 534 |
- }
|
|
| 535 |
- |
|
| 536 |
- validationHelper.setObjectValueAdjusting(true);
|
|
| 537 |
- |
|
| 538 |
- try {
|
|
| 539 |
- |
|
| 540 |
- SectionsTableModel sectionsTableModel = getSectionsTableModel();
|
|
| 541 |
- BasketsTableModel basketsTableModel = getBasketsTableModel();
|
|
| 542 |
- BranchlinesTableModel branchlinesTableModel = getBranchlinesTableModel();
|
|
| 543 |
- |
|
| 544 |
- List<SectionWithTemplate> sections = new ArrayList<>(nbSections);
|
|
| 545 |
- |
|
| 546 |
- for (int sectionNumber = 0; sectionNumber < nbSections; sectionNumber++) {
|
|
| 547 |
- |
|
| 548 |
- SectionWithTemplate section = sectionsTableModel.createNewRow();
|
|
| 549 |
- sections.add(section);
|
|
| 550 |
- |
|
| 551 |
- for (int basketNumber = 0; basketNumber < basketsCount; basketNumber++) {
|
|
| 552 |
- |
|
| 553 |
- BasketDto basket = basketsTableModel.createNewRow();
|
|
| 554 |
- section.addBasket(basket);
|
|
| 555 |
- |
|
| 556 |
- for (int branchlineNumber = 0; branchlineNumber < nbBranchlines; branchlineNumber++) {
|
|
| 557 |
- |
|
| 558 |
- BranchlineDto branchline = branchlinesTableModel.createNewRow();
|
|
| 559 |
- basket.addBranchline(branchline);
|
|
| 560 |
- |
|
| 561 |
- }
|
|
| 562 |
- |
|
| 563 |
- LinkedList<BranchlineDto> branchlines = Lists.newLinkedList(basket.getBranchline());
|
|
| 564 |
- branchlinesTableModel.rearrangeIds(branchlines);
|
|
| 565 |
- |
|
| 566 |
- }
|
|
| 567 |
- |
|
| 568 |
- List<BasketDto> baskets = Lists.newLinkedList(section.getBasket());
|
|
| 569 |
- basketsTableModel.rearrangeIds(baskets);
|
|
| 570 |
- |
|
| 571 |
- if (usingTemplate) {
|
|
| 572 |
- |
|
| 573 |
- section.setSectionTemplate(template);
|
|
| 574 |
- template.applyToBaskets(baskets);
|
|
| 575 |
- |
|
| 576 |
- }
|
|
| 577 |
- |
|
| 578 |
- }
|
|
| 579 |
- |
|
| 580 |
- sectionsTableModel.rearrangeIds(sections);
|
|
| 581 |
- sectionsTableModel.setData(sections);
|
|
| 582 |
- |
|
| 583 |
- List<SectionDto> sectionHelper = sections.stream()
|
|
| 584 |
- .map(SectionWithTemplate::getDelegate)
|
|
| 585 |
- .collect(Collectors.toList());
|
|
| 586 |
- |
|
| 587 |
- getBean().addAllSection(sectionHelper);
|
|
| 588 |
- |
|
| 589 |
- getModel().setModified(true);
|
|
| 590 |
- |
|
| 591 |
- } finally {
|
|
| 592 |
- |
|
| 593 |
- validationHelper.setObjectValueAdjusting(false);
|
|
| 594 |
- validationHelper.whenSectionChanged();
|
|
| 595 |
- |
|
| 596 |
- }
|
|
| 597 |
- |
|
| 598 |
- }
|
|
| 599 |
- |
|
| 600 |
- public void deleteAllSections() {
|
|
| 601 |
- |
|
| 602 |
- if (getSectionsTableModel().isEmpty()) {
|
|
| 603 |
- |
|
| 604 |
- // no section
|
|
| 605 |
- return;
|
|
| 606 |
- }
|
|
| 607 |
- |
|
| 608 |
- boolean canDelete = true;
|
|
| 609 |
- for (SectionWithTemplate sectionWithTemplate : getSectionsTableModel().getNotEmptyData()) {
|
|
| 610 |
- |
|
| 611 |
- if (!canDeleteSection(sectionWithTemplate.getDelegate())) {
|
|
| 612 |
- canDelete = false;
|
|
| 613 |
- break;
|
|
| 614 |
- }
|
|
| 615 |
- }
|
|
| 616 |
- |
|
| 617 |
- if (!canDelete) {
|
|
| 618 |
- |
|
| 619 |
- // there is some references, can't delete
|
|
| 620 |
- UIHelper.displayWarning(t("observe.common.LonglineDetailCompositionDto.section.cant.delete.title"), t("observe.common.LonglineDetailCompositionDto.section.cant.delete.message"));
|
|
| 621 |
- return;
|
|
| 622 |
- |
|
| 623 |
- }
|
|
| 624 |
- |
|
| 625 |
- ObserveMainUI mainUI = ObserveSwingApplicationContext.get().getMainUI();
|
|
| 626 |
- int response = UIHelper.askUser(mainUI,
|
|
| 627 |
- t("observe.title.delete"),
|
|
| 628 |
- t("observe.common.LonglineDetailCompositionDto.section.delete.message"),
|
|
| 629 |
- JOptionPane.WARNING_MESSAGE,
|
|
| 630 |
- new Object[]{t("observe.choice.confirm.delete"),
|
|
| 631 |
- t("observe.choice.cancel")},
|
|
| 632 |
- 1);
|
|
| 633 |
- |
|
| 634 |
- if (response != 0) {
|
|
| 635 |
- |
|
| 636 |
- // user cancel
|
|
| 637 |
- return;
|
|
| 638 |
- }
|
|
| 639 |
- |
|
| 640 |
- if (log.isInfoEnabled()) {
|
|
| 641 |
- log.info("Remove all sections.");
|
|
| 642 |
- }
|
|
| 643 |
- |
|
| 644 |
- validationHelper.setObjectValueAdjusting(true);
|
|
| 645 |
- |
|
| 646 |
- try {
|
|
| 647 |
- |
|
| 648 |
- getSectionsTableModel().setData(new ArrayList<>());
|
|
| 649 |
- getBean().getSection().clear();
|
|
| 650 |
- getModel().setModified(true);
|
|
| 651 |
- |
|
| 652 |
- } finally {
|
|
| 653 |
- |
|
| 654 |
- validationHelper.setObjectValueAdjusting(false);
|
|
| 655 |
- validationHelper.whenSectionChanged();
|
|
| 656 |
- |
|
| 657 |
- }
|
|
| 658 |
- |
|
| 659 |
- }
|
|
| 660 |
- |
|
| 661 | 490 |
public void insertBeforeSelectedSectionTemplate() {
|
| 662 | 491 |
getSectionTemplatesTableModel().insertBeforeSelectedRow();
|
| 663 | 492 |
}
|
| ... | ... | @@ -1367,7 +1196,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong |
| 1367 | 1196 |
return getUi().getBranchlineDetailUIModel();
|
| 1368 | 1197 |
}
|
| 1369 | 1198 |
|
| 1370 |
- private boolean canDeleteSection(SectionDto section) {
|
|
| 1199 |
+ public boolean canDeleteSection(SectionDto section) {
|
|
| 1371 | 1200 |
|
| 1372 | 1201 |
return section.isNotPersisted() || getSetLonglineDetailCompositionService().canDeleteSection(section.getId());
|
| 1373 | 1202 |
|
| ... | ... | @@ -1385,4 +1214,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong |
| 1385 | 1214 |
|
| 1386 | 1215 |
}
|
| 1387 | 1216 |
|
| 1217 |
+ public LonglineDetailCompositionUIValidationHelper getValidationHelper() {
|
|
| 1218 |
+ return validationHelper;
|
|
| 1219 |
+ }
|
|
| 1388 | 1220 |
}
|
| ... | ... | @@ -47,7 +47,7 @@ import java.util.Set; |
| 47 | 47 |
* @author Tony Chemit - dev@tchemit.fr
|
| 48 | 48 |
* @since 3.15
|
| 49 | 49 |
*/
|
| 50 |
-class LonglineDetailCompositionUIValidationHelper {
|
|
| 50 |
+public class LonglineDetailCompositionUIValidationHelper {
|
|
| 51 | 51 |
|
| 52 | 52 |
/** Logger. */
|
| 53 | 53 |
private static final Log log = LogFactory.getLog(LonglineDetailCompositionUIValidationHelper.class);
|
| ... | ... | @@ -89,7 +89,7 @@ class LonglineDetailCompositionUIValidationHelper { |
| 89 | 89 |
);
|
| 90 | 90 |
}
|
| 91 | 91 |
|
| 92 |
- void whenSectionChanged() {
|
|
| 92 |
+ public void whenSectionChanged() {
|
|
| 93 | 93 |
|
| 94 | 94 |
if (!objectValueAdjusting) {
|
| 95 | 95 |
|
| ... | ... | @@ -157,7 +157,7 @@ class LonglineDetailCompositionUIValidationHelper { |
| 157 | 157 |
});
|
| 158 | 158 |
}
|
| 159 | 159 |
|
| 160 |
- void setObjectValueAdjusting(boolean objectValueAdjusting) {
|
|
| 160 |
+ public void setObjectValueAdjusting(boolean objectValueAdjusting) {
|
|
| 161 | 161 |
this.objectValueAdjusting = objectValueAdjusting;
|
| 162 | 162 |
}
|
| 163 | 163 |
|
| ... | ... | @@ -47,7 +47,7 @@ public class SectionsTableModel extends LonglineCompositionTableModelSupport<Sec |
| 47 | 47 |
}
|
| 48 | 48 |
|
| 49 | 49 |
@Override
|
| 50 |
- protected SectionWithTemplate createNewRow() {
|
|
| 50 |
+ public SectionWithTemplate createNewRow() {
|
|
| 51 | 51 |
return new SectionWithTemplate();
|
| 52 | 52 |
}
|
| 53 | 53 |
|