Skip to content
Snippets Groups Projects
Commit 6a6fb9e3 authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

moves the corresponding utility methods (after generalizing them)

refs 2708
parent 0c828311
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2016 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.utils;
import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getActiveConstraintsTransitively;
import java.util.List;
import org.fortiss.tooling.base.model.element.ConstraintConfiguration;
import org.fortiss.tooling.base.model.element.IConstraintBasedProcess;
import org.fortiss.tooling.kernel.extension.IConstraint;
import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer;
import org.fortiss.tooling.kernel.ui.service.IConstraintUIService;
/**
* Utility methods related to constraints.
*
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 364E3DB6782217410744A36167874C40
*/
public class ConstraintsBaseUIUtils {
/** Factorized behaviour. */
public static void doActivateAll(IConstraintInstanceContainer cstrContainer,
IConstraintBasedProcess cbdProcess) {
// First activate the constraints which should always be activated
for(Class<? extends IConstraint> cstrClass : IConstraintUIService.getInstance()
.getAlwaysActivatedConstraints()) {
IConstraintUIService.getInstance().activate(cstrClass, cstrContainer);
}
// Then activate the constraints of the current objective
ConstraintConfiguration currentObj = cbdProcess.getCurrentObjective();
if(currentObj != null) {
List<Class<? extends IConstraint>> activeCstrs =
getActiveConstraintsTransitively(currentObj, null);
for(Class<? extends IConstraint> cstrClass : activeCstrs) {
IConstraintUIService.getInstance().activate(cstrClass, cstrContainer);
}
}
}
/**
* Activates all constraints which are active in the given configuration, potentially adding new
* constraint instances to the provided container.
*/
public static void activateConfiguration(ConstraintConfiguration config,
IConstraintInstanceContainer cstrContainer) {
for(Class<? extends IConstraint> cstr : getActiveConstraintsTransitively(config, null)) {
IConstraintUIService.getInstance().activate(cstr, cstrContainer);
}
}
/**
* Deactivates all constraints which are active in the given configuration, if they are not
* still active in the provided context.
*/
public static void deactivateConfiguration(ConstraintConfiguration config,
IConstraintInstanceContainer cstrContainer, ConstraintConfiguration context) {
List<Class<? extends IConstraint>> stillActiveConstraints =
getActiveConstraintsTransitively(context, config);
for(Class<? extends IConstraint> cstr : getActiveConstraintsTransitively(config, null)) {
if(!stillActiveConstraints.contains(cstr)) {
IConstraintUIService.getInstance().deactivate(cstr, cstrContainer);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment