]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/Copy.java
Allow simulation stop handling in Simantics/Sequences
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / Copy.java
1 package org.simantics.modeling.ui.actions;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6
7 import org.eclipse.core.runtime.IProgressMonitor;
8 import org.eclipse.core.runtime.IStatus;
9 import org.eclipse.core.runtime.Status;
10 import org.eclipse.core.runtime.jobs.Job;
11 import org.simantics.db.Resource;
12 import org.simantics.db.layer0.adapter.ActionFactory;
13 import org.simantics.db.layer0.adapter.ActionFactory2;
14 import org.simantics.modeling.ui.modelBrowser.handlers.StandardCopyHandler;
15
16 public class Copy implements ActionFactory, ActionFactory2 {
17
18         @Override
19     public Runnable create(Object target) {
20                 return create(Collections.singletonList(target));
21         }
22
23         @Override
24     public Runnable create(Collection<?> target) {
25
26                 final ArrayList<Resource> resources = new ArrayList<Resource>();
27                 
28                 for(Object o : target) {
29                         if(!(o instanceof Resource))
30                                 return null;
31                         resources.add((Resource)o);
32                 }
33         return () -> {
34             Job job = new Job(Messages.Copy_Copy) {
35
36                 @Override
37                 protected IStatus run(IProgressMonitor monitor) {
38                     StandardCopyHandler.copyResourcesToClipboard(resources.toArray(new Resource[resources.size()]), null, monitor);
39                     return Status.OK_STATUS;
40                 }
41             };
42             job.setUser(true);
43             job.schedule();
44         };
45     }
46
47 }