Search in sources :

Example 1 with BusinessObjectProviderHelper

use of org.osate.ge.internal.util.BusinessObjectProviderHelper in project osate2 by osate.

the class ShowElementsInModeHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final InternalDiagramEditor editor = getDiagramEditor(event);
    referenceService = Objects.requireNonNull(Adapters.adapt(editor, ProjectReferenceService.class), "Unable to retrieve reference service");
    final ExtensionRegistryService extService = Objects.requireNonNull(Adapters.adapt(editor, ExtensionRegistryService.class), "Unable to retrieve extension service");
    final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
    final BusinessObjectTreeUpdater boTreeUpdater = editor.getBoTreeUpdater();
    final BusinessObjectNode boTree = getBoTree(editor, boTreeUpdater);
    final List<BusinessObjectContext> selectedModes = AgeHandlerUtil.getSelectedBusinessObjectContexts().stream().filter(de -> isModal(de.getBusinessObject())).collect(Collectors.toList());
    for (final BusinessObjectContext selectedMode : selectedModes) {
        enableInModeNodes(bopHelper, boTree, selectedMode);
    }
    final AgeDiagram diagram = editor.getDiagram();
    final DiagramUpdater diagramUpdater = editor.getDiagramUpdater();
    final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(editor, LayoutInfoProvider.class), "Unable to retrieve layout info provider");
    editor.getActionExecutor().execute("Show Elements In Mode", ExecutionMode.NORMAL, () -> {
        // Update the diagram
        diagramUpdater.updateDiagram(diagram, boTree);
        // Update layout
        diagram.modify("Layout Incrementally", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
        return null;
    });
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ModalElement(org.osate.aadl2.ModalElement) DiagramToBusinessObjectTreeConverter(org.osate.ge.internal.diagram.runtime.updating.DiagramToBusinessObjectTreeConverter) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ModeTransition(org.osate.aadl2.ModeTransition) LinkedList(java.util.LinkedList) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) Completeness(org.osate.ge.internal.diagram.runtime.updating.Completeness) IEditorPart(org.eclipse.ui.IEditorPart) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) FeatureGroup(org.osate.aadl2.FeatureGroup) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) ModeFeature(org.osate.aadl2.ModeFeature) UUID(java.util.UUID) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) Objects(java.util.Objects) Adapters(org.eclipse.core.runtime.Adapters) Mode(org.osate.aadl2.Mode) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) ModeInstance(org.osate.aadl2.instance.ModeInstance) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) AadlModalElementUtil(org.osate.ge.aadl2.internal.util.AadlModalElementUtil) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) Queue(java.util.Queue) AbstractHandler(org.eclipse.core.commands.AbstractHandler) NamedElement(org.osate.aadl2.NamedElement) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Collections(java.util.Collections) InstanceObject(org.osate.aadl2.instance.InstanceObject) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) BusinessObjectContext(org.osate.ge.BusinessObjectContext) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider)

Example 2 with BusinessObjectProviderHelper

use of org.osate.ge.internal.util.BusinessObjectProviderHelper in project osate2 by osate.

the class DefaultBusinessObjectTreeUpdater method updateTree.

