Of course this is purely speculative, but it seems to me that the CalendarViewer creates a DefaultDateSelectionModel in its constructor. It seems that the following things happen to this default selection model:
- This default selection model gets a DateSelectionListener from the CalendarViewer.
- This default selection model is given to all DateChooserPanels in createDateChooserPanel
It seems that when changing the date selection model using CalendarViewer#setSelectionModel, that these two steps are not done for the new model.
Also there is no way to give a selection model to the contructor (this is possible for a DateModel though).
Now my question:
If I have implemented my own DateSelectionModel, how can I then make the CalendarViewer use it?
Currently I can only think of extending the CalendarViewer and overwriting this:
- Code: Select all
@Override
public void setSelectionModel(final DateSelectionModel dateSelectionModel)
{
super.setSelectionModel(dateSelectionModel);
// we need our superclass to respond to changes in the selection model
dateSelectionModel.addDateSelectionListener(new DateSelectionListener()
{
@Override
public void valueChanged(DateSelectionEvent dateselectionevent)
{
try
{
// private method a() seems to process the update
final Method respondToDateSelectionEventMethod = super.getClass() //
.getDeclaredMethod("a", //
new Class[]
{ DateSelectionModel.class });
respondToDateSelectionEventMethod.setAccessible(true);
respondToDateSelectionEventMethod.invoke(EODCalendarViewer.this, //
new Object[]
{ dateSelectionModel });
} catch (NoSuchMethodException e)
{
// method not public so we can expect such exception when switching to newer version
// of Jide
} catch (IllegalAccessException e)
{
// method not public API so what can we do?..
} catch (InvocationTargetException e)
{
// exceptions in Jide code we can only ignore
} catch (IllegalArgumentException e)
{
// should not happen in this case
}
}
});
// all date chooser panels got the old selection model when created
for (DateChooserPanel dateChooserPanel : getDateChooserPanels())
{
dateChooserPanel.setSelectionModel(dateSelectionModel);
}
}
Many thanks for reading. I hope you can help me through this.
Cheers,
Paul