use of org.osate.ge.internal.model.EmbeddedBusinessObject in project osate2 by osate.
the class DeleteHandler method createBusinessObjectRemovalOrRemoveDiagramElement.
/**
* Creates a BusinessObjectRemoval object which can be used to remove the business object for the diagram element.
* If the diagram element's business object is an embedded business object, remove the element.
* @param de
* @return
*/
private static BusinessObjectRemoval createBusinessObjectRemovalOrRemoveDiagramElement(final DiagramElement de) {
// Remove the EObject from the model
final Object bo = de.getBusinessObject();
final Object boHandler = de.getBusinessObjectHandler();
if (bo instanceof EObject) {
EObject boEObj = (EObject) bo;
if (boHandler instanceof CustomDeleter) {
final CustomDeleter deleter = (CustomDeleter) boHandler;
final EObject ownerBo = boEObj.eContainer();
return new BusinessObjectRemoval(ownerBo, (boToModify) -> {
deleter.delete(new CustomDeleteContext(boToModify, bo));
});
}
// When deleting AnnexSubclauses, the deletion must executed on the container DefaultAnnexSubclause
if (boEObj instanceof AnnexSubclause && boEObj.eContainer() instanceof DefaultAnnexSubclause) {
boEObj = boEObj.eContainer();
}
return new BusinessObjectRemoval(boEObj, (boToModify) -> EcoreUtil.remove(boToModify));
} else if (bo instanceof EmfContainerProvider) {
if (!(boHandler instanceof CustomDeleter)) {
throw new RuntimeException("Business object handler '" + boHandler + "' for " + EmfContainerProvider.class.getName() + " based business object must implement " + CustomDeleter.class.getCanonicalName() + ".");
}
final CustomDeleter deleter = (CustomDeleter) boHandler;
final EObject ownerBo = ((EmfContainerProvider) bo).getEmfContainer();
return new BusinessObjectRemoval(ownerBo, (boToModify) -> {
deleter.delete(new CustomDeleteContext(boToModify, bo));
});
} else if (bo instanceof EmbeddedBusinessObject) {
// For embedded business objects, there isn't a model from which to remove the business object.
// Instead, we remove the diagram element and return null.
final AgeDiagram diagram = DiagramElementUtil.getDiagram(de);
diagram.modify("Delete Element", m -> m.removeElement(de));
return null;
} else {
// canDelete() should have returned false in this case
throw new RuntimeException("Unhandled case: " + bo);
}
}
use of org.osate.ge.internal.model.EmbeddedBusinessObject in project osate2 by osate.
the class DiagramSerialization method convertElementToMetamodel.
private static void convertElementToMetamodel(final IProject project, final org.osate.ge.diagram.DiagramNode mmContainer, final DiagramElement e) {
// Write BO Reference
final org.osate.ge.diagram.DiagramElement newElement = new org.osate.ge.diagram.DiagramElement();
mmContainer.getElement().add(newElement);
newElement.setUuid(e.getId().toString());
newElement.setBo(e.getRelativeReference().toMetamodel());
// Store embedded business object data.
if (e.getBusinessObject() instanceof EmbeddedBusinessObject) {
final EmbeddedBusinessObject bo = (EmbeddedBusinessObject) e.getBusinessObject();
newElement.setBoData(bo.getData());
}
newElement.setManual(true);
if (e.hasPosition()) {
newElement.setPosition(e.getPosition().toMetamodel());
}
if (e.hasSize() && DiagramElementPredicates.isResizeable(e)) {
newElement.setSize(e.getSize().toMetamodel());
}
if (e.getDockArea() != null && e.getDockArea() != DockArea.GROUP) {
// Don't serialize null or group dock areas
newElement.setDockArea(e.getDockArea().id);
}
final Style currentStyle = e.getStyle();
final org.osate.ge.graphics.Color backgroundColor = currentStyle.getBackgroundColor();
if (backgroundColor != null) {
newElement.setBackground(colorToHex(backgroundColor));
}
final IPath image = currentStyle.getImagePath();
if (image != null) {
// Get image path relative to the diagram's project
final String portablePath = image.makeRelativeTo(project.getFullPath()).toPortableString();
newElement.setImage(portablePath);
newElement.setShowAsImage(currentStyle.getShowAsImage());
}
final org.osate.ge.graphics.Color fontColor = currentStyle.getFontColor();
if (fontColor != null) {
newElement.setFontColor(colorToHex(fontColor));
}
final org.osate.ge.graphics.Color outlineColor = currentStyle.getOutlineColor();
if (outlineColor != null) {
newElement.setOutline(colorToHex(outlineColor));
}
final Double fontSize = currentStyle.getFontSize();
if (fontSize != null) {
newElement.setFontSize(fontSize);
}
final Double lineWidth = currentStyle.getLineWidth();
if (lineWidth != null) {
newElement.setLineWidth(lineWidth);
}
if (currentStyle.getPrimaryLabelVisible() != null) {
newElement.setPrimaryLabelVisible(currentStyle.getPrimaryLabelVisible());
}
// Connection Specific
if (e.getBendpoints().size() > 0) {
final org.osate.ge.diagram.BendpointList mmBendpoints = new org.osate.ge.diagram.BendpointList();
newElement.setBendpoints(mmBendpoints);
for (final Point bendpoint : e.getBendpoints()) {
mmBendpoints.getPoint().add(bendpoint.toMetamodel());
}
}
if (e.getConnectionPrimaryLabelPosition() != null) {
newElement.setPrimaryLabelPosition(e.getConnectionPrimaryLabelPosition().toMetamodel());
}
convertElementsToMetamodel(project, newElement, e.getChildren());
}
use of org.osate.ge.internal.model.EmbeddedBusinessObject in project osate2 by osate.
the class DiagramToBusinessObjectTreeConverter method createBusinessObjectNodesForElements.
private static void createBusinessObjectNodesForElements(final BusinessObjectNode parent, final DiagramElement e, final Map<DiagramNode, Map<RelativeBusinessObjectReference, FutureElementInfo>> futureElementInfoMap, final Map<DiagramNode, Map<RelativeBusinessObjectReference, DiagramElement>> containerToRelativeReferenceToGhostMap) {
// For embedded business objects, store the object in the business object node.
// Typically, the business object node isn't stored in the business object node to prevent retaining references
// to old business objects.
final Object bo = e.getBusinessObject() instanceof EmbeddedBusinessObject ? e.getBusinessObject() : null;
// Don't keep the business object when building the business object tree. This will ensure that tree expander or other user of the tree updates
// the business object based on the model.
final BusinessObjectNode childNode = new BusinessObjectNode(parent, e.getId(), e.getRelativeReference(), bo, Completeness.UNKNOWN, true);
createBusinessObjectNodesForElements(childNode, e.getChildren(), futureElementInfoMap, containerToRelativeReferenceToGhostMap);
createBusinessObjectNodesForGhostedElements(childNode, e, futureElementInfoMap, containerToRelativeReferenceToGhostMap);
createBusinessObjectNodesForFutureElements(childNode, e, futureElementInfoMap);
}
use of org.osate.ge.internal.model.EmbeddedBusinessObject in project osate2 by osate.
the class DefaultGraphicalEditorService method getObjectDetails.
@Override
public Optional<ObjectDetails> getObjectDetails(Object selectedObject) {
if (!(selectedObject instanceof DiagramElement)) {
return Optional.empty();
}
final DiagramElement selectedDiagramElement = (DiagramElement) selectedObject;
final Object bo = selectedDiagramElement.getBusinessObject();
if (bo == null) {
return Optional.empty();
}
// Diagrams do not have a reference to the context business object. It is non-trivial to resolve the context business object using the diagram
// configuration. Instead, return the business object associated with the only root child which is is associated with a non-embedded business object.
// If there are multiple such root children then the diagram is a contextless diagram and null will be returned.
final AgeDiagram diagram = DiagramElementUtil.getDiagram(selectedDiagramElement);
Object diagramBo = null;
if (diagram != null) {
final List<BusinessObjectContext> rootChildren = diagram.getChildren().stream().filter(boc -> boc.getBusinessObject() != null && !(boc.getBusinessObject() instanceof EmbeddedBusinessObject)).collect(Collectors.toUnmodifiableList());
if (rootChildren.size() == 1) {
diagramBo = rootChildren.get(0).getBusinessObject();
}
}
return Optional.of(new ObjectDetails(diagramBo, bo));
}
use of org.osate.ge.internal.model.EmbeddedBusinessObject in project osate2 by osate.
the class OperationResultsProcessor method processResults.
/**
* @param editor the editor which is displaying the diagram for which the operation was executed
* @param targetNode is the node to which the targetPosition is relative.
* @param targetPosition the position at which the operation was executed. Relative to the target node. This is used to position
* a newly created diagram element.
* @param results the results to process
*/
public static void processResults(final InternalDiagramEditor editor, final DiagramNode targetNode, final Point targetPosition, final OperationResults results) {
Objects.requireNonNull(editor, "diagram must not be null");
boolean update = false;
// Notify the diagram updater to add the element on the next update
for (final Entry<BusinessObjectContext, OperationResults.BusinessObjectToShowDetails> containerToBoEntry : results.getContainerToBoToShowDetailsMap().entries()) {
if (containerToBoEntry.getKey() instanceof DiagramNode) {
final DiagramNode containerNode = (DiagramNode) containerToBoEntry.getKey();
final OperationResults.BusinessObjectToShowDetails newValue = containerToBoEntry.getValue();
// Don't set the position if multiple items are being added.
// Don't set the position if the incremental layout mode is set to diagram.
// This will ensure the shape is laid out even if it is a docked shape.
final Point position;
if (results.getContainerToBoToShowDetailsMap().size() == 1 && LayoutPreferences.getCurrentIncrementalLayoutMode() != IncrementalLayoutMode.LAYOUT_DIAGRAM && containerNode == targetNode) {
position = targetPosition;
} else {
position = null;
}
// If the BO being added is an embedded business object, it must be provided to the diagram updater.
final EmbeddedBusinessObject embeddedBo = (newValue.bo instanceof EmbeddedBusinessObject) ? (EmbeddedBusinessObject) newValue.bo : null;
editor.getDiagramUpdater().addToNextUpdate(containerNode, newValue.ref, new FutureElementInfo(position, embeddedBo));
if (embeddedBo != null) {
update = true;
}
}
}
// If an embedded business object was added, then update the diagram to ensure it was updated.
if (update) {
editor.updateDiagram();
}
}
Aggregations