@Override
public BusinessObjectNode updateTree(final DiagramConfiguration configuration, final BusinessObjectNode tree) {
    // Refresh Child Nodes
    final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
    final BusinessObjectNode newRoot = nodeFactory.create(null, UUID.randomUUID(), null, Completeness.UNKNOWN);
    final Map<RelativeBusinessObjectReference, Object> boMap;
    // Determine what business objects are required based on the diagram configuration
    if (configuration.getContextBoReference() == null) {
        // Get potential top level business objects from providers
        // A simple business object context which is used as the root BOC for contextless diagrams. It has no parent and used the current
        // project as the business object.
        final BusinessObjectContext contextlessRootBoc = new BusinessObjectContext() {

            @Override
            public Collection<? extends BusinessObjectContext> getChildren() {
                return Collections.emptyList();
            }

            @Override
            public BusinessObjectContext getParent() {
                return null;
            }

            @Override
            public Object getBusinessObject() {
                return projectProvider.getProject();
            }
        };
        final Collection<Object> potentialRootBusinessObjects = bopHelper.getChildBusinessObjects(contextlessRootBoc);
        // Determine the root business objects
        final Set<RelativeBusinessObjectReference> existingRootBranches = tree.getChildrenMap().keySet();
        // Content filters are not supported for the root of diagrams.
        final ImmutableSet<ContentFilter> rootContentFilters = ImmutableSet.of();
        boMap = getChildBusinessObjects(potentialRootBusinessObjects, existingRootBranches, rootContentFilters);
        // Contextless diagrams are always considered complete
        newRoot.setCompleteness(Completeness.COMPLETE);
        // This is needed so the configure diagram dialog, etc will know which project should be used to
        // retrieve root objects.
        // Set the root of the BO tree to the project
        newRoot.setBusinessObject(projectProvider.getProject());
    } else {
        // Get the context business object
        Object contextBo = refService.resolve(configuration.getContextBoReference());
        if (contextBo == null) {
            final String contextLabel = refService.getLabel(configuration.getContextBoReference());
            throw new GraphicalEditorException("Unable to find context business object: " + contextLabel);
        }
        // Require the use of the business object specified in the diagram along with any other business objects which are already in the diagram.
        final RelativeBusinessObjectReference relativeReference = refService.getRelativeReference(contextBo);
        if (relativeReference == null) {
            throw new GraphicalEditorException("Unable to build relative reference for context business object: " + contextBo);
        }
        boMap = new HashMap<>();
        boMap.put(relativeReference, contextBo);
        newRoot.setCompleteness(Completeness.COMPLETE);
    }
    // Add embedded business objects to the child BO map
    addEmbeddedBusinessObjectsToBoMap(tree.getChildrenMap().values(), boMap);
    // Populate the new tree
    final Map<RelativeBusinessObjectReference, BusinessObjectNode> oldNodes = tree.getChildrenMap();
    createNodes(configuration.getDiagramType(), bopHelper, boMap, oldNodes, newRoot);
    // Build set of the names of all properties which are enabled
    final Set<String> enabledPropertyNames = new HashSet<>(configuration.getEnabledAadlPropertyNames());
    // Add properties which are always enabled regardless of configuration setting
    enabledPropertyNames.add("communication_properties::timing");
    // Get the property objects
    final Set<Property> enabledProperties = getPropertiesByLowercasePropertyNames(enabledPropertyNames);
    // Process properties. This is done after everything else since properties may need to refer to other nodes.
    final AadlPropertyResolver propertyResolver = new AadlPropertyResolver(newRoot);
    processProperties(propertyResolver, newRoot, tree, enabledProperties);
    return newRoot;
}
Also used : AadlPropertyResolver(org.osate.ge.aadl2.internal.aadlproperties.AadlPropertyResolver) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) ContentFilter(org.osate.ge.ContentFilter) FundamentalContentFilter(org.osate.ge.FundamentalContentFilter) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) EObject(org.eclipse.emf.ecore.EObject) InstanceObject(org.osate.aadl2.instance.InstanceObject) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Property(org.osate.aadl2.Property) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) HashSet(java.util.HashSet)

Example 3 with BusinessObjectProviderHelper

use of org.osate.ge.internal.util.BusinessObjectProviderHelper in project osate2 by osate.

the class RestoreMissingDiagramElementsHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof InternalDiagramEditor)) {
        throw new RuntimeException("Unexpected editor: " + activeEditor);
    }
    // Get editor and various services
    final InternalDiagramEditor diagramEditor = (InternalDiagramEditor) activeEditor;
    final ProjectProvider projectProvider = (ProjectProvider) Objects.requireNonNull(diagramEditor.getAdapter(ProjectProvider.class), "Unable to retrieve project provider");
    final DiagramUpdater diagramUpdater = Objects.requireNonNull(diagramEditor.getDiagramUpdater(), "Unable to retrieve diagram updater");
    final ExtensionRegistryService extService = (ExtensionRegistryService) Objects.requireNonNull(diagramEditor.getAdapter(ExtensionRegistryService.class), "Unable to retrieve extension service");
    final AgeDiagram diagram = diagramEditor.getDiagram();
    final IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext());
    final ReferenceService referenceService = Objects.requireNonNull(serviceContext.get(ReferenceService.class), "Unable to retrieve reference service");
    final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(diagramEditor, LayoutInfoProvider.class), "Unable to retrieve layout info provider");
    // Stores child business object contexts which are applicable for a given parent node
    final Multimap<DiagramNode, BusinessObjectContext> diagramNodeToAvailableBusinessObjectContextsMap = ArrayListMultimap.create();
    // Build a list of ghosts that will be presented to the user to modify
    final List<DiagramUpdater.GhostedElement> ghostsToModify = new ArrayList<>();
    final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
    // Walk all nodes and look for ghosts
    diagram.getAllDiagramNodes().forEachOrdered(parent -> {
        final Collection<DiagramUpdater.GhostedElement> ghosts = diagramUpdater.getGhosts(parent);
        if (!ghosts.isEmpty()) {
            final BusinessObjectContext parentToUse;
            if (diagram.getConfiguration().getContextBoReference() == null && parent.getParent() == null) {
                parentToUse = getRootContextForProject(projectProvider);
            } else {
                parentToUse = parent;
            }
            // Create a mapping between relative reference and available child business objects
            final Map<RelativeBusinessObjectReference, Object> relRefToBusinessObjectMap = bopHelper.getChildBusinessObjects(parentToUse).stream().collect(HashMap::new, (map, bo) -> {
                final RelativeBusinessObjectReference relRef = referenceService.getRelativeReference(bo);
                if (relRef != null) {
                    map.put(relRef, bo);
                }
            }, Map::putAll);
            // Remove any entries based on existing node relative references.
            parent.getChildren().forEach(de -> relRefToBusinessObjectMap.remove(de.getRelativeReference()));
            // Don't show ghosts if there aren't any unused business objects
            if (!relRefToBusinessObjectMap.isEmpty()) {
                // Store the ghosts and the available business objects
                relRefToBusinessObjectMap.values().stream().map(bo -> new BusinessObjectContext() {

                    @Override
                    public Collection<? extends BusinessObjectContext> getChildren() {
                        return Collections.emptyList();
                    }

                    @Override
                    public BusinessObjectContext getParent() {
                        return parent;
                    }

                    @Override
                    public Object getBusinessObject() {
                        return bo;
                    }
                }).forEachOrdered(// see https://github.com/osate/osate2/issues/976
                boc -> diagramNodeToAvailableBusinessObjectContextsMap.put(parent, (BusinessObjectContext) boc));
                ghostsToModify.addAll(ghosts);
            }
        }
    });
    // Show the dialog
    final RestoreMissingDiagramElementsDialog.Result<DiagramUpdater.GhostedElement, BusinessObjectContext> result = RestoreMissingDiagramElementsDialog.show(null, new RestoreMissingDiagramElementsDialog.Model<DiagramUpdater.GhostedElement, BusinessObjectContext>() {

        @Override
        public Collection<DiagramUpdater.GhostedElement> getElements() {
            return ghostsToModify;
        }

        @Override
        public String getParentLabel(final DiagramUpdater.GhostedElement element) {
            return UiUtil.getPathLabel(element.getParent());
        }

        @Override
        public String getMissingReferenceLabel(final DiagramUpdater.GhostedElement element) {
            return referenceService.getLabel(element.getRelativeReference());
        }

        @Override
        public Collection<BusinessObjectContext> getAvailableBusinessObjects(final DiagramUpdater.GhostedElement element) {
            return diagramNodeToAvailableBusinessObjectContextsMap.get(element.getParent());
        }

        @Override
        public String getBusinessObjectLabel(final BusinessObjectContext boc) {
            return UiUtil.getDescription(boc, extService);
        }
    });
    if (result != null) {
        diagramEditor.getActionExecutor().execute("Restore Missing Diagram Elements", ExecutionMode.NORMAL, () -> {
            // Update the ghosts and the diagram
            diagram.modify("Restore Missing Diagram Elements", m -> {
                result.getObjectToNewBoMap().forEach((ghost, newBoc) -> {
                    final Object newBo = newBoc.getBusinessObject();
                    ghost.updateBusinessObject(m, newBo, referenceService.getRelativeReference(newBo));
                });
                // Update the diagram
                diagramUpdater.updateDiagram(diagram);
            });
            diagram.modify("Layout", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
            return null;
        });
    }
    return null;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) EclipseContextFactory(org.eclipse.e4.core.contexts.EclipseContextFactory) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) RestoreMissingDiagramElementsDialog(org.osate.ge.internal.ui.dialogs.RestoreMissingDiagramElementsDialog) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) HashMap(java.util.HashMap) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectContext(org.osate.ge.BusinessObjectContext) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Map(java.util.Map) ProjectProvider(org.osate.ge.internal.services.ProjectProvider) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) IEditorPart(org.eclipse.ui.IEditorPart) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) Collection(java.util.Collection) ExecutionException(org.eclipse.core.commands.ExecutionException) Objects(java.util.Objects) Adapters(org.eclipse.core.runtime.Adapters) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) ReferenceService(org.osate.ge.internal.services.ReferenceService) List(java.util.List) UiUtil(org.osate.ge.internal.ui.util.UiUtil) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) AbstractHandler(org.eclipse.core.commands.AbstractHandler) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) ReferenceService(org.osate.ge.internal.services.ReferenceService) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) HashMap(java.util.HashMap) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) ArrayList(java.util.ArrayList) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) ProjectProvider(org.osate.ge.internal.services.ProjectProvider) RestoreMissingDiagramElementsDialog(org.osate.ge.internal.ui.dialogs.RestoreMissingDiagramElementsDialog) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) IEditorPart(org.eclipse.ui.IEditorPart) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Collection(java.util.Collection) BusinessObjectContext(org.osate.ge.BusinessObjectContext) HashMap(java.util.HashMap) Map(java.util.Map) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider)

Example 4 with BusinessObjectProviderHelper

use of org.osate.ge.internal.util.BusinessObjectProviderHelper in project osate2 by osate.

the class ShowContentsUtil method addChildrenDuringNextUpdate.

/**
 * Adds children of the specified diagram elements to the list of elements which will be added during the next diagram update.
 * @return whether children were added to the diagram.
 */
private static boolean addChildrenDuringNextUpdate(final List<DiagramElement> diagramElements, final DiagramUpdater diagramUpdater, final ExtensionRegistryService extService, final ReferenceBuilderService referenceBuilder, final Function<DiagramElement, ImmutableSet<ContentFilter>> filters) {
    boolean childrenAdded = false;
    final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
    for (final DiagramElement selectedElement : diagramElements) {
        final ImmutableSet<ContentFilter> contentFilters = filters.apply(selectedElement);
        if (!contentFilters.isEmpty()) {
            for (final Object childBo : bopHelper.getChildBusinessObjects(selectedElement)) {
                final RelativeBusinessObjectReference relativeReference = referenceBuilder.getRelativeReference(childBo);
                if (relativeReference != null && selectedElement.getChildByRelativeReference(relativeReference) == null && ContentFilterUtil.passesAnyContentFilter(childBo, contentFilters)) {
                    diagramUpdater.addToNextUpdate(selectedElement, relativeReference, new FutureElementInfo());
                    childrenAdded = true;
                }
            }
        }
    }
    return childrenAdded;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) FutureElementInfo(org.osate.ge.internal.diagram.runtime.updating.FutureElementInfo) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) ContentFilter(org.osate.ge.ContentFilter)

Aggregations

RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)4 BusinessObjectProviderHelper (org.osate.ge.internal.util.BusinessObjectProviderHelper)4 BusinessObjectContext (org.osate.ge.BusinessObjectContext)3 Collections (java.util.Collections)2 List (java.util.List)2 Objects (java.util.Objects)2 AbstractHandler (org.eclipse.core.commands.AbstractHandler)2 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 Adapters (org.eclipse.core.runtime.Adapters)2 IEditorPart (org.eclipse.ui.IEditorPart)2 HandlerUtil (org.eclipse.ui.handlers.HandlerUtil)2 InstanceObject (org.osate.aadl2.instance.InstanceObject)2 ContentFilter (org.osate.ge.ContentFilter)2 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)2 DiagramElementLayoutUtil (org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil)2 LayoutInfoProvider (org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider)2 DiagramUpdater (org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater)2 ExecutionMode (org.osate.ge.internal.services.ActionExecutor.ExecutionMode)2 ExtensionRegistryService (org.osate.ge.internal.services.ExtensionRegistryService)2