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);
}
}
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);
}
}
Aggregations