Skip to content

Commit

Permalink
Closes #260 - Support for drag-n-drop of function block to function b…
Browse files Browse the repository at this point in the history
…lock

Signed-off-by: Erle Czar Mantos <[email protected]>
  • Loading branch information
Erle Czar Mantos committed Jun 14, 2016
1 parent 6c4fdab commit a8c21d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,48 @@
* A drop action for dropping an IModelProject to another IModelProject
*
*/
public class AddSharedReferenceDropAction implements IDropAction<IModelElement,ModelResource> {
public class AddSharedReferenceDropAction implements IDropAction<IModelElement, ModelResource> {

private Class<?> droppedObjectClass = null;

private IModelRepository modelRepo = ModelRepositoryFactory.getModelRepository();

public AddSharedReferenceDropAction(Class<?> droppedObjectClass) {
this.droppedObjectClass = 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;
}
}

0 comments on commit a8c21d7

Please sign in to comment.