Search in sources :

Example 21 with CanonicalBusinessObjectReference

use of org.osate.ge.CanonicalBusinessObjectReference in project osate2 by osate.

the class EditorRenameUtil method rename.

public static void rename(final DiagramElement de, final String value, final InternalDiagramEditor editor) {
    final ReferenceBuilderService referenceBuilder = Objects.requireNonNull(editor.getAdapter(ReferenceBuilderService.class), "Unable to retrieve reference builder service");
    final DiagramService diagramService = Objects.requireNonNull(editor.getAdapter(DiagramService.class), "Unable to retrieve diagram service");
    final AadlModificationService aadlModService = Objects.requireNonNull(editor.getAdapter(AadlModificationService.class), "Unable to retrieve AADL modification service");
    final ProjectProvider projectProvider = Objects.requireNonNull(editor.getAdapter(ProjectProvider.class), "Unable to retrieve project provider");
    final ActionExecutor actionExecutor = editor.getActionExecutor();
    final ModelChangeNotifier modelChangeNotifier = Objects.requireNonNull(editor.getAdapter(ModelChangeNotifier.class), "Unable to retrieve model change notifier");
    final EObject bo = (EObject) de.getBusinessObject();
    final BusinessObjectHandler handler = de.getBusinessObjectHandler();
    final String initialValue = getCurrentName(de);
    // If the business object handler provides a Rename method, then use it to rename the element instead of using LTK refactoring.
    if (RenameUtil.supportsNonLtkRename(handler)) {
        final CanonicalBusinessObjectReference canonicalRef = referenceBuilder.getCanonicalReference(bo);
        final IProject project = ProjectUtil.getProjectOrNull(EcoreUtil.getURI(bo));
        final ReferenceCollection references;
        if (canonicalRef == null || project == null) {
            references = null;
        } else {
            final Set<IProject> relevantProjects = ProjectUtil.getAffectedProjects(project, new HashSet<>());
            references = diagramService.getReferences(relevantProjects, Collections.singleton(canonicalRef));
        }
        aadlModService.modify(bo, (boToModify) -> {
            RenameUtil.performNonLtkRename(boToModify, handler, value);
            // Update diagram references. This is done in the modify block because the project is build and the diagram is updated before the modify()
            // function returns.
            final CanonicalBusinessObjectReference newCanonicalRef = referenceBuilder.getCanonicalReference(boToModify);
            final RelativeBusinessObjectReference newRelRef = referenceBuilder.getRelativeReference(boToModify);
            if (newCanonicalRef != null && newRelRef != null) {
                references.update(new UpdatedReferenceValueProvider() {

                    @Override
                    public CanonicalBusinessObjectReference getNewCanonicalReference(final CanonicalBusinessObjectReference originalCanonicalReference) {
                        if (originalCanonicalReference.equals(canonicalRef)) {
                            return newCanonicalRef;
                        }
                        return null;
                    }

                    @Override
                    public RelativeBusinessObjectReference getNewRelativeReference(final CanonicalBusinessObjectReference originalCanonicalReference) {
                        if (originalCanonicalReference.equals(canonicalRef)) {
                            return newRelRef;
                        }
                        return null;
                    }
                });
            }
        });
    } else {
        // Rename using LTK
        actionExecutor.execute("Rename Element " + initialValue + " to " + value, ActionExecutor.ExecutionMode.NORMAL, new LtkRenameAction(projectProvider, modelChangeNotifier, new BoSupplier(de), value, initialValue));
    }
}
Also used : ActionExecutor(org.osate.ge.internal.services.ActionExecutor) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) IProject(org.eclipse.core.resources.IProject) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) UpdatedReferenceValueProvider(org.osate.ge.internal.services.DiagramService.UpdatedReferenceValueProvider) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) EObject(org.eclipse.emf.ecore.EObject) LtkRenameAction(org.osate.ge.internal.ui.LtkRenameAction) DiagramService(org.osate.ge.internal.services.DiagramService) ReferenceCollection(org.osate.ge.internal.services.DiagramService.ReferenceCollection) ProjectProvider(org.osate.ge.internal.services.ProjectProvider)

Aggregations

CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)21 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)6 HashMap (java.util.HashMap)5 IProject (org.eclipse.core.resources.IProject)4 URI (org.eclipse.emf.common.util.URI)4 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)4 DiagramConfigurationBuilder (org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Objects (java.util.Objects)3 IResource (org.eclipse.core.resources.IResource)3 CoreException (org.eclipse.core.runtime.CoreException)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 EObject (org.eclipse.emf.ecore.EObject)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 BusinessObjectContext (org.osate.ge.BusinessObjectContext)3 AgeDiagramProvider (org.osate.ge.internal.AgeDiagramProvider)3 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)3 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)3 Collections (java.util.Collections)2