Search in sources :

Example 6 with ReferenceBuilderService

use of org.osate.ge.services.ReferenceBuilderService in project osate2 by osate.

the class CopyDiagramElementsHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // Get clipboard. The clipboard service stores the clipboard weakly but this handler does not need to
    // because the paste action stores a strong reference to the clipboard. This isn't stored in a field by
    // the constructor because the handler is not instantiated for each editor.
    final Bundle bundle = FrameworkUtil.getBundle(getClass());
    final IEclipseContext context = EclipseContextFactory.getServiceContext(bundle.getBundleContext());
    final Clipboard clipboard = Objects.requireNonNull(context.get(ClipboardService.class), "Unable to get clipboard service").getClipboard();
    final ReferenceBuilderService refBuilder = Objects.requireNonNull(context.get(ReferenceBuilderService.class), "Unable to get reference builder service");
    final List<CopiedDiagramElement> copiedElements = new ArrayList<>();
    for (final DiagramElement de : AgeHandlerUtil.getSelectedDiagramElements()) {
        final DiagramElement copiedElement = CopyAndPasteUtil.copyDiagramElement(de, null, de.getRelativeReference(), refBuilder);
        final Point position = CopyAndPasteUtil.getPositionToCopy(de);
        copiedElements.add(new CopiedDiagramElement(copiedElement, de.getBusinessObject(), position));
    }
    clipboard.setContents(new CopiedDiagramElements(ImmutableList.copyOf(copiedElements)));
    return null;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) CopiedDiagramElement(org.osate.ge.internal.ui.editor.actions.CopiedDiagramElement) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Bundle(org.osgi.framework.Bundle) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) CopiedDiagramElement(org.osate.ge.internal.ui.editor.actions.CopiedDiagramElement) ArrayList(java.util.ArrayList) CopiedDiagramElements(org.osate.ge.internal.ui.editor.actions.CopiedDiagramElements) Clipboard(org.osate.ge.internal.services.ClipboardService.Clipboard) Point(org.osate.ge.graphics.Point)

Example 7 with ReferenceBuilderService

use of org.osate.ge.services.ReferenceBuilderService in project osate2 by osate.

the class ShowContentsUtil method addContentsToSelectedElements.

/**
 * Adds contents to the selected diagram elements. Adds all children which pass the specified filter.
 * @param event is the ExecutionEvent of the handler which provides the active editor.
 * @param filters determines the filters to apply to the selected elements.
 */
public static void addContentsToSelectedElements(final ExecutionEvent event, final Function<DiagramElement, ImmutableSet<ContentFilter>> filters) {
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof InternalDiagramEditor)) {
        throw new RuntimeException("Unexpected editor: " + activeEditor);
    }
    final InternalDiagramEditor diagramEditor = (InternalDiagramEditor) activeEditor;
    final ExtensionRegistryService extService = Objects.requireNonNull(Adapters.adapt(diagramEditor, ExtensionRegistryService.class), "Unable to retrieve extension service");
    final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
    final AgeDiagram diagram = diagramEditor.getDiagram();
    if (diagram == null) {
        throw new RuntimeException("Unable to retrieve diagram");
    }
    final DiagramUpdater diagramUpdater = Objects.requireNonNull(diagramEditor.getDiagramUpdater(), "Unable to retrieve diagram updater");
    final ReferenceBuilderService referenceBuilder = Objects.requireNonNull(Adapters.adapt(diagramEditor, ReferenceBuilderService.class), "Unable to retrieve reference builder service");
    if (addChildrenDuringNextUpdate(selectedDiagramElements, diagramUpdater, extService, referenceBuilder, filters)) {
        diagramEditor.getActionExecutor().execute("Show Contents", ExecutionMode.NORMAL, () -> {
            diagramEditor.updateDiagram();
            return null;
        });
    }
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) IEditorPart(org.eclipse.ui.IEditorPart)

Example 8 with ReferenceBuilderService

use of org.osate.ge.services.ReferenceBuilderService 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

ReferenceBuilderService (org.osate.ge.services.ReferenceBuilderService)8 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)6 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)5 AadlModificationService (org.osate.ge.internal.services.AadlModificationService)5 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Objects (java.util.Objects)4 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)4 EObject (org.eclipse.emf.ecore.EObject)4 BusinessObjectHandler (org.osate.ge.businessobjecthandling.BusinessObjectHandler)4 Bundle (org.osgi.framework.Bundle)4 Predicates (com.google.common.base.Predicates)3 Collection (java.util.Collection)3 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)3 IEditorPart (org.eclipse.ui.IEditorPart)3 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)3 Collections (java.util.Collections)2 AbstractHandler (org.eclipse.core.commands.AbstractHandler)2 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2