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