(refs #7362) Creation of new SCL modules in SCL module browser
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / modulebrowser / SCLModuleBrowser.java
index 5e08a55a407958d12c0b1b542307074e018559c2..b175a3e600c14cc69db9c7e1a8e6ea23de1b6048 100644 (file)
@@ -1,13 +1,17 @@
 package org.simantics.scl.ui.modulebrowser;
 
 import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
 import org.eclipse.ui.part.ViewPart;
 import org.simantics.scl.osgi.SCLOsgi;
 import org.simantics.scl.ui.Activator;
@@ -21,6 +25,8 @@ public class SCLModuleBrowser extends ViewPart {
     public void createPartControl(Composite parent) {
         this.content = new SCLModuleTree(parent, SWT.NONE, SCLOsgi.MODULE_REPOSITORY);
         setPartName("SCL Modules");
+        
+        // Opening modules
         content.addDoubleClickListener(new IDoubleClickListener() {
             @Override
             public void doubleClick(DoubleClickEvent event) {
@@ -33,15 +39,41 @@ public class SCLModuleBrowser extends ViewPart {
             }
         });
         
+        // Toolbar
         IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
         toolBarManager.add(new Action("Refresh modules",
                 Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/arrow_refresh.png")) {
             @Override
             public void run() {
-                SCLOsgi.MODULE_REPOSITORY.getSourceRepository().checkUpdates();
-                content.recalculateInput();
+                refresh();
+            }
+        });
+        
+        // Context menu
+        MenuManager menuMgr = new MenuManager();
+        menuMgr.setRemoveAllWhenShown(true);
+        menuMgr.addMenuListener(new IMenuListener() {
+            public void menuAboutToShow(IMenuManager manager) {
+                ModuleNameTreeEntry entry = (ModuleNameTreeEntry)content.getStructuredSelection().getFirstElement();
+                if(!entry.isModule)
+                    manager.add(new Action("New Module...") {
+                        @Override
+                        public void run() {
+                            CreateModuleDialog dialog = new CreateModuleDialog(content.getControl().getShell(), SCLModuleBrowser.this);
+                            dialog.setPackage(entry.fullName);
+                            dialog.open();
+                        }
+                    });
             }
         });
+        Menu menu = menuMgr.createContextMenu(content.getControl());
+        content.getControl().setMenu(menu);
+        getSite().registerContextMenu(menuMgr, content);
+    }
+    
+    public void refresh() {
+        SCLOsgi.MODULE_REPOSITORY.getSourceRepository().checkUpdates();
+        content.recalculateInput();
     }
 
     @Override