Search in sources :

Example 6 with ModelResource

use of org.eclipse.vorto.core.api.repository.ModelResource in project vorto by eclipse.

the class RepositoryResourceDropAction method downloadAndSaveModel.

// Download and save model from repository to local project.
// It also recursively do the same for the model references.
private IModelElement downloadAndSaveModel(IModelProject modelProject, ModelId modelId) {
    IModelElement modelElement = null;
    try {
        ModelResource model = modelRepo.getModel(modelId);
        if (model != null) {
            if (!modelProject.exists(modelId)) {
                for (ModelId reference : model.getReferences()) {
                    downloadAndSaveModel(modelProject, reference);
                }
                downloadMappings(modelProject, model.getReferencedBy());
                MessageDisplayFactory.getMessageDisplay().display("Downloading " + modelId.toString());
                byte[] modelContent = modelRepo.downloadContent(model.getId());
                modelElement = saveToProject(modelProject, modelContent, model.getId());
            } else {
                modelElement = modelProject.getModelElementById(modelId);
            }
        } else {
            MessageDisplayFactory.getMessageDisplay().displayError("Model " + modelId.toString() + " not found in repository.");
        }
    } catch (RepositoryException e) {
        ExceptionHandlerFactory.getHandler().handle(e);
    }
    return modelElement;
}
Also used : IModelElement(org.eclipse.vorto.core.ui.model.IModelElement) ModelResource(org.eclipse.vorto.core.api.repository.ModelResource) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Aggregations

ModelResource (org.eclipse.vorto.core.api.repository.ModelResource)6 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)4 RepositoryException (org.eclipse.vorto.core.api.repository.RepositoryException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Menu (org.eclipse.swt.widgets.Menu)1 IModelElement (org.eclipse.vorto.core.ui.model.IModelElement)1