Search in sources :

Example 6 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService in project osate2 by osate.

the class HideAllContentsHandler 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 the extension registry
    final Bundle bundle = FrameworkUtil.getBundle(getClass());
    final ExtensionRegistryService extService = EclipseContextFactory.getServiceContext(bundle.getBundleContext()).get(ExtensionRegistryService.class);
    if (extService == null) {
        throw new RuntimeException("Unable to retrieve extension registry");
    }
    // Get diagram and selected elements
    final InternalDiagramEditor diagramEditor = (InternalDiagramEditor) activeEditor;
    final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
    final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
    if (diagram == null) {
        throw new RuntimeException("Unable to get diagram");
    }
    diagram.modify("Hide All Contents", m -> {
        // Remove children of selected elements
        for (final DiagramElement e : selectedDiagramElements) {
            for (final DiagramElement child : e.getChildren()) {
                m.removeElement(child);
            }
        }
    });
    // Update the diagram
    diagramEditor.updateDiagram();
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Bundle(org.osgi.framework.Bundle) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) IEditorPart(org.eclipse.ui.IEditorPart)

Example 7 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService in project osate2 by osate.

the class ShowHideFiltersContributionItem method getContributionItems.

@Override
protected IContributionItem[] getContributionItems() {
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return EMPTY;
    }
    if (window.getActivePage() == null) {
        return EMPTY;
    }
    final IEditorPart activeEditor = window.getActivePage().getActiveEditor();
    if (!(activeEditor instanceof InternalDiagramEditor)) {
        return EMPTY;
    }
    // Don't contribute commands if editor is not editable
    final InternalDiagramEditor editor = (InternalDiagramEditor) activeEditor;
    if (activeEditor == null || !editor.isEditable()) {
        return EMPTY;
    }
    final Bundle bundle = FrameworkUtil.getBundle(getClass());
    final ExtensionRegistryService extRegistry = Objects.requireNonNull(EclipseContextFactory.getServiceContext(bundle.getBundleContext()).get(ExtensionRegistryService.class), "Unable to retrieve extension registry");
    final List<DiagramElement> diagramElements = SelectionUtil.getSelectedDiagramElements(window.getActivePage().getSelection(), true);
    final AgeDiagram diagram = UiUtil.getDiagram(diagramElements);
    if (diagram == null) {
        return EMPTY;
    }
    final Multimap<String, ContentFilter> parentToApplicableFiltersMap = HashMultimap.create();
    for (final ContentFilter contentFilter : extRegistry.getConfigurableContentFilters()) {
        for (final DiagramElement diagramElement : diagramElements) {
            if (contentFilter.isApplicable(diagramElement.getBusinessObject())) {
                parentToApplicableFiltersMap.put(contentFilter.getParentId(), contentFilter);
                break;
            }
        }
    }
    // Create command contributions
    final List<IContributionItem> contributions = new ArrayList<>();
    addContributionItems(contributions, null, parentToApplicableFiltersMap, window);
    if (contributions.size() != 0) {
        contributions.add(new Separator());
    }
    return contributions.toArray(new IContributionItem[contributions.size()]);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Bundle(org.osgi.framework.Bundle) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ContentFilter(org.osate.ge.ContentFilter) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Separator(org.eclipse.jface.action.Separator)

Example 8 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService 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 9 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService in project osate2 by osate.

the class HideContentFilterHandler method getContentFilterProvider.

private ContentFilterProvider getContentFilterProvider() {
    final Bundle bundle = FrameworkUtil.getBundle(getClass());
    final ExtensionRegistryService extService = Objects.requireNonNull(EclipseContextFactory.getServiceContext(bundle.getBundleContext()).get(ExtensionRegistryService.class), "Unable to retrieve extension registry");
    return extService;
}
Also used : Bundle(org.osgi.framework.Bundle) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService)

Example 10 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService in project osate2 by osate.

the class HideElementHandler method getElementsToHide.

/**
 * Gets the elements to hide. Elements are hideable if they are configurable and they are not at the root of a diagram which has a context.
 * @param selectedDiagramElements
 * @return
 */
private List<DiagramElement> getElementsToHide(final List<DiagramElement> selectedDiagramElements) {
    final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
    final boolean diagramHasContext = diagram != null && diagram.getConfiguration().getContextBoReference() != null;
    // Get the extension registry
    final Bundle bundle = FrameworkUtil.getBundle(getClass());
    final ExtensionRegistryService extService = Objects.requireNonNull(EclipseContextFactory.getServiceContext(bundle.getBundleContext()).get(ExtensionRegistryService.class), "Unable to retrieve extension registry");
    return selectedDiagramElements.stream().filter(de -> (!diagramHasContext || de.getParent() != diagram) && FilteringUtil.isConfigurable(extService, de.getBusinessObject())).collect(Collectors.toList());
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) EclipseContextFactory(org.eclipse.e4.core.contexts.EclipseContextFactory) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) Objects(java.util.Objects) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) UiUtil(org.osate.ge.internal.ui.util.UiUtil) FilteringUtil(org.osate.ge.internal.diagram.runtime.filtering.FilteringUtil) AbstractHandler(org.eclipse.core.commands.AbstractHandler) Bundle(org.osgi.framework.Bundle) IEditorPart(org.eclipse.ui.IEditorPart) FrameworkUtil(org.osgi.framework.FrameworkUtil) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Bundle(org.osgi.framework.Bundle) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService)

Aggregations

ExtensionRegistryService (org.osate.ge.internal.services.ExtensionRegistryService)12 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)8 IEditorPart (org.eclipse.ui.IEditorPart)7 Bundle (org.osgi.framework.Bundle)7 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)6 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)5 DiagramUpdater (org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater)5 List (java.util.List)3 Objects (java.util.Objects)3 AbstractHandler (org.eclipse.core.commands.AbstractHandler)3 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 HandlerUtil (org.eclipse.ui.handlers.HandlerUtil)3 LayoutInfoProvider (org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider)3 ProjectProvider (org.osate.ge.internal.services.ProjectProvider)3 ProjectReferenceService (org.osate.ge.internal.services.ProjectReferenceService)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2