Search in sources :

Example 1 with ModelResource

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;
}
Also used : ModelResource(org.eclipse.vorto.core.api.repository.ModelResource)

Example 2 with ModelResource

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);
}
Also used : ModelResource(org.eclipse.vorto.core.api.repository.ModelResource) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuListener(org.eclipse.jface.action.IMenuListener)

Example 3 with ModelResource

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();
}
Also used : ModelResource(org.eclipse.vorto.core.api.repository.ModelResource) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Example 4 with ModelResource

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());
        }
    }
}
Also used : ModelResource(org.eclipse.vorto.core.api.repository.ModelResource) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Example 5 with ModelResource

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;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ModelResource(org.eclipse.vorto.core.api.repository.ModelResource) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) 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