From a8c21d7a4a71f7298aba656c68ba920a892d6c96 Mon Sep 17 00:00:00 2001 From: Erle Czar Mantos Date: Tue, 14 Jun 2016 15:21:09 +0800 Subject: [PATCH] Closes #260 - Support for drag-n-drop of function block to function block Signed-off-by: Erle Czar Mantos --- .../dnd/ModelDropListenerFactory.java | 5 ++ .../AddSharedReferenceDropAction.java | 48 +++++++++---------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListenerFactory.java b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListenerFactory.java index 0c9ff28cbf..4ac7e99c7b 100644 --- a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListenerFactory.java +++ b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListenerFactory.java @@ -56,6 +56,11 @@ public static DropTargetListener functionblockViewPartDropListener(Viewer viewer FunctionblockModelElement.class, DatatypeModelElement.class), new AddLocalReferenceDropAction(DatatypeModelElement.class)) + .addDropAction( + new TargetClassSourceClassValidator( + FunctionblockModelElement.class, + FunctionblockModelElement.class), + new AddLocalReferenceDropAction(FunctionblockModelElement.class)) .addDropAction( new TargetClassModelTypeValidator( VortoModelProject.class, ModelType.Functionblock), diff --git a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/dropaction/AddSharedReferenceDropAction.java b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/dropaction/AddSharedReferenceDropAction.java index 6acf427535..4cfc854060 100644 --- a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/dropaction/AddSharedReferenceDropAction.java +++ b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/dropaction/AddSharedReferenceDropAction.java @@ -29,10 +29,10 @@ * A drop action for dropping an IModelProject to another IModelProject * */ -public class AddSharedReferenceDropAction implements IDropAction { +public class AddSharedReferenceDropAction implements IDropAction { private Class droppedObjectClass = null; - + private IModelRepository modelRepo = ModelRepositoryFactory.getModelRepository(); public AddSharedReferenceDropAction(Class droppedObjectClass) { @@ -40,37 +40,37 @@ public AddSharedReferenceDropAction(Class droppedObjectClass) { } @Override - public IModelElement performDrop(IModelElement receivingModelElement, - ModelResource modelElementToBeDropped) { + public IModelElement performDrop(IModelElement receivingModelElement, ModelResource modelElementToBeDropped) { if (droppedObjectClass.isInstance(modelElementToBeDropped) && !receivingModelElement.equals(modelElementToBeDropped)) { - ModelResource modelToAddAsReference = downloadAndSaveModel(receivingModelElement.getProject(), modelElementToBeDropped.getId()); - - receivingModelElement.addModelReference(modelToAddAsReference.getId()); + ModelResource modelToAddAsReference = downloadAndSaveModel(receivingModelElement.getProject(), + modelElementToBeDropped.getId()); + + receivingModelElement.addModelReference(modelToAddAsReference.getId()); receivingModelElement.save(); return receivingModelElement; } - + return null; } - + // Download and save model from repository to local project. - // It also recursively do the same for the model references. - private ModelResource downloadAndSaveModel(IModelProject project, ModelId modelId) { - ModelResource model = modelRepo.getModel(modelId); - if (model != null) { - for (ModelId reference : model.getReferences()) { - downloadAndSaveModel(project, reference); - } - MessageDisplayFactory.getMessageDisplay().display("Downloading " + modelId.toString()); - byte[] modelContent = modelRepo.downloadContent(model.getId()); - project.addModelElement(model.getId(),new ByteArrayInputStream(modelContent)); - } else { - MessageDisplayFactory.getMessageDisplay().displayError( - "Model " + modelId.toString() + " not found in repository."); + // It also recursively do the same for the model references. + private ModelResource downloadAndSaveModel(IModelProject project, ModelId modelId) { + ModelResource model = modelRepo.getModel(modelId); + if (model != null) { + for (ModelId reference : model.getReferences()) { + downloadAndSaveModel(project, reference); } - - return model; + MessageDisplayFactory.getMessageDisplay().display("Downloading " + modelId.toString()); + byte[] modelContent = modelRepo.downloadContent(model.getId()); + project.addModelElement(model.getId(), new ByteArrayInputStream(modelContent)); + } else { + MessageDisplayFactory.getMessageDisplay() + .displayError("Model " + modelId.toString() + " not found in repository."); } + + return model; + } }