diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/editor/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/editor/.ratings index 7b672cb407f325d3e708dae32125084d5b8d68e2..c25fd1ce6f8ab3d3da2ec20465c9e302f84ad675 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/editor/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/editor/.ratings @@ -1,5 +1,5 @@ ActionBarContributor.java 18d9db3744c5381cca8b6823b5f7bc18183a1cfa GREEN -ExtendableMultiPageEditor.java f8eb6fdc347098fb03e776f23fab61109aa55d6e GREEN +ExtendableMultiPageEditor.java e06a7746f2bdcd2dfa279ae87e0578e0ee5046b2 YELLOW IActionContributingEditor.java 4aa7496d67822de919a8cf0af0ddaafc61bf2919 GREEN ModelElementEditorInput.java e269eff5d992d375a646e54d048f1f0efc6144dd GREEN TutorialStepUIEditor.java 9eadc96c302b5131ff4cc3715777718fa06ec7e8 GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java index f8eb6fdc347098fb03e776f23fab61109aa55d6e..e06a7746f2bdcd2dfa279ae87e0578e0ee5046b2 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java @@ -18,6 +18,7 @@ package org.fortiss.tooling.kernel.ui.internal.editor; import static java.util.Collections.sort; import static org.conqat.ide.commons.ui.logging.LoggingUtils.error; +import java.lang.reflect.Constructor; import java.util.Collection; import java.util.Comparator; import java.util.EventObject; @@ -196,7 +197,8 @@ public class ExtendableMultiPageEditor extends MultiPageEditorPart Class<? extends IEditorPart> editorClass = editorBinding.getEditorClass(editedObject); if(editorClass != null) { - IEditorPart editorPart = editorClass.newInstance(); + Class<? extends EObject> inputType = editedObject.getClass(); + IEditorPart editorPart = constructEditorPart(editorClass, inputType); addPage(editorPart, getEditorInput()); setPageText(pageIndex++, editorBinding.getLabel(editedObject)); } @@ -206,6 +208,23 @@ public class ExtendableMultiPageEditor extends MultiPageEditorPart } } + /** + * Constructs an {@link IEditorPart} instance of the given {@code editorClass}. + * {@link IEditorPart}s that take the input model element type as a parameter are preferred over + * no-arg constructors. + */ + protected IEditorPart constructEditorPart(Class<? extends IEditorPart> editorClass, + Class<? extends EObject> inputType) throws Exception { + try { + Constructor<? extends IEditorPart> ctor = editorClass.getConstructor(Class.class); + return ctor.newInstance(inputType); + } catch(NoSuchMethodException | SecurityException e) { + // Fallback for no-arg constructors. + Constructor<? extends IEditorPart> ctor = editorClass.getConstructor(); + return ctor.newInstance(); + } + } + /** {@inheritDoc} */ @Override public void doSave(IProgressMonitor monitor) {