Search in sources :

Example 1 with Clipboard

use of org.osate.ge.internal.services.ClipboardService.Clipboard 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)

Aggregations

ArrayList (java.util.ArrayList)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 Point (org.osate.ge.graphics.Point)1 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)1 Clipboard (org.osate.ge.internal.services.ClipboardService.Clipboard)1 CopiedDiagramElement (org.osate.ge.internal.ui.editor.actions.CopiedDiagramElement)1 CopiedDiagramElements (org.osate.ge.internal.ui.editor.actions.CopiedDiagramElements)1 ReferenceBuilderService (org.osate.ge.services.ReferenceBuilderService)1 Bundle (org.osgi.framework.Bundle)1