# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\projects\nb.saveas_int # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: openide/loaders/src/org/openide/text/DataEditorSupport.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\text\DataEditorSupport.java Base (1.40) --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\text\DataEditorSupport.java Locally Modified (Based On 1.40) *************** *** 29,36 **** --- 29,39 ---- import java.util.logging.Logger; import javax.swing.text.*; import org.netbeans.api.queries.FileEncodingQuery; + import org.netbeans.modules.openide.loaders.DataObjectAccessor; import org.netbeans.modules.openide.loaders.UIException; import org.openide.*; + import org.openide.cookies.OpenCookie; + import org.openide.loaders.SaveAsCapable; import org.openide.filesystems.*; import org.openide.loaders.*; import org.openide.nodes.*; *************** *** 349,354 **** --- 352,462 ---- return (DataObject)l.getLookup ().lookup (DataObject.class); } + /** + * Save the document under a new file name and/or extension. + * @throws java.io.IOException If the operation failed + * @since 6.2 + */ + public void saveAs( FileObject newFileName ) throws IOException { + if( env instanceof Env ) { + + FileObject newFolder = newFileName.getParent(); + //ask the user for a new file name to save to + String newExtension = newFileName.getExt(); + + DataObject newDob = null; + DataObject currentDob = getDataObject(); + if( !currentDob.isModified() || null == getDocument() ) { + //the document is not modified on disk, we copy/rename the file + DataFolder df = DataFolder.findFolder( newFolder ); + //remove the target file if it already exists + newFileName.delete(); + + newDob = DataObjectAccessor.DEFAULT.copyRename( currentDob, df, newFileName.getName(), newExtension ); + } else { + //the document is modified in editor, we need to save the editor kit instead + + saveDocumentAs( newFileName.getOutputStream() ); + currentDob.setModified( false ); + newDob = DataObject.find( newFileName ); + } + + if( null != newDob ) { + //TODO open the document at the position of the original document when #94607 is implemented + OpenCookie c = newDob.getCookie( OpenCookie.class ); + if( null != c ) { + //close the original document + close( false ); + //open the new one + c.open(); + } + } + } + } + + /** + * Save the document to a new file. + * @param output + * @exception IOException on I/O error + */ + private void saveDocumentAs( final OutputStream output ) throws IOException { + + final StyledDocument myDoc = getDocument(); + + // save the document as a reader + class SaveAsWriter implements Runnable { + private IOException ex; + + public void run() { + try { + OutputStream os = null; + + try { + os = new BufferedOutputStream( output ); + saveFromKitToStream( myDoc, os ); + + os.close(); // performs firing + os = null; + + } catch( BadLocationException ex ) { + ERR.log( Level.INFO, null, ex ); + } finally { + if (os != null) { // try to close if not yet done + os.close(); + } + } + } catch (IOException e) { + this.ex = e; + } + } + + public void after() throws IOException { + if (ex != null) { + throw ex; + } + } + } + + SaveAsWriter saveAsWriter = new SaveAsWriter(); + myDoc.render(saveAsWriter); + saveAsWriter.after(); + } + + /** + * Save the document to given stream + * @param myDoc + * @param os + * @throws IOException + * @throws BadLocationException + */ + private void saveFromKitToStream( StyledDocument myDoc, OutputStream os ) throws IOException, BadLocationException { + // Note: there's no new kit getting created, the method actually caches + // previously created kit and has just a funny name + final EditorKit kit = createEditorKit(); + + saveFromKitToStream( myDoc, kit, os ); + } + /** Environment that connects the data object and the CloneableEditorSupport. */ public static abstract class Env extends OpenSupport.Env implements CloneableEditorSupport.Env { *************** *** 374,380 **** --- 482,494 ---- */ public Env (DataObject obj) { super (obj); + if( null == obj.getLookup().lookup( SaveAsCapable.class ) + && obj instanceof MultiDataObject + && obj.getLoader() instanceof UniFileLoader ) { + CookieSet cs = DataObjectAccessor.DEFAULT.getCookieSet( (MultiDataObject)obj ); + cs.assign( SaveAsCapable.class, new SaveAsCapableImpl() ); } + } /** Getter for the file to work on. * @return the file *************** *** 614,619 **** --- 728,742 ---- ois.defaultReadObject (); warned = true; } + + private class SaveAsCapableImpl implements SaveAsCapable { + public void saveAs(FileObject newFileName) throws IOException { + CloneableOpenSupport cos = Env.super.findCloneableOpenSupport(); + if (cos instanceof DataEditorSupport) { + ((DataEditorSupport)cos).saveAs( newFileName ); + } + } + } } // end of Env /** Listener on file object that notifies the Env object Index: openide/loaders/src/org/openide/loaders/Bundle.properties *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\Bundle.properties Base (1.19) --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\Bundle.properties Locally Modified (Based On 1.19) *************** *** 305,307 **** --- 305,312 ---- This file appears to contain binary data. \ Are you sure you want to open it in the text editor? MSG_BinaryFileWarning=Binary File Detected + + CTL_SaveAsAction=Sa&ve As + MSG_SaveAsFailed=Save As action failed. + LBL_SaveAsTitle=Save As + MSG_CannotCreateTargetFolder=Cannot create the target folder. Index: openide/loaders/src/org/openide/loaders/MultiDataObject.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\MultiDataObject.java Base (1.27) --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\MultiDataObject.java Locally Modified (Based On 1.27) *************** *** 712,717 **** --- 712,728 ---- } } + @Override + protected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException { + if( getLoader() instanceof UniFileLoader ) { + //allow the operation for single file DataObjects + FileObject fo = getPrimaryEntry().copyRename (df.getPrimaryFile (), name, ext); + return DataObject.find( fo ); + } + + throw new IOException( "SaveAs operation not supported for this file type." ); + } + /** Set the set of cookies. * To the provided cookie set a listener is attached, * and any change to the set is propagated by *************** *** 1089,1094 **** --- 1100,1118 ---- */ public abstract FileObject createFromTemplate (FileObject f, String name) throws IOException; + /** + * Called when the entry is to be copied and renamed. + * @param f the folder to create this entry in + * @param name new file name + * @param ext new file extension + * @return the copied and renamed FileObject, never null + * @exception IOException when the operation fails + * @since 6.2 + */ + public FileObject copyRename (FileObject f, String name, String ext) throws IOException { + throw new IOException( "Unsupported operation" ); + } + /** Try to lock this file entry. * @return the lock if the operation was successful; otherwise null * @throws IOException if the lock could not be taken Index: openide/loaders/src/org/openide/loaders/DataObjectAccessorImpl.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\DataObjectAccessorImpl.java No Base Revision --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\DataObjectAccessorImpl.java Locally New *************** *** 1,0 **** --- 1,41 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + + package org.openide.loaders; + + import java.io.IOException; + import org.netbeans.modules.openide.loaders.DataObjectAccessor; + import org.openide.nodes.CookieSet; + + /** + * API trampoline to access package private methods in DataObject class. + * @since 6.2 + * @author S. Aubrecht + */ + final class DataObjectAccessorImpl extends DataObjectAccessor { + + public DataObject copyRename( DataObject dob, DataFolder f, String name, String ext ) throws IOException { + return dob.copyRename( f, name, ext ); + } + + public CookieSet getCookieSet(MultiDataObject dob) { + return dob.getCookieSet(); + } + } Index: core/ui/src/org/netbeans/core/ui/resources/layer.xml *** D:\projects\nb.saveas_int\core\ui\src\org\netbeans\core\ui\resources\layer.xml Base (1.118) --- D:\projects\nb.saveas_int\core\ui\src\org\netbeans\core\ui\resources\layer.xml Locally Modified (Based On 1.118) *************** *** 61,66 **** --- 61,67 ---- + *************** *** 113,119 **** ! --- 114,122 ---- ! ! ! Index: openide/loaders/src/org/openide/loaders/DataObject.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\DataObject.java Base (1.35) --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\DataObject.java Locally Modified (Based On 1.35) *************** *** 27,32 **** --- 27,33 ---- import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.event.*; + import org.netbeans.modules.openide.loaders.DataObjectAccessor; import org.openide.filesystems.*; import org.openide.nodes.*; import org.openide.util.*; *************** *** 114,119 **** --- 115,124 ---- /** default logger for whole package */ static final Logger LOG = Logger.getLogger("org.openide.loaders"); // NOI18N + static { + DataObjectAccessor.DEFAULT = new DataObjectAccessorImpl(); + } + /** Create a new data object. * * @param pf primary file object for this data object *************** *** 528,533 **** --- 533,570 ---- */ protected abstract DataObject handleCopy (DataFolder f) throws IOException; + /** Copy this object to a folder under a different name and file extension. + * The copy of the object is required to be deletable and movable. + *

An event is fired, and atomicity is implemented. + * @param f the folder to copy the object to + * @exception IOException if something went wrong + * @return the new object + */ + final DataObject copyRename (final DataFolder f, final String name, final String ext) throws IOException { + final DataObject[] result = new DataObject[1]; + invokeAtomicAction (f.getPrimaryFile (), new FileSystem.AtomicAction () { + public void run () throws IOException { + result[0] = handleCopyRename (f, name, ext); + } + }, null); + fireOperationEvent ( + new OperationEvent(result[0]), OperationEvent.CREATE + ); + return result[0]; + } + /** + * Copy and rename this object to a folder (implemented by subclasses). + * @param f target folder + * @param name new file name + * @param ext new file extension + * @return the new data object + * @exception IOException if an error occures or the file cannot be copied/renamed + * @since 6.2 + */ + protected DataObject handleCopyRename (DataFolder f, String name, String ext) throws IOException { + throw new IOException( "Unsupported operation" ); //NOI18N + } + /** Delete this object. *

Events are fired and atomicity is implemented. * @exception IOException if an error occures Index: openide/loaders/src/org/netbeans/modules/openide/loaders/DataObjectAccessor.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\netbeans\modules\openide\loaders\DataObjectAccessor.java No Base Revision --- D:\projects\nb.saveas_int\openide\loaders\src\org\netbeans\modules\openide\loaders\DataObjectAccessor.java Locally New *************** *** 1,0 **** --- 1,52 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + package org.netbeans.modules.openide.loaders; + + import java.io.IOException; + import org.openide.loaders.DataFolder; + import org.openide.loaders.DataObject; + import org.openide.loaders.MultiDataObject; + import org.openide.nodes.CookieSet; + + /** + * API trampoline to access package private methods in DataObject class. + * + * @since 6.2 + * @author S. Aubrecht + */ + public abstract class DataObjectAccessor { + + public static DataObjectAccessor DEFAULT; + + static { + // invokes static initializer of Item.class + // that will assign value to the DEFAULT field above + Class c = DataObject.class; + try { + Class.forName(c.getName(), true, c.getClassLoader()); + } catch (ClassNotFoundException ex) { + assert false : ex; + } + // assert DEFAULT != null : "The DEFAULT field must be initialized"; + } + + public abstract DataObject copyRename( DataObject dob, DataFolder f, String name, String ext ) throws IOException; + + public abstract CookieSet getCookieSet( MultiDataObject dob ); + } Index: form/src/org/netbeans/modules/form/FormDataObject.java *** D:\projects\nb.saveas_int\form\src\org\netbeans\modules\form\FormDataObject.java Base (1.49) --- D:\projects\nb.saveas_int\form\src\org\netbeans\modules\form\FormDataObject.java Locally Modified (Based On 1.49) *************** *** 20,31 **** --- 20,35 ---- package org.netbeans.modules.form; + import java.io.IOException; import org.openide.cookies.EditCookie; import org.openide.cookies.OpenCookie; import org.openide.filesystems.FileObject; + import org.openide.loaders.DataFolder; + import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectExistsException; import org.openide.loaders.FileEntry; import org.openide.loaders.MultiDataObject; + import org.openide.loaders.SaveAsCapable; import org.openide.nodes.Node; import org.openide.nodes.Node.Cookie; *************** *** 64,70 **** --- 68,79 ---- { super(jfo, loader); formEntry = (FileEntry)registerEntry(ffo); + getCookieSet().assign( SaveAsCapable.class, new SaveAsCapable() { + public void saveAs(FileObject newFileName) throws IOException { + getFormEditorSupport().saveAs( newFileName ); } + }); + } //-------------------------------------------------------------------- // Other methods *************** *** 149,155 **** --- 158,171 ---- is.defaultReadObject(); } + @Override + protected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException { + FileObject fo = getPrimaryEntry().copyRename (df.getPrimaryFile (), name, ext); + return DataObject.find( fo ); } + + } Index: openide/loaders/src/org/openide/loaders/SaveAsCapable.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\SaveAsCapable.java No Base Revision --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\SaveAsCapable.java Locally New *************** *** 1,0 **** --- 1,38 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + package org.openide.loaders; + + import java.io.IOException; + import org.openide.filesystems.FileObject; + + + /** + * Save document under a different file name and/or extension. + * + * @since 7.1 + * @author S. Aubrecht + */ + public interface SaveAsCapable { + /** + * Invoke the save operation. + * @param newFileName File name to save to. + * @throws IOException if the object could not be saved + */ + void saveAs( FileObject newFileName ) throws IOException; + } Index: openide/loaders/src/org/openide/loaders/DefaultDataObject.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\DefaultDataObject.java Base (1.12) --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\DefaultDataObject.java Locally Modified (Based On 1.12) *************** *** 127,132 **** --- 127,138 ---- return super.handleCreateFromTemplate (df, name); } + @Override + protected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException { + FileObject fo = getPrimaryEntry ().copyRename (df.getPrimaryFile (), name, ext); + return DataObject.find( fo ); + } + /** Either opens the in text editor or asks user questions. */ public void open() { Index: java/source/src/org/netbeans/modules/java/JavaDataObject.java *** D:\projects\nb.saveas_int\java\source\src\org\netbeans\modules\java\JavaDataObject.java Base (1.3) --- D:\projects\nb.saveas_int\java\source\src\org\netbeans\modules\java\JavaDataObject.java Locally Modified (Based On 1.3) *************** *** 36,44 **** --- 36,47 ---- import org.openide.cookies.SaveCookie; import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; + import org.openide.loaders.DataFolder; + import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectExistsException; import org.openide.loaders.MultiDataObject; import org.openide.loaders.MultiFileLoader; + import org.openide.loaders.SaveAsCapable; import org.openide.nodes.Node; import org.openide.nodes.Node.Cookie; import org.openide.text.CloneableEditor; *************** *** 65,70 **** --- 68,81 ---- return super.getCookie(type); } + protected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException { + String originalName = getName(); + FileObject fo = getPrimaryEntry ().copyRename (df.getPrimaryFile (), name, ext); + DataObject dob = DataObject.find( fo ); + //TODO invoke refactoring here + return dob; + } + private synchronized JavaEditorSupport createJavaEditorSupport () { if (jes == null) { jes = new JavaEditorSupport (this); *************** *** 89,95 **** --- 100,111 ---- public Environment(JavaDataObject obj) { super(obj); + obj.getCookieSet().assign( SaveAsCapable.class, new SaveAsCapable() { + public void saveAs( FileObject newFileName ) throws IOException { + ((JavaEditorSupport)findCloneableOpenSupport()).saveAs( newFileName ); } + }); + } protected FileObject getFile() { return this.getDataObject().getPrimaryFile(); Index: openide/loaders/src/org/openide/loaders/FileEntry.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\FileEntry.java Base (1.5) --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\FileEntry.java Locally Modified (Based On 1.5) *************** *** 51,56 **** --- 51,62 ---- return fo.copy (f, newName, fo.getExt ()); } + @Override + public FileObject copyRename(FileObject f, String name, String ext) throws IOException { + FileObject fo = getFile(); + return fo.copy (f, name, ext); + } + /* Renames underlying fileobject. This implementation return the * same file. * Index: openide/loaders/src/org/openide/actions/SaveAsAction.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\actions\SaveAsAction.java No Base Revision --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\actions\SaveAsAction.java Locally New *************** *** 1,0 **** --- 1,183 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + package org.openide.actions; + + import java.awt.event.ActionEvent; + import java.beans.PropertyChangeEvent; + import java.beans.PropertyChangeListener; + import java.io.File; + import java.io.IOException; + import java.util.Collection; + import javax.swing.AbstractAction; + import javax.swing.Action; + import javax.swing.JFileChooser; + import javax.swing.SwingUtilities; + import org.openide.DialogDisplayer; + import org.openide.NotifyDescriptor; + import org.openide.filesystems.FileObject; + import org.openide.filesystems.FileUtil; + import org.openide.loaders.SaveAsCapable; + import org.openide.loaders.DataObject; + import org.openide.util.ContextAwareAction; + import org.openide.util.Lookup; + import org.openide.util.LookupEvent; + import org.openide.util.LookupListener; + import org.openide.util.NbBundle; + import org.openide.util.Utilities; + import org.openide.windows.TopComponent; + import org.openide.windows.WindowManager; + + /** + * Action to save document under a different file name and/or extension. + * The action is enabled for editor windows only. + * + * @since 6.2 + * @author S. Aubrecht + */ + final public class SaveAsAction extends AbstractAction implements ContextAwareAction, LookupListener, PropertyChangeListener { + + private Lookup context; + private Lookup.Result lkpInfo; + + public SaveAsAction() { + this( Utilities.actionsGlobalContext() ); + TopComponent.getRegistry().addPropertyChangeListener( this ); + } + + private SaveAsAction( Lookup context ) { + super( NbBundle.getMessage(DataObject.class, "CTL_SaveAsAction") ); //NOI18N + this.context = context; + putValue("noIconInMenu", Boolean.TRUE); //NOI18N + } + + void init() { + assert SwingUtilities.isEventDispatchThread() + : "this shall be called just from AWT thread"; + + if (lkpInfo != null) { + return; + } + + //The thing we want to listen for the presence or absence of + //on the global selection + Lookup.Template tpl = new Lookup.Template(SaveAsCapable.class); + lkpInfo = context.lookup (tpl); + lkpInfo.addLookupListener(this); + resultChanged(null); + } + + public boolean isEnabled() { + init(); + return super.isEnabled(); + } + + public void actionPerformed(ActionEvent e) { + init(); + Collection inst = lkpInfo.allInstances(); + if( inst.size() > 0 ) { + SaveAsCapable saveAs = inst.iterator().next(); + File newFile = getNewFileName(); + if( null != newFile ) { + FileObject newFolder = FileUtil.toFileObject( newFile.getParentFile() ); + FileObject newFileObj = FileUtil.toFileObject( newFile ); + try { + if( null == newFileObj ) { + String newFilename = getFileName( newFile ); + String newExtension = FileUtil.getExtension( newFile.getName() ); + newFileObj = newFolder.createData( newFilename, newExtension ); + } + saveAs.saveAs( newFileObj ); + } catch( IOException ioE ) { + ioE.printStackTrace(); + } + } + } + } + + /** + * Get the name part without the extension of the given file + * @param file + * @return name part of the given file + */ + private static String getFileName( File file ) { + String fileName = file.getName(); + int index = fileName.lastIndexOf( '.' ); + if( index > 0 ) + return fileName.substring( 0, index ); + return fileName; + } + + + public void resultChanged(LookupEvent ev) { + TopComponent tc = TopComponent.getRegistry().getActivated(); + + setEnabled (lkpInfo.allItems().size() != 0 && null != tc && WindowManager.getDefault().isEditorTopComponent( tc ) ); + } + + /** + * Show file 'save as' dialog window to ask user for a new file name. + * @return File selected by the user or null if no file was selected. + */ + private File getNewFileName() { + File newFile = null; + FileObject currentFileObject = null;//((Env)env).getFile(); + if( null != currentFileObject ) + newFile = FileUtil.toFile( currentFileObject ); + + JFileChooser chooser = new JFileChooser(); + chooser.setDialogTitle( NbBundle.getMessage(DataObject.class, "LBL_SaveAsTitle" ) ); //NOI18N + chooser.setMultiSelectionEnabled( false ); + if( null != newFile ) + chooser.setSelectedFile( newFile ); + File origFile = newFile; + if( JFileChooser.APPROVE_OPTION != chooser.showSaveDialog( WindowManager.getDefault().getMainWindow() ) ) { + return null; + } + newFile = chooser.getSelectedFile(); + if( null == newFile || newFile.equals( origFile ) ) + return null; + + //create target folder if necessary + File targetFolder = newFile.getParentFile(); + if( !targetFolder.exists() ) + targetFolder.mkdirs(); + FileObject targetFileObjectFolder = FileUtil.toFileObject( targetFolder ); + if( null == targetFileObjectFolder ) { + NotifyDescriptor error = new NotifyDescriptor( + NbBundle.getMessage(DataObject.class, "MSG_CannotCreateTargetFolder"), //NOI18N + NbBundle.getMessage(DataObject.class, "LBL_SaveAsTitle"), //NOI18N + NotifyDescriptor.DEFAULT_OPTION, + NotifyDescriptor.ERROR_MESSAGE, + new Object[] {NotifyDescriptor.OK_OPTION}, + NotifyDescriptor.OK_OPTION ); + DialogDisplayer.getDefault().notify( error ); + return null; + } + return newFile; + } + + public Action createContextAwareInstance(Lookup actionContext) { + return new SaveAsAction( actionContext ); + } + + public void propertyChange(PropertyChangeEvent arg0) { + resultChanged( null ); + } + } +