use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.PreExpression in project AGREE by loonwerks.
the class InputConstraintDialog method addNewEClassMenuItem.
private void addNewEClassMenuItem(final Menu menu, final Reference ref, final String label, final EClass eClass) {
final MenuItem menuItem = new MenuItem(menu, SWT.RADIO);
final boolean isInstanceOfEClass = eClass.isInstance(ref.get());
menuItem.setSelection(isInstanceOfEClass);
menuItem.setEnabled(!isInstanceOfEClass);
menuItem.setText(label);
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
if (((MenuItem) e.widget).getSelection()) {
final Object oldValue = ref.get();
// Store interval from current expression in case it is needed to initialize new object
final IntervalExpression oldInterval;
if (oldValue instanceof RandomIntegerExpression) {
oldInterval = ((RandomIntegerExpression) oldValue).getInterval();
} else if (oldValue instanceof RandomRealExpression) {
oldInterval = ((RandomRealExpression) oldValue).getInterval();
} else if (oldValue instanceof IntervalExpression) {
oldInterval = (IntervalExpression) oldValue;
} else {
oldInterval = null;
}
final Object newValue;
if (eClass == icp.getIntervalExpression() && oldInterval != null) {
newValue = oldInterval;
} else {
newValue = InputConstraintFactory.eINSTANCE.create(eClass);
}
ref.set(newValue);
// Perform initialization on the new object
if (newValue instanceof RandomIntegerExpression || newValue instanceof RandomRealExpression) {
final IntervalExpression newInterval = oldInterval == null ? InputConstraintFactory.eINSTANCE.createIntervalExpression() : oldInterval;
if (newValue instanceof RandomIntegerExpression) {
((RandomIntegerExpression) newValue).setInterval(newInterval);
} else if (newValue instanceof RandomRealExpression) {
((RandomRealExpression) newValue).setInterval(newInterval);
}
} else if (newValue instanceof RandomElementExpression) {
((RandomElementExpression) newValue).setSet(InputConstraintFactory.eINSTANCE.createSetExpression());
} else if (newValue instanceof PreExpression && oldValue instanceof ElementRefExpression) {
((PreExpression) newValue).setRef((ElementRefExpression) oldValue);
}
dlg.refreshContraint();
}
}
});
}
use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.PreExpression in project AGREE by loonwerks.
the class InputConstraintDialog method addPreviousValueMenuItem.
private void addPreviousValueMenuItem(final Menu menu, final Reference ref) {
final MenuItem menuItem = new MenuItem(menu, SWT.CHECK);
menuItem.setSelection(ref.get() instanceof PreExpression);
menuItem.setText("Previous Value");
menuItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
final boolean checked = ((MenuItem) e.widget).getSelection();
if (checked) {
final PreExpression preExpr = (PreExpression) InputConstraintFactory.eINSTANCE.create(InputConstraintPackage.eINSTANCE.getPreExpression());
final Object oldValue = ref.get();
if (oldValue instanceof ElementRefExpression) {
preExpr.setRef((ElementRefExpression) oldValue);
}
ref.set(preExpr);
} else {
ref.set(((PreExpression) ref.get()).getRef());
}
dlg.refreshContraint();
}
});
}
use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.PreExpression in project AGREE by loonwerks.
the class InputConstraintDialog method createConstraintWidgets.
private void createConstraintWidgets(final Composite container, final Object parentValue, final Reference ref) {
final Object value = ref.get();
if (value instanceof IntervalExpression) {
final IntervalExpression ie = (IntervalExpression) value;
if (ref.getEType() == icp.getIntervalExpression()) {
newLabel(container, "interval");
} else {
newLink(container, ref, "interval");
}
newLink(container, new StructuralFeatureReference(ref, ie, icp.getIntervalExpression_LeftClosed()), ie.isLeftClosed() ? "[" : "(");
createConstraintWidgets(container, value, new StructuralFeatureReference(ref, ie, icp.getIntervalExpression_Left()));
newLabel(container, ",");
createConstraintWidgets(container, value, new StructuralFeatureReference(ref, ie, icp.getIntervalExpression_Right()));
newLink(container, new StructuralFeatureReference(ref, ie, icp.getIntervalExpression_RightClosed()), ie.isRightClosed() ? "]" : ")");
} else if (value instanceof SetExpression) {
final SetExpression se = (SetExpression) value;
if (ref.getEType() == icp.getSetExpression()) {
newLabel(container, "set");
} else {
newLink(container, ref, "set");
}
newLabel(container, "{");
final int numberOfMembers = se.getMembers().size();
for (int i = 0; i < numberOfMembers; i++) {
createConstraintWidgets(container, value, new ListMemberReference(ref, icp.getSetExpression_Members().getEType(), se.getMembers(), i));
newLabel(container, ",");
}
newLink(container, new ListMemberReference(ref, icp.getSetExpression_Members().getEType(), se.getMembers(), -1), "<add>");
newLabel(container, "}");
} else if (value instanceof BinaryExpression) {
final BinaryExpression be = (BinaryExpression) value;
boolean showParentheses = parentValue instanceof NegativeExpression;
if (!showParentheses && parentValue instanceof BinaryExpression) {
final BinaryExpression parentBe = (BinaryExpression) parentValue;
final boolean isAddOrSubstract = be.getOp() == Operator.ADDITION || be.getOp() == Operator.SUBTRACTION;
final boolean isParentAddOrSubstract = parentBe.getOp() == Operator.ADDITION || parentBe.getOp() == Operator.SUBTRACTION;
if (isAddOrSubstract && !isParentAddOrSubstract) {
showParentheses = true;
}
}
if (showParentheses) {
newLabel(container, "(");
}
createConstraintWidgets(container, value, new StructuralFeatureReference(ref, be, icp.getBinaryExpression_Left()));
newLink(container, new StructuralFeatureReference(ref, be, icp.getBinaryExpression_Op()), be.getOp().toString());
createConstraintWidgets(container, value, new StructuralFeatureReference(ref, be, icp.getBinaryExpression_Right()));
if (showParentheses) {
newLabel(container, ")");
}
} else if (value instanceof NegativeExpression) {
final NegativeExpression ne = (NegativeExpression) value;
newLabel(container, "-");
createConstraintWidgets(container, value, new StructuralFeatureReference(ref, ne, icp.getNegativeExpression_Value()));
} else if (value instanceof PreExpression) {
newLink(container, ref, "previous value of");
createConstraintWidgets(container, value, new StructuralFeatureReference(ref, (PreExpression) value, icp.getPreExpression_Ref()));
} else if (value instanceof RandomElementExpression) {
newLink(container, ref, "random element");
newLabel(container, "in");
createConstraintWidgets(container, value, new StructuralFeatureReference(ref, (RandomElementExpression) value, icp.getRandomElementExpression_Set()));
} else if (value instanceof RandomIntegerExpression) {
newLink(container, ref, "random integer");
newLabel(container, "in");
createConstraintWidgets(container, value, new StructuralFeatureReference(ref, (RandomIntegerExpression) value, icp.getRandomIntegerExpression_Interval()));
} else if (value instanceof RandomRealExpression) {
newLink(container, ref, "random real");
newLabel(container, "in");
createConstraintWidgets(container, value, new StructuralFeatureReference(ref, (RandomRealExpression) value, icp.getRandomRealExpression_Interval()));
} else if (value instanceof ConstRefExpression) {
newLink(container, ref, model.unparse((ConstRefExpression) value));
} else if (value instanceof ElementRefExpression) {
newLink(container, ref, model.unparse((ElementRefExpression) value));
} else if (value instanceof RealLiteral) {
final RealLiteral rl = (RealLiteral) value;
newLink(container, ref, rl.getValue().toString());
} else if (value instanceof IntegerLiteral) {
final IntegerLiteral il = (IntegerLiteral) value;
newLink(container, ref, il.getValue().toString());
} else if (value instanceof BooleanLiteral) {
final BooleanLiteral bl = (BooleanLiteral) value;
newLink(container, ref, Boolean.toString(bl.isValue()));
} else if (value == null) {
newLink(container, ref, "<select>");
} else {
throw new RuntimeException("Unexpected value: " + value);
}
}
use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.PreExpression in project AGREE by loonwerks.
the class InputConstraintSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == InputConstraintPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case InputConstraintPackage.BINARY_EXPRESSION:
sequence_AddSub_MultDiv(context, (BinaryExpression) semanticObject);
return;
case InputConstraintPackage.BOOLEAN_LITERAL:
sequence_BooleanLiteral(context, (BooleanLiteral) semanticObject);
return;
case InputConstraintPackage.CONST_REF_EXPRESSION:
sequence_ConstRef(context, (ConstRefExpression) semanticObject);
return;
case InputConstraintPackage.ELEMENT_REF_EXPRESSION:
sequence_ElementRef(context, (ElementRefExpression) semanticObject);
return;
case InputConstraintPackage.INTEGER_LITERAL:
sequence_IntegerLiteral(context, (IntegerLiteral) semanticObject);
return;
case InputConstraintPackage.INTERVAL_EXPRESSION:
sequence_Interval(context, (IntervalExpression) semanticObject);
return;
case InputConstraintPackage.NEGATIVE_EXPRESSION:
sequence_Negative(context, (NegativeExpression) semanticObject);
return;
case InputConstraintPackage.PRE_EXPRESSION:
sequence_Pre(context, (PreExpression) semanticObject);
return;
case InputConstraintPackage.RANDOM_ELEMENT_EXPRESSION:
sequence_RandomElement(context, (RandomElementExpression) semanticObject);
return;
case InputConstraintPackage.RANDOM_INTEGER_EXPRESSION:
sequence_RandomInteger(context, (RandomIntegerExpression) semanticObject);
return;
case InputConstraintPackage.RANDOM_REAL_EXPRESSION:
sequence_RandomReal(context, (RandomRealExpression) semanticObject);
return;
case InputConstraintPackage.REAL_LITERAL:
sequence_RealLiteral(context, (RealLiteral) semanticObject);
return;
case InputConstraintPackage.SET_EXPRESSION:
sequence_Set(context, (SetExpression) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Aggregations