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 190736
Collapse All | Expand All

(-)a/openide.explorer/apichanges.xml (+16 lines)
Lines 50-55 Link Here
50
<apidef name="explorer">Explorer API</apidef>
50
<apidef name="explorer">Explorer API</apidef>
51
</apidefs>
51
</apidefs>
52
<changes>
52
<changes>
53
    <change id="slowRename">
54
        <api name="explorer"/>
55
        <summary>In-place rename can be processed on background</summary>
56
        <version major="6" minor="37"/>
57
        <date day="23" month="6" year="2011"/>
58
        <author login="jtulach"/>
59
        <compatibility binary="compatible" source="compatible" deprecation="no" deletion="no" addition="yes"/>
60
        <description>
61
            By providing <a href="@TOP@/architecture-summary.html#property-slowRename">slowRename</a>
62
            property, nodes can request in-place rename to be finished on background.
63
        </description>
64
        <class package="org.openide.explorer.view" name="TreeView"/>
65
        <class package="org.openide.explorer.view" name="TreeTableView"/>
66
        <class package="org.openide.explorer.view" name="OutlineView"/>
67
        <issue number="190736"/>
68
    </change>
53
    <change id="TreeView.quickSearchAllowed">
69
    <change id="TreeView.quickSearchAllowed">
54
        <api name="explorer"/>
70
        <api name="explorer"/>
55
        <summary>It's possible to define whether the quick search is enabled or disabled in TreeView.</summary>
71
        <summary>It's possible to define whether the quick search is enabled or disabled in TreeView.</summary>
(-)a/openide.explorer/arch.xml (+5 lines)
Lines 420-425 Link Here
420
    provide their own confirmation dialog for delete action and explorer will not show
420
    provide their own confirmation dialog for delete action and explorer will not show
421
    default one when they are deleted.
421
    default one when they are deleted.
422
    </api>
422
    </api>
423
    <api name="slowRename" group="property" category="devel" type="export">
424
    Nodes returing Boolean.TRUE from getValue(&quot;slowRename&quot;) are expected
425
    to have potentially slow implemenation of <code>setName</code>. Explorer views
426
    rather process in-place rename in background for such nodes.
427
    </api>
423
</answer>
428
</answer>
424
429
425
430
(-)a/openide.explorer/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.explorer
2
OpenIDE-Module: org.openide.explorer
3
OpenIDE-Module-Localizing-Bundle: org/openide/explorer/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/explorer/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 6.36
5
OpenIDE-Module-Specification-Version: 6.37
6
6
(-)a/openide.explorer/src/org/openide/explorer/view/OutlineView.java (-1 / +1 lines)
Lines 1742-1748 Link Here
1742
        protected void setTreeValueAt(Object aValue, int rowIndex) {
1742
        protected void setTreeValueAt(Object aValue, int rowIndex) {
1743
            Node n = getNodeAt(rowIndex);
1743
            Node n = getNodeAt(rowIndex);
1744
            if( null != n ) {
1744
            if( null != n ) {
1745
                n.setName(aValue == null ? "" : aValue.toString());
1745
                ViewUtil.nodeRename(n, aValue == null ? "" : aValue.toString());
1746
            }
1746
            }
1747
        }
1747
        }
1748
1748
(-)a/openide.explorer/src/org/openide/explorer/view/TreeTable.java (-19 / +2 lines)
Lines 42-47 Link Here
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
package org.openide.explorer.view;
44
package org.openide.explorer.view;
45
import java.util.MissingResourceException;
45
import javax.swing.table.TableColumnModel;
46
import javax.swing.table.TableColumnModel;
46
import org.openide.explorer.propertysheet.PropertyPanel;
47
import org.openide.explorer.propertysheet.PropertyPanel;
47
import org.openide.nodes.Node;
48
import org.openide.nodes.Node;
Lines 1419-1443 Link Here
1419
1420
1420
                if ((n != null) && n.canRename()) {
1421
                if ((n != null) && n.canRename()) {
1421
                    String newStr = (String) getCellEditorValue();
1422
                    String newStr = (String) getCellEditorValue();
1422
1423
                    ViewUtil.nodeRename(n, newStr);
1423
                    try {
1424
                        // bugfix #21589 don't update name if there is not any change
1425
                        if (!n.getName().equals(newStr)) {
1426
                            n.setName(newStr);
1427
                        }
1428
                    } catch (IllegalArgumentException exc) {
1429
                        boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null;
1430
1431
                        // annotate new localized message only if there is no localized message yet
1432
                        if (needToAnnotate) {
1433
                            String msg = NbBundle.getMessage(
1434
                                    TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr
1435
                                );
1436
                            Exceptions.attachLocalizedMessage(exc, msg);
1437
                        }
1438
1439
                        Exceptions.printStackTrace(exc);
1440
                    }
1441
                }
1424
                }
1442
            }
1425
            }
1443
        }
1426
        }
(-)a/openide.explorer/src/org/openide/explorer/view/TreeViewCellEditor.java (-17 / +1 lines)
Lines 134-156 Link Here
134
134
135
            if ((n != null) && n.canRename()) {
135
            if ((n != null) && n.canRename()) {
136
                String newStr = (String) getCellEditorValue();
136
                String newStr = (String) getCellEditorValue();
137
137
                ViewUtil.nodeRename(n, newStr);
138
                try {
139
                    // bugfix #21589 don't update name if there is not any change
140
                    if (!n.getName().equals(newStr)) {
141
                        n.setName(newStr);
142
                    }
143
                } catch (IllegalArgumentException exc) {
144
                    boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null;
145
146
                    // annotate new localized message only if there is no localized message yet
147
                    if (needToAnnotate) {
148
                        String msg = NbBundle.getMessage(TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr);
149
                        Exceptions.attachLocalizedMessage(exc, msg);
150
                    }
151
152
                    Exceptions.printStackTrace(exc);
153
                }
154
            }
138
            }
155
        }
139
        }
156
    }
140
    }
