View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.validation.tree;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2014 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import com.google.common.collect.Lists;
28  import com.google.common.collect.Sets;
29  import fr.ifremer.tutti.persistence.entities.data.Cruise;
30  import jaxx.runtime.SwingUtil;
31  import org.nuiton.validator.NuitonValidatorResult;
32  import org.nuiton.validator.NuitonValidatorScope;
33  
34  import javax.swing.ImageIcon;
35  import java.util.List;
36  import java.util.Set;
37  
38  import static org.nuiton.i18n.I18n.t;
39  
40  /**
41   * Created on 7/9/14.
42   *
43   * @author Tony Chemit - chemit@codelutin.com
44   * @since 3.6
45   */
46  public class CruiseTreeNode extends TuttiMessageNodeSupport<Cruise> {
47  
48      private static final long serialVersionUID = 1L;
49  
50      private static final ImageIcon CRUISE_ICON = SwingUtil.createActionIcon("cruise");
51  
52      public CruiseTreeNode(Cruise cruise, NuitonValidatorResult validationResult) {
53          super(cruise, CRUISE_ICON, null);
54  
55          setAllowsChildren(true);
56          createChildren(validationResult);
57      }
58  
59      public void createChildren(NuitonValidatorResult validationResult) {
60  
61          boolean withMessage = false;
62  
63          if (validationResult.hasFatalMessages()) {
64              addMessages(NuitonValidatorScope.FATAL,
65                          validationResult.getMessagesForScope(NuitonValidatorScope.FATAL));
66              withMessage = true;
67          }
68  
69          if (validationResult.hasErrorMessagess()) {
70              addMessages(NuitonValidatorScope.ERROR,
71                          validationResult.getMessagesForScope(NuitonValidatorScope.ERROR));
72              withMessage = true;
73          }
74  
75          if (validationResult.hasWarningMessages()) {
76              addMessages(NuitonValidatorScope.WARNING,
77                          validationResult.getMessagesForScope(NuitonValidatorScope.WARNING));
78              withMessage = true;
79          }
80  
81          if (!withMessage) {
82              addMessages(NuitonValidatorScope.INFO,
83                          Lists.newArrayList(t("tutti.validator.info.cruise.noError")));
84          }
85      }
86  
87      protected void addMessages(NuitonValidatorScope scope, List<String> messages) {
88          // use a set to remove doublons
89          Set<String> messageSet = Sets.newHashSet(messages);
90          for (String message : messageSet) {
91              MessageTreeNode child = new MessageTreeNode(scope, message, null);
92              this.add(child);
93          }
94      }
95  
96  }