Search in sources :

Example 11 with DiagramNode

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;
}
Also used : BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) DefaultDiagramConfigurationDialogModel(org.osate.ge.internal.ui.dialogs.DefaultDiagramConfigurationDialogModel) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) IEditorPart(org.eclipse.ui.IEditorPart) LinkedList(java.util.LinkedList) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) DiagramConfigurationDialog(org.osate.ge.internal.ui.dialogs.DiagramConfigurationDialog) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) ProjectProvider(org.osate.ge.internal.services.ProjectProvider)

Example 12 with DiagramNode

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);
}
Also used : Element(org.osate.aadl2.Element) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) RenameUtil(org.osate.ge.internal.ui.RenameUtil) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) ClipboardService(org.osate.ge.internal.services.ClipboardService) ClassifierCreationHelper(org.osate.ge.aadl2.internal.util.classifiers.ClassifierCreationHelper) Classifier(org.osate.aadl2.Classifier) ComponentType(org.osate.aadl2.ComponentType) DiagramNodePredicates(org.osate.ge.internal.diagram.runtime.DiagramNodePredicates) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) Bundle(org.osgi.framework.Bundle) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Collection(java.util.Collection) PackageSection(org.osate.aadl2.PackageSection) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) Point(org.osate.ge.graphics.Point) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) Objects(java.util.Objects) List(java.util.List) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) EclipseContextFactory(org.eclipse.e4.core.contexts.EclipseContextFactory) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) Feature(org.osate.aadl2.Feature) ComponentImplementation(org.osate.aadl2.ComponentImplementation) DiagramModification(org.osate.ge.internal.diagram.runtime.DiagramModification) ArrayList(java.util.ArrayList) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) EClass(org.eclipse.emf.ecore.EClass) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Predicates(com.google.common.base.Predicates) GetNameContext(org.osate.ge.businessobjecthandling.GetNameContext) SimpleModifier(org.osate.ge.internal.services.AadlModificationService.SimpleModifier) Subcomponent(org.osate.aadl2.Subcomponent) XtextResource(org.eclipse.xtext.resource.XtextResource) AadlNameUtil(org.osate.ge.aadl2.internal.util.AadlNameUtil) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Action(org.eclipse.jface.action.Action) CanRenameContext(org.osate.ge.businessobjecthandling.CanRenameContext) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) ComponentTypeRename(org.osate.aadl2.ComponentTypeRename) ActionFactory(org.eclipse.ui.actions.ActionFactory) NamedElement(org.osate.aadl2.NamedElement) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) EObject(org.eclipse.emf.ecore.EObject) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 13 with DiagramNode

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;
}
Also used : BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Node(javafx.scene.Node) Bounds(javafx.geometry.Bounds) DOMImplementation(org.w3c.dom.DOMImplementation) GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Transform(javafx.scene.transform.Transform) AffineTransform(java.awt.geom.AffineTransform) Document(org.w3c.dom.Document)

Example 14 with DiagramNode

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;
}
Also used : BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Node(javafx.scene.Node) Bounds(javafx.geometry.Bounds) Color(java.awt.Color) Transform(javafx.scene.transform.Transform) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D)

Example 15 with DiagramNode

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()));
}
Also used : DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Point2D(javafx.geometry.Point2D) GeometryNode(org.eclipse.gef.fx.nodes.GeometryNode) Node(javafx.scene.Node) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) DockingPosition(org.osate.ge.DockingPosition) GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext)

Aggregations

DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)29 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)18 List (java.util.List)13 Point (org.osate.ge.graphics.Point)13 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)13 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)13 Objects (java.util.Objects)12 IEditorPart (org.eclipse.ui.IEditorPart)11 Collection (java.util.Collection)10 Collections (java.util.Collections)10 BusinessObjectContext (org.osate.ge.BusinessObjectContext)9 LinkedList (java.util.LinkedList)8 Collectors (java.util.stream.Collectors)8 DiagramModification (org.osate.ge.internal.diagram.runtime.DiagramModification)8 Stream (java.util.stream.Stream)7 Node (javafx.scene.Node)7 IStatus (org.eclipse.core.runtime.IStatus)7 Status (org.eclipse.core.runtime.Status)7 DiagramNodePredicates (org.osate.ge.internal.diagram.runtime.DiagramNodePredicates)7 DiagramElementUtil (org.osate.ge.internal.util.DiagramElementUtil)7