- 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
3.0
nor..67 13 years ago
parent b5dccedb0b
commit 76fef5cbae
  1. 48
      sdk/jme3-android/src/com/jme3/gde/android/AndroidImportantFiles.java
  2. 30
      sdk/jme3-android/src/com/jme3/gde/android/MobileCompositeProvider.java
  3. 13
      sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFiles.java
  4. 50
      sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java
  5. 31
      sdk/jme3-core/src/com/jme3/gde/core/j2seproject/J2seImportantFiles.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<FileObject> list = new ArrayList<FileObject>();
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<Node> list = new ArrayList<Node>();
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;
}
}

@ -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();
}
}
}
}

@ -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);
}

@ -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<FileObject[]> {
public static class ImportantFilesChildren extends Children.Keys<ImportantFiles> {
private Project project;
@ -138,11 +134,12 @@ public class ImportantFilesNode extends AbstractNode implements FileChangeListen
this.project = project;
}
protected List<FileObject[]> createKeys() {
ArrayList<FileObject[]> list = new ArrayList<FileObject[]>();
protected List<ImportantFiles> createKeys() {
ArrayList<ImportantFiles> list = new ArrayList<ImportantFiles>();
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;
}
}

@ -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<FileObject> list = new ArrayList<FileObject>();
// 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;
}
}

Loading…
Cancel
Save