restorable="true">
</view>
<view
- allowMultiple="true"
+ allowMultiple="false"
category="org.simantics.scl.ui.category"
class="org.simantics.scl.ui.issues.SCLIssuesView"
icon="icons/error.png"
name="SCL Issues"
restorable="true">
</view>
+ <view
+ allowMultiple="false"
+ category="org.simantics.scl.ui.category"
+ class="org.simantics.scl.ui.modulebrowser.SCLModuleBrowser"
+ icon="icons/lambda.png"
+ id="org.simantics.scl.ui.modulebrowser"
+ name="SCL Module Browser"
+ restorable="true">
+ </view>
</extension>
<extension
point="org.eclipse.ui.menus">
id="org.simantics.scl.ui.editor.inputFactory">
</factory>
</extension>
+ <extension
+ point="org.eclipse.ui.perspectives">
+ <perspective
+ class="org.simantics.scl.ui.perspective.SCLPerspectiveFactory"
+ icon="icons/lambda.png"
+ id="org.simantics.scl.ui.perspective"
+ name="SCL Development Perspective">
+ </perspective>
+ </extension>
+ <extension
+ point="org.eclipse.ui.perspectiveExtensions">
+ <perspectiveExtension
+ targetID="org.simantics.scl.ui.perspective">
+ <view
+ id="org.simantics.scl.ui.modulebrowser"
+ minimized="false"
+ ratio="0.2"
+ relationship="left"
+ relative="org.eclipse.ui.editorss">
+ </view>
+ <view
+ id="org.simantics.scl.ui.console"
+ minimized="false"
+ ratio="0.8"
+ relationship="bottom"
+ relative="org.eclipse.ui.editorss">
+ </view>
+ <view
+ id="org.simantics.scl.ui.issues"
+ minimized="false"
+ ratio="0.8"
+ relationship="bottom"
+ relative="org.simantics.scl.ui.modulebrowser">
+ </view>
+ </perspectiveExtension>
+ </extension>
</plugin>
--- /dev/null
+package org.simantics.scl.ui.modulebrowser;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import gnu.trove.map.hash.THashMap;
+
+public class ModuleNameTreeEntry implements Comparable<ModuleNameTreeEntry> {
+ public final ModuleNameTreeEntry parent;
+ public final String fullName;
+ public final String name;
+ public final THashMap<String, ModuleNameTreeEntry> childMap = new THashMap<String, ModuleNameTreeEntry>();
+ public boolean isModule;
+
+ public ModuleNameTreeEntry(ModuleNameTreeEntry parent, String fullName, String name) {
+ this.parent = parent;
+ this.fullName = fullName;
+ this.name = name;
+ }
+
+ public void addModule(String moduleFullName) {
+ int startingPos = fullName.isEmpty() ? 0 : fullName.length()+1;
+ int p = moduleFullName.indexOf('/', startingPos);
+ if(p == -1) {
+ String name = moduleFullName.substring(startingPos);
+ ModuleNameTreeEntry entry = getOrCreateChildMapEntry(name);
+ entry.isModule = true;
+ }
+ else {
+ String name = moduleFullName.substring(startingPos, p);
+ ModuleNameTreeEntry entry = getOrCreateChildMapEntry(name);
+ entry.addModule(moduleFullName);
+ }
+ }
+
+ private ModuleNameTreeEntry getOrCreateChildMapEntry(String name) {
+ ModuleNameTreeEntry entry = childMap.get(name);
+ if(entry == null) {
+ String newFullName = fullName.isEmpty() ? name : fullName + "/" + name;
+ entry = new ModuleNameTreeEntry(this, newFullName, name);
+ childMap.put(name, entry);
+ }
+ return entry;
+ }
+
+ public Collection<ModuleNameTreeEntry> children() {
+ ArrayList<ModuleNameTreeEntry> children = new ArrayList<ModuleNameTreeEntry>(childMap.values());
+ Collections.sort(children);
+ return children;
+ }
+
+ @Override
+ public int compareTo(ModuleNameTreeEntry o) {
+ return name.compareTo(o.name);
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+}
--- /dev/null
+package org.simantics.scl.ui.modulebrowser;
+
+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.ui.part.ViewPart;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.ui.editor2.OpenSCLModule;
+
+public class SCLModuleBrowser extends ViewPart {
+
+ SCLModuleTree content;
+
+ @Override
+ public void createPartControl(Composite parent) {
+ this.content = new SCLModuleTree(parent, SWT.NONE, SCLOsgi.MODULE_REPOSITORY);
+ setPartName("SCL Modules");
+ content.addDoubleClickListener(new IDoubleClickListener() {
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ ISelection selection = event.getSelection();
+ if(!(selection instanceof IStructuredSelection))
+ return;
+ ModuleNameTreeEntry entry = (ModuleNameTreeEntry)((IStructuredSelection)selection).getFirstElement();
+ if(entry.isModule)
+ OpenSCLModule.openModule(entry.fullName);
+ }
+ });
+ }
+
+ @Override
+ public void setFocus() {
+ content.getControl().setFocus();
+ }
+
+}
--- /dev/null
+package org.simantics.scl.ui.modulebrowser;
+
+import java.util.Collection;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Composite;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
+
+public class SCLModuleTree extends TreeViewer {
+
+ private final ModuleRepository repository;
+
+
+ private ITreeContentProvider contentProvider = new ITreeContentProvider() {
+ ModuleNameTreeEntry rootEntry;
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ this.rootEntry = createModuleTreeEntry((Collection<String>)newInput);
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return rootEntry.children().toArray();
+ }
+
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ return ((ModuleNameTreeEntry)parentElement).children().toArray();
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ return ((ModuleNameTreeEntry)element).parent;
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ return !((ModuleNameTreeEntry)element).childMap.isEmpty();
+ }
+ };
+
+ private LabelProvider labelProvider = new LabelProvider();
+
+ public SCLModuleTree(Composite parent, int style, ModuleRepository repository) {
+ super(parent, style);
+ this.repository = repository;
+ setLabelProvider(labelProvider);
+ setContentProvider(contentProvider);
+ setAutoExpandLevel(1);
+ setInput(repository.getSourceRepository().getModuleNames());
+ }
+
+ private static ModuleNameTreeEntry createModuleTreeEntry(Collection<String> names) {
+ ModuleNameTreeEntry root = new ModuleNameTreeEntry(null, "", "");
+ for(String name : names)
+ root.addModule(name);
+ return root;
+ }
+
+}
--- /dev/null
+package org.simantics.scl.ui.perspective;
+
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+public class SCLPerspectiveFactory implements IPerspectiveFactory {
+
+ @Override
+ public void createInitialLayout(IPageLayout layout) {
+ }
+
+}