Search in sources :

Example 16 with CanonicalBusinessObjectReference

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);
}
Also used : CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger)

Example 17 with CanonicalBusinessObjectReference

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);
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) Classifier(org.osate.aadl2.Classifier) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 18 with CanonicalBusinessObjectReference

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);
}
Also used : CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) Test(org.junit.Test)

Example 19 with CanonicalBusinessObjectReference

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);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) URI(org.eclipse.emf.common.util.URI) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException)

Example 20 with CanonicalBusinessObjectReference

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());
    }
}
Also used : CustomDiagramType(org.osate.ge.aadl2.internal.diagramtypes.CustomDiagramType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) ContentFilter(org.osate.ge.ContentFilter) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) DiagramConfiguration(org.osate.ge.internal.diagram.runtime.DiagramConfiguration) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) Collection(java.util.Collection) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)21 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)6 HashMap (java.util.HashMap)5 IProject (org.eclipse.core.resources.IProject)4 URI (org.eclipse.emf.common.util.URI)4 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)4 DiagramConfigurationBuilder (org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Objects (java.util.Objects)3 IResource (org.eclipse.core.resources.IResource)3 CoreException (org.eclipse.core.runtime.CoreException)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 EObject (org.eclipse.emf.ecore.EObject)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 BusinessObjectContext (org.osate.ge.BusinessObjectContext)3 AgeDiagramProvider (org.osate.ge.internal.AgeDiagramProvider)3 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)3 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)3 Collections (java.util.Collections)2