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.netbeans.core;
043:
044: import java.io.*;
045: import java.util.*;
046: import org.netbeans.junit.NbTestCase;
047: import org.openide.filesystems.*;
048: import org.openide.actions.*;
049: import org.openide.loaders.DataLoader;
050: import org.openide.loaders.MultiDataObject;
051: import org.openide.loaders.UniFileLoader;
052: import org.openide.nodes.Index;
053: import org.openide.nodes.Node;
054: import org.openide.util.actions.SystemAction;
055:
056: /**
057: *
058: * @author Jaroslav Tulach
059: */
060: public class LoaderPoolNodeReorderTest extends NbTestCase {
061: private OldStyleLoader oldL;
062: private NewStyleLoader newL;
063:
064: public LoaderPoolNodeReorderTest(String testName) {
065: super (testName);
066: }
067:
068: protected @Override
069: void setUp() throws Exception {
070: LoaderPoolNode.installationFinished();
071:
072: oldL = DataLoader.getLoader(OldStyleLoader.class);
073: newL = DataLoader.getLoader(NewStyleLoader.class);
074: LoaderPoolNode.doAdd(oldL, null);
075: LoaderPoolNode.doAdd(newL, null);
076: LoaderPoolNode.waitFinished();
077: }
078:
079: protected @Override
080: void tearDown() throws Exception {
081: for (Enumeration en = LoaderPoolNode.getNbLoaderPool()
082: .loaders(); en.hasMoreElements();) {
083: DataLoader l = (DataLoader) en.nextElement();
084:
085: LoaderPoolNode.remove(l);
086: }
087: LoaderPoolNode.waitFinished();
088: }
089:
090: public void testReorderABit() throws Exception {
091: {
092: Node[] arr = extractFixed(LoaderPoolNode
093: .getLoaderPoolNode().getChildren().getNodes());
094: assertEquals(2, arr.length);
095: assertEquals(arr[0].getDisplayName(), oldL.getDisplayName());
096: assertEquals(arr[1].getDisplayName(), newL.getDisplayName());
097: }
098:
099: Index idx = LoaderPoolNode.getLoaderPoolNode().getLookup()
100: .lookup(Index.class);
101: assertNotNull("There is index in the node", idx);
102:
103: idx.reorder(new int[] { 1, 0 });
104: LoaderPoolNode.waitFinished();
105:
106: {
107: Node[] arr = extractFixed(LoaderPoolNode
108: .getLoaderPoolNode().getChildren().getNodes());
109: assertEquals(2, arr.length);
110: assertEquals("reord1", arr[1].getDisplayName(), oldL
111: .getDisplayName());
112: assertEquals("reord0", arr[0].getDisplayName(), newL
113: .getDisplayName());
114: }
115:
116: idx.reorder(new int[] { 1, 0 });
117: LoaderPoolNode.waitFinished();
118:
119: {
120: Node[] arr = extractFixed(LoaderPoolNode
121: .getLoaderPoolNode().getChildren().getNodes());
122: assertEquals(2, arr.length);
123: assertEquals("noreord0", arr[0].getDisplayName(), oldL
124: .getDisplayName());
125: assertEquals("noreord1", arr[1].getDisplayName(), newL
126: .getDisplayName());
127: }
128: }
129:
130: private static Node[] extractFixed(Node[] arr) {
131: List<Node> all = new ArrayList<Node>();
132: for (Node n : arr) {
133: if (!n.getDisplayName().contains("fixed")) {
134: all.add(n);
135: }
136: }
137: return all.toArray(new Node[0]);
138: }
139:
140: public static class OldStyleLoader extends UniFileLoader {
141: boolean defaultActionsCalled;
142:
143: public OldStyleLoader() {
144: super (MultiDataObject.class.getName());
145:
146: setDisplayName(getClass().getName());
147: }
148:
149: protected MultiDataObject createMultiObject(FileObject fo)
150: throws IOException {
151: throw new IOException("Not implemented");
152: }
153:
154: protected SystemAction[] defaultActions() {
155: defaultActionsCalled = true;
156: SystemAction[] retValue;
157:
158: retValue = super .defaultActions();
159: return retValue;
160: }
161:
162: }
163:
164: public static final class NewStyleLoader extends OldStyleLoader {
165: protected String actionsContext() {
166: return "Loaders/IamTheNewBeggining";
167: }
168: }
169:
170: public static final class L1 extends OldStyleLoader {
171: }
172:
173: public static final class L2 extends OldStyleLoader {
174: }
175:
176: public static final class L3 extends OldStyleLoader {
177: }
178:
179: public static final class L4 extends OldStyleLoader {
180: }
181:
182: public static final class L5 extends OldStyleLoader {
183: }
184: }
|