Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9816faff4f90b4643c188e5b5bd97d42eaf6ecfd (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
 * Copyright (c) 2013 CEA LIST.
 * 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:
 *     Cedric Dumoulin - cedric.dumoulin@lifl.fr
 ******************************************************************************/
package org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.operators;

import org.eclipse.emf.common.util.EList;
import org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.LayersException;
import org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.command.ComputePropertyValueCommand;
import org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.BooleanInstance;
import org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.LayersFactory;
import org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.layers.TypeInstance;


/**
 * @author cedric dumoulin
 *
 */
public class BooleanOrOperator implements CustomPropertyOperatorsInstance {

	public static final BooleanInstance FALSE_INSTANCE;
	public static final BooleanInstance TRUE_INSTANCE;

	static {
		FALSE_INSTANCE = LayersFactory.eINSTANCE.createBooleanInstance();
		FALSE_INSTANCE.setValue(false);
		TRUE_INSTANCE = LayersFactory.eINSTANCE.createBooleanInstance();
		TRUE_INSTANCE.setValue(true);
	}

	/**
	 *
	 * @see org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.operators.CustomPropertyOperatorsInstance#getComputePropertyValueCommand(org.eclipse.emf.common.util.EList)
	 *
	 * @param property
	 * @return
	 * @throws LayersException
	 */
	@Override
	public ComputePropertyValueCommand getComputePropertyValueCommand(EList<ComputePropertyValueCommand> nestedCommand) throws LayersException {
		return new BooleanOrOperatorCommand(nestedCommand);
	}


	/**
	 * Class implementing an And command.
	 *
	 */
	class BooleanOrOperatorCommand implements ComputePropertyValueCommand {

		EList<ComputePropertyValueCommand> nestedCommand;

		/**
		 *
		 * Constructor.
		 *
		 * @param nestedCommand
		 */
		public BooleanOrOperatorCommand(EList<ComputePropertyValueCommand> nestedCommand) {
			this.nestedCommand = nestedCommand;
		}

		/**
		 * Compute the value.
		 *
		 * @see org.eclipse.papyrus.internal.infra.gmfdiag.layers.model.command.ComputePropertyValueCommand#getCmdValue()
		 *
		 * @return
		 * @throws LayersException
		 */
		@Override
		public TypeInstance getCmdValue() throws LayersException {

			// Do an boolean or: at least one value should be true.
			// Return as soon as a true is encountered
			for (ComputePropertyValueCommand curCmd : nestedCommand) {
				boolean curCmdRes = ((BooleanInstance) curCmd.getCmdValue()).isValue();
				if (curCmdRes == true) {
					return TRUE_INSTANCE;
				}
			}

			return FALSE_INSTANCE;
		}

	}
}

Back to the top