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

working on csp support

parent 5fbed712
Branches
No related tags found
No related merge requests found
Showing
with 761 additions and 10 deletions
...@@ -61,6 +61,21 @@ ...@@ -61,6 +61,21 @@
name="Observer" name="Observer"
restorable="true"> restorable="true">
</view> </view>
<view
allowMultiple="true"
category="de.bmotionstudio.views"
class="de.bmotionstudio.gef.editor.VisualizationView"
id="de.bmotionstudio.gef.editor.VisualizationView"
name="Visualization"
restorable="true">
</view>
<view
category="de.bmotionstudio.views"
class="de.bmotionstudio.gef.editor.BMSPaletteView"
id="de.bmotionstudio.gef.editor.PaletteView"
name="Palette"
restorable="true">
</view>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.menus"> point="org.eclipse.ui.menus">
...@@ -357,6 +372,10 @@ ...@@ -357,6 +372,10 @@
class="de.bmotionstudio.gef.editor.observer.ColumnObserver" class="de.bmotionstudio.gef.editor.observer.ColumnObserver"
name="Column Observer"> name="Column Observer">
</observer> </observer>
<observer
class="de.bmotionstudio.gef.editor.observer.CSPEventObserver"
name="CSP Event Observer">
</observer>
</extension> </extension>
<extension <extension
point="de.bmotionstudio.gef.editor.schedulerEvent"> point="de.bmotionstudio.gef.editor.schedulerEvent">
...@@ -397,6 +416,10 @@ ...@@ -397,6 +416,10 @@
service="de.bmotionstudio.gef.editor.eventb.EventBLanguageService" service="de.bmotionstudio.gef.editor.eventb.EventBLanguageService"
id="EventB"> id="EventB">
</language> </language>
<language
id="CSP"
service="de.bmotionstudio.gef.editor.csp.CSPLanguageService">
</language>
</extension> </extension>
<extension <extension
point="de.bmotionstudio.gef.editor.includeObserver"> point="de.bmotionstudio.gef.editor.includeObserver">
...@@ -652,5 +675,20 @@ ...@@ -652,5 +675,20 @@
</observer> </observer>
</control> </control>
</include> </include>
<include
language="CSP">
<control
id="de.bmotionstudio.gef.editor.rectangle">
<observer
id="de.bmotionstudio.gef.editor.observer.CSPEventObserver">
</observer>
</control>
<control
id="de.bmotionstudio.gef.editor.tank">
<observer
id="de.bmotionstudio.gef.editor.observer.CSPEventObserver">
</observer>
</control>
</include>
</extension> </extension>
</plugin> </plugin>
...@@ -30,6 +30,8 @@ public class Animation implements IAnimationListener { ...@@ -30,6 +30,8 @@ public class Animation implements IAnimationListener {
private Animator animator; private Animator animator;
private Operation lastExecutedOperation;
private final Map<String, Operation> currentStateOperations; private final Map<String, Operation> currentStateOperations;
private final Map<String, EvaluationElement> cachedEvalElements = new HashMap<String, EvaluationElement>(); private final Map<String, EvaluationElement> cachedEvalElements = new HashMap<String, EvaluationElement>();
...@@ -58,19 +60,18 @@ public class Animation implements IAnimationListener { ...@@ -58,19 +60,18 @@ public class Animation implements IAnimationListener {
@Override @Override
public void currentStateChanged(State currentState, Operation operation) { public void currentStateChanged(State currentState, Operation operation) {
this.lastExecutedOperation = operation;
// set new state and remember old state, if possible // set new state and remember old state, if possible
setNewState(currentState); setNewState(currentState);
updateCachedExpressions(currentState); // updateCachedExpressions(currentState);
if (currentState.isInitialized()) { // if (currentState.isInitialized()) {
if (animator == null) { if (animator == null) {
animator = Animator.getAnimator(); animator = Animator.getAnimator();
} }
if (!operation.getName().equals("start_cspm_MAIN"))
checkObserver(); checkObserver();
// }
}
} }
/** /**
...@@ -175,4 +176,8 @@ public class Animation implements IAnimationListener { ...@@ -175,4 +176,8 @@ public class Animation implements IAnimationListener {
return currentStateOperations; return currentStateOperations;
} }
public Operation getLastExecutedOperation() {
return lastExecutedOperation;
}
} }
package de.bmotionstudio.gef.editor;
import org.eclipse.gef.ui.views.palette.PaletteView;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
public class BMSPaletteView extends PaletteView {
@Override
protected IWorkbenchPart getBootstrapPart() {
IWorkbenchPage page = getSite().getPage();
if (page != null)
return page.getActiveEditor();
return null;
}
// public BMSPaletteView() {
// // TODO Auto-generated constructor stub
// }
//
// @Override
// public void createPartControl(Composite parent) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void setFocus() {
// // TODO Auto-generated method stub
//
// }
}
package de.bmotionstudio.gef.editor;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.gef.EditDomain;
import org.eclipse.gef.editparts.ScalableRootEditPart;
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.mapper.MapperWrapper;
import de.bmotionstudio.gef.editor.model.Visualization;
import de.bmotionstudio.gef.editor.part.BMSEditPartFactory;
public class VisualizationView extends ViewPart {
@Override
public void createPartControl(Composite parent) {
ScrollingGraphicalViewer scrollingGraphicalViewer = new ScrollingGraphicalViewer();
scrollingGraphicalViewer.createControl(parent);
ScalableRootEditPart rootEditPart = new ScalableRootEditPart();
rootEditPart.setViewer(scrollingGraphicalViewer);
scrollingGraphicalViewer.setRootEditPart(rootEditPart);
scrollingGraphicalViewer.setEditPartFactory(new BMSEditPartFactory());
scrollingGraphicalViewer.setEditDomain(new EditDomain());
IFile file = ResourcesPlugin.getWorkspace().getRoot()
.getProject("Farmer").getFile("Farmer.bmso");
try {
InputStream inputStream = file.getContents();
XStream xstream = new XStream() {
@Override
protected MapperWrapper wrapMapper(final MapperWrapper next) {
return new MapperWrapper(next) {
@Override
public boolean shouldSerializeMember(
@SuppressWarnings("rawtypes") final Class definedIn,
final String fieldName) {
if (definedIn == Object.class)
return false;
return super.shouldSerializeMember(definedIn,
fieldName);
}
};
}
};
BMotionEditorPlugin.setAliases(xstream);
Visualization visualization = (Visualization) xstream
.fromXML(inputStream);
visualization.setProjectFile(file);
scrollingGraphicalViewer.setContents(visualization);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
}
package de.bmotionstudio.gef.editor.csp;
import java.io.File;
import org.eclipse.core.resources.IFile;
import de.bmotionstudio.gef.editor.ILanguageService;
import de.bmotionstudio.gef.editor.model.Visualization;
import de.prob.core.command.LoadCspModelCommand;
import de.prob.exceptions.ProBException;
public class CSPLanguageService implements ILanguageService {
@Override
public void startProBAnimator(Visualization v) throws ProBException {
IFile f = v.getProjectFile().getProject().getFile(v.getMachineName());
String n = f.getName();
String name = n.substring(0, n.length() - 4);
File file = new File(f.getLocationURI());
LoadCspModelCommand.load(v.getAnimation().getAnimator(), file, name);
}
@Override
public boolean isLanguageFile(IFile f) {
if (f.getFileExtension().equals("csp"))
return true;
return false;
}
}
...@@ -91,10 +91,15 @@ public class NewBMotionProjectWizard extends Wizard implements INewWizard { ...@@ -91,10 +91,15 @@ public class NewBMotionProjectWizard extends Wizard implements INewWizard {
try { try {
getContainer().run(true, false, op); getContainer().run(true, false, op);
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
e.printStackTrace();
final Throwable realException = e.getCause();
MessageDialog.openError(getShell(), e.getMessage(),
realException.getMessage());
return false; return false;
} catch (final InvocationTargetException e) { } catch (final InvocationTargetException e) {
e.printStackTrace();
final Throwable realException = e.getTargetException(); final Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), "Error", MessageDialog.openError(getShell(), e.getMessage(),
realException.getMessage()); realException.getMessage());
return false; return false;
} }
......
...@@ -186,6 +186,7 @@ public abstract class BControl implements IAdaptable, Cloneable { ...@@ -186,6 +186,7 @@ public abstract class BControl implements IAdaptable, Cloneable {
String langID = configurationElement String langID = configurationElement
.getAttribute("language"); .getAttribute("language");
if (langID != null if (langID != null
&& langID.equals(getVisualization() && langID.equals(getVisualization()
.getLanguage())) { .getLanguage())) {
...@@ -194,7 +195,6 @@ public abstract class BControl implements IAdaptable, Cloneable { ...@@ -194,7 +195,6 @@ public abstract class BControl implements IAdaptable, Cloneable {
.getChildren("control")) { .getChildren("control")) {
String cID = configC.getAttribute("id"); String cID = configC.getAttribute("id");
if (getType().equals(cID)) { if (getType().equals(cID)) {
for (IConfigurationElement configO : configC for (IConfigurationElement configO : configC
...@@ -228,6 +228,8 @@ public abstract class BControl implements IAdaptable, Cloneable { ...@@ -228,6 +228,8 @@ public abstract class BControl implements IAdaptable, Cloneable {
// Check if control has already the observer // Check if control has already the observer
if (!hasObserver(oID)) { if (!hasObserver(oID)) {
// If no, create a new instance and add the observer to the // If no, create a new instance and add the observer to the
// control // control
IConfigurationElement observerExtension = BMotionEditorPlugin IConfigurationElement observerExtension = BMotionEditorPlugin
...@@ -239,6 +241,9 @@ public abstract class BControl implements IAdaptable, Cloneable { ...@@ -239,6 +241,9 @@ public abstract class BControl implements IAdaptable, Cloneable {
Observer newObserver = (Observer) observerExtension Observer newObserver = (Observer) observerExtension
.createExecutableExtension("class"); .createExecutableExtension("class");
addObserver(newObserver); addObserver(newObserver);
} catch (CoreException e) { } catch (CoreException e) {
e.printStackTrace(); e.printStackTrace();
......
package de.bmotionstudio.gef.editor.observer;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.swt.widgets.Shell;
import de.bmotionstudio.gef.editor.Animation;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverCSPOperation;
import de.prob.core.command.CSPEvauateExpressionCommand;
import de.prob.exceptions.ProBException;
public class CSPEventObserver extends Observer {
private List<SetAttributeObject> setAttributeObjects;
private transient List<String> setAttributes;
public CSPEventObserver() {
super();
this.setAttributeObjects = new ArrayList<SetAttributeObject>();
this.setAttributes = new ArrayList<String>();
}
protected Object readResolve() {
setAttributes = new ArrayList<String>();
return super.readResolve();
}
@Override
public void check(Animation animation, BControl control) {
IFile f = animation.getVisualization().getProjectFile().getProject()
.getFile(animation.getVisualization().getMachineName());
// String n = f.getName();
// String name = n.substring(0, n.length() - 4);
File file = new File(f.getLocationURI());
this.setAttributes.clear();
// Collect evaluate predicate objects in list
for (SetAttributeObject obj : setAttributeObjects) {
obj.setHasError(false);
// First evaluate predicate (predicate field)
String bolValue = "true";
if (obj.getEval().length() > 0) {
String AsImplodedString = "";
if (animation.getLastExecutedOperation().getArguments().size() > 0) {
String[] inputArray = animation
.getLastExecutedOperation()
.getArguments()
.toArray(
new String[animation
.getLastExecutedOperation()
.getArguments().size()]);
StringBuffer sb = new StringBuffer();
sb.append(inputArray[0]);
for (int i = 1; i < inputArray.length; i++) {
sb.append(".");
sb.append(inputArray[i]);
}
AsImplodedString = "." + sb.toString();
}
try {
bolValue = CSPEvauateExpressionCommand.evaluate(animation
.getAnimator(), "member("
+ animation.getLastExecutedOperation().getName()
+ AsImplodedString + "," + obj.getEval()
+ ")",
file
.getAbsolutePath());
System.out.println("BOOL: ==> " + bolValue);
} catch (ProBException e) {
e.printStackTrace();
}
// bolValue = BMSUtil.parsePredicate(obj.getEval(), control,
// animation);
}
System.out.println(Boolean.valueOf(bolValue));
if (!obj.hasError() && Boolean.valueOf(bolValue)) {
String attributeID = obj.getAttribute();
// AbstractAttribute attributeObj = control
// .getAttribute(attributeID);
Object attributeVal = obj.getValue();
// if (obj.isExpressionMode()) {
// String strAtrVal = BMSUtil.parseExpression(
// attributeVal.toString(), control, animation);
// String er = attributeObj.validateValue(strAtrVal, null);
// if (er != null) {
// obj.setHasError(true);
// } else {
// attributeVal = attributeObj.unmarshal(strAtrVal);
// }
// }
if (!obj.hasError()) {
Object oldAttrVal = control.getAttributeValue(attributeID);
if (!oldAttrVal.equals(attributeVal)) {
control.setAttributeValue(attributeID, attributeVal,
true, false);
}
}
setAttributes.add(attributeID);
}
}
// Restore attribute values
// for (SetAttributeObject obj : setAttributeObjects) {
// if (!setAttributes.contains(obj.getAttribute())) {
// AbstractAttribute attributeObj = control.getAttribute(obj
// .getAttribute());
// Object oldAttrVal = control.getAttributeValue(obj
// .getAttribute());
// if (!oldAttrVal.equals(attributeObj.getInitValue())) {
// control.restoreDefaultValue(attributeObj.getID());
// }
// }
// }
}
public void setSetAttributeObjects(
List<SetAttributeObject> setAttributeObjects) {
this.setAttributeObjects = setAttributeObjects;
}
public List<SetAttributeObject> getSetAttributeObjects() {
return setAttributeObjects;
}
@Override
public ObserverWizard getWizard(Shell shell, BControl control) {
return new WizardObserverCSPOperation(shell, control, this);
}
}
/**
* (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.wizard;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.list.ComputedList;
import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableFontProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import de.bmotionstudio.gef.editor.BMotionStudioImage;
import de.bmotionstudio.gef.editor.EditorImageRegistry;
import de.bmotionstudio.gef.editor.attribute.AbstractAttribute;
import de.bmotionstudio.gef.editor.edit.AttributeExpressionEdittingSupport;
import de.bmotionstudio.gef.editor.edit.IsExpressionModeEditingSupport;
import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.observer.CSPEventObserver;
import de.bmotionstudio.gef.editor.observer.Observer;
import de.bmotionstudio.gef.editor.observer.ObserverWizard;
import de.bmotionstudio.gef.editor.observer.SetAttributeObject;
import de.bmotionstudio.gef.editor.property.CheckboxCellEditorHelper;
import de.bmotionstudio.gef.editor.util.BMotionWizardUtil;
public class WizardObserverCSPOperation extends ObserverWizard {
private WritableList input;
private TableViewer tableViewer;
@Override
public Control createWizardContent(Composite parent) {
parent.setLayout(new FillLayout());
DataBindingContext dbc = new DataBindingContext();
GridLayout gl = new GridLayout(1, true);
gl.horizontalSpacing = 0;
gl.verticalSpacing = 0;
gl.marginHeight = 0;
gl.marginWidth = 0;
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(gl);
tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer(
container, SetAttributeObject.class, getName());
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
column.getColumn().setText("Expression");
column.getColumn().setWidth(300);
PredicateEditingSupport pEditingSupport = new PredicateEditingSupport(
tableViewer, dbc, "eval", getBControl().getVisualization(),
getShell());
column.setEditingSupport(pEditingSupport);
column = new TableViewerColumn(tableViewer, SWT.NONE);
column.getColumn().setText("Attribute");
column.getColumn().setWidth(150);
column.setEditingSupport(new AttributeObserverValueEditing(tableViewer));
column = new TableViewerColumn(tableViewer, SWT.NONE);
column.getColumn().setText("Value");
column.getColumn().setWidth(175);
column.setEditingSupport(new AttributeExpressionEdittingSupport(
tableViewer, getBControl()));
column = new TableViewerColumn(tableViewer, SWT.NONE);
column.getColumn().setText("Expression?");
column.getColumn().setWidth(100);
column.setEditingSupport(new IsExpressionModeEditingSupport(
tableViewer, getBControl()));
ObservableListContentProvider contentProvider = new ObservableListContentProvider();
tableViewer.setContentProvider(contentProvider);
tableViewer.setLabelProvider(new ObserverLabelProvider(BeansObservables
.observeMaps(contentProvider.getKnownElements(), new String[] {
"eval", "attribute", "value", "isExpressionMode" })));
input = new WritableList(
((CSPEventObserver) getObserver()).getSetAttributeObjects(),
SetAttributeObject.class);
tableViewer.setInput(input);
Composite comp = new Composite(container, SWT.NONE);
comp.setLayout(new RowLayout());
comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
Button btRemove = new Button(comp, SWT.PUSH);
btRemove.setText("Remove");
btRemove.setImage(BMotionStudioImage
.getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT));
btRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (tableViewer.getSelection().isEmpty()) {
MessageDialog.openInformation(getShell(),
"Please select an entry.",
"Please select an entry.");
return;
}
SetAttributeObject toggleObj = (SetAttributeObject) ((IStructuredSelection) tableViewer
.getSelection()).getFirstElement();
input.remove(toggleObj);
}
});
Button btAdd = new Button(comp, SWT.PUSH);
btAdd.setText("Add");
btAdd.setImage(BMotionStudioImage
.getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ));
btAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SetAttributeObject toggleObj = new SetAttributeObject("");
input.add(toggleObj);
tableViewer.setSelection(new StructuredSelection(toggleObj));
}
});
return container;
}
public WizardObserverCSPOperation(Shell shell, BControl control,
Observer observer) {
super(shell, control, observer);
}
@Override
public Point getSize() {
return new Point(800, 500);
}
private class ObserverLabelProvider extends ObservableMapLabelProvider
implements ITableLabelProvider, ITableColorProvider,
ITableFontProvider {
public ObserverLabelProvider(IObservableMap[] attributeMaps) {
super(attributeMaps);
}
private final Color errorColor = Display.getDefault().getSystemColor(
SWT.COLOR_INFO_BACKGROUND);
// final Font bold = JFaceResources.getFontRegistry().getBold(
// JFaceResources.BANNER_FONT);
@Override
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == 3) {
return CheckboxCellEditorHelper
.getCellEditorImage(((SetAttributeObject) element)
.isExpressionMode());
}
return null;
}
@Override
public String getColumnText(Object element, int columnIndex) {
SetAttributeObject attributeObject = (SetAttributeObject) element;
if (columnIndex == 1) {
String atrID = attributeObject.getAttribute();
String atrName = "";
if (atrID != null) {
if (atrID.length() > 0) {
AbstractAttribute atr = getBControl().getAttributes()
.get(atrID);
if (atr != null)
atrName = atr.getName();
}
}
return atrName;
}
if (columnIndex == 2) {
if (attributeObject.getValue() != null)
return attributeObject.getValue().toString();
return "";
}
if (columnIndex == 3)
return "";
return super.getColumnText(element, columnIndex);
}
public Color getBackground(final Object element, final int column) {
SetAttributeObject attributeObject = (SetAttributeObject) element;
if (attributeObject.hasError())
return errorColor;
return null;
}
public Color getForeground(final Object element, final int column) {
return null;
}
public Font getFont(final Object element, final int column) {
return null;
}
}
private class AttributeObserverValueEditing extends EditingSupport {
private ComboBoxViewerCellEditor cellEditor = null;
public AttributeObserverValueEditing(TableViewer cv) {
super(cv);
}
@Override
protected boolean canEdit(Object element) {
return BMotionWizardUtil.isEditElement(getViewer());
}
@Override
protected Object getValue(Object element) {
return ((SetAttributeObject) element).getAttribute();
}
@Override
protected void setValue(Object element, Object value) {
if (value != null) {
SetAttributeObject obj = (SetAttributeObject) element;
obj.setAttribute(value.toString());
obj.setIsExpressionMode(false);
}
}
@Override
protected CellEditor getCellEditor(Object element) {
if (cellEditor == null) {
cellEditor = new ComboBoxViewerCellEditor(
(Composite) tableViewer.getControl(), SWT.READ_ONLY);
cellEditor
.setContentProvider(new ObservableListContentProvider());
cellEditor.setLabelProvider(new LabelProvider() {
public String getText(Object element) {
return getBControl().getAttributes()
.get(element.toString()).getName();
}
});
cellEditor.setInput(new ComputedList() {
@Override
protected List<String> calculate() {
ArrayList<String> atrList = new ArrayList<String>();
for (AbstractAttribute atr : getBControl()
.getAttributes().values()) {
atrList.add(atr.getID());
}
return atrList;
}
});
((CCombo) cellEditor.getControl())
.addFocusListener(new FocusListener() {
String oldValue;
public void focusGained(FocusEvent e) {
oldValue = ((CCombo) cellEditor.getControl())
.getText();
}
public void focusLost(FocusEvent e) {
if (!oldValue.equals(((CCombo) cellEditor
.getControl()).getText())) {
IStructuredSelection selection = (IStructuredSelection) getViewer()
.getSelection();
SetAttributeObject p = (SetAttributeObject) selection
.getFirstElement();
AbstractAttribute atr = getBControl()
.getAttributes().get(
p.getAttribute());
p.setValue(atr.getValue());
tableViewer.refresh();
}
}
});
}
return cellEditor;
}
}
}
package de.prob.core.command;
import de.prob.core.Animator;
import de.prob.exceptions.ProBException;
import de.prob.parser.ISimplifiedROMap;
import de.prob.prolog.output.IPrologTermOutput;
import de.prob.prolog.term.CompoundPrologTerm;
import de.prob.prolog.term.PrologTerm;
public class CSPEvauateExpressionCommand implements IComposableCommand {
private static final String EVALUATE_TERM_VARIABLE = "Res";
private String expression;
private String fileName;
private static String result;
public CSPEvauateExpressionCommand(String expression, String fileName) {
this.expression = expression;
this.fileName = fileName;
}
public static String evaluate(final Animator a, final String expression,
final String fileName) throws ProBException {
CSPEvauateExpressionCommand command = new CSPEvauateExpressionCommand(
expression, fileName);
a.execute(command);
return result;
}
@Override
public void writeCommand(IPrologTermOutput pout) throws CommandException {
pout.openTerm("evaluate_csp_expression_eclipse");
pout.printAtom(expression);
pout.printAtom(fileName);
pout.printVariable(EVALUATE_TERM_VARIABLE);
pout.closeTerm();
}
@Override
public void processResult(ISimplifiedROMap<String, PrologTerm> bindings)
throws CommandException {
CompoundPrologTerm prologTerm = (CompoundPrologTerm) bindings
.get(EVALUATE_TERM_VARIABLE);
result = prologTerm.toString();
}
}
...@@ -94,6 +94,7 @@ public final class LoadCspModelCommand { ...@@ -94,6 +94,7 @@ public final class LoadCspModelCommand {
final State commandResult = explore.getState(); final State commandResult = explore.getState();
animator.announceCurrentStateChanged(commandResult, animator.announceCurrentStateChanged(commandResult,
Operation.NULL_OPERATION); Operation.NULL_OPERATION);
} }
private static IComposableCommand getLoadCommand(final File model, private static IComposableCommand getLoadCommand(final File model,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment