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-2007 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.compapp.test.ui;
043:
044: import org.netbeans.modules.compapp.projects.jbi.JbiProject;
045: import org.netbeans.modules.compapp.test.ui.actions.AddTestcaseAction;
046: import org.netbeans.modules.compapp.test.ui.actions.TestCaseOutputCookie;
047: import org.netbeans.modules.compapp.test.ui.actions.TestCaseSaveRecentResultAsOutputAction;
048: import org.netbeans.modules.compapp.test.ui.actions.TestCookie;
049: import java.awt.Image;
050: import java.io.File;
051: import java.util.ArrayList;
052: import javax.swing.Action;
053: import javax.swing.ImageIcon;
054: import org.openide.actions.EditAction;
055: import org.openide.filesystems.FileChangeAdapter;
056: import org.openide.filesystems.FileChangeListener;
057: import org.openide.filesystems.FileObject;
058: import org.openide.filesystems.FileEvent;
059: import org.openide.filesystems.FileUtil;
060: import org.openide.loaders.DataFolder;
061: import org.openide.loaders.DataObject;
062: import org.openide.nodes.Children;
063: import org.openide.nodes.FilterNode;
064: import org.openide.nodes.Node;
065: import org.openide.util.NbBundle;
066: import org.openide.util.Utilities;
067: import org.openide.util.actions.SystemAction;
068: import org.openide.util.RequestProcessor;
069:
070: /**
071: * DOCUMENT ME!
072: *
073: * @author Jun Qian
074: */
075: public class TestCaseOutputNode extends FilterNode {
076: private static final java.util.logging.Logger mLogger = java.util.logging.Logger
077: .getLogger("org.netbeans.modules.compapp.projects.jbi.ui.TestCaseOutputNode"); // NOI18N
078:
079: private static final Image OUTPUT_ICON = Utilities
080: .loadImage(
081: "org/netbeans/modules/compapp/test/ui/resources/output.png",
082: true); // NOI18N
083:
084: private static final Image WARNING_BADGE = Utilities
085: .loadImage(
086: "org/netbeans/modules/compapp/test/ui/resources/warningBadge.gif",
087: true); // NOI18N
088:
089: private JbiProject mProject; // FIXME probably not needed
090: private FileObject mOutputFile;
091: private FileChangeListener mFileChangeListener;
092:
093: private TestCaseOutputCookie mTestCaseOutputCookie;
094:
095: /**
096: * Creates a new TestInputNode object.
097: *
098: * @param jpp DOCUMENT ME!
099: * @param mProject DOCUMENT ME!
100: */
101: public TestCaseOutputNode(JbiProject project,
102: DataObject outputDataObject) {
103: super (outputDataObject.getNodeDelegate(), Children.LEAF);
104: mProject = project;
105: mOutputFile = outputDataObject.getPrimaryFile();
106:
107: // set the model listener
108: mFileChangeListener = new FileChangeAdapter() {
109: public void fileChanged(FileEvent fe) {
110: fireIconChange();
111: }
112: };
113:
114: mOutputFile.addFileChangeListener(mFileChangeListener);
115:
116: mTestCaseOutputCookie = new TestCaseOutputCookie(this );
117: }
118:
119: public String getDisplayName() {
120: return NbBundle.getMessage(TestCaseInputNode.class,
121: "LBL_TestOutputNode"); // NOI18N
122: }
123:
124: public boolean canCut() {
125: return false;
126: }
127:
128: // public boolean canCopy() {
129: // return false;
130: // }
131:
132: public boolean canDestroy() {
133: return false;
134: }
135:
136: public boolean canRename() {
137: return false;
138: }
139:
140: /**
141: * DOCUMENT ME!
142: *
143: * @param type DOCUMENT ME!
144: *
145: * @return DOCUMENT ME!
146: */
147: public Image getIcon(int type) {
148: return computeIcon(false, type);
149: }
150:
151: private Image computeIcon(boolean opened, int type) {
152: Image image = OUTPUT_ICON;
153: File file = FileUtil.toFile(mOutputFile);
154: if (file.length() == 0) {
155: return Utilities.mergeImages(image, WARNING_BADGE, 15, 8); //7, 5);
156: } else {
157: return image;
158: }
159: }
160:
161: // Create the popup menu:
162: public Action[] getActions(boolean context) {
163: return new Action[] {
164: SystemAction.get(EditAction.class),
165: SystemAction
166: .get(TestCaseSaveRecentResultAsOutputAction.class) };
167: }
168:
169: public Node.Cookie getCookie(Class type) {
170: if (type == TestCaseOutputCookie.class) {
171: return mTestCaseOutputCookie;
172: }
173: return super.getCookie(type);
174: }
175: }
|