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()]);
}
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);
}
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;
}
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());
}
}
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;
}
Aggregations