diff --git a/org.fortiss.tooling.kernel/trunk/plugin.xml b/org.fortiss.tooling.kernel/trunk/plugin.xml index e3605d576d076cea545612f2a4bc92928f9d430b..c87f11ba8daf535a836c9887f23304dcc4d4ef95 100644 --- a/org.fortiss.tooling.kernel/trunk/plugin.xml +++ b/org.fortiss.tooling.kernel/trunk/plugin.xml @@ -13,6 +13,15 @@ uri="http://www.fortiss.org/tooling/kernel"> </package> </extension> + <extension + point="org.eclipse.ui.editors"> + <editor + class="org.fortiss.tooling.kernel.internal.editor.BindingEditor" + default="false" + id="org.fortiss.tooling.kernel.internal.editor.BindingEditor" + name="Binding Editor"> + </editor> + </extension> <extension point="org.eclipse.ui.views"> <view diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java new file mode 100644 index 0000000000000000000000000000000000000000..d24a91887a519af83ff09538073495c2a9f90cb9 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java @@ -0,0 +1,107 @@ +/*--------------------------------------------------------------------------+ +$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.base; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.part.EditorPart; +import org.fortiss.tooling.kernel.interfaces.IEditorBinding; +import org.fortiss.tooling.kernel.interfaces.IHandler; +import org.fortiss.tooling.kernel.internal.editor.ModelElementEditorInput; +import org.fortiss.tooling.kernel.services.ICommandStackService; + +/** + * Base implementation of model element editors returned by + * {@link IEditorBinding}s. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public abstract class EditorBase<T extends EObject> extends EditorPart { + + /** + * The object shown in this editor. This is valid as soon as + * {@link #init(IEditorSite, IEditorInput)} has been called. + */ + protected T editedObject; + + /** The model element handler to be used with the {@link #editedObject}. */ + protected IHandler<T> handler; + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + if (!(input instanceof ModelElementEditorInput)) { + throw new PartInitException("Expected input of type " + + ModelElementEditorInput.class); + } + ModelElementEditorInput meInput = (ModelElementEditorInput) input; + + editedObject = (T) meInput.getEditorInput(); + if (editedObject == null) { + throw new PartInitException("Missing model element!"); + } + + handler = (IHandler<T>) meInput.getModelElementHandler(); + if (handler == null) { + throw new PartInitException("Missing model element handler!"); + } + + setInput(input); + setSite(site); + + setPartName(handler.getName(editedObject)); + setContentDescription(handler.getDescription(editedObject)); + } + + /** Runs the given {@link Runnable} in the emfStore editing domain. */ + protected final void executeCommand(Runnable runner) { + ICommandStackService.INSTANCE.runAsCommand(editedObject, runner); + } + + /** {@inheritDoc} */ + @Override + public final boolean isDirty() { + return false; + } + + /** {@inheritDoc} */ + @Override + public final boolean isSaveAsAllowed() { + return false; + } + + /** {@inheritDoc} */ + @Override + public final void doSave(IProgressMonitor monitor) { + // Saving is handled automatically by emfStore + } + + /** {@inheritDoc} */ + @Override + public final void doSaveAs() { + // Saving is handled automatically by emfStore + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java index 9a8e7f35247931fa7bc9041f72f976b12bd1eda7..6339b8d4c72e75d4a80020ba8027c92aecacc9b2 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java @@ -27,6 +27,8 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; @@ -40,10 +42,14 @@ import org.eclipse.ui.IDecoratorManager; import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.progress.UIJob; import org.fortiss.tooling.kernel.ToolingKernelActivator; +import org.fortiss.tooling.kernel.internal.editor.BindingEditor; +import org.fortiss.tooling.kernel.internal.editor.ModelElementEditorInput; +import org.fortiss.tooling.kernel.util.EObjectSelectionUtils; import org.unicase.ecp.model.ECPWorkspaceManager; import org.unicase.ecp.model.NoWorkspaceException; import org.unicase.ecp.model.workSpaceModel.ECPProject; @@ -60,7 +66,7 @@ import org.unicase.ecp.model.workSpaceModel.WorkSpaceModelPackage; * @levd.rating RED Rev: */ public final class NavigatorViewPart extends ViewPart implements - ISelectionListener, ISelectionChangedListener { + ISelectionListener, ISelectionChangedListener, IDoubleClickListener { /** Stores the TreeViewer. */ private TreeViewer viewer; @@ -77,9 +83,6 @@ public final class NavigatorViewPart extends ViewPart implements /** Stores the menu manager. */ private MenuManager menuManager; - /** Stores the new model element menu. */ - private NewMenu newMenu; - /** Constructor. */ public NavigatorViewPart() { try { @@ -172,6 +175,7 @@ public final class NavigatorViewPart extends ViewPart implements .getLabelDecorator())); viewer.setContentProvider(new NavigatorTreeContentProvider()); viewer.setInput(workspace); + viewer.addDoubleClickListener(this); } createContextMenu(); @@ -261,4 +265,31 @@ public final class NavigatorViewPart extends ViewPart implements super.dispose(); } + + /** {@inheritDoc} */ + @Override + public void doubleClick(DoubleClickEvent event) { + if (event.getSelection() instanceof IStructuredSelection) { + EObject element = EObjectSelectionUtils.getFirstElement(event + .getSelection()); + if (element != null) { + openInEditor(element); + } + } + } + + /** Opens an editor for the given element. */ + private void openInEditor(EObject element) { + try { + PlatformUI + .getWorkbench() + .getActiveWorkbenchWindow() + .getActivePage() + .openEditor(new ModelElementEditorInput(element), + BindingEditor.ID); + } catch (final PartInitException e) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + "Could not open editor with ID " + BindingEditor.ID, e); + } + } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java index d1cd7b88b2d007dddbd48848959700ad89ed5491..1ffc233f869f329cef38cf0dfe5d32f0234a7470 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java @@ -25,12 +25,12 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.CompoundContributionItem; import org.fortiss.tooling.kernel.interfaces.IPrototypeProvider; -import org.fortiss.tooling.kernel.internal.util.EObjectSelectionUtils; import org.fortiss.tooling.kernel.services.ICommandStackService; import org.fortiss.tooling.kernel.services.ICompositorService; import org.fortiss.tooling.kernel.services.IModelElementService; import org.fortiss.tooling.kernel.services.IPrototypeService; import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; +import org.fortiss.tooling.kernel.util.EObjectSelectionUtils; /** * The contributor for the dynamic new menu based on composition. diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java similarity index 97% rename from org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java rename to org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java index f740a87b14d1bfd6b5117d96597326c444216530..04cd15ce40a0a36e6a90d0f08239391bdb332d23 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java @@ -15,7 +15,7 @@ $Id$ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.kernel.internal.util; +package org.fortiss.tooling.kernel.util; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.viewers.ISelection;