Skip to content

Package: ProgressCopyCommandFactory

ProgressCopyCommandFactory

nameinstructionbranchcomplexitylinemethod
create(EditingDomain, Collection, IProgressMonitorProvider)
M: 41 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 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.emf.common.command.Command;
19: import org.eclipse.emf.common.command.CompoundCommand;
20: import org.eclipse.emf.common.command.UnexecutableCommand;
21: import org.eclipse.emf.edit.command.CommandParameter;
22: import org.eclipse.emf.edit.command.CopyCommand;
23: import org.eclipse.emf.edit.command.CopyCommand.Helper;
24: import org.eclipse.emf.edit.domain.EditingDomain;
25:
26: /**
27: * Factory to create copy commands enabling progress reposrting.
28: *
29: * @since 1.11
30: */
31: public final class ProgressCopyCommandFactory {
32:
33:         private ProgressCopyCommandFactory() {
34:         }
35:
36:         /**
37:          * This creates a command that copies the given collection of objects. If the collection contains more than one
38:          * object,
39:          * then a compound command will be created containing individual copy commands for each object.
40:          *
41:          * @param domain {@link EditingDomain}
42:          * @param collection objects to copy
43:          * @param monitor the monitor.
44:          * @return the copy command.
45:          */
46:         public static Command create(final EditingDomain domain, final Collection<?> collection,
47:                 IProgressMonitorProvider monitor) {
48:•                if (collection == null || collection.isEmpty()) {
49:                         return UnexecutableCommand.INSTANCE;
50:                 }
51:
52:                 final Helper copyHelper = new Helper();
53:                 final CompoundCommand copyCommand = new ProgressCompoundCommand(CompoundCommand.MERGE_COMMAND_ALL, monitor);
54:•                for (final Object object : collection) {
55:                         copyCommand.append(domain.createCommand(CopyCommand.class, new CommandParameter(object, null, copyHelper)));
56:                 }
57:
58:                 return copyCommand.unwrap();
59:         }
60: }