import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
if(copyText(selection)) return null;
formatSelectionToClipboardText(event);
-
final Resource[] rs = ResourceAdaptionUtils.toResources(selection);
- copyResourcesToClipboard(rs, selection);
+ Job job = new Job("Copy resources") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Copy resources to clipboard", 1);
+ copyResourcesToClipboard(rs, selection, SubMonitor.convert(monitor, 1));
+ return null;
+ }
+ };
+ job.setUser(true);
+ job.schedule();
+
return null;
}
- public static String copyResourcesToClipboard(final Resource[] rs, ISelection selection) {
+ public static String copyResourcesToClipboard(final Resource[] rs, ISelection selection, IProgressMonitor monitor) {
if(rs == null || rs.length == 0) {
// This support was added for copying of properties (variables)
if(!variables.isEmpty()) {
final SimanticsClipboardImpl builder = new SimanticsClipboardImpl();
for(Variable var : variables) {
- builder.addContent(Collections.singleton(ClipboardUtils.createVariable(Simantics.getSession(), var)));
+ builder.addContent(Collections.singleton(ClipboardUtils.createVariable(Simantics.getSession(), var)), monitor);
}
Simantics.setClipboard(builder);
setCopyMessage(builder.getContents().size(), "variable");
public void run(ReadGraph graph) throws DatabaseException {
for (Resource r : rs) {
CopyHandler handler = graph.adapt(r, CopyHandler.class);
- handler.copyToClipboard(graph, builder);
+ handler.copyToClipboard(graph, builder, monitor);
}
}
});
}
private static void setStatus(String message) {
- if (status != null)
- status.setMessage(message);
+ if (status != null) {
+ SWTUtils.asyncExec(
+ PlatformUI.getWorkbench().getDisplay(),
+ () -> status.setMessage(message));
+ }
}
private boolean formatSelectionToClipboardText(ExecutionEvent event) {