From 8c204e0d7a52d417ee1e8d2cf4985a6fac7a82d7 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Tue, 8 Jul 2014 08:02:55 +0200 Subject: [PATCH] =?UTF-8?q?Do=20agendy=20Budovy=20byl=20p=C5=99id=C3=A1n?= =?UTF-8?q?=20polo=C5=BEkov=C3=BD=20grid=20pro=20definici=20m=C3=ADstnost?= =?UTF-8?q?=C3=AD.=20closes=20#95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../info/bukova/isspst/data/Building.java | 33 +++++ .../java/info/bukova/isspst/data/Room.java | 94 ++++++++++++++ .../isspst/ui/buildings/BuildingForm.java | 17 +++ src/main/resources/hibernate.cfg.xml | 1 + .../webapp/WEB-INF/locales/columns.properties | 5 + .../WEB-INF/locales/zk-label.properties | 4 + src/main/webapp/app/navigation.zul | 2 +- src/main/webapp/lists/buildings/building.zul | 115 +++++++++++------- .../webapp/lists/buildings/buildingForm.zul | 24 +++- 9 files changed, 248 insertions(+), 47 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/data/Room.java diff --git a/src/main/java/info/bukova/isspst/data/Building.java b/src/main/java/info/bukova/isspst/data/Building.java index 7730055e..424ce803 100644 --- a/src/main/java/info/bukova/isspst/data/Building.java +++ b/src/main/java/info/bukova/isspst/data/Building.java @@ -1,9 +1,16 @@ package info.bukova.isspst.data; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.OneToMany; import javax.persistence.Table; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; import org.hibernate.validator.constraints.NotBlank; @Entity @@ -18,6 +25,14 @@ public class Building extends BaseData implements DataModel { @Column(name = "DESCRIPTION") private String description; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "building", orphanRemoval = true) + @LazyCollection(LazyCollectionOption.FALSE) + private List rooms; + + public Building() { + rooms = new ArrayList(); + } /** * @return the code @@ -64,4 +79,22 @@ public class Building extends BaseData implements DataModel { public void setDescription(String description) { this.description = description; } + + public List getRooms() { + return rooms; + } + + public void setRooms(List rooms) { + this.rooms = rooms; + } + + public void addRoom(Room room) { + room.setBuilding(this); + rooms.add(room); + } + + public void removeRoom(Room room) { + rooms.remove(room); + } + } diff --git a/src/main/java/info/bukova/isspst/data/Room.java b/src/main/java/info/bukova/isspst/data/Room.java new file mode 100644 index 00000000..f8d7704a --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/Room.java @@ -0,0 +1,94 @@ +package info.bukova.isspst.data; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "ROOM") +public class Room { + + @Id + @Column(name = "ID") + @GeneratedValue + private int id; + @Column(name = "CODE") + private String code; + @Column(name = "SHORTCUT") + private String shortcut; + @Column(name = "NAME") + private String name; + @Column(name = "FLOOR") + private Integer floor; + @Column(name = "NUMBER") + private Integer number; + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "BUILDING_ID") + private Building building; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getShortcut() { + return shortcut; + } + + public void setShortcut(String shortcut) { + this.shortcut = shortcut; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getFloor() { + return floor; + } + + public void setFloor(Integer floor) { + this.floor = floor; + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } + + public Building getBuilding() { + return building; + } + + public void setBuilding(Building building) { + this.building = building; + } + + public boolean equals(Object o) { + return ((o instanceof Room) && (((Room)o).getId() == this.getId())); + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/buildings/BuildingForm.java b/src/main/java/info/bukova/isspst/ui/buildings/BuildingForm.java index d0a4c0de..3290d038 100644 --- a/src/main/java/info/bukova/isspst/ui/buildings/BuildingForm.java +++ b/src/main/java/info/bukova/isspst/ui/buildings/BuildingForm.java @@ -1,9 +1,13 @@ package info.bukova.isspst.ui.buildings; import info.bukova.isspst.data.Building; +import info.bukova.isspst.data.Room; import info.bukova.isspst.ui.FormViewModel; +import org.zkoss.bind.annotation.BindingParam; +import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; public class BuildingForm extends FormViewModel { @@ -11,5 +15,18 @@ public class BuildingForm extends FormViewModel { public void init() { } + + @Command + @NotifyChange("dataBean") + public void addRoom() { + Room r = new Room(); + getDataBean().addRoom(r); + } + + @Command + @NotifyChange("dataBean") + public void removeRoom(@BindingParam("room") Room room) { + getDataBean().getRooms().remove(room); + } } diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index 115c5d51..c8e47108 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -11,6 +11,7 @@ + diff --git a/src/main/webapp/WEB-INF/locales/columns.properties b/src/main/webapp/WEB-INF/locales/columns.properties index e86db2e6..2e25f7ef 100644 --- a/src/main/webapp/WEB-INF/locales/columns.properties +++ b/src/main/webapp/WEB-INF/locales/columns.properties @@ -23,6 +23,11 @@ zipCode=PSČ #Budova code=Kód name=Název +rooms=Místnosti +#Místnost +shortcut=Zkratka +number=Číslo +floor=Podlaží #Uživatel accountNonExpired=Platný diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index b68bf9f2..7fbd7bde 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -39,9 +39,13 @@ BuildingsFormTitle=Budova BuildingsFormCode=Kód BuildingsFormName=Název BuildingsFormDescription=Popis +BuildingsFormAddRoom=Přidat místnost +BuildingsFormRemove=Odstranit BuildingsGridColumnCode=Kód BuildingsGridColumnName=Název BuildingsGridColumnDescription=Popis +BuildingsGridRooms=Místnosti: + AgendaRooms=Místnosti diff --git a/src/main/webapp/app/navigation.zul b/src/main/webapp/app/navigation.zul index 4c9d7a3a..bc4856e7 100644 --- a/src/main/webapp/app/navigation.zul +++ b/src/main/webapp/app/navigation.zul @@ -33,7 +33,7 @@ - + diff --git a/src/main/webapp/lists/buildings/building.zul b/src/main/webapp/lists/buildings/building.zul index de6af063..c1693c99 100644 --- a/src/main/webapp/lists/buildings/building.zul +++ b/src/main/webapp/lists/buildings/building.zul @@ -5,54 +5,79 @@ - - - - - - - - - -
-
- + + + + + + + + + + +
+
+ +
+
+ +
-
- + + +
+
+ +
+
+ +
-
-
- -
-
- + + +
+
+ +
+
+ +
-
- -
-
- - -
-
- -
-
- -
-
-
- - - - + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/lists/buildings/buildingForm.zul b/src/main/webapp/lists/buildings/buildingForm.zul index 11bc4d0c..7dfea89f 100644 --- a/src/main/webapp/lists/buildings/buildingForm.zul +++ b/src/main/webapp/lists/buildings/buildingForm.zul @@ -1,6 +1,7 @@ - + @@ -29,6 +30,27 @@ +