Skip to content

Package: DeleteModelElementHandler

DeleteModelElementHandler

nameinstructionbranchcomplexitylinemethod
DeleteModelElementHandler()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
canExecute(EObject, List)
M: 8 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
execute(EObject, List)
M: 27 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.ui.e4.handlers;
16:
17: import java.util.ArrayList;
18: import java.util.List;
19:
20: import javax.inject.Named;
21:
22: import org.eclipse.e4.core.di.annotations.CanExecute;
23: import org.eclipse.e4.core.di.annotations.Execute;
24: import org.eclipse.e4.core.di.annotations.Optional;
25: import org.eclipse.e4.ui.services.IServiceConstants;
26: import org.eclipse.emf.ecore.EObject;
27: import org.eclipse.emf.ecp.core.ECPProjectManager;
28: import org.eclipse.emf.ecp.core.util.ECPUtil;
29: import org.eclipse.emf.ecp.spi.ui.util.ECPHandlerHelper;
30:
31: /**
32: * Handler to delete selected {@link EObject}.
33: *
34: * @author Jonas
35: *
36: */
37: public class DeleteModelElementHandler {
38:
39:         /**
40:          * Deletes a single {@link EObject} or a list of {@link EObject}.
41:          *
42:          * @param eObject the eobject to be deleted or null, if several eobjects are to be deleted.
43:          * @param eObjects A List of EObjects to be deleted or null, if only one {@link EObject} should be deleted.
44:          */
45:         @Execute
46:         public void execute(
47:                 @Named(IServiceConstants.ACTIVE_SELECTION) @Optional EObject eObject,
48:                 @Named(IServiceConstants.ACTIVE_SELECTION) @Optional List<EObject> eObjects) {
49:                 final ECPProjectManager ecpProjectManager = ECPUtil.getECPProjectManager();
50:                 final List<Object> toBeDeleted = new ArrayList<Object>();
51:•                if (eObject != null) {
52:                         toBeDeleted.add(eObject);
53:                 }
54:•                if (eObjects != null) {
55:                         toBeDeleted.addAll(eObjects);
56:                 }
57:•                if (!toBeDeleted.isEmpty()) {
58:                         ECPHandlerHelper.deleteModelElement(
59:                                 ecpProjectManager.getProject(eObject),
60:                                 toBeDeleted);
61:                 }
62:         }
63:
64:         /**
65:          * Checks if one EObject or a list of EObjects are selected.
66:          *
67:          * @param eObject the selected eobject or null, if several or none eobjects are selected.
68:          * @param eObjects the list of selected eobjects or null, if one or none eobjects are selected.
69:          * @return true if one EObject or a list of EObjects are selected.
70:          */
71:         @CanExecute
72:         public boolean canExecute(
73:                 @Named(IServiceConstants.ACTIVE_SELECTION) @Optional EObject eObject,
74:                 @Named(IServiceConstants.ACTIVE_SELECTION) @Optional List<EObject> eObjects) {
75:•                return eObject != null || eObjects != null;
76:         }
77: }