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