use of org.osate.ge.internal.util.BusinessObjectProviderHelper in project osate2 by osate.
the class ShowElementsInModeHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final InternalDiagramEditor editor = getDiagramEditor(event);
referenceService = Objects.requireNonNull(Adapters.adapt(editor, ProjectReferenceService.class), "Unable to retrieve reference service");
final ExtensionRegistryService extService = Objects.requireNonNull(Adapters.adapt(editor, ExtensionRegistryService.class), "Unable to retrieve extension service");
final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
final BusinessObjectTreeUpdater boTreeUpdater = editor.getBoTreeUpdater();
final BusinessObjectNode boTree = getBoTree(editor, boTreeUpdater);
final List<BusinessObjectContext> selectedModes = AgeHandlerUtil.getSelectedBusinessObjectContexts().stream().filter(de -> isModal(de.getBusinessObject())).collect(Collectors.toList());
for (final BusinessObjectContext selectedMode : selectedModes) {
enableInModeNodes(bopHelper, boTree, selectedMode);
}
final AgeDiagram diagram = editor.getDiagram();
final DiagramUpdater diagramUpdater = editor.getDiagramUpdater();
final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(editor, LayoutInfoProvider.class), "Unable to retrieve layout info provider");
editor.getActionExecutor().execute("Show Elements In Mode", ExecutionMode.NORMAL, () -> {
// Update the diagram
diagramUpdater.updateDiagram(diagram, boTree);
// Update layout
diagram.modify("Layout Incrementally", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
return null;
});
return null;
}
use of org.osate.ge.internal.util.BusinessObjectProviderHelper 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.internal.util.BusinessObjectProviderHelper 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;
}
use of org.osate.ge.internal.util.BusinessObjectProviderHelper in project osate2 by osate.
the class ShowContentsUtil method addChildrenDuringNextUpdate.
/**
* Adds children of the specified diagram elements to the list of elements which will be added during the next diagram update.
* @return whether children were added to the diagram.
*/
private static boolean addChildrenDuringNextUpdate(final List<DiagramElement> diagramElements, final DiagramUpdater diagramUpdater, final ExtensionRegistryService extService, final ReferenceBuilderService referenceBuilder, final Function<DiagramElement, ImmutableSet<ContentFilter>> filters) {
boolean childrenAdded = false;
final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
for (final DiagramElement selectedElement : diagramElements) {
final ImmutableSet<ContentFilter> contentFilters = filters.apply(selectedElement);
if (!contentFilters.isEmpty()) {
for (final Object childBo : bopHelper.getChildBusinessObjects(selectedElement)) {
final RelativeBusinessObjectReference relativeReference = referenceBuilder.getRelativeReference(childBo);
if (relativeReference != null && selectedElement.getChildByRelativeReference(relativeReference) == null && ContentFilterUtil.passesAnyContentFilter(childBo, contentFilters)) {
diagramUpdater.addToNextUpdate(selectedElement, relativeReference, new FutureElementInfo());
childrenAdded = true;
}
}
}
}
return childrenAdded;
}
Aggregations