import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.adapter.PasteHandlerAdapter;
import org.simantics.db.layer0.internal.SimanticsInternal;
import org.simantics.db.layer0.util.SimanticsClipboard;
import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
import org.simantics.db.layer0.util.SimanticsKeys;
-import org.simantics.db.layer0.util.TransferableGraphConfiguration2.RootSpec;
+import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec;
+import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec.SeedSpecType;
import org.simantics.graph.db.IImportAdvisor;
import org.simantics.graph.db.IImportAdvisor2;
import org.simantics.graph.db.IImportAdvisor2.RootInfo;
ModelTransferableGraphSource mtgs = (ModelTransferableGraphSource)tgs;
- loop: for(RootSpec spec : mtgs.getConfiguration().roots) {
- if(!spec.internal) continue;
+ loop: for(SeedSpec spec : mtgs.getConfiguration().seeds) {
+ if(SeedSpecType.SPECIAL_ROOT.equals(spec.specType)) continue;
for(RootInfo info : roots) {
if(spec.name.equals(info.root.name)) {
result.add(info.resource);
Collection<Resource> result = new ArrayList<>();
+
+ // Check if root resource is allowed for pasting
+ checkIfRootAllowsPaste(graph);
+
Map<String,Object> hints = Collections.singletonMap(ClipboardUtils.HINT_TARGET_RESOURCE, resource);
onPasteBegin(graph);
}
+ protected void checkIfRootAllowsPaste(ReadGraph graph) throws DatabaseException {
+ if (resource == null)
+ return;
+ Layer0 L0 = Layer0.getInstance(graph);
+ // check if root is published
+ Boolean published = graph.getPossibleRelatedValue(resource, L0.Entity_published);
+ if (published != null && published) {
+ throw new DatabaseException("Target resource " + NameUtils.getSafeName(graph, resource) + " is published and does not allow paste.");
+ }
+ }
+
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class adapter) {