@ -70,29 +70,29 @@ public final class ImportModel implements ActionListener {
}
}
private void copyModel ( WizardDescriptor wiz ) {
private void copyModel ( WizardDescriptor wiz ) {
// List<AssetKey> keyList = (List<AssetKey>) wiz.getProperty("assetlist");
// String path = (String) wiz.getProperty("path");
AssetKey key = ( AssetKey ) wiz . getProperty ( "mainkey" ) ;
AssetKey key = ( AssetKey ) wiz . getProperty ( "mainkey" ) ;
boolean keepFiles = ( Boolean ) wiz . getProperty ( "keepfiles" ) ;
boolean keepFiles = ( Boolean ) wiz . getProperty ( "keepfiles" ) ;
List < AssetKey > keyList = ( List < AssetKey > ) wiz . getProperty ( "assetlist" ) ;
List < FileObject > assetList = ( List < FileObject > ) wiz . getProperty ( "assetfiles" ) ;
String path = ( String ) wiz . getProperty ( "path" ) ;
String importPath = ( String ) wiz . getProperty ( "destpath" ) ;
String importPath = ( String ) wiz . getProperty ( "destpath" ) ;
ProjectAssetManager manager = context . getLookup ( ) . lookup ( ProjectAssetManager . class ) ;
ProjectAssetManager manager = context . getLookup ( ) . lookup ( ProjectAssetManager . class ) ;
if ( manager = = null ) {
if ( manager = = null ) {
throw new IllegalStateException ( "Cannot find project AssetManager!" ) ;
throw new IllegalStateException ( "Cannot find project AssetManager!" ) ;
}
}
List < FileObject > deleteList = new LinkedList < FileObject > ( ) ;
List < FileObject > deleteList = new LinkedList < FileObject > ( ) ;
for ( Iterator < AssetKey > it = keyList . iterator ( ) ; it . hasNext ( ) ; ) {
for ( Iterator < FileObject > it = assetList . iterator ( ) ; it . hasNext ( ) ; ) {
AssetKey assetKey = it . next ( ) ;
FileObject source = it . next ( ) ;
File file = new File ( path + "/" + assetKey . getFolder ( ) + assetKey . getName ( ) ) ;
if ( file . exists ( ) ) {
FileObject source = FileUtil . toFileObject ( file ) ;
File destFolder = new File ( manager . getAssetFolderName ( ) + "/" + importPath + "/" + assetKey . getFolder ( ) + "/" ) ;
destFolder . mkdirs ( ) ;
FileObject dest = FileUtil . toFileObject ( destFolder ) ;
try {
try {
String folderName = importPath + "/" + manager . getRelativeAssetPath ( source . getParent ( ) . getPath ( ) ) ;
FileObject dest = manager . getAssetFolder ( ) . getFileObject ( folderName ) ;
if ( dest = = null ) {
dest = FileUtil . createFolder ( manager . getAssetFolder ( ) , folderName ) ;
}
FileObject fileObj = dest . getFileObject ( source . getName ( ) , source . getExt ( ) ) ;
FileObject fileObj = dest . getFileObject ( source . getName ( ) , source . getExt ( ) ) ;
if ( fileObj ! = null ) {
if ( fileObj ! = null ) {
NotifyDescriptor . Confirmation msg = new NotifyDescriptor . Confirmation (
NotifyDescriptor . Confirmation msg = new NotifyDescriptor . Confirmation (
"File " + source . getNameExt ( ) + " exists, overwrite?" ,
"File " + source . getNameExt ( ) + " exists, overwrite?" ,
NotifyDescriptor . YES_NO_OPTION ,
NotifyDescriptor . YES_NO_OPTION ,
NotifyDescriptor . WARNING_MESSAGE ) ;
NotifyDescriptor . WARNING_MESSAGE ) ;
Object result = DialogDisplayer . getDefault ( ) . notify ( msg ) ;
Object result = DialogDisplayer . getDefault ( ) . notify ( msg ) ;
@ -104,19 +104,25 @@ public final class ImportModel implements ActionListener {
} else {
} else {
fileObj = source . copy ( dest , source . getName ( ) , source . getExt ( ) ) ;
fileObj = source . copy ( dest , source . getName ( ) , source . getExt ( ) ) ;
}
}
if ( fileObj ! = null ) {
DataObject obj = DataObject . find ( fileObj ) ;
AssetData data = obj . getLookup ( ) . lookup ( AssetData . class ) ;
if ( data ! = null ) {
AssetKey assetKey = data . getAssetKey ( ) ;
if ( ! ( assetKey instanceof TextureKey ) & & fileObj ! = null ) {
if ( ! ( assetKey instanceof TextureKey ) & & fileObj ! = null ) {
deleteList . add ( fileObj ) ;
deleteList . add ( fileObj ) ;
}
}
}
}
} catch ( Exception ex ) {
} catch ( Exception ex ) {
Exceptions . printStackTrace ( ex ) ;
Exceptions . printStackTrace ( ex ) ;
}
}
}
}
}
File file = new File ( manager . getAssetFolderName ( ) + "/" + importPath + "/" + key . getName ( ) ) ;
FileObject file = manager . getAssetFolder ( ) . getFileObject ( importPath + "/" + key . getName ( ) ) ;
// File outFile = new File(manager.getAssetFolderName() + "/" + importPath + "/" + key.getName().replaceAll(key.getExtension(), "j3o"));
DataObject targetModel ;
DataObject targetModel ;
try {
try {
targetModel = DataObject . find ( FileUtil . toFileObject ( file ) ) ;
targetModel = DataObject . find ( file ) ;
if ( targetModel instanceof SpatialAssetDataObject ) {
if ( targetModel instanceof SpatialAssetDataObject ) {
//TODO: wtf? why do i have to add the assetmanager?
//TODO: wtf? why do i have to add the assetmanager?
( ( SpatialAssetDataObject ) targetModel ) . getLookupContents ( ) . add ( manager ) ;
( ( SpatialAssetDataObject ) targetModel ) . getLookupContents ( ) . add ( manager ) ;
@ -128,8 +134,6 @@ public final class ImportModel implements ActionListener {
}
}
data . saveAsset ( ) ;
data . saveAsset ( ) ;
// BinaryExporter exp = BinaryExporter.getInstance();
// exp.save(spat, outFile);
}
}
} catch ( Exception ex ) {
} catch ( Exception ex ) {
Exceptions . printStackTrace ( ex ) ;
Exceptions . printStackTrace ( ex ) ;