Skip to content
Snippets Groups Projects
Commit 0a80ea3d authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Editors: Allow editors consuming the model type on construction

parent 31c26dc6
No related branches found
No related tags found
1 merge request!81JFX: Base classes
ActionBarContributor.java 18d9db3744c5381cca8b6823b5f7bc18183a1cfa GREEN ActionBarContributor.java 18d9db3744c5381cca8b6823b5f7bc18183a1cfa GREEN
ExtendableMultiPageEditor.java f8eb6fdc347098fb03e776f23fab61109aa55d6e GREEN ExtendableMultiPageEditor.java e06a7746f2bdcd2dfa279ae87e0578e0ee5046b2 YELLOW
IActionContributingEditor.java 4aa7496d67822de919a8cf0af0ddaafc61bf2919 GREEN IActionContributingEditor.java 4aa7496d67822de919a8cf0af0ddaafc61bf2919 GREEN
ModelElementEditorInput.java e269eff5d992d375a646e54d048f1f0efc6144dd GREEN ModelElementEditorInput.java e269eff5d992d375a646e54d048f1f0efc6144dd GREEN
TutorialStepUIEditor.java 9eadc96c302b5131ff4cc3715777718fa06ec7e8 GREEN TutorialStepUIEditor.java 9eadc96c302b5131ff4cc3715777718fa06ec7e8 GREEN
......
...@@ -18,6 +18,7 @@ package org.fortiss.tooling.kernel.ui.internal.editor; ...@@ -18,6 +18,7 @@ package org.fortiss.tooling.kernel.ui.internal.editor;
import static java.util.Collections.sort; import static java.util.Collections.sort;
import static org.conqat.ide.commons.ui.logging.LoggingUtils.error; import static org.conqat.ide.commons.ui.logging.LoggingUtils.error;
import java.lang.reflect.Constructor;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.EventObject; import java.util.EventObject;
...@@ -196,7 +197,8 @@ public class ExtendableMultiPageEditor extends MultiPageEditorPart ...@@ -196,7 +197,8 @@ public class ExtendableMultiPageEditor extends MultiPageEditorPart
Class<? extends IEditorPart> editorClass = Class<? extends IEditorPart> editorClass =
editorBinding.getEditorClass(editedObject); editorBinding.getEditorClass(editedObject);
if(editorClass != null) { if(editorClass != null) {
IEditorPart editorPart = editorClass.newInstance(); Class<? extends EObject> inputType = editedObject.getClass();
IEditorPart editorPart = constructEditorPart(editorClass, inputType);
addPage(editorPart, getEditorInput()); addPage(editorPart, getEditorInput());
setPageText(pageIndex++, editorBinding.getLabel(editedObject)); setPageText(pageIndex++, editorBinding.getLabel(editedObject));
} }
...@@ -206,6 +208,23 @@ public class ExtendableMultiPageEditor extends MultiPageEditorPart ...@@ -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} */ /** {@inheritDoc} */
@Override @Override
public void doSave(IProgressMonitor monitor) { public void doSave(IProgressMonitor monitor) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment