Search in sources :

Example 1 with UnrecognizedDiagramType

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;
}
Also used : HashMap(java.util.HashMap) UnrecognizedDiagramType(org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) CustomDiagramType(org.osate.ge.aadl2.internal.diagramtypes.CustomDiagramType) StructureDiagramType(org.osate.ge.aadl2.internal.diagramtypes.StructureDiagramType) DiagramType(org.osate.ge.DiagramType) PackageDiagramType(org.osate.ge.aadl2.internal.diagramtypes.PackageDiagramType) UnrecognizedDiagramType(org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType) UUID(java.util.UUID)

Example 2 with UnrecognizedDiagramType

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IStatus(org.eclipse.core.runtime.IStatus) Map(java.util.Map) StatusManager(org.eclipse.ui.statushandlers.StatusManager) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IEditorPart(org.eclipse.ui.IEditorPart) ImmutableSet(com.google.common.collect.ImmutableSet) PlatformUI(org.eclipse.ui.PlatformUI) Collection(java.util.Collection) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) Display(org.eclipse.swt.widgets.Display) ListDialog(org.eclipse.ui.dialogs.ListDialog) DiagramSerialization(org.osate.ge.internal.diagram.runtime.DiagramSerialization) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) ProjectUtil(org.osate.ge.ProjectUtil) Objects(java.util.Objects) ReferenceService(org.osate.ge.internal.services.ReferenceService) List(java.util.List) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) GraphicalEditor(org.osate.ge.GraphicalEditor) Entry(java.util.Map.Entry) Resource(org.eclipse.emf.ecore.resource.Resource) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) AgeDiagramProvider(org.osate.ge.internal.AgeDiagramProvider) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) URI(org.eclipse.emf.common.util.URI) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) DiagramModification(org.osate.ge.internal.diagram.runtime.DiagramModification) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) HashMap(java.util.HashMap) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IFile(org.eclipse.core.resources.IFile) DefaultCreateDiagramModel(org.osate.ge.internal.ui.dialogs.DefaultCreateDiagramModel) DiagramService(org.osate.ge.internal.services.DiagramService) IOException(java.io.IOException) SavedDiagramIndex(org.osate.ge.internal.indexing.SavedDiagramIndex) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) EditorUtil(org.osate.ge.internal.ui.util.EditorUtil) SavedDiagramIndexInvalidator(org.osate.ge.internal.indexing.SavedDiagramIndexInvalidator) IResource(org.eclipse.core.resources.IResource) DiagramType(org.osate.ge.DiagramType) IEditorReference(org.eclipse.ui.IEditorReference) Log(org.osate.ge.internal.util.Log) CreateDiagramDialog(org.osate.ge.internal.ui.dialogs.CreateDiagramDialog) UnrecognizedDiagramType(org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ListDialog(org.eclipse.ui.dialogs.ListDialog) UnrecognizedDiagramType(org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType)

Aggregations

HashMap (java.util.HashMap)2 CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)2 DiagramType (org.osate.ge.DiagramType)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1