View Javadoc
1   package fr.ifremer.dali.dto.enums;
2   
3   /*
4    * #%L
5    * Dali :: Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (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 Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import fr.ifremer.dali.dto.DaliBeanFactory;
27  import fr.ifremer.dali.dto.StateDTO;
28  
29  import static org.nuiton.i18n.I18n.n;
30  import static org.nuiton.i18n.I18n.t;
31  
32  /**
33   * Etat values.
34   */
35  public enum StateValues {
36  
37      CONTROLLED(n("dali.property.state.controlled"), "control"),
38      VALIDATED(n("dali.property.state.validated"), "accept"),
39      QUALIFIED(n("dali.property.state.qualified"), "qualify");
40  
41      private final String i18nKey;
42      private final String iconAction;
43  
44      StateValues(final String i18nKey, final String iconAction) {
45          this.i18nKey = i18nKey;
46          this.iconAction = iconAction;
47      }
48  
49      /**
50       * <p>getLabel.</p>
51       *
52       * @return a {@link java.lang.String} object.
53       */
54      public String getLabel() {
55          return t(this.i18nKey);
56      }
57  
58      public String getIconAction() {
59          return iconAction;
60      }
61  
62      public StateDTO toStateDTO() {
63          StateDTO state = DaliBeanFactory.newStateDTO();
64          state.setId(ordinal());
65          state.setName(getLabel());
66          state.setIconName(getIconAction());
67          return state;
68      }
69  
70      /**
71       * <p>getState.</p>
72       *
73       * @param label a {@link java.lang.String} object.
74       * @return a {@link fr.ifremer.dali.dto.enums.StateValues} object.
75       */
76      public static StateValues getState(final String label) {
77          if (label != null) {
78              for (final StateValues stateValue : StateValues.values()) {
79                  if (label.equals(stateValue.getLabel())) {
80                      return stateValue;
81                  }
82              }
83          }
84          return null;
85      }
86  }