View Javadoc

1   package org.whatsitcalled.webflange.webapp.model;
2   
3   import org.apache.wicket.markup.repeater.IItemReuseStrategy;
4   import org.apache.wicket.model.LoadableDetachableModel;
5   import org.whatsitcalled.webflange.ResourceFactory;
6   import org.whatsitcalled.webflange.model.Project;
7   import org.whatsitcalled.webflange.model.ProjectDAO;
8   
9   public class ProjectDetachableModel extends LoadableDetachableModel {
10  	private transient Project project;
11  	private Long id;
12  	public ProjectDetachableModel(Project p) {
13  		this(p.getId());
14  		this.project = p;
15  	}
16  	
17  	public ProjectDetachableModel(Long id) {
18  		this.id = id;
19  	}
20  	
21  	protected ProjectDAO getDAO() {
22  		return ResourceFactory.getProjectDAO();
23  	}
24  	
25  	@Override
26  	protected Object load() {
27  		project = getDAO().getProject(id);
28  		return project;
29  	}
30  
31  	@Override
32  	public Object getObject() {
33  		return project;
34  	}
35  
36  	@Override
37  	protected void onAttach() {
38  		if (project == null) {
39  			project = getDAO().getProject(id); 
40  		}
41  	}
42  
43  	@Override
44  	protected void onDetach() {
45  		project=null;
46  	}
47  
48  	/**
49  	 * @see java.lang.Object#hashCode()
50  	 */
51  	public int hashCode()
52  	{
53  		return id.hashCode();
54  	}
55  
56  	/**
57  	 * used for dataview with ReuseIfModelsEqualStrategy item reuse strategy
58  	 * 
59  	 * @see wicket.extensions.markup.html.repeater.pageable.AbstractPageableView#setItemReuseStrategy(IItemReuseStrategy)
60  	 * @see wicket.extensions.markup.html.repeater.refreshing.ReuseIfModelsEqualStrategy
61  	 * @see java.lang.Object#equals(java.lang.Object)
62  	 */
63  	public boolean equals(Object obj)
64  	{
65  		if (obj instanceof ProjectDetachableModel)
66  		{
67  			ProjectDetachableModel other = (ProjectDetachableModel)obj;
68  			return other.id.equals(this.id);
69  		}
70  		return false;
71  	}
72  	
73  
74  }