Change Request #3877

Updated by Tiziano Munaro 11 months ago

Checks of the type
<pre><code class="java">
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:
<pre><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:
<pre><code class="java">
/** {@inheritDoc} */
protected String getName() {
return KernelUIUtils.getName(getModel());