Skip to content
Snippets Groups Projects
Commit eee86f54 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

added delete operation

parent 716d2136
No related branches found
No related tags found
No related merge requests found
......@@ -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>
......@@ -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) {
......
......@@ -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);
}
}
......@@ -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);
......
/*--------------------------------------------------------------------------+
$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;
}
}
......@@ -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();
}
......@@ -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);
}
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