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.modules.apisupport.project.ui.wizard.action;
043:
044: import java.io.File;
045: import java.util.Arrays;
046: import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
047: import org.netbeans.modules.apisupport.project.CreatedModifiedFilesTest;
048: import org.netbeans.modules.apisupport.project.NbModuleProject;
049: import org.netbeans.modules.apisupport.project.TestBase;
050: import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
051: import org.netbeans.modules.apisupport.project.layers.LayerUtils;
052: import org.netbeans.modules.apisupport.project.ui.wizard.action.DataModel.Position;
053: import org.netbeans.modules.project.uiapi.ProjectChooserFactory;
054: import org.openide.WizardDescriptor;
055: import org.openide.filesystems.FileObject;
056: import org.openide.filesystems.FileUtil;
057:
058: /**
059: * Tests {@link DataModel}.
060: *
061: * @author Martin Krauskopf
062: */
063: public class DataModelTest extends LayerTestBase {
064:
065: public DataModelTest(String name) {
066: super (name);
067: }
068:
069: protected void setUp() throws Exception {
070: super .setUp();
071: TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
072: }
073:
074: public void testDataModelGenarationForAlwaysEnabledActions()
075: throws Exception {
076: NbModuleProject project = TestBase.generateStandaloneModule(
077: getWorkDir(), "module1");
078: LayerUtils.LayerHandle handle = LayerUtils
079: .layerForProject(project);
080: FileObject root = handle.layer(true).getRoot();
081: FileUtil
082: .createData(root, "Menu/Help/Tutorials/quick-start.url")
083: .setAttribute("position", 100);
084: FileUtil.createData(root,
085: "Menu/Help/Tutorials/prj-import-guide.url")
086: .setAttribute("position", 200);
087: FileUtil
088: .createData(root,
089: "Toolbars/Edit/org-openide-actions-FindAction.instance")
090: .setAttribute("position", 600);
091:
092: WizardDescriptor wd = new WizardDescriptor() {
093: };
094: wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT,
095: project);
096: DataModel data = new DataModel(wd);
097:
098: // first panel data (Action Type)
099: data.setAlwaysEnabled(true);
100:
101: // second panel data (GUI Registration)
102: data.setCategory("Actions/Tools");
103: // global menu item
104: data.setGlobalMenuItemEnabled(true);
105: data.setGMIParentMenu("Menu/Help/Tutorials");
106: data.setGMIPosition(new Position("quick-start.url",
107: "prj-import-guide.url"));
108: data.setGMISeparatorBefore(true);
109: data.setGMISeparatorAfter(true);
110: // global toolbar button
111: data.setToolbarEnabled(true);
112: data.setToolbar("Toolbars/Edit");
113: data.setToolbarPosition(new Position(
114: "org-openide-actions-FindAction.instance", null));
115: // global keyboard shortcut
116: data.setKeyboardShortcutEnabled(true);
117: data.setKeyStroke("DA-B");
118:
119: // third panel data (Name, Icon, and Location)
120: data.setClassName("BeepAction");
121: data.setDisplayName("Beep");
122: data.setPackageName("org.example.module1");
123:
124: CreatedModifiedFiles cmf = data.getCreatedModifiedFiles();
125: assertEquals(Arrays.asList(new String[] {
126: "src/org/example/module1/BeepAction.java",
127: "src/org/example/module1/Bundle.properties" }), Arrays
128: .asList(cmf.getCreatedPaths()));
129: assertEquals(Arrays.asList(new String[] {
130: "nbproject/project.xml",
131: "src/org/example/module1/resources/layer.xml" }),
132: Arrays.asList(cmf.getModifiedPaths()));
133:
134: cmf.run();
135:
136: String[] supposedContent = new String[] {
137: "<filesystem>",
138: "<folder name=\"Actions\">",
139: "<folder name=\"Tools\">",
140: "<file name=\"org-example-module1-BeepAction.instance\"/>",
141: "</folder>",
142: "</folder>",
143: "<folder name=\"Menu\">",
144: "<folder name=\"Help\">",
145: "<folder name=\"Tutorials\">",
146: "<file name=\"org-example-module1-BeepAction.shadow\">",
147: "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
148: "<attr name=\"position\" intvalue=\"150\"/>",
149: "</file>",
150: "<file name=\"org-example-module1-separatorAfter.instance\">",
151: "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
152: "<attr name=\"position\" intvalue=\"175\"/>",
153: "</file>",
154: "<file name=\"org-example-module1-separatorBefore.instance\">",
155: "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
156: "<attr name=\"position\" intvalue=\"125\"/>",
157: "</file>",
158: "<file name=\"prj-import-guide.url\">",
159: "<attr name=\"position\" intvalue=\"200\"/>",
160: "</file>",
161: "<file name=\"quick-start.url\">",
162: "<attr name=\"position\" intvalue=\"100\"/>",
163: "</file>",
164: "</folder>",
165: "</folder>",
166: "</folder>",
167: "<folder name=\"Shortcuts\">",
168: "<file name=\"DA-B.shadow\">",
169: "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
170: "</file>",
171: "</folder>",
172: "<folder name=\"Toolbars\">",
173: "<folder name=\"Edit\">",
174: "<file name=\"org-example-module1-BeepAction.shadow\">",
175: "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
176: "<attr name=\"position\" intvalue=\"700\"/>",
177: "</file>",
178: "<file name=\"org-openide-actions-FindAction.instance\">",
179: "<attr name=\"position\" intvalue=\"600\"/>",
180: "</file>", "</folder>", "</folder>", "</filesystem>" };
181:
182: CreatedModifiedFilesTest
183: .assertLayerContent(
184: supposedContent,
185: new File(getWorkDir(),
186: "module1/src/org/example/module1/resources/layer.xml"));
187: }
188:
189: public void testDataModelGenarationForConditionallyEnabledActions()
190: throws Exception {
191: NbModuleProject project = TestBase.generateStandaloneModule(
192: getWorkDir(), "module1");
193: WizardDescriptor wd = new WizardDescriptor() {
194: };
195: wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT,
196: project);
197: DataModel data = new DataModel(wd);
198:
199: // first panel data (Action Type)
200: data.setAlwaysEnabled(false);
201: data.setCookieClasses(new String[] {
202: DataModel.PREDEFINED_COOKIE_CLASSES[1],
203: DataModel.PREDEFINED_COOKIE_CLASSES[2] });
204: data.setMultiSelection(false);
205:
206: // second panel data (GUI Registration)
207: data.setCategory("Actions/Tools");
208: // global menu item
209: data.setGlobalMenuItemEnabled(true);
210: data.setGMIParentMenu("Menu/Help/Tutorials");
211: data.setGMIPosition(new Position("quick-start.url",
212: "prj-import-guide.url"));
213: data.setGMISeparatorBefore(true);
214: data.setGMISeparatorAfter(true);
215: // global toolbar button
216: data.setToolbarEnabled(true);
217: data.setToolbar("Toolbars/Edit");
218: data.setToolbarPosition(new Position(
219: "org-openide-actions-FindAction.instance", null));
220: // file type context menu item
221: data.setFileTypeContextEnabled(true);
222: data.setFTContextType("Loaders/text/x-java/Actions");
223: data.setFTContextPosition(new Position(null,
224: "OpenAction.instance"));
225: data.setFTContextSeparatorBefore(false);
226: data.setFTContextSeparatorAfter(true);
227: // editor context menu item
228: data.setEditorContextEnabled(true);
229: data.setEdContextType("Editors/text/x-java/Popup");
230: data.setEdContextPosition(new Position(null,
231: "generate-goto-popup"));
232: data.setEdContextSeparatorBefore(false);
233: data.setEdContextSeparatorAfter(true);
234:
235: // third panel data (Name, Icon, and Location)
236: data.setClassName("BeepAction");
237: data.setDisplayName("Beep");
238: data.setPackageName("org.example.module1");
239:
240: CreatedModifiedFiles cmf = data.getCreatedModifiedFiles();
241: assertEquals("new files", Arrays.asList(new String[] {
242: "src/org/example/module1/BeepAction.java",
243: "src/org/example/module1/Bundle.properties" }), Arrays
244: .asList(cmf.getCreatedPaths()));
245: assertEquals("modified files", Arrays.asList(new String[] {
246: "nbproject/project.xml",
247: "src/org/example/module1/resources/layer.xml" }),
248: Arrays.asList(cmf.getModifiedPaths()));
249:
250: cmf.run();
251:
252: String[] supposedContent = new String[] {
253: "<filesystem>",
254: "<folder name=\"Actions\">",
255: "<folder name=\"Tools\">",
256: "<file name=\"org-example-module1-BeepAction.instance\"/>",
257: "</folder>",
258: "</folder>",
259: "<folder name=\"Editors\">",
260: "<folder name=\"text\">",
261: "<folder name=\"x-java\">",
262: "<folder name=\"Popup\">",
263: "<attr name=\"org-example-module1-BeepAction.shadow/generate-goto-popup\" boolvalue=\"true\"/>",
264: "<attr name=\"org-example-module1-BeepAction.shadow/org-example-module1-separatorAfter.instance\" boolvalue=\"true\"/>",
265: "<attr name=\"org-example-module1-separatorAfter.instance/generate-goto-popup\" boolvalue=\"true\"/>",
266: "<file name=\"org-example-module1-BeepAction.shadow\">",
267: "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
268: "</file>",
269: "<file name=\"org-example-module1-separatorAfter.instance\">",
270: "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
271: "</file>",
272: "</folder>",
273: "</folder>",
274: "</folder>",
275: "</folder>",
276: "<folder name=\"Loaders\">",
277: "<folder name=\"text\">",
278: "<folder name=\"x-java\">",
279: "<folder name=\"Actions\">",
280: "<attr name=\"org-example-module1-BeepAction.shadow/OpenAction.instance\" boolvalue=\"true\"/>",
281: "<attr name=\"org-example-module1-BeepAction.shadow/org-example-module1-separatorAfter.instance\" boolvalue=\"true\"/>",
282: "<attr name=\"org-example-module1-separatorAfter.instance/OpenAction.instance\" boolvalue=\"true\"/>",
283: "<file name=\"org-example-module1-BeepAction.shadow\">",
284: "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
285: "</file>",
286: "<file name=\"org-example-module1-separatorAfter.instance\">",
287: "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
288: "</file>",
289: "</folder>",
290: "</folder>",
291: "</folder>",
292: "</folder>",
293: "<folder name=\"Menu\">",
294: "<folder name=\"Help\">",
295: "<folder name=\"Tutorials\">",
296: "<attr name=\"org-example-module1-BeepAction.shadow/org-example-module1-separatorAfter.instance\" boolvalue=\"true\"/>",
297: "<attr name=\"org-example-module1-BeepAction.shadow/prj-import-guide.url\" boolvalue=\"true\"/>",
298: "<attr name=\"org-example-module1-separatorAfter.instance/prj-import-guide.url\" boolvalue=\"true\"/>",
299: "<attr name=\"org-example-module1-separatorBefore.instance/org-example-module1-BeepAction.shadow\" boolvalue=\"true\"/>",
300: "<attr name=\"quick-start.url/org-example-module1-BeepAction.shadow\" boolvalue=\"true\"/>",
301: "<attr name=\"quick-start.url/org-example-module1-separatorBefore.instance\" boolvalue=\"true\"/>",
302: "<file name=\"org-example-module1-BeepAction.shadow\">",
303: "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
304: "</file>",
305: "<file name=\"org-example-module1-separatorAfter.instance\">",
306: "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
307: "</file>",
308: "<file name=\"org-example-module1-separatorBefore.instance\">",
309: "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
310: "</file>",
311: "</folder>",
312: "</folder>",
313: "</folder>",
314: "<folder name=\"Toolbars\">",
315: "<folder name=\"Edit\">",
316: "<attr name=\"org-openide-actions-FindAction.instance/org-example-module1-BeepAction.shadow\" boolvalue=\"true\"/>",
317: "<file name=\"org-example-module1-BeepAction.shadow\">",
318: "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
319: "</file>", "</folder>", "</folder>", "</filesystem>" };
320:
321: CreatedModifiedFilesTest
322: .assertLayerContent(
323: supposedContent,
324: new File(getWorkDir(),
325: "module1/src/org/example/module1/resources/layer.xml"));
326: }
327:
328: }
|