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;
}
Aggregations