Skip to content
Snippets Groups Projects
Commit 3e39d021 authored by Jens Bendisposto's avatar Jens Bendisposto
Browse files

Merge remote-tracking branch 'origin/develop' into develop

parents d7423698 83c7dec9
No related branches found
No related tags found
No related merge requests found
Showing
with 233 additions and 519 deletions
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/ext/groovy-all-1.8.6.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
......
......@@ -6,14 +6,14 @@ Bundle-Version: 5.3.1.qualifier
Bundle-Activator: de.bmotionstudio.gef.editor.BMotionEditorPlugin
Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ui.views;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ui.views;bundle-version="[3.5.0,4.0.0)";visibility:=reexport,
org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.jface;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.databinding;bundle-version="[1.2.0,2.0.0)",
org.eclipse.jface.databinding;bundle-version="[1.2.1,2.0.0)",
org.eclipse.core.databinding.beans;bundle-version="[1.1.1,2.0.0)",
org.eclipse.gef;bundle-version="[3.7.0,4.0.0)",
de.prob.core;bundle-version="[9.2.0,9.3.0)",
org.eclipse.gef;bundle-version="[3.7.0,4.0.0)";visibility:=reexport,
de.prob.core;bundle-version="[9.2.0,9.3.0)";visibility:=reexport,
org.eventb.core;bundle-version="[2.1.0,2.6.0)"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
......@@ -57,4 +57,5 @@ Export-Package: com.thoughtworks.xstream,
Bundle-ClassPath: lib/ext/xpp3_min-1.1.4c.jar,
lib/ext/xstream-1.3.1.jar,
lib/ext/animation-1.2.0.jar,
.
.,
lib/ext/groovy-all-1.8.6.jar
......@@ -5,5 +5,6 @@ bin.includes = plugin.xml,\
.,\
icons/,\
schema/,\
lib/
lib/,\
lib/ext/groovy-all-1.8.6.jar
File added
......@@ -259,9 +259,8 @@
name="Switch Coordinates">
</observer>
<observer
class="de.bmotionstudio.gef.editor.observer.CloneObserver"
description="This observer clones the control depending on an expression rule"
name="Clone Observer">
class="de.bmotionstudio.gef.editor.observer.ExternalObserverScript"
name="External Observer Script">
</observer>
</extension>
<extension
......@@ -440,6 +439,33 @@
id="de.bmotionstudio.gef.editor.visualization">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.ExternalObserverScript">
<control
id="de.bmotionstudio.gef.editor.image">
</control>
<control
id="de.bmotionstudio.gef.editor.button">
</control>
<control
id="de.bmotionstudio.gef.editor.composite">
</control>
<control
id="de.bmotionstudio.gef.editor.text">
</control>
<control
id="de.bmotionstudio.gef.editor.shape">
</control>
<control
id="de.bmotionstudio.gef.editor.radiobutton">
</control>
<control
id="de.bmotionstudio.gef.editor.checkbox">
</control>
<control
id="de.bmotionstudio.gef.editor.connection">
</control>
</observer>
</include>
</extension>
</plugin>
......@@ -115,7 +115,7 @@
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="de.bmotionstudio.gef.editor.service.AbstractBControlService:de.bmotionstudio.gef.editor.IBControlService"/>
<meta.attribute kind="java" basedOn="de.bmotionstudio.gef.editor.AbstractBControlService:de.bmotionstudio.gef.editor.IBControlService"/>
</appInfo>
</annotation>
</attribute>
......
......@@ -6,40 +6,15 @@
package de.bmotionstudio.gef.editor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.be4.classicalb.core.parser.exceptions.BException;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.ObserverEvalObject;
import de.bmotionstudio.gef.editor.part.AppAbstractEditPart;
import de.bmotionstudio.gef.editor.observer.IObserver;
import de.bmotionstudio.gef.editor.scheduler.SchedulerEvent;
import de.prob.core.command.EvaluationGetValuesCommand;
import de.prob.core.command.GetOperationByPredicateCommand;
import de.prob.core.domainobjects.EvaluationElement;
import de.prob.core.domainobjects.EvaluationStateElement;
import de.prob.core.domainobjects.Operation;
import de.prob.core.domainobjects.State;
import de.prob.exceptions.ProBException;
import de.prob.parserbase.ProBParseException;
public abstract class AbstractExpressionControl extends BindingObject {
private static final Pattern PATTERN = Pattern.compile("\\$(.+?)\\$");
protected transient String ID;
protected transient String name;
protected transient String description;
protected transient Boolean hasError = false;
private transient static final String DEFAULT_PREDICATE = "1=1";
private transient static final String DEFAULT_BOOLVAL = "true";
public String getID() {
return this.ID;
......@@ -53,220 +28,6 @@ public abstract class AbstractExpressionControl extends BindingObject {
return this.description;
}
public void addError(BControl control, Animation animation, String message) {
// TODO: Implement me!
// History history = animation.getAnimator().getHistory();
// int currentHistoryPos = history.getCurrentPosition();
// control.getVisualization().addError(
// new ErrorMessage(history.getAllItems()[currentHistoryPos - 1],
// this, control, message));
}
/**
* tbd
*
* @param expressionString
* @param control
* @param animation
* @param obj
* @return true or false
*/
protected String parsePredicate(String expressionString, BControl control,
Animation animation, ObserverEvalObject obj) {
if (expressionString == null || expressionString.trim().length() == 0)
return DEFAULT_BOOLVAL;
return parseExpression(expressionString, true, control, animation, obj,
true);
}
protected String parseExpression(String expressionString, BControl control,
Animation animation, ObserverEvalObject obj) {
return parseExpression(expressionString, true, control, animation, obj,
false);
}
protected String parseExpression(final String expressionString,
final boolean evalSingleExpression, final BControl control,
final Animation animation, final ObserverEvalObject obj,
final boolean isPredicate) {
Map<EvaluationElement, String> evaluationKeys = new HashMap<EvaluationElement, String>();
boolean hasSubExpressions = false;
hasError = false;
// Find expressions and collect ExpressionEvalElements
final Matcher matcher = PATTERN.matcher(expressionString);
while (matcher.find()) {
final String subExpr = matcher.group(1);
collectEvalElements(subExpr, "$" + subExpr + "$", isPredicate,
animation, control, evaluationKeys);
hasSubExpressions = true;
}
// We have only one expression (without "$$")
if (!hasSubExpressions) {
if (evalSingleExpression) {
collectEvalElements(expressionString, expressionString,
isPredicate, animation, control, evaluationKeys);
} else {
return expressionString;
}
}
// Try to get expression results and parse expression string
Collection<EvaluationStateElement> resultList;
try {
resultList = getExpressionValues(control, animation,
new ArrayList<EvaluationElement>(evaluationKeys.keySet()));
} catch (ProBException e) {
resultList = Collections.emptyList();
hasError = true;
}
// If getting ExpressionEvalElement throws no error, try to get
// expression results
String result = expressionString;
if (!hasError) {
for (EvaluationStateElement stateElement : resultList) {
final EvaluationElement evalElement = stateElement.getElement();
final String text;
if (isPredicate) {
text = stateElement.getResult().isPredicateTrue() ? "true"
: "false";
} else {
text = stateElement.getText();
}
final String subExpression = evaluationKeys.get(evalElement);
result = result.replace(subExpression, text);
}
} else {
if (obj != null)
obj.setHasError(true);
addError(control, animation,
"An error occurred while evaluating expression\\predicate value: \""
+ expressionString
+ "\". Please check your expression\\predicate.");
}
return result;
}
private void collectEvalElements(final String subexpression,
final String key, final boolean isPredicate,
final Animation animation, final BControl control,
final Map<EvaluationElement, String> evaluationKeys) {
final String parsedSubexpr = parseControls(subexpression, control);
EvaluationElement evalElement;
try {
evalElement = animation.getCachedEvalElement(parsedSubexpr,
isPredicate);
evaluationKeys.put(evalElement, key);
} catch (UnsupportedOperationException e) {
hasError = true;
} catch (ProBException e) {
hasError = true;
} catch (ProBParseException e) {
addError(control, animation, e.getMessage());
hasError = true;
}
}
protected List<Operation> parseOperation(final String opName,
String opPredicate, int opRandom, final Animation animation,
final String currentState, final BControl control) {
try {
if (opPredicate != null && opPredicate.length() > 0)
opPredicate = parseControls(opPredicate, control);
else
opPredicate = DEFAULT_PREDICATE;
if (opRandom < 1)
opRandom = 1;
return GetOperationByPredicateCommand.getOperations(
animation.getAnimator(), currentState, opName, opPredicate,
opRandom);
} catch (ProBException e) {
addError(control, animation, e.getMessage());
hasError = true;
} catch (BException e) {
addError(control, animation, e.getMessage());
hasError = true;
}
return null;
}
/**
* This method matches the pattern <i>(\\w+)</i>. This means that the method
* matches alphanumeric words in the given predicate or expression string.
* The method focuses on control id's or the key word <i>this</i>. In the
* first case the method tries to find a reference on the corresponding
* control in the visualization regarding to the matched control id. In the
* second case the method creates a reference to the control which contains
* the observer. In addition in both cases the method returns the value of
* {@link AppAbstractEditPart#getValueOfData()} of the located
* {@link BControl}.
*
* @param expressionString
* @param control
* @return the parsed expression
*/
protected String parseControls(String expressionString, BControl control) {
List<String> allControlIDs = control.getVisualization()
.getAllBControlNames();
// Search for control ids
Pattern cPattern = Pattern.compile("(\\w+)");
Matcher cMatcher = cPattern.matcher(expressionString);
while (cMatcher.find()) {
String controlID = cMatcher.group(1);
if (controlID.equals("this")) {
expressionString = expressionString.replace(controlID, control
.getAttributeValue(AttributeConstants.ATTRIBUTE_CUSTOM)
.toString());
} else if (allControlIDs.contains(controlID)) {
expressionString = expressionString.replace(controlID, control
.getVisualization().getBControl(controlID)
.getValueOfData());
} else {
// TODO: Return error if no control exists
}
}
return expressionString;
}
protected Collection<EvaluationStateElement> getExpressionValues(
final BControl control, final Animation animation,
final Collection<EvaluationElement> evalElements)
throws ProBException {
final State state = animation.getAnimator().getCurrentState();
// TODO[DP, 11.04.2011] Add an animator to the parameters!
final Collection<EvaluationStateElement> values = EvaluationGetValuesCommand
.getValuesForExpressionsCached(state, evalElements);
return values;
}
/**
* This method is invoked before the expression control ({@link IObserver}
* or {@link SchedulerEvent}) will be deleted.
......
......@@ -4,14 +4,17 @@
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.internal;
package de.bmotionstudio.gef.editor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.swt.widgets.Display;
import de.bmotionstudio.gef.editor.animation.StaticListenerRegistry;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.model.Visualization;
import de.prob.core.Animator;
import de.prob.core.IAnimationListener;
......@@ -87,22 +90,34 @@ public class Animation implements IAnimationListener {
}
}
public void collectAllBControls(List<BControl> allBControls,
BControl control) {
if (control.getChildrenArray().isEmpty())
return;
for (BControl bcontrol : control.getChildrenArray()) {
allBControls.add(bcontrol);
collectAllBControls(allBControls, bcontrol);
}
}
public void checkObserver() {
if (visualization.isRunning()) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
visualization.checkObserver(Animation.this);
visualization.afterCheckObserver(Animation.this);
List<BControl> allBControls = new ArrayList<BControl>();
allBControls.add(visualization);
collectAllBControls(allBControls, visualization);
for (BControl c : allBControls)
c.checkObserver(Animation.this);
}
});
}
}
// public boolean checkObserverCallBack() {
// return visualization.checkObserverCallBack();
// }
public State getState() {
return currentState;
}
......
......@@ -36,7 +36,6 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.mapper.MapperWrapper;
import de.bmotionstudio.gef.editor.animation.StaticListenerRegistry;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.internal.BMSConverter512;
import de.bmotionstudio.gef.editor.model.Visualization;
import de.prob.core.ILifecycleListener;
......
......@@ -31,6 +31,7 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.mapper.MapperWrapper;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.BMotionEditorPlugin;
import de.bmotionstudio.gef.editor.BMotionStudioEditor;
import de.bmotionstudio.gef.editor.ILanguageService;
......
......@@ -24,6 +24,7 @@ import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.ui.views.properties.IPropertySource;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.BMotionEditorPlugin;
import de.bmotionstudio.gef.editor.IBControlService;
......@@ -37,7 +38,6 @@ import de.bmotionstudio.gef.editor.attribute.BAttributeVisible;
import de.bmotionstudio.gef.editor.attribute.BAttributeWidth;
import de.bmotionstudio.gef.editor.attribute.BAttributeX;
import de.bmotionstudio.gef.editor.attribute.BAttributeY;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.internal.BControlPropertySource;
import de.bmotionstudio.gef.editor.observer.IObserverListener;
import de.bmotionstudio.gef.editor.observer.Observer;
......@@ -625,26 +625,6 @@ public abstract class BControl implements IAdaptable, Cloneable {
con.checkObserver(animation);
}
// Check Observers of children
if (getChildrenArray().size() > 0) {
for (BControl bcontrol : getChildrenArray()) {
bcontrol.checkObserver(animation);
}
}
}
public void afterCheckObserver(Animation animation) {
// Check all Observers
for (Observer observer : getObservers().values()) {
observer.afterCheck(animation, this);
}
// Check Observers of children
if (getChildrenArray().size() > 0) {
for (BControl bcontrol : getChildrenArray()) {
bcontrol.afterCheckObserver(animation);
}
}
}
public void executeEvent(String eventID) {
......
......@@ -13,10 +13,10 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.draw2d.PositionConstants;
import de.be4.classicalb.core.parser.exceptions.BException;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.ButtonGroupHelper;
import de.bmotionstudio.gef.editor.IAddErrorListener;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.scheduler.PredicateOperation;
import de.prob.core.command.ExecuteOperationCommand;
import de.prob.core.command.GetOperationByPredicateCommand;
......
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.observer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverClone;
public class CloneObserver extends Observer {
private transient Collection<BControl> clonedControls;
private List<ObserverCloneObject> observerCloneObjects;
private boolean newControls = false;
private int oldInt = 0;
public CloneObserver() {
observerCloneObjects = new ArrayList<ObserverCloneObject>();
}
@Override
public void check(Animation animation, final BControl control) {
for (ObserverCloneObject obj : observerCloneObjects) {
final BControl toCloneControl = animation.getVisualization()
.getBControl(obj.getControlId());
String evalString = obj.getEval();
String fEval = parseExpression(evalString, control, animation, obj);
if (toCloneControl == null) {
addError(control, animation,
"No control found with id: " + obj.getControlId());
} else {
int clones = 0;
try {
clones = Integer.parseInt(fEval);
} catch (NumberFormatException e) {
addError(control, animation, "The expression: " + fEval
+ " should return an integer value!");
}
if (oldInt == clones) {
newControls = false;
} else {
for (BControl c : getClonedControls()) {
control.removeChild(c);
}
getClonedControls().clear();
for (int i = obj.getCounter(); i < clones
+ obj.getCounter(); i++) {
try {
BControl clonedControl = toCloneControl.clone();
clonedControl.setAttributeValue(
AttributeConstants.ATTRIBUTE_CUSTOM, i);
getClonedControls().add(clonedControl);
} catch (CloneNotSupportedException e) {
}
}
oldInt = clones;
newControls = true;
}
}
}
}
@Override
public ObserverWizard getWizard(BControl control) {
return new WizardObserverClone(control, this);
}
public List<ObserverCloneObject> getObserverCloneObjects() {
return observerCloneObjects;
}
public void setObserverCloneObjects(
List<ObserverCloneObject> observerCloneObjects) {
this.observerCloneObjects = observerCloneObjects;
}
public Observer clone() throws CloneNotSupportedException {
CloneObserver clonedObserver = (CloneObserver) super.clone();
List<ObserverCloneObject> list = new ArrayList<ObserverCloneObject>();
for (ObserverCloneObject obj : getObserverCloneObjects()) {
list.add(obj.clone());
}
clonedObserver.setObserverCloneObjects(list);
return clonedObserver;
}
@Override
public void afterCheck(final Animation animation, final BControl control) {
if (newControls) {
synchronized (control) {
for (BControl c : clonedControls) {
control.addChild(c);
c.checkObserver(animation);
}
}
}
}
public Collection<BControl> getClonedControls() {
if (clonedControls == null)
clonedControls = new ArrayList<BControl>();
return clonedControls;
}
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.observer;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import java.io.File;
import java.io.IOException;
import org.codehaus.groovy.control.CompilationFailedException;
import org.eclipse.core.resources.IFile;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverExternalObserverScript;
public class ExternalObserverScript extends Observer {
public static String ID = "de.bmotionstudio.gef.editor.observer.ExternalObserverScript";
private transient GroovyObject groovyObject;
private String scriptPath;
// private String language;
@Override
public void check(Animation animation, BControl control) {
try {
if (groovyObject == null) {
IFile pFile = control.getVisualization().getProjectFile();
String myPath = (pFile.getProject().getLocation() + "/" + scriptPath)
.replace("file:", "");
ClassLoader parent = getClass().getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);
Class<?> groovyClass;
groovyClass = loader.parseClass(new File(myPath));
// let's call some method on an instance
groovyObject = (GroovyObject) groovyClass.newInstance();
}
Object[] args = { animation, control };
groovyObject.invokeMethod("check", args);
} catch (CompilationFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
@Override
public ObserverWizard getWizard(BControl control) {
return new WizardObserverExternalObserverScript(control, this);
}
public String getScriptPath() {
return scriptPath;
}
public void setScriptPath(String scriptPath) {
this.scriptPath = scriptPath;
}
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.observer;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
public interface IObserver {
/**
* This method is called after every state change. The method tells the
* control how it has to look like and how to behave.
*
* @param animation
* The running animation
* @param bcontrol
* The corresponding control
* @throws BMotionObserverException
*/
public void check(Animation animation, BControl control);
}
......@@ -10,12 +10,13 @@ import java.util.ArrayList;
import java.util.List;
import de.be4.classicalb.core.parser.exceptions.BException;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverListenOperationByPredicate;
import de.bmotionstudio.gef.editor.scheduler.PredicateOperation;
import de.bmotionstudio.gef.editor.util.BMSUtil;
import de.prob.core.Animator;
import de.prob.core.command.GetOperationByPredicateCommand;
import de.prob.core.domainobjects.Operation;
......@@ -70,7 +71,7 @@ public class ListenOperationByPredicate extends Observer {
if (animation.getCurrentStateOperations().containsKey(fOpName)) {
if (fPredicate.length() > 0) {
fPredicate = parseControls(fPredicate, control);
fPredicate = BMSUtil.parseControls(fPredicate, control);
}
try {
......@@ -89,20 +90,21 @@ public class ListenOperationByPredicate extends Observer {
Object attributeVal = pop.getValue();
if (pop.isExpressionMode()) {
String strAtrVal = parseExpression(
String strAtrVal = BMSUtil.parseExpression(
attributeVal.toString(), control,
animation, pop);
animation);
String er = attributeObj.validateValue(
strAtrVal, null);
if (er != null) {
addError(
control,
animation,
"You selected "
+ attributeObj.getName()
+ " as attribute. There is a problem with your value: "
+ strAtrVal + " - Reason: "
+ er);
// addError(
// control,
// animation,
// "You selected "
// + attributeObj.getName()
// +
// " as attribute. There is a problem with your value: "
// + strAtrVal + " - Reason: "
// + er);
pop.setHasError(true);
} else {
attributeVal = attributeObj
......@@ -123,12 +125,12 @@ public class ListenOperationByPredicate extends Observer {
}
} catch (ProBException e) {
addError(control, animation,
"An error occurred while evaluating. Reason: "
+ e.getMessage());
// addError(control, animation,
// "An error occurred while evaluating. Reason: "
// + e.getMessage());
} catch (BException e) {
addError(control, animation, "Parsing error in: "
+ fPredicate + " Reason: " + e.getMessage());
// addError(control, animation, "Parsing error in: "
// + fPredicate + " Reason: " + e.getMessage());
}
}
......
......@@ -11,7 +11,6 @@ import org.eclipse.draw2d.IFigure;
import de.bmotionstudio.gef.editor.AbstractExpressionControl;
import de.bmotionstudio.gef.editor.BMotionEditorPlugin;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
/**
......@@ -27,9 +26,8 @@ import de.bmotionstudio.gef.editor.model.BControl;
* @author Lukas Ladenberger
*
*/
public abstract class Observer extends AbstractExpressionControl {
// private transient Boolean callBack = false;
public abstract class Observer extends AbstractExpressionControl implements
IObserver {
public Observer() {
init();
......@@ -37,7 +35,6 @@ public abstract class Observer extends AbstractExpressionControl {
protected Object readResolve() {
init();
// callBack = false;
return this;
}
......@@ -64,26 +61,6 @@ public abstract class Observer extends AbstractExpressionControl {
return (Observer) super.clone();
}
// public void setCallBack(Boolean callBack) {
// this.callBack = callBack;
// }
//
// public Boolean isCallBack() {
// return callBack;
// }
/**
* This method is called after every state change. The method tells the
* control how it has to look like and how to behave.
*
* @param animation
* The running animation
* @param bcontrol
* The corresponding control
* @throws BMotionObserverException
*/
public abstract void check(Animation animation, BControl control);
/**
* Returns a corresponding wizard for the observer.
*
......@@ -97,7 +74,4 @@ public abstract class Observer extends AbstractExpressionControl {
return null;
}
public void afterCheck(Animation animation, BControl control) {
}
}
......@@ -11,10 +11,11 @@ import java.util.List;
import org.eclipse.draw2d.IFigure;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverSetAttribute;
import de.bmotionstudio.gef.editor.util.BMSUtil;
public class SetAttribute extends Observer {
......@@ -45,8 +46,8 @@ public class SetAttribute extends Observer {
// First evaluate predicate (predicate field)
String bolValue = "true";
if (obj.getEval().length() > 0) {
bolValue = parsePredicate(obj.getEval(), control, animation,
obj);
bolValue = BMSUtil.parsePredicate(obj.getEval(), control,
animation);
}
if (!obj.hasError() && Boolean.valueOf(bolValue)) {
......@@ -59,17 +60,18 @@ public class SetAttribute extends Observer {
Object attributeVal = obj.getValue();
if (obj.isExpressionMode()) {
String strAtrVal = parseExpression(attributeVal.toString(),
control, animation, obj);
String strAtrVal = BMSUtil.parseExpression(
attributeVal.toString(), control, animation);
String er = attributeObj.validateValue(strAtrVal, null);
if (er != null) {
addError(
control,
animation,
"You selected "
+ attributeObj.getName()
+ " as attribute. There is a problem with your value: "
+ strAtrVal + " - Reason: " + er);
// addError(
// control,
// animation,
// "You selected "
// + attributeObj.getName()
// +
// " as attribute. There is a problem with your value: "
// + strAtrVal + " - Reason: " + er);
obj.setHasError(true);
} else {
attributeVal = attributeObj.unmarshal(strAtrVal);
......
......@@ -6,10 +6,11 @@
package de.bmotionstudio.gef.editor.observer;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverSimpleValueDisplay;
import de.bmotionstudio.gef.editor.util.BMSUtil;
public class SimpleValueDisplay extends Observer {
......@@ -25,12 +26,12 @@ public class SimpleValueDisplay extends Observer {
// First evaluate predicate (predicate field)
String bolValue = "true";
if (predicate != null && predicate.length() > 0) {
bolValue = parsePredicate(predicate, bcontrol, animation, null);
bolValue = BMSUtil.parsePredicate(predicate, bcontrol, animation);
}
if (Boolean.valueOf(bolValue)) {
String fEval = parseExpression(eval, bcontrol, animation, null);
String fEval = BMSUtil.parseExpression(eval, bcontrol, animation);
if (!isOrgStringSet) {
orgString = bcontrol.getAttributeValue(
......
......@@ -9,46 +9,23 @@ package de.bmotionstudio.gef.editor.observer;
import java.util.ArrayList;
import java.util.List;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.animation.AnimationMove;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverCSwitchCoordinates;
import de.bmotionstudio.gef.editor.util.BMSUtil;
public class SwitchChildCoordinates extends Observer {
private List<ToggleObjectCoordinates> toggleObjects;
// private transient AnimationListener animationListener;
// private transient Boolean checked;
public SwitchChildCoordinates() {
toggleObjects = new ArrayList<ToggleObjectCoordinates>();
}
public void check(final Animation animation, final BControl control) {
// if (checked == null)
// checked = true;
//
// if (!checked)
// return;
//
// if (animationListener == null) {
// animationListener = new AnimationListener() {
// public void animationStopped(AnimationEvent evt) {
// setCallBack(true);
// // checked = true;
// }
//
// public void animationStarted(AnimationEvent evt) {
// setCallBack(false);
// checked = false;
// }
// };
// }
// Collect evaluate predicate objects in list
for (ToggleObjectCoordinates obj : toggleObjects) {
......@@ -57,42 +34,42 @@ public class SwitchChildCoordinates extends Observer {
// First evaluate predicate (predicate field)
String bolValue = "true";
if (obj.getEval().length() > 0) {
bolValue = parsePredicate(obj.getEval(), control, animation,
obj);
bolValue = BMSUtil.parsePredicate(obj.getEval(), control,
animation);
}
if (!obj.hasError() && Boolean.valueOf(bolValue)) {
// Handle control field
BControl toggleControl = null;
String parsedControl = parseExpression(obj.getBcontrol(),
false, control, animation, obj, false);
String parsedControl = BMSUtil.parseExpression(
obj.getBcontrol(), control, animation, false);
toggleControl = control.getChild(parsedControl);
if (toggleControl == null) {
obj.setHasError(true);
addError(control, animation, "No such control: "
+ parsedControl);
// addError(control, animation, "No such control: "
// + parsedControl);
}
Integer parsedX = 0;
Integer parsedY = 0;
// Handle X field
try {
parsedX = Integer.valueOf(parseExpression(obj.getX(),
false, control, animation, obj, false));
parsedX = Integer.valueOf(BMSUtil.parseExpression(
obj.getX(), control, animation));
} catch (NumberFormatException n) {
obj.setHasError(true);
addError(control, animation, "x is not a valid integer: "
+ n.getMessage());
// addError(control, animation, "x is not a valid integer: "
// + n.getMessage());
}
// Handle Y field
try {
parsedY = Integer.valueOf(parseExpression(obj.getY(),
false, control, animation, obj, false));
parsedY = Integer.valueOf(BMSUtil.parseExpression(
obj.getY(), control, animation));
} catch (NumberFormatException n) {
obj.setHasError(true);
addError(control, animation, "y is not a valid integer: "
+ n.getMessage());
// addError(control, animation, "y is not a valid integer: "
// + n.getMessage());
}
if (!obj.hasError()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment