Search in sources :

Example 1 with DiagramType

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;
}
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 DiagramType

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;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IHandlerService(org.eclipse.ui.handlers.IHandlerService) DiagramType(org.osate.ge.DiagramType) EObject(org.eclipse.emf.ecore.EObject) CreateDiagramComposite(org.osate.ge.internal.ui.dialogs.CreateDiagramComposite)

Example 3 with DiagramType

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();
}
Also used : DiagramType(org.osate.ge.DiagramType) UnrecognizedDiagramType(org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType) DefaultCreateDiagramModel(org.osate.ge.internal.ui.dialogs.DefaultCreateDiagramModel) CreateDiagramDialog(org.osate.ge.internal.ui.dialogs.CreateDiagramDialog) IProject(org.eclipse.core.resources.IProject)

Example 4 with DiagramType

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;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) EclipseContextFactory(org.eclipse.e4.core.contexts.EclipseContextFactory) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ImmutableSet(com.google.common.collect.ImmutableSet) DiagramTypeUtil(org.osate.ge.internal.util.DiagramTypeUtil) ContentFilter(org.osate.ge.ContentFilter) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) ExecutionException(org.eclipse.core.commands.ExecutionException) Function(java.util.function.Function) Objects(java.util.Objects) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) UiUtil(org.osate.ge.internal.ui.util.UiUtil) DiagramType(org.osate.ge.DiagramType) AbstractHandler(org.eclipse.core.commands.AbstractHandler) Bundle(org.osgi.framework.Bundle) FrameworkUtil(org.osgi.framework.FrameworkUtil) ContentFilterProvider(org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider) ImmutableSet(com.google.common.collect.ImmutableSet) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) DiagramType(org.osate.ge.DiagramType) ContentFilterProvider(org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider)

Aggregations

DiagramType (org.osate.ge.DiagramType)4 UnrecognizedDiagramType (org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 AbstractHandler (org.eclipse.core.commands.AbstractHandler)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IProject (org.eclipse.core.resources.IProject)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 EclipseContextFactory (org.eclipse.e4.core.contexts.EclipseContextFactory)1 EObject (org.eclipse.emf.ecore.EObject)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 IHandlerService (org.eclipse.ui.handlers.IHandlerService)1 CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)1 ContentFilter (org.osate.ge.ContentFilter)1