diff -r 8581b5f5fb16 openide.explorer/apichanges.xml --- a/openide.explorer/apichanges.xml Thu Jun 16 07:29:36 2011 +0200 +++ b/openide.explorer/apichanges.xml Thu Jun 16 09:24:20 2011 +0200 @@ -50,6 +50,22 @@ Explorer API + + + In-place rename can be processed on background + + + + + + By providing slowRename + property, nodes can request in-place rename to be finished on background. + + + + + + It's possible to define whether the quick search is enabled or disabled in TreeView. diff -r 8581b5f5fb16 openide.explorer/arch.xml --- a/openide.explorer/arch.xml Thu Jun 16 07:29:36 2011 +0200 +++ b/openide.explorer/arch.xml Thu Jun 16 09:24:20 2011 +0200 @@ -420,6 +420,11 @@ provide their own confirmation dialog for delete action and explorer will not show default one when they are deleted. + + Nodes returing Boolean.TRUE from getValue("slowRename") are expected + to have potentially slow implemenation of setName. Explorer views + rather process in-place rename in background for such nodes. + diff -r 8581b5f5fb16 openide.explorer/manifest.mf --- a/openide.explorer/manifest.mf Thu Jun 16 07:29:36 2011 +0200 +++ b/openide.explorer/manifest.mf Thu Jun 16 09:24:20 2011 +0200 @@ -2,5 +2,5 @@ OpenIDE-Module: org.openide.explorer OpenIDE-Module-Localizing-Bundle: org/openide/explorer/Bundle.properties AutoUpdate-Essential-Module: true -OpenIDE-Module-Specification-Version: 6.36 +OpenIDE-Module-Specification-Version: 6.37 diff -r 8581b5f5fb16 openide.explorer/src/org/openide/explorer/view/OutlineView.java --- a/openide.explorer/src/org/openide/explorer/view/OutlineView.java Thu Jun 16 07:29:36 2011 +0200 +++ b/openide.explorer/src/org/openide/explorer/view/OutlineView.java Thu Jun 16 09:24:20 2011 +0200 @@ -1742,7 +1742,7 @@ protected void setTreeValueAt(Object aValue, int rowIndex) { Node n = getNodeAt(rowIndex); if( null != n ) { - n.setName(aValue == null ? "" : aValue.toString()); + ViewUtil.nodeRename(n, aValue == null ? "" : aValue.toString()); } } diff -r 8581b5f5fb16 openide.explorer/src/org/openide/explorer/view/TreeTable.java --- a/openide.explorer/src/org/openide/explorer/view/TreeTable.java Thu Jun 16 07:29:36 2011 +0200 +++ b/openide.explorer/src/org/openide/explorer/view/TreeTable.java Thu Jun 16 09:24:20 2011 +0200 @@ -42,6 +42,7 @@ * made subject to such option by the copyright holder. */ package org.openide.explorer.view; +import java.util.MissingResourceException; import javax.swing.table.TableColumnModel; import org.openide.explorer.propertysheet.PropertyPanel; import org.openide.nodes.Node; @@ -1419,25 +1420,7 @@ if ((n != null) && n.canRename()) { String newStr = (String) getCellEditorValue(); - - try { - // bugfix #21589 don't update name if there is not any change - if (!n.getName().equals(newStr)) { - n.setName(newStr); - } - } catch (IllegalArgumentException exc) { - boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null; - - // annotate new localized message only if there is no localized message yet - if (needToAnnotate) { - String msg = NbBundle.getMessage( - TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr - ); - Exceptions.attachLocalizedMessage(exc, msg); - } - - Exceptions.printStackTrace(exc); - } + ViewUtil.nodeRename(n, newStr); } } } diff -r 8581b5f5fb16 openide.explorer/src/org/openide/explorer/view/TreeViewCellEditor.java --- a/openide.explorer/src/org/openide/explorer/view/TreeViewCellEditor.java Thu Jun 16 07:29:36 2011 +0200 +++ b/openide.explorer/src/org/openide/explorer/view/TreeViewCellEditor.java Thu Jun 16 09:24:20 2011 +0200 @@ -134,23 +134,7 @@ if ((n != null) && n.canRename()) { String newStr = (String) getCellEditorValue(); - - try { - // bugfix #21589 don't update name if there is not any change - if (!n.getName().equals(newStr)) { - n.setName(newStr); - } - } catch (IllegalArgumentException exc) { - boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null; - - // annotate new localized message only if there is no localized message yet - if (needToAnnotate) { - String msg = NbBundle.getMessage(TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr); - Exceptions.attachLocalizedMessage(exc, msg); - } - - Exceptions.printStackTrace(exc); - } + ViewUtil.nodeRename(n, newStr); } } } diff -r 8581b5f5fb16 openide.explorer/src/org/openide/explorer/view/ViewUtil.java --- a/openide.explorer/src/org/openide/explorer/view/ViewUtil.java Thu Jun 16 07:29:36 2011 +0200 +++ b/openide.explorer/src/org/openide/explorer/view/ViewUtil.java Thu Jun 16 09:24:20 2011 +0200 @@ -44,9 +44,13 @@ import java.awt.Color; import java.awt.Component; +import java.awt.EventQueue; import javax.swing.JComponent; import javax.swing.UIManager; import javax.swing.plaf.UIResource; +import org.openide.nodes.Node; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; /** @@ -101,4 +105,36 @@ } return false; } + + static void nodeRename(final Node n, final String newStr) { + // bugfix #21589 don't update name if there is not any change + if (n.getName().equals(newStr)) { + return; + } + if (EventQueue.isDispatchThread() && Boolean.TRUE.equals(n.getValue("slowRename"))) { // NOI18N + RP.post(new Runnable() { + @Override + public void run() { + nodeRename(n, newStr); + } + }); + return; + } + try { + n.setName(newStr); + } catch (IllegalArgumentException exc) { + boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null; + + // annotate new localized message only if there is no localized message yet + if (needToAnnotate) { + String msg = NbBundle.getMessage( + TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr + ); + Exceptions.attachLocalizedMessage(exc, msg); + } + + Exceptions.printStackTrace(exc); + } + } + } diff -r 8581b5f5fb16 openide.explorer/test/unit/src/org/openide/explorer/view/ViewUtilTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.explorer/test/unit/src/org/openide/explorer/view/ViewUtilTest.java Thu Jun 16 09:24:20 2011 +0200 @@ -0,0 +1,109 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, 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-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.openide.explorer.view; + +import java.awt.EventQueue; +import org.netbeans.junit.NbTestCase; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.Exceptions; + +public class ViewUtilTest extends NbTestCase { + + public ViewUtilTest(String n) { + super(n); + } + + @Override + protected boolean runInEQ() { + return true; + } + + @Override + protected int timeOut() { + return 20000; + } + + public void testRenameNormalNode() { + Node n = new AbstractNode(Children.LEAF) { + @Override + public void setName(String s) { + assertTrue("In AWT", EventQueue.isDispatchThread()); + super.setName(s); + } + }; + + n.setName("newName"); + assertEquals("newName", n.getName()); + } + + public void testRenameForSlowNode() { + Node n = new AbstractNode(Children.LEAF) { + boolean renamed; + + @Override + public synchronized void setName(String s) { + renamed = true; + notifyAll(); + assertFalse("Not in AWT", EventQueue.isDispatchThread()); + super.setName(s); + } + + @Override + public synchronized String toString() { + while (!renamed) { + try { + wait(); + } catch (InterruptedException ex) { + Exceptions.printStackTrace(ex); + } + } + return super.getName(); + } + }; + + n.setValue("slowRename", true); + ViewUtil.nodeRename(n, "newName"); + assertEquals("newName", n.toString()); + } +} diff -r 8581b5f5fb16 openide.loaders/src/org/openide/loaders/DataFolder.java --- a/openide.loaders/src/org/openide/loaders/DataFolder.java Thu Jun 16 07:29:36 2011 +0200 +++ b/openide.loaders/src/org/openide/loaders/DataFolder.java Thu Jun 16 09:24:20 2011 +0200 @@ -1363,6 +1363,18 @@ } } + @Override + public Object getValue(String attributeName) { + if ("slowRename".equals(attributeName)) { // NOI18N + if (getRenameHandler() != null) { + return Boolean.TRUE; + } + } + return super.getValue(attributeName); + } + + + /* May add some paste types for objects being added to folders. * May move data objects; copy them; create links for them; instantiate * them as templates; serialize instances; or create instance data objects diff -r 8581b5f5fb16 openide.loaders/test/unit/src/org/openide/loaders/DataFolderTest.java --- a/openide.loaders/test/unit/src/org/openide/loaders/DataFolderTest.java Thu Jun 16 07:29:36 2011 +0200 +++ b/openide.loaders/test/unit/src/org/openide/loaders/DataFolderTest.java Thu Jun 16 09:24:20 2011 +0200 @@ -724,4 +724,18 @@ } } + public void testRenameSlow() throws DataObjectNotFoundException, IOException { + FileObject root = FileUtil.createMemoryFileSystem().getRoot(); + DataObject obj = DataObject.find(root); + Node n = obj.getNodeDelegate(); + assertNull("not slow rename by default", n.getValue("slowRename")); + registerIntoLookup(new MyHandler()); + assertEquals("now rename is slow", Boolean.TRUE, n.getValue("slowRename")); + } + + private static final class MyHandler implements FolderRenameHandler { + @Override + public void handleRename(DataFolder folder, String newName) throws IllegalArgumentException { + } + } }