001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.openide.explorer;
043:
044: import java.util.Arrays;
045:
046: import junit.framework.Test;
047: import junit.framework.TestSuite;
048: import org.netbeans.junit.NbTestCase;
049: import org.netbeans.junit.NbTestSuite;
050:
051: import javax.swing.Action;
052: import javax.swing.ActionMap;
053: import javax.swing.JMenu;
054: import javax.swing.text.DefaultEditorKit;
055:
056: import org.openide.actions.CopyAction;
057: import org.openide.actions.CutAction;
058: import org.openide.nodes.Children;
059: import org.openide.nodes.Node;
060: import org.openide.nodes.AbstractNode;
061: import org.openide.util.actions.SystemAction;
062: import org.openide.util.ContextAwareAction;
063: import org.openide.util.Lookup;
064: import org.openide.util.Utilities;
065: import org.openide.util.datatransfer.PasteType;
066:
067: /**
068: * Test whether the old behaviour of ExplorerPanel is correctly simulated
069: * by new API. Inherits testing methods from ExplorerPanel tests, just
070: * setup is changed.
071: *
072: * @author Jaroslav Tulach
073: */
074: public class ExplorerActionsImplTest extends ExplorerPanelTest {
075:
076: public ExplorerActionsImplTest(java.lang.String testName) {
077: super (testName);
078: }
079:
080: public static void main(java.lang.String[] args) {
081: junit.textui.TestRunner.run(suite());
082: }
083:
084: public static Test suite() {
085: TestSuite suite = new NbTestSuite(ExplorerActionsImplTest.class);
086: return suite;
087: }
088:
089: /** Creates a manager to operate on.
090: */
091: protected Object[] createManagerAndContext(boolean confirm) {
092: ExplorerManager em = new ExplorerManager();
093: ActionMap map = new ActionMap();
094: map.put(DefaultEditorKit.copyAction, ExplorerUtils
095: .actionCopy(em));
096: map
097: .put(DefaultEditorKit.cutAction, ExplorerUtils
098: .actionCut(em));
099: map.put(DefaultEditorKit.pasteAction, ExplorerUtils
100: .actionPaste(em));
101: map.put("delete", ExplorerUtils.actionDelete(em, confirm));
102:
103: return new Object[] { em,
104: org.openide.util.lookup.Lookups.singleton(map) };
105: }
106:
107: /** Instructs the actions to stop/
108: */
109: protected void stopActions(ExplorerManager em) {
110: ExplorerUtils.activateActions(em, false);
111: }
112:
113: /** Instructs the actions to start again.
114: */
115: protected void startActions(ExplorerManager em) {
116: ExplorerUtils.activateActions(em, true);
117: }
118:
119: public void testActionDeleteDoesNotAffectStateOfPreviousInstances()
120: throws Exception {
121: ExplorerManager em = new ExplorerManager();
122: Action a1 = ExplorerUtils.actionDelete(em, false);
123: Action a2 = ExplorerUtils.actionDelete(em, true);
124:
125: Node node = new AbstractNode(Children.LEAF) {
126: public boolean canDestroy() {
127: return true;
128: }
129: };
130: em.setRootContext(node);
131: em.setSelectedNodes(new Node[] { node });
132:
133: assertTrue("A1 enabled", a1.isEnabled());
134: assertTrue("A2 enabled", a2.isEnabled());
135:
136: // this should not show a dialog
137: a1.actionPerformed(new java.awt.event.ActionEvent(this , 0, ""));
138: }
139: }
|