diff --git a/ccm-cms/src/com/arsdigita/cms/ui/type/ContentTypeItemPane.java b/ccm-cms/src/com/arsdigita/cms/ui/type/ContentTypeItemPane.java index c568e8770..e7d7c5044 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/type/ContentTypeItemPane.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/type/ContentTypeItemPane.java @@ -223,8 +223,7 @@ final class ContentTypeItemPane extends BaseItemPane { RelationAttributeSection(/*final ActionLink attributeEditLink*/) { setHeading(new Label(gz("cms.ui.type.attributes"))); - setBody(new RelationAttributeContainer(m_type)); -// setBody(new Label("RelationAttributeContainer")); + setBody(new RelationAttributeList(m_type)); } @Override diff --git a/ccm-cms/src/com/arsdigita/cms/ui/type/RelationAttributeContainer.java b/ccm-cms/src/com/arsdigita/cms/ui/type/RelationAttributeContainer.java deleted file mode 100644 index 32b2f221c..000000000 --- a/ccm-cms/src/com/arsdigita/cms/ui/type/RelationAttributeContainer.java +++ /dev/null @@ -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 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); - } - } - } -} diff --git a/ccm-cms/src/com/arsdigita/cms/ui/type/RelationAttributeList.java b/ccm-cms/src/com/arsdigita/cms/ui/type/RelationAttributeList.java new file mode 100644 index 000000000..fbc9de1d6 --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/ui/type/RelationAttributeList.java @@ -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 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 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); + } + } +}