X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fadapter%2Fimpl%2FDefaultPasteHandler.java;h=067ed9207fe4d224f2add76b0ae00d71e098b51d;hp=6b30e4ddb576c3424ba6283dacedf29af7a4f607;hb=2ee4ce7f7cb1df434c7552d4fce34fd7330352e5;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultPasteHandler.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultPasteHandler.java index 6b30e4ddb..067ed9207 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultPasteHandler.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultPasteHandler.java @@ -21,6 +21,7 @@ import java.util.Set; 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; @@ -31,7 +32,8 @@ import org.simantics.db.layer0.util.RemoverUtil; 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; @@ -119,8 +121,8 @@ public class DefaultPasteHandler extends PasteHandlerAdapter { 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); @@ -145,6 +147,10 @@ public class DefaultPasteHandler extends PasteHandlerAdapter { Collection result = new ArrayList<>(); + + // Check if root resource is allowed for pasting + checkIfRootAllowsPaste(graph); + Map hints = Collections.singletonMap(ClipboardUtils.HINT_TARGET_RESOURCE, resource); onPasteBegin(graph); @@ -178,6 +184,15 @@ public class DefaultPasteHandler extends PasteHandlerAdapter { } + protected void checkIfRootAllowsPaste(ReadGraph graph) throws DatabaseException { + 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) {