diff --git a/org.fortiss.tooling.kernel/trunk/model/kernel.ecore b/org.fortiss.tooling.kernel/trunk/model/kernel.ecore index ac5a932110f6cae3a8f0ee6a4c857c5cab50e5af..520d37b477ad583841483aabcaa13a63c2718fa5 100644 --- a/org.fortiss.tooling.kernel/trunk/model/kernel.ecore +++ b/org.fortiss.tooling.kernel/trunk/model/kernel.ecore @@ -5,11 +5,25 @@ nsURI="http://www.fortiss.org/tooling/kernel" nsPrefix="org-fortiss-tooling-kernel"> <eClassifiers xsi:type="ecore:EClass" name="INamedElement" abstract="true" interface="true" eSuperTypes="#//IIdLabeled"> - <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> + <details key="documentation" value="Model elements implementing this interface have a unique id and a name."/> + </eAnnotations> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"> + <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> + <details key="documentation" value="The name attribute."/> + </eAnnotations> + </eStructuralFeatures> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="INamedCommentedElement" abstract="true" interface="true" eSuperTypes="#//INamedElement"> - <eStructuralFeatures xsi:type="ecore:EAttribute" name="comment" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> + <details key="documentation" value="Model elements implementing this interface have a unique id, a name and a comment."/> + </eAnnotations> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="comment" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"> + <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> + <details key="documentation" value="The comment attribute."/> + </eAnnotations> + </eStructuralFeatures> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="IProjectRootElement" abstract="true" interface="true" eSuperTypes="#//INamedCommentedElement"> @@ -18,6 +32,30 @@ </eAnnotations> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="IIdLabeled" abstract="true" interface="true"> - <eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> + <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> + <details key="documentation" value="Model elements implementing this interface have a unique identifier."/> + </eAnnotations> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"> + <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> + <details key="documentation" value="The unique integer id."/> + </eAnnotations> + </eStructuralFeatures> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="IRemovable" abstract="true" interface="true"> + <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> + <details key="documentation" value="Model elements implementing this interface can provide a custom remove operatoin."/> + </eAnnotations> + <eOperations name="canRemove" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"> + <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> + <details key="documentation" value="Returns whether the current model element can be removed."/> + <details key="body" value="return IRemovableStaticImpl.canRemove(this);"/> + </eAnnotations> + </eOperations> + <eOperations name="remove" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"> + <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> + <details key="documentation" value="Removes the current model element from its parent."/> + <details key="body" value="return IRemovableStaticImpl.remove(this);"/> + </eAnnotations> + </eOperations> </eClassifiers> </ecore:EPackage> diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java index 95c5fe5e158fe5e2de8973361c107461007cf236..757f5f490721556ad626ede7d0a42d3620991249 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java @@ -18,14 +18,18 @@ $Id$ package org.fortiss.tooling.kernel.internal; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.IViewSite; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionFactory; +import org.fortiss.tooling.kernel.model.IRemovable; import org.fortiss.tooling.kernel.services.IActionService; import org.fortiss.tooling.kernel.services.ICommandStackService; import org.fortiss.tooling.kernel.util.EObjectSelectionUtils; @@ -40,6 +44,9 @@ import org.fortiss.tooling.kernel.util.EObjectSelectionUtils; */ public class ActionService implements IActionService { + /** The group id of the global default action group. */ + public static final String GROUP_GLOBAL_DEFAULTS = "globalDefaults"; + /** The global undo action. */ public final IAction globalUndoAction = new Action("Undo", PlatformUI .getWorkbench().getSharedImages() @@ -63,6 +70,48 @@ public class ActionService implements IActionService { } }; + /** The global delete action. */ + public final IAction globalDeleteAction = new Action("Delete", PlatformUI + .getWorkbench().getSharedImages() + .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)) { + @Override + public void run() { + EObject selectedObject = EObjectSelectionUtils + .getCurrentSelectionFirstElement(); + if (selectedObject != null) { + if (selectedObject instanceof IRemovable) { + ((IRemovable) selectedObject).remove(); + } else { + EcoreUtil.delete(selectedObject, true); + } + } + } + + @Override + public boolean isEnabled() { + EObject selectedObject = EObjectSelectionUtils + .getCurrentSelectionFirstElement(); + if (selectedObject != null) { + if (selectedObject instanceof IRemovable) { + return ((IRemovable) selectedObject).canRemove(); + } + return selectedObject.eContainer() != null; + } + return false; + } + }; + + /** {@inheritDoc} */ + @Override + public void addGlobalDefaultActionSectionToMenu(MenuManager menuManager) { + Separator globalDefaults = new Separator(GROUP_GLOBAL_DEFAULTS); + globalDefaults.setVisible(true); + menuManager.add(globalDefaults); + + menuManager.appendToGroup(GROUP_GLOBAL_DEFAULTS, globalDeleteAction); + menuManager.appendToGroup(GROUP_GLOBAL_DEFAULTS, globalUndoAction); + } + /** {@inheritDoc} */ @Override public void registerGlobalActions(IViewSite site) { diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ContextMenuService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ContextMenuService.java index b4a708132e9f0d18fc01189320e31e2362336a56..d9945d0b08634efc6d162bcaab4fc9e9b438395b 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ContextMenuService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ContextMenuService.java @@ -17,9 +17,6 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.fortiss.tooling.kernel.services.IActionService; import org.fortiss.tooling.kernel.services.IContextMenuService; /** @@ -32,17 +29,4 @@ import org.fortiss.tooling.kernel.services.IContextMenuService; */ public class ContextMenuService implements IContextMenuService { - /** The group id of the global default action group. */ - public static final String GROUP_GLOBAL_DEFAULTS = "globalDefaults"; - - /** {@inheritDoc} */ - @Override - public void addGlobalDefaultActionSection(MenuManager menuManager) { - Separator globalDefaults = new Separator(GROUP_GLOBAL_DEFAULTS); - globalDefaults.setVisible(true); - menuManager.add(globalDefaults); - - menuManager.appendToGroup(GROUP_GLOBAL_DEFAULTS, - ((ActionService) IActionService.INSTANCE).globalUndoAction); - } } 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 cc106d17cf52b665231c3c999476a932430b849a..945e85e293e34b627f3aeb02542dd9f840875d44 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 @@ -48,7 +48,6 @@ import org.eclipse.ui.progress.UIJob; import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.internal.NavigatorService; import org.fortiss.tooling.kernel.services.IActionService; -import org.fortiss.tooling.kernel.services.IContextMenuService; import org.fortiss.tooling.kernel.services.IEditorService; import org.fortiss.tooling.kernel.services.INavigatorService; import org.fortiss.tooling.kernel.util.EObjectSelectionUtils; @@ -209,7 +208,8 @@ public final class NavigatorViewPart extends ViewPart implements repositorySection.setVisible(true); menuManager.add(repositorySection); - IContextMenuService.INSTANCE.addGlobalDefaultActionSection(menuManager); + IActionService.INSTANCE + .addGlobalDefaultActionSectionToMenu(menuManager); Separator additions = new Separator( IWorkbenchActionConstants.MB_ADDITIONS); diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/model/impl/IRemovableStaticImpl.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/model/impl/IRemovableStaticImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..c9039610d0817b6862b14cb6432c0346ef5643ee --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/model/impl/IRemovableStaticImpl.java @@ -0,0 +1,50 @@ +/*--------------------------------------------------------------------------+ +$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.model.impl; + +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.fortiss.tooling.kernel.model.IRemovable; + +/** + * Static implementations for {@link IRemovable}. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public final class IRemovableStaticImpl { + /** Constructor. */ + private IRemovableStaticImpl() { + // class not intended to be instantiated. + } + + /** Returns true, if a parent exists. */ + public static boolean canRemove(IRemovable element) { + return element.eContainer() != null; + } + + /** + * Removes element from its parent container and deletes all references to + * it and its children. + */ + public static boolean remove(IRemovable element) { + EcoreUtil.delete(element, true); + return true; + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java index 90cf40fa9d8bebfef96c80fd0dd906560276a03e..a0c2c8196ecb397184ce08e785299af58e0aef73 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java @@ -17,6 +17,7 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.services; +import org.eclipse.jface.action.MenuManager; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IViewSite; import org.fortiss.tooling.kernel.internal.ActionService; @@ -41,6 +42,9 @@ public interface IActionService { /** Registers global actions with an editor site. */ void registerGlobalActions(IEditorSite site); + /** Adds the global default actions like undo to the given context menu. */ + void addGlobalDefaultActionSectionToMenu(MenuManager menuManager); + /** Updates the enabled state of the global actions. */ void update(); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IContextMenuService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IContextMenuService.java index c4aff7d48fbd0f4affe86484a628acc78a6bdceb..e17bd3f5230dbd164693d80b1c6591ee0352ebe7 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IContextMenuService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IContextMenuService.java @@ -17,7 +17,6 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.services; -import org.eclipse.jface.action.MenuManager; import org.fortiss.tooling.kernel.internal.ContextMenuService; /** @@ -33,7 +32,4 @@ public interface IContextMenuService { /** Returns the singleton instance of the service. */ public static final IContextMenuService INSTANCE = new ContextMenuService(); - - /** Adds the global default actions like undo to the given context menu. */ - void addGlobalDefaultActionSection(MenuManager menuManager); }