fr.ird.observe.client.form.open.OpenDataFormUIModel Maven / Gradle / Ivy
package fr.ird.observe.client.form.open;
/*-
* #%L
* ObServe Toolkit :: Common Client
* %%
* Copyright (C) 2008 - 2017 IRD, Ultreia.io
* %%
* 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
* .
* #L%
*/
import fr.ird.observe.client.form.FormUIModel;
import fr.ird.observe.client.form.WithBeanTypeFormModel;
import fr.ird.observe.client.spi.context.OpenableDtoUIContext;
import fr.ird.observe.dto.IdHelper;
import fr.ird.observe.dto.data.OpenableDto;
import fr.ird.observe.dto.form.Form;
import fr.ird.observe.dto.reference.DataDtoReference;
import fr.ird.observe.services.service.referential.ReferentialDtoCacheManager;
/**
* Created by tchemit on 02/10/17.
*
* @author Tony Chemit - [email protected]
*/
public abstract class OpenDataFormUIModel> extends FormUIModel implements WithBeanTypeFormModel {
private static final String PROPERTY_CAN_REOPEN = "canReopen";
private static final String PROPERTY_HISTORICAL_DATA = "historicalData";
private final OpenableDtoUIContext dtoContext;
private final String selectedParentId;
private final String selectedId;
protected D bean;
protected Form form;
private boolean canReopen;
private boolean historicalData;
private int position;
private boolean tripEndDateUpdated;
public boolean isCanReopen() {
return canReopen;
}
public void setCanReopen(boolean canReopen) {
boolean old = isCanReopen();
this.canReopen = canReopen;
firePropertyChange(PROPERTY_CAN_REOPEN, old, canReopen);
}
public boolean isHistoricalData() {
return historicalData;
}
public void setHistoricalData(boolean historicalData) {
boolean old = isHistoricalData();
this.historicalData = historicalData;
firePropertyChange(PROPERTY_HISTORICAL_DATA, old, historicalData);
}
public OpenDataFormUIModel(OpenableDtoUIContext dtoContext) {
this.dtoContext = dtoContext;
this.selectedId = dtoContext.getSelectedId();
this.selectedParentId = dtoContext.getParent().getSelectedId();
}
public String getSelectedParentId() {
return selectedParentId;
}
public String getSelectedId() {
return selectedId;
}
public D getBean() {
return bean;
}
public void setBean(D bean) {
this.bean = bean;
}
public OpenableDtoUIContext getDtoContext() {
return dtoContext;
}
@Override
public Class getBeanType() {
return dtoContext.getType();
}
public void setPosition(int position) {
this.position = position;
}
public void setTripEndDateUpdated(boolean tripEndDateUpdated) {
this.tripEndDateUpdated = tripEndDateUpdated;
}
// void loadOrPreCreateForm(ReferentialDtoCacheManager dataSource, String parentId, String id) {
//
// if (id == null) {
// PreCreateFormRequestDto preCreateFormRequest = PreCreateFormRequestDto.of(parentId);
// preCreateForm(dataSource, preCreateFormRequest);
// return;
// }
//
// LoadFormRequestDto loadFormRequest;
// if (parentId == null) {
// loadFormRequest = LoadFormRequestDto.of(id);
// } else {
// loadFormRequest = LoadFormRequestDto.of(parentId, id);
// }
// loadForm(dataSource, loadFormRequest);
// }
//
// protected void loadForm(ReferentialDtoCacheManager dataSource, LoadFormRequestDto loadFormRequest) {
// form = getLoadDtoFormServiceAction().loadForm(loadFormRequest);
// formUIContext.loadFormDependencies(dataSource, dtoContext.formContext().toFormDefinition(), true);
// formUIContext.updateUi(this);
// form.copyTo(getBean());
// }
//
// protected Form loadForm(ReferentialDtoCacheManager dataSource, String id) {
// form = getLoadDtoFormServiceAction().loadForm(LoadFormRequestDto.of(id));
// formUIContext.loadFormDependencies(dataSource, dtoContext.formContext().toFormDefinition(), true);
// formUIContext.updateUi(this);
// form.copyTo(getBean());
// return form;
// }
//
// void preCreateForm(ReferentialDtoCacheManager dataSource, PreCreateFormRequestDto preCreateFormRequest) {
// form = getPreCreateFormServiceAction().preCreate(preCreateFormRequest);
// formUIContext.loadFormDependencies(dataSource, dtoContext.formContext().toFormDefinition(), true);
// formUIContext.updateUi(this);
// form.copyTo(getBean());
// }
//
// public SaveResultDto save(SaveResultDto saveResult) {
// saveResult.toDto(bean);
// tripEndDateUpdated = saveResult.isTripEndDateUpdated();
// position = getOpenCloseServiceAction().getDataPosition(getSelectedParentId(), getSelectedId());
// return saveResult;
// }
//
// public DeleteResultDto delete(String id) {
// return formUIContext.getDeleteServiceAction().delete(DeleteRequestDto.of(id));
// }
//
// public DeleteResultDto delete(String parentId, String id) {
// return formUIContext.getDeleteServiceAction().delete(DeleteRequestDto.of(parentId, id));
// }
public void loadFormDependencies(ReferentialDtoCacheManager cacheManager, boolean clear) {
formUIContext.loadFormDependencies(cacheManager, dtoContext.formContext().toFormDefinition(), clear);
}
public void updateUi() {
formUIContext.updateUi(this);
}
@Override
protected String computePrefix() {
return "[" + IdHelper.getDtoSimplifiedName(getBeanType()) + "UI] ";
}
// public void obtainChildPosition() {
// position = getOpenCloseServiceAction().getDataPosition(getSelectedParentId(), getSelectedId());
// }
public int getPosition() {
return position;
}
public boolean isTripEndDateUpdated() {
return tripEndDateUpdated;
}
public abstract void loadOrPreCreateForm();
public abstract void save();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy