com.squadd.chat.ChatListener.java Source code

Java tutorial

Introduction

Here is the source code for com.squadd.chat.ChatListener.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.squadd.chat;

import com.squadd.javaBeans.ChatMessage;
import com.vaadin.data.Property;
import com.vaadin.ui.Button;
import com.vaadin.ui.TextField;
import java.util.Date;

/**
 *
 * @author Glebao
 */
public class ChatListener implements Button.ClickListener, Property.ValueChangeListener {

    private DialogController control;
    private TextField chatInput;

    public ChatListener(DialogController control, TextField chatInput) {
        this.control = control;
        this.chatInput = chatInput;
    }

    @Override
    public void valueChange(final Property.ValueChangeEvent event) {
        control.updateChatLog();
    }

    @Override
    public void buttonClick(final Button.ClickEvent event) {
        ChatMessage mess = new ChatMessage(control.getUserFromId(), control.getUserToId(), new Date(), "adad");
        control.addNewChatLine(mess);
        chatInput.clear();
        chatInput.focus();
    }
}