Commits

Sven Reimers committed c167792

Initial prototype for SceneBuilder navigation hierarchy in navigator panel

  • Participants
  • Parent commits 55ab11f

Comments (0)

Files changed (4)

File integration/nbproject/genfiles.properties

-build.xml.data.CRC32=74700754
+build.xml.data.CRC32=8407bc12
 build.xml.script.CRC32=28c26d1a
 build.xml.stylesheet.CRC32=a56c6a5b@2.65
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=74700754
+nbproject/build-impl.xml.data.CRC32=8407bc12
 nbproject/build-impl.xml.script.CRC32=bc45e77b
 nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.65

File integration/nbproject/project.xml

                     </run-dependency>
                 </dependency>
                 <dependency>
+                    <code-name-base>org.netbeans.modules.settings</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.43</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.spi.navigator</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.31</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     <code-name-base>org.openide.awt</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>

File integration/src/org/netbeans/scenebuilder/embedded/FxmlNavigator.java

+/*
+ * The MIT License
+ *
+ * Copyright 2013 Sven Reimers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package org.netbeans.scenebuilder.embedded;
+
+import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import com.oracle.javafx.scenebuilder.kit.editor.panel.hierarchy.HierarchyPanelController;
+import java.util.Optional;
+import javafx.application.Platform;
+import javafx.embed.swing.JFXPanel;
+import javafx.scene.Scene;
+import javafx.scene.layout.BorderPane;
+import javax.swing.JComponent;
+import org.netbeans.spi.navigator.NavigatorPanel;
+import org.openide.util.Lookup;
+import org.openide.util.LookupEvent;
+import org.openide.util.LookupListener;
+import org.openide.util.lookup.AbstractLookup;
+import org.openide.util.lookup.InstanceContent;
+
+/**
+ *
+ * @author sven
+ */
+@NavigatorPanel.Registration(displayName = "Hierarchy", mimeType = "text/scenebuilder")
+public class FxmlNavigator implements NavigatorPanel, LookupListener {
+
+    private JFXPanel panel = new JFXPanel();
+    private Lookup lkp;
+    private InstanceContent ic;
+    private Lookup.Result<EditorController> editorControllerResult;
+
+    public FxmlNavigator() {
+        ic = new InstanceContent();
+        lkp = new AbstractLookup(ic);
+    }
+
+    @Override
+    public String getDisplayName() {
+        return "Hierarchy";
+    }
+
+    @Override
+    public String getDisplayHint() {
+        return "Hierarchy Hint";
+    }
+
+    @Override
+    public JComponent getComponent() {
+        return panel;
+    }
+
+    @Override
+    public void panelActivated(Lookup lkp) {
+        editorControllerResult = lkp.lookupResult(EditorController.class);
+        editorControllerResult.addLookupListener(this);
+        resultChanged(new LookupEvent(editorControllerResult));
+    }
+
+    @Override
+    public void panelDeactivated() {
+    }
+
+    @Override
+    public Lookup getLookup() {
+        return lkp;
+    }
+
+    @Override
+    public void resultChanged(LookupEvent le) {
+        final Optional<? extends EditorController> optionalController = editorControllerResult.allInstances().stream().findFirst();
+        if (optionalController.isPresent()) {
+            Platform.runLater(new Runnable() {
+
+                @Override
+                public void run() {
+                    HierarchyPanelController h = new HierarchyPanelController(optionalController.get());
+                    final BorderPane pane = new BorderPane();
+                    pane.setCenter(h.getPanelRoot());
+                    Scene scene = new Scene(pane);
+                    panel.setScene(scene);
+                }
+            });
+        }
+    }
+
+}

File integration/src/org/netbeans/scenebuilder/embedded/SBFxmlMultiViewElement.java

 import org.netbeans.core.spi.multiview.CloseOperationState;
 import org.netbeans.core.spi.multiview.MultiViewElement;
 import org.netbeans.core.spi.multiview.MultiViewElementCallback;
+import org.netbeans.spi.navigator.NavigatorLookupHint;
 import org.openide.awt.UndoRedo;
 import org.openide.filesystems.FileUtil;
 import org.openide.loaders.DataObject;
+import org.openide.nodes.AbstractNode;
+import org.openide.nodes.ChildFactory;
+import org.openide.nodes.Children;
+import org.openide.nodes.Node;
 import org.openide.util.Exceptions;
 import org.openide.util.Lookup;
 import org.openide.util.NbBundle;
+import org.openide.util.lookup.AbstractLookup;
+import org.openide.util.lookup.InstanceContent;
+import org.openide.util.lookup.Lookups;
 import org.openide.windows.TopComponent;
 
 /**
 
     private MultiViewElementCallback callback;
     private DataObject dao;
+    private  EditorController editorController;
+    
+    private Lookup lkp;
+    private InstanceContent ic;
+    
+    private JFXPanel jfxPanel;
 
-    public SBFxmlMultiViewElement(Lookup lkp) {
-        dao = lkp.lookup(DataObject.class);
+    public SBFxmlMultiViewElement(Lookup lookup) {
+        Platform.setImplicitExit(false);
+        dao = lookup.lookup(DataObject.class);
         assert dao != null;
+        ic = new InstanceContent();
+        ic.add(new SBTypeLookupHint());
+        lkp = new AbstractLookup(ic);
     }
 
     @Override
     public JComponent getVisualRepresentation() {
-        final JFXPanel jfxPanel = new JFXPanel();
-        try {
-            final File fxmlFile = FileUtil.toFile(dao.getPrimaryFile());
-            final String fxmlText = readContentFromFile(fxmlFile);
-            final URL fxmlLocation = fxmlFile.toURI().toURL();
-            Platform.runLater(new Runnable() {
+        if (null == jfxPanel) {
+            jfxPanel = new JFXPanel();
+            try {
+                final File fxmlFile = FileUtil.toFile(dao.getPrimaryFile());
+                final String fxmlText = readContentFromFile(fxmlFile);
+                final URL fxmlLocation = fxmlFile.toURI().toURL();
+                Platform.runLater(new Runnable() {
 
-                @Override
-                public void run() {
-                    try {
-                        final EditorController editorController = new EditorController();
-                        ContentPanelController contentPanelController = new ContentPanelController(editorController);
-                        final BorderPane pane = new BorderPane();
-                        pane.setCenter(contentPanelController.getPanelRoot());
-                        Scene scene = new Scene(pane);
-                        jfxPanel.setScene(scene);
-                        editorController.setFxmlTextAndLocation(fxmlText, fxmlLocation);
-                    } catch (IOException ex) {
-                        Exceptions.printStackTrace(ex);
+                    @Override
+                    public void run() {
+                        try {
+                            editorController = new EditorController();
+                            Node node = new AbstractNode(Children.LEAF, Lookups.fixed(editorController));
+                            ic.add(node);
+                            ContentPanelController contentPanelController = new ContentPanelController(editorController);
+                            final BorderPane pane = new BorderPane();
+                            pane.setCenter(contentPanelController.getPanelRoot());
+                            Scene scene = new Scene(pane);
+                            jfxPanel.setScene(scene);
+                            editorController.setFxmlTextAndLocation(fxmlText, fxmlLocation);
+                        } catch (IOException ex) {
+                            Exceptions.printStackTrace(ex);
+                        }
                     }
-                }
-            });
+                });
 
 
-        } catch (IOException ex) {
-            Exceptions.printStackTrace(ex);
+            } catch (IOException ex) {
+                Exceptions.printStackTrace(ex);
+            }
         }
         return jfxPanel;
     }
 
     @Override
     public Lookup getLookup() {
-        return Lookup.EMPTY;
+        return lkp;
     }
 
     @Override
 
         return new String(buffer, Charset.forName("UTF-8"));
     }
+    
+    class SBTypeLookupHint implements NavigatorLookupHint {
+        public String getContentType () {
+            return "text/scenebuilder";
+        }
+    }    
 
 }