From 454ec49357977a555dc92e225313a496744d8fb1 Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Mon, 28 Nov 2011 15:35:57 +0000 Subject: [PATCH] improved editor bindings and editor base implementation. refs 335 --- .../kernel/ui/extension/IModelEditor.java | 43 +++++++++++++++++++ .../kernel/ui/extension/base/EditorBase.java | 18 +++++++- .../internal/ModelEditorBindingService.java | 39 ++++++++++++++++- .../editor/ExtendableMultiPageEditor.java | 23 +++++++++- .../kernel/ui/internal/views/LibraryView.java | 4 +- .../service/IModelEditorBindingService.java | 18 ++++++-- 6 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/IModelEditor.java diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/IModelEditor.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/IModelEditor.java new file mode 100644 index 000000000..ac8290e00 --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/IModelEditor.java @@ -0,0 +1,43 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.ui.extension; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.ui.IEditorPart; + +/** + * Kernel specific extension of Eclipse {@link IEditorPart}. + * + * @author hoelzl + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Hash: + */ +public interface IModelEditor<T extends EObject> extends IEditorPart { + // FIXME (FH): define + + /** Returns the edited object. */ + T getEditedObject(); + + /** Sets the highlighting of the given model element to the given value. */ + void setHighlight(EObject element, boolean highlighted); + + /** Clears all highlightings from the editor. */ + void clearAllHighlights(); + +} diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java index 2f8ff4953..61f7bed0a 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java @@ -26,6 +26,7 @@ import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.EditorPart; import org.fortiss.tooling.kernel.service.ICommandStackService; +import org.fortiss.tooling.kernel.ui.extension.IModelEditor; import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding; import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler; import org.fortiss.tooling.kernel.ui.internal.editor.IActionContributingEditor; @@ -41,7 +42,7 @@ import org.fortiss.tooling.kernel.ui.internal.editor.ModelElementEditorInput; * @ConQAT.Rating RED Hash: 1F16F778F300E3605E648ABFB4EE1589 */ public abstract class EditorBase<T extends EObject> extends EditorPart - implements IActionContributingEditor { + implements IActionContributingEditor, IModelEditor<T> { /** * The object shown in this editor. This is valid as soon as @@ -55,7 +56,8 @@ public abstract class EditorBase<T extends EObject> extends EditorPart /** Databinding context used for model changes. */ protected final EMFDataBindingContext dbc = new EMFDataBindingContext(); - /** Returns the edited object. */ + /** {@inheritDoc} */ + @Override public T getEditedObject() { return editedObject; } @@ -145,4 +147,16 @@ public abstract class EditorBase<T extends EObject> extends EditorPart public void setFocus() { // nothing to do } + + /** {@inheritDoc} */ + @Override + public void setHighlight(EObject element, boolean highlighted) { + // nothing to do + } + + /** {@inheritDoc} */ + @Override + public void clearAllHighlights() { + // nothing to do + } } diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java index 3a18b33fb..772e569fe 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ModelEditorBindingService.java @@ -38,6 +38,7 @@ import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; import org.fortiss.tooling.kernel.service.ICommandStackService; import org.fortiss.tooling.kernel.service.IPersistencyService; import org.fortiss.tooling.kernel.service.base.EObjectAwareServiceBase; +import org.fortiss.tooling.kernel.ui.extension.IModelEditor; import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding; import org.fortiss.tooling.kernel.ui.internal.editor.ExtendableMultiPageEditor; import org.fortiss.tooling.kernel.ui.internal.editor.ModelElementEditorInput; @@ -51,7 +52,7 @@ import org.fortiss.tooling.kernel.utils.ModelElementUtils; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating RED Hash: 5544DDDB18F4389B85B35A1CAA58FD17 + * @ConQAT.Rating YELLOW Hash: D719F4D54DBF1707B1BE0B6FEA65624A */ public class ModelEditorBindingService extends EObjectAwareServiceBase<IModelEditorBinding<EObject>> implements @@ -229,4 +230,40 @@ public class ModelEditorBindingService extends } } } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override + public <T extends EObject, E extends IModelEditor<T>> E getOpenEditor( + T editedElement, Class<E> editorClass) { + for (IEditorPart part : currentEditors.keySet()) { + if (currentEditors.get(part) == editedElement) { + if (part instanceof ExtendableMultiPageEditor) { + E inner = ((ExtendableMultiPageEditor) part) + .getPageEditor(editorClass); + if (inner != null) { + return inner; + } + } else if (editorClass.isInstance(part)) { + return (E) part; + } + } + } + return null; + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override + public IModelEditor<EObject> getActiveEditor() { + IEditorPart activeEditor = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + if (activeEditor instanceof ExtendableMultiPageEditor) { + return ((ExtendableMultiPageEditor) activeEditor) + .getActiveModelEditor(); + } else if (activeEditor instanceof IModelEditor) { + return (IModelEditor<EObject>) activeEditor; + } + return null; + } } diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java index ee8ff4e16..5708234da 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java @@ -43,6 +43,7 @@ import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; import org.fortiss.tooling.kernel.service.ICommandStackService; import org.fortiss.tooling.kernel.service.IPersistencyService; +import org.fortiss.tooling.kernel.ui.extension.IModelEditor; import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding; import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler; import org.fortiss.tooling.kernel.ui.listener.ExtendableMultiPageEditorPageChangeListener; @@ -126,8 +127,9 @@ public class ExtendableMultiPageEditor extends MultiPageEditorPart implements } /** Returns the active editor. */ - public IEditorPart getActiveEditorPart() { - return getActiveEditor(); + @SuppressWarnings("unchecked") + public IModelEditor<EObject> getActiveModelEditor() { + return (IModelEditor<EObject>) getActiveEditor(); } /** {@inheritDoc} */ @@ -259,4 +261,21 @@ public class ExtendableMultiPageEditor extends MultiPageEditorPart implements public void commandStackChanged(EventObject event) { firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY); } + + /** + * Finds a contributed editor of the given class in the list of editor + * pages. + */ + @SuppressWarnings("unchecked") + public <T extends EObject, E extends IModelEditor<T>> E getPageEditor( + Class<E> editorClass) { + int num = getPageCount(); + for (int i = 0; i < num; i++) { + IEditorPart part = getEditor(i); + if (editorClass.isInstance(part)) { + return (E) part; + } + } + return null; + } } diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/LibraryView.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/LibraryView.java index 2672cc169..e3a4a4047 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/LibraryView.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/LibraryView.java @@ -76,7 +76,7 @@ public class LibraryView extends ViewPart { private final ExtendableMultiPageEditorPageChangeListener bindingEditorPageChangeListener = new ExtendableMultiPageEditorPageChangeListener() { @Override public void pageChanged() { - updateEditorFilters(activeBindingEditor.getActiveEditorPart()); + updateEditorFilters(activeBindingEditor.getActiveModelEditor()); } }; @@ -120,7 +120,7 @@ public class LibraryView extends ViewPart { activeBindingEditor = (ExtendableMultiPageEditor) editor; activeBindingEditor .addBindingEditorListener(bindingEditorPageChangeListener); - updateEditorFilters(activeBindingEditor.getActiveEditorPart()); + updateEditorFilters(activeBindingEditor.getActiveModelEditor()); } else if (editor != null) { updateEditorFilters(editor); } diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/service/IModelEditorBindingService.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/service/IModelEditorBindingService.java index 681e87e6f..6e53554a7 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/service/IModelEditorBindingService.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/service/IModelEditorBindingService.java @@ -20,19 +20,20 @@ package org.fortiss.tooling.kernel.ui.service; import java.util.List; import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.ui.extension.IModelEditor; import org.fortiss.tooling.kernel.ui.extension.IModelEditorBinding; import org.fortiss.tooling.kernel.ui.internal.ModelEditorBindingService; /** - * The model editor binding service handles editor registration. It also allows - * opening and closing of editors. + * The model editor service handles editor registration. It also allows opening + * and closing of editors. * * @see IModelEditorBinding * * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating GREEN Hash: 6A80D8ED088608C52D21BC3F4B73BE8B + * @ConQAT.Rating YELLOW Hash: 8EFBD4397AB482FDAAD1F96749BBEAE0 */ public interface IModelEditorBindingService { @@ -45,6 +46,17 @@ public interface IModelEditorBindingService { /** Closes editors which depend on the given element or a sub-element. */ void closeEditors(EObject parentElement); + /** Returns the currently editor. */ + IModelEditor<EObject> getActiveEditor(); + + /** + * Returns an {@link IModelEditor} instance of the given class for the given + * model if such an editor is currently open. Otherwise, returns + * <code>null</code>. + */ + <T extends EObject, E extends IModelEditor<T>> E getOpenEditor( + T editedElement, Class<E> editorClass); + /** Returns registered editor bindings for the given {@link EObject}. */ List<IModelEditorBinding<EObject>> getBindings(EObject element); } -- GitLab