Skip to content
Snippets Groups Projects
Commit 83c7dec9 authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

some refactoring + new observer for executing an external groovy script

parent cf88cc5e
Branches
Tags
No related merge requests found
Showing
with 241 additions and 551 deletions
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <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.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="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
......
...@@ -57,4 +57,5 @@ Export-Package: com.thoughtworks.xstream, ...@@ -57,4 +57,5 @@ Export-Package: com.thoughtworks.xstream,
Bundle-ClassPath: lib/ext/xpp3_min-1.1.4c.jar, Bundle-ClassPath: lib/ext/xpp3_min-1.1.4c.jar,
lib/ext/xstream-1.3.1.jar, lib/ext/xstream-1.3.1.jar,
lib/ext/animation-1.2.0.jar, lib/ext/animation-1.2.0.jar,
. .,
lib/ext/groovy-all-1.8.6.jar
...@@ -5,5 +5,6 @@ bin.includes = plugin.xml,\ ...@@ -5,5 +5,6 @@ bin.includes = plugin.xml,\
.,\ .,\
icons/,\ icons/,\
schema/,\ schema/,\
lib/ lib/,\
lib/ext/groovy-all-1.8.6.jar
File added
...@@ -259,9 +259,8 @@ ...@@ -259,9 +259,8 @@
name="Switch Coordinates"> name="Switch Coordinates">
</observer> </observer>
<observer <observer
class="de.bmotionstudio.gef.editor.observer.CloneObserver" class="de.bmotionstudio.gef.editor.observer.ExternalObserverScript"
description="This observer clones the control depending on an expression rule" name="External Observer Script">
name="Clone Observer">
</observer> </observer>
</extension> </extension>
<extension <extension
...@@ -440,6 +439,33 @@ ...@@ -440,6 +439,33 @@
id="de.bmotionstudio.gef.editor.visualization"> id="de.bmotionstudio.gef.editor.visualization">
</control> </control>
</observer> </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> </include>
</extension> </extension>
</plugin> </plugin>
...@@ -6,40 +6,15 @@ ...@@ -6,40 +6,15 @@
package de.bmotionstudio.gef.editor; 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.model.BControl;
import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.IObserver;
import de.bmotionstudio.gef.editor.part.AppAbstractEditPart;
import de.bmotionstudio.gef.editor.scheduler.SchedulerEvent; 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 { public abstract class AbstractExpressionControl extends BindingObject {
private static final Pattern PATTERN = Pattern.compile("\\$(.+?)\\$");
protected transient String ID; protected transient String ID;
protected transient String name; protected transient String name;
protected transient String description; 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() { public String getID() {
return this.ID; return this.ID;
...@@ -53,220 +28,6 @@ public abstract class AbstractExpressionControl extends BindingObject { ...@@ -53,220 +28,6 @@ public abstract class AbstractExpressionControl extends BindingObject {
return this.description; 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} * This method is invoked before the expression control ({@link IObserver}
* or {@link SchedulerEvent}) will be deleted. * or {@link SchedulerEvent}) will be deleted.
......
...@@ -4,14 +4,17 @@ ...@@ -4,14 +4,17 @@
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * 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.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import de.bmotionstudio.gef.editor.animation.StaticListenerRegistry; import de.bmotionstudio.gef.editor.animation.StaticListenerRegistry;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.model.Visualization;
import de.prob.core.Animator; import de.prob.core.Animator;
import de.prob.core.IAnimationListener; import de.prob.core.IAnimationListener;
...@@ -87,22 +90,34 @@ public class Animation implements 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() { public void checkObserver() {
if (visualization.isRunning()) { if (visualization.isRunning()) {
Display.getDefault().asyncExec(new Runnable() { Display.getDefault().asyncExec(new Runnable() {
@Override @Override
public void run() { public void run() {
visualization.checkObserver(Animation.this); List<BControl> allBControls = new ArrayList<BControl>();
visualization.afterCheckObserver(Animation.this); allBControls.add(visualization);
collectAllBControls(allBControls, visualization);
for (BControl c : allBControls)
c.checkObserver(Animation.this);
} }
}); });
} }
} }
// public boolean checkObserverCallBack() {
// return visualization.checkObserverCallBack();
// }
public State getState() { public State getState() {
return currentState; return currentState;
} }
......
...@@ -36,7 +36,6 @@ import com.thoughtworks.xstream.XStream; ...@@ -36,7 +36,6 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.mapper.MapperWrapper; import com.thoughtworks.xstream.mapper.MapperWrapper;
import de.bmotionstudio.gef.editor.animation.StaticListenerRegistry; 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.internal.BMSConverter512;
import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.model.Visualization;
import de.prob.core.ILifecycleListener; import de.prob.core.ILifecycleListener;
......
...@@ -31,6 +31,7 @@ import com.thoughtworks.xstream.XStream; ...@@ -31,6 +31,7 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver; import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.mapper.MapperWrapper; import com.thoughtworks.xstream.mapper.MapperWrapper;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.BMotionEditorPlugin; import de.bmotionstudio.gef.editor.BMotionEditorPlugin;
import de.bmotionstudio.gef.editor.BMotionStudioEditor; import de.bmotionstudio.gef.editor.BMotionStudioEditor;
import de.bmotionstudio.gef.editor.ILanguageService; import de.bmotionstudio.gef.editor.ILanguageService;
......
...@@ -24,6 +24,7 @@ import org.eclipse.draw2d.geometry.Point; ...@@ -24,6 +24,7 @@ import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.IPropertySource;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.BMotionEditorPlugin; import de.bmotionstudio.gef.editor.BMotionEditorPlugin;
import de.bmotionstudio.gef.editor.IBControlService; import de.bmotionstudio.gef.editor.IBControlService;
...@@ -37,7 +38,6 @@ import de.bmotionstudio.gef.editor.attribute.BAttributeVisible; ...@@ -37,7 +38,6 @@ import de.bmotionstudio.gef.editor.attribute.BAttributeVisible;
import de.bmotionstudio.gef.editor.attribute.BAttributeWidth; import de.bmotionstudio.gef.editor.attribute.BAttributeWidth;
import de.bmotionstudio.gef.editor.attribute.BAttributeX; import de.bmotionstudio.gef.editor.attribute.BAttributeX;
import de.bmotionstudio.gef.editor.attribute.BAttributeY; 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.internal.BControlPropertySource;
import de.bmotionstudio.gef.editor.observer.IObserverListener; import de.bmotionstudio.gef.editor.observer.IObserverListener;
import de.bmotionstudio.gef.editor.observer.Observer; import de.bmotionstudio.gef.editor.observer.Observer;
...@@ -625,26 +625,6 @@ public abstract class BControl implements IAdaptable, Cloneable { ...@@ -625,26 +625,6 @@ public abstract class BControl implements IAdaptable, Cloneable {
con.checkObserver(animation); 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) { public void executeEvent(String eventID) {
......
...@@ -13,10 +13,10 @@ import org.eclipse.core.resources.IFile; ...@@ -13,10 +13,10 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.draw2d.PositionConstants; import org.eclipse.draw2d.PositionConstants;
import de.be4.classicalb.core.parser.exceptions.BException; 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.AttributeConstants;
import de.bmotionstudio.gef.editor.ButtonGroupHelper; import de.bmotionstudio.gef.editor.ButtonGroupHelper;
import de.bmotionstudio.gef.editor.IAddErrorListener; import de.bmotionstudio.gef.editor.IAddErrorListener;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.scheduler.PredicateOperation; import de.bmotionstudio.gef.editor.scheduler.PredicateOperation;
import de.prob.core.command.ExecuteOperationCommand; import de.prob.core.command.ExecuteOperationCommand;
import de.prob.core.command.GetOperationByPredicateCommand; 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; ...@@ -10,12 +10,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.be4.classicalb.core.parser.exceptions.BException; 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.AttributeConstants;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; 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.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverListenOperationByPredicate; import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverListenOperationByPredicate;
import de.bmotionstudio.gef.editor.scheduler.PredicateOperation; import de.bmotionstudio.gef.editor.scheduler.PredicateOperation;
import de.bmotionstudio.gef.editor.util.BMSUtil;
import de.prob.core.Animator; import de.prob.core.Animator;
import de.prob.core.command.GetOperationByPredicateCommand; import de.prob.core.command.GetOperationByPredicateCommand;
import de.prob.core.domainobjects.Operation; import de.prob.core.domainobjects.Operation;
...@@ -70,7 +71,7 @@ public class ListenOperationByPredicate extends Observer { ...@@ -70,7 +71,7 @@ public class ListenOperationByPredicate extends Observer {
if (animation.getCurrentStateOperations().containsKey(fOpName)) { if (animation.getCurrentStateOperations().containsKey(fOpName)) {
if (fPredicate.length() > 0) { if (fPredicate.length() > 0) {
fPredicate = parseControls(fPredicate, control); fPredicate = BMSUtil.parseControls(fPredicate, control);
} }
try { try {
...@@ -89,20 +90,21 @@ public class ListenOperationByPredicate extends Observer { ...@@ -89,20 +90,21 @@ public class ListenOperationByPredicate extends Observer {
Object attributeVal = pop.getValue(); Object attributeVal = pop.getValue();
if (pop.isExpressionMode()) { if (pop.isExpressionMode()) {
String strAtrVal = parseExpression( String strAtrVal = BMSUtil.parseExpression(
attributeVal.toString(), control, attributeVal.toString(), control,
animation, pop); animation);
String er = attributeObj.validateValue( String er = attributeObj.validateValue(
strAtrVal, null); strAtrVal, null);
if (er != null) { if (er != null) {
addError( // addError(
control, // control,
animation, // animation,
"You selected " // "You selected "
+ attributeObj.getName() // + attributeObj.getName()
+ " as attribute. There is a problem with your value: " // +
+ strAtrVal + " - Reason: " // " as attribute. There is a problem with your value: "
+ er); // + strAtrVal + " - Reason: "
// + er);
pop.setHasError(true); pop.setHasError(true);
} else { } else {
attributeVal = attributeObj attributeVal = attributeObj
...@@ -123,12 +125,12 @@ public class ListenOperationByPredicate extends Observer { ...@@ -123,12 +125,12 @@ public class ListenOperationByPredicate extends Observer {
} }
} catch (ProBException e) { } catch (ProBException e) {
addError(control, animation, // addError(control, animation,
"An error occurred while evaluating. Reason: " // "An error occurred while evaluating. Reason: "
+ e.getMessage()); // + e.getMessage());
} catch (BException e) { } catch (BException e) {
addError(control, animation, "Parsing error in: " // addError(control, animation, "Parsing error in: "
+ fPredicate + " Reason: " + e.getMessage()); // + fPredicate + " Reason: " + e.getMessage());
} }
} }
......
...@@ -11,7 +11,6 @@ import org.eclipse.draw2d.IFigure; ...@@ -11,7 +11,6 @@ import org.eclipse.draw2d.IFigure;
import de.bmotionstudio.gef.editor.AbstractExpressionControl; import de.bmotionstudio.gef.editor.AbstractExpressionControl;
import de.bmotionstudio.gef.editor.BMotionEditorPlugin; import de.bmotionstudio.gef.editor.BMotionEditorPlugin;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.model.BControl;
/** /**
...@@ -27,9 +26,8 @@ import de.bmotionstudio.gef.editor.model.BControl; ...@@ -27,9 +26,8 @@ import de.bmotionstudio.gef.editor.model.BControl;
* @author Lukas Ladenberger * @author Lukas Ladenberger
* *
*/ */
public abstract class Observer extends AbstractExpressionControl { public abstract class Observer extends AbstractExpressionControl implements
IObserver {
// private transient Boolean callBack = false;
public Observer() { public Observer() {
init(); init();
...@@ -37,7 +35,6 @@ public abstract class Observer extends AbstractExpressionControl { ...@@ -37,7 +35,6 @@ public abstract class Observer extends AbstractExpressionControl {
protected Object readResolve() { protected Object readResolve() {
init(); init();
// callBack = false;
return this; return this;
} }
...@@ -64,26 +61,6 @@ public abstract class Observer extends AbstractExpressionControl { ...@@ -64,26 +61,6 @@ public abstract class Observer extends AbstractExpressionControl {
return (Observer) super.clone(); 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. * Returns a corresponding wizard for the observer.
* *
...@@ -97,7 +74,4 @@ public abstract class Observer extends AbstractExpressionControl { ...@@ -97,7 +74,4 @@ public abstract class Observer extends AbstractExpressionControl {
return null; return null;
} }
public void afterCheck(Animation animation, BControl control) {
}
} }
...@@ -11,10 +11,11 @@ import java.util.List; ...@@ -11,10 +11,11 @@ import java.util.List;
import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.IFigure;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; 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.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverSetAttribute; import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverSetAttribute;
import de.bmotionstudio.gef.editor.util.BMSUtil;
public class SetAttribute extends Observer { public class SetAttribute extends Observer {
...@@ -45,8 +46,8 @@ public class SetAttribute extends Observer { ...@@ -45,8 +46,8 @@ public class SetAttribute extends Observer {
// First evaluate predicate (predicate field) // First evaluate predicate (predicate field)
String bolValue = "true"; String bolValue = "true";
if (obj.getEval().length() > 0) { if (obj.getEval().length() > 0) {
bolValue = parsePredicate(obj.getEval(), control, animation, bolValue = BMSUtil.parsePredicate(obj.getEval(), control,
obj); animation);
} }
if (!obj.hasError() && Boolean.valueOf(bolValue)) { if (!obj.hasError() && Boolean.valueOf(bolValue)) {
...@@ -59,17 +60,18 @@ public class SetAttribute extends Observer { ...@@ -59,17 +60,18 @@ public class SetAttribute extends Observer {
Object attributeVal = obj.getValue(); Object attributeVal = obj.getValue();
if (obj.isExpressionMode()) { if (obj.isExpressionMode()) {
String strAtrVal = parseExpression(attributeVal.toString(), String strAtrVal = BMSUtil.parseExpression(
control, animation, obj); attributeVal.toString(), control, animation);
String er = attributeObj.validateValue(strAtrVal, null); String er = attributeObj.validateValue(strAtrVal, null);
if (er != null) { if (er != null) {
addError( // addError(
control, // control,
animation, // animation,
"You selected " // "You selected "
+ attributeObj.getName() // + attributeObj.getName()
+ " as attribute. There is a problem with your value: " // +
+ strAtrVal + " - Reason: " + er); // " as attribute. There is a problem with your value: "
// + strAtrVal + " - Reason: " + er);
obj.setHasError(true); obj.setHasError(true);
} else { } else {
attributeVal = attributeObj.unmarshal(strAtrVal); attributeVal = attributeObj.unmarshal(strAtrVal);
......
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
package de.bmotionstudio.gef.editor.observer; package de.bmotionstudio.gef.editor.observer;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants; 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.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverSimpleValueDisplay; import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverSimpleValueDisplay;
import de.bmotionstudio.gef.editor.util.BMSUtil;
public class SimpleValueDisplay extends Observer { public class SimpleValueDisplay extends Observer {
...@@ -25,12 +26,12 @@ public class SimpleValueDisplay extends Observer { ...@@ -25,12 +26,12 @@ public class SimpleValueDisplay extends Observer {
// First evaluate predicate (predicate field) // First evaluate predicate (predicate field)
String bolValue = "true"; String bolValue = "true";
if (predicate != null && predicate.length() > 0) { if (predicate != null && predicate.length() > 0) {
bolValue = parsePredicate(predicate, bcontrol, animation, null); bolValue = BMSUtil.parsePredicate(predicate, bcontrol, animation);
} }
if (Boolean.valueOf(bolValue)) { if (Boolean.valueOf(bolValue)) {
String fEval = parseExpression(eval, bcontrol, animation, null); String fEval = BMSUtil.parseExpression(eval, bcontrol, animation);
if (!isOrgStringSet) { if (!isOrgStringSet) {
orgString = bcontrol.getAttributeValue( orgString = bcontrol.getAttributeValue(
......
...@@ -9,46 +9,23 @@ package de.bmotionstudio.gef.editor.observer; ...@@ -9,46 +9,23 @@ package de.bmotionstudio.gef.editor.observer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.animation.AnimationMove; 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.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverCSwitchCoordinates; import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverCSwitchCoordinates;
import de.bmotionstudio.gef.editor.util.BMSUtil;
public class SwitchChildCoordinates extends Observer { public class SwitchChildCoordinates extends Observer {
private List<ToggleObjectCoordinates> toggleObjects; private List<ToggleObjectCoordinates> toggleObjects;
// private transient AnimationListener animationListener;
// private transient Boolean checked;
public SwitchChildCoordinates() { public SwitchChildCoordinates() {
toggleObjects = new ArrayList<ToggleObjectCoordinates>(); toggleObjects = new ArrayList<ToggleObjectCoordinates>();
} }
public void check(final Animation animation, final BControl control) { 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 // Collect evaluate predicate objects in list
for (ToggleObjectCoordinates obj : toggleObjects) { for (ToggleObjectCoordinates obj : toggleObjects) {
...@@ -57,42 +34,42 @@ public class SwitchChildCoordinates extends Observer { ...@@ -57,42 +34,42 @@ public class SwitchChildCoordinates extends Observer {
// First evaluate predicate (predicate field) // First evaluate predicate (predicate field)
String bolValue = "true"; String bolValue = "true";
if (obj.getEval().length() > 0) { if (obj.getEval().length() > 0) {
bolValue = parsePredicate(obj.getEval(), control, animation, bolValue = BMSUtil.parsePredicate(obj.getEval(), control,
obj); animation);
} }
if (!obj.hasError() && Boolean.valueOf(bolValue)) { if (!obj.hasError() && Boolean.valueOf(bolValue)) {
// Handle control field // Handle control field
BControl toggleControl = null; BControl toggleControl = null;
String parsedControl = parseExpression(obj.getBcontrol(), String parsedControl = BMSUtil.parseExpression(
false, control, animation, obj, false); obj.getBcontrol(), control, animation, false);
toggleControl = control.getChild(parsedControl); toggleControl = control.getChild(parsedControl);
if (toggleControl == null) { if (toggleControl == null) {
obj.setHasError(true); obj.setHasError(true);
addError(control, animation, "No such control: " // addError(control, animation, "No such control: "
+ parsedControl); // + parsedControl);
} }
Integer parsedX = 0; Integer parsedX = 0;
Integer parsedY = 0; Integer parsedY = 0;
// Handle X field // Handle X field
try { try {
parsedX = Integer.valueOf(parseExpression(obj.getX(), parsedX = Integer.valueOf(BMSUtil.parseExpression(
false, control, animation, obj, false)); obj.getX(), control, animation));
} catch (NumberFormatException n) { } catch (NumberFormatException n) {
obj.setHasError(true); obj.setHasError(true);
addError(control, animation, "x is not a valid integer: " // addError(control, animation, "x is not a valid integer: "
+ n.getMessage()); // + n.getMessage());
} }
// Handle Y field // Handle Y field
try { try {
parsedY = Integer.valueOf(parseExpression(obj.getY(), parsedY = Integer.valueOf(BMSUtil.parseExpression(
false, control, animation, obj, false)); obj.getY(), control, animation));
} catch (NumberFormatException n) { } catch (NumberFormatException n) {
obj.setHasError(true); obj.setHasError(true);
addError(control, animation, "y is not a valid integer: " // addError(control, animation, "y is not a valid integer: "
+ n.getMessage()); // + n.getMessage());
} }
if (!obj.hasError()) { if (!obj.hasError()) {
......
...@@ -9,20 +9,17 @@ package de.bmotionstudio.gef.editor.observer; ...@@ -9,20 +9,17 @@ package de.bmotionstudio.gef.editor.observer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.animation.AnimationMove; 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.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverSwitchCoordinates; import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverSwitchCoordinates;
import de.bmotionstudio.gef.editor.util.BMSUtil;
public class SwitchCoordinates extends Observer { public class SwitchCoordinates extends Observer {
private List<ToggleObjectCoordinates> toggleObjects; private List<ToggleObjectCoordinates> toggleObjects;
// private transient AnimationListener animationListener;
// private transient Boolean checked;
public SwitchCoordinates() { public SwitchCoordinates() {
toggleObjects = new ArrayList<ToggleObjectCoordinates>(); toggleObjects = new ArrayList<ToggleObjectCoordinates>();
} }
...@@ -31,27 +28,6 @@ public class SwitchCoordinates extends Observer { ...@@ -31,27 +28,6 @@ public class SwitchCoordinates extends Observer {
boolean set = false; boolean set = false;
// if (checked == null)
// checked = true;
// if (animationListener == null) {
// animationListener = new AnimationListener() {
// public void animationStopped(AnimationEvent evt) {
// setCallBack(true);
// checked = true;
// // System.out
// // .println("Animation stopped ---> Set callback to TRUE!");
// }
//
// public void animationStarted(AnimationEvent evt) {
// setCallBack(false);
// checked = false;
// // System.out
// // .println("Animation started ---> Set callback to FALSE!");
// }
// };
// }
// Collect evaluate predicate objects in list // Collect evaluate predicate objects in list
for (ToggleObjectCoordinates obj : toggleObjects) { for (ToggleObjectCoordinates obj : toggleObjects) {
...@@ -60,8 +36,8 @@ public class SwitchCoordinates extends Observer { ...@@ -60,8 +36,8 @@ public class SwitchCoordinates extends Observer {
// First evaluate predicate (predicate field) // First evaluate predicate (predicate field)
String bolValue = "true"; String bolValue = "true";
if (obj.getEval().length() > 0) { if (obj.getEval().length() > 0) {
bolValue = parsePredicate(obj.getEval(), control, animation, bolValue = BMSUtil.parsePredicate(obj.getEval(), control,
obj); animation);
} }
if (!obj.hasError() && Boolean.valueOf(bolValue)) { if (!obj.hasError() && Boolean.valueOf(bolValue)) {
...@@ -70,21 +46,21 @@ public class SwitchCoordinates extends Observer { ...@@ -70,21 +46,21 @@ public class SwitchCoordinates extends Observer {
int parsedY = 0; int parsedY = 0;
// Handle X field // Handle X field
try { try {
parsedX = Integer.valueOf(parseExpression(obj.getX(), parsedX = Integer.valueOf(BMSUtil.parseExpression(
false, control, animation, obj, false)); obj.getX(), control, animation));
} catch (NumberFormatException n) { } catch (NumberFormatException n) {
obj.setHasError(true); obj.setHasError(true);
addError(control, animation, "x is not a valid integer: " // addError(control, animation, "x is not a valid integer: "
+ n.getMessage()); // + n.getMessage());
} }
// Handle Y field // Handle Y field
try { try {
parsedY = Integer.valueOf(parseExpression(obj.getY(), parsedY = Integer.valueOf(BMSUtil.parseExpression(
false, control, animation, obj, false)); obj.getY(), control, animation));
} catch (NumberFormatException n) { } catch (NumberFormatException n) {
obj.setHasError(true); obj.setHasError(true);
addError(control, animation, "y is not a valid integer: " // addError(control, animation, "y is not a valid integer: "
+ n.getMessage()); // + n.getMessage());
} }
int currentX = Integer.valueOf(control.getAttributeValue( int currentX = Integer.valueOf(control.getAttributeValue(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment