Lines 24-29
Link Here
|
24 |
import org.netbeans.junit.NbTestSuite; |
24 |
import org.netbeans.junit.NbTestSuite; |
25 |
|
25 |
|
26 |
import javax.swing.Action; |
26 |
import javax.swing.Action; |
|
|
27 |
import org.openide.DialogDisplayer; |
28 |
import org.openide.NotifyDescriptor; |
27 |
|
29 |
|
28 |
import org.openide.actions.CopyAction; |
30 |
import org.openide.actions.CopyAction; |
29 |
import org.openide.actions.CutAction; |
31 |
import org.openide.actions.CutAction; |
Lines 78-84
Link Here
|
78 |
protected final void setUp () { |
80 |
protected final void setUp () { |
79 |
System.setProperty ("org.openide.util.Lookup", "org.openide.explorer.ExplorerPanelTest$Lkp"); |
81 |
System.setProperty ("org.openide.util.Lookup", "org.openide.explorer.ExplorerPanelTest$Lkp"); |
80 |
|
82 |
|
81 |
Object[] arr = createManagerAndContext (); |
83 |
Object[] arr = createManagerAndContext (false); |
82 |
manager = (ExplorerManager)arr[0]; |
84 |
manager = (ExplorerManager)arr[0]; |
83 |
context = (Lookup)arr[1]; |
85 |
context = (Lookup)arr[1]; |
84 |
|
86 |
|
Lines 86-93
Link Here
|
86 |
|
88 |
|
87 |
/** Creates a manager to operate on. |
89 |
/** Creates a manager to operate on. |
88 |
*/ |
90 |
*/ |
89 |
protected Object[] createManagerAndContext () { |
91 |
protected Object[] createManagerAndContext (boolean confirm) { |
90 |
ep = new ExplorerPanel (null, false); |
92 |
ep = new ExplorerPanel (null, confirm); |
91 |
return new Object[] { ep.getExplorerManager(), ep.getLookup() }; |
93 |
return new Object[] { ep.getExplorerManager(), ep.getLookup() }; |
92 |
} |
94 |
} |
93 |
|
95 |
|
Lines 172-177
Link Here
|
172 |
|
174 |
|
173 |
} |
175 |
} |
174 |
|
176 |
|
|
|
177 |
public void testDeleteConfirmAction () throws Exception { |
178 |
TestNode [] nodes = new TestNode [] { |
179 |
new TestNode(true, true, true), |
180 |
new TestNode(true, true, true, true), |
181 |
new TestNode(true, true, true), |
182 |
new TestNode(true, true, true, true), |
183 |
new TestNode(false, false, false) |
184 |
}; |
185 |
|
186 |
YesDialogDisplayer ydd = (YesDialogDisplayer)Lookup.getDefault().lookup(YesDialogDisplayer.class); |
187 |
DialogDisplayer dd = (DialogDisplayer)Lookup.getDefault().lookup(DialogDisplayer.class); |
188 |
assertNotNull("Custom DialogDisplayer is not set", ydd); |
189 |
int notifyCount = ydd.getNotifyCount(); |
190 |
assertEquals("YesDialogDisplayer is current DialogDisplayer", ydd, dd); |
191 |
|
192 |
Object[] arr = createManagerAndContext (true); |
193 |
|
194 |
ExplorerPanel delep = new ExplorerPanel ((ExplorerManager)arr[0], true); |
195 |
ExplorerManager delManager = delep.getExplorerManager(); |
196 |
delManager.setRootContext(new TestRoot( |
197 |
nodes)); |
198 |
|
199 |
Action delete = ((ContextAwareAction)SystemAction.get(org.openide.actions.DeleteAction.class)).createContextAwareInstance((Lookup)arr[1]); |
200 |
|
201 |
// delete should ask for confirmation |
202 |
delManager.setSelectedNodes (new Node[] { nodes[0] }); |
203 |
assertTrue ("It gets enabled", delete.isEnabled ()); |
204 |
|
205 |
delete.actionPerformed(new java.awt.event.ActionEvent (this, 0, "waitFinished")); |
206 |
|
207 |
assertEquals ("Destoy was called", 1, nodes[0].countDelete); |
208 |
|
209 |
assertEquals ("Confirm delete was called ", notifyCount+1, ydd.getNotifyCount()); |
210 |
|
211 |
// but delete should not ask for confirmation if the node wants to perform handle delete |
212 |
delManager.setSelectedNodes (new Node[] { nodes[1] }); |
213 |
assertTrue ("It gets enabled", delete.isEnabled ()); |
214 |
|
215 |
delete.actionPerformed(new java.awt.event.ActionEvent (this, 0, "waitFinished")); |
216 |
|
217 |
assertEquals ("Destoy was called", 1, nodes[1].countDelete); |
218 |
|
219 |
assertEquals ("Confirm delete was called ", notifyCount+1, ydd.getNotifyCount()); // no next dialog |
220 |
|
221 |
// anyway ask for confirmation if at least one node has default behaviour |
222 |
delManager.setSelectedNodes (new Node[] { nodes[2], nodes[3] }); |
223 |
assertTrue ("It gets enabled", delete.isEnabled ()); |
224 |
|
225 |
delete.actionPerformed(new java.awt.event.ActionEvent (this, 0, "waitFinished")); |
226 |
|
227 |
assertEquals ("Destoy was called", 1, nodes[2].countDelete); |
228 |
assertEquals ("Destoy was called", 1, nodes[3].countDelete); |
229 |
|
230 |
assertEquals ("Confirm delete was called ", notifyCount+2, ydd.getNotifyCount()); // no next dialog |
231 |
|
232 |
} |
233 |
|
175 |
public void testPasteAction () throws Exception { |
234 |
public void testPasteAction () throws Exception { |
176 |
TestNode enabledNode = new TestNode(true, true, true); |
235 |
TestNode enabledNode = new TestNode(true, true, true); |
177 |
TestNode disabledNode = new TestNode(false, false, false); |
236 |
TestNode disabledNode = new TestNode(false, false, false); |
Lines 317-322
Link Here
|
317 |
public boolean canCopy; |
376 |
public boolean canCopy; |
318 |
public boolean canCut; |
377 |
public boolean canCut; |
319 |
public boolean canDelete; |
378 |
public boolean canDelete; |
|
|
379 |
private boolean customDelete; |
320 |
public PasteType[] types = new PasteType[0]; |
380 |
public PasteType[] types = new PasteType[0]; |
321 |
public java.awt.datatransfer.Transferable lastTransferable; |
381 |
public java.awt.datatransfer.Transferable lastTransferable; |
322 |
|
382 |
|
Lines 324-329
Link Here
|
324 |
public int countCut; |
384 |
public int countCut; |
325 |
public int countDelete; |
385 |
public int countDelete; |
326 |
|
386 |
|
|
|
387 |
public TestNode(boolean canCopy, boolean canCut, boolean canDelete, boolean customDelete) { |
388 |
this (canCopy, canCut, canDelete); |
389 |
this.customDelete = customDelete; |
390 |
} |
391 |
|
327 |
public TestNode(boolean b, boolean c, boolean d) { |
392 |
public TestNode(boolean b, boolean c, boolean d) { |
328 |
super(Children.LEAF); |
393 |
super(Children.LEAF); |
329 |
canCopy = b; |
394 |
canCopy = b; |
Lines 370-375
Link Here
|
370 |
this.lastTransferable = t; |
435 |
this.lastTransferable = t; |
371 |
s.addAll (Arrays.asList (types)); |
436 |
s.addAll (Arrays.asList (types)); |
372 |
} |
437 |
} |
|
|
438 |
|
439 |
public Object getValue(String attributeName) { |
440 |
if (customDelete && "customDelete".equals(attributeName)) { |
441 |
return Boolean.TRUE; |
442 |
} |
443 |
return super.getValue(attributeName); |
444 |
} |
373 |
|
445 |
|
374 |
} |
446 |
} |
375 |
|
447 |
|
Lines 416-421
Link Here
|
416 |
private Lkp (org.openide.util.lookup.InstanceContent ic) { |
488 |
private Lkp (org.openide.util.lookup.InstanceContent ic) { |
417 |
super (ic); |
489 |
super (ic); |
418 |
ic.add (new Clb ("Testing clipboard")); |
490 |
ic.add (new Clb ("Testing clipboard")); |
|
|
491 |
ic.add (new YesDialogDisplayer()); |
419 |
} |
492 |
} |
420 |
} |
493 |
} |
421 |
|
494 |
|
Lines 431-436
Link Here
|
431 |
public void setContents (Transferable t, ClipboardOwner o) { |
504 |
public void setContents (Transferable t, ClipboardOwner o) { |
432 |
super.setContents (t, o); |
505 |
super.setContents (t, o); |
433 |
fireClipboardChange (); |
506 |
fireClipboardChange (); |
|
|
507 |
} |
508 |
} |
509 |
|
510 |
private static final class YesDialogDisplayer extends DialogDisplayer { |
511 |
private int counter = 0; |
512 |
|
513 |
public YesDialogDisplayer() { |
514 |
super(); |
515 |
} |
516 |
|
517 |
public Object notify(org.openide.NotifyDescriptor descriptor) { |
518 |
counter++; |
519 |
return NotifyDescriptor.YES_OPTION; |
520 |
} |
521 |
|
522 |
public java.awt.Dialog createDialog(org.openide.DialogDescriptor descriptor) { |
523 |
return null; |
524 |
} |
525 |
|
526 |
public int getNotifyCount() { |
527 |
return counter; |
434 |
} |
528 |
} |
435 |
} |
529 |
} |
436 |
} |
530 |
} |