1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.properties.widgets.modules;
\r
14 import org.simantics.browsing.ui.content.Labeler.Modifier;
\r
15 import org.simantics.browsing.ui.model.modifiers.ModifierRule;
\r
16 import org.simantics.db.ReadGraph;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.db.WriteGraph;
\r
19 import org.simantics.db.common.request.ObjectsWithType;
\r
20 import org.simantics.db.common.request.WriteRequest;
\r
21 import org.simantics.db.exception.DatabaseException;
\r
22 import org.simantics.db.layer0.util.RemoverUtil;
\r
23 import org.simantics.db.request.Read;
\r
24 import org.simantics.layer0.Layer0;
\r
25 import org.simantics.layer0.utils.direct.GraphUtils;
\r
26 import org.simantics.sysdyn.SysdynResource;
\r
27 import org.simantics.sysdyn.representation.Variability;
\r
28 import org.simantics.sysdyn.ui.properties.widgets.ColumnKeys;
\r
29 import org.simantics.ui.SimanticsUI;
\r
31 public class ParameterModifierRule implements ModifierRule {
\r
34 public boolean isCompatible(Class<?> contentType) {
\r
35 return contentType.equals(Object.class);
\r
39 public Modifier getModifier(ReadGraph graph, Object content, String columnKey) throws DatabaseException {
\r
40 if(content instanceof ParameterNode && ColumnKeys.VALUE.equals(columnKey)) {
\r
41 final ParameterNode node = (ParameterNode) content;
\r
42 return new Modifier() {
\r
45 public String getValue() {
\r
46 Read<String> request =
\r
47 new Read<String>() {
\r
50 public String perform(ReadGraph graph) throws DatabaseException {
\r
51 String parameterExpression = ModuleParameterOverrideUtils.getParameterExpressionOrOverride(
\r
54 node.getIndependentVariable());
\r
56 return parameterExpression != null ? parameterExpression : "";
\r
61 return SimanticsUI.getSession().syncRequest(request);
\r
62 } catch (DatabaseException e) {
\r
63 e.printStackTrace();
\r
69 public String isValid(String label) {
\r
73 if(Variability.CONTINUOUS.equals(Variability.getVariability(node.getIndependentVariable(), label, false, node.getParentConfiguration())))
\r
80 public void modify(final String label) {
\r
81 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
\r
83 public void perform(WriteGraph graph) throws DatabaseException {
\r
84 SysdynResource sr = SysdynResource.getInstance(graph);
\r
85 Layer0 L0 = Layer0.getInstance(graph);
\r
87 // Remove possible old override
\r
88 for(Resource r : graph.syncRequest(new ObjectsWithType(node.getParent(), L0.ConsistsOf, sr.Module_ParameterOverride))) {
\r
89 if(node.getVariableResource().equals(graph.getPossibleObject(r, sr.Module_ParameterOverride_overriddenParameter))) {
\r
90 RemoverUtil.remove(graph, r);
\r
95 // Write the new override, if there is one
\r
96 if(label != null && !label.isEmpty()) {
\r
97 GraphUtils.create2(graph, sr.Module_ParameterOverride,
\r
98 sr.Module_ParameterOverride_overriddenParameter, node.getVariableResource(),
\r
99 sr.Module_ParameterOverride_overrideExpression, label,
\r
100 L0.PartOf, node.getParent()
\r