code: /*--------------------------------------------------------------*
    Copyright (C) 2006-2020 OpenSim Ltd.
  
    This file is distributed WITHOUT ANY WARRANTY. See the file
    'License' for details on this and other legal matters.
  *--------------------------------------------------------------*/
  
  package org.omnetpp.scave.actions;
  
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.jface.viewers.ISelection;
  import org.eclipse.swt.custom.BusyIndicator;
  import org.eclipse.swt.widgets.Display;
  import org.omnetpp.scave.ScaveImages;
  import org.omnetpp.scave.ScavePlugin;
  import org.omnetpp.scave.editors.ScaveEditor;
  import org.omnetpp.scave.python.ChartViewerBase;
  
  /**
   * Copy plot image to the clipboard.
   */
  public class CopyImageToClipboardAction extends AbstractScaveAction {
      public CopyImageToClipboardAction() {
          setText("Copy Image to Clipboard");
          setImageDescriptor(ScavePlugin.getImageDescriptor(ScaveImages.IMG_ETOOL16_COPYIMAGE));
      }
  
      @Override
      protected void doRun(ScaveEditor editor, ISelection selection) throws CoreException {
          final ChartViewerBase chartViewer = editor.getActiveChartViewer();
  
          if (chartViewer != null) {
              BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
                  public void run() {
                      chartViewer.copyImageToClipboard();
                  }
              });
          }
  
      }
  
      @Override
      protected boolean isApplicable(ScaveEditor editor, ISelection selection) {
          return editor.getActiveChartViewer() != null;
      }
  }
  