Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.25 KB | None | 0 0
  1. package com.smartera3s.nasec.screens;
  2.  
  3. import com.smartera3s.nasec.listeners.PatientHeaderListener;
  4. import com.smartera3s.nasec.model.entities.PatientEntity;
  5. import com.vaadin.data.fieldgroup.BeanFieldGroup;
  6. import com.vaadin.data.fieldgroup.PropertyId;
  7. import com.vaadin.data.util.ObjectProperty;
  8. import com.vaadin.event.ShortcutAction;
  9. import com.vaadin.server.FileResource;
  10. import com.vaadin.server.Resource;
  11. import com.vaadin.ui.*;
  12. import com.vaadin.ui.themes.ValoTheme;
  13.  
  14. import java.io.File;
  15. import java.util.Date;
  16.  
  17. import static com.smartera3s.nasec.controllers.PatientHeaderController.PATIENTSEARCH;
  18. import static com.smartera3s.nasec.controllers.PatientHeaderController.PATIENTLOAD;
  19. import static com.smartera3s.nasec.controllers.PatientHeaderController.PATIENTADD;
  20. import static com.smartera3s.nasec.controllers.PatientHeaderController.PATIENTVISITID;
  21. import static com.smartera3s.nasec.controllers.PatientHeaderController.PATIENTVISITDATE;
  22. import static com.smartera3s.nasec.controllers.PatientHeaderController.PATIENTNAME;
  23. import static com.smartera3s.nasec.controllers.PatientHeaderController.PATIENTAGE;
  24. import static com.smartera3s.utils.InternationalizationFileBundle.CAPTIONS;
  25. import static com.smartera3s.utils.InternationalizationFileBundle.getBundleValue;
  26.  
  27. /**
  28. * Created by aelabasery on 21/08/16.
  29. */
  30. public class PatientHeaderScreen extends CustomComponent {
  31.  
  32.  
  33. public static final String PATIENTBASICINFOSTYLE = "Patient-Basic-Infos-tyle";
  34.  
  35.  
  36. private Image myLocalImage;
  37.  
  38.  
  39. //Labels
  40. @PropertyId("fullName")
  41. private TextField Patientname;
  42.  
  43. @PropertyId("age")
  44. private TextField patientage;
  45.  
  46.  
  47. private Label Visitid;
  48. private Label Visitdate;
  49.  
  50. //windowLayouts
  51.  
  52. private Layout loadwindowLayout;
  53. private Layout addwindowLayout;
  54. private Layout searchwindowLayout;
  55.  
  56. //Layouts
  57. private Layout pateintimageLayout;
  58. private Layout pateintNameLayout;
  59. private Layout pateintAgeLayout;
  60. private Layout visitIDLayout;
  61. private Layout visitDateLayout;
  62.  
  63. //Object Property to fill Labels
  64.  
  65. private ObjectProperty<String> NameLabel;
  66.  
  67. private ObjectProperty<String> ageLabel;
  68.  
  69. private ObjectProperty<String> VisitLabel;
  70.  
  71. private ObjectProperty<Date> DateLabel;
  72.  
  73. private Button addPatient;
  74. private Button loadPatient;
  75. private Button searchPatient;
  76.  
  77. private Layout mainLayout;
  78. private Layout controlersLayout;
  79. private Layout patinetInfoLayout;
  80.  
  81.  
  82. private BeanFieldGroup<PatientEntity> fieldGroup;
  83. private PatientEntity patientEntity;
  84.  
  85. private PatientHeaderListener eventsListener;
  86.  
  87. public PatientHeaderScreen(PatientHeaderListener patientHeaderListener) {
  88. this.eventsListener = patientHeaderListener;
  89. NameLabel = new ObjectProperty<String>("");
  90. ageLabel = new ObjectProperty<String>("");
  91. VisitLabel = new ObjectProperty<String>("");
  92. DateLabel = new ObjectProperty<Date>(new Date());
  93. patientEntity = new PatientEntity();
  94.  
  95. addLayout();
  96. fillLayout(mainLayout);
  97. addControls(controlersLayout);
  98. initFiledGroup();
  99. }
  100.  
  101. public void addLayout() {
  102. mainLayout = new VerticalLayout();
  103. mainLayout.setSizeFull();
  104. mainLayout.setStyleName(PATIENTBASICINFOSTYLE);
  105.  
  106. loadwindowLayout = new VerticalLayout();
  107. loadwindowLayout.setSizeUndefined();
  108.  
  109. addwindowLayout = new VerticalLayout();
  110. addwindowLayout.setSizeUndefined();
  111.  
  112. searchwindowLayout = new VerticalLayout();
  113. searchwindowLayout.setSizeUndefined();
  114.  
  115. controlersLayout = new HorizontalLayout();
  116. controlersLayout.setSizeUndefined();
  117. // ((AbstractOrderedLayout) layoutControls).setSpacing(true);
  118. controlersLayout.addStyleName("visit-toolbar");
  119.  
  120. pateintimageLayout = new HorizontalLayout();
  121. pateintimageLayout.setSizeUndefined();
  122. pateintimageLayout.setStyleName("spark");
  123.  
  124. pateintNameLayout = new VerticalLayout();
  125. pateintNameLayout.setSizeUndefined();
  126. pateintNameLayout.setStyleName("spark");
  127.  
  128. pateintAgeLayout = new VerticalLayout();
  129. pateintAgeLayout.setSizeUndefined();
  130. pateintAgeLayout.setStyleName("spark");
  131.  
  132. visitIDLayout = new VerticalLayout();
  133. visitIDLayout.setSizeUndefined();
  134. visitIDLayout.setStyleName("spark");
  135.  
  136. visitDateLayout = new VerticalLayout();
  137. visitDateLayout.setSizeUndefined();
  138. visitDateLayout.setStyleName("spark");
  139.  
  140. patinetInfoLayout = new CssLayout();
  141. patinetInfoLayout.setSizeUndefined();
  142. patinetInfoLayout.setStyleName("patient-info");
  143.  
  144. setCompositionRoot(mainLayout);
  145. }
  146.  
  147. public void fillLayout(Layout mainLayout) {
  148.  
  149. myLocalImage = createImage();
  150. patientage = createPatientAge();
  151. Patientname = createPatientName();
  152. Visitdate = createVisitDate();
  153. Visitid = createVisitID();
  154. pateintimageLayout.addComponent(myLocalImage);
  155.  
  156. pateintNameLayout.addComponent(Patientname);
  157. pateintAgeLayout.addComponent(patientage);
  158.  
  159. visitIDLayout.addComponent(Visitid);
  160. visitDateLayout.addComponent(Visitdate);
  161.  
  162. patinetInfoLayout.addComponent(pateintimageLayout);
  163. patinetInfoLayout.addComponent(pateintNameLayout);
  164. patinetInfoLayout.addComponent(pateintAgeLayout);
  165. patinetInfoLayout.addComponent(visitIDLayout);
  166. patinetInfoLayout.addComponent(visitDateLayout);
  167.  
  168. mainLayout.addComponent(buildHeader());
  169. mainLayout.addComponent(patinetInfoLayout);
  170.  
  171.  
  172. }
  173.  
  174. /////Header Buttons Controlers .
  175. private Component buildHeader() {
  176. HorizontalLayout header = new HorizontalLayout();
  177. header.addStyleName("Visit-header");
  178. header.setSpacing(true);
  179.  
  180. /// This is the Layout That have the Buttons
  181. header.addComponent(controlersLayout);
  182. return header;
  183. }
  184.  
  185. private void addControls(Layout layout) {
  186. loadPatient = createLoadButton();
  187. addPatient = createAddButton();
  188. searchPatient = createVisitSearch();
  189. // fill related layout
  190. layout.addComponent(loadPatient);
  191. layout.addComponent(addPatient);
  192. layout.addComponent(searchPatient);
  193. }
  194.  
  195. private Button createVisitSearch() {
  196. Button search = new Button(getBundleValue(CAPTIONS, PATIENTSEARCH));
  197. search.setStyleName(ValoTheme.BUTTON_PRIMARY);
  198. search.setClickShortcut(ShortcutAction.KeyCode.ENTER);
  199. search.setId(PATIENTSEARCH);
  200.  
  201. // assign the listener class that handles events
  202. search.addClickListener(eventsListener);
  203. return search;
  204. }
  205.  
  206. private Button createLoadButton() {
  207. Button load = new Button(getBundleValue(CAPTIONS, PATIENTLOAD));
  208. load.setStyleName(ValoTheme.BUTTON_PRIMARY);
  209. load.setClickShortcut(ShortcutAction.KeyCode.ENTER);
  210. load.setId(PATIENTLOAD);
  211.  
  212. // assign the listener class that handles events
  213. load.addClickListener(eventsListener);
  214. return load;
  215. }
  216.  
  217. private Button createAddButton() {
  218. Button add = new Button(getBundleValue(CAPTIONS, PATIENTADD));
  219. add.setStyleName(ValoTheme.BUTTON_PRIMARY);
  220. add.setClickShortcut(ShortcutAction.KeyCode.ENTER);
  221. add.setId(PATIENTADD);
  222.  
  223. // assign the listener class that handles events
  224. add.addClickListener(eventsListener);
  225. return add;
  226. }
  227.  
  228. private Image createImage() {
  229. myLocalImage = new Image();
  230. myLocalImage.setWidth("40px");
  231. myLocalImage.setHeight("40px");
  232. myLocalImage.setStyleName("user-menu");
  233.  
  234. return myLocalImage;
  235.  
  236. }
  237.  
  238. private TextField createPatientName() {
  239. Patientname = new TextField();
  240. Patientname.setId(PATIENTNAME);
  241. Patientname.setCaption(getBundleValue(CAPTIONS, PATIENTNAME));
  242. Patientname.setStyleName(ValoTheme.LABEL_NO_MARGIN);
  243. // Patientname.setPropertyDataSource(NameLabel);
  244. Patientname.setNullRepresentation("");
  245. Patientname.setReadOnly(true);
  246. Patientname.setSizeFull();
  247.  
  248. return Patientname;
  249. }
  250.  
  251. private TextField createPatientAge() {
  252. patientage = new TextField();
  253. patientage.setId(PATIENTAGE);
  254. patientage.setStyleName(ValoTheme.LABEL_NO_MARGIN);
  255. patientage.setCaption(getBundleValue(CAPTIONS, PATIENTAGE));
  256. // patientage.setPropertyDataSource(ageLabel);
  257. patientage.setReadOnly(true);
  258. patientage.setSizeFull();
  259.  
  260.  
  261. return patientage;
  262. }
  263.  
  264. private Label createVisitID() {
  265. Visitid = new Label("");
  266. Visitid.setId(PATIENTVISITID);
  267. Visitid.setCaption(getBundleValue(CAPTIONS, PATIENTVISITID));
  268. Visitid.setStyleName(ValoTheme.LABEL_NO_MARGIN);
  269. Visitid.setPropertyDataSource(VisitLabel);
  270. return Visitid;
  271. }
  272.  
  273. private Label createVisitDate() {
  274. Visitdate = new Label("");
  275. Visitdate.setId(PATIENTVISITDATE);
  276. Visitdate.setCaption(getBundleValue(CAPTIONS, PATIENTVISITDATE));
  277. Visitdate.setStyleName(ValoTheme.LABEL_NO_MARGIN);
  278. Visitdate.setPropertyDataSource(DateLabel);
  279. return Visitdate;
  280. }
  281.  
  282.  
  283. public Image getMyLocalImage() {
  284. return myLocalImage;
  285. }
  286.  
  287. public void setMyLocalImage(Image myLocalImage) {
  288. this.myLocalImage = myLocalImage;
  289. }
  290.  
  291. public TextField getPatientname() {
  292. return Patientname;
  293. }
  294.  
  295. public void setPatientname(TextField patientname) {
  296. Patientname = patientname;
  297. }
  298.  
  299. public TextField getPatientage() {
  300. return patientage;
  301. }
  302.  
  303. public void setPatientage(TextField patientage) {
  304. this.patientage = patientage;
  305. }
  306.  
  307. public Label getVisitid() {
  308. return Visitid;
  309. }
  310.  
  311. public void setVisitid(Label visitid) {
  312. Visitid = visitid;
  313. }
  314.  
  315. public Label getVisitdate() {
  316. return Visitdate;
  317. }
  318.  
  319. public void setVisitdate(Label visitdate) {
  320. Visitdate = visitdate;
  321. }
  322.  
  323. public Layout getPateintimageLayout() {
  324. return pateintimageLayout;
  325. }
  326.  
  327. public void setPateintimageLayout(Layout pateintimageLayout) {
  328. this.pateintimageLayout = pateintimageLayout;
  329. }
  330.  
  331. public Layout getPateintNameLayout() {
  332. return pateintNameLayout;
  333. }
  334.  
  335. public void setPateintNameLayout(Layout pateintNameLayout) {
  336. this.pateintNameLayout = pateintNameLayout;
  337. }
  338.  
  339. public Layout getPateintAgeLayout() {
  340. return pateintAgeLayout;
  341. }
  342.  
  343. public void setPateintAgeLayout(Layout pateintAgeLayout) {
  344. this.pateintAgeLayout = pateintAgeLayout;
  345. }
  346.  
  347. public Layout getVisitIDLayout() {
  348. return visitIDLayout;
  349. }
  350.  
  351. public void setVisitIDLayout(Layout visitIDLayout) {
  352. this.visitIDLayout = visitIDLayout;
  353. }
  354.  
  355. public Layout getVisitDateLayout() {
  356. return visitDateLayout;
  357. }
  358.  
  359. public void setVisitDateLayout(Layout visitDateLayout) {
  360. this.visitDateLayout = visitDateLayout;
  361. }
  362.  
  363. public ObjectProperty<String> getNameLabel() {
  364. return NameLabel;
  365. }
  366.  
  367. public void setNameLabel(ObjectProperty<String> nameLabel) {
  368. NameLabel = nameLabel;
  369. }
  370.  
  371. public ObjectProperty<String> getAgeLabel() {
  372. return ageLabel;
  373. }
  374.  
  375. public void setAgeLabel(ObjectProperty<String> ageLabel) {
  376. this.ageLabel = ageLabel;
  377. }
  378.  
  379. public ObjectProperty<String> getVisitLabel() {
  380. return VisitLabel;
  381. }
  382.  
  383. public void setVisitLabel(ObjectProperty<String> visitLabel) {
  384. VisitLabel = visitLabel;
  385. }
  386.  
  387. public ObjectProperty<Date> getDateLabel() {
  388. return DateLabel;
  389. }
  390.  
  391. public void setDateLabel(ObjectProperty<Date> dateLabel) {
  392. DateLabel = dateLabel;
  393. }
  394.  
  395. public Button getAddPatient() {
  396. return addPatient;
  397. }
  398.  
  399. public void setAddPatient(Button addPatient) {
  400. this.addPatient = addPatient;
  401. }
  402.  
  403. public Button getLoadPatient() {
  404. return loadPatient;
  405. }
  406.  
  407. public void setLoadPatient(Button loadPatient) {
  408. this.loadPatient = loadPatient;
  409. }
  410.  
  411. public Button getSearchPatient() {
  412. return searchPatient;
  413. }
  414.  
  415. public void setSearchPatient(Button searchPatient) {
  416. this.searchPatient = searchPatient;
  417. }
  418.  
  419. public Layout getMainLayout() {
  420. return mainLayout;
  421. }
  422.  
  423. public void setMainLayout(Layout mainLayout) {
  424. this.mainLayout = mainLayout;
  425. }
  426.  
  427. public Layout getControlersLayout() {
  428. return controlersLayout;
  429. }
  430.  
  431. public void setControlersLayout(Layout controlersLayout) {
  432. this.controlersLayout = controlersLayout;
  433. }
  434.  
  435. public Layout getPatinetInfoLayout() {
  436. return patinetInfoLayout;
  437. }
  438.  
  439. public void setPatinetInfoLayout(Layout patinetInfoLayout) {
  440. this.patinetInfoLayout = patinetInfoLayout;
  441. }
  442.  
  443. public Layout getLoadwindowLayout() {
  444. return loadwindowLayout;
  445. }
  446.  
  447. public void setLoadwindowLayout(Layout loadwindowLayout) {
  448. this.loadwindowLayout = loadwindowLayout;
  449. }
  450.  
  451. public Layout getAddwindowLayout() {
  452. return addwindowLayout;
  453. }
  454.  
  455. public void setAddwindowLayout(Layout addwindowLayout) {
  456. this.addwindowLayout = addwindowLayout;
  457. }
  458.  
  459. public Layout getSearchwindowLayout() {
  460. return searchwindowLayout;
  461. }
  462.  
  463. public void setSearchwindowLayout(Layout searchwindowLayout) {
  464. this.searchwindowLayout = searchwindowLayout;
  465. }
  466.  
  467. public BeanFieldGroup<PatientEntity> getFieldGroup() {
  468. return fieldGroup;
  469. }
  470.  
  471. public void initFiledGroup() {
  472.  
  473. fieldGroup = new BeanFieldGroup<>(PatientEntity.class);
  474.  
  475. fieldGroup.setBuffered(false);
  476.  
  477.  
  478. fieldGroup.bindMemberFields(this);
  479.  
  480.  
  481. }
  482.  
  483. public void updateFiledGroup(PatientEntity selectedPatient) {
  484.  
  485.  
  486. this.fieldGroup.setItemDataSource(selectedPatient);
  487. this.setReadOnlyProberty();
  488.  
  489.  
  490. }
  491.  
  492. private void setReadOnlyProberty() {
  493. patientage.setReadOnly(true);
  494. Patientname.setReadOnly(true);
  495.  
  496.  
  497. }
  498. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement