KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > ui > actions > RefreshAction


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.modules.j2ee.deployment.impl.ui.actions;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import javax.swing.AbstractAction JavaDoc;
24 import javax.swing.ImageIcon JavaDoc;
25 import org.netbeans.modules.j2ee.deployment.config.Utils;
26 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
27 import org.openide.nodes.*;
28 import org.openide.util.actions.*;
29 import org.openide.util.HelpCtx;
30 import org.openide.util.NbBundle;
31 import org.openide.util.Utilities;
32
33 /**
34  * Resfresh action refreshes the server state.
35  *
36  * @author nn136682
37  */

38 public class RefreshAction extends NodeAction {
39     
40     public String JavaDoc getName() {
41         return NbBundle.getMessage(DebugAction.class, "LBL_Refresh");
42     }
43     
44     protected void performAction(Node[] nodes) {
45         performActionImpl(nodes);
46     }
47     
48     protected boolean enable(Node[] nodes) {
49         return enableImpl(nodes);
50     }
51     
52     public HelpCtx getHelpCtx() {
53         return HelpCtx.DEFAULT_HELP;
54     }
55     
56     protected boolean asynchronous() {
57         return false;
58     }
59     
60     // private helper methods -------------------------------------------------
61

62     private static void performActionImpl(Node[] nodes) {
63         for (int i = 0; i < nodes.length; i++) {
64             ServerInstance si = (ServerInstance)nodes[i].getCookie(ServerInstance.class);
65             if (si != null) {
66                 si.refresh();
67             }
68         }
69     }
70     
71     private static boolean enableImpl(Node[] nodes) {
72         for (int i = 0; i < nodes.length; i++) {
73             ServerInstance si = (ServerInstance)nodes[i].getCookie(ServerInstance.class);
74             if (si == null || si.getServerState() == ServerInstance.STATE_WAITING) {
75                 return false;
76             }
77         }
78         return true;
79     }
80     
81     /** This action will be displayed in the server output window */
82     public static class OutputAction extends AbstractAction JavaDoc implements ServerInstance.StateListener {
83         
84         private static final String JavaDoc ICON =
85                 "org/netbeans/modules/j2ee/deployment/impl/ui/resources/refresh.png"; // NOI18N
86
private static final String JavaDoc PROP_ENABLED = "enabled"; // NOI18N
87
private Node node;
88         
89         public OutputAction(Node node) {
90             super(NbBundle.getMessage(DebugAction.class, "LBL_RefreshOutput"),
91                   new ImageIcon JavaDoc(Utilities.loadImage(ICON)));
92             putValue(SHORT_DESCRIPTION, NbBundle.getMessage(DebugAction.class, "LBL_RefreshOutputDesc"));
93             this.node = node;
94             
95             // start listening to changes
96
ServerInstance si = (ServerInstance)node.getCookie(ServerInstance.class);
97             si.addStateListener(this);
98         }
99
100         public void actionPerformed(ActionEvent JavaDoc e) {
101             performActionImpl(new Node[] {node});
102         }
103
104         public boolean isEnabled() {
105             return enableImpl(new Node[] {node});
106         }
107         
108         // ServerInstance.StateListener implementation --------------------------
109

110         public void stateChanged(final int oldState, final int newState) {
111             Utils.runInEventDispatchThread(new Runnable JavaDoc() {
112                 public void run() {
113                     firePropertyChange(
114                         PROP_ENABLED,
115                         null,
116                         isEnabled() ? Boolean.TRUE : Boolean.FALSE);
117                 }
118             });
119         }
120     }
121 }
122
Popular Tags