Eventview showing start and end Date.

master
Markus Kreth 7 years ago
parent 6e6e2f5480
commit a3d6af41ba
  1. 50
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/SingleEventView.java

@ -1,8 +1,12 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import com.vaadin.ui.CustomComponent; import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.DateField;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.TextField; import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
@ -13,9 +17,14 @@ public class SingleEventView extends CustomComponent {
private final TextField textTitle; private final TextField textTitle;
private final TextField textLocation; private final TextField textLocation;
private DateField startDate;
private DateField endDate;
public SingleEventView() { public SingleEventView() {
setCaption("Gewählte Veranstaltung"); setCaption("Gewählte Veranstaltung");
addStyleName("bold-caption"); addStyleName("bold-caption");
setWidth(40.0f, Unit.PERCENTAGE);
textTitle = new TextField(); textTitle = new TextField();
textTitle.setId("event.title"); textTitle.setId("event.title");
@ -31,20 +40,28 @@ public class SingleEventView extends CustomComponent {
textLocation.setEnabled(false); textLocation.setEnabled(false);
textLocation.setSizeFull(); textLocation.setSizeFull();
VerticalLayout panel = new VerticalLayout(); startDate = new DateField("Beginn");
panel.setMargin(false); startDate.setEnabled(false);
panel.addComponents(textTitle, textLocation); endDate = new DateField("Ende");
setCompositionRoot(panel); endDate.setEnabled(false);
textLocation.setHeight(endDate.getHeight(), endDate.getHeightUnits());
GridLayout layout = new GridLayout(2, 2);
layout.setMargin(true);
layout.setSpacing(true);
layout.addComponents(textTitle, startDate, textLocation, endDate);
setCompositionRoot(layout);
} }
public void setTitle(String value) { void setTitle(String value) {
if (value == null) { if (value == null) {
value = ""; value = "";
} }
textTitle.setValue(value); textTitle.setValue(value);
} }
public void setLocation(String value) { void setLocation(String value) {
if (value == null) { if (value == null) {
value = ""; value = "";
} }
@ -57,11 +74,30 @@ public class SingleEventView extends CustomComponent {
setTitle(ev.getCaption()); setTitle(ev.getCaption());
setLocation(ev.getLocation()); setLocation(ev.getLocation());
setStartDate(ev.getStart());
setEndDate(ev);
} else { } else {
setTitle(""); setTitle("");
setLocation(""); setLocation("");
endDate.setVisible(false);
}
} }
private void setEndDate(ClubEvent ev) {
ZonedDateTime start = ev.getStart();
ZonedDateTime end = ev.getEnd();
if (start.until(end, ChronoUnit.DAYS) > 0) {
endDate.setValue(end.toLocalDate());
endDate.setVisible(true);
} else {
endDate.setValue(null);
endDate.setVisible(false);
}
}
private void setStartDate(ZonedDateTime start) {
startDate.setValue(start.toLocalDate());
} }
} }

Loading…
Cancel
Save