1 24 package org.riotfamily.riot.list.ui; 25 26 import javax.servlet.http.HttpServletRequest ; 27 28 import org.riotfamily.common.i18n.MessageResolver; 29 import org.riotfamily.riot.dao.ListParams; 30 import org.riotfamily.riot.dao.RiotDao; 31 import org.riotfamily.riot.editor.EditorDefinitionUtils; 32 import org.riotfamily.riot.editor.ListDefinition; 33 import org.riotfamily.riot.list.ListConfig; 34 import org.riotfamily.riot.list.command.CommandContext; 35 36 class CommandContextImpl implements CommandContext { 37 38 private ListSession session; 39 40 private ListItem item; 41 42 private int itemsTotal; 43 44 private Object bean; 45 46 private Object parent; 47 48 private HttpServletRequest request; 49 50 public CommandContextImpl(ListSession session, HttpServletRequest request) { 51 this.session = session; 52 this.request = request; 53 } 54 55 public void setItem(ListItem item) { 56 this.item = item; 57 } 58 59 public Class getBeanClass() { 60 return session.getBeanClass(); 61 } 62 63 public RiotDao getDao() { 64 return session.getListDefinition().getListConfig().getDao(); 65 } 66 67 public Object getBean() { 68 if (bean == null && getObjectId() != null) { 69 bean = session.loadBean(getObjectId()); 70 } 71 return bean; 72 } 73 74 public void setBean(Object bean) { 75 this.bean = bean; 76 } 77 78 public Object getParent() { 79 if (parent == null && getParentId() != null) { 80 ListDefinition listDef = getListDefinition(); 81 parent = EditorDefinitionUtils.loadParent(listDef, getParentId()); 82 } 83 return parent; 84 } 85 86 public void setItemsTotal(int itemsTotal) { 87 this.itemsTotal = itemsTotal; 88 } 89 90 public int getItemsTotal() { 91 return itemsTotal; 92 } 93 94 public ListDefinition getListDefinition() { 95 return session.getListDefinition(); 96 } 97 98 public ListConfig getListConfig() { 99 return getListDefinition().getListConfig(); 100 } 101 102 public MessageResolver getMessageResolver() { 103 return session.getMessageResolver(); 104 } 105 106 public String getObjectId() { 107 return item != null ? item.getObjectId() : null; 108 } 109 110 public ListParams getParams() { 111 return session.getParams(); 112 } 113 114 public String getParentId() { 115 return session.getParentId(); 116 } 117 118 public HttpServletRequest getRequest() { 119 return request; 120 } 121 122 public int getRowIndex() { 123 return item.getRowIndex(); 124 } 125 126 } | Popular Tags |