use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class ClassifierInfoView method updateDisplay.
// Synchronized to make manipulation of the currentRefreshJob atomic
private synchronized void updateDisplay(final Classifier inputHierarchy, final Classifier inputMember) {
// Stop any current refresh job
if (currentRefreshJob != null) {
currentRefreshJob.cancel();
}
final Job waitForJob = currentRefreshJob;
// Compute the tree in a separate job and then update the view on the display thread.
final IWorkbenchSiteProgressService service = getSite().getService(IWorkbenchSiteProgressService.class);
final Job refreshJob = new Job("Classifier Info View Refresh") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
// Wait for the current refresh to finish (it should have been cancelled)
if (waitForJob != null) {
try {
waitForJob.join();
} catch (final OperationCanceledException | InterruptedException e) {
/*
* We were interrupted while waiting. Not sure this should be possible, but
* if it happens, we clear the display.
*/
clearDisplay(false);
return Status.CANCEL_STATUS;
}
}
boolean needsRefresh = false;
boolean skipMember = false;
final SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
if (inputHierarchy != null) {
subMonitor.subTask("Buidling classifier hiearchy");
final Set<IProject> projects = getDependantProjects(inputHierarchy);
projectDependancies.addAll(projects);
try {
final AncestorTree ancestorTreeModel = createAncestorTree(inputHierarchy, subMonitor);
subMonitor.worked(1);
final DescendantTree descendantTreeModel = createDescendantTree(inputHierarchy, projects, subMonitor.split(1));
// Update the view contents in the UI thread
getViewSite().getShell().getDisplay().asyncExec(() -> {
ancestorTreeViewer.setInput(ancestorTreeModel);
ancestorTreeViewer.expandToLevel(2);
ancestorTreeViewer.setSelection(new TreeSelection(new TreePath(ancestorTreeModel.getChildren())));
descendantTreeViewer.setInput(descendantTreeModel);
descendantTreeViewer.expandToLevel(2);
descendantTreeViewer.setSelection(new TreeSelection(new TreePath(descendantTreeModel.getChildren())));
});
} catch (final OperationCanceledException | InterruptedException e) {
/*
* Hierarchy build cancelled-- clear both panes. Originally we just cleared the
* hierarchy pane, but then it is confusing what is being shown in the member pane.
* Set the 'skip' flag so we don't readd the member pane below.
*/
clearDisplay(false);
// Update incomplete, so we still need to refresh later
needsRefresh = true;
skipMember = true;
}
subMonitor.done();
} else {
subMonitor.worked(2);
}
if (inputMember != null && !skipMember) {
final MemberTree memberTree;
if (inputMember instanceof ComponentType) {
memberTree = createMemberTree((ComponentType) inputMember);
} else if (inputMember instanceof ComponentImplementation) {
memberTree = createMemberTree((ComponentImplementation) inputMember);
} else if (inputMember instanceof FeatureGroupType) {
memberTree = createMemberTree((FeatureGroupType) inputMember);
} else {
// Shouldn't get here
memberTree = null;
}
if (memberTree != null) {
// Update the view contents in the UI thread
getViewSite().getShell().getDisplay().asyncExec(() -> {
memberTreeViewer.setInput(memberTree);
memberTreeViewer.expandToLevel(2);
});
} else {
clearMembers(false);
}
}
setNeedsRefresh(needsRefresh);
// Mark the view as changed (should show up with a bold title)
service.warnOfContentChange();
return Status.OK_STATUS;
}
};
// doesn't write resources
refreshJob.setRule(null);
refreshJob.setUser(true);
refreshJob.setSystem(false);
// Run the job using the progress service so that the view is marked as busy (italics)
currentRefreshJob = refreshJob;
service.schedule(refreshJob, 0, true);
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class PrototypesModel method setConstrainingClassifier.
@Override
public void setConstrainingClassifier(final EditablePrototype prototype, final NamedElementOrDescription value) {
modifyPrototype("Set Constraining Classifier", prototype, p -> {
final EObject classifier = value.getResolvedValue(prototype.prototype.eResource().getResourceSet());
if (classifier != null) {
// Import its package if necessary
final AadlPackage pkg = (AadlPackage) p.getElementRoot();
if (classifier instanceof Classifier && ((Classifier) classifier).getNamespace() != null && pkg != null) {
final PackageSection section = pkg.getPublicSection();
final AadlPackage selectedClassifierPkg = (AadlPackage) ((Classifier) classifier).getNamespace().getOwner();
if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
}
}
}
// Update the classifier
if (p instanceof ComponentPrototype) {
((ComponentPrototype) p).setConstrainingClassifier((ComponentClassifier) classifier);
} else if (p instanceof FeatureGroupPrototype) {
((FeatureGroupPrototype) p).setConstrainingFeatureGroupType((FeatureGroupType) classifier);
} else if (p instanceof FeaturePrototype) {
((FeaturePrototype) p).setConstrainingClassifier((ComponentClassifier) classifier);
}
});
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class FeatureInstanceTooltipContributor method addTooltipContents.
@Override
public void addTooltipContents(final TooltipContributorContext ctx) {
ctx.getBusinessObjectContext().getBusinessObject(FeatureInstance.class).ifPresent(featureInstance -> {
final Feature feature = featureInstance.getFeature();
if (feature instanceof Feature || feature instanceof InternalFeature || feature instanceof ProcessorFeature) {
// Determine the feature classifier
final Classifier featureClassifier;
if (feature instanceof EventDataSource) {
final EventDataSource aadlFeature = (EventDataSource) feature;
featureClassifier = aadlFeature.getDataClassifier();
} else if (feature instanceof PortProxy) {
final PortProxy aadlFeature = (PortProxy) feature;
featureClassifier = aadlFeature.getDataClassifier();
} else if (feature instanceof SubprogramProxy) {
final SubprogramProxy aadlFeature = (SubprogramProxy) feature;
featureClassifier = aadlFeature.getSubprogramClassifier();
} else if (feature instanceof Feature) {
final Feature aadlFeature = (Feature) feature;
featureClassifier = aadlFeature.getAllClassifier();
} else {
featureClassifier = null;
}
// Build the text to contribute to the tooltip
final StringBuffer tooltipContents = new StringBuffer();
if (featureClassifier instanceof ComponentClassifier) {
tooltipContents.append(((ComponentClassifier) featureClassifier).getCategory() + " " + featureClassifier.getQualifiedName());
} else if (featureClassifier instanceof FeatureGroupType) {
tooltipContents.append("feature group " + featureClassifier.getQualifiedName());
} else if (featureClassifier == null) {
tooltipContents.append("No Classifier");
} else {
tooltipContents.append(featureClassifier.getQualifiedName());
}
// Create the styled text describing the feature
final Label lbl = new Label(ctx.getTooltip(), SWT.NONE);
lbl.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
lbl.setText(tooltipContents.toString());
}
});
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class EMV2Util method getErrorPropagationFeatureDirection.
/**
* returns the feature instance in the component instance that is referenced by the Error Propagation (or Containment)
* @param ep
* @param ci
* @return
*/
public static DirectionType getErrorPropagationFeatureDirection(ErrorPropagation ep) {
FeatureorPPReference fref = ep.getFeatureorPPRef();
boolean inverse = false;
NamedElement f = null;
DirectionType featuredir = DirectionType.IN_OUT;
while (fref != null) {
f = fref.getFeatureorPP();
fref = fref.getNext();
if (f instanceof FeatureGroup && fref != null) {
FeatureGroup fg = (FeatureGroup) f;
FeatureGroupType fgt = fg.getAllFeatureGroupType();
if (fg.isInverse()) {
inverse = !inverse;
}
if (fgt != null && fgt.getInverse() != null && !fgt.getOwnedFeatures().contains(fref.getFeatureorPP())) {
inverse = !inverse;
}
}
}
if (f instanceof DirectedFeature) {
featuredir = ((DirectedFeature) f).getDirection();
if (inverse) {
return featuredir.getInverseDirection();
} else {
return featuredir;
}
}
return featuredir;
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class FeatureInstanceImpl method findInverseFeatureGroup.
/**
* find the matching inverse feature group instance in this feature group instance
* the contained feature group instance must have the inverse feature group type
* @param targetpgt feature group instance with feature group type to be found
* @return feature instance with the specified feature, or null
*/
// XXX: [AADL 1 -> AADL 2] Added to make instantiation work.
public FeatureInstance findInverseFeatureGroup(FeatureGroupType targetpgt) {
if (!(getFeature() instanceof FeatureGroup)) {
return null;
}
EList<FeatureInstance> subcil = getFeatureInstances();
for (Iterator<FeatureInstance> it = subcil.iterator(); it.hasNext(); ) {
FeatureInstance fi = it.next();
if (fi.getFeature() instanceof FeatureGroup) {
FeatureGroupType srcpgt = ((FeatureGroup) fi.getFeature()).getFeatureGroupType();
if (srcpgt != null && srcpgt.isInverseOf(targetpgt)) {
return fi;
}
fi.findInverseFeatureGroup(targetpgt);
}
}
return null;
}
Aggregations