KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > log > LogExecutor


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.log;
21
22 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem;
23 import org.netbeans.modules.versioning.system.cvss.ExecutorSupport;
24 import org.netbeans.modules.versioning.system.cvss.ClientRuntime;
25 import org.netbeans.lib.cvsclient.command.GlobalOptions;
26 import org.netbeans.lib.cvsclient.command.Command;
27 import org.netbeans.lib.cvsclient.command.log.LogCommand;
28 import org.netbeans.lib.cvsclient.command.log.LogInformation;
29 import org.netbeans.lib.cvsclient.event.FileInfoEvent;
30 import org.openide.util.NbBundle;
31 import org.openide.ErrorManager;
32
33 import java.util.*;
34 import java.io.IOException JavaDoc;
35
36
37 /**
38  * Executes a given 'log' command.
39  *
40  * @author Petr Kuzel
41  * @author Maros Sandor
42  */

43 public class LogExecutor extends ExecutorSupport {
44
45     private final List listeners = new ArrayList(1);
46
47     /**
48      * Splits the original command into more commands if the original
49      * command would execute on incompatible files.
50      * See {@link #prepareBasicCommand(org.netbeans.lib.cvsclient.command.BasicCommand)}
51      * for more information.
52      *
53      * @param cmd command o execute
54      * @param options global option for the command
55      * @return array of executors that will execute the command (or array of splitted commands)
56      */

57     public static LogExecutor [] splitCommand(LogCommand cmd, GlobalOptions options) {
58         Command [] cmds = new org.netbeans.lib.cvsclient.command.Command[0];
59         if (cmd.getDisplayName() == null) cmd.setDisplayName(NbBundle.getMessage(LogExecutor.class, "MSG_LogExecutor_CmdDisplayName"));
60         try {
61             cmds = prepareBasicCommand(cmd);
62         } catch (IOException JavaDoc e) {
63             ErrorManager.getDefault().notify(e);
64             return null;
65         }
66         LogExecutor [] executors = new LogExecutor[cmds.length];
67         for (int i = 0; i < cmds.length; i++) {
68             Command command = cmds[i];
69             executors[i] = new LogExecutor(CvsVersioningSystem.getInstance(), (LogCommand) command, options);
70         }
71         return executors;
72     }
73     
74     public LogExecutor(CvsVersioningSystem cvs, LogCommand cmd) {
75         this(cvs, cmd, null);
76     }
77     
78     public LogExecutor(CvsVersioningSystem cvs, LogCommand cmd, GlobalOptions options) {
79         super(cvs, cmd, options);
80     }
81
82     protected void commandFinished(ClientRuntime.Result result) {
83     }
84
85     public void fileInfoGenerated(FileInfoEvent e) {
86         super.fileInfoGenerated(e);
87         LogInformation li = (LogInformation) e.getInfoContainer();
88         List revisions = li.getRevisionList();
89         Iterator rit = revisions.iterator();
90         Map messages = new HashMap(revisions.size());
91         while (rit.hasNext()) {
92             LogInformation.Revision rev = (LogInformation.Revision) rit.next();
93             String JavaDoc message = rev.getMessage();
94             String JavaDoc revId = rev.getNumber();
95             messages.put(revId, message);
96         }
97         Iterator it = listeners.iterator();
98         while (it.hasNext()) {
99             LogOutputListener listener = (LogOutputListener) it.next();
100             listener.commitMessages(messages);
101         }
102     }
103
104     public void addLogOutputListener(LogOutputListener listener) {
105         listeners.add(listener);
106     }
107
108     public List getLogEntries() {
109         return toRefresh;
110     }
111
112     protected boolean logCommandOutput() {
113         return false;
114     }
115 }
116
Popular Tags