@ -70,53 +70,59 @@ 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 ( ) ) ;
try {
if ( file . exists ( ) ) {
String folderName = importPath + "/" + manager . getRelativeAssetPath ( source . getParent ( ) . getPath ( ) ) ;
FileObject source = FileUtil . toFileObject ( file ) ;
FileObject dest = manager . getAssetFolder ( ) . getFileObject ( folderName ) ;
File destFolder = new File ( manager . getAssetFolderName ( ) + "/" + importPath + "/" + assetKey . getFolder ( ) + "/" ) ;
if ( dest = = null ) {
destFolder . mkdirs ( ) ;
dest = FileUtil . createFolder ( manager . getAssetFolder ( ) , folderName ) ;
FileObject dest = FileUtil . toFileObject ( destFolder ) ;
}
try {
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 ) ;
if ( NotifyDescriptor . YES_OPTION . equals ( result ) ) {
if ( NotifyDescriptor . YES_OPTION . equals ( result ) ) {
fileObj . delete ( ) ;
fileObj . delete ( ) ;
fileObj = source . copy ( dest , source . getName ( ) , source . getExt ( ) ) ;
} else {
}
} else {
fileObj = source . copy ( dest , source . getName ( ) , source . getExt ( ) ) ;
fileObj = source . copy ( dest , source . getName ( ) , source . getExt ( ) ) ;
} else {
}
}
if ( ! ( assetKey instanceof TextureKey ) & & fileObj ! = null ) {
} else {
deleteList . add ( fileObj ) ;
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 ) {
deleteList . add ( fileObj ) ;
}
}
}
} catch ( Exception ex ) {
Exceptions . printStackTrace ( ex ) ;
}
}
} catch ( Exception ex ) {
Exceptions . printStackTrace ( ex ) ;
}
}
}
}
File file = new File ( manager . getAssetFolderName ( ) + "/" + importPath + "/" + key . getName ( ) ) ;
// File outFile = new File(manager.getAssetFolderName() + "/" + importPath + "/" + key.getName().replaceAll(key.getExtension(), "j3o"));
FileObject file = manager . getAssetFolder ( ) . getFileObject ( importPath + "/" + key . getName ( ) ) ;
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 ) ;