All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.ird.observe.client.form.table.DataTableFormUIModel Maven / Gradle / Ivy

package fr.ird.observe.client.form.table;

/*-
 * #%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.simplelist.SimpleDataListFormUIModel;
import fr.ird.observe.client.spi.context.DataDtoUIContext;
import fr.ird.observe.dto.data.DataDto;
import java.util.List;
import javax.swing.ListSelectionModel;
import org.nuiton.util.beans.BinderModelBuilder;

/**
 * Created by tchemit on 02/10/17.
 *
 * @author Tony Chemit - [email protected]
 */
public abstract class DataTableFormUIModel extends SimpleDataListFormUIModel {

    private static final String PROPERTY_CAN_SAVE_ROW = "canSaveRow";
    private static final String PROPERTY_CAN_RESET_ROW = "canResetRow";
    static final String PROPERTY_SHOW_DATA = "showData";
    private static final String PROPERTY_ROW_SAVED = "rowSaved";

    private final Class childType;
    private final String[] parentProperties;
    private final String[] childProperties;
    private final transient ListSelectionModel selectionModel;
    protected C tableEditBean;
    private boolean canSaveRow;
    private boolean canResetRow;

    /**
     * Pour savoir si on peut voir les données du l'écran.
     * 

* Cela diffère du mode de l'écran, à utiliser par exemple pour les écrans * d'échantillons lorsqu'aucune discarded n'est effectuée. on se retrouve en * mode ContentUIMode.READ mais ce n'est pas suffisant. * * @since 3.0 */ private boolean showData; private boolean rowSaved; private ContentTableModel tableModel; public DataTableFormUIModel(DataDtoUIContext dtoContext, Class childType, String propertyName, String[] parentProperties, String[] childProperties) { super(dtoContext, childType, propertyName); this.childType = childType; this.parentProperties = parentProperties; this.childProperties = childProperties; this.selectionModel = new ContentTableListSelectionModel(this); } public void initModel(List> metas) { this.tableModel = createTableModel(metas); } protected abstract ContentTableModel createTableModel(List> metas); public String[] getParentProperties() { return parentProperties; } private String[] getChildProperties() { return childProperties; } public ContentTableModel getTableModel() { return tableModel; } public ListSelectionModel getSelectionModel() { return selectionModel; } /** @return le bean d'une ligne du tableau actuellement sélectionné */ public C getTableEditBean() { if (tableEditBean == null) { tableEditBean = newTableEditBean(); } return tableEditBean; } public C newTableEditBean() { try { return childType.getConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException("Can't create table edit bean", e); } } public boolean isCanSaveRow() { return canSaveRow; } public void setCanSaveRow(boolean canSaveRow) { boolean oldValue = this.canSaveRow; this.canSaveRow = canSaveRow; firePropertyChange(PROPERTY_CAN_SAVE_ROW, oldValue, canSaveRow); } boolean isCanResetRow() { return canResetRow; } public void setCanResetRow(boolean canResetRow) { boolean oldValue = this.canResetRow; this.canResetRow = canResetRow; firePropertyChange(PROPERTY_CAN_RESET_ROW, oldValue, canResetRow); } public boolean isRowSaved() { return rowSaved; } void setRowSaved(boolean rowSaved) { boolean oldValue = this.rowSaved; this.rowSaved = rowSaved; firePropertyChange(PROPERTY_ROW_SAVED, oldValue, rowSaved); } public boolean isShowData() { return showData; } public void setShowData(boolean showData) { boolean oldValue = this.showData; this.showData = showData; firePropertyChange(PROPERTY_SHOW_DATA, oldValue, showData); } @Override public void destroy() { super.destroy(); tableEditBean = null; tableModel = null; } //FIXME!!! On utilise les nouvelles api de java-lang by ultreia.io protected BinderModelBuilder prepareChildLoador(String binderName) { String[] properties = getChildProperties(); BinderModelBuilder builder = BinderModelBuilder.newEmptyBuilder(childType); builder.addSimpleProperties(properties); return builder; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy