Search in sources :

Example 1 with ContentFilter

use of org.osate.ge.ContentFilter 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 2 with ContentFilter

use of org.osate.ge.ContentFilter in project osate2 by osate.

the class DefaultBusinessObjectTreeUpdater method createNode.

private void createNode(final DiagramType diagramType, final BusinessObjectProviderHelper bopHelper, final Map<RelativeBusinessObjectReference, BusinessObjectNode> oldNodeMap, final BusinessObjectNode parentNode, final Object bo, final RelativeBusinessObjectReference relReference) {
    // Get the node which is in the input tree from the old node map
    final BusinessObjectNode oldNode = oldNodeMap.get(relReference);
    // Create the node
    final ImmutableSet<ContentFilter> contentFilters = oldNode == null || !oldNode.getDefaultChildrenHaveBeenPopulated() ? getDefaultContentFilters(diagramType, bo) : ImmutableSet.of();
    final UUID id = oldNode == null || oldNode.getId() == null ? UUID.randomUUID() : oldNode.getId();
    final BusinessObjectNode newNode = nodeFactory.create(parentNode, id, bo, Completeness.UNKNOWN);
    // Determine the business objects for which nodes in the tree should be created.
    final Map<RelativeBusinessObjectReference, BusinessObjectNode> childOldNodes = oldNode == null ? Collections.emptyMap() : oldNode.getChildrenMap();
    final Collection<Object> childBusinessObjectsFromProviders = bopHelper.getChildBusinessObjects(newNode);
    final Map<RelativeBusinessObjectReference, Object> childBoMap = getChildBusinessObjects(childBusinessObjectsFromProviders, childOldNodes.keySet(), contentFilters);
    // Update the business objects before considering embedded business objects
    newNode.setCompleteness(childBusinessObjectsFromProviders.size() == childBoMap.size() ? Completeness.COMPLETE : Completeness.INCOMPLETE);
    addEmbeddedBusinessObjectsToBoMap(childOldNodes.values(), childBoMap);
    createNodes(diagramType, bopHelper, childBoMap, childOldNodes, newNode);
}
Also used : RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) EObject(org.eclipse.emf.ecore.EObject) InstanceObject(org.osate.aadl2.instance.InstanceObject) UUID(java.util.UUID) ContentFilter(org.osate.ge.ContentFilter) FundamentalContentFilter(org.osate.ge.FundamentalContentFilter)

Example 3 with ContentFilter

use of org.osate.ge.ContentFilter 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 4 with ContentFilter

use of org.osate.ge.ContentFilter in project osate2 by osate.

the class DiagramConfigurationDialog method main.

public static void main(String[] args) {
    final Model model = new Model() {

        @Override
        public RelativeBusinessObjectReference getRelativeBusinessObjectReference(final Object bo) {
            return new RelativeBusinessObjectReference(bo.toString());
        }

        @Override
        public Collection<Object> getChildBusinessObjects(final BusinessObjectContext boc) {
            final Collection<Object> children = new ArrayList<>();
            for (int i = 1; i <= 100; i++) {
                children.add("C" + i);
            }
            return children;
        }

        @Override
        public String getName(final BusinessObjectContext boc) {
            return boc.getBusinessObject().toString();
        }

        @Override
        public ImmutableSet<ContentFilter> getDefaultContentFilters(final Object bo) {
            return ImmutableSet.of(TestContentsFilter.FILTER1);
        }

        @Override
        public Map<String, Collection<String>> getAadlProperties() {
            final Map<String, Collection<String>> result = new HashMap<>();
            result.put("test_ps1", Arrays.asList(new String[] { "a", "c", "b" }));
            result.put("test_ps2", Arrays.asList(new String[] { "a", "b", "c" }));
            result.put("test_ps3", Arrays.asList(new String[] { "d", "f", "e" }));
            return result;
        }

        @Override
        public Object getBusinessObject(final CanonicalBusinessObjectReference ref) {
            return new Object();
        }

        @Override
        public String getContextDescription(final Object contextBo) {
            return "a::b::c (TestType)";
        }

        @Override
        public boolean shouldShowBusinessObject(final Object bo) {
            return !bo.equals("C3");
        }

        @Override
        public Image getImage(final Object bo) {
            return null;
        }

        @Override
        public Object resolve(final Object bo) {
            return bo;
        }

        @Override
        public boolean isProxy(Object bo) {
            return false;
        }
    };
    final DiagramConfiguration diagramConfig = new DiagramConfigurationBuilder(new CustomDiagramType(), false).contextBoReference(new CanonicalBusinessObjectReference("test")).addAadlProperty("test::prop1").addAadlProperty("test_ps2::b").connectionPrimaryLabelsVisible(true).build();
    // Create a test business object tree
    final BusinessObjectNode rootNode = new BusinessObjectNode(null, UUID.randomUUID(), null, null, Completeness.UNKNOWN, true);
    new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("A"), "A", Completeness.UNKNOWN, true);
    new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("B"), "B", Completeness.UNKNOWN, true);
    new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("C"), "C", Completeness.UNKNOWN, true);
    new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("D"), "D", Completeness.UNKNOWN, true);
    // Show the dialog
    final Result result = DiagramConfigurationDialog.show(null, model, diagramConfig, rootNode, new Object[] { "A", "C1", "C2", "C4" });
    if (result == null) {
        System.out.println("Dialog was canceled.");
    } else {
        System.out.println(result.getDiagramConfiguration());
        System.out.println(result.getBusinessObjectTree());
    }
}
Also used : CustomDiagramType(org.osate.ge.aadl2.internal.diagramtypes.CustomDiagramType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) ContentFilter(org.osate.ge.ContentFilter) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) DiagramConfiguration(org.osate.ge.internal.diagram.runtime.DiagramConfiguration) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) Collection(java.util.Collection) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 5 with ContentFilter

use of org.osate.ge.ContentFilter 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)

Aggregations

ContentFilter (org.osate.ge.ContentFilter)9 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)5 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)4 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)4 ExtensionRegistryService (org.osate.ge.internal.services.ExtensionRegistryService)4 Bundle (org.osgi.framework.Bundle)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Objects (java.util.Objects)3 EclipseContextFactory (org.eclipse.e4.core.contexts.EclipseContextFactory)3 IEditorPart (org.eclipse.ui.IEditorPart)3 ContentFilterProvider (org.osate.ge.internal.diagram.runtime.filtering.ContentFilterProvider)3 UiUtil (org.osate.ge.internal.ui.util.UiUtil)3 FrameworkUtil (org.osgi.framework.FrameworkUtil)3 Collection (java.util.Collection)2 AbstractHandler (org.eclipse.core.commands.AbstractHandler)2 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 EObject (org.eclipse.emf.ecore.EObject)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2