use of org.osate.ge.DiagramType 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.DiagramType in project osate2 by osate.
the class NewDiagramWizard method performFinish.
@Override
public boolean performFinish() {
try {
if (contextTypePage.getContextType() == ContextType.NEW_PACKAGE) {
// Use async exec so the current wizard will be closed before the new wizard opens.
Display.getDefault().asyncExec(() -> {
// Ideally, this would open the wizard and select the option to open it in the diagram editor. The wizard class can't be used directly at
// this time because that would require a circular dependency.
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IHandlerService handlerService = (IHandlerService) window.getService(IHandlerService.class);
try {
handlerService.executeCommand("org.osate.ui.wizards.packageWizard", null);
} catch (final Exception e) {
final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "New Diagram Error", e);
StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
throw new RuntimeException(e);
}
});
return true;
} else {
final Object context = getContext();
final CreateDiagramComposite.Value<DiagramType> diagramNameAndType = diagramNameAndTypePage.getValue();
diagramService.createDiagram(diagramNameAndType.getFile(), diagramNameAndType.getDiagramType(), context);
EditorUtil.openEditor(diagramNameAndType.getFile(), false);
return true;
}
} catch (final RuntimeException ex) {
final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "New Diagram Error", ex);
StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
return false;
}
}
use of org.osate.ge.DiagramType in project osate2 by osate.
the class DefaultDiagramService method createDiagram.
@Override
public IFile createDiagram(final Object contextBo) {
final IProject project = ProjectUtil.getProjectForBoOrThrow(contextBo);
// Prompt to determine the filepath and diagram type.
final CreateDiagramDialog.Model<DiagramType> createDiagramModel = new DefaultCreateDiagramModel(extRegistry, project, contextBo);
final CreateDiagramDialog.Result<DiagramType> result = CreateDiagramDialog.show(null, createDiagramModel);
if (result == null) {
return null;
}
createDiagram(result.getDiagramFile(), result.getDiagramType(), contextBo);
return result.getDiagramFile();
}
use of org.osate.ge.DiagramType in project osate2 by osate.
the class ShowDefaultContentsHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
if (diagram == null) {
throw new RuntimeException("Unable to get diagram");
}
final DiagramType diagramType = diagram.getConfiguration().getDiagramType();
final ContentFilterProvider contentFilterProvider = getContentFilterProvider();
final Function<DiagramElement, ImmutableSet<ContentFilter>> getContentFilters = (diagramElement) -> DiagramTypeUtil.getApplicableDefaultContentFilters(diagramType, diagramElement.getBusinessObject(), contentFilterProvider);
// Show elements matching the filter
ShowContentsUtil.addContentsToSelectedElements(event, getContentFilters);
return null;
}
Aggregations