Debian Codegraph @

plugins/org.eclipse.emf.edit.ui/src/org/eclipse/emf/edit/ui/action/DeleteAction.java

raw
1 /**
2 * Copyright (c) 2002-2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v20.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 */
11 package org.eclipse.emf.edit.ui.action;
12
13
14 import java.util.Collection;
15
16 import org.eclipse.ui.IEditorPart;
17 import org.eclipse.ui.IWorkbenchPart;
18
19 import org.eclipse.emf.common.command.Command;
20 import org.eclipse.emf.edit.command.DeleteCommand;
21 import org.eclipse.emf.edit.command.RemoveCommand;
22 import org.eclipse.emf.edit.domain.EditingDomain;
23 import org.eclipse.emf.edit.domain.IEditingDomainProvider;
24 import org.eclipse.emf.edit.ui.EMFEditUIPlugin;
25
26
27 /**
28 * A delete action removes objects from their parent containers, optionally cleaning up other references to the objects.
29 * It is implemented by creating a {@link RemoveCommand} or {@link DeleteCommand}.
30 */
31 public class DeleteAction extends CommandActionHandler
32 {
33 /**
34 * Whether the action should clean up all references to deleted objects.
35 * @since 2.2
36 */
37 protected boolean removeAllReferences;
38
39 /**
40 * @since 2.2
41 */
42 public DeleteAction(EditingDomain domain, boolean removeAllReferences)
43 {
44 super(domain, EMFEditUIPlugin.INSTANCE.getString("_UI_Delete_menu_item"));
45 this.removeAllReferences = removeAllReferences;
46 }
47
48 public DeleteAction(EditingDomain domain)
49 {
50 this(domain, false);
51 }
52
53 /**
54 * @since 2.2
55 */
56 public DeleteAction(boolean removeAllReferences)
57 {
58 this(null, removeAllReferences);
59 }
60
61 public DeleteAction()
62 {
63 this(null);
64 }
65
66 @Override
67 public Command createCommand(Collection<?> selection)
68 {
69 return removeAllReferences ? DeleteCommand.create(domain, selection) : RemoveCommand.create(domain, selection);
70 }
71
72 /**
73 * @deprecated As of EMF 2.1.0, replaced by {@link #setActiveWorkbenchPart}.
74 */
75 @Deprecated
76 public void setActiveEditor(IEditorPart editorPart)
77 {
78 setActiveWorkbenchPart(editorPart);
79 }
80
81 /**
82 * @since 2.1.0
83 */
84 public void setActiveWorkbenchPart(IWorkbenchPart workbenchPart)
85 {
86 if (workbenchPart instanceof IEditingDomainProvider)
87 {
88 domain = ((IEditingDomainProvider)workbenchPart).getEditingDomain();
89 }
90 }
91 }