use of org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType in project osate2 by osate.
the class DiagramSerialization method createAgeDiagram.
/**
* Converts the serialized diagram to a runtime diagram
* @param project the project in which the serialized diagram is contained.
* @param mmDiagram the serialized diagram
* @param extRegistry the Eclipse extension registry
* @return the runtime diagram
*/
public static AgeDiagram createAgeDiagram(final IProject project, final org.osate.ge.diagram.Diagram mmDiagram, final ExtensionRegistryService extRegistry) {
Objects.requireNonNull(extRegistry, "extRegistry is null");
// Set the id which should be used for new diagram elements.
final AgeDiagram ageDiagram = new AgeDiagram();
// Read the diagram configuration
// Set the diagram type
final String diagramTypeId;
if (mmDiagram.getConfig() == null || mmDiagram.getConfig().getType() == null) {
// Assign a diagram type ID if the diagram does not have specify one.
String autoAssignedDiagramTypeId = CustomDiagramType.ID;
// Set the diagram type based on the diagram's context
if (mmDiagram.getConfig() != null) {
final CanonicalBusinessObjectReference contextRef = convert(mmDiagram.getConfig().getContext());
if (contextRef != null && contextRef.getSegments().size() > 1) {
if (DeclarativeReferenceType.PACKAGE.getId().equals(contextRef.getSegments().get(0))) {
autoAssignedDiagramTypeId = PackageDiagramType.ID;
} else if (DeclarativeReferenceType.CLASSIFIER.getId().equals(contextRef.getSegments().get(0))) {
autoAssignedDiagramTypeId = StructureDiagramType.ID;
}
}
}
diagramTypeId = autoAssignedDiagramTypeId;
} else {
diagramTypeId = mmDiagram.getConfig().getType();
}
final DiagramType diagramType = extRegistry.getDiagramTypeById(diagramTypeId).orElseGet(() -> new UnrecognizedDiagramType(diagramTypeId));
final DiagramConfigurationBuilder configBuilder = new DiagramConfigurationBuilder(diagramType, false);
if (mmDiagram.getConfig() != null) {
final org.osate.ge.diagram.DiagramConfiguration mmDiagramConfig = mmDiagram.getConfig();
configBuilder.contextBoReference(convert(mmDiagramConfig.getContext()));
final org.osate.ge.diagram.AadlPropertiesSet enabledAadlProperties = mmDiagramConfig.getEnabledAadlProperties();
if (enabledAadlProperties != null) {
for (final String enabledProperty : enabledAadlProperties.getProperty()) {
configBuilder.addAadlProperty(enabledProperty);
}
}
configBuilder.connectionPrimaryLabelsVisible(mmDiagramConfig.getConnectionPrimaryLabelsVisible());
}
// Ensure UUIDs are valid and handle migration from legacy id's.
final Map<Long, UUID> legacyIdToUuidMap = new HashMap<>();
ensureIdsAreValid(mmDiagram, legacyIdToUuidMap);
updateReferencesToLegacyIds(mmDiagram, legacyIdToUuidMap);
ageDiagram.modify("Configure Diagram", m -> {
m.setDiagramConfiguration(configBuilder.build());
});
// Read elements
ageDiagram.modify("Read from File", m -> {
readElements(project, m, ageDiagram, mmDiagram, legacyIdToUuidMap);
});
return ageDiagram;
}
use of org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType in project osate2 by osate.
the class DefaultDiagramService method promptForDiagram.
private InternalDiagramReference promptForDiagram(final List<InternalDiagramReference> diagramRefs) {
// Sort the diagram references
final InternalDiagramReference[] sortedDiagramRefs = diagramRefs.stream().sorted((r1, r2) -> r1.getFile().getName().compareToIgnoreCase(r2.getFile().getName())).toArray(InternalDiagramReference[]::new);
// Prompt user to select a single dialog reference
final ListDialog dialog = new ListDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
dialog.setAddCancelButton(true);
dialog.setTitle("Select Diagram");
dialog.setMessage("Select a Diagram to Open");
dialog.setWidthInChars(90);
dialog.setLabelProvider(new LabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof InternalDiagramReference) {
final InternalDiagramReference diagramRef = (InternalDiagramReference) element;
final String diagramTypeName = extRegistry.getDiagramTypeById(diagramRef.getDiagramTypeId()).orElseGet(() -> new UnrecognizedDiagramType(diagramRef.getDiagramTypeId())).getName();
return diagramRef.getFile().getName() + " (" + diagramTypeName + ")";
}
return super.getText(element);
}
});
dialog.setContentProvider(new ArrayContentProvider());
dialog.setInput(sortedDiagramRefs);
dialog.setInitialElementSelections(Collections.singletonList(sortedDiagramRefs[0]));
dialog.open();
final Object[] result = dialog.getResult();
return (result != null && result.length > 0) ? (InternalDiagramReference) result[0] : null;
}
Aggregations