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/manifest.mf
*** D:\projects\nb.saveas_int\openide\loaders\manifest.mf Base (1.30)
--- D:\projects\nb.saveas_int\openide\loaders\manifest.mf Locally Modified (Based On 1.30)
***************
*** 1,5 ****
Manifest-Version: 1.0
OpenIDE-Module: org.openide.loaders
! OpenIDE-Module-Specification-Version: 6.1
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
--- 1,5 ----
Manifest-Version: 1.0
OpenIDE-Module: org.openide.loaders
! OpenIDE-Module-Specification-Version: 6.2
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
Index: openide/loaders/src/org/openide/loaders/OperationEvent.java
*** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\OperationEvent.java Base (1.6)
--- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\OperationEvent.java Locally Modified (Based On 1.6)
***************
*** 21,27 ****
import java.util.EventObject;
- import org.openide.util.Lookup;
import org.openide.filesystems.FileObject;
/** Event that describes operations taken on
--- 21,26 ----
***************
*** 31,37 ****
*/
public class OperationEvent extends EventObject {
/** package private numbering of methods */
! static final int COPY = 1, MOVE = 2, DELETE = 3, RENAME = 4, SHADOW = 5, TEMPL = 6, CREATE = 7;
/** data object */
private DataObject obj;
--- 30,36 ----
*/
public class OperationEvent extends EventObject {
/** package private numbering of methods */
! static final int COPY = 1, MOVE = 2, DELETE = 3, RENAME = 4, SHADOW = 5, TEMPL = 6, CREATE = 7, COPY_RENAME = 8;
/** data object */
private DataObject obj;
***************
*** 149,155 ****
--- 148,187 ----
sb.append(orig);
}
}
+
+ /**
+ * Notification of a copy+rename action of a data object.
+ * @since 6.2
+ */
+ public static final class CopyRename extends OperationEvent {
+ /** original data object */
+ private DataObject orig;
+
+ static final long serialVersionUID =-1L;
+ /** @param obj renamed object
+ * @param orig original object
+ */
+ CopyRename (DataObject obj, DataObject orig) {
+ super (obj);
+ this.orig = orig;
}
+
+
+ /** Get the original data object.
+ * @return the data object
+ */
+ public DataObject getOriginalDataObject () {
+ return orig;
+ }
+
+
+ final void writeDebug(StringBuffer sb) {
+ sb.append(" originalobj: ");
+ sb.append(orig);
+ }
+ }
+ }
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,37 ----
+ /*
+ * 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;
+
+ /**
+ * 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 );
+ }
+
+ }
Index: openide/loaders/src/org/openide/loaders/DataLoaderPool.java
*** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\DataLoaderPool.java Base (1.31)
--- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\DataLoaderPool.java Locally Modified (Based On 1.31)
***************
*** 212,217 ****
--- 212,220 ----
case OperationEvent.CREATE:
l.operationPostCreate (ev);
break;
+ case OperationEvent.COPY_RENAME:
+ l.operationCopyRename ((OperationEvent.CopyRename)ev);
+ break;
}
}
}
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.CopyRename (result[0], this), OperationEvent.COPY_RENAME + ); + 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/openide/loaders/ShadowChangeAdapter.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\ShadowChangeAdapter.java Base (1.5) --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\ShadowChangeAdapter.java Locally Modified (Based On 1.5) *************** *** 21,27 **** import java.util.EventObject; - import org.openide.util.Lookup; import org.openide.filesystems.*; /** Adapter for listening on changes of fileobjects and refreshing data --- 21,26 ---- *************** *** 103,109 **** --- 102,118 ---- checkBrokenDataShadows(ev); } + /** + * Object has been successfully copied and renamed. + * @param ev event describing the action + * @since 6.2 + */ + public void operationCopyRename(OperationEvent.CopyRename ev) { + checkDataShadows(ev); + checkBrokenDataShadows(ev); } + } 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,49 ---- + /* + * 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; + + /** + * 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; + + } 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,28 **** --- 20,31 ---- 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; *************** *** 149,155 **** --- 152,165 ---- 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/nodes/nbproject/project.properties *** D:\projects\nb.saveas_int\openide\nodes\nbproject\project.properties Base (1.10) --- D:\projects\nb.saveas_int\openide\nodes\nbproject\project.properties Locally Modified (Based On 1.10) *************** *** 22,25 **** javadoc.arch=${basedir}/../arch/arch-openide-nodes.xml javadoc.apichanges=${basedir}/apichanges.xml ! spec.version.base=7.0 --- 22,25 ---- javadoc.arch=${basedir}/../arch/arch-openide-nodes.xml javadoc.apichanges=${basedir}/apichanges.xml ! spec.version.base=7.1 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: openide/loaders/src/org/openide/loaders/OperationAdapter.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\OperationAdapter.java Base (1.3) --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\OperationAdapter.java Locally Modified (Based On 1.3) *************** *** 51,57 **** --- 51,62 ---- /* Empty implementation */ public void operationCreateFromTemplate (OperationEvent.Copy ev) { } + + /* Empty implementation */ + public void operationCopyRename (OperationEvent.CopyRename ev) { } + } 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,41 **** --- 36,43 ---- 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; *************** *** 65,70 **** --- 67,80 ---- 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); 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/loaders/OperationListener.java *** D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\OperationListener.java Base (1.3) --- D:\projects\nb.saveas_int\openide\loaders\src\org\openide\loaders\OperationListener.java Locally Modified (Based On 1.3) *************** *** 64,67 **** --- 64,74 ---- * @param ev event describing the action */ public void operationCreateFromTemplate (OperationEvent.Copy ev); + + /** + * Object has been successfully copied and renamed. + * @param ev event describing the action + * @since 6.2 + */ + public void operationCopyRename (OperationEvent.CopyRename ev); } 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,85 ---- + /* + * 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.io.IOException; + import java.util.logging.Level; + import java.util.logging.Logger; + import org.openide.cookies.SaveAsCookie; + import org.openide.loaders.DataObject; + import org.openide.nodes.Node; + import org.openide.util.HelpCtx; + import org.openide.util.NbBundle; + import org.openide.util.actions.NodeAction; + 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 + */ + public final class SaveAsAction extends NodeAction { + + @Override + protected void initialize() { + super.initialize(); + putValue("noIconInMenu", Boolean.TRUE); //NOI18N + //TODO add listener to topcomponent.registry? + } + + @Override + protected void performAction(Node[] activatedNodes) { + SaveAsCookie c = (SaveAsCookie) activatedNodes[0].getCookie(SaveAsCookie.class); + try { + c.saveAs(); + } catch( IOException ioE ) { + Logger.getLogger( SaveAsAction.class.getName() ).log( Level.WARNING, + NbBundle.getMessage(DataObject.class, "MSG_SaveAsFailed"), ioE ); //NOI18N + } + } + + @Override + protected boolean enable(Node[] activatedNodes) { + TopComponent tc = TopComponent.getRegistry().getActivated(); + return null != activatedNodes + && activatedNodes.length > 0 + && null != activatedNodes[0].getCookie( SaveAsCookie.class ) + && null == tc + && WindowManager.getDefault().isEditorTopComponent( tc ); + } + + @Override + public String getName() { + return NbBundle.getMessage(DataObject.class, "CTL_SaveAsAction"); //NOI18N + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous() { + return false; + } + } +