View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.home;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import fr.ifremer.tutti.persistence.entities.data.Cruise;
26  import fr.ifremer.tutti.persistence.entities.data.Cruises;
27  import fr.ifremer.tutti.persistence.entities.data.Program;
28  import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
29  import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel;
30  
31  import java.util.List;
32  
33  /**
34   * Model of ui {@link SelectCruiseUI}.
35   *
36   * @author Tony Chemit - chemit@codelutin.com
37   * @since 0.1
38   */
39  public class SelectCruiseUIModel extends AbstractTuttiBeanUIModel<Cruise, SelectCruiseUIModel> {
40  
41      private static final long serialVersionUID = 1L;
42  
43      public static final String PROPERTY_PROGRAMS = "programs";
44  
45      public static final String PROPERTY_PROGRAM = "program";
46  
47      public static final String PROPERTY_PROGRAM_VALID = "programValid";
48  
49      public static final String PROPERTY_CRUISES = "cruises";
50  
51      public static final String PROPERTY_CRUISE = "cruise";
52  
53      public static final String PROPERTY_PROTOCOLS = "protocols";
54  
55      public static final String PROPERTY_PROTOCOL = "protocol";
56  
57      public static final String PROPERTY_PROGRAM_FOUND = "programFound";
58  
59      public static final String PROPERTY_CRUISE_FOUND = "cruiseFound";
60  
61      public static final String PROPERTY_PROTOCOL_FOUND = "protocolFound";
62  
63      protected List<Program> programs;
64  
65      protected Program program;
66  
67      protected List<Cruise> cruises;
68  
69      protected Cruise cruise;
70  
71      protected List<TuttiProtocol> protocols;
72  
73      protected TuttiProtocol protocol;
74  
75      public SelectCruiseUIModel() {
76          super(null, null);
77      }
78  
79      public List<Program> getPrograms() {
80          return programs;
81      }
82  
83      public void setPrograms(List<Program> programs) {
84          Object oldValue = getPrograms();
85          this.programs = programs;
86          firePropertyChange(PROPERTY_PROGRAMS, oldValue, programs);
87      }
88  
89      public Program getProgram() {
90          return program;
91      }
92  
93      public void setProgram(Program program) {
94          Program oldValue = getProgram();
95          this.program = program;
96          firePropertyChange(PROPERTY_PROGRAM, oldValue, program);
97          firePropertyChange(PROPERTY_PROGRAM_FOUND, oldValue != null, program != null);
98          firePropertyChange(PROPERTY_PROGRAM_VALID, null, isProgramValid());
99      }
100 
101     public boolean isProgramFound() {
102         return program != null;
103     }
104 
105     public boolean isProgramValid() {
106         return program == null || program.getZone() != null;
107     }
108 
109     public List<Cruise> getCruises() {
110         return cruises;
111     }
112 
113     public void setCruises(List<Cruise> cruises) {
114         Object oldValue = getCruises();
115         this.cruises = cruises;
116         firePropertyChange(PROPERTY_CRUISES, oldValue, cruises);
117     }
118 
119     public Cruise getCruise() {
120         return cruise;
121     }
122 
123     public void setCruise(Cruise cruise) {
124         Cruise oldValue = getCruise();
125         this.cruise = cruise;
126         firePropertyChange(PROPERTY_CRUISE, oldValue, cruise);
127         firePropertyChange(PROPERTY_CRUISE_FOUND, oldValue != null, cruise != null);
128     }
129 
130     public boolean isCruiseFound() {
131         return cruise != null;
132     }
133 
134     public List<TuttiProtocol> getProtocols() {
135         return protocols;
136     }
137 
138     public void setProtocols(List<TuttiProtocol> protocols) {
139         Object oldValue = getProtocols();
140         this.protocols = protocols;
141         firePropertyChange(PROPERTY_PROTOCOLS, oldValue, protocols);
142     }
143 
144     public TuttiProtocol getProtocol() {
145         return protocol;
146     }
147 
148     public void setProtocol(TuttiProtocol protocol) {
149         Object oldValue = getProtocol();
150         this.protocol = protocol;
151         firePropertyChange(PROPERTY_PROTOCOL, oldValue, protocol);
152         firePropertyChange(PROPERTY_PROTOCOL_FOUND, oldValue != null, protocol != null);
153     }
154 
155     public boolean isProtocolFound() {
156         return protocol != null;
157     }
158 
159     @Override
160     protected Cruise newEntity() {
161         return Cruises.newCruise();
162     }
163 }