001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.testtools;
021:
022: /*
023: * XTestDataLoader.java
024: *
025: * Created on May 2, 2002, 4:07 PM
026: */
027:
028: import java.io.IOException;
029: import java.io.BufferedReader;
030: import java.io.InputStreamReader;
031:
032: import org.openide.actions.*;
033: import org.openide.nodes.Node;
034: import org.openide.util.HelpCtx;
035: import org.openide.compiler.Compiler;
036: import org.openide.filesystems.FileObject;
037: import org.openide.util.actions.SystemAction;
038: import org.openide.loaders.UniFileLoader;
039: import org.openide.loaders.MultiDataObject;
040: import org.openide.loaders.DataObjectExistsException;
041:
042: import org.openide.util.NbBundle;
043:
044: /** Data Loader class for XTest Workspace Script Data Object
045: * @author <a href="mailto:adam.sotona@sun.com">Adam Sotona</a> */
046: public class XTestDataLoader extends UniFileLoader {
047:
048: static final long serialVersionUID = 3860621574863539101L;
049:
050: /** creates new XTestDataLoader */
051: public XTestDataLoader() {
052: super ("XTestDataObject");
053: }
054:
055: /** returns default display name of XTestDataObject
056: * @return String default display name of XTestDataObject */
057: protected String defaultDisplayName() {
058: return NbBundle.getMessage(XTestDataLoader.class,
059: "XTestBuildScriptName"); // NOI18N
060: }
061:
062: /** performs initialization of Data Loader */
063: protected void initialize() {
064: super .initialize();
065: getExtensions().addMimeType("text/x-ant+xml"); // NOI18N
066: }
067:
068: /** returns default System Actions supported by XTestDataObject
069: * @return array of SystemAction */
070: protected SystemAction[] defaultActions() {
071: return new SystemAction[] { SystemAction.get(OpenAction.class),
072: SystemAction.get(FileSystemAction.class), null,
073: SystemAction.get(OpenLocalExplorerAction.class), null,
074: SystemAction.get(CleanAction.class), null,
075: SystemAction.get(CompileAction.class), null,
076: SystemAction.get(ExecuteAction.class), null,
077: SystemAction.get(CleanResultsAction.class), null,
078: SystemAction.get(CutAction.class),
079: SystemAction.get(CopyAction.class),
080: SystemAction.get(PasteAction.class), null,
081: SystemAction.get(ReorderAction.class), null,
082: SystemAction.get(DeleteAction.class),
083: SystemAction.get(RenameAction.class), null,
084: SystemAction.get(NewAction.class), null,
085: SystemAction.get(SaveAsTemplateAction.class), null,
086: SystemAction.get(ToolsAction.class),
087: SystemAction.get(PropertiesAction.class), };
088: }
089:
090: /** performs recognition of XTestDataObject
091: * @param fo tested FileObject
092: * @return given FileObject or null when XTestDataObject not recognized */
093: protected FileObject findPrimaryFile(FileObject fo) {
094: fo = super .findPrimaryFile(fo);
095: if (fo == null)
096: return null;
097: try {
098: BufferedReader br = new BufferedReader(
099: new InputStreamReader(fo.getInputStream()));
100: String line;
101: while ((line = br.readLine()) != null)
102: if (line.indexOf("\"xtest.module\"") >= 0) { // NOI18N
103: br.close();
104: return fo;
105: }
106: } catch (Exception e) {
107: }
108: return null;
109: }
110:
111: /** creates instance of XTestDataObject for given FileObject
112: * @param primaryFile FileObject
113: * @throws DataObjectExistsException when Data Object already exists
114: * @throws IOException when some IO problems
115: * @return new XTestDataObject for given FileObject */
116: protected MultiDataObject createMultiObject(FileObject primaryFile)
117: throws DataObjectExistsException, IOException {
118: return new XTestDataObject(primaryFile, this );
119: }
120:
121: /** Action performing cleanup of XTest results */
122: public static class CleanResultsAction extends
123: AbstractCompileAction {
124: /** returns Depth of Compiler
125: * @return Compiler.DEPTH_ONE */
126: protected Compiler.Depth depth() {
127: return Compiler.DEPTH_ONE;
128: }
129:
130: /** returns Cookie for this Action
131: * @return XTestDataObject.CleanResults.class */
132: protected final Class cookie() {
133: return XTestDataObject.CleanResults.class;
134: }
135:
136: /** returns name of the Action
137: * @return String Action name */
138: public String getName() {
139: return NbBundle.getMessage(XTestDataLoader.class,
140: "CleanResultsActionName"); // NOI18N
141: }
142:
143: /** returns Help Context of the Action
144: * @return HelpCtx */
145: public HelpCtx getHelpCtx() {
146: return new HelpCtx(CleanResultsAction.class);
147: }
148: }
149: }
|