use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class ElkGraphBuilder method buildLayoutGraph.
private LayoutMapping buildLayoutGraph(final DiagramNode rootDiagramNode) {
// Create the graph
final LayoutMapping mapping = new LayoutMapping(null);
final ElkNode rootNode = ElkGraphUtil.createGraph();
rootNode.setProperty(CoreOptions.DIRECTION, Direction.RIGHT);
mapping.setLayoutGraph(rootNode);
// As of 2020-04-06, INCLUDE_CHILDREN causes layout issues. In particular, labels can overlap with children
// https://github.com/eclipse/elk/issues/316
// https://github.com/eclipse/elk/issues/412
rootNode.setProperty(CoreOptions.HIERARCHY_HANDLING, HierarchyHandling.SEPARATE_CHILDREN);
if (rootDiagramNode instanceof AgeDiagram) {
final ElkNode diagramElkNode = ElkGraphUtil.createNode(rootNode);
mapping.getGraphMap().put(diagramElkNode, rootDiagramNode);
createElkGraphElementsForNonLabelChildShapes(rootDiagramNode, diagramElkNode, mapping);
} else if (rootDiagramNode instanceof DiagramElement) {
createElkGraphElementsForElements(Collections.singleton((DiagramElement) rootDiagramNode), rootNode, mapping);
}
createElkGraphElementsForConnections(rootDiagramNode, mapping);
return mapping;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class SetBindingTool method activated.
@Override
public void activated(final ActivatedEvent ctx) {
final BusinessObjectContext[] selectedBocs = ctx.getSelectedBocs().toArray(new BusinessObjectContext[ctx.getSelectedBocs().size()]);
final AgeDiagram diagram = ctx.getDiagram();
final AadlModificationService aadlModService = ctx.getAadlModificatonService();
final UiService uiService = ctx.getUiService();
try {
final BusinessObjectContext componentImplementationBoc = ToolUtil.findComponentImplementationBoc(selectedBocs[0]);
// Open Dialog
if (currentWindow == null && componentImplementationBoc != null) {
currentWindow = new SetBindingWindow(Display.getCurrent().getActiveShell(), componentImplementationBoc, selectedBocs);
if (currentWindow.open() == Window.OK) {
// Ensure the diagram is configured to show the specified binding property
if (!diagram.getConfiguration().getEnabledAadlPropertyNames().contains(currentWindow.getSelectedProperty().getQualifiedName().toLowerCase())) {
diagram.modify("Configure Diagram", m -> {
m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagram.getConfiguration()).addAadlProperty(currentWindow.getSelectedProperty().getQualifiedName()).build());
});
}
// Create the property association
createPropertyAssociations(aadlModService);
}
currentWindow = null;
}
} finally {
uiService.deactivateActiveTool();
}
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram 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.diagram.runtime.AgeDiagram in project osate2 by osate.
the class MatchSizeHandler 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");
}
diagram.modify("Match Size", m -> {
final Dimension newSize = AgeHandlerUtil.getPrimaryDiagramElement(selectedDiagramElements).getSize();
for (final DiagramElement tmpElement : selectedDiagramElements) {
m.setSize(tmpElement, newSize);
}
});
return null;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class RemoveBendpointsHandler 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");
}
diagram.modify("Remove Bendpoints", m -> {
for (final DiagramElement de : selectedDiagramElements) {
if (DiagramElementPredicates.isConnection(de)) {
m.setBendpoints(de, Collections.emptyList());
}
}
});
return null;
}
Aggregations