001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.gwt.client.ui;
029
030import org.opencms.gwt.client.dnd.I_CmsDropTarget;
031import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
032import org.opencms.gwt.client.util.CmsDomUtil;
033
034import com.google.common.base.Optional;
035import com.google.gwt.dom.client.Element;
036import com.google.gwt.user.client.ui.Composite;
037import com.google.gwt.user.client.ui.Widget;
038
039/**
040 * Provides a UI list item.<p>
041 *
042 * @since 8.0.0
043 */
044public class CmsSimpleListItem extends Composite implements I_CmsListItem {
045
046    /** The logical id, it is not the HTML id. */
047    protected String m_id;
048
049    /** The underlying panel. */
050    protected CmsFlowPanel m_panel;
051
052    /**
053     * Constructor.<p>
054     */
055    public CmsSimpleListItem() {
056
057        m_panel = new CmsFlowPanel(CmsDomUtil.Tag.li.name());
058        m_panel.setStyleName(I_CmsLayoutBundle.INSTANCE.listTreeCss().listTreeItem());
059        initWidget(m_panel);
060    }
061
062    /**
063     * Constructor.<p>
064     *
065     * @param widget the widget to use
066     */
067    public CmsSimpleListItem(CmsListItemWidget widget) {
068
069        this();
070        add(widget);
071    }
072
073    /**
074     * @see org.opencms.gwt.client.ui.I_CmsListItem#add(com.google.gwt.user.client.ui.Widget)
075     */
076    public void add(Widget w) {
077
078        m_panel.add(w);
079    }
080
081    /**
082     * @see org.opencms.gwt.client.dnd.I_CmsDraggable#getCursorOffsetDelta()
083     */
084    public Optional<int[]> getCursorOffsetDelta() {
085
086        return Optional.absent();
087    }
088
089    /**
090     * @see org.opencms.gwt.client.dnd.I_CmsDraggable#getDragHelper(org.opencms.gwt.client.dnd.I_CmsDropTarget)
091     */
092    public Element getDragHelper(org.opencms.gwt.client.dnd.I_CmsDropTarget target) {
093
094        // TODO: Auto-generated method stub
095        return null;
096    }
097
098    /**
099     * @see org.opencms.gwt.client.ui.I_CmsListItem#getId()
100     */
101    public String getId() {
102
103        return m_id;
104    }
105
106    /**
107     * @see org.opencms.gwt.client.dnd.I_CmsDraggable#getParentTarget()
108     */
109    public I_CmsDropTarget getParentTarget() {
110
111        // TODO: Auto-generated method stub
112        return null;
113    }
114
115    /**
116     * @see org.opencms.gwt.client.dnd.I_CmsDraggable#getPlaceholder(org.opencms.gwt.client.dnd.I_CmsDropTarget)
117     */
118    public Element getPlaceholder(org.opencms.gwt.client.dnd.I_CmsDropTarget target) {
119
120        // TODO: Auto-generated method stub
121        return null;
122    }
123
124    /**
125     * Returns the child widget with the given index.<p>
126     *
127     * @param index the index
128     *
129     * @return the child widget
130     */
131    public Widget getWidget(int index) {
132
133        return m_panel.getWidget(index);
134    }
135
136    /**
137     * @see org.opencms.gwt.client.dnd.I_CmsDraggable#onDragCancel()
138     */
139    public void onDragCancel() {
140
141        // TODO: Auto-generated method stub
142
143    }
144
145    /**
146     * @see org.opencms.gwt.client.dnd.I_CmsDraggable#onDrop(org.opencms.gwt.client.dnd.I_CmsDropTarget)
147     */
148    public void onDrop(org.opencms.gwt.client.dnd.I_CmsDropTarget target) {
149
150        // TODO: Auto-generated method stub
151
152    }
153
154    /**
155     * @see org.opencms.gwt.client.dnd.I_CmsDraggable#onStartDrag(org.opencms.gwt.client.dnd.I_CmsDropTarget)
156     */
157    public void onStartDrag(org.opencms.gwt.client.dnd.I_CmsDropTarget target) {
158
159        // TODO: Auto-generated method stub
160
161    }
162
163    /**
164     * @see org.opencms.gwt.client.ui.I_CmsListItem#setId(java.lang.String)
165     */
166    public void setId(String id) {
167
168        m_id = id;
169    }
170
171    /**
172     * @see org.opencms.gwt.client.ui.I_CmsTruncable#truncate(java.lang.String, int)
173     */
174    public void truncate(String textMetricsPrefix, int widgetWidth) {
175
176        for (Widget widget : m_panel) {
177            if (!(widget instanceof I_CmsTruncable)) {
178                continue;
179            }
180            int width = widgetWidth - 4; // just to be on the safe side
181            if (widget instanceof CmsList<?>) {
182                width -= 25; // 25px left margin
183            }
184            ((I_CmsTruncable)widget).truncate(textMetricsPrefix, width);
185        }
186    }
187
188}