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.client.editablegroup; 029 030import org.opencms.gwt.client.ui.CmsPushButton; 031import org.opencms.gwt.client.ui.I_CmsButton; 032import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; 033 034import com.google.gwt.core.shared.GWT; 035import com.google.gwt.dom.client.StyleInjector; 036import com.google.gwt.event.dom.client.ClickEvent; 037import com.google.gwt.uibinder.client.UiBinder; 038import com.google.gwt.uibinder.client.UiField; 039import com.google.gwt.uibinder.client.UiHandler; 040import com.google.gwt.user.client.ui.Composite; 041import com.google.gwt.user.client.ui.FlowPanel; 042 043/** 044 * Client side button bar widget for multivalue widget groups.<p> 045 */ 046public class CmsClientEditableGroupButtons extends Composite { 047 048 /** The UI binder interface. */ 049 interface I_UiBinder extends UiBinder<FlowPanel, CmsClientEditableGroupButtons> { 050 // nothing to do 051 } 052 053 /** Indicates whether we have already flushed the UiBinder style. */ 054 private static boolean flushedStyle; 055 056 /** The UI binder instance. */ 057 private static I_UiBinder uiBinder = GWT.create(I_UiBinder.class); 058 059 /** The 'add' button. */ 060 @UiField 061 protected CmsPushButton m_addButton; 062 063 /** The 'delete' button. */ 064 @UiField 065 protected CmsPushButton m_deleteButton; 066 067 /** The 'down' button. */ 068 @UiField 069 protected CmsPushButton m_downButton; 070 071 /** OpenCms 'bullseye' dummy button, does nothing. */ 072 @UiField 073 protected CmsPushButton m_dummyButton; 074 075 /** The 'edit' button. */ 076 @UiField 077 protected CmsPushButton m_editButton; 078 079 /** The 'up' button. */ 080 @UiField 081 protected CmsPushButton m_upButton; 082 083 /** The connector instance. */ 084 private CmsEditableGroupButtonsConnector m_connector; 085 086 /** 087 * Creates a new instance.<p> 088 * 089 * @param connector the connector for which the widget should be created 090 */ 091 public CmsClientEditableGroupButtons(CmsEditableGroupButtonsConnector connector) { 092 093 FlowPanel panel = uiBinder.createAndBindUi(this); 094 if (!flushedStyle) { 095 StyleInjector.flush(); // make sure UiBinder CSS is loaded synchronously, otherwise Vaadin width calculation will go wrong 096 flushedStyle = true; 097 } 098 initWidget(panel); 099 m_connector = connector; 100 for (CmsPushButton button : new CmsPushButton[] { 101 m_dummyButton, 102 m_upButton, 103 m_downButton, 104 m_deleteButton, 105 m_addButton, 106 m_editButton}) { 107 button.setButtonStyle(ButtonStyle.FONT_ICON, null); 108 } 109 110 m_downButton.setImageClass(I_CmsButton.EDIT_DOWN_SMALL); 111 m_upButton.setImageClass(I_CmsButton.EDIT_UP_SMALL); 112 m_deleteButton.setImageClass(I_CmsButton.CUT_SMALL); 113 m_addButton.setImageClass(I_CmsButton.ADD_SMALL); 114 m_editButton.setImageClass(I_CmsButton.EDIT_SMALL); 115 m_dummyButton.setImageClass(I_CmsButton.EDIT_POINT_SMALL); 116 117 } 118 119 /** 120 * Shows / hides the edit button. 121 * 122 * @param editEnabled true if edit button should be shown 123 */ 124 public void setEditVisible(boolean editEnabled) { 125 126 m_editButton.setVisible(editEnabled); 127 } 128 129 /** 130 * Sets the 'first' status of the button bar.<p> 131 * 132 * @param first true if this is the button bar of the first row of a multivalue field 133 */ 134 public void setFirst(boolean first) { 135 136 m_upButton.setVisible(!first); 137 } 138 139 /** 140 * Hides the add button.<p> 141 * 142 * @param hideAdd true-> hide the add button 143 */ 144 public void setHideAdd(boolean hideAdd) { 145 146 m_addButton.setVisible(!hideAdd); 147 } 148 149 /** 150 * Sets the 'last' status of the button bar.<p> 151 * 152 * @param last true if this is the button bar of the last row of a multivalue field 153 */ 154 public void setLast(boolean last) { 155 156 m_downButton.setVisible(!last); 157 } 158 159 /** 160 * UI handler for the 'add' button.<p> 161 * 162 * @param event the click event 163 */ 164 @UiHandler("m_addButton") 165 void clickAdd(ClickEvent event) { 166 167 //HANDLER.closeAll(); 168 m_connector.getRpc().onAdd(); 169 170 } 171 172 /** 173 * UI handler for the 'delete' button.<p> 174 * 175 * @param event the click event 176 */ 177 @UiHandler("m_deleteButton") 178 void clickDelete(ClickEvent event) { 179 180 //HANDLER.closeAll(); 181 m_connector.getRpc().onDelete(); 182 183 } 184 185 /** 186 * UI handler for the 'down' button.<p> 187 * 188 * @param event the click event 189 */ 190 @UiHandler("m_downButton") 191 void clickDown(ClickEvent event) { 192 193 //HANDLER.closeAll(); 194 m_connector.getRpc().onDown(); 195 } 196 197 /** 198 * Handler for the edit button. 199 * 200 * @param event the event 201 */ 202 @UiHandler("m_editButton") 203 void clickEdit(ClickEvent event) { 204 205 m_connector.getRpc().onEdit(); 206 } 207 208 /** 209 * UI handler for the 'up' button.<p> 210 * 211 * @param event the click event 212 */ 213 @UiHandler("m_upButton") 214 void clickUp(ClickEvent event) { 215 216 //HANDLER.closeAll(); 217 m_connector.getRpc().onUp(); 218 } 219 220}