Search in sources :

Example 1 with ContentFilterProvider

use of org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider in project osate2 by osate.

the class HideContentFilterHandler 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 diagram and selected elements
    final InternalDiagramEditor diagramEditor = (InternalDiagramEditor) activeEditor;
    final String contentFilterId = (String) event.getParameters().get(PARAM_CONTENTS_FILTER_ID);
    if (contentFilterId == null) {
        throw new RuntimeException("Unable to get content filter");
    }
    final ContentFilterProvider contentFilterProvider = getContentFilterProvider();
    final ContentFilter filter = contentFilterProvider.getContentFilterById(contentFilterId).orElseThrow(() -> new RuntimeException("Unable to get content filter"));
    final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
    final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
    if (diagram == null) {
        throw new RuntimeException("Unable to get diagram");
    }
    final List<DiagramElement> elementsToRemove = selectedDiagramElements.stream().filter(s -> filter.isApplicable(s.getBusinessObject())).flatMap(s -> s.getChildren().stream().filter(child -> filter.test(child.getBusinessObject()))).collect(Collectors.toList());
    if (!elementsToRemove.isEmpty()) {
        diagram.modify("Hide", m -> {
            for (final DiagramElement selectedDiagramElement : selectedDiagramElements) {
                if (filter.isApplicable(selectedDiagramElement.getBusinessObject())) {
                    for (final DiagramElement child : selectedDiagramElement.getChildren()) {
                        if (filter.test(child.getBusinessObject())) {
                            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) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) EclipseContextFactory(org.eclipse.e4.core.contexts.EclipseContextFactory) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ContentFilter(org.osate.ge.ContentFilter) 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) AbstractHandler(org.eclipse.core.commands.AbstractHandler) Bundle(org.osgi.framework.Bundle) IEditorPart(org.eclipse.ui.IEditorPart) FrameworkUtil(org.osgi.framework.FrameworkUtil) ContentFilterProvider(org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) IEditorPart(org.eclipse.ui.IEditorPart) ContentFilterProvider(org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider) ContentFilter(org.osate.ge.ContentFilter)

Example 2 with ContentFilterProvider

use of org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider in project osate2 by osate.

the class ShowContentFilterHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // Get the content filter
    final String contentFilterId = (String) event.getParameters().get(PARAM_CONTENTS_FILTER_ID);
    if (contentFilterId == null) {
        throw new RuntimeException("Unable to get content filter");
    }
    final ContentFilterProvider contentFilterProvider = getContentFilterProvider();
    final ContentFilter contentFilter = contentFilterProvider.getContentFilterById(contentFilterId).orElseThrow(() -> new RuntimeException("Unable to get content filter"));
    // Show elements matching the filter
    ShowContentsUtil.addContentsToSelectedElements(event, (diagramElement) -> ImmutableSet.of(contentFilter));
    return null;
}
Also used : ContentFilterProvider(org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider) ContentFilter(org.osate.ge.ContentFilter)

Example 3 with ContentFilterProvider

use of org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider 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

ContentFilter (org.osate.ge.ContentFilter)3 ContentFilterProvider (org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider)3 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 EclipseContextFactory (org.eclipse.e4.core.contexts.EclipseContextFactory)2 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)2 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)2 ExtensionRegistryService (org.osate.ge.internal.services.ExtensionRegistryService)2 UiUtil (org.osate.ge.internal.ui.util.UiUtil)2 Bundle (org.osgi.framework.Bundle)2 FrameworkUtil (org.osgi.framework.FrameworkUtil)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IEditorPart (org.eclipse.ui.IEditorPart)1 HandlerUtil (org.eclipse.ui.handlers.HandlerUtil)1 DiagramType (org.osate.ge.DiagramType)1