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; 029 030import org.opencms.gwt.client.CmsCoreProvider; 031import org.opencms.gwt.client.Messages; 032import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle; 033import org.opencms.gwt.client.util.CmsEmbeddedDialogHandler; 034import org.opencms.gwt.shared.CmsGwtConstants; 035import org.opencms.util.CmsUUID; 036 037import java.util.Collections; 038import java.util.HashMap; 039import java.util.Map; 040 041import com.google.gwt.event.dom.client.ClickEvent; 042import com.google.gwt.event.dom.client.ClickHandler; 043import com.google.gwt.user.client.Command; 044 045/** 046 * The user info toolbar button.<p> 047 */ 048public class CmsUserInfo extends A_CmsToolbarButton<I_CmsToolbarHandler> { 049 050 /** The embedded dialog handler. */ 051 private CmsEmbeddedDialogHandler m_dialogHandler; 052 053 /** 054 * Constructor.<p> 055 */ 056 public CmsUserInfo() { 057 058 super(null, null); 059 addStyleName(I_CmsLayoutBundle.INSTANCE.toolbarCss().userInfo()); 060 getUpFace().setHTML("<img src=\"" + CmsCoreProvider.get().getUserInfo().getUserIcon() + "\" />"); 061 setTitle(Messages.get().key(Messages.GUI_USER_INFO_0)); 062 m_dialogHandler = new CmsEmbeddedDialogHandler(); 063 addClickHandler(new ClickHandler() { 064 065 /** 066 * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) 067 */ 068 @Override 069 public void onClick(ClickEvent event) { 070 071 onToolbarClick(); 072 } 073 }); 074 } 075 076 /** 077 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#isActive() 078 */ 079 @Override 080 public boolean isActive() { 081 082 return false; 083 } 084 085 /** 086 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarActivate() 087 */ 088 @Override 089 public void onToolbarActivate() { 090 091 Map<String, String> params = new HashMap<String, String>(); 092 params.put("left", String.valueOf(getElement().getAbsoluteLeft())); 093 m_dialogHandler.setOnCloseCommand(new Command() { 094 095 public void execute() { 096 097 onClose(); 098 } 099 }); 100 m_dialogHandler.openDialog( 101 "org.opencms.ui.actions.CmsUserInfoDialogAction", 102 CmsGwtConstants.CONTEXT_TYPE_APP_TOOLBAR, 103 Collections.<CmsUUID> emptyList(), 104 params); 105 } 106 107 /** 108 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarClick() 109 */ 110 @Override 111 public void onToolbarClick() { 112 113 boolean active = isActive(); 114 115 setActive(!active); 116 117 } 118 119 /** 120 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarDeactivate() 121 */ 122 @Override 123 public void onToolbarDeactivate() { 124 125 m_dialogHandler.setOnCloseCommand(null); 126 m_dialogHandler.finish(null); 127 } 128 129 /** 130 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#setActive(boolean) 131 */ 132 @Override 133 public void setActive(boolean active) { 134 135 if (active) { 136 if (m_handler != null) { 137 m_handler.deactivateCurrentButton(); 138 m_handler.setActiveButton(this); 139 } 140 onToolbarActivate(); 141 142 } else { 143 onToolbarDeactivate(); 144 145 if (m_handler != null) { 146 m_handler.setActiveButton(null); 147 m_handler.activateSelection(); 148 } 149 } 150 } 151 152 /** 153 * Sets the button handler.<p> 154 * 155 * @param handler the button handler 156 */ 157 public void setHandler(I_CmsToolbarHandler handler) { 158 159 m_handler = handler; 160 } 161 162 /** 163 * Returns the container-page handler.<p> 164 * 165 * @return the container-page handler 166 */ 167 @Override 168 protected I_CmsToolbarHandler getHandler() { 169 170 return m_handler; 171 } 172 173 /** 174 * Executed on window close.<p> 175 */ 176 protected void onClose() { 177 178 onToolbarDeactivate(); 179 if (m_handler != null) { 180 m_handler.setActiveButton(null); 181 m_handler.activateSelection(); 182 } 183 } 184}