KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > output > OutputWindowAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.output;
21
22 import org.openide.util.HelpCtx;
23 import org.openide.util.NbBundle;
24 import org.openide.util.actions.CallableSystemAction;
25
26 import org.openide.windows.Mode;
27 import org.openide.windows.TopComponent;
28 import org.openide.windows.WindowManager;
29
30 /** The action which shows standard IO component.
31 *
32 * @author Dafe Simonek
33 */

34 public final class OutputWindowAction extends CallableSystemAction {
35
36     public void performAction() {
37         OutputView output = OutputView.findDefault();
38         if (!output.isDisplayable()) {
39             output = findOutputComponent();
40             if (output != null) {
41                 //OutputView should be defined in XML layer so default
42
//code flow is here.
43
output.open();
44                 output.requestActive();
45             } else {
46                 //If OutputView is not defined in XML layer (or is not already present
47
//in some mode get instance and dock it to default "output" mode.
48
output = OutputView.findDefault();
49                 if (!output.isShowing()) {
50                     Mode mode = WindowManager.getDefault().getCurrentWorkspace().findMode("output"); // NOI18N
51
if (mode == null) {
52                         //Mode output not found, create it.
53
String JavaDoc displayName = NbBundle.getBundle(OutputWindowAction.class).getString("CTL_OutputWindow_OutputTab");
54                         mode = WindowManager.getDefault().getCurrentWorkspace().createMode("output", displayName, null);
55                     }
56                     //Dock OutputView to "output" mode.
57
mode.dockInto(output);
58                     output.open();
59                 }
60             }
61         }
62         output.requestActive();
63         
64         //String name = NbBundle.getBundle(OutputWindowAction.class).getString("CTL_OutputWindow_OutputTab");
65
//InputOutput io = output.getIO(name,false);
66
//io.select();
67
}
68     
69     protected boolean asynchronous() {
70         return false;
71     }
72
73     public String JavaDoc getName() {
74         return NbBundle.getBundle(OutputWindowAction.class).getString("OutputWindow");
75     }
76
77     public HelpCtx getHelpCtx() {
78         return new HelpCtx (OutputWindowAction.class);
79     }
80
81     protected String JavaDoc iconResource () {
82         return "org/netbeans/core/resources/frames/output.gif"; // NOI18N
83
}
84     
85     // PENDING When the output will be singleton (new UI spec), remove this method.
86
/** Finds last selected component of output family */
87     private static OutputView findOutputComponent() {
88         Mode mode = WindowManager.getDefault().getCurrentWorkspace().findMode("output"); // NOI18N
89

90         if (mode != null) {
91             TopComponent[] tcs = mode.getTopComponents();
92             for (int i = 0; i < tcs.length; i++) {
93                 if (tcs[i] instanceof OutputView) {
94                     return (OutputView) tcs[i];
95                 }
96             }
97         }
98         
99         return null;
100     }
101
102 }
103
Popular Tags