瀏覽代碼

UndoSupport, now the editor will reload the gui only if file is changed and some property editors. Also xml auto completition and XmlNavigator

relu91 11 年之前
父節點
當前提交
ba848391dd

二進制
sdk/jme3-gui/release/modules/ext/Nifty-Editor0.5.9.jar


+ 9 - 9
sdk/jme3-gui/src/com/jme3/gde/gui/EmptyNiftyGui.xml

@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
-  <!-- +++++++++++++++++++++++++++++++++++++++ -->
-  <!-- start screen -->
-  <!-- +++++++++++++++++++++++++++++++++++++++ -->
-  <screen id="GScreen0" controller="mygame.Main">
-    <layer id="GLayer0" childLayout="absolute">
-    </layer>
-  </screen>
+<?xml version="1.0" encoding="UTF-8"?>
+<nifty xmlns="http://nifty-gui.lessvoid.com/nifty-gui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd">
+  <!-- +++++++++++++++++++++++++++++++++++++++ -->
+  <!-- start screen -->
+  <!-- +++++++++++++++++++++++++++++++++++++++ -->
+  <screen id="GScreen0" controller="mygame.Main">
+    <layer id="GLayer0" childLayout="absolute">
+    </layer>
+  </screen>
 </nifty>

+ 202 - 191
sdk/jme3-gui/src/com/jme3/gde/gui/Navigator.java

@@ -1,191 +1,202 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.jme3.gde.gui;
-
-import com.jme3.gde.gui.nodes.GElementNode;
-import com.jme3.gde.gui.nodes.ScreenChildFactory;
-import jada.ngeditor.controller.GUIEditor;
-import jada.ngeditor.model.elements.GElement;
-import java.awt.BorderLayout;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyVetoException;
-import java.util.ArrayList;
-import java.util.Observable;
-import java.util.Observer;
-import javax.swing.JComponent;
-import org.netbeans.spi.navigator.NavigatorPanel;
-import org.openide.explorer.ExplorerManager;
-import org.openide.explorer.ExplorerUtils;
-import org.openide.explorer.view.BeanTreeView;
-import org.openide.nodes.AbstractNode;
-import org.openide.nodes.Children;
-import org.openide.nodes.Node;
-import org.openide.util.Exceptions;
-import org.openide.util.Lookup;
-import org.openide.util.LookupEvent;
-import org.openide.util.LookupListener;
-import org.openide.util.Utilities;
-import org.openide.util.lookup.ProxyLookup;
-import org.openide.windows.TopComponent;
-
-/**
- *
- * @author cris
- */
[email protected](mimeType = "text/x-niftygui+xml", displayName="Gui View")
-public class Navigator extends javax.swing.JPanel implements NavigatorPanel,ExplorerManager.Provider , Observer, PropertyChangeListener, LookupListener{
-    private Lookup lookup;
-    private  ExplorerManager mgr = new ExplorerManager();
-    private final BeanTreeView beanTreeView;
-    private GUIEditor editor;
-    private Lookup context;
-    private boolean lock;
-    /**
-     * Creates new form Navigator
-     */
-    public Navigator() {
-        initComponents();
-        setLayout(new BorderLayout());
-        beanTreeView = new BeanTreeView();
-        add(beanTreeView, BorderLayout.CENTER);
-        
-    }
-
-    /**
-     * This method is called from within the constructor to initialize the form.
-     * WARNING: Do NOT modify this code. The content of this method is always
-     * regenerated by the Form Editor.
-     */
-    @SuppressWarnings("unchecked")
-    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
-    private void initComponents() {
-
-        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
-        this.setLayout(layout);
-        layout.setHorizontalGroup(
-            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGap(0, 244, Short.MAX_VALUE)
-        );
-        layout.setVerticalGroup(
-            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGap(0, 274, Short.MAX_VALUE)
-        );
-    }// </editor-fold>//GEN-END:initComponents
-    // Variables declaration - do not modify//GEN-BEGIN:variables
-    // End of variables declaration//GEN-END:variables
-
-    @Override
-    public String getDisplayName() {
-       return "GuiView";
-    }
-
-    @Override
-    public String getDisplayHint() {
-       return "Easy view for your gui";
-    }
-
-    @Override
-    public JComponent getComponent() {
-       return this;
-    }
-
-    @Override
-    public void panelActivated(Lookup context) {
-        try {
-            this.context = context;
-            context.lookupResult(NiftyGuiDataObject.class).addLookupListener(this);
-            intNavigator(context);
-        } catch (PropertyVetoException ex) {
-            Exceptions.printStackTrace(ex);
-        }
-    }
-
-    @Override
-    public void panelDeactivated() {
-        ExplorerUtils.activateActions(mgr, false);
-    }
-
-    @Override
-    public Lookup getLookup() {
-       return lookup;
-    }
-
-    @Override
-    public ExplorerManager getExplorerManager() {
-        return mgr;
-    }
-
-    @Override
-    public void update(Observable o, Object arg) {
-        
-        jada.ngeditor.listeners.actions.Action act = ( jada.ngeditor.listeners.actions.Action) arg;
-       if(act.getType() == jada.ngeditor.listeners.actions.Action.SEL){
-           ArrayList<String> path = new ArrayList<String>();
-           GElement parent = act.getGUIElement();
-           while(parent!=null){
-               path.add(parent.getID());
-               parent = parent.getParent();
-           }
-           Node result = mgr.getRootContext();
-           for(int i=path.size()-1;i>=0;i--){
-               result = result.getChildren().findChild(path.get(i));
-           }
-            try {
-                mgr.setSelectedNodes(new Node[]{result});
-            } catch (PropertyVetoException ex) {
-                Exceptions.printStackTrace(ex);
-            }
-       }else  if(act.getType() == jada.ngeditor.listeners.actions.Action.NEW){
-            try {
-                this.intNavigator(context);
-            } catch (PropertyVetoException ex) {
-                Exceptions.printStackTrace(ex);
-            }
-       }
-        beanTreeView.updateUI();
-    }
-
-    @Override
-    public void propertyChange(PropertyChangeEvent evt) {
-        if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
-            Node[] newValue = (Node[]) evt.getNewValue();
-            if (newValue.length > 0) {
-                AbstractNode firstSelected = (AbstractNode) newValue[0];
-                if (firstSelected instanceof GElementNode) {
-                    GElement element = ((GElementNode) firstSelected).getGelement();
-                    
-                    editor.selectElement(element);
-                    
-                }
-            }
-        }
-    }
-
-    @Override
-    public void resultChanged(LookupEvent ev) {
-        try {
-            intNavigator(context);
-        } catch (PropertyVetoException ex) {
-            Exceptions.printStackTrace(ex);
-        }
-    }
-
-    private void intNavigator(Lookup context) throws PropertyVetoException {
-        
-        NiftyGuiDataObject man = context.lookup(NiftyGuiDataObject.class);
-        ExplorerUtils.activateActions(mgr, true);
-        editor = man.getLookup().lookup(GUIEditor.class);
-        AbstractNode guiRoot = new AbstractNode(Children.create(new ScreenChildFactory(editor.getGui()), true));
-        guiRoot.setName("Gui");
-        this.mgr.setRootContext(guiRoot);
-        this.beanTreeView.updateUI();
-        mgr.addPropertyChangeListener(this);
-        this.mgr.setSelectedNodes(new Node[]{guiRoot});
-        Lookup lookup1 = ExplorerUtils.createLookup(mgr, getActionMap());
-        lookup = new ProxyLookup(lookup1);
-        editor.addObserver(this);
-    }
-}
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.jme3.gde.gui;
+
+import com.jme3.gde.gui.nodes.GElementNode;
+import com.jme3.gde.gui.nodes.GUINode;
+import com.jme3.gde.gui.nodes.ScreenChildFactory;
+import jada.ngeditor.controller.CommandProcessor;
+import jada.ngeditor.controller.GUIEditor;
+import jada.ngeditor.controller.commands.SelectCommand;
+import jada.ngeditor.listeners.events.ReloadGuiEvent;
+import jada.ngeditor.listeners.events.SelectionChanged;
+import jada.ngeditor.model.GUI;
+import jada.ngeditor.model.GuiEditorModel;
+import jada.ngeditor.model.elements.GElement;
+import java.awt.BorderLayout;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyVetoException;
+import java.util.ArrayList;
+import java.util.Observable;
+import java.util.Observer;
+import javax.swing.JComponent;
+import org.netbeans.spi.navigator.NavigatorPanel;
+import org.openide.explorer.ExplorerManager;
+import org.openide.explorer.ExplorerUtils;
+import org.openide.explorer.view.BeanTreeView;
+import org.openide.nodes.AbstractNode;
+import org.openide.nodes.Children;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.util.LookupEvent;
+import org.openide.util.LookupListener;
+import org.openide.util.Utilities;
+import org.openide.util.lookup.ProxyLookup;
+import org.openide.windows.TopComponent;
+
+/**
+ *
+ * @author cris
+ */
[email protected](mimeType = "text/x-niftygui+xml", displayName="Gui View")
+public class Navigator extends javax.swing.JPanel implements NavigatorPanel,ExplorerManager.Provider , Observer, PropertyChangeListener{
+    private Lookup lookup;
+    private  ExplorerManager mgr = new ExplorerManager();
+    private final BeanTreeView beanTreeView;
+    private GUIEditor editor;
+    private Lookup context;
+    private boolean lock;
+    /**
+     * Creates new form Navigator
+     */
+    public Navigator() {
+        initComponents();
+        setLayout(new BorderLayout());
+        beanTreeView = new BeanTreeView();
+        add(beanTreeView, BorderLayout.CENTER);
+        CommandProcessor.getInstance().getObservable().addObserver(this);
+        
+    }
+
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    @SuppressWarnings("unchecked")
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+        this.setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGap(0, 244, Short.MAX_VALUE)
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGap(0, 274, Short.MAX_VALUE)
+        );
+    }// </editor-fold>//GEN-END:initComponents
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    // End of variables declaration//GEN-END:variables
+
+    @Override
+    public String getDisplayName() {
+       return "GuiView";
+    }
+
+    @Override
+    public String getDisplayHint() {
+       return "Easy view for your gui";
+    }
+
+    @Override
+    public JComponent getComponent() {
+       return this;
+    }
+
+    @Override
+    public void panelActivated(Lookup context) {
+        
+    }
+
+    @Override
+    public void panelDeactivated() {
+        ExplorerUtils.activateActions(mgr, false);
+    }
+
+    @Override
+    public Lookup getLookup() {
+       return lookup;
+    }
+
+    @Override
+    public ExplorerManager getExplorerManager() {
+        return mgr;
+    }
+
+    @Override
+    public void update(Observable o, Object arg) {
+       if(o instanceof GuiEditorModel){
+           try {
+               GuiEditorModel model = (GuiEditorModel) o;
+               model.getCurrent().addObserver(this);
+               model.getCurrent().getSelection().addObserver(this);
+               this.intNavigator(model.getCurrent());
+           } catch (PropertyVetoException ex) {
+               Exceptions.printStackTrace(ex);
+           }
+       }
+       
+       if(arg instanceof SelectionChanged){
+           SelectionChanged event = (SelectionChanged) arg;
+           if(event.getNewSelection().isEmpty()){
+               return;
+           }
+           ArrayList<String> path = new ArrayList<String>();
+           GElement parent = ((SelectionChanged)arg).getElement();
+           while(parent!=null){
+               path.add(parent.getID());
+               parent = parent.getParent();
+           }
+           Node result = mgr.getRootContext();
+           for(int i=path.size()-1;i>=0;i--){
+               result = result.getChildren().findChild(path.get(i));
+           }
+            try {
+                mgr.setSelectedNodes(new Node[]{result});
+            } catch (PropertyVetoException ex) {
+                Exceptions.printStackTrace(ex);
+            }
+       }
+        beanTreeView.updateUI();
+    }
+
+    @Override
+    public void propertyChange(PropertyChangeEvent evt) {
+        if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
+            Node[] newValue = (Node[]) evt.getNewValue();
+            if (newValue.length > 0) {
+                AbstractNode firstSelected = (AbstractNode) newValue[0];
+                if (firstSelected instanceof GElementNode) {
+                    GElement element = ((GElementNode) firstSelected).getGelement();
+                    GUI gui = ((GUINode)mgr.getRootContext()).getGui();
+                    gui.getSelection().deleteObserver(this); // I don't wont to get notified about this selection change
+                    SelectCommand command = CommandProcessor.getInstance().getCommand(SelectCommand.class);
+                    command.setElement(element);
+                    try {
+                        lock = true;
+                        CommandProcessor.getInstance().excuteCommand(command);
+                    } catch (Exception ex) {
+                        Exceptions.printStackTrace(ex);
+                    }
+                     gui.getSelection().addObserver(this);
+                    
+                }
+            }
+        }
+    }
+
+
+    private void intNavigator(GUI gui) throws PropertyVetoException {
+        
+       
+        ExplorerUtils.activateActions(mgr, true);
+       
+        
+        AbstractNode guiRoot = new GUINode(gui);
+        guiRoot.setName("Gui");
+        this.mgr.setRootContext(guiRoot);
+        this.beanTreeView.updateUI();
+        mgr.addPropertyChangeListener(this);
+        this.mgr.setSelectedNodes(new Node[]{guiRoot});
+        Lookup lookup1 = ExplorerUtils.createLookup(mgr, getActionMap());
+        lookup = new ProxyLookup(lookup1);
+        
+    }
+}

+ 149 - 148
sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiDataObject.java

@@ -1,148 +1,149 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.jme3.gde.gui;
-
-import com.jme3.gde.core.assets.ProjectAssetManager;
-import jada.ngeditor.controller.GUIEditor;
-import java.io.IOException;
-import org.netbeans.api.project.Project;
-import org.netbeans.api.project.ProjectManager;
-import org.netbeans.core.spi.multiview.MultiViewElement;
-import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
-import org.openide.awt.ActionID;
-import org.openide.awt.ActionReference;
-import org.openide.awt.ActionReferences;
-import org.openide.filesystems.FileObject;
-import org.openide.filesystems.MIMEResolver;
-import org.openide.loaders.DataNode;
-import org.openide.loaders.DataObject;
-import org.openide.loaders.DataObjectExistsException;
-import org.openide.loaders.MultiDataObject;
-import org.openide.loaders.MultiFileLoader;
-import org.openide.nodes.Children;
-import org.openide.nodes.Node;
-import org.openide.util.Lookup;
-import org.openide.util.NbBundle.Messages;
-import org.openide.windows.TopComponent;
-
-@Messages({
-    "LBL_NiftyGui_LOADER=Files of NiftyGui"
-})
[email protected](
-        displayName = "#LBL_NiftyGui_LOADER",
-        resource = "NiftyGuiResolver.xml")
[email protected](
-        mimeType = "text/x-niftygui+xml",
-        iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
-        displayName = "#LBL_NiftyGui_LOADER",
-        position = 300)
-@ActionReferences({
-    @ActionReference(
-            path = "Loaders/text/x-niftygui+xml/Actions",
-            id =
-            @ActionID(category = "System", id = "org.openide.actions.OpenAction"),
-            position = 100,
-            separatorAfter = 200),
-    @ActionReference(
-            path = "Loaders/text/x-niftygui+xml/Actions",
-            id =
-            @ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
-            position = 300),
-    @ActionReference(
-            path = "Loaders/text/x-niftygui+xml/Actions",
-            id =
-            @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
-            position = 400,
-            separatorAfter = 500),
-    @ActionReference(
-            path = "Loaders/text/x-niftygui+xml/Actions",
-            id =
-            @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
-            position = 600),
-    @ActionReference(
-            path = "Loaders/text/x-niftygui+xml/Actions",
-            id =
-            @ActionID(category = "System", id = "org.openide.actions.RenameAction"),
-            position = 700,
-            separatorAfter = 800),
-    @ActionReference(
-            path = "Loaders/text/x-niftygui+xml/Actions",
-            id =
-            @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
-            position = 900,
-            separatorAfter = 1000),
-    @ActionReference(
-            path = "Loaders/text/x-niftygui+xml/Actions",
-            id =
-            @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
-            position = 1100,
-            separatorAfter = 1200),
-    @ActionReference(
-            path = "Loaders/text/x-niftygui+xml/Actions",
-            id =
-            @ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
-            position = 1300),
-    @ActionReference(
-            path = "Loaders/text/x-niftygui+xml/Actions",
-            id =
-            @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
-            position = 1400)
-})
-public class NiftyGuiDataObject extends MultiDataObject {
-
-    public NiftyGuiDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
-        super(pf, loader);
-        registerEditor("text/x-niftygui+xml", true);
-        findAssetManager();
-        this.getCookieSet().assign(GUIEditor.class,new GUIEditor());
-    }
-
-    protected final void findAssetManager() {
-        FileObject file = getPrimaryFile();
-        ProjectManager pm = ProjectManager.getDefault();
-        while (file != null) {
-            if (file.isFolder() && pm.isProject(file)) {
-                try {
-                    Project project = ProjectManager.getDefault().findProject(file);
-                    if (project != null) {
-                        ProjectAssetManager mgr = project.getLookup().lookup(ProjectAssetManager.class);
-                        if (mgr != null) {
-                            this.getCookieSet().assign(mgr.getClass(),mgr);
-                            return;
-                        }
-                    }
-                } catch (IOException ex) {
-                } catch (IllegalArgumentException ex) {
-                }
-            }
-            file = file.getParent();
-        }
-    }
-
-    @Override
-    protected Node createNodeDelegate() {
-        DataNode node = new DataNode(this, Children.LEAF, getLookup());
-        node.setIconBaseWithExtension("com/jme3/gde/gui/Computer_File_043.gif");
-        return node;
-    }
-    
-    @Override
-    protected int associateLookup() {
-        return 1;
-    }
-
-    @MultiViewElement.Registration(
-            displayName = "#LBL_NiftyGui_EDITOR",
-            iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
-            mimeType = "text/x-niftygui+xml",
-            persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
-            preferredID = "NiftyGui",
-            position = 1000)
-    @Messages("LBL_NiftyGui_EDITOR=XML")
-    public static MultiViewEditorElement createEditor(Lookup lkp) {
-        final MultiViewEditorElement multiViewEditorElement = new MultiViewEditorElement(lkp);
-        return multiViewEditorElement;
-    }
-}
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.jme3.gde.gui;
+
+import com.jme3.gde.core.assets.ProjectAssetManager;
+import jada.ngeditor.controller.CommandProcessor;
+import jada.ngeditor.controller.GUIEditor;
+import java.io.IOException;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.core.spi.multiview.MultiViewElement;
+import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.MIMEResolver;
+import org.openide.loaders.DataNode;
+import org.openide.loaders.DataObject;
+import org.openide.loaders.DataObjectExistsException;
+import org.openide.loaders.MultiDataObject;
+import org.openide.loaders.MultiFileLoader;
+import org.openide.nodes.Children;
+import org.openide.nodes.Node;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle.Messages;
+import org.openide.windows.TopComponent;
+
+@Messages({
+    "LBL_NiftyGui_LOADER=Files of NiftyGui"
+})
[email protected](
+        displayName = "#LBL_NiftyGui_LOADER",
+        resource = "NiftyGuiResolver.xml")
[email protected](
+        mimeType = "text/x-niftygui+xml",
+        iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
+        displayName = "#LBL_NiftyGui_LOADER",
+        position = 300)
+@ActionReferences({
+    @ActionReference(
+            path = "Loaders/text/x-niftygui+xml/Actions",
+            id =
+            @ActionID(category = "System", id = "org.openide.actions.OpenAction"),
+            position = 100,
+            separatorAfter = 200),
+    @ActionReference(
+            path = "Loaders/text/x-niftygui+xml/Actions",
+            id =
+            @ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
+            position = 300),
+    @ActionReference(
+            path = "Loaders/text/x-niftygui+xml/Actions",
+            id =
+            @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
+            position = 400,
+            separatorAfter = 500),
+    @ActionReference(
+            path = "Loaders/text/x-niftygui+xml/Actions",
+            id =
+            @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
+            position = 600),
+    @ActionReference(
+            path = "Loaders/text/x-niftygui+xml/Actions",
+            id =
+            @ActionID(category = "System", id = "org.openide.actions.RenameAction"),
+            position = 700,
+            separatorAfter = 800),
+    @ActionReference(
+            path = "Loaders/text/x-niftygui+xml/Actions",
+            id =
+            @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
+            position = 900,
+            separatorAfter = 1000),
+    @ActionReference(
+            path = "Loaders/text/x-niftygui+xml/Actions",
+            id =
+            @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
+            position = 1100,
+            separatorAfter = 1200),
+    @ActionReference(
+            path = "Loaders/text/x-niftygui+xml/Actions",
+            id =
+            @ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
+            position = 1300),
+    @ActionReference(
+            path = "Loaders/text/x-niftygui+xml/Actions",
+            id =
+            @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
+            position = 1400)
+})
+public class NiftyGuiDataObject extends MultiDataObject {
+
+    public NiftyGuiDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
+        super(pf, loader);
+        registerEditor("text/x-niftygui+xml", true);
+        findAssetManager();
+        this.getCookieSet().assign(GUIEditor.class, CommandProcessor.getInstance().getGuiEditor());
+    }
+
+    protected final void findAssetManager() {
+        FileObject file = getPrimaryFile();
+        ProjectManager pm = ProjectManager.getDefault();
+        while (file != null) {
+            if (file.isFolder() && pm.isProject(file)) {
+                try {
+                    Project project = ProjectManager.getDefault().findProject(file);
+                    if (project != null) {
+                        ProjectAssetManager mgr = project.getLookup().lookup(ProjectAssetManager.class);
+                        if (mgr != null) {
+                            this.getCookieSet().assign(mgr.getClass(),mgr);
+                            return;
+                        }
+                    }
+                } catch (IOException ex) {
+                } catch (IllegalArgumentException ex) {
+                }
+            }
+            file = file.getParent();
+        }
+    }
+
+    @Override
+    protected Node createNodeDelegate() {
+        DataNode node = new DataNode(this, Children.LEAF, getLookup());
+        node.setIconBaseWithExtension("com/jme3/gde/gui/Computer_File_043.gif");
+        return node;
+    }
+    
+    @Override
+    protected int associateLookup() {
+        return 1;
+    }
+
+    @MultiViewElement.Registration(
+            displayName = "#LBL_NiftyGui_EDITOR",
+            iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
+            mimeType = "text/x-niftygui+xml",
+            persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
+            preferredID = "NiftyGui",
+            position = 1000)
+    @Messages("LBL_NiftyGui_EDITOR=XML")
+    public static MultiViewEditorElement createEditor(Lookup lkp) {
+        final MultiViewEditorElement multiViewEditorElement = new MultiViewEditorElement(lkp);
+        return multiViewEditorElement;
+    }
+}

+ 335 - 332
sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiVisualElement.java

@@ -1,332 +1,335 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.jme3.gde.gui;
-
-import com.jme3.gde.core.assets.ProjectAssetManager;
-import com.jme3.gde.core.scene.SceneApplication;
-import com.jme3.gde.gui.nodes.GUINode;
-import com.jme3.gde.gui.palette.NiftyGUIPaletteFactory;
-import de.lessvoid.nifty.Nifty;
-import jada.ngeditor.controller.GUIEditor;
-import jada.ngeditor.guiviews.DND.PaletteDropTarget;
-import jada.ngeditor.guiviews.DND.TrasferHandling;
-import jada.ngeditor.guiviews.J2DNiftyView;
-import jada.ngeditor.model.elements.GElement;
-import jada.ngeditor.model.elements.GLayer;
-import jada.ngeditor.model.exception.NoProductException;
-import java.awt.Dimension;
-import java.awt.dnd.DropTarget;
-import java.awt.dnd.DropTargetDragEvent;
-import java.awt.dnd.DropTargetDropEvent;
-import java.awt.dnd.DropTargetEvent;
-import java.awt.dnd.DropTargetListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.beans.PropertyVetoException;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Observable;
-import java.util.Observer;
-import java.util.concurrent.Callable;
-import javax.swing.Action;
-import javax.swing.ActionMap;
-import javax.swing.DefaultComboBoxModel;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import javax.swing.JPanel;
-import javax.swing.JToolBar;
-import javax.swing.text.AbstractDocument;
-import javax.xml.bind.JAXBException;
-import javax.xml.parsers.ParserConfigurationException;
-import org.netbeans.api.progress.ProgressHandle;
-import org.netbeans.api.progress.ProgressHandleFactory;
-import org.netbeans.core.spi.multiview.CloseOperationState;
-import org.netbeans.core.spi.multiview.MultiViewElement;
-import org.netbeans.core.spi.multiview.MultiViewElementCallback;
-import org.openide.DialogDisplayer;
-import org.openide.NotifyDescriptor;
-import org.openide.awt.UndoRedo;
-import org.openide.explorer.ExplorerManager;
-import org.openide.explorer.ExplorerUtils;
-import org.openide.nodes.Node;
-import org.openide.util.Exceptions;
-import org.openide.util.Lookup;
-import org.openide.util.NbBundle.Messages;
-import org.openide.util.lookup.AbstractLookup;
-import org.openide.util.lookup.InstanceContent;
-import org.openide.util.lookup.ProxyLookup;
-import org.openide.windows.TopComponent;
-import org.xml.sax.SAXException;
-
[email protected](
-        displayName = "#LBL_NiftyGui_VISUAL",
-        iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
-        mimeType = "text/x-niftygui+xml",
-        persistenceType = TopComponent.PERSISTENCE_NEVER,
-        preferredID = "NiftyGuiVisual",
-        position = 2000)
-@Messages("LBL_NiftyGui_VISUAL=Visual")
-public final class NiftyGuiVisualElement extends JPanel implements MultiViewElement , ExplorerManager.Provider,Observer {
-
-    private NiftyGuiDataObject obj;
-    private JToolBar toolbar = new JToolBar();
-    private transient MultiViewElementCallback callback;
-    private GUIEditor editor;
-    private final Nifty nifty;
-    private final J2DNiftyView view;
-    private final JComboBox layers = new JComboBox();
-    private final ExplorerManager nodesManager;
-   
-
-    public NiftyGuiVisualElement(Lookup lkp) {
-        obj = lkp.lookup(NiftyGuiDataObject.class);
-        assert obj != null;
-        initComponents();
-        view = new J2DNiftyView(800, 600);
-        view.init();
-        this.scrollArea.getViewport().addChangeListener(view);
-        this.scrollArea.setViewportView(view);
-        TrasferHandling tranf = new TrasferHandling();
-        PaletteDropTarget tmp = new PaletteDropTarget();
-        editor = obj.getLookup().lookup(GUIEditor.class);
-        editor.addObserver(this);
-        nodesManager = new ExplorerManager();
-        nifty = view.getNifty();
-        view.setTransferHandler(tranf);
-        view.setDropTarget(tmp);
-        editor.addObserver(view);
-        editor.addObserver(tranf);
-        editor.addObserver(tmp);
-        this.createToolbar();
-    }
- /**
- * Old code
- * @author normenhansen
- */
-     private void createToolbar() {
-        toolbar.setPreferredSize(new Dimension(10000, 24));
-        toolbar.setMaximumSize(new Dimension(10000, 24));
-        toolbar.setFloatable(false);
-        JComboBox comboBox = new JComboBox(new String[]{"640x480", "480x800", "800x480", "800x600", "1024x768", "1280x720"});
-        comboBox.addItemListener(new ItemListener() {
-
-            public void itemStateChanged(ItemEvent e) {
-                String string = (String) e.getItem();
-                if ("640x480".equals(string)) {
-                    view.setResoltion(640, 480);
-                } else if ("1024x768".equals(string)) {
-                     view.setResoltion(1024, 768);
-                } else if ("1280x720".equals(string)) {
-                     view.setResoltion(1280, 720);
-                } else if ("800x600".equals(string)) {
-                     view.setResoltion(800, 600);
-                } else if ("800x480".equals(string)) {
-                     view.setResoltion(800, 480);
-                } else if ("480x800".equals(string)) {
-                     view.setResoltion(480, 800);
-                } else {
-                     view.setResoltion(800, 600);
-                }
-            }
-        });
-        toolbar.add(comboBox);
-        comboBox.setSelectedItem("800x600");
-        layers.addItemListener(new ItemListener() {
-
-            public void itemStateChanged(ItemEvent e) {
-                GLayer item = (GLayer) e.getItem();
-                editor.selectElement(item);
-            }
-        });
-        toolbar.add(layers);
-     }
-    @Override
-    public String getName() {
-        return "NiftyGuiVisualElement";
-    }
-
-    /**
-     * This method is called from within the constructor to initialize the form.
-     * WARNING: Do NOT modify this code. The content of this method is always
-     * regenerated by the Form Editor.
-     */
-    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
-    private void initComponents() {
-
-        scrollArea = new javax.swing.JScrollPane();
-
-        setLayout(new java.awt.BorderLayout());
-        add(scrollArea, java.awt.BorderLayout.CENTER);
-    }// </editor-fold>//GEN-END:initComponents
-
-    // Variables declaration - do not modify//GEN-BEGIN:variables
-    private javax.swing.JScrollPane scrollArea;
-    // End of variables declaration//GEN-END:variables
-    @Override
-    public JComponent getVisualRepresentation() {
-        return this;
-    }
-
-    @Override
-    public JComponent getToolbarRepresentation() {
-        return toolbar;
-    }
-
-    @Override
-    public Action[] getActions() {
-        return new Action[0];
-    }
-
-    @Override
-    public Lookup getLookup() {
-        return ExplorerUtils.createLookup(nodesManager, new ActionMap());
-    }
-    /**
-     * Raw implementation , just to prototype the editor
-     */
-    @Override
-    public void componentOpened() {
-        try {
-            ProgressHandle handle = ProgressHandleFactory.createHandle("Loading the gui file");
-            String path = this.obj.getPrimaryFile().getPath();
-            ProjectAssetManager mgr = obj.getLookup().lookup(ProjectAssetManager.class);
-            String assetPath = mgr.getAssetFolder().getPath();
-            handle.progress(50);
-            this.editor.createNewGui(nifty,new File(path),new File(assetPath));
-            nodesManager.setRootContext(new GUINode(this.editor.getGui()));
-            Collection<GLayer> layers1 = this.editor.getGui().getLayers();
-            DefaultComboBoxModel<GLayer> model = new DefaultComboBoxModel<GLayer>(layers1.toArray(new GLayer[0]));
-            layers.setModel(model);
-            layers.setSelectedItem(this.editor.getCurrentLayer());
-            
-            handle.finish();
-            
-        } catch (ParserConfigurationException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (JAXBException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (ClassNotFoundException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (IOException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (NoProductException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (SAXException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (Exception ex) {
-            Exceptions.printStackTrace(ex);
-        }
-    }
-
-    @Override
-    public void componentClosed() {
-    }
-    /**
-     * Raw implementation , just to prototype the editor
-     */
-    @Override
-    public void componentShowing() {
-        try {
-            ProgressHandle handle = ProgressHandleFactory.createHandle("Loading the gui file");
-            String path = this.obj.getPrimaryFile().getPath();
-            ProjectAssetManager mgr = this.obj.getLookup().lookup(ProjectAssetManager.class);
-            String assetPath = mgr.getAssetFolder().getPath();
-            this.editor.createNewGui(nifty,new File(path),new File(assetPath));
-             nodesManager.setRootContext(new GUINode(this.editor.getGui()));
-            Collection<GLayer> layers1 = this.editor.getGui().getLayers();
-            DefaultComboBoxModel<GLayer> model = new DefaultComboBoxModel<GLayer>(layers1.toArray(new GLayer[0]));
-            layers.setModel(model);
-            layers.setSelectedItem(this.editor.getCurrentLayer());
-           
-            handle.finish();
-        } catch (ParserConfigurationException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (JAXBException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (ClassNotFoundException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (IOException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (NoProductException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (SAXException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (Exception ex) {
-            Exceptions.printStackTrace(ex);
-        }
-        
-    }
-    /**
-     * Raw implementation , just to prototype the editor
-     */
-    @Override
-    public void componentHidden() {
-        String path = this.obj.getPrimaryFile().getPath();
-        try {
-            this.editor.saveGui(path);
-        } catch (FileNotFoundException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (JAXBException ex) {
-            Exceptions.printStackTrace(ex);
-        }
-    }
-
-    @Override
-    public void componentActivated() {
-    }
-
-    @Override
-    public void componentDeactivated() {
-    }
-
-    @Override
-    public UndoRedo getUndoRedo() {
-        return UndoRedo.NONE;
-    }
-
-    @Override
-    public void setMultiViewCallback(MultiViewElementCallback callback) {
-        this.callback = callback;
-    }
-
-    @Override
-    public CloseOperationState canCloseElement() {
-        return CloseOperationState.STATE_OK;
-    }
-
-    @Override
-    public ExplorerManager getExplorerManager() {
-       return nodesManager;
-    }
-
-    @Override
-    public void update(Observable o, Object arg) {
-        jada.ngeditor.listeners.actions.Action act = ( jada.ngeditor.listeners.actions.Action) arg;
-       if(act.getType() == jada.ngeditor.listeners.actions.Action.SEL){
-           ArrayList<String> path = new ArrayList<String>();
-           GElement parent = act.getGUIElement();
-           while(parent!=null){
-               path.add(parent.getID());
-               parent = parent.getParent();
-           }
-           
-           Node result = nodesManager.getRootContext();
-          
-           for(int i=path.size()-1;i>=0 && result!=null;i--){
-               result = result.getChildren().findChild(path.get(i));
-           }
-            try {
-                if(result!=null){
-                nodesManager.setSelectedNodes(new Node[]{result});
-                }
-            } catch (PropertyVetoException ex) {
-                Exceptions.printStackTrace(ex);
-            }
-       }
-    }
-}
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.jme3.gde.gui;
+
+import com.jme3.gde.core.assets.ProjectAssetManager;
+import com.jme3.gde.gui.nodes.GUINode;
+import de.lessvoid.nifty.Nifty;
+import jada.ngeditor.controller.CommandProcessor;
+import jada.ngeditor.controller.GUIEditor;
+import jada.ngeditor.guiviews.DND.PaletteDropTarget;
+import jada.ngeditor.guiviews.DND.TrasferHandling;
+import jada.ngeditor.guiviews.J2DNiftyView;
+import jada.ngeditor.listeners.events.SelectionChanged;
+import jada.ngeditor.model.GuiEditorModel;
+import jada.ngeditor.model.elements.GElement;
+import jada.ngeditor.model.elements.GLayer;
+import jada.ngeditor.model.exception.NoProductException;
+import java.awt.Dimension;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyVetoException;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Observable;
+import java.util.Observer;
+import javax.swing.Action;
+import javax.swing.ActionMap;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JToolBar;
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
+import org.netbeans.api.progress.ProgressHandle;
+import org.netbeans.api.progress.ProgressHandleFactory;
+import org.netbeans.core.spi.multiview.CloseOperationState;
+import org.netbeans.core.spi.multiview.MultiViewElement;
+import org.netbeans.core.spi.multiview.MultiViewElementCallback;
+import org.openide.awt.UndoRedo;
+import org.openide.explorer.ExplorerManager;
+import org.openide.explorer.ExplorerUtils;
+import org.openide.loaders.DataObject;
+import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle.Messages;
+import org.openide.windows.TopComponent;
+import org.xml.sax.SAXException;
+import sun.rmi.runtime.Log;
+
[email protected](
+        displayName = "#LBL_NiftyGui_VISUAL",
+        iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
+        mimeType = "text/x-niftygui+xml",
+        persistenceType = TopComponent.PERSISTENCE_NEVER,
+        preferredID = "NiftyGuiVisual",
+        position = 2000)
+@Messages("LBL_NiftyGui_VISUAL=Visual")
+public final class NiftyGuiVisualElement extends JPanel implements MultiViewElement , ExplorerManager.Provider,Observer, PropertyChangeListener {
+
+    private NiftyGuiDataObject obj;
+    private JToolBar toolbar = new JToolBar();
+    private transient MultiViewElementCallback callback;
+    private GUIEditor editor;
+    private final Nifty nifty;
+    private final J2DNiftyView view;
+    private final JComboBox layers = new JComboBox();
+    private final ExplorerManager nodesManager;
+    private final UndoRedo.Manager undoSupport;
+    private int guiID;
+   
+
+    public NiftyGuiVisualElement(Lookup lkp) {
+        obj = lkp.lookup(NiftyGuiDataObject.class);
+        assert obj != null;
+        initComponents();
+        view = new J2DNiftyView(800, 600);
+        view.init();
+        this.scrollArea.getViewport().addChangeListener(view);
+        this.scrollArea.setViewportView(view);
+        TrasferHandling tranf = new TrasferHandling();
+        PaletteDropTarget tmp = new PaletteDropTarget();
+        editor = obj.getLookup().lookup(GUIEditor.class);
+        nodesManager = new ExplorerManager();
+        nifty = view.getNifty();
+        view.setTransferHandler(tranf);
+        view.setDropTarget(tmp);
+       // editor.addObserver(view);
+       // editor.addObserver(tranf);
+        this.obj.addPropertyChangeListener(this);
+        this.createToolbar();
+        this.undoSupport = new UndoRedo.Manager();
+        CommandProcessor.getInstance().setUndoManager(undoSupport);
+    }
+ /**
+ * Old code
+ * @author normenhansen
+ */
+     private void createToolbar() {
+        toolbar.setPreferredSize(new Dimension(10000, 24));
+        toolbar.setMaximumSize(new Dimension(10000, 24));
+        toolbar.setFloatable(false);
+        toolbar.add(new JLabel("Change Resolution"));
+        JComboBox comboBox = new JComboBox(new String[]{"640x480", "480x800", "800x480", "800x600", "1024x768", "1280x720"});
+        comboBox.addItemListener(new ItemListener() {
+
+            public void itemStateChanged(ItemEvent e) {
+                String string = (String) e.getItem();
+                if ("640x480".equals(string)) {
+                    view.setResoltion(640, 480);
+                } else if ("1024x768".equals(string)) {
+                     view.setResoltion(1024, 768);
+                } else if ("1280x720".equals(string)) {
+                     view.setResoltion(1280, 720);
+                } else if ("800x600".equals(string)) {
+                     view.setResoltion(800, 600);
+                } else if ("800x480".equals(string)) {
+                     view.setResoltion(800, 480);
+                } else if ("480x800".equals(string)) {
+                     view.setResoltion(480, 800);
+                } else {
+                     view.setResoltion(800, 600);
+                }
+            }
+        });
+        toolbar.add(comboBox);
+        comboBox.setSelectedItem("800x600");
+        toolbar.add(new JLabel("Current Layer"));
+        layers.addItemListener(new ItemListener() {
+
+            public void itemStateChanged(ItemEvent e) {
+                GLayer item = (GLayer) e.getItem();
+                editor.selectElement(item);
+            }
+        });
+        toolbar.add(layers);
+     }
+    @Override
+    public String getName() {
+        return "NiftyGuiVisualElement";
+    }
+
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+
+        scrollArea = new javax.swing.JScrollPane();
+
+        setLayout(new java.awt.BorderLayout());
+        add(scrollArea, java.awt.BorderLayout.CENTER);
+    }// </editor-fold>//GEN-END:initComponents
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JScrollPane scrollArea;
+    // End of variables declaration//GEN-END:variables
+    @Override
+    public JComponent getVisualRepresentation() {
+        return this;
+    }
+
+    @Override
+    public JComponent getToolbarRepresentation() {
+        return toolbar;
+    }
+
+    @Override
+    public Action[] getActions() {
+        return new Action[0];
+    }
+
+    @Override
+    public Lookup getLookup() {
+        return ExplorerUtils.createLookup(nodesManager, new ActionMap());
+    }
+    /**
+     * Raw implementation , just to prototype the editor
+     */
+    @Override
+    public void componentOpened() {
+       loadGui();
+    }
+
+    @Override
+    public void componentClosed() {
+        
+    }
+    /**
+     * Raw implementation , just to prototype the editor
+     */
+    @Override
+    public void componentShowing() {
+        if(!this.obj.isModified()){
+            return;
+        }
+        loadGui();
+        
+    }
+    /**
+     * Raw implementation , just to prototype the editor
+     */
+    @Override
+    public void componentHidden() {
+        String path = this.obj.getPrimaryFile().getPath();
+        try {
+            this.editor.saveGui(path);
+        } catch (FileNotFoundException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (JAXBException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (NullPointerException ex){
+             Exceptions.printStackTrace(ex);
+        }
+    }
+
+    @Override
+    public void componentActivated() {
+        GuiEditorModel model = (GuiEditorModel) CommandProcessor.getInstance().getObservable();
+        model.setCurrentGUI(guiID);
+        CommandProcessor.getInstance().setUndoManager(undoSupport);
+    }
+
+    @Override
+    public void componentDeactivated() {
+    }
+
+    @Override
+    public UndoRedo getUndoRedo() {
+        return this.undoSupport;
+    }
+
+    @Override
+    public void setMultiViewCallback(MultiViewElementCallback callback) {
+        this.callback = callback;
+    }
+
+    @Override
+    public CloseOperationState canCloseElement() {
+        return CloseOperationState.STATE_OK;
+    }
+
+    @Override
+    public ExplorerManager getExplorerManager() {
+       return nodesManager;
+    }
+
+    @Override
+    public void update(Observable o, Object arg) {
+       if(arg instanceof SelectionChanged ){
+           SelectionChanged event = (SelectionChanged) arg;
+           if(event.getNewSelection().isEmpty()){
+               return;
+           }
+           ArrayList<String> path = new ArrayList<String>();
+           GElement parent = event.getElement();
+           while(parent!=null){
+               path.add(parent.getID());
+               parent = parent.getParent();
+           }
+           
+           Node result = nodesManager.getRootContext();
+          
+           for(int i=path.size()-1;i>=0 && result!=null;i--){
+               result = result.getChildren().findChild(path.get(i));
+           }
+            try {
+                if(result!=null){
+                nodesManager.setSelectedNodes(new Node[]{result});
+                }
+            } catch (PropertyVetoException ex) {
+                Exceptions.printStackTrace(ex);
+            }
+       }
+    }
+
+    @Override
+    public void propertyChange(PropertyChangeEvent evt) {
+        if(evt.getPropertyName().equals(DataObject.PROP_MODIFIED)){
+            boolean old = (Boolean)evt.getOldValue();
+            boolean nev = (Boolean)evt.getNewValue();
+            if(old && !nev){
+                this.loadGui();
+            }
+        }
+      
+    }
+
+    private void loadGui() {
+        try {
+            ProgressHandle handle = ProgressHandleFactory.createHandle("Loading the gui file");
+            InputStream is = this.obj.getPrimaryFile().getInputStream();
+            
+            ProjectAssetManager mgr = this.obj.getLookup().lookup(ProjectAssetManager.class);
+            String assetPath = mgr.getAssetFolder().getPath();
+            this.editor.createNewGui(nifty,is,new File(assetPath));
+            this.view.newGui(this.editor.getGui());
+            nodesManager.setRootContext(new GUINode(this.editor.getGui()));
+            this.editor.getGui().getSelection().addObserver(this);
+            Collection<GLayer> layers1 = this.editor.getGui().getLayers();
+            guiID = this.editor.getGui().getGUIid();
+            DefaultComboBoxModel<GLayer> model = new DefaultComboBoxModel<GLayer>(layers1.toArray(new GLayer[0]));
+            layers.setModel(model);
+            layers.setSelectedItem(this.editor.getCurrentLayer());
+           
+            handle.finish();
+        } catch (ParserConfigurationException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (JAXBException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (ClassNotFoundException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (IOException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (NoProductException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (SAXException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (Exception ex) {
+            Exceptions.printStackTrace(ex);
+        }
+    }
+}

+ 19 - 10
sdk/jme3-gui/src/com/jme3/gde/gui/layer.xml

@@ -1,10 +1,19 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
-<filesystem>
-<folder name="NiftyPalette">
-    <folder name="Items">
-         <file name="Screen" url="com/jme3/gde/gui/palette/Screen.xml">
-        </file>
-    </folder>
-</folder>
-</filesystem>
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
+<filesystem>
+<folder name="NiftyPalette">
+    <folder name="Items">
+         <file name="Screen" url="com/jme3/gde/gui/palette/Screen.xml">
+        </file>
+    </folder>
+</folder>
+ <folder name="Navigator">
+        <folder name="Panels">
+            <folder name="text">
+                <folder name="x-niftygui+xml">
+                    <file name="org-netbeans-modules-xml-text-navigator-XMLNavigatorPanel.instance"/>
+                </folder>
+            </folder>
+        </folder>
+ </folder> 
+</filesystem>

+ 117 - 97
sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GElementNode.java

@@ -1,97 +1,117 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.jme3.gde.gui.nodes;
-
-import jada.ngeditor.model.elements.GElement;
-import java.beans.PropertyEditor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Map.Entry;
-import org.openide.nodes.AbstractNode;
-import org.openide.nodes.Children;
-import org.openide.nodes.Node;
-import org.openide.nodes.Sheet;
-
-/**
- *
- * @author cris
- */
-public class GElementNode extends AbstractNode{
-    private final GElement element;
-
-    public GElementNode(GElement element) {
-        super(Children.create(new GElementChildFactory(element), false));
-        
-        this.element = element;
-        this.setName(element.getID());
-        
-    }
-    
-    public GElement getGelement(){
-        return element;
-    }
-    
-    public void updateChildren(){
-        
-    }
-    @Override
-    protected Sheet createSheet() {
-        Sheet s = super.createSheet();
-        Sheet.Set set = s.get(Sheet.PROPERTIES);
-        if (set == null) {
-            set = Sheet.createPropertiesSet();
-            s.put(set);
-        }
-        set.setName("Element Properties");
-        set.setShortDescription("You can set element properties");
-        for(Entry<String,String> pair : this.element.listAttributes().entrySet()){
-            set.put(new ElementAttributeProperty(element,pair.getKey()));
-        }
-        s.put(set);
-        return s; 
-    }
-    
-    public  class ElementAttributeProperty extends Node.Property {
-
-        private String attributeName;
-        private GElement element;
-
-        public ElementAttributeProperty(GElement element, String attributeName) {
-            super(String.class);
-            this.element = element;
-            this.attributeName = attributeName;
-            this.setName(attributeName);
-            this.setDisplayName(attributeName);
-           
-        }
-
-        @Override
-        public boolean canRead() {
-            return true;
-        }
-
-        @Override
-        public String getValue() throws IllegalAccessException, InvocationTargetException{
-            return element.getAttribute(attributeName);
-        }
-
-        @Override
-        public boolean canWrite() {
-            return true;
-        }
-
-        @Override
-        public PropertyEditor getPropertyEditor() {  
-            return super.getPropertyEditor(); //To change body of generated methods, choose Tools | Templates.
-        }
-        
-        
-
-        @Override
-        public void setValue(Object val) throws IllegalAccessException, IllegalArgumentException {
-            element.addAttribute(attributeName, val.toString());
-            element.refresh();
-        }
-    };
-}
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.jme3.gde.gui.nodes;
+
+import com.jme3.gde.gui.propertyeditors.ResourceEditor;
+import com.jme3.gde.gui.propertyeditors.SizeEditor;
+import jada.ngeditor.model.elements.GElement;
+import java.beans.PropertyEditor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Map.Entry;
+import org.openide.nodes.AbstractNode;
+import org.openide.nodes.Children;
+import org.openide.nodes.Node;
+import org.openide.nodes.Sheet;
+import sun.beans.editors.BoolEditor;
+import sun.beans.editors.BooleanEditor;
+
+/**
+ *
+ * @author cris
+ */
+public class GElementNode extends AbstractNode{
+    private final GElement element;
+
+    public GElementNode(GElement element) {
+        super(Children.create(new GElementChildFactory(element), false));
+        
+        this.element = element;
+        this.setName(element.getID());
+        
+    }
+    
+    public GElement getGelement(){
+        return element;
+    }
+    
+    public void updateChildren(){
+        
+    }
+    @Override
+    protected Sheet createSheet() {
+        Sheet s = super.createSheet();
+        Sheet.Set set = s.get(Sheet.PROPERTIES);
+        if (set == null) {
+            set = Sheet.createPropertiesSet();
+            s.put(set);
+        }
+        set.setName("Element Properties");
+        set.setShortDescription("You can set element properties");
+        for(Entry<String,String> pair : this.element.listAttributes().entrySet()){
+            final ElementAttributeProperty elementAttributeProperty = new ElementAttributeProperty(element,pair.getKey());
+            pickEditor(pair, elementAttributeProperty);
+            set.put(elementAttributeProperty);
+        }
+        s.put(set);
+        return s; 
+    }
+
+    private void pickEditor(Entry<String, String> pair, final ElementAttributeProperty elementAttributeProperty) {
+        if(pair.getKey().equals("width")||pair.getKey().equals("height") || pair.getKey().equals("x") || pair.getKey().equals("y") ){
+           elementAttributeProperty.setPropertyEditor(new SizeEditor());
+        }else if(pair.getKey().equals("filename")){
+            elementAttributeProperty.setPropertyEditor(new ResourceEditor());
+        }
+        
+    }
+    
+    public  class ElementAttributeProperty extends Node.Property {
+
+        private String attributeName;
+        private GElement element;
+        private PropertyEditor editor;
+
+        public ElementAttributeProperty(GElement element, String attributeName) {
+            super(String.class);
+            this.element = element;
+            this.attributeName = attributeName;
+            this.setName(attributeName);
+            this.setDisplayName(attributeName);
+           
+        }
+
+        @Override
+        public boolean canRead() {
+            return true;
+        }
+
+        @Override
+        public String getValue() throws IllegalAccessException, InvocationTargetException{
+            return element.getAttribute(attributeName);
+        }
+
+        @Override
+        public boolean canWrite() {
+            return true;
+        }
+        
+        public void setPropertyEditor(PropertyEditor editor){
+            this.editor = editor;
+        }
+        @Override
+        public PropertyEditor getPropertyEditor() {  
+            
+            return this.editor; //To change body of generated methods, choose Tools | Templates.
+        }
+        
+        
+
+        @Override
+        public void setValue(Object val) throws IllegalAccessException, IllegalArgumentException {
+            element.addAttribute(attributeName, val.toString());
+            element.refresh();
+        }
+    };
+}

+ 71 - 0
sdk/jme3-gui/src/com/jme3/gde/gui/propertyeditors/ResourceEditor.java

@@ -0,0 +1,71 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.jme3.gde.gui.propertyeditors;
+
+import jada.ngeditor.controller.CommandProcessor;
+import jada.ngeditor.guiviews.editors.FileChooserEditor;
+import jada.ngeditor.model.GuiEditorModel;
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyEditorSupport;
+import java.io.File;
+import java.util.Observable;
+import java.util.Observer;
+import javax.swing.JFileChooser;
+
+/**
+ *
+ * @author cris
+ */
+public class ResourceEditor extends PropertyEditorSupport implements Observer, ActionListener{
+    private final FileChooserEditor fileChooserEditor;
+    private File assetFolder;
+    
+
+    public ResourceEditor() {
+      CommandProcessor.getInstance().getObservable().addObserver(this);
+     
+      GuiEditorModel model = (GuiEditorModel)  CommandProcessor.getInstance().getObservable();
+      this.assetFolder = model.getCurrent().getAssetFolder();
+      fileChooserEditor = new FileChooserEditor(this.assetFolder);
+      fileChooserEditor.getFileChooser().addActionListener(this);
+    }
+    
+    
+    @Override
+    public Component getCustomEditor() {
+   
+        return fileChooserEditor.getFileChooser(); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public boolean supportsCustomEditor() {
+        return true; //To change body of generated methods, choose Tools | Templates.
+    }
+
+    
+
+    @Override
+    public void update(Observable o, Object arg) {
+       if(o instanceof GuiEditorModel){
+           GuiEditorModel model = (GuiEditorModel) o;
+           this.assetFolder = model.getCurrent().getAssetFolder();
+       }
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        if (JFileChooser.APPROVE_SELECTION.equals(e.getActionCommand())) {
+            this.setValue(fileChooserEditor.traslateFile());
+        }
+    }
+    
+    
+    
+    
+}

+ 59 - 0
sdk/jme3-gui/src/com/jme3/gde/gui/propertyeditors/SizeEditor.java

@@ -0,0 +1,59 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.jme3.gde.gui.propertyeditors;
+
+import java.awt.Component;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyEditorSupport;
+import java.beans.PropertyVetoException;
+import java.beans.VetoableChangeListener;
+import javax.swing.JLabel;
+import org.openide.explorer.propertysheet.ExPropertyEditor;
+import org.openide.explorer.propertysheet.PropertyEnv;
+
+/**
+ *
+ * @author cris
+ */
+public class SizeEditor  extends PropertyEditorSupport implements ExPropertyEditor, PropertyChangeListener{
+    private PropertyEnv env;
+
+    @Override
+    public void setAsText(String text) throws IllegalArgumentException {
+        super.setAsText(text); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public String getAsText() {
+        return super.getAsText(); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public Component getCustomEditor() {
+        jada.ngeditor.guiviews.editors.SizeEditor editor = new jada.ngeditor.guiviews.editors.SizeEditor();
+        editor.setValue(this.getValue());
+        editor.addPropertyChangeListener(this);
+        return editor.getComponent(); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public boolean supportsCustomEditor() {
+        return true; //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public void attachEnv(PropertyEnv env) {
+        this.env = env;
+    }
+
+    @Override
+    public void propertyChange(PropertyChangeEvent evt) {
+       this.setValue(evt.getNewValue());
+    }
+
+   
+    
+}