gt: 		message.setMessageBody( messageBodyTextArea.getText() );
context: /**
   * X-Cure-Chat
   * Copyright (C) 2013  Dr. Ivan S. Zapreev
   * www: https://nl.linkedin.com/in/zapreevis
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.#
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   *
   * The user interface package.
   * (C) Ivan S. Zapreev, 2009
   */
  package com.xcurechat.client.dialogs.messages;
  
  import com.google.gwt.event.dom.client.ClickHandler;
  import com.google.gwt.event.dom.client.ClickEvent;
  import com.google.gwt.event.logical.shared.CloseEvent;
  import com.google.gwt.event.logical.shared.CloseHandler;
  
  import com.google.gwt.user.client.ui.DialogBox;
  import com.google.gwt.user.client.ui.FlexTable;
  import com.google.gwt.user.client.ui.Label;
  import com.google.gwt.user.client.ui.PopupPanel;
  import com.google.gwt.user.client.ui.TextArea;
  import com.google.gwt.user.client.ui.TextBox;
  import com.google.gwt.user.client.ui.HorizontalPanel;
  import com.google.gwt.user.client.ui.HTML;
  
  import com.xcurechat.client.SiteManager;
  import com.xcurechat.client.data.UserData;
  import com.xcurechat.client.data.PrivateMessageData;
  
  import com.xcurechat.client.rpc.RPCAccessManager;
  import com.xcurechat.client.rpc.MessageManagerAsync;
  import com.xcurechat.client.rpc.ServerSideAccessManager;
  
  import com.xcurechat.client.rpc.exceptions.SiteException;
  
  
  import com.xcurechat.client.dialogs.ActionGridDialog;
  import com.xcurechat.client.dialogs.PagedActionGridDialog;
  import com.xcurechat.client.dialogs.profile.ViewUserProfileDialogUI;
  import com.xcurechat.client.dialogs.system.messages.ErrorMessagesDialogUI;
  
  import com.xcurechat.client.utils.CommStatusAsyncCallback;
  import com.xcurechat.client.utils.InterfaceUtils;
  import com.xcurechat.client.utils.SplitLoad;
  import com.xcurechat.client.utils.StringUtils;
  import com.xcurechat.client.utils.widgets.ActionLinkPanel;
  import com.xcurechat.client.utils.widgets.SmileSelectionDialogUI;
  import com.xcurechat.client.utils.widgets.CommonResourcesContainer;
  import com.xcurechat.client.utils.widgets.TextBaseTranslitAndProgressBar;
  
  /**
   * @author zapreevis
   * This dialog is used for sending personal (private) messages
   */
  public class SendMessageDialogUI extends ActionGridDialog implements SmileSelectionDialogUI.SmileySelectionTarget {
  	
  	//The maximum length of the message body
  	private static final int MAXIMUM_MESSAGE_BODY_VISIBLE_LINES_LENGTH = 10;
  	
  	//The coefficient for the length of the message body that we will keep in case the message body gets too long 
  	private static final double MESSAGE_BODY_LENGTH_TRIMMING_COEFFICIENT = ( 2.0 / 3.0);
  	
  	//The action smiley link
  	private ActionLinkPanel actionSmileysLink = new ActionLinkPanel( ServerSideAccessManager.getChatMessageSmilesLinkImageURL( ),
  																	 titlesI18N.smilesLinkToolTip(),
  																	 ServerSideAccessManager.getChatMessageSmilesLinkImageURL( ), "",
  																	 titlesI18N.smilesLinkTitle(), new ClickHandler(){
  																		@Override
  																		public void onClick(ClickEvent event) {
  																			SmileSelectionDialogUI.open();
  																		}},
  																	 true, true);
  	
  	//The name of the person we send the message to
  	private final Label messageRecepientLabel = new Label();
  	//The title of the message
  	private final TextBox messageSubjectTextBox = new TextBox();
  	//The object that wraps around the text box of the off-line message subject
  	private final TextBaseTranslitAndProgressBar messageTextSubjWrapper = new TextBaseTranslitAndProgressBar( messageSubjectTextBox, PrivateMessageData.MAXIMUM_MESSAGE_SUBJECT_LENGTH);
  	
  	//The body of the message
  	private final TextArea messageBodyTextArea = new TextArea();
  	//The object that wraps around the text box of the off-line message body
  	private final TextBaseTranslitAndProgressBar messageTextBodyWrapper = new TextBaseTranslitAndProgressBar( messageBodyTextArea, PrivateMessageData.MAXIMUM_MESSAGE_BODY_LENGTH );
  	//True if the user selection for the recipient is active
  	private boolean isRecepientSelectEnabled = true;
  	
  	private void setEnabledElements(final boolean enabledLeftActionButton,
  									final boolean enabledRightActionButton,
  									final boolean enabledOthers){
  		setLeftEnabled( enabledLeftActionButton );
  		setRightEnabled( enabledRightActionButton );
  		messageSubjectTextBox.setEnabled( enabledOthers );
  		messageBodyTextArea.setEnabled( enabledOthers );
  		isRecepientSelectEnabled = enabledOthers;
  	}
  
  	//The ID of the user we send the message to
  	private int toUserID;
  	//The login name of the user we send the message to 
  	private String toUserLoginName;
  	//The data of the message we reply to, if any
  	private PrivateMessageData replyMsgData = null;
  	
  	//Contains the counter for the number of opened send message dialogs.
  	//This is used to prevent sending private messages to users through
  	//the chain of send msg dialogs
  	private static int openSendMessageDialogCounter = 0;
  	
  	/**
  	 * Allows to detect if a send message dialog is open
  	 * @return true if there is a send message dialog is open,
  	 *              even if it is currently invisible.
  	 */
  	public static boolean isSendMessageDialogOpen() {
  		return openSendMessageDialogCounter > 0;
  	}
  	
  	/**
  	 * The main constructor
  	 * @param parentDialog the parent dialog, i.e. the one we open this dialog from
  	 */
  	public SendMessageDialogUI(final DialogBox parentDialog) {
  		this(parentDialog, UserData.UNKNOWN_UID, null, null);
  	}
  
  	/**
  	 * The constructor that has to be used when we send
  	 * a message to a particular user 
  	 * @param parentDialog the parent dialog, i.e. the one we open this dialog from
  	 * @param toUserID the ID of the user we send the message to
  	 * @param toUserLoginName the login name of the user we send the message to
  	 * @param replyMsgData if not null then this is the message we reply to
  	 */
  	public SendMessageDialogUI( final DialogBox parentDialog, final int toUserID,
  								final String toUserLoginName, final PrivateMessageData replyMsgData) {
  		super( true, false, true, parentDialog );
  		
  		//Store the local value of the message we reply to
  		this.replyMsgData = replyMsgData;
  		
  		//Increment the number of opened send message dialogs
  		openSendMessageDialogCounter++;
  		this.addCloseHandler( new CloseHandler<PopupPanel>(){
  			public void onClose( CloseEvent<PopupPanel> e ) {
  				if( e.getTarget() == thisDialog ) {
  					//The send message is closed, decrement the number of
  					//opened send message dialogs
  					if( openSendMessageDialogCounter > 0 ) {
  						openSendMessageDialogCounter--;
  					}
  				}
  			}
  		} );
  		
  		//Set the message recepient
  		setMessageRecepient(toUserID, toUserLoginName);
  		
  		//Set title and style
  		this.setText(titlesI18N.sendPersonalMessageDialogTitle() );
  		this.setStyleName( CommonResourcesContainer.USER_DIALOG_STYLE_NAME );
  		
  		//Fill dialog with data
  		populateDialog();		
  	}
  	
  	/**
  	 * Sets the message recipient, or resets it to "undefined"
  	 * @param toUserID the ID of the user we send the message to
  	 * @param toUserLoginName the login name of the user we send the message to 
  	 */
  	public void setMessageRecepient(final int toUserID, final String toUserLoginName) {
  		this.toUserID = toUserID;
  		this.toUserLoginName = toUserLoginName;
  		
  		if( this.toUserID != UserData.UNKNOWN_UID && this.toUserLoginName != null ) {
  			messageRecepientLabel.setStyleName( CommonResourcesContainer.DEFINED_MESSAGE_RECEPIENT_LINK );
  			messageRecepientLabel.setText( toUserLoginName );
  		} else {
  			messageRecepientLabel.setStyleName( CommonResourcesContainer.UNDEFINED_MESSAGE_RECEPIENT_LINK );
  			messageRecepientLabel.setText( titlesI18N.undefinedRecepientFieldValue() );
  		}
  	}
  	
  	/**
  	 * @return the left-button caption
  	 */
  	@Override
  	protected String getLeftButtonText(){
  		return titlesI18N.cancelButton();
  	}
  
  	/**
  	 * @return the right-button caption
  	 */
  	@Override
  	protected String getRightButtonText(){
  		return titlesI18N.sendButton();
  	}
  		
  	@Override
  	protected void actionLeftButton() {
  		hide();
  	}
  
  	@Override
  	protected void actionRightButton() {
  		//Disable the controls
  		setEnabledElements( false, false, false );
  		
  		//Send a personal message
  		final PrivateMessageData message = new PrivateMessageData();
  		message.setToUID( toUserID );
  		//We do not need to set the recepient's login name here
  		message.setMessageTitle( messageSubjectTextBox.getText() );
  