KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > commit > CommitExecutor


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.versioning.system.cvss.ui.actions.commit;
21
22 import org.netbeans.modules.versioning.system.cvss.*;
23 import org.netbeans.lib.cvsclient.command.GlobalOptions;
24 import org.netbeans.lib.cvsclient.command.Command;
25 import org.netbeans.lib.cvsclient.command.commit.CommitInformation;
26 import org.netbeans.lib.cvsclient.command.commit.CommitCommand;
27 import org.openide.filesystems.FileObject;
28 import org.openide.filesystems.FileUtil;
29 import org.openide.ErrorManager;
30 import org.openide.util.NbBundle;
31
32 import java.util.*;
33 import java.io.File JavaDoc;
34 import java.io.IOException JavaDoc;
35
36 /**
37  * Executes a given 'commit' command and refreshes file statuses.
38  *
39  * @author Maros Sandor
40  */

41 public class CommitExecutor extends ExecutorSupport {
42     
43     /**
44      * Splits the original command into more commands if the original
45      * command would execute on incompatible files.
46      * See {@link #prepareBasicCommand(org.netbeans.lib.cvsclient.command.BasicCommand)}
47      * for more information.
48      *
49      * @param cmd command o execute
50      * @param cvs CVS engine to use
51      * @param options global option for the command
52      * @return array of executors that will execute the command (or array of splitted commands)
53      */

54     public static CommitExecutor [] splitCommand(CommitCommand cmd, CvsVersioningSystem cvs, GlobalOptions options) {
55         Command [] cmds = new org.netbeans.lib.cvsclient.command.Command[0];
56         ResourceBundle loc = NbBundle.getBundle(CommitExecutor.class);
57         if (cmd.getDisplayName() == null) cmd.setDisplayName(loc.getString("MSG_CommitExecutor_CmdDisplayName"));
58         try {
59             cmds = prepareBasicCommand(cmd);
60         } catch (IOException JavaDoc e) {
61             ErrorManager.getDefault().notify(e);
62             return null;
63         }
64         CommitExecutor [] executors = new CommitExecutor[cmds.length];
65         for (int i = 0; i < cmds.length; i++) {
66             Command command = cmds[i];
67             executors[i] = new CommitExecutor(cvs, (CommitCommand) command, options);
68         }
69         return executors;
70     }
71     
72     private CommitExecutor(CvsVersioningSystem cvs, CommitCommand cmd, GlobalOptions options) {
73         super(cvs, cmd, options);
74     }
75
76     /**
77      * Refreshes statuse of relevant files after this command terminates.
78      */

79     protected void commandFinished(ClientRuntime.Result result) {
80         
81         CommitCommand xcmd = (CommitCommand) cmd;
82         
83         for (Iterator i = toRefresh.iterator(); i.hasNext();) {
84             CommitInformation info = (CommitInformation) i.next();
85             if (info.getFile() == null) continue;
86             int repositoryStatus = FileStatusCache.REPOSITORY_STATUS_UNKNOWN;
87             String JavaDoc type = info.getType();
88             if (CommitInformation.CHANGED.equals(type) || CommitInformation.ADDED.equals(type)) {
89                 repositoryStatus = FileStatusCache.REPOSITORY_STATUS_UPTODATE;
90             } else if (CommitInformation.REMOVED.equals(type) || CommitInformation.TO_ADD.equals(type)) {
91                 repositoryStatus = FileStatusCache.REPOSITORY_STATUS_UNKNOWN;
92             }
93             cache.refreshCached(info.getFile(), repositoryStatus);
94         }
95
96         if (cmd.hasFailed()) return;
97
98         // refresh all command roots
99
File JavaDoc [] files = xcmd.getFiles();
100         for (int i = 0; i < files.length; i++) {
101             FileObject fo = FileUtil.toFileObject(files[i]);
102             if (fo != null) {
103                 fo.refresh(true);
104             }
105         }
106     }
107
108 }
109
Popular Tags