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 ----
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