|
That's a bit disappointing, considering how much time I lost trying to debug the no-args issue. Having an explicit ITemplateComponent.createTemplateCopy() API would definitely be much cleaner and less error-prone. There could even be a smooth migration path using if(c instanceof ITemplateComponent){((ITemplateComponent) c).createTemplateCopy();...}else{...}
It seems that Canoo still does not make any attempts to make working with custom renderers any easier Alternative the ICellComponent Interface could be changed
public interface ICellComponent extends IProxy { public void copyAttributes(ICellComponent source); public ICellComponent copy(); public boolean areAttributesEqual(ICellComponent component); public int attributesHashCode(); } Migrating existing ICellComponents is easy, just add the following copy method public ICellComponent copy() { ICellComponent newMy = new MyConstructor(); newMy.copyAttributes(this); return newMy; } ICellComponents with non-default constructors can create the new Instance as needed Another correction would be that the factory interface IComboBoxCellRenderer getComboBoxCellRendererComponent() returns a independent object that can be used without the risk of sideeffects.
For a minor release we can throw a exception if there is no accessible default-constructor and one of the methods of the ICellComponent interface or typeString is overwritten.
ULC now throws a connection if
|
|||||||||||||||||||||||||||||||||||||||
a template copy of cell renderer component, which is passed in. The template copy is created
via c.getClass().newInstance() but this does not work if
If the former does not work, then createTemplate()tries to create a copy via
c.getClass().getSuperclass().newInstance() but then, the template copy does not
have the right type anymore.
(Using ... getSuperclass().newInstance() acts as "workaround" if the c has an
anonymous (and thus private) class type.
Currently there is no good point, where ULC could a give a hint to the programmer (such
as throwing an exception) in case this behaviour is undesired.
A possible solution would be to offer a new interface e.g.:
public interface ITemplateComponent {
ICellComponent createTemplateCopy();
}
An extension writer could make the cell component implement this interface and then
CellComponentTemplateStorage.createTemplate(ICellComponent c)
could try c.createTemplateCopy() if c implements ITemplateComponent. Otherwise it would
work as before.
Adding the new interface is considered as adding too much additional complexity for
a workaround and therefore it is rejected.