Search in sources :

Example 6 with IModelElement

use of org.eclipse.vorto.core.ui.model.IModelElement in project vorto by eclipse.

the class CodeGeneratorInvocationHandler method evaluate.

private boolean evaluate(String generatorServiceKey) {
    IModelElement selectedElement = ModelProjectFactory.getInstance().getModelElementFromSelection();
    if (selectedElement == null) {
        selectedElement = ModelProjectFactory.getInstance().getSelectedModel();
    }
    if (selectedElement == null) {
        MessageDisplayFactory.getMessageDisplay().displayWarning("Model was not properly selected. Please try again.");
        return false;
    }
    if (!hasNoErrors(selectedElement)) {
        MessageDisplayFactory.getMessageDisplay().displayError("Model has errors. Cannot generate.");
        return false;
    }
    InformationModel informationModel = getInformationModel(selectedElement.getModel());
    try {
        IVortoCodeGenerator generator = lookupService.lookupByKey(generatorServiceKey);
        IGenerationResult result = generator.generate(informationModel, createInvocationContext(selectedElement.getProject(), generator.getServiceKey()), VortoCodeGenProgressMonitorFactory.getCodeGenStatusReporter());
        CodeGenerationHelper.createEclipseProject(ModelIdFactory.newInstance(informationModel), generator.getServiceKey(), result);
        VortoProgressMonitor.getDefault().display();
    } catch (Exception e) {
        MessageDisplayFactory.getMessageDisplay().displayError(e);
    }
    return true;
}
Also used : IModelElement(org.eclipse.vorto.core.ui.model.IModelElement) IVortoCodeGenerator(org.eclipse.vorto.codegen.api.IVortoCodeGenerator) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IGenerationResult(org.eclipse.vorto.codegen.api.IGenerationResult) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 7 with IModelElement

use of org.eclipse.vorto.core.ui.model.IModelElement in project vorto by eclipse.

the class ModelTreeViewer method init.

protected void init() {
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection().isEmpty()) {
                return;
            }
            if (event.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                if (selection.size() > 0) {
                    if (selection.getFirstElement() instanceof IModelElement) {
                        IModelElement modelElement = (IModelElement) selection.getFirstElement();
                        if (modelElement.getModelFile() != null) {
                            ModelProjectFactory.getInstance().setSelectedModel(modelElement);
                            openFileInEditor(modelElement.getModelFile());
                        }
                    }
                }
            }
        }
    });
    treeViewer.getControl().addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
        }

        @Override
        public void focusGained(FocusEvent e) {
            localModelWorkspace.setFocus(treeViewer);
        }
    });
}
Also used : IModelElement(org.eclipse.vorto.core.ui.model.IModelElement) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 8 with IModelElement

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

Example 9 with IModelElement

use of org.eclipse.vorto.core.ui.model.IModelElement in project vorto by eclipse.

the class DeleteModelAction method run.

@Override
public void run() {
    IModelElement modelElement = getSelectedElement();
    final boolean isOKOrYes = MessageDialog.open(MessageDialog.QUESTION, getViewer().getControl().getShell(), "Delete Model", "Are you sure you want to delete the model " + modelElement.getId().getName() + " ?", SWT.NONE);
    if (isOKOrYes) {
        deleteResource(getViewer().getControl().getShell(), modelElement.getModelFile());
    }
}
Also used : IModelElement(org.eclipse.vorto.core.ui.model.IModelElement)

Aggregations

IModelElement (org.eclipse.vorto.core.ui.model.IModelElement)9 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)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 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 PopulateGeneratorsMenu (org.eclipse.vorto.codegen.ui.handler.PopulateGeneratorsMenu)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 IGenerationResult (org.eclipse.vorto.codegen.api.IGenerationResult)1 IVortoCodeGenerator (org.eclipse.vorto.codegen.api.IVortoCodeGenerator)1 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)1 ModelResource (org.eclipse.vorto.core.api.repository.ModelResource)1