From dd540f4d842f993c1d819aa991682e4bcf337174 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Sun, 27 Jan 2013 14:42:19 +0000 Subject: [PATCH] SDK: - add createAsset method to ProjectAssetManager git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10199 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../gde/core/assets/ProjectAssetManager.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java b/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java index f51829c1c..519a58d87 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java @@ -38,6 +38,7 @@ import com.jme3.asset.DesktopAssetManager; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLClassLoader; @@ -56,11 +57,14 @@ import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; 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.filesystems.FileUtil; import org.openide.filesystems.XMLFileSystem; import org.openide.util.Exceptions; import org.openide.util.Lookup; @@ -278,6 +282,50 @@ public class ProjectAssetManager extends DesktopAssetManager { }); } + public FileObject createAsset(String path) { + return createAsset(path, null); + } + + public FileObject createAsset(String path, FileObject source) { + FileObject assetFolder = getAssetFolder(); + FileObject dest = getAssetFolder().getFileObject(path); + if (dest == null) { + try { + dest = FileUtil.createData(assetFolder, path); + if (source != null) { + FileObject parent = dest.getParent(); + dest.delete(); + return source.copy(parent, source.getName(), source.getExt()); + } else { + return dest; + } + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } else { + NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation( + "File " + source.getNameExt() + " exists, overwrite?", + NotifyDescriptor.YES_NO_OPTION, + NotifyDescriptor.WARNING_MESSAGE); + Object result = DialogDisplayer.getDefault().notify(msg); + if (NotifyDescriptor.YES_OPTION.equals(result)) { + try { + if (source != null) { + FileObject parent = dest.getParent(); + dest.delete(); + return source.copy(parent, source.getName(), source.getExt()); + } else { + dest.delete(); + return FileUtil.createData(assetFolder, path); + } + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } + return null; + } + /** * Adds a locator to a folder within the main project directory */