Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 Daniel Murphy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
Created at Jun 21, 2010, 3:54:44 AM
 
 package com.dmurph.mvc.model;
 
This model keeps track of original and changed property values through the AbstractModel.firePropertyChange(java.lang.String,java.lang.Object,java.lang.Object) method. Assuming an extending class correctly implements AbstractModel.firePropertyChange(java.lang.String,java.lang.Object,java.lang.Object) and setProperty(java.lang.String,java.lang.Object) correctly, this class will keep track of any changes to the model so the model can save or revert changes. This also makes the isDirty() method more accurate, as it can check all the properties to see if they have changed.

Author(s):
Daniel Murphy
 
 public abstract class AbstractRevertibleModel extends AbstractModel implements IDirtyableIRevertible{
 	private static final long serialVersionUID = 1L;
 	
 	private boolean overridingDirty = false;
 	
 		super();
 			public void setProperty(String argPropertyNameObject argProperty) {
 				AbstractRevertibleModel.this.setProperty(argPropertyNameargProperty);
 			}
 		}, this);
 	}
    
If the model is "dirty", or changed since last save. This method can be expensive, as it checks all changed properties to see if they are dirty. Will also return true if setDirty(boolean) was recently called with true.

 
 	public boolean isDirty(){
 			return ;
 		}
 			if(prop.isDirty()){
 				return true;
 			}
 		}
 		return false;
 	}

If called with false, this is the equivalent of saveChanges(). If called with true, the model is dirty until saveChanges(), revertChanges(), or this method is called with false.
 
 	public void setDirty(boolean argDirty) {
 		if(argDirty){
 			 = true;
 		}else{
 			 = false;
 		}
 	}

Used to reset variables when revertChanges() is called.

Parameters:
argPropertyName the property name corresponding to the name given to the AbstractModel.firePropertyChange(java.lang.String,java.lang.Object,java.lang.Object) method
argValue the value to set the property
Returns:
the old value
 
	protected abstract Object setProperty(String argPropertyNameObject argValue);


	public void saveChanges() {
	}

	public void revertChanges() {
	}
New to GrepCode? Check out our FAQ X