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.input; 029 030import org.opencms.gwt.client.ui.I_CmsTruncable; 031import org.opencms.gwt.client.ui.css.I_CmsInputLayoutBundle; 032 033/** 034 * This class represents a single select option in the selector of the select box. 035 */ 036public class CmsLabelSelectCell extends A_CmsSelectCell implements I_CmsTruncable { 037 038 /** The value of the select option. */ 039 protected String m_value; 040 041 /** The label of which this select cell consists. */ 042 private CmsLabel m_label = new CmsLabel(); 043 044 /** The label width last used in a truncate()-call. */ 045 private int m_labelWidth; 046 047 /** The opener text. */ 048 private String m_openerText; 049 050 /** The text of the select option. */ 051 private String m_text; 052 053 /** The text metrics key last used in a truncate()-call. */ 054 private String m_textMetricsKey; 055 056 /** 057 * Creates a new select cell.<p> 058 * 059 * @param value the value of the select option 060 * @param text the text to display for the select option 061 */ 062 public CmsLabelSelectCell(String value, String text) { 063 064 this(value, text, null); 065 } 066 067 /** 068 * Creates a new select cell.<p> 069 * 070 * @param value the value of the select option 071 * @param text the text to display for the select option 072 * @param title the title to display on mouseover 073 */ 074 public CmsLabelSelectCell(String value, String text, String title) { 075 076 super(); 077 m_value = value; 078 m_text = text; 079 m_openerText = text; 080 initWidget(m_label); 081 addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().selectBoxCell()); 082 m_label.setText(m_text); 083 m_label.setTitle(title != null ? title : m_text); 084 } 085 086 /** 087 * Gets the opener text.<p> 088 * 089 * @return the opener text 090 */ 091 public String getOpenerText() { 092 093 return m_openerText; 094 } 095 096 /** 097 * Returns the text as which the select option should be displayed to the user.<p> 098 * 099 * @return the text of the select option 100 */ 101 public String getText() { 102 103 return m_text; 104 } 105 106 /** 107 * @see org.opencms.gwt.client.ui.input.A_CmsSelectCell#getValue() 108 */ 109 @Override 110 public String getValue() { 111 112 return m_value; 113 } 114 115 /** 116 * Sets the opener text.<p> 117 * 118 * @param openerText the new opener text 119 */ 120 public void setOpenerText(String openerText) { 121 122 m_openerText = openerText; 123 } 124 125 /** 126 * Sets the text of the label.<p> 127 * 128 * @param text the new text 129 */ 130 public void setText(String text) { 131 132 m_label.setText(text); 133 m_label.setTitle(text); 134 m_text = text; 135 if (m_textMetricsKey != null) { 136 truncate(m_textMetricsKey, m_labelWidth); 137 } 138 } 139 140 /** 141 * @see org.opencms.gwt.client.ui.I_CmsTruncable#truncate(java.lang.String, int) 142 */ 143 public void truncate(String textMetricsKey, int labelWidth) { 144 145 m_textMetricsKey = textMetricsKey; 146 m_labelWidth = labelWidth; 147 m_label.truncate(textMetricsKey, labelWidth); 148 } 149 150}