Project

General

Profile

Change Request #3877

[UI] Move type checks and casts from LWFXEF visuals to a common base class within SystemFocus

Added by Tiziano Munaro 10 months ago. Updated 5 months ago.

Status:
New
Priority:
Normal
Category:
-
Start date:
11/29/2019
Due date:
% Done:

0%

Estimated time:

Description

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:
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:

/** {@inheritDoc} */
@Override
protected String getName() {
    return KernelUIUtils.getName(getModel());
}

History

#1 Updated by Tiziano Munaro 10 months ago

  • Description updated (diff)

#2 Updated by Tiziano Munaro 10 months ago

  • Description updated (diff)

#3 Updated by Florian Hölzl 9 months ago

LWFXEF does only depend on JavaFX and is located in the kernel.common plugin.
It therefore knows neither about ILayoutedElement (kernel.base) nor KernelUIUtils (kernel.core.ui).
Abstract base classes should therefore go there, but not into MVCBundlePartBase.

#4 Updated by Johannes Eder 5 months ago

  • Target version changed from AF3 2.17 (Feature Freeze) to AF3 2.18 - Feature Freeze

Also available in: Atom PDF