KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > editors > EditorsCommand


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 package org.netbeans.lib.cvsclient.command.editors;
20
21 import java.io.*;
22
23 import org.netbeans.lib.cvsclient.*;
24 import org.netbeans.lib.cvsclient.command.*;
25 import org.netbeans.lib.cvsclient.connection.*;
26 import org.netbeans.lib.cvsclient.event.*;
27 import org.netbeans.lib.cvsclient.request.*;
28
29 /**
30  * @author Thomas Singer
31  */

32 public class EditorsCommand extends BasicCommand {
33
34     /**
35      * Construct a new editors command.
36      */

37     public EditorsCommand() {
38         resetCVSCommand();
39     }
40
41     /**
42      * Creates the EditorsBuilder.
43      * @param eventManager the event manager used to received cvs events
44      */

45     public Builder createBuilder(EventManager eventManager) {
46         return new EditorsBuilder(eventManager);
47     }
48
49     /**
50      * Execute the command.
51      *
52      * @param client the client services object that provides any necessary
53      * services to this command, including the ability to actually
54      * process all the requests.
55      */

56     public void execute(ClientServices clientServices, EventManager eventManager)
57             throws CommandException, AuthenticationException {
58
59         clientServices.ensureConnection();
60
61         super.execute(clientServices, eventManager);
62
63         try {
64             addRequestForWorkingDirectory(clientServices);
65             addArgumentRequests();
66             addRequest(CommandRequest.EDITORS);
67
68             clientServices.processRequests(requests);
69         }
70         catch (CommandException ex) {
71             throw ex;
72         }
73         catch (EOFException ex) {
74             throw new CommandException(ex, CommandException.getLocalMessage("CommandException.EndOfFile", null)); //NOI18N
75
}
76         catch (Exception JavaDoc ex) {
77             throw new CommandException(ex, ex.getLocalizedMessage());
78         }
79         finally {
80             requests.clear();
81         }
82     }
83
84     /**
85      * Called when server responses with "ok" or "error", (when the command
86      * finishes).
87      */

88     public void commandTerminated(TerminationEvent e) {
89         if (builder != null) {
90             builder.outputDone();
91         }
92     }
93
94     /**
95      * This method returns how the tag command would looklike when typed on the
96      * command line.
97      */

98     public String JavaDoc getCVSCommand() {
99         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc("editors "); //NOI18N
100
toReturn.append(getCVSArguments());
101         File[] files = getFiles();
102         if (files != null) {
103             for (int index = 0; index < files.length; index++) {
104                 toReturn.append(files[index].getName());
105                 toReturn.append(' ');
106             }
107         }
108         return toReturn.toString();
109     }
110
111     /**
112      * Takes the arguments and sets the command.
113      * To be mainly used for automatic settings (like parsing the .cvsrc file)
114      * @return true if the option (switch) was recognized and set
115      */

116     public boolean setCVSCommand(char opt, String JavaDoc optArg) {
117         if (opt == 'R') {
118             setRecursive(true);
119         }
120         else if (opt == 'l') {
121             setRecursive(false);
122         }
123         else {
124             return false;
125         }
126         return true;
127     }
128
129     /**
130      * String returned by this method defines which options are available for
131      * this command.
132      */

133     public String JavaDoc getOptString() {
134         return "Rl"; //NOI18N
135
}
136
137     /**
138      * Resets all switches in the command.
139      * After calling this method, the command should have no switches defined
140      * and should behave defaultly.
141      */

142     public void resetCVSCommand() {
143         setRecursive(true);
144     }
145
146     /**
147      * Returns the arguments of the command in the command-line style.
148      * Similar to getCVSCommand() however without the files and command's name
149      */

150     public String JavaDoc getCVSArguments() {
151         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc();
152         if (!isRecursive()) {
153             toReturn.append("-l "); //NOI18N
154
}
155         return toReturn.toString();
156     }
157
158 }
159
Popular Tags