use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.
the class ConfigureDiagramHandler 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 diagram and selected elements
final InternalDiagramEditor diagramEditor = (InternalDiagramEditor) activeEditor;
final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
final AgeDiagram diagram = diagramEditor.getDiagram();
if (diagram == null) {
throw new RuntimeException("Unable to get diagram");
}
// Get services
final BusinessObjectTreeUpdater boTreeUpdater = diagramEditor.getBoTreeUpdater();
final DiagramUpdater diagramUpdater = diagramEditor.getDiagramUpdater();
final ProjectProvider projectProvider = Objects.requireNonNull(Adapters.adapt(diagramEditor, ProjectProvider.class), "Unable to retrieve project provider");
final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(diagramEditor, LayoutInfoProvider.class), "Unable to retrieve layout information provider");
final ExtensionRegistryService extService = Objects.requireNonNull(Adapters.adapt(diagramEditor, ExtensionRegistryService.class), "Unable to retrieve extension service");
final ProjectReferenceService referenceService = Objects.requireNonNull(Adapters.adapt(diagramEditor, ProjectReferenceService.class), "Unable to retrieve reference service");
BusinessObjectNode boTree = DiagramToBusinessObjectTreeConverter.createBusinessObjectNode(diagram);
// Update the tree so that it's business objects are refreshed
boTree = boTreeUpdater.updateTree(diagram.getConfiguration(), boTree);
final DefaultDiagramConfigurationDialogModel model = new DefaultDiagramConfigurationDialogModel(referenceService, extService, projectProvider, diagram.getConfiguration().getDiagramType());
// Create a BO path for the initial selection. The initial selection will be the first diagram element which will be included in the BO tree.
Object[] initialSelectionBoPath = null;
for (final DiagramElement selectedDiagramElement : selectedDiagramElements) {
if (model.shouldShowBusinessObject(selectedDiagramElement.getBusinessObject())) {
// Only build a selection path if the BO will be shown
DiagramNode tmp = selectedDiagramElement;
final LinkedList<Object> boList = new LinkedList<>();
while (tmp instanceof DiagramElement) {
boList.addFirst(tmp.getBusinessObject());
tmp = tmp.getParent();
}
initialSelectionBoPath = boList.toArray();
break;
}
}
// Show the dialog
final DiagramConfigurationDialog.Result result = DiagramConfigurationDialog.show(null, model, diagram.getConfiguration(), boTree, initialSelectionBoPath);
if (result != null) {
// Update the diagram
diagramEditor.getActionExecutor().execute("Set Diagram Configuration", ExecutionMode.NORMAL, () -> {
diagram.modify("Set Diagram Configuration", m -> {
m.setDiagramConfiguration(result.getDiagramConfiguration());
diagramUpdater.updateDiagram(diagram, result.getBusinessObjectTree());
});
// Clear ghosts triggered by this update to prevent them from being unghosted during the next update.
diagramUpdater.clearGhosts();
diagram.modify("Layout", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
return null;
});
}
return null;
}
use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.
the class PasteAction method run.
@Override
public void run() {
// Get services
final Bundle bundle = FrameworkUtil.getBundle(getClass());
final IEclipseContext context = EclipseContextFactory.getServiceContext(bundle.getBundleContext());
final AadlModificationService aadlModificationService = Objects.requireNonNull(context.getActive(AadlModificationService.class), "Unable to retrieve AADL modification service");
final ReferenceBuilderService refBuilder = Objects.requireNonNull(context.getActive(ReferenceBuilderService.class), "Unable to retrieve reference builder service");
// Perform modification
final DiagramNode dstDiagramNode = getDestinationDiagramNode();
final EObject dstBo = getDestinationEObject(dstDiagramNode);
final AgeDiagram diagram = DiagramElementUtil.getDiagram(dstDiagramNode);
final List<DiagramElement> newDiagramElements = new ArrayList<>();
diagram.modify("Paste", m -> {
// The modifier will do the actual copying to the diagram elements. It will also copy the business objects
// if the copied element includes the business object.
final SimpleModifier<EObject> modifier = dstBoToModify -> {
newDiagramElements.addAll(copyClipboardContents(dstBoToModify, dstDiagramNode, m, refBuilder));
};
// If any non-embedded business objects have been copied, then modify the AADL model. Otherwise, just modify the diagram.
final boolean anyHaveNonEmbeddedBo = getCopiedDiagramElements().stream().anyMatch(de -> de.getCopiedBusinessObject() instanceof EObject);
if (anyHaveNonEmbeddedBo) {
aadlModificationService.modify(dstBo, modifier);
} else {
modifier.modify(null);
}
// Update the diagram. This will set business objects and update the diagram to be consistent.
editor.getDiagramUpdater().updateDiagram(diagram);
});
// Update selection to match created diagram elements
editor.selectDiagramNodes(newDiagramElements);
}
use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.
the class GefDiagramExportService method exportToSvg.
private static SVGGraphics2D exportToSvg(final GefAgeDiagram diagram, final DiagramNode exportRootDiagramNode, final Transform sceneToDiagramTransform, final double scaling) {
final List<Node> exportNodes = getExportNodes(diagram, exportRootDiagramNode);
final Bounds bounds = getBounds(exportNodes, sceneToDiagramTransform);
final Transform sceneToExportTransform = Transform.translate(-bounds.getMinX(), -bounds.getMinY()).createConcatenation(sceneToDiagramTransform);
// Generate the SVG
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
String svgNS = "http://www.w3.org/2000/svg";
Document doc = domImpl.createDocument(svgNS, "svg", null);
final SVGGraphics2D svgGenerator = new SVGGraphics2D(doc);
svgGenerator.setSVGCanvasSize(new java.awt.Dimension((int) Math.ceil(bounds.getWidth() * scaling), (int) Math.ceil(bounds.getHeight() * scaling)));
draw(exportNodes, sceneToExportTransform, scaling, svgGenerator);
return svgGenerator;
}
use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.
the class GefDiagramExportService method exportToRasterImage.
private static BufferedImage exportToRasterImage(final GefAgeDiagram diagram, final DiagramNode exportRootDiagramNode, final Transform sceneToDiagramTransform, final double scaling) {
final List<Node> exportNodes = getExportNodes(diagram, exportRootDiagramNode);
final Bounds bounds = getBounds(exportNodes, sceneToDiagramTransform);
final Transform sceneToExportTransform = Transform.translate(-bounds.getMinX(), -bounds.getMinY()).createConcatenation(sceneToDiagramTransform);
final BufferedImage image = new BufferedImage((int) Math.ceil(bounds.getWidth() * scaling), (int) Math.ceil(bounds.getHeight() * scaling), BufferedImage.TYPE_INT_RGB);
final Graphics2D graphics = image.createGraphics();
graphics.setColor(new Color(255, 255, 255, 255));
graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
draw(exportNodes, sceneToExportTransform, scaling, graphics);
return image;
}
use of org.osate.ge.internal.diagram.runtime.DiagramNode in project osate2 by osate.
the class CreateConnectionInteraction method createGetTargetedOperationContext.
private Optional<GetTargetedOperationContext> createGetTargetedOperationContext(final MouseEvent event) {
// Find the closest diagram node
final DiagramNode targetDiagramNode = InputEventHandlerUtil.getTargetDiagramNode(editor.getGefDiagram(), event.getTarget());
if (targetDiagramNode == null) {
return Optional.empty();
}
final Node targetSceneNode = editor.getGefDiagram().getSceneNode(targetDiagramNode);
final Point2D targetPosition = getTargetPosition(targetSceneNode, event.getSceneX(), event.getSceneY());
final DockingPosition dockingPostion = AgeDiagramUtil.determineDockingPosition(targetDiagramNode, targetPosition.getX(), targetPosition.getY(), 0, 0);
return Optional.of(new GetTargetedOperationContext(targetDiagramNode, dockingPostion, editor.getQueryService()));
}
Aggregations