RelationAttribute zum List-typen gemacht

git-svn-id: https://svn.libreccm.org/ccm/trunk@516 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-08-24 16:51:44 +00:00
parent 11ffecfffb
commit 7c5c3e6165
3 changed files with 144 additions and 93 deletions

View File

@ -223,8 +223,7 @@ final class ContentTypeItemPane extends BaseItemPane {
RelationAttributeSection(/*final ActionLink attributeEditLink*/) { RelationAttributeSection(/*final ActionLink attributeEditLink*/) {
setHeading(new Label(gz("cms.ui.type.attributes"))); setHeading(new Label(gz("cms.ui.type.attributes")));
setBody(new RelationAttributeContainer(m_type)); setBody(new RelationAttributeList(m_type));
// setBody(new Label("RelationAttributeContainer"));
} }
@Override @Override

View File

@ -1,91 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentType;
import com.arsdigita.toolbox.ui.ComponentMap;
import com.arsdigita.xml.Element;
import java.util.Iterator;
import java.util.StringTokenizer;
/**
*
* @author quasi
*/
class RelationAttributeContainer extends ComponentMap {
private ContentTypeRequestLocal m_type;
private ContentType contentType;
private StringTokenizer relationAttributeList;
// private static final RequestLocal s_components = new RequestLocal() {
// protected final Object initialValue(final PageState state) {
// return new ComponentMap();
// }
// };
public RelationAttributeContainer(ContentTypeRequestLocal type) {
super();
m_type = type;
relationAttributeList = null;
}
@Override
public final boolean isVisible(final PageState state) {
boolean retVal = false;
ContentType ct = (ContentType) m_type.getContentType(state);
ContentItem ci = null;
try {
Class<? extends ContentItem> clazz = Class.forName(ct.getClassName()).asSubclass(ContentItem.class);
ci = clazz.newInstance();
retVal = clazz.cast(ci).hasRelationAttributes();
relationAttributeList = clazz.cast(ci).getRelationAttributes();
ci.delete();
} catch (Exception ex) {
//retVal = false;
}
// Test
while (relationAttributeList.hasMoreElements()) {
String token = relationAttributeList.nextToken();
put(token, new Label(token));
// ActionLink link = new ActionLink(new Label(token));
// link.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// }
// });
}
return retVal;
}
// HACK: Dies sollte geändert werden, aber ich weiß nicht wie. Das ist der einfachste
// Weg, die exception zu verhindern, aber ich bin mir sicher, daß das später zu
// Problemen führen wird.
@Override
public void lock() {
}
public final void generateXML(final PageState state, final Element parent) {
if (isVisible(state)) {
Iterator iter = children();
while (iter.hasNext()) {
((Component) iter.next()).generateXML(state, parent);
}
}
}
}

View File

@ -0,0 +1,143 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.List;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.list.AbstractListModelBuilder;
import com.arsdigita.bebop.list.ListCellRenderer;
import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentType;
import java.util.StringTokenizer;
/**
*
* @author quasi
*/
public class RelationAttributeList extends List {
private ContentTypeRequestLocal m_type;
private ContentType contentType;
private StringTokenizer relationAttributeList;
public RelationAttributeList(ContentTypeRequestLocal type) {
super(new RelationAttributeListModelBuilder(type));
m_type = type;
relationAttributeList = null;
setCellRenderer(new CellRenderer());
}
@Override
public final boolean isVisible(final PageState state) {
boolean retVal = false;
ContentType ct = (ContentType) m_type.getContentType(state);
ContentItem ci = null;
try {
Class<? extends ContentItem> clazz = Class.forName(ct.getClassName()).asSubclass(ContentItem.class);
ci = clazz.newInstance();
retVal = clazz.cast(ci).hasRelationAttributes();
relationAttributeList = clazz.cast(ci).getRelationAttributes();
ci.delete();
} catch (Exception ex) {
//retVal = false;
}
return retVal;
}
private static class RelationAttributeListModelBuilder extends AbstractListModelBuilder {
private ContentTypeRequestLocal m_type;
private ContentType contentType;
private StringTokenizer relationAttributeList;
public RelationAttributeListModelBuilder(ContentTypeRequestLocal type) {
super();
m_type = type;
relationAttributeList = null;
}
public final ListModel makeModel(final List list, final PageState state) {
boolean retVal = false;
ContentType ct = (ContentType) m_type.getContentType(state);
ContentItem ci = null;
try {
Class<? extends ContentItem> clazz = Class.forName(ct.getClassName()).asSubclass(ContentItem.class);
ci = clazz.newInstance();
retVal = clazz.cast(ci).hasRelationAttributes();
relationAttributeList = clazz.cast(ci).getRelationAttributes();
ci.delete();
} catch (Exception ex) {
//retVal = false;
}
// final DataCollection folders =
// SessionManager.getSession().retrieve(Folder.BASE_DATA_OBJECT_TYPE);
//
// folders.addEqualsFilter(ContentItem.PARENT, parent.getID());
// folders.addOrder("lower(" + ACSObject.DISPLAY_NAME + ")");
//
// return new Model(new ItemCollection(folders));
return new Model(relationAttributeList);
}
private class Model implements ListModel {
// private final ItemCollection m_items;
private final StringTokenizer m_items;
private String m_item;
// Model(final ItemCollection items) {
// m_items = items;
// }
Model(final StringTokenizer items) {
m_items = items;
m_item = null;
}
public final boolean next() {
if (m_items.hasMoreTokens()) {
m_item = m_items.nextToken();
return true;
} else {
m_item = null;
return false;
}
}
// Label
public final Object getElement() {
return m_item;
}
// URL
public final String getKey() {
return m_item + "/";
}
}
}
private class CellRenderer implements ListCellRenderer {
public final Component getComponent(final List list,
final PageState state,
final Object value,
final String key,
final int index,
final boolean isSelected) {
return new Link((String) value, key);
}
}
}