| 1 | /* |
| 2 | * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH) |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.resource.part; |
| 5 | |
| 6 | import java.util.Iterator; |
| 7 | import java.util.List; |
| 8 | |
| 9 | import org.eclipse.gef.EditPart; |
| 10 | import org.eclipse.gef.Request; |
| 11 | import org.eclipse.gef.commands.Command; |
| 12 | import org.eclipse.gef.commands.UnexecutableCommand; |
| 13 | import org.eclipse.gmf.runtime.diagram.ui.actions.AbstractDeleteFromAction; |
| 14 | import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds; |
| 15 | import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy; |
| 16 | import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; |
| 17 | import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; |
| 18 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
| 19 | import org.eclipse.ui.ISharedImages; |
| 20 | import org.eclipse.ui.IWorkbenchPage; |
| 21 | import org.eclipse.ui.IWorkbenchPart; |
| 22 | import org.eclipse.ui.PlatformUI; |
| 23 | |
| 24 | /** |
| 25 | * @generated |
| 26 | */ |
| 27 | public class DeleteElementAction extends AbstractDeleteFromAction { |
| 28 | |
| 29 | /** |
| 30 | * @generated |
| 31 | */ |
| 32 | public DeleteElementAction(IWorkbenchPart part) { |
| 33 | super(part); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @generated |
| 38 | */ |
| 39 | public DeleteElementAction(IWorkbenchPage workbenchPage) { |
| 40 | super(workbenchPage); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @generated |
| 45 | */ |
| 46 | public void init() { |
| 47 | super.init(); |
| 48 | setId(ActionIds.ACTION_DELETE_FROM_MODEL); |
| 49 | setText(DiagramUIMessages.DiagramEditor_Delete_from_Model); |
| 50 | setToolTipText(DiagramUIMessages.DiagramEditor_Delete_from_ModelToolTip); |
| 51 | ISharedImages workbenchImages = PlatformUI.getWorkbench() |
| 52 | .getSharedImages(); |
| 53 | setHoverImageDescriptor(workbenchImages |
| 54 | .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); |
| 55 | setImageDescriptor(workbenchImages |
| 56 | .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); |
| 57 | setDisabledImageDescriptor(workbenchImages |
| 58 | .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED)); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @generated |
| 63 | */ |
| 64 | protected String getCommandLabel() { |
| 65 | return DiagramUIMessages.DiagramEditor_Delete_from_Model; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @generated |
| 70 | */ |
| 71 | protected Command getCommand(Request request) { |
| 72 | List operationSet = getOperationSet(); |
| 73 | if (operationSet.isEmpty()) { |
| 74 | return UnexecutableCommand.INSTANCE; |
| 75 | } |
| 76 | Iterator editParts = operationSet.iterator(); |
| 77 | CompositeTransactionalCommand command = new CompositeTransactionalCommand( |
| 78 | getEditingDomain(), getCommandLabel()); |
| 79 | while (editParts.hasNext()) { |
| 80 | EditPart editPart = (EditPart) editParts.next(); |
| 81 | Command curCommand = editPart.getCommand(request); |
| 82 | if (curCommand != null) { |
| 83 | command.compose(new CommandProxy(curCommand)); |
| 84 | } |
| 85 | } |
| 86 | if (command.isEmpty() || command.size() != operationSet.size()) { |
| 87 | return UnexecutableCommand.INSTANCE; |
| 88 | } |
| 89 | return new ICommandProxy(command); |
| 90 | } |
| 91 | } |