- create unified "Configuration Files" node in project where e.g. build.xml and android MainActivity can be put
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8727 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
7bf68e691f
commit
ef9d2bc171
@ -0,0 +1,55 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.android; |
||||||
|
|
||||||
|
import com.jme3.gde.core.importantfiles.ImportantFiles; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.util.ArrayList; |
||||||
|
import org.netbeans.api.project.Project; |
||||||
|
import org.openide.filesystems.FileObject; |
||||||
|
import org.openide.util.Exceptions; |
||||||
|
import org.openide.xml.XMLUtil; |
||||||
|
import org.w3c.dom.Document; |
||||||
|
import org.xml.sax.InputSource; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author normenhansen |
||||||
|
*/ |
||||||
|
@org.openide.util.lookup.ServiceProvider(service = ImportantFiles.class) |
||||||
|
public class AndroidImportantFiles implements ImportantFiles { |
||||||
|
|
||||||
|
@Override |
||||||
|
public FileObject[] getFiles(Project project) { |
||||||
|
FileObject manifest = project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"); |
||||||
|
String mainActivity = "mobile/src"; |
||||||
|
if (manifest != null) { |
||||||
|
InputStream in = null; |
||||||
|
try { |
||||||
|
in = manifest.getInputStream(); |
||||||
|
Document configuration = XMLUtil.parse(new InputSource(in), false, false, null, null); |
||||||
|
mainActivity = "mobile/src/" + configuration.getDocumentElement().getAttribute("package").replaceAll("\\.", "/") + "/MainActivity.java"; |
||||||
|
in.close(); |
||||||
|
} catch (Exception ex) { |
||||||
|
Exceptions.printStackTrace(ex); |
||||||
|
} 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); |
||||||
|
} |
||||||
|
FileObject buildProp = project.getProjectDirectory().getFileObject("mobile/ant.properties"); |
||||||
|
if (buildProp != null) { |
||||||
|
list.add(buildProp); |
||||||
|
} |
||||||
|
return list.toArray(new FileObject[list.size()]); |
||||||
|
} |
||||||
|
} |
@ -1,160 +0,0 @@ |
|||||||
/* |
|
||||||
* To change this template, choose Tools | Templates |
|
||||||
* and open the template in the editor. |
|
||||||
*/ |
|
||||||
package com.jme3.gde.android; |
|
||||||
|
|
||||||
import java.awt.Image; |
|
||||||
import java.io.InputStream; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
import org.netbeans.api.project.Project; |
|
||||||
import org.netbeans.spi.project.LookupProvider; |
|
||||||
import org.netbeans.spi.project.ui.support.NodeFactory; |
|
||||||
import org.netbeans.spi.project.ui.support.NodeFactorySupport; |
|
||||||
import org.netbeans.spi.project.ui.support.NodeList; |
|
||||||
import org.openide.filesystems.FileObject; |
|
||||||
import org.openide.loaders.DataObject; |
|
||||||
import org.openide.loaders.DataObjectNotFoundException; |
|
||||||
import org.openide.nodes.AbstractNode; |
|
||||||
import org.openide.nodes.Children; |
|
||||||
import org.openide.nodes.Node; |
|
||||||
import org.openide.util.Exceptions; |
|
||||||
import org.openide.util.ImageUtilities; |
|
||||||
import org.openide.util.Lookup; |
|
||||||
import org.openide.util.lookup.Lookups; |
|
||||||
import org.openide.xml.XMLUtil; |
|
||||||
import org.w3c.dom.Document; |
|
||||||
import org.xml.sax.InputSource; |
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
* @author normenhansen |
|
||||||
*/ |
|
||||||
public class ImportantFilesNode extends AbstractNode { |
|
||||||
|
|
||||||
private static Image smallImage = |
|
||||||
ImageUtilities.loadImage("com/jme3/gde/android/properties/Phone_16.gif"); |
|
||||||
|
|
||||||
public ImportantFilesNode(Project proj) throws DataObjectNotFoundException { |
|
||||||
super(new ImportantFilesChildren(proj)); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String getDisplayName() { |
|
||||||
return "Android Files"; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public Image getIcon(int type) { |
|
||||||
return smallImage; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public Image getOpenedIcon(int type) { |
|
||||||
return smallImage; |
|
||||||
} |
|
||||||
|
|
||||||
public static class LookupProviderImpl implements LookupProvider { |
|
||||||
|
|
||||||
public Lookup createAdditionalLookup(Lookup lookup) { |
|
||||||
|
|
||||||
Project prj = lookup.lookup(Project.class); |
|
||||||
|
|
||||||
//create node if lookup has important files node
|
|
||||||
FileObject folder = prj.getProjectDirectory().getFileObject("mobile"); |
|
||||||
if (folder != null && folder.isFolder()) { |
|
||||||
return Lookups.fixed(new ImportantFilesLookupItem(prj)); |
|
||||||
} |
|
||||||
|
|
||||||
return Lookups.fixed(); |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static class ImportantFilesNodeFactoryImpl implements NodeFactory { |
|
||||||
|
|
||||||
public NodeList createNodes(Project project) { |
|
||||||
|
|
||||||
// this.proj = project;
|
|
||||||
|
|
||||||
//If our item is in the project's lookup,
|
|
||||||
//return a new node in the node list:
|
|
||||||
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); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//If our item isn't in the lookup,
|
|
||||||
//then return an empty list of nodes:
|
|
||||||
return NodeFactorySupport.fixedNodeList(); |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static class ImportantFilesLookupItem { |
|
||||||
|
|
||||||
public ImportantFilesLookupItem(Project prj) { |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static class ImportantFilesChildren extends Children.Keys<FileObject> { |
|
||||||
|
|
||||||
private Project project; |
|
||||||
|
|
||||||
public ImportantFilesChildren(Project project) { |
|
||||||
this.project = project; |
|
||||||
} |
|
||||||
|
|
||||||
protected List<FileObject> createKeys() { |
|
||||||
// package="com.mycompany.mygame"
|
|
||||||
FileObject manifest = project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"); |
|
||||||
String mainActivity = "mobile/src"; |
|
||||||
if (manifest != null) { |
|
||||||
InputStream in = null; |
|
||||||
try { |
|
||||||
in = manifest.getInputStream(); |
|
||||||
Document configuration = XMLUtil.parse(new InputSource(in), false, false, null, null); |
|
||||||
mainActivity = "mobile/src/" + configuration.getDocumentElement().getAttribute("package").replaceAll("\\.", "/") + "/MainActivity.java"; |
|
||||||
in.close(); |
|
||||||
} catch (Exception ex) { |
|
||||||
Exceptions.printStackTrace(ex); |
|
||||||
} finally { |
|
||||||
} |
|
||||||
} |
|
||||||
ArrayList<FileObject> list = new ArrayList<FileObject>(); |
|
||||||
addFileObject(project.getProjectDirectory().getFileObject(mainActivity), list); |
|
||||||
addFileObject(project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"), list); |
|
||||||
addFileObject(project.getProjectDirectory().getFileObject("mobile/build.properties"), list); |
|
||||||
return list; |
|
||||||
} |
|
||||||
|
|
||||||
private void addFileObject(FileObject file, List<FileObject> list) { |
|
||||||
if (file != null) { |
|
||||||
list.add(file); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void addNotify() { |
|
||||||
super.addNotify(); |
|
||||||
setKeys(createKeys()); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected Node[] createNodes(FileObject key) { |
|
||||||
try { |
|
||||||
DataObject obj = DataObject.find(key); |
|
||||||
return new Node[]{obj.getNodeDelegate()}; |
|
||||||
} catch (DataObjectNotFoundException ex) { |
|
||||||
Exceptions.printStackTrace(ex); |
|
||||||
} |
|
||||||
return new Node[]{}; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,43 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2009-2010 jMonkeyEngine |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are |
||||||
|
* met: |
||||||
|
* |
||||||
|
* * Redistributions of source code must retain the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer. |
||||||
|
* |
||||||
|
* * Redistributions in binary form must reproduce the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer in the |
||||||
|
* documentation and/or other materials provided with the distribution. |
||||||
|
* |
||||||
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||||
|
* may be used to endorse or promote products derived from this software |
||||||
|
* without specific prior written permission. |
||||||
|
* |
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.core.importantfiles; |
||||||
|
|
||||||
|
import org.netbeans.api.project.Project; |
||||||
|
import org.openide.filesystems.FileObject; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author normenhansen |
||||||
|
*/ |
||||||
|
public interface ImportantFiles { |
||||||
|
public FileObject[] getFiles(Project proj); |
||||||
|
} |
@ -0,0 +1,171 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.core.importantfiles; |
||||||
|
|
||||||
|
import java.awt.Image; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import org.netbeans.api.project.Project; |
||||||
|
import org.netbeans.spi.project.ui.support.NodeFactory; |
||||||
|
import org.netbeans.spi.project.ui.support.NodeFactorySupport; |
||||||
|
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; |
||||||
|
import org.openide.nodes.Node; |
||||||
|
import org.openide.util.Exceptions; |
||||||
|
import org.openide.util.ImageUtilities; |
||||||
|
import org.openide.util.Lookup; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author normenhansen |
||||||
|
*/ |
||||||
|
public class ImportantFilesNode extends AbstractNode implements FileChangeListener{ |
||||||
|
|
||||||
|
private static Image smallImage = |
||||||
|
ImageUtilities.loadImage("com/jme3/gde/core/importantfiles/important.gif"); |
||||||
|
|
||||||
|
public ImportantFilesNode(Project proj) throws DataObjectNotFoundException { |
||||||
|
super(new ImportantFilesChildren(proj)); |
||||||
|
proj.getProjectDirectory().addRecursiveListener(this); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getDisplayName() { |
||||||
|
return "Configuration Files"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Image getIcon(int type) { |
||||||
|
return smallImage; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Image getOpenedIcon(int type) { |
||||||
|
return smallImage; |
||||||
|
} |
||||||
|
|
||||||
|
public void fileFolderCreated(FileEvent fe) { |
||||||
|
java.awt.EventQueue.invokeLater(new Runnable() { |
||||||
|
|
||||||
|
public void run() { |
||||||
|
((ImportantFilesChildren)getChildren()).addNotify(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public void fileDataCreated(FileEvent fe) { |
||||||
|
java.awt.EventQueue.invokeLater(new Runnable() { |
||||||
|
|
||||||
|
public void run() { |
||||||
|
((ImportantFilesChildren)getChildren()).addNotify(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public void fileChanged(FileEvent fe) { |
||||||
|
} |
||||||
|
|
||||||
|
public void fileDeleted(FileEvent fe) { |
||||||
|
java.awt.EventQueue.invokeLater(new Runnable() { |
||||||
|
|
||||||
|
public void run() { |
||||||
|
((ImportantFilesChildren)getChildren()).addNotify(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public void fileRenamed(FileRenameEvent fre) { |
||||||
|
java.awt.EventQueue.invokeLater(new Runnable() { |
||||||
|
|
||||||
|
public void run() { |
||||||
|
((ImportantFilesChildren)getChildren()).addNotify(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public void fileAttributeChanged(FileAttributeEvent fae) { |
||||||
|
} |
||||||
|
|
||||||
|
// public static class LookupProviderImpl implements LookupProvider {
|
||||||
|
//
|
||||||
|
// public Lookup createAdditionalLookup(Lookup lookup) {
|
||||||
|
//
|
||||||
|
// Project prj = lookup.lookup(Project.class);
|
||||||
|
//
|
||||||
|
// 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); |
||||||
|
} |
||||||
|
// }
|
||||||
|
|
||||||
|
return NodeFactorySupport.fixedNodeList(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// public static class ImportantFilesLookupItem {
|
||||||
|
//
|
||||||
|
// public ImportantFilesLookupItem(Project prj) {
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static class ImportantFilesChildren extends Children.Keys<FileObject[]> { |
||||||
|
|
||||||
|
private Project project; |
||||||
|
|
||||||
|
public ImportantFilesChildren(Project project) { |
||||||
|
this.project = project; |
||||||
|
} |
||||||
|
|
||||||
|
protected List<FileObject[]> createKeys() { |
||||||
|
ArrayList<FileObject[]> list = new ArrayList<FileObject[]>(); |
||||||
|
for (ImportantFiles di : Lookup.getDefault().lookupAll(ImportantFiles.class)) { |
||||||
|
FileObject[] nodes = di.getFiles(project); |
||||||
|
list.add(nodes); |
||||||
|
} |
||||||
|
return list; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void addNotify() { |
||||||
|
super.addNotify(); |
||||||
|
setKeys(createKeys()); |
||||||
|
} |
||||||
|
|
||||||
|
@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); |
||||||
|
} |
||||||
|
} |
||||||
|
return nodes; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 386 B |
@ -0,0 +1,27 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.core.j2seproject; |
||||||
|
|
||||||
|
import com.jme3.gde.core.importantfiles.ImportantFiles; |
||||||
|
import java.util.ArrayList; |
||||||
|
import org.netbeans.api.project.Project; |
||||||
|
import org.openide.filesystems.FileObject; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author normenhansen |
||||||
|
*/ |
||||||
|
@org.openide.util.lookup.ServiceProvider(service = ImportantFiles.class) |
||||||
|
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()]); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue