Index: openide/api/doc/changes/apichanges.xml =================================================================== RCS file: /cvs/openide/api/doc/changes/apichanges.xml,v retrieving revision 1.234 diff -u -r1.234 apichanges.xml --- openide/api/doc/changes/apichanges.xml 9 Feb 2005 12:33:24 -0000 1.234 +++ openide/api/doc/changes/apichanges.xml 11 Mar 2005 12:12:02 -0000 @@ -114,6 +114,21 @@ + + + Nodes in explorer can supress default confirmation dialog during delete operation + + + + + + Nodes that need to supress default confirmation dialog shown during delete action + can do this if they return Boolean.TRUE from Node.getValue(String) + for attribute customDelete. + + + + Added paramater leaf to DialogDescriptor Index: openide/arch/arch-openide-explorer.xml =================================================================== RCS file: /cvs/openide/arch/arch-openide-explorer.xml,v retrieving revision 1.19 diff -u -r1.19 arch-openide-explorer.xml --- openide/arch/arch-openide-explorer.xml 9 Sep 2004 18:09:52 -0000 1.19 +++ openide/arch/arch-openide-explorer.xml 11 Mar 2005 12:12:02 -0000 @@ -370,10 +370,16 @@ --> - + Checks by Drag & Drop support for views. True is regard as default (no matter what jdk's version). False value disallows Drag & Drop in all views. + + + Nodes returing Boolean.TRUE from getValue("customDelete") are assumed to + provide their own confirmation dialog for delete action and explorer will not show + default one when they are deleted. + Index: openide/openide-spec-vers.properties =================================================================== RCS file: /cvs/openide/openide-spec-vers.properties,v retrieving revision 1.166 diff -u -r1.166 openide-spec-vers.properties --- openide/openide-spec-vers.properties 9 Feb 2005 12:33:24 -0000 1.166 +++ openide/openide-spec-vers.properties 11 Mar 2005 12:12:02 -0000 @@ -4,4 +4,4 @@ # Must always be numeric (numbers separated by '.', e.g. 4.11). # See http://openide.netbeans.org/versioning-policy.html for more. -openide.specification.version=5.5 +openide.specification.version=5.6 Index: openide/src/org/openide/explorer/ExplorerActions.java =================================================================== RCS file: /cvs/openide/src/org/openide/explorer/ExplorerActions.java,v retrieving revision 1.65 diff -u -r1.65 ExplorerActions.java --- openide/src/org/openide/explorer/ExplorerActions.java 19 Feb 2004 13:01:00 -0000 1.65 +++ openide/src/org/openide/explorer/ExplorerActions.java 11 Mar 2005 12:12:02 -0000 @@ -634,6 +634,16 @@ private boolean doConfirm(Node[] sel) { String message, title; + boolean customDelete = true; + for (int i = 0; i < sel.length; i++) { + if (!Boolean.TRUE.equals(sel[i].getValue("customDelete"))) { // NOI18N + customDelete = false; + break; + } + } + if (customDelete) { + return true; + } if (sel.length == 1) { /* Treatment of special cases removed * Index: openide/src/org/openide/explorer/ExplorerActionsImpl.java =================================================================== RCS file: /cvs/openide/src/org/openide/explorer/ExplorerActionsImpl.java,v retrieving revision 1.7 diff -u -r1.7 ExplorerActionsImpl.java --- openide/src/org/openide/explorer/ExplorerActionsImpl.java 7 Sep 2004 08:51:19 -0000 1.7 +++ openide/src/org/openide/explorer/ExplorerActionsImpl.java 11 Mar 2005 12:12:02 -0000 @@ -523,6 +523,16 @@ private boolean doConfirm(Node[] sel) { String message, title; + boolean customDelete = true; + for (int i = 0; i < sel.length; i++) { + if (!Boolean.TRUE.equals(sel[i].getValue("customDelete"))) { // NOI18N + customDelete = false; + break; + } + } + if (customDelete) { + return true; + } if (sel.length == 1) { /* Treatment of special cases removed * Index: openide/test/unit/src/org/openide/explorer/ExplorerActionsImplTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/explorer/ExplorerActionsImplTest.java,v retrieving revision 1.6 diff -u -r1.6 ExplorerActionsImplTest.java --- openide/test/unit/src/org/openide/explorer/ExplorerActionsImplTest.java 21 Nov 2003 10:51:20 -0000 1.6 +++ openide/test/unit/src/org/openide/explorer/ExplorerActionsImplTest.java 11 Mar 2005 12:12:02 -0000 @@ -62,13 +62,13 @@ /** Creates a manager to operate on. */ - protected Object[] createManagerAndContext () { + protected Object[] createManagerAndContext (boolean confirm) { ExplorerManager em = new ExplorerManager (); ActionMap map = new ActionMap (); map.put (DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(em)); map.put (DefaultEditorKit.cutAction, ExplorerUtils.actionCut(em)); map.put (DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(em)); - map.put ("delete", ExplorerUtils.actionDelete(em, false)); + map.put ("delete", ExplorerUtils.actionDelete(em, confirm)); return new Object[] { em, org.openide.util.lookup.Lookups.singleton(map) }; } Index: openide/test/unit/src/org/openide/explorer/ExplorerPanelTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/explorer/ExplorerPanelTest.java,v retrieving revision 1.11 diff -u -r1.11 ExplorerPanelTest.java --- openide/test/unit/src/org/openide/explorer/ExplorerPanelTest.java 4 Aug 2004 11:07:33 -0000 1.11 +++ openide/test/unit/src/org/openide/explorer/ExplorerPanelTest.java 11 Mar 2005 12:12:02 -0000 @@ -24,6 +24,8 @@ import org.netbeans.junit.NbTestSuite; import javax.swing.Action; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; import org.openide.actions.CopyAction; import org.openide.actions.CutAction; @@ -78,7 +80,7 @@ protected final void setUp () { System.setProperty ("org.openide.util.Lookup", "org.openide.explorer.ExplorerPanelTest$Lkp"); - Object[] arr = createManagerAndContext (); + Object[] arr = createManagerAndContext (false); manager = (ExplorerManager)arr[0]; context = (Lookup)arr[1]; @@ -86,8 +88,8 @@ /** Creates a manager to operate on. */ - protected Object[] createManagerAndContext () { - ep = new ExplorerPanel (null, false); + protected Object[] createManagerAndContext (boolean confirm) { + ep = new ExplorerPanel (null, confirm); return new Object[] { ep.getExplorerManager(), ep.getLookup() }; } @@ -172,6 +174,63 @@ } + public void testDeleteConfirmAction () throws Exception { + TestNode [] nodes = new TestNode [] { + new TestNode(true, true, true), + new TestNode(true, true, true, true), + new TestNode(true, true, true), + new TestNode(true, true, true, true), + new TestNode(false, false, false) + }; + + YesDialogDisplayer ydd = (YesDialogDisplayer)Lookup.getDefault().lookup(YesDialogDisplayer.class); + DialogDisplayer dd = (DialogDisplayer)Lookup.getDefault().lookup(DialogDisplayer.class); + assertNotNull("Custom DialogDisplayer is not set", ydd); + int notifyCount = ydd.getNotifyCount(); + assertEquals("YesDialogDisplayer is current DialogDisplayer", ydd, dd); + + Object[] arr = createManagerAndContext (true); + + ExplorerPanel delep = new ExplorerPanel ((ExplorerManager)arr[0], true); + ExplorerManager delManager = delep.getExplorerManager(); + delManager.setRootContext(new TestRoot( + nodes)); + + Action delete = ((ContextAwareAction)SystemAction.get(org.openide.actions.DeleteAction.class)).createContextAwareInstance((Lookup)arr[1]); + + // delete should ask for confirmation + delManager.setSelectedNodes (new Node[] { nodes[0] }); + assertTrue ("It gets enabled", delete.isEnabled ()); + + delete.actionPerformed(new java.awt.event.ActionEvent (this, 0, "waitFinished")); + + assertEquals ("Destoy was called", 1, nodes[0].countDelete); + + assertEquals ("Confirm delete was called ", notifyCount+1, ydd.getNotifyCount()); + + // but delete should not ask for confirmation if the node wants to perform handle delete + delManager.setSelectedNodes (new Node[] { nodes[1] }); + assertTrue ("It gets enabled", delete.isEnabled ()); + + delete.actionPerformed(new java.awt.event.ActionEvent (this, 0, "waitFinished")); + + assertEquals ("Destoy was called", 1, nodes[1].countDelete); + + assertEquals ("Confirm delete was called ", notifyCount+1, ydd.getNotifyCount()); // no next dialog + + // anyway ask for confirmation if at least one node has default behaviour + delManager.setSelectedNodes (new Node[] { nodes[2], nodes[3] }); + assertTrue ("It gets enabled", delete.isEnabled ()); + + delete.actionPerformed(new java.awt.event.ActionEvent (this, 0, "waitFinished")); + + assertEquals ("Destoy was called", 1, nodes[2].countDelete); + assertEquals ("Destoy was called", 1, nodes[3].countDelete); + + assertEquals ("Confirm delete was called ", notifyCount+2, ydd.getNotifyCount()); // no next dialog + + } + public void testPasteAction () throws Exception { TestNode enabledNode = new TestNode(true, true, true); TestNode disabledNode = new TestNode(false, false, false); @@ -317,6 +376,7 @@ public boolean canCopy; public boolean canCut; public boolean canDelete; + private boolean customDelete; public PasteType[] types = new PasteType[0]; public java.awt.datatransfer.Transferable lastTransferable; @@ -324,6 +384,11 @@ public int countCut; public int countDelete; + public TestNode(boolean canCopy, boolean canCut, boolean canDelete, boolean customDelete) { + this (canCopy, canCut, canDelete); + this.customDelete = customDelete; + } + public TestNode(boolean b, boolean c, boolean d) { super(Children.LEAF); canCopy = b; @@ -370,6 +435,13 @@ this.lastTransferable = t; s.addAll (Arrays.asList (types)); } + + public Object getValue(String attributeName) { + if (customDelete && "customDelete".equals(attributeName)) { + return Boolean.TRUE; + } + return super.getValue(attributeName); + } } @@ -416,6 +488,7 @@ private Lkp (org.openide.util.lookup.InstanceContent ic) { super (ic); ic.add (new Clb ("Testing clipboard")); + ic.add (new YesDialogDisplayer()); } } @@ -431,6 +504,27 @@ public void setContents (Transferable t, ClipboardOwner o) { super.setContents (t, o); fireClipboardChange (); + } + } + + private static final class YesDialogDisplayer extends DialogDisplayer { + private int counter = 0; + + public YesDialogDisplayer() { + super(); + } + + public Object notify(org.openide.NotifyDescriptor descriptor) { + counter++; + return NotifyDescriptor.YES_OPTION; + } + + public java.awt.Dialog createDialog(org.openide.DialogDescriptor descriptor) { + return null; + } + + public int getNotifyCount() { + return counter; } } }