(no commit message)
[simdecs.git] / src / java / org / ufcspa / simdecs / diagram / mb / EditActor.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 package org.ufcspa.simdecs.diagram.mb;
6
7 import java.util.HashMap;
8 import java.util.Map;
9 import javax.faces.component.html.HtmlSelectOneMenu;
10 import org.primefaces.component.commandbutton.CommandButton;
11 import org.ufcspa.simdecs.diagram.elements.Doctor;
12 import org.ufcspa.simdecs.diagram.elements.Patient;
13 import org.ufcspa.simdecs.diagram.elements.SwimLane;
14
15 /**
16  *
17  * @author Maroni
18  */
19 public class EditActor extends DefaultManagedBean {
20
21     private String id;
22     private String name;
23     private Integer age;
24     private Map<String, String> actorTypes;
25     private String type;
26     private String sex;
27     private Float weight;
28     private Float height;
29     private EditDiagram editDiagram;
30     
31     public void addActor() {
32         if (type.equals("doctor")) {
33             Doctor doctor = new Doctor(getMessageBundle(), getLocale());
34             doctor.setAge(age);
35             doctor.setHeight(height);
36             doctor.setName(name);
37             doctor.setSex(sex);
38             doctor.setWeight(weight);
39             editDiagram.getDiagramManager().addSwimLane(doctor);
40         } else if (type.equals("patient")) {
41             Patient patient = new Patient(getMessageBundle(), getLocale());
42             patient.setAge(age);
43             patient.setHeight(height);
44             patient.setName(name);
45             patient.setSex(sex);
46             patient.setWeight(weight);
47             editDiagram.getDiagramManager().addSwimLane(patient);
48         }
49         
50         addInfoMessage("defaultInfoMessageTitle", "SucessAddActorMessage");
51     }
52   
53     public void editActor() {
54         SwimLane actorToEdit = editDiagram.getDiagramManager().getSwimLane(id);
55         actorToEdit.setAge(age);
56         actorToEdit.setHeight(height);
57         actorToEdit.setName(name);
58         actorToEdit.setSex(sex);
59         actorToEdit.setWeight(weight);
60         
61         addInfoMessage("defaultInfoMessageTitle", "SucessEditActorMessage");    
62     }
63
64     public void removeActor() {
65         editDiagram.getDiagramManager().removeSwimLane(id);
66         addInfoMessage("defaultInfoMessageTitle", "SucessRemoveActorMessage");    
67     }
68
69     public void prepareWindowAddActor() {
70         id = name = type = sex = null;
71         age = null;
72         weight = height = null;
73         
74         CommandButton buttonAdd  = (CommandButton) getComponentById("fEditActor:buttonAddActor");
75         CommandButton buttonEdit = (CommandButton) getComponentById("fEditActor:buttonEditActor");
76         CommandButton buttonRemove   = (CommandButton) getComponentById("fEditActor:buttonRemoveActor");
77         HtmlSelectOneMenu selectType = (HtmlSelectOneMenu) getComponentById("fEditActor:editActorType");
78         buttonAdd.setRendered(true);
79         buttonEdit.setRendered(false);
80         buttonRemove.setRendered(false);
81         selectType.setDisabled(false);
82     }
83     
84     public void prepareWindowEditActor() {
85         id=getTextParameter("pActorID");
86         SwimLane actorToEdit = editDiagram.getDiagramManager().getSwimLane(id);
87         age     = actorToEdit.getAge();
88         height  = actorToEdit.getHeight();
89         weight  = actorToEdit.getWeight();
90         name    = actorToEdit.getName();
91         sex     = actorToEdit.getSex();
92         type    = actorToEdit.getType();
93     
94         CommandButton buttonAdd      = (CommandButton) getComponentById("fEditActor:buttonAddActor");
95         CommandButton buttonEdit     = (CommandButton) getComponentById("fEditActor:buttonEditActor");
96         CommandButton buttonRemove   = (CommandButton) getComponentById("fEditActor:buttonRemoveActor");
97         HtmlSelectOneMenu selectType = (HtmlSelectOneMenu) getComponentById("fEditActor:editActorType");
98         buttonAdd.setRendered(false);
99         buttonRemove.setRendered(true);
100         buttonEdit.setRendered(true);
101         selectType.setDisabled(true);
102     }
103     
104     public EditActor() {
105         actorTypes = new HashMap<String, String>();
106         actorTypes.put(getResourceMessage("DoctorActorType"), "doctor");
107         actorTypes.put(getResourceMessage("PatientActorType"), "patient");
108     }
109
110     public Map<String, String> getActorTypes() {
111         return actorTypes;
112     }
113
114     public void setActorTypes(Map<String, String> actorTypes) {
115         this.actorTypes = actorTypes;
116     }
117
118     public String getType() {
119         return type;
120     }
121
122     public void setType(String type) {
123         this.type = type;
124     }
125
126     public Integer getAge() {
127         return age;
128     }
129
130     public void setAge(Integer age) {
131         this.age = age;
132     }
133
134     public Float getHeight() {
135         return height;
136     }
137
138     public void setHeight(Float height) {
139         this.height = height;
140     }
141
142     public String getName() {
143         return name;
144     }
145
146     public void setName(String name) {
147         this.name = name;
148     }
149
150
151     public String getSex() {
152         return sex;
153     }
154
155     public void setSex(String sex) {
156         this.sex = sex;
157     }
158
159     public Float getWeight() {
160         return weight;
161     }
162
163     public void setWeight(Float weight) {
164         this.weight = weight;
165     }
166
167     public EditDiagram getEditDiagram() {
168         return editDiagram;
169     }
170
171     public void setEditDiagram(EditDiagram editDiagram) {
172         this.editDiagram = editDiagram;
173     }
174
175     public String getId() {
176         return id;
177     }
178
179     public void setId(String id) {
180         this.id = id;
181     }
182
183 }