blob: 4666c22d495b3be8226af23ffd5ce6ab63a1ca07 [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.runtime.web.vaadin.databinding.model.internal;
import java.util.Date;
import org.eclipse.core.databinding.property.IProperty;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
import org.eclipse.core.databinding.property.NativePropertyListener;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
// TODO: Auto-generated Javadoc
/**
* The listener interface for receiving buttonClick events. The class that is
* interested in processing a buttonClick event implements this interface, and
* the object created with that class is registered with a component using the
* component's <code>addButtonClickListener</code> method. When
* the buttonClick event occurs, that object's appropriate
* method is invoked.
*
* @see #buttonClick(ClickEvent)
*/
@SuppressWarnings("serial")
public class ButtonClickListener extends NativePropertyListener implements
Button.ClickListener {
/** The last activation. */
private long lastActivation;
/**
* Instantiates a new button click listener.
*
* @param property
* the property
* @param listener
* the listener
*/
public ButtonClickListener(IProperty property,
ISimplePropertyListener listener) {
super(property, listener);
}
/* (non-Javadoc)
* @see org.eclipse.core.databinding.property.NativePropertyListener#doAddTo(java.lang.Object)
*/
protected void doAddTo(Object source) {
if (source instanceof Button) {
Button notifier = (Button) source;
notifier.addClickListener(this);
}
}
/* (non-Javadoc)
* @see org.eclipse.core.databinding.property.NativePropertyListener#doRemoveFrom(java.lang.Object)
*/
protected void doRemoveFrom(Object source) {
if (source instanceof Button) {
Button notifier = (Button) source;
notifier.removeClickListener(this);
}
}
/* (non-Javadoc)
* @see com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button.ClickEvent)
*/
@Override
public void buttonClick(ClickEvent event) {
// on button click, just send the current time in ms to the receiver
lastActivation = new Date().getTime();
fireChange(lastActivation, null);
}
/**
* Returns the time of the last activation.
*
* @return the last activation
*/
public long getLastActivation() {
return lastActivation;
}
}