blob: 7c473fbf8b8a4e861b6157a36b4af0e042d82bd4 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* EclipseSource Munich GmbH - initial API and implementation
******************************************************************************/
package org.eclipse.emf.ecp.view.spi.rule.model.impl;
import java.util.Collection;
import java.util.Map;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.emf.ecp.view.spi.rule.model.Condition;
import org.eclipse.emf.ecp.view.spi.rule.model.LeafCondition;
import org.eclipse.emf.ecp.view.spi.rule.model.OrCondition;
import org.eclipse.emf.ecp.view.spi.rule.model.RulePackage;
import org.eclipse.emf.ecp.view.spi.rule.model.util.ConditionEvaluationUtil;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Or Condition</b></em>'.
*
* @since 1.2
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.emf.ecp.view.spi.rule.model.impl.OrConditionImpl#getConditions
* <em>Conditions</em>}</li>
* </ul>
*
* @generated
*/
public class OrConditionImpl extends ConditionImpl implements OrCondition {
/**
* The cached value of the '{@link #getConditions() <em>Conditions</em>}' containment reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @see #getConditions()
* @generated
* @ordered
*/
protected EList<Condition> conditions;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
protected OrConditionImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
protected EClass eStaticClass() {
return RulePackage.Literals.OR_CONDITION;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public EList<Condition> getConditions() {
if (conditions == null) {
conditions = new EObjectContainmentEList<Condition>(Condition.class, this,
RulePackage.OR_CONDITION__CONDITIONS);
}
return conditions;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd,
int featureID, NotificationChain msgs) {
switch (featureID) {
case RulePackage.OR_CONDITION__CONDITIONS:
return ((InternalEList<?>) getConditions()).basicRemove(otherEnd, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case RulePackage.OR_CONDITION__CONDITIONS:
return getConditions();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case RulePackage.OR_CONDITION__CONDITIONS:
getConditions().clear();
getConditions().addAll((Collection<? extends Condition>) newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case RulePackage.OR_CONDITION__CONDITIONS:
getConditions().clear();
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case RulePackage.OR_CONDITION__CONDITIONS:
return conditions != null && !conditions.isEmpty();
}
return super.eIsSet(featureID);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.view.spi.rule.model.Condition#evaluate(org.eclipse.emf.ecore.EObject)
* @since 1.9
*/
@Override
public boolean evaluate(EObject domainModel) {
boolean result = getConditions().isEmpty();
for (final Condition innerCondition : getConditions()) {
result |= innerCondition.evaluate(domainModel);
}
return result;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.view.spi.rule.model.Condition#evaluateChangedValues(org.eclipse.emf.ecore.EObject,
* java.util.Map)
* @since 1.9
*/
@Override
public boolean evaluateChangedValues(EObject domainModel, Map<Setting, Object> possibleNewValues) {
boolean result = false;
for (final Condition innerCondition : getConditions()) {
if (LeafCondition.class.isInstance(innerCondition)) {
if (ConditionEvaluationUtil.isLeafConditionForSetting(LeafCondition.class.cast(innerCondition),
domainModel, possibleNewValues)) {
result |= innerCondition.evaluateChangedValues(domainModel, possibleNewValues);
} else {
result |= innerCondition.evaluate(domainModel);
}
} else {
result |= innerCondition.evaluateChangedValues(domainModel, possibleNewValues);
}
}
return result;
}
} // OrConditionImpl