Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » DateChooserComboObservableValue & databinding
DateChooserComboObservableValue & databinding [message #591241] Mon, 21 July 2008 20:59
Pascal Leclercq is currently offline Pascal LeclercqFriend
Messages: 7
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.
--------------070800050507070305050303
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

for my needs I wrote the "IObservableValue" for the DateChooserCombo widget.

It seems to work and I want to share it with the community.


Please send me your feedbacks

--------------070800050507070305050303
Content-Type: text/plain;
name="DateChooserComboObservableValue.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="DateChooserComboObservableValue.java"

package com.adeo.rcp.technique.observables;

import java.util.Date;

import org.eclipse.core.databinding.observable.Diffs;
import org.eclipse.core.databinding.observable.value.AbstractObserv ableValue;
import org.eclipse.core.databinding.observable.value.IObservableVal ue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.nebula.widgets.datechooser.DateChooserCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

/**
* @author Pascal Leclercq
*
*/
public class DateChooserComboObservableValue extends AbstractObservableValue implements IObservableValue {

/**
* The Control being observed here.
*/
protected final DateChooserCombo dateChooserCombo;

/**
* Flag to prevent infinite recursion in {@link #doSetValue(Object)}.
*/
protected boolean updating = false;

/**
* The "old" value before a selection event is fired.
*/

protected Date oldValue;

/**
* SWT event that on firing this observable will fire change events to its
* listeners.
*/
private final int updateEventType;

/**
* Valid types for the {@link #updateEventType}.
*/
private static final int[] validUpdateEventTypes = new int[] { SWT.Modify, SWT.FocusOut, SWT.None };

/**
* Observe the selection property of the provided DateChooserCombo control.
*
* @param dateChooserCombo
* the control to observe
*/
public DateChooserComboObservableValue(DateChooserCombo dateChooserCombo, int updateEventType) {
super(SWTObservables.getRealm(dateChooserCombo.getDisplay()) );

boolean eventValid = false;
for (int i = 0; !eventValid && i < validUpdateEventTypes.length; i++) {
eventValid = (updateEventType == validUpdateEventTypes[i]);
}
if (!eventValid) {
throw new IllegalArgumentException("UpdateEventType [" + updateEventType + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$
}
this.dateChooserCombo = dateChooserCombo;
oldValue = dateChooserCombo.getValue();
this.updateEventType = updateEventType;
if (updateEventType != SWT.None) {
dateChooserCombo.addListener(updateEventType, updateListener);
}

dateChooserCombo.addDisposeListener(disposeListener);

}

private DisposeListener disposeListener = new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
DateChooserComboObservableValue.this.dispose();
}
};

public void dispose() {
if (!dateChooserCombo.isDisposed()) {
if (updateEventType != SWT.None) {
dateChooserCombo.removeListener(updateEventType, updateListener);
}

}
super.dispose();
}


public Object getValueType() {
return Date.class;
}



protected Object doGetValue() {
return dateChooserCombo.getValue();
}

private Listener updateListener = new Listener() {
public void handleEvent(Event event) {
if (!updating) {
Date newValue = dateChooserCombo.getValue();

if (!newValue.equals(oldValue)) {
fireValueChange(Diffs.createValueDiff(oldValue, newValue));
oldValue = newValue;
}
}
}
};

protected void doSetValue(Object value) {

Date newValue;

try {
updating = true;
newValue = (Date) value;
dateChooserCombo.setValue(newValue);

if (!newValue.equals(oldValue)) {
fireValueChange(Diffs.createValueDiff(oldValue, newValue));
oldValue = newValue;
}
} finally {
updating = false;
}
}
}

--------------070800050507070305050303--
Previous Topic:java.lang.IllegalArgumentException: Index out of bounds
Next Topic:Grid - GridViewer - Memory Leaks
Goto Forum:
  


Current Time: Sun Dec 21 01:12:00 GMT 2014

Powered by FUDForum. Page generated in 0.01539 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software