This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 53295
Collapse All | Expand All

(-)openide/loaders/src/org/openide/loaders/FolderRenameHandler.java (+24 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openide.loaders;
15
16
import org.openide.nodes.Node;
17
18
/**
19
 *
20
 * @author Jan Becicka
21
 */
22
public interface FolderRenameHandler {
23
    void handleRename(DataFolder folder, String newName) throws IllegalArgumentException ;
24
}
(-)openide/loaders/src/org/openide/loaders/DataFolder.java (+20 lines)
Lines 29-34 Link Here
29
29
30
import org.openide.ErrorManager;
30
import org.openide.ErrorManager;
31
import org.openide.NotifyDescriptor;
31
import org.openide.NotifyDescriptor;
32
import org.openide.util.LookupEvent;
33
import org.openide.util.LookupListener;
32
import org.openide.util.datatransfer.*;
34
import org.openide.util.datatransfer.*;
33
import org.openide.cookies.*;
35
import org.openide.cookies.*;
34
import org.openide.filesystems.*;
36
import org.openide.filesystems.*;
Lines 1183-1188 Link Here
1183
                return new NewType[] { new NewFolder () };
1185
                return new NewType[] { new NewFolder () };
1184
            }
1186
            }
1185
 */
1187
 */
1188
        }
1189
        private synchronized FolderRenameHandler getRenameHandler() {
1190
            Lookup.Result renameImplementations = Lookup.getDefault().lookup(new Lookup.Template(FolderRenameHandler.class));
1191
            List handlers = (List) renameImplementations.allInstances();
1192
            if (handlers.size()==0)
1193
                return null;
1194
            if (handlers.size()>1)
1195
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new RuntimeException("Multiple instances of FolderRenameHandler found in Lookup")); //NOI18N
1196
            return (FolderRenameHandler) handlers.get(0);
1197
        }
1198
1199
        public void setName(String name) {
1200
            FolderRenameHandler handler = getRenameHandler();
1201
            if (handler == null) {
1202
                super.setName(name);
1203
            } else {
1204
                handler.handleRename(DataFolder.this, name);
1205
            }
1186
        }
1206
        }
1187
        
1207
        
1188
        /* May add some paste types for objects being added to folders.
1208
        /* May add some paste types for objects being added to folders.
(-)openide/loaders/test/unit/src/org/openide/loaders/FolderRenameHandlerTest.java (+100 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openide.loaders;
15
16
import junit.framework.*;
17
import org.openide.filesystems.*;
18
import org.openide.nodes.Node;
19
20
/**
21
 * @author Jan Becicka
22
 */
23
public class FolderRenameHandlerTest extends TestCase {
24
    static {
25
        System.setProperty ("org.openide.util.Lookup", "org.openide.loaders.FolderRenameHandlerTest$Lkp"); // NOI18N
26
    }
27
    
28
    private FileObject fo;
29
    private Node n;
30
    private FolderRenameHandlerImpl frh = new FolderRenameHandlerImpl();
31
    private boolean lookupAdded;
32
    
33
    
34
    public FolderRenameHandlerTest (String testName) {
35
        super (testName);
36
    }
37
    
38
    public static junit.framework.Test suite () {
39
        junit.framework.TestSuite suite = new junit.framework.TestSuite(FolderRenameHandlerTest.class);
40
        
41
        return suite;
42
    }
43
    
44
    public void setUp() throws Exception {
45
        FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot ();
46
        fo = FileUtil.createFolder (root, "test");// NOI18N
47
        
48
        DataObject obj = DataObject.find (fo);
49
        if (!  (obj instanceof DataFolder)) {
50
            fail ("It should be DataFolder: " + obj);// NOI18N
51
        }
52
        
53
        assertNotNull(obj);
54
        n = obj.getNodeDelegate();
55
        assertNotNull(n);
56
    }
57
    
58
    public void tearDown() throws Exception {
59
         fo.delete();
60
    }
61
62
    public void testRenameHandlerNotCalled () throws Exception {
63
        if (lookupAdded) {
64
            Lkp.ic.remove(frh);
65
            lookupAdded = false;
66
        }
67
        frh.called = false;
68
        
69
        n.setName("blabla");
70
        assertFalse(frh.called);
71
    }
72
    
73
    public void testRenameHandlerCalled () throws Exception {
74
        Lkp.ic.add (frh);
75
        lookupAdded = true;
76
        frh.called = false;
77
        
78
        n.setName("foo");// NOI18N
79
        assertTrue(frh.called);
80
    }
81
    
82
    public static final class Lkp extends org.openide.util.lookup.AbstractLookup {
83
        static org.openide.util.lookup.InstanceContent ic = new org.openide.util.lookup.InstanceContent ();
84
        public Lkp () {
85
            this (ic);
86
        }
87
        
88
        private Lkp (org.openide.util.lookup.InstanceContent ic) {
89
            super (ic);
90
        }
91
    }
92
    
93
    private static final class FolderRenameHandlerImpl implements FolderRenameHandler {
94
        boolean called  = false;
95
        public void handleRename(DataFolder folder, String newName) throws IllegalArgumentException {
96
            called = true;
97
        }
98
    }
99
    
100
}
(-)java/project/src/org/netbeans/spi/java/project/support/ui/PackageViewChildren.java (+17 lines)
Lines 52-57 Link Here
52
import org.openide.nodes.FilterNode;
52
import org.openide.nodes.FilterNode;
53
import org.openide.nodes.Node;
53
import org.openide.nodes.Node;
54
import org.openide.util.Lookup;
54
import org.openide.util.Lookup;
55
import org.openide.util.LookupEvent;
56
import org.openide.util.LookupListener;
55
import org.openide.util.NbBundle;
57
import org.openide.util.NbBundle;
56
import org.openide.util.RequestProcessor;
58
import org.openide.util.RequestProcessor;
57
import org.openide.util.Utilities;
59
import org.openide.util.Utilities;
Lines 642-649 Link Here
642
            return false;
644
            return false;
643
        }
645
        }
644
646
647
        private static synchronized PackageRenameHandler getRenameHandler() {
648
            Lookup.Result renameImplementations = Lookup.getDefault().lookup(new Lookup.Template(PackageRenameHandler.class));
649
            List handlers = (List) renameImplementations.allInstances();
650
            if (handlers.size()==0)
651
                return null;
652
            if (handlers.size()>1)
653
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new RuntimeException("Multiple instances of PackageRenameHandler found in Lookup")); //NOI18N
654
            return (PackageRenameHandler) handlers.get(0);
655
        }
645
        
656
        
646
        public void setName(String name) {
657
        public void setName(String name) {
658
            PackageRenameHandler handler = getRenameHandler();
659
            if (handler!=null) {
660
                handler.handleRename(this, name);
661
                return;
662
            }
663
            
647
            if (isDefaultPackage) {
664
            if (isDefaultPackage) {
648
                return;
665
                return;
649
            }
666
            }
(-)java/project/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandler.java (+24 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.java.project.support.ui;
15
16
import org.openide.nodes.Node;
17
18
/**
19
 *
20
 * @author Jan Becicka
21
 */
22
public interface PackageRenameHandler {
23
    void handleRename(Node node, String newName) throws IllegalArgumentException;
24
}
(-)java/project/test/unit/src/org/netbeans/spi/java/project/support/ui/PackageRenameHandlerTest.java (+137 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.java.project.support.ui;
15
16
import java.beans.PropertyChangeListener;
17
import javax.swing.Icon;
18
import junit.framework.*;
19
import org.netbeans.api.project.SourceGroup;
20
import org.openide.filesystems.*;
21
import org.openide.nodes.Children;
22
import org.openide.nodes.Node;
23
24
/**
25
 * @author Jan Becicka
26
 */
27
public class PackageRenameHandlerTest extends TestCase {
28
    static {
29
        System.setProperty ("org.openide.util.Lookup", "org.netbeans.spi.java.project.support.ui.PackageRenameHandlerTest$Lkp"); // NOI18N
30
    }
31
    
32
    private FileObject fo;
33
    private Node n;
34
    private PackageRenameHandlerImpl frh = new PackageRenameHandlerImpl();
35
    private boolean lookupAdded;
36
    
37
    
38
    public PackageRenameHandlerTest (String testName) {
39
        super (testName);
40
    }
41
    
42
    public static junit.framework.Test suite () {
43
        junit.framework.TestSuite suite = new junit.framework.TestSuite(PackageRenameHandlerTest.class);
44
        
45
        return suite;
46
    }
47
    
48
    public void setUp() throws Exception {
49
        FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot ();
50
        fo = FileUtil.createFolder (root, "test");// NOI18N
51
52
        SourceGroup group = new SimpleSourceGroup( FileUtil.createFolder( root, "src" ) );
53
        Children ch = PackageView.createPackageView( group ).getChildren();
54
        
55
        // Create folder
56
	FileUtil.createFolder( root, "src/foo" );
57
        n = ch.findChild( "foo" );           
58
        
59
        assertNotNull(n);
60
    }
61
    
62
    public void tearDown() throws Exception {
63
         fo.delete();
64
    }
65
66
    public void testRenameHandlerNotCalled () throws Exception {
67
        if (lookupAdded) {
68
            Lkp.ic.remove(frh);
69
            lookupAdded = false;
70
        }
71
        frh.called = false;
72
        
73
        n.setName("blabla");
74
        assertFalse(frh.called);
75
    }
76
    
77
    public void testRenameHandlerCalled () throws Exception {
78
        Lkp.ic.add (frh);
79
        lookupAdded = true;
80
        frh.called = false;
81
        
82
        n.setName("foo");// NOI18N
83
        assertTrue(frh.called);
84
    }
85
    
86
    public static final class Lkp extends org.openide.util.lookup.AbstractLookup {
87
        static org.openide.util.lookup.InstanceContent ic = new org.openide.util.lookup.InstanceContent ();
88
        public Lkp () {
89
            this (ic);
90
        }
91
        
92
        private Lkp (org.openide.util.lookup.InstanceContent ic) {
93
            super (ic);
94
        }
95
    }
96
    
97
    private static final class PackageRenameHandlerImpl implements PackageRenameHandler {
98
        boolean called  = false;
99
        public void handleRename(Node n, String newName) throws IllegalArgumentException {
100
            called = true;
101
        }
102
    }
103
    private static class SimpleSourceGroup implements SourceGroup {
104
        
105
        private FileObject root;
106
        
107
        public SimpleSourceGroup( FileObject root ) {
108
            this.root = root;
109
        }
110
        
111
        public FileObject getRootFolder() {
112
            return root;
113
        }
114
        
115
        public String getName() {
116
            return "TestGroup";
117
        }
118
        
119
        public String getDisplayName() {
120
            return getName();
121
        }
122
        
123
        public Icon getIcon(boolean opened) {
124
            return null;
125
        }
126
127
        public boolean contains(FileObject file) throws IllegalArgumentException {
128
            return FileUtil.isParentOf( root, file );
129
        }
130
    
131
        public void addPropertyChangeListener(PropertyChangeListener listener) {}
132
133
        public void removePropertyChangeListener(PropertyChangeListener listener) {}
134
        
135
    }    
136
    
137
}
(-)java/src/org/netbeans/modules/java/JavaNode.java (-11 / +27 lines)
Lines 14-19 Link Here
14
package org.netbeans.modules.java;
14
package org.netbeans.modules.java;
15
15
16
import java.awt.Image;
16
import java.awt.Image;
17
import java.awt.datatransfer.Transferable;
17
import java.beans.PropertyChangeEvent;
18
import java.beans.PropertyChangeEvent;
18
import java.beans.PropertyChangeListener;
19
import java.beans.PropertyChangeListener;
19
import java.beans.PropertyEditor;
20
import java.beans.PropertyEditor;
Lines 26-39 Link Here
26
import java.lang.reflect.Modifier;
27
import java.lang.reflect.Modifier;
27
import java.net.URI;
28
import java.net.URI;
28
import java.net.URL;
29
import java.net.URL;
29
import java.nio.charset.Charset;
30
import java.text.MessageFormat;
30
import java.text.MessageFormat;
31
import java.util.ArrayList;
31
import java.util.*;
32
import java.util.Arrays;
33
import java.util.HashSet;
34
import java.util.Iterator;
35
import java.util.List;
36
import java.util.Set;
37
import javax.jmi.reflect.InvalidObjectException;
32
import javax.jmi.reflect.InvalidObjectException;
38
import javax.swing.SwingUtilities;
33
import javax.swing.SwingUtilities;
39
import javax.swing.event.ChangeEvent;
34
import javax.swing.event.ChangeEvent;
Lines 63-79 Link Here
63
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileStateInvalidException;
59
import org.openide.filesystems.FileStateInvalidException;
65
import org.openide.filesystems.FileUtil;
60
import org.openide.filesystems.FileUtil;
61
import org.openide.loaders.DataFolder;
66
import org.openide.loaders.DataNode;
62
import org.openide.loaders.DataNode;
67
import org.openide.loaders.DataObject;
63
import org.openide.loaders.DataObject;
68
import org.openide.nodes.Children;
64
import org.openide.nodes.Children;
69
import org.openide.nodes.Node;
65
import org.openide.nodes.Node;
66
import org.openide.nodes.NodeTransfer;
70
import org.openide.nodes.PropertySupport;
67
import org.openide.nodes.PropertySupport;
71
import org.openide.nodes.Sheet;
68
import org.openide.nodes.Sheet;
72
import org.openide.util.NbBundle;
69
import org.openide.util.*;
73
import org.openide.util.RequestProcessor;
74
import org.openide.util.Utilities;
75
import org.openide.util.WeakSet;
76
import org.openide.util.datatransfer.NewType;
70
import org.openide.util.datatransfer.NewType;
71
import org.openide.util.datatransfer.PasteType;
72
import org.openide.util.lookup.AbstractLookup;
73
import org.openide.util.lookup.InstanceContent;
77
74
78
/**
75
/**
79
 * The node representation of Java source files.
76
 * The node representation of Java source files.
Lines 423-428 Link Here
423
    
418
    
424
    public Image getOpenedIcon(int type) {
419
    public Image getOpenedIcon(int type) {
425
        return iconCache.getIcon(super.getOpenedIcon(type), getBadges());
420
        return iconCache.getIcon(super.getOpenedIcon(type), getBadges());
421
    }
422
    
423
    public void setName(String name) {
424
        RenameHandler handler = getRenameHandler();
425
        if (handler == null) {
426
            super.setName(name);
427
        } else {
428
            handler.handleRename(JavaNode.this, name);
429
        }
430
    }
431
    
432
    private static synchronized RenameHandler getRenameHandler() {
433
        Lookup.Result renameImplementations = Lookup.getDefault().lookup(new Lookup.Template(RenameHandler.class));
434
        List handlers = (List) renameImplementations.allInstances();
435
        if (handlers.size()==0)
436
            return null;
437
        if (handlers.size()>1)
438
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new RuntimeException("Multiple instances of RenameHandler found in Lookup")); //NOI18N
439
        return (RenameHandler) handlers.get(0);
426
    }
440
    }
427
441
428
    /** Get the icon base.
442
    /** Get the icon base.
(-)java/src/org/netbeans/modules/java/RenameHandler.java (+24 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.java;
15
16
import org.openide.nodes.Node;
17
18
/**
19
 *
20
 * @author Jan Becicka
21
 */
22
public interface RenameHandler {
23
    void handleRename(Node node, String newName) throws IllegalArgumentException;
24
}

Return to bug 53295