- Kleine Optimierung RelatedLinkTable

- Neue RelatedLinks erhalten jetzt wieder eine richtige Order-Angabe


git-svn-id: https://svn.libreccm.org/ccm/trunk@898 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2011-05-06 16:13:37 +00:00
parent 9c810f3e97
commit d4ad0bb5d8
7 changed files with 339 additions and 304 deletions

View File

@ -39,26 +39,24 @@ import org.apache.log4j.Logger;
* @version $Revision: #4 $ $Date: 2004/03/30 $ * @version $Revision: #4 $ $Date: 2004/03/30 $
* @author Scott Seago (sseago@redhat.com) * @author Scott Seago (sseago@redhat.com)
*/ */
public class RelatedLink extends Link { public class RelatedLink extends Link {
private static final Logger s_log = Logger.getLogger(RelatedLink.class); private static final Logger s_log = Logger.getLogger(RelatedLink.class);
/** PDL properties */ /** PDL properties */
public static final String LINK_LIST_NAME = "linkListName"; public static final String LINK_LIST_NAME = "linkListName";
public static final String RESOURCE_SIZE = "resourceSize"; public static final String RESOURCE_SIZE = "resourceSize";
public static final String RESOURCE_TYPE = "resourceType"; public static final String RESOURCE_TYPE = "resourceType";
public static final String LINK_OWNER = "linkOwner"; public static final String LINK_OWNER = "linkOwner";
public static final String RELATED_LINKS = "links"; public static final String RELATED_LINKS = "links";
/** Data object type for this domain object */ /** Data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE public static final String BASE_DATA_OBJECT_TYPE =
= "com.arsdigita.cms.contentassets.RelatedLink"; "com.arsdigita.cms.contentassets.RelatedLink";
/** /**
* Default constructor. This creates a new RelatedLink. * Default constructor. This creates a new RelatedLink.
*/ */
public RelatedLink() { public RelatedLink() {
this( BASE_DATA_OBJECT_TYPE ); this(BASE_DATA_OBJECT_TYPE);
} }
/** /**
@ -69,9 +67,9 @@ public class RelatedLink extends Link {
* @param id The <code>id</code> for the retrieved * @param id The <code>id</code> for the retrieved
* <code>DataObject</code> * <code>DataObject</code>
*/ */
public RelatedLink( BigDecimal id ) public RelatedLink(BigDecimal id)
throws DataObjectNotFoundException { throws DataObjectNotFoundException {
this( new OID( BASE_DATA_OBJECT_TYPE, id ) ); this(new OID(BASE_DATA_OBJECT_TYPE, id));
} }
/** /**
@ -82,9 +80,9 @@ public class RelatedLink extends Link {
* @param oid The <code>OID</code> for the retrieved * @param oid The <code>OID</code> for the retrieved
* <code>DataObject</code> * <code>DataObject</code>
*/ */
public RelatedLink( OID oid ) public RelatedLink(OID oid)
throws DataObjectNotFoundException { throws DataObjectNotFoundException {
super( oid ); super(oid);
} }
/** /**
@ -94,8 +92,8 @@ public class RelatedLink extends Link {
* @param obj The <code>DataObject</code> with which to create or * @param obj The <code>DataObject</code> with which to create or
* load a content item * load a content item
*/ */
public RelatedLink( DataObject obj ) { public RelatedLink(DataObject obj) {
super( obj ); super(obj);
} }
/** /**
@ -105,18 +103,18 @@ public class RelatedLink extends Link {
* @param type The <code>String</code> data object type of the * @param type The <code>String</code> data object type of the
* item to create * item to create
*/ */
public RelatedLink( String type ) { public RelatedLink(String type) {
super( type ); super(type);
} }
/** get the name of the named link list. */ /** get the name of the named link list. */
public String getLinkListName(){ public String getLinkListName() {
return (String) get(LINK_LIST_NAME); return (String) get(LINK_LIST_NAME);
} }
/** Set the name of the named link list. */ /** Set the name of the named link list. */
public void setLinkListName(String name){ public void setLinkListName(String name) {
set(LINK_LIST_NAME , name); set(LINK_LIST_NAME, name);
} }
/** /**
@ -124,12 +122,12 @@ public class RelatedLink extends Link {
* *
* @return <code>MimeType</code> of target resource. * @return <code>MimeType</code> of target resource.
*/ */
public MimeType getResourceType(){ public MimeType getResourceType() {
DataObject obj = (DataObject) get ( RESOURCE_TYPE ); DataObject obj = (DataObject) get(RESOURCE_TYPE);
if(obj != null){ if (obj != null) {
return new MimeType(obj); return new MimeType(obj);
} }
return null; return null;
} }
/** /**
@ -137,18 +135,18 @@ public class RelatedLink extends Link {
* *
* @param type , <code>MimeType</code> of target resource. * @param type , <code>MimeType</code> of target resource.
*/ */
public void setResourceType(MimeType type){ public void setResourceType(MimeType type) {
setAssociation(RESOURCE_TYPE , type); setAssociation(RESOURCE_TYPE, type);
} }
/** get the size of the target resource. */ /** get the size of the target resource. */
public String getResourceSize(){ public String getResourceSize() {
return (String) get(RESOURCE_SIZE); return (String) get(RESOURCE_SIZE);
} }
/** Set the size of the target resource. */ /** Set the size of the target resource. */
public void setResourceSize(String size){ public void setResourceSize(String size) {
set(RESOURCE_SIZE , size); set(RESOURCE_SIZE, size);
} }
/** /**
@ -172,7 +170,7 @@ public class RelatedLink extends Link {
if (dobj == null) { if (dobj == null) {
return null; return null;
} else { } else {
return (ContentItem)DomainObjectFactory.newInstance(dobj); return (ContentItem) DomainObjectFactory.newInstance(dobj);
} }
} }
@ -185,12 +183,20 @@ public class RelatedLink extends Link {
* @return * @return
*/ */
public static DataCollection getRelatedLinks(ContentItem item, String name) { public static DataCollection getRelatedLinks(ContentItem item, String name) {
s_log.debug("Getting related links for a content item"); s_log.debug(String.format("Getting related links for content item %s",
item.getID()));
long now = System.currentTimeMillis();
s_log.debug(String.format("Started at %d", now));
Session session = SessionManager.getSession(); Session session = SessionManager.getSession();
DataCollection links = session.retrieve(BASE_DATA_OBJECT_TYPE); DataCollection links = session.retrieve(BASE_DATA_OBJECT_TYPE);
links.addEqualsFilter(LINK_OWNER + ".id", item.getID()); links.addEqualsFilter(LINK_OWNER + ".id", item.getID());
links.addEqualsFilter(LINK_LIST_NAME, name); links.addEqualsFilter(LINK_LIST_NAME, name);
links.addOrder(ORDER); links.addOrder(ORDER);
s_log.debug(String.format(
"Got all related links for content item %s in %d ms. (time finished: %d)",
item.getID().toString(),
System.currentTimeMillis() - now,
System.currentTimeMillis()));
return links; return links;
} }
@ -205,22 +211,24 @@ public class RelatedLink extends Link {
public static DataCollection getReferringRelatedLinks(ContentItem item) { public static DataCollection getReferringRelatedLinks(ContentItem item) {
Session session = SessionManager.getSession(); Session session = SessionManager.getSession();
DataCollection links = session.retrieve(BASE_DATA_OBJECT_TYPE); DataCollection links = session.retrieve(BASE_DATA_OBJECT_TYPE);
Filter filter = links.addInSubqueryFilter("id", "com.arsdigita.cms.contentassets.getReferringRelatedLinks"); Filter filter =
links.addInSubqueryFilter("id",
"com.arsdigita.cms.contentassets.getReferringRelatedLinks");
filter.set("itemID", item.getID()); filter.set("itemID", item.getID());
return links; return links;
} }
/** /**
* Swaps this <code>RelatedLink</code> with the next one, * Swaps this <code>RelatedLink</code> with the next one,
* according to the linkOrder * according to the linkOrder
*/ */
@Override @Override
public void swapWithNext() { public void swapWithNext() {
swapWithNext("com.arsdigita.cms.contentassets.allRelatedLinkOrderForItem", swapWithNext(
"com.arsdigita.cms.contentassets.swapRelatedLinkWithNextInGroup", "com.arsdigita.cms.contentassets.allRelatedLinkOrderForItem",
this.getLinkListName()); "com.arsdigita.cms.contentassets.swapRelatedLinkWithNextInGroup",
this.getLinkListName());
} }
/** /**
@ -229,9 +237,10 @@ public class RelatedLink extends Link {
*/ */
@Override @Override
public void swapWithPrevious() { public void swapWithPrevious() {
swapWithPrevious("com.arsdigita.cms.contentassets.allRelatedLinkOrderForItem", swapWithPrevious(
"com.arsdigita.cms.contentassets.swapRelatedLinkWithNextInGroup", "com.arsdigita.cms.contentassets.allRelatedLinkOrderForItem",
this.getLinkListName()); "com.arsdigita.cms.contentassets.swapRelatedLinkWithNextInGroup",
this.getLinkListName());
} }
/** /**
@ -268,8 +277,6 @@ public class RelatedLink extends Link {
return operation; return operation;
} }
/** /**
* This method is only used for setting initial sort keys for * This method is only used for setting initial sort keys for
* links which exist without them. This is called by swapKeys * links which exist without them. This is called by swapKeys
@ -306,13 +313,13 @@ public class RelatedLink extends Link {
return 0; return 0;
} }
int returnOrder = 0; int returnOrder = 0;
DataQuery query = SessionManager.getSession().retrieveQuery DataQuery query = SessionManager.getSession().retrieveQuery(
("com.arsdigita.cms.contentassets.allRelatedLinkOrderForItem"); "com.arsdigita.cms.contentassets.allRelatedLinkOrderForItem");
query.setParameter("ownerID", getLinkOwner().getID()); query.setParameter("ownerID", getLinkOwner().getID());
query.setParameter("linkListName", getLinkListName()); query.setParameter("linkListName", getLinkListName());
query.addOrder("linkOrder DESC"); query.addOrder("linkOrder DESC");
if (query.next()) { if (query.next()) {
Integer linkOrder = ((Integer)query.get("linkOrder")); Integer linkOrder = ((Integer) query.get("linkOrder"));
query.close(); query.close();
if (linkOrder != null) { if (linkOrder != null) {
returnOrder = linkOrder.intValue(); returnOrder = linkOrder.intValue();
@ -326,7 +333,7 @@ public class RelatedLink extends Link {
public void beforeSave() { public void beforeSave() {
super.beforeSave(); super.beforeSave();
if (getOrder() == null) { if (getOrder() == null) {
setOrder(maxOrder()+1); setOrder(maxOrder() + 1);
} }
} }
} }

View File

@ -35,6 +35,7 @@ import com.arsdigita.cms.contentassets.RelatedLink;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.mimetypes.MimeType; import com.arsdigita.mimetypes.MimeType;
import com.arsdigita.mimetypes.MimeTypeCollection; import com.arsdigita.mimetypes.MimeTypeCollection;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -190,6 +191,10 @@ public class RelatedLinkPropertyForm extends LinkPropertyForm {
rl.setResourceType(mType); rl.setResourceType(mType);
} }
rl.setLinkListName((String) data.get(RelatedLink.LINK_LIST_NAME)); rl.setLinkListName((String) data.get(RelatedLink.LINK_LIST_NAME));
DataCollection links = RelatedLink.getRelatedLinks(getContentItem(fse.getPageState()), m_linkListName);
rl.setOrder((int) links.size() + 1);
super.setLinkProperties(link, fse); super.setLinkProperties(link, fse);
} }
} }

View File

@ -74,7 +74,7 @@ public class Link extends ACSObject {
public static final String ORDER = "linkOrder"; public static final String ORDER = "linkOrder";
/** Data object type for this domain object */ /** Data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE = public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.Link"; "com.arsdigita.cms.contenttypes.Link";
/** /**
* Default constructor. This creates a new Link. * Default constructor. This creates a new Link.
@ -165,8 +165,9 @@ public class Link extends ACSObject {
* Link.INTERNAL_LINK * Link.INTERNAL_LINK
*/ */
public void setTargetType(String type) { public void setTargetType(String type) {
Assert.isTrue(type != null && (type.equals(EXTERNAL_LINK) || type.equals( Assert.isTrue(type != null && (type.equals(EXTERNAL_LINK)
INTERNAL_LINK))); || type.equals(
INTERNAL_LINK)));
set(TARGET_TYPE, type); set(TARGET_TYPE, type);
} }
@ -196,7 +197,7 @@ public class Link extends ACSObject {
public ContentItem getTargetItem() { public ContentItem getTargetItem() {
DataObject object = (DataObject) get(TARGET_ITEM); DataObject object = (DataObject) get(TARGET_ITEM);
ACSObject acsObject = ACSObject acsObject =
(ACSObject) DomainObjectFactory.newInstance(object); (ACSObject) DomainObjectFactory.newInstance(object);
// Quasimodo: BEGIN // Quasimodo: BEGIN
// This is part of the patch to make RelatedLink (and Link) multilanguage compatible // This is part of the patch to make RelatedLink (and Link) multilanguage compatible
@ -207,7 +208,8 @@ public class Link extends ACSObject {
// If acsObject is instance of ContentBundle // If acsObject is instance of ContentBundle
if (acsObject instanceof ContentBundle) { if (acsObject instanceof ContentBundle) {
// get the negotiated language version of this ContentBundle // get the negotiated language version of this ContentBundle
ci = ((ContentBundle) acsObject).negotiate(DispatcherHelper.getRequest().getLocales()); ci = ((ContentBundle) acsObject).negotiate(DispatcherHelper.
getRequest().getLocales());
} else { } else {
// else there are no language versions so just use the acsObject // else there are no language versions so just use the acsObject
ci = (ContentItem) acsObject; ci = (ContentItem) acsObject;
@ -299,6 +301,7 @@ public class Link extends ACSObject {
* @return the Link URI * @return the Link URI
*/ */
public String getInternalOrExternalURI(PageState state) { public String getInternalOrExternalURI(PageState state) {
if (EXTERNAL_LINK.equals(getTargetType())) { if (EXTERNAL_LINK.equals(getTargetType())) {
return getTargetURI(); return getTargetURI();
} else { } else {
@ -306,7 +309,7 @@ public class Link extends ACSObject {
if (item == null) { if (item == null) {
s_log.error(getOID() s_log.error(getOID()
+ " is internal link, but has null target item"); + " is internal link, but has null target item");
return ""; return "";
} }
@ -333,7 +336,7 @@ public class Link extends ACSObject {
String.format( String.format(
"Internal link with parameters found. Generated URL is: %s", "Internal link with parameters found. Generated URL is: %s",
URL.there(state.getRequest(), url, URL.there(state.getRequest(), url,
parameters). parameters).
toString())); toString()));
return URL.there(state.getRequest(), url, parameters). return URL.there(state.getRequest(), url, parameters).
toString(); toString();
@ -356,8 +359,8 @@ public class Link extends ACSObject {
Session session = SessionManager.getSession(); Session session = SessionManager.getSession();
DataCollection links = session.retrieve(BASE_DATA_OBJECT_TYPE); DataCollection links = session.retrieve(BASE_DATA_OBJECT_TYPE);
Filter filter = Filter filter =
links.addInSubqueryFilter("id", links.addInSubqueryFilter("id",
"com.arsdigita.cms.contenttypes.getReferringLinks"); "com.arsdigita.cms.contenttypes.getReferringLinks");
filter.set("itemID", item.getID()); filter.set("itemID", item.getID());
return links; return links;
@ -400,7 +403,8 @@ public class Link extends ACSObject {
swapKeys(true, queryName, operationName, ""); swapKeys(true, queryName, operationName, "");
} }
public void swapWithNext(String queryName, String operationName, String linkListName) { public void swapWithNext(String queryName, String operationName,
String linkListName) {
swapKeys(true, queryName, operationName, linkListName); swapKeys(true, queryName, operationName, linkListName);
} }
@ -417,7 +421,8 @@ public class Link extends ACSObject {
swapKeys(false, queryName, operationName, ""); swapKeys(false, queryName, operationName, "");
} }
public void swapWithPrevious(String queryName, String operationName, String linkListName) { public void swapWithPrevious(String queryName, String operationName,
String linkListName) {
swapKeys(false, queryName, operationName, linkListName); swapKeys(false, queryName, operationName, linkListName);
} }
@ -457,12 +462,12 @@ public class Link extends ACSObject {
* @param queryName This is used to find the key with which to swap * @param queryName This is used to find the key with which to swap
*/ */
protected void swapKeys(boolean swapNext, String queryName, protected void swapKeys(boolean swapNext, String queryName,
String operationName) { String operationName) {
this.swapKeys(swapNext, queryName, operationName, ""); this.swapKeys(swapNext, queryName, operationName, "");
} }
protected void swapKeys(boolean swapNext, String queryName, protected void swapKeys(boolean swapNext, String queryName,
String operationName, String linkListName) { String operationName, String linkListName) {
String methodName = null; String methodName = null;
if (swapNext) { if (swapNext) {
@ -472,7 +477,7 @@ public class Link extends ACSObject {
} }
Assert.isTrue(!isNew(), methodName + " cannot be called on an " Assert.isTrue(!isNew(), methodName + " cannot be called on an "
+ "object that is new"); + "object that is new");
Integer currentKey = (Integer) get(ORDER); Integer currentKey = (Integer) get(ORDER);
// if the current item is not already ordered, alphabetize // if the current item is not already ordered, alphabetize
@ -483,8 +488,8 @@ public class Link extends ACSObject {
return; return;
} }
Assert.isTrue(currentKey != null, methodName + " cannot be " Assert.isTrue(currentKey != null, methodName + " cannot be "
+ "called on an object that is not currently in the " + "called on an object that is not currently in the "
+ "list"); + "list");
int key = currentKey.intValue(); int key = currentKey.intValue();
@ -493,17 +498,19 @@ public class Link extends ACSObject {
int otherKey = key; int otherKey = key;
if (swapNext) { if (swapNext) {
otherKey = key + 1; otherKey = key + 1;
query.addOrder("linkOrder ASC"); query.addOrder("linkOrder ASC");
query.addFilter(query.getFilterFactory().greaterThan("linkOrder", query.addFilter(query.getFilterFactory().greaterThan("linkOrder",
currentKey, currentKey,
true)); true));
} else { } else {
otherKey = key - 1; otherKey = key - 1;
query.addOrder("linkOrder DESC"); query.addOrder("linkOrder DESC");
query.addFilter(query.getFilterFactory().lessThan("linkOrder", query.addFilter(query.getFilterFactory().lessThan("linkOrder",
currentKey, true)); currentKey, true));
} }
if (query.next()) { if (query.next()) {

View File

@ -50,7 +50,6 @@ import com.arsdigita.cms.dispatcher.Utilities;
* @version $Revision: #6 $ $Date: 2004/08/17 $ * @version $Revision: #6 $ $Date: 2004/08/17 $
* @author Nobuko Asakai (nasakai@redhat.com) * @author Nobuko Asakai (nasakai@redhat.com)
*/ */
public class LinkTable extends Table { public class LinkTable extends Table {
private static final Logger s_log = Logger.getLogger(LinkTable.class); private static final Logger s_log = Logger.getLogger(LinkTable.class);
@ -62,11 +61,8 @@ public class LinkTable extends Table {
private TableColumn m_moveDownCol; private TableColumn m_moveDownCol;
private TableColumn m_editCol; private TableColumn m_editCol;
private TableColumn m_delCol; private TableColumn m_delCol;
private RequestLocal m_size; private RequestLocal m_size;
private RequestLocal m_editor; private RequestLocal m_editor;
protected static final String EDIT_EVENT = "Edit"; protected static final String EDIT_EVENT = "Edit";
protected static final String DELETE_EVENT = "Delete"; protected static final String DELETE_EVENT = "Delete";
protected static final String UP_EVENT = "up"; protected static final String UP_EVENT = "up";
@ -90,18 +86,18 @@ public class LinkTable extends Table {
m_size = new RequestLocal(); m_size = new RequestLocal();
m_editor = new RequestLocal() { m_editor = new RequestLocal() {
public Object initialValue(PageState state) {
SecurityManager sm = Utilities.getSecurityManager(state); public Object initialValue(PageState state) {
ContentItem item = (ContentItem)m_itemModel SecurityManager sm = Utilities.getSecurityManager(state);
.getSelectedObject(state); ContentItem item = (ContentItem) m_itemModel.getSelectedObject(
Boolean val = new Boolean(sm.canAccess( state);
state.getRequest(), Boolean val = new Boolean(sm.canAccess(
SecurityManager.EDIT_ITEM, state.getRequest(),
item SecurityManager.EDIT_ITEM,
)); item));
return val; return val;
} }
}; };
Label empty = new Label("There are no links for this content item"); Label empty = new Label("There are no links for this content item");
setEmptyView(empty); setEmptyView(empty);
@ -117,9 +113,9 @@ public class LinkTable extends Table {
TableColumnModel model = getColumnModel(); TableColumnModel model = getColumnModel();
int i = 0; int i = 0;
m_titleCol = new TableColumn(i, "Link"); m_titleCol = new TableColumn(i, "Link");
m_descCol = new TableColumn(++i, "Description"); m_descCol = new TableColumn(++i, "Description");
m_editCol = new TableColumn(++i, "Edit"); m_editCol = new TableColumn(++i, "Edit");
m_delCol = new TableColumn(++i, "Delete"); m_delCol = new TableColumn(++i, "Delete");
m_moveUpCol = new TableColumn(++i, ""); m_moveUpCol = new TableColumn(++i, "");
m_moveDownCol = new TableColumn(++i, ""); m_moveDownCol = new TableColumn(++i, "");
model.add(m_titleCol); model.add(m_titleCol);
@ -135,6 +131,7 @@ public class LinkTable extends Table {
* TableCellRenderer class for LinkTable * TableCellRenderer class for LinkTable
*/ */
private class LinkTableRenderer implements TableCellRenderer { private class LinkTableRenderer implements TableCellRenderer {
public Component getComponent(Table table, public Component getComponent(Table table,
PageState state, PageState state,
Object value, Object value,
@ -142,29 +139,30 @@ public class LinkTable extends Table {
Object key, Object key,
int row, int row,
int column) { int column) {
Link link = (Link)value; Link link = (Link) value;
boolean isFirst = (row == 0); boolean isFirst = (row == 0);
if (m_size.get(state) == null) { if (m_size.get(state) == null) {
m_size.set(state, m_size.set(state,
new Long(((LinkTableModelBuilder.LinkTableModel) new Long(((LinkTableModelBuilder.LinkTableModel) table.
table.getTableModel(state)).size())); getTableModel(state)).size()));
} }
boolean isLast = (row == ((Long)m_size.get(state)).intValue() - 1); boolean isLast = (row == ((Long) m_size.get(state)).intValue() - 1);
String url = link.getInternalOrExternalURI(state);
if (column == m_titleCol.getModelIndex()) { if (column == m_titleCol.getModelIndex()) {
ExternalLink extLink = new ExternalLink(link.getTitle(), url); String url = link.getInternalOrExternalURI(state);
extLink.setTargetFrame("_blank"); ExternalLink extLink = new ExternalLink(link.getTitle(), url);
extLink.setTargetFrame("_blank");
return extLink; return extLink;
} else if ( column == m_descCol.getModelIndex()) { } else if (column == m_descCol.getModelIndex()) {
if ( isSelected ) { if (isSelected) {
return new Label(link.getDescription(), Label.BOLD); return new Label(link.getDescription(), Label.BOLD);
} else { } else {
return new Label(link.getDescription()); return new Label(link.getDescription());
} }
} else if ( column == m_editCol.getModelIndex()) { } else if (column == m_editCol.getModelIndex()) {
if (Boolean.TRUE.equals(m_editor.get(state))) { if (Boolean.TRUE.equals(m_editor.get(state))) {
if (isSelected ) { if (isSelected) {
return new Label(EDIT_EVENT, Label.BOLD); return new Label(EDIT_EVENT, Label.BOLD);
} else { } else {
return new ControlLink(EDIT_EVENT); return new ControlLink(EDIT_EVENT);
@ -172,7 +170,7 @@ public class LinkTable extends Table {
} else { } else {
return new Label(EDIT_EVENT); return new Label(EDIT_EVENT);
} }
} else if ( column == m_delCol.getModelIndex()) { } else if (column == m_delCol.getModelIndex()) {
if (Boolean.TRUE.equals(m_editor.get(state))) { if (Boolean.TRUE.equals(m_editor.get(state))) {
return new ControlLink(DELETE_EVENT); return new ControlLink(DELETE_EVENT);
} else { } else {
@ -180,20 +178,20 @@ public class LinkTable extends Table {
} }
} else if (column == m_moveUpCol.getModelIndex()) { } else if (column == m_moveUpCol.getModelIndex()) {
if (Boolean.TRUE.equals(m_editor.get(state)) && !isFirst) { if (Boolean.TRUE.equals(m_editor.get(state)) && !isFirst) {
Label upLabel = new Label(UP_EVENT); Label upLabel = new Label(UP_EVENT);
upLabel.setClassAttr("linkSort"); upLabel.setClassAttr("linkSort");
return new ControlLink(upLabel); return new ControlLink(upLabel);
} else { } else {
return new Label(""); return new Label("");
} }
} else if (column == m_moveDownCol.getModelIndex()) { } else if (column == m_moveDownCol.getModelIndex()) {
if (Boolean.TRUE.equals(m_editor.get(state)) && !isLast) { if (Boolean.TRUE.equals(m_editor.get(state)) && !isLast) {
Label downLabel = new Label(DOWN_EVENT); Label downLabel = new Label(DOWN_EVENT);
downLabel.setClassAttr("linkSort"); downLabel.setClassAttr("linkSort");
return new ControlLink(downLabel); return new ControlLink(downLabel);
} else { } else {
return new Label(""); return new Label("");
} }
} else { } else {
throw new UncheckedWrapperException("column out of bounds"); throw new UncheckedWrapperException("column out of bounds");
} }
@ -204,20 +202,22 @@ public class LinkTable extends Table {
* TableActionListener class for LinkTable * TableActionListener class for LinkTable
*/ */
private class LinkTableActionListener implements TableActionListener { private class LinkTableActionListener implements TableActionListener {
private Link getLink(TableActionEvent e) { private Link getLink(TableActionEvent e) {
Object o = e.getRowKey(); Object o = e.getRowKey();
BigDecimal id; BigDecimal id;
if (o instanceof String) { if (o instanceof String) {
s_log.debug("row key is a string : " + o); s_log.debug("row key is a string : " + o);
id = new BigDecimal((String)o); id = new BigDecimal((String) o);
} else { } else {
id = (BigDecimal)e.getRowKey(); id = (BigDecimal) e.getRowKey();
} }
Assert.exists(id); Assert.exists(id);
Link link; Link link;
try { try {
link = (Link)DomainObjectFactory.newInstance(new OID(Link.BASE_DATA_OBJECT_TYPE,id)); link = (Link) DomainObjectFactory.newInstance(new OID(
Link.BASE_DATA_OBJECT_TYPE, id));
} catch (DataObjectNotFoundException de) { } catch (DataObjectNotFoundException de) {
throw new UncheckedWrapperException(de); throw new UncheckedWrapperException(de);
} }
@ -225,40 +225,41 @@ public class LinkTable extends Table {
} }
public void cellSelected(TableActionEvent e) { public void cellSelected(TableActionEvent e) {
int col = e.getColumn().intValue(); int col = e.getColumn().intValue();
PageState state = e.getPageState(); PageState state = e.getPageState();
Link link = getLink(e); Link link = getLink(e);
Assert.exists(link); Assert.exists(link);
if (col== m_titleCol.getModelIndex()) { if (col == m_titleCol.getModelIndex()) {
// do nothing // do nothing
} else if (col == m_editCol.getModelIndex()) { } else if (col == m_editCol.getModelIndex()) {
if (Boolean.TRUE.equals(m_editor.get(state))) { if (Boolean.TRUE.equals(m_editor.get(state))) {
// This selection is passed to the LinkPropertyForm // This selection is passed to the LinkPropertyForm
s_log.debug("setting linkModel to :" + link.getTitle()); s_log.debug("setting linkModel to :" + link.getTitle());
m_linkModel.setSelectedObject(state, link); m_linkModel.setSelectedObject(state, link);
} }
} else if (col == m_delCol.getModelIndex()) { } else if (col == m_delCol.getModelIndex()) {
if (Boolean.TRUE.equals(m_editor.get(state))) { if (Boolean.TRUE.equals(m_editor.get(state))) {
try { try {
s_log.debug("About to delete"); s_log.debug("About to delete");
m_linkModel.clearSelection(state); m_linkModel.clearSelection(state);
link.delete(); link.delete();
} catch ( PersistenceException pe) { } catch (PersistenceException pe) {
throw new UncheckedWrapperException(pe); throw new UncheckedWrapperException(pe);
} }
} }
} else if (col == m_moveUpCol.getModelIndex() ) { } else if (col == m_moveUpCol.getModelIndex()) {
// move the link up // move the link up
m_linkModel.clearSelection(state); m_linkModel.clearSelection(state);
link.swapWithPrevious(); link.swapWithPrevious();
} else if ( col == m_moveDownCol.getModelIndex() ) { } else if (col == m_moveDownCol.getModelIndex()) {
// move the link down // move the link down
m_linkModel.clearSelection(state); m_linkModel.clearSelection(state);
link.swapWithNext(); link.swapWithNext();
} }
} }
public void headSelected(TableActionEvent e) {} public void headSelected(TableActionEvent e) {
}
} }
} }

View File

@ -36,12 +36,11 @@ import org.apache.log4j.Logger;
* @version $Revision: #4 $ $Date: 2004/08/17 $ * @version $Revision: #4 $ $Date: 2004/08/17 $
* @author Nobuko Asakai (nasakai@redhat.com) * @author Nobuko Asakai (nasakai@redhat.com)
*/ */
public abstract class LinkTableModelBuilder public abstract class LinkTableModelBuilder
extends LockableImpl implements TableModelBuilder { extends LockableImpl implements TableModelBuilder {
private static final Logger s_log =
Logger.getLogger(LinkTableModelBuilder.class);
private static final Logger s_log =
Logger.getLogger(LinkTableModelBuilder.class);
/** /**
* Creates the LinKTableModel based on the current table and pagestate * Creates the LinKTableModel based on the current table and pagestate
@ -55,7 +54,7 @@ public abstract class LinkTableModelBuilder
DataCollection links = getLinks(s); DataCollection links = getLinks(s);
if ( links.isEmpty() ) { if (links.isEmpty()) {
return Table.EMPTY_MODEL; return Table.EMPTY_MODEL;
} else { } else {
return new LinkTableModel(links); return new LinkTableModel(links);
@ -78,15 +77,22 @@ public abstract class LinkTableModelBuilder
Link m_link; Link m_link;
DataCollection m_links; DataCollection m_links;
public LinkTableModel(DataCollection links) { public LinkTableModel(DataCollection links) {
m_links = links; m_links = links;
m_link = null; m_link = null;
} }
public boolean nextRow() { public boolean nextRow() {
s_log.debug(String.format("m_links.size() = %d", m_links.size()));
if (m_links.next()) { if (m_links.next()) {
s_log.debug("Getting domain object for link...");
long now = System.currentTimeMillis();
DataObject object = m_links.getDataObject(); DataObject object = m_links.getDataObject();
m_link = (Link)DomainObjectFactory.newInstance(object); m_link = (Link) DomainObjectFactory.newInstance(object);
s_log.debug(String.format("Got domain object in %d ms", System.
currentTimeMillis() - now));
return true; return true;
} else { } else {
return false; return false;
@ -94,7 +100,7 @@ public abstract class LinkTableModelBuilder
} }
public int getColumnCount() { public int getColumnCount() {
return (int)m_links.size(); return (int) m_links.size();
} }
@ -105,8 +111,9 @@ public abstract class LinkTableModelBuilder
public Object getKeyAt(int columnIndex) { public Object getKeyAt(int columnIndex) {
return m_link.getID(); return m_link.getID();
} }
public long size() { public long size() {
return m_links.size(); return m_links.size();
} }
} }
} }

View File

@ -38,6 +38,7 @@ import com.arsdigita.util.Assert;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import java.util.Iterator; import java.util.Iterator;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import org.apache.log4j.Logger;
/** /**
* Displays statically or * Displays statically or
@ -92,45 +93,33 @@ import javax.servlet.ServletException;
*/ */
public class Table extends BlockStylable implements BebopConstants { public class Table extends BlockStylable implements BebopConstants {
private static final Logger logger = Logger.getLogger(Table.class);
// Names for HTML Attributes // Names for HTML Attributes
private static final String WIDTH = "width"; private static final String WIDTH = "width";
private static final String CELL_SPACING = "cellspacing"; private static final String CELL_SPACING = "cellspacing";
private static final String CELL_PADDING = "cellpadding"; private static final String CELL_PADDING = "cellpadding";
private static final String BORDER = "border"; private static final String BORDER = "border";
private static final String SELECTED_ROW = "row";
private static final String SELECTED_ROW="row";
/** /**
* The control event when the user selects one table cell. * The control event when the user selects one table cell.
* This control event will only be used when * This control event will only be used when
*/ */
protected static final String CELL_EVENT = "cell"; protected static final String CELL_EVENT = "cell";
protected static final char SEP = ' '; protected static final char SEP = ' ';
private TableModelBuilder m_modelBuilder; private TableModelBuilder m_modelBuilder;
private TableColumnModel m_columnModel; private TableColumnModel m_columnModel;
private TableHeader m_header; private TableHeader m_header;
private RequestLocal m_tableModel; private RequestLocal m_tableModel;
private SingleSelectionModel m_rowSelectionModel; private SingleSelectionModel m_rowSelectionModel;
/** /**
* A listener to forward headSelected events originating from the * A listener to forward headSelected events originating from the
* TableHeader. This will be null until somebody actually registers a * TableHeader. This will be null until somebody actually registers a
* TableActionListener from the outside. * TableActionListener from the outside.
*/ */
private TableActionListener m_headerForward; private TableActionListener m_headerForward;
private EventListenerList m_listeners; private EventListenerList m_listeners;
private TableCellRenderer m_defaultCellRenderer; private TableCellRenderer m_defaultCellRenderer;
private Component m_emptyView; private Component m_emptyView;
private boolean m_striped = false; private boolean m_striped = false;
/** /**
@ -184,14 +173,13 @@ public class Table extends BlockStylable implements BebopConstants {
m_columnModel = c; m_columnModel = c;
setHeader(new TableHeader(m_columnModel)); setHeader(new TableHeader(m_columnModel));
m_rowSelectionModel = m_rowSelectionModel =
new ParameterSingleSelectionModel(new StringParameter(SELECTED_ROW)); new ParameterSingleSelectionModel(new StringParameter(SELECTED_ROW));
m_listeners = new EventListenerList(); m_listeners = new EventListenerList();
m_defaultCellRenderer = new DefaultTableCellRenderer(); m_defaultCellRenderer = new DefaultTableCellRenderer();
initTableModel(); initTableModel();
} }
// Events and listeners // Events and listeners
/** /**
* Adds a {@link TableActionListener} to the table. The listener is * Adds a {@link TableActionListener} to the table. The listener is
* fired whenever a table cell is clicked. * fired whenever a table cell is clicked.
@ -200,16 +188,15 @@ public class Table extends BlockStylable implements BebopConstants {
*/ */
public void addTableActionListener(TableActionListener l) { public void addTableActionListener(TableActionListener l) {
Assert.isUnlocked(this); Assert.isUnlocked(this);
if ( m_headerForward == null ) { if (m_headerForward == null) {
m_headerForward = createTableActionListener(); m_headerForward = createTableActionListener();
if ( m_header != null ) { if (m_header != null) {
m_header.addTableActionListener(m_headerForward); m_header.addTableActionListener(m_headerForward);
} }
} }
m_listeners.add(TableActionListener.class, l); m_listeners.add(TableActionListener.class, l);
} }
/** /**
* Removes a {@link TableActionListener} from the table. * Removes a {@link TableActionListener} from the table.
* *
@ -230,12 +217,11 @@ public class Table extends BlockStylable implements BebopConstants {
*/ */
protected void fireCellSelected(PageState state, protected void fireCellSelected(PageState state,
Object rowKey, Integer column) { Object rowKey, Integer column) {
Iterator Iterator i = m_listeners.getListenerIterator(TableActionListener.class);
i=m_listeners.getListenerIterator(TableActionListener.class);
TableActionEvent e = null; TableActionEvent e = null;
while (i.hasNext()) { while (i.hasNext()) {
if ( e == null ) { if (e == null) {
e = new TableActionEvent(this, state, rowKey, column); e = new TableActionEvent(this, state, rowKey, column);
} }
((TableActionListener) i.next()).cellSelected(e); ((TableActionListener) i.next()).cellSelected(e);
@ -252,19 +238,17 @@ public class Table extends BlockStylable implements BebopConstants {
*/ */
protected void fireHeadSelected(PageState state, protected void fireHeadSelected(PageState state,
Object rowKey, Integer column) { Object rowKey, Integer column) {
Iterator Iterator i = m_listeners.getListenerIterator(TableActionListener.class);
i=m_listeners.getListenerIterator(TableActionListener.class);
TableActionEvent e = null; TableActionEvent e = null;
while (i.hasNext()) { while (i.hasNext()) {
if ( e == null ) { if (e == null) {
e = new TableActionEvent(this, state, rowKey, column); e = new TableActionEvent(this, state, rowKey, column);
} }
((TableActionListener) i.next()).headSelected(e); ((TableActionListener) i.next()).headSelected(e);
} }
} }
/** /**
* Instantiates a new {@link TableActionListener} for this table. * Instantiates a new {@link TableActionListener} for this table.
* *
@ -274,12 +258,12 @@ public class Table extends BlockStylable implements BebopConstants {
*/ */
protected TableActionListener createTableActionListener() { protected TableActionListener createTableActionListener() {
return new TableActionAdapter() { return new TableActionAdapter() {
public void headSelected(TableActionEvent e) {
fireHeadSelected(e.getPageState(), e.getRowKey(), e.getColumn());
}
};
}
public void headSelected(TableActionEvent e) {
fireHeadSelected(e.getPageState(), e.getRowKey(), e.getColumn());
}
};
}
/** /**
* @return the {@link TableColumnModel} for this table. * @return the {@link TableColumnModel} for this table.
@ -310,7 +294,7 @@ public class Table extends BlockStylable implements BebopConstants {
* *
* @param v the new {@link TableModelBuilder} * @param v the new {@link TableModelBuilder}
*/ */
public void setModelBuilder(TableModelBuilder v) { public void setModelBuilder(TableModelBuilder v) {
Assert.isUnlocked(this); Assert.isUnlocked(this);
m_modelBuilder = v; m_modelBuilder = v;
} }
@ -329,18 +313,18 @@ public class Table extends BlockStylable implements BebopConstants {
* @param v the new header for this table. If null, the header will be * @param v the new header for this table. If null, the header will be
* hidden. * hidden.
*/ */
public void setHeader(TableHeader v) { public void setHeader(TableHeader v) {
Assert.isUnlocked(this); Assert.isUnlocked(this);
if ( m_headerForward != null ) { if (m_headerForward != null) {
if ( m_header != null ) { if (m_header != null) {
m_header.removeTableActionListener(m_headerForward); m_header.removeTableActionListener(m_headerForward);
} }
if ( v != null ) { if (v != null) {
v.addTableActionListener(m_headerForward); v.addTableActionListener(m_headerForward);
} }
} }
m_header = v; m_header = v;
if ( m_header != null ) { if (m_header != null) {
m_header.setTable(this); m_header.setTable(this);
} }
} }
@ -361,7 +345,7 @@ public class Table extends BlockStylable implements BebopConstants {
* @param i the numerical index of the column * @param i the numerical index of the column
* @param v the column that is to be mapped at i * @param v the column that is to be mapped at i
*/ */
public void setColumn(int i, TableColumn v) { public void setColumn(int i, TableColumn v) {
getColumnModel().set(i, v); getColumnModel().set(i, v);
} }
@ -379,7 +363,7 @@ public class Table extends BlockStylable implements BebopConstants {
* *
* @param v a {@link SingleSelectionModel} * @param v a {@link SingleSelectionModel}
*/ */
public void setRowSelectionModel(SingleSelectionModel v) { public void setRowSelectionModel(SingleSelectionModel v) {
Assert.isUnlocked(this); Assert.isUnlocked(this);
m_rowSelectionModel = v; m_rowSelectionModel = v;
} }
@ -389,8 +373,8 @@ public class Table extends BlockStylable implements BebopConstants {
* for selecting the current column. * for selecting the current column.
*/ */
public SingleSelectionModel getColumnSelectionModel() { public SingleSelectionModel getColumnSelectionModel() {
return ( getColumnModel() == null ) ? null : return (getColumnModel() == null) ? null : getColumnModel().
getColumnModel().getSelectionModel(); getSelectionModel();
} }
/** /**
@ -399,7 +383,7 @@ public class Table extends BlockStylable implements BebopConstants {
* *
* @param v a {@link SingleSelectionModel} * @param v a {@link SingleSelectionModel}
*/ */
public void setColumnSelectionModel(SingleSelectionModel v) { public void setColumnSelectionModel(SingleSelectionModel v) {
Assert.isUnlocked(this); Assert.isUnlocked(this);
// TODO: make sure table gets notified of changes // TODO: make sure table gets notified of changes
getColumnModel().setSelectionModel(v); getColumnModel().setSelectionModel(v);
@ -431,7 +415,7 @@ public class Table extends BlockStylable implements BebopConstants {
* *
* @param v the default {@link TableCellRenderer} * @param v the default {@link TableCellRenderer}
*/ */
public final void setDefaultCellRenderer(TableCellRenderer v) { public final void setDefaultCellRenderer(TableCellRenderer v) {
m_defaultCellRenderer = v; m_defaultCellRenderer = v;
} }
@ -443,7 +427,6 @@ public class Table extends BlockStylable implements BebopConstants {
return m_emptyView; return m_emptyView;
} }
/** /**
* Sets the empty view. The empty view is the component that * Sets the empty view. The empty view is the component that
* is shown if the table is empty. Usually, the component * is shown if the table is empty. Usually, the component
@ -451,12 +434,11 @@ public class Table extends BlockStylable implements BebopConstants {
* *
* @param v a Bebop component * @param v a Bebop component
*/ */
public final void setEmptyView(Component v) { public final void setEmptyView(Component v) {
m_emptyView = v; m_emptyView = v;
} }
// Set HTML table attributes // Set HTML table attributes
/** /**
* *
* @return the HTML width of the table. * @return the HTML width of the table.
@ -469,7 +451,7 @@ public class Table extends BlockStylable implements BebopConstants {
* *
* @param v the HTML width of the table * @param v the HTML width of the table
*/ */
public void setWidth(String v) { public void setWidth(String v) {
setAttribute(WIDTH, v); setAttribute(WIDTH, v);
} }
@ -485,11 +467,10 @@ public class Table extends BlockStylable implements BebopConstants {
* *
* @param v the HTML border of the table * @param v the HTML border of the table
*/ */
public void setBorder(String v) { public void setBorder(String v) {
setAttribute(BORDER, v); setAttribute(BORDER, v);
} }
public String getCellSpacing() { public String getCellSpacing() {
return getAttribute(CELL_SPACING); return getAttribute(CELL_SPACING);
} }
@ -498,7 +479,7 @@ public class Table extends BlockStylable implements BebopConstants {
* *
* @param v the HTML width of the table * @param v the HTML width of the table
*/ */
public void setCellSpacing(String v) { public void setCellSpacing(String v) {
setAttribute(CELL_SPACING, v); setAttribute(CELL_SPACING, v);
} }
@ -514,7 +495,7 @@ public class Table extends BlockStylable implements BebopConstants {
* *
* @param v the HTML cell padding of the table * @param v the HTML cell padding of the table
*/ */
public void setCellPadding(String v) { public void setCellPadding(String v) {
setAttribute(CELL_PADDING, v); setAttribute(CELL_PADDING, v);
} }
@ -529,13 +510,13 @@ public class Table extends BlockStylable implements BebopConstants {
String rowKey = null; String rowKey = null;
Integer column = null; Integer column = null;
if ( CELL_EVENT.equals(event) ) { if (CELL_EVENT.equals(event)) {
String value = s.getControlEventValue(); String value = s.getControlEventValue();
SingleSelectionModel rowSel = getRowSelectionModel(); SingleSelectionModel rowSel = getRowSelectionModel();
SingleSelectionModel colSel = getColumnSelectionModel(); SingleSelectionModel colSel = getColumnSelectionModel();
int split = value.indexOf(SEP); int split = value.indexOf(SEP);
rowKey = value.substring(0, split); rowKey = value.substring(0, split);
column = new Integer(value.substring(split+1)); column = new Integer(value.substring(split + 1));
colSel.setSelectedKey(s, column); colSel.setSelectedKey(s, column);
rowSel.setSelectedKey(s, rowKey); rowSel.setSelectedKey(s, rowKey);
fireCellSelected(s, rowKey, column); fireCellSelected(s, rowKey, column);
@ -552,12 +533,14 @@ public class Table extends BlockStylable implements BebopConstants {
* @param p the page that contains this table * @param p the page that contains this table
*/ */
public void register(Page p) { public void register(Page p) {
ParameterModel m = getRowSelectionModel() == null ? null : getRowSelectionModel().getStateParameter(); ParameterModel m = getRowSelectionModel() == null ? null
if ( m != null ) { : getRowSelectionModel().getStateParameter();
if (m != null) {
p.addComponentStateParam(this, m); p.addComponentStateParam(this, m);
} }
m = getColumnSelectionModel() == null ? null : getColumnSelectionModel().getStateParameter(); m = getColumnSelectionModel() == null ? null : getColumnSelectionModel().
if ( m != null ) { getStateParameter();
if (m != null) {
p.addComponentStateParam(this, m); p.addComponentStateParam(this, m);
} }
return; return;
@ -571,25 +554,26 @@ public class Table extends BlockStylable implements BebopConstants {
*/ */
public Iterator children() { public Iterator children() {
return new Iterator() { return new Iterator() {
int pos = (getHeader()==null) ? -1 : -2;
public boolean hasNext() { int pos = (getHeader() == null) ? -1 : -2;
return pos < getColumnModel().size() -1;
}
public Object next() { public boolean hasNext() {
pos += 1; return pos < getColumnModel().size() - 1;
if ( pos == -1 ) { }
return getHeader();
} else {
return getColumn(pos);
}
}
public void remove() { public Object next() {
throw new UnsupportedOperationException("Read-only iterator."); pos += 1;
if (pos == -1) {
return getHeader();
} else {
return getColumn(pos);
} }
}; }
public void remove() {
throw new UnsupportedOperationException("Read-only iterator.");
}
};
} }
/** /**
@ -601,12 +585,12 @@ public class Table extends BlockStylable implements BebopConstants {
* <code>false</code> otherwise. * <code>false</code> otherwise.
*/ */
public boolean isSelectedRow(PageState s, Object rowKey) { public boolean isSelectedRow(PageState s, Object rowKey) {
if ( rowKey == null || getRowSelectionModel() == null) { if (rowKey == null || getRowSelectionModel() == null) {
return false; return false;
} }
return getRowSelectionModel().isSelected(s) return getRowSelectionModel().isSelected(s)
&& rowKey.toString().equals( && rowKey.toString().equals(
getRowSelectionModel().getSelectedKey(s).toString()); getRowSelectionModel().getSelectedKey(s).toString());
} }
/** /**
@ -619,12 +603,12 @@ public class Table extends BlockStylable implements BebopConstants {
* <code>false</code> otherwise. * <code>false</code> otherwise.
*/ */
public boolean isSelectedColumn(PageState s, Object column) { public boolean isSelectedColumn(PageState s, Object column) {
if ( column == null || getColumnSelectionModel() == null) { if (column == null || getColumnSelectionModel() == null) {
return false; return false;
} }
return getColumnSelectionModel().isSelected(s) return getColumnSelectionModel().isSelected(s)
&& column.toString().equals( && column.toString().equals(
getColumnSelectionModel().getSelectedKey(s).toString()); getColumnSelectionModel().getSelectedKey(s).toString());
} }
/** /**
@ -644,7 +628,6 @@ public class Table extends BlockStylable implements BebopConstants {
return isSelectedRow(s, rowKey) && isSelectedColumn(s, column); return isSelectedRow(s, rowKey) && isSelectedColumn(s, column);
} }
public void setStriped(boolean striped) { public void setStriped(boolean striped) {
m_striped = striped; m_striped = striped;
} }
@ -695,13 +678,13 @@ public class Table extends BlockStylable implements BebopConstants {
final boolean tableIsRegisteredWithPage = final boolean tableIsRegisteredWithPage =
s.getPage().stateContains(getControler()); s.getPage().stateContains(getControler());
if (model.nextRow()) { if (model.nextRow()) {
Element table = p.newChildElement(BEBOP_TABLE, BEBOP_XML_NS); Element table = p.newChildElement(BEBOP_TABLE, BEBOP_XML_NS);
exportAttributes(table); exportAttributes(table);
generateExtraXMLAttributes(s, table); generateExtraXMLAttributes(s, table);
if ( getHeader() != null ) { if (getHeader() != null) {
getHeader().generateXML(s, table); getHeader().generateXML(s, table);
} }
Element tbody = table.newChildElement(BEBOP_TABLEBODY, BEBOP_XML_NS); Element tbody = table.newChildElement(BEBOP_TABLEBODY, BEBOP_XML_NS);
@ -711,37 +694,63 @@ public class Table extends BlockStylable implements BebopConstants {
final int modelSize = getColumnModel().size(); final int modelSize = getColumnModel().size();
int row = 0; int row = 0;
do {
Element trow = tbody.newChildElement(BEBOP_TABLEROW, BEBOP_XML_NS);
for (int i=0; i< modelSize; i++) { logger.debug("Creating table rows...");
long start = System.currentTimeMillis();
do {
long rowStart = System.currentTimeMillis();
Element trow = tbody.newChildElement(BEBOP_TABLEROW,
BEBOP_XML_NS);
for (int i = 0; i < modelSize; i++) {
TableColumn tc = getColumn(i); TableColumn tc = getColumn(i);
if ( tc.isVisible(s) ) { if (tc.isVisible(s)) {
TableCellRenderer r = tc.getCellRenderer(); TableCellRenderer r = tc.getCellRenderer();
if ( r == null ) { if (r == null) {
r = m_defaultCellRenderer; r = m_defaultCellRenderer;
} }
final int modelIndex = tc.getModelIndex(); final int modelIndex = tc.getModelIndex();
Object key = model.getKeyAt(modelIndex); Object key = model.getKeyAt(modelIndex);
Object value = model.getElementAt(modelIndex); Object value = model.getElementAt(modelIndex);
boolean selected = isSelectedCell(s, key, new Integer(i)); boolean selected =
isSelectedCell(s, key, new Integer(i));
if (tableIsRegisteredWithPage) { if (tableIsRegisteredWithPage) {
StringBuffer coords = new StringBuffer(40); /*StringBuffer coords = new StringBuffer(40);
coords.append(model.getKeyAt(modelIndex)) coords.append(model.getKeyAt(modelIndex)).append(SEP).
.append(SEP).append(i); append(i);
s.setControlEvent(getControler(), CELL_EVENT, s.setControlEvent(getControler(), CELL_EVENT,
coords.toString()); coords.toString());*/
s.setControlEvent(getControler(),
CELL_EVENT,
String.format("%s%s%d",
model.getKeyAt(
modelIndex),
SEP,
i));
} }
Element cell = trow.newChildElement(BEBOP_CELL, BEBOP_XML_NS);
Element cell = trow.newChildElement(BEBOP_CELL,
BEBOP_XML_NS);
tc.exportCellAttributes(cell); tc.exportCellAttributes(cell);
r.getComponent(this, s, value, selected, key, row, i) long begin = System.currentTimeMillis();
.generateXML(s, cell); r.getComponent(this, s, value, selected, key, row, i).
generateXML(s, cell);
logger.debug(String.format("until here i needed %d ms",
System.currentTimeMillis()
- begin));
} }
} }
row += 1; row += 1;
logger.debug(
String.format("Created row in %d ms",
System.currentTimeMillis() - rowStart));
} while (model.nextRow()); } while (model.nextRow());
} else if ( m_emptyView != null ) { logger.debug(String.format("Build table rows in %d ms",
System.currentTimeMillis() - start));
} else if (m_emptyView != null) {
m_emptyView.generateXML(s, p); m_emptyView.generateXML(s, p);
} }
if (tableIsRegisteredWithPage) { if (tableIsRegisteredWithPage) {
@ -771,10 +780,11 @@ public class Table extends BlockStylable implements BebopConstants {
*/ */
private void initTableModel() { private void initTableModel() {
m_tableModel = new RequestLocal() { m_tableModel = new RequestLocal() {
protected Object initialValue(PageState s) {
return m_modelBuilder.makeModel(Table.this, s); protected Object initialValue(PageState s) {
} return m_modelBuilder.makeModel(Table.this, s);
}; }
};
} }
/** /**
@ -799,7 +809,7 @@ public class Table extends BlockStylable implements BebopConstants {
* builder use row numbers, converted to strings, as the key for * builder use row numbers, converted to strings, as the key for
* each column of a row. */ * each column of a row. */
public static class MatrixTableModelBuilder public static class MatrixTableModelBuilder
extends AbstractTableModelBuilder { extends AbstractTableModelBuilder {
private Object[][] m_data; private Object[][] m_data;
@ -809,48 +819,46 @@ public class Table extends BlockStylable implements BebopConstants {
public TableModel makeModel(Table t, PageState s) { public TableModel makeModel(Table t, PageState s) {
return new TableModel() { return new TableModel() {
private int row = -1;
public int getColumnCount() { private int row = -1;
return m_data[0].length;
}
public boolean nextRow() { public int getColumnCount() {
return ( ++row < m_data.length ); return m_data[0].length;
} }
public Object getElementAt(int j) { public boolean nextRow() {
return m_data[row][j]; return (++row < m_data.length);
} }
public Object getKeyAt(int j) { public Object getElementAt(int j) {
return String.valueOf(row); return m_data[row][j];
} }
};
public Object getKeyAt(int j) {
return String.valueOf(row);
}
};
} }
} }
/** /**
* A {@link TableModel} that has no rows. * A {@link TableModel} that has no rows.
*/ */
public static final TableModel EMPTY_MODEL = new TableModel() { public static final TableModel EMPTY_MODEL = new TableModel() {
public int getColumnCount() { public int getColumnCount() {
return 0; return 0;
} }
public boolean nextRow() { public boolean nextRow() {
return false; return false;
} }
public Object getKeyAt(int column) { public Object getKeyAt(int column) {
throw new IllegalStateException("TableModel is empty"); throw new IllegalStateException("TableModel is empty");
} }
public Object getElementAt(int column) {
throw new IllegalStateException("TableModel is empty");
}
};
public Object getElementAt(int column) {
throw new IllegalStateException("TableModel is empty");
}
};
} }

View File

@ -854,8 +854,8 @@ public class URL {
} }
public static URL excursion(final HttpServletRequest sreq, public static URL excursion(final HttpServletRequest sreq,
final String path, final String path,
final ParameterMap params) { final ParameterMap params) {
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Creating excursion URL to " + path); s_log.debug("Creating excursion URL to " + path);
} }
@ -868,7 +868,7 @@ public class URL {
} }
public static URL excursion(final HttpServletRequest sreq, public static URL excursion(final HttpServletRequest sreq,
final String path) { final String path) {
return URL.excursion(sreq, path, new ParameterMap()); return URL.excursion(sreq, path, new ParameterMap());
} }