[UI] Move type checks and casts from LWFXEF visuals to a common base class within SystemFocus
Checks of the type
object model = mvcb.getmodel();
if(!(model instanceof ilayoutedmodelelement)) {
throw new illegalargumentexception(
"expected model of type ilayoutedmodelelement, but was " +
model.getclass().getsimplename() + ".");
}
shall be moved to a common base class within the systemfocus kernel.
mvcbundlepartbase
would be the most common class to place such a
check. this way the class itself does not have to be parameterized while
still avoiding code duplication.
the same base class could be accomodate a generic method for returning
the casted model element:
<code class="java">
protected <t> t getmodelelement(class<t> elementtype)
of course calling this method with a wrong parameter leads to class-cast
exceptions, but the expected type is already checked in the constructor.
also, a misuse is limited to derived classes, where a contributor should
know the context.
moreover, the `getname` method of the `contentvisualbase` is currently
returning an empty string, leaving it to its children to implement a
component-specific override. this method is usually identical in all
visuals, except for the class-cast. by using the `getname` method of the
`kerneluiutils` directly in the `componentvisualbase`, this code
duplication could be avoided:
<code class="java
/** {@inheritDoc} */
@Override
protected String getName() {
return KernelUIUtils.getName(getModel());
}
(from redmine: issue id 3877, created on 2019-11-29)