Search in sources :

Example 1 with FunctionBlockWizard

use of org.eclipse.vorto.wizard.functionblock.FunctionBlockWizard 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)

Aggregations

IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Menu (org.eclipse.swt.widgets.Menu)1 PopulateGeneratorsMenu (org.eclipse.vorto.codegen.ui.handler.PopulateGeneratorsMenu)1 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)1 IModelElement (org.eclipse.vorto.core.ui.model.IModelElement)1 ProjectAction (org.eclipse.vorto.perspective.command.ProjectAction)1 FunctionBlockWizard (org.eclipse.vorto.wizard.functionblock.FunctionBlockWizard)1 MappingModelWizard (org.eclipse.vorto.wizard.mapping.MappingModelWizard)1