de.symeda.sormas.ui.caze.CaseDataView.java Source code

Java tutorial

Introduction

Here is the source code for de.symeda.sormas.ui.caze.CaseDataView.java

Source

/*******************************************************************************
 * SORMAS - Surveillance Outbreak Response Management & Analysis System
 * Copyright  2016-2018 Helmholtz-Zentrum fr Infektionsforschung GmbH (HZI)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *******************************************************************************/
package de.symeda.sormas.ui.caze;

import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.CustomLayout;
import com.vaadin.ui.VerticalLayout;

import de.symeda.sormas.api.FacadeProvider;
import de.symeda.sormas.api.caze.CaseDataDto;
import de.symeda.sormas.api.task.TaskContext;
import de.symeda.sormas.api.user.UserRight;
import de.symeda.sormas.ui.ControllerProvider;
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.samples.SampleListComponent;
import de.symeda.sormas.ui.task.TaskListComponent;
import de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent;
import de.symeda.sormas.ui.utils.CssStyles;
import de.symeda.sormas.ui.utils.LayoutUtil;
import de.symeda.sormas.ui.utils.ViewMode;

/**
 * CaseDataView for reading and editing the case data fields. Contains the
 * {@link CaseDataForm}.
 * 
 * @author Stefan Szczesny
 *
 */
public class CaseDataView extends AbstractCaseView {

    private static final long serialVersionUID = -1L;

    public static final String VIEW_NAME = ROOT_VIEW_NAME + "/data";

    public static final String CASE_LOC = "case";
    public static final String TASKS_LOC = "tasks";
    public static final String SAMPLES_LOC = "samples";

    public CaseDataView() {
        super(VIEW_NAME);
    }

    @Override
    public void enter(ViewChangeEvent event) {
        super.enter(event);
        setHeightUndefined();

        CaseDataDto caze = FacadeProvider.getCaseFacade().getCaseDataByUuid(getCaseRef().getUuid());

        String htmlLayout = LayoutUtil.fluidRow(LayoutUtil.fluidColumnLoc(8, 0, 12, 0, CASE_LOC),
                LayoutUtil.fluidColumnLoc(4, 0, 6, 0, TASKS_LOC),
                LayoutUtil.fluidColumnLoc(4, 0, 6, 0, SAMPLES_LOC));

        VerticalLayout container = new VerticalLayout();
        container.setWidth(100, Unit.PERCENTAGE);
        container.setMargin(true);
        setSubComponent(container);
        CustomLayout layout = new CustomLayout();
        layout.addStyleName(CssStyles.ROOT_COMPONENT);
        layout.setTemplateContents(htmlLayout);
        layout.setWidth(100, Unit.PERCENTAGE);
        layout.setHeightUndefined();
        container.addComponent(layout);

        CommitDiscardWrapperComponent<?> editComponent;
        if (getViewMode() == ViewMode.SIMPLE) {
            editComponent = ControllerProvider.getCaseController()
                    .getCaseCombinedEditComponent(getCaseRef().getUuid(), ViewMode.SIMPLE);
        } else {
            editComponent = ControllerProvider.getCaseController().getCaseDataEditComponent(getCaseRef().getUuid(),
                    ViewMode.NORMAL);
        }

        // setSubComponent(editComponent);
        editComponent.setMargin(false);
        editComponent.setWidth(100, Unit.PERCENTAGE);
        editComponent.getWrappedComponent().setWidth(100, Unit.PERCENTAGE);
        editComponent.addStyleName(CssStyles.MAIN_COMPONENT);
        layout.addComponent(editComponent, CASE_LOC);

        TaskListComponent taskList = new TaskListComponent(TaskContext.CASE, getCaseRef());
        taskList.addStyleName(CssStyles.SIDE_COMPONENT);
        layout.addComponent(taskList, TASKS_LOC);

        if (UserProvider.getCurrent().hasUserRight(UserRight.SAMPLE_VIEW) && !caze.isUnreferredPortHealthCase()) {
            SampleListComponent sampleList = new SampleListComponent(getCaseRef());
            sampleList.addStyleName(CssStyles.SIDE_COMPONENT);
            layout.addComponent(sampleList, SAMPLES_LOC);
        }
    }
}