Search in sources :

Example 1 with Diagram

use of org.osate.ge.diagram.Diagram in project osate2 by osate.

the class DiagramSerialization method readMetaModelDiagram.

/**
 * Loads the serialized diagram
 * @param uri the URI specifying the location of the diagram file
 * @return the serialized diagram
 */
public static org.osate.ge.diagram.Diagram readMetaModelDiagram(final URI uri) {
    Objects.requireNonNull(uri, "uri must not be null");
    // Load the resource
    final ResourceSet rs = new ResourceSetImpl();
    final Resource resource = rs.createResource(uri);
    try {
        resource.load(Collections.singletonMap(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, true));
        if (resource.getContents().size() == 0 || !(resource.getContents().get(0) instanceof org.osate.ge.diagram.Diagram)) {
            throw new GraphicalEditorException("Unable to load diagram.");
        }
        final org.osate.ge.diagram.Diagram mmDiagram = (org.osate.ge.diagram.Diagram) resource.getContents().get(0);
        return mmDiagram;
    } catch (final IOException e) {
        throw new GraphicalEditorException(e);
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) Diagram(org.osate.ge.diagram.Diagram) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) Diagram(org.osate.ge.diagram.Diagram)

Example 2 with Diagram

use of org.osate.ge.diagram.Diagram in project osate2 by osate.

the class DiagramSerialization method write.

/**
 * Serialized the specified runtime diagram and writes is to a file.
 * @param project the project in which the diagram is contained.
 * @param diagram the runtime diagram to serialize
 * @param uri the URI specifying the file to which to write the serialized diagram
 */
public static void write(final IProject project, final AgeDiagram diagram, final URI uri) {
    // Convert from the runtime format to the metamodel format which is stored
    final org.osate.ge.diagram.Diagram mmDiagram = new Diagram();
    mmDiagram.setFormatVersion(FORMAT_VERSION);
    final org.osate.ge.diagram.DiagramConfiguration mmConfig = new org.osate.ge.diagram.DiagramConfiguration();
    mmDiagram.setConfig(mmConfig);
    // Populate the diagram configuration
    final DiagramConfiguration config = diagram.getConfiguration();
    mmConfig.setType(config.getDiagramType().getId());
    mmConfig.setContext(config.getContextBoReference() == null ? null : config.getContextBoReference().toMetamodel());
    mmConfig.setConnectionPrimaryLabelsVisible(config.getConnectionPrimaryLabelsVisible());
    final org.osate.ge.diagram.AadlPropertiesSet enabledProperties = new org.osate.ge.diagram.AadlPropertiesSet();
    mmConfig.setEnabledAadlProperties(enabledProperties);
    for (final String enabledPropertyName : config.getEnabledAadlPropertyNames()) {
        enabledProperties.getProperty().add(enabledPropertyName);
    }
    convertElementsToMetamodel(project, mmDiagram, diagram.getChildren());
    // Save the resource
    final ResourceSet rs = new ResourceSetImpl();
    final Resource resource = rs.createResource(uri);
    resource.getContents().add(mmDiagram);
    try {
        resource.save(Collections.emptyMap());
    } catch (IOException e) {
        throw new GraphicalEditorException(e);
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Diagram(org.osate.ge.diagram.Diagram) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) Diagram(org.osate.ge.diagram.Diagram) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException)

Aggregations

IOException (java.io.IOException)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)2 Diagram (org.osate.ge.diagram.Diagram)2 GraphicalEditorException (org.osate.ge.internal.GraphicalEditorException)2