1 package org.musicontroller.gui.components;
2
3 import org.apache.hivemind.util.PropertyUtils;
4 import org.apache.tapestry.BaseComponent;
5 import org.apache.tapestry.IPage;
6 import org.apache.tapestry.IRequestCycle;
7 import org.musicontroller.core.Song;
8
9 /**
10 * This component is a clickable link to an edit screen
11 * for a MusiController object. The object to edit is passed
12 * in the mandatory "object" property of the component. The
13 * object class is passed in the required "objectClass" property.
14 * The EditLink component inspects the object class and chooses
15 * a page to edit the object with. The EditLink then writes the
16 * object to the chosen pages and renders it.
17 * The "returnPage" parameter selects the page to render after
18 * editing the object has completed. This property defaults to
19 * the page the EditLink component is bound to.
20 *
21 * @author deksels
22 * @version $Id: EditLink.java,v 1.1 2010/03/16 18:55:42 varienaja Exp $
23 */
24 public abstract class EditLink extends BaseComponent {
25
26 /**
27 * Getter for the object to edit. This property is a required
28 * parameter of the EditLink component.
29 * @return The object the EditLink must send to the page the
30 * EditLink refers to.
31 */
32 public abstract Object getEditObject();
33
34 public abstract Class getEditClass();
35
36 /**
37 * Getter for the name of the page to render on completion
38 * of the edit. Default value is the page where the EditLink component
39 * is bound to. The returnPage must be a valid name of a Tapestry page
40 * in the application.
41 *
42 * @return Page name of the screen to render after the edit completes.
43 */
44 public abstract String getReturnPage();
45
46 public void editObject(IRequestCycle cycle) {
47 Object objToEdit = getEditObject();
48 Class theClass = getClass();
49 if(theClass==org.musicontroller.core.Song.class) {
50 IPage page = cycle.getPage("edit/SongEdit");
51 PropertyUtils.write(page,"song",(Song)objToEdit);
52 PropertyUtils.write(page, "returnPage", getReturnPage());
53 cycle.activate(page);
54 }
55 }
56 }