Search in sources :

Example 1 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram 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);
    }
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) URI(org.eclipse.emf.common.util.URI) ListMultimap(com.google.common.collect.ListMultimap) CanDeleteContext(org.osate.ge.businessobjecthandling.CanDeleteContext) Modification(org.osate.ge.internal.services.AadlModificationService.Modification) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) CustomDeleteContext(org.osate.ge.businessobjecthandling.CustomDeleteContext) Predicates(com.google.common.base.Predicates) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IEditorPart(org.eclipse.ui.IEditorPart) EmfContainerProvider(org.osate.ge.EmfContainerProvider) PlatformUI(org.eclipse.ui.PlatformUI) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Collection(java.util.Collection) CustomDeleter(org.osate.ge.businessobjecthandling.CustomDeleter) RawDeleter(org.osate.ge.businessobjecthandling.RawDeleter) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) EObject(org.eclipse.emf.ecore.EObject) ExecutionException(org.eclipse.core.commands.ExecutionException) Display(org.eclipse.swt.widgets.Display) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) Objects(java.util.Objects) Consumer(java.util.function.Consumer) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) RawDeleteContext(org.osate.ge.businessobjecthandling.RawDeleteContext) Entry(java.util.Map.Entry) Resource(org.eclipse.emf.ecore.resource.Resource) AnnexSubclause(org.osate.aadl2.AnnexSubclause) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) AbstractHandler(org.eclipse.core.commands.AbstractHandler) NamedElement(org.osate.aadl2.NamedElement) AnnexLibrary(org.osate.aadl2.AnnexLibrary) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) EObject(org.eclipse.emf.ecore.EObject) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) EObject(org.eclipse.emf.ecore.EObject) EmfContainerProvider(org.osate.ge.EmfContainerProvider) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) CustomDeleter(org.osate.ge.businessobjecthandling.CustomDeleter) CustomDeleteContext(org.osate.ge.businessobjecthandling.CustomDeleteContext) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 2 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class ShowElementsInModeHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final InternalDiagramEditor editor = getDiagramEditor(event);
    referenceService = Objects.requireNonNull(Adapters.adapt(editor, ProjectReferenceService.class), "Unable to retrieve reference service");
    final ExtensionRegistryService extService = Objects.requireNonNull(Adapters.adapt(editor, ExtensionRegistryService.class), "Unable to retrieve extension service");
    final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
    final BusinessObjectTreeUpdater boTreeUpdater = editor.getBoTreeUpdater();
    final BusinessObjectNode boTree = getBoTree(editor, boTreeUpdater);
    final List<BusinessObjectContext> selectedModes = AgeHandlerUtil.getSelectedBusinessObjectContexts().stream().filter(de -> isModal(de.getBusinessObject())).collect(Collectors.toList());
    for (final BusinessObjectContext selectedMode : selectedModes) {
        enableInModeNodes(bopHelper, boTree, selectedMode);
    }
    final AgeDiagram diagram = editor.getDiagram();
    final DiagramUpdater diagramUpdater = editor.getDiagramUpdater();
    final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(editor, LayoutInfoProvider.class), "Unable to retrieve layout info provider");
    editor.getActionExecutor().execute("Show Elements In Mode", ExecutionMode.NORMAL, () -> {
        // Update the diagram
        diagramUpdater.updateDiagram(diagram, boTree);
        // Update layout
        diagram.modify("Layout Incrementally", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
        return null;
    });
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ModalElement(org.osate.aadl2.ModalElement) DiagramToBusinessObjectTreeConverter(org.osate.ge.internal.diagram.runtime.updating.DiagramToBusinessObjectTreeConverter) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ModeTransition(org.osate.aadl2.ModeTransition) LinkedList(java.util.LinkedList) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) Completeness(org.osate.ge.internal.diagram.runtime.updating.Completeness) IEditorPart(org.eclipse.ui.IEditorPart) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) FeatureGroup(org.osate.aadl2.FeatureGroup) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) ModeFeature(org.osate.aadl2.ModeFeature) UUID(java.util.UUID) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) Objects(java.util.Objects) Adapters(org.eclipse.core.runtime.Adapters) Mode(org.osate.aadl2.Mode) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) ModeInstance(org.osate.aadl2.instance.ModeInstance) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) AadlModalElementUtil(org.osate.ge.aadl2.internal.util.AadlModalElementUtil) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) Queue(java.util.Queue) AbstractHandler(org.eclipse.core.commands.AbstractHandler) NamedElement(org.osate.aadl2.NamedElement) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Collections(java.util.Collections) InstanceObject(org.osate.aadl2.instance.InstanceObject) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) BusinessObjectContext(org.osate.ge.BusinessObjectContext) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider)

Example 3 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class ModeContributionItem method refresh.

void refresh() {
    final ComboViewer comboViewer = getComboViewer();
    final SortedSet<ModeFeatureReference> modeFeatureReferences = new TreeSet<>((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    if (comboViewer != null) {
        final ModeFeatureReference nullValue = AadlModalElementUtil.createModeFeatureReference(getNullValueString(), null, null);
        modeFeatureReferences.add(nullValue);
        Object selectedValue = nullValue;
        final String selectedModeName = editor == null ? null : editor.getPartProperty(SELECTED_MODE_PROPERTY_KEY);
        // Clear the combo box
        comboViewer.setInput(null);
        if (editor == null) {
            return;
        }
        final AgeDiagram diagram = editor.getDiagram();
        if (diagram != null) {
            final QueryService queryService = ContributionUtil.getQueryService(editor);
            if (queryService != null) {
                queryService.getResults(MODE_CONTAINER_QUERY, diagram, null).stream().flatMap(modeContainer -> {
                    // If container contains a modal element
                    if (AadlModalElementUtil.getModalElement(modeContainer.getBusinessObjectContext()) != null) {
                        // Get qualified modes to add to the drop-down
                        return Stream.concat(getModeBindingFeatureReferences((DiagramNode) modeContainer.getBusinessObjectContext()), getModeFeatureReferences((DiagramNode) modeContainer.getBusinessObjectContext()));
                    }
                    return Stream.empty();
                }).forEach(modeFeatureRef -> {
                    modeFeatureReferences.add(modeFeatureRef);
                });
                // Find ComboViewer selection
                final Optional<ModeFeatureReference> tmpSelectedValue = modeFeatureReferences.stream().filter(tmpKey -> tmpKey.getName().equalsIgnoreCase(selectedModeName)).findAny();
                if (tmpSelectedValue.isPresent()) {
                    selectedValue = tmpSelectedValue.get();
                }
                comboViewer.setLabelProvider(new LabelProvider() {

                    @Override
                    public String getText(final Object element) {
                        final ModeFeatureReference mf = (ModeFeatureReference) element;
                        return mf.getName();
                    }
                });
                comboViewer.setInput(modeFeatureReferences);
            }
        }
        final StructuredSelection newSelection = new StructuredSelection(selectedValue);
        if (!Objects.equal(newSelection, comboViewer.getSelection())) {
            comboViewer.setSelection(newSelection);
            onSelection(newSelection.getFirstElement());
        }
    }
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SortedSet(java.util.SortedSet) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TreeSet(java.util.TreeSet) ModeFeatureReference(org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) Composite(org.eclipse.swt.widgets.Composite) ComboContributionItem(org.osate.ge.internal.ui.editor.ComboContributionItem) Subcomponent(org.osate.aadl2.Subcomponent) Objects(com.google.common.base.Objects) IEditorPart(org.eclipse.ui.IEditorPart) ChangeListener(org.osate.ge.internal.services.ModelChangeNotifier.ChangeListener) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) Collectors(java.util.stream.Collectors) Mode(org.osate.aadl2.Mode) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) Stream(java.util.stream.Stream) UiUtil(org.osate.ge.internal.ui.util.UiUtil) QueryService(org.osate.ge.services.QueryService) AadlModalElementUtil(org.osate.ge.aadl2.internal.util.AadlModalElementUtil) Optional(java.util.Optional) NamedElement(org.osate.aadl2.NamedElement) ExecutableQuery(org.osate.ge.query.ExecutableQuery) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Control(org.eclipse.swt.widgets.Control) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) ModeFeatureReference(org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ComboViewer(org.eclipse.jface.viewers.ComboViewer) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) QueryService(org.osate.ge.services.QueryService) TreeSet(java.util.TreeSet) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 4 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class DiagramElementLayoutUtil method layoutIncrementally.

