KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javadoc > httpfs > RefreshAction


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

24
25
26 package org.netbeans.modules.javadoc.httpfs;
27
28 import org.openide.nodes.Node;
29 import org.openide.util.HelpCtx;
30 import org.openide.loaders.DataObject;
31 import org.openide.filesystems.FileObject;
32 import org.openide.util.NbBundle;
33
34
35 /**
36  * Performs the action of refreshing this file system from the web site.
37  *
38  * @since 3.4
39  */

40 class RefreshAction
41     extends org.openide.util.actions.NodeAction {
42
43     /**
44      * Constructs a <code>RefreshAction</code> used to refresh the file system.
45      *
46      * @since 3.4
47      */

48     RefreshAction(
49     ) {
50     }
51
52
53     /**
54      * Returns the name of this action to display in the context menu.
55      *
56      * @return The name of the action.
57      *
58      * @since 3.4
59      */

60     public String JavaDoc getName(
61     ) {
62
63         return NbBundle.getMessage(RefreshAction.class, "RefreshFS" ); // NOI18N
64

65     }
66
67     /**
68      * Tests the selected nodes if they are HTTPRootFileObject items, and if so,
69      * allows this action to be displayed.
70      *
71      * @param activatedNodes Current activated nodes.
72      *
73      * @return <code>true</code> to be enabled, <code>false</code> to be disabled
74      *
75      * @since 3.4
76      */

77     protected boolean enable(
78         Node[] activatedNodes
79     ) {
80
81         // Flags whether all of the selected nodes represent HTTPRootFileObject nodes
82
boolean rootFolderSelected;
83         // Index into the array of nodes
84
int nodeIndex;
85         // Object behind the node
86
DataObject dataObject;
87         // File object behind the node
88
FileObject fileObject;
89
90
91         rootFolderSelected = true;
92         nodeIndex = 0;
93
94         // Loop through all the nodes passed to this routine
95
while( nodeIndex < activatedNodes.length && rootFolderSelected ) {
96
97             // Get the node object
98
dataObject = (DataObject)activatedNodes[ nodeIndex ].getCookie( DataObject.class );
99             if( dataObject != null ) {
100
101                 // Get the file
102
fileObject = dataObject.getPrimaryFile( );
103
104                 // If this file is not an HTTPRootFileObject,
105
if( !( fileObject instanceof HTTPRootFileObject ) ) {
106
107                     // Flag that this action doesn't apply
108
rootFolderSelected = false;
109
110                 }
111
112             } else {
113
114                 // Flag that this action doesn't apply
115
rootFolderSelected = false;
116
117             }
118             nodeIndex++;
119
120         }
121         return rootFolderSelected;
122
123     }
124
125
126     /**
127      * Return the default help context.
128      *
129      * @return The help context for this action
130      *
131      * @since 3.4
132      */

133     public HelpCtx getHelpCtx(
134     ) {
135
136         return HelpCtx.DEFAULT_HELP;
137
138     }
139
140
141     /**
142      * Perform this action on the currently selected list of nodes.
143      *
144      * @param activatedNodes Current activated nodes.
145      *
146      * @since 3.4
147      */

148     protected void performAction(
149         Node[] activatedNodes
150     ) {
151
152         // Index into the list of nodes
153
int nodeIndex;
154         // Data object behind each node
155
DataObject dataObject;
156         // File object behind each node
157
HTTPRootFileObject rootFileObject;
158
159
160         // Loop through each of the nodes passed
161
for( nodeIndex = 0; nodeIndex < activatedNodes.length; nodeIndex++ ) {
162
163             // Refresh the contents of each file system selected
164
dataObject = (DataObject)activatedNodes[ nodeIndex ].getCookie( DataObject.class );
165             rootFileObject = (HTTPRootFileObject)dataObject.getPrimaryFile( );
166             rootFileObject.triggerRefresh( );
167
168         }
169
170     }
171
172 }
173
Popular Tags