From b412db3b22fbd78af7c7d747c4f2a15363b35b6d Mon Sep 17 00:00:00 2001 From: Phillipus Date: Thu, 21 Nov 2024 08:52:32 +0000 Subject: [PATCH] Add new methods to UIProviders to support default value and value for features - This will be needed for line styles where the default value will be different for the Grouping figure - Add getDefaultFeatureValue(String featureName) to return a default value for a feature - Add getFeatureValue(String featureName) to return a value for a feature which might be the feature value or the default feature value - Move some methods up into IObjectUIProvider as default implementations - Remove deprecated methods --- .../AbstractGraphicalObjectUIProvider.java | 8 ---- .../ui/factory/AbstractObjectUIProvider.java | 34 --------------- .../factory/IGraphicalObjectUIProvider.java | 6 --- .../editor/ui/factory/IObjectUIProvider.java | 42 +++++++++++++------ .../AbstractObjectUIProviderTests.java | 10 +++++ 5 files changed, 40 insertions(+), 60 deletions(-) diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/AbstractGraphicalObjectUIProvider.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/AbstractGraphicalObjectUIProvider.java index 046222988..b7ebe3556 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/AbstractGraphicalObjectUIProvider.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/AbstractGraphicalObjectUIProvider.java @@ -40,14 +40,6 @@ public Dimension getDefaultSize() { return new Dimension(-1, -1); } - /** - * @deprecated Use {@link #getDefaultSize()} - */ - @Override - public Dimension getUserDefaultSize() { - return getDefaultSize(); - } - @Override public int getDefaultTextAlignment() { return ITextAlignment.TEXT_ALIGNMENT_CENTER; diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/AbstractObjectUIProvider.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/AbstractObjectUIProvider.java index 76d770943..2388d009d 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/AbstractObjectUIProvider.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/AbstractObjectUIProvider.java @@ -5,11 +5,7 @@ */ package com.archimatetool.editor.ui.factory; -import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; -import org.eclipse.gef.EditPart; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.graphics.Image; @@ -36,34 +32,4 @@ void setInstance(EObject instance) { this.instance = instance; } - @Override - public String getDefaultName() { - return ""; //$NON-NLS-1$ - } - - @Override - public EditPart createEditPart() { - return null; - } - - @Override - public Image getImage() { - return null; - } - - @Override - public ImageDescriptor getImageDescriptor() { - return null; - } - - @Override - @Deprecated - public boolean shouldExposeFeature(EAttribute feature) { - return shouldExposeFeature(feature.getName()); - } - - @Override - public boolean shouldExposeFeature(String featureName) { - return true; - } } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/IGraphicalObjectUIProvider.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/IGraphicalObjectUIProvider.java index 9b6f934a5..528565f67 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/IGraphicalObjectUIProvider.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/IGraphicalObjectUIProvider.java @@ -38,12 +38,6 @@ static Dimension defaultSize() { */ Dimension getDefaultSize(); - /** - * @deprecated Use {@link #getDefaultSize()} - * @return The default size as set by the user for this object - */ - Dimension getUserDefaultSize(); - /** * @return The default text alignment */ diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/IObjectUIProvider.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/IObjectUIProvider.java index db665d178..ae2ae9a4e 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/IObjectUIProvider.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/IObjectUIProvider.java @@ -5,7 +5,6 @@ */ package com.archimatetool.editor.ui.factory; -import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClass; import org.eclipse.gef.EditPart; import org.eclipse.jface.resource.ImageDescriptor; @@ -29,33 +28,52 @@ public interface IObjectUIProvider { /** * @return A new GEF EditPart for this type of class */ - EditPart createEditPart(); + default EditPart createEditPart() { + return null; + } /** * @return The default name for this type of object */ - String getDefaultName(); + default String getDefaultName() { + return ""; //$NON-NLS-1$ + } /** * @return The iconic image to use for this object */ - Image getImage(); + default Image getImage() { + return null; + } /** * @return The iconic image descriptor to use for this object */ - ImageDescriptor getImageDescriptor(); + default ImageDescriptor getImageDescriptor() { + return null; + } /** - * @param feature The feature in question + * @param featureName The feature in question * @return True if this object should expose a feature in the UI - * @deprecated Use shouldExposeFeature(String featureName) */ - boolean shouldExposeFeature(EAttribute feature); - + default boolean shouldExposeFeature(String featureName) { + return true; + } + /** - * @param feature The feature in question - * @return True if this object should expose a feature in the UI + * @param featureName The feature in question + * @return a default value for a given feature. Default is null + */ + default Object getDefaultFeatureValue(String featureName) { + return null; + } + + /** + * @param featureName The feature in question + * @return a value for a given feature. Default is null */ - boolean shouldExposeFeature(String featureName); + default Object getFeatureValue(String featureName) { + return null; + } } diff --git a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/factory/AbstractObjectUIProviderTests.java b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/factory/AbstractObjectUIProviderTests.java index c07914baf..b686c8854 100644 --- a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/factory/AbstractObjectUIProviderTests.java +++ b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/ui/factory/AbstractObjectUIProviderTests.java @@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.emf.ecore.EClass; @@ -82,7 +83,16 @@ public void testShouldExposeFeature(IObjectUIProvider provider) { assertTrue(provider.shouldExposeFeature((String)null)); } + @ParamsTest + public void testGetDefaultFeatureValue(IObjectUIProvider provider) { + assertNull(provider.getDefaultFeatureValue((String)null)); + } + @ParamsTest + public void testGetFeatureValue(IObjectUIProvider provider) { + assertNull(provider.getFeatureValue((String)null)); + } + protected EObject createInstanceForExpectedClass(EClass expectedClass) { return expectedClass.getEPackage().getEFactoryInstance().create(expectedClass); }