Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » DateChooser component databinding
DateChooser component databinding [message #548086] Tue, 20 July 2010 11:35 Go to next message
Istvan Benedek is currently offline Istvan Benedek
Messages: 14
Registered: May 2010
Junior Member
Hi folks,

we would like to use a component which is able to bind to a java.util.Date property, has somebody a solutionion for this issue?

We tried to use the nebula's DateChooserCombo for this purpose, without success. Tell the truth, the first part of the binding works fine. So the value goes from the model object to the control, unfortunately we don't get the modified value from the control.. I guess we should use something similar solution what used at comboviewer.singleSelection...

Any Idea? Fast answer is appreciated.

Istvan
Re: DateChooser component databinding [message #548256 is a reply to message #548086] Wed, 21 July 2010 05:20 Go to previous messageGo to next message
Istvan Benedek is currently offline Istvan Benedek
Messages: 14
Registered: May 2010
Junior Member
One of my colleague made a workaround to solve this issue.

He created a wrapper class which is inherited from Viewer and contains a CalendarCombo (nebula widget).

<MyWidget:BindableCalendarCombo
    x:Style="BORDER | COMPACT | DROP_DOWN | DATE_SHORT" name="dod"
    input="{Binding Path= dod}">
    <MyWidget:BindableCalendarCombo.singleSelection>
     <Binding path="dod"></Binding>
    </MyWidget:BindableCalendarCombo.singleSelection>
   </MyWidget:BindableCalendarCombo>


public class BindableCalendarCombo extends Viewer implements ICalendarListener{

 private CalendarCombo calendarCombo;
    public BindableCalendarCombo(Composite parent) {
  this(parent,BORDER | DROP_DOWN  );
  
 }
 public BindableCalendarCombo(Composite parent, int style) {
  this.calendarCombo=new CalendarCombo(parent, style);
  this.calendarCombo.addCalendarListener(this);
  this.calendarCombo.setDate(new Date());
 }

 @Override
 public Control getControl() {
  return this.calendarCombo.getCombo();
 }

 @Override
 public Object getInput() {
  return calendarCombo.getDate().getTime();
 }

 @Override
 public ISelection getSelection() {
  if(this.calendarCombo!=null){
  Date date=calendarCombo.getDate().getTime();
  if(date!=null){
  StructuredSelection selection=new StructuredSelection(date);
  if(selection!=null)
  return selection;
  }
  }
  
    return StructuredSelection.EMPTY;
  
  
 }

 @Override
 public void refresh() {
  
 }

 @Override
 public void setInput(Object input) {
  this.calendarCombo.setDate((Date) input);
  
 }

 @Override
 public void setSelection(ISelection selection, boolean reveal) {
  if(selection instanceof Date && selection!=null){
   this.updateSelection(selection);
  }
  
 }
 protected void updateSelection(ISelection selection) {
  SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
  this.fireSelectionChanged(event);
 }
 @Override
 public void dateChanged(Calendar date) {
  if(date!=null)
  this.updateSelection(new StructuredSelection(date.getTime()));
  
 }
 @Override
 public void dateRangeChanged(Calendar start, Calendar end) {
  // TODO Auto-generated method stub
  
 }
 @Override
 public void popupClosed() {
 
  
 }
 public void setDate(Date date){
  if(date !=null )
  this.calendarCombo.setDate(date); 
 }
 
 

}


If you have any other solution for this issue, just let me know.

Thx in advance.

Istvan
Re: DateChooser component databinding [message #548424 is a reply to message #548256] Wed, 21 July 2010 14:30 Go to previous message
Werner Keil is currently offline Werner Keil
Messages: 1083
Registered: July 2009
Senior Member
I know, the Nebula one works, but keep in mind, Eclipse has at least a
second set of Date/Time classes superior to java.util.Date & Co.

ICU4J with full Unicode Support and many additional calendars.

Same is created for the JDK by Joda founder Stephen Colebourne with JSR-310.
It may come a bit later to Java than E4-embraced JSR-330, but then that only
has 3 or 4 annotations, while Date/Time is MUCH more complex ;-)

Still worth to look at both those Date APIs if you're serious about working
with date and time.

Werner
Re: DateChooser component databinding [message #578988 is a reply to message #548086] Wed, 21 July 2010 05:20 Go to previous message
Istvan Benedek is currently offline Istvan Benedek
Messages: 14
Registered: May 2010
Junior Member
One of my colleague made a workaround to solve this issue.

He created a wrapper class which is inherited from Viewer and contains a CalendarCombo (nebula widget).

<MyWidget:BindableCalendarCombo
   x:Style="BORDER | COMPACT | DROP_DOWN | DATE_SHORT" name="dod"
   input="{Binding Path= dod}">
   <MyWidget:BindableCalendarCombo.singleSelection>
    <Binding path="dod"></Binding>
   </MyWidget:BindableCalendarCombo.singleSelection>
  </MyWidget:BindableCalendarCombo>

public class BindableCalendarCombo extends Viewer implements ICalendarListener{

private CalendarCombo calendarCombo;
   public BindableCalendarCombo(Composite parent) {
 this(parent,BORDER | DROP_DOWN  );
 
}
public BindableCalendarCombo(Composite parent, int style) {
 this.calendarCombo=new CalendarCombo(parent, style);
 this.calendarCombo.addCalendarListener(this);
 this.calendarCombo.setDate(new Date());
}

@Override
public Control getControl() {
 return this.calendarCombo.getCombo();
}

@Override
public Object getInput() {
 return calendarCombo.getDate().getTime();
}

@Override
public ISelection getSelection() {
 if(this.calendarCombo!=null){
 Date date=calendarCombo.getDate().getTime();
 if(date!=null){
 StructuredSelection selection=new StructuredSelection(date);
 if(selection!=null)
 return selection;
 }
 }
 
   return StructuredSelection.EMPTY;
 
 
}

@Override
public void refresh() {
 
}

@Override
public void setInput(Object input) {
 this.calendarCombo.setDate((Date) input);
 
}

@Override
public void setSelection(ISelection selection, boolean reveal) {
 if(selection instanceof Date && selection!=null){
  this.updateSelection(selection);
 }
 
}
protected void updateSelection(ISelection selection) {
 SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
 this.fireSelectionChanged(event);
}
@Override
public void dateChanged(Calendar date) {
 if(date!=null)
 this.updateSelection(new StructuredSelection(date.getTime()));
 
}
@Override
public void dateRangeChanged(Calendar start, Calendar end) {
 // TODO Auto-generated method stub
 
}
@Override
public void popupClosed() {

 
}
public void setDate(Date date){
 if(date !=null )
 this.calendarCombo.setDate(date);
}



}

If you have any other solution for this issue, just let me know.

Thx in advance.

Istvan
Re: DateChooser component databinding [message #579047 is a reply to message #548256] Wed, 21 July 2010 14:30 Go to previous message
Werner Keil is currently offline Werner Keil
Messages: 1083
Registered: July 2009
Senior Member
I know, the Nebula one works, but keep in mind, Eclipse has at least a
second set of Date/Time classes superior to java.util.Date & Co.

ICU4J with full Unicode Support and many additional calendars.

Same is created for the JDK by Joda founder Stephen Colebourne with JSR-310.
It may come a bit later to Java than E4-embraced JSR-330, but then that only
has 3 or 4 annotations, while Date/Time is MUCH more complex ;-)

Still worth to look at both those Date APIs if you're serious about working
with date and time.

Werner
Previous Topic:Close or hide a part on startup
Next Topic:xwt code refactor
Goto Forum:
  


Current Time: Tue Jul 29 08:53:52 EDT 2014

Powered by FUDForum. Page generated in 0.04279 seconds