Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2015-07-07 19:42:43 +0000
committerTom Schindl2015-07-07 19:42:43 +0000
commitdd93f11d91fdc6595c96464bc71406ada58c710b (patch)
treea2d7e2d0344198492331ac28e822531ee4293c43 /experimental
parent05dd56fe8c5e509eabe4ed2de21e07161ac29ca9 (diff)
downloadorg.eclipse.efxclipse-dd93f11d91fdc6595c96464bc71406ada58c710b.tar.gz
org.eclipse.efxclipse-dd93f11d91fdc6595c96464bc71406ada58c710b.tar.xz
org.eclipse.efxclipse-dd93f11d91fdc6595c96464bc71406ada58c710b.zip
add a default outline viewer
Diffstat (limited to 'experimental')
-rw-r--r--experimental/compensator/org.eclipse.fx.code.compensator.editor/src/org/eclipse/fx/code/compensator/editor/FileOutlineViewer.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor/src/org/eclipse/fx/code/compensator/editor/FileOutlineViewer.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor/src/org/eclipse/fx/code/compensator/editor/FileOutlineViewer.java
new file mode 100644
index 000000000..322f978aa
--- /dev/null
+++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor/src/org/eclipse/fx/code/compensator/editor/FileOutlineViewer.java
@@ -0,0 +1,101 @@
+package org.eclipse.fx.code.compensator.editor;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.fx.code.compensator.editor.Outline.OutlineItem;
+import org.eclipse.fx.core.URI;
+import org.eclipse.fx.ui.controls.tree.SimpleTreeCell;
+import org.eclipse.fx.ui.services.resources.GraphicsLoader;
+
+import javafx.collections.ListChangeListener.Change;
+import javafx.scene.control.Label;
+import javafx.scene.control.TreeCell;
+import javafx.scene.control.TreeItem;
+import javafx.scene.control.TreeView;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.HBox;
+
+public class FileOutlineViewer {
+ private final GraphicsLoader nodeProvider;
+ private Map<Outline, TreeView<OutlineItem>> treeCache = new WeakHashMap<>();
+
+ private final BorderPane container;
+
+ @Inject
+ public FileOutlineViewer(BorderPane container, GraphicsLoader nodeProvider) {
+ this.container = container;
+ this.nodeProvider = nodeProvider;
+ }
+
+ @PostConstruct
+ public void initUI() {
+ HBox b = new HBox();
+ b.getStyleClass().add("tool-bar");
+ b.getChildren().add(new Label("Outline", nodeProvider.getGraphicsNode(URI.createPlatformPluginURI("org.eclipse.fx.code.compensator.editor","css/icons/16/outline_co.png"))));
+ container.setTop(b);
+ }
+
+ private TreeView<OutlineItem> createView() {
+ TreeView<OutlineItem> outlineView = new TreeView<>();
+ outlineView.setShowRoot(false);
+ outlineView.setCellFactory(this::createCell);
+ return outlineView;
+ }
+
+ TreeCell<OutlineItem> createCell(TreeView<OutlineItem> param) {
+ return new SimpleTreeCell<OutlineItem>(i -> i.getLabel(), i -> i.getGraphic(), i -> Collections.emptyList());
+ }
+
+ @Inject
+ void updateInput(@Optional @Named("activeOutline") Outline outline) {
+ if( outline != null ) {
+ TreeView<OutlineItem> view = treeCache.get(outline);
+
+ if( view == null ) {
+ view = createView();
+ TreeItem<OutlineItem> root = new TreeItem<>();
+ for( OutlineItem l : outline.getRootItems() ) {
+ root.getChildren().add(createRec(l));
+ }
+
+ outline.getRootItems().addListener( (Change<? extends OutlineItem> c) -> {
+ while( c.next() ) {
+ if( c.wasAdded() ) {
+ root.getChildren().addAll(
+ c.getAddedSubList().stream()
+ .map(this::createRec)
+ .collect(Collectors.toList()));
+ }
+
+ if( c.wasRemoved() ) {
+ root.getChildren().removeIf( t -> c.getRemoved().contains(t.getValue()));
+ }
+ }
+ });
+ view.setRoot(root);
+ treeCache.put(outline, view);
+ }
+
+ container.setCenter(view);
+ } else {
+ container.setCenter(null);
+ }
+ }
+
+ TreeItem<OutlineItem> createRec(OutlineItem i) {
+ TreeItem<OutlineItem> l = new TreeItem<Outline.OutlineItem>(i);
+ for( OutlineItem c : i.getChildren() ) {
+ l.getChildren().add(createRec(c));
+ }
+
+ return l;
+ }
+}

Back to the top