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.editablegroup; 029 030import org.opencms.ui.shared.CmsEditableGroupButtonsState; 031import org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc; 032 033import com.vaadin.ui.AbstractComponent; 034 035/** 036 * Button bar for manipulating rows in a multivalued field list.<p> 037 * 038 * Has buttons for moving a row up and down, deleting it, and adding a new row. 039 */ 040public class CmsEditableGroupButtons extends AbstractComponent implements I_CmsEditableGroupButtonsServerRpc { 041 042 /** Serial version id. */ 043 private static final long serialVersionUID = 1L; 044 045 /** The action handler instance. */ 046 private I_CmsEditableGroupActionHandler m_handler; 047 048 /** 049 * Creates a new instance.<p> 050 * 051 * @param actionHandler handler which should be called for different button presses 052 */ 053 public CmsEditableGroupButtons(I_CmsEditableGroupActionHandler actionHandler) { 054 registerRpc(this, I_CmsEditableGroupButtonsServerRpc.class); 055 m_handler = actionHandler; 056 } 057 058 /** 059 * @see com.vaadin.ui.AbstractComponent#getState() 060 */ 061 @Override 062 public CmsEditableGroupButtonsState getState() { 063 064 return (CmsEditableGroupButtonsState)super.getState(); 065 } 066 067 /** 068 * @see org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc#onAdd() 069 */ 070 public void onAdd() { 071 072 m_handler.onAdd(); 073 } 074 075 /** 076 * @see org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc#onDelete() 077 */ 078 public void onDelete() { 079 080 m_handler.onDelete(); 081 } 082 083 /** 084 * @see org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc#onDown() 085 */ 086 public void onDown() { 087 088 m_handler.onDown(); 089 } 090 091 /** 092 * @see org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc#onUp() 093 */ 094 public void onUp() { 095 096 m_handler.onUp(); 097 } 098 099 /** 100 * Sets the 'first' and 'last' status of the button bar.<p> 101 * 102 * @param first true if this is the button bar of the first row 103 * @param last true if this is the button bar of the last row 104 * @param hideAdd true -> hide add option 105 */ 106 public void setFirstLast(boolean first, boolean last, boolean hideAdd) { 107 108 CmsEditableGroupButtonsState state = (CmsEditableGroupButtonsState)getState(false); 109 if ((state.isFirst() != first) || (state.isLast() != last)) { 110 state.setFirst(first); 111 state.setLast(last); 112 state.setAddOptionHidden(hideAdd); 113 markAsDirty(); 114 } 115 } 116 117}