]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7242) First version of SCL Development perspective 44/544/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 24 May 2017 08:50:15 +0000 (11:50 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 24 May 2017 09:46:24 +0000 (12:46 +0300)
Change-Id: Ica1a3d93c05e11ccee2cab3c0cf517cbe332106a

bundles/org.simantics.scl.ui/plugin.xml
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java [new file with mode: 0644]
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java [new file with mode: 0644]
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleTree.java [new file with mode: 0644]
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/perspective/SCLPerspectiveFactory.java [new file with mode: 0644]

index 293778230d58fbf9440f6ce170050cbc28efccd5..dd1539c4627e7df2e0601c5480af4731db60e886 100644 (file)
@@ -55,7 +55,7 @@
             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>
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 (file)
index 0000000..6f657b3
--- /dev/null
@@ -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<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;
+    }
+}
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 (file)
index 0000000..379a446
--- /dev/null
@@ -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 (file)
index 0000000..43e6781
--- /dev/null
@@ -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<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;
+    }
+
+}
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 (file)
index 0000000..4591d53
--- /dev/null
@@ -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) {
+    }
+
+}