Skip to content

Commit

Permalink
#2 Zwischenstand: Bootstrap reingezogen, Formlogik angepasst,
Browse files Browse the repository at this point in the history
CommitDiscardWrapper reingezogen
  • Loading branch information
StefanSzczesny committed Jun 17, 2016
1 parent 3bd787c commit 483e174
Show file tree
Hide file tree
Showing 12 changed files with 7,227 additions and 45 deletions.
2 changes: 1 addition & 1 deletion sormas-api/src/de/symeda/sormas/api/caze/CaseStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public enum CaseStatus {

PROBABLE, INVESTIGATED, SUSPECT, CONFIRMED, NEGATIVE, POSITIVE, NO_CASE, RECOVERED, DECEASED
POSSIBLE, INVESTIGATED, SUSPECT, PROBABLE, CONFIRMED, NEGATIVE, POSITIVE, NO_CASE, RECOVERED, DECEASED
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package de.symeda.sormas.ui.surveillance.caze;

import java.util.HashMap;
import java.util.Map;

import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.fieldgroup.BeanFieldGroup;
import com.vaadin.data.fieldgroup.FieldGroup.CommitEvent;
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
import com.vaadin.data.fieldgroup.FieldGroup.CommitHandler;
import com.vaadin.data.util.BeanItem;
import com.vaadin.server.Page;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.CustomLayout;
import com.vaadin.ui.Field;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;

import de.symeda.sormas.api.caze.CaseDto;
Expand All @@ -31,15 +32,20 @@ public class CaseForm extends CustomLayout {
private CaseController viewLogic;
private BeanFieldGroup<CaseDto> fieldGroup;

private final TextField id;
private final NativeSelect caseStatus;
private final TextArea description;

private static final String HTML_LAYOUT =
LayoutUtil.h3(CssStyles.VSPACE3, "Case")+
LayoutUtil.locCss(CssStyles.VSPACE2, CaseDto.UUID)+
LayoutUtil.locCss(CssStyles.VSPACE2, CaseDto.CASE_STATUS)+
LayoutUtil.locCss(CssStyles.VSPACE2, CaseDto.DESCRIPTION);
LayoutUtil.h3(CssStyles.VSPACE3, "Case data")+
LayoutUtil.div(
LayoutUtil.fluidRowCss(
CssStyles.VSPACE4,
LayoutUtil.oneOfThreeCol(LayoutUtil.loc(CaseDto.UUID)),
LayoutUtil.oneOfThreeCol(LayoutUtil.loc(CaseDto.CASE_STATUS))
// LayoutUtil.oneOfThreeCol(LayoutUtil.loc(CaseDto.DESCRIPTION))
),
LayoutUtil.fluidRowCss(
CssStyles.VSPACE4,
LayoutUtil.oneOfThreeCol(LayoutUtil.loc(CaseDto.DISEASE))
)
);

public CaseForm(CaseController caseController) {
super();
Expand All @@ -48,37 +54,7 @@ public CaseForm(CaseController caseController) {

viewLogic = caseController;

fieldGroup = new BeanFieldGroup<CaseDto>(CaseDto.class);

id = fieldGroup.buildAndBind("ID", CaseDto.UUID, TextField.class);
id.setReadOnly(true);
addComponent(id, CaseDto.UUID);

caseStatus = fieldGroup.buildAndBind("Status", CaseDto.CASE_STATUS, NativeSelect.class);
addComponent(caseStatus, CaseDto.CASE_STATUS);

description = fieldGroup.buildAndBind("Description", CaseDto.DESCRIPTION, TextArea.class);
addComponent(description, CaseDto.DESCRIPTION);

// perform validation and enable/disable buttons while editing
ValueChangeListener valueListener = e -> formHasChanged();

for (Field f : fieldGroup.getFields()) {
f.addValueChangeListener(valueListener);
}

fieldGroup.addCommitHandler(new CommitHandler() {

@Override
public void preCommit(CommitEvent commitEvent)
throws CommitException {
}

@Override
public void postCommit(CommitEvent commitEvent) throws CommitException {
viewLogic.updateCase(fieldGroup.getItemDataSource().getBean());
}
});
addFields();


// save.addClickListener(new ClickListener() {
Expand Down Expand Up @@ -115,6 +91,60 @@ public void postCommit(CommitEvent commitEvent) throws CommitException {
// });
}

private void addFields() {
Map<String, Class<? extends Field<?>>> formProperties = new HashMap<String, Class<? extends Field<?>>>();
formProperties.put(CaseDto.UUID, TextField.class);
formProperties.put(CaseDto.CASE_STATUS, NativeSelect.class);
formProperties.put(CaseDto.DISEASE, NativeSelect.class);

// @TODO: put this in i18n properties
Map<String, String> captions = new HashMap<String, String>();
captions.put(CaseDto.UUID, "ID");
captions.put(CaseDto.CASE_STATUS, "Status");
captions.put(CaseDto.DISEASE, "Disease");

fieldGroup = new BeanFieldGroup<CaseDto>(CaseDto.class);

for (String propertyId : formProperties.keySet()) {
Field<?> field = fieldGroup.buildAndBind(captions.get(propertyId), propertyId, formProperties.get(propertyId));
field.setReadOnly(true);
field.setSizeFull();
addComponent(field, propertyId);
}

// id = fieldGroup.buildAndBind("ID", CaseDto.UUID, TextField.class);
// id.setReadOnly(true);
// addComponent(id, CaseDto.UUID);
//
// caseStatus = fieldGroup.buildAndBind("Status", CaseDto.CASE_STATUS, NativeSelect.class);
// addComponent(caseStatus, CaseDto.CASE_STATUS);
//
// description = fieldGroup.buildAndBind("Description", CaseDto.DESCRIPTION, TextArea.class);
// addComponent(description, CaseDto.DESCRIPTION);

// perform validation and enable/disable buttons while editing
ValueChangeListener valueListener = e -> formHasChanged();

for (Field<?> f : fieldGroup.getFields()) {
f.addValueChangeListener(valueListener);
}

fieldGroup.addCommitHandler(new CommitHandler() {

private static final long serialVersionUID = -8160135868709228006L;

@Override
public void preCommit(CommitEvent commitEvent)
throws CommitException {
}

@Override
public void postCommit(CommitEvent commitEvent) throws CommitException {
viewLogic.updateCase(fieldGroup.getItemDataSource().getBean());
}
});
}

public void editCase(CaseDto caze) {
if (caze == null) {
caze = new CaseDto();
Expand All @@ -141,4 +171,5 @@ private void formHasChanged() {
}
//delete.setEnabled(canRemoveProduct);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public HorizontalLayout createTopBar() {

//topLayout.addComponent(new Label("<h3>status:</h3>", ContentMode.HTML));

Button statusProbable = new Button("probable", e -> grid.setFilter(CaseStatus.PROBABLE));
statusProbable.setStyleName(ValoTheme.BUTTON_LINK);
topLayout.addComponent(statusProbable);
Button statusPossible = new Button("possible", e -> grid.setFilter(CaseStatus.POSSIBLE));
statusPossible.setStyleName(ValoTheme.BUTTON_LINK);
topLayout.addComponent(statusPossible);

Button statusInvestigated = new Button("investigated", e -> grid.setFilter(CaseStatus.INVESTIGATED));
statusInvestigated.setStyleName(ValoTheme.BUTTON_LINK);
Expand Down
Loading

0 comments on commit 483e174

Please sign in to comment.