Skip to content

Package: ProgressAddCommand

ProgressAddCommand

nameinstructionbranchcomplexitylinemethod
ProgressAddCommand(EditingDomain, EObject, EStructuralFeature, Collection, int)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
doExecute()
M: 56 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
setIProgressMonitorAccessor(IProgressMonitorProvider)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
worked()
M: 14 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.edit.spi.swt.commands;
15:
16: import java.util.Collection;
17:
18: import org.eclipse.core.runtime.IProgressMonitor;
19: import org.eclipse.emf.ecore.EObject;
20: import org.eclipse.emf.ecore.EStructuralFeature;
21: import org.eclipse.emf.edit.command.AddCommand;
22: import org.eclipse.emf.edit.command.CommandParameter;
23: import org.eclipse.emf.edit.domain.EditingDomain;
24: import org.eclipse.swt.widgets.Display;
25:
26: /**
27: * {@link AddCommand} which is able to report progress.
28: *
29: * @author Johannes Faltermeier
30: * @since 1.11
31: *
32: */
33: public class ProgressAddCommand extends AddCommand implements IProgressMonitorConsumer {
34:
35:         private IProgressMonitorProvider monitor;
36:
37:         /**
38:          * Constructs a {@link ProgressAddCommand}.
39:          *
40:          * @param domain the {@link EditingDomain}
41:          * @param owner the parent
42:          * @param feature the feature
43:          * @param collection the children to add
44:          * @param index the start index
45:          */
46:         public ProgressAddCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Collection<?> collection,
47:                 int index) {
48:                 super(domain, owner, feature, collection, index);
49:         }
50:
51:         @Override
52:         public void setIProgressMonitorAccessor(IProgressMonitorProvider monitor) {
53:                 this.monitor = monitor;
54:         }
55:
56:         @Override
57:         public void doExecute() {
58:                 // Simply add the collection to the list.
59:                 //
60:•                if (index == CommandParameter.NO_INDEX) {
61:•                        for (final Object object : collection) {
62:                                 ownerList.add(object);
63:                                 worked();
64:                         }
65:                 } else {
66:                         int i = index;
67:•                        for (final Object object : collection) {
68:                                 ownerList.add(i++, object);
69:                                 worked();
70:                         }
71:                 }
72:
73:                 // Update the containing map, if necessary.
74:                 //
75:                 updateEMap(owner, feature);
76:
77:                 // We'd like the collection of things added to be selected after this command completes.
78:                 //
79:                 affectedObjects = collection;
80:         }
81:
82:         private void worked() {
83:                 final IProgressMonitor progressMonitor = monitor.getProgressMonitor();
84:•                if (progressMonitor == null) {
85:                         return;
86:                 }
87:                 progressMonitor.worked(1);
88:•                while (Display.getDefault().readAndDispatch()) {
89:                 }
90:         }
91:
92: }