Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5bbe480bd68ef71376d57991c96f9c50fe130d32 (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
69
70
71
72
73
74
75
76
77
/*****************************************************************************
 * Copyright (c) 2013, 2017 CEA LIST 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:
 *   CEA LIST - Initial API and implementation
 *   Eike Stepper (CEA) - bug 466520
 *****************************************************************************/
package org.eclipse.papyrus.cdo.internal.core;

import java.util.Collection;
import java.util.List;

import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.papyrus.cdo.core.IResourceSetDisposalApprover;

import com.google.common.collect.Lists;

/**
 * This is the CompositeResourceSetDisposalApprover type. Enjoy.
 */
class CompositeResourceSetDisposalApprover
		implements IResourceSetDisposalApprover {

	private final List<IResourceSetDisposalApprover> approvers = Lists
			.newArrayListWithExpectedSize(1);

	CompositeResourceSetDisposalApprover() {
		super();
	}

	@Override
	public DisposeAction disposalRequested(CDOCheckout checkout,
			Collection<ResourceSet> resourceSets) {

		DisposeAction result = DisposeAction.CLOSE;

		if (!resourceSets.isEmpty() && !approvers.isEmpty()) {
			for (IResourceSetDisposalApprover next : approvers) {
				DisposeAction action = wrapNull(next
						.disposalRequested(checkout, resourceSets));

				result = result.compareTo(action) > 0
						? action
						: result;

				if (result == DisposeAction.NONE) {
					// no need to consult anyone else
					break;
				}
			}
		}

		return result;
	}

	private DisposeAction wrapNull(DisposeAction action) {
		return (action == null)
				? DisposeAction.NONE
				: action;
	}

	void addApprover(IResourceSetDisposalApprover approver) {
		if (!approvers.contains(approver)) {
			approvers.add(approver);
		}
	}

	void removeApprover(IResourceSetDisposalApprover approver) {
		approvers.remove(approver);
	}
}

Back to the top