From 76fef5cbaef44e17ac8d84fad9fa84ce71d8005d Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Mon, 21 Nov 2011 18:47:07 +0000 Subject: [PATCH] - make ImportantFiles functionality more flexible - give more descriptive names to android ImportantFiles and build.xml git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8749 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../gde/android/AndroidImportantFiles.java | 48 +++++++++++++----- .../gde/android/MobileCompositeProvider.java | 30 ----------- .../core/importantfiles/ImportantFiles.java | 13 ++++- .../importantfiles/ImportantFilesNode.java | 50 +++++++------------ .../core/j2seproject/J2seImportantFiles.java | 33 +++++++++--- 5 files changed, 90 insertions(+), 84 deletions(-) diff --git a/sdk/jme3-android/src/com/jme3/gde/android/AndroidImportantFiles.java b/sdk/jme3-android/src/com/jme3/gde/android/AndroidImportantFiles.java index 6b3952eca..346d443cc 100644 --- a/sdk/jme3-android/src/com/jme3/gde/android/AndroidImportantFiles.java +++ b/sdk/jme3-android/src/com/jme3/gde/android/AndroidImportantFiles.java @@ -9,6 +9,9 @@ import java.io.InputStream; import java.util.ArrayList; import org.netbeans.api.project.Project; import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; +import org.openide.nodes.Node; import org.openide.util.Exceptions; import org.openide.xml.XMLUtil; import org.w3c.dom.Document; @@ -22,7 +25,7 @@ import org.xml.sax.InputSource; public class AndroidImportantFiles implements ImportantFiles { @Override - public FileObject[] getFiles(Project project) { + public Node[] getNodes(Project project) { FileObject manifest = project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"); String mainActivity = "mobile/src"; if (manifest != null) { @@ -37,19 +40,38 @@ public class AndroidImportantFiles implements ImportantFiles { } finally { } } - ArrayList list = new ArrayList(); - FileObject mainAct = project.getProjectDirectory().getFileObject(mainActivity); - if (mainAct != null) { - list.add(mainAct); - } - FileObject manif = project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"); - if (manif != null) { - list.add(manif); + ArrayList list = new ArrayList(); + try { + FileObject mainAct = project.getProjectDirectory().getFileObject(mainActivity); + if (mainAct != null) { + Node node = DataObject.find(mainAct).getNodeDelegate(); + node.setDisplayName("Android Main Activity"); + list.add(node); + } + FileObject manif = project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"); + if (manif != null) { + Node node = DataObject.find(manif).getNodeDelegate(); + node.setDisplayName("Android Manifest"); + list.add(node); + } + FileObject buildProp = project.getProjectDirectory().getFileObject("mobile/ant.properties"); + if (buildProp != null) { + Node node = DataObject.find(buildProp).getNodeDelegate(); + node.setDisplayName("Android Properties"); + list.add(node); + } + } catch (DataObjectNotFoundException ex) { + Exceptions.printStackTrace(ex); } - FileObject buildProp = project.getProjectDirectory().getFileObject("mobile/ant.properties"); - if (buildProp != null) { - list.add(buildProp); + return list.toArray(new Node[list.size()]); + } + + @Override + public boolean hasFiles(Project proj) { + if (proj.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml") != null) { + return true; } - return list.toArray(new FileObject[list.size()]); + return false; } + } diff --git a/sdk/jme3-android/src/com/jme3/gde/android/MobileCompositeProvider.java b/sdk/jme3-android/src/com/jme3/gde/android/MobileCompositeProvider.java index 95d50bd5d..ba5592fca 100644 --- a/sdk/jme3-android/src/com/jme3/gde/android/MobileCompositeProvider.java +++ b/sdk/jme3-android/src/com/jme3/gde/android/MobileCompositeProvider.java @@ -9,16 +9,11 @@ import com.jme3.gde.core.j2seproject.ProjectExtensionProperties; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; import javax.swing.JComponent; import org.netbeans.api.project.Project; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.Lookup; @@ -104,30 +99,5 @@ public class MobileCompositeProvider implements ProjectCustomizer.CompositeCateg } } - private void unZipFile(InputStream source, FileObject projectRoot) throws IOException { - try { - ZipInputStream str = new ZipInputStream(source); - ZipEntry entry; - while ((entry = str.getNextEntry()) != null) { - if (entry.isDirectory()) { - FileUtil.createFolder(projectRoot, entry.getName()); - } else { - FileObject fo = FileUtil.createData(projectRoot, entry.getName()); - writeFile(str, fo); - } - } - } finally { - source.close(); - } - } - - private void writeFile(ZipInputStream str, FileObject fo) throws IOException { - OutputStream out = fo.getOutputStream(); - try { - FileUtil.copy(str, out); - } finally { - out.close(); - } - } } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFiles.java b/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFiles.java index ae0cc4abe..757b85d86 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFiles.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFiles.java @@ -32,12 +32,21 @@ package com.jme3.gde.core.importantfiles; import org.netbeans.api.project.Project; -import org.openide.filesystems.FileObject; +import org.openide.nodes.Node; /** * * @author normenhansen */ public interface ImportantFiles { - public FileObject[] getFiles(Project proj); + /** + * should return true if given project contains files relevant to this project + */ + public boolean hasFiles(Project proj); + /** + * get the node(s) for the configuration files, can also be a node containing children + * @param proj + * @return + */ + public Node[] getNodes(Project proj); } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java b/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java index deddc3aa8..5c3865c08 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java @@ -14,9 +14,7 @@ import org.netbeans.spi.project.ui.support.NodeList; import org.openide.filesystems.FileAttributeEvent; import org.openide.filesystems.FileChangeListener; import org.openide.filesystems.FileEvent; -import org.openide.filesystems.FileObject; import org.openide.filesystems.FileRenameEvent; -import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; @@ -29,7 +27,7 @@ import org.openide.util.Lookup; * * @author normenhansen */ -public class ImportantFilesNode extends AbstractNode implements FileChangeListener{ +public class ImportantFilesNode extends AbstractNode implements FileChangeListener { private static Image smallImage = ImageUtilities.loadImage("com/jme3/gde/core/importantfiles/important.gif"); @@ -58,7 +56,7 @@ public class ImportantFilesNode extends AbstractNode implements FileChangeListen java.awt.EventQueue.invokeLater(new Runnable() { public void run() { - ((ImportantFilesChildren)getChildren()).addNotify(); + ((ImportantFilesChildren) getChildren()).addNotify(); } }); } @@ -67,7 +65,7 @@ public class ImportantFilesNode extends AbstractNode implements FileChangeListen java.awt.EventQueue.invokeLater(new Runnable() { public void run() { - ((ImportantFilesChildren)getChildren()).addNotify(); + ((ImportantFilesChildren) getChildren()).addNotify(); } }); } @@ -79,7 +77,7 @@ public class ImportantFilesNode extends AbstractNode implements FileChangeListen java.awt.EventQueue.invokeLater(new Runnable() { public void run() { - ((ImportantFilesChildren)getChildren()).addNotify(); + ((ImportantFilesChildren) getChildren()).addNotify(); } }); } @@ -88,7 +86,7 @@ public class ImportantFilesNode extends AbstractNode implements FileChangeListen java.awt.EventQueue.invokeLater(new Runnable() { public void run() { - ((ImportantFilesChildren)getChildren()).addNotify(); + ((ImportantFilesChildren) getChildren()).addNotify(); } }); } @@ -105,19 +103,18 @@ public class ImportantFilesNode extends AbstractNode implements FileChangeListen // return Lookups.fixed(new ImportantFilesLookupItem(prj)); // } // } - public static class ImportantFilesNodeFactoryImpl implements NodeFactory { public NodeList createNodes(Project project) { // ImportantFilesLookupItem item = project.getLookup().lookup(ImportantFilesLookupItem.class); // if (item != null) { - try { - ImportantFilesNode nd = new ImportantFilesNode(project); - return NodeFactorySupport.fixedNodeList(nd); - } catch (DataObjectNotFoundException ex) { - Exceptions.printStackTrace(ex); - } + try { + ImportantFilesNode nd = new ImportantFilesNode(project); + return NodeFactorySupport.fixedNodeList(nd); + } catch (DataObjectNotFoundException ex) { + Exceptions.printStackTrace(ex); + } // } return NodeFactorySupport.fixedNodeList(); @@ -129,8 +126,7 @@ public class ImportantFilesNode extends AbstractNode implements FileChangeListen // public ImportantFilesLookupItem(Project prj) { // } // } - - public static class ImportantFilesChildren extends Children.Keys { + public static class ImportantFilesChildren extends Children.Keys { private Project project; @@ -138,11 +134,12 @@ public class ImportantFilesNode extends AbstractNode implements FileChangeListen this.project = project; } - protected List createKeys() { - ArrayList list = new ArrayList(); + protected List createKeys() { + ArrayList list = new ArrayList(); for (ImportantFiles di : Lookup.getDefault().lookupAll(ImportantFiles.class)) { - FileObject[] nodes = di.getFiles(project); - list.add(nodes); + if (di.hasFiles(project)) { + list.add(di); + } } return list; } @@ -154,17 +151,8 @@ public class ImportantFilesNode extends AbstractNode implements FileChangeListen } @Override - protected Node[] createNodes(FileObject[] key) { - Node[] nodes= new Node[key.length]; - for (int i = 0; i < key.length; i++) { - FileObject fileObject = key[i]; - try { - nodes[i] = DataObject.find(fileObject).getNodeDelegate(); - } catch (DataObjectNotFoundException ex) { - nodes[i] = Node.EMPTY; - Exceptions.printStackTrace(ex); - } - } + protected Node[] createNodes(ImportantFiles key) { + Node[] nodes = key.getNodes(project); return nodes; } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/j2seproject/J2seImportantFiles.java b/sdk/jme3-core/src/com/jme3/gde/core/j2seproject/J2seImportantFiles.java index 02f308bde..04ff8a081 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/j2seproject/J2seImportantFiles.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/j2seproject/J2seImportantFiles.java @@ -8,20 +8,37 @@ import com.jme3.gde.core.importantfiles.ImportantFiles; import java.util.ArrayList; import org.netbeans.api.project.Project; import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; +import org.openide.nodes.Node; +import org.openide.util.Exceptions; /** * * @author normenhansen */ @org.openide.util.lookup.ServiceProvider(service = ImportantFiles.class) -public class J2seImportantFiles implements ImportantFiles{ +public class J2seImportantFiles implements ImportantFiles { - @Override - public FileObject[] getFiles(Project project) { - ArrayList list = new ArrayList(); -// list.add(project.getProjectDirectory().getFileObject("nbproject/project.properties")); - list.add(project.getProjectDirectory().getFileObject("build.xml")); - return list.toArray(new FileObject[list.size()]); + public Node[] getNodes(Project proj) { + FileObject obj = proj.getProjectDirectory().getFileObject("build.xml"); + if (obj == null) { + return new Node[]{Node.EMPTY}; + } + Node[] nodes = new Node[1]; + try { + nodes[0] = DataObject.find(obj).getNodeDelegate(); + nodes[0].setDisplayName("Build File"); + } catch (DataObjectNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + return nodes; + } + + public boolean hasFiles(Project proj) { + if (proj.getProjectDirectory().getFileObject("build.xml") != null) { + return true; + } + return false; } - }