Search in sources :

Example 1 with ModelId

use of org.eclipse.vorto.core.api.model.model.ModelId in project vorto by eclipse.

the class ModelUploadDialog method createReferencesTable.

private void createReferencesTable(Composite container, List<ModelId> references) {
    Label lbtFirstName = new Label(container, SWT.NONE);
    lbtFirstName.setText(REFERENCES_LABEL);
    GridData data = new GridData();
    data.grabExcessHorizontalSpace = true;
    data.horizontalAlignment = GridData.FILL;
    Table table = new Table(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    table.setLayoutData(data);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    for (String columnName : COLUMNS) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText(columnName);
    }
    if (references != null) {
        for (ModelId id : references) {
            TableItem item = new TableItem(table, 0);
            item.setImage(0, getImage(id));
            item.setImage(1, ImageUtil.getImageForModelType(id.getModelType()));
            item.setText(1, id.getName());
            item.setText(2, id.getNamespace());
            item.setText(3, id.getVersion());
        }
    }
    for (int i = 0; i < COLUMNS.length; i++) {
        table.getColumn(i).pack();
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) TableColumn(org.eclipse.swt.widgets.TableColumn) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Example 2 with ModelId

use of org.eclipse.vorto.core.api.model.model.ModelId 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 3 with ModelId

use of org.eclipse.vorto.core.api.model.model.ModelId 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 4 with ModelId

use of org.eclipse.vorto.core.api.model.model.ModelId in project vorto by eclipse.

the class AbstractModelElement method getReferences.

public Set<IModelElement> getReferences() {
    Set<IModelElement> references = new TreeSet<>();
    for (ModelReference modelReference : getModel().getReferences()) {
        for (ModelType possibleType : getPossibleReferenceTypes()) {
            ModelId modelId = ModelIdFactory.newInstance(possibleType, modelReference);
            IModelElement modelElementReference = this.modelProject.getModelElementById(modelId);
            if (modelElementReference != null) {
                references.add(modelElementReference);
                break;
            }
        }
    }
    return references;
}
Also used : TreeSet(java.util.TreeSet) ModelType(org.eclipse.vorto.core.api.model.model.ModelType) ModelId(org.eclipse.vorto.core.api.model.model.ModelId) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference)

Example 5 with ModelId

use of org.eclipse.vorto.core.api.model.model.ModelId in project vorto by eclipse.

the class DatatypeTreeViewer method initContextMenu.

protected void initContextMenu() {
    final MenuManager menuMgr = new MenuManager("#PopupMenuDt");
    Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            if (!treeViewer.getStructuredSelection().isEmpty()) {
                final IModelElement model = (IModelElement) treeViewer.getStructuredSelection().getFirstElement();
                if (model.getId().getModelType() == ModelType.Datatype) {
                    menuMgr.add(ShareModelAction.newInstance(treeViewer, model));
                    menuMgr.add(DeleteModelAction.newInstance(localModelWorkspace, treeViewer, model));
                    menuMgr.add(new ProjectAction("New Mapping Model", ImageUtil.getImage("add_obj.gif"), treeViewer.getLocalModelWorkspace()) {

                        @Override
                        public void doAction() {
                            IModelElement firstElement = (IModelElement) treeViewer.getStructuredSelection().getFirstElement();
                            ModelId modelId = firstElement.getId();
                            WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), new MappingModelWizard(treeViewer.getLocalModelWorkspace().getProjectBrowser().getSelectedProject(), modelId));
                            dialog.create();
                            dialog.open();
                        }
                    });
                }
            }
            manager.add(new ProjectAction("New Entity", ImageUtil.getImage("add_obj.gif"), treeViewer.getLocalModelWorkspace()) {

                @Override
                public void doAction() {
                    WizardDialog wizardDialog = new WizardDialog(treeViewer.getControl().getShell(), new EntityWizard(treeViewer.getLocalModelWorkspace().getProjectBrowser().getSelectedProject()));
                    if (wizardDialog.open() == Window.OK) {
                        populate(treeViewer.getLocalModelWorkspace().getProjectBrowser().getSelectedProject().getModelElementsByType(ModelType.Datatype));
                    }
                }
            });
            manager.add(new ProjectAction("New Enum", ImageUtil.getImage("add_obj.gif"), treeViewer.getLocalModelWorkspace()) {

                @Override
                public void doAction() {
                    WizardDialog wizardDialog = new WizardDialog(treeViewer.getControl().getShell(), new EnumWizard(treeViewer.getLocalModelWorkspace().getProjectBrowser().getSelectedProject()));
                    if (wizardDialog.open() == Window.OK) {
                        populate(treeViewer.getLocalModelWorkspace().getProjectBrowser().getSelectedProject().getModelElementsByType(ModelType.Datatype));
                    }
                }
            });
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    this.treeViewer.getControl().setMenu(menu);
}
Also used : MappingModelWizard(org.eclipse.vorto.wizard.mapping.MappingModelWizard) EntityWizard(org.eclipse.vorto.wizard.datatype.EntityWizard) IModelElement(org.eclipse.vorto.core.ui.model.IModelElement) ProjectAction(org.eclipse.vorto.perspective.command.ProjectAction) EnumWizard(org.eclipse.vorto.wizard.datatype.EnumWizard) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IMenuManager(org.eclipse.jface.action.IMenuManager) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IMenuListener(org.eclipse.jface.action.IMenuListener) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Aggregations

ModelId (org.eclipse.vorto.core.api.model.model.ModelId)10 ModelResource (org.eclipse.vorto.core.api.repository.ModelResource)4 IModelElement (org.eclipse.vorto.core.ui.model.IModelElement)4 IMenuListener (org.eclipse.jface.action.IMenuListener)3 IMenuManager (org.eclipse.jface.action.IMenuManager)3 MenuManager (org.eclipse.jface.action.MenuManager)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3 Menu (org.eclipse.swt.widgets.Menu)3 ProjectAction (org.eclipse.vorto.perspective.command.ProjectAction)3 MappingModelWizard (org.eclipse.vorto.wizard.mapping.MappingModelWizard)3 GridData (org.eclipse.swt.layout.GridData)2 PopulateGeneratorsMenu (org.eclipse.vorto.codegen.ui.handler.PopulateGeneratorsMenu)2 RepositoryException (org.eclipse.vorto.core.api.repository.RepositoryException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 TreeSet (java.util.TreeSet)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Table (org.eclipse.swt.widgets.Table)1