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;
}
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);
}
});
}
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;
}
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());
}
}
Aggregations