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 055 registerRpc(this, I_CmsEditableGroupButtonsServerRpc.class); 056 m_handler = actionHandler; 057 } 058 059 /** 060 * @see com.vaadin.ui.AbstractComponent#getState() 061 */ 062 @Override 063 public CmsEditableGroupButtonsState getState() { 064 065 return (CmsEditableGroupButtonsState)super.getState(); 066 } 067 068 /** 069 * @see org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc#onAdd() 070 */ 071 public void onAdd() { 072 073 m_handler.onAdd(); 074 } 075 076 /** 077 * @see org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc#onDelete() 078 */ 079 public void onDelete() { 080 081 m_handler.onDelete(); 082 } 083 084 /** 085 * @see org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc#onDown() 086 */ 087 public void onDown() { 088 089 m_handler.onDown(); 090 } 091 092 /** 093 * @see org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc#onEdit() 094 */ 095 public void onEdit() { 096 097 m_handler.onEdit(); 098 } 099 100 /** 101 * @see org.opencms.ui.shared.rpc.I_CmsEditableGroupButtonsServerRpc#onUp() 102 */ 103 public void onUp() { 104 105 m_handler.onUp(); 106 } 107 108 /** 109 * Sets the 'first' and 'last' status of the button bar.<p> 110 * 111 * @param first true if this is the button bar of the first row 112 * @param last true if this is the button bar of the last row 113 * @param hideAdd true -> hide add option 114 */ 115 public void setFirstLast(boolean first, boolean last, boolean hideAdd) { 116 117 CmsEditableGroupButtonsState state = (CmsEditableGroupButtonsState)getState(false); 118 if ((state.isFirst() != first) || (state.isLast() != last)) { 119 state.setFirst(first); 120 state.setLast(last); 121 state.setAddOptionHidden(hideAdd); 122 markAsDirty(); 123 } 124 } 125 126}