Search in sources :

Example 1 with IModelElement

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

the class ModelDropListener method performDrop.

@SuppressWarnings("unchecked")
public boolean performDrop(Object data) {
    Object target = getTarget();
    if (data instanceof IStructuredSelection) {
        Object droppedResource = ((IStructuredSelection) data).getFirstElement();
        IModelElement result = null;
        for (DropSourceValidatorAndAction dropActor : dropActors) {
            if (dropActor.validator.allow(target, droppedResource)) {
                result = dropActor.action.performDrop(target, droppedResource);
                break;
            }
        }
        if (target != null) {
            ModelProjectTreeViewer viewer = (ModelProjectTreeViewer) this.getViewer();
            viewer.getLocalModelWorkspace().refreshCurrent();
            if (target instanceof IModelElement) {
                IModelElement targetModelElement = findTarget((IModelElement) target, (Collection<IModelElement>) viewer.getInput());
                if (targetModelElement != null) {
                    viewer.expandToLevel(targetModelElement, 1);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : IModelElement(org.eclipse.vorto.core.ui.model.IModelElement) ModelProjectTreeViewer(org.eclipse.vorto.perspective.view.ModelProjectTreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with IModelElement

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

the class ShareModelAction method run.

@Override
public void run() {
    IModelElement modelElement = getSelectedElement();
    try {
        UploadResult uploadResult = modelRepo.upload(modelElement.getModelFile().getName(), ByteStreams.toByteArray(modelElement.getModelFile().getContents()));
        ModelUploadDialog uploadDialog = new ModelUploadDialog(getViewer().getControl().getShell(), uploadResult);
        uploadDialog.create();
        int result = uploadDialog.open();
        if (uploadResult.statusOk() && result == Window.OK) {
            modelRepo.commit(uploadResult.getHandleId());
            MessageDisplayFactory.getMessageDisplay().displaySuccess("Model " + modelElement.getModelFile().getName() + " saved to repository.");
        }
    } catch (Exception e) {
        ExceptionHandlerFactory.getHandler().handle(e);
    }
}
Also used : IModelElement(org.eclipse.vorto.core.ui.model.IModelElement) ModelUploadDialog(org.eclipse.vorto.perspective.view.ModelUploadDialog) UploadResult(org.eclipse.vorto.core.api.repository.UploadResult)

Example 3 with IModelElement

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

Example 4 with IModelElement

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

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

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