use of org.osate.ge.internal.diagram.runtime.DiagramElement in project osate2 by osate.
the class SelectAllConnectionsHandler 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);
}
final InternalDiagramEditor editor = (InternalDiagramEditor) activeEditor;
final List<DiagramElement> connectionDiagramElements = editor.getDiagram().getAllDiagramNodes().filter(dn -> dn instanceof DiagramElement).map(DiagramElement.class::cast).filter(DiagramElementPredicates::isConnection).collect(Collectors.toList());
editor.selectDiagramNodes(connectionDiagramElements);
return null;
}
use of org.osate.ge.internal.diagram.runtime.DiagramElement 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.DiagramElement in project osate2 by osate.
the class ImageErrorTooltipContributor method addTooltipContents.
@Override
public void addTooltipContents(final TooltipContributorContext ctx) {
final BusinessObjectContext boc = ctx.getBusinessObjectContext();
if (boc instanceof DiagramElement) {
final DiagramElement de = (DiagramElement) boc;
final Style style = de.getStyle();
if (style != null && Boolean.TRUE.equals(style.getShowAsImage())) {
final IPath imagePath = style.getImagePath();
if (imagePath != null) {
final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
final IResource imageResource = workspaceRoot.findMember(imagePath);
if (imageResource == null) {
final Label lbl = new Label(ctx.getTooltip(), SWT.NONE);
lbl.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
lbl.setText("Unable to load image: " + imagePath.toPortableString());
}
}
}
}
}
use of org.osate.ge.internal.diagram.runtime.DiagramElement 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.DiagramElement 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