From 8569be907f7c65ff76d74af3fcb581d1af27168c Mon Sep 17 00:00:00 2001 From: Dongyue Mou <mou@fortiss.org> Date: Mon, 7 May 2012 11:17:46 +0000 Subject: [PATCH] added model and UI elements for BMC parameter modified ts specification editor to observe all changes in the part list and update the UI. refs 802 --- .../internal/ModelEditorBindingService.java | 96 +++++++------------ .../service/IModelEditorBindingService.java | 10 +- 2 files changed, 38 insertions(+), 68 deletions(-) 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 4e13cf194..7d391a1a4 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 @@ -53,14 +53,15 @@ import org.fortiss.tooling.kernel.utils.LoggingUtils; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating GREEN Hash: 5D8E3357E3B8F103A782BBD7096D5616 + * @ConQAT.Rating YELLOW Hash: 7F415EAA11A7C0E77D09F08D2E615DF8 */ public class ModelEditorBindingService extends EObjectAwareServiceBase<IModelEditorBinding<EObject>> implements IModelEditorBindingService, IPartListener, CommandStackListener { /** The compositor extension point ID. */ - private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.ui.modelEditorBinding"; + private static final String EXTENSION_POINT_NAME = + "org.fortiss.tooling.kernel.ui.modelEditorBinding"; /** The compositor configuration element name. */ private static final String CONFIGURATION_ELEMENT_NAME = "modelEditorBinding"; @@ -72,14 +73,15 @@ public class ModelEditorBindingService extends private final Map<IEditorPart, EObject> currentEditors = new HashMap<IEditorPart, EObject>(); /** Stores the command stack registrations. */ - private final Map<EObject, ITopLevelElement> currentCommandStacks = new HashMap<EObject, ITopLevelElement>(); + private final Map<EObject, ITopLevelElement> currentCommandStacks = + new HashMap<EObject, ITopLevelElement>(); /** Constructor. */ public ModelEditorBindingService() { super(); // sort editor bindings by priority. EditorBindingComparator comparator = new EditorBindingComparator(); - for (Class<?> clazz : handlerMap.keySet()) { + for(Class<?> clazz : handlerMap.keySet()) { Collections.sort(handlerMap.get(clazz), comparator); } } @@ -93,42 +95,39 @@ public class ModelEditorBindingService extends /** Opens the editor or proceeds with parent element. */ private void openInEditor(EObject element, int depth) { Assert.isTrue(depth >= 0); - if (getBindings(element).isEmpty()) { - if (depth > 0 && element.eContainer() != null) { + if(getBindings(element).isEmpty()) { + if(depth > 0 && element.eContainer() != null) { openInEditor(element.eContainer(), depth - 1); } return; } try { - IEditorPart part = PlatformUI - .getWorkbench() - .getActiveWorkbenchWindow() - .getActivePage() - .openEditor(new ModelElementEditorInput(element), - ExtendableMultiPageEditor.ID); + IEditorPart part = + PlatformUI + .getWorkbench() + .getActiveWorkbenchWindow() + .getActivePage() + .openEditor(new ModelElementEditorInput(element), + ExtendableMultiPageEditor.ID); currentEditors.put(part, element); // ensure registration with part service - IPartService service = (IPartService) part.getSite().getService( - IPartService.class); + IPartService service = (IPartService)part.getSite().getService(IPartService.class); service.addPartListener(this); // ensure registration with command stack service - ITopLevelElement top = IPersistencyService.INSTANCE - .getTopLevelElementFor(element); + ITopLevelElement top = IPersistencyService.INSTANCE.getTopLevelElementFor(element); ICommandStackService.INSTANCE.addCommandStackListener(top, this); currentCommandStacks.put(element, top); - } catch (final PartInitException e) { + } catch(final PartInitException e) { LoggingUtils.error(ToolingKernelActivator.getDefault(), - "Could not open editor with ID " - + ExtendableMultiPageEditor.ID, e); + "Could not open editor with ID " + ExtendableMultiPageEditor.ID, e); } } /** {@inheritDoc} */ @Override public List<IModelEditorBinding<EObject>> getBindings(EObject element) { - List<IModelEditorBinding<EObject>> bindings = getRegisteredHandlers(element - .getClass()); - if (bindings == null) { + List<IModelEditorBinding<EObject>> bindings = getRegisteredHandlers(element.getClass()); + if(bindings == null) { bindings = CollectionUtils.emptyList(); } return bindings; @@ -158,8 +157,7 @@ public class ModelEditorBindingService extends /** {@inheritDoc} */ @Override - public int compare(IModelEditorBinding<EObject> eb0, - IModelEditorBinding<EObject> eb1) { + public int compare(IModelEditorBinding<EObject> eb0, IModelEditorBinding<EObject> eb1) { return eb1.getPriority() - eb0.getPriority(); } } @@ -201,14 +199,14 @@ public class ModelEditorBindingService extends /** {@inheritDoc} */ @Override public void partClosed(IWorkbenchPart part) { - if (currentEditors.containsKey(part)) { + if(currentEditors.containsKey(part)) { EObject eo = currentEditors.get(part); ITopLevelElement top = currentCommandStacks.get(eo); currentCommandStacks.remove(eo); currentEditors.remove(part); // clean up command stack registration - for (IEditorPart other : currentEditors.keySet()) { - if (top == currentCommandStacks.get(currentEditors.get(other))) { + for(IEditorPart other : currentEditors.keySet()) { + if(top == currentCommandStacks.get(currentEditors.get(other))) { return; } } @@ -232,52 +230,32 @@ public class ModelEditorBindingService extends /** {@inheritDoc} */ @Override public void commandStackChanged(EventObject event) { - for (IEditorPart part : currentEditors.keySet()) { - ITopLevelElement top = IPersistencyService.INSTANCE - .getTopLevelElementFor(currentEditors.get(part)); - if (top == null) { + for(IEditorPart part : currentEditors.keySet()) { + ITopLevelElement top = + IPersistencyService.INSTANCE.getTopLevelElementFor(currentEditors.get(part)); + if(top == null) { closeEditor(part); } } } - /** {@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) { - ExtendableMultiPageEditor extEditor = (ExtendableMultiPageEditor) activeEditor; + IEditorPart activeEditor = + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() + .getActiveEditor(); + if(activeEditor instanceof ExtendableMultiPageEditor) { + ExtendableMultiPageEditor extEditor = (ExtendableMultiPageEditor)activeEditor; IModelEditor<EObject> inner = extEditor.getActiveModelEditor(); - if (inner != null) { + if(inner != null) { return inner; } return extEditor; } - if (activeEditor instanceof IModelEditor) { - return (IModelEditor<EObject>) activeEditor; + 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/service/IModelEditorBindingService.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/service/IModelEditorBindingService.java index 27e1a0dd0..cda0ba9ce 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 @@ -33,7 +33,7 @@ import org.fortiss.tooling.kernel.ui.internal.ModelEditorBindingService; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating GREEN Hash: A76E99E4EAF5A391267B44D9EE22B3DF + * @ConQAT.Rating YELLOW Hash: 8C3DE2C0EDF7A9B71DA28244180538DD */ public interface IModelEditorBindingService { @@ -49,14 +49,6 @@ public interface IModelEditorBindingService { /** Returns the currently active 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