Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Binding Long-Values in FormattedText (DateTimeFormatter)
Binding Long-Values in FormattedText (DateTimeFormatter) [message #769613] Thu, 22 December 2011 12:14 Go to next message
Marcel  is currently offline Marcel
Messages: 1
Registered: December 2011
Junior Member
Hi @ all,

I need your help in binding a FormattedText.
From the database I get Long values. These values must be brought in the format "HH: mm".

Here is a little bit code:

The FormattedText
        FormattedText worktimeText = new FormattedText(client);
        worktimeText.setFormatter(new DateTimeFormatter("HH:mm"));
        gd = new GridData();
        gd.horizontalSpan = 2;
        worktimeText.getControl().setLayoutData(gd);
        GridDataFactory.swtDefaults().hint(30, SWT.DEFAULT).applyTo(worktimeText.getControl());
        bindWorktimeText(worktimeText.getControl(), editor);


The Binding
    private void bindWorktimeText(Text worktimeText, StandbyTypeEditor editor) {
        IObservableValue worktimeWidget = WidgetProperties.text(SWT.Modify).observe(worktimeText);
        IObservableValue worktimeModel = PojoProperties
            .value(StandbyTypeVO.WORK_TIME_FIELD).observe(editor.getModel());
        UpdateValueStrategy worktimeToTarget = new UpdateValueStrategy();
        worktimeToTarget.setConverter(new IConverter() {
            
            @Override
            public Object getToType() {
                return Date.class;
            }
            
            @Override
            public Object getFromType() {
                return Long.class;
            }
            
            @Override
            public Object convert(Object fromObject) {
                  Date date = new Date((Long) fromObject);
                  return date;
            }
        });
        editor.getBindingContext().bindValue(worktimeWidget, worktimeModel, null, worktimeToTarget);


Without the ValueStrategy-Converter the text is blank but i get an exception when i try to convert it.

org.eclipse.core.databinding.BindingException: converter does not convert to type class java.lang.String Expected: class java.sql.Date, actual: class java.lang.String


can someone help me?

Greetings

[Updated on: Thu, 22 December 2011 13:28]

Report message to a moderator

Re: Binding Long-Values in FormattedText (DateTimeFormatter) [message #780444 is a reply to message #769613] Tue, 17 January 2012 22:52 Go to previous messageGo to next message
Wim Jongman is currently offline Wim Jongman
Messages: 280
Registered: July 2009
Senior Member

Hi Marcel,

what do you expect is wrong? Do you think the widget is not playing along with the databinding framework?

Please file a bug if this is the case.

Best regards,

Wim
Re: Binding Long-Values in FormattedText (DateTimeFormatter) [message #809522 is a reply to message #780444] Wed, 29 February 2012 00:41 Go to previous message
Wim Jongman is currently offline Wim Jongman
Messages: 280
Registered: July 2009
Senior Member

On second view:

bindWorktimeText(worktimeText.getControl(), editor);


Binds to a String. Your converter expects a long.
Previous Topic:TableCombo Fix for Windows 7
Next Topic:How traverse on composite Nebula widget DateChooserCombo
Goto Forum:
  


Current Time: Sat Oct 25 11:27:42 GMT 2014

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

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