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.ui.components; 029 030import com.vaadin.server.FontIcon; 031import com.vaadin.ui.Button; 032import com.vaadin.ui.Button.ClickEvent; 033import com.vaadin.ui.Button.ClickListener; 034import com.vaadin.ui.Component; 035import com.vaadin.v7.ui.HorizontalLayout; 036 037/** 038 * Form row with button.<p> 039 * @param <T> T of Field 040 */ 041public class CmsButtonFormRow<T extends Component> extends HorizontalLayout { 042 043 /**Vaadin serial id. */ 044 private static final long serialVersionUID = 7691914937148837396L; 045 046 /** The text input field. */ 047 private T m_input; 048 049 /** 050 * Public constructor.<p> 051 * 052 * @param input field 053 * @param buttonIcon icon 054 * @param buttonRun runnable 055 * @param buttonDescription description 056 */ 057 public CmsButtonFormRow(T input, FontIcon buttonIcon, final Runnable buttonRun, String buttonDescription) { 058 059 setWidth("100%"); 060 m_input = input; 061 setSpacing(true); 062 input.setWidth("100%"); 063 addComponent(input); 064 setExpandRatio(input, 1f); 065 Button deleteButton = new Button(""); 066 deleteButton.setIcon(buttonIcon); 067 deleteButton.addStyleName(CmsRemovableFormRow.REMOVE_BUTTON_STYLE); 068 deleteButton.addStyleName(OpenCmsTheme.BUTTON_ICON); 069 deleteButton.setDescription(buttonDescription); 070 deleteButton.addClickListener(new ClickListener() { 071 072 private static final long serialVersionUID = 1L; 073 074 public void buttonClick(ClickEvent event) { 075 076 buttonRun.run(); 077 } 078 }); 079 addComponent(deleteButton); 080 } 081 082 /** 083 * Gets the input field.<p> 084 * 085 * @return input field 086 */ 087 public T getInput() { 088 089 return m_input; 090 } 091 092}