From 0b1f301a6a42beea2716b3268a402db125b927eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Wed, 24 May 2017 11:50:15 +0300 Subject: [PATCH] (refs #7242) First version of SCL Development perspective Change-Id: Ica1a3d93c05e11ccee2cab3c0cf517cbe332106a --- bundles/org.simantics.scl.ui/plugin.xml | 47 ++++++++++++- .../ui/modulebrowser/ModuleNameTreeEntry.java | 62 +++++++++++++++++ .../ui/modulebrowser/SCLModuleBrowser.java | 39 +++++++++++ .../scl/ui/modulebrowser/SCLModuleTree.java | 68 +++++++++++++++++++ .../ui/perspective/SCLPerspectiveFactory.java | 12 ++++ 5 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java create mode 100644 bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java create mode 100644 bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleTree.java create mode 100644 bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/perspective/SCLPerspectiveFactory.java diff --git a/bundles/org.simantics.scl.ui/plugin.xml b/bundles/org.simantics.scl.ui/plugin.xml index 293778230..dd1539c46 100644 --- a/bundles/org.simantics.scl.ui/plugin.xml +++ b/bundles/org.simantics.scl.ui/plugin.xml @@ -55,7 +55,7 @@ restorable="true"> + + @@ -171,5 +180,41 @@ id="org.simantics.scl.ui.editor.inputFactory"> + + + + + + + + + + + + + + diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java new file mode 100644 index 000000000..6f657b351 --- /dev/null +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java @@ -0,0 +1,62 @@ +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 { + public final ModuleNameTreeEntry parent; + public final String fullName; + public final String name; + public final THashMap childMap = new THashMap(); + 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 children() { + ArrayList children = new ArrayList(childMap.values()); + Collections.sort(children); + return children; + } + + @Override + public int compareTo(ModuleNameTreeEntry o) { + return name.compareTo(o.name); + } + + @Override + public String toString() { + return name; + } +} diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java new file mode 100644 index 000000000..379a446f9 --- /dev/null +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java @@ -0,0 +1,39 @@ +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(); + } + +} diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleTree.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleTree.java new file mode 100644 index 000000000..43e6781d4 --- /dev/null +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleTree.java @@ -0,0 +1,68 @@ +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)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 names) { + ModuleNameTreeEntry root = new ModuleNameTreeEntry(null, "", ""); + for(String name : names) + root.addModule(name); + return root; + } + +} diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/perspective/SCLPerspectiveFactory.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/perspective/SCLPerspectiveFactory.java new file mode 100644 index 000000000..4591d53c1 --- /dev/null +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/perspective/SCLPerspectiveFactory.java @@ -0,0 +1,12 @@ +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) { + } + +} -- 2.47.1