Search in sources :

Example 1 with DiagramConfigurationBuilder

use of org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder in project osate2 by osate.

the class SetBindingTool method activated.

@Override
public void activated(final ActivatedEvent ctx) {
    final BusinessObjectContext[] selectedBocs = ctx.getSelectedBocs().toArray(new BusinessObjectContext[ctx.getSelectedBocs().size()]);
    final AgeDiagram diagram = ctx.getDiagram();
    final AadlModificationService aadlModService = ctx.getAadlModificatonService();
    final UiService uiService = ctx.getUiService();
    try {
        final BusinessObjectContext componentImplementationBoc = ToolUtil.findComponentImplementationBoc(selectedBocs[0]);
        // Open Dialog
        if (currentWindow == null && componentImplementationBoc != null) {
            currentWindow = new SetBindingWindow(Display.getCurrent().getActiveShell(), componentImplementationBoc, selectedBocs);
            if (currentWindow.open() == Window.OK) {
                // Ensure the diagram is configured to show the specified binding property
                if (!diagram.getConfiguration().getEnabledAadlPropertyNames().contains(currentWindow.getSelectedProperty().getQualifiedName().toLowerCase())) {
                    diagram.modify("Configure Diagram", m -> {
                        m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagram.getConfiguration()).addAadlProperty(currentWindow.getSelectedProperty().getQualifiedName()).build());
                    });
                }
                // Create the property association
                createPropertyAssociations(aadlModService);
            }
            currentWindow = null;
        }
    } finally {
        uiService.deactivateActiveTool();
    }
}
Also used : UiService(org.osate.ge.internal.services.UiService) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 2 with DiagramConfigurationBuilder

use of org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder in project osate2 by osate.

the class AgeDiagramTest method testDiagramConfigurationEvent.

// Ensure that the element updated added is received.
@Test
public void testDiagramConfigurationEvent() {
    assertThat(ml.wasDiagramConfigurationChanged(), is(equalTo(false)));
    // Test an add event
    diagram.modify("Set Diagram Configuration", m -> m.setDiagramConfiguration(new DiagramConfigurationBuilder(new CustomDiagramType(), false).addAadlProperty("test::test2").build()));
    assertThat(ml.wasDiagramConfigurationChanged(), is(equalTo(true)));
}
Also used : CustomDiagramType(org.osate.ge.aadl2.internal.diagramtypes.CustomDiagramType) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) Test(org.junit.Test)

Example 3 with DiagramConfigurationBuilder

use of org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder in project osate2 by osate.

the class DiagramContextChecker method promptToRelink.

/**
 * Returns whether or not the diagram context was adjusted.
 * @param diagram
 * @param missingContextRef
 * @return
 */
private boolean promptToRelink(final AgeDiagram diagram) {
    final CanonicalBusinessObjectReference missingContextRef = diagram.getConfiguration().getContextBoReference();
    final List<String> refSegs = missingContextRef.getSegments();
    if (refSegs.size() < 2) {
        return false;
    }
    final boolean isPackageRef = DeclarativeReferenceType.PACKAGE.getId().equals(refSegs.get(0));
    final boolean isClassifierRef = DeclarativeReferenceType.CLASSIFIER.getId().equals(refSegs.get(0));
    final boolean isSystemInstance = AadlReferenceUtil.isSystemInstanceReference(missingContextRef);
    if (!isPackageRef && !isClassifierRef && !isSystemInstance) {
        return false;
    }
    // Determine the options to present to the user
    final Collection<?> options;
    String searchPrefix = "";
    if (isPackageRef || isClassifierRef) {
        // Find all packages
        final Collection<IEObjectDescription> packageDescriptions = AadlModelAccessUtil.getAllEObjectsByType(project, Aadl2Package.eINSTANCE.getAadlPackage());
        if (isPackageRef) {
            options = packageDescriptions;
        } else {
            // isClassifierRef
            options = AadlModelAccessUtil.getAllEObjectsByType(project, Aadl2Package.eINSTANCE.getClassifier());
            // Check if the package portion of the qualified name is a valid package.
            // If so, use it as the initial filter
            final String referencedClassifierQualifiedName = refSegs.get(1);
            final String[] qualifiedNameParts = referencedClassifierQualifiedName.split("::");
            if (qualifiedNameParts.length == 2) {
                final String pkgName = qualifiedNameParts[0];
                for (final IEObjectDescription desc : packageDescriptions) {
                    if (desc.getName().toString("::").equalsIgnoreCase(pkgName)) {
                        searchPrefix = pkgName.toLowerCase() + "::";
                    }
                }
            }
        }
    } else if (isSystemInstance) {
        options = findInstanceModelFiles(project, new ArrayList<IPath>());
    } else {
        // Unexpected case: there is already a short circuit for the case where the reference isn't a package or classifier reference
        throw new RuntimeException("Unexpected case");
    }
    // Don't prompt if there aren't any options.
    if (options.size() == 0) {
        return false;
    }
    final ElementSelectionDialog dlg = new ElementSelectionDialog(null, "Missing Diagram Context", "Unable to find diagram context \"" + refService.getLabel(missingContextRef) + "\".\nIf the model element has been renamed, select the new name for the model element.", options);
    dlg.setFilter(searchPrefix);
    if (dlg.open() != Window.OK) {
        return false;
    }
    final CanonicalBusinessObjectReference newContextCanonicalRef;
    final RelativeBusinessObjectReference newContextRelativeRef;
    final Object newContext;
    if (isSystemInstance) {
        final IPath systemInstancePath = (IPath) dlg.getFirstSelectedElement();
        newContextCanonicalRef = AadlReferenceUtil.getCanonicalBusinessObjectReferenceForSystemInstance(systemInstanceLoader, systemInstancePath);
        newContextRelativeRef = AadlReferenceUtil.getRelativeBusinessObjectReferenceForSystemInstance(systemInstanceLoader, systemInstancePath);
        // Create a dummy system instance. It will be replaced as part of the diagram updating process.
        newContext = InstanceFactory.eINSTANCE.createSystemInstance();
    } else {
        final EObject newContextProxy = (EObject) dlg.getFirstSelectedElement();
        // Find the live object
        final ResourceSet liveResourceSet = AadlModelAccessUtil.getLiveResourceSet(project);
        newContext = EcoreUtil.resolve(newContextProxy, liveResourceSet);
        if (((EObject) newContext).eIsProxy()) {
            throw new RuntimeException("Unable to retrieve non-proxy object for selection");
        }
        // Find canonical and relative reference
        newContextCanonicalRef = refService.getCanonicalReference(newContext);
        if (newContextCanonicalRef == null) {
            throw new RuntimeException("Unable to retrieve reference for new diagram context: " + newContext);
        }
        newContextRelativeRef = refService.getRelativeReference(newContext);
        if (newContextRelativeRef == null) {
            throw new RuntimeException("Unable to retrieve relative reference for new diagram context: " + newContext);
        }
    }
    // Update the diagram
    diagram.modify("Update Diagram Context", m -> {
        // Update the diagram's context
        m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagram.getConfiguration()).contextBoReference(newContextCanonicalRef).build());
        // Update the root element
        if (diagram.getChildren().size() == 1) {
            m.updateBusinessObject(diagram.getChildren().stream().findAny().get(), newContext, newContextRelativeRef);
        }
    });
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ElementSelectionDialog(org.osate.ge.aadl2.ui.internal.dialogs.ElementSelectionDialog) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) EObject(org.eclipse.emf.ecore.EObject) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) EObject(org.eclipse.emf.ecore.EObject)

Example 4 with DiagramConfigurationBuilder

use of org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder 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 5 with DiagramConfigurationBuilder

use of org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder 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

DiagramConfigurationBuilder (org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder)5 CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)3 BusinessObjectContext (org.osate.ge.BusinessObjectContext)2 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)2 CustomDiagramType (org.osate.ge.aadl2.internal.diagramtypes.CustomDiagramType)2 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 Test (org.junit.Test)1 ContentFilter (org.osate.ge.ContentFilter)1 ElementSelectionDialog (org.osate.ge.aadl2.ui.internal.dialogs.ElementSelectionDialog)1 GraphicalEditorException (org.osate.ge.internal.GraphicalEditorException)1 DiagramConfiguration (org.osate.ge.internal.diagram.runtime.DiagramConfiguration)1