use of org.eclipse.vorto.core.api.repository.ModelResource in project vorto by eclipse.
the class ModelResourceViewerComparator method compare.
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
int ret = -1;
ModelResource p1 = (ModelResource) e1;
ModelResource p2 = (ModelResource) e2;
switch(columnName) {
case AbstractModelRepositoryViewPart.NAMESPACE:
ret = p1.getId().getNamespace().compareTo(p2.getId().getNamespace());
break;
case AbstractModelRepositoryViewPart.NAME:
ret = p1.getDisplayName().compareTo(p2.getDisplayName());
break;
case AbstractModelRepositoryViewPart.VERSION:
ret = p1.getId().getVersion().compareTo(p2.getId().getVersion());
break;
case AbstractModelRepositoryViewPart.DESCRIPTION:
ret = p1.getDescription().compareTo(p2.getDescription());
break;
default:
ret = p1.getId().getModelType().compareTo(p2.getId().getModelType());
break;
}
if (direction == SWT.UP) {
ret = -ret;
}
return ret;
}
use of org.eclipse.vorto.core.api.repository.ModelResource in project vorto by eclipse.
the class AbstractModelRepositoryViewPart method initContextMenu.
/**
* Create the context menu
*/
private void initContextMenu() {
final MenuManager menuMgr = new MenuManager("#PopupMenu");
Menu menu = menuMgr.createContextMenu(viewer.getControl());
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
if (viewer.getStructuredSelection().isEmpty()) {
return;
}
ModelResource model = (ModelResource) viewer.getStructuredSelection().getFirstElement();
if (model.getId().getModelType() == ModelType.InformationModel || model.getId().getModelType() == ModelType.Functionblock) {
addListGeneratorsToMenu(manager, model);
}
menuMgr.add(new PreviewSharedModelAction(model));
}
});
menuMgr.setRemoveAllWhenShown(true);
viewer.getControl().setMenu(menu);
}
use of org.eclipse.vorto.core.api.repository.ModelResource in project vorto by eclipse.
the class AddSharedReferenceDropAction method downloadAndSaveModel.
// Download and save model from repository to local project.
// It also recursively do the same for the model references.
private Optional<IModelElement> downloadAndSaveModel(IModelProject project, ModelId modelId) {
try {
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());
return Optional.of(project.addModelElement(model.getId(), new ByteArrayInputStream(modelContent)));
} else {
MessageDisplayFactory.getMessageDisplay().displayError("Model " + modelId.toString() + " not found in repository.");
}
} catch (RepositoryException e) {
ExceptionHandlerFactory.getHandler().handle(e);
}
return Optional.empty();
}
use of org.eclipse.vorto.core.api.repository.ModelResource in project vorto by eclipse.
the class RepositoryResourceDropAction method downloadMappings.
private void downloadMappings(IModelProject modelProject, List<ModelId> referencedBy) {
for (ModelId modelId : referencedBy) {
ModelResource model = modelRepo.getModel(modelId);
if (model != null && model.getId().getModelType() == ModelType.Mapping) {
MessageDisplayFactory.getMessageDisplay().display("Downloading " + modelId.toString());
byte[] modelContent = modelRepo.downloadContent(model.getId());
saveToProject(modelProject, modelContent, model.getId());
}
}
}
use of org.eclipse.vorto.core.api.repository.ModelResource in project vorto by eclipse.
the class ModelUploadDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
Composite container = new Composite(composite, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout layout = new GridLayout(2, false);
container.setLayout(layout);
String namespace = null;
String name = null;
String version = null;
String modelType = null;
String displayName = null;
String description = null;
ModelResource modelResource = uploadResult.getModelResource();
if (modelResource != null) {
ModelId id = modelResource.getId();
if (id != null) {
namespace = id.getNamespace();
name = id.getName();
version = id.getVersion();
modelType = id.getModelType().toString();
}
displayName = modelResource.getDisplayName();
description = modelResource.getDescription();
}
createField(container, NAMESPACE_LABEL, namespace);
createField(container, NAME_LABEL, name);
createField(container, VERSION_LABEL, version);
createField(container, MODELTYPE_LABEL, modelType);
createField(container, DISPLAY_NAME_LABEL, displayName);
createField(container, DESCRIPTION_LABEL, description);
if (modelResource != null) {
createReferencesTable(container, modelResource.getReferences());
}
return composite;
}
Aggregations