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