Index: openide/loaders/src/org/openide/loaders/FolderRenameHandler.java =================================================================== RCS file: openide/loaders/src/org/openide/loaders/FolderRenameHandler.java diff -N openide/loaders/src/org/openide/loaders/FolderRenameHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openide/loaders/src/org/openide/loaders/FolderRenameHandler.java 3 May 2005 09:45:17 -0000 1.1.2.2 @@ -0,0 +1,24 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.openide.loaders; + +import org.openide.nodes.Node; + +/** + * + * @author Jan Becicka + */ +public interface FolderRenameHandler { + void handleRename(DataFolder folder, String newName) throws IllegalArgumentException ; +} Index: openide/loaders/src/org/openide/loaders/DataFolder.java =================================================================== RCS file: /cvs/openide/loaders/src/org/openide/loaders/DataFolder.java,v retrieving revision 1.35 retrieving revision 1.35.22.3 diff -u -r1.35 -r1.35.22.3 --- openide/loaders/src/org/openide/loaders/DataFolder.java 11 Feb 2005 12:44:55 -0000 1.35 +++ openide/loaders/src/org/openide/loaders/DataFolder.java 3 May 2005 15:09:48 -0000 1.35.22.3 @@ -29,6 +29,8 @@ import org.openide.ErrorManager; import org.openide.NotifyDescriptor; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; import org.openide.util.datatransfer.*; import org.openide.cookies.*; import org.openide.filesystems.*; @@ -1183,6 +1185,24 @@ return new NewType[] { new NewFolder () }; } */ + } + private synchronized FolderRenameHandler getRenameHandler() { + Lookup.Result renameImplementations = Lookup.getDefault().lookup(new Lookup.Template(FolderRenameHandler.class)); + List handlers = (List) renameImplementations.allInstances(); + if (handlers.size()==0) + return null; + if (handlers.size()>1) + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new RuntimeException("Multiple instances of FolderRenameHandler found in Lookup")); //NOI18N + return (FolderRenameHandler) handlers.get(0); + } + + public void setName(String name) { + FolderRenameHandler handler = getRenameHandler(); + if (handler == null) { + super.setName(name); + } else { + handler.handleRename(DataFolder.this, name); + } } /* May add some paste types for objects being added to folders. Index: openide/loaders/test/unit/src/org/openide/loaders/FolderRenameHandlerTest.java =================================================================== RCS file: openide/loaders/test/unit/src/org/openide/loaders/FolderRenameHandlerTest.java diff -N openide/loaders/test/unit/src/org/openide/loaders/FolderRenameHandlerTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openide/loaders/test/unit/src/org/openide/loaders/FolderRenameHandlerTest.java 3 May 2005 09:45:16 -0000 1.1.2.1 @@ -0,0 +1,100 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.openide.loaders; + +import junit.framework.*; +import org.openide.filesystems.*; +import org.openide.nodes.Node; + +/** + * @author Jan Becicka + */ +public class FolderRenameHandlerTest extends TestCase { + static { + System.setProperty ("org.openide.util.Lookup", "org.openide.loaders.FolderRenameHandlerTest$Lkp"); // NOI18N + } + + private FileObject fo; + private Node n; + private FolderRenameHandlerImpl frh = new FolderRenameHandlerImpl(); + private boolean lookupAdded; + + + public FolderRenameHandlerTest (String testName) { + super (testName); + } + + public static junit.framework.Test suite () { + junit.framework.TestSuite suite = new junit.framework.TestSuite(FolderRenameHandlerTest.class); + + return suite; + } + + public void setUp() throws Exception { + FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot (); + fo = FileUtil.createFolder (root, "test");// NOI18N + + DataObject obj = DataObject.find (fo); + if (! (obj instanceof DataFolder)) { + fail ("It should be DataFolder: " + obj);// NOI18N + } + + assertNotNull(obj); + n = obj.getNodeDelegate(); + assertNotNull(n); + } + + public void tearDown() throws Exception { + fo.delete(); + } + + public void testRenameHandlerNotCalled () throws Exception { + if (lookupAdded) { + Lkp.ic.remove(frh); + lookupAdded = false; + } + frh.called = false; + + n.setName("blabla"); + assertFalse(frh.called); + } + + public void testRenameHandlerCalled () throws Exception { + Lkp.ic.add (frh); + lookupAdded = true; + frh.called = false; + + n.setName("foo");// NOI18N + assertTrue(frh.called); + } + + public static final class Lkp extends org.openide.util.lookup.AbstractLookup { + static org.openide.util.lookup.InstanceContent ic = new org.openide.util.lookup.InstanceContent (); + public Lkp () { + this (ic); + } + + private Lkp (org.openide.util.lookup.InstanceContent ic) { + super (ic); + } + } + + private static final class FolderRenameHandlerImpl implements FolderRenameHandler { + boolean called = false; + public void handleRename(DataFolder folder, String newName) throws IllegalArgumentException { + called = true; + } + } + +} Index: java/project/src/org/netbeans/spi/java/project/support/ui/PackageViewChildren.java =================================================================== RCS file: /cvs/java/project/src/org/netbeans/spi/java/project/support/ui/PackageViewChildren.java,v retrieving revision 1.57 retrieving revision 1.57.10.3 diff -u -r1.57 -r1.57.10.3 --- java/project/src/org/netbeans/spi/java/project/support/ui/PackageViewChildren.java 26 Mar 2005 16:01:41 -0000 1.57 +++ java/project/src/org/netbeans/spi/java/project/support/ui/PackageViewChildren.java 3 May 2005 15:09:50 -0000 1.57.10.3 @@ -52,6 +52,8 @@ import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.openide.util.Lookup; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; import org.openide.util.Utilities; @@ -642,8 +644,23 @@ return false; } + private static synchronized PackageRenameHandler getRenameHandler() { + Lookup.Result renameImplementations = Lookup.getDefault().lookup(new Lookup.Template(PackageRenameHandler.class)); + List handlers = (List) renameImplementations.allInstances(); + if (handlers.size()==0) + return null; + if (handlers.size()>1) + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new RuntimeException("Multiple instances of PackageRenameHandler found in Lookup")); //NOI18N + return (PackageRenameHandler) handlers.get(0); + } public void setName(String name) { + PackageRenameHandler handler = getRenameHandler(); + if (handler!=null) { + handler.handleRename(this, name); + return; + } + if (isDefaultPackage) { return; } Index: java/project/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandler.java =================================================================== RCS file: java/project/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandler.java diff -N java/project/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/project/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandler.java 3 May 2005 09:47:55 -0000 1.1.2.2 @@ -0,0 +1,24 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.spi.java.project.support.ui; + +import org.openide.nodes.Node; + +/** + * + * @author Jan Becicka + */ +public interface PackageRenameHandler { + void handleRename(Node node, String newName) throws IllegalArgumentException; +} Index: java/project/test/unit/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandlerTest.java =================================================================== RCS file: java/project/test/unit/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandlerTest.java diff -N java/project/test/unit/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandlerTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/project/test/unit/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandlerTest.java 3 May 2005 09:48:35 -0000 1.1.2.1 @@ -0,0 +1,137 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.spi.java.project.support.ui; + +import java.beans.PropertyChangeListener; +import javax.swing.Icon; +import junit.framework.*; +import org.netbeans.api.project.SourceGroup; +import org.openide.filesystems.*; +import org.openide.nodes.Children; +import org.openide.nodes.Node; + +/** + * @author Jan Becicka + */ +public class PackageRenameHandlerTest extends TestCase { + static { + System.setProperty ("org.openide.util.Lookup", "org.netbeans.spi.java.project.support.ui.PackageRenameHandlerTest$Lkp"); // NOI18N + } + + private FileObject fo; + private Node n; + private PackageRenameHandlerImpl frh = new PackageRenameHandlerImpl(); + private boolean lookupAdded; + + + public PackageRenameHandlerTest (String testName) { + super (testName); + } + + public static junit.framework.Test suite () { + junit.framework.TestSuite suite = new junit.framework.TestSuite(PackageRenameHandlerTest.class); + + return suite; + } + + public void setUp() throws Exception { + FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot (); + fo = FileUtil.createFolder (root, "test");// NOI18N + + SourceGroup group = new SimpleSourceGroup( FileUtil.createFolder( root, "src" ) ); + Children ch = PackageView.createPackageView( group ).getChildren(); + + // Create folder + FileUtil.createFolder( root, "src/foo" ); + n = ch.findChild( "foo" ); + + assertNotNull(n); + } + + public void tearDown() throws Exception { + fo.delete(); + } + + public void testRenameHandlerNotCalled () throws Exception { + if (lookupAdded) { + Lkp.ic.remove(frh); + lookupAdded = false; + } + frh.called = false; + + n.setName("blabla"); + assertFalse(frh.called); + } + + public void testRenameHandlerCalled () throws Exception { + Lkp.ic.add (frh); + lookupAdded = true; + frh.called = false; + + n.setName("foo");// NOI18N + assertTrue(frh.called); + } + + public static final class Lkp extends org.openide.util.lookup.AbstractLookup { + static org.openide.util.lookup.InstanceContent ic = new org.openide.util.lookup.InstanceContent (); + public Lkp () { + this (ic); + } + + private Lkp (org.openide.util.lookup.InstanceContent ic) { + super (ic); + } + } + + private static final class PackageRenameHandlerImpl implements PackageRenameHandler { + boolean called = false; + public void handleRename(Node n, String newName) throws IllegalArgumentException { + called = true; + } + } + private static class SimpleSourceGroup implements SourceGroup { + + private FileObject root; + + public SimpleSourceGroup( FileObject root ) { + this.root = root; + } + + public FileObject getRootFolder() { + return root; + } + + public String getName() { + return "TestGroup"; + } + + public String getDisplayName() { + return getName(); + } + + public Icon getIcon(boolean opened) { + return null; + } + + public boolean contains(FileObject file) throws IllegalArgumentException { + return FileUtil.isParentOf( root, file ); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) {} + + public void removePropertyChangeListener(PropertyChangeListener listener) {} + + } + +} Index: java/src/org/netbeans/modules/java/JavaNode.java =================================================================== RCS file: /cvs/java/src/org/netbeans/modules/java/JavaNode.java,v retrieving revision 1.128 retrieving revision 1.127.10.4 diff -u -r1.128 -r1.127.10.4 --- java/src/org/netbeans/modules/java/JavaNode.java 2 May 2005 21:21:42 -0000 1.128 +++ java/src/org/netbeans/modules/java/JavaNode.java 3 May 2005 15:09:49 -0000 1.127.10.4 @@ -14,6 +14,7 @@ package org.netbeans.modules.java; import java.awt.Image; +import java.awt.datatransfer.Transferable; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyEditor; @@ -26,14 +27,8 @@ import java.lang.reflect.Modifier; import java.net.URI; import java.net.URL; -import java.nio.charset.Charset; import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; +import java.util.*; import javax.jmi.reflect.InvalidObjectException; import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; @@ -63,17 +58,19 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataFolder; import org.openide.loaders.DataNode; import org.openide.loaders.DataObject; import org.openide.nodes.Children; import org.openide.nodes.Node; +import org.openide.nodes.NodeTransfer; import org.openide.nodes.PropertySupport; import org.openide.nodes.Sheet; -import org.openide.util.NbBundle; -import org.openide.util.RequestProcessor; -import org.openide.util.Utilities; -import org.openide.util.WeakSet; +import org.openide.util.*; import org.openide.util.datatransfer.NewType; +import org.openide.util.datatransfer.PasteType; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; /** * The node representation of Java source files. @@ -423,6 +418,25 @@ public Image getOpenedIcon(int type) { return iconCache.getIcon(super.getOpenedIcon(type), getBadges()); + } + + public void setName(String name) { + RenameHandler handler = getRenameHandler(); + if (handler == null) { + super.setName(name); + } else { + handler.handleRename(JavaNode.this, name); + } + } + + private static synchronized RenameHandler getRenameHandler() { + Lookup.Result renameImplementations = Lookup.getDefault().lookup(new Lookup.Template(RenameHandler.class)); + List handlers = (List) renameImplementations.allInstances(); + if (handlers.size()==0) + return null; + if (handlers.size()>1) + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new RuntimeException("Multiple instances of RenameHandler found in Lookup")); //NOI18N + return (RenameHandler) handlers.get(0); } /** Get the icon base. Index: java/src/org/netbeans/modules/java/RenameHandler.java =================================================================== RCS file: java/src/org/netbeans/modules/java/RenameHandler.java diff -N java/src/org/netbeans/modules/java/RenameHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/src/org/netbeans/modules/java/RenameHandler.java 3 May 2005 09:52:58 -0000 1.1.2.3 @@ -0,0 +1,24 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.java; + +import org.openide.nodes.Node; + +/** + * + * @author Jan Becicka + */ +public interface RenameHandler { + void handleRename(Node node, String newName) throws IllegalArgumentException; +}