(-)a/openide.explorer/src/org/openide/explorer/view/ViewUtil.java (+36 lines)
Lines 44-52 Link Here
44
44
45
import java.awt.Color;
45
import java.awt.Color;
46
import java.awt.Component;
46
import java.awt.Component;
47
import java.awt.EventQueue;
47
import javax.swing.JComponent;
48
import javax.swing.JComponent;
48
import javax.swing.UIManager;
49
import javax.swing.UIManager;
49
import javax.swing.plaf.UIResource;
50
import javax.swing.plaf.UIResource;
51
import org.openide.nodes.Node;
52
import org.openide.util.Exceptions;
53
import org.openide.util.NbBundle;
50
import org.openide.util.RequestProcessor;
54
import org.openide.util.RequestProcessor;
51
55
52
/**
56
/**
Lines 101-104 Link Here
101
        }
105
        }
102
        return false;
106
        return false;
103
    }
107
    }
108
109
    static void nodeRename(final Node n, final String newStr) {
110
        // bugfix #21589 don't update name if there is not any change
111
        if (n.getName().equals(newStr)) {
112
            return;
113
        }
114
        if (EventQueue.isDispatchThread() && Boolean.TRUE.equals(n.getValue("slowRename"))) { // NOI18N
115
            RP.post(new Runnable() {
116
                @Override
117
                public void run() {
118
                    nodeRename(n, newStr);
119
                }
120
            });
121
            return;
122
        }
123
        try {
124
            n.setName(newStr);
125
        } catch (IllegalArgumentException exc) {
126
            boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null;
127
128
            // annotate new localized message only if there is no localized message yet
129
            if (needToAnnotate) {
130
                String msg = NbBundle.getMessage(
131
                        TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr
132
                    );
133
                Exceptions.attachLocalizedMessage(exc, msg);
134
            }
135
136
            Exceptions.printStackTrace(exc);
137
        }
138
    }
139
104
}
140
}
(-)8581b5f5fb16 (+109 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.openide.explorer.view;
43
44
import java.awt.EventQueue;
45
import org.netbeans.junit.NbTestCase;
46
import org.openide.nodes.AbstractNode;
47
import org.openide.nodes.Children;
48
import org.openide.nodes.Node;
49
import org.openide.util.Exceptions;
50
51
public class ViewUtilTest extends NbTestCase {
52
    
53
    public ViewUtilTest(String n) {
54
        super(n);
55
    }
56
57
    @Override
58
    protected boolean runInEQ() {
59
        return true;
60
    }
61
62
    @Override
63
    protected int timeOut() {
64
        return 20000;
65
    }
66
    
67
    public void testRenameNormalNode() {
68
        Node n = new AbstractNode(Children.LEAF) {
69
            @Override
70
            public void setName(String s) {
71
                assertTrue("In AWT", EventQueue.isDispatchThread());
72
                super.setName(s);
73
            }
74
        };
75
        
76
        n.setName("newName");
77
        assertEquals("newName", n.getName());
78
    }
79
80
    public void testRenameForSlowNode() {
81
        Node n = new AbstractNode(Children.LEAF) {
82
            boolean renamed;
83
            
84
            @Override
85
            public synchronized void setName(String s) {
86
                renamed = true;
87
                notifyAll();
88
                assertFalse("Not in AWT", EventQueue.isDispatchThread());
89
                super.setName(s);
90
            }
91
92
            @Override
93
            public synchronized String toString() {
94
                while (!renamed) {
95
                    try {
96
                        wait();
97
                    } catch (InterruptedException ex) {
98
                        Exceptions.printStackTrace(ex);
99
                    }
100
                }
101
                return super.getName();
102
            }
103
        };
104
105
        n.setValue("slowRename", true);
106
        ViewUtil.nodeRename(n, "newName");
107
        assertEquals("newName", n.toString());
108
    }
109
}
(-)a/openide.loaders/src/org/openide/loaders/DataFolder.java (+12 lines)
Lines 1363-1368 Link Here
1363
            }
1363
            }
1364
        }
1364
        }
1365
1365
1366
        @Override
1367
        public Object getValue(String attributeName) {
1368
            if ("slowRename".equals(attributeName)) { // NOI18N
1369
                if (getRenameHandler() != null) {
1370
                    return Boolean.TRUE;
1371
                }
1372
            }
1373
            return super.getValue(attributeName);
1374
        }
1375
        
1376
        
1377
1366
        /* May add some paste types for objects being added to folders.
1378
        /* May add some paste types for objects being added to folders.
1367
        * May move data objects; copy them; create links for them; instantiate
1379
        * May move data objects; copy them; create links for them; instantiate
1368
        * them as templates; serialize instances; or create instance data objects
1380
        * them as templates; serialize instances; or create instance data objects
(-)a/openide.loaders/test/unit/src/org/openide/loaders/DataFolderTest.java (+14 lines)
Lines 724-727 Link Here
724
        }
724
        }
725
        
725
        
726
    }
726
    }
727
    public void testRenameSlow() throws DataObjectNotFoundException, IOException {
728
        FileObject root = FileUtil.createMemoryFileSystem().getRoot();
729
        DataObject obj = DataObject.find(root);
730
        Node n = obj.getNodeDelegate();
731
        assertNull("not slow rename by default", n.getValue("slowRename"));
732
        registerIntoLookup(new MyHandler());
733
        assertEquals("now rename is slow", Boolean.TRUE, n.getValue("slowRename"));
734
    }
735
    
736
    private static final class MyHandler implements FolderRenameHandler {
737
        @Override
738
        public void handleRename(DataFolder folder, String newName) throws IllegalArgumentException {
739
        }
740
    }
727
}
741
}

Return to bug 190736