use of org.osate.ge.businessobjecthandling.BusinessObjectHandler in project osate2 by osate.
the class DefaultReferenceService method getRelativeReference.
@Override
public RelativeBusinessObjectReference getRelativeReference(final Object bo) {
Objects.requireNonNull(bo, "bo must not be null");
final BusinessObjectHandler boh = bohProvider.getApplicableBusinessObjectHandler(bo);
if (boh == null) {
return null;
}
try {
return Objects.requireNonNull(boh.getRelativeReference(new ReferenceContext(bo, this)), () -> "Business object handlers must not return a null relative reference. Null reference returned by '" + boh.getClass().getCanonicalName() + "'");
} catch (RuntimeException ex) {
StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error retrieving relative reference for " + bo.getClass().getCanonicalName() + ".", ex), StatusManager.LOG | StatusManager.SHOW);
return null;
}
}
use of org.osate.ge.businessobjecthandling.BusinessObjectHandler in project osate2 by osate.
the class EditorRenameUtil method canRename.
public static boolean canRename(final DiagramElement de) {
final Object bo = de.getBusinessObject();
// Only EObjects are supported at this time
if (!(bo instanceof EObject)) {
return false;
}
final BusinessObjectHandler handler = de.getBusinessObjectHandler();
if (!handler.canRename(new CanRenameContext(bo))) {
return false;
}
if (!RenameUtil.supportsNonLtkRename(handler) && RenameUtil.getRenameRefactoring(bo) == null) {
return false;
}
return true;
}
use of org.osate.ge.businessobjecthandling.BusinessObjectHandler in project osate2 by osate.
the class DeleteHandler method canDelete.
private boolean canDelete(final DiagramElement de) {
final Object bo = de.getBusinessObject();
final BusinessObjectHandler boHandler = de.getBusinessObjectHandler();
if (boHandler == null) {
return false;
}
// Don't allow proxies.
if (bo instanceof EObject) {
final EObject eobj = ((EObject) bo);
if (eobj.eIsProxy()) {
return false;
}
// Prevent deletion of resources which are part of plugins
final Resource res = eobj.eResource();
if (res != null && res.getURI().isPlatformPlugin()) {
return false;
}
}
return boHandler.canDelete(new CanDeleteContext(bo));
}
use of org.osate.ge.businessobjecthandling.BusinessObjectHandler in project osate2 by osate.
the class DiagramUpdater method updateStructure.
/**
* Updates the structure of the diagram based on the business object tree.
* Creates/Unghosts elements to match the business object tree. Ghosts diagram elements which are not in the diagram element tree.
* @param m
* @param container
* @param bos
*/
private void updateStructure(final DiagramModification m, final DiagramNode container, final Collection<BusinessObjectNode> bos) {
for (final BusinessObjectNode n : bos) {
// Get existing element if it exists.
DiagramElement element = container.getChildByRelativeReference(n.getRelativeReference());
// Create the element if it does not exist
if (element == null) {
final DiagramElement removedGhost = removeGhost(container, n.getRelativeReference());
if (removedGhost == null) {
final BusinessObjectHandler boh = infoProvider.getApplicableBusinessObjectHandler(n.getBusinessObject());
if (boh == null) {
// Ignore the object
continue;
}
element = new DiagramElement(container, n.getBusinessObject(), boh, n.getRelativeReference(), n.getId());
} else {
element = removedGhost;
m.updateBusinessObject(element, n.getBusinessObject(), n.getRelativeReference());
}
m.addElement(element);
} else {
// Update the business object and relative reference. Although the reference matches. The business object may be new and the
// relative reference may have case differences.
m.updateBusinessObject(element, n.getBusinessObject(), n.getRelativeReference());
}
// Set the business object handler if it is null
if (element.getBusinessObjectHandler() == null) {
final BusinessObjectHandler boh = infoProvider.getApplicableBusinessObjectHandler(n.getBusinessObject());
if (boh == null) {
ghostAndRemove(m, element);
continue;
} else {
m.setBusinessObjectHandler(element, boh);
}
}
// Update the element's children
updateStructure(m, element, n.getChildren());
}
// If the collections are the same size, there is nothing to remove
if (bos.size() != container.getChildren().size()) {
// Build Set of Relative References of All the Objects in the Business Object Tree
final Set<RelativeBusinessObjectReference> boTreeRelativeReferenceSet = bos.stream().map((n) -> n.getRelativeReference()).collect(Collectors.toCollection(HashSet::new));
Iterator<DiagramElement> childrenIt = container.getChildren().iterator();
while (childrenIt.hasNext()) {
final DiagramElement child = childrenIt.next();
if (!boTreeRelativeReferenceSet.contains(child.getRelativeReference())) {
ghostAndRemove(m, child);
}
}
}
}
use of org.osate.ge.businessobjecthandling.BusinessObjectHandler in project osate2 by osate.
the class DefaultReferenceService method getCanonicalReference.
@Override
public CanonicalBusinessObjectReference getCanonicalReference(final Object bo) {
Objects.requireNonNull(bo, "bo must not be null");
final BusinessObjectHandler boh = bohProvider.getApplicableBusinessObjectHandler(bo);
if (boh == null) {
return null;
}
try {
return boh.getCanonicalReference(new ReferenceContext(bo, this));
} catch (RuntimeException ex) {
StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error retrieving canonical reference for " + bo.getClass().getCanonicalName() + ".", ex), StatusManager.LOG | StatusManager.SHOW);
return null;
}
}
Aggregations