KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > changelog > ChangeLogAction


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.changelog;
21
22 import org.openide.util.NbBundle;
23 import org.openide.util.HelpCtx;
24 import org.openide.filesystems.FileObject;
25 import org.openide.nodes.Node;
26 import org.openide.*;
27
28 import javax.swing.*;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.awt.event.ActionEvent JavaDoc;
31
32
33 import org.netbeans.modules.vcscore.actions.GeneralCommandAction;
34 import org.netbeans.modules.javacvs.commands.*;
35 import org.netbeans.modules.cvsclient.commands.*;
36 import org.netbeans.modules.cvsclient.NbJavaCvsFileSystem;
37 import org.netbeans.modules.cvsclient.actions.*;
38
39 import org.netbeans.modules.changelog.wizard.*;
40 import org.netbeans.modules.changelog.*;
41
42 /**
43  * Runs a cvs log command, processes it's output and generates a changelog.
44  * @author Milos Kleint, Ralph Krueger
45  */

46 public class ChangeLogAction extends CallBackCommandAction {
47
48
49     private transient ChangeLogDisplayer displayer = null;
50     private transient ChangeLogProcessor processor = null;
51     
52     private transient WizardDescriptor wd;
53     
54     /** Creates new UpdateCommandAction */
55     public ChangeLogAction() {
56     }
57
58     public HelpCtx getHelpCtx() {
59         HelpCtx retValue;
60         
61         retValue = super.getHelpCtx();
62         return retValue;
63     }
64     
65     protected String JavaDoc iconResource() {
66        return null;
67     }
68     
69     public String JavaDoc getName() {
70         return NbBundle.getMessage(ChangeLogAction.class, "LBL_ChangeLogAction"); //NOI18N
71
}
72     
73     
74     /**
75      * Runs a command and attaches the changelog displayer to it.
76      * Should be called only from within the performsAction() code.
77      * @param fs the filesystem that are the fileobjects related to.
78      * @param fos part of files that are selected (they come from the same filesystem)
79      */

80     
81     private void doChangeLog(NbJavaCvsFileSystem fs, FileObject[] fos) {
82            CvsLog.LogImpl stImpl = (CvsLog.LogImpl)fs.createLog();
83            stImpl.setNoTags(!processor.isIncludeBranchNames());
84            stImpl.setUserFilter(processor.getUser());
85            stImpl.setDateFilter(processor.getDateRange());
86            stImpl.setRevisionFilter(processor.getRevisionRange());
87            stImpl.setFileObjects(fos);
88            if (displayer != null) {
89                stImpl.addDisplayerListener(displayer);
90            }
91            stImpl.addDisplayerListener(new ErrorLogPanel(stImpl.getOuterClassInstance(), false));
92            displayer.setNumberOfCommands(displayer.getNumberOfCommand() + 1);
93            fs.prepareCommand(stImpl.getOuterClassInstance());
94            stImpl.startCommand();
95      }
96     
97     /**
98      * This method doesn't extract the fileobjects from the activated nodes itself, but rather
99      * consults the AbstractCommandAction to get a list of supporters.
100      * On this list then performs the action.
101      */

102     protected void performAction(final Node[] nodes) {
103         String JavaDoc[] names = new String JavaDoc[3];
104         names[0] = NbBundle.getBundle(ChangeLogAction.class).getString("ChangeLogAction.wizard_firstPanel");
105         names[1] = NbBundle.getBundle(ChangeLogAction.class).getString("ChangeLogAction.wizard_secondPanel");
106         names[2] = NbBundle.getBundle(ChangeLogAction.class).getString("ChangeLogAction.wizard_htmlPanel");
107         WizardDescriptor.Panel[] panels = new WizardDescriptor.Panel[3];
108         panels[0] = new FilterPanel.Panel(names[0]);
109         panels[1] = new OutputPanel.Panel(names[1]);
110         panels[2] = new HtmlPanel.Panel(names[2]);
111         processor = new ChangeLogProcessor();
112         wd = new WizardDescriptor(panels, processor);
113         wd.setTitle(NbBundle.getBundle(ChangeLogAction.class).getString("ChangeLogAction.wizard_title"));
114         wd.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
115         wd.putProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
116         wd.putProperty("WizardPanel_contentNumbered", Boolean.TRUE);
117         wd.putProperty("WizardPanel_contentData", names);
118         
119 /* wd.setButtonListener(new ActionListener() {
120             public void actionPerformed(ActionEvent evt) {
121                 if (wd != null) {
122                     if (wd.getValue().equals(WizardDescriptor.FINISH_OPTION)) {
123                         displayer = new ChangeLogDisplayer(processor);
124                         ChangeLogAction.super.performAction(nodes);
125                         wd = null;
126                         processor = null;
127                     }
128                 }
129             }
130         });
131   */

132         final java.awt.Dialog JavaDoc dial = TopManager.getDefault().createDialog(wd);
133         final WizardDescriptor desc = wd;
134         SwingUtilities.invokeLater(new Runnable JavaDoc() {
135             public void run() {
136                 dial.show();
137                 if (desc.getValue().equals(WizardDescriptor.FINISH_OPTION)) {
138                     displayer = new ChangeLogDisplayer(processor);
139                     ChangeLogAction.super.performAction(nodes);
140 // wd = null;
141
processor = null;
142                 }
143             }
144         });
145     }
146     
147     /**
148      * Each supporter are checked if if they enable the action.
149      * All supporters need to come to a concensus in order for the action to be enabled.
150      * *experimental* annotates the toolbar tooltip according to the supporter's requests.
151      */

152     protected boolean enable(Node[] nodes) {
153         boolean retValue;
154         retValue = super.enable(nodes);
155         return true;
156     }
157     
158     /** Is called from the ActionSupporter when it stops iterating the
159      * collected filesystems and fileobjects..
160      * Can be used for clean up, etc.
161      *
162      */

163     public void finishCallBack() {
164         super.finishCallBack();
165     }
166     
167     /** Is called from the ActionSupporter when it starts iterating the
168      * collected filesystems and fileobjects..
169      * Can be used for initial settings, eg. to create a common displayer for everyone.
170      *
171      */

172     public void initCallBack(JavaCvsActionSupporter supporter) {
173         
174     }
175     
176     /** method is called from the ActionSupporter and executes the action on the fileobjects..
177      *
178      */

179     public void performCallBack(NbJavaCvsFileSystem fs, FileObject[] fos) {
180         doChangeLog(fs, fos);
181     }
182     
183 }
184
Popular Tags