Skip to content

Package: DeleteServiceAdapter

DeleteServiceAdapter

nameinstructionbranchcomplexitylinemethod
DeleteServiceAdapter(DeleteService)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
canDelete(Iterable)
M: 0 C: 33
100%
M: 2 C: 10
83%
M: 2 C: 5
71%
M: 0 C: 7
100%
M: 0 C: 1
100%
deleteElement(Object)
M: 5 C: 9
64%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 4
80%
M: 0 C: 1
100%
deleteElements(Collection)
M: 5 C: 9
64%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 4
80%
M: 0 C: 1
100%
dispose()
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getPriority()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
instantiate(ViewModelContext)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.edit.spi;
15:
16: import java.util.Collection;
17:
18: import org.eclipse.emf.ecore.EObject;
19: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
20:
21: /**
22: * An adapter for delete services that do not implement the {@link ConditionalDeleteService} protocol.
23: */
24: final class DeleteServiceAdapter implements ConditionalDeleteService {
25:
26:         /** An adapter for the {@code null} service (when there is no delete service at all). */
27:         static final ConditionalDeleteService NULL = new DeleteServiceAdapter(null);
28:
29:         private final DeleteService delegate;
30:
31:         /**
32:          * Initializes me with the real delete service.
33:          *
34:          * @param delegate the real delete service
35:          */
36:         DeleteServiceAdapter(DeleteService delegate) {
37:                 super();
38:
39:                 this.delegate = delegate;
40:         }
41:
42:         @Override
43:         public void deleteElements(Collection<Object> toDelete) {
44:•                if (delegate != null) {
45:                         delegate.deleteElements(toDelete);
46:                 } else {
47:                         throw new IllegalStateException("No deletion service available."); //$NON-NLS-1$
48:                 }
49:         }
50:
51:         @Override
52:         public void deleteElement(Object toDelete) {
53:•                if (delegate != null) {
54:                         delegate.deleteElement(toDelete);
55:                 } else {
56:                         throw new IllegalStateException("No deletion service available."); //$NON-NLS-1$
57:                 }
58:         }
59:
60:         @Override
61:         public void instantiate(ViewModelContext context) {
62:•                if (delegate != null) {
63:                         delegate.instantiate(context);
64:                 }
65:         }
66:
67:         @Override
68:         public void dispose() {
69:•                if (delegate != null) {
70:                         delegate.dispose();
71:                 }
72:         }
73:
74:         @Override
75:         public int getPriority() {
76:•                return delegate == null ? Integer.MIN_VALUE : delegate.getPriority();
77:         }
78:
79:         @Override
80:         public boolean canDelete(Iterable<?> objects) {
81:                 // Cannot delete if we have no service to effect the deletion
82:•                boolean result = delegate != null;
83:
84:•                if (result) {
85:•                        for (final Object next : objects) {
86:                                 // Cannot delete a null or a root object
87:•                                if (next == null || next instanceof EObject && ((EObject) next).eContainer() == null) {
88:                                         result = false;
89:                                         break;
90:                                 }
91:                         }
92:                 }
93:
94:                 return result;
95:         }
96:
97: }