use of org.osate.ge.CanonicalBusinessObjectReference in project osate2 by osate.
the class AadlReferenceUtil method getCanonicalReferenceForUnnamedModeTransition.
public static CanonicalBusinessObjectReference getCanonicalReferenceForUnnamedModeTransition(final ModeTransition mt) {
final List<ModeTransitionTrigger> triggers = mt.getOwnedTriggers();
final String[] segments = new String[5 + (triggers.size() * 2)];
int index = 0;
segments[index++] = DeclarativeReferenceType.MODE_TRANSITION_UNNAMED.getId();
segments[index++] = mt.getContainingClassifier().getQualifiedName();
segments[index++] = getNameForSerialization(mt);
segments[index++] = getNameForSerialization(mt.getSource());
segments[index++] = getNameForSerialization(mt.getDestination());
for (final ModeTransitionTrigger trigger : triggers) {
segments[index++] = getNameForSerialization(trigger.getContext());
segments[index++] = getNameForSerialization(trigger.getTriggerPort());
}
return new CanonicalBusinessObjectReference(segments);
}
use of org.osate.ge.CanonicalBusinessObjectReference in project osate2 by osate.
the class AnnexHandler method getCanonicalReference.
@Override
public CanonicalBusinessObjectReference getCanonicalReference(final ReferenceContext ctx) {
final Object bo = ctx.getBusinessObject();
if (bo instanceof AnnexLibrary) {
final AnnexLibrary annexLibrary = (AnnexLibrary) bo;
final AadlPackage annexPkg = getAnnexLibraryPackage(annexLibrary);
if (annexPkg == null) {
throw new RuntimeException("Unable to retrieve package.");
}
final int index = getAnnexLibraryIndex(annexLibrary);
return new CanonicalBusinessObjectReference(DeclarativeReferenceType.ANNEX_LIBRARY.getId(), annexPkg.getQualifiedName(), annexLibrary.getName(), Integer.toString(index));
} else if (bo instanceof AnnexSubclause) {
final AnnexSubclause annexSubclause = (AnnexSubclause) bo;
if (annexSubclause.getContainingClassifier() == null) {
throw new RuntimeException("Unable to retrieve containing classifier.");
}
final Classifier annexSubclauseClassifier = annexSubclause.getContainingClassifier();
final int index = getAnnexSubclauseIndex(annexSubclause, false);
return new CanonicalBusinessObjectReference(DeclarativeReferenceType.ANNEX_SUBCLAUSE.getId(), ctx.getReferenceBuilder().getCanonicalReference(annexSubclauseClassifier).encode(), annexSubclause.getName(), Integer.toString(index));
}
throw new RuntimeException("Unexpected business object " + bo);
}
use of org.osate.ge.CanonicalBusinessObjectReference in project osate2 by osate.
the class ReferencesTest method testCanonicalReferenceComparison.
@Test
public void testCanonicalReferenceComparison() {
final CanonicalBusinessObjectReference r1 = new CanonicalBusinessObjectReference("A", "B");
final CanonicalBusinessObjectReference r2 = new CanonicalBusinessObjectReference("A", "B");
final CanonicalBusinessObjectReference r3 = new CanonicalBusinessObjectReference("A", "b");
final CanonicalBusinessObjectReference r4 = new CanonicalBusinessObjectReference("A", "B2");
assertEquals("Identical reference should be equal.", r1, r2);
assertEquals("References should be case insensitive.", r1, r3);
assertNotEquals("References with different segments should not be equal.", r1, r4);
}
use of org.osate.ge.CanonicalBusinessObjectReference in project osate2 by osate.
the class DefaultDiagramService method createDiagram.
@Override
public void createDiagram(final IFile diagramFile, final DiagramType diagramType, final Object contextBo) {
// Create an AgeDiagram object. This object doesn't have to be completely valid. It just needs to be able to be written.
final AgeDiagram diagram = new AgeDiagram();
// Build diagram configuration
final CanonicalBusinessObjectReference contextBoCanonicalRef = contextBo == null ? null : Objects.requireNonNull(referenceService.getCanonicalReference(contextBo), "Unable to build canonical reference for business object: " + contextBo);
diagram.modify("Configure Diagram", m -> m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagramType, true).contextBoReference(contextBoCanonicalRef).connectionPrimaryLabelsVisible(false).build()));
final URI newDiagramUri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
DiagramSerialization.write(diagramFile.getProject(), diagram, newDiagramUri);
try {
diagramFile.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (final CoreException e) {
throw new GraphicalEditorException(e);
}
}
use of org.osate.ge.CanonicalBusinessObjectReference in project osate2 by osate.
the class DiagramConfigurationDialog method main.
public static void main(String[] args) {
final Model model = new Model() {
@Override
public RelativeBusinessObjectReference getRelativeBusinessObjectReference(final Object bo) {
return new RelativeBusinessObjectReference(bo.toString());
}
@Override
public Collection<Object> getChildBusinessObjects(final BusinessObjectContext boc) {
final Collection<Object> children = new ArrayList<>();
for (int i = 1; i <= 100; i++) {
children.add("C" + i);
}
return children;
}
@Override
public String getName(final BusinessObjectContext boc) {
return boc.getBusinessObject().toString();
}
@Override
public ImmutableSet<ContentFilter> getDefaultContentFilters(final Object bo) {
return ImmutableSet.of(TestContentsFilter.FILTER1);
}
@Override
public Map<String, Collection<String>> getAadlProperties() {
final Map<String, Collection<String>> result = new HashMap<>();
result.put("test_ps1", Arrays.asList(new String[] { "a", "c", "b" }));
result.put("test_ps2", Arrays.asList(new String[] { "a", "b", "c" }));
result.put("test_ps3", Arrays.asList(new String[] { "d", "f", "e" }));
return result;
}
@Override
public Object getBusinessObject(final CanonicalBusinessObjectReference ref) {
return new Object();
}
@Override
public String getContextDescription(final Object contextBo) {
return "a::b::c (TestType)";
}
@Override
public boolean shouldShowBusinessObject(final Object bo) {
return !bo.equals("C3");
}
@Override
public Image getImage(final Object bo) {
return null;
}
@Override
public Object resolve(final Object bo) {
return bo;
}
@Override
public boolean isProxy(Object bo) {
return false;
}
};
final DiagramConfiguration diagramConfig = new DiagramConfigurationBuilder(new CustomDiagramType(), false).contextBoReference(new CanonicalBusinessObjectReference("test")).addAadlProperty("test::prop1").addAadlProperty("test_ps2::b").connectionPrimaryLabelsVisible(true).build();
// Create a test business object tree
final BusinessObjectNode rootNode = new BusinessObjectNode(null, UUID.randomUUID(), null, null, Completeness.UNKNOWN, true);
new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("A"), "A", Completeness.UNKNOWN, true);
new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("B"), "B", Completeness.UNKNOWN, true);
new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("C"), "C", Completeness.UNKNOWN, true);
new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("D"), "D", Completeness.UNKNOWN, true);
// Show the dialog
final Result result = DiagramConfigurationDialog.show(null, model, diagramConfig, rootNode, new Object[] { "A", "C1", "C2", "C4" });
if (result == null) {
System.out.println("Dialog was canceled.");
} else {
System.out.println(result.getDiagramConfiguration());
System.out.println(result.getBusinessObjectTree());
}
}
Aggregations