/**
 * Performs layout on elements in the specified diagram which have not been laid out.
 * @param diagram the diagram for which to perform the incremental layout
 * @param mod the modification to use to modify the diagram
 * @param layoutInfoProvider the layout info provider which provides additional information required for laying out the diagram
 */
public static void layoutIncrementally(final AgeDiagram diagram, final DiagramModification mod, final LayoutInfoProvider layoutInfoProvider) {
    Objects.requireNonNull(diagram, "diagram must not be null");
    Objects.requireNonNull(mod, "mod must not be null");
    Objects.requireNonNull(layoutInfoProvider, "layoutInfoProvider must not be null");
    final IncrementalLayoutMode currentLayoutMode = LayoutPreferences.getCurrentIncrementalLayoutMode();
    // Get all the nodes that need to be layed out.
    final Set<DiagramNode> unfilteredNodesToLayout = getNodesToLayoutIncrementally(diagram, currentLayoutMode, new HashSet<>());
    if (unfilteredNodesToLayout.size() == 0) {
        return;
    }
    // Lay our flow indicators. In the container is eventually layed out, this will be replaced but in cases where that is not the case,
    // we provide a default layout. Flow indicators are connections and as such will be filtered in the next step.
    layoutFlowIndicators(mod, unfilteredNodesToLayout.stream().filter(DiagramNodePredicates::isFlowIndicator).map(DiagramElement.class::cast), layoutInfoProvider);
    final Collection<DiagramNode> nodesToLayout = DiagramElementLayoutUtil.filterUnnecessaryNodes(unfilteredNodesToLayout, currentLayoutMode == IncrementalLayoutMode.LAYOUT_DIAGRAM);
    if (nodesToLayout.size() == 0) {
        // If the filtered node list is empty then the unfiltered list still contain feature self loop connections that need to be layed out.
        unfilteredNodesToLayout.stream().filter(DiagramElementLayoutUtil::isFeatureSelfLoopConnection).map(DiagramElement.class::cast).forEachOrdered(de -> layoutFeatureSelfLoopConnection(de, mod, layoutInfoProvider));
        return;
    }
    final LayoutOptions layoutOptions = LayoutOptions.createFromPreferences();
    if (currentLayoutMode == IncrementalLayoutMode.LAYOUT_DIAGRAM) {
        layout(INCREMENTAL_LAYOUT_LABEL, diagram, layoutInfoProvider, layoutOptions);
    } else {
        layout(mod, nodesToLayout, new StyleCalculator(diagram.getConfiguration(), StyleProvider.EMPTY), layoutInfoProvider, layoutOptions);
        // Set Positions of elements which do not have a position set.
        for (final DiagramNode dn : nodesToLayout) {
            if (dn instanceof DiagramElement) {
                final DiagramElement de = (DiagramElement) dn;
                if (!de.hasPosition()) {
                    if (de.getDockArea() == null) {
                        mod.setPosition(de, new Point(0.0, 0.0));
                    } else if (de.getDockArea() != DockArea.GROUP && de.getParent() instanceof DiagramElement) {
                        final DiagramElement parent = (DiagramElement) de.getParent();
                        final DockingPosition defaultDockingPosition = de.getGraphicalConfiguration().getDefaultDockingPosition();
                        final DockArea defaultDockArea = DockArea.fromDockingPosition(defaultDockingPosition);
                        if (parent.hasSize()) {
                            final Stream<DiagramElement> otherElementsAlongSide = parent.getChildren().stream().filter(c -> c.hasPosition() && c.hasSize() && c.getDockArea() == defaultDockArea);
                            // Determine the position of the new element along it's preferred docking position.
                            double locationAlongSide;
                            if (defaultDockingPosition == DockingPosition.TOP || defaultDockingPosition == DockingPosition.BOTTOM) {
                                locationAlongSide = otherElementsAlongSide.max(Comparator.comparingDouble(c -> c.getY())).map(c -> c.getX() + c.getWidth()).orElse(0.0);
                            } else {
                                locationAlongSide = otherElementsAlongSide.max(Comparator.comparingDouble(c -> c.getY())).map(c -> c.getY() + c.getHeight()).orElse(0.0);
                            }
                            // Set position based on the docking position
                            switch(defaultDockingPosition) {
                                case TOP:
                                    mod.setPosition(de, new Point(locationAlongSide, 0));
                                    break;
                                case BOTTOM:
                                    mod.setPosition(de, new Point(locationAlongSide, parent.getHeight()));
                                    break;
                                case LEFT:
                                    mod.setPosition(de, new Point(0, locationAlongSide));
                                    break;
                                case RIGHT:
                                    mod.setPosition(de, new Point(parent.getWidth(), locationAlongSide));
                                    break;
                                default:
                                    break;
                            }
                        }
                        mod.setDockArea(de, defaultDockArea);
                    }
                }
            }
        }
    }
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PortSide(org.eclipse.elk.core.options.PortSide) LayoutMapping(org.eclipse.elk.core.service.LayoutMapping) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) IGraphElementVisitor(org.eclipse.elk.core.util.IGraphElementVisitor) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) IStatus(org.eclipse.core.runtime.IStatus) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Graphic(org.osate.ge.graphics.Graphic) DiagramNodePredicates(org.osate.ge.internal.diagram.runtime.DiagramNodePredicates) StatusManager(org.eclipse.ui.statushandlers.StatusManager) IEditorPart(org.eclipse.ui.IEditorPart) EnumSet(java.util.EnumSet) Collection(java.util.Collection) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Point(org.osate.ge.graphics.Point) Collectors(java.util.stream.Collectors) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) DockingPosition(org.osate.ge.DockingPosition) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) Entry(java.util.Map.Entry) Optional(java.util.Optional) ElkEdge(org.eclipse.elk.graph.ElkEdge) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) Dimension(org.osate.ge.graphics.Dimension) ElkGraphPackage(org.eclipse.elk.graph.ElkGraphPackage) ModeGraphic(org.osate.ge.graphics.internal.ModeGraphic) DiagramModification(org.osate.ge.internal.diagram.runtime.DiagramModification) HashSet(java.util.HashSet) ElkUtil(org.eclipse.elk.core.util.ElkUtil) Style(org.osate.ge.graphics.Style) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) AgeShape(org.osate.ge.graphics.internal.AgeShape) LinkedList(java.util.LinkedList) Activator(org.osate.ge.internal.Activator) DiagramElementPredicates(org.osate.ge.internal.diagram.runtime.DiagramElementPredicates) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVector(org.eclipse.elk.core.math.KVector) Label(org.osate.ge.graphics.internal.Label) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) ElkShape(org.eclipse.elk.graph.ElkShape) Adapters(org.eclipse.core.runtime.Adapters) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AgeDiagramUtil(org.osate.ge.internal.diagram.runtime.AgeDiagramUtil) Comparator(java.util.Comparator) StyleProvider(org.osate.ge.internal.diagram.runtime.styling.StyleProvider) Collections(java.util.Collections) StyleCalculator(org.osate.ge.internal.diagram.runtime.styling.StyleCalculator) StyleCalculator(org.osate.ge.internal.diagram.runtime.styling.StyleCalculator) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Point(org.osate.ge.graphics.Point) DiagramNodePredicates(org.osate.ge.internal.diagram.runtime.DiagramNodePredicates) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) DockingPosition(org.osate.ge.DockingPosition) Stream(java.util.stream.Stream)

Example 5 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class DiagramElementLayoutUtil method getConnectionsAffectedByMove.

/**
 * Returns the connections which are affected by moving the specified elements
 * @param movedElement is the element which to get the affected connections
 * @param diagram is the diagram which contains the connections.
 * @param checkDescendants whether to check descendants of the specified elements when looking for connections
 * @return he connections which are affected by moving the specified elements
 */
public static Stream<DiagramElement> getConnectionsAffectedByMove(final DiagramElement movedElement, final AgeDiagram diagram, final boolean checkDescendants) {
    // Build a set containing the moved elements and all of their descendant which are represented as shapes
    final Set<BusinessObjectContext> diagramElements = checkDescendants ? movedElement.getAllDescendants().collect(Collectors.toSet()) : Collections.singleton(movedElement);
    final Stream<DiagramElement> connections = diagram.getAllDiagramNodes().filter(q -> q instanceof DiagramElement && DiagramElementPredicates.isConnection((DiagramElement) q)).map(DiagramElement.class::cast);
    // Iterate over all the connections in the diagram and update their bendpoints if their ends are in the set above.
    return connections.filter(c -> {
        final DiagramElement startElement = c.getStartElement();
        final DiagramElement endElement = c.getEndElement();
        final boolean isFlowIndicator = ((AgeConnection) c.getGraphic()).isFlowIndicator;
        return diagramElements.contains(startElement) && (diagramElements.contains(endElement) || isFlowIndicator);
    });
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) CoreOptions(org.eclipse.elk.core.options.CoreOptions) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PortSide(org.eclipse.elk.core.options.PortSide) LayoutMapping(org.eclipse.elk.core.service.LayoutMapping) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) IGraphElementVisitor(org.eclipse.elk.core.util.IGraphElementVisitor) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) IStatus(org.eclipse.core.runtime.IStatus) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Graphic(org.osate.ge.graphics.Graphic) DiagramNodePredicates(org.osate.ge.internal.diagram.runtime.DiagramNodePredicates) StatusManager(org.eclipse.ui.statushandlers.StatusManager) IEditorPart(org.eclipse.ui.IEditorPart) EnumSet(java.util.EnumSet) Collection(java.util.Collection) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Point(org.osate.ge.graphics.Point) Collectors(java.util.stream.Collectors) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) DockingPosition(org.osate.ge.DockingPosition) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) Entry(java.util.Map.Entry) Optional(java.util.Optional) ElkEdge(org.eclipse.elk.graph.ElkEdge) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) Dimension(org.osate.ge.graphics.Dimension) ElkGraphPackage(org.eclipse.elk.graph.ElkGraphPackage) ModeGraphic(org.osate.ge.graphics.internal.ModeGraphic) DiagramModification(org.osate.ge.internal.diagram.runtime.DiagramModification) HashSet(java.util.HashSet) ElkUtil(org.eclipse.elk.core.util.ElkUtil) Style(org.osate.ge.graphics.Style) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) AgeShape(org.osate.ge.graphics.internal.AgeShape) LinkedList(java.util.LinkedList) Activator(org.osate.ge.internal.Activator) DiagramElementPredicates(org.osate.ge.internal.diagram.runtime.DiagramElementPredicates) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVector(org.eclipse.elk.core.math.KVector) Label(org.osate.ge.graphics.internal.Label) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) ElkShape(org.eclipse.elk.graph.ElkShape) Adapters(org.eclipse.core.runtime.Adapters) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AgeDiagramUtil(org.osate.ge.internal.diagram.runtime.AgeDiagramUtil) Comparator(java.util.Comparator) StyleProvider(org.osate.ge.internal.diagram.runtime.styling.StyleProvider) Collections(java.util.Collections) StyleCalculator(org.osate.ge.internal.diagram.runtime.styling.StyleCalculator) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)46 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)35 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)20 IEditorPart (org.eclipse.ui.IEditorPart)18 List (java.util.List)16 Objects (java.util.Objects)16 Collectors (java.util.stream.Collectors)12 BusinessObjectContext (org.osate.ge.BusinessObjectContext)12 ExtensionRegistryService (org.osate.ge.internal.services.ExtensionRegistryService)11 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)10 Collections (java.util.Collections)9 Adapters (org.eclipse.core.runtime.Adapters)9 DiagramUpdater (org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater)9 Collection (java.util.Collection)8 LinkedList (java.util.LinkedList)8 Optional (java.util.Optional)8 Stream (java.util.stream.Stream)8 Point (org.osate.ge.graphics.Point)8 ArrayList (java.util.ArrayList)7 UiUtil (org.osate.ge.internal.ui.util.UiUtil)7