CVS: TapestryBook/examples/src/java/examples/todo1 ToDo.java,NONE,1.1 ToDoItem.java,NONE,1.1
Howard Lewis Ship <[email protected]> Fri, 11 Jul 2003 21:16:48 -0700
| Newsgroups | gmane.comp.java.tapestry.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tapestry/TapestryBook/examples/src/java/examples/todo1
In directory sc8-pr-cvs1:/tmp/cvs-serv6871/examples/src/java/examples/todo1
Added Files:
ToDo.java ToDoItem.java
Log Message:
Reorganize examples application to reflect standard organization
--- NEW FILE: ToDo.java ---
package examples.todo1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.event.PageRenderListener;
import org.apache.tapestry.html.BasePage;
public abstract class ToDo extends BasePage implements PageRenderListener
{
public abstract List getToDoList();
public abstract void setToDoList(List toDoList);
public abstract ToDoItem getMoveUpItem();
public abstract ToDoItem getMoveDownItem();
public void addTodoItem(IRequestCycle cycle)
{
getToDoList().add(createNewItem("New Item"));
}
protected ToDoItem createNewItem(String title)
{
return new ToDoItem(title);
}
// The Submit for this is after the main loop, so its safe to
// actually edit the list.
public void deleteCompleted(IRequestCycle cycle)
{
ListIterator i = getToDoList().listIterator();
while (i.hasNext())
{
ToDoItem item = (ToDoItem) i.next();
if (item.isCompleted())
i.remove();
}
}
public void formSubmit(IRequestCycle cycle)
{
List list = getToDoList();
int count = list.size();
ToDoItem moveUpItem = getMoveUpItem();
ToDoItem moveDownItem = getMoveDownItem();
for (int i = 0; i < count; i++)
{
ToDoItem item = (ToDoItem) list.get(i);
if (item == moveUpItem)
{
if (i > 0)
Collections.swap(list, i, i - 1);
break;
}
if (item == moveDownItem)
{
if (i + 1 < count)
Collections.swap(list, i, i + 1);
break;
}
}
// Always important to set peristent properties; otherwise changes
// made in this request cycle will be lost. The framework
// makes a copy of the list.
setToDoList(list);
}
public void pageBeginRender(PageEvent event)
{
List list = getToDoList();
if (list == null)
{
list = new ArrayList();
list.add(createNewItem("Finish reading Tapestry Book"));
list.add(createNewItem("Download latest version of Tapestry"));
setToDoList(list);
}
}
}
--- NEW FILE: ToDoItem.java ---
package examples.todo1;
import java.io.Serializable;
public class ToDoItem implements Serializable
{
private boolean _completed;
private String _title;
public ToDoItem()
{
}
public ToDoItem(String title)
{
_title = title;
}
public boolean isCompleted()
{
return _completed;
}
public String getTitle()
{
return _title;
}
public void setCompleted(boolean completed)
{
_completed = completed;
}
public void setTitle(String title)
{
_title = title;
}
}
-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1