use of org.osate.ge.aadl2.ui.internal.viewmodels.PrototypesModel.EditablePrototype in project osate2 by osate.
the class PrototypesModel method setRefined.
@Override
public void setRefined(final EditablePrototype prototype, final boolean value) {
if (value) {
// Create refinement
modifySelectedClassifier("Refine Prototype", prototype, c -> {
final Prototype refinement = (Prototype) c.createOwnedPrototype(prototype.prototype.eClass());
refinement.setRefined(prototype.prototype);
if (refinement instanceof FeaturePrototype) {
final FeaturePrototype fpRefinement = ((FeaturePrototype) refinement);
final FeaturePrototype fp = (FeaturePrototype) prototype.prototype;
fpRefinement.setIn(fp.isIn());
fpRefinement.setOut(fp.isOut());
}
});
} else {
// Remove refinement
modifyPrototype("Remove Prototype Refinement", prototype, p -> EcoreUtil.remove(p));
}
}
use of org.osate.ge.aadl2.ui.internal.viewmodels.PrototypesModel.EditablePrototype in project osate2 by osate.
the class PrototypesModel method setBusinessObjectSelection.
/**
* Refreshes the internal state of the model based on the specified business object selection
*/
public void setBusinessObjectSelection(final BusinessObjectSelection value) {
this.bos = Objects.requireNonNull(value, "value must not be null");
final boolean singleSelection = this.bos.boStream(Classifier.class).limit(2).count() == 1;
// Build set of all editable prototypes..
prototypes = new ArrayList<>();
value.bocStream().filter(boc -> boc.getBusinessObject() instanceof Classifier).forEachOrdered(boc -> {
final Classifier c = (Classifier) boc.getBusinessObject();
final String suffix = singleSelection ? "" : " [" + c.getQualifiedName() + "]";
AadlPrototypeUtil.getAllPrototypes(boc.getBusinessObject()).forEach(p -> {
final String name = p.getName();
if (!Strings.isNullOrEmpty(name)) {
prototypes.add(new EditablePrototype(boc, name + suffix, name, p));
}
});
});
// If a prototype was previously selected, update the selection based on the previously selected prototype's same classifier BOC and name.
if (this.selectedPrototype != null) {
selectedPrototype = prototypes.stream().filter(p -> {
return p.classifierBoc == selectedPrototype.classifierBoc && p.name.equalsIgnoreCase(this.selectedPrototype.name);
}).findAny().orElse(null);
}
triggerChangeEvent();
}
use of org.osate.ge.aadl2.ui.internal.viewmodels.PrototypesModel.EditablePrototype in project osate2 by osate.
the class PrototypesModel method addPrototype.
@Override
public void addPrototype() {
bos.modify("Add Prototype", boc -> boc.getBusinessObject() instanceof Classifier, boc -> (Classifier) boc.getBusinessObject(), (c, boc) -> {
// Create a new prototype
final ComponentPrototype cp = (ComponentPrototype) c.createOwnedPrototype(Aadl2Package.eINSTANCE.getDataPrototype());
// Assign a name
final String newName = AadlNamingUtil.buildUniqueIdentifier(c, "new_prototype");
cp.setName(newName);
// Update the selected prototype
selectedPrototype = new EditablePrototype(boc, newName, newName, cp);
});
}
use of org.osate.ge.aadl2.ui.internal.viewmodels.PrototypesModel.EditablePrototype in project osate2 by osate.
the class PrototypesModel method setPrototypeName.
@Override
public void setPrototypeName(EditablePrototype prototype, String value) {
renamer.rename(new RenamePrototypeSupplier(prototype.classifierBoc), value, prototype.name);
// Select will be lost on undo/redo but this will retain selection on the original rename.
selectedPrototype = new EditablePrototype(prototype.classifierBoc, value, value, prototype.prototype);
}
use of org.osate.ge.aadl2.ui.internal.viewmodels.PrototypesModel.EditablePrototype in project osate2 by osate.
the class PrototypesModel method getConstrainingClassifier.
@Override
public NamedElementOrDescription getConstrainingClassifier(final EditablePrototype prototype) {
final Prototype p = prototype.prototype;
final NamedElement namedElement;
if (p instanceof ComponentPrototype) {
namedElement = ((ComponentPrototype) p).getConstrainingClassifier();
} else if (p instanceof FeatureGroupPrototype) {
namedElement = ((FeatureGroupPrototype) p).getConstrainingFeatureGroupType();
} else if (p instanceof FeaturePrototype) {
namedElement = ((FeaturePrototype) p).getConstrainingClassifier();
} else {
namedElement = null;
}
return namedElement == null ? null : new NamedElementOrDescription(namedElement);
}
Aggregations