Search in sources :

Example 6 with ModelId

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

the class FunctionblockTreeViewer method initContextMenu.

protected void initContextMenu() {
    final MenuManager menuMgr = new MenuManager("#PopupMenuFb");
    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.Functionblock) {
                    MenuManager generatorMenuMgr = new MenuManager("Generate Code");
                    generatorMenuMgr.add(new PopulateGeneratorsMenu());
                    menuMgr.add(generatorMenuMgr);
                    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 Functionblock", ImageUtil.getImage("add_obj.gif"), treeViewer.getLocalModelWorkspace()) {

                @Override
                public void doAction() {
                    WizardDialog wizardDialog = new WizardDialog(treeViewer.getControl().getShell(), new FunctionBlockWizard(treeViewer.getLocalModelWorkspace().getProjectBrowser().getSelectedProject()));
                    if (wizardDialog.open() == Window.OK) {
                        populate(treeViewer.getLocalModelWorkspace().getProjectBrowser().getSelectedProject().getModelElementsByType(ModelType.Functionblock));
                    }
                }
            });
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    this.treeViewer.getControl().setMenu(menu);
}
Also used : MappingModelWizard(org.eclipse.vorto.wizard.mapping.MappingModelWizard) IModelElement(org.eclipse.vorto.core.ui.model.IModelElement) ProjectAction(org.eclipse.vorto.perspective.command.ProjectAction) FunctionBlockWizard(org.eclipse.vorto.wizard.functionblock.FunctionBlockWizard) PopulateGeneratorsMenu(org.eclipse.vorto.codegen.ui.handler.PopulateGeneratorsMenu) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) PopulateGeneratorsMenu(org.eclipse.vorto.codegen.ui.handler.PopulateGeneratorsMenu) 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)

Example 7 with ModelId

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

the class InfomodelTreeViewer method initContextMenu.

protected void initContextMenu() {
    final MenuManager menuMgr = new MenuManager("#PopupMenuIM");
    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.InformationModel) {
                    MenuManager generatorMenuMgr = new MenuManager("Generate Code");
                    generatorMenuMgr.add(new PopulateGeneratorsMenu());
                    menuMgr.add(generatorMenuMgr);
                    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 Information Model", ImageUtil.getImage("add_obj.gif"), treeViewer.getLocalModelWorkspace()) {

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

Example 8 with ModelId

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

the class CodeGenerationHelper method createEclipseProject.

public static void createEclipseProject(ModelId modelId, String serviceKey, IGenerationResult generatedResult) {
    byte[] generated = generatedResult.getContent();
    ICodeGeneratorTask<ModelId> task = null;
    String name = modelId.getName() + "_" + serviceKey + "_generated";
    boolean containsEclipseProject = false;
    boolean generateMaven = false;
    if (generatedResult.getFileName().endsWith(".zip")) {
        ZipContentExtractCodeGeneratorTask tmp = new ZipContentExtractCodeGeneratorTask(generated);
        tmp.preprocess();
        if (tmp.getEclipseProjectName() != null) {
            name = tmp.getEclipseProjectName();
            containsEclipseProject = true;
        } else {
            generateMaven = tmp.isMavenContent();
        }
        task = tmp;
    } else {
        task = new SingleFileContentCodeGeneratorTask(generatedResult.getFileName(), generated);
    }
    EclipseProjectGenerator<ModelId> generator = new EclipseProjectGenerator<>(name);
    generator.addTask(task);
    generator.generate(modelId, containsEclipseProject ? InvocationContext.simpleInvocationContext(Collections.singletonMap(EclipseProjectGenerator.SKIP_PROJECT_CONFIGURATION, Boolean.TRUE.toString())) : InvocationContext.simpleInvocationContext(), new NullProgressMonitor());
    if (generateMaven) {
        createMavenProjectFromGeneratedCode(generator);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SingleFileContentCodeGeneratorTask(org.eclipse.vorto.codegen.api.SingleFileContentCodeGeneratorTask) ZipContentExtractCodeGeneratorTask(org.eclipse.vorto.codegen.api.ZipContentExtractCodeGeneratorTask) EclipseProjectGenerator(org.eclipse.vorto.codegen.ui.tasks.EclipseProjectGenerator) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Example 9 with ModelId

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

Example 10 with ModelId

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

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