Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c898ddf559285aeaa76eb3f85b5280baffc18593 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*****************************************************************************
 * Copyright (c) 2018 Christian W. Damus and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Christian W. Damus - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.uml.service.types.helper.advice;

import static org.eclipse.gmf.runtime.common.core.command.CompositeCommand.compose;

import java.util.Optional;
import java.util.Set;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
import org.eclipse.uml2.uml.CombinedFragment;
import org.eclipse.uml2.uml.InteractionOperand;

/**
 * Edit-helper advice for {@link InteractionOperand}s.
 * 
 * @since 3.1
 */
public class InteractionOperandEditHelperAdvice extends InteractionFragmentContainerEditHelperAdvice {

	/**
	 * Initializes me.
	 */
	public InteractionOperandEditHelperAdvice() {
		super();
	}

	@Override
	protected ICommand getAfterDestroyDependentsCommand(DestroyDependentsRequest request) {
		ICommand result = super.getAfterDestroyDependentsCommand(request);

		if (request.getElementToDestroy() instanceof InteractionOperand) {
			InteractionOperand operand = (InteractionOperand) request.getElementToDestroy();
			CombinedFragment cfrag = (CombinedFragment) operand.getOwner();

			// Are we deleting all of the operands of this combined fragment?
			Optional<InteractionContainerDeletionContext> context = InteractionContainerDeletionContext.get(request);

			result = compose(context.filter(ctx -> deletingAllOperands(ctx, cfrag, request))
					.map(__ -> request.getDestroyDependentCommand(cfrag))
					.orElse(null), result);
		}

		return result;
	}

	static boolean deletingAllOperands(InteractionContainerDeletionContext ctx, CombinedFragment cfrag, DestroyDependentsRequest req) {
		@SuppressWarnings("unchecked")
		Set<? extends EObject> destroying = req.getDependentElementsToDestroy();

		return cfrag.getOperands().stream().allMatch(
				operand -> ctx.isBeingDestroyed(operand) || destroying.contains(operand));
	}

}

Back to the top