001/*
002 * (C) Copyright 2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id: EditableModel.java 27477 2007-11-20 19:55:44Z jcarsique $
020 */
021
022package org.nuxeo.ecm.platform.ui.web.model;
023
024import javax.faces.model.DataModel;
025
026import org.nuxeo.ecm.core.api.ListDiff;
027
028/**
029 * Interface for editable data model.
030 * <p>
031 * Follows data model interface and adds method to deal with edit/add/modify.
032 *
033 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
034 */
035public interface EditableModel {
036
037    /**
038     * Returns original data used for data model creation.
039     */
040    Object getOriginalData();
041
042    /**
043     * Gets wrapped data.
044     * <p>
045     * This data may be different from the original one if any changes occured on the model.
046     */
047    Object getWrappedData();
048
049    /**
050     * Sets wrapped data.
051     */
052    void setWrappedData(Object data);
053
054    /**
055     * @since 7.2
056     */
057    Object getUnreferencedTemplate();
058
059    // row data methods
060
061    /**
062     * @see DataModel#isRowAvailable()
063     */
064    boolean isRowAvailable();
065
066    /**
067     * Returns true if row data has changed from its original value.
068     */
069    boolean isRowModified();
070
071    /**
072     * Returns true if row data is not in the original list.
073     */
074    boolean isRowNew();
075
076    /**
077     * Records a value has been modified at given index.
078     */
079    void recordValueModified(int index, Object newValue);
080
081    /**
082     * @see DataModel#getRowCount()
083     */
084    int getRowCount();
085
086    /**
087     * @see DataModel#getRowData()
088     */
089    Object getRowData();
090
091    /**
092     * Sets row data using given value.
093     */
094    void setRowData(Object rowData);
095
096    /**
097     * @see DataModel#getRowIndex()
098     */
099    int getRowIndex();
100
101    /**
102     * @see DataModel#setRowIndex(int)
103     */
104    void setRowIndex(int rowIndex);
105
106    /**
107     * Gets unique key identifier for this row.
108     */
109    Integer getRowKey();
110
111    /**
112     * Sets unique key identifier for this row.
113     */
114    void setRowKey(Integer key);
115
116    /**
117     * Returns the list diff, ignoring all data that has not changed.
118     * <p>
119     * The list diff tracks chronologically all changes that were made to the original (and changing) model.
120     */
121    ListDiff getListDiff();
122
123    /**
124     * Sets list diff.
125     */
126    void setListDiff(ListDiff listDiff);
127
128    /**
129     * Returns true if any changes occurred on the model.
130     */
131    boolean isDirty();
132
133    /**
134     * Adds new value at the end of the model.
135     */
136    boolean addValue(Object value);
137
138    /**
139     * @since 7.2
140     */
141    void addTemplateValue();
142
143    /**
144     * Inserts value at given index on the model.
145     *
146     * @throws IllegalArgumentException if model does not handle this index.
147     */
148    void insertValue(int index, Object value);
149
150    /**
151     * @since 7.2
152     */
153    void insertTemplateValue(int index);
154
155    /**
156     * Modifies value at given index on the model.
157     *
158     * @return the old value at that index.
159     * @throws IllegalArgumentException if model does not handle one of given indexes.
160     */
161    Object moveValue(int fromIndex, int toIndex);
162
163    /**
164     * Removes value at given index.
165     *
166     * @return the old value at that index.
167     * @throws IllegalArgumentException if model does not handle this index.
168     */
169    Object removeValue(int index);
170
171    /**
172     * Returns the model size.
173     */
174    int size();
175
176}