5e08a55a407958d12c0b1b542307074e018559c2
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / modulebrowser / SCLModuleBrowser.java
1 package org.simantics.scl.ui.modulebrowser;
2
3 import org.eclipse.jface.action.Action;
4 import org.eclipse.jface.action.IToolBarManager;
5 import org.eclipse.jface.viewers.DoubleClickEvent;
6 import org.eclipse.jface.viewers.IDoubleClickListener;
7 import org.eclipse.jface.viewers.ISelection;
8 import org.eclipse.jface.viewers.IStructuredSelection;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.widgets.Composite;
11 import org.eclipse.ui.part.ViewPart;
12 import org.simantics.scl.osgi.SCLOsgi;
13 import org.simantics.scl.ui.Activator;
14 import org.simantics.scl.ui.editor2.OpenSCLModule;
15
16 public class SCLModuleBrowser extends ViewPart {
17
18     SCLModuleTree content;
19     
20     @Override
21     public void createPartControl(Composite parent) {
22         this.content = new SCLModuleTree(parent, SWT.NONE, SCLOsgi.MODULE_REPOSITORY);
23         setPartName("SCL Modules");
24         content.addDoubleClickListener(new IDoubleClickListener() {
25             @Override
26             public void doubleClick(DoubleClickEvent event) {
27                 ISelection selection = event.getSelection();
28                 if(!(selection instanceof IStructuredSelection))
29                     return;
30                 ModuleNameTreeEntry entry = (ModuleNameTreeEntry)((IStructuredSelection)selection).getFirstElement();
31                 if(entry.isModule)
32                     OpenSCLModule.openModule(entry.fullName);
33             }
34         });
35         
36         IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
37         toolBarManager.add(new Action("Refresh modules",
38                 Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/arrow_refresh.png")) {
39             @Override
40             public void run() {
41                 SCLOsgi.MODULE_REPOSITORY.getSourceRepository().checkUpdates();
42                 content.recalculateInput();
43             }
44         });
45     }
46
47     @Override
48     public void setFocus() {
49         content.getControl().setFocus();
50     }
51
